[{"id":38242,"web_url":"https://patchwork.libcamera.org/comment/38242/","msgid":"<20260219115954.GC688396@killaraus.ideasonboard.com>","date":"2026-02-19T11:59:54","subject":"Re: [PATCH v7 12/15] ipa: mali-c55: Convert AWB to UQ<4, 8> usage","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"On Fri, Feb 13, 2026 at 04:57:51PM +0000, Kieran Bingham wrote:\n> Utilise the new FixedPoint type to explicitly calculate gains for AWB in Q4.8\n> format. This ensures that reporting of gains in metadata reflect the true\n> AWB gains applied.\n> \n> Reviewed-by: Isaac Scott <isaac.scott@ideasonboard.com>\n> Reviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\n> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> \n> ---\n> v5:\n> - Use UQ<4, 8> directly\n> - Change debug prints to use operator<<\n> - Now based on top of float types instead of doubles\n> ---\n>  src/ipa/mali-c55/algorithms/awb.cpp | 36 ++++++++++++++++++------------------\n>  src/ipa/mali-c55/ipa_context.h      | 10 ++++++----\n>  2 files changed, 24 insertions(+), 22 deletions(-)\n> \n> diff --git a/src/ipa/mali-c55/algorithms/awb.cpp b/src/ipa/mali-c55/algorithms/awb.cpp\n> index b179dd7f0c1c..a5150bbf3d97 100644\n> --- a/src/ipa/mali-c55/algorithms/awb.cpp\n> +++ b/src/ipa/mali-c55/algorithms/awb.cpp\n> @@ -37,8 +37,8 @@ int Awb::configure([[maybe_unused]] IPAContext &context,\n>  \t * for the first frame we will make no assumptions and leave the R/B\n>  \t * channels unmodified.\n>  \t */\n> -\tcontext.activeState.awb.rGain = 1.0;\n> -\tcontext.activeState.awb.bGain = 1.0;\n> +\tcontext.activeState.awb.rGain = 1.0f;\n> +\tcontext.activeState.awb.bGain = 1.0f;\n>  \n>  \treturn 0;\n>  }\n> @@ -46,8 +46,8 @@ int Awb::configure([[maybe_unused]] IPAContext &context,\n>  void Awb::fillGainsParamBlock(MaliC55Params *params, IPAContext &context,\n>  \t\t\t\tIPAFrameContext &frameContext)\n>  {\n> -\tdouble rGain = context.activeState.awb.rGain;\n> -\tdouble bGain = context.activeState.awb.bGain;\n> +\tUQ<4, 8> rGain = context.activeState.awb.rGain;\n> +\tUQ<4, 8> bGain = context.activeState.awb.bGain;\n>  \n>  \t/*\n>  \t * The gains here map as follows:\n> @@ -61,10 +61,10 @@ void Awb::fillGainsParamBlock(MaliC55Params *params, IPAContext &context,\n>  \t */\n>  \tauto block = params->block<MaliC55Blocks::AwbGains>();\n>  \n> -\tblock->gain00 = floatingToFixedPoint<4, 8, uint16_t, double>(rGain);\n> -\tblock->gain01 = floatingToFixedPoint<4, 8, uint16_t, double>(1.0);\n> -\tblock->gain10 = floatingToFixedPoint<4, 8, uint16_t, double>(1.0);\n> -\tblock->gain11 = floatingToFixedPoint<4, 8, uint16_t, double>(bGain);\n> +\tblock->gain00 = rGain.quantized();\n> +\tblock->gain01 = UQ<4, 8>(1.0f).quantized();\n> +\tblock->gain10 = UQ<4, 8>(1.0f).quantized();\n> +\tblock->gain11 = bGain.quantized();\n>  \n>  \tframeContext.awb.rGain = rGain;\n>  \tframeContext.awb.bGain = bGain;\n> @@ -140,18 +140,18 @@ void Awb::process(IPAContext &context, const uint32_t frame,\n>  \t * gain figures that we can apply to approximate a grey world.\n>  \t */\n>  \tunsigned int counted_zones = 0;\n> -\tdouble rgSum = 0, bgSum = 0;\n> +\tfloat rgSum = 0, bgSum = 0;\n>  \n>  \tfor (unsigned int i = 0; i < 225; i++) {\n>  \t\tif (!awb_ratios[i].num_pixels)\n>  \t\t\tcontinue;\n>  \n>  \t\t/*\n> -\t\t * The statistics are in Q4.8 format, so we convert to double\n> +\t\t * The statistics are in Q4.8 format, so we convert to float\n>  \t\t * here.\n>  \t\t */\n> -\t\trgSum += fixedToFloatingPoint<4, 8, double, uint16_t>(awb_ratios[i].avg_rg_gr);\n> -\t\tbgSum += fixedToFloatingPoint<4, 8, double, uint16_t>(awb_ratios[i].avg_bg_br);\n> +\t\trgSum += UQ<4, 8>(awb_ratios[i].avg_rg_gr).value();\n> +\t\tbgSum += UQ<4, 8>(awb_ratios[i].avg_bg_br).value();\n>  \t\tcounted_zones++;\n>  \t}\n>  \n> @@ -174,8 +174,8 @@ void Awb::process(IPAContext &context, const uint32_t frame,\n>  \t * figure by the gains that were applied when the statistics for this\n>  \t * frame were generated.\n>  \t */\n> -\tfloat rRatio = rgAvg / frameContext.awb.rGain;\n> -\tfloat bRatio = bgAvg / frameContext.awb.bGain;\n> +\tfloat rRatio = rgAvg / frameContext.awb.rGain.value();\n> +\tfloat bRatio = bgAvg / frameContext.awb.bGain.value();\n>  \n>  \t/*\n>  \t * And then we can simply invert the ratio to find the gain we should\n> @@ -191,15 +191,15 @@ void Awb::process(IPAContext &context, const uint32_t frame,\n>  \t * want to fix the miscolouring as quickly as possible.\n>  \t */\n>  \tfloat speed = frame < kNumStartupFrames ? 1.0 : 0.2;\n\nWhile at it,\n\ns/1.0/1.0f/\ns/0.2/0.2f/\n\n> -\trGain = speed * rGain + context.activeState.awb.rGain * (1.0 - speed);\n> -\tbGain = speed * bGain + context.activeState.awb.bGain * (1.0 - speed);\n> +\trGain = speed * rGain + context.activeState.awb.rGain.value() * (1.0 - speed);\n> +\tbGain = speed * bGain + context.activeState.awb.bGain.value() * (1.0 - speed);\n\ns/1.0/1.0f/\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n>  \n>  \tcontext.activeState.awb.rGain = rGain;\n>  \tcontext.activeState.awb.bGain = bGain;\n>  \n>  \tmetadata.set(controls::ColourGains, {\n> -\t\tstatic_cast<float>(frameContext.awb.rGain),\n> -\t\tstatic_cast<float>(frameContext.awb.bGain),\n> +\t\tframeContext.awb.rGain.value(),\n> +\t\tframeContext.awb.bGain.value(),\n>  \t});\n>  \n>  \tLOG(MaliC55Awb, Debug) << \"For frame number \" << frame << \": \"\n> diff --git a/src/ipa/mali-c55/ipa_context.h b/src/ipa/mali-c55/ipa_context.h\n> index 13885eb83b5c..08f78e4f74ce 100644\n> --- a/src/ipa/mali-c55/ipa_context.h\n> +++ b/src/ipa/mali-c55/ipa_context.h\n> @@ -14,6 +14,8 @@\n>  \n>  #include <libipa/fc_queue.h>\n>  \n> +#include \"libipa/fixedpoint.h\"\n> +\n>  namespace libcamera {\n>  \n>  namespace ipa::mali_c55 {\n> @@ -53,8 +55,8 @@ struct IPAActiveState {\n>  \t} agc;\n>  \n>  \tstruct {\n> -\t\tdouble rGain;\n> -\t\tdouble bGain;\n> +\t\tUQ<4, 8> rGain;\n> +\t\tUQ<4, 8> bGain;\n>  \t} awb;\n>  };\n>  \n> @@ -66,8 +68,8 @@ struct IPAFrameContext : public FrameContext {\n>  \t} agc;\n>  \n>  \tstruct {\n> -\t\tdouble rGain;\n> -\t\tdouble bGain;\n> +\t\tUQ<4, 8> rGain;\n> +\t\tUQ<4, 8> bGain;\n>  \t} awb;\n>  };\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 9E99EC31E9\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 19 Feb 2026 12:00:00 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id A4B3F6223F;\n\tThu, 19 Feb 2026 12:59:59 +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 4EC88620C9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 19 Feb 2026 12:59:58 +0100 (CET)","from killaraus.ideasonboard.com (unknown [83.245.237.175])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id DE48B673;\n\tThu, 19 Feb 2026 12:59:04 +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=\"DItgEalx\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1771502345;\n\tbh=iBlX2DTg55RzzLUEs35Im1HJK5oTFNHUkOfJehTNO4M=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=DItgEalxJ+EaQeMeYaLrM7utlblZkS7t2RB7FY4Yrb/p+ItKpN7TdhPELonXatsmV\n\t1LRCxi3F01niyEm8mk/TZ49y5VlYvnNCzbiTZKeC/O5Yo31MTkmChirMN3+GAaDZiD\n\tlzf8AYIyi8WlsIotaFCPWG/78Ffd9R0wdfEfpTcM=","Date":"Thu, 19 Feb 2026 12:59:54 +0100","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org, Isaac Scott\n\t<isaac.scott@ideasonboard.com>, =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?=\n\t<barnabas.pocze@ideasonboard.com>","Subject":"Re: [PATCH v7 12/15] ipa: mali-c55: Convert AWB to UQ<4, 8> usage","Message-ID":"<20260219115954.GC688396@killaraus.ideasonboard.com>","References":"<20260213-kbingham-quantizers-v7-0-1626b9aaabf1@ideasonboard.com>\n\t<20260213-kbingham-quantizers-v7-12-1626b9aaabf1@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20260213-kbingham-quantizers-v7-12-1626b9aaabf1@ideasonboard.com>","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>"}}]