[{"id":25045,"web_url":"https://patchwork.libcamera.org/comment/25045/","msgid":"<166371771557.18961.7288172187170992369@Monstersaurus>","date":"2022-09-20T23:48:35","subject":"Re: [libcamera-devel] [PATCH v4 32/32] ipa: rkisp1: awb: Remove\n\tbias from gain calculation","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Laurent Pinchart via libcamera-devel (2022-09-08 02:42:00)\n> The red and blue gains are computed by dividing the green mean by the\n> red and blue means respectively. An offset of 1 is added to the dividers\n> to avoid divisions by zero. This introduces a bias in the gain values.\n> Fix it by clamping the divisors to a minimum of 1.0 instead of adding an\n> offset.\n> \n\nSounds resonable. That 'hardcoded green gain of 0' is there, which\ndoesn't make sense to me, but I've questioned that in an earlier patch.\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> ---\n>  src/ipa/rkisp1/algorithms/awb.cpp | 7 ++++---\n>  1 file changed, 4 insertions(+), 3 deletions(-)\n> \n> diff --git a/src/ipa/rkisp1/algorithms/awb.cpp b/src/ipa/rkisp1/algorithms/awb.cpp\n> index 404ad66e6953..fe1ba09a99a2 100644\n> --- a/src/ipa/rkisp1/algorithms/awb.cpp\n> +++ b/src/ipa/rkisp1/algorithms/awb.cpp\n> @@ -280,10 +280,11 @@ void Awb::process(IPAContext &context,\n>  \n>         /*\n>          * Estimate the red and blue gains to apply in a grey world. The green\n> -        * gain is hardcoded to 0.\n> +        * gain is hardcoded to 0. Avoid divisions by zero by clamping the\n> +        * divisor to a minimum value of 1.0.\n>          */\n> -       double redGain = greenMean / (redMean + 1);\n> -       double blueGain = greenMean / (blueMean + 1);\n> +       double redGain = greenMean / std::max(redMean, 1.0);\n> +       double blueGain = greenMean / std::max(blueMean, 1.0);\n>  \n>         /*\n>          * Clamp the gain values to the hardware, which expresses gains as Q2.8\n> -- \n> Regards,\n> \n> Laurent Pinchart\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 33362C0DA4\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 20 Sep 2022 23:48:42 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 7B70A621DA;\n\tWed, 21 Sep 2022 01:48:41 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 157A961F7D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 21 Sep 2022 01:48:39 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 8A493415;\n\tWed, 21 Sep 2022 01:48:38 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1663717721;\n\tbh=cdFvjU90L2mKFl/spdHlU1YvhxDK6skhEUntRskCqp8=;\n\th=In-Reply-To:References:To:Date:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=VaWfUFssauHriiEsXjEdfgklhv71EMn0W418ClQIEsKYyx3TOHzrWdLIKgpzKctNc\n\tTfzSYcn8C2ohURxDJ9QsckzTY2b0X5W3JZHvhzl+xehXKp8+rG4s3V52/xVK9pFUfY\n\twg/WqwDRkpY6ep+6Pwm1sPha0C+ywCZTQT9wO02HE2dY6Td4gh/e5BshnrtM09CNGo\n\thebnlO+6161rYrdEOlveyoFGblI7zWySy2CPusLC+zBMZGHPsYUuyBqLQfacZL+Qw8\n\t8ig9b7N4cUqsIPqAwL8nwt4pslBLDusg8ZzFaSL5Ibi/Owad3KcSsEp8+ZO+/1EUox\n\txBT3OnnOpsqfw==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1663717718;\n\tbh=cdFvjU90L2mKFl/spdHlU1YvhxDK6skhEUntRskCqp8=;\n\th=In-Reply-To:References:Subject:From:To:Date:From;\n\tb=VWO9EcEnSAIkaxsa4PdKpFVoJcndXQ2PVgl/qh4NuT3YbCaY0zKWxP6SALFb+ryNZ\n\tnSVCVvAzb2OGm0hY+p9xGRvSyKScWbe7KhaPVt5ev7qKJlbeRGeBAYMhxXtzG0+9SU\n\tar9FTT8Dbp/o6LOQeJrNTAnvHlobn3VTcyRHPSZY="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"VWO9EcEn\"; dkim-atps=neutral","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20220908014200.28728-33-laurent.pinchart@ideasonboard.com>","References":"<20220908014200.28728-1-laurent.pinchart@ideasonboard.com>\n\t<20220908014200.28728-33-laurent.pinchart@ideasonboard.com>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Wed, 21 Sep 2022 00:48:35 +0100","Message-ID":"<166371771557.18961.7288172187170992369@Monstersaurus>","User-Agent":"alot/0.10","Subject":"Re: [libcamera-devel] [PATCH v4 32/32] ipa: rkisp1: awb: Remove\n\tbias from gain calculation","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>","From":"Kieran Bingham via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":25082,"web_url":"https://patchwork.libcamera.org/comment/25082/","msgid":"<20220922105148.pun4srwznro24c3s@uno.localdomain>","date":"2022-09-22T10:51:48","subject":"Re: [libcamera-devel] [PATCH v4 32/32] ipa: rkisp1: awb: Remove\n\tbias from gain calculation","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"On Thu, Sep 08, 2022 at 04:42:00AM +0300, Laurent Pinchart via libcamera-devel wrote:\n> The red and blue gains are computed by dividing the green mean by the\n> red and blue means respectively. An offset of 1 is added to the dividers\n> to avoid divisions by zero. This introduces a bias in the gain values.\n> Fix it by clamping the divisors to a minimum of 1.0 instead of adding an\n> offset.\n>\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> ---\n>  src/ipa/rkisp1/algorithms/awb.cpp | 7 ++++---\n>  1 file changed, 4 insertions(+), 3 deletions(-)\n>\n> diff --git a/src/ipa/rkisp1/algorithms/awb.cpp b/src/ipa/rkisp1/algorithms/awb.cpp\n> index 404ad66e6953..fe1ba09a99a2 100644\n> --- a/src/ipa/rkisp1/algorithms/awb.cpp\n> +++ b/src/ipa/rkisp1/algorithms/awb.cpp\n> @@ -280,10 +280,11 @@ void Awb::process(IPAContext &context,\n>\n>  \t/*\n>  \t * Estimate the red and blue gains to apply in a grey world. The green\n> -\t * gain is hardcoded to 0.\n> +\t * gain is hardcoded to 0. Avoid divisions by zero by clamping the\n> +\t * divisor to a minimum value of 1.0.\n>  \t */\n> -\tdouble redGain = greenMean / (redMean + 1);\n> -\tdouble blueGain = greenMean / (blueMean + 1);\n> +\tdouble redGain = greenMean / std::max(redMean, 1.0);\n> +\tdouble blueGain = greenMean / std::max(blueMean, 1.0);\n\nDumb question, do we care about divisors in the ]0.0, 1.0[ range ?\n\n>\n>  \t/*\n>  \t * Clamp the gain values to the hardware, which expresses gains as Q2.8\n> --\n> Regards,\n>\n> Laurent Pinchart\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 59A2DBD16B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 22 Sep 2022 10:51:52 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 8D29D6220B;\n\tThu, 22 Sep 2022 12:51:51 +0200 (CEST)","from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net\n\t[IPv6:2001:4b98:dc4:8::223])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id A77AC6219A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 22 Sep 2022 12:51:50 +0200 (CEST)","(Authenticated sender: jacopo@jmondi.org)\n\tby mail.gandi.net (Postfix) with ESMTPSA id DDA6760007;\n\tThu, 22 Sep 2022 10:51:49 +0000 (UTC)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1663843911;\n\tbh=YM45XN78mue2764uX4aYieOdgrrOYfh1kY0CAdLo7iU=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=o3Zmg56OZ7Ax2taEnXFm7Vq4eW11An18Ocw38YDnLIRWAsw6BzvEdyP+31edKKamd\n\tY9PQtPgIXbFjXIGmz4T0is5kBM6ptI2Uk4VRlJ+j/46WP955a+yNzDRnh4tLkMpgNw\n\tJUOjNwQa/vMuTSi6f9SYS5cbTwCSDhu1bTN5XhhWrgC0Bp3rpUkQIATMffVGLl7upt\n\tbsQ4o5laZgKUPqJ8j9Zz5ZR1ZtQLSr5saUOnjP9WcM1H6wcGeHKZ39uJvoPoEt+beu\n\tKBC6LHhb0lO22Yytrk83vMkJZGc9aqBTPGSs+mmy36Q/528rUsh/rXCLZrwH5BhP2O\n\tPOnZjc3ubeN6A==","Date":"Thu, 22 Sep 2022 12:51:48 +0200","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Message-ID":"<20220922105148.pun4srwznro24c3s@uno.localdomain>","References":"<20220908014200.28728-1-laurent.pinchart@ideasonboard.com>\n\t<20220908014200.28728-33-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20220908014200.28728-33-laurent.pinchart@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v4 32/32] ipa: rkisp1: awb: Remove\n\tbias from gain calculation","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>","From":"Jacopo Mondi via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"Jacopo Mondi <jacopo@jmondi.org>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":25105,"web_url":"https://patchwork.libcamera.org/comment/25105/","msgid":"<YyzvCXUkiMxJrG1G@pendragon.ideasonboard.com>","date":"2022-09-22T23:26:01","subject":"Re: [libcamera-devel] [PATCH v4 32/32] ipa: rkisp1: awb: Remove\n\tbias from gain calculation","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"On Wed, Sep 21, 2022 at 12:48:35AM +0100, Kieran Bingham wrote:\n> Quoting Laurent Pinchart via libcamera-devel (2022-09-08 02:42:00)\n> > The red and blue gains are computed by dividing the green mean by the\n> > red and blue means respectively. An offset of 1 is added to the dividers\n> > to avoid divisions by zero. This introduces a bias in the gain values.\n> > Fix it by clamping the divisors to a minimum of 1.0 instead of adding an\n> > offset.\n> \n> Sounds resonable. That 'hardcoded green gain of 0' is there, which\n> doesn't make sense to me, but I've questioned that in an earlier patch.\n\nI meant 1.0, not 0. I've fixed it.\n\n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> \n> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> > ---\n> >  src/ipa/rkisp1/algorithms/awb.cpp | 7 ++++---\n> >  1 file changed, 4 insertions(+), 3 deletions(-)\n> > \n> > diff --git a/src/ipa/rkisp1/algorithms/awb.cpp b/src/ipa/rkisp1/algorithms/awb.cpp\n> > index 404ad66e6953..fe1ba09a99a2 100644\n> > --- a/src/ipa/rkisp1/algorithms/awb.cpp\n> > +++ b/src/ipa/rkisp1/algorithms/awb.cpp\n> > @@ -280,10 +280,11 @@ void Awb::process(IPAContext &context,\n> >  \n> >         /*\n> >          * Estimate the red and blue gains to apply in a grey world. The green\n> > -        * gain is hardcoded to 0.\n> > +        * gain is hardcoded to 0. Avoid divisions by zero by clamping the\n> > +        * divisor to a minimum value of 1.0.\n> >          */\n> > -       double redGain = greenMean / (redMean + 1);\n> > -       double blueGain = greenMean / (blueMean + 1);\n> > +       double redGain = greenMean / std::max(redMean, 1.0);\n> > +       double blueGain = greenMean / std::max(blueMean, 1.0);\n> >  \n> >         /*\n> >          * Clamp the gain values to the hardware, which expresses gains as Q2.8","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 44BC0C0DA4\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 22 Sep 2022 23:26:19 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 9C91962226;\n\tFri, 23 Sep 2022 01:26:18 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 27EE361F7B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 23 Sep 2022 01:26:17 +0200 (CEST)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 4A4784F7;\n\tFri, 23 Sep 2022 01:26:16 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1663889178;\n\tbh=gVldr9R5WHgUNYljfSDJSzjvGfnDb2uXeOyWFNcRXW4=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=BQ3VAngzYVQlE5qDQH2fCP6AfqWBy/hZWJAiLm2B+Z6iVvmjqfaPIkrggFF5GssQ3\n\t7kPMltki+Ka3U4K7B3epj9vSDz+UXGu0jejVCnleaWXv5/Z8OwE3awJEc685cFeSlG\n\tBt9VROMSdAXyh45OnzrB8MO1F0bd1xB63L+VAGQZKXBcYDRzDt7hqBJd8m5k60vyIR\n\ttHxG09rbpuaLh2/Cxw2Xr0g8RalklQe+lzhl54/OKnzal0vu6opoYnU1LWjlb3QNNs\n\tlpsq54Z+iqrYWS1w+dp7K0bbHJ5WietYvUeZ7mEuCHAu7PuvrEXJ7i7phWNHK+/zzi\n\tEMH+HXfDVZ4pw==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1663889176;\n\tbh=gVldr9R5WHgUNYljfSDJSzjvGfnDb2uXeOyWFNcRXW4=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=DUkGKV3/QlwVkHTrWeYQRdyO7oWFjRmsU/Plxnw+HnaMSb+GwbU1Gi6vCxcHcmv0t\n\teB4f1tgj4Sg4NFLsI/8389LVS0pxE/IQxqrDn7C/gacn3CHMDXQ274P4Joxu2fQvvE\n\tNecRSFj8DQ/CK3U2i2E/8Pln2xSG4+fJ0hFTxa0k="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"DUkGKV3/\"; dkim-atps=neutral","Date":"Fri, 23 Sep 2022 02:26:01 +0300","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Message-ID":"<YyzvCXUkiMxJrG1G@pendragon.ideasonboard.com>","References":"<20220908014200.28728-1-laurent.pinchart@ideasonboard.com>\n\t<20220908014200.28728-33-laurent.pinchart@ideasonboard.com>\n\t<166371771557.18961.7288172187170992369@Monstersaurus>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<166371771557.18961.7288172187170992369@Monstersaurus>","Subject":"Re: [libcamera-devel] [PATCH v4 32/32] ipa: rkisp1: awb: Remove\n\tbias from gain calculation","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>","From":"Laurent Pinchart via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":25106,"web_url":"https://patchwork.libcamera.org/comment/25106/","msgid":"<YyzvxAHkvNdBL2Ng@pendragon.ideasonboard.com>","date":"2022-09-22T23:29:08","subject":"Re: [libcamera-devel] [PATCH v4 32/32] ipa: rkisp1: awb: Remove\n\tbias from gain calculation","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Jacopo,\n\nOn Thu, Sep 22, 2022 at 12:51:48PM +0200, Jacopo Mondi wrote:\n> On Thu, Sep 08, 2022 at 04:42:00AM +0300, Laurent Pinchart via libcamera-devel wrote:\n> > The red and blue gains are computed by dividing the green mean by the\n> > red and blue means respectively. An offset of 1 is added to the dividers\n> > to avoid divisions by zero. This introduces a bias in the gain values.\n> > Fix it by clamping the divisors to a minimum of 1.0 instead of adding an\n> > offset.\n> >\n> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> > ---\n> >  src/ipa/rkisp1/algorithms/awb.cpp | 7 ++++---\n> >  1 file changed, 4 insertions(+), 3 deletions(-)\n> >\n> > diff --git a/src/ipa/rkisp1/algorithms/awb.cpp b/src/ipa/rkisp1/algorithms/awb.cpp\n> > index 404ad66e6953..fe1ba09a99a2 100644\n> > --- a/src/ipa/rkisp1/algorithms/awb.cpp\n> > +++ b/src/ipa/rkisp1/algorithms/awb.cpp\n> > @@ -280,10 +280,11 @@ void Awb::process(IPAContext &context,\n> >\n> >  \t/*\n> >  \t * Estimate the red and blue gains to apply in a grey world. The green\n> > -\t * gain is hardcoded to 0.\n> > +\t * gain is hardcoded to 0. Avoid divisions by zero by clamping the\n> > +\t * divisor to a minimum value of 1.0.\n> >  \t */\n> > -\tdouble redGain = greenMean / (redMean + 1);\n> > -\tdouble blueGain = greenMean / (blueMean + 1);\n> > +\tdouble redGain = greenMean / std::max(redMean, 1.0);\n> > +\tdouble blueGain = greenMean / std::max(blueMean, 1.0);\n> \n> Dumb question, do we care about divisors in the ]0.0, 1.0[ range ?\n\nGiven that the range for the mean values is [0, 255] and that we freeze\nAWB when the means are below 2.0, we don't.\n\nI wrote this patch before adding the thresholds, the std::max isn't\nstrictly needed anymore, but I feel safer keeping it in case we change\nthe threshold mechanism later.\n\n> >\n> >  \t/*\n> >  \t * Clamp the gain values to the hardware, which expresses gains as Q2.8","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 203F5BD16B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 22 Sep 2022 23:29:27 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 586DD62228;\n\tFri, 23 Sep 2022 01:29:26 +0200 (CEST)","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 BEF6D61F7B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 23 Sep 2022 01:29:24 +0200 (CEST)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id ECFEE4F7;\n\tFri, 23 Sep 2022 01:29:23 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1663889366;\n\tbh=BMFDKPFTWSVBJNpkpQWH86T+/qUSdA3+EH4m5A0eKsc=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=MOJrR4zQHtGMq7k7sdYnar6VBtxgemZKiMjCFhrCZJyB8LFPQ+YAErZrZSdKlakhS\n\tYUj9PVZ0jqfUKzQGvZN70HgwlMuJztj+v36Rxi4IRMRPDSNw+NYDd4L280LNWikLo7\n\tN2Kac4u7EtiA82ae9oXqwVeHWSxMzIBdXb6a8yH+FA3RJVn8ePTzvQF04am7f6ab1K\n\txXHD6E3D71LzMS/KB7p9BOEZ2YFMw0f3IfcgIp9pqjoSZtyDaA7ABn7Im5QB3uxkOe\n\t8SHSDtMx8KwtE9mS4Q5ZTHdTbI2vJCR2ToJ5V+PVeuFmGOU+fgvV+1VZOLOf888RjQ\n\tG0olwhwaHPNUw==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1663889364;\n\tbh=BMFDKPFTWSVBJNpkpQWH86T+/qUSdA3+EH4m5A0eKsc=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=OZJTh1v9/IDMo8mAYTZRM9Y2SGlecrRYqdxPkb6lcEbsX7X/6sSnhdzOpcxi8toMf\n\tKdTQd48Ol6m8DWH/Ip3UyF9tigOy6d2dkNz6ofRFcBCHYUT7Dr25rhKMZAi7NnWxQK\n\tkVX70ojPExd3b2Na79KoorO99Fme6EnY+mw8JnQw="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"OZJTh1v9\"; dkim-atps=neutral","Date":"Fri, 23 Sep 2022 02:29:08 +0300","To":"Jacopo Mondi <jacopo@jmondi.org>","Message-ID":"<YyzvxAHkvNdBL2Ng@pendragon.ideasonboard.com>","References":"<20220908014200.28728-1-laurent.pinchart@ideasonboard.com>\n\t<20220908014200.28728-33-laurent.pinchart@ideasonboard.com>\n\t<20220922105148.pun4srwznro24c3s@uno.localdomain>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20220922105148.pun4srwznro24c3s@uno.localdomain>","Subject":"Re: [libcamera-devel] [PATCH v4 32/32] ipa: rkisp1: awb: Remove\n\tbias from gain calculation","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>","From":"Laurent Pinchart via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]