[{"id":35317,"web_url":"https://patchwork.libcamera.org/comment/35317/","msgid":"<175467513658.560048.819883406628432547@ping.linuxembedded.co.uk>","date":"2025-08-08T17:45:36","subject":"Re: [PATCH v2 03/16] libipa: camera_sensor_helper: Add\n\tquantizeGain() function","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Stefan Klug (2025-08-08 15:12:41)\n> Add a small utility function that calculates the quantized gain that\n> gets applied by a sensor when the gain code is set to gainCode(gain).\n> This is needed by algorithms to calculate a digital correction gain that\n> gets applied to mitigate the error introduce by quantization.\n> \n> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n> ---\n>  src/ipa/libipa/camera_sensor_helper.cpp | 23 +++++++++++++++++++++++\n>  src/ipa/libipa/camera_sensor_helper.h   |  1 +\n>  2 files changed, 24 insertions(+)\n> \n> diff --git a/src/ipa/libipa/camera_sensor_helper.cpp b/src/ipa/libipa/camera_sensor_helper.cpp\n> index dcd69d9f2bbb..0a7b66cd003a 100644\n> --- a/src/ipa/libipa/camera_sensor_helper.cpp\n> +++ b/src/ipa/libipa/camera_sensor_helper.cpp\n> @@ -131,6 +131,29 @@ double CameraSensorHelper::gain(uint32_t gainCode) const\n>         }\n>  }\n>  \n> +/**\n> + * \\brief Quantize the given gain value\n> + * \\param[in] _gain The real gain\n> + * \\param[out] quantizationGain The gain that is lost due to quantization\n> + *\n> + * This function returns the actual gain that get's applied when the sensors\n> + * gain is set to gainCode(gain).\n> + *\n> + * It shall be guaranteed that gainCode(gain) == gainCode(quantizeGain(gain)).\n> + *\n> + * If \\a quantizationGain is provided it is filled with the gain that is lost\n> + * due to quantization.\n> + *\n> + * \\return The quantized real gain\n> + */\n> +double CameraSensorHelper::quantizeGain(double _gain, double *quantizationGain) const\n> +{\n> +       double g = gain(gainCode(_gain));\n> +       if (quantizationGain)\n> +               *quantizationGain = _gain / g;\n> +       return g;\n> +}\n> +\n>  /**\n>   * \\struct CameraSensorHelper::AnalogueGainLinear\n>   * \\brief Analogue gain constants for the linear gain model\n> diff --git a/src/ipa/libipa/camera_sensor_helper.h b/src/ipa/libipa/camera_sensor_helper.h\n> index a9300a64f1e7..42bdb3c5550f 100644\n> --- a/src/ipa/libipa/camera_sensor_helper.h\n> +++ b/src/ipa/libipa/camera_sensor_helper.h\n> @@ -29,6 +29,7 @@ public:\n>         std::optional<int16_t> blackLevel() const { return blackLevel_; }\n>         virtual uint32_t gainCode(double gain) const;\n>         virtual double gain(uint32_t gainCode) const;\n> +       virtual double quantizeGain(double gain, double *quantizationGain) const;\n\nShould this be virtual? do you expect it to be overridden by anything?\n--\nKieran\n\n>  \n>  protected:\n>         struct AnalogueGainLinear {\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 6FFC4BEFBE\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  8 Aug 2025 17:45:41 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 70DD16921E;\n\tFri,  8 Aug 2025 19:45:40 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0EF796084D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  8 Aug 2025 19:45:39 +0200 (CEST)","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 D8AF6465;\n\tFri,  8 Aug 2025 19:44:48 +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=\"rsCYd+05\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1754675088;\n\tbh=X5uO9axzceoFcUvWELHY2g6lyDARaGg8qXrM7EWETP0=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=rsCYd+05pus+NBqE/TKai0CAyB93sRRXBWY7It6s+FwWXpV3OqX2VYxepuDhofb3q\n\tw2nBaQfnG7xo+ctTmM2NUt811dY5Q0RkeQHezvMz3kSmsyNJfsXyAv8PmS5ngcKnWE\n\tfZvmEiTobjyjIaW1BCV6B/WLfHpCugToueia6P5o=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20250808141315.413839-4-stefan.klug@ideasonboard.com>","References":"<20250808141315.413839-1-stefan.klug@ideasonboard.com>\n\t<20250808141315.413839-4-stefan.klug@ideasonboard.com>","Subject":"Re: [PATCH v2 03/16] libipa: camera_sensor_helper: Add\n\tquantizeGain() function","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"Stefan Klug <stefan.klug@ideasonboard.com>","To":"Stefan Klug <stefan.klug@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Fri, 08 Aug 2025 18:45:36 +0100","Message-ID":"<175467513658.560048.819883406628432547@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>"}},{"id":35319,"web_url":"https://patchwork.libcamera.org/comment/35319/","msgid":"<9c61c698-4158-43f1-86e3-3d8c8e6d400e@ideasonboard.com>","date":"2025-08-08T21:07:16","subject":"Re: [PATCH v2 03/16] libipa: camera_sensor_helper: Add\n\tquantizeGain() function","submitter":{"id":156,"url":"https://patchwork.libcamera.org/api/people/156/","name":"Dan Scally","email":"dan.scally@ideasonboard.com"},"content":"Hi Stefan - thanks for the patches\n\nOn 08/08/2025 15:12, Stefan Klug wrote:\n> Add a small utility function that calculates the quantized gain that\n> gets applied by a sensor when the gain code is set to gainCode(gain).\n> This is needed by algorithms to calculate a digital correction gain that\n> gets applied to mitigate the error introduce by quantization.\n>\n> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n> ---\n>   src/ipa/libipa/camera_sensor_helper.cpp | 23 +++++++++++++++++++++++\n>   src/ipa/libipa/camera_sensor_helper.h   |  1 +\n>   2 files changed, 24 insertions(+)\n>\n> diff --git a/src/ipa/libipa/camera_sensor_helper.cpp b/src/ipa/libipa/camera_sensor_helper.cpp\n> index dcd69d9f2bbb..0a7b66cd003a 100644\n> --- a/src/ipa/libipa/camera_sensor_helper.cpp\n> +++ b/src/ipa/libipa/camera_sensor_helper.cpp\n> @@ -131,6 +131,29 @@ double CameraSensorHelper::gain(uint32_t gainCode) const\n>   \t}\n>   }\n>   \n> +/**\n> + * \\brief Quantize the given gain value\n> + * \\param[in] _gain The real gain\n> + * \\param[out] quantizationGain The gain that is lost due to quantization\n> + *\n> + * This function returns the actual gain that get's applied when the sensors\n\ns/get's/gets and s/sensors/sensor's\n\n> + * gain is set to gainCode(gain).\n> + *\n> + * It shall be guaranteed that gainCode(gain) == gainCode(quantizeGain(gain)).\n> + *\n> + * If \\a quantizationGain is provided it is filled with the gain that is lost\n> + * due to quantization.\n\nMaybe \"gain that must be applied to correct the losses due to quantization\"?\n\n> + *\n> + * \\return The quantized real gain\n> + */\n> +double CameraSensorHelper::quantizeGain(double _gain, double *quantizationGain) const\n\nWhy the underscore prefix for _gain?\n\n> +{\n> +\tdouble g = gain(gainCode(_gain));\n> +\tif (quantizationGain)\n> +\t\t*quantizationGain = _gain / g;\n> +\treturn g;\n> +}\n> +\n>   /**\n>    * \\struct CameraSensorHelper::AnalogueGainLinear\n>    * \\brief Analogue gain constants for the linear gain model\n> diff --git a/src/ipa/libipa/camera_sensor_helper.h b/src/ipa/libipa/camera_sensor_helper.h\n> index a9300a64f1e7..42bdb3c5550f 100644\n> --- a/src/ipa/libipa/camera_sensor_helper.h\n> +++ b/src/ipa/libipa/camera_sensor_helper.h\n> @@ -29,6 +29,7 @@ public:\n>   \tstd::optional<int16_t> blackLevel() const { return blackLevel_; }\n>   \tvirtual uint32_t gainCode(double gain) const;\n>   \tvirtual double gain(uint32_t gainCode) const;\n> +\tvirtual double quantizeGain(double gain, double *quantizationGain) const;\n\nDoes this need to be virtual? The calculation seems pretty universal.\n\n\nThanks\n\nDan\n\n>   \n>   protected:\n>   \tstruct AnalogueGainLinear {","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 BC257BEFBE\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  8 Aug 2025 21:07:22 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6997D6921A;\n\tFri,  8 Aug 2025 23:07:21 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 862E66084D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  8 Aug 2025 23:07:19 +0200 (CEST)","from [192.168.0.43]\n\t(cpc141996-chfd3-2-0-cust928.12-3.cable.virginm.net [86.13.91.161])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 506BBC71\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  8 Aug 2025 23:06:29 +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=\"NgGw1nc3\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1754687189;\n\tbh=ZcyFxDMeKedMrO6EQb2Tvbmm4SJX6v8/joqvIFHmWJ0=;\n\th=Date:From:Subject:To:References:In-Reply-To:From;\n\tb=NgGw1nc3O6z/09OuHxkYmH7tiCiupFiHUDqrbBi7ZuxcRRYr1CA7iWsnl1ILMGDq1\n\tX64q6aXmeW98zdDYq4zjyCAbLaBNgrnsk/+EpPJ/zk1IEW/6BDtwG1yBuDuKIBED32\n\tc9CeWS9Zm/owONdFDP1O5ytQmLtA8vrdmM9Mj54Y=","Message-ID":"<9c61c698-4158-43f1-86e3-3d8c8e6d400e@ideasonboard.com>","Date":"Fri, 8 Aug 2025 22:07:16 +0100","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","From":"Dan Scally <dan.scally@ideasonboard.com>","Subject":"Re: [PATCH v2 03/16] libipa: camera_sensor_helper: Add\n\tquantizeGain() function","To":"libcamera-devel@lists.libcamera.org","References":"<20250808141315.413839-1-stefan.klug@ideasonboard.com>\n\t<20250808141315.413839-4-stefan.klug@ideasonboard.com>","Content-Language":"en-US","In-Reply-To":"<20250808141315.413839-4-stefan.klug@ideasonboard.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>"}},{"id":35325,"web_url":"https://patchwork.libcamera.org/comment/35325/","msgid":"<175488973841.354573.17575485429706807192@localhost>","date":"2025-08-11T05:22:18","subject":"Re: [PATCH v2 03/16] libipa: camera_sensor_helper: Add\n\tquantizeGain() function","submitter":{"id":184,"url":"https://patchwork.libcamera.org/api/people/184/","name":"Stefan Klug","email":"stefan.klug@ideasonboard.com"},"content":"Hi Kieran,\n\nThank you for the review.\n\nQuoting Kieran Bingham (2025-08-08 19:45:36)\n> Quoting Stefan Klug (2025-08-08 15:12:41)\n> > Add a small utility function that calculates the quantized gain that\n> > gets applied by a sensor when the gain code is set to gainCode(gain).\n> > This is needed by algorithms to calculate a digital correction gain that\n> > gets applied to mitigate the error introduce by quantization.\n> > \n> > Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n> > ---\n> >  src/ipa/libipa/camera_sensor_helper.cpp | 23 +++++++++++++++++++++++\n> >  src/ipa/libipa/camera_sensor_helper.h   |  1 +\n> >  2 files changed, 24 insertions(+)\n> > \n> > diff --git a/src/ipa/libipa/camera_sensor_helper.cpp b/src/ipa/libipa/camera_sensor_helper.cpp\n> > index dcd69d9f2bbb..0a7b66cd003a 100644\n> > --- a/src/ipa/libipa/camera_sensor_helper.cpp\n> > +++ b/src/ipa/libipa/camera_sensor_helper.cpp\n> > @@ -131,6 +131,29 @@ double CameraSensorHelper::gain(uint32_t gainCode) const\n> >         }\n> >  }\n> >  \n> > +/**\n> > + * \\brief Quantize the given gain value\n> > + * \\param[in] _gain The real gain\n> > + * \\param[out] quantizationGain The gain that is lost due to quantization\n> > + *\n> > + * This function returns the actual gain that get's applied when the sensors\n> > + * gain is set to gainCode(gain).\n> > + *\n> > + * It shall be guaranteed that gainCode(gain) == gainCode(quantizeGain(gain)).\n> > + *\n> > + * If \\a quantizationGain is provided it is filled with the gain that is lost\n> > + * due to quantization.\n> > + *\n> > + * \\return The quantized real gain\n> > + */\n> > +double CameraSensorHelper::quantizeGain(double _gain, double *quantizationGain) const\n> > +{\n> > +       double g = gain(gainCode(_gain));\n> > +       if (quantizationGain)\n> > +               *quantizationGain = _gain / g;\n> > +       return g;\n> > +}\n> > +\n> >  /**\n> >   * \\struct CameraSensorHelper::AnalogueGainLinear\n> >   * \\brief Analogue gain constants for the linear gain model\n> > diff --git a/src/ipa/libipa/camera_sensor_helper.h b/src/ipa/libipa/camera_sensor_helper.h\n> > index a9300a64f1e7..42bdb3c5550f 100644\n> > --- a/src/ipa/libipa/camera_sensor_helper.h\n> > +++ b/src/ipa/libipa/camera_sensor_helper.h\n> > @@ -29,6 +29,7 @@ public:\n> >         std::optional<int16_t> blackLevel() const { return blackLevel_; }\n> >         virtual uint32_t gainCode(double gain) const;\n> >         virtual double gain(uint32_t gainCode) const;\n> > +       virtual double quantizeGain(double gain, double *quantizationGain) const;\n> \n> Should this be virtual? do you expect it to be overridden by anything?\n\nNo, I will remove that virtual. I can't really foresee a use case for\noverwriting that.\n\nBest regards,\nStefan\n\n> --\n> Kieran\n> \n> >  \n> >  protected:\n> >         struct AnalogueGainLinear {\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 F3052BDCC1\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 11 Aug 2025 05:22:23 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E47766921D;\n\tMon, 11 Aug 2025 07:22:22 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 3DA736921A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 11 Aug 2025 07:22:21 +0200 (CEST)","from ideasonboard.com (unknown\n\t[IPv6:2a00:6020:448c:6c00:8310:637a:ed36:7b42])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 2BD8E465;\n\tMon, 11 Aug 2025 07:21:29 +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=\"D6A2zgga\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1754889689;\n\tbh=cqaLUAgoNDoj2ACd/pwqPHBMZccp3wQbnVJ/iNjY9LM=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=D6A2zggaXpGDX5l3Bp11a76wH1npiHRz0/gr0UT1NDO8W6SMt0Hnu2KVesd4zcSct\n\t+jDCKqUup7E/aEX28OBlsNOiNP6dAWZQAF5Jk3AcvEEITMlOvblkKR8kQvCM06w7LJ\n\tMw6IG3gklliQ70O5I1OsBjeuY44qJdf7fc7dfNds=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<175467513658.560048.819883406628432547@ping.linuxembedded.co.uk>","References":"<20250808141315.413839-1-stefan.klug@ideasonboard.com>\n\t<20250808141315.413839-4-stefan.klug@ideasonboard.com>\n\t<175467513658.560048.819883406628432547@ping.linuxembedded.co.uk>","Subject":"Re: [PATCH v2 03/16] libipa: camera_sensor_helper: Add\n\tquantizeGain() function","From":"Stefan Klug <stefan.klug@ideasonboard.com>","Cc":"","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Mon, 11 Aug 2025 07:22:18 +0200","Message-ID":"<175488973841.354573.17575485429706807192@localhost>","User-Agent":"alot/0.12.dev8+g2c003385c862.d20250602","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":35326,"web_url":"https://patchwork.libcamera.org/comment/35326/","msgid":"<175488997688.354573.13819619891936282648@localhost>","date":"2025-08-11T05:26:16","subject":"Re: [PATCH v2 03/16] libipa: camera_sensor_helper: Add\n\tquantizeGain() function","submitter":{"id":184,"url":"https://patchwork.libcamera.org/api/people/184/","name":"Stefan Klug","email":"stefan.klug@ideasonboard.com"},"content":"Hi Dan,\n\nThank you for the review.\n\nQuoting Dan Scally (2025-08-08 23:07:16)\n> Hi Stefan - thanks for the patches\n> \n> On 08/08/2025 15:12, Stefan Klug wrote:\n> > Add a small utility function that calculates the quantized gain that\n> > gets applied by a sensor when the gain code is set to gainCode(gain).\n> > This is needed by algorithms to calculate a digital correction gain that\n> > gets applied to mitigate the error introduce by quantization.\n> >\n> > Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n> > ---\n> >   src/ipa/libipa/camera_sensor_helper.cpp | 23 +++++++++++++++++++++++\n> >   src/ipa/libipa/camera_sensor_helper.h   |  1 +\n> >   2 files changed, 24 insertions(+)\n> >\n> > diff --git a/src/ipa/libipa/camera_sensor_helper.cpp b/src/ipa/libipa/camera_sensor_helper.cpp\n> > index dcd69d9f2bbb..0a7b66cd003a 100644\n> > --- a/src/ipa/libipa/camera_sensor_helper.cpp\n> > +++ b/src/ipa/libipa/camera_sensor_helper.cpp\n> > @@ -131,6 +131,29 @@ double CameraSensorHelper::gain(uint32_t gainCode) const\n> >       }\n> >   }\n> >   \n> > +/**\n> > + * \\brief Quantize the given gain value\n> > + * \\param[in] _gain The real gain\n> > + * \\param[out] quantizationGain The gain that is lost due to quantization\n> > + *\n> > + * This function returns the actual gain that get's applied when the sensors\n> \n> s/get's/gets and s/sensors/sensor's\n\nThanks.\n\n> \n> > + * gain is set to gainCode(gain).\n> > + *\n> > + * It shall be guaranteed that gainCode(gain) == gainCode(quantizeGain(gain)).\n> > + *\n> > + * If \\a quantizationGain is provided it is filled with the gain that is lost\n> > + * due to quantization.\n> \n> Maybe \"gain that must be applied to correct the losses due to quantization\"?\n\nYes, that sounds better.\n\n> \n> > + *\n> > + * \\return The quantized real gain\n> > + */\n> > +double CameraSensorHelper::quantizeGain(double _gain, double *quantizationGain) const\n> \n> Why the underscore prefix for _gain?\n\nIf I call it gain, there is a name clash with the gain() function. I\nthought I saw that pattern elsewhere. Do you have a preferred name?\n\n> \n> > +{\n> > +     double g = gain(gainCode(_gain));\n> > +     if (quantizationGain)\n> > +             *quantizationGain = _gain / g;\n> > +     return g;\n> > +}\n> > +\n> >   /**\n> >    * \\struct CameraSensorHelper::AnalogueGainLinear\n> >    * \\brief Analogue gain constants for the linear gain model\n> > diff --git a/src/ipa/libipa/camera_sensor_helper.h b/src/ipa/libipa/camera_sensor_helper.h\n> > index a9300a64f1e7..42bdb3c5550f 100644\n> > --- a/src/ipa/libipa/camera_sensor_helper.h\n> > +++ b/src/ipa/libipa/camera_sensor_helper.h\n> > @@ -29,6 +29,7 @@ public:\n> >       std::optional<int16_t> blackLevel() const { return blackLevel_; }\n> >       virtual uint32_t gainCode(double gain) const;\n> >       virtual double gain(uint32_t gainCode) const;\n> > +     virtual double quantizeGain(double gain, double *quantizationGain) const;\n> \n> Does this need to be virtual? The calculation seems pretty universal.\n\nYes, right. I'll remove that.\n\nThanks,\nStefan\n\n> \n> \n> Thanks\n> \n> Dan\n> \n> >   \n> >   protected:\n> >       struct AnalogueGainLinear {","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 24DC4BEFBE\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 11 Aug 2025 05:26:23 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 040436921A;\n\tMon, 11 Aug 2025 07:26:21 +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 EFC006921A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 11 Aug 2025 07:26:19 +0200 (CEST)","from ideasonboard.com (unknown\n\t[IPv6:2a00:6020:448c:6c00:8310:637a:ed36:7b42])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 069614C7;\n\tMon, 11 Aug 2025 07:25:27 +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=\"cdrnofWe\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1754889928;\n\tbh=sfZWZY7aiNWBJAGBUe+PMEsA0/Bs2gERftgNCbBwFw8=;\n\th=In-Reply-To:References:Subject:From:To:Date:From;\n\tb=cdrnofWevuvwLIBqBz0syDZ51VyPUjuVe05yM0gYWmHOfTef09fbt70XMgCzLOcLU\n\tiTnD/of86y87jNmSkxmShnOTwyaSmg/dWCmpJm1YaN6QpavblPGDYDrMoc1YKRNZOX\n\tNUJ4D31mXMj3vQju5TrjlJYXajugBiPNeT1eZ+ao=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<9c61c698-4158-43f1-86e3-3d8c8e6d400e@ideasonboard.com>","References":"<20250808141315.413839-1-stefan.klug@ideasonboard.com>\n\t<20250808141315.413839-4-stefan.klug@ideasonboard.com>\n\t<9c61c698-4158-43f1-86e3-3d8c8e6d400e@ideasonboard.com>","Subject":"Re: [PATCH v2 03/16] libipa: camera_sensor_helper: Add\n\tquantizeGain() function","From":"Stefan Klug <stefan.klug@ideasonboard.com>","To":"Dan Scally <dan.scally@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Mon, 11 Aug 2025 07:26:16 +0200","Message-ID":"<175488997688.354573.13819619891936282648@localhost>","User-Agent":"alot/0.12.dev8+g2c003385c862.d20250602","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":35335,"web_url":"https://patchwork.libcamera.org/comment/35335/","msgid":"<829b700a-88f3-4767-83a6-901d3469885e@ideasonboard.com>","date":"2025-08-11T11:29:24","subject":"Re: [PATCH v2 03/16] libipa: camera_sensor_helper: Add\n\tquantizeGain() function","submitter":{"id":156,"url":"https://patchwork.libcamera.org/api/people/156/","name":"Dan Scally","email":"dan.scally@ideasonboard.com"},"content":"Hi Stefan\n\nOn 11/08/2025 06:26, Stefan Klug wrote:\n> Hi Dan,\n> \n> Thank you for the review.\n> \n> Quoting Dan Scally (2025-08-08 23:07:16)\n>> Hi Stefan - thanks for the patches\n>>\n>> On 08/08/2025 15:12, Stefan Klug wrote:\n>>> Add a small utility function that calculates the quantized gain that\n>>> gets applied by a sensor when the gain code is set to gainCode(gain).\n>>> This is needed by algorithms to calculate a digital correction gain that\n>>> gets applied to mitigate the error introduce by quantization.\n>>>\n>>> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n>>> ---\n>>>    src/ipa/libipa/camera_sensor_helper.cpp | 23 +++++++++++++++++++++++\n>>>    src/ipa/libipa/camera_sensor_helper.h   |  1 +\n>>>    2 files changed, 24 insertions(+)\n>>>\n>>> diff --git a/src/ipa/libipa/camera_sensor_helper.cpp b/src/ipa/libipa/camera_sensor_helper.cpp\n>>> index dcd69d9f2bbb..0a7b66cd003a 100644\n>>> --- a/src/ipa/libipa/camera_sensor_helper.cpp\n>>> +++ b/src/ipa/libipa/camera_sensor_helper.cpp\n>>> @@ -131,6 +131,29 @@ double CameraSensorHelper::gain(uint32_t gainCode) const\n>>>        }\n>>>    }\n>>>    \n>>> +/**\n>>> + * \\brief Quantize the given gain value\n>>> + * \\param[in] _gain The real gain\n>>> + * \\param[out] quantizationGain The gain that is lost due to quantization\n>>> + *\n>>> + * This function returns the actual gain that get's applied when the sensors\n>>\n>> s/get's/gets and s/sensors/sensor's\n> \n> Thanks.\n> \n>>\n>>> + * gain is set to gainCode(gain).\n>>> + *\n>>> + * It shall be guaranteed that gainCode(gain) == gainCode(quantizeGain(gain)).\n>>> + *\n>>> + * If \\a quantizationGain is provided it is filled with the gain that is lost\n>>> + * due to quantization.\n>>\n>> Maybe \"gain that must be applied to correct the losses due to quantization\"?\n> \n> Yes, that sounds better.\n> \n>>\n>>> + *\n>>> + * \\return The quantized real gain\n>>> + */\n>>> +double CameraSensorHelper::quantizeGain(double _gain, double *quantizationGain) const\n>>\n>> Why the underscore prefix for _gain?\n> \n> If I call it gain, there is a name clash with the gain() function. I\n> thought I saw that pattern elsewhere. Do you have a preferred name?\n\nNo not particularly; I just hadn't spotted the name clash - that's fine.\n\n> \n>>\n>>> +{\n>>> +     double g = gain(gainCode(_gain));\n>>> +     if (quantizationGain)\n>>> +             *quantizationGain = _gain / g;\n>>> +     return g;\n>>> +}\n>>> +\n>>>    /**\n>>>     * \\struct CameraSensorHelper::AnalogueGainLinear\n>>>     * \\brief Analogue gain constants for the linear gain model\n>>> diff --git a/src/ipa/libipa/camera_sensor_helper.h b/src/ipa/libipa/camera_sensor_helper.h\n>>> index a9300a64f1e7..42bdb3c5550f 100644\n>>> --- a/src/ipa/libipa/camera_sensor_helper.h\n>>> +++ b/src/ipa/libipa/camera_sensor_helper.h\n>>> @@ -29,6 +29,7 @@ public:\n>>>        std::optional<int16_t> blackLevel() const { return blackLevel_; }\n>>>        virtual uint32_t gainCode(double gain) const;\n>>>        virtual double gain(uint32_t gainCode) const;\n>>> +     virtual double quantizeGain(double gain, double *quantizationGain) const;\n>>\n>> Does this need to be virtual? The calculation seems pretty universal.\n> \n> Yes, right. I'll remove that.\n\nWith that change then:\n\nReviewed-by: Daniel Scally <dan.scally@ideasonboard.com>\n\n> \n> Thanks,\n> Stefan\n> \n>>\n>>\n>> Thanks\n>>\n>> Dan\n>>\n>>>    \n>>>    protected:\n>>>        struct AnalogueGainLinear {","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 8C53CBEFBE\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 11 Aug 2025 11:29:31 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 705E66921F;\n\tMon, 11 Aug 2025 13:29:30 +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 7C1626921A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 11 Aug 2025 13:29:29 +0200 (CEST)","from [192.168.0.43]\n\t(cpc141996-chfd3-2-0-cust928.12-3.cable.virginm.net [86.13.91.161])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 5A0BD82A;\n\tMon, 11 Aug 2025 13:28:37 +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=\"DprGSp+x\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1754911717;\n\tbh=9jJ5c6uvL4hM4aE7SfTaIA99LXT8MQ//ZV1Uu3dyaOA=;\n\th=Date:Subject:To:References:From:In-Reply-To:From;\n\tb=DprGSp+xSBy5sqV2gW+w2xZZ4UfaDi5MwSGbp+mYd2HGcjpugOC8kqAnwt2y6jWzY\n\tcwRD3SgtORHdjeSNHVSDt2Q8Vgt4ibY5laRun8J6wDc9RZXfDZsDJGt0BVrfvuM4U1\n\t5sK38/zwHxx5p6NKGzuNK6NFjbchscgPlefd0bQ8=","Message-ID":"<829b700a-88f3-4767-83a6-901d3469885e@ideasonboard.com>","Date":"Mon, 11 Aug 2025 12:29:24 +0100","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH v2 03/16] libipa: camera_sensor_helper: Add\n\tquantizeGain() function","To":"Stefan Klug <stefan.klug@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","References":"<20250808141315.413839-1-stefan.klug@ideasonboard.com>\n\t<20250808141315.413839-4-stefan.klug@ideasonboard.com>\n\t<9c61c698-4158-43f1-86e3-3d8c8e6d400e@ideasonboard.com>\n\t<175488997688.354573.13819619891936282648@localhost>","Content-Language":"en-US","From":"Dan Scally <dan.scally@ideasonboard.com>","In-Reply-To":"<175488997688.354573.13819619891936282648@localhost>","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>"}}]