{"id":20508,"url":"https://patchwork.libcamera.org/api/1.1/patches/20508/?format=json","web_url":"https://patchwork.libcamera.org/patch/20508/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20240703135000.242227-2-stefan.klug@ideasonboard.com>","date":"2024-07-03T13:49:49","name":"[v3,1/6] ipa: libipa: Add black levels to camera sensor helper","commit_ref":"808a395d195ff7d35b00da34f6276a0178492081","pull_url":null,"state":"accepted","archived":false,"hash":"cbd221f1822c49c8b7c002c51084d8a1f500e99f","submitter":{"id":184,"url":"https://patchwork.libcamera.org/api/1.1/people/184/?format=json","name":"Stefan Klug","email":"stefan.klug@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/20508/mbox/","series":[{"id":4436,"url":"https://patchwork.libcamera.org/api/1.1/series/4436/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4436","date":"2024-07-03T13:49:48","name":"ipa: Add black level to camera sensor helpers","version":3,"mbox":"https://patchwork.libcamera.org/series/4436/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/20508/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/20508/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 8C0EEBD87C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  3 Jul 2024 13:50:11 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 0319362E25;\n\tWed,  3 Jul 2024 15:50:11 +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 D98EE62C95\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  3 Jul 2024 15:50:08 +0200 (CEST)","from ideasonboard.com (unknown\n\t[IPv6:2a00:6020:448c:6c00:9263:c199:9587:576])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id BFE713D6;\n\tWed,  3 Jul 2024 15:49:40 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"D38LDlSF\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1720014580;\n\tbh=HX3uAUPRMm66rx8wnqck16xTrciPzeJCvjFVfNnc+Ls=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=D38LDlSF970FKEbn5zqrMmGQYaytb8NOD0+vRAJCGb+WD/Z/3Qte2dowxbVeqjaiW\n\taFlp7ZTjLTtCw/ytDqUObN23Sel9CoGkRfK+Jon2i9nG61xl7mP322fDaJPrQdxJfR\n\tQ9KhxhPRh5dqaE59X3ZmLbKt8YJ+A/uv4OADpk1A=","From":"Stefan Klug <stefan.klug@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"Stefan Klug <stefan.klug@ideasonboard.com>,\n\tPaul Elder <paul.elder@ideasonboard.com>,\n\tKieran Bingham <kieran.bingham@ideasonboard.com>,\n\tLaurent Pinchart <laurent.pinchart@ideasonboard.com>","Subject":"[PATCH v3 1/6] ipa: libipa: Add black levels to camera sensor helper","Date":"Wed,  3 Jul 2024 15:49:49 +0200","Message-ID":"<20240703135000.242227-2-stefan.klug@ideasonboard.com>","X-Mailer":"git-send-email 2.43.0","In-Reply-To":"<20240703135000.242227-1-stefan.klug@ideasonboard.com>","References":"<20240703135000.242227-1-stefan.klug@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"For a proper tuning process we need to know the sensor black levels. In\nmost cases these are fixed and not reported by the kernel driver. Store\nthem inside the sensor helpers for later retrieval by the algorithms.\n\nAdd black level value corresponding to the data pedestal for three\ninitial sensors as documented in the datasheets. More should be added,\neventually filling the gaps for all supported sensors.\n\nSigned-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\nReviewed-by: Paul Elder <paul.elder@ideasonboard.com>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/ipa/libipa/camera_sensor_helper.cpp | 38 +++++++++++++++++++++++++\n src/ipa/libipa/camera_sensor_helper.h   |  3 ++\n 2 files changed, 41 insertions(+)","diff":"diff --git a/src/ipa/libipa/camera_sensor_helper.cpp b/src/ipa/libipa/camera_sensor_helper.cpp\nindex 782ff9904e81..82c795eac71b 100644\n--- a/src/ipa/libipa/camera_sensor_helper.cpp\n+++ b/src/ipa/libipa/camera_sensor_helper.cpp\n@@ -47,6 +47,33 @@ namespace ipa {\n  * function.\n  */\n \n+/**\n+ * \\fn CameraSensorHelper::blackLevel()\n+ * \\brief Fetch the black level of the sensor\n+ *\n+ * This function returns the black level of the sensor scaled to a 16bit pixel\n+ * width. If it is unknown an empty optional is returned.\n+ *\n+ * \\todo Fill the blanks and add pedestal values for all supported sensors. Once\n+ * done, drop the std::optional<>.\n+ *\n+ * Black levels are typically the result of the following phenomena:\n+ * - Pedestal added by the sensor to pixel values. They are typically fixed,\n+ *   sometimes programmable and should be reported in datasheets (but\n+ *   documentation is not always available).\n+ * - Dark currents and other physical effects that add charge to pixels in the\n+ *   absence of light. Those can depend on the integration time and the sensor\n+ *   die temperature, and their contribution to pixel values depend on the\n+ *   sensor gains.\n+ *\n+ * The pedestal is usually the value with the biggest contribution to the\n+ * overall black level. In most cases it is either known before or in rare cases\n+ * (there is not a single driver with such a control in the linux kernel) can be\n+ * queried from the sensor. This function provides that fixed, known value.\n+ *\n+ * \\return The black level of the sensor, or std::nullopt if not known\n+ */\n+\n /**\n  * \\brief Compute gain code from the analogue gain absolute value\n  * \\param[in] gain The real gain to pass\n@@ -204,6 +231,11 @@ double CameraSensorHelper::gain(uint32_t gainCode) const\n  * \\brief Constants for the exponential gain model\n  */\n \n+/**\n+ * \\var CameraSensorHelper::blackLevel_\n+ * \\brief The black level of the sensor\n+ */\n+\n /**\n  * \\var CameraSensorHelper::gainType_\n  * \\brief The analogue gain model type\n@@ -396,6 +428,8 @@ class CameraSensorHelperImx219 : public CameraSensorHelper\n public:\n \tCameraSensorHelperImx219()\n \t{\n+\t\t/* From datasheet: 64 at 10bits. */\n+\t\tblackLevel_ = 4096;\n \t\tgainType_ = AnalogueGainLinear;\n \t\tgainConstants_.linear = { 0, 256, -1, 256 };\n \t}\n@@ -407,6 +441,8 @@ class CameraSensorHelperImx258 : public CameraSensorHelper\n public:\n \tCameraSensorHelperImx258()\n \t{\n+\t\t/* From datasheet: 0x40 at 10bits. */\n+\t\tblackLevel_ = 4096;\n \t\tgainType_ = AnalogueGainLinear;\n \t\tgainConstants_.linear = { 0, 512, -1, 512 };\n \t}\n@@ -456,6 +492,8 @@ class CameraSensorHelperImx335 : public CameraSensorHelper\n public:\n \tCameraSensorHelperImx335()\n \t{\n+\t\t/* From datasheet: 0x32 at 10bits. */\n+\t\tblackLevel_ = 3200;\n \t\tgainType_ = AnalogueGainExponential;\n \t\tgainConstants_.exp = { 1.0, expGainDb(0.3) };\n \t}\ndiff --git a/src/ipa/libipa/camera_sensor_helper.h b/src/ipa/libipa/camera_sensor_helper.h\nindex 0d99073bea82..ac276e27f523 100644\n--- a/src/ipa/libipa/camera_sensor_helper.h\n+++ b/src/ipa/libipa/camera_sensor_helper.h\n@@ -10,6 +10,7 @@\n #include <stdint.h>\n \n #include <memory>\n+#include <optional>\n #include <string>\n #include <vector>\n \n@@ -25,6 +26,7 @@ public:\n \tCameraSensorHelper() = default;\n \tvirtual ~CameraSensorHelper() = default;\n \n+\tstd::optional<int16_t> blackLevel() const { return blackLevel_; }\n \tvirtual uint32_t gainCode(double gain) const;\n \tvirtual double gain(uint32_t gainCode) const;\n \n@@ -51,6 +53,7 @@ protected:\n \t\tAnalogueGainExpConstants exp;\n \t};\n \n+\tstd::optional<int16_t> blackLevel_;\n \tAnalogueGainType gainType_;\n \tAnalogueGainConstants gainConstants_;\n \n","prefixes":["v3","1/6"]}