Show a patch.

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

{
    "id": 22890,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/22890/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/22890/",
    "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": "<20250227105733.187611-8-keke.li@amlogic.com>",
    "date": "2025-02-27T10:57:29",
    "name": "[v3,07/11] ipa: c3-isp: Add BLC Algorithm",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "74c9dcb8b65453e553032d56f6f8a15696da854d",
    "submitter": {
        "id": 217,
        "url": "https://patchwork.libcamera.org/api/1.1/people/217/?format=api",
        "name": "Keke Li",
        "email": "keke.li@amlogic.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/22890/mbox/",
    "series": [
        {
            "id": 5027,
            "url": "https://patchwork.libcamera.org/api/1.1/series/5027/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=5027",
            "date": "2025-02-27T10:57:22",
            "name": "Add Amlogic C3 ISP pipeline handler and IPA",
            "version": 3,
            "mbox": "https://patchwork.libcamera.org/series/5027/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/22890/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/22890/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 E5AFBBF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 27 Feb 2025 10:58:59 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 80A5968767;\n\tThu, 27 Feb 2025 11:58:59 +0100 (CET)",
            "from mail-sh.amlogic.com (unknown [58.32.228.46])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 9009368751\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 27 Feb 2025 11:58:55 +0100 (CET)",
            "from droid10.amlogic.com (10.18.11.213) by mail-sh.amlogic.com\n\t(10.18.11.5) with Microsoft SMTP Server id 15.1.2507.39;\n\tThu, 27 Feb 2025 18:58:54 +0800"
        ],
        "From": "Keke Li <keke.li@amlogic.com>",
        "To": "<libcamera-devel@lists.libcamera.org>",
        "CC": "<kieran.bingham@ideasonboard.com>, <laurent.pinchart@ideasonboard.com>, \n\t<dan.scally@ideasonboard.com>, Keke Li <keke.li@amlogic.com>",
        "Subject": "[PATCH v3 07/11] ipa: c3-isp: Add BLC Algorithm",
        "Date": "Thu, 27 Feb 2025 18:57:29 +0800",
        "Message-ID": "<20250227105733.187611-8-keke.li@amlogic.com>",
        "X-Mailer": "git-send-email 2.29.0",
        "In-Reply-To": "<20250227105733.187611-1-keke.li@amlogic.com>",
        "References": "<20250227105733.187611-1-keke.li@amlogic.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Content-Type": "text/plain",
        "X-Originating-IP": "[10.18.11.213]",
        "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": "Add a new Black Level Correction algorithm.\n\nSigned-off-by: Keke Li <keke.li@amlogic.com>\n---\n src/ipa/c3-isp/algorithms/blc.cpp     | 151 ++++++++++++++++++++++++++\n src/ipa/c3-isp/algorithms/blc.h       |  45 ++++++++\n src/ipa/c3-isp/algorithms/meson.build |   1 +\n 3 files changed, 197 insertions(+)\n create mode 100644 src/ipa/c3-isp/algorithms/blc.cpp\n create mode 100644 src/ipa/c3-isp/algorithms/blc.h",
    "diff": "diff --git a/src/ipa/c3-isp/algorithms/blc.cpp b/src/ipa/c3-isp/algorithms/blc.cpp\nnew file mode 100644\nindex 00000000..4410d03f\n--- /dev/null\n+++ b/src/ipa/c3-isp/algorithms/blc.cpp\n@@ -0,0 +1,151 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2024, Amlogic\n+ *\n+ * C3ISP Black Level Correction control\n+ */\n+\n+#include \"blc.h\"\n+\n+#include <cmath>\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::c3isp::algorithms {\n+\n+/**\n+ * \\class Blc\n+ * \\brief C3 ISP Black Level Correction control\n+ *\n+ * The pixels output by the camera normally include a black level, because\n+ * sensors do not always report a signal level of '0' for black. Pixels at or\n+ * below this level should be considered black. To achieve that, the C3 ISP BLC\n+ * algorithm subtracts a configurable offset from all pixels.\n+ *\n+ * The black level can be measured at runtime from an optical dark region of the\n+ * camera sensor, or measured during the camera tuning process. The first option\n+ * isn't currently supported.\n+ */\n+\n+LOG_DEFINE_CATEGORY(C3ISPBlc)\n+\n+Blc::Blc()\n+\t: tuningBlc_(false)\n+{\n+}\n+\n+/**\n+ * \\copydoc libcamera::ipa::Algorithm::init\n+ */\n+int Blc::init([[maybe_unused]] IPAContext &context, const YamlObject &tuningData)\n+{\n+\toffsetR_ = tuningData[\"offsetR\"].get<uint32_t>(0);\n+\toffsetGr_ = tuningData[\"offsetGr\"].get<uint32_t>(0);\n+\toffsetGb_ = tuningData[\"offsetGb\"].get<uint32_t>(0);\n+\toffsetB_ = tuningData[\"offsetB\"].get<uint32_t>(0);\n+\n+\tif (!(offsetR_ + offsetGr_ + offsetGb_ + offsetB_)) {\n+\t\tLOG(C3ISPBlc, Debug) << \"All black level offsets are empty\";\n+\t\ttuningBlc_ = false;\n+\t} else {\n+\t\ttuningBlc_ = true;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+/**\n+ * \\copydoc libcamera::ipa::Algorithm::configure\n+ */\n+int Blc::configure(IPAContext &context,\n+\t\t   [[maybe_unused]] const IPACameraSensorInfo &configInfo)\n+{\n+\tuint16_t blackLevel = offsetCompress(context.configuration.sensor.blackLevel);\n+\n+\tif (blackLevel && !tuningBlc_) {\n+\t\toffsetR_ = context.configuration.sensor.blackLevel;\n+\t\toffsetGr_ = context.configuration.sensor.blackLevel;\n+\t\toffsetGb_ = context.configuration.sensor.blackLevel;\n+\t\toffsetB_ = context.configuration.sensor.blackLevel;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+uint16_t Blc::offsetCompress(uint32_t blackLevel)\n+{\n+\tuint8_t shift = 0;\n+\tuint32_t integer = 0;\n+\tuint8_t highestBitPos = static_cast<uint8_t>(log2(blackLevel));\n+\n+\t/* The compressed offset is stored in Q4.12 format */\n+\tif (highestBitPos < 12) {\n+\t\tshift = 0;\n+\t\tinteger = blackLevel;\n+\t} else {\n+\t\tshift = highestBitPos - 11;\n+\t\tinteger = blackLevel >> shift;\n+\t}\n+\n+\tshift = (shift > 0xf) ? 0xf : shift;\n+\n+\treturn (shift & 0xf) << 12 | (integer & 0xfff);\n+}\n+\n+/**\n+ * \\copydoc libcamera::ipa::Algorithm::prepare\n+ */\n+void Blc::prepare([[maybe_unused]] IPAContext &context, const uint32_t frame,\n+\t\t  [[maybe_unused]] IPAFrameContext &frameContext,\n+\t\t  C3ISPParams *params)\n+{\n+\tif (frame > 0)\n+\t\treturn;\n+\n+\tif (!tuningBlc_ && !context.configuration.sensor.blackLevel)\n+\t\treturn;\n+\n+\tauto blcCfg = params->block<BlockType::Blc>();\n+\tblcCfg.setEnabled(C3_ISP_PARAMS_BLOCK_FL_ENABLE);\n+\n+\tblcCfg->gr_ofst = offsetCompress(offsetGr_);\n+\tblcCfg->r_ofst = offsetCompress(offsetR_);\n+\tblcCfg->b_ofst = offsetCompress(offsetB_);\n+\tblcCfg->gb_ofst = offsetCompress(offsetGb_);\n+}\n+\n+/**\n+ * \\copydoc libcamera::ipa::Algorithm::process\n+ */\n+void Blc::process([[maybe_unused]] IPAContext &context,\n+\t\t  [[maybe_unused]] const uint32_t frame,\n+\t\t  [[maybe_unused]] IPAFrameContext &frameContext,\n+\t\t  [[maybe_unused]] const c3_isp_stats_info *stats,\n+\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+\tmetadata.set(controls::SensorBlackLevels,\n+\t\t     { static_cast<int32_t>(offsetR_ >> 4),\n+\t\t       static_cast<int32_t>(offsetGr_ >> 4),\n+\t\t       static_cast<int32_t>(offsetGb_ >> 4),\n+\t\t       static_cast<int32_t>(offsetB_ >> 4) });\n+}\n+\n+REGISTER_IPA_ALGORITHM(Blc, \"Blc\")\n+\n+} /* namespace ipa::c3isp::algorithms */\n+\n+} /* namespace libcamera */\ndiff --git a/src/ipa/c3-isp/algorithms/blc.h b/src/ipa/c3-isp/algorithms/blc.h\nnew file mode 100644\nindex 00000000..67244e4a\n--- /dev/null\n+++ b/src/ipa/c3-isp/algorithms/blc.h\n@@ -0,0 +1,45 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2024, Amlogic\n+ *\n+ * C3ISP Black Level Correction control\n+ */\n+\n+#pragma once\n+\n+#include \"algorithm.h\"\n+\n+namespace libcamera {\n+\n+namespace ipa::c3isp::algorithms {\n+\n+class Blc : public Algorithm\n+{\n+public:\n+\tBlc();\n+\t~Blc() = default;\n+\n+\tint init(IPAContext &context, const YamlObject &tuningData) override;\n+\tint configure(IPAContext &context,\n+\t\t      const IPACameraSensorInfo &configInfo) override;\n+\tvoid prepare(IPAContext &context, const uint32_t frame,\n+\t\t     IPAFrameContext &frameContext,\n+\t\t     C3ISPParams *params) override;\n+\tvoid process(IPAContext &context, const uint32_t frame,\n+\t\t     IPAFrameContext &frameContext,\n+\t\t     const c3_isp_stats_info *stats,\n+\t\t     ControlList &metadata) override;\n+\n+private:\n+\tuint16_t offsetCompress(uint32_t blackLevel);\n+\n+\tbool tuningBlc_;\n+\tuint32_t offsetR_;\n+\tuint32_t offsetGr_;\n+\tuint32_t offsetGb_;\n+\tuint32_t offsetB_;\n+};\n+\n+} /* namespace ipa::c3isp::algorithms */\n+\n+} /* namespace libcamera */\ndiff --git a/src/ipa/c3-isp/algorithms/meson.build b/src/ipa/c3-isp/algorithms/meson.build\nindex 9460da99..d91973e3 100644\n--- a/src/ipa/c3-isp/algorithms/meson.build\n+++ b/src/ipa/c3-isp/algorithms/meson.build\n@@ -3,4 +3,5 @@\n c3isp_ipa_algorithms = files([\n     'agc.cpp',\n     'awb.cpp',\n+    'blc.cpp',\n ])\n",
    "prefixes": [
        "v3",
        "07/11"
    ]
}