Show a patch.

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

{
    "id": 20567,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/20567/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/20567/",
    "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": "<20240703225230.3530-6-laurent.pinchart@ideasonboard.com>",
    "date": "2024-07-03T22:52:24",
    "name": "[v1,05/11] ipa: rkisp1: Add ISP parameters abstraction class",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "13c7af9e3412d280e7aee1acd1cc884d0eaef1a1",
    "submitter": {
        "id": 2,
        "url": "https://patchwork.libcamera.org/api/1.1/people/2/?format=api",
        "name": "Laurent Pinchart",
        "email": "laurent.pinchart@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/20567/mbox/",
    "series": [
        {
            "id": 4442,
            "url": "https://patchwork.libcamera.org/api/1.1/series/4442/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4442",
            "date": "2024-07-03T22:52:19",
            "name": "rkisp1: Support BLS on i.MX8MP",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/4442/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/20567/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/20567/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 5133FBEFBE\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  3 Jul 2024 22:53:10 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 238FB63369;\n\tThu,  4 Jul 2024 00:53:09 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id DF4BC63334\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  4 Jul 2024 00:52:56 +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 71BB74CC;\n\tThu,  4 Jul 2024 00:52:28 +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=\"DkSANe+1\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1720047148;\n\tbh=Kc72srql5yGTU3CFi0fNHVCGnkuMUnsFRzPOPTsFE+o=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=DkSANe+1YJc02tcwPYpkicnm0lvIOhmXs83Pl4fUyUMQnVLE1hsxV3SEc59/B2OOv\n\tTFSjzKhRlexS52pdzJ7Xn0cCtVZ3apuhy93KuzmSyloP5ybxrnGiiNybRJAna7vNyT\n\tH4fq4kKeVn8RfMu/aM6qdrwwsfSM/pS6K8QXMP9Q=",
        "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "Jacopo Mondi <jacopo.mondi@ideasonboard.com>,\n\tPaul Elder <paul.elder@ideasonboard.com>",
        "Subject": "[PATCH v1 05/11] ipa: rkisp1: Add ISP parameters abstraction class",
        "Date": "Thu,  4 Jul 2024 01:52:24 +0300",
        "Message-ID": "<20240703225230.3530-6-laurent.pinchart@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.44.2",
        "In-Reply-To": "<20240703225230.3530-1-laurent.pinchart@ideasonboard.com>",
        "References": "<20240703225230.3530-1-laurent.pinchart@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": "Individual algorithms of the rkisp1 IPA module access their\ncorresponding ISP parameters through the top-level structure\nrkisp1_params_cfg. This will not work anymore with the new parameters\nformat. In order to ease the transition to the new format, abstract the\nISP parameters in a new RkISP1Params class that offers the same\ninterface regardless of the format.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/ipa/rkisp1/meson.build |   1 +\n src/ipa/rkisp1/params.cpp  | 169 +++++++++++++++++++++++++++++++++++++\n src/ipa/rkisp1/params.h    | 140 ++++++++++++++++++++++++++++++\n 3 files changed, 310 insertions(+)\n create mode 100644 src/ipa/rkisp1/params.cpp\n create mode 100644 src/ipa/rkisp1/params.h",
    "diff": "diff --git a/src/ipa/rkisp1/meson.build b/src/ipa/rkisp1/meson.build\nindex e8b266f1ccca..65eef5d69c32 100644\n--- a/src/ipa/rkisp1/meson.build\n+++ b/src/ipa/rkisp1/meson.build\n@@ -7,6 +7,7 @@ ipa_name = 'ipa_rkisp1'\n \n rkisp1_ipa_sources = files([\n     'ipa_context.cpp',\n+    'params.cpp',\n     'rkisp1.cpp',\n     'utils.cpp',\n ])\ndiff --git a/src/ipa/rkisp1/params.cpp b/src/ipa/rkisp1/params.cpp\nnew file mode 100644\nindex 000000000000..ac25ade1c8c4\n--- /dev/null\n+++ b/src/ipa/rkisp1/params.cpp\n@@ -0,0 +1,169 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2024, Ideas On Board\n+ *\n+ * RkISP1 ISP Parameters\n+ */\n+\n+#include \"params.h\"\n+\n+#include <map>\n+#include <stddef.h>\n+#include <string.h>\n+\n+#include <linux/rkisp1-config.h>\n+#include <linux/videodev2.h>\n+\n+namespace libcamera {\n+\n+namespace ipa::rkisp1 {\n+\n+namespace {\n+\n+struct BlockTypeInfo {\n+\tenum rkisp1_ext_params_block_type type;\n+\tsize_t size;\n+\tsize_t offset;\n+\t__u32 enableBit;\n+};\n+\n+#define RKISP1_BLOCK_TYPE_ENTRY(block, id, type, category, bit)\t\t\t\\\n+\t{ Block::block, {\t\t\t\t\t\t\t\\\n+\t\tRKISP1_EXT_PARAMS_BLOCK_TYPE_##id,\t\t\t\t\\\n+\t\tsizeof(struct rkisp1_cif_isp_##type##_config),\t\t\t\\\n+\t\toffsetof(struct rkisp1_params_cfg, category.type##_config),\t\\\n+\t\tRKISP1_CIF_ISP_MODULE_##bit,\t\t\t\t\t\\\n+\t} }\n+\n+#define RKISP1_BLOCK_TYPE_ENTRY_MEAS(block, id, type)\t\t\t\t\\\n+\tRKISP1_BLOCK_TYPE_ENTRY(block, id##_MEAS, type, meas, id)\n+\n+#define RKISP1_BLOCK_TYPE_ENTRY_OTHERS(block, id, type)\t\t\t\t\\\n+\tRKISP1_BLOCK_TYPE_ENTRY(block, id, type, others, id)\n+\n+#define RKISP1_BLOCK_TYPE_ENTRY_EXT(block, id, type)\t\t\t\t\\\n+\t{ Block::block, {\t\t\t\t\t\t\t\\\n+\t\tRKISP1_EXT_PARAMS_BLOCK_TYPE_##id,\t\t\t\t\\\n+\t\tsizeof(struct rkisp1_cif_isp_##type##_config),\t\t\t\\\n+\t\t0, 0,\t\t\t\t\t\t\t\t\\\n+\t} }\n+\n+const std::map<Block, BlockTypeInfo> kBlockTypeInfo = {\n+\tRKISP1_BLOCK_TYPE_ENTRY_OTHERS(Bls, BLS, bls),\n+\tRKISP1_BLOCK_TYPE_ENTRY_OTHERS(Dpcc, DPCC, dpcc),\n+\tRKISP1_BLOCK_TYPE_ENTRY_OTHERS(Sdg, SDG, sdg),\n+\tRKISP1_BLOCK_TYPE_ENTRY_OTHERS(AwbGain, AWB_GAIN, awb_gain),\n+\tRKISP1_BLOCK_TYPE_ENTRY_OTHERS(Flt, FLT, flt),\n+\tRKISP1_BLOCK_TYPE_ENTRY_OTHERS(Bdm, BDM, bdm),\n+\tRKISP1_BLOCK_TYPE_ENTRY_OTHERS(Ctk, CTK, ctk),\n+\tRKISP1_BLOCK_TYPE_ENTRY_OTHERS(Goc, GOC, goc),\n+\tRKISP1_BLOCK_TYPE_ENTRY_OTHERS(Dpf, DPF, dpf),\n+\tRKISP1_BLOCK_TYPE_ENTRY_OTHERS(DpfStrength, DPF_STRENGTH, dpf_strength),\n+\tRKISP1_BLOCK_TYPE_ENTRY_OTHERS(Cproc, CPROC, cproc),\n+\tRKISP1_BLOCK_TYPE_ENTRY_OTHERS(Ie, IE, ie),\n+\tRKISP1_BLOCK_TYPE_ENTRY_OTHERS(Lsc, LSC, lsc),\n+\tRKISP1_BLOCK_TYPE_ENTRY_MEAS(Awb, AWB, awb_meas),\n+\tRKISP1_BLOCK_TYPE_ENTRY_MEAS(Hst, HST, hst),\n+\tRKISP1_BLOCK_TYPE_ENTRY_MEAS(Aec, AEC, aec),\n+\tRKISP1_BLOCK_TYPE_ENTRY_MEAS(Afc, AFC, afc),\n+};\n+\n+} /* namespace */\n+\n+RkISP1Params::RkISP1Params(uint32_t format, Span<uint8_t> data)\n+\t: format_(format), data_(data), used_(0)\n+{\n+\tif (format_ == V4L2_META_FMT_RK_ISP1_EXT_PARAMS) {\n+\t\tstruct rkisp1_ext_params_cfg *cfg =\n+\t\t\treinterpret_cast<struct rkisp1_ext_params_cfg *>(data.data());\n+\n+\t\tcfg->version = RKISP1_EXT_PARAM_BUFFER_V1;\n+\t\tcfg->data_size = 0;\n+\n+\t\tused_ += offsetof(struct rkisp1_ext_params_cfg, data);\n+\t} else {\n+\t\tmemset(data.data(), 0, data.size());\n+\t\tused_ = sizeof(struct rkisp1_params_cfg);\n+\t}\n+}\n+\n+Span<uint8_t> RkISP1Params::block(Block type, State state)\n+{\n+\tauto infoIt = kBlockTypeInfo.find(type);\n+\tif (infoIt == kBlockTypeInfo.end())\n+\t\treturn {};\n+\n+\tconst BlockTypeInfo &info = infoIt->second;\n+\n+\t/*\n+\t * For the legacy format, return a block referencing the fixed location\n+\t * of the data.\n+\t */\n+\tif (format_ == V4L2_META_FMT_RK_ISP1_PARAMS) {\n+\t\t/*\n+\t\t * Blocks available in extended parameters only have an offset\n+\t\t * of 0. Return nullptr in that case.\n+\t\t */\n+\t\tif (info.offset == 0)\n+\t\t\treturn {};\n+\n+\t\tstruct rkisp1_params_cfg *cfg =\n+\t\t\treinterpret_cast<struct rkisp1_params_cfg *>(data_.data());\n+\n+\t\tcfg->module_cfg_update = info.enableBit;\n+\t\tcfg->module_en_update = info.enableBit;\n+\t\tcfg->module_ens = state == State::Enable ? info.enableBit : 0;\n+\n+\t\treturn data_.subspan(info.offset, info.size);\n+\t}\n+\n+\t/*\n+\t * For the extensible format, allocate memory for the block, including\n+\t * the header.\n+\t */\n+\n+\t/* Look up the block in the cache first. Caching helps providing the\n+\t * same behaviour for the legacy and extensible formats when block() is\n+\t * called multiple times for the same block, which simplifies the\n+\t * implementation of algorithms and avoids hard to debug issues.\n+\t */\n+\tauto cacheIt = blocks_.find(type);\n+\tif (cacheIt != blocks_.end())\n+\t\treturn cacheIt->second;\n+\n+\t/* Make sure we don't run out of space. */\n+\tsize_t size = sizeof(struct rkisp1_ext_params_block_header)\n+\t\t    + ((info.size + 7) & ~7);\n+\tif (size > data_.size() - used_)\n+\t\treturn {};\n+\n+\t/* Allocate a new block, clear its memory, and initialize its header. */\n+\tSpan<uint8_t> block = data_.subspan(used_, size);\n+\tused_ += size;\n+\n+\tstruct rkisp1_ext_params_cfg *cfg =\n+\t\treinterpret_cast<struct rkisp1_ext_params_cfg *>(data_.data());\n+\tcfg->data_size += size;\n+\n+\tmemset(block.data(), 0, block.size());\n+\n+\tstruct rkisp1_ext_params_block_header *header =\n+\t\treinterpret_cast<struct rkisp1_ext_params_block_header *>(block.data());\n+\theader->type = info.type;\n+\theader->enable = state == State::Enable\n+\t\t       ? RKISP1_EXT_PARAMS_BLOCK_ENABLE\n+\t\t       : RKISP1_EXT_PARAMS_BLOCK_DISABLE;\n+\theader->size = block.size();\n+\n+\t/* Skip the block header to get the data. */\n+\tblock = block.subspan(sizeof(*header));\n+\n+\t/* Update the cache. */\n+\tblocks_[type] = block;\n+\n+\treturn block;\n+}\n+\n+} /* namespace ipa::rkisp1 */\n+\n+} /* namespace libcamera */\ndiff --git a/src/ipa/rkisp1/params.h b/src/ipa/rkisp1/params.h\nnew file mode 100644\nindex 000000000000..ddd081de7894\n--- /dev/null\n+++ b/src/ipa/rkisp1/params.h\n@@ -0,0 +1,140 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2024, Ideas On Board\n+ *\n+ * RkISP1 ISP Parameters\n+ */\n+\n+#pragma once\n+\n+#include <map>\n+#include <optional>\n+#include <stdint.h>\n+\n+#include <linux/rkisp1-config.h>\n+\n+#include <libcamera/base/span.h>\n+\n+namespace libcamera {\n+\n+namespace ipa::rkisp1 {\n+\n+enum class Block {\n+\tBls,\n+\tDpcc,\n+\tSdg,\n+\tAwbGain,\n+\tFlt,\n+\tBdm,\n+\tCtk,\n+\tGoc,\n+\tDpf,\n+\tDpfStrength,\n+\tCproc,\n+\tIe,\n+\tLsc,\n+\tAwb,\n+\tHst,\n+\tAec,\n+\tAfc,\n+};\n+\n+namespace details {\n+\n+template<Block B>\n+struct block_type {\n+};\n+\n+#define RKISP1_DEFINE_BLOCK_TYPE(blockType, blockStruct)\t\t\\\n+template<>\t\t\t\t\t\t\t\t\\\n+struct block_type<Block::blockType> {\t\t\t\t\t\\\n+\tusing type = struct rkisp1_cif_isp_##blockStruct##_config;\t\\\n+};\n+\n+RKISP1_DEFINE_BLOCK_TYPE(Bls, bls)\n+RKISP1_DEFINE_BLOCK_TYPE(Dpcc, dpcc)\n+RKISP1_DEFINE_BLOCK_TYPE(Sdg, sdg)\n+RKISP1_DEFINE_BLOCK_TYPE(AwbGain, awb_gain)\n+RKISP1_DEFINE_BLOCK_TYPE(Flt, flt)\n+RKISP1_DEFINE_BLOCK_TYPE(Bdm, bdm)\n+RKISP1_DEFINE_BLOCK_TYPE(Ctk, ctk)\n+RKISP1_DEFINE_BLOCK_TYPE(Goc, goc)\n+RKISP1_DEFINE_BLOCK_TYPE(Dpf, dpf)\n+RKISP1_DEFINE_BLOCK_TYPE(DpfStrength, dpf_strength)\n+RKISP1_DEFINE_BLOCK_TYPE(Cproc, cproc)\n+RKISP1_DEFINE_BLOCK_TYPE(Ie, ie)\n+RKISP1_DEFINE_BLOCK_TYPE(Lsc, lsc)\n+RKISP1_DEFINE_BLOCK_TYPE(Awb, awb_meas)\n+RKISP1_DEFINE_BLOCK_TYPE(Hst, hst)\n+RKISP1_DEFINE_BLOCK_TYPE(Aec, aec)\n+RKISP1_DEFINE_BLOCK_TYPE(Afc, afc)\n+\n+} /* namespace details */\n+\n+template<Block B>\n+class RkISP1ParamsBlock\n+{\n+public:\n+\tusing Type = typename details::block_type<B>::type;\n+\n+\tRkISP1ParamsBlock(const Span<uint8_t> &data)\n+\t\t: data_(data)\n+\t{\n+\t}\n+\n+\tconst Type *operator->() const\n+\t{\n+\t\treturn reinterpret_cast<const Type *>(data_.data());\n+\t}\n+\n+\tType *operator->()\n+\t{\n+\t\treturn reinterpret_cast<Type *>(data_.data());\n+\t}\n+\n+\tconst Type &operator*() const &\n+\t{\n+\t\treturn *reinterpret_cast<const Type *>(data_.data());\n+\t}\n+\n+\tType &operator*() &\n+\t{\n+\t\treturn *reinterpret_cast<Type *>(data_.data());\n+\t}\n+\n+private:\n+\tSpan<uint8_t> data_;\n+};\n+\n+class RkISP1Params\n+{\n+public:\n+\tenum class State {\n+\t\tDisable = 1,\n+\t\tEnable = 1,\n+\t};\n+\n+\tRkISP1Params(uint32_t format, Span<uint8_t> data);\n+\n+\ttemplate<Block B>\n+\tRkISP1ParamsBlock<B> block(State state)\n+\t{\n+\t\treturn RkISP1ParamsBlock<B>(block(B, state));\n+\t}\n+\n+\tsize_t size() const { return used_; }\n+\n+private:\n+\tSpan<uint8_t> block(Block type, State state);\n+\n+\tuint32_t format_;\n+\n+\tSpan<uint8_t> data_;\n+\tsize_t used_;\n+\n+\tstd::map<Block, Span<uint8_t>> blocks_;\n+};\n+\n+} /* namespace ipa::rkisp1 */\n+\n+} /* namespace libcamera*/\n",
    "prefixes": [
        "v1",
        "05/11"
    ]
}