{"id":24405,"url":"https://patchwork.libcamera.org/api/patches/24405/?format=json","web_url":"https://patchwork.libcamera.org/patch/24405/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/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":"<20250918144333.108695-17-stefan.klug@ideasonboard.com>","date":"2025-09-18T14:43:25","name":"[v4,16/19] libipa: agc_mean_luminance: Add support for additional constraints","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"455ec6d38086a01b0217dbd94b4d2c1165259b20","submitter":{"id":184,"url":"https://patchwork.libcamera.org/api/people/184/?format=json","name":"Stefan Klug","email":"stefan.klug@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/24405/mbox/","series":[{"id":5449,"url":"https://patchwork.libcamera.org/api/series/5449/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=5449","date":"2025-09-18T14:43:09","name":"Implement WDR algorithm","version":4,"mbox":"https://patchwork.libcamera.org/series/5449/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/24405/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/24405/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 3AE1DC32C2\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 18 Sep 2025 14:44:37 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 9182169385;\n\tThu, 18 Sep 2025 16:44:36 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 3134669385\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 18 Sep 2025 16:44:33 +0200 (CEST)","from ideasonboard.com (unknown\n\t[IPv6:2a00:6020:448c:6c00:ace3:d2c2:5eff:9cc5])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 7BD2F15EE; \n\tThu, 18 Sep 2025 16:43:13 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"Iqnj0R8u\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1758206593;\n\tbh=gi941HfRJagZuymHyqcptRQwT/eEd3sqBWkoTAKVsC4=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=Iqnj0R8ui5ogwUlr7F5pJsMjqNH7z0maeNF8INiVJIDvm5OpNwprO1mFddVa8AZz4\n\tv8DgXopo2W1A+SXkkcaSmkXid3VW7XKtbzdXRlahZLqPqD+AgyLg+9jX+wsFvnZJ1s\n\tFctwCNyYkFQ2FOYKgNVbtWiNbmvWA9OTf/KGhIOI=","From":"Stefan Klug <stefan.klug@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"Stefan Klug <stefan.klug@ideasonboard.com>,\n\tPaul Elder <paul.elder@ideasonboard.com>","Subject":"[PATCH v4 16/19] libipa: agc_mean_luminance: Add support for\n\tadditional constraints","Date":"Thu, 18 Sep 2025 16:43:25 +0200","Message-ID":"<20250918144333.108695-17-stefan.klug@ideasonboard.com>","X-Mailer":"git-send-email 2.48.1","In-Reply-To":"<20250918144333.108695-1-stefan.klug@ideasonboard.com>","References":"<20250918144333.108695-1-stefan.klug@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","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 support for additional constraints added at runtime. This is for\nexample useful for WDR use cases where you want to add an upper\nconstraint to limit the amount of saturated pixels.\n\nSigned-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\nReviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n\n---\n\nChanges in v4:\n- Added missings docs for the constraints parameter\n- Collected tag\n\nChanges in v3:\n- Added this patch\n---\n src/ipa/ipu3/algorithms/agc.cpp       |  2 +-\n src/ipa/libipa/agc_mean_luminance.cpp | 17 +++++++++++++----\n src/ipa/libipa/agc_mean_luminance.h   |  3 ++-\n src/ipa/mali-c55/algorithms/agc.cpp   |  3 ++-\n src/ipa/rkisp1/algorithms/agc.cpp     |  4 ++--\n 5 files changed, 20 insertions(+), 9 deletions(-)","diff":"diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp\nindex da045640d569..b0d89541da85 100644\n--- a/src/ipa/ipu3/algorithms/agc.cpp\n+++ b/src/ipa/ipu3/algorithms/agc.cpp\n@@ -117,7 +117,7 @@ int Agc::configure(IPAContext &context,\n \n \t/* \\todo Run this again when FrameDurationLimits is passed in */\n \tsetLimits(minExposureTime_, maxExposureTime_, minAnalogueGain_,\n-\t\t  maxAnalogueGain_);\n+\t\t  maxAnalogueGain_, {});\n \tresetFrameCount();\n \n \treturn 0;\ndiff --git a/src/ipa/libipa/agc_mean_luminance.cpp b/src/ipa/libipa/agc_mean_luminance.cpp\nindex 45eba97516f3..64f36bd75dd2 100644\n--- a/src/ipa/libipa/agc_mean_luminance.cpp\n+++ b/src/ipa/libipa/agc_mean_luminance.cpp\n@@ -7,6 +7,7 @@\n \n #include \"agc_mean_luminance.h\"\n \n+#include <algorithm>\n #include <cmath>\n \n #include <libcamera/base/log.h>\n@@ -408,16 +409,20 @@ int AgcMeanLuminance::parseTuningData(const YamlObject &tuningData)\n  * \\param[in] maxExposureTime Maximum ewposure time to allow\n  * \\param[in] minGain Minimum gain to allow\n  * \\param[in] maxGain Maximum gain to allow\n+ * \\param[in] constraints Additional constraints to apply\n  *\n  * This function calls \\ref ExposureModeHelper::setLimits() for each\n  * ExposureModeHelper that has been created for this class.\n  */\n void AgcMeanLuminance::setLimits(utils::Duration minExposureTime,\n \t\t\t\t utils::Duration maxExposureTime,\n-\t\t\t\t double minGain, double maxGain)\n+\t\t\t\t double minGain, double maxGain,\n+\t\t\t\t std::vector<AgcMeanLuminance::AgcConstraint> constraints)\n {\n \tfor (auto &[id, helper] : exposureModeHelpers_)\n \t\thelper->setLimits(minExposureTime, maxExposureTime, minGain, maxGain);\n+\n+\tadditionalConstraints_ = std::move(constraints);\n }\n \n /**\n@@ -495,8 +500,7 @@ double AgcMeanLuminance::constraintClampGain(uint32_t constraintModeIndex,\n \t\t\t\t\t     const Histogram &hist,\n \t\t\t\t\t     double gain)\n {\n-\tstd::vector<AgcConstraint> &constraints = constraintModes_[constraintModeIndex];\n-\tfor (const AgcConstraint &constraint : constraints) {\n+\tauto applyConstraint = [&gain, &hist](const AgcConstraint &constraint) {\n \t\tdouble newGain = constraint.yTarget * hist.bins() /\n \t\t\t\t hist.interQuantileMean(constraint.qLo, constraint.qHi);\n \n@@ -515,7 +519,12 @@ double AgcMeanLuminance::constraintClampGain(uint32_t constraintModeIndex,\n \t\t\t\t<< newGain;\n \t\t\tgain = newGain;\n \t\t}\n-\t}\n+\t};\n+\n+\tstd::vector<AgcConstraint> &constraints = constraintModes_[constraintModeIndex];\n+\tstd::for_each(constraints.begin(), constraints.end(), applyConstraint);\n+\n+\tstd::for_each(additionalConstraints_.begin(), additionalConstraints_.end(), applyConstraint);\n \n \treturn gain;\n }\ndiff --git a/src/ipa/libipa/agc_mean_luminance.h b/src/ipa/libipa/agc_mean_luminance.h\nindex 950b7b893754..d7ec548e3e58 100644\n--- a/src/ipa/libipa/agc_mean_luminance.h\n+++ b/src/ipa/libipa/agc_mean_luminance.h\n@@ -51,7 +51,7 @@ public:\n \t}\n \n \tvoid setLimits(utils::Duration minExposureTime, utils::Duration maxExposureTime,\n-\t\t       double minGain, double maxGain);\n+\t\t       double minGain, double maxGain, std::vector<AgcConstraint> constraints);\n \n \tstd::map<int32_t, std::vector<AgcConstraint>> constraintModes()\n \t{\n@@ -97,6 +97,7 @@ private:\n \tutils::Duration filteredExposure_;\n \tdouble relativeLuminanceTarget_;\n \n+\tstd::vector<AgcConstraint> additionalConstraints_;\n \tstd::map<int32_t, std::vector<AgcConstraint>> constraintModes_;\n \tstd::map<int32_t, std::shared_ptr<ExposureModeHelper>> exposureModeHelpers_;\n \tControlInfoMap::Map controls_;\ndiff --git a/src/ipa/mali-c55/algorithms/agc.cpp b/src/ipa/mali-c55/algorithms/agc.cpp\nindex 88f8664c9823..f60fddac3f04 100644\n--- a/src/ipa/mali-c55/algorithms/agc.cpp\n+++ b/src/ipa/mali-c55/algorithms/agc.cpp\n@@ -173,7 +173,8 @@ int Agc::configure(IPAContext &context,\n \tsetLimits(context.configuration.agc.minShutterSpeed,\n \t\t  context.configuration.agc.maxShutterSpeed,\n \t\t  context.configuration.agc.minAnalogueGain,\n-\t\t  context.configuration.agc.maxAnalogueGain);\n+\t\t  context.configuration.agc.maxAnalogueGain,\n+\t\t  {});\n \n \tresetFrameCount();\n \ndiff --git a/src/ipa/rkisp1/algorithms/agc.cpp b/src/ipa/rkisp1/algorithms/agc.cpp\nindex d0337fd0027f..d1b6bb7196f4 100644\n--- a/src/ipa/rkisp1/algorithms/agc.cpp\n+++ b/src/ipa/rkisp1/algorithms/agc.cpp\n@@ -206,7 +206,7 @@ int Agc::configure(IPAContext &context, const IPACameraSensorInfo &configInfo)\n \tsetLimits(context.configuration.sensor.minExposureTime,\n \t\t  context.configuration.sensor.maxExposureTime,\n \t\t  context.configuration.sensor.minAnalogueGain,\n-\t\t  context.configuration.sensor.maxAnalogueGain);\n+\t\t  context.configuration.sensor.maxAnalogueGain, {});\n \n \tresetFrameCount();\n \n@@ -590,7 +590,7 @@ void Agc::process(IPAContext &context, [[maybe_unused]] const uint32_t frame,\n \t\tmaxAnalogueGain = frameContext.agc.gain;\n \t}\n \n-\tsetLimits(minExposureTime, maxExposureTime, minAnalogueGain, maxAnalogueGain);\n+\tsetLimits(minExposureTime, maxExposureTime, minAnalogueGain, maxAnalogueGain, {});\n \n \t/*\n \t * The Agc algorithm needs to know the effective exposure value that was\n","prefixes":["v4","16/19"]}