[{"id":21563,"web_url":"https://patchwork.libcamera.org/comment/21563/","msgid":"<YamDlOhWjJY9sRFu@pendragon.ideasonboard.com>","date":"2021-12-03T02:40:20","subject":"Re: [libcamera-devel] [PATCH v1 5/6] ipa: rkisp1: Introduce\n\tcrosstalk 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\nOn Thu, Dec 02, 2021 at 07:04:09PM +0100, Jean-Michel Hautbois wrote:\n> Introduce the color correction matrix for the RkISP1 based on a simple\n> assumptions on the gains until we can tune the sensor properly.\n> \n> Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>\n> ---\n>  src/ipa/rkisp1/algorithms/ctk.cpp     | 59 +++++++++++++++++++++++++++\n>  src/ipa/rkisp1/algorithms/ctk.h       | 30 ++++++++++++++\n>  src/ipa/rkisp1/algorithms/meson.build |  1 +\n>  src/ipa/rkisp1/rkisp1.cpp             |  2 +\n>  4 files changed, 92 insertions(+)\n>  create mode 100644 src/ipa/rkisp1/algorithms/ctk.cpp\n>  create mode 100644 src/ipa/rkisp1/algorithms/ctk.h\n> \n> diff --git a/src/ipa/rkisp1/algorithms/ctk.cpp b/src/ipa/rkisp1/algorithms/ctk.cpp\n> new file mode 100644\n> index 000000000..81600e776\n> --- /dev/null\n> +++ b/src/ipa/rkisp1/algorithms/ctk.cpp\n> @@ -0,0 +1,59 @@\n> +/* SPDX-License-Identifier: LGPL-2.1-or-later */\n> +/*\n> + * Copyright (C) 2021, Ideas On Board\n> + *\n> + * ctk.cpp - RkISP1 Cross-Talk Correction control\n> + */\n> +\n> +#include \"ctk.h\"\n> +\n> +/**\n> + * \\file ctk.h\n> + */\n> +\n> +namespace libcamera {\n> +\n> +namespace ipa::rkisp1::algorithms {\n> +\n> +/**\n> + * \\class CrossTalkCorrection\n> + * \\brief RkISP1 Cross-Talk Correction control (color correction matrix)\n> + *\n> + * The crosstalk in image sensor is an effect when signal from a specific pixel\n> + * is affected by its adjacent pixels. An image sensor can be considered as a\n> + * linear system, with linear crosstalk existing only between horizontal and\n> + * vertical neighboring pixels. This matrix should be calculated based on tuning\n> + * but a first approximation can be obtained by using the grey-world gains and\n> + * applying them to their respective channel.\n> + */\n> +\n> +/**\n> + * \\copydoc libcamera::ipa::Algorithm::prepare\n> + */\n> +void CrossTalkCorrection::prepare([[maybe_unused]] IPAContext &context,\n> +\t\t\t\t  rkisp1_params_cfg *params)\n> +{\n> +\tparams->others.ctk_config.coeff[0][0] = 128 * context.frameContext.awb.gains.red;\n> +\tparams->others.ctk_config.coeff[0][1] = 0;\n> +\tparams->others.ctk_config.coeff[0][2] = 0;\n> +\n> +\tparams->others.ctk_config.coeff[1][0] = 0;\n> +\tparams->others.ctk_config.coeff[1][1] = 128 * context.frameContext.awb.gains.green;\n> +\tparams->others.ctk_config.coeff[1][2] = 0;\n> +\n> +\tparams->others.ctk_config.coeff[2][0] = 0;\n> +\tparams->others.ctk_config.coeff[2][1] = 0;\n> +\tparams->others.ctk_config.coeff[2][2] = 128 * context.frameContext.awb.gains.blue;\n\nI don't get it, won't this essentially apply the AWB gains a second time\n?\n\n> +\n> +\tparams->others.ctk_config.ct_offset[0] = 0;\n> +\tparams->others.ctk_config.ct_offset[1] = 0;\n> +\tparams->others.ctk_config.ct_offset[2] = 0;\n> +\n> +\tparams->module_en_update |= RKISP1_CIF_ISP_MODULE_CTK;\n> +\tparams->module_ens |= RKISP1_CIF_ISP_MODULE_CTK;\n> +\tparams->module_cfg_update |= RKISP1_CIF_ISP_MODULE_CTK;\n> +}\n> +\n> +} /* namespace ipa::rkisp1::algorithms */\n> +\n> +} /* namespace libcamera */\n> diff --git a/src/ipa/rkisp1/algorithms/ctk.h b/src/ipa/rkisp1/algorithms/ctk.h\n> new file mode 100644\n> index 000000000..c4d240e2d\n> --- /dev/null\n> +++ b/src/ipa/rkisp1/algorithms/ctk.h\n> @@ -0,0 +1,30 @@\n> +/* SPDX-License-Identifier: LGPL-2.1-or-later */\n> +/*\n> + * Copyright (C) 2021, Ideas On Board\n> + *\n> + * blc.h - RkISP1 Cross-Talk Correction control\n> + */\n> +\n> +#pragma once\n> +\n> +#include <linux/rkisp1-config.h>\n> +\n> +#include \"algorithm.h\"\n> +\n> +namespace libcamera {\n> +\n> +struct IPACameraSensorInfo;\n> +\n> +namespace ipa::rkisp1::algorithms {\n> +\n> +class CrossTalkCorrection : public Algorithm\n> +{\n> +public:\n> +\tCrossTalkCorrection() = default;\n> +\t~CrossTalkCorrection() = default;\n> +\n> +\tvoid prepare(IPAContext &context, rkisp1_params_cfg *params) override;\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 faec0eb3e..482e88474 100644\n> --- a/src/ipa/rkisp1/algorithms/meson.build\n> +++ b/src/ipa/rkisp1/algorithms/meson.build\n> @@ -4,5 +4,6 @@ rkisp1_ipa_algorithms = files([\n>      'agc.cpp',\n>      'awb.cpp',\n>      'blc.cpp',\n> +    'ctk.cpp',\n>      'sdg.cpp',\n>  ])\n> diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp\n> index 979f28420..21a9d15b9 100644\n> --- a/src/ipa/rkisp1/rkisp1.cpp\n> +++ b/src/ipa/rkisp1/rkisp1.cpp\n> @@ -29,6 +29,7 @@\n>  #include \"algorithms/algorithm.h\"\n>  #include \"algorithms/awb.h\"\n>  #include \"algorithms/blc.h\"\n> +#include \"algorithms/ctk.h\"\n>  #include \"algorithms/sdg.h\"\n>  #include \"libipa/camera_sensor_helper.h\"\n>  \n> @@ -130,6 +131,7 @@ int IPARkISP1::init(const IPASettings &settings, unsigned int hwRevision)\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::CrossTalkCorrection>());\n>  \talgorithms_.push_back(std::make_unique<algorithms::SensorDeGamma>());\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 4EEB7BDB13\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  3 Dec 2021 02:40:49 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 932B960592;\n\tFri,  3 Dec 2021 03:40:48 +0100 (CET)","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 0DC1F60118\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  3 Dec 2021 03:40:47 +0100 (CET)","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 8CC5BA59;\n\tFri,  3 Dec 2021 03:40:46 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"vow51fFl\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1638499246;\n\tbh=KLGInfDp5FMfFOTfPu6HhC7ufNILPao8JTfp70dinag=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=vow51fFlkTaKi/jEl2RZylxc1V3f8pElUzswWaYwbRV+AyAxZo5KU6FLo8n+7WgdH\n\tszuEyaRkXg0tugrjf8RPdQbcP+dmzzRPa+oYt2RrGodvyfcI3jh4OrG0n1Yal/wkcj\n\tjVQOa50QlZKEJ446DBykOTC3TPbEUE/vipWZB5wg=","Date":"Fri, 3 Dec 2021 04:40:20 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>","Message-ID":"<YamDlOhWjJY9sRFu@pendragon.ideasonboard.com>","References":"<20211202180410.518232-1-jeanmichel.hautbois@ideasonboard.com>\n\t<20211202180410.518232-6-jeanmichel.hautbois@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20211202180410.518232-6-jeanmichel.hautbois@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v1 5/6] ipa: rkisp1: Introduce\n\tcrosstalk 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>"}},{"id":21565,"web_url":"https://patchwork.libcamera.org/comment/21565/","msgid":"<71d22a2f-8070-a8aa-c456-5bc924e97785@ideasonboard.com>","date":"2021-12-03T06:57:18","subject":"Re: [libcamera-devel] [PATCH v1 5/6] ipa: rkisp1: Introduce\n\tcrosstalk correction","submitter":{"id":75,"url":"https://patchwork.libcamera.org/api/people/75/","name":"Jean-Michel Hautbois","email":"jeanmichel.hautbois@ideasonboard.com"},"content":"Hi Laurent,\n\nOn 03/12/2021 03:40, Laurent Pinchart wrote:\n> Hi Jean-Michel,\n> \n> On Thu, Dec 02, 2021 at 07:04:09PM +0100, Jean-Michel Hautbois wrote:\n>> Introduce the color correction matrix for the RkISP1 based on a simple\n>> assumptions on the gains until we can tune the sensor properly.\n>>\n>> Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>\n>> ---\n>>   src/ipa/rkisp1/algorithms/ctk.cpp     | 59 +++++++++++++++++++++++++++\n>>   src/ipa/rkisp1/algorithms/ctk.h       | 30 ++++++++++++++\n>>   src/ipa/rkisp1/algorithms/meson.build |  1 +\n>>   src/ipa/rkisp1/rkisp1.cpp             |  2 +\n>>   4 files changed, 92 insertions(+)\n>>   create mode 100644 src/ipa/rkisp1/algorithms/ctk.cpp\n>>   create mode 100644 src/ipa/rkisp1/algorithms/ctk.h\n>>\n>> diff --git a/src/ipa/rkisp1/algorithms/ctk.cpp b/src/ipa/rkisp1/algorithms/ctk.cpp\n>> new file mode 100644\n>> index 000000000..81600e776\n>> --- /dev/null\n>> +++ b/src/ipa/rkisp1/algorithms/ctk.cpp\n>> @@ -0,0 +1,59 @@\n>> +/* SPDX-License-Identifier: LGPL-2.1-or-later */\n>> +/*\n>> + * Copyright (C) 2021, Ideas On Board\n>> + *\n>> + * ctk.cpp - RkISP1 Cross-Talk Correction control\n>> + */\n>> +\n>> +#include \"ctk.h\"\n>> +\n>> +/**\n>> + * \\file ctk.h\n>> + */\n>> +\n>> +namespace libcamera {\n>> +\n>> +namespace ipa::rkisp1::algorithms {\n>> +\n>> +/**\n>> + * \\class CrossTalkCorrection\n>> + * \\brief RkISP1 Cross-Talk Correction control (color correction matrix)\n>> + *\n>> + * The crosstalk in image sensor is an effect when signal from a specific pixel\n>> + * is affected by its adjacent pixels. An image sensor can be considered as a\n>> + * linear system, with linear crosstalk existing only between horizontal and\n>> + * vertical neighboring pixels. This matrix should be calculated based on tuning\n>> + * but a first approximation can be obtained by using the grey-world gains and\n>> + * applying them to their respective channel.\n>> + */\n>> +\n>> +/**\n>> + * \\copydoc libcamera::ipa::Algorithm::prepare\n>> + */\n>> +void CrossTalkCorrection::prepare([[maybe_unused]] IPAContext &context,\n>> +\t\t\t\t  rkisp1_params_cfg *params)\n>> +{\n>> +\tparams->others.ctk_config.coeff[0][0] = 128 * context.frameContext.awb.gains.red;\n>> +\tparams->others.ctk_config.coeff[0][1] = 0;\n>> +\tparams->others.ctk_config.coeff[0][2] = 0;\n>> +\n>> +\tparams->others.ctk_config.coeff[1][0] = 0;\n>> +\tparams->others.ctk_config.coeff[1][1] = 128 * context.frameContext.awb.gains.green;\n>> +\tparams->others.ctk_config.coeff[1][2] = 0;\n>> +\n>> +\tparams->others.ctk_config.coeff[2][0] = 0;\n>> +\tparams->others.ctk_config.coeff[2][1] = 0;\n>> +\tparams->others.ctk_config.coeff[2][2] = 128 * context.frameContext.awb.gains.blue;\n> \n> I don't get it, won't this essentially apply the AWB gains a second time\n> ?\n> \n\nThat's what I thought, but if you look closely to the CCM matrices in \nimx219 json data file, you will notice that the numbers are more than 1 \non the diagonals. For example, the CCM matrix for a color temperature of \n5716K is :\n{\n\t 1.80439, -0.73699, -0.06739,\n\t-0.36073,  1.83327, -0.47255,\n\t-0.08378, -0.56403,  1.64781\n}\n\nThe sums on the rows should be 1 (this is not the case here) to preserve \ngrey. So, we could imagine having -64*gain for the other values in the \nrows. Until I can repair my SD connector I won't be able to go test it \nthough... :-(\n\n>> +\n>> +\tparams->others.ctk_config.ct_offset[0] = 0;\n>> +\tparams->others.ctk_config.ct_offset[1] = 0;\n>> +\tparams->others.ctk_config.ct_offset[2] = 0;\n>> +\n>> +\tparams->module_en_update |= RKISP1_CIF_ISP_MODULE_CTK;\n>> +\tparams->module_ens |= RKISP1_CIF_ISP_MODULE_CTK;\n>> +\tparams->module_cfg_update |= RKISP1_CIF_ISP_MODULE_CTK;\n>> +}\n>> +\n>> +} /* namespace ipa::rkisp1::algorithms */\n>> +\n>> +} /* namespace libcamera */\n>> diff --git a/src/ipa/rkisp1/algorithms/ctk.h b/src/ipa/rkisp1/algorithms/ctk.h\n>> new file mode 100644\n>> index 000000000..c4d240e2d\n>> --- /dev/null\n>> +++ b/src/ipa/rkisp1/algorithms/ctk.h\n>> @@ -0,0 +1,30 @@\n>> +/* SPDX-License-Identifier: LGPL-2.1-or-later */\n>> +/*\n>> + * Copyright (C) 2021, Ideas On Board\n>> + *\n>> + * blc.h - RkISP1 Cross-Talk Correction control\n>> + */\n>> +\n>> +#pragma once\n>> +\n>> +#include <linux/rkisp1-config.h>\n>> +\n>> +#include \"algorithm.h\"\n>> +\n>> +namespace libcamera {\n>> +\n>> +struct IPACameraSensorInfo;\n>> +\n>> +namespace ipa::rkisp1::algorithms {\n>> +\n>> +class CrossTalkCorrection : public Algorithm\n>> +{\n>> +public:\n>> +\tCrossTalkCorrection() = default;\n>> +\t~CrossTalkCorrection() = default;\n>> +\n>> +\tvoid prepare(IPAContext &context, rkisp1_params_cfg *params) override;\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 faec0eb3e..482e88474 100644\n>> --- a/src/ipa/rkisp1/algorithms/meson.build\n>> +++ b/src/ipa/rkisp1/algorithms/meson.build\n>> @@ -4,5 +4,6 @@ rkisp1_ipa_algorithms = files([\n>>       'agc.cpp',\n>>       'awb.cpp',\n>>       'blc.cpp',\n>> +    'ctk.cpp',\n>>       'sdg.cpp',\n>>   ])\n>> diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp\n>> index 979f28420..21a9d15b9 100644\n>> --- a/src/ipa/rkisp1/rkisp1.cpp\n>> +++ b/src/ipa/rkisp1/rkisp1.cpp\n>> @@ -29,6 +29,7 @@\n>>   #include \"algorithms/algorithm.h\"\n>>   #include \"algorithms/awb.h\"\n>>   #include \"algorithms/blc.h\"\n>> +#include \"algorithms/ctk.h\"\n>>   #include \"algorithms/sdg.h\"\n>>   #include \"libipa/camera_sensor_helper.h\"\n>>   \n>> @@ -130,6 +131,7 @@ int IPARkISP1::init(const IPASettings &settings, unsigned int hwRevision)\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::CrossTalkCorrection>());\n>>   \talgorithms_.push_back(std::make_unique<algorithms::SensorDeGamma>());\n>>   \n>>   \treturn 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 F4204BF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  3 Dec 2021 06:57:24 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3C0FD605B8;\n\tFri,  3 Dec 2021 07:57:24 +0100 (CET)","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 499DB60118\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  3 Dec 2021 07:57:21 +0100 (CET)","from [IPV6:2a01:e0a:169:7140:458d:6388:c3ac:74bf] (unknown\n\t[IPv6:2a01:e0a:169:7140:458d:6388:c3ac:74bf])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id F2A48A59;\n\tFri,  3 Dec 2021 07:57:20 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"ps6d3FbY\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1638514641;\n\tbh=psLLDl33xuymA7kko3AJ+jLiPUP9RMPhxG2n2vXvUEY=;\n\th=Date:Subject:To:Cc:References:From:In-Reply-To:From;\n\tb=ps6d3FbYyITPZaqtm+fc7LfTTC7HqVCHbhXDGJcz2AuqZJe307qVAfFpr7+TDRUN6\n\tYjASjWdQSbBUmarE9n/b5qMFziKCkr+Gn0W0VbdftvasyYzNPCKVMgyYARQ4Y2BkIR\n\tQzYxu1Q9GGLMCRGFB9RUxT35bU1xbw4lJvPkBkG4=","Message-ID":"<71d22a2f-8070-a8aa-c456-5bc924e97785@ideasonboard.com>","Date":"Fri, 3 Dec 2021 07:57:18 +0100","MIME-Version":"1.0","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101\n\tThunderbird/91.3.1","Content-Language":"en-US","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","References":"<20211202180410.518232-1-jeanmichel.hautbois@ideasonboard.com>\n\t<20211202180410.518232-6-jeanmichel.hautbois@ideasonboard.com>\n\t<YamDlOhWjJY9sRFu@pendragon.ideasonboard.com>","From":"Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>","In-Reply-To":"<YamDlOhWjJY9sRFu@pendragon.ideasonboard.com>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"7bit","Subject":"Re: [libcamera-devel] [PATCH v1 5/6] ipa: rkisp1: Introduce\n\tcrosstalk 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>"}},{"id":21569,"web_url":"https://patchwork.libcamera.org/comment/21569/","msgid":"<YanktvcED3EeDdtE@pendragon.ideasonboard.com>","date":"2021-12-03T09:34:46","subject":"Re: [libcamera-devel] [PATCH v1 5/6] ipa: rkisp1: Introduce\n\tcrosstalk 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\nOn Fri, Dec 03, 2021 at 07:57:18AM +0100, Jean-Michel Hautbois wrote:\n> On 03/12/2021 03:40, Laurent Pinchart wrote:\n> > On Thu, Dec 02, 2021 at 07:04:09PM +0100, Jean-Michel Hautbois wrote:\n> >> Introduce the color correction matrix for the RkISP1 based on a simple\n> >> assumptions on the gains until we can tune the sensor properly.\n> >>\n> >> Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>\n> >> ---\n> >>   src/ipa/rkisp1/algorithms/ctk.cpp     | 59 +++++++++++++++++++++++++++\n> >>   src/ipa/rkisp1/algorithms/ctk.h       | 30 ++++++++++++++\n> >>   src/ipa/rkisp1/algorithms/meson.build |  1 +\n> >>   src/ipa/rkisp1/rkisp1.cpp             |  2 +\n> >>   4 files changed, 92 insertions(+)\n> >>   create mode 100644 src/ipa/rkisp1/algorithms/ctk.cpp\n> >>   create mode 100644 src/ipa/rkisp1/algorithms/ctk.h\n> >>\n> >> diff --git a/src/ipa/rkisp1/algorithms/ctk.cpp b/src/ipa/rkisp1/algorithms/ctk.cpp\n> >> new file mode 100644\n> >> index 000000000..81600e776\n> >> --- /dev/null\n> >> +++ b/src/ipa/rkisp1/algorithms/ctk.cpp\n> >> @@ -0,0 +1,59 @@\n> >> +/* SPDX-License-Identifier: LGPL-2.1-or-later */\n> >> +/*\n> >> + * Copyright (C) 2021, Ideas On Board\n> >> + *\n> >> + * ctk.cpp - RkISP1 Cross-Talk Correction control\n> >> + */\n> >> +\n> >> +#include \"ctk.h\"\n> >> +\n> >> +/**\n> >> + * \\file ctk.h\n> >> + */\n> >> +\n> >> +namespace libcamera {\n> >> +\n> >> +namespace ipa::rkisp1::algorithms {\n> >> +\n> >> +/**\n> >> + * \\class CrossTalkCorrection\n> >> + * \\brief RkISP1 Cross-Talk Correction control (color correction matrix)\n> >> + *\n> >> + * The crosstalk in image sensor is an effect when signal from a specific pixel\n> >> + * is affected by its adjacent pixels. An image sensor can be considered as a\n> >> + * linear system, with linear crosstalk existing only between horizontal and\n> >> + * vertical neighboring pixels. This matrix should be calculated based on tuning\n> >> + * but a first approximation can be obtained by using the grey-world gains and\n> >> + * applying them to their respective channel.\n> >> + */\n> >> +\n> >> +/**\n> >> + * \\copydoc libcamera::ipa::Algorithm::prepare\n> >> + */\n> >> +void CrossTalkCorrection::prepare([[maybe_unused]] IPAContext &context,\n> >> +\t\t\t\t  rkisp1_params_cfg *params)\n> >> +{\n> >> +\tparams->others.ctk_config.coeff[0][0] = 128 * context.frameContext.awb.gains.red;\n> >> +\tparams->others.ctk_config.coeff[0][1] = 0;\n> >> +\tparams->others.ctk_config.coeff[0][2] = 0;\n> >> +\n> >> +\tparams->others.ctk_config.coeff[1][0] = 0;\n> >> +\tparams->others.ctk_config.coeff[1][1] = 128 * context.frameContext.awb.gains.green;\n> >> +\tparams->others.ctk_config.coeff[1][2] = 0;\n> >> +\n> >> +\tparams->others.ctk_config.coeff[2][0] = 0;\n> >> +\tparams->others.ctk_config.coeff[2][1] = 0;\n> >> +\tparams->others.ctk_config.coeff[2][2] = 128 * context.frameContext.awb.gains.blue;\n> > \n> > I don't get it, won't this essentially apply the AWB gains a second time\n> > ?\n> \n> That's what I thought, but if you look closely to the CCM matrices in \n> imx219 json data file, you will notice that the numbers are more than 1 \n> on the diagonals. For example, the CCM matrix for a color temperature of \n> 5716K is :\n> {\n> \t 1.80439, -0.73699, -0.06739,\n> \t-0.36073,  1.83327, -0.47255,\n> \t-0.08378, -0.56403,  1.64781\n> }\n\nSure, but that's still not related to the AWB colour gains. Throwing\nrandom values in the CCM doesn't seem like a very good strategy to me.\nIf you want to use it, you should understand how to calibrate it.\n\n> The sums on the rows should be 1 (this is not the case here) to preserve \n> grey. So, we could imagine having -64*gain for the other values in the \n> rows. Until I can repair my SD connector I won't be able to go test it \n> though... :-(\n> \n> >> +\n> >> +\tparams->others.ctk_config.ct_offset[0] = 0;\n> >> +\tparams->others.ctk_config.ct_offset[1] = 0;\n> >> +\tparams->others.ctk_config.ct_offset[2] = 0;\n> >> +\n> >> +\tparams->module_en_update |= RKISP1_CIF_ISP_MODULE_CTK;\n> >> +\tparams->module_ens |= RKISP1_CIF_ISP_MODULE_CTK;\n> >> +\tparams->module_cfg_update |= RKISP1_CIF_ISP_MODULE_CTK;\n> >> +}\n> >> +\n> >> +} /* namespace ipa::rkisp1::algorithms */\n> >> +\n> >> +} /* namespace libcamera */\n> >> diff --git a/src/ipa/rkisp1/algorithms/ctk.h b/src/ipa/rkisp1/algorithms/ctk.h\n> >> new file mode 100644\n> >> index 000000000..c4d240e2d\n> >> --- /dev/null\n> >> +++ b/src/ipa/rkisp1/algorithms/ctk.h\n> >> @@ -0,0 +1,30 @@\n> >> +/* SPDX-License-Identifier: LGPL-2.1-or-later */\n> >> +/*\n> >> + * Copyright (C) 2021, Ideas On Board\n> >> + *\n> >> + * blc.h - RkISP1 Cross-Talk Correction control\n> >> + */\n> >> +\n> >> +#pragma once\n> >> +\n> >> +#include <linux/rkisp1-config.h>\n> >> +\n> >> +#include \"algorithm.h\"\n> >> +\n> >> +namespace libcamera {\n> >> +\n> >> +struct IPACameraSensorInfo;\n> >> +\n> >> +namespace ipa::rkisp1::algorithms {\n> >> +\n> >> +class CrossTalkCorrection : public Algorithm\n> >> +{\n> >> +public:\n> >> +\tCrossTalkCorrection() = default;\n> >> +\t~CrossTalkCorrection() = default;\n> >> +\n> >> +\tvoid prepare(IPAContext &context, rkisp1_params_cfg *params) override;\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 faec0eb3e..482e88474 100644\n> >> --- a/src/ipa/rkisp1/algorithms/meson.build\n> >> +++ b/src/ipa/rkisp1/algorithms/meson.build\n> >> @@ -4,5 +4,6 @@ rkisp1_ipa_algorithms = files([\n> >>       'agc.cpp',\n> >>       'awb.cpp',\n> >>       'blc.cpp',\n> >> +    'ctk.cpp',\n> >>       'sdg.cpp',\n> >>   ])\n> >> diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp\n> >> index 979f28420..21a9d15b9 100644\n> >> --- a/src/ipa/rkisp1/rkisp1.cpp\n> >> +++ b/src/ipa/rkisp1/rkisp1.cpp\n> >> @@ -29,6 +29,7 @@\n> >>   #include \"algorithms/algorithm.h\"\n> >>   #include \"algorithms/awb.h\"\n> >>   #include \"algorithms/blc.h\"\n> >> +#include \"algorithms/ctk.h\"\n> >>   #include \"algorithms/sdg.h\"\n> >>   #include \"libipa/camera_sensor_helper.h\"\n> >>   \n> >> @@ -130,6 +131,7 @@ int IPARkISP1::init(const IPASettings &settings, unsigned int hwRevision)\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::CrossTalkCorrection>());\n> >>   \talgorithms_.push_back(std::make_unique<algorithms::SensorDeGamma>());\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 04BEABF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  3 Dec 2021 09:35:15 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 41E2960836;\n\tFri,  3 Dec 2021 10:35:14 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 7816060710\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  3 Dec 2021 10:35:13 +0100 (CET)","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 D72BBA59;\n\tFri,  3 Dec 2021 10:35:12 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"hz/A3RgS\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1638524113;\n\tbh=EBjlLddinLQrjBmW1U65d8+G1lvxO0yl8ybPnPpeNEk=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=hz/A3RgSCgfLGMa09uEDExjxeFrdLdFZnja9aYT4NnChbCsOfxHsmTcgni152iIGz\n\tl5JEafGldjc3aRDqeE75AHQckRZDDPxJ8+rIHz4tFdb3pGJRrWOm0lyGEnus4skU/J\n\tUAVRbiMXBy5y2YjWoFzqZnNnEY9OohyND39+JXmo=","Date":"Fri, 3 Dec 2021 11:34:46 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>","Message-ID":"<YanktvcED3EeDdtE@pendragon.ideasonboard.com>","References":"<20211202180410.518232-1-jeanmichel.hautbois@ideasonboard.com>\n\t<20211202180410.518232-6-jeanmichel.hautbois@ideasonboard.com>\n\t<YamDlOhWjJY9sRFu@pendragon.ideasonboard.com>\n\t<71d22a2f-8070-a8aa-c456-5bc924e97785@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<71d22a2f-8070-a8aa-c456-5bc924e97785@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v1 5/6] ipa: rkisp1: Introduce\n\tcrosstalk 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>"}}]