From patchwork Tue Oct 28 09:31:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 24838 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 A915DBE080 for ; Tue, 28 Oct 2025 09:32:10 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 25D4B607A6; Tue, 28 Oct 2025 10:32:09 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="n617lxAu"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3A05F603ED for ; Tue, 28 Oct 2025 10:32:07 +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 641BA176B; Tue, 28 Oct 2025 10:30:18 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1761643818; bh=7/iRzEv8o9gerSSWX0rbFJdz+GJJ31XOnaTmVTToLNI=; h=From:Subject:Date:To:Cc:From; b=n617lxAuI32YfXamrvOZZL5IPLvjvEvCIihucycZ+bQPE8/RTvbV8INdth8eedlim RWNgrvtJ18Y5I/x3mceJC02h3unLe75FP8OES04wHLwmJ7ux6omuZHbMViZFsSoA24 XpUJZjxhkpL8XBMbtGEFrubixgyibengXOyV+dy0= From: Jacopo Mondi Subject: [PATCH v2 00/10] libipa: agc: Calculate exposure limits Date: Tue, 28 Oct 2025 10:31:46 +0100 Message-Id: <20251028-exposure-limits-v2-0-a8b5a318323e@ideasonboard.com> MIME-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAIONAGkC/3WNQQ6CMBBFr0JmbQ1tKFRX3sOwqO0gkwglHWwwp He3snf5XvLf34ExEjJcqx0iJmIKcwF1qsCNdn6iIF8YVK20rGUncFsCvyOKF020stCuMUqrAXV joKyWiANtR/HeFx6J1xA/x0GSP/u/laSoRauMcd602MnLjTxaDvMj2OjPLkzQ55y/FTZiSLUAA AA= X-Change-ID: 20251017-exposure-limits-5c48252fe548 To: =?utf-8?q?Niklas_S=C3=B6derlund?= , Robert Mader , libcamera-devel@lists.libcamera.org Cc: Jacopo Mondi , Kieran Bingham X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=4197; i=jacopo.mondi@ideasonboard.com; h=from:subject:message-id; bh=7/iRzEv8o9gerSSWX0rbFJdz+GJJ31XOnaTmVTToLNI=; b=owEBbQKS/ZANAwAKAXI0Bo8WoVY8AcsmYgBpAI2Uq9RbceLkV+Be34JBU/y8eXWnofcasVysp 7AqaCb7YeSJAjMEAAEKAB0WIQS1xD1IgJogio9YOMByNAaPFqFWPAUCaQCNlAAKCRByNAaPFqFW PFATD/9k1Iz9j0rnVTCP3GPhQeoU4X0T3WNzNWy+f089xAdQbk6E3TU3qr9Tg2CnALbA7wfCEFZ Gcm6NkOA66oaXYhz8Zy36bLwS0cdBM2XL7CY4bvmWNSRYW5N2nT0bdP32SOTuy9bB82BCSqdl3j rWtyGSoMcFY/3AUEBsfRLMdQ/Xn2yxbXX1mJGGKYzNGdlgVDEOHbrPDgwHAB9obOUqpU7q5tv9d vvguJNcpUue1pxOFWJf9/VvH6kETh+Mp4KBZYRKYR+bj83gZ6rpBeJtVC3VGX1rG8zFPbug1Mp6 fbf0SPlqYJVLVgHjWgkV11N5ML9Cz2ptOFiZJQYbnkq2mCsDO8obcaxCuqcP+BJoDjNu3hphkvv XYkf5K2aPyr5umxjOr0GmdhcJgUjUsEhjRmVM9XhSPhAA3dL4qkdyp667xpR8b1eRBxbcUpIXKG PXACJmJfP0BYP6lL5ejA1pmQk00/JZdz028TXKp5qomwCV+zhZJKCiowjHN4j/8sEmo2a2DBFYs Quqzfw8dKe6C0kjj01CvBaVFwe7I2T8PCq0D+lBZA5KQ0tfho5Kziusl9hklIxOXK7M4pskuIj9 8BzAq4NoLOwbyrJAJ8Tbbz+NPAlmXta+kptygHSmVN4mQfx9uLXlFD0k92tdFKiR0qjAbjV2xvU NeA5A1h+8TOQJcg== 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" By definition, the exposure time that can be programmed on a sensor is limited by the frame duration and whenever the frame duration is updated, the exposure time limits should be updated as well. This is not the case for IPAs using the AgcMeanLuminance algorithm from libipa, where the exposure limits are computed at configure() time and never updated. This has two implications: 1) The AGC algorithms will always operate with an exposure time bound to the frame duration programmed at startup time 2) The Camera::controls() limits are not updated to reflect the new constraints This series addresses issue 1) by changing the AgcMeanLuminance class and the associated helpers to regulate the exposure time base on the currently programmed max frame duration using a sensor-specific margin that is now reported by the CameraHelper class. As the AgcMeanLuminance algorithm tries to push the exposure time up to the maximum allowed frame duration, initializing the algorithm with the sensor's maximum capabilities results in a very low frame rate, unless the user specifies a FrameDurationLimits range in which the algorithm should operate. To avoid slowing the frame rate down too much compute a "default" frame rate at algorithm configuration time, were the canonical 30, 15 and 10 FPS values are tested and selected in order of preference. The last patch is not for inclusion as Mali support needs to be finalized upstream first, but shows how is it possible to handle frame duration limits and exposure with the new model (and I needed that patch for testing on Mali anyway). Tested with camshark on Mali-C55 and with a test scripts that sets a longer frame duration (66 msecs) and by validating that the exposure time is increased to match the new limits on RkISP1. RkISP1Agc agc.cpp:644 Divided up exposure time, analogue gain, quantization gain and digital gain are 33251.27us, 10.6667, 1.00018 and 6.49639 61.545331 (47.58 fps) cam0-stream0 seq: 000050 bytesused: 2073600/1036800 kISP1Agc agc.cpp:644 Divided up exposure time, analogue gain, quantization gain and digital gain are 66578.16us, 10.6667, 1.00018 and 3.24451 61.566241 (47.82 fps) cam0-stream0 seq: 000051 bytesused: 2073600/1036800 Signed-off-by: Jacopo Mondi Tested-by: Robert Mader --- Changes in v2: - Rework of v1 that moves the exposure limits computation to the AgcMeanLuminance exposure helpers --- Jacopo Mondi (9): ipa: camera_sensor_helper: Introduce exposureMargin() ipa: ipu3: Move CameraHelper to context ipa: libipa: agc: Make Agc::configure() set limits ipa: libipa: agc: Configure with frame duration ipa: libipa: agc: Initialize exposure with frame duration ipa: libipa: agc: Set exposure limits with frame duration ipa: libipa: agc: Initialize a sensible frame duration ipa: libipa: agc: Calculate frame duration in helper [DNI] ipa: mali: Handle FrameDurationLimits Kieran Bingham (1): ipa: mali-c55: Move CameraHelper to context src/ipa/ipu3/algorithms/agc.cpp | 32 +++++++--- src/ipa/ipu3/ipa_context.cpp | 3 + src/ipa/ipu3/ipa_context.h | 3 + src/ipa/ipu3/ipu3.cpp | 22 +++---- src/ipa/libipa/agc_mean_luminance.cpp | 73 ++++++++++++++++++--- src/ipa/libipa/agc_mean_luminance.h | 18 +++++- src/ipa/libipa/camera_sensor_helper.cpp | 72 +++++++++++++++++++++ src/ipa/libipa/camera_sensor_helper.h | 2 + src/ipa/libipa/exposure_mode_helper.cpp | 109 +++++++++++++++++++++++++++----- src/ipa/libipa/exposure_mode_helper.h | 16 ++++- src/ipa/mali-c55/algorithms/agc.cpp | 76 +++++++++++++++++++--- src/ipa/mali-c55/ipa_context.cpp | 6 ++ src/ipa/mali-c55/ipa_context.h | 12 ++++ src/ipa/mali-c55/mali-c55.cpp | 44 ++++++------- src/ipa/rkisp1/algorithms/agc.cpp | 42 ++++++------ 15 files changed, 430 insertions(+), 100 deletions(-) --- base-commit: 36f9cdcdb4a3c69e10b7da8a3de8354421cdcb56 change-id: 20251017-exposure-limits-5c48252fe548 Best regards,