[{"id":37986,"web_url":"https://patchwork.libcamera.org/comment/37986/","msgid":"<20260128112753.GD2558360@killaraus>","date":"2026-01-28T11:27:53","subject":"Re: [PATCH v5 15/15] ipa: rkisp1: Implement\n\tLensShadingCorrectionEnable control","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"On Tue, Jan 20, 2026 at 01:26:20PM +0100, Stefan Klug wrote:\n> Implement the LensShadingCorrectionEnable control for rkisp1.\n> \n> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n> Tested-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> \n> ---\n> \n> Changes in v5:\n> - Split patch 14 into two again, to have a separate patch for\n>   control_ids_core.yaml\n> \n> Changes in v4:\n> - Squahed patch 14 (addition od the LSC control) and 15 (implementation)\n>   into one.\n> - Collected tag\n> \n> Changes in v3:\n> - Include LensShadingCorrectionEnable in metadata\n> - Add the queueRequest function in the header in logical order instead\n>   of alphabetical order\n> \n> Changes in v2:\n> - Add the control only if LSC is properly configured in the tuning file\n> - Introduce enable flag in frame context for per frame control\n> ---\n>  src/ipa/rkisp1/algorithms/dpf.cpp |  2 +-\n>  src/ipa/rkisp1/algorithms/lsc.cpp | 67 +++++++++++++++++++++++++++++++++------\n>  src/ipa/rkisp1/algorithms/lsc.h   |  7 ++++\n>  src/ipa/rkisp1/ipa_context.h      | 13 +++++---\n>  4 files changed, 74 insertions(+), 15 deletions(-)\n> \n> diff --git a/src/ipa/rkisp1/algorithms/dpf.cpp b/src/ipa/rkisp1/algorithms/dpf.cpp\n> index 39f3e461f313dfbf35cb5d6a0daca0540bdf7b6b..83c1e4b7b355041295cbe0498a8dd70877ea6636 100644\n> --- a/src/ipa/rkisp1/algorithms/dpf.cpp\n> +++ b/src/ipa/rkisp1/algorithms/dpf.cpp\n> @@ -233,7 +233,7 @@ void Dpf::prepare(IPAContext &context, const uint32_t frame,\n>  \t\t*strengthConfig = strengthConfig_;\n>  \n>  \t\tconst auto &awb = context.configuration.awb;\n> -\t\tconst auto &lsc = context.configuration.lsc;\n> +\t\tconst auto &lsc = context.activeState.lsc;\n>  \n>  \t\tauto &mode = config->gain.mode;\n>  \n> diff --git a/src/ipa/rkisp1/algorithms/lsc.cpp b/src/ipa/rkisp1/algorithms/lsc.cpp\n> index 8589243ea04f5a712fb2ddd95677a197566f390f..8e3878d7e738d4b6212ca09671ed4e66b2dc5102 100644\n> --- a/src/ipa/rkisp1/algorithms/lsc.cpp\n> +++ b/src/ipa/rkisp1/algorithms/lsc.cpp\n> @@ -416,6 +416,8 @@ int LensShadingCorrection::init([[maybe_unused]] IPAContext &context,\n>  \tif (ret)\n>  \t\treturn ret;\n>  \n> +\tcontext.ctrlMap[&controls::LensShadingCorrectionEnable] = ControlInfo(false, true, true);\n\nLine wrap.\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> +\n>  \tshadingDescriptors_ = std::move(lscData);\n>  \n>  \treturn 0;\n> @@ -460,7 +462,7 @@ int LensShadingCorrection::configure(IPAContext &context,\n>  \n>  \tsets_.setData(std::move(shadingData));\n>  \n> -\tcontext.configuration.lsc.enabled = true;\n> +\tcontext.activeState.lsc.enabled = true;\n>  \treturn 0;\n>  }\n>  \n> @@ -481,6 +483,29 @@ void LensShadingCorrection::copyTable(rkisp1_cif_isp_lsc_config &config,\n>  \tstd::copy(set.b.begin(), set.b.end(), &config.b_data_tbl[0][0]);\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 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::LensShadingCorrectionEnable);\n> +\tif (lscEnable && *lscEnable != lsc.enabled) {\n> +\t\tlsc.enabled = *lscEnable;\n> +\n> +\t\tLOG(RkISP1Lsc, Debug)\n> +\t\t\t<< (lsc.enabled ? \"Enabling\" : \"Disabling\") << \" Lsc\";\n> +\n> +\t\tframeContext.lsc.update = true;\n> +\t}\n> +\n> +\tframeContext.lsc.enabled = lsc.enabled;\n> +}\n> +\n>  /**\n>   * \\copydoc libcamera::ipa::Algorithm::prepare\n>   */\n> @@ -492,18 +517,28 @@ void LensShadingCorrection::prepare([[maybe_unused]] IPAContext &context,\n>  \tuint32_t ct = frameContext.awb.temperatureK;\n>  \tunsigned int quantizedCt = quantize(ct, kColourTemperatureQuantization);\n>  \n> -\t/*\n> -\t * Add a threshold so that oscillations around a quantization step don't\n> -\t * lead to constant changes.\n> -\t */\n> -\tif (utils::abs_diff(ct, lastAppliedCt_) < kColourTemperatureQuantization / 2)\n> -\t\treturn;\n> +\t/* Check if we can skip the update. */\n> +\tif (!frameContext.lsc.update) {\n> +\t\tif (!frameContext.lsc.enabled)\n> +\t\t\treturn;\n>  \n> -\tif (quantizedCt == lastAppliedQuantizedCt_)\n> -\t\treturn;\n> +\t\t/*\n> +\t\t * Add a threshold so that oscillations around a quantization\n> +\t\t * step don't lead to constant changes.\n> +\t\t */\n> +\t\tif (utils::abs_diff(ct, lastAppliedCt_) < kColourTemperatureQuantization / 2)\n> +\t\t\treturn;\n> +\n> +\t\tif (quantizedCt == lastAppliedQuantizedCt_)\n> +\t\t\treturn;\n> +\t}\n>  \n>  \tauto config = params->block<BlockType::Lsc>();\n> -\tconfig.setEnabled(true);\n> +\tconfig.setEnabled(frameContext.lsc.enabled);\n> +\n> +\tif (!frameContext.lsc.enabled)\n> +\t\treturn;\n> +\n>  \tsetParameters(*config);\n>  \n>  \tconst Components &set = sets_.getInterpolated(quantizedCt);\n> @@ -517,6 +552,18 @@ void LensShadingCorrection::prepare([[maybe_unused]] IPAContext &context,\n>  \t\t<< quantizedCt;\n>  }\n>  \n> +/**\n> + * \\copydoc libcamera::ipa::Algorithm::process\n> + */\n> +void LensShadingCorrection::process([[maybe_unused]] IPAContext &context,\n> +\t\t\t\t    [[maybe_unused]] const uint32_t frame,\n> +\t\t\t\t    IPAFrameContext &frameContext,\n> +\t\t\t\t    [[maybe_unused]] const rkisp1_stat_buffer *stats,\n> +\t\t\t\t    ControlList &metadata)\n> +{\n> +\tmetadata.set(controls::LensShadingCorrectionEnable, frameContext.lsc.enabled);\n> +}\n> +\n>  REGISTER_IPA_ALGORITHM(LensShadingCorrection, \"LensShadingCorrection\")\n>  \n>  } /* namespace ipa::rkisp1::algorithms */\n> diff --git a/src/ipa/rkisp1/algorithms/lsc.h b/src/ipa/rkisp1/algorithms/lsc.h\n> index 3097740a6cb2ce9063a4ba087856987a489b0ab6..fb9dcc1a52af4a88a52808346b5da99e3f2b1c87 100644\n> --- a/src/ipa/rkisp1/algorithms/lsc.h\n> +++ b/src/ipa/rkisp1/algorithms/lsc.h\n> @@ -26,9 +26,16 @@ 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     RkISP1Params *params) override;\n> +\tvoid process(IPAContext &context, const uint32_t frame,\n> +\t\t     IPAFrameContext &frameContext,\n> +\t\t     const rkisp1_stat_buffer *stats,\n> +\t\t     ControlList &metadata) override;\n>  \n>  \tstruct Components {\n>  \t\tstd::vector<uint16_t> r;\n> diff --git a/src/ipa/rkisp1/ipa_context.h b/src/ipa/rkisp1/ipa_context.h\n> index b257cee55379ad932b42e613f94eccbe69a939e3..fa748811be743b43ce6ee289408c054c6f9a7046 100644\n> --- a/src/ipa/rkisp1/ipa_context.h\n> +++ b/src/ipa/rkisp1/ipa_context.h\n> @@ -55,10 +55,6 @@ struct IPASessionConfiguration {\n>  \t\tbool supported;\n>  \t} compress;\n>  \n> -\tstruct {\n> -\t\tbool enabled;\n> -\t} lsc;\n> -\n>  \tstruct {\n>  \t\tutils::Duration minExposureTime;\n>  \t\tutils::Duration maxExposureTime;\n> @@ -143,6 +139,10 @@ struct IPAActiveState {\n>  \t\tdouble gain;\n>  \t\tdouble strength;\n>  \t} wdr;\n> +\n> +\tstruct {\n> +\t\tbool enabled;\n> +\t} lsc;\n>  };\n>  \n>  struct IPAFrameContext : public FrameContext {\n> @@ -218,6 +218,11 @@ struct IPAFrameContext : public FrameContext {\n>  \t\tdouble strength;\n>  \t\tdouble gain;\n>  \t} wdr;\n> +\n> +\tstruct {\n> +\t\tbool enabled;\n> +\t\tbool update;\n> +\t} lsc;\n>  };\n>  \n>  struct IPAContext {","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 7AF80C3200\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 28 Jan 2026 11:27:57 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 74C3861FC9;\n\tWed, 28 Jan 2026 12:27:56 +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 31DE561FC4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 28 Jan 2026 12:27:55 +0100 (CET)","from pendragon.ideasonboard.com\n\t(2001-14ba-703d-e500--2a1.rev.dnainternet.fi\n\t[IPv6:2001:14ba:703d:e500::2a1])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id CF8D0C6F;\n\tWed, 28 Jan 2026 12:27:17 +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=\"qMUgn1Nu\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1769599638;\n\tbh=mhII41KJIA5XEriYzTpfDK4z+95HcW3RnAfQfHb6pPc=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=qMUgn1NuMsa5RA2EpAb7LWIAxcv/iUOFH5a5b5tUl5yT0bG2+ybovRbC8nrCL66Vn\n\tC7gc7fA/4z33PLZ4XXaTv6TomF5euR5Bme0gZHTod0yvTAsJD717ca1M+GXfL7zdaa\n\tdzob9Ho+GIu45rPypSv4w/oQruim3bvOKLYW8N38=","Date":"Wed, 28 Jan 2026 13:27:53 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Stefan Klug <stefan.klug@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org, =?utf-8?b?QmFybmFiw6FzIFDFkWN6?=\n\t=?utf-8?q?e?= <barnabas.pocze@ideasonboard.com>, Kieran Bingham\n\t<kieran.bingham@ideasonboard.com>","Subject":"Re: [PATCH v5 15/15] ipa: rkisp1: Implement\n\tLensShadingCorrectionEnable control","Message-ID":"<20260128112753.GD2558360@killaraus>","References":"<20260120-sklug-lsc-resampling-v2-dev-v5-0-ef5cec7b299f@ideasonboard.com>\n\t<20260120-sklug-lsc-resampling-v2-dev-v5-15-ef5cec7b299f@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20260120-sklug-lsc-resampling-v2-dev-v5-15-ef5cec7b299f@ideasonboard.com>","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]