[{"id":24081,"web_url":"https://patchwork.libcamera.org/comment/24081/","msgid":"<Yt1w9wXJOv07KAAh@pendragon.ideasonboard.com>","date":"2022-07-24T16:19:03","subject":"Re: [libcamera-devel] [PATCH v2 2/5] ipa: rkisp1: Add support of\n\tGamma Sensor Linearization control","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Florian,\n\nThank you for the patch.\n\nOn Fri, Jul 22, 2022 at 05:16:32PM +0200, Florian Sylvestre via libcamera-devel wrote:\n> The GammaSensorLinearization algorithm improves the image dynamic using\n> a coefficient table in the YAML tuning file.\n\nI think you can drop this sentence, the second one is a better\ndescription.\n\n> The GammaSensorLinearization algorithm linearizes the sensor output to\n> compensate the sensor non-linearities by applying piecewise linear curves to\n\ns/linear curves/piecewise linear functions/\n\nA linear curve is just a line :-)\n\n> the red, green and blue channels.\n> \n> Signed-off-by: Florian Sylvestre <fsylvestre@baylibre.com>\n> ---\n>  src/ipa/rkisp1/algorithms/gsl.cpp     | 147 ++++++++++++++++++++++++++\n>  src/ipa/rkisp1/algorithms/gsl.h       |  34 ++++++\n>  src/ipa/rkisp1/algorithms/meson.build |   1 +\n>  src/ipa/rkisp1/data/ov5640.yaml       |   6 ++\n>  src/ipa/rkisp1/rkisp1.cpp             |   1 +\n>  5 files changed, 189 insertions(+)\n>  create mode 100644 src/ipa/rkisp1/algorithms/gsl.cpp\n>  create mode 100644 src/ipa/rkisp1/algorithms/gsl.h\n> \n> diff --git a/src/ipa/rkisp1/algorithms/gsl.cpp b/src/ipa/rkisp1/algorithms/gsl.cpp\n> new file mode 100644\n> index 00000000..1680ddc3\n> --- /dev/null\n> +++ b/src/ipa/rkisp1/algorithms/gsl.cpp\n> @@ -0,0 +1,147 @@\n> +/* SPDX-License-Identifier: LGPL-2.1-or-later */\n> +/*\n> + * Copyright (C) 2021-2022, Ideas On Board\n> + *\n> + * gsl.cpp - RkISP1 Gamma Sensor Linearization control\n> + */\n> +\n> +#include \"gsl.h\"\n> +\n> +#include <libcamera/base/log.h>\n> +\n> +#include \"libcamera/internal/yaml_parser.h\"\n> +\n> +#include \"linux/rkisp1-config.h\"\n> +\n> +/**\n> + * \\file gsl.h\n> + */\n> +\n> +namespace libcamera {\n> +\n> +namespace ipa::rkisp1::algorithms {\n> +\n> +/**\n> + * \\class GammaSensorLinearization\n> + * \\brief RkISP1 Gamma Sensor Linearization control\n> + *\n> + * This algorithm linearizes the sensor output to compensate the sensor\n> + * non-linearities by applying piecewise linear curves to the red, green and\n> + * blue channels.\n> + *\n> + * The curves are specified in the tuning data and defined using 17 points.\n> + *\n> + * - The X coordinates are expressed using 16 intervals, with the first point\n> + *   at X coordinate 0. Each interval is expressed as a 2-bit value DX (from\n> + *   GAMMA_DX_1 to GAMMA_DX_16), stored in the RKISP1_CIF_ISP_GAMMA_DX_LO and\n> + *   RKISP1_CIF_ISP_GAMMA_DX_HI registers. The real interval is equal to\n> + *   \\f$2^{dx+4}\\f$. X coordinates are shared between the red, green and blue\n> + *   curves.\n> + *\n> + * - The Y coordinates are specified as 17 values separately for the\n> + *   red, green and blue channels, with a 12-bit resolution. Each value must be\n> + *   in the [-2048, 2047] range compared to the previous value.\n> + */\n> +\n> +LOG_DEFINE_CATEGORY(RkISP1Gsl)\n> +\n> +static constexpr unsigned int kDegammaXIntervals = 16;\n> +\n> +GammaSensorLinearization::GammaSensorLinearization()\n> +\t: initialized_(false)\n> +{\n> +}\n> +\n> +/**\n> + * \\copydoc libcamera::ipa::Algorithm::init\n> + */\n> +int GammaSensorLinearization::init([[maybe_unused]] IPAContext &context,\n> +\t\t\t\t   const YamlObject &tuningData)\n> +{\n> +\tstd::vector<uint16_t> xIntervals = tuningData[\"x-intervals\"].getList<uint16_t>();\n> +\tif (xIntervals.size() != kDegammaXIntervals) {\n> +\t\tLOG(RkISP1Gsl, Error)\n> +\t\t\t<< \"Invalid 'x' coordinates: expected \"\n> +\t\t\t<< kDegammaXIntervals << \" elements, got \"\n> +\t\t\t<< xIntervals.size();\n> +\n> +\t\treturn -EINVAL;\n> +\t}\n> +\n> +\t/* Compute gammaDx_ intervals from xIntervals values */\n> +\tgammaDx_[0] = 0;\n> +\tgammaDx_[1] = 0;\n> +\tfor (unsigned int i = 0; i < kDegammaXIntervals; ++i)\n> +\t\tgammaDx_[i / 8] |= (xIntervals[i] & 0x07) << ((i % 8) * 4);\n> +\n> +\tconst YamlObject &yObject = tuningData[\"y\"];\n> +\tif (!yObject.isDictionary()) {\n> +\t\tLOG(RkISP1Gsl, Error)\n> +\t\t\t<< \"Issue while parsing 'y' in tuning file: \"\n> +\t\t\t<< \"entry must be a dictionary\";\n> +\t\treturn -EINVAL;\n> +\t}\n> +\n> +\tcurveYr_ = yObject[\"red\"].getList<uint16_t>();\n> +\tif (curveYr_.size() != RKISP1_CIF_ISP_DEGAMMA_CURVE_SIZE) {\n> +\t\tLOG(RkISP1Gsl, Error)\n> +\t\t\t<< \"Invalid 'y:red' coordinates: expected \"\n> +\t\t\t<< RKISP1_CIF_ISP_DEGAMMA_CURVE_SIZE\n> +\t\t\t<< \" elements, got \" << curveYr_.size();\n> +\t\treturn -EINVAL;\n> +\t}\n> +\n> +\tcurveYg_ = yObject[\"green\"].getList<uint16_t>();\n> +\tif (curveYg_.size() != RKISP1_CIF_ISP_DEGAMMA_CURVE_SIZE) {\n> +\t\tLOG(RkISP1Gsl, Error)\n> +\t\t\t<< \"Invalid 'y:green' coordinates: expected \"\n> +\t\t\t<< RKISP1_CIF_ISP_DEGAMMA_CURVE_SIZE\n> +\t\t\t<< \" elements, got \" << curveYg_.size();\n> +\t\treturn -EINVAL;\n> +\t}\n> +\n> +\tcurveYb_ = yObject[\"blue\"].getList<uint16_t>();\n> +\tif (curveYb_.size() != RKISP1_CIF_ISP_DEGAMMA_CURVE_SIZE) {\n> +\t\tLOG(RkISP1Gsl, Error)\n> +\t\t\t<< \"Invalid 'y:blue' coordinates: expected \"\n> +\t\t\t<< RKISP1_CIF_ISP_DEGAMMA_CURVE_SIZE\n> +\t\t\t<< \" elements, got \" << curveYb_.size();\n> +\t\treturn -EINVAL;\n> +\t}\n> +\n> +\tinitialized_ = true;\n> +\treturn 0;\n> +}\n> +\n> +/**\n> + * \\copydoc libcamera::ipa::Algorithm::prepare\n> + */\n> +void GammaSensorLinearization::prepare(IPAContext &context,\n> +\t\t\t\t       rkisp1_params_cfg *params)\n> +{\n> +\tif (context.frameContext.frameCount > 0)\n> +\t\treturn;\n> +\n> +\tif (!initialized_)\n> +\t\treturn;\n> +\n> +\tparams->others.sdg_config.xa_pnts.gamma_dx0 = gammaDx_[0];\n> +\tparams->others.sdg_config.xa_pnts.gamma_dx1 = gammaDx_[1];\n> +\n> +\tstd::copy(curveYr_.begin(), curveYr_.end(),\n> +\t\t  params->others.sdg_config.curve_r.gamma_y);\n> +\tstd::copy(curveYg_.begin(), curveYg_.end(),\n> +\t\t  params->others.sdg_config.curve_g.gamma_y);\n> +\tstd::copy(curveYb_.begin(), curveYb_.end(),\n> +\t\t  params->others.sdg_config.curve_b.gamma_y);\n> +\n> +\tparams->module_en_update |= RKISP1_CIF_ISP_MODULE_SDG;\n> +\tparams->module_ens |= RKISP1_CIF_ISP_MODULE_SDG;\n> +\tparams->module_cfg_update |= RKISP1_CIF_ISP_MODULE_SDG;\n> +}\n> +\n> +REGISTER_IPA_ALGORITHM(GammaSensorLinearization, \"GammaSensorLinearization\")\n> +\n> +} /* namespace ipa::rkisp1::algorithms */\n> +\n> +} /* namespace libcamera */\n> diff --git a/src/ipa/rkisp1/algorithms/gsl.h b/src/ipa/rkisp1/algorithms/gsl.h\n> new file mode 100644\n> index 00000000..db287dc2\n> --- /dev/null\n> +++ b/src/ipa/rkisp1/algorithms/gsl.h\n> @@ -0,0 +1,34 @@\n> +/* SPDX-License-Identifier: LGPL-2.1-or-later */\n> +/*\n> + * Copyright (C) 2021-2022, Ideas On Board\n> + *\n> + * gsl.h - RkISP1 Gamma Sensor Linearization control\n> + */\n> +\n> +#pragma once\n> +\n> +#include \"algorithm.h\"\n> +\n> +namespace libcamera {\n> +\n> +namespace ipa::rkisp1::algorithms {\n> +\n> +class GammaSensorLinearization : public Algorithm\n> +{\n> +public:\n> +\tGammaSensorLinearization();\n> +\t~GammaSensorLinearization() = default;\n> +\n> +\tint init(IPAContext &context, const YamlObject &tuningData) override;\n> +\tvoid prepare(IPAContext &context, rkisp1_params_cfg *params) override;\n> +\n> +private:\n> +\tbool initialized_;\n> +\tuint32_t gammaDx_[2];\n> +\tstd::vector<uint16_t> curveYr_;\n> +\tstd::vector<uint16_t> curveYg_;\n> +\tstd::vector<uint16_t> curveYb_;\n> +};\n> +\n> +} /* namespace ipa::rkisp1::algorithms */\n> +} /* namespace libcamera */\n> diff --git a/src/ipa/rkisp1/algorithms/meson.build b/src/ipa/rkisp1/algorithms/meson.build\n> index 7ec53d89..0597c353 100644\n> --- a/src/ipa/rkisp1/algorithms/meson.build\n> +++ b/src/ipa/rkisp1/algorithms/meson.build\n> @@ -4,4 +4,5 @@ rkisp1_ipa_algorithms = files([\n>      'agc.cpp',\n>      'awb.cpp',\n>      'blc.cpp',\n> +    'gsl.cpp',\n>  ])\n> diff --git a/src/ipa/rkisp1/data/ov5640.yaml b/src/ipa/rkisp1/data/ov5640.yaml\n> index 232d8ae8..13f76412 100644\n> --- a/src/ipa/rkisp1/data/ov5640.yaml\n> +++ b/src/ipa/rkisp1/data/ov5640.yaml\n> @@ -10,4 +10,10 @@ algorithms:\n>        Gr: 256\n>        Gb: 256\n>        B:  256\n> +  - GammaSensorLinearization:\n> +      x-intervals: [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ]\n> +      y:\n> +        red:   [ 0, 256, 512, 768, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 2816, 3072, 3328, 3584, 3840, 4095 ]\n> +        green: [ 0, 256, 512, 768, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 2816, 3072, 3328, 3584, 3840, 4095 ]\n> +        blue:  [ 0, 256, 512, 768, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 2816, 3072, 3328, 3584, 3840, 4095 ]\n>  ...\n> diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp\n> index 4018265c..1c002939 100644\n> --- a/src/ipa/rkisp1/rkisp1.cpp\n> +++ b/src/ipa/rkisp1/rkisp1.cpp\n> @@ -31,6 +31,7 @@\n>  #include \"algorithms/algorithm.h\"\n>  #include \"algorithms/awb.h\"\n>  #include \"algorithms/blc.h\"\n> +#include \"algorithms/gsl.h\"\n\nThis doesn't seem to be needed. Apart from that,\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n>  #include \"libipa/camera_sensor_helper.h\"\n>  \n>  #include \"ipa_context.h\"","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 087A4BE173\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun, 24 Jul 2022 16:19:10 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5E25A63312;\n\tSun, 24 Jul 2022 18:19:09 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id C49506330B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 24 Jul 2022 18:19:07 +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 CC260835;\n\tSun, 24 Jul 2022 18:19:06 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1658679549;\n\tbh=wvbyh2qY22azW828R6KC8+HovjaQoEZwlLg+hdodeOo=;\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=vy1O7yFRCDE5UTYaaYzBau/g8cl2C6TTEc0sIM6wanLyXQ4F0i7wawIAam3uTpu3K\n\tQPrUFDvVguLDCGboYsH1RjLv6dEs8YQyK8wmChHol0MVUiJALeVcpveF38AmIGtmlt\n\tbEJTNH1FLliTgnjWSGaLzbJEhSxreo13+ii3NR3g44a0d7OCJoqlE2iclWqm4/172s\n\tsattdd7SHAkPrOv0yzRT0uywU+F6lBhWLDDkzVYMdu5iuh68uFtF95JVKveJPHum2e\n\tbX3TQMVUT7pPUD1hS3232SnMvt5zAMGfp/7t6X8zVdn2p13PN8c1AEem5lJUsniggR\n\t68awf+Nix9kxQ==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1658679547;\n\tbh=wvbyh2qY22azW828R6KC8+HovjaQoEZwlLg+hdodeOo=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=Rl3yMmaGv4g8ibuNM7w4wf1zV8PmEaGH8K5k+ZMeRR/e6DQB98Vm7S6ePjTKmhvod\n\t49L2A7GGnHBGqrpUEUzyUqfm2jWXhxIo/k0Y0ezArF6+rXl1XY1ifuASapnw720RCZ\n\txX1G5ZU+QHLF+1OEvTyrPKJq+FRaaoTpOY8QndXE="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"Rl3yMmaG\"; dkim-atps=neutral","Date":"Sun, 24 Jul 2022 19:19:03 +0300","To":"Florian Sylvestre <fsylvestre@baylibre.com>","Message-ID":"<Yt1w9wXJOv07KAAh@pendragon.ideasonboard.com>","References":"<20220722151635.239221-1-fsylvestre@baylibre.com>\n\t<20220722151635.239221-3-fsylvestre@baylibre.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20220722151635.239221-3-fsylvestre@baylibre.com>","Subject":"Re: [libcamera-devel] [PATCH v2 2/5] ipa: rkisp1: Add support of\n\tGamma Sensor Linearization control","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":24088,"web_url":"https://patchwork.libcamera.org/comment/24088/","msgid":"<20220725074035.GK3984498@pyrite.rasen.tech>","date":"2022-07-25T07:40:35","subject":"Re: [libcamera-devel] [PATCH v2 2/5] ipa: rkisp1: Add support of\n\tGamma Sensor Linearization control","submitter":{"id":97,"url":"https://patchwork.libcamera.org/api/people/97/","name":"Nicolas Dufresne via libcamera-devel","email":"libcamera-devel@lists.libcamera.org"},"content":"On Fri, Jul 22, 2022 at 05:16:32PM +0200, Florian Sylvestre via libcamera-devel wrote:\n> The GammaSensorLinearization algorithm improves the image dynamic using\n> a coefficient table in the YAML tuning file.\n> The GammaSensorLinearization algorithm linearizes the sensor output to\n> compensate the sensor non-linearities by applying piecewise linear curves to\n> the red, green and blue channels.\n> \n> Signed-off-by: Florian Sylvestre <fsylvestre@baylibre.com>\n\nReviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n\n> ---\n>  src/ipa/rkisp1/algorithms/gsl.cpp     | 147 ++++++++++++++++++++++++++\n>  src/ipa/rkisp1/algorithms/gsl.h       |  34 ++++++\n>  src/ipa/rkisp1/algorithms/meson.build |   1 +\n>  src/ipa/rkisp1/data/ov5640.yaml       |   6 ++\n>  src/ipa/rkisp1/rkisp1.cpp             |   1 +\n>  5 files changed, 189 insertions(+)\n>  create mode 100644 src/ipa/rkisp1/algorithms/gsl.cpp\n>  create mode 100644 src/ipa/rkisp1/algorithms/gsl.h\n> \n> diff --git a/src/ipa/rkisp1/algorithms/gsl.cpp b/src/ipa/rkisp1/algorithms/gsl.cpp\n> new file mode 100644\n> index 00000000..1680ddc3\n> --- /dev/null\n> +++ b/src/ipa/rkisp1/algorithms/gsl.cpp\n> @@ -0,0 +1,147 @@\n> +/* SPDX-License-Identifier: LGPL-2.1-or-later */\n> +/*\n> + * Copyright (C) 2021-2022, Ideas On Board\n> + *\n> + * gsl.cpp - RkISP1 Gamma Sensor Linearization control\n> + */\n> +\n> +#include \"gsl.h\"\n> +\n> +#include <libcamera/base/log.h>\n> +\n> +#include \"libcamera/internal/yaml_parser.h\"\n> +\n> +#include \"linux/rkisp1-config.h\"\n> +\n> +/**\n> + * \\file gsl.h\n> + */\n> +\n> +namespace libcamera {\n> +\n> +namespace ipa::rkisp1::algorithms {\n> +\n> +/**\n> + * \\class GammaSensorLinearization\n> + * \\brief RkISP1 Gamma Sensor Linearization control\n> + *\n> + * This algorithm linearizes the sensor output to compensate the sensor\n> + * non-linearities by applying piecewise linear curves to the red, green and\n> + * blue channels.\n> + *\n> + * The curves are specified in the tuning data and defined using 17 points.\n> + *\n> + * - The X coordinates are expressed using 16 intervals, with the first point\n> + *   at X coordinate 0. Each interval is expressed as a 2-bit value DX (from\n> + *   GAMMA_DX_1 to GAMMA_DX_16), stored in the RKISP1_CIF_ISP_GAMMA_DX_LO and\n> + *   RKISP1_CIF_ISP_GAMMA_DX_HI registers. The real interval is equal to\n> + *   \\f$2^{dx+4}\\f$. X coordinates are shared between the red, green and blue\n> + *   curves.\n> + *\n> + * - The Y coordinates are specified as 17 values separately for the\n> + *   red, green and blue channels, with a 12-bit resolution. Each value must be\n> + *   in the [-2048, 2047] range compared to the previous value.\n> + */\n> +\n> +LOG_DEFINE_CATEGORY(RkISP1Gsl)\n> +\n> +static constexpr unsigned int kDegammaXIntervals = 16;\n> +\n> +GammaSensorLinearization::GammaSensorLinearization()\n> +\t: initialized_(false)\n> +{\n> +}\n> +\n> +/**\n> + * \\copydoc libcamera::ipa::Algorithm::init\n> + */\n> +int GammaSensorLinearization::init([[maybe_unused]] IPAContext &context,\n> +\t\t\t\t   const YamlObject &tuningData)\n> +{\n> +\tstd::vector<uint16_t> xIntervals = tuningData[\"x-intervals\"].getList<uint16_t>();\n> +\tif (xIntervals.size() != kDegammaXIntervals) {\n> +\t\tLOG(RkISP1Gsl, Error)\n> +\t\t\t<< \"Invalid 'x' coordinates: expected \"\n> +\t\t\t<< kDegammaXIntervals << \" elements, got \"\n> +\t\t\t<< xIntervals.size();\n> +\n> +\t\treturn -EINVAL;\n> +\t}\n> +\n> +\t/* Compute gammaDx_ intervals from xIntervals values */\n> +\tgammaDx_[0] = 0;\n> +\tgammaDx_[1] = 0;\n> +\tfor (unsigned int i = 0; i < kDegammaXIntervals; ++i)\n> +\t\tgammaDx_[i / 8] |= (xIntervals[i] & 0x07) << ((i % 8) * 4);\n> +\n> +\tconst YamlObject &yObject = tuningData[\"y\"];\n> +\tif (!yObject.isDictionary()) {\n> +\t\tLOG(RkISP1Gsl, Error)\n> +\t\t\t<< \"Issue while parsing 'y' in tuning file: \"\n> +\t\t\t<< \"entry must be a dictionary\";\n> +\t\treturn -EINVAL;\n> +\t}\n> +\n> +\tcurveYr_ = yObject[\"red\"].getList<uint16_t>();\n> +\tif (curveYr_.size() != RKISP1_CIF_ISP_DEGAMMA_CURVE_SIZE) {\n> +\t\tLOG(RkISP1Gsl, Error)\n> +\t\t\t<< \"Invalid 'y:red' coordinates: expected \"\n> +\t\t\t<< RKISP1_CIF_ISP_DEGAMMA_CURVE_SIZE\n> +\t\t\t<< \" elements, got \" << curveYr_.size();\n> +\t\treturn -EINVAL;\n> +\t}\n> +\n> +\tcurveYg_ = yObject[\"green\"].getList<uint16_t>();\n> +\tif (curveYg_.size() != RKISP1_CIF_ISP_DEGAMMA_CURVE_SIZE) {\n> +\t\tLOG(RkISP1Gsl, Error)\n> +\t\t\t<< \"Invalid 'y:green' coordinates: expected \"\n> +\t\t\t<< RKISP1_CIF_ISP_DEGAMMA_CURVE_SIZE\n> +\t\t\t<< \" elements, got \" << curveYg_.size();\n> +\t\treturn -EINVAL;\n> +\t}\n> +\n> +\tcurveYb_ = yObject[\"blue\"].getList<uint16_t>();\n> +\tif (curveYb_.size() != RKISP1_CIF_ISP_DEGAMMA_CURVE_SIZE) {\n> +\t\tLOG(RkISP1Gsl, Error)\n> +\t\t\t<< \"Invalid 'y:blue' coordinates: expected \"\n> +\t\t\t<< RKISP1_CIF_ISP_DEGAMMA_CURVE_SIZE\n> +\t\t\t<< \" elements, got \" << curveYb_.size();\n> +\t\treturn -EINVAL;\n> +\t}\n> +\n> +\tinitialized_ = true;\n> +\treturn 0;\n> +}\n> +\n> +/**\n> + * \\copydoc libcamera::ipa::Algorithm::prepare\n> + */\n> +void GammaSensorLinearization::prepare(IPAContext &context,\n> +\t\t\t\t       rkisp1_params_cfg *params)\n> +{\n> +\tif (context.frameContext.frameCount > 0)\n> +\t\treturn;\n> +\n> +\tif (!initialized_)\n> +\t\treturn;\n> +\n> +\tparams->others.sdg_config.xa_pnts.gamma_dx0 = gammaDx_[0];\n> +\tparams->others.sdg_config.xa_pnts.gamma_dx1 = gammaDx_[1];\n> +\n> +\tstd::copy(curveYr_.begin(), curveYr_.end(),\n> +\t\t  params->others.sdg_config.curve_r.gamma_y);\n> +\tstd::copy(curveYg_.begin(), curveYg_.end(),\n> +\t\t  params->others.sdg_config.curve_g.gamma_y);\n> +\tstd::copy(curveYb_.begin(), curveYb_.end(),\n> +\t\t  params->others.sdg_config.curve_b.gamma_y);\n> +\n> +\tparams->module_en_update |= RKISP1_CIF_ISP_MODULE_SDG;\n> +\tparams->module_ens |= RKISP1_CIF_ISP_MODULE_SDG;\n> +\tparams->module_cfg_update |= RKISP1_CIF_ISP_MODULE_SDG;\n> +}\n> +\n> +REGISTER_IPA_ALGORITHM(GammaSensorLinearization, \"GammaSensorLinearization\")\n> +\n> +} /* namespace ipa::rkisp1::algorithms */\n> +\n> +} /* namespace libcamera */\n> diff --git a/src/ipa/rkisp1/algorithms/gsl.h b/src/ipa/rkisp1/algorithms/gsl.h\n> new file mode 100644\n> index 00000000..db287dc2\n> --- /dev/null\n> +++ b/src/ipa/rkisp1/algorithms/gsl.h\n> @@ -0,0 +1,34 @@\n> +/* SPDX-License-Identifier: LGPL-2.1-or-later */\n> +/*\n> + * Copyright (C) 2021-2022, Ideas On Board\n> + *\n> + * gsl.h - RkISP1 Gamma Sensor Linearization control\n> + */\n> +\n> +#pragma once\n> +\n> +#include \"algorithm.h\"\n> +\n> +namespace libcamera {\n> +\n> +namespace ipa::rkisp1::algorithms {\n> +\n> +class GammaSensorLinearization : public Algorithm\n> +{\n> +public:\n> +\tGammaSensorLinearization();\n> +\t~GammaSensorLinearization() = default;\n> +\n> +\tint init(IPAContext &context, const YamlObject &tuningData) override;\n> +\tvoid prepare(IPAContext &context, rkisp1_params_cfg *params) override;\n> +\n> +private:\n> +\tbool initialized_;\n> +\tuint32_t gammaDx_[2];\n> +\tstd::vector<uint16_t> curveYr_;\n> +\tstd::vector<uint16_t> curveYg_;\n> +\tstd::vector<uint16_t> curveYb_;\n> +};\n> +\n> +} /* namespace ipa::rkisp1::algorithms */\n> +} /* namespace libcamera */\n> diff --git a/src/ipa/rkisp1/algorithms/meson.build b/src/ipa/rkisp1/algorithms/meson.build\n> index 7ec53d89..0597c353 100644\n> --- a/src/ipa/rkisp1/algorithms/meson.build\n> +++ b/src/ipa/rkisp1/algorithms/meson.build\n> @@ -4,4 +4,5 @@ rkisp1_ipa_algorithms = files([\n>      'agc.cpp',\n>      'awb.cpp',\n>      'blc.cpp',\n> +    'gsl.cpp',\n>  ])\n> diff --git a/src/ipa/rkisp1/data/ov5640.yaml b/src/ipa/rkisp1/data/ov5640.yaml\n> index 232d8ae8..13f76412 100644\n> --- a/src/ipa/rkisp1/data/ov5640.yaml\n> +++ b/src/ipa/rkisp1/data/ov5640.yaml\n> @@ -10,4 +10,10 @@ algorithms:\n>        Gr: 256\n>        Gb: 256\n>        B:  256\n> +  - GammaSensorLinearization:\n> +      x-intervals: [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ]\n> +      y:\n> +        red:   [ 0, 256, 512, 768, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 2816, 3072, 3328, 3584, 3840, 4095 ]\n> +        green: [ 0, 256, 512, 768, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 2816, 3072, 3328, 3584, 3840, 4095 ]\n> +        blue:  [ 0, 256, 512, 768, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 2816, 3072, 3328, 3584, 3840, 4095 ]\n>  ...\n> diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp\n> index 4018265c..1c002939 100644\n> --- a/src/ipa/rkisp1/rkisp1.cpp\n> +++ b/src/ipa/rkisp1/rkisp1.cpp\n> @@ -31,6 +31,7 @@\n>  #include \"algorithms/algorithm.h\"\n>  #include \"algorithms/awb.h\"\n>  #include \"algorithms/blc.h\"\n> +#include \"algorithms/gsl.h\"\n>  #include \"libipa/camera_sensor_helper.h\"\n>  \n>  #include \"ipa_context.h\"\n> -- \n> 2.34.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 3C46FC3275\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 25 Jul 2022 07:40:45 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E58C163312;\n\tMon, 25 Jul 2022 09:40:44 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id ED3F263309\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 25 Jul 2022 09:40:42 +0200 (CEST)","from pyrite.rasen.tech (h175-177-042-159.catv02.itscom.jp\n\t[175.177.42.159])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id B2DF86DD;\n\tMon, 25 Jul 2022 09:40:41 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1658734844;\n\tbh=GgVhB/tsuhJ0hiQ6QONQqtIRhqOsE6PIfiQDbIvqrTc=;\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=VkVM7qf3MZWods13gaAOTu0dtMdfBOnMzJYHbzzNVztEEt7BtFY3N3o+HEVt2H1vS\n\tatcxz0z4WQNoOQzGXliRc02+95q17MO+LwkVPKTBFj/YWoTHJx2j8Ae18ElFSiOylA\n\tkLw8esJBwcAZNEAIQZ2Rdi1GoRDkjRqBOyw0SA3oFMtb0k+ZN84qmbNCD5z2NG2NVb\n\tY8tVA9rMUulwAlxEDqKJqzF3vYNvcafuynUjkd4pJ7w02wNy2gT1RxEzxLWLB+PraX\n\t+Dd5sK0mIxLbW6Iyp8eYdz0/jAh/Nbd8BFw0c8eLnyDukGIEDhLuGesB7BNAViHqfU\n\tPHte2+f/0YJDw==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1658734842;\n\tbh=GgVhB/tsuhJ0hiQ6QONQqtIRhqOsE6PIfiQDbIvqrTc=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=EKm7ZRVG/Je8W3Q2wFDhrbg7Ma0rGcFc4EPsZj/30jRPtdamgaeu7o9rBaFYEHe6Y\n\tCVUTUKsB2ZWPh0065wdOKkvC4ndkm23gB03aN8bCo3vwvg7TWlqFVl2+slSKmqO7V8\n\tTxvqAhCqILe/BcOqCQcCNd0J/x5ysVN8YwBGHsSE="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"EKm7ZRVG\"; dkim-atps=neutral","Date":"Mon, 25 Jul 2022 16:40:35 +0900","To":"Florian Sylvestre <fsylvestre@baylibre.com>","Message-ID":"<20220725074035.GK3984498@pyrite.rasen.tech>","References":"<20220722151635.239221-1-fsylvestre@baylibre.com>\n\t<20220722151635.239221-3-fsylvestre@baylibre.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<20220722151635.239221-3-fsylvestre@baylibre.com>","Subject":"Re: [libcamera-devel] [PATCH v2 2/5] ipa: rkisp1: Add support of\n\tGamma Sensor Linearization control","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":"Paul Elder via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"paul.elder@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>"}}]