[{"id":32979,"web_url":"https://patchwork.libcamera.org/comment/32979/","msgid":"<173644143049.2992722.11552948025724744649@ping.linuxembedded.co.uk>","date":"2025-01-09T16:50:30","subject":"Re: [PATCH v3 1/9] libcamera: software_isp: Determine color\n\ttemperature","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Milan Zamazal (2024-12-10 15:34:31)\n> The AWB algorithm has data to determine color temperature of the image.\n> Let's compute the temperature from it and store it into the context.\n> This piece of information is currently unused but it will be needed in a\n> followup patch introducing support for color correction matrix.\n> \n> Let's store the white balance related information under `awb' subsection\n> of the active state, as the hardware pipelines do.\n> \n> Signed-off-by: Milan Zamazal <mzamazal@redhat.com>\n\nLooks reasonable.\n\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> ---\n>  src/ipa/simple/algorithms/awb.cpp | 13 ++++++++++---\n>  src/ipa/simple/algorithms/lut.cpp |  2 +-\n>  src/ipa/simple/ipa_context.h      | 11 +++++++----\n>  3 files changed, 18 insertions(+), 8 deletions(-)\n> \n> diff --git a/src/ipa/simple/algorithms/awb.cpp b/src/ipa/simple/algorithms/awb.cpp\n> index 195de41d..f4fe1af6 100644\n> --- a/src/ipa/simple/algorithms/awb.cpp\n> +++ b/src/ipa/simple/algorithms/awb.cpp\n> @@ -12,6 +12,7 @@\n>  \n>  #include <libcamera/base/log.h>\n>  \n> +#include \"libipa/colours.h\"\n>  #include \"simple/ipa_context.h\"\n>  \n>  namespace libcamera {\n> @@ -23,7 +24,7 @@ namespace ipa::soft::algorithms {\n>  int Awb::configure(IPAContext &context,\n>                    [[maybe_unused]] const IPAConfigInfo &configInfo)\n>  {\n> -       auto &gains = context.activeState.gains;\n> +       auto &gains = context.activeState.awb.gains;\n>         gains.red = gains.green = gains.blue = 1.0;\n>  \n>         return 0;\n> @@ -54,12 +55,18 @@ void Awb::process(IPAContext &context,\n>          * Calculate red and blue gains for AWB.\n>          * Clamp max gain at 4.0, this also avoids 0 division.\n>          */\n> -       auto &gains = context.activeState.gains;\n> +       auto &gains = context.activeState.awb.gains;\n>         gains.red = sumR <= sumG / 4 ? 4.0 : static_cast<double>(sumG) / sumR;\n>         gains.blue = sumB <= sumG / 4 ? 4.0 : static_cast<double>(sumG) / sumB;\n>         /* Green gain is fixed to 1.0 */\n>  \n> -       LOG(IPASoftAwb, Debug) << \"gain R/B \" << gains.red << \"/\" << gains.blue;\n> +       RGB<double> rgbGains{ { 1 / gains.red, 1 / gains.green, 1 / gains.blue } };\n> +       uint32_t temperature = estimateCCT(rgbGains);\n> +       context.activeState.awb.temperatureK = temperature;\n> +\n> +       LOG(IPASoftAwb, Debug)\n> +               << \"gain R/B: \" << gains.red << \"/\" << gains.blue\n> +               << \"; temperature: \" << context.activeState.awb.temperatureK;\n>  }\n>  \n>  REGISTER_IPA_ALGORITHM(Awb, \"Awb\")\n> diff --git a/src/ipa/simple/algorithms/lut.cpp b/src/ipa/simple/algorithms/lut.cpp\n> index 0ba2391f..d75ff710 100644\n> --- a/src/ipa/simple/algorithms/lut.cpp\n> +++ b/src/ipa/simple/algorithms/lut.cpp\n> @@ -95,7 +95,7 @@ void Lut::prepare(IPAContext &context,\n>             context.activeState.gamma.contrast != context.activeState.knobs.contrast)\n>                 updateGammaTable(context);\n>  \n> -       auto &gains = context.activeState.gains;\n> +       auto &gains = context.activeState.awb.gains;\n>         auto &gammaTable = context.activeState.gamma.gammaTable;\n>         const unsigned int gammaTableSize = gammaTable.size();\n>  \n> diff --git a/src/ipa/simple/ipa_context.h b/src/ipa/simple/ipa_context.h\n> index 4af51306..607af45a 100644\n> --- a/src/ipa/simple/ipa_context.h\n> +++ b/src/ipa/simple/ipa_context.h\n> @@ -36,10 +36,13 @@ struct IPAActiveState {\n>         } blc;\n>  \n>         struct {\n> -               double red;\n> -               double green;\n> -               double blue;\n> -       } gains;\n> +               struct {\n> +                       double red;\n> +                       double green;\n> +                       double blue;\n> +               } gains;\n> +               unsigned int temperatureK;\n> +       } awb;\n>  \n>         static constexpr unsigned int kGammaLookupSize = 1024;\n>         struct {\n> -- \n> 2.44.2\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 8EA87C32EF\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  9 Jan 2025 16:50:36 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 8AF51684EA;\n\tThu,  9 Jan 2025 17:50:35 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id E79E661880\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  9 Jan 2025 17:50:33 +0100 (CET)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id F2BB3110F;\n\tThu,  9 Jan 2025 17:49:39 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"KVbD7q5u\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1736441380;\n\tbh=QdV5ri0YkYW8hNgOI2FeAj70YIOpa5alYi5aG58IBGA=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=KVbD7q5u2XnV7kJpHxIkXBY9IiHJ1tYdjYESYwUPKKuHij8GwvrszzITumC2D20/k\n\tz+K2tyKDnit2mv3sxfz+TbYXQP8ROowSYbb3tOHYMtbw3FqSe4UTvSJ2CU+zLwk+PF\n\tOJBtaFZUvCDYGh6HikwbLXlsijAdy00TbB2pFKCw=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20241210153440.1007470-2-mzamazal@redhat.com>","References":"<20241210153440.1007470-1-mzamazal@redhat.com>\n\t<20241210153440.1007470-2-mzamazal@redhat.com>","Subject":"Re: [PATCH v3 1/9] libcamera: software_isp: Determine color\n\ttemperature","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"Milan Zamazal <mzamazal@redhat.com>,\n\tRobert Mader <robert.mader@collabora.com>,\n\tHans de Goede <hdegoede@redhat.com>, \n\tLaurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Milan Zamazal <mzamazal@redhat.com>, libcamera-devel@lists.libcamera.org","Date":"Thu, 09 Jan 2025 16:50:30 +0000","Message-ID":"<173644143049.2992722.11552948025724744649@ping.linuxembedded.co.uk>","User-Agent":"alot/0.10","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]