{"id":24425,"url":"https://patchwork.libcamera.org/api/patches/24425/?format=json","web_url":"https://patchwork.libcamera.org/patch/24425/","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":"<20250919094041.183031-17-stefan.klug@ideasonboard.com>","date":"2025-09-19T09:40:31","name":"[v5,16/19] libipa: agc_mean_luminance: Add support for additional constraints","commit_ref":"06fe931d7995523d0d3ef69b1040b21ea48168f6","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/24425/mbox/","series":[{"id":5450,"url":"https://patchwork.libcamera.org/api/series/5450/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=5450","date":"2025-09-19T09:40:15","name":"Implement WDR algorithm","version":5,"mbox":"https://patchwork.libcamera.org/series/5450/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/24425/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/24425/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 957D4C3331\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 19 Sep 2025 09:41:45 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 675586B5C8;\n\tFri, 19 Sep 2025 11:41:44 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2561262C38\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 19 Sep 2025 11:41:41 +0200 (CEST)","from ideasonboard.com (unknown\n\t[IPv6:2a00:6020:448c:6c00:4d54:eab8:98ca:163b])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id E3B87C67;\n\tFri, 19 Sep 2025 11:40:20 +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=\"vRx0c5d0\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1758274821;\n\tbh=8QESrQ2P6bkZ2N/UKPNrA4RaLN0gtxHRQyM5r/MAJM4=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=vRx0c5d06lrgaRXrSpBcOqfbUhCELlB54/wyQnd/SbFStDjr/pZH1nMPk+JOwYfnC\n\tYdecA9pstMq+zdDasiLoaMznuaA5Kb+upj3SSwLk1hNKX5jH2N8O++bR//2Ced34d8\n\tY2LIdwaMCNEWnbp50Nd3pc9JQnEsthZ1C0DQ7cM8=","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>,\n\tKieran Bingham <kieran.bingham@ideasonboard.com>","Subject":"[PATCH v5 16/19] libipa: agc_mean_luminance: Add support for\n\tadditional constraints","Date":"Fri, 19 Sep 2025 11:40:31 +0200","Message-ID":"<20250919094041.183031-17-stefan.klug@ideasonboard.com>","X-Mailer":"git-send-email 2.48.1","In-Reply-To":"<20250919094041.183031-1-stefan.klug@ideasonboard.com>","References":"<20250919094041.183031-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>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n---\n\nChanges in v5:\n- Collected tag\n\nChanges in v4:\n- Added missing 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":["v5","16/19"]}