[{"id":35906,"web_url":"https://patchwork.libcamera.org/comment/35906/","msgid":"<175822008984.3990114.9925162157685072016@ping.linuxembedded.co.uk>","date":"2025-09-18T18:28:09","subject":"Re: [PATCH v4 16/19] libipa: agc_mean_luminance: Add support for\n\tadditional constraints","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Stefan Klug (2025-09-18 15:43:25)\n> Add support for additional constraints added at runtime. This is for\n> example useful for WDR use cases where you want to add an upper\n> constraint to limit the amount of saturated pixels.\n> \n> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n> \n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> ---\n> \n> Changes in v4:\n> - Added missings docs for the constraints parameter\n> - Collected tag\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 | 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(-)\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 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>                                  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 +500,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 +519,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 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>         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> @@ -590,7 +590,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 6B43CBE173\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 18 Sep 2025 18:28:16 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1B9B769371;\n\tThu, 18 Sep 2025 20:28:15 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D12DA62C3A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 18 Sep 2025 20:28:12 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id C1DCC596;\n\tThu, 18 Sep 2025 20:26:52 +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=\"SEN4M5AA\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1758220012;\n\tbh=n22Bwn996BVDuR4ws2nIqVFKQeDvuGUvslqOhn7BOco=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=SEN4M5AA1g7uCiUjfLlUd0OfaSqeXTvaXyFkNj7Iq1mvh58Ui7m0BmVwMkW1GGFgz\n\th9qJ8Pmiy6VLXaj+0ZJrfzCoy4dSLYC5IXEpmAxnrX6vCXtyNyi3SC6One5XLWqmVp\n\tXTByUu6/kx7wsoHqpf+u1jpybDpBoED1ctyowki8=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20250918144333.108695-17-stefan.klug@ideasonboard.com>","References":"<20250918144333.108695-1-stefan.klug@ideasonboard.com>\n\t<20250918144333.108695-17-stefan.klug@ideasonboard.com>","Subject":"Re: [PATCH v4 16/19] libipa: agc_mean_luminance: Add support for\n\tadditional constraints","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"Stefan Klug <stefan.klug@ideasonboard.com>,\n\tPaul Elder <paul.elder@ideasonboard.com>","To":"Stefan Klug <stefan.klug@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Thu, 18 Sep 2025 19:28:09 +0100","Message-ID":"<175822008984.3990114.9925162157685072016@ping.linuxembedded.co.uk>","User-Agent":"alot/0.9.1","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>"}}]