Show a patch.

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

{
    "id": 20637,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/20637/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/20637/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/1.1/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": "<20240709144950.3277837-7-dan.scally@ideasonboard.com>",
    "date": "2024-07-09T14:49:46",
    "name": "[v2,06/10] ipa: mali-c55: Add BLC Algorithm",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "97bd3dd1ae12a93b512ee45c7a5bcfcd4f10a654",
    "submitter": {
        "id": 156,
        "url": "https://patchwork.libcamera.org/api/1.1/people/156/?format=api",
        "name": "Dan Scally",
        "email": "dan.scally@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/20637/mbox/",
    "series": [
        {
            "id": 4449,
            "url": "https://patchwork.libcamera.org/api/1.1/series/4449/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4449",
            "date": "2024-07-09T14:49:40",
            "name": "Add Mali-C55 IPA Module and Algorithms",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/4449/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/20637/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/20637/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 8F1A4C328C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  9 Jul 2024 14:50:14 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2AB5563387;\n\tTue,  9 Jul 2024 16: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 08BE363377\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  9 Jul 2024 16:49:57 +0200 (CEST)",
            "from mail.ideasonboard.com\n\t(cpc141996-chfd3-2-0-cust928.12-3.cable.virginm.net [86.13.91.161])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 94EBE2395;\n\tTue,  9 Jul 2024 16:49:24 +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=\"QzURKxgy\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1720536564;\n\tbh=1Woc6L1aMTKznMg98pJn+b77rCkkD4KH5Ty+CT3Logw=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=QzURKxgyGM3vpkpw07/KbCq0aKrl157xDRsErvW5BxB12iZGVjRQlR3N8B6M9PRTR\n\tM9IDpwv8ZMtyd/ogYmegBMsHKakxf7uuzakl4Vd1OGLHOdPjS5kanhzq71RhX4bK5B\n\tySPraB17fjHoOR3N2R1MsBwcOc5D7KO1PeGjy/hU=",
        "From": "Daniel Scally <dan.scally@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "Jacopo Mondi <jacopo.mondi@ideasonboard.com>,\n\tNayden Kanchev <nayden.kanchev@arm.com>",
        "Subject": "[PATCH v2 06/10] ipa: mali-c55: Add BLC Algorithm",
        "Date": "Tue,  9 Jul 2024 15:49:46 +0100",
        "Message-Id": "<20240709144950.3277837-7-dan.scally@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.34.1",
        "In-Reply-To": "<20240709144950.3277837-1-dan.scally@ideasonboard.com>",
        "References": "<20240709144950.3277837-1-dan.scally@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": "From: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n\nAdd a Black Level Correction algorithm.\n\nAcked-by: Nayden Kanchev  <nayden.kanchev@arm.com>\nJacopo Mondi <jacopo.mondi@ideasonboard.com>\n---\nChanges in v2:\n\n\t- Use the union rather than reinterpret_cast<>() to abstract the block\n\n src/ipa/mali-c55/algorithms/blc.cpp     | 121 ++++++++++++++++++++++++\n src/ipa/mali-c55/algorithms/blc.h       |  40 ++++++++\n src/ipa/mali-c55/algorithms/meson.build |   1 +\n 3 files changed, 162 insertions(+)\n create mode 100644 src/ipa/mali-c55/algorithms/blc.cpp\n create mode 100644 src/ipa/mali-c55/algorithms/blc.h",
    "diff": "diff --git a/src/ipa/mali-c55/algorithms/blc.cpp b/src/ipa/mali-c55/algorithms/blc.cpp\nnew file mode 100644\nindex 00000000..aebb9dc4\n--- /dev/null\n+++ b/src/ipa/mali-c55/algorithms/blc.cpp\n@@ -0,0 +1,121 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2021-2022, Ideas On Board\n+ *\n+ * blc.cpp - Mali-C55 sensor offset (black level) correction\n+ */\n+\n+#include \"blc.h\"\n+\n+#include <libcamera/base/log.h>\n+#include <libcamera/control_ids.h>\n+\n+#include \"libcamera/internal/yaml_parser.h\"\n+\n+/**\n+ * \\file blc.h\n+ */\n+\n+namespace libcamera {\n+\n+namespace ipa::mali_c55::algorithms {\n+\n+/**\n+ * \\class BlackLevelCorrection\n+ * \\brief MaliC55 Black Level Correction control\n+ *\n+ * todo\n+ */\n+\n+LOG_DEFINE_CATEGORY(MaliC55Blc)\n+\n+BlackLevelCorrection::BlackLevelCorrection()\n+\t: tuningParameters_(false)\n+{\n+}\n+\n+/**\n+ * \\copydoc libcamera::ipa::Algorithm::init\n+ */\n+int BlackLevelCorrection::init([[maybe_unused]] IPAContext &context,\n+\t\t\t       const YamlObject &tuningData)\n+{\n+\toffset00 = tuningData[\"offset00\"].get<uint32_t>(256);\n+\toffset01 = tuningData[\"offset01\"].get<uint32_t>(256);\n+\toffset10 = tuningData[\"offset10\"].get<uint32_t>(256);\n+\toffset11 = tuningData[\"offset11\"].get<uint32_t>(256);\n+\n+\tif (offset00 > kMaxOffset || offset01 > kMaxOffset ||\n+\t    offset10 > kMaxOffset || offset11 > kMaxOffset) {\n+\t\tLOG(MaliC55Blc, Error) << \"Invalid black level offsets\";\n+\t\treturn -EINVAL;\n+\t}\n+\n+\ttuningParameters_ = true;\n+\n+\tLOG(MaliC55Blc, Debug)\n+\t\t<< \"Black levels: 00 \" << offset00 << \", 01 \" << offset01\n+\t\t<< \", 10 \" << offset10 << \", 11 \" << offset11;\n+\n+\treturn 0;\n+}\n+\n+/**\n+ * \\copydoc libcamera::ipa::Algorithm::prepare\n+ */\n+void BlackLevelCorrection::prepare([[maybe_unused]] IPAContext &context,\n+\t\t\t\t   const uint32_t frame,\n+\t\t\t\t   [[maybe_unused]] IPAFrameContext &frameContext,\n+\t\t\t\t   mali_c55_params_buffer *params)\n+{\n+\tmali_c55_params_block block;\n+\tblock.data = &params->data[params->total_size];\n+\n+\tif (frame > 0)\n+\t\treturn;\n+\n+\tif (!tuningParameters_)\n+\t\treturn;\n+\n+\tblock.header->type = MALI_C55_PARAM_BLOCK_SENSOR_OFFS;\n+\tblock.header->enabled = true;\n+\tblock.header->size = sizeof(mali_c55_params_sensor_off_preshading);\n+\n+\tblock.sensor_offs->chan00 = offset00;\n+\tblock.sensor_offs->chan01 = offset01;\n+\tblock.sensor_offs->chan10 = offset10;\n+\tblock.sensor_offs->chan11 = offset11;\n+\n+\tparams->total_size += block.header->size;\n+}\n+\n+void BlackLevelCorrection::process([[maybe_unused]] IPAContext &context,\n+\t\t\t\t   [[maybe_unused]] const uint32_t frame,\n+\t\t\t\t   [[maybe_unused]] IPAFrameContext &frameContext,\n+\t\t\t\t   [[maybe_unused]] const mali_c55_stats_buffer *stats,\n+\t\t\t\t   ControlList &metadata)\n+{\n+\t/*\n+\t * Black Level Offsets in tuning data need to be 20-bit, whereas the\n+\t * metadata expects values from a 16-bit range. Right-shift to remove\n+\t * the 4 least significant bits.\n+\t *\n+\t * The black levels should be reported in the order R, Gr, Gb, B. We\n+\t * ignore that here given we're using matching values so far, but it\n+\t * would be safer to check the sensor's bayer order.\n+\t *\n+\t * \\todo Account for bayer order.\n+\t */\n+\tmetadata.set(controls::SensorBlackLevels, {\n+\t\tstatic_cast<int32_t>(offset00 >> 4),\n+\t\tstatic_cast<int32_t>(offset01 >> 4),\n+\t\tstatic_cast<int32_t>(offset10 >> 4),\n+\t\tstatic_cast<int32_t>(offset11 >> 4),\n+\t});\n+}\n+\n+REGISTER_IPA_ALGORITHM(BlackLevelCorrection, \"BlackLevelCorrection\")\n+\n+} /* namespace ipa::mali_c55::algorithms */\n+\n+} /* namespace libcamera */\ndiff --git a/src/ipa/mali-c55/algorithms/blc.h b/src/ipa/mali-c55/algorithms/blc.h\nnew file mode 100644\nindex 00000000..e73056e0\n--- /dev/null\n+++ b/src/ipa/mali-c55/algorithms/blc.h\n@@ -0,0 +1,40 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2021-2022, Ideas On Board\n+ *\n+ * blc.h - Mali-C55 sensor offset (black level) correction\n+ */\n+\n+#include \"algorithm.h\"\n+\n+namespace libcamera {\n+\n+namespace ipa::mali_c55::algorithms {\n+\n+class BlackLevelCorrection : public Algorithm\n+{\n+public:\n+\tBlackLevelCorrection();\n+\t~BlackLevelCorrection() = default;\n+\n+\tint init(IPAContext &context, const YamlObject &tuningData) override;\n+\tvoid prepare(IPAContext &context, const uint32_t frame,\n+\t\t     IPAFrameContext &frameContext,\n+\t\t     mali_c55_params_buffer *params) override;\n+\tvoid process(IPAContext &context, const uint32_t frame,\n+\t\t     IPAFrameContext &frameContext,\n+\t\t     const mali_c55_stats_buffer *stats,\n+\t\t     ControlList &metadata) override;\n+\n+private:\n+\tstatic constexpr uint32_t kMaxOffset = 0xfffff;\n+\n+\tbool tuningParameters_;\n+\tuint32_t offset00;\n+\tuint32_t offset01;\n+\tuint32_t offset10;\n+\tuint32_t offset11;\n+};\n+\n+} /* namespace ipa::mali_c55::algorithms */\n+} /* namespace libcamera */\ndiff --git a/src/ipa/mali-c55/algorithms/meson.build b/src/ipa/mali-c55/algorithms/meson.build\nindex f2203b15..d84432b9 100644\n--- a/src/ipa/mali-c55/algorithms/meson.build\n+++ b/src/ipa/mali-c55/algorithms/meson.build\n@@ -1,4 +1,5 @@\n # SPDX-License-Identifier: CC0-1.0\n \n mali_c55_ipa_algorithms = files([\n+    'blc.cpp',\n ])\n",
    "prefixes": [
        "v2",
        "06/10"
    ]
}