From patchwork Tue Oct 14 07:52:34 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 24628 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 91477BF415 for ; Tue, 14 Oct 2025 07:53:36 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 462D9605EF; Tue, 14 Oct 2025 09:53:36 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="HdsK6f2g"; 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 BD60E605DD for ; Tue, 14 Oct 2025 09:53:34 +0200 (CEST) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:61fb:8e55:ff1e:be62]) by perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 84CF8C73; Tue, 14 Oct 2025 09:51:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1760428316; bh=mBl3sCmfidcqdXPeszxfzmjPP031maQ+jUPB6OKVpBc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HdsK6f2gG9jBTzUxj/2Yqh7LVmmHDiQyW5f4nETwSL6WUJzV3TtTQE4iP4fYMn0Fh TFxHsrm8Uc7ccUMMhseq37+IylMnSn6kP/hOzMj/j8/rcQ3U/tcHJaU0RNbHX75ZZq +iRHgXsNw+i2xw03WpxBenmiYClDt2JdMBepwGTc= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug Subject: [PATCH v1 12/12] ipa: rkisp1: Add LensShadingEnable control Date: Tue, 14 Oct 2025 09:52:34 +0200 Message-ID: <20251014075252.2876485-13-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251014075252.2876485-1-stefan.klug@ideasonboard.com> References: <20251014075252.2876485-1-stefan.klug@ideasonboard.com> MIME-Version: 1.0 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 LensShadingEnable control for rkisp1. Signed-off-by: Stefan Klug --- src/ipa/rkisp1/algorithms/dpf.cpp | 2 +- src/ipa/rkisp1/algorithms/lsc.cpp | 41 ++++++++++++++++++++++++++--- src/ipa/rkisp1/algorithms/lsc.h | 3 +++ src/ipa/rkisp1/ipa_context.h | 12 ++++++--- src/libcamera/control_ids_core.yaml | 3 +++ 5 files changed, 52 insertions(+), 9 deletions(-) diff --git a/src/ipa/rkisp1/algorithms/dpf.cpp b/src/ipa/rkisp1/algorithms/dpf.cpp index cb6095daeeed..79cb4829fdbb 100644 --- a/src/ipa/rkisp1/algorithms/dpf.cpp +++ b/src/ipa/rkisp1/algorithms/dpf.cpp @@ -229,7 +229,7 @@ void Dpf::prepare(IPAContext &context, const uint32_t frame, *config = config_; 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 68cf35064182..ddb7154a0211 100644 --- a/src/ipa/rkisp1/algorithms/lsc.cpp +++ b/src/ipa/rkisp1/algorithms/lsc.cpp @@ -366,6 +366,8 @@ LensShadingCorrection::LensShadingCorrection() int LensShadingCorrection::init([[maybe_unused]] IPAContext &context, const YamlObject &tuningData) { + context.ctrlMap[&controls::LensShadingEnable] = ControlInfo(false, true, true); + xSize_ = parseSizes(tuningData, "x-size"); ySize_ = parseSizes(tuningData, "y-size"); @@ -449,7 +451,7 @@ int LensShadingCorrection::configure(IPAContext &context, sets_.setData(std::move(shadingData)); - context.configuration.lsc.enabled = true; + context.activeState.lsc.enabled = true; return 0; } @@ -470,6 +472,27 @@ 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::LensShadingEnable); + if (lscEnable && *lscEnable != lsc.enabled) { + lsc.enabled = *lscEnable; + + LOG(RkISP1Lsc, Debug) + << (*lscEnable ? "Enabling" : "Disabling") << " Lsc"; + + frameContext.lsc.update = true; + } +} + /** * \copydoc libcamera::ipa::Algorithm::prepare */ @@ -479,16 +502,26 @@ void LensShadingCorrection::prepare([[maybe_unused]] IPAContext &context, RkISP1Params *params) { uint32_t ct = frameContext.awb.temperatureK; - if (std::abs(static_cast(ct) - static_cast(lastAppliedCt_)) < + + if (!frameContext.lsc.update && !context.activeState.lsc.enabled) + return; + + if (!frameContext.lsc.update && + std::abs(static_cast(ct) - static_cast(lastAppliedCt_)) < kColourTemperatureChangeThreshhold) return; + unsigned int quantizedCt; const Components &set = sets_.getInterpolated(ct, &quantizedCt); - if (lastAppliedQuantizedCt_ == quantizedCt) + if (!frameContext.lsc.update && lastAppliedQuantizedCt_ == quantizedCt) return; auto config = params->block(); - config.setEnabled(true); + config.setEnabled(context.activeState.lsc.enabled); + + if (!context.activeState.lsc.enabled) + return; + setParameters(*config); copyTable(*config, set); diff --git a/src/ipa/rkisp1/algorithms/lsc.h b/src/ipa/rkisp1/algorithms/lsc.h index 43fee337931f..a3d8042130c0 100644 --- a/src/ipa/rkisp1/algorithms/lsc.h +++ b/src/ipa/rkisp1/algorithms/lsc.h @@ -29,6 +29,9 @@ public: void prepare(IPAContext &context, const uint32_t frame, IPAFrameContext &frameContext, RkISP1Params *params) override; + void queueRequest(IPAContext &context, const uint32_t frame, + IPAFrameContext &frameContext, + const ControlList &controls) override; struct Components { std::vector r; diff --git a/src/ipa/rkisp1/ipa_context.h b/src/ipa/rkisp1/ipa_context.h index f85a130d9c23..5ec87ae4e5a3 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; @@ -139,6 +135,10 @@ struct IPAActiveState { double gain; double strength; } wdr; + + struct { + bool enabled; + } lsc; }; struct IPAFrameContext : public FrameContext { @@ -214,6 +214,10 @@ struct IPAFrameContext : public FrameContext { double strength; double gain; } wdr; + + struct { + bool update; + } lsc; }; struct IPAContext { diff --git a/src/libcamera/control_ids_core.yaml b/src/libcamera/control_ids_core.yaml index 9244b7eddb77..3b062df64bf5 100644 --- a/src/libcamera/control_ids_core.yaml +++ b/src/libcamera/control_ids_core.yaml @@ -1352,4 +1352,7 @@ controls: description: | Enable or disable the lens shading algorithm. + This control is only available when there are valid lens shading + correction parameters available in the tuning file. + ...