Show a patch.

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

{
    "id": 27171,
    "url": "https://patchwork.libcamera.org/api/patches/27171/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/27171/",
    "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": "<20260703122543.1991189-13-paul.elder@ideasonboard.com>",
    "date": "2026-07-03T12:25:18",
    "name": "[RFC,12/19] ipa: rkisp2: algo: csm: Implement color space conversion",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "af33bc7bd4b7c96413a7740c235a510bf893bf54",
    "submitter": {
        "id": 17,
        "url": "https://patchwork.libcamera.org/api/people/17/?format=api",
        "name": "Paul Elder",
        "email": "paul.elder@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/27171/mbox/",
    "series": [
        {
            "id": 6035,
            "url": "https://patchwork.libcamera.org/api/series/6035/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=6035",
            "date": "2026-07-03T12:25:06",
            "name": "Add support for rkisp2",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/6035/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/27171/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/27171/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 003DDC328C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  3 Jul 2026 12:26:44 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 9D7E865FE7;\n\tFri,  3 Jul 2026 14:26:44 +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 E876965FDF\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  3 Jul 2026 14:26:42 +0200 (CEST)",
            "from neptunite.hamster-moth.ts.net (unknown\n\t[IPv6:2404:7a81:160:2100:a2cc:2f45:3bd7:2589])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 112981121;\n\tFri,  3 Jul 2026 14:25:53 +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=\"TR/nWMVm\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1783081557;\n\tbh=DMsTFHJRsAKgRMApswYooOF/3mCrzmh/8E+8LHvAgdU=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=TR/nWMVmFkiwWDGb/pDy5cbvGII7dBMF0M/8UUCGx64762Nmw35drDGnRJSwnhg6n\n\tl2adT9SkCRAXsk9K3S0h8+tVINTvMw+APoszHPUl0qzCJj9kRGYtsSu8Se3MGTI1C/\n\tZ6g9zNCyUAGtK3UU0kvEB9FGw2dBDGuMieBMxmS8=",
        "From": "Paul Elder <paul.elder@ideasonboard.com>",
        "To": "laurent.pinchart@ideasonboard.com",
        "Cc": "Paul Elder <paul.elder@ideasonboard.com>, michael.riesch@collabora.com, \n\txuhf@rock-chips.com, stefan.klug@ideasonboard.com,\n\tkieran.bingham@ideasonboard.com, dan.scally@ideasonboard.com,\n\tjacopo.mondi@ideasonboard.com, nicolas.dufresne@collabora.com,\n\tlibcamera-devel@lists.libcamera.org",
        "Subject": "[RFC PATCH 12/19] ipa: rkisp2: algo: csm: Implement color space\n\tconversion",
        "Date": "Fri,  3 Jul 2026 21:25:18 +0900",
        "Message-ID": "<20260703122543.1991189-13-paul.elder@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.47.2",
        "In-Reply-To": "<20260703122543.1991189-1-paul.elder@ideasonboard.com>",
        "References": "<20260703122543.1991189-1-paul.elder@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": "Implement a static color space conversion algorithm for the rkisp2 IPA.\n\nSigned-off-by: Paul Elder <paul.elder@ideasonboard.com>\n---\n src/ipa/rkisp2/algorithms/csm.cpp     | 177 ++++++++++++++++++++++++++\n src/ipa/rkisp2/algorithms/csm.h       |  34 +++++\n src/ipa/rkisp2/algorithms/meson.build |   1 +\n 3 files changed, 212 insertions(+)\n create mode 100644 src/ipa/rkisp2/algorithms/csm.cpp\n create mode 100644 src/ipa/rkisp2/algorithms/csm.h",
    "diff": "diff --git a/src/ipa/rkisp2/algorithms/csm.cpp b/src/ipa/rkisp2/algorithms/csm.cpp\nnew file mode 100644\nindex 000000000000..1733c2938d23\n--- /dev/null\n+++ b/src/ipa/rkisp2/algorithms/csm.cpp\n@@ -0,0 +1,177 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2026, Ideas On Board\n+ *\n+ * RkISP2 Color space conversion\n+ */\n+\n+#include \"csm.h\"\n+\n+#include <array>\n+#include <cmath>\n+\n+#include <libcamera/base/log.h>\n+#include <libcamera/base/utils.h>\n+\n+#include <libcamera/color_space.h>\n+#include <libcamera/control_ids.h>\n+\n+#include \"linux/rkisp2-config.h\"\n+\n+/**\n+ * \\file csm.h\n+ */\n+\n+namespace libcamera {\n+\n+namespace ipa::rkisp2::algorithms {\n+\n+/**\n+ * \\class ColorSpaceConversion\n+ * \\brief RkISP2 Color space conversion\n+ *\n+ * This algorithm implements the color space conversion for the RkISP2.\n+ */\n+\n+LOG_DEFINE_CATEGORY(RkISP2Csm)\n+\n+namespace {\n+\tstruct CsmCoeffs {\n+\t\tuint16_t limited[9];\n+\t\tuint16_t full[9];\n+\t};\n+\n+\tstatic const struct CsmCoeffs rec601Coeffs = {\n+\t\t{\n+\t\t\t0x0021, 0x0042, 0x000d,\n+\t\t\t0x01ed, 0x01db, 0x0038,\n+\t\t\t0x0038, 0x01d1, 0x01f7,\n+\t\t},\n+\t\t{\n+\t\t\t0x0026, 0x004b, 0x000f,\n+\t\t\t0x01ea, 0x01d6, 0x0040,\n+\t\t\t0x0040, 0x01ca, 0x01f6,\n+\t\t},\n+\t};\n+\n+\tstatic const struct CsmCoeffs rec709Coeffs = {\n+\t\t{\n+\t\t\t0x0018, 0x0050, 0x0008,\n+\t\t\t0x01f3, 0x01d5, 0x0038,\n+\t\t\t0x0038, 0x01cd, 0x01fb,\n+\t\t},\n+\t\t{\n+\t\t\t0x001b, 0x005c, 0x0009,\n+\t\t\t0x01f1, 0x01cf, 0x0040,\n+\t\t\t0x0040, 0x01c6, 0x01fa,\n+\t\t},\n+\t};\n+\n+\tstatic const struct CsmCoeffs rec2020Coeffs = {\n+\t\t{\n+\t\t\t0x001d, 0x004c, 0x0007,\n+\t\t\t0x01f0, 0x01d8, 0x0038,\n+\t\t\t0x0038, 0x01cd, 0x01fb,\n+\t\t},\n+\t\t{\n+\t\t\t0x0022, 0x0057, 0x0008,\n+\t\t\t0x01ee, 0x01d2, 0x0040,\n+\t\t\t0x0040, 0x01c5, 0x01fb,\n+\t\t},\n+\t};\n+\n+\tstatic const struct CsmCoeffs smpte240mCoeffs = {\n+\t\t{\n+\t\t\t0x0018, 0x004f, 0x000a,\n+\t\t\t0x01f3, 0x01d5, 0x0038,\n+\t\t\t0x0038, 0x01ce, 0x01fa,\n+\t\t},\n+\t\t{\n+\t\t\t0x001b, 0x005a, 0x000b,\n+\t\t\t0x01f1, 0x01cf, 0x0040,\n+\t\t\t0x0040, 0x01c7, 0x01f9,\n+\t\t},\n+\t};\n+\n+\tuint16_t identityCsm[9] = {\n+\t\t1, 0, 0,\n+\t\t0, 1, 0,\n+\t\t0, 0, 1,\n+\t};\n+} /* namespace */\n+\n+/**\n+ * \\copydoc libcamera::ipa::Algorithm::init\n+ */\n+int ColorSpaceConversion::init([[maybe_unused]] IPAContext &context,\n+\t\t\t       [[maybe_unused]] const ValueNode &tuningData)\n+{\n+\treturn 0;\n+}\n+\n+/**\n+ * \\copydoc libcamera::ipa::Algorithm::configure\n+ */\n+int ColorSpaceConversion::configure(IPAContext &context,\n+\t\t\t\t    [[maybe_unused]] const IPACameraSensorInfo &configInfo)\n+{\n+\tconst CsmCoeffs *coeffs;\n+\tswitch (context.configuration.csm.colorSpaceEncoding) {\n+\tcase static_cast<int>(ColorSpace::YcbcrEncoding::Rec601):\n+\t\tcoeffs = &rec601Coeffs;\n+\t\tbreak;\n+\tcase static_cast<int>(ColorSpace::YcbcrEncoding::Rec709):\n+\t\tcoeffs = &rec709Coeffs;\n+\t\tbreak;\n+\tcase static_cast<int>(ColorSpace::YcbcrEncoding::Rec2020):\n+\t\tcoeffs = &rec2020Coeffs;\n+\t\tbreak;\n+\tdefault:\n+\t\tcoeffs = nullptr;\n+\t\tbreak;\n+\t}\n+\n+\tif (!coeffs) {\n+\t\tcontext.activeState.csm.csm = Matrix<uint16_t, 3, 3>(identityCsm);\n+\t\treturn 0;\n+\t}\n+\n+\tif (context.configuration.csm.colorSpaceRange == static_cast<int>(ColorSpace::Range::Limited))\n+\t\tcontext.activeState.csm.csm = Matrix<uint16_t, 3, 3>(coeffs->limited);\n+\telse\n+\t\tcontext.activeState.csm.csm = Matrix<uint16_t, 3, 3>(coeffs->full);\n+\tcontext.activeState.csm.update = true;\n+\n+\treturn 0;\n+}\n+\n+/**\n+ * \\copydoc libcamera::ipa::Algorithm::prepare\n+ */\n+void ColorSpaceConversion::prepare(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   RkISP2Params *params)\n+{\n+\tif (!context.activeState.csm.update)\n+\t\treturn;\n+\n+\tauto config = params->block<RkISP2Blocks::Csm>();\n+\tconfig.setEnabled(true);\n+\n+\t/*\n+\t * We'll use the active state directly as we don't support runtime\n+\t * configuration of the csm\n+\t */\n+\tfor (size_t i = 0; i < 3; i++)\n+\t\tfor (size_t j = 0; j < 3; j++)\n+\t\t\tconfig->coeff[i][j] = context.activeState.csm.csm[i][j];\n+\n+\tcontext.activeState.csm.update = false;\n+}\n+\n+REGISTER_IPA_ALGORITHM(ColorSpaceConversion, \"ColorSpaceConversion\")\n+\n+} /* namespace ipa::rkisp2::algorithms */\n+\n+} /* namespace libcamera */\ndiff --git a/src/ipa/rkisp2/algorithms/csm.h b/src/ipa/rkisp2/algorithms/csm.h\nnew file mode 100644\nindex 000000000000..d34e4d3959e8\n--- /dev/null\n+++ b/src/ipa/rkisp2/algorithms/csm.h\n@@ -0,0 +1,34 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2026, Ideas On Board\n+ *\n+ * RkISP2 Color space conversion\n+ */\n+\n+#pragma once\n+\n+#include \"libcamera/internal/matrix.h\"\n+\n+#include \"algorithm.h\"\n+\n+namespace libcamera {\n+\n+namespace ipa::rkisp2::algorithms {\n+\n+class ColorSpaceConversion : public Algorithm\n+{\n+public:\n+\tColorSpaceConversion() = default;\n+\t~ColorSpaceConversion() = default;\n+\n+\tint init(IPAContext &context, const ValueNode &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     RkISP2Params *params) override;\n+};\n+\n+} /* namespace ipa::rkisp2::algorithms */\n+\n+} /* namespace libcamera */\ndiff --git a/src/ipa/rkisp2/algorithms/meson.build b/src/ipa/rkisp2/algorithms/meson.build\nindex e7ae3d163bfb..01829e25d254 100644\n--- a/src/ipa/rkisp2/algorithms/meson.build\n+++ b/src/ipa/rkisp2/algorithms/meson.build\n@@ -5,5 +5,6 @@ rkisp2_ipa_algorithms = files([\n     'awb.cpp',\n     'bls.cpp',\n     'ccm.cpp',\n+    'csm.cpp',\n ])\n \n",
    "prefixes": [
        "RFC",
        "12/19"
    ]
}