Show a patch.

GET /api/patches/20574/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 20574,
    "url": "https://patchwork.libcamera.org/api/patches/20574/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/20574/",
    "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": "<20240703231136.5732-1-laurent.pinchart@ideasonboard.com>",
    "date": "2024-07-03T23:11:36",
    "name": "[v2] libcamera: libipa: camera_sensor: Add onsemi AR0144 sensor properties",
    "commit_ref": "74513c398762737996267b3da7dc6af3c782bd05",
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "a2e57707e92e3cd18dbd4aa2b4d4c165b29b66e9",
    "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/20574/mbox/",
    "series": [
        {
            "id": 4443,
            "url": "https://patchwork.libcamera.org/api/series/4443/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4443",
            "date": "2024-07-03T23:11:36",
            "name": "[v2] libcamera: libipa: camera_sensor: Add onsemi AR0144 sensor properties",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/4443/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/20574/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/20574/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 C9157BD87C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  3 Jul 2024 23:12:01 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 9B1F262C96;\n\tThu,  4 Jul 2024 01:12:00 +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 31BE0619CC\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  4 Jul 2024 01:11:58 +0200 (CEST)",
            "from pendragon.ideasonboard.com\n\t(117.145-247-81.adsl-dyn.isp.belgacom.be [81.247.145.117])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 9B1AE4CC\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  4 Jul 2024 01:11:29 +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=\"sW7yjRtp\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1720048289;\n\tbh=fdficpfTr1jQZMeZO9K+Vv6SJoftMLB2rEeriRCxuSc=;\n\th=From:To:Subject:Date:From;\n\tb=sW7yjRtp7C+DpRfZjPTbZwyABw8PGnR6ahJarWQZqy8tknP1bML4xomVLaguhnYlz\n\tTY4xFxYrtuqCqfROuum693e9/0SDmEqppJEyfb3K+3EgONIVbONxRCm02RMXhTvJhE\n\tj4TvPcQ0zckv4nGGau1ei2IXVmUG/tEzo0/gFeF8=",
        "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Subject": "[PATCH v2] libcamera: libipa: camera_sensor: Add onsemi AR0144\n\tsensor properties",
        "Date": "Thu,  4 Jul 2024 02:11:36 +0300",
        "Message-ID": "<20240703231136.5732-1-laurent.pinchart@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.44.2",
        "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": "Provide the onsemi AR0144 camera sensor properties and registration with\nlibipa for the gain code helpers.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\nNow that the kernel driver has been posted to the linux-media mailing\nlist ([1]), it's time for a second version of this patch.\n\n[1] https://lore.kernel.org/r/20240603230301.26550-1-laurent.pinchart@ideasonboard.com\n\nChanges since RFC:\n\n- Add default case\n- Add black level\n---\n src/ipa/libipa/camera_sensor_helper.cpp       | 94 +++++++++++++++++++\n .../sensor/camera_sensor_properties.cpp       |  9 ++\n 2 files changed, 103 insertions(+)\n\n\nbase-commit: 196abb8d1d6e0fe9d190315e72a85eb12d16a554",
    "diff": "diff --git a/src/ipa/libipa/camera_sensor_helper.cpp b/src/ipa/libipa/camera_sensor_helper.cpp\nindex a1339c83c4cb..1cae0b3840af 100644\n--- a/src/ipa/libipa/camera_sensor_helper.cpp\n+++ b/src/ipa/libipa/camera_sensor_helper.cpp\n@@ -8,6 +8,7 @@\n #include \"camera_sensor_helper.h\"\n \n #include <cmath>\n+#include <limits>\n \n #include <libcamera/base/log.h>\n \n@@ -398,6 +399,99 @@ static constexpr double expGainDb(double step)\n \treturn log2_10 * step / 20;\n }\n \n+class CameraSensorHelperAr0144 : public CameraSensorHelper\n+{\n+public:\n+\tCameraSensorHelperAr0144()\n+\t{\n+\t\t/* Power-on default value: 168 at 12bits. */\n+\t\tblackLevel_ = 2688;\n+\t}\n+\n+\tuint32_t gainCode(double gain) const override\n+\t{\n+\t\t/* The recommended minimum gain is 1.6842 to avoid artifacts. */\n+\t\tgain = std::clamp(gain, 1.0 / (1.0 - 13.0 / 32.0), 18.45);\n+\n+\t\t/*\n+\t\t * The analogue gain is made of a coarse exponential gain in\n+\t\t * the range [2^0, 2^4] and a fine inversely linear gain in the\n+\t\t * range [1.0, 2.0[. There is an additional fixed 1.153125\n+\t\t * multiplier when the coarse gain reaches 2^2.\n+\t\t */\n+\n+\t\tif (gain > 4.0)\n+\t\t\tgain /= 1.153125;\n+\n+\t\tunsigned int coarse = std::log2(gain);\n+\t\tunsigned int fine = (1 - (1 << coarse) / gain) * 32;\n+\n+\t\t/* The fine gain rounding depends on the coarse gain. */\n+\t\tif (coarse == 1 || coarse == 3)\n+\t\t\tfine &= ~1;\n+\t\telse if (coarse == 4)\n+\t\t\tfine &= ~3;\n+\n+\t\treturn (coarse << 4) | (fine & 0xf);\n+\t}\n+\n+\tdouble gain(uint32_t gainCode) const override\n+\t{\n+\t\tunsigned int coarse = gainCode >> 4;\n+\t\tunsigned int fine = gainCode & 0xf;\n+\t\tunsigned int d1;\n+\t\tdouble d2, m;\n+\n+\t\tswitch (coarse) {\n+\t\tdefault:\n+\t\tcase 0:\n+\t\t\td1 = 1;\n+\t\t\td2 = 32.0;\n+\t\t\tm = 1.0;\n+\t\t\tbreak;\n+\t\tcase 1:\n+\t\t\td1 = 2;\n+\t\t\td2 = 16.0;\n+\t\t\tm = 1.0;\n+\t\t\tbreak;\n+\t\tcase 2:\n+\t\t\td1 = 1;\n+\t\t\td2 = 32.0;\n+\t\t\tm = 1.153125;\n+\t\t\tbreak;\n+\t\tcase 3:\n+\t\t\td1 = 2;\n+\t\t\td2 = 16.0;\n+\t\t\tm = 1.153125;\n+\t\t\tbreak;\n+\t\tcase 4:\n+\t\t\td1 = 4;\n+\t\t\td2 = 8.0;\n+\t\t\tm = 1.153125;\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\t/*\n+\t\t * With infinite precision, the calculated gain would be exact,\n+\t\t * and the reverse conversion with gainCode() would produce the\n+\t\t * same gain code. In the real world, rounding errors may cause\n+\t\t * the calculated gain to be lower by an amount negligible for\n+\t\t * all purposes, except for the reverse conversion. Converting\n+\t\t * the gain to a gain code could then return the quantized value\n+\t\t * just lower than the original gain code. To avoid this, tests\n+\t\t * showed that adding the machine epsilon to the multiplier m is\n+\t\t * sufficient.\n+\t\t */\n+\t\tm += std::numeric_limits<decltype(m)>::epsilon();\n+\n+\t\treturn m * (1 << coarse) / (1.0 - (fine / d1) / d2);\n+\t}\n+\n+private:\n+\tstatic constexpr double kStep_ = 16;\n+};\n+REGISTER_CAMERA_SENSOR_HELPER(\"ar0144\", CameraSensorHelperAr0144)\n+\n class CameraSensorHelperAr0521 : public CameraSensorHelper\n {\n public:\ndiff --git a/src/libcamera/sensor/camera_sensor_properties.cpp b/src/libcamera/sensor/camera_sensor_properties.cpp\nindex b18524d85b37..4e5217ab51ef 100644\n--- a/src/libcamera/sensor/camera_sensor_properties.cpp\n+++ b/src/libcamera/sensor/camera_sensor_properties.cpp\n@@ -52,6 +52,15 @@ LOG_DEFINE_CATEGORY(CameraSensorProperties)\n const CameraSensorProperties *CameraSensorProperties::get(const std::string &sensor)\n {\n \tstatic const std::map<std::string, const CameraSensorProperties> sensorProps = {\n+\t\t{ \"ar0144\", {\n+\t\t\t.unitCellSize = { 3000, 3000 },\n+\t\t\t.testPatternModes = {\n+\t\t\t\t{ controls::draft::TestPatternModeOff, 0 },\n+\t\t\t\t{ controls::draft::TestPatternModeSolidColor, 1 },\n+\t\t\t\t{ controls::draft::TestPatternModeColorBars, 2 },\n+\t\t\t\t{ controls::draft::TestPatternModeColorBarsFadeToGray, 3 },\n+\t\t\t},\n+\t\t} },\n \t\t{ \"ar0521\", {\n \t\t\t.unitCellSize = { 2200, 2200 },\n \t\t\t.testPatternModes = {\n",
    "prefixes": [
        "v2"
    ]
}