[{"id":20094,"web_url":"https://patchwork.libcamera.org/comment/20094/","msgid":"<YV3BUfNky2xHmjue@pendragon.ideasonboard.com>","date":"2021-10-06T15:31:29","subject":"Re: [libcamera-devel] [PATCH v3 10/12] ipa: ipu3: awb: Introduce\n\tBlack Level Correction","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Jean-Michel,\n\nThank you for the patch.\n\nOn Wed, Oct 06, 2021 at 04:00:40PM +0200, Jean-Michel Hautbois wrote:\n> The pixels output by the camera normally include a black level, because\n> sensors do not always report a signal level of '0' for black. Pixels at\n> or below this level should be considered black and to achieve that, we\n> need to substract an offset to all the pixels. This can be taken into\n> account by reading the lowest value of a special region on sensors which\n> is not exposed to light. This provides a substracting factor to be\n> able to adjust the expected black levels in the resulting images.\n> \n> For a camera outputting 10-bit pixel values (in the range 0 to 1023) a\n> typical black level might be 64. It is a fixed value, obtained by\n> capturing a raw frame with minimum exposure and gain fixed to 1.0 while\n> covering the sensor (the darker the better). We consider it good enough\n> as a very first approximation, until we measure it during a tuning\n> process and include it in a configuration file\n> \n> Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>\n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> ---\n>  src/ipa/ipu3/algorithms/blc.cpp     | 66 +++++++++++++++++++++++++++++\n>  src/ipa/ipu3/algorithms/blc.h       | 28 ++++++++++++\n>  src/ipa/ipu3/algorithms/meson.build |  1 +\n>  src/ipa/ipu3/ipu3.cpp               |  2 +\n>  4 files changed, 97 insertions(+)\n>  create mode 100644 src/ipa/ipu3/algorithms/blc.cpp\n>  create mode 100644 src/ipa/ipu3/algorithms/blc.h\n> \n> diff --git a/src/ipa/ipu3/algorithms/blc.cpp b/src/ipa/ipu3/algorithms/blc.cpp\n> new file mode 100644\n> index 00000000..df56e292\n> --- /dev/null\n> +++ b/src/ipa/ipu3/algorithms/blc.cpp\n> @@ -0,0 +1,66 @@\n> +/* SPDX-License-Identifier: LGPL-2.1-or-later */\n> +/*\n> + * Copyright (C) 2021, Google inc.\n> + *\n> + * blc.cpp - IPU3 Black Level Correction control\n> + */\n> +\n> +#include \"blc.h\"\n> +\n> +#include <string.h>\n> +\n> +/**\n> + * \\file blc.h\n\n * \\brief IPU3 Black Level Correction control\n\n> + */\n> +\n> +namespace libcamera {\n> +\n> +namespace ipa::ipu3::algorithms {\n> +\n> +/**\n> + * \\class BlackLevelCorrection\n> + * \\brief A class to handle optical black correction\n\ns/optical black correction/black level correction/\n\n> + *\n> + * The pixels output by the camera normally include a black level, because\n> + * sensors do not always report a signal level of '0' for black. Pixels at or\n> + * below this level should be considered black. To achieve that, the ImgU BLC\n> + * algorithm subtracts a configurable offset from all pixels.\n> + *\n> + * The black level can be measured at runtime from an optical dark region of the\n> + * camera sensor, or measured during the camera tuning process. The first option\n> + * isn't currently supported.\n> + */\n> +\n> +BlackLevelCorrection::BlackLevelCorrection()\n> +{\n> +}\n> +\n> +/**\n> + * \\brief Fill in the parameter structure, and enable optical black correction\n\ns/optical black correction/black level correction/\n\n> + * \\param context The shared IPA context\n> + * \\param params The IPU3 parameters\n> + *\n> + * Populate the IPU3 parameter structure with the correction values for each\n> + * channel and enable the corresponding ImgU block processing.\n> + */\n> +void BlackLevelCorrection::prepare([[maybe_unused]] IPAContext &context,\n> +\t\t\t      ipu3_uapi_params *params)\n> +{\n> +\t/*\n> +\t * The Optical Black Level correction values\n> +\t * \\todo The correction values should come from sensor specific\n> +\t * tuning processes. This is a first rough approximation\n\ns/$/./\n\n> +\t */\n> +\tparams->obgrid_param.gr = 64;\n> +\tparams->obgrid_param.r  = 64;\n> +\tparams->obgrid_param.b  = 64;\n> +\tparams->obgrid_param.gb = 64;\n> +\n> +\t/* Enable the custom optical black correction processing */\n> +\tparams->use.obgrid = 1;\n> +\tparams->use.obgrid_param = 1;\n> +}\n> +\n> +} /* namespace ipa::ipu3::algorithms */\n> +\n> +} /* namespace libcamera */\n> diff --git a/src/ipa/ipu3/algorithms/blc.h b/src/ipa/ipu3/algorithms/blc.h\n> new file mode 100644\n> index 00000000..4b7cb483\n> --- /dev/null\n> +++ b/src/ipa/ipu3/algorithms/blc.h\n> @@ -0,0 +1,28 @@\n> +/* SPDX-License-Identifier: LGPL-2.1-or-later */\n> +/*\n> + * Copyright (C) 2021, Google inc.\n> + *\n> + * black_correction.h - IPU3 Black Level Correction control\n> + */\n> +#ifndef __LIBCAMERA_IPU3_ALGORITHMS_BLC_H__\n> +#define __LIBCAMERA_IPU3_ALGORITHMS_BLC_H__\n> +\n> +#include \"algorithm.h\"\n> +\n> +namespace libcamera {\n> +\n> +namespace ipa::ipu3::algorithms {\n> +\n> +class BlackLevelCorrection : public Algorithm\n> +{\n> +public:\n> +\tBlackLevelCorrection();\n> +\n> +\tvoid prepare(IPAContext &context, ipu3_uapi_params *params) override;\n> +};\n> +\n> +} /* namespace ipa::ipu3::algorithms */\n> +\n> +} /* namespace libcamera */\n> +\n> +#endif /* __LIBCAMERA_IPU3_ALGORITHMS_BLC_H__ */\n> diff --git a/src/ipa/ipu3/algorithms/meson.build b/src/ipa/ipu3/algorithms/meson.build\n> index deae225b..3ec42f72 100644\n> --- a/src/ipa/ipu3/algorithms/meson.build\n> +++ b/src/ipa/ipu3/algorithms/meson.build\n> @@ -4,5 +4,6 @@ ipu3_ipa_algorithms = files([\n>      'agc.cpp',\n>      'algorithm.cpp',\n>      'awb.cpp',\n> +    'blc.cpp',\n>      'tone_mapping.cpp',\n>  ])\n> diff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp\n> index 06f53fbe..6d9bbf39 100644\n> --- a/src/ipa/ipu3/ipu3.cpp\n> +++ b/src/ipa/ipu3/ipu3.cpp\n> @@ -33,6 +33,7 @@\n>  #include \"algorithms/agc.h\"\n>  #include \"algorithms/algorithm.h\"\n>  #include \"algorithms/awb.h\"\n> +#include \"algorithms/blc.h\"\n>  #include \"algorithms/tone_mapping.h\"\n>  #include \"libipa/camera_sensor_helper.h\"\n>  \n> @@ -282,6 +283,7 @@ int IPAIPU3::init(const IPASettings &settings,\n>  \t/* Construct our Algorithms */\n>  \talgorithms_.push_back(std::make_unique<algorithms::Agc>());\n>  \talgorithms_.push_back(std::make_unique<algorithms::Awb>());\n> +\talgorithms_.push_back(std::make_unique<algorithms::BlackLevelCorrection>());\n>  \talgorithms_.push_back(std::make_unique<algorithms::ToneMapping>());\n>  \n>  \treturn 0;","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 12368BDC71\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  6 Oct 2021 15:31:40 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 8A582691BD;\n\tWed,  6 Oct 2021 17:31:39 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 6CB046023D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  6 Oct 2021 17:31:38 +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 D9EC0FFD;\n\tWed,  6 Oct 2021 17:31:37 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"ZuSiC1ne\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1633534298;\n\tbh=8Oi9/TGuQ8XA0T1eDdPWe/6rx2CKTEB31PxzxdMWIWM=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=ZuSiC1nees9KHAkX7biPy4oZ5EiQXZN+AZOCMXZwjWS+P+mAmxIo+jK8nYVQIuEYo\n\tO0Taxgp1C1xm/NV4c58ZxaDZV8GF3RrREMXx8ScxcC2U5+vVIISx/IzsftuAQdovqL\n\tI/uHEYXz5pMq6jHavIlJzcnJmO5KFDjksCOs4ys4=","Date":"Wed, 6 Oct 2021 18:31:29 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>","Message-ID":"<YV3BUfNky2xHmjue@pendragon.ideasonboard.com>","References":"<20211006140041.964542-1-jeanmichel.hautbois@ideasonboard.com>\n\t<20211006140041.964542-11-jeanmichel.hautbois@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20211006140041.964542-11-jeanmichel.hautbois@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v3 10/12] ipa: ipu3: awb: Introduce\n\tBlack Level Correction","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>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]