[{"id":33673,"web_url":"https://patchwork.libcamera.org/comment/33673/","msgid":"<174250593138.2039497.5256575438293184896@ping.linuxembedded.co.uk>","date":"2025-03-20T21:25:31","subject":"Re: [PATCH v7 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-02-07 10:16:54)\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> ---\n>  src/ipa/simple/algorithms/awb.cpp | 16 +++++++++-------\n>  src/ipa/simple/algorithms/lut.cpp | 14 ++++----------\n>  src/ipa/simple/ipa_context.h      |  7 ++-----\n>  3 files changed, 15 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 d75ff710..1d392737 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..df0552db 100644\n> --- a/src/ipa/simple/ipa_context.h\n> +++ b/src/ipa/simple/ipa_context.h\n> @@ -14,6 +14,7 @@\n>  #include <libcamera/controls.h>\n>  \n>  #include <libipa/fc_queue.h>\n> +#include <libipa/vector.h>\n\nSince Fixes: fa93d40035db (\"libipa: Drop Vector class\"), this now needs\nto be \n\n#include \"libcamera/internal/vector.h\".\n\nWith that:\n\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n>  \n>  namespace libcamera {\n>  \n> @@ -36,11 +37,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.48.1\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 AAF37C3274\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 20 Mar 2025 21:25:36 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1C94168950;\n\tThu, 20 Mar 2025 22:25:36 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 508E0617F5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 20 Mar 2025 22:25:34 +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 4F64E710;\n\tThu, 20 Mar 2025 22:23:50 +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=\"dkRYUkSt\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1742505830;\n\tbh=mZxInXS28rSoQAk00fQHSQcVgmisqqHuonFDdHvSzt8=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=dkRYUkStBL+UuNtvrqoq6MAh7hF757f8+0F0wsIshJtateLYbMaMFbTv8R5JK020T\n\t+0Gn6LkuBRppNBGXd+UakpMoGQ+eWWpp98m2Wc7idt9k4XiewIn8OH7SLQiy+BwkVj\n\tZmjNznF4JTwW4v/1OFxj+6Gcta40PAlleRLqRlcg=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20250207101703.21149-3-mzamazal@redhat.com>","References":"<20250207101703.21149-1-mzamazal@redhat.com>\n\t<20250207101703.21149-3-mzamazal@redhat.com>","Subject":"Re: [PATCH v7 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":"Thu, 20 Mar 2025 21:25:31 +0000","Message-ID":"<174250593138.2039497.5256575438293184896@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>"}}]