Show a patch.

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

{
    "id": 24111,
    "url": "https://patchwork.libcamera.org/api/patches/24111/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/24111/",
    "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": "<20250815102945.1602071-2-stefan.klug@ideasonboard.com>",
    "date": "2025-08-15T10:29:21",
    "name": "[v3,01/19] ipa: rkisp1: Add basic compression algorithm",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "c9aba4ec0b63a1ec50a40a2d13b4378e40de275f",
    "submitter": {
        "id": 184,
        "url": "https://patchwork.libcamera.org/api/people/184/?format=api",
        "name": "Stefan Klug",
        "email": "stefan.klug@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/24111/mbox/",
    "series": [
        {
            "id": 5382,
            "url": "https://patchwork.libcamera.org/api/series/5382/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=5382",
            "date": "2025-08-15T10:29:20",
            "name": "Implement WDR algorithm",
            "version": 3,
            "mbox": "https://patchwork.libcamera.org/series/5382/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/24111/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/24111/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 C3C2BBDCC1\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 15 Aug 2025 10:29:59 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 811A96925B;\n\tFri, 15 Aug 2025 12:29:59 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8CE4F69251\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 15 Aug 2025 12:29:55 +0200 (CEST)",
            "from ideasonboard.com (unknown\n\t[IPv6:2a00:6020:448c:6c00:83d1:ae5d:93a6:6837])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 982D456D;\n\tFri, 15 Aug 2025 12:29:00 +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=\"Ju5Y0qTO\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1755253740;\n\tbh=lsk9w3MyOz2hILQGYUq2kn6sPEIubE9VLB6jGgkvR/c=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=Ju5Y0qTO6R/x36iNfOo2fz0wdni/qr3A10ZqEvl4X6YWrD5ZOU5IhSTu8nD3Z+lvR\n\tlPw15g+gNe6cr93UD3Kp1HNAMMoWnyrEUHokkfzoMtQR+4IycDSx0xfMyBcuZzOphV\n\t8dma8ozI0tt/jmamN1SKzcdWMYNydV4EIn9a2cHE=",
        "From": "Stefan Klug <stefan.klug@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "Stefan Klug <stefan.klug@ideasonboard.com>",
        "Subject": "[PATCH v3 01/19] ipa: rkisp1: Add basic compression algorithm",
        "Date": "Fri, 15 Aug 2025 12:29:21 +0200",
        "Message-ID": "<20250815102945.1602071-2-stefan.klug@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.48.1",
        "In-Reply-To": "<20250815102945.1602071-1-stefan.klug@ideasonboard.com>",
        "References": "<20250815102945.1602071-1-stefan.klug@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": "The i.MX8 M Plus has a compression curve inside the compand block.  This\ncurve is necessary to process HDR stitched data and is useful for other\naspects like applying a digital gain to the incoming sensor data.\n\nAdd a basic algorithm for the compression curve. This algorithm has a\nhardcoded input width of 20bit and output width of 12bit which matches\nthe imx8mp pipeline. Only a static gain is supported in this version.\n\nSigned-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n\n---\n\nChanges in v3:\n- Removed unused member\n- Fixed comment referencing copy-paste source\n- Ensure activeState.compress.supported stays false if unsupported\n---\n src/ipa/rkisp1/algorithms/compress.cpp | 102 +++++++++++++++++++++++++\n src/ipa/rkisp1/algorithms/compress.h   |  30 ++++++++\n src/ipa/rkisp1/algorithms/meson.build  |   1 +\n src/ipa/rkisp1/ipa_context.h           |   9 +++\n 4 files changed, 142 insertions(+)\n create mode 100644 src/ipa/rkisp1/algorithms/compress.cpp\n create mode 100644 src/ipa/rkisp1/algorithms/compress.h",
    "diff": "diff --git a/src/ipa/rkisp1/algorithms/compress.cpp b/src/ipa/rkisp1/algorithms/compress.cpp\nnew file mode 100644\nindex 000000000000..e076727de4f1\n--- /dev/null\n+++ b/src/ipa/rkisp1/algorithms/compress.cpp\n@@ -0,0 +1,102 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2025, Ideas On Board\n+ *\n+ * RkISP1 Compression curve\n+ */\n+#include \"compress.h\"\n+\n+#include <linux/videodev2.h>\n+\n+#include <libcamera/base/log.h>\n+#include <libcamera/base/utils.h>\n+\n+#include \"libcamera/internal/yaml_parser.h\"\n+\n+#include \"linux/rkisp1-config.h\"\n+\n+/**\n+ * \\file compress.h\n+ */\n+\n+namespace libcamera {\n+\n+namespace ipa::rkisp1::algorithms {\n+\n+/**\n+ * \\class Compress\n+ * \\brief RkISP1 Compress curve\n+ *\n+ * This algorithm implements support for the compressions curve in the compand\n+ * block available in the i.MX8 M Plus\n+ *\n+ * In its current version it only supports a static gain. This is useful for\n+ * the agc algorithm to compensate for exposure/gain quantization effects.\n+ *\n+ * This algorithm doesn't have any configuration options. It needs to be\n+ * configured per frame by other algorithms.\n+ *\n+ * Other algorithms can check activeState.compress.supported to see if\n+ * compression is available. If it is available they can configure it per frame\n+ * using frameContext.compress.enable and frameContext.compress.gain.\n+ */\n+\n+LOG_DEFINE_CATEGORY(RkISP1Compress)\n+\n+constexpr static int kRkISP1CompressInBits = 20;\n+constexpr static int kRkISP1CompressOutBits = 12;\n+\n+/**\n+ * \\copydoc libcamera::ipa::Algorithm::configure\n+ */\n+int Compress::configure(IPAContext &context,\n+\t\t\t[[maybe_unused]] const IPACameraSensorInfo &configInfo)\n+{\n+\tif (context.configuration.paramFormat != V4L2_META_FMT_RK_ISP1_EXT_PARAMS ||\n+\t    !context.hw->compand) {\n+\t\tLOG(RkISP1Compress, Warning)\n+\t\t\t<< \"Compression is not supported by the hardware or kernel.\";\n+\t\treturn 0;\n+\t}\n+\n+\tcontext.activeState.compress.supported = true;\n+\treturn 0;\n+}\n+\n+/**\n+ * \\copydoc libcamera::ipa::Algorithm::prepare\n+ */\n+void Compress::prepare([[maybe_unused]] IPAContext &context,\n+\t\t       [[maybe_unused]] const uint32_t frame,\n+\t\t       IPAFrameContext &frameContext,\n+\t\t       RkISP1Params *params)\n+{\n+\tauto comp = params->block<BlockType::CompandCompress>();\n+\tcomp.setEnabled(frameContext.compress.enable);\n+\n+\tif (!frameContext.compress.enable)\n+\t\treturn;\n+\n+\tint xmax = (1 << kRkISP1CompressInBits);\n+\tint ymax = (1 << kRkISP1CompressOutBits);\n+\tint inLogStep = std::log2(xmax / 64);\n+\n+\tfor (unsigned int i = 0; i < RKISP1_CIF_ISP_COMPAND_NUM_POINTS; i++) {\n+\t\tdouble x = (i + 1) * (1.0 / RKISP1_CIF_ISP_COMPAND_NUM_POINTS);\n+\t\tdouble y = x * frameContext.compress.gain;\n+\n+\t\tcomp->px[i] = inLogStep;\n+\t\tcomp->x[i] = std::min<int>(x * xmax, xmax - 1);\n+\t\tcomp->y[i] = std::min<int>(y * ymax, ymax - 1);\n+\t}\n+\n+\tLOG(RkISP1Compress, Debug) << \"Compression: \" << kRkISP1CompressInBits\n+\t\t\t\t   << \" bits to \" << kRkISP1CompressOutBits\n+\t\t\t\t   << \" bits gain: \" << frameContext.compress.gain;\n+}\n+\n+REGISTER_IPA_ALGORITHM(Compress, \"Compress\")\n+\n+} /* namespace ipa::rkisp1::algorithms */\n+\n+} /* namespace libcamera */\ndiff --git a/src/ipa/rkisp1/algorithms/compress.h b/src/ipa/rkisp1/algorithms/compress.h\nnew file mode 100644\nindex 000000000000..87797b8ebcc5\n--- /dev/null\n+++ b/src/ipa/rkisp1/algorithms/compress.h\n@@ -0,0 +1,30 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2025, Ideas On Board\n+ *\n+ * RkISP1 Compression curve\n+ */\n+\n+#pragma once\n+\n+#include \"algorithm.h\"\n+\n+namespace libcamera {\n+\n+namespace ipa::rkisp1::algorithms {\n+\n+class Compress : public Algorithm\n+{\n+public:\n+\tCompress() = default;\n+\t~Compress() = default;\n+\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     RkISP1Params *params) override;\n+};\n+\n+} /* namespace ipa::rkisp1::algorithms */\n+} /* namespace libcamera */\ndiff --git a/src/ipa/rkisp1/algorithms/meson.build b/src/ipa/rkisp1/algorithms/meson.build\nindex c66b0b70b82f..2e42a80cf99d 100644\n--- a/src/ipa/rkisp1/algorithms/meson.build\n+++ b/src/ipa/rkisp1/algorithms/meson.build\n@@ -5,6 +5,7 @@ rkisp1_ipa_algorithms = files([\n     'awb.cpp',\n     'blc.cpp',\n     'ccm.cpp',\n+    'compress.cpp',\n     'cproc.cpp',\n     'dpcc.cpp',\n     'dpf.cpp',\ndiff --git a/src/ipa/rkisp1/ipa_context.h b/src/ipa/rkisp1/ipa_context.h\nindex 7ccc7b501aff..37a74215ce19 100644\n--- a/src/ipa/rkisp1/ipa_context.h\n+++ b/src/ipa/rkisp1/ipa_context.h\n@@ -106,6 +106,10 @@ struct IPAActiveState {\n \t\tMatrix<float, 3, 3> automatic;\n \t} ccm;\n \n+\tstruct {\n+\t\tbool supported;\n+\t} compress;\n+\n \tstruct {\n \t\tint8_t brightness;\n \t\tuint8_t contrast;\n@@ -158,6 +162,11 @@ struct IPAFrameContext : public FrameContext {\n \t\tbool update;\n \t} cproc;\n \n+\tstruct {\n+\t\tbool enable;\n+\t\tdouble gain;\n+\t} compress;\n+\n \tstruct {\n \t\tbool denoise;\n \t\tbool update;\n",
    "prefixes": [
        "v3",
        "01/19"
    ]
}