[{"id":30251,"web_url":"https://patchwork.libcamera.org/comment/30251/","msgid":"<ZoU1TOzoPz3oIRZR@pyrite.rasen.tech>","date":"2024-07-03T11:26:04","subject":"Re: [PATCH v2 1/6] ipa: libipa: Add black levels to camera sensor\n\thelper","submitter":{"id":17,"url":"https://patchwork.libcamera.org/api/people/17/","name":"Paul Elder","email":"paul.elder@ideasonboard.com"},"content":"On Wed, Jul 03, 2024 at 12:39:48PM +0200, Stefan Klug wrote:\n> For a proper tuning process we need to know the sensor black levels. In\n> most cases these are fixed and not reported by the kernel driver. Store\n> them inside the sensor helpers for later retrieval by the algorithms.\n> \n> Add black level value corresponding to the data pedestal for three\n> initial sensors as documented in the datasheets. More should be added,\n> eventually filling the gaps for all supported sensors.\n> \n> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n\nReviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n\n> ---\n>  src/ipa/libipa/camera_sensor_helper.cpp | 27 +++++++++++++++++++++++++\n>  src/ipa/libipa/camera_sensor_helper.h   |  3 +++\n>  2 files changed, 30 insertions(+)\n> \n> diff --git a/src/ipa/libipa/camera_sensor_helper.cpp b/src/ipa/libipa/camera_sensor_helper.cpp\n> index 782ff9904e81..3d0e756927f0 100644\n> --- a/src/ipa/libipa/camera_sensor_helper.cpp\n> +++ b/src/ipa/libipa/camera_sensor_helper.cpp\n> @@ -47,6 +47,30 @@ namespace ipa {\n>   * function.\n>   */\n>  \n> +/**\n> + * \\fn CameraSensorHelper::blackLevel()\n> + * \\brief Fetch the black level of the sensor\n> + *\n> + * This function returns the black level of the sensor scaled to a 16bit pixel\n> + * width. If it is unknown an empty optional is returned.\n> + *\n> + * Black levels are typically the result of the following phenomena:\n> + * - Pedestal added by the sensor to pixel values. They are typically fixed,\n> + *   sometimes programmable and should be reported in datasheets (but\n> + *   documentation is not always available).\n> + * - Dark currents and other physical effects that add charge to pixels in the\n> + *   absence of light. Those can depend on the integration time and the sensor\n> + *   die temperature, and their contribution to pixel values depend on the\n> + *   sensor gains.\n> + *\n> + * The pedestal is usually the value with the biggest contribution to the\n> + * overall black level. In most cases it is either known before or in rare cases\n> + * (There is not a single driver with such a control in the linux kernel) can be\n> + * queried from the sensor. This function shall provide that fixed, known value.\n> + *\n> + * \\return The black level of the sensor, or std::nullopt if not known\n> + */\n> +\n>  /**\n>   * \\brief Compute gain code from the analogue gain absolute value\n>   * \\param[in] gain The real gain to pass\n> @@ -396,6 +420,7 @@ class CameraSensorHelperImx219 : public CameraSensorHelper\n>  public:\n>  \tCameraSensorHelperImx219()\n>  \t{\n> +\t\tblackLevel_ = 4096;\n>  \t\tgainType_ = AnalogueGainLinear;\n>  \t\tgainConstants_.linear = { 0, 256, -1, 256 };\n>  \t}\n> @@ -407,6 +432,7 @@ class CameraSensorHelperImx258 : public CameraSensorHelper\n>  public:\n>  \tCameraSensorHelperImx258()\n>  \t{\n> +\t\tblackLevel_ = 4096;\n>  \t\tgainType_ = AnalogueGainLinear;\n>  \t\tgainConstants_.linear = { 0, 512, -1, 512 };\n>  \t}\n> @@ -456,6 +482,7 @@ class CameraSensorHelperImx335 : public CameraSensorHelper\n>  public:\n>  \tCameraSensorHelperImx335()\n>  \t{\n> +\t\tblackLevel_ = 3200;\n>  \t\tgainType_ = AnalogueGainExponential;\n>  \t\tgainConstants_.exp = { 1.0, expGainDb(0.3) };\n>  \t}\n> diff --git a/src/ipa/libipa/camera_sensor_helper.h b/src/ipa/libipa/camera_sensor_helper.h\n> index 0d99073bea82..ac276e27f523 100644\n> --- a/src/ipa/libipa/camera_sensor_helper.h\n> +++ b/src/ipa/libipa/camera_sensor_helper.h\n> @@ -10,6 +10,7 @@\n>  #include <stdint.h>\n>  \n>  #include <memory>\n> +#include <optional>\n>  #include <string>\n>  #include <vector>\n>  \n> @@ -25,6 +26,7 @@ public:\n>  \tCameraSensorHelper() = default;\n>  \tvirtual ~CameraSensorHelper() = default;\n>  \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>  \n> @@ -51,6 +53,7 @@ protected:\n>  \t\tAnalogueGainExpConstants exp;\n>  \t};\n>  \n> +\tstd::optional<int16_t> blackLevel_;\n>  \tAnalogueGainType gainType_;\n>  \tAnalogueGainConstants gainConstants_;\n>  \n> -- \n> 2.43.0\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 69ED0BD87C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  3 Jul 2024 11:26:13 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1E41362E22;\n\tWed,  3 Jul 2024 13:26:12 +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 1D1FE62C99\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  3 Jul 2024 13:26:11 +0200 (CEST)","from pyrite.rasen.tech (h175-177-049-156.catv02.itscom.jp\n\t[175.177.49.156])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 2A2E94CA;\n\tWed,  3 Jul 2024 13:25:41 +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=\"Oad6HEu+\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1720005943;\n\tbh=F2ncl0Cz/dGctWEAfGOHNKX9uH89K/9lzL2aHjQLtXk=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=Oad6HEu+Ljwamm5lolYg0sre3BocGQ4hgPxtmggVBXGp57bzEkq7kPPahyEW31Vf+\n\tVB11LXHdkCQieYsTNtSf+iEoAo6Awg6Jo3UCLVczdCflbnKEktKUuMy4t1XkO+dHr5\n\t9V1lPvBuKO9WviHm6dYhWBFcR7gYuLVXRPSwWZzQ=","Date":"Wed, 3 Jul 2024 20:26:04 +0900","From":"Paul Elder <paul.elder@ideasonboard.com>","To":"Stefan Klug <stefan.klug@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH v2 1/6] ipa: libipa: Add black levels to camera sensor\n\thelper","Message-ID":"<ZoU1TOzoPz3oIRZR@pyrite.rasen.tech>","References":"<20240703104004.184783-1-stefan.klug@ideasonboard.com>\n\t<20240703104004.184783-2-stefan.klug@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<20240703104004.184783-2-stefan.klug@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>"}},{"id":30254,"web_url":"https://patchwork.libcamera.org/comment/30254/","msgid":"<172000831398.3353312.9588401549914133330@ping.linuxembedded.co.uk>","date":"2024-07-03T12:05:13","subject":"Re: [PATCH v2 1/6] ipa: libipa: Add black levels to camera sensor\n\thelper","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Stefan Klug (2024-07-03 11:39:48)\n> For a proper tuning process we need to know the sensor black levels. In\n> most cases these are fixed and not reported by the kernel driver. Store\n> them inside the sensor helpers for later retrieval by the algorithms.\n> \n> Add black level value corresponding to the data pedestal for three\n> initial sensors as documented in the datasheets. More should be added,\n> eventually filling the gaps for all supported sensors.\n> \n> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n> ---\n>  src/ipa/libipa/camera_sensor_helper.cpp | 27 +++++++++++++++++++++++++\n>  src/ipa/libipa/camera_sensor_helper.h   |  3 +++\n>  2 files changed, 30 insertions(+)\n> \n> diff --git a/src/ipa/libipa/camera_sensor_helper.cpp b/src/ipa/libipa/camera_sensor_helper.cpp\n> index 782ff9904e81..3d0e756927f0 100644\n> --- a/src/ipa/libipa/camera_sensor_helper.cpp\n> +++ b/src/ipa/libipa/camera_sensor_helper.cpp\n> @@ -47,6 +47,30 @@ namespace ipa {\n>   * function.\n>   */\n>  \n> +/**\n> + * \\fn CameraSensorHelper::blackLevel()\n> + * \\brief Fetch the black level of the sensor\n> + *\n> + * This function returns the black level of the sensor scaled to a 16bit pixel\n> + * width. If it is unknown an empty optional is returned.\n> + *\n> + * Black levels are typically the result of the following phenomena:\n> + * - Pedestal added by the sensor to pixel values. They are typically fixed,\n> + *   sometimes programmable and should be reported in datasheets (but\n> + *   documentation is not always available).\n> + * - Dark currents and other physical effects that add charge to pixels in the\n> + *   absence of light. Those can depend on the integration time and the sensor\n> + *   die temperature, and their contribution to pixel values depend on the\n> + *   sensor gains.\n> + *\n> + * The pedestal is usually the value with the biggest contribution to the\n> + * overall black level. In most cases it is either known before or in rare cases\n> + * (There is not a single driver with such a control in the linux kernel) can be\n> + * queried from the sensor. This function shall provide that fixed, known value.\n> + *\n> + * \\return The black level of the sensor, or std::nullopt if not known\n> + */\n> +\n>  /**\n>   * \\brief Compute gain code from the analogue gain absolute value\n>   * \\param[in] gain The real gain to pass\n> @@ -396,6 +420,7 @@ class CameraSensorHelperImx219 : public CameraSensorHelper\n>  public:\n>         CameraSensorHelperImx219()\n>         {\n> +               blackLevel_ = 4096;\n>                 gainType_ = AnalogueGainLinear;\n>                 gainConstants_.linear = { 0, 256, -1, 256 };\n>         }\n> @@ -407,6 +432,7 @@ class CameraSensorHelperImx258 : public CameraSensorHelper\n>  public:\n>         CameraSensorHelperImx258()\n>         {\n> +               blackLevel_ = 4096;\n>                 gainType_ = AnalogueGainLinear;\n>                 gainConstants_.linear = { 0, 512, -1, 512 };\n>         }\n> @@ -456,6 +482,7 @@ class CameraSensorHelperImx335 : public CameraSensorHelper\n>  public:\n>         CameraSensorHelperImx335()\n>         {\n> +               blackLevel_ = 3200;\n>                 gainType_ = AnalogueGainExponential;\n>                 gainConstants_.exp = { 1.0, expGainDb(0.3) };\n>         }\n> diff --git a/src/ipa/libipa/camera_sensor_helper.h b/src/ipa/libipa/camera_sensor_helper.h\n> index 0d99073bea82..ac276e27f523 100644\n> --- a/src/ipa/libipa/camera_sensor_helper.h\n> +++ b/src/ipa/libipa/camera_sensor_helper.h\n> @@ -10,6 +10,7 @@\n>  #include <stdint.h>\n>  \n>  #include <memory>\n> +#include <optional>\n>  #include <string>\n>  #include <vector>\n>  \n> @@ -25,6 +26,7 @@ public:\n>         CameraSensorHelper() = default;\n>         virtual ~CameraSensorHelper() = default;\n>  \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>  \n> @@ -51,6 +53,7 @@ protected:\n>                 AnalogueGainExpConstants exp;\n>         };\n>  \n> +       std::optional<int16_t> blackLevel_;\n\nShouldn't the black level be a uint16_t ? Otherwise, this would then be\nlimited to 15 bit max ? Can we expect a blacklevel above 32767?\n\n\n\n>         AnalogueGainType gainType_;\n>         AnalogueGainConstants gainConstants_;\n>  \n> -- \n> 2.43.0\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 2B7BBBD87C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  3 Jul 2024 12:05:20 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E4EB862E22;\n\tWed,  3 Jul 2024 14:05:18 +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 D246F62C95\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  3 Jul 2024 14:05:16 +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 90F453E6;\n\tWed,  3 Jul 2024 14:04: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=\"mt/bznDo\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1720008288;\n\tbh=5zID3ZE3K49Vm4k8PCmGUpcwz3d/uVmFoGP4jTejU3A=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=mt/bznDo8SUm8tF+8mNzCje31nkkd4jk55UKsjpRpXy3eVzBueqMTnChx7rhjgKMx\n\tNWt2a06PS1mpeMrRCjSZUCqb50YnlOhC7d35FxMYjXf0JAckfvaW/L7cKny8U1ZW1m\n\tBvJGKCN4TikVMaUhhJiHeluRfhq4HBRF7v/OKNpQ=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20240703104004.184783-2-stefan.klug@ideasonboard.com>","References":"<20240703104004.184783-1-stefan.klug@ideasonboard.com>\n\t<20240703104004.184783-2-stefan.klug@ideasonboard.com>","Subject":"Re: [PATCH v2 1/6] ipa: libipa: Add black levels to camera sensor\n\thelper","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":"Wed, 03 Jul 2024 13:05:13 +0100","Message-ID":"<172000831398.3353312.9588401549914133330@ping.linuxembedded.co.uk>","User-Agent":"alot/0.10","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":30265,"web_url":"https://patchwork.libcamera.org/comment/30265/","msgid":"<172000996629.3353312.3037221085985621158@ping.linuxembedded.co.uk>","date":"2024-07-03T12:32:46","subject":"Re: [PATCH v2 1/6] ipa: libipa: Add black levels to camera sensor\n\thelper","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Kieran Bingham (2024-07-03 13:05:13)\n> Quoting Stefan Klug (2024-07-03 11:39:48)\n> > For a proper tuning process we need to know the sensor black levels. In\n> > most cases these are fixed and not reported by the kernel driver. Store\n> > them inside the sensor helpers for later retrieval by the algorithms.\n> > \n> > Add black level value corresponding to the data pedestal for three\n> > initial sensors as documented in the datasheets. More should be added,\n> > eventually filling the gaps for all supported sensors.\n> > \n> > Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n> > ---\n> >  src/ipa/libipa/camera_sensor_helper.cpp | 27 +++++++++++++++++++++++++\n> >  src/ipa/libipa/camera_sensor_helper.h   |  3 +++\n> >  2 files changed, 30 insertions(+)\n> > \n> > diff --git a/src/ipa/libipa/camera_sensor_helper.cpp b/src/ipa/libipa/camera_sensor_helper.cpp\n> > index 782ff9904e81..3d0e756927f0 100644\n> > --- a/src/ipa/libipa/camera_sensor_helper.cpp\n> > +++ b/src/ipa/libipa/camera_sensor_helper.cpp\n> > @@ -47,6 +47,30 @@ namespace ipa {\n> >   * function.\n> >   */\n> >  \n> > +/**\n> > + * \\fn CameraSensorHelper::blackLevel()\n> > + * \\brief Fetch the black level of the sensor\n> > + *\n> > + * This function returns the black level of the sensor scaled to a 16bit pixel\n> > + * width. If it is unknown an empty optional is returned.\n> > + *\n> > + * Black levels are typically the result of the following phenomena:\n> > + * - Pedestal added by the sensor to pixel values. They are typically fixed,\n> > + *   sometimes programmable and should be reported in datasheets (but\n> > + *   documentation is not always available).\n> > + * - Dark currents and other physical effects that add charge to pixels in the\n> > + *   absence of light. Those can depend on the integration time and the sensor\n> > + *   die temperature, and their contribution to pixel values depend on the\n> > + *   sensor gains.\n> > + *\n> > + * The pedestal is usually the value with the biggest contribution to the\n> > + * overall black level. In most cases it is either known before or in rare cases\n> > + * (There is not a single driver with such a control in the linux kernel) can be\n> > + * queried from the sensor. This function shall provide that fixed, known value.\n> > + *\n> > + * \\return The black level of the sensor, or std::nullopt if not known\n> > + */\n> > +\n> >  /**\n> >   * \\brief Compute gain code from the analogue gain absolute value\n> >   * \\param[in] gain The real gain to pass\n> > @@ -396,6 +420,7 @@ class CameraSensorHelperImx219 : public CameraSensorHelper\n> >  public:\n> >         CameraSensorHelperImx219()\n> >         {\n> > +               blackLevel_ = 4096;\n> >                 gainType_ = AnalogueGainLinear;\n> >                 gainConstants_.linear = { 0, 256, -1, 256 };\n> >         }\n> > @@ -407,6 +432,7 @@ class CameraSensorHelperImx258 : public CameraSensorHelper\n> >  public:\n> >         CameraSensorHelperImx258()\n> >         {\n> > +               blackLevel_ = 4096;\n> >                 gainType_ = AnalogueGainLinear;\n> >                 gainConstants_.linear = { 0, 512, -1, 512 };\n> >         }\n> > @@ -456,6 +482,7 @@ class CameraSensorHelperImx335 : public CameraSensorHelper\n> >  public:\n> >         CameraSensorHelperImx335()\n> >         {\n> > +               blackLevel_ = 3200;\n> >                 gainType_ = AnalogueGainExponential;\n> >                 gainConstants_.exp = { 1.0, expGainDb(0.3) };\n> >         }\n> > diff --git a/src/ipa/libipa/camera_sensor_helper.h b/src/ipa/libipa/camera_sensor_helper.h\n> > index 0d99073bea82..ac276e27f523 100644\n> > --- a/src/ipa/libipa/camera_sensor_helper.h\n> > +++ b/src/ipa/libipa/camera_sensor_helper.h\n> > @@ -10,6 +10,7 @@\n> >  #include <stdint.h>\n> >  \n> >  #include <memory>\n> > +#include <optional>\n> >  #include <string>\n> >  #include <vector>\n> >  \n> > @@ -25,6 +26,7 @@ public:\n> >         CameraSensorHelper() = default;\n> >         virtual ~CameraSensorHelper() = default;\n> >  \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> >  \n> > @@ -51,6 +53,7 @@ protected:\n> >                 AnalogueGainExpConstants exp;\n> >         };\n> >  \n> > +       std::optional<int16_t> blackLevel_;\n> \n> Shouldn't the black level be a uint16_t ? Otherwise, this would then be\n> limited to 15 bit max ? Can we expect a blacklevel above 32767?\n> \n\nGiven it's a known stipulation that we're using int16_t to read from the\nyaml files currently:\n\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> \n> \n> >         AnalogueGainType gainType_;\n> >         AnalogueGainConstants gainConstants_;\n> >  \n> > -- \n> > 2.43.0\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 054B7BD87C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  3 Jul 2024 12:32:51 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id AAD376333B;\n\tWed,  3 Jul 2024 14:32:50 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id EE06662E23\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  3 Jul 2024 14:32:48 +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 D68643E6;\n\tWed,  3 Jul 2024 14:32:20 +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=\"hOB0K74B\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1720009940;\n\tbh=RE25eYy3fK1YpaeU9eXENYqfO3E54xDiRRDOwrlsVyQ=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=hOB0K74BDZDdnlWLlawXKjDDT6faYfGQsxT1K6UKeaWnlMfZeAF2cq4LysmBZopjp\n\t/P1P60Lqx3uaKSUaC/Ixy5tVkcreUCawqdSYih64PXztVN4+aqhlSxltQk0o7eL4np\n\tL5SUmHeTw8Nx3Ks2IbQQbsWNlRQSvUOdXQ3G4WUw=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<172000831398.3353312.9588401549914133330@ping.linuxembedded.co.uk>","References":"<20240703104004.184783-1-stefan.klug@ideasonboard.com>\n\t<20240703104004.184783-2-stefan.klug@ideasonboard.com>\n\t<172000831398.3353312.9588401549914133330@ping.linuxembedded.co.uk>","Subject":"Re: [PATCH v2 1/6] ipa: libipa: Add black levels to camera sensor\n\thelper","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":"Wed, 03 Jul 2024 13:32:46 +0100","Message-ID":"<172000996629.3353312.3037221085985621158@ping.linuxembedded.co.uk>","User-Agent":"alot/0.10","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":30266,"web_url":"https://patchwork.libcamera.org/comment/30266/","msgid":"<20240703123752.GA27927@pendragon.ideasonboard.com>","date":"2024-07-03T12:37:52","subject":"Re: [PATCH v2 1/6] ipa: libipa: Add black levels to camera sensor\n\thelper","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Stefan,\n\nThank you for the patch.\n\nOn Wed, Jul 03, 2024 at 12:39:48PM +0200, Stefan Klug wrote:\n> For a proper tuning process we need to know the sensor black levels. In\n> most cases these are fixed and not reported by the kernel driver. Store\n> them inside the sensor helpers for later retrieval by the algorithms.\n> \n> Add black level value corresponding to the data pedestal for three\n> initial sensors as documented in the datasheets. More should be added,\n> eventually filling the gaps for all supported sensors.\n> \n> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n> ---\n>  src/ipa/libipa/camera_sensor_helper.cpp | 27 +++++++++++++++++++++++++\n>  src/ipa/libipa/camera_sensor_helper.h   |  3 +++\n>  2 files changed, 30 insertions(+)\n> \n> diff --git a/src/ipa/libipa/camera_sensor_helper.cpp b/src/ipa/libipa/camera_sensor_helper.cpp\n> index 782ff9904e81..3d0e756927f0 100644\n> --- a/src/ipa/libipa/camera_sensor_helper.cpp\n> +++ b/src/ipa/libipa/camera_sensor_helper.cpp\n> @@ -47,6 +47,30 @@ namespace ipa {\n>   * function.\n>   */\n>  \n> +/**\n> + * \\fn CameraSensorHelper::blackLevel()\n> + * \\brief Fetch the black level of the sensor\n> + *\n> + * This function returns the black level of the sensor scaled to a 16bit pixel\n> + * width. If it is unknown an empty optional is returned.\n\nLet's add\n\n * \\todo Fill the blanks and add pedestal values for all supported sensors. Once\n * done, drop the std::optional<>.\n\n> + *\n> + * Black levels are typically the result of the following phenomena:\n> + * - Pedestal added by the sensor to pixel values. They are typically fixed,\n> + *   sometimes programmable and should be reported in datasheets (but\n> + *   documentation is not always available).\n> + * - Dark currents and other physical effects that add charge to pixels in the\n> + *   absence of light. Those can depend on the integration time and the sensor\n> + *   die temperature, and their contribution to pixel values depend on the\n> + *   sensor gains.\n> + *\n> + * The pedestal is usually the value with the biggest contribution to the\n> + * overall black level. In most cases it is either known before or in rare cases\n> + * (There is not a single driver with such a control in the linux kernel) can be\n\ns/There/there/\n\n> + * queried from the sensor. This function shall provide that fixed, known value.\n\ns/shall provide/provides/\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> + *\n> + * \\return The black level of the sensor, or std::nullopt if not known\n> + */\n> +\n>  /**\n>   * \\brief Compute gain code from the analogue gain absolute value\n>   * \\param[in] gain The real gain to pass\n> @@ -396,6 +420,7 @@ class CameraSensorHelperImx219 : public CameraSensorHelper\n>  public:\n>  \tCameraSensorHelperImx219()\n>  \t{\n> +\t\tblackLevel_ = 4096;\n>  \t\tgainType_ = AnalogueGainLinear;\n>  \t\tgainConstants_.linear = { 0, 256, -1, 256 };\n>  \t}\n> @@ -407,6 +432,7 @@ class CameraSensorHelperImx258 : public CameraSensorHelper\n>  public:\n>  \tCameraSensorHelperImx258()\n>  \t{\n> +\t\tblackLevel_ = 4096;\n>  \t\tgainType_ = AnalogueGainLinear;\n>  \t\tgainConstants_.linear = { 0, 512, -1, 512 };\n>  \t}\n> @@ -456,6 +482,7 @@ class CameraSensorHelperImx335 : public CameraSensorHelper\n>  public:\n>  \tCameraSensorHelperImx335()\n>  \t{\n> +\t\tblackLevel_ = 3200;\n>  \t\tgainType_ = AnalogueGainExponential;\n>  \t\tgainConstants_.exp = { 1.0, expGainDb(0.3) };\n>  \t}\n> diff --git a/src/ipa/libipa/camera_sensor_helper.h b/src/ipa/libipa/camera_sensor_helper.h\n> index 0d99073bea82..ac276e27f523 100644\n> --- a/src/ipa/libipa/camera_sensor_helper.h\n> +++ b/src/ipa/libipa/camera_sensor_helper.h\n> @@ -10,6 +10,7 @@\n>  #include <stdint.h>\n>  \n>  #include <memory>\n> +#include <optional>\n>  #include <string>\n>  #include <vector>\n>  \n> @@ -25,6 +26,7 @@ public:\n>  \tCameraSensorHelper() = default;\n>  \tvirtual ~CameraSensorHelper() = default;\n>  \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>  \n> @@ -51,6 +53,7 @@ protected:\n>  \t\tAnalogueGainExpConstants exp;\n>  \t};\n>  \n> +\tstd::optional<int16_t> blackLevel_;\n>  \tAnalogueGainType gainType_;\n>  \tAnalogueGainConstants gainConstants_;\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 90032BEFBE\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  3 Jul 2024 12:38:16 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5D9C062E25;\n\tWed,  3 Jul 2024 14:38:15 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 6C07762C95\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  3 Jul 2024 14:38:13 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(117.145-247-81.adsl-dyn.isp.belgacom.be [81.247.145.117])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 403453E6;\n\tWed,  3 Jul 2024 14:37:45 +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=\"UxQJg/rh\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1720010265;\n\tbh=qY9mobfZWiF/omJr0JvaYXZHJuNWfcjiRKc5zJSik98=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=UxQJg/rh9+/i2ZvmiOihQocYIN8j1Jk/vHDe+klPhI1VOygbNVxt5M9xz38TvhEQP\n\tRxL6d7wBZONCp9Xd/MWVbpGR+/RrVAlC7I3MMyQEu8ZBOs+g3WaLMJg99G+wPhf826\n\tzpJkuclhX2pvuYCYtpam/qQoppS2hK5J+hFdrtGw=","Date":"Wed, 3 Jul 2024 15:37:52 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Stefan Klug <stefan.klug@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH v2 1/6] ipa: libipa: Add black levels to camera sensor\n\thelper","Message-ID":"<20240703123752.GA27927@pendragon.ideasonboard.com>","References":"<20240703104004.184783-1-stefan.klug@ideasonboard.com>\n\t<20240703104004.184783-2-stefan.klug@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20240703104004.184783-2-stefan.klug@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>"}}]