From patchwork Mon Mar 28 12:03:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 15572 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 5F872C3265 for ; Mon, 28 Mar 2022 12:03:45 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6B29865637; Mon, 28 Mar 2022 14:03:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1648469024; bh=dCdO5KC0qS8Expo4HQ/g6DfXtFRZn5qq3lY+qK221lI=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=yR1doETy88D3/GdlI2yru0WiRWmyNFSAFoMNAySMsBTezLtMG0qf3IGO5zxc7F6ZS k7e69nJBc3bbnDsfDnxztv3N6PSjCmkp+XXE5rd8BzELAPXd1ZC6eW41EFwNEKUSme T54nmGz5JtM7TFiquI0vXvYTv942CAMbywlqsxXJxh2KhQrqTsdeo9BrxFEDo7VLW6 tiKxu0J6fszEvYfFZJnW+MhNCEEgWln1BCroMwPEF070+E+hjOxE2VSFLMCS3G6n5U /qcpMomQhCSZzObNITGNOFpqnru/bveOojC5nl+TWqVfuA5WwwPhD/yG+w0v0qKiVj Qa7mYarYHD/ww== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2602B601F5 for ; Mon, 28 Mar 2022 14:03:42 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="dPgpZ8AE"; dkim-atps=neutral Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id C2A8FE0A for ; Mon, 28 Mar 2022 14:03:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1648469021; bh=dCdO5KC0qS8Expo4HQ/g6DfXtFRZn5qq3lY+qK221lI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=dPgpZ8AEwIsQRhJ6WSfN8dHqwZBo422ts/4ReCjuP/ZD72mIKns4YwlFKESZi5E96 aTxWjvsFeNqD5ybMlgIYH4ditLfOP/pqoQL+ciB3Gm4QohqR2yipgAB66shySArQHN 1vJA9Rwh63MF1Lk5yzREwEa8/BqfB72wQv7pE5DE= To: libcamera-devel@lists.libcamera.org Date: Mon, 28 Mar 2022 15:03:33 +0300 Message-Id: <20220328120336.10834-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220328120336.10834-1-laurent.pinchart@ideasonboard.com> References: <20220328120336.10834-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/4] libipa: camera_sensor_helper: Reorganize gain constants 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: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" To prepare for other gain models than the linear model, store the gain constants in a union with per-model members. Due to the lack of designated initializer support in gcc with C++17, initializing a single complex structure that includes a union will be difficult. Split the gain model type to a separate variable to work around this issue. Signed-off-by: Laurent Pinchart Reviewed-by: Jacopo Mondi Reviewed-by: Umang Jain Reviewed-by: Paul Elder --- src/ipa/libipa/camera_sensor_helper.cpp | 102 ++++++++++++++---------- src/ipa/libipa/camera_sensor_helper.h | 10 ++- 2 files changed, 65 insertions(+), 47 deletions(-) diff --git a/src/ipa/libipa/camera_sensor_helper.cpp b/src/ipa/libipa/camera_sensor_helper.cpp index c953def04fd7..714cd86f039f 100644 --- a/src/ipa/libipa/camera_sensor_helper.cpp +++ b/src/ipa/libipa/camera_sensor_helper.cpp @@ -58,11 +58,13 @@ namespace ipa { */ uint32_t CameraSensorHelper::gainCode(double gain) const { - ASSERT(analogueGainConstants_.m0 == 0 || analogueGainConstants_.m1 == 0); - ASSERT(analogueGainConstants_.type == AnalogueGainLinear); + const AnalogueGainConstants &k = gainConstants_; - return (analogueGainConstants_.c0 - analogueGainConstants_.c1 * gain) / - (analogueGainConstants_.m1 * gain - analogueGainConstants_.m0); + ASSERT(gainType_ == AnalogueGainLinear); + ASSERT(k.linear.m0 == 0 || k.linear.m1 == 0); + + return (k.linear.c0 - k.linear.c1 * gain) / + (k.linear.m1 * gain - k.linear.m0); } /** @@ -80,11 +82,13 @@ uint32_t CameraSensorHelper::gainCode(double gain) const */ double CameraSensorHelper::gain(uint32_t gainCode) const { - ASSERT(analogueGainConstants_.m0 == 0 || analogueGainConstants_.m1 == 0); - ASSERT(analogueGainConstants_.type == AnalogueGainLinear); + const AnalogueGainConstants &k = gainConstants_; - return (analogueGainConstants_.m0 * static_cast(gainCode) + analogueGainConstants_.c0) / - (analogueGainConstants_.m1 * static_cast(gainCode) + analogueGainConstants_.c1); + ASSERT(gainType_ == AnalogueGainLinear); + ASSERT(k.linear.m0 == 0 || k.linear.m1 == 0); + + return (k.linear.m0 * static_cast(gainCode) + k.linear.c0) / + (k.linear.m1 * static_cast(gainCode) + k.linear.c1); } /** @@ -127,42 +131,45 @@ double CameraSensorHelper::gain(uint32_t gainCode) const * \todo not implemented in libipa */ +/** + * \struct CameraSensorHelper::AnalogueGainLinearConstants + * \brief Analogue gain constants for the linear gain model + * + * \var CameraSensorHelper::AnalogueGainLinearConstants::m0 + * \brief Constant used in the linear gain coding/decoding + * + * \note Either m0 or m1 shall be zero. + * + * \var CameraSensorHelper::AnalogueGainLinearConstants::c0 + * \brief Constant used in the linear gain coding/decoding + * + * \var CameraSensorHelper::AnalogueGainLinearConstants::m1 + * \brief Constant used in the linear gain coding/decoding + * + * \note Either m0 or m1 shall be zero. + * + * \var CameraSensorHelper::AnalogueGainLinearConstants::c1 + * \brief Constant used in the linear gain coding/decoding + */ + /** * \struct CameraSensorHelper::AnalogueGainConstants - * \brief Analogue gain constants used for gain calculation - */ - -/** - * \var CameraSensorHelper::AnalogueGainConstants::type - * \brief Analogue gain calculation mode - */ - -/** - * \var CameraSensorHelper::AnalogueGainConstants::m0 - * \brief Constant used in the analogue Gain coding/decoding + * \brief Analogue gain model constants * - * \note Either m0 or m1 shall be zero. - */ - -/** - * \var CameraSensorHelper::AnalogueGainConstants::c0 - * \brief Constant used in the analogue gain coding/decoding - */ - -/** - * \var CameraSensorHelper::AnalogueGainConstants::m1 - * \brief Constant used in the analogue gain coding/decoding + * This union stores the constants used to calculate the analogue gain. The + * CameraSensorHelper::gainType_ variable selects which union member is valid. * - * \note Either m0 or m1 shall be zero. + * \var CameraSensorHelper::AnalogueGainConstants::linear + * \brief Constants for the linear gain model */ /** - * \var CameraSensorHelper::AnalogueGainConstants::c1 - * \brief Constant used in the analogue gain coding/decoding + * \var CameraSensorHelper::gainType_ + * \brief The analogue gain model type */ /** - * \var CameraSensorHelper::analogueGainConstants_ + * \var CameraSensorHelper::gainConstants_ * \brief The analogue gain parameters used for calculation * * The analogue gain is calculated through a formula, and its parameters are @@ -290,7 +297,8 @@ class CameraSensorHelperImx219 : public CameraSensorHelper public: CameraSensorHelperImx219() { - analogueGainConstants_ = { AnalogueGainLinear, 0, 256, -1, 256 }; + gainType_ = AnalogueGainLinear; + gainConstants_.linear = { 0, 256, -1, 256 }; } }; REGISTER_CAMERA_SENSOR_HELPER("imx219", CameraSensorHelperImx219) @@ -298,10 +306,11 @@ REGISTER_CAMERA_SENSOR_HELPER("imx219", CameraSensorHelperImx219) class CameraSensorHelperImx258 : public CameraSensorHelper { public: - CameraSensorHelperImx258() - { - analogueGainConstants_ = { AnalogueGainLinear, 0, 512, -1, 512 }; - } + CameraSensorHelperImx258() + { + gainType_ = AnalogueGainLinear; + gainConstants_.linear = { 0, 512, -1, 512 }; + } }; REGISTER_CAMERA_SENSOR_HELPER("imx258", CameraSensorHelperImx258) @@ -310,7 +319,8 @@ class CameraSensorHelperOv2740 : public CameraSensorHelper public: CameraSensorHelperOv2740() { - analogueGainConstants_ = { AnalogueGainLinear, 1, 0, 0, 128 }; + gainType_ = AnalogueGainLinear; + gainConstants_.linear = { 1, 0, 0, 128 }; } }; REGISTER_CAMERA_SENSOR_HELPER("ov2740", CameraSensorHelperOv2740) @@ -320,7 +330,8 @@ class CameraSensorHelperOv5670 : public CameraSensorHelper public: CameraSensorHelperOv5670() { - analogueGainConstants_ = { AnalogueGainLinear, 1, 0, 0, 128 }; + gainType_ = AnalogueGainLinear; + gainConstants_.linear = { 1, 0, 0, 128 }; } }; REGISTER_CAMERA_SENSOR_HELPER("ov5670", CameraSensorHelperOv5670) @@ -330,7 +341,8 @@ class CameraSensorHelperOv5693 : public CameraSensorHelper public: CameraSensorHelperOv5693() { - analogueGainConstants_ = { AnalogueGainLinear, 1, 0, 0, 16 }; + gainType_ = AnalogueGainLinear; + gainConstants_.linear = { 1, 0, 0, 16 }; } }; REGISTER_CAMERA_SENSOR_HELPER("ov5693", CameraSensorHelperOv5693) @@ -340,7 +352,8 @@ class CameraSensorHelperOv8865 : public CameraSensorHelper public: CameraSensorHelperOv8865() { - analogueGainConstants_ = { AnalogueGainLinear, 1, 0, 0, 128 }; + gainType_ = AnalogueGainLinear; + gainConstants_.linear = { 1, 0, 0, 128 }; } }; REGISTER_CAMERA_SENSOR_HELPER("ov8865", CameraSensorHelperOv8865) @@ -350,7 +363,8 @@ class CameraSensorHelperOv13858 : public CameraSensorHelper public: CameraSensorHelperOv13858() { - analogueGainConstants_ = { AnalogueGainLinear, 1, 0, 0, 128 }; + gainType_ = AnalogueGainLinear; + gainConstants_.linear = { 1, 0, 0, 128 }; } }; REGISTER_CAMERA_SENSOR_HELPER("ov13858", CameraSensorHelperOv13858) diff --git a/src/ipa/libipa/camera_sensor_helper.h b/src/ipa/libipa/camera_sensor_helper.h index 26adfcb5955f..6b96520ba601 100644 --- a/src/ipa/libipa/camera_sensor_helper.h +++ b/src/ipa/libipa/camera_sensor_helper.h @@ -34,15 +34,19 @@ protected: AnalogueGainExponential, }; - struct AnalogueGainConstants { - AnalogueGainType type; + struct AnalogueGainLinearConstants { int16_t m0; int16_t c0; int16_t m1; int16_t c1; }; - AnalogueGainConstants analogueGainConstants_; + union AnalogueGainConstants { + AnalogueGainLinearConstants linear; + }; + + AnalogueGainType gainType_; + AnalogueGainConstants gainConstants_; private: LIBCAMERA_DISABLE_COPY_AND_MOVE(CameraSensorHelper) From patchwork Mon Mar 28 12:03:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 15573 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 1DF72C0F1B for ; Mon, 28 Mar 2022 12:03:46 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B93496563F; Mon, 28 Mar 2022 14:03:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1648469025; bh=/yJsoujfORPoipbpynh5ZxqKJClQzRj2IvNtqntWa14=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=Nnv9LtgiUxbgXvqnZndX2cauQ4nAb9KOoHQTgbyjCZVFwcJoJB0ObfPqTkGlM7nfS vftcoPVoZBLQBfvs1O52WoNSBUMa18XJ6rbAELaxfUIcj3uhU1Q3TWykXk/9r80aHC ZM2LAWyBHzKu2IJ0eEtZv3PqPCEsIUxq73Lgxg30fK5H+HnnLA4xVIpTf5fIBdA0Op QuUoDpMMHFKo63RN7vw7OaqMMp8Drb/wz8vDcbRbgDeykUSJhcb861bxM42WHJ1OEW IPzpGeGrAFXsqQ94LHgrwIyiUCtSMhXaB86gkg5W86zf9kYSPEHIR0EZhcRrNVhQB5 wG/v+4sIkgJhQ== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 88BBF601F5 for ; Mon, 28 Mar 2022 14:03:42 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Oc851Zz/"; dkim-atps=neutral Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 2DF5F299 for ; Mon, 28 Mar 2022 14:03:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1648469022; bh=/yJsoujfORPoipbpynh5ZxqKJClQzRj2IvNtqntWa14=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Oc851Zz/DY+0zVJjN2u/rEDDgqUojG/BfvYiX4uOOKON0rl53usG5mnTNM3JjKJ0w i4osw3Z6X+O8CVI+7R1OFJk1F6klmGjsIDjEy4gdAiA/OR/P+Q4q72v6dsIF2x/3b6 Pp2rP0dvVJSh5ng/73UlEkOKkARlSVrJvb8HnMuM= To: libcamera-devel@lists.libcamera.org Date: Mon, 28 Mar 2022 15:03:34 +0300 Message-Id: <20220328120336.10834-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220328120336.10834-1-laurent.pinchart@ideasonboard.com> References: <20220328120336.10834-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/4] libipa: camera_sensor_helper: Implement exponential gain model 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: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The CameraSensorHelper specifies two gain models, linear and an exponential. They are modelled after the MIPI CCS specification. Only the linear model has been implemented, the exponential model was left for later. We now need to support sensors that configure their gain in a hardware register with a value expressed in dB. This has similarities with the MIPI CCS exponential gain model, but is only has an exponential factor, while CCS also allows sensors to support a configurable linear factor. The full CCS exponential model needs two values (for the linear and exponential factors) to express a gain, while IPAs use a single linear gain value internally. However, the exponential gain model example in the CCS specification has a fixed linear factor, which may indicate that it could be common for sensors that implement the exponential gain model to only use the exponential factor. For this reason, implement the exponential gain model with a fixed linear factor, but with a sensor-specific coefficient for the exponential factor that allows expressing the gain in dB (or other logarithmical units) instead of limiting it to powers of 2 as in the MIPI CCS specification. Signed-off-by: Laurent Pinchart Reviewed-by: Jacopo Mondi Reviewed-by: Umang Jain Reviewed-by: Paul Elder --- src/ipa/libipa/camera_sensor_helper.cpp | 82 ++++++++++++++++++------- src/ipa/libipa/camera_sensor_helper.h | 6 ++ 2 files changed, 67 insertions(+), 21 deletions(-) diff --git a/src/ipa/libipa/camera_sensor_helper.cpp b/src/ipa/libipa/camera_sensor_helper.cpp index 714cd86f039f..7bb999e19102 100644 --- a/src/ipa/libipa/camera_sensor_helper.cpp +++ b/src/ipa/libipa/camera_sensor_helper.cpp @@ -7,6 +7,8 @@ */ #include "camera_sensor_helper.h" +#include + #include /** @@ -51,20 +53,28 @@ namespace ipa { * This function aims to abstract the calculation of the gain letting the IPA * use the real gain for its estimations. * - * The parameters come from the MIPI Alliance Camera Specification for - * Camera Command Set (CCS). - * * \return The gain code to pass to V4L2 */ uint32_t CameraSensorHelper::gainCode(double gain) const { const AnalogueGainConstants &k = gainConstants_; - ASSERT(gainType_ == AnalogueGainLinear); - ASSERT(k.linear.m0 == 0 || k.linear.m1 == 0); + switch (gainType_) { + case AnalogueGainLinear: + ASSERT(k.linear.m0 == 0 || k.linear.m1 == 0); - return (k.linear.c0 - k.linear.c1 * gain) / - (k.linear.m1 * gain - k.linear.m0); + return (k.linear.c0 - k.linear.c1 * gain) / + (k.linear.m1 * gain - k.linear.m0); + + case AnalogueGainExponential: + ASSERT(k.exp.a != 0 && k.exp.m != 0); + + return std::log2(gain / k.exp.a) / k.exp.m; + + default: + ASSERT(false); + return 0; + } } /** @@ -75,20 +85,29 @@ uint32_t CameraSensorHelper::gainCode(double gain) const * use the real gain for its estimations. It is the counterpart of the function * CameraSensorHelper::gainCode. * - * The parameters come from the MIPI Alliance Camera Specification for - * Camera Command Set (CCS). - * * \return The real gain */ double CameraSensorHelper::gain(uint32_t gainCode) const { const AnalogueGainConstants &k = gainConstants_; + double gain = static_cast(gainCode); - ASSERT(gainType_ == AnalogueGainLinear); - ASSERT(k.linear.m0 == 0 || k.linear.m1 == 0); + switch (gainType_) { + case AnalogueGainLinear: + ASSERT(k.linear.m0 == 0 || k.linear.m1 == 0); - return (k.linear.m0 * static_cast(gainCode) + k.linear.c0) / - (k.linear.m1 * static_cast(gainCode) + k.linear.c1); + return (k.linear.m0 * gain + k.linear.c0) / + (k.linear.m1 * gain + k.linear.c1); + + case AnalogueGainExponential: + ASSERT(k.exp.a != 0 && k.exp.m != 0); + + return k.exp.a * std::exp2(k.exp.m * gain); + + default: + ASSERT(false); + return 0.0; + } } /** @@ -120,15 +139,22 @@ double CameraSensorHelper::gain(uint32_t gainCode) const /** * \var CameraSensorHelper::AnalogueGainExponential - * \brief Gain is computed using exponential gain estimation - * (introduced in CCS v1.1) + * \brief Gain is expressed using an exponential model * - * Starting with CCS v1.1, Alternate Global Analogue Gain is also available. - * If the image sensor supports it, then the global analogue gain can be - * controlled by linear and exponential gain formula: + * The relationship between the integer gain parameter and the resulting gain + * multiplier is given by the following equation: * - * \f$gain = analogLinearGainGlobal * 2^{analogExponentialGainGlobal}\f$ - * \todo not implemented in libipa + * \f$gain = a \cdot 2^{m \cdot x}\f$ + * + * Where 'x' is the gain control parameter, and 'a' and 'm' are image + * sensor-specific constants. + * + * This is a subset of the MIPI CCS exponential gain model with the linear + * factor 'a' being a constant, but with the exponent being configurable + * through the 'm' coefficient. + * + * When the gain is expressed in dB, 'a' is equal to 1 and 'm' to + * \f$log_{2}{10^{frac{1}{20}}}\f$. */ /** @@ -152,6 +178,17 @@ double CameraSensorHelper::gain(uint32_t gainCode) const * \brief Constant used in the linear gain coding/decoding */ +/** + * \struct CameraSensorHelper::AnalogueGainExpConstants + * \brief Analogue gain constants for the exponential gain model + * + * \var CameraSensorHelper::AnalogueGainExpConstants::a + * \brief Constant used in the exponential gain coding/decoding + * + * \var CameraSensorHelper::AnalogueGainExpConstants::m + * \brief Constant used in the exponential gain coding/decoding + */ + /** * \struct CameraSensorHelper::AnalogueGainConstants * \brief Analogue gain model constants @@ -161,6 +198,9 @@ double CameraSensorHelper::gain(uint32_t gainCode) const * * \var CameraSensorHelper::AnalogueGainConstants::linear * \brief Constants for the linear gain model + * + * \var CameraSensorHelper::AnalogueGainConstants::exp + * \brief Constants for the exponential gain model */ /** diff --git a/src/ipa/libipa/camera_sensor_helper.h b/src/ipa/libipa/camera_sensor_helper.h index 6b96520ba601..7351fc7c2928 100644 --- a/src/ipa/libipa/camera_sensor_helper.h +++ b/src/ipa/libipa/camera_sensor_helper.h @@ -41,8 +41,14 @@ protected: int16_t c1; }; + struct AnalogueGainExpConstants { + double a; + double m; + }; + union AnalogueGainConstants { AnalogueGainLinearConstants linear; + AnalogueGainExpConstants exp; }; AnalogueGainType gainType_; From patchwork Mon Mar 28 12:03:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 15574 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 9B3E2C3266 for ; Mon, 28 Mar 2022 12:03:46 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 372D665641; Mon, 28 Mar 2022 14:03:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1648469026; bh=+d6kCB2e1hteA+xpyl+y3/U0IOD1WIQchvxBLbIwORg=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=HPydSr1dR4bY2VsdTYNc5Sh/vFc81WF1hA858NeHddLD9Joq0fZNbyj8GOa0YGhTE uJUqEqmG60UtdnzXIIw7fs2j0y7lRsVBQQnXvTKN9oJs9pyzqX+SBzNkgLKBcHFJvZ /NZ6Jj7yUZzk9pB3WOw/AzC7XP+IEXf7PPmFZ9n+gyT8sVroXLWX9VMc2B4pYk88n0 /w4jjqqTzkHJBuHV9rBVQbghv91n6X4nd5mzv16Km/IAqVwD3MOaDgg4an6VHq3hX/ +yKgfYUQeJg2hMPtM6h/xfHV9bELNugwpYdcKX7T86Dgxexa7bWs6zKXrteBJH8S0w Sm0N+47SYtFiQ== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E3ACE601F5 for ; Mon, 28 Mar 2022 14:03:42 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Zh/EU+e7"; dkim-atps=neutral Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 8A46EE0A for ; Mon, 28 Mar 2022 14:03:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1648469022; bh=+d6kCB2e1hteA+xpyl+y3/U0IOD1WIQchvxBLbIwORg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Zh/EU+e7mWOr22MPn4Bv8px+4pKkGvn4Q0xqX5W3YonzpaFnT7AFYqzqcr0HEn3bO 60HVDiT++yiV49OEBTRTKZGj2WusrZ7BNqFgq2lY2W8C67D4e92SXNexU0IQIFpGyj /BXnrNdRMkXW7mYx0IN90NjzpCUumxgDitXAVb0A= To: libcamera-devel@lists.libcamera.org Date: Mon, 28 Mar 2022 15:03:35 +0300 Message-Id: <20220328120336.10834-4-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220328120336.10834-1-laurent.pinchart@ideasonboard.com> References: <20220328120336.10834-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 3/4] libipa: camera_sensor_helper: Add IMX290 helper 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: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The IMX290 is a Sony sensor that expresses its gain in 0.3dB units. It thus maps to the exponential gain model. Signed-off-by: Laurent Pinchart Reviewed-by: Jacopo Mondi Reviewed-by: Paul Elder Reviewed-by: Umang Jain --- src/ipa/libipa/camera_sensor_helper.cpp | 31 +++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/ipa/libipa/camera_sensor_helper.cpp b/src/ipa/libipa/camera_sensor_helper.cpp index 7bb999e19102..136b9f6bc3c5 100644 --- a/src/ipa/libipa/camera_sensor_helper.cpp +++ b/src/ipa/libipa/camera_sensor_helper.cpp @@ -332,6 +332,26 @@ std::vector &CameraSensorHelperFactory::factories() #ifndef __DOXYGEN__ +/* + * Helper function to compute the m parameter of the exponential gain model + * when the gain code is expressed in dB. + */ +static constexpr double expGainDb(double step) +{ + constexpr double log2_10 = 3.321928094887362; + + /* + * The gain code is expressed in step * dB (e.g. in 0.1 dB steps): + * + * G_code = G_dB/step = 20/step*log10(G_linear) + * + * Inverting the formula, we get + * + * G_linear = 10^(step/20*G_code) = 2^(log2(10)*step/20*G_code) + */ + return log2_10 * step / 20; +} + class CameraSensorHelperImx219 : public CameraSensorHelper { public: @@ -354,6 +374,17 @@ public: }; REGISTER_CAMERA_SENSOR_HELPER("imx258", CameraSensorHelperImx258) +class CameraSensorHelperImx290 : public CameraSensorHelper +{ +public: + CameraSensorHelperImx290() + { + gainType_ = AnalogueGainExponential; + gainConstants_.exp = { 1.0, expGainDb(0.3) }; + } +}; +REGISTER_CAMERA_SENSOR_HELPER("imx290", CameraSensorHelperImx290) + class CameraSensorHelperOv2740 : public CameraSensorHelper { public: From patchwork Mon Mar 28 12:03:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 15575 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 5B0DDC3267 for ; Mon, 28 Mar 2022 12:03:47 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E714C6563D; Mon, 28 Mar 2022 14:03:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1648469027; bh=UKRPKOpzs+ZAu7vwYjGLZMBGJvET+VtGr3m73Iz7vy8=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=puyA9LxyL4kFP3hOkKdY8nC550MoCy5swTQUHZvpN3yamCDNPGPkImimAkDiNBlRx Em7KnoKAXn1XBI3n5bw5qYNYo00Au3QeLrd1ofqst0PStXFlZQXhacox8R+6wiEi8+ utX8+llt8pxkLKHbSjdMAZdbrOFPbd+suju4cdrJJ33CwRs8HqJtL2LbZ0x52ljAaE 138RzkdT5awwnnQ2Ae2WzL2oliLvw2BHZuDzw1nAVpRiNhZAUnLGiInDkPrNbDNQH3 O4IVnn5FO/E3b0YkGq34C6HYGm19ZC+UTv/EDwteZF/s0ZDU0BY6SqAu9ULtJkLTlS GLfSgpzmlTgog== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 50FAB601F5 for ; Mon, 28 Mar 2022 14:03:43 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="A6n+HxSo"; dkim-atps=neutral Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id E6FAF299 for ; Mon, 28 Mar 2022 14:03:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1648469023; bh=UKRPKOpzs+ZAu7vwYjGLZMBGJvET+VtGr3m73Iz7vy8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=A6n+HxSoMP5Ql0UJUVHkP9LN6Os6i4rANPW7qyfIGdz5XUXFpGt2kct+MdMJOoKvn W8HK0eVKkobvBaKbgAGs4+Eq3qAp7328JGgsGiggXhE3EsnwOa7tc12XNGWqW7/Ezo UgiJ0n2f5Z0WJGSoBQliljX/8AIA1ojEzo2Y53N4= To: libcamera-devel@lists.libcamera.org Date: Mon, 28 Mar 2022 15:03:36 +0300 Message-Id: <20220328120336.10834-5-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220328120336.10834-1-laurent.pinchart@ideasonboard.com> References: <20220328120336.10834-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 4/4] libipa: camera_sensor_helper: Add IMX296 helper 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: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The IMX296 is a Sony sensor that expresses its gain in 0.1dB units. It thus maps to the exponential gain model. Signed-off-by: Laurent Pinchart Reviewed-by: Jacopo Mondi Reviewed-by: Umang Jain Reviewed-by: Paul Elder --- src/ipa/libipa/camera_sensor_helper.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/ipa/libipa/camera_sensor_helper.cpp b/src/ipa/libipa/camera_sensor_helper.cpp index 136b9f6bc3c5..0ec51f4e0753 100644 --- a/src/ipa/libipa/camera_sensor_helper.cpp +++ b/src/ipa/libipa/camera_sensor_helper.cpp @@ -385,6 +385,17 @@ public: }; REGISTER_CAMERA_SENSOR_HELPER("imx290", CameraSensorHelperImx290) +class CameraSensorHelperImx296 : public CameraSensorHelper +{ +public: + CameraSensorHelperImx296() + { + gainType_ = AnalogueGainExponential; + gainConstants_.exp = { 1.0, expGainDb(0.1) }; + } +}; +REGISTER_CAMERA_SENSOR_HELPER("imx296", CameraSensorHelperImx296) + class CameraSensorHelperOv2740 : public CameraSensorHelper { public: