From patchwork Fri Nov 14 14:17:08 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 25065 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 D9956C3333 for ; Fri, 14 Nov 2025 14:17:40 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2B3E260B2F; Fri, 14 Nov 2025 15:17:38 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="lxS4vk15"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D707560AB1 for ; Fri, 14 Nov 2025 15:17:22 +0100 (CET) Received: from [192.168.1.101] (93-61-96-190.ip145.fastwebnet.it [93.61.96.190]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id C8B141E1B; Fri, 14 Nov 2025 15:15:21 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1763129722; bh=iYzyCp/zPGlYBdF4UutFJ3h+dospQqXQ5PWcTaVGjvI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=lxS4vk15lcJcKgdvgl70g50Eu/4jlet3Zhhb6uhbb73/fUK/amms7RNN1sjaZZURU gjvwHupJYfXpXvt9Lcl1J0SQMhTZYpAb1sda8DyrTSVffk7IttVn4JA9SQ5lGNSgkQ RybGZgKG7KqTNczdA31fLK8469mVWlcCUbz8TRY0= From: Jacopo Mondi Date: Fri, 14 Nov 2025 15:17:08 +0100 Subject: [PATCH v3 13/19] ipa: libipa: agc: Calculate exposure limits with frame duration MIME-Version: 1.0 Message-Id: <20251114-exposure-limits-v3-13-b7c07feba026@ideasonboard.com> References: <20251114-exposure-limits-v3-0-b7c07feba026@ideasonboard.com> In-Reply-To: <20251114-exposure-limits-v3-0-b7c07feba026@ideasonboard.com> To: =?utf-8?q?Niklas_S=C3=B6derlund?= , Robert Mader , libcamera-devel@lists.libcamera.org Cc: Jacopo Mondi X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=8940; i=jacopo.mondi@ideasonboard.com; h=from:subject:message-id; bh=iYzyCp/zPGlYBdF4UutFJ3h+dospQqXQ5PWcTaVGjvI=; b=owEBbQKS/ZANAwAKAXI0Bo8WoVY8AcsmYgBpFznrCjePb8iR8uvULI4MogZSVXGV6RI1SsHOT NwC0GpX3FOJAjMEAAEKAB0WIQS1xD1IgJogio9YOMByNAaPFqFWPAUCaRc56wAKCRByNAaPFqFW PEb7D/4t4YPeatYPATmn+7ZrsG1q+DmIjTSkRGYa/MjNXUMmdp+c1QzM+x0OUpsMkKFaCFLT7AJ o+DJSTZTd6f4z6fxGZ8gFCKzlDfXZ0tlnwz48QF/bC0bLjVR3V/GgLAbM0TdO/fIsV6QNbFY+Gs IjbDDEQBris1EwvG9Aq1ZJJzbsZwmotpKviodH6UgOTQ4ZfHXOlkGHFaZfz9IBo3qCMMkicHxLx GPierFSKwe5+tu+e2rd6eXIZQziBu8kap2S8cApcFHG0TKfnaEwJ1oG3cp49llJx9gIWKHfjaeB mWq4fts5zm3Jn2SHur1f4q3hHSfH/tbPEvF1c+fnizNaGOac3UyCtiawnZ/V2IN2ECavSPCADUw UTiVcYAMTBl3vDHkVqYaP5bDofNU4e8fKMpLAhVRg7hWbfSXunAwvbnCKrxWo+SPTw6UMO9I48+ hO1mdlwpEcqpyRkZl0QNt63c0FJ1zYrURTOgg9hZknqIicPEImIrlVsDIa/V4NjT1ZDppYwrdwh Fmgwk44/WjvGpiH6GWRp5bixtm6eo8gSXpQ9kOH8TY4JThfLb2ywGDeNUsBoed7SFnxre/lXXfg z2spKB/ir+VRGxX7ECgrlXQtCvQJPgmjq4DyrDYxnsR8ntozgZF1M5DXdmyR4g5hcl9LQ1XRDIC E5Xc0J+Nggh9sDg== X-Developer-Key: i=jacopo.mondi@ideasonboard.com; a=openpgp; fpr=72392EDC88144A65C701EA9BA5826A2587AD026B 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" Similarly to what now happens at configure() time, the AGC maximum shutter time is calculated at runtime in the setLimits() function using the CameraSensorHelper. Factor-out in the ExposureModeHelper class the maximum shutter time calculation from the configure() function so that it can be performed at setLimits() time too. Update the only IPA that handles limits update at runtime (RkISP1) to pass to the AGC the updated frame durations. Signed-off-by: Jacopo Mondi --- src/ipa/libipa/agc_mean_luminance.cpp | 5 +++- src/ipa/libipa/agc_mean_luminance.h | 3 ++- src/ipa/libipa/exposure_mode_helper.cpp | 47 +++++++++++++++++++++------------ src/ipa/libipa/exposure_mode_helper.h | 5 +++- src/ipa/rkisp1/algorithms/agc.cpp | 8 +++--- 5 files changed, 43 insertions(+), 25 deletions(-) diff --git a/src/ipa/libipa/agc_mean_luminance.cpp b/src/ipa/libipa/agc_mean_luminance.cpp index 602050729fd08649e2db8d07623a8a39e7a53a77..0c8e15030c377ac0797dbdc9d53694ee894cd9b8 100644 --- a/src/ipa/libipa/agc_mean_luminance.cpp +++ b/src/ipa/libipa/agc_mean_luminance.cpp @@ -461,6 +461,7 @@ int AgcMeanLuminance::parseTuningData(const YamlObject &tuningData) * \brief Set the ExposureModeHelper limits for this class * \param[in] minExposureTime Minimum exposure time to allow * \param[in] maxExposureTime Maximum ewposure time to allow + * \param[in] maxFrameDuration Maximum frame duration * \param[in] minGain Minimum gain to allow * \param[in] maxGain Maximum gain to allow * \param[in] constraints Additional constraints to apply @@ -470,11 +471,13 @@ int AgcMeanLuminance::parseTuningData(const YamlObject &tuningData) */ void AgcMeanLuminance::setLimits(utils::Duration minExposureTime, utils::Duration maxExposureTime, + utils::Duration maxFrameDuration, double minGain, double maxGain, std::vector constraints) { for (auto &[id, helper] : exposureModeHelpers_) - helper->setLimits(minExposureTime, maxExposureTime, minGain, maxGain); + helper->setLimits(minExposureTime, maxExposureTime, maxFrameDuration, + minGain, maxGain); additionalConstraints_ = std::move(constraints); } diff --git a/src/ipa/libipa/agc_mean_luminance.h b/src/ipa/libipa/agc_mean_luminance.h index c3c8ce1cdda9229eca400b730f2ee896e9a0af93..535f94502dc2649a5f4ba49a7040de12f9f74179 100644 --- a/src/ipa/libipa/agc_mean_luminance.h +++ b/src/ipa/libipa/agc_mean_luminance.h @@ -62,7 +62,8 @@ public: } void setLimits(utils::Duration minExposureTime, utils::Duration maxExposureTime, - double minGain, double maxGain, std::vector constraints); + utils::Duration maxFrameDuration, double minGain, double maxGain, + std::vector constraints); const std::map> &constraintModes() const { diff --git a/src/ipa/libipa/exposure_mode_helper.cpp b/src/ipa/libipa/exposure_mode_helper.cpp index 45f51f9088170c983bb0de2c18714627514c5641..fad13ff1521498244224a8a5f375738ee3fc9ff2 100644 --- a/src/ipa/libipa/exposure_mode_helper.cpp +++ b/src/ipa/libipa/exposure_mode_helper.cpp @@ -109,6 +109,27 @@ ExposureModeHelper::ExposureModeHelper(const SpanmaxShutterTime(maxFrameDuration, + sensor_.lineDuration_) + : minExposureTime; +} + /** * \brief Configure sensor details * \param[in] sensorConfig The sensor configuration @@ -136,27 +157,15 @@ void ExposureModeHelper::configure(const SensorConfiguration &sensorConfig, minGain_ = sensor_.minGain_; maxGain_ = sensor_.maxGain_; - minExposureTime_ = sensor_.minExposureTime_; - - /* - * Compute the maximum shutter time. - * - * If maxExposureTime is equal to minExposureTime then we use them - * to fix the exposure time. - * - * Otherwise, if the exposure can range between a min and max delegate - * the maximum shutter time calculation to the sensor helper. - */ - maxExposureTime_ = minExposureTime_ != sensorConfig.maxExposureTime_ - ? sensorHelper_->maxShutterTime(sensorConfig.maxFrameDuration_, - sensorConfig.lineDuration_) - : minExposureTime_; + setMaxExposure(sensorConfig.minExposureTime_, sensorConfig.maxExposureTime_, + sensorConfig.maxFrameDuration_); } /** * \brief Set the exposure time and gain limits * \param[in] minExposureTime The minimum exposure time supported * \param[in] maxExposureTime The maximum exposure time supported + * \param[in] maxFrameDuration The maximum frame duration * \param[in] minGain The minimum analogue gain supported * \param[in] maxGain The maximum analogue gain supported * @@ -168,15 +177,19 @@ void ExposureModeHelper::configure(const SensorConfiguration &sensorConfig, * If the algorithm using the helpers needs to indicate that either exposure time * or analogue gain or both should be fixed it can do so by setting both the * minima and maxima to the same value. + * + * The exposure time limits are calculated using \a maxFrameDuration as the + * upper bound, the \a maxExposureTime paramter effectivelly only serves + * to indicate that the caller wants a fixed exposure value. */ void ExposureModeHelper::setLimits(utils::Duration minExposureTime, utils::Duration maxExposureTime, + utils::Duration maxFrameDuration, double minGain, double maxGain) { - minExposureTime_ = minExposureTime; - maxExposureTime_ = maxExposureTime; minGain_ = minGain; maxGain_ = maxGain; + setMaxExposure(minExposureTime, maxExposureTime, maxFrameDuration); } utils::Duration ExposureModeHelper::clampExposureTime(utils::Duration exposureTime, diff --git a/src/ipa/libipa/exposure_mode_helper.h b/src/ipa/libipa/exposure_mode_helper.h index e41c58767eee65dd27946336beb2bc182dd4ab58..36791c99face056835b0bb2d28b533380e8d9b95 100644 --- a/src/ipa/libipa/exposure_mode_helper.h +++ b/src/ipa/libipa/exposure_mode_helper.h @@ -41,12 +41,15 @@ public: void configure(const SensorConfiguration &sensorConfig, const CameraSensorHelper *sensorHelper); void setLimits(utils::Duration minExposureTime, utils::Duration maxExposureTime, - double minGain, double maxGain); + utils::Duration maxFrameDuration, double minGain, double maxGain); std::tuple splitExposure(utils::Duration exposure) const; private: + void setMaxExposure(utils::Duration minExposureTime, + utils::Duration maxExposureTime, + utils::Duration maxFrameDuration); utils::Duration clampExposureTime(utils::Duration exposureTime, double *quantizationGain = nullptr) const; double clampGain(double gain, double *quantizationGain = nullptr) const; diff --git a/src/ipa/rkisp1/algorithms/agc.cpp b/src/ipa/rkisp1/algorithms/agc.cpp index de2980485f2d3a8973f065981f8cdd520e3dfc47..db318a2c49f2fbd9b00222ec699a657eed131595 100644 --- a/src/ipa/rkisp1/algorithms/agc.cpp +++ b/src/ipa/rkisp1/algorithms/agc.cpp @@ -580,9 +580,7 @@ void Agc::process(IPAContext &context, [[maybe_unused]] const uint32_t frame, if (frameContext.agc.autoExposureEnabled) { minExposureTime = context.configuration.sensor.minExposureTime; - maxExposureTime = std::clamp(frameContext.agc.maxFrameDuration, - context.configuration.sensor.minExposureTime, - context.configuration.sensor.maxExposureTime); + maxExposureTime = context.configuration.sensor.maxExposureTime; } else { minExposureTime = context.configuration.sensor.lineDuration * frameContext.agc.exposure; @@ -601,8 +599,8 @@ void Agc::process(IPAContext &context, [[maybe_unused]] const uint32_t frame, if (context.activeState.wdr.mode != controls::WdrOff) additionalConstraints.push_back(context.activeState.wdr.constraint); - setLimits(minExposureTime, maxExposureTime, minAnalogueGain, maxAnalogueGain, - std::move(additionalConstraints)); + setLimits(minExposureTime, maxExposureTime, frameContext.agc.maxFrameDuration, + minAnalogueGain, maxAnalogueGain, std::move(additionalConstraints)); /* * The Agc algorithm needs to know the effective exposure value that was