[{"id":35702,"web_url":"https://patchwork.libcamera.org/comment/35702/","msgid":"<175706897255.1787083.5339650835029572354@neptunite.rasen.tech>","date":"2025-09-05T10:42:52","subject":"Re: [PATCH v3 16/19] libipa: agc_mean_luminance: Add support for\n\tadditional constraints","submitter":{"id":17,"url":"https://patchwork.libcamera.org/api/people/17/","name":"Paul Elder","email":"paul.elder@ideasonboard.com"},"content":"Quoting Stefan Klug (2025-08-15 19:29:36)\n> Add support for additional constraints added at runtime. This is for\n> example useful for WDR use cases where you want to add a upper\n\ns/a /an /\n\n> constraint to limit the amount of saturated pixels.\n> \n> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n\nReviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n\n> \n> ---\n> \n> Changes in v3:\n> - Added this patch\n> ---\n>  src/ipa/ipu3/algorithms/agc.cpp       |  2 +-\n>  src/ipa/libipa/agc_mean_luminance.cpp | 16 ++++++++++++----\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, 19 insertions(+), 9 deletions(-)\n> \n> diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp\n> index 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>         /* \\todo Run this again when FrameDurationLimits is passed in */\n>         setLimits(minExposureTime_, maxExposureTime_, minAnalogueGain_,\n> -                 maxAnalogueGain_);\n> +                 maxAnalogueGain_, {});\n>         resetFrameCount();\n>  \n>         return 0;\n> diff --git a/src/ipa/libipa/agc_mean_luminance.cpp b/src/ipa/libipa/agc_mean_luminance.cpp\n> index 2bfafe9b2d02..5cd5d9ad2012 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> @@ -414,10 +415,13 @@ int AgcMeanLuminance::parseTuningData(const YamlObject &tuningData)\n>   */\n>  void AgcMeanLuminance::setLimits(utils::Duration minExposureTime,\n>                                  utils::Duration maxExposureTime,\n> -                                double minGain, double maxGain)\n> +                                double minGain, double maxGain,\n> +                                std::vector<AgcMeanLuminance::AgcConstraint> constraints)\n>  {\n>         for (auto &[id, helper] : exposureModeHelpers_)\n>                 helper->setLimits(minExposureTime, maxExposureTime, minGain, maxGain);\n> +\n> +       additionalConstraints_ = std::move(constraints);\n>  }\n>  \n>  /**\n> @@ -495,8 +499,7 @@ double AgcMeanLuminance::constraintClampGain(uint32_t constraintModeIndex,\n>                                              const Histogram &hist,\n>                                              double gain)\n>  {\n> -       std::vector<AgcConstraint> &constraints = constraintModes_[constraintModeIndex];\n> -       for (const AgcConstraint &constraint : constraints) {\n> +       auto applyConstraint = [&gain, &hist](const AgcConstraint &constraint) {\n>                 double newGain = constraint.yTarget * hist.bins() /\n>                                  hist.interQuantileMean(constraint.qLo, constraint.qHi);\n>  \n> @@ -515,7 +518,12 @@ double AgcMeanLuminance::constraintClampGain(uint32_t constraintModeIndex,\n>                                 << newGain;\n>                         gain = newGain;\n>                 }\n> -       }\n> +       };\n> +\n> +       std::vector<AgcConstraint> &constraints = constraintModes_[constraintModeIndex];\n> +       std::for_each(constraints.begin(), constraints.end(), applyConstraint);\n> +\n> +       std::for_each(additionalConstraints_.begin(), additionalConstraints_.end(), applyConstraint);\n>  \n>         return gain;\n>  }\n> diff --git a/src/ipa/libipa/agc_mean_luminance.h b/src/ipa/libipa/agc_mean_luminance.h\n> index 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>         }\n>  \n>         void setLimits(utils::Duration minExposureTime, utils::Duration maxExposureTime,\n> -                      double minGain, double maxGain);\n> +                      double minGain, double maxGain, std::vector<AgcConstraint> constraints);\n>  \n>         std::map<int32_t, std::vector<AgcConstraint>> constraintModes()\n>         {\n> @@ -97,6 +97,7 @@ private:\n>         utils::Duration filteredExposure_;\n>         double relativeLuminanceTarget_;\n>  \n> +       std::vector<AgcConstraint> additionalConstraints_;\n>         std::map<int32_t, std::vector<AgcConstraint>> constraintModes_;\n>         std::map<int32_t, std::shared_ptr<ExposureModeHelper>> exposureModeHelpers_;\n>         ControlInfoMap::Map controls_;\n> diff --git a/src/ipa/mali-c55/algorithms/agc.cpp b/src/ipa/mali-c55/algorithms/agc.cpp\n> index 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>         setLimits(context.configuration.agc.minShutterSpeed,\n>                   context.configuration.agc.maxShutterSpeed,\n>                   context.configuration.agc.minAnalogueGain,\n> -                 context.configuration.agc.maxAnalogueGain);\n> +                 context.configuration.agc.maxAnalogueGain,\n> +                 {});\n>  \n>         resetFrameCount();\n>  \n> diff --git a/src/ipa/rkisp1/algorithms/agc.cpp b/src/ipa/rkisp1/algorithms/agc.cpp\n> index ba617a4e6e0c..d566a3fbef4a 100644\n> --- a/src/ipa/rkisp1/algorithms/agc.cpp\n> +++ b/src/ipa/rkisp1/algorithms/agc.cpp\n> @@ -205,7 +205,7 @@ int Agc::configure(IPAContext &context, const IPACameraSensorInfo &configInfo)\n>         setLimits(context.configuration.sensor.minExposureTime,\n>                   context.configuration.sensor.maxExposureTime,\n>                   context.configuration.sensor.minAnalogueGain,\n> -                 context.configuration.sensor.maxAnalogueGain);\n> +                 context.configuration.sensor.maxAnalogueGain, {});\n>  \n>         resetFrameCount();\n>  \n> @@ -589,7 +589,7 @@ void Agc::process(IPAContext &context, [[maybe_unused]] const uint32_t frame,\n>                 maxAnalogueGain = frameContext.agc.gain;\n>         }\n>  \n> -       setLimits(minExposureTime, maxExposureTime, minAnalogueGain, maxAnalogueGain);\n> +       setLimits(minExposureTime, maxExposureTime, minAnalogueGain, maxAnalogueGain, {});\n>  \n>         /*\n>          * The Agc algorithm needs to know the effective exposure value that was\n> -- \n> 2.48.1\n>","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 BF3C1BEFBE\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  5 Sep 2025 10:43:00 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 7D1EE69345;\n\tFri,  5 Sep 2025 12:43:00 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 5EEFC69337\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  5 Sep 2025 12:42:58 +0200 (CEST)","from neptunite.rasen.tech (unknown\n\t[IPv6:2404:7a81:160:2100:dbfb:387c:7405:52bc])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id E2BE11129; \n\tFri,  5 Sep 2025 12:41:47 +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=\"OGCqgF5q\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1757068908;\n\tbh=cxW47A/RG/gBBhOleZYNc68r+py5uGnyrxV6JCdbxO0=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=OGCqgF5qDR39z9oHrZgEQox6f1qrTZ48of/lDgO6P1CDnWnPrlLuyl2WRfTqadalu\n\tP1wzd5E4AINLLlxXOJfutXPkDNeU/Cn8L4Tv4X4IeNQuluy1zsOb55fbV7esZ1i3kz\n\tHFOwCMj6n0mMaiyaesv4henJPIXvQ+fyyA69camM=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20250815102945.1602071-17-stefan.klug@ideasonboard.com>","References":"<20250815102945.1602071-1-stefan.klug@ideasonboard.com>\n\t<20250815102945.1602071-17-stefan.klug@ideasonboard.com>","Subject":"Re: [PATCH v3 16/19] libipa: agc_mean_luminance: Add support for\n\tadditional constraints","From":"Paul Elder <paul.elder@ideasonboard.com>","Cc":"Stefan Klug <stefan.klug@ideasonboard.com>","To":"Stefan Klug <stefan.klug@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Fri, 05 Sep 2025 19:42:52 +0900","Message-ID":"<175706897255.1787083.5339650835029572354@neptunite.rasen.tech>","User-Agent":"alot/0.0.0","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>"}}]