From patchwork Tue Oct 28 09:31:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 24845 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 E14E6BE080 for ; Tue, 28 Oct 2025 09:32:25 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 91F68607EE; Tue, 28 Oct 2025 10:32:23 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="BWNDT1Yd"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0400C6079C for ; Tue, 28 Oct 2025 10:32:11 +0100 (CET) Received: from [192.168.0.172] (mob-5-90-58-13.net.vodafone.it [5.90.58.13]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 2E54B4B38; Tue, 28 Oct 2025 10:30:22 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1761643822; bh=RNUI2xtURg4B/VVj79hQSs2yG/gpcllwIsjZCRcUIcc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=BWNDT1Ydlz35KnqnsllSTZX4TXGeXHNctOLZuNnoPgdqlTH+fHHK44gvgVM3BGHDx OO+S9weB+jUHHgYEkhoVNXAc7BJZ2vkTDZGxRxxlK5CQzrEFgJLSJB/D6hEKc5eXn/ VFh2Z9WOmnam82z5JGvzpHOVmYyDquo3IjADQM0E= From: Jacopo Mondi Date: Tue, 28 Oct 2025 10:31:53 +0100 Subject: [PATCH v2 07/10] ipa: libipa: agc: Set exposure limits with frame duration MIME-Version: 1.0 Message-Id: <20251028-exposure-limits-v2-7-a8b5a318323e@ideasonboard.com> References: <20251028-exposure-limits-v2-0-a8b5a318323e@ideasonboard.com> In-Reply-To: <20251028-exposure-limits-v2-0-a8b5a318323e@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=9294; i=jacopo.mondi@ideasonboard.com; h=from:subject:message-id; bh=RNUI2xtURg4B/VVj79hQSs2yG/gpcllwIsjZCRcUIcc=; b=owEBbQKS/ZANAwAKAXI0Bo8WoVY8AcsmYgBpAI2VV35YcZuNFy8iUrKLvGkjOfGHuCuzymYKI gm2D2YnLp6JAjMEAAEKAB0WIQS1xD1IgJogio9YOMByNAaPFqFWPAUCaQCNlQAKCRByNAaPFqFW PFZaD/9B6hiUApzGIQOgBdhJBME2by2fT6fdeIDYRx8ol7MuejEGQSr++xnCV8YX99N7U42txAU nK4U78eZoEzchvpjLeWkm8DJi6Hfg9CM8KS1/l/qcijnFeof5Oahm6CEudbzIvBS7PtHXXFlJ/j UNff0RuGOczKFyzgUNNrllj3PfLUuTq/b5sCvtNeuQTrItWKf9SJ+ZpHs79yoBoY70dHJPWjeaI 6aOxL9tW175NyctCL1pa9BYJZfy+x7vklv6BN+wc4mN1UMZw+oAutXOxkwESIGrtLyAbV/M+8AZ KBcJ6HqEXAvzfVESbP8ihM3lWlm9pSNqbjnK5XtL9YyEPQQ5NZkgZ0gkUBs0xB7DiyUlTtadr+H wH6yxdsl6vjl2tlYucx71BmcdyDTZcZwc2k2bHOD8WylVBn3zvCHKpeoTsc1sM2HOCklxF5dp3z hf+841rzC+H3jFd3Gm6KKUy4an+R6SDZCO7SYpVHslyTqSFHJSA5UMbfu46NYmhW/DPWdmT9P17 5PidDV7gcY/VrvB1cLicB2jWi8FZH5Rm1+ZwLXeWlPJf2n2uGBkHDFsLQkn7cDv++kSLMLLX8+3 pGeGYWXPsDuCft/RFf7aZHYTn0er6hiBPIGoXk22qRdpLlCZEBn1qZiLoulhEesaLeQcaS4+gwd uP+peSkutB2dJgQ== 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 exposure limits updated at runtime with the setLimits() function are now computed using the maximum frame duration. Factor-out in the ExposureModeHelper class the exposure limits 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 | 59 +++++++++++++++++++-------------- src/ipa/libipa/exposure_mode_helper.h | 5 ++- src/ipa/rkisp1/algorithms/agc.cpp | 8 ++--- 5 files changed, 48 insertions(+), 32 deletions(-) diff --git a/src/ipa/libipa/agc_mean_luminance.cpp b/src/ipa/libipa/agc_mean_luminance.cpp index 195de2f2e93ce229b8047909b949e1d06ef8d5bf..1098865519ca9ca2679331edd9441720366c717d 100644 --- a/src/ipa/libipa/agc_mean_luminance.cpp +++ b/src/ipa/libipa/agc_mean_luminance.cpp @@ -453,6 +453,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 @@ -462,11 +463,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 c3d52c0b1cba23af14135dace8b3c13da4ae3e4b..0f7a4f53188d8d2759076c37d186efc088ddd279 100644 --- a/src/ipa/libipa/agc_mean_luminance.h +++ b/src/ipa/libipa/agc_mean_luminance.h @@ -61,7 +61,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); std::map> constraintModes() { diff --git a/src/ipa/libipa/exposure_mode_helper.cpp b/src/ipa/libipa/exposure_mode_helper.cpp index 8f40290959e24294ead008c7228e2f67ffc5adf8..d1d94cf46d5ef2c077508fd94dfe9715fdbc6f03 100644 --- a/src/ipa/libipa/exposure_mode_helper.cpp +++ b/src/ipa/libipa/exposure_mode_helper.cpp @@ -79,6 +79,33 @@ ExposureModeHelper::ExposureModeHelper(const SpanexposureMargin(); + if (!margin.has_value()) { + LOG(ExposureModeHelper, Warning) + << "Exposure margin not known. Default to 4"; + margin = { 4 }; + } + + maxExposureTime_ = minExposureTime != maxExposureTime + ? maxFrameDuration - margin.value() * lineDuration_ + : minExposureTime; +} + /** * \brief Configure sensor details * \param[in] lineDuration The current line length of the sensor @@ -111,34 +138,14 @@ void ExposureModeHelper::configure(utils::Duration lineDuration, maxGain_ = maxGain; sensorHelper_ = sensorHelper; - minExposureTime_ = minExposureTime; - - /* - * Compute the maximum exposure 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, use the - * maxFrameDuration minus the margin as upper limit for exposure - * (capped to the provided max exposure). - */ - auto margin = sensorHelper_->exposureMargin(); - if (!margin.has_value()) { - LOG(ExposureModeHelper, Warning) - << "Exposure margin not known. Default to 4"; - margin = { 4 }; - } - - maxExposureTime_ = minExposureTime != maxExposureTime - ? maxFrameDuration - margin.value() * lineDuration - : minExposureTime; + setMaxExposure(minExposureTime, maxExposureTime, 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 * @@ -150,15 +157,19 @@ void ExposureModeHelper::configure(utils::Duration lineDuration, * 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 8a7d2161912d318c2d1c5c8d009edc8a2d0c0427..b1de96d4a3a13e3771ff2162f11201e5f9253265 100644 --- a/src/ipa/libipa/exposure_mode_helper.h +++ b/src/ipa/libipa/exposure_mode_helper.h @@ -31,7 +31,7 @@ public: double minGain, double maxGain, 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; @@ -43,6 +43,9 @@ public: double maxGain() const { return maxGain_; } 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 121e75449a6985f951c50fdc85b0298026344297..96189254885c47d29b92f3fb40f0e86d10e2a7fc 100644 --- a/src/ipa/rkisp1/algorithms/agc.cpp +++ b/src/ipa/rkisp1/algorithms/agc.cpp @@ -579,9 +579,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; @@ -600,8 +598,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