[{"id":20042,"web_url":"https://patchwork.libcamera.org/comment/20042/","msgid":"<YVuqR7fqzDtKq6sS@pendragon.ideasonboard.com>","date":"2021-10-05T01:28:39","subject":"Re: [libcamera-devel] [PATCH v2 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 Thu, Sep 30, 2021 at 11:37:13AM +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 resultant images.\n\ns/resultant/resulting/\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> ---\n>  src/ipa/ipu3/algorithms/black_correction.cpp | 67 ++++++++++++++++++++\n>  src/ipa/ipu3/algorithms/black_correction.h   | 28 ++++++++\n\nAs you've correctly mentioned in the subject, this is called black level\ncorrection (or sometimes compensation). The file name would get a bit\nlong, so we could name it blc.cpp and blc.h. Same for the class, but I\nwouldn't mind a BlackLevelCorrection class.\n\n>  src/ipa/ipu3/algorithms/meson.build          |  1 +\n>  src/ipa/ipu3/ipu3.cpp                        |  2 +\n>  4 files changed, 98 insertions(+)\n>  create mode 100644 src/ipa/ipu3/algorithms/black_correction.cpp\n>  create mode 100644 src/ipa/ipu3/algorithms/black_correction.h\n> \n> diff --git a/src/ipa/ipu3/algorithms/black_correction.cpp b/src/ipa/ipu3/algorithms/black_correction.cpp\n> new file mode 100644\n> index 00000000..5b5b5d31\n> --- /dev/null\n> +++ b/src/ipa/ipu3/algorithms/black_correction.cpp\n> @@ -0,0 +1,67 @@\n> +/* SPDX-License-Identifier: LGPL-2.1-or-later */\n> +/*\n> + * Copyright (C) 2021, Google inc.\n> + *\n> + * black_correction.cpp - IPU3 Optical Black Correction control\n\ns/Optical Black Correction/Black Level Correction/\n\nSame below. \"optical black\" (or optical dark) is the name of the sensor\nregion not exposed to light, but the algorithm is named \"black level\ncorrection\".\n\n> + */\n> +\n> +#include \"black_correction.h\"\n> +\n> +#include <string.h>\n> +\n> +/**\n> + * \\file black_correction.h\n> + */\n> +\n> +namespace libcamera {\n> +\n> +namespace ipa::ipu3::algorithms {\n> +\n> +/**\n> + * \\class BlackCorrection\n> + * \\brief A class to handle optical black correction\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 and to achieve that, we need to\n> + * substract an offset to all the pixels.\n\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> + *\n> + * This can be taken into account by reading the lowest value of a special\n> + * region on sensors which is not exposed to light. This provides a substracting\n> + * factor to be able to adjust the expected black levels in the resultant\n> + * images.\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> +\n> +BlackCorrection::BlackCorrection()\n> +{\n> +}\n> +\n> +/**\n> + * \\brief Fill in the parameter structure, and enable optical black correction\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 BlackCorrection::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 approximation\n\ns/approximation/rough approximation./\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\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/black_correction.h b/src/ipa/ipu3/algorithms/black_correction.h\n> new file mode 100644\n> index 00000000..6486ac5b\n> --- /dev/null\n> +++ b/src/ipa/ipu3/algorithms/black_correction.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 Optical Black Correction control\n> + */\n> +#ifndef __LIBCAMERA_IPU3_ALGORITHMS_BLACK_CORRECTION_H__\n> +#define __LIBCAMERA_IPU3_ALGORITHMS_BLACK_CORRECTION_H__\n> +\n> +#include \"algorithm.h\"\n> +\n> +namespace libcamera {\n> +\n> +namespace ipa::ipu3::algorithms {\n> +\n> +class BlackCorrection : public Algorithm\n> +{\n> +public:\n> +\tBlackCorrection();\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_BLACK_CORRECTION_H__ */\n> diff --git a/src/ipa/ipu3/algorithms/meson.build b/src/ipa/ipu3/algorithms/meson.build\n> index deae225b..66877c1b 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> +    'black_correction.cpp',\n>      'tone_mapping.cpp',\n>  ])\n> diff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp\n> index b33e8c77..7cc0fb89 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/black_correction.h\"\n>  #include \"algorithms/tone_mapping.h\"\n>  #include \"libipa/camera_sensor_helper.h\"\n>  \n> @@ -279,6 +280,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::BlackCorrection>());\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 93AC3BDC71\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  5 Oct 2021 01:28:48 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 027626918F;\n\tTue,  5 Oct 2021 03:28:48 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id E614269189\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  5 Oct 2021 03:28:46 +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 68B0025B;\n\tTue,  5 Oct 2021 03:28:46 +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=\"Txi7usbN\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1633397326;\n\tbh=5vh9vxaaX0j6gt6D4sPHLUHomW3Im0VJgH/m5B8+FS8=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=Txi7usbNxo4/XwkUmswsS97D8JLVWV4jH9ylpJ7soy94NwR2ne7suntn7/qmSkU28\n\tBOYUye2X7kFDukrZ1lj+cyxlSiTbUo0VOc5DhQNfjnx8MfFmg2kZiJcgMYXaB2rzCS\n\tgOV3Lu/gX/tn/amKVZ2utR3P9xHhcCtnDgBMLE7M=","Date":"Tue, 5 Oct 2021 04:28:39 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>","Message-ID":"<YVuqR7fqzDtKq6sS@pendragon.ideasonboard.com>","References":"<20210930093715.73293-1-jeanmichel.hautbois@ideasonboard.com>\n\t<20210930093715.73293-11-jeanmichel.hautbois@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20210930093715.73293-11-jeanmichel.hautbois@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v2 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>"}}]