[{"id":26638,"web_url":"https://patchwork.libcamera.org/comment/26638/","msgid":"<20230312160130.GX2545@pendragon.ideasonboard.com>","date":"2023-03-12T16:01:30","subject":"Re: [libcamera-devel] [PATCH 2/3] ipa: rkisp1: lsc: Enable/disable\n\tLSC algorithm","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Jacopo,\n\nThank you for the patch.\n\nOn Wed, Mar 08, 2023 at 05:40:27PM +0100, Jacopo Mondi via libcamera-devel wrote:\n> Implement LSC algorithm enable/disable by parsing the\n> \"LensShadingEnable\" control in queueRequest().\n\nI'll assume here that we have use cases for this control, that question\nis better discussed in replies to 1/3.\n\n> Start with the LSC algorithm enabled by default and disable it\n> on application request.\n> \n> Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n> ---\n>  src/ipa/rkisp1/algorithms/lsc.cpp | 54 ++++++++++++++++++++++++++++++-\n>  src/ipa/rkisp1/algorithms/lsc.h   |  4 +++\n>  src/ipa/rkisp1/ipa_context.h      |  5 +++\n>  src/ipa/rkisp1/rkisp1.cpp         |  1 +\n>  4 files changed, 63 insertions(+), 1 deletion(-)\n> \n> diff --git a/src/ipa/rkisp1/algorithms/lsc.cpp b/src/ipa/rkisp1/algorithms/lsc.cpp\n> index a7ccedb1ed3b..0c9f6cbd1dec 100644\n> --- a/src/ipa/rkisp1/algorithms/lsc.cpp\n> +++ b/src/ipa/rkisp1/algorithms/lsc.cpp\n> @@ -14,6 +14,8 @@\n>  #include <libcamera/base/log.h>\n>  #include <libcamera/base/utils.h>\n>  \n> +#include <libcamera/control_ids.h>\n> +\n>  #include \"libcamera/internal/yaml_parser.h\"\n>  \n>  #include \"linux/rkisp1-config.h\"\n> @@ -147,6 +149,8 @@ int LensShadingCorrection::init([[maybe_unused]] IPAContext &context,\n>  \t\treturn -EINVAL;\n>  \t}\n>  \n> +\tcontext.configuration.lsc.enabled = false;\n> +\n>  \treturn 0;\n>  }\n>  \n> @@ -181,10 +185,20 @@ int LensShadingCorrection::configure(IPAContext &context,\n>  \t\tyGrad_[i] = std::round(32768 / ySizes_[i]);\n>  \t}\n>  \n> -\tcontext.configuration.lsc.enabled = true;\n> +\t/* Enable LSC on first run unless explicitly disabled by application. */\n> +\tcontext.activeState.lsc.enable = true;\n> +\tcontext.activeState.lsc.active = false;\n> +\n>  \treturn 0;\n>  }\n>  \n> +void LensShadingCorrection::disableLSC(rkisp1_params_cfg *params)\n> +{\n> +\tparams->module_en_update |= RKISP1_CIF_ISP_MODULE_LSC;\n> +\tparams->module_ens &= ~RKISP1_CIF_ISP_MODULE_LSC;\n> +\tparams->module_cfg_update |= RKISP1_CIF_ISP_MODULE_LSC;\n> +}\n> +\n>  void LensShadingCorrection::setParameters(rkisp1_params_cfg *params)\n>  {\n>  \tstruct rkisp1_cif_isp_lsc_config &config = params->others.lsc_config;\n> @@ -242,6 +256,25 @@ void LensShadingCorrection::interpolateTable(rkisp1_cif_isp_lsc_config &config,\n>  \t}\n>  }\n>  \n> +/**\n> + * \\copydoc libcamera::ipa::Algorithm::queueRequest\n> + */\n> +void LensShadingCorrection::queueRequest(IPAContext &context,\n> +\t\t\t\t\t [[maybe_unused]] const uint32_t frame,\n> +\t\t\t\t\t [[maybe_unused]] IPAFrameContext &frameContext,\n> +\t\t\t\t\t const ControlList &controls)\n> +{\n> +\tauto lsc = &context.activeState.lsc;\n> +\n> +\tconst auto lscEnable = controls.get(controls::LensShadingEnable);\n> +\tif (lscEnable && *lscEnable != lsc->enable) {\n> +\t\tLOG(RkISP1Lsc, Debug)\n> +\t\t\t<< (*lscEnable ? \"Enabling\" : \"Disabling\") << \" LSC\";\n> +\n> +\t\tlsc->enable = *lscEnable;\n> +\t}\n> +}\n> +\n>  /**\n>   * \\copydoc libcamera::ipa::Algorithm::prepare\n>   */\n> @@ -250,6 +283,25 @@ void LensShadingCorrection::prepare(IPAContext &context,\n>  \t\t\t\t    [[maybe_unused]] IPAFrameContext &frameContext,\n>  \t\t\t\t    rkisp1_params_cfg *params)\n>  {\n> +\tauto lsc = &context.activeState.lsc;\n\nThis doesn't look right, you will apply the LSC enable control value of\nthe very last request that was queued too early. You need to use the\nframe context.\n\n> +\n> +\tif (lsc->enable != lsc->active) {\n> +\t\t/* If LSC has to be disabled, disable it and return here. */\n> +\t\tif (!lsc->enable) {\n> +\t\t\tdisableLSC(params);\n> +\t\t\tlsc->active = false;\n> +\t\t\tcontext.configuration.lsc.enabled = false;\n> +\t\t\treturn;\n> +\t\t}\n> +\n> +\t\tlsc->active = true;\n> +\t\tcontext.configuration.lsc.enabled = true;\n> +\t}\n> +\n> +\t/* Nothing more to do here if LSC is not active. */\n> +\tif (!lsc->active)\n> +\t\treturn;\n> +\n>  \tstruct rkisp1_cif_isp_lsc_config &config = params->others.lsc_config;\n>  \n>  \t/*\n> diff --git a/src/ipa/rkisp1/algorithms/lsc.h b/src/ipa/rkisp1/algorithms/lsc.h\n> index e2a93a566973..4708065bcfb7 100644\n> --- a/src/ipa/rkisp1/algorithms/lsc.h\n> +++ b/src/ipa/rkisp1/algorithms/lsc.h\n> @@ -23,6 +23,9 @@ public:\n>  \n>  \tint init(IPAContext &context, const YamlObject &tuningData) override;\n>  \tint configure(IPAContext &context, const IPACameraSensorInfo &configInfo) override;\n> +\tvoid queueRequest(IPAContext &context, const uint32_t frame,\n> +\t\t\t  IPAFrameContext &frameContext,\n> +\t\t\t  const ControlList &controls) override;\n>  \tvoid prepare(IPAContext &context, const uint32_t frame,\n>  \t\t     IPAFrameContext &frameContext,\n>  \t\t     rkisp1_params_cfg *params) override;\n> @@ -36,6 +39,7 @@ private:\n>  \t\tstd::vector<uint16_t> b;\n>  \t};\n>  \n> +\tvoid disableLSC(rkisp1_params_cfg *params);\n>  \tvoid setParameters(rkisp1_params_cfg *params);\n>  \tvoid copyTable(rkisp1_cif_isp_lsc_config &config, const Components &set0);\n>  \tvoid interpolateTable(rkisp1_cif_isp_lsc_config &config,\n> diff --git a/src/ipa/rkisp1/ipa_context.h b/src/ipa/rkisp1/ipa_context.h\n> index b9b2065328d6..ada995274ebf 100644\n> --- a/src/ipa/rkisp1/ipa_context.h\n> +++ b/src/ipa/rkisp1/ipa_context.h\n> @@ -98,6 +98,11 @@ struct IPAActiveState {\n>  \t\tuint8_t denoise;\n>  \t\tuint8_t sharpness;\n>  \t} filter;\n> +\n> +\tstruct {\n> +\t\tbool enable;\n> +\t\tbool active;\n> +\t} lsc;\n>  };\n>  \n>  struct IPAFrameContext : public FrameContext {\n> diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp\n> index 6544c925ba25..2772592eda66 100644\n> --- a/src/ipa/rkisp1/rkisp1.cpp\n> +++ b/src/ipa/rkisp1/rkisp1.cpp\n> @@ -106,6 +106,7 @@ const ControlInfoMap::Map rkisp1Controls{\n>  \t{ &controls::Saturation, ControlInfo(0.0f, 1.993f, 1.0f) },\n>  \t{ &controls::Sharpness, ControlInfo(0.0f, 10.0f, 1.0f) },\n>  \t{ &controls::draft::NoiseReductionMode, ControlInfo(controls::draft::NoiseReductionModeValues) },\n> +\t{ &controls::LensShadingEnable, ControlInfo(false, true) },\n\nShouldn't the default control value be true ?\n\n>  };\n>  \n>  } /* namespace */","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 1235FBE080\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun, 12 Mar 2023 16:01:32 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5ADC462705;\n\tSun, 12 Mar 2023 17:01:31 +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 EEA4762705\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 12 Mar 2023 17:01:29 +0100 (CET)","from pendragon.ideasonboard.com (85-76-21-162-nat.elisa-mobile.fi\n\t[85.76.21.162])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id F0EA0814;\n\tSun, 12 Mar 2023 17:01:28 +0100 (CET)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1678636891;\n\tbh=cBIi6Ss9yKs5MrfGXVuP1kdsQ0zyQ3Her69uZKkT8co=;\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=gJJ742IBuCh1W3plFi+7qH2LVRPCrr3XVHPYOWV+Ix+Uip/0iBpajbKzm2DaC5J18\n\t21sakvXMtx5BwwuAWbrjDTSCCJnPV9AnlzndZUcrlMjpUT5Bt39UZkM3Z34WzWYpDb\n\tpoybUL4WD6dqHQy31EMRPPxjoTXSWoGGpDq0kkhcn4xpJYJ5Nz/pHatXe0wQS3YNey\n\tzCduutFT4+6D96TNmyJvnaHui03zKvZ9MmQuK45l4ifoSgYGu+BCibMM47wlElw9Yj\n\tEtUKHJ8qf3vK20BflBlTdEoY/gkzu6C/8H9rTs5TISgqgnKc4mUr4eeoIuMRnsDURW\n\tY3jfb1MebtWuQ==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1678636889;\n\tbh=cBIi6Ss9yKs5MrfGXVuP1kdsQ0zyQ3Her69uZKkT8co=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=SSn58628nlbMz4xNVgESTQcUzm76Q1kXtSBAtOsoDwJ4dMejJKk9j0uqoSzaRTImu\n\tR1sG9BmuyU+k/Gbe8FQz7zOaUuFGnF5qTLEoyEPop5E+XIGblJLolvKkNrMt3lBOyn\n\tvQ52R/x5Q5s2scvvhV/lhKlAIwuAJNMMCEgibt/k="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"SSn58628\"; dkim-atps=neutral","Date":"Sun, 12 Mar 2023 18:01:30 +0200","To":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","Message-ID":"<20230312160130.GX2545@pendragon.ideasonboard.com>","References":"<20230308164028.235638-1-jacopo.mondi@ideasonboard.com>\n\t<20230308164028.235638-3-jacopo.mondi@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20230308164028.235638-3-jacopo.mondi@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH 2/3] ipa: rkisp1: lsc: Enable/disable\n\tLSC algorithm","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>"}}]