Patch Detail
Show a patch.
GET /api/patches/15573/?format=api
{ "id": 15573, "url": "https://patchwork.libcamera.org/api/patches/15573/?format=api", "web_url": "https://patchwork.libcamera.org/patch/15573/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20220328120336.10834-3-laurent.pinchart@ideasonboard.com>", "date": "2022-03-28T12:03:34", "name": "[libcamera-devel,2/4] libipa: camera_sensor_helper: Implement exponential gain model", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "8b8f3d441da581e1003bb307987d7e940286c639", "submitter": { "id": 2, "url": "https://patchwork.libcamera.org/api/people/2/?format=api", "name": "Laurent Pinchart", "email": "laurent.pinchart@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/15573/mbox/", "series": [ { "id": 3008, "url": "https://patchwork.libcamera.org/api/series/3008/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3008", "date": "2022-03-28T12:03:32", "name": "IPA sensor helpers for IMX290 and IMX296", "version": 1, "mbox": "https://patchwork.libcamera.org/series/3008/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/15573/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/15573/checks/", "tags": {}, "headers": { "Return-Path": "<libcamera-devel-bounces@lists.libcamera.org>", "X-Original-To": "parsemail@patchwork.libcamera.org", "Delivered-To": "parsemail@patchwork.libcamera.org", "Received": [ "from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 1DF72C0F1B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 28 Mar 2022 12:03:46 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id B93496563F;\n\tMon, 28 Mar 2022 14:03:45 +0200 (CEST)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 88BBF601F5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 28 Mar 2022 14:03:42 +0200 (CEST)", "from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 2DF5F299\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 28 Mar 2022 14:03:42 +0200 (CEST)" ], "DKIM-Signature": [ "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1648469025;\n\tbh=/yJsoujfORPoipbpynh5ZxqKJClQzRj2IvNtqntWa14=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=Nnv9LtgiUxbgXvqnZndX2cauQ4nAb9KOoHQTgbyjCZVFwcJoJB0ObfPqTkGlM7nfS\n\tvftcoPVoZBLQBfvs1O52WoNSBUMa18XJ6rbAELaxfUIcj3uhU1Q3TWykXk/9r80aHC\n\tZM2LAWyBHzKu2IJ0eEtZv3PqPCEsIUxq73Lgxg30fK5H+HnnLA4xVIpTf5fIBdA0Op\n\tQuUoDpMMHFKo63RN7vw7OaqMMp8Drb/wz8vDcbRbgDeykUSJhcb861bxM42WHJ1OEW\n\tIPzpGeGrAFXsqQ94LHgrwIyiUCtSMhXaB86gkg5W86zf9kYSPEHIR0EZhcRrNVhQB5\n\twG/v+4sIkgJhQ==", "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1648469022;\n\tbh=/yJsoujfORPoipbpynh5ZxqKJClQzRj2IvNtqntWa14=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=Oc851Zz/DY+0zVJjN2u/rEDDgqUojG/BfvYiX4uOOKON0rl53usG5mnTNM3JjKJ0w\n\ti4osw3Z6X+O8CVI+7R1OFJk1F6klmGjsIDjEy4gdAiA/OR/P+Q4q72v6dsIF2x/3b6\n\tPp2rP0dvVJSh5ng/73UlEkOKkARlSVrJvb8HnMuM=" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"Oc851Zz/\"; dkim-atps=neutral", "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", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH 2/4] libipa: camera_sensor_helper:\n\tImplement exponential gain model", "X-BeenThere": "libcamera-devel@lists.libcamera.org", "X-Mailman-Version": "2.1.29", "Precedence": "list", "List-Id": "<libcamera-devel.lists.libcamera.org>", "List-Unsubscribe": "<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>", "List-Archive": "<https://lists.libcamera.org/pipermail/libcamera-devel/>", "List-Post": "<mailto:libcamera-devel@lists.libcamera.org>", "List-Help": "<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>", "List-Subscribe": "<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>", "From": "Laurent Pinchart via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>", "Reply-To": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "The CameraSensorHelper specifies two gain models, linear and an\nexponential. They are modelled after the MIPI CCS specification. Only\nthe linear model has been implemented, the exponential model was left\nfor later.\n\nWe now need to support sensors that configure their gain in a hardware\nregister with a value expressed in dB. This has similarities with the\nMIPI CCS exponential gain model, but is only has an exponential factor,\nwhile CCS also allows sensors to support a configurable linear factor.\n\nThe full CCS exponential model needs two values (for the linear and\nexponential factors) to express a gain, while IPAs use a single linear\ngain value internally. However, the exponential gain model example in\nthe CCS specification has a fixed linear factor, which may indicate that\nit could be common for sensors that implement the exponential gain model\nto only use the exponential factor. For this reason, implement the\nexponential gain model with a fixed linear factor, but with a\nsensor-specific coefficient for the exponential factor that allows\nexpressing the gain in dB (or other logarithmical units) instead of\nlimiting it to powers of 2 as in the MIPI CCS specification.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/ipa/libipa/camera_sensor_helper.cpp | 82 ++++++++++++++++++-------\n src/ipa/libipa/camera_sensor_helper.h | 6 ++\n 2 files changed, 67 insertions(+), 21 deletions(-)", "diff": "diff --git a/src/ipa/libipa/camera_sensor_helper.cpp b/src/ipa/libipa/camera_sensor_helper.cpp\nindex 714cd86f039f..7bb999e19102 100644\n--- a/src/ipa/libipa/camera_sensor_helper.cpp\n+++ b/src/ipa/libipa/camera_sensor_helper.cpp\n@@ -7,6 +7,8 @@\n */\n #include \"camera_sensor_helper.h\"\n \n+#include <cmath>\n+\n #include <libcamera/base/log.h>\n \n /**\n@@ -51,20 +53,28 @@ namespace ipa {\n * This function aims to abstract the calculation of the gain letting the IPA\n * use the real gain for its estimations.\n *\n- * The parameters come from the MIPI Alliance Camera Specification for\n- * Camera Command Set (CCS).\n- *\n * \\return The gain code to pass to V4L2\n */\n uint32_t CameraSensorHelper::gainCode(double gain) const\n {\n \tconst AnalogueGainConstants &k = gainConstants_;\n \n-\tASSERT(gainType_ == AnalogueGainLinear);\n-\tASSERT(k.linear.m0 == 0 || k.linear.m1 == 0);\n+\tswitch (gainType_) {\n+\tcase AnalogueGainLinear:\n+\t\tASSERT(k.linear.m0 == 0 || k.linear.m1 == 0);\n \n-\treturn (k.linear.c0 - k.linear.c1 * gain) /\n-\t (k.linear.m1 * gain - k.linear.m0);\n+\t\treturn (k.linear.c0 - k.linear.c1 * gain) /\n+\t\t (k.linear.m1 * gain - k.linear.m0);\n+\n+\tcase AnalogueGainExponential:\n+\t\tASSERT(k.exp.a != 0 && k.exp.m != 0);\n+\n+\t\treturn std::log2(gain / k.exp.a) / k.exp.m;\n+\n+\tdefault:\n+\t\tASSERT(false);\n+\t\treturn 0;\n+\t}\n }\n \n /**\n@@ -75,20 +85,29 @@ uint32_t CameraSensorHelper::gainCode(double gain) const\n * use the real gain for its estimations. It is the counterpart of the function\n * CameraSensorHelper::gainCode.\n *\n- * The parameters come from the MIPI Alliance Camera Specification for\n- * Camera Command Set (CCS).\n- *\n * \\return The real gain\n */\n double CameraSensorHelper::gain(uint32_t gainCode) const\n {\n \tconst AnalogueGainConstants &k = gainConstants_;\n+\tdouble gain = static_cast<double>(gainCode);\n \n-\tASSERT(gainType_ == AnalogueGainLinear);\n-\tASSERT(k.linear.m0 == 0 || k.linear.m1 == 0);\n+\tswitch (gainType_) {\n+\tcase AnalogueGainLinear:\n+\t\tASSERT(k.linear.m0 == 0 || k.linear.m1 == 0);\n \n-\treturn (k.linear.m0 * static_cast<double>(gainCode) + k.linear.c0) /\n-\t (k.linear.m1 * static_cast<double>(gainCode) + k.linear.c1);\n+\t\treturn (k.linear.m0 * gain + k.linear.c0) /\n+\t\t (k.linear.m1 * gain + k.linear.c1);\n+\n+\tcase AnalogueGainExponential:\n+\t\tASSERT(k.exp.a != 0 && k.exp.m != 0);\n+\n+\t\treturn k.exp.a * std::exp2(k.exp.m * gain);\n+\n+\tdefault:\n+\t\tASSERT(false);\n+\t\treturn 0.0;\n+\t}\n }\n \n /**\n@@ -120,15 +139,22 @@ double CameraSensorHelper::gain(uint32_t gainCode) const\n \n /**\n * \\var CameraSensorHelper::AnalogueGainExponential\n- * \\brief Gain is computed using exponential gain estimation\n- * (introduced in CCS v1.1)\n+ * \\brief Gain is expressed using an exponential model\n *\n- * Starting with CCS v1.1, Alternate Global Analogue Gain is also available.\n- * If the image sensor supports it, then the global analogue gain can be\n- * controlled by linear and exponential gain formula:\n+ * The relationship between the integer gain parameter and the resulting gain\n+ * multiplier is given by the following equation:\n *\n- * \\f$gain = analogLinearGainGlobal * 2^{analogExponentialGainGlobal}\\f$\n- * \\todo not implemented in libipa\n+ * \\f$gain = a \\cdot 2^{m \\cdot x}\\f$\n+ *\n+ * Where 'x' is the gain control parameter, and 'a' and 'm' are image\n+ * sensor-specific constants.\n+ *\n+ * This is a subset of the MIPI CCS exponential gain model with the linear\n+ * factor 'a' being a constant, but with the exponent being configurable\n+ * through the 'm' coefficient.\n+ *\n+ * When the gain is expressed in dB, 'a' is equal to 1 and 'm' to\n+ * \\f$log_{2}{10^{frac{1}{20}}}\\f$.\n */\n \n /**\n@@ -152,6 +178,17 @@ double CameraSensorHelper::gain(uint32_t gainCode) const\n * \\brief Constant used in the linear gain coding/decoding\n */\n \n+/**\n+ * \\struct CameraSensorHelper::AnalogueGainExpConstants\n+ * \\brief Analogue gain constants for the exponential gain model\n+ *\n+ * \\var CameraSensorHelper::AnalogueGainExpConstants::a\n+ * \\brief Constant used in the exponential gain coding/decoding\n+ *\n+ * \\var CameraSensorHelper::AnalogueGainExpConstants::m\n+ * \\brief Constant used in the exponential gain coding/decoding\n+ */\n+\n /**\n * \\struct CameraSensorHelper::AnalogueGainConstants\n * \\brief Analogue gain model constants\n@@ -161,6 +198,9 @@ double CameraSensorHelper::gain(uint32_t gainCode) const\n *\n * \\var CameraSensorHelper::AnalogueGainConstants::linear\n * \\brief Constants for the linear gain model\n+ *\n+ * \\var CameraSensorHelper::AnalogueGainConstants::exp\n+ * \\brief Constants for the exponential gain model\n */\n \n /**\ndiff --git a/src/ipa/libipa/camera_sensor_helper.h b/src/ipa/libipa/camera_sensor_helper.h\nindex 6b96520ba601..7351fc7c2928 100644\n--- a/src/ipa/libipa/camera_sensor_helper.h\n+++ b/src/ipa/libipa/camera_sensor_helper.h\n@@ -41,8 +41,14 @@ protected:\n \t\tint16_t c1;\n \t};\n \n+\tstruct AnalogueGainExpConstants {\n+\t\tdouble a;\n+\t\tdouble m;\n+\t};\n+\n \tunion AnalogueGainConstants {\n \t\tAnalogueGainLinearConstants linear;\n+\t\tAnalogueGainExpConstants exp;\n \t};\n \n \tAnalogueGainType gainType_;\n", "prefixes": [ "libcamera-devel", "2/4" ] }