[{"id":37672,"web_url":"https://patchwork.libcamera.org/comment/37672/","msgid":"<f8382c6f-d346-4624-b9f6-a32914666896@ideasonboard.com>","date":"2026-01-15T10:44:00","subject":"Re: [PATCH v5 11/16] ipa: mali-c55: Reduce AWB calculations to float\n\tprecision","submitter":{"id":216,"url":"https://patchwork.libcamera.org/api/people/216/","name":"Barnabás Pőcze","email":"barnabas.pocze@ideasonboard.com"},"content":"2026. 01. 14. 18:39 keltezéssel, Kieran Bingham írta:\n> The AWB calculations are determined using double precision, and then\n> will be soon stored in a quantized float.\n> \n> Use float types for the intermediate types after the sums have been\n> converted to an average to remove static cast assignments.\n> \n> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> \n> ---\n> v5:\n>   - New in v5\n> \n> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> ---\n>   src/ipa/mali-c55/algorithms/awb.cpp | 12 ++++++------\n>   1 file changed, 6 insertions(+), 6 deletions(-)\n> \n> diff --git a/src/ipa/mali-c55/algorithms/awb.cpp b/src/ipa/mali-c55/algorithms/awb.cpp\n> index 964e810882a9..b179dd7f0c1c 100644\n> --- a/src/ipa/mali-c55/algorithms/awb.cpp\n> +++ b/src/ipa/mali-c55/algorithms/awb.cpp\n> @@ -159,7 +159,7 @@ void Awb::process(IPAContext &context, const uint32_t frame,\n\nWhy not convert `{rg,bg}Sum` as well? There are only 225 zones,\nso the sum should fit a `float`, no?\n\n\n>   \t * Sometimes the first frame's statistics have no valid pixels, in which\n>   \t * case we'll just assume a grey world until they say otherwise.\n>   \t */\n> -\tdouble rgAvg, bgAvg;\n> +\tfloat rgAvg, bgAvg;\n>   \tif (!counted_zones) {\n>   \t\trgAvg = 1.0;\n>   \t\tbgAvg = 1.0;\n> @@ -174,15 +174,15 @@ 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> -\tdouble rRatio = rgAvg / frameContext.awb.rGain;\n> -\tdouble bRatio = bgAvg / frameContext.awb.bGain;\n> +\tfloat rRatio = rgAvg / frameContext.awb.rGain;\n> +\tfloat bRatio = bgAvg / frameContext.awb.bGain;\n>   \n>   \t/*\n>   \t * And then we can simply invert the ratio to find the gain we should\n>   \t * apply.\n>   \t */\n> -\tdouble rGain = 1 / rRatio;\n> -\tdouble bGain = 1 / bRatio;\n> +\tfloat rGain = 1 / rRatio;\n> +\tfloat bGain = 1 / bRatio;\n>   \n>   \t/*\n>   \t * Running at full speed, this algorithm results in oscillations in the\n> @@ -190,7 +190,7 @@ void Awb::process(IPAContext &context, const uint32_t frame,\n>   \t * changes in gain, unless we're in the startup phase in which case we\n>   \t * want to fix the miscolouring as quickly as possible.\n>   \t */\n> -\tdouble speed = frame < kNumStartupFrames ? 1.0 : 0.2;\n> +\tfloat speed = frame < kNumStartupFrames ? 1.0 : 0.2;\n>   \trGain = speed * rGain + context.activeState.awb.rGain * (1.0 - speed);\n>   \tbGain = speed * bGain + context.activeState.awb.bGain * (1.0 - speed);\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 6926EC3226\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 15 Jan 2026 10:44:07 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2EB2561FBC;\n\tThu, 15 Jan 2026 11:44:06 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id C8F8661F61\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 15 Jan 2026 11:44:04 +0100 (CET)","from [192.168.33.20] (185.221.143.114.nat.pool.zt.hu\n\t[185.221.143.114])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 4DFC34E1;\n\tThu, 15 Jan 2026 11:43:37 +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=\"vlrmB0Xl\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1768473817;\n\tbh=z7zO3H7J1RNXea8qEnGeEn0llS+rDH9RrfjSV2leW0E=;\n\th=Date:Subject:To:References:From:In-Reply-To:From;\n\tb=vlrmB0XlT3B7AJdtiXfVPlAvd7sKaouw2YIcPZNpEhfBh/FtHrLfqIdDaOGHFOPCG\n\tvObnyDakEk1viL4TifIjJDht6aM/DynCub6d2nfbXvk0hAwcVqMqh6hlTDE/xnKgoQ\n\tz7iLn0mWJzrZLVwkk2SFaDFLSLpOgWB3KPdbZDk0=","Message-ID":"<f8382c6f-d346-4624-b9f6-a32914666896@ideasonboard.com>","Date":"Thu, 15 Jan 2026 11:44:00 +0100","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH v5 11/16] ipa: mali-c55: Reduce AWB calculations to float\n\tprecision","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>,\n\tlibcamera devel <libcamera-devel@lists.libcamera.org>","References":"<20260114173918.1744023-1-kieran.bingham@ideasonboard.com>\n\t<20260114173918.1744023-12-kieran.bingham@ideasonboard.com>","From":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","Content-Language":"en-US, hu-HU","In-Reply-To":"<20260114173918.1744023-12-kieran.bingham@ideasonboard.com>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"8bit","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>"}},{"id":37814,"web_url":"https://patchwork.libcamera.org/comment/37814/","msgid":"<176901314727.1693075.3831981148860377667@ping.linuxembedded.co.uk>","date":"2026-01-21T16:32:27","subject":"Re: [PATCH v5 11/16] ipa: mali-c55: Reduce AWB calculations to float\n\tprecision","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Barnabás Pőcze (2026-01-15 10:44:00)\n> 2026. 01. 14. 18:39 keltezéssel, Kieran Bingham írta:\n> > The AWB calculations are determined using double precision, and then\n> > will be soon stored in a quantized float.\n> > \n> > Use float types for the intermediate types after the sums have been\n> > converted to an average to remove static cast assignments.\n> > \n> > Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> > \n> > ---\n> > v5:\n> >   - New in v5\n> > \n> > Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> > ---\n> >   src/ipa/mali-c55/algorithms/awb.cpp | 12 ++++++------\n> >   1 file changed, 6 insertions(+), 6 deletions(-)\n> > \n> > diff --git a/src/ipa/mali-c55/algorithms/awb.cpp b/src/ipa/mali-c55/algorithms/awb.cpp\n> > index 964e810882a9..b179dd7f0c1c 100644\n> > --- a/src/ipa/mali-c55/algorithms/awb.cpp\n> > +++ b/src/ipa/mali-c55/algorithms/awb.cpp\n> > @@ -159,7 +159,7 @@ void Awb::process(IPAContext &context, const uint32_t frame,\n> \n> Why not convert `{rg,bg}Sum` as well? There are only 225 zones,\n> so the sum should fit a `float`, no?\n\nYes, I think we could do fixed point arithmetic in the future too\nallowing the UQ<4, 8> to accumulate into a UQ<8, 8> for instance without\nlosing any precision.\n\nBut I've taken this in for now to keep it consistent.\n\n--\nKieran\n\n> \n> \n> >        * Sometimes the first frame's statistics have no valid pixels, in which\n> >        * case we'll just assume a grey world until they say otherwise.\n> >        */\n> > -     double rgAvg, bgAvg;\n> > +     float rgAvg, bgAvg;\n> >       if (!counted_zones) {\n> >               rgAvg = 1.0;\n> >               bgAvg = 1.0;\n> > @@ -174,15 +174,15 @@ void Awb::process(IPAContext &context, const uint32_t frame,\n> >        * figure by the gains that were applied when the statistics for this\n> >        * frame were generated.\n> >        */\n> > -     double rRatio = rgAvg / frameContext.awb.rGain;\n> > -     double bRatio = bgAvg / frameContext.awb.bGain;\n> > +     float rRatio = rgAvg / frameContext.awb.rGain;\n> > +     float bRatio = bgAvg / frameContext.awb.bGain;\n> >   \n> >       /*\n> >        * And then we can simply invert the ratio to find the gain we should\n> >        * apply.\n> >        */\n> > -     double rGain = 1 / rRatio;\n> > -     double bGain = 1 / bRatio;\n> > +     float rGain = 1 / rRatio;\n> > +     float bGain = 1 / bRatio;\n> >   \n> >       /*\n> >        * Running at full speed, this algorithm results in oscillations in the\n> > @@ -190,7 +190,7 @@ void Awb::process(IPAContext &context, const uint32_t frame,\n> >        * changes in gain, unless we're in the startup phase in which case we\n> >        * want to fix the miscolouring as quickly as possible.\n> >        */\n> > -     double speed = frame < kNumStartupFrames ? 1.0 : 0.2;\n> > +     float speed = frame < kNumStartupFrames ? 1.0 : 0.2;\n> >       rGain = speed * rGain + context.activeState.awb.rGain * (1.0 - speed);\n> >       bGain = speed * bGain + context.activeState.awb.bGain * (1.0 - speed);\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 E2E1EBDCBF\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 21 Jan 2026 16:32:32 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 9440D61FC9;\n\tWed, 21 Jan 2026 17:32:32 +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 4CAB161F9F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 21 Jan 2026 17:32:30 +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 61EB31C6;\n\tWed, 21 Jan 2026 17:31:58 +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=\"o+M5QldC\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1769013118;\n\tbh=3yQLzuy/ciEqU5KKJE4oEcsxG3OZriCed4Bs9/cdPA8=;\n\th=In-Reply-To:References:Subject:From:To:Date:From;\n\tb=o+M5QldCOov88yDyrcW71Ft2BDn/bX7lGXn8Gev623xaQ3XPgrRGD+yKIpp/XJjAX\n\tQpD7fsmL4tl5FjBMK4vYteBqk1FAwATPVOvju5kVSj12bAFjPgPWefPJFDl1ikOuEQ\n\tbkK/a3rh77maQNGp75VcKgriWe9NbCnI0q7Eu0sY=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<f8382c6f-d346-4624-b9f6-a32914666896@ideasonboard.com>","References":"<20260114173918.1744023-1-kieran.bingham@ideasonboard.com>\n\t<20260114173918.1744023-12-kieran.bingham@ideasonboard.com>\n\t<f8382c6f-d346-4624-b9f6-a32914666896@ideasonboard.com>","Subject":"Re: [PATCH v5 11/16] ipa: mali-c55: Reduce AWB calculations to float\n\tprecision","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","To":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>,\n\tlibcamera devel <libcamera-devel@lists.libcamera.org>","Date":"Wed, 21 Jan 2026 16:32:27 +0000","Message-ID":"<176901314727.1693075.3831981148860377667@ping.linuxembedded.co.uk>","User-Agent":"alot/0.9.1","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>"}}]