From patchwork Fri Aug 15 10:29:23 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 24113 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 DA989C3295 for ; Fri, 15 Aug 2025 10:30:04 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 52B0F6925B; Fri, 15 Aug 2025 12:30:04 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="mb7a5oX5"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 59D1C6925F for ; Fri, 15 Aug 2025 12:30:01 +0200 (CEST) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:83d1:ae5d:93a6:6837]) by perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 7302E6A8; Fri, 15 Aug 2025 12:29:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1755253746; bh=mWtUqJOJC7TVcOpemCa1QvnrB5NPTO8ItDL14bBuGig=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mb7a5oX5uGOqV6RT1wKVq7ZRuQh7ixWqIfWL6kKQqYBrgPjvt7qVFr378gkItb/11 NhfiZBsvrjGf0DqjN8tKzcFKreNbyDks9Csw8KniUhSUlvx3l3eiHq+Rsoz22YTsFO chMCAg0P+67fBybYfDL5pJel994WxtczwgDEaJGU= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug , Isaac Scott , Daniel Scally Subject: [PATCH v3 03/19] libipa: camera_sensor_helper: Add quantizeGain() function Date: Fri, 15 Aug 2025 12:29:23 +0200 Message-ID: <20250815102945.1602071-4-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250815102945.1602071-1-stefan.klug@ideasonboard.com> References: <20250815102945.1602071-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" Add a small utility function that calculates the quantized gain that gets applied by a sensor when the gain code is set to gainCode(gain). This is needed by algorithms to calculate a digital correction gain that gets applied to mitigate the error introduce by quantization. Signed-off-by: Stefan Klug Reviewed-by: Isaac Scott Reviewed-by: Daniel Scally --- Changes in v3: - Remove virtual from quantizeGain() - Improved documentation - Collected tags --- src/ipa/libipa/camera_sensor_helper.cpp | 23 +++++++++++++++++++++++ src/ipa/libipa/camera_sensor_helper.h | 1 + 2 files changed, 24 insertions(+) diff --git a/src/ipa/libipa/camera_sensor_helper.cpp b/src/ipa/libipa/camera_sensor_helper.cpp index dcd69d9f2bbb..a490161faf4c 100644 --- a/src/ipa/libipa/camera_sensor_helper.cpp +++ b/src/ipa/libipa/camera_sensor_helper.cpp @@ -131,6 +131,29 @@ double CameraSensorHelper::gain(uint32_t gainCode) const } } +/** + * \brief Quantize the given gain value + * \param[in] _gain The real gain + * \param[out] quantizationGain The gain that is lost due to quantization + * + * This function returns the actual gain that is applied when the sensors gain + * is set to gainCode(gain). + * + * It shall be guaranteed that gainCode(gain) == gainCode(quantizeGain(gain)). + * + * If \a quantizationGain is provided it is filled with the gain that must be + * applied to correct the losses due to quantization. + * + * \return The quantized real gain + */ +double CameraSensorHelper::quantizeGain(double _gain, double *quantizationGain) const +{ + double g = gain(gainCode(_gain)); + if (quantizationGain) + *quantizationGain = _gain / g; + return g; +} + /** * \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 a9300a64f1e7..bd3d0beec77f 100644 --- a/src/ipa/libipa/camera_sensor_helper.h +++ b/src/ipa/libipa/camera_sensor_helper.h @@ -29,6 +29,7 @@ public: std::optional blackLevel() const { return blackLevel_; } virtual uint32_t gainCode(double gain) const; virtual double gain(uint32_t gainCode) const; + double quantizeGain(double gain, double *quantizationGain) const; protected: struct AnalogueGainLinear {