From patchwork Tue Oct 28 09:31:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 24844 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 6026CBE080 for ; Tue, 28 Oct 2025 09:32:24 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 905A1607E9; Tue, 28 Oct 2025 10:32:21 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="HQmdQ2lt"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 436A8607AA for ; Tue, 28 Oct 2025 10:32:10 +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 A0F004B34; Tue, 28 Oct 2025 10:30:21 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1761643822; bh=hotdbwOYqkfu27YSExC1g/AWsdly5yABlmUf2Zw8aRE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=HQmdQ2lt2Mqoazis40z54zsqLuIc0oY32rVDHHKCi5MCFdg5VBtiMIs/zn4X0JqAM cUe66vk+PrNX8zrdP+Ke40qC0hnOD6bCGhuQTCB+TH4UCk4SezEtxUvTCoZwCaMBal PHV22/gTIcAwD7K3m0Sc0bwsl3CLPQojHwud/aLk= From: Jacopo Mondi Date: Tue, 28 Oct 2025 10:31:52 +0100 Subject: [PATCH v2 06/10] ipa: libipa: agc: Initialize exposure with frame duration MIME-Version: 1.0 Message-Id: <20251028-exposure-limits-v2-6-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=1945; i=jacopo.mondi@ideasonboard.com; h=from:subject:message-id; bh=hotdbwOYqkfu27YSExC1g/AWsdly5yABlmUf2Zw8aRE=; b=owEBbQKS/ZANAwAKAXI0Bo8WoVY8AcsmYgBpAI2V0Bi8e8LraYeVr4SpKdZcuxzsXkAbhqqi6 J/YBDShUx2JAjMEAAEKAB0WIQS1xD1IgJogio9YOMByNAaPFqFWPAUCaQCNlQAKCRByNAaPFqFW PL4ZD/wJgVts1J6cz9EqxXKhzsbQXLwnL309WPbHfPPsExgKsk+Firh3WeiWPabWKF+Fijw0EwL PgAWjdyAP0baQ6VRBKavWfP0SwIHtA21ffQZHveZdi22bcOXDSqzh4rXhqvSQWSplaBJ3Z+0N40 WwmIYezyo++IuTdORgcv9Glt86bas0ybvj0AnMBAJcSbLTlbdcVReMwWFkpsvDyoi+Ukryn3kBt 4cc5uSg78LWm+/5Zsj2jdyOJrMySqvp7fioNolyboG+VpKa8UvYD5tU9K+tWP18BstlCFgpp969 4k0RGdCecpqknWKiTsv0UgEiI6ths0GP8t72XDq8zuPR20Fy6tYvIha0OMGvGvzugW9vBSAZvNk /0EXhHnHhhwIiIXYYdYO5hp7kJbcUK5jsZiNgd3tbNQ1ejyyVjmmgnVmi/eU8C5nKuBAONbDD9P RkjFBcSiMF3PETA3VOlOFE8B/AkThCXAPDee9NoYxzU6I6u/GQULgjt6p/Ow2PlLHCvK3OuKoZj XToJagW9QFi1zMkXkmWycOfQVHSl6gMjq+awTn12T2Svr1Tcq2RDxW5ghOwTtB3voEDp6mGoj2c T1bz1ZehLppnPWBnCoyofz838r51+G785NiGKMY+Pmg94b9jeNpdgfgxGJA1Thp3PZq6dBK1Ug4 Q5Tb539YNI0/a2w== 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" The maximum exposure time the AGC algorithm can achieve is, by definition, limited by the maximum programmed frame duration. When initializing the AGC algorithm, use the frame duration and the sensor's exposure margin to calculate the maximum exposure, unless the IPA has asked for a fixed exposure by setting min == max. Signed-off-by: Jacopo Mondi --- src/ipa/libipa/exposure_mode_helper.cpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/ipa/libipa/exposure_mode_helper.cpp b/src/ipa/libipa/exposure_mode_helper.cpp index edb8f04b245f01119d0d0b0917d10f98c7172dc0..8f40290959e24294ead008c7228e2f67ffc5adf8 100644 --- a/src/ipa/libipa/exposure_mode_helper.cpp +++ b/src/ipa/libipa/exposure_mode_helper.cpp @@ -106,12 +106,33 @@ void ExposureModeHelper::configure(utils::Duration lineDuration, const CameraSensorHelper *sensorHelper) { lineDuration_ = lineDuration; - minExposureTime_ = minExposureTime; - maxExposureTime_ = maxExposureTime; maxFrameDuration_ = maxFrameDuration; minGain_ = minGain; 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; } /**