From patchwork Fri Nov 14 14:17:02 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 25059 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 C268CC3241 for ; Fri, 14 Nov 2025 14:17:35 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 519F760B0C; Fri, 14 Nov 2025 15:17:29 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="fGbxdtTd"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 626B0606E6 for ; Fri, 14 Nov 2025 15:17:20 +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 6BA4516A8; Fri, 14 Nov 2025 15:15:19 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1763129719; bh=fNhOjrRZ0+5i+LCbzY00gFZZx32gNfi6ytAYY93//5Y=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=fGbxdtTdWkFUW8Dq5eq7KVwzyJVm9mSDofb9U0WKTrqmt/qGI8SUF3VCOyWwucMd3 bV5PS7WFQArBkM3kCH3Uy16cdj7ysLm2Oat7ZfBkZ2q/GfQS2rR1ia71vn5l9UcdGS Py5u4htiDt28laG9MzdOXlXhbr0uRtKwvkMBRjZI= From: Jacopo Mondi Date: Fri, 14 Nov 2025 15:17:02 +0100 Subject: [PATCH v3 07/19] ipa: camera_sensor_helper: Introduce minFrameDuration() MIME-Version: 1.0 Message-Id: <20251114-exposure-limits-v3-7-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=3332; i=jacopo.mondi@ideasonboard.com; h=from:subject:message-id; bh=fNhOjrRZ0+5i+LCbzY00gFZZx32gNfi6ytAYY93//5Y=; b=owEBbQKS/ZANAwAKAXI0Bo8WoVY8AcsmYgBpFznriHKLuoteRA/oX9HiveLoN0B4nbqTNYnig POhdRNQ/taJAjMEAAEKAB0WIQS1xD1IgJogio9YOMByNAaPFqFWPAUCaRc56wAKCRByNAaPFqFW POm8D/97fthPNErIDv8KE2BD2C0Lkq0IocUJEkRT1l91qInraR6/APwpLDFuFD6uhqVAJhOod2O 7Zl+r6241S/fQc+0xoaCUg0PcmLMGZl50XyvtslB53HTA6MCpcFEqaFcMaAqeb7myE17aT6y29c DjILXJIIXMeh3RctDqQlzUMi15HuyPojJoFSAzEc5hRn9jxiot4VHydUylVVyJMkLZMU1qyakPv cqBuETVjHZZegb3Osg1e7IiEom5bL7KEr42OG1kWeAZnCMXTeH7+qgCL+Oul9yQPneSGmGQWnXD YY25iTw7iE9ENTsSCLlZFvAQWeQ4oPqqZdtpdIfToNTylw2ykjYFkhBgfGWeQR6o3bTAbCKH3kv K4QihJisaxMqtS4dk8BiqChjMnBVuzvQhwpj8WF7rv6scLDfZhWBGHR2y01C+4N9uuPsOuVwbAp FyvIZQ4Z2EcGdkHZGtrYY0WDunk6F1+Um51WSXg84hgBAzkJ1augTJXKT19BXFv/RYbsiukPe2/ BGzP/lY5FSoQ1FIu8XyIOkujjm5HsG9YsaDsTzLYe4cFs3ZOCTKMuWMzbonVjk3Y4T1ih9RvfOb n/qHZ8LLZ0tyTj7CzPyVnStCb2aTkILahsHx9lNDBmpLwN2V+wEgk+xiVb+8SJourCqv3YCR2NF gBAhC8g3psnwjJw== 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" After having introduced CameraSensorHelper::maxShutterTime() which calculates the maximum shutter time which can be achieved given a frame duration, this patch introduces the opposite operation, that given a desired shutter time calculates what is the minimum frame duration required to achieve it. The intended users of this function are IPA modules that after having calculated a new exposure time need to regulate the frame duration to achieve it. Signed-off-by: Jacopo Mondi --- src/ipa/libipa/camera_sensor_helper.cpp | 33 +++++++++++++++++++++++++++++++++ src/ipa/libipa/camera_sensor_helper.h | 2 ++ 2 files changed, 35 insertions(+) diff --git a/src/ipa/libipa/camera_sensor_helper.cpp b/src/ipa/libipa/camera_sensor_helper.cpp index 3c3e24c1cdefa4bca059352482bb29654a37b42f..a38f1eb40446b98a0db4642f086742674a13854f 100644 --- a/src/ipa/libipa/camera_sensor_helper.cpp +++ b/src/ipa/libipa/camera_sensor_helper.cpp @@ -184,6 +184,39 @@ utils::Duration CameraSensorHelper::maxShutterTime(utils::Duration maxFrameDurat return maxFrameDuration - exposureMargin * lineDuration; } +/** + * \brief Compute the minimum frame duration required for a desired exposure + * \param[in] shutterTime The shutter time + * \param[in] lineDuration The current sensor line duration + * + * This function returns the minimum frame duration required to achieve the + * desired \a shutterTime. The frame duration is calculated by adding to + * \a shutterTime the difference between the frame length and the maximum + * achievable integration time. + * + * The intended users of this function are IPA modules that want to calculate + * the minium required frame duration give a newly calculated shutter time. + * + * \todo The line duration should be a property of the CameraSensorHelper class + * instead of being provided by the IPA. + * + * \return The minimum frame duration required to achieve the desired shutter + * time + */ +utils::Duration CameraSensorHelper::minFrameDuration(utils::Duration shutterTime, + utils::Duration lineDuration) const +{ + /* Use a static to rate-limit the error message. */ + static uint32_t exposureMargin = exposureMargin_.has_value() + ? exposureMargin_.value() : 0; + if (!exposureMargin_.has_value() && !exposureMargin) { + LOG(CameraSensorHelper, Warning) + << "Exposure margin not known. Default to 4"; + exposureMargin = 4; + } + + return shutterTime + exposureMargin * lineDuration; +} /** * \struct CameraSensorHelper::AnalogueGainLinear * \brief Analogue gain constants for the linear gain model diff --git a/src/ipa/libipa/camera_sensor_helper.h b/src/ipa/libipa/camera_sensor_helper.h index a1cf4bc334ad3b9a51d26b345bd5f0630c7ae87c..e9b53f183e8e6d305b50b5f3b46dc0199efee018 100644 --- a/src/ipa/libipa/camera_sensor_helper.h +++ b/src/ipa/libipa/camera_sensor_helper.h @@ -33,6 +33,8 @@ public: double quantizeGain(double gain, double *quantizationGain) const; utils::Duration maxShutterTime(utils::Duration maxFrameDuration, utils::Duration lineDuration) const; + utils::Duration minFrameDuration(utils::Duration exposureTime, + utils::Duration lineDuration) const; protected: struct AnalogueGainLinear {