[{"id":31420,"web_url":"https://patchwork.libcamera.org/comment/31420/","msgid":"<253abbf6-0e9f-4b87-b396-7aa36baf7855@ideasonboard.com>","date":"2024-09-26T19:24:08","subject":"Re: [PATCH v7 15/18] libcamera: software_isp: Use floating point for\n\tcolor parameters","submitter":{"id":86,"url":"https://patchwork.libcamera.org/api/people/86/","name":"Umang Jain","email":"umang.jain@ideasonboard.com"},"content":"Hi Milan,\n\nThank you for the patch.\n\nOn 21/09/24 12:01 am, Milan Zamazal wrote:\n> It's more natural to represent color gains as floating point numbers\n> rather than using a particular pixel-related representation.\n>\n> double is used rather than float because it's a more common floating\n> point type in libcamera algorithms.  Otherwise there is no obvious\n> reason to select one over the other here.\n>\n> The constructed color tables still use integer representation for\n> efficiency.\n>\n> Black level still uses pixel (integer) values, for consistency with\n> other libcamera parts.\n>\n> Signed-off-by: Milan Zamazal <mzamazal@redhat.com>\n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> Signed-off-by: Milan Zamazal <mzamazal@redhat.com>\n\ndouble Sign-off-by\n\n\nOtherwise,\n\nReviewed-by: Umang Jain <umang.jain@ideasonboard.com>\n> ---\n>   src/ipa/simple/algorithms/awb.cpp |  9 ++++-----\n>   src/ipa/simple/algorithms/lut.cpp | 13 ++++++++-----\n>   src/ipa/simple/ipa_context.h      |  6 +++---\n>   3 files changed, 15 insertions(+), 13 deletions(-)\n>\n> diff --git a/src/ipa/simple/algorithms/awb.cpp b/src/ipa/simple/algorithms/awb.cpp\n> index 3d76cc2f..195de41d 100644\n> --- a/src/ipa/simple/algorithms/awb.cpp\n> +++ b/src/ipa/simple/algorithms/awb.cpp\n> @@ -24,7 +24,7 @@ int Awb::configure(IPAContext &context,\n>   \t\t   [[maybe_unused]] const IPAConfigInfo &configInfo)\n>   {\n>   \tauto &gains = context.activeState.gains;\n> -\tgains.red = gains.green = gains.blue = 256;\n> +\tgains.red = gains.green = gains.blue = 1.0;\n>   \n>   \treturn 0;\n>   }\n> @@ -53,12 +53,11 @@ void Awb::process(IPAContext &context,\n>   \t/*\n>   \t * Calculate red and blue gains for AWB.\n>   \t * Clamp max gain at 4.0, this also avoids 0 division.\n> -\t * Gain: 128 = 0.5, 256 = 1.0, 512 = 2.0, etc.\n>   \t */\n>   \tauto &gains = context.activeState.gains;\n> -\tgains.red = sumR <= sumG / 4 ? 1024 : 256 * sumG / sumR;\n> -\tgains.blue = sumB <= sumG / 4 ? 1024 : 256 * sumG / sumB;\n> -\t/* Green gain is fixed to 256 */\n> +\tgains.red = sumR <= sumG / 4 ? 4.0 : static_cast<double>(sumG) / sumR;\n> +\tgains.blue = sumB <= sumG / 4 ? 4.0 : static_cast<double>(sumG) / sumB;\n> +\t/* Green gain is fixed to 1.0 */\n>   \n>   \tLOG(IPASoftAwb, Debug) << \"gain R/B \" << gains.red << \"/\" << gains.blue;\n>   }\n> diff --git a/src/ipa/simple/algorithms/lut.cpp b/src/ipa/simple/algorithms/lut.cpp\n> index 44e13864..794d3644 100644\n> --- a/src/ipa/simple/algorithms/lut.cpp\n> +++ b/src/ipa/simple/algorithms/lut.cpp\n> @@ -59,15 +59,18 @@ void Lut::prepare(IPAContext &context,\n>   \tauto &gammaTable = context.activeState.gamma.gammaTable;\n>   \tconst unsigned int gammaTableSize = gammaTable.size();\n>   \tfor (unsigned int i = 0; i < DebayerParams::kRGBLookupSize; i++) {\n> -\t\tconst unsigned int div = static_cast<double>(DebayerParams::kRGBLookupSize) *\n> -\t\t\t\t\t 256 / gammaTableSize;\n> +\t\tconst double div = static_cast<double>(DebayerParams::kRGBLookupSize) /\n> +\t\t\t\t   gammaTableSize;\n>   \t\t/* Apply gamma after gain! */\n>   \t\tunsigned int idx;\n> -\t\tidx = std::min({ i * gains.red / div, gammaTableSize - 1 });\n> +\t\tidx = std::min({ static_cast<unsigned int>(i * gains.red / div),\n> +\t\t\t\t gammaTableSize - 1 });\n>   \t\tparams->red[i] = gammaTable[idx];\n> -\t\tidx = std::min({ i * gains.green / div, gammaTableSize - 1 });\n> +\t\tidx = std::min({ static_cast<unsigned int>(i * gains.green / div),\n> +\t\t\t\t gammaTableSize - 1 });\n>   \t\tparams->green[i] = gammaTable[idx];\n> -\t\tidx = std::min({ i * gains.blue / div, gammaTableSize - 1 });\n> +\t\tidx = std::min({ static_cast<unsigned int>(i * gains.blue / div),\n> +\t\t\t\t gammaTableSize - 1 });\n>   \t\tparams->blue[i] = gammaTable[idx];\n>   \t}\n>   }\n> diff --git a/src/ipa/simple/ipa_context.h b/src/ipa/simple/ipa_context.h\n> index 737bbbc3..cf1ef3fd 100644\n> --- a/src/ipa/simple/ipa_context.h\n> +++ b/src/ipa/simple/ipa_context.h\n> @@ -26,9 +26,9 @@ struct IPAActiveState {\n>   \t} blc;\n>   \n>   \tstruct {\n> -\t\tunsigned int red;\n> -\t\tunsigned int green;\n> -\t\tunsigned int blue;\n> +\t\tdouble red;\n> +\t\tdouble green;\n> +\t\tdouble blue;\n>   \t} gains;\n>   \n>   \tstatic constexpr unsigned int kGammaLookupSize = 1024;","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 016FFC0F1B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 26 Sep 2024 19:24:15 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E012B6350F;\n\tThu, 26 Sep 2024 21:24:14 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 5E339618DA\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 26 Sep 2024 21:24:13 +0200 (CEST)","from [IPV6:2405:201:2015:f873:c173:4b:4a04:3a21] (unknown\n\t[IPv6:2405:201:2015:f873:c173:4b:4a04:3a21])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 270F88D4;\n\tThu, 26 Sep 2024 21:22:43 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"Ic6VPe2s\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1727378564;\n\tbh=EekYOzgvx8WS8POwybMlUreG8GB1n0x160NWV9btblk=;\n\th=Date:Subject:To:Cc:References:From:In-Reply-To:From;\n\tb=Ic6VPe2s3U6MzZ2cgHNq5l0+S+35ciQRD9S2kY/vfNLzvCdrlbIkVZG/DQgYms09N\n\tD4eh7TuW/Tlo8emPCoC8ngD68KEO/FM+fuSSXWku2SWRzNokS2cJ/qt4L7UXyU+KP3\n\tZQJ9gdbvQoaC4flKYcj4MZWxviFncDs5QWqi9f/M=","Message-ID":"<253abbf6-0e9f-4b87-b396-7aa36baf7855@ideasonboard.com>","Date":"Fri, 27 Sep 2024 00:54:08 +0530","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH v7 15/18] libcamera: software_isp: Use floating point for\n\tcolor parameters","To":"Milan Zamazal <mzamazal@redhat.com>, libcamera-devel@lists.libcamera.org","Cc":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tDaniel Scally <dan.scally@ideasonboard.com>,\n\tKieran Bingham <kieran.bingham@ideasonboard.com>","References":"<20240920183143.1674117-1-mzamazal@redhat.com>\n\t<20240920183143.1674117-16-mzamazal@redhat.com>","Content-Language":"en-US","From":"Umang Jain <umang.jain@ideasonboard.com>","In-Reply-To":"<20240920183143.1674117-16-mzamazal@redhat.com>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"7bit","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>"}}]