From patchwork Fri Aug 15 10:29:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 24126 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 A9D51BDCC1 for ; Fri, 15 Aug 2025 10:30:43 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5F1256926A; Fri, 15 Aug 2025 12:30:43 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="jR9eb4oB"; 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 A42C46926D for ; Fri, 15 Aug 2025 12:30:40 +0200 (CEST) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:83d1:ae5d:93a6:6837]) by perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id A399F19E5; Fri, 15 Aug 2025 12:29:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1755253785; bh=rvYLu+sse6RTu8xpvp2r74SR5Ehd1XYkA9eT8aVfSTM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jR9eb4oBAv1RHrDWWL5w+k5l+lNOygzIGfmkVzoNYGJeSIEEMT8S3wzt7UiVjiftf BxlNgLr7PO/3Z8ob43K3/cItaP4dLw4gJJd+uD1FOR9aNAISEsXmgiFxJnabm3MEWg 65xYHdcxgKq0j9/SXiXh7D3qubVSUO7QCKMKkasc= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug Subject: [PATCH v3 16/19] libipa: agc_mean_luminance: Add support for additional constraints Date: Fri, 15 Aug 2025 12:29:36 +0200 Message-ID: <20250815102945.1602071-17-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250815102945.1602071-1-stefan.klug@ideasonboard.com> References: <20250815102945.1602071-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" Add support for additional constraints added at runtime. This is for example useful for WDR use cases where you want to add a upper constraint to limit the amount of saturated pixels. Signed-off-by: Stefan Klug --- Changes in v3: - Added this patch --- src/ipa/ipu3/algorithms/agc.cpp | 2 +- src/ipa/libipa/agc_mean_luminance.cpp | 16 ++++++++++++---- src/ipa/libipa/agc_mean_luminance.h | 3 ++- src/ipa/mali-c55/algorithms/agc.cpp | 3 ++- src/ipa/rkisp1/algorithms/agc.cpp | 4 ++-- 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp index da045640d569..b0d89541da85 100644 --- a/src/ipa/ipu3/algorithms/agc.cpp +++ b/src/ipa/ipu3/algorithms/agc.cpp @@ -117,7 +117,7 @@ int Agc::configure(IPAContext &context, /* \todo Run this again when FrameDurationLimits is passed in */ setLimits(minExposureTime_, maxExposureTime_, minAnalogueGain_, - maxAnalogueGain_); + maxAnalogueGain_, {}); resetFrameCount(); return 0; diff --git a/src/ipa/libipa/agc_mean_luminance.cpp b/src/ipa/libipa/agc_mean_luminance.cpp index 2bfafe9b2d02..5cd5d9ad2012 100644 --- a/src/ipa/libipa/agc_mean_luminance.cpp +++ b/src/ipa/libipa/agc_mean_luminance.cpp @@ -7,6 +7,7 @@ #include "agc_mean_luminance.h" +#include #include #include @@ -414,10 +415,13 @@ int AgcMeanLuminance::parseTuningData(const YamlObject &tuningData) */ void AgcMeanLuminance::setLimits(utils::Duration minExposureTime, utils::Duration maxExposureTime, - double minGain, double maxGain) + double minGain, double maxGain, + std::vector constraints) { for (auto &[id, helper] : exposureModeHelpers_) helper->setLimits(minExposureTime, maxExposureTime, minGain, maxGain); + + additionalConstraints_ = std::move(constraints); } /** @@ -495,8 +499,7 @@ double AgcMeanLuminance::constraintClampGain(uint32_t constraintModeIndex, const Histogram &hist, double gain) { - std::vector &constraints = constraintModes_[constraintModeIndex]; - for (const AgcConstraint &constraint : constraints) { + auto applyConstraint = [&gain, &hist](const AgcConstraint &constraint) { double newGain = constraint.yTarget * hist.bins() / hist.interQuantileMean(constraint.qLo, constraint.qHi); @@ -515,7 +518,12 @@ double AgcMeanLuminance::constraintClampGain(uint32_t constraintModeIndex, << newGain; gain = newGain; } - } + }; + + std::vector &constraints = constraintModes_[constraintModeIndex]; + std::for_each(constraints.begin(), constraints.end(), applyConstraint); + + std::for_each(additionalConstraints_.begin(), additionalConstraints_.end(), applyConstraint); return gain; } diff --git a/src/ipa/libipa/agc_mean_luminance.h b/src/ipa/libipa/agc_mean_luminance.h index 950b7b893754..d7ec548e3e58 100644 --- a/src/ipa/libipa/agc_mean_luminance.h +++ b/src/ipa/libipa/agc_mean_luminance.h @@ -51,7 +51,7 @@ public: } void setLimits(utils::Duration minExposureTime, utils::Duration maxExposureTime, - double minGain, double maxGain); + double minGain, double maxGain, std::vector constraints); std::map> constraintModes() { @@ -97,6 +97,7 @@ private: utils::Duration filteredExposure_; double relativeLuminanceTarget_; + std::vector additionalConstraints_; std::map> constraintModes_; std::map> exposureModeHelpers_; ControlInfoMap::Map controls_; diff --git a/src/ipa/mali-c55/algorithms/agc.cpp b/src/ipa/mali-c55/algorithms/agc.cpp index 88f8664c9823..f60fddac3f04 100644 --- a/src/ipa/mali-c55/algorithms/agc.cpp +++ b/src/ipa/mali-c55/algorithms/agc.cpp @@ -173,7 +173,8 @@ int Agc::configure(IPAContext &context, setLimits(context.configuration.agc.minShutterSpeed, context.configuration.agc.maxShutterSpeed, context.configuration.agc.minAnalogueGain, - context.configuration.agc.maxAnalogueGain); + context.configuration.agc.maxAnalogueGain, + {}); resetFrameCount(); diff --git a/src/ipa/rkisp1/algorithms/agc.cpp b/src/ipa/rkisp1/algorithms/agc.cpp index ba617a4e6e0c..d566a3fbef4a 100644 --- a/src/ipa/rkisp1/algorithms/agc.cpp +++ b/src/ipa/rkisp1/algorithms/agc.cpp @@ -205,7 +205,7 @@ int Agc::configure(IPAContext &context, const IPACameraSensorInfo &configInfo) setLimits(context.configuration.sensor.minExposureTime, context.configuration.sensor.maxExposureTime, context.configuration.sensor.minAnalogueGain, - context.configuration.sensor.maxAnalogueGain); + context.configuration.sensor.maxAnalogueGain, {}); resetFrameCount(); @@ -589,7 +589,7 @@ void Agc::process(IPAContext &context, [[maybe_unused]] const uint32_t frame, maxAnalogueGain = frameContext.agc.gain; } - setLimits(minExposureTime, maxExposureTime, minAnalogueGain, maxAnalogueGain); + setLimits(minExposureTime, maxExposureTime, minAnalogueGain, maxAnalogueGain, {}); /* * The Agc algorithm needs to know the effective exposure value that was