From patchwork Wed Nov 19 13:22:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 25082 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 E4EF3BD80A for ; Wed, 19 Nov 2025 13:22:33 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 949F260AA3; Wed, 19 Nov 2025 14:22:33 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="CbKFEkx0"; 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 8089E606A0 for ; Wed, 19 Nov 2025 14:22:31 +0100 (CET) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:5419:7bb:83a3:3d7a]) by perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id D284E195E; Wed, 19 Nov 2025 14:20:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1763558426; bh=qGvT3BW9ZL4aP9kR1bgRb+4Ux+dAaMHhmM0jb17WS7w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CbKFEkx0uQmc5O8rr04I9yBkopw8PTBLeYs1Kp94llrq3cZ6FxupBlh0Kr++etiW+ Xd6hFYf2e1vx3wJjXIxfZapfYiyqLxeyyCUPeoFDFjKmRsShJZW5LVXmKZQT30V6a9 f4SObOQWNMaM0Z4b+am9/SmP6MBU7A82PrBrBvM0= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug Subject: [PATCH v3 2/4] ipa: rkisp1: lux: Properly handle frame context and active state Date: Wed, 19 Nov 2025 14:22:11 +0100 Message-ID: <20251119132221.2088013-3-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251119132221.2088013-1-stefan.klug@ideasonboard.com> References: <20251119132221.2088013-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" WIth the upcoming regulation rework the processing order in the IPA is updated a bit so that process() updates the active state with new measurements and fills the metadata with the data from the corresponding frame context. In prepare() all parameters for one frame are tied together using the most up to date values from active state. Change the lux algorithm to support that order of events. Also prepare for cases where stats can be null which can happen with the upcoming regulation rework. While at it fix a formatting issue reported by checkstyle and drop a unnecessary local variable. Signed-off-by: Stefan Klug Reviewed-by: Kieran Bingham --- Changes in v3: - Added this patch in response to the comment from Kieran in https://patchwork.libcamera.org/patch/24982/#36740 --- src/ipa/rkisp1/algorithms/lux.cpp | 23 ++++++++++++++++++----- src/ipa/rkisp1/algorithms/lux.h | 3 +++ src/ipa/rkisp1/ipa_context.h | 4 ++++ 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/ipa/rkisp1/algorithms/lux.cpp b/src/ipa/rkisp1/algorithms/lux.cpp index e8da69810008..bc714b7a82c6 100644 --- a/src/ipa/rkisp1/algorithms/lux.cpp +++ b/src/ipa/rkisp1/algorithms/lux.cpp @@ -46,6 +46,16 @@ int Lux::init([[maybe_unused]] IPAContext &context, const YamlObject &tuningData return lux_.parseTuningData(tuningData); } +/** + * \copydoc libcamera::ipa::Algorithm::prepare + */ +void Lux::prepare(IPAContext &context, [[maybe_unused]] const uint32_t frame, + IPAFrameContext &frameContext, + [[maybe_unused]] RkISP1Params *params) +{ + frameContext.lux.lux = context.activeState.lux.lux; +} + /** * \copydoc libcamera::ipa::Algorithm::process */ @@ -55,8 +65,13 @@ void Lux::process(IPAContext &context, const rkisp1_stat_buffer *stats, ControlList &metadata) { - utils::Duration exposureTime = context.configuration.sensor.lineDuration - * frameContext.sensor.exposure; + metadata.set(controls::Lux, frameContext.lux.lux); + + if (!stats) + return; + + utils::Duration exposureTime = context.configuration.sensor.lineDuration * + frameContext.sensor.exposure; double gain = frameContext.sensor.gain; /* \todo Deduplicate the histogram calculation from AGC */ @@ -64,9 +79,7 @@ void Lux::process(IPAContext &context, Histogram yHist({ params->hist.hist_bins, context.hw.numHistogramBins }, [](uint32_t x) { return x >> 4; }); - double lux = lux_.estimateLux(exposureTime, gain, 1.0, yHist); - frameContext.lux.lux = lux; - metadata.set(controls::Lux, lux); + context.activeState.lux.lux = lux_.estimateLux(exposureTime, gain, 1.0, yHist); } REGISTER_IPA_ALGORITHM(Lux, "Lux") diff --git a/src/ipa/rkisp1/algorithms/lux.h b/src/ipa/rkisp1/algorithms/lux.h index 8dcadc284a84..e0239848e252 100644 --- a/src/ipa/rkisp1/algorithms/lux.h +++ b/src/ipa/rkisp1/algorithms/lux.h @@ -23,6 +23,9 @@ public: Lux(); int init(IPAContext &context, const YamlObject &tuningData) 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, diff --git a/src/ipa/rkisp1/ipa_context.h b/src/ipa/rkisp1/ipa_context.h index f85a130d9c23..b257cee55379 100644 --- a/src/ipa/rkisp1/ipa_context.h +++ b/src/ipa/rkisp1/ipa_context.h @@ -133,6 +133,10 @@ struct IPAActiveState { double gamma; } goc; + struct { + double lux; + } lux; + struct { controls::WdrModeEnum mode; AgcMeanLuminance::AgcConstraint constraint;