[{"id":37862,"web_url":"https://patchwork.libcamera.org/comment/37862/","msgid":"<176907346104.3882822.13927452429774377453@neptunite.rasen.tech>","date":"2026-01-22T09:17:41","subject":"Re: [PATCH v1 33/35] libipa: agc_mean_luminance: Make startup frames\n\tand regulations speed configurable","submitter":{"id":17,"url":"https://patchwork.libcamera.org/api/people/17/","name":"Paul Elder","email":"paul.elder@ideasonboard.com"},"content":"Quoting Stefan Klug (2025-10-24 17:50:57)\n> The rkisp1 has now a good synchronization between sensor settings/isp\n> params and stats.  It can therefore benefit from a faster regulation. To\n> do that without breaking others IPAs that use AgcMeanLuminance, move\n> regulation speed and startup frames into member variables that can be\n> set at runtime.\n> \n\nAh, configurable by IPAs, not by the user :)\n\n> As this requires the introduction of a protected access modifier. This\n> was added, so that most of the previously public functions are now also\n> protected, because public visibility is not needed.\n> \n> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n\nReviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n\n> ---\n>  src/ipa/libipa/agc_mean_luminance.cpp | 25 +++++++++++++++++++++----\n>  src/ipa/libipa/agc_mean_luminance.h   |  4 ++++\n>  2 files changed, 25 insertions(+), 4 deletions(-)\n> \n> diff --git a/src/ipa/libipa/agc_mean_luminance.cpp b/src/ipa/libipa/agc_mean_luminance.cpp\n> index 64f36bd75dd2..0cd3fbee99e8 100644\n> --- a/src/ipa/libipa/agc_mean_luminance.cpp\n> +++ b/src/ipa/libipa/agc_mean_luminance.cpp\n> @@ -34,7 +34,7 @@ namespace ipa {\n>   * Number of frames for which to run the algorithm at full speed, before slowing\n>   * down to prevent large and jarring changes in exposure from frame to frame.\n>   */\n> -static constexpr uint32_t kNumStartupFrames = 10;\n> +static constexpr uint32_t kDefaultNumStartupFrames = 10;\n>  \n>  /*\n>   * Default relative luminance target\n> @@ -144,7 +144,8 @@ static constexpr double kMaxRelativeLuminanceTarget = 0.95;\n>   */\n>  \n>  AgcMeanLuminance::AgcMeanLuminance()\n> -       : exposureCompensation_(1.0), frameCount_(0), filteredExposure_(0s),\n> +       : numStartupFrames_(kDefaultNumStartupFrames), regulationSpeed_(0.2),\n> +         exposureCompensation_(1.0), frameCount_(0), filteredExposure_(0s),\n>           relativeLuminanceTarget_(0)\n>  {\n>  }\n> @@ -554,10 +555,10 @@ double AgcMeanLuminance::effectiveYTarget() const\n>   */\n>  utils::Duration AgcMeanLuminance::filterExposure(utils::Duration exposureValue)\n>  {\n> -       double speed = 0.2;\n> +       double speed = regulationSpeed_;\n>  \n>         /* Adapt instantly if we are in startup phase. */\n> -       if (frameCount_ < kNumStartupFrames)\n> +       if (frameCount_ < numStartupFrames_)\n>                 speed = 1.0;\n>  \n>         /*\n> @@ -649,6 +650,22 @@ AgcMeanLuminance::calculateNewEv(uint32_t constraintModeIndex,\n>   * their configure() function.\n>   */\n>  \n> +/**\n> + * \\var AgcMeanLuminance::numStartupFrames_\n> + * \\brief The number of startup frames\n> + *\n> + * During this number of frames after startup, the regulation is very aggressive\n> + * to reach the target value within one or two cycles.\n> + *\n> + * \\var AgcMeanLuminance::regulationSpeed_\n> + * The regulation speed. This controls the speed at which new target values are\n> + * applied. The new target value is calculated as:\n> + *\n> + * \\code{.unparsed}\n> + * value = target * speed + oldValue * (1.0 - speed)\n> + * \\endcode\n> + */\n> +\n>  } /* namespace ipa */\n>  \n>  } /* namespace libcamera */\n> diff --git a/src/ipa/libipa/agc_mean_luminance.h b/src/ipa/libipa/agc_mean_luminance.h\n> index d7ec548e3e58..b176c3e28410 100644\n> --- a/src/ipa/libipa/agc_mean_luminance.h\n> +++ b/src/ipa/libipa/agc_mean_luminance.h\n> @@ -42,6 +42,7 @@ public:\n>                 double yTarget;\n>         };\n>  \n> +protected:\n>         void configure(utils::Duration lineDuration, const CameraSensorHelper *sensorHelper);\n>         int parseTuningData(const YamlObject &tuningData);\n>  \n> @@ -79,6 +80,9 @@ public:\n>                 frameCount_ = 0;\n>         }\n>  \n> +       uint32_t numStartupFrames_;\n> +       double regulationSpeed_;\n> +\n>  private:\n>         virtual double estimateLuminance(const double gain) const = 0;\n>  \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 BEDB1BDCBF\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 22 Jan 2026 09:17:48 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 7D72A61FF3;\n\tThu, 22 Jan 2026 10:17:48 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 296C161FBF\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 22 Jan 2026 10:17:47 +0100 (CET)","from neptunite.rasen.tech (unknown\n\t[IPv6:2404:7a81:160:2100:8816:a947:ebed:2ec7])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 453ED2DD;\n\tThu, 22 Jan 2026 10:17:14 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"u/GVWlFb\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1769073434;\n\tbh=mMYJul7hWP+YvUTr8w4vsfFq4VJLqU7FBuMr37cSccE=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=u/GVWlFb21tSintuDDW/Pk26wxfbbvoh7OUT/qDUUZHgJm7wxnaNCnbPcTd3V2zMF\n\tEK5nHtXwMuZsnJX9XYvX3ZPxWD8phmCuxHnUkuNdybzSj6FlJ33kohPjJJR4T/dFsr\n\tq7K1dCbIHKJltyBlYUBpgXdXfmkFLKFpFhzy4ZII=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20251024085130.995967-34-stefan.klug@ideasonboard.com>","References":"<20251024085130.995967-1-stefan.klug@ideasonboard.com>\n\t<20251024085130.995967-34-stefan.klug@ideasonboard.com>","Subject":"Re: [PATCH v1 33/35] libipa: agc_mean_luminance: Make startup frames\n\tand regulations speed configurable","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":"Thu, 22 Jan 2026 18:17:41 +0900","Message-ID":"<176907346104.3882822.13927452429774377453@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>"}}]