From patchwork Wed Jan 14 11:58:08 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 25795 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 6ED1CC3226 for ; Wed, 14 Jan 2026 11:58:45 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 221B661FD0; Wed, 14 Jan 2026 12:58:45 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="DNHAJzhV"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 56E1861FD0 for ; Wed, 14 Jan 2026 12:58:43 +0100 (CET) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:b781:dff2:957:7831]) by perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id A2D64177A; Wed, 14 Jan 2026 12:58:16 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1768391896; bh=reCyd+c7EfAMy9j42VXH5hGZUl1gUt8ZhF87wdnRdxE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=DNHAJzhVQxgfNnV6apIkTVKgL8Nd8HCqkpRu719lJ55hNFAcWRChbXDaAY7eDNtgX cwWM9pBHTHkh8Wkc4cgDbccoJhYgha8bIxejCekFXFpT0ILEGO0+4AUPDyyiEqQBJ2 cyy2AZlXgNAq4xYNHHZ6aR54JhxRC8PzaA//tGI4= From: Stefan Klug Date: Wed, 14 Jan 2026 12:58:08 +0100 Subject: [PATCH v3 15/15] ipa: rkisp1: Implement LensShadingCorrectionEnable control MIME-Version: 1.0 Message-Id: <20260114-sklug-lsc-resampling-v2-dev-v3-15-80cd24f4dd61@ideasonboard.com> References: <20260114-sklug-lsc-resampling-v2-dev-v3-0-80cd24f4dd61@ideasonboard.com> In-Reply-To: <20260114-sklug-lsc-resampling-v2-dev-v3-0-80cd24f4dd61@ideasonboard.com> To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug , =?utf-8?q?Barnab=C3=A1s_P?= =?utf-8?b?xZFjemU=?= X-Mailer: b4 0.14.2 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Implement the LensShadingCorrectionEnable control for rkisp1. Signed-off-by: Stefan Klug Tested-by: Barnabás Pőcze --- Changes in v3: - Include LensShadingCorrectionEnable in metadata - Add the queueRequest function in the header in logical order instead of alphabetical order Changes in v2: - Add the control only if LSC is properly configured in the tuning file - Introduce enable flag in frame context for per frame control --- src/ipa/rkisp1/algorithms/dpf.cpp | 2 +- src/ipa/rkisp1/algorithms/lsc.cpp | 67 +++++++++++++++++++++++++++++++++------ src/ipa/rkisp1/algorithms/lsc.h | 7 ++++ src/ipa/rkisp1/ipa_context.h | 13 +++++--- 4 files changed, 74 insertions(+), 15 deletions(-) diff --git a/src/ipa/rkisp1/algorithms/dpf.cpp b/src/ipa/rkisp1/algorithms/dpf.cpp index 39f3e461f313dfbf35cb5d6a0daca0540bdf7b6b..83c1e4b7b355041295cbe0498a8dd70877ea6636 100644 --- a/src/ipa/rkisp1/algorithms/dpf.cpp +++ b/src/ipa/rkisp1/algorithms/dpf.cpp @@ -233,7 +233,7 @@ void Dpf::prepare(IPAContext &context, const uint32_t frame, *strengthConfig = strengthConfig_; const auto &awb = context.configuration.awb; - const auto &lsc = context.configuration.lsc; + const auto &lsc = context.activeState.lsc; auto &mode = config->gain.mode; diff --git a/src/ipa/rkisp1/algorithms/lsc.cpp b/src/ipa/rkisp1/algorithms/lsc.cpp index 8427c48f65b2e6e200f834db506939c6c85fd2a3..bcf44e83a0b99cc617a1d849d56ca4f288f472a3 100644 --- a/src/ipa/rkisp1/algorithms/lsc.cpp +++ b/src/ipa/rkisp1/algorithms/lsc.cpp @@ -416,6 +416,8 @@ int LensShadingCorrection::init([[maybe_unused]] IPAContext &context, if (ret) return ret; + context.ctrlMap[&controls::LensShadingCorrectionEnable] = ControlInfo(false, true, true); + shadingDescriptors_ = std::move(lscData); return 0; @@ -460,7 +462,7 @@ int LensShadingCorrection::configure(IPAContext &context, sets_.setData(std::move(shadingData)); - context.configuration.lsc.enabled = true; + context.activeState.lsc.enabled = true; return 0; } @@ -481,6 +483,29 @@ void LensShadingCorrection::copyTable(rkisp1_cif_isp_lsc_config &config, std::copy(set.b.begin(), set.b.end(), &config.b_data_tbl[0][0]); } +/** + * \copydoc libcamera::ipa::Algorithm::queueRequest + */ +void LensShadingCorrection::queueRequest(IPAContext &context, + [[maybe_unused]] const uint32_t frame, + IPAFrameContext &frameContext, + const ControlList &controls) +{ + auto &lsc = context.activeState.lsc; + + const auto &lscEnable = controls.get(controls::LensShadingCorrectionEnable); + if (lscEnable && *lscEnable != lsc.enabled) { + lsc.enabled = *lscEnable; + + LOG(RkISP1Lsc, Debug) + << (lsc.enabled ? "Enabling" : "Disabling") << " Lsc"; + + frameContext.lsc.update = true; + } + + frameContext.lsc.enabled = lsc.enabled; +} + /** * \copydoc libcamera::ipa::Algorithm::prepare */ @@ -493,18 +518,28 @@ void LensShadingCorrection::prepare([[maybe_unused]] IPAContext &context, unsigned int quantizedCt = quantize(ct, kColourTemperatureQuantization); int ctDiff = static_cast(ct) - static_cast(lastAppliedCt_); - /* - * Add a threshold so that oscillations around a quantization step don't - * lead to constant changes. - */ - if (std::abs(ctDiff) < kColourTemperatureQuantization / 2) - return; + /* Check if we can skip the update. */ + if (!frameContext.lsc.update) { + if (!frameContext.lsc.enabled) + return; - if (quantizedCt == lastAppliedQuantizedCt_) - return; + /* + * Add a threshold so that oscillations around a quantization + * step don't lead to constant changes. + */ + if (std::abs(ctDiff) < kColourTemperatureQuantization / 2) + return; + + if (quantizedCt == lastAppliedQuantizedCt_) + return; + } auto config = params->block(); - config.setEnabled(true); + config.setEnabled(frameContext.lsc.enabled); + + if (!frameContext.lsc.enabled) + return; + setParameters(*config); const Components &set = sets_.getInterpolated(quantizedCt); @@ -518,6 +553,18 @@ void LensShadingCorrection::prepare([[maybe_unused]] IPAContext &context, << quantizedCt; } +/** + * \copydoc libcamera::ipa::Algorithm::process + */ +void LensShadingCorrection::process([[maybe_unused]] IPAContext &context, + [[maybe_unused]] const uint32_t frame, + IPAFrameContext &frameContext, + [[maybe_unused]] const rkisp1_stat_buffer *stats, + ControlList &metadata) +{ + metadata.set(controls::LensShadingCorrectionEnable, frameContext.lsc.enabled); +} + REGISTER_IPA_ALGORITHM(LensShadingCorrection, "LensShadingCorrection") } /* namespace ipa::rkisp1::algorithms */ diff --git a/src/ipa/rkisp1/algorithms/lsc.h b/src/ipa/rkisp1/algorithms/lsc.h index 3097740a6cb2ce9063a4ba087856987a489b0ab6..fb9dcc1a52af4a88a52808346b5da99e3f2b1c87 100644 --- a/src/ipa/rkisp1/algorithms/lsc.h +++ b/src/ipa/rkisp1/algorithms/lsc.h @@ -26,9 +26,16 @@ public: int init(IPAContext &context, const YamlObject &tuningData) override; int configure(IPAContext &context, const IPACameraSensorInfo &configInfo) override; + void queueRequest(IPAContext &context, const uint32_t frame, + IPAFrameContext &frameContext, + const ControlList &controls) override; void prepare(IPAContext &context, const uint32_t frame, IPAFrameContext &frameContext, RkISP1Params *params) override; + void process(IPAContext &context, const uint32_t frame, + IPAFrameContext &frameContext, + const rkisp1_stat_buffer *stats, + ControlList &metadata) override; struct Components { std::vector r; diff --git a/src/ipa/rkisp1/ipa_context.h b/src/ipa/rkisp1/ipa_context.h index b257cee55379ad932b42e613f94eccbe69a939e3..fa748811be743b43ce6ee289408c054c6f9a7046 100644 --- a/src/ipa/rkisp1/ipa_context.h +++ b/src/ipa/rkisp1/ipa_context.h @@ -55,10 +55,6 @@ struct IPASessionConfiguration { bool supported; } compress; - struct { - bool enabled; - } lsc; - struct { utils::Duration minExposureTime; utils::Duration maxExposureTime; @@ -143,6 +139,10 @@ struct IPAActiveState { double gain; double strength; } wdr; + + struct { + bool enabled; + } lsc; }; struct IPAFrameContext : public FrameContext { @@ -218,6 +218,11 @@ struct IPAFrameContext : public FrameContext { double strength; double gain; } wdr; + + struct { + bool enabled; + bool update; + } lsc; }; struct IPAContext {