From patchwork Mon Jul 7 08:55:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 23757 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 120BAC3237 for ; Mon, 7 Jul 2025 08:56:02 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8660868E8C; Mon, 7 Jul 2025 10:56:01 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="R7gKpb48"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B2F1768EB1 for ; Mon, 7 Jul 2025 10:55:57 +0200 (CEST) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:c79f:85df:e7f5:4c31]) by perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 140D91942; Mon, 7 Jul 2025 10:55:31 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1751878531; bh=1wKU0pjobuw79Vf1aXQoXME+va0b4U8ybOtk7pQXB0w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R7gKpb48flSLmcRIGN/wWo8WsoHNWR6UXvnvR83fMs9QFHh/4+tsYm5q/UoInBifc u5IAej0Qejw1nfwwxhZzHhZDJjgRrZoe9rHWEz/bklnaFvMEcs46Om0jXGjfjwPA6X oeiQ/09MEA6onveocOTcAERmatG9amKWC1k8BlF8= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug , Daniel Scally , Paul Elder Subject: [PATCH v3 8/9] libipa: agc_mean_luminance: Add exposure compensation support Date: Mon, 7 Jul 2025 10:55:11 +0200 Message-ID: <20250707085520.39777-9-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250707085520.39777-1-stefan.klug@ideasonboard.com> References: <20250707085520.39777-1-stefan.klug@ideasonboard.com> MIME-Version: 1.0 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" Exposure compensation allows to over- or under-expose an image by a given value. Add support for that in agc_mean_luminance. The added exposure compensation can lead to luminance target values that are close or above saturation and are therefore never reachable. Add a fix for that by limiting the maximum luminance target to 0.95. Signed-off-by: Stefan Klug Reviewed-by: Daniel Scally Reviewed-by: Paul Elder --- Changes in v3: - Fixed line wrap - Collected tags Changes in v2: - Fixed compiler error that slipped through in v1 - Improved commit message to explain the luminance target limitation - Collected tag --- src/ipa/libipa/agc_mean_luminance.cpp | 24 ++++++++++++++++++++++-- src/ipa/libipa/agc_mean_luminance.h | 6 ++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/ipa/libipa/agc_mean_luminance.cpp b/src/ipa/libipa/agc_mean_luminance.cpp index ebdb4d755741..ff96a381ffce 100644 --- a/src/ipa/libipa/agc_mean_luminance.cpp +++ b/src/ipa/libipa/agc_mean_luminance.cpp @@ -44,6 +44,15 @@ static constexpr uint32_t kNumStartupFrames = 10; */ static constexpr double kDefaultRelativeLuminanceTarget = 0.16; +/* + * Maximum relative luminance target + * + * This value limits the relative luminance target after applying the exposure + * compensation. Targeting a value above this limit results in saturation + * and the inability to regulate properly. + */ +static constexpr double kMaxRelativeLuminanceTarget = 0.95; + /** * \struct AgcMeanLuminance::AgcConstraint * \brief The boundaries and target for an AeConstraintMode constraint @@ -134,7 +143,8 @@ static constexpr double kDefaultRelativeLuminanceTarget = 0.16; */ AgcMeanLuminance::AgcMeanLuminance() - : frameCount_(0), filteredExposure_(0s), relativeLuminanceTarget_(0) + : exposureCompensation_(1.0), frameCount_(0), filteredExposure_(0s), + relativeLuminanceTarget_(0) { } @@ -368,6 +378,15 @@ int AgcMeanLuminance::parseTuningData(const YamlObject &tuningData) return parseExposureModes(tuningData); } +/** + * \fn AgcMeanLuminance::setExposureCompensation() + * \brief Set the exposure compensation value + * \param[in] gain The exposure compensation gain + * + * This function sets the exposure compensation value to be used in the + * AGC calculations. It is expressed as gain instead of EV. + */ + /** * \brief Set the ExposureModeHelper limits for this class * \param[in] minExposureTime Minimum exposure time to allow @@ -424,7 +443,8 @@ void AgcMeanLuminance::setLimits(utils::Duration minExposureTime, */ double AgcMeanLuminance::estimateInitialGain() const { - double yTarget = relativeLuminanceTarget_; + double yTarget = std::min(relativeLuminanceTarget_ * exposureCompensation_, + kMaxRelativeLuminanceTarget); double yGain = 1.0; /* diff --git a/src/ipa/libipa/agc_mean_luminance.h b/src/ipa/libipa/agc_mean_luminance.h index c41391cb0b73..cad7ef845487 100644 --- a/src/ipa/libipa/agc_mean_luminance.h +++ b/src/ipa/libipa/agc_mean_luminance.h @@ -44,6 +44,11 @@ public: int parseTuningData(const YamlObject &tuningData); + void setExposureCompensation(double gain) + { + exposureCompensation_ = gain; + } + void setLimits(utils::Duration minExposureTime, utils::Duration maxExposureTime, double minGain, double maxGain); @@ -84,6 +89,7 @@ private: double gain); utils::Duration filterExposure(utils::Duration exposureValue); + double exposureCompensation_; uint64_t frameCount_; utils::Duration filteredExposure_; double relativeLuminanceTarget_;