From patchwork Fri Oct 24 08:50:57 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 24799 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 2811FBE080 for ; Fri, 24 Oct 2025 08:53:20 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D33F260971; Fri, 24 Oct 2025 10:53:19 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="HO8MhuxT"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6D0D160938 for ; Fri, 24 Oct 2025 10:53:18 +0200 (CEST) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:7edc:62f4:c118:1549]) by perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id F04C51E46; Fri, 24 Oct 2025 10:51:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1761295893; bh=zcuiv9yXlvr31uOtzmfQAHWhJ9/2QeBPoCVD0DK3llI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HO8MhuxTuh4AjHTwdhdVf//Fh9tYgHvsNgXKi22jTtWbGnozriqnep/ZxnCpQb95k +ljmsLcn2OtTaRCotxHP600GgmqXGv4PyUGnjg6kjKyJ17QedmeTy8jWlKV7pOXZvf 9+aMeFbLCUmGEmHTwN0Bs0vm/oA4gRGDMNfjuCFc= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug Subject: [PATCH v1 33/35] libipa: agc_mean_luminance: Make startup frames and regulations speed configurable Date: Fri, 24 Oct 2025 10:50:57 +0200 Message-ID: <20251024085130.995967-34-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251024085130.995967-1-stefan.klug@ideasonboard.com> References: <20251024085130.995967-1-stefan.klug@ideasonboard.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The rkisp1 has now a good synchronization between sensor settings/isp params and stats. It can therefore benefit from a faster regulation. To do that without breaking others IPAs that use AgcMeanLuminance, move regulation speed and startup frames into member variables that can be set at runtime. As this requires the introduction of a protected access modifier. This was added, so that most of the previously public functions are now also protected, because public visibility is not needed. Signed-off-by: Stefan Klug --- src/ipa/libipa/agc_mean_luminance.cpp | 25 +++++++++++++++++++++---- src/ipa/libipa/agc_mean_luminance.h | 4 ++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/ipa/libipa/agc_mean_luminance.cpp b/src/ipa/libipa/agc_mean_luminance.cpp index 64f36bd75dd2..0cd3fbee99e8 100644 --- a/src/ipa/libipa/agc_mean_luminance.cpp +++ b/src/ipa/libipa/agc_mean_luminance.cpp @@ -34,7 +34,7 @@ namespace ipa { * Number of frames for which to run the algorithm at full speed, before slowing * down to prevent large and jarring changes in exposure from frame to frame. */ -static constexpr uint32_t kNumStartupFrames = 10; +static constexpr uint32_t kDefaultNumStartupFrames = 10; /* * Default relative luminance target @@ -144,7 +144,8 @@ static constexpr double kMaxRelativeLuminanceTarget = 0.95; */ AgcMeanLuminance::AgcMeanLuminance() - : exposureCompensation_(1.0), frameCount_(0), filteredExposure_(0s), + : numStartupFrames_(kDefaultNumStartupFrames), regulationSpeed_(0.2), + exposureCompensation_(1.0), frameCount_(0), filteredExposure_(0s), relativeLuminanceTarget_(0) { } @@ -554,10 +555,10 @@ double AgcMeanLuminance::effectiveYTarget() const */ utils::Duration AgcMeanLuminance::filterExposure(utils::Duration exposureValue) { - double speed = 0.2; + double speed = regulationSpeed_; /* Adapt instantly if we are in startup phase. */ - if (frameCount_ < kNumStartupFrames) + if (frameCount_ < numStartupFrames_) speed = 1.0; /* @@ -649,6 +650,22 @@ AgcMeanLuminance::calculateNewEv(uint32_t constraintModeIndex, * their configure() function. */ +/** + * \var AgcMeanLuminance::numStartupFrames_ + * \brief The number of startup frames + * + * During this number of frames after startup, the regulation is very aggressive + * to reach the target value within one or two cycles. + * + * \var AgcMeanLuminance::regulationSpeed_ + * The regulation speed. This controls the speed at which new target values are + * applied. The new target value is calculated as: + * + * \code{.unparsed} + * value = target * speed + oldValue * (1.0 - speed) + * \endcode + */ + } /* namespace ipa */ } /* namespace libcamera */ diff --git a/src/ipa/libipa/agc_mean_luminance.h b/src/ipa/libipa/agc_mean_luminance.h index d7ec548e3e58..b176c3e28410 100644 --- a/src/ipa/libipa/agc_mean_luminance.h +++ b/src/ipa/libipa/agc_mean_luminance.h @@ -42,6 +42,7 @@ public: double yTarget; }; +protected: void configure(utils::Duration lineDuration, const CameraSensorHelper *sensorHelper); int parseTuningData(const YamlObject &tuningData); @@ -79,6 +80,9 @@ public: frameCount_ = 0; } + uint32_t numStartupFrames_; + double regulationSpeed_; + private: virtual double estimateLuminance(const double gain) const = 0;