{"id":25869,"url":"https://patchwork.libcamera.org/api/1.1/patches/25869/?format=json","web_url":"https://patchwork.libcamera.org/patch/25869/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20260120-sklug-lsc-resampling-v2-dev-v4-14-2411c4be6d6d@ideasonboard.com>","date":"2026-01-20T08:45:56","name":"[v4,14/14] ipa: rkisp1: Introduce LensShadingCorrectionEnable control","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"81486ad4285233f810a06958d928d7338cc808e1","submitter":{"id":184,"url":"https://patchwork.libcamera.org/api/1.1/people/184/?format=json","name":"Stefan Klug","email":"stefan.klug@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/25869/mbox/","series":[{"id":5720,"url":"https://patchwork.libcamera.org/api/1.1/series/5720/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=5720","date":"2026-01-20T08:45:42","name":"Add resampling support for polynomial LSC data","version":4,"mbox":"https://patchwork.libcamera.org/series/5720/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/25869/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/25869/checks/","tags":{},"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 D3E49BDCBF\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 20 Jan 2026 08:46:34 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 974AF61FDA;\n\tTue, 20 Jan 2026 09:46:34 +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 0032C61FD2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 20 Jan 2026 09:46:32 +0100 (CET)","from ideasonboard.com (unknown\n\t[IPv6:2a00:6020:448c:6c00:7f76:a386:d798:7544])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 0976B19D3; \n\tTue, 20 Jan 2026 09:46:02 +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=\"vKhiFVbC\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1768898762;\n\tbh=biDI4wv9IbcGO4KRmsyIj6kArY1eDXfDjqfkwKYuMxU=;\n\th=From:Date:Subject:References:In-Reply-To:To:Cc:From;\n\tb=vKhiFVbCNcHL3Z/tSGBKZGr2fqAkzGbEdylRpNI+aCVQkKhHBOghsjzSd/yb2XQKz\n\tA6Lt8d5cfsWNPwc7cA6rwKyYZUk78xaotLmqvVDRdvI/kx5mWknwEOE6TgWpGOLeVk\n\t+Kn8p9kG2Ufs2f9vekxZPM02hp1sitil8o+per9M=","From":"Stefan Klug <stefan.klug@ideasonboard.com>","Date":"Tue, 20 Jan 2026 09:45:56 +0100","Subject":"[PATCH v4 14/14] ipa: rkisp1: Introduce\n\tLensShadingCorrectionEnable control","MIME-Version":"1.0","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"8bit","Message-Id":"<20260120-sklug-lsc-resampling-v2-dev-v4-14-2411c4be6d6d@ideasonboard.com>","References":"<20260120-sklug-lsc-resampling-v2-dev-v4-0-2411c4be6d6d@ideasonboard.com>","In-Reply-To":"<20260120-sklug-lsc-resampling-v2-dev-v4-0-2411c4be6d6d@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"Stefan Klug <stefan.klug@ideasonboard.com>, =?utf-8?q?Barnab=C3=A1s_P?=\n\t=?utf-8?b?xZFjemU=?= <barnabas.pocze@ideasonboard.com>, Kieran Bingham\n\t<kieran.bingham@ideasonboard.com>","X-Mailer":"b4 0.14.2","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>"},"content":"Add a LensShadingCorrectionEnable control that allows the user to enable\nor disbale the lens shading correction at runtime. Implement it for the\nrkisp1.\n\nSigned-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\nTested-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n---\n\nChanges in v4:\n- Squahed patch 14 (addition od the LSC control) and 15 (implementation)\n  into one.\n- Collected tag\n\nChanges in v3:\n- Include LensShadingCorrectionEnable in metadata\n- Add the queueRequest function in the header in logical order instead\n  of alphabetical order\n\nChanges 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 src/libcamera/control_ids_core.yaml |  9 +++++\n 5 files changed, 83 insertions(+), 15 deletions(-)","diff":"diff --git a/src/ipa/rkisp1/algorithms/dpf.cpp b/src/ipa/rkisp1/algorithms/dpf.cpp\nindex 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 \ndiff --git a/src/ipa/rkisp1/algorithms/lsc.cpp b/src/ipa/rkisp1/algorithms/lsc.cpp\nindex 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+\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 */\ndiff --git a/src/ipa/rkisp1/algorithms/lsc.h b/src/ipa/rkisp1/algorithms/lsc.h\nindex 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;\ndiff --git a/src/ipa/rkisp1/ipa_context.h b/src/ipa/rkisp1/ipa_context.h\nindex 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 {\ndiff --git a/src/libcamera/control_ids_core.yaml b/src/libcamera/control_ids_core.yaml\nindex 8e99bd84825f6060dbc323be3f4b0cd6283e0942..ced98e4625bfba9165be4f93d1fd2756881a2d1b 100644\n--- a/src/libcamera/control_ids_core.yaml\n+++ b/src/libcamera/control_ids_core.yaml\n@@ -1356,4 +1356,13 @@ controls:\n         Enable or disable lens dewarping. This control is only available if lens\n         dewarp parameters are configured in the tuning file.\n \n+  - LensShadingCorrectionEnable:\n+      type: bool\n+      direction: inout\n+      description: |\n+        Enable or disable the lens shading algorithm.\n+\n+        This control is only available when there are valid lens shading\n+        correction parameters available in the tuning file.\n+\n ...\n","prefixes":["v4","14/14"]}