[{"id":33711,"web_url":"https://patchwork.libcamera.org/comment/33711/","msgid":"<174298546107.670680.9769840826469120155@ping.linuxembedded.co.uk>","date":"2025-03-26T10:37:41","subject":"Re: [PATCH v8 02/10] libcamera: software_isp: Use RGB type to\n\trepresent gains","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Milan Zamazal (2025-03-26 09:08:39)\n> Rather than using a custom struct to represent RGB values, let's use the\n> corresponding type and its facilities.\n> \n> Signed-off-by: Milan Zamazal <mzamazal@redhat.com>\n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> Signed-off-by: Milan Zamazal <mzamazal@redhat.com>\n> ---\n>  src/ipa/simple/algorithms/awb.cpp | 16 +++++++++-------\n>  src/ipa/simple/algorithms/lut.cpp | 14 ++++----------\n>  src/ipa/simple/ipa_context.h      |  8 +++-----\n>  3 files changed, 16 insertions(+), 22 deletions(-)\n> \n> diff --git a/src/ipa/simple/algorithms/awb.cpp b/src/ipa/simple/algorithms/awb.cpp\n> index 1efc7090..310be6a7 100644\n> --- a/src/ipa/simple/algorithms/awb.cpp\n> +++ b/src/ipa/simple/algorithms/awb.cpp\n> @@ -25,7 +25,7 @@ int Awb::configure(IPAContext &context,\n>                    [[maybe_unused]] const IPAConfigInfo &configInfo)\n>  {\n>         auto &gains = context.activeState.awb.gains;\n> -       gains.red = gains.green = gains.blue = 1.0;\n> +       gains = { { 1.0, 1.0, 1.0 } };\n>  \n>         return 0;\n>  }\n> @@ -56,16 +56,18 @@ void Awb::process(IPAContext &context,\n>          * Clamp max gain at 4.0, this also avoids 0 division.\n>          */\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> +       gains = { {\n> +               sumR <= sumG / 4 ? 4.0 : static_cast<double>(sumG) / sumR,\n> +               1.0,\n> +               sumB <= sumG / 4 ? 4.0 : static_cast<double>(sumG) / sumB,\n> +       } };\n>  \n> -       RGB<double> rgbGains{ { 1 / gains.red, 1 / gains.green, 1 / gains.blue } };\n> +       RGB<double> rgbGains{ { 1 / gains.r(), 1 / gains.g(), 1 / gains.b() } };\n>         context.activeState.awb.temperatureK = estimateCCT(rgbGains);\n>  \n>         LOG(IPASoftAwb, Debug)\n> -               << \"gain R/B: \" << gains.red << \"/\" << gains.blue\n> -               << \"; temperature: \" << context.activeState.awb.temperatureK;\n> +               << \"gain R/B: \" << gains << \"; temperature: \"\n> +               << 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 a2e11d3b..83df71a9 100644\n> --- a/src/ipa/simple/algorithms/lut.cpp\n> +++ b/src/ipa/simple/algorithms/lut.cpp\n> @@ -103,16 +103,10 @@ void Lut::prepare(IPAContext &context,\n>                 const double div = static_cast<double>(DebayerParams::kRGBLookupSize) /\n>                                    gammaTableSize;\n>                 /* Apply gamma after gain! */\n> -               unsigned int idx;\n> -               idx = std::min({ static_cast<unsigned int>(i * gains.red / div),\n> -                                gammaTableSize - 1 });\n> -               params->red[i] = gammaTable[idx];\n> -               idx = std::min({ static_cast<unsigned int>(i * gains.green / div),\n> -                                gammaTableSize - 1 });\n> -               params->green[i] = gammaTable[idx];\n> -               idx = std::min({ static_cast<unsigned int>(i * gains.blue / div),\n> -                                gammaTableSize - 1 });\n> -               params->blue[i] = gammaTable[idx];\n> +               const RGB<double> lutGains = (gains * i / div).min(gammaTableSize - 1);\n> +               params->red[i] = gammaTable[static_cast<unsigned int>(lutGains.r())];\n> +               params->green[i] = gammaTable[static_cast<unsigned int>(lutGains.g())];\n> +               params->blue[i] = gammaTable[static_cast<unsigned int>(lutGains.b())];\n>         }\n>  }\n>  \n> diff --git a/src/ipa/simple/ipa_context.h b/src/ipa/simple/ipa_context.h\n> index 607af45a..6a285414 100644\n> --- a/src/ipa/simple/ipa_context.h\n> +++ b/src/ipa/simple/ipa_context.h\n> @@ -13,6 +13,8 @@\n>  \n>  #include <libcamera/controls.h>\n>  \n> +#include \"libcamera/internal/vector.h\"\n> +\n>  #include <libipa/fc_queue.h>\n>  \n>  namespace libcamera {\n> @@ -36,11 +38,7 @@ struct IPAActiveState {\n>         } blc;\n>  \n>         struct {\n> -               struct {\n> -                       double red;\n> -                       double green;\n> -                       double blue;\n> -               } gains;\n> +               RGB<double> gains;\n>                 unsigned int temperatureK;\n>         } awb;\n>  \n> -- \n> 2.49.0\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 AC3E2C3213\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 26 Mar 2025 10:37:45 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id D524C68955;\n\tWed, 26 Mar 2025 11:37:44 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 84B1368947\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 26 Mar 2025 11:37:43 +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 8D866475;\n\tWed, 26 Mar 2025 11:35:55 +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=\"Pq8nzC79\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1742985355;\n\tbh=iluhNS32Gzy/vYRdq/DS7D9IZeA622QL7UIsIDTPTS0=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=Pq8nzC79W7uRzZrlipZvcmIdIa2TBdwj84YIY0oQL/Ltft9j1We/ZTkImrn8dIyK1\n\tNTWRx4JwhFl9FxvRdxi6QOW6M/QMDBu2gipOxre4GBgsFf8yQjfA3xjWEPbt1tdQRn\n\t+6qPvegJfcnX9U3xQH0jM+y3t5ugo2UYOn8ziIwg=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20250326090849.15494-3-mzamazal@redhat.com>","References":"<20250326090849.15494-1-mzamazal@redhat.com>\n\t<20250326090849.15494-3-mzamazal@redhat.com>","Subject":"Re: [PATCH v8 02/10] libcamera: software_isp: Use RGB type to\n\trepresent gains","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":"Wed, 26 Mar 2025 10:37:41 +0000","Message-ID":"<174298546107.670680.9769840826469120155@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>"}}]