Show a patch.

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

{
    "id": 20098,
    "url": "https://patchwork.libcamera.org/api/patches/20098/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/20098/",
    "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": "<20240524135256.649406-2-kieran.bingham@ideasonboard.com>",
    "date": "2024-05-24T13:52:55",
    "name": "[v2,1/2] test: ipa: libipa: Add CameraSensorHelper Gain Model tests",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "560db56249634a31c22cca2f8b377e36df8c237d",
    "submitter": {
        "id": 4,
        "url": "https://patchwork.libcamera.org/api/people/4/?format=api",
        "name": "Kieran Bingham",
        "email": "kieran.bingham@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/20098/mbox/",
    "series": [
        {
            "id": 4325,
            "url": "https://patchwork.libcamera.org/api/series/4325/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4325",
            "date": "2024-05-24T13:52:54",
            "name": "libipa: Fix CameraSensorHelper gain helpers",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/4325/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/20098/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/20098/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 A0FE2BD87C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 24 May 2024 13:53:06 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 28B9E634AC;\n\tFri, 24 May 2024 15:53:06 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id EFCB9634A8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 24 May 2024 15:53:00 +0200 (CEST)",
            "from Monstersaurus.local\n\t(cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id A6B4FD01;\n\tFri, 24 May 2024 15:52:46 +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=\"qWrDM98J\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1716558766;\n\tbh=7Z/SPyYH4evZP8X6lerq9wW+MNk5DuxVuhlmrGxCiHw=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=qWrDM98J4C1vL18xk1pG7RO15cJ5RIax6gUEKvlSs+I9zl3stnpQXbYeC3MWCHUuB\n\t13tTDb9nBOyh0aEshI9bb2zHKTZ4U7jMmg6VPdblCW+VFj2gOgQNWsHwW/MmUfROrq\n\tGy9B+Z/+xfgFff1OH/oWAkToSISHPiNN+knVFi2Y=",
        "From": "Kieran Bingham <kieran.bingham@ideasonboard.com>",
        "To": "libcamera devel <libcamera-devel@lists.libcamera.org>",
        "Cc": "Kieran Bingham <kieran.bingham@ideasonboard.com>",
        "Subject": "[PATCH v2 1/2] test: ipa: libipa: Add CameraSensorHelper Gain Model\n\ttests",
        "Date": "Fri, 24 May 2024 14:52:55 +0100",
        "Message-Id": "<20240524135256.649406-2-kieran.bingham@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.34.1",
        "In-Reply-To": "<20240524135256.649406-1-kieran.bingham@ideasonboard.com>",
        "References": "<20240524135256.649406-1-kieran.bingham@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": "Introduce a test that validates conversion of the gain model\nin both Linear and Exponential models.\n\nIt should be expected that if a gainCode produces a given gain\nvalue, then converting that gain back should produce the same\nresult.\n\nThe test is known to fail and is marked as such. The test will be\nupdated with the corresponding fix.\n\nSigned-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n---\n test/ipa/camera_sensor_helper.cpp | 101 ++++++++++++++++++++++++++++++\n test/ipa/meson.build              |   5 +-\n 2 files changed, 105 insertions(+), 1 deletion(-)\n create mode 100644 test/ipa/camera_sensor_helper.cpp",
    "diff": "diff --git a/test/ipa/camera_sensor_helper.cpp b/test/ipa/camera_sensor_helper.cpp\nnew file mode 100644\nindex 000000000000..d8a8c6850a04\n--- /dev/null\n+++ b/test/ipa/camera_sensor_helper.cpp\n@@ -0,0 +1,101 @@\n+/* SPDX-License-Identifier: GPL-2.0-or-later */\n+/*\n+ * Copyright (C) 2024, Ideas on Board Oy.\n+ */\n+\n+#include \"libipa/camera_sensor_helper.h\"\n+\n+#include <iostream>\n+#include <string.h>\n+\n+#include \"test.h\"\n+\n+using namespace std;\n+using namespace libcamera;\n+using namespace libcamera::ipa;\n+\n+/*\n+ * Helper function to compute the m parameter of the exponential gain model\n+ * when the gain code is expressed in dB.\n+ */\n+static constexpr double expGainDb(double step)\n+{\n+\tconstexpr double log2_10 = 3.321928094887362;\n+\n+\t/*\n+         * The gain code is expressed in step * dB (e.g. in 0.1 dB steps):\n+         *\n+         * G_code = G_dB/step = 20/step*log10(G_linear)\n+         *\n+         * Inverting the formula, we get\n+         *\n+         * G_linear = 10^(step/20*G_code) = 2^(log2(10)*step/20*G_code)\n+         */\n+\treturn log2_10 * step / 20;\n+}\n+\n+class CameraSensorHelperExponential : public CameraSensorHelper\n+{\n+public:\n+\tCameraSensorHelperExponential()\n+\t{\n+\t\tgainType_ = AnalogueGainExponential;\n+\t\tgainConstants_.exp = { 1.0, expGainDb(0.3) };\n+\t}\n+};\n+\n+class CameraSensorHelperLinear : public CameraSensorHelper\n+{\n+public:\n+\tCameraSensorHelperLinear()\n+\t{\n+\t\tgainType_ = AnalogueGainLinear;\n+\t\tgainConstants_.linear = { 0, 1024, -1, 1024 };\n+\t}\n+};\n+\n+class CameraSensorHelperTest : public Test\n+{\n+protected:\n+\tint testGainModel(CameraSensorHelper &helper)\n+\t{\n+\t\tint ret = TestPass;\n+\n+\t\t/*\n+\t\t * Arbitrarily test 255 code positions assuming 8 bit fields\n+\t\t * are the normal maximum for a gain code register.\n+\t\t */\n+\t\tfor (unsigned int i = 0; i < 255; i++) {\n+\t\t\tfloat gain = helper.gain(i);\n+\t\t\tuint32_t gainCode = helper.gainCode(gain);\n+\n+\t\t\tif (i != gainCode) {\n+\t\t\t\tstd::cout << \"Gain conversions failed: \"\n+\t\t\t\t\t  << i << \" : \" << gain << \" : \"\n+\t\t\t\t\t  << gainCode << std::endl;\n+\n+\t\t\t\tret = TestFail;\n+\t\t\t}\n+\t\t};\n+\n+\t\treturn ret;\n+\t}\n+\n+\tint run() override\n+\t{\n+\t\tunsigned int failures = 0;\n+\n+\t\tCameraSensorHelperExponential exponential;\n+\t\tCameraSensorHelperLinear linear;\n+\n+\t\tif (testGainModel(exponential) == TestFail)\n+\t\t\tfailures++;\n+\n+\t\tif (testGainModel(linear) == TestFail)\n+\t\t\tfailures++;\n+\n+\t\treturn failures ? TestFail : TestPass;\n+\t}\n+};\n+\n+TEST_REGISTER(CameraSensorHelperTest)\ndiff --git a/test/ipa/meson.build b/test/ipa/meson.build\nindex 180b0da0a51a..abc2456fc341 100644\n--- a/test/ipa/meson.build\n+++ b/test/ipa/meson.build\n@@ -1,6 +1,8 @@\n # SPDX-License-Identifier: CC0-1.0\n \n ipa_test = [\n+    {'name': 'camera_sensor_helper', 'sources': ['camera_sensor_helper.cpp'],\n+     'should_fail': true},\n     {'name': 'ipa_module_test', 'sources': ['ipa_module_test.cpp']},\n     {'name': 'ipa_interface_test', 'sources': ['ipa_interface_test.cpp']},\n ]\n@@ -11,5 +13,6 @@ foreach test : ipa_test\n                      link_with : [libipa, test_libraries],\n                      include_directories : [libipa_includes, test_includes_internal])\n \n-    test(test['name'], exe, suite : 'ipa')\n+    test(test['name'], exe, suite : 'ipa',\n+         should_fail : test.get('should_fail', false))\n endforeach\n",
    "prefixes": [
        "v2",
        "1/2"
    ]
}