Show a patch.

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

{
    "id": 24558,
    "url": "https://patchwork.libcamera.org/api/patches/24558/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/24558/",
    "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": "<20251003121821.659081-2-naush@raspberrypi.com>",
    "date": "2025-10-03T12:15:52",
    "name": "[v2,1/4] ipa: rpi: pisp: Add decompand support using PiSP hardware block",
    "commit_ref": "bfd09aa474c9e3fa35c04f0b2fd90874fa478646",
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "10653bce46cb2ea95c7f9064200b06202fbbff0b",
    "submitter": {
        "id": 34,
        "url": "https://patchwork.libcamera.org/api/people/34/?format=api",
        "name": "Naushir Patuck",
        "email": "naush@raspberrypi.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/24558/mbox/",
    "series": [
        {
            "id": 5477,
            "url": "https://patchwork.libcamera.org/api/series/5477/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=5477",
            "date": "2025-10-03T12:15:51",
            "name": "Raspberry Pi: Decompanding support",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/5477/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/24558/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/24558/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 5480AC324C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  3 Oct 2025 12:18:37 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 297666B5F3;\n\tFri,  3 Oct 2025 14:18:33 +0200 (CEST)",
            "from mail-wr1-x431.google.com (mail-wr1-x431.google.com\n\t[IPv6:2a00:1450:4864:20::431])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8322169318\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  3 Oct 2025 14:18:31 +0200 (CEST)",
            "by mail-wr1-x431.google.com with SMTP id\n\tffacd0b85a97d-3ee0fd0c5c4so198816f8f.3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 03 Oct 2025 05:18:31 -0700 (PDT)",
            "from NAUSH-P-DELL.pitowers.org ([93.93.133.154])\n\tby smtp.gmail.com with ESMTPSA id\n\tffacd0b85a97d-4255d8f02a8sm7812529f8f.39.2025.10.03.05.18.29\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tFri, 03 Oct 2025 05:18:30 -0700 (PDT)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=raspberrypi.com header.i=@raspberrypi.com\n\theader.b=\"BAbJ8hZz\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google; t=1759493911; x=1760098711;\n\tdarn=lists.libcamera.org; \n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=UbalvF77R6m7kRGcNwpXf4C99U24C/faJvy6AO/sdII=;\n\tb=BAbJ8hZzCnAkgLeNUgtnIuR3HF1angcdN0dnj0I1kcWPaXfevphwRWZD1P2LyaezZG\n\t6pnfMhbE51LxOm9rOuEytw37PKqzTXzSkf8AG5bx6c0r1UYBt/8ZDACXylAIDebCBCKB\n\thjaBNWwuOArKqG1SXWA+o7XKtUs94RzNLJbw785oMUW9GwwFbtzAvMspvlVyjsdvD/FI\n\tlVTuBSV5F7D99MtkJxJRKxy4sAtRElajj/vlRDoQ/N1thogC43mc8ef7AXv5klPUw9KI\n\tgsKG6+5e2spNwOaT47sYxqjMQsezV/xwLPLP2NY2bKXk3hZAOSXTI5kdnE2QoNFFPV1K\n\t7OSg==",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1759493911; x=1760098711;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc\n\t:subject:date:message-id:reply-to;\n\tbh=UbalvF77R6m7kRGcNwpXf4C99U24C/faJvy6AO/sdII=;\n\tb=RxFAvWvyzvz4aG7wfvNu93Bu26nadEjWo2mK1miAgAy1uQUR3eCI0EcVGkMJY4Ac0g\n\t4cZgPGqotMj1cHaidJgZeXtmjVv1wFtKLk21I3fqsztzmYoWDNQKdJvcGnHyZfApVSHp\n\tC3kYTHtXjG0M+HPG4BYwFik4lZ75zQ6yQPSK8YqoMMrJFPv9WIYNHGUSe3XDq5AoR3Nk\n\t54XKwFP8KtZG0Q7+WE8FT7US7CEmi8KZI4GpYpXN+pVvF14T4diESapFGwe3kAZqWKkR\n\tP0ne+bsAragGaqUvPlXhxCeAc6ZHm+quBoxYEuTTUi+486kcwj+5MK5yXd54q0IMy35h\n\trRJQ==",
        "X-Gm-Message-State": "AOJu0YyBGXLEg073jP/N/yFAz+82O7ZHJGeyC5za/Ikr4tB7Zo9mM/cg\n\tZ0q9due1gZ7H3MvPoY8m1YbOOsRCQYuhXZSgB5iyd8EzC2YlSwKJ3zI34DiyNZ5wriAeJ7OGXiP\n\tWgWxF",
        "X-Gm-Gg": "ASbGncvmGg2HhjWpfa9BT8FLwPdATvB+Svb8E7QANjDcdYkjK1leVxlhv4fzC/o+f3M\n\tMZDGLDj/1SjBudbeuN/OREdzANuaOu78In6c/Bo6PjOKgYOs0oq72ZTC/DcnGWTMZYUajFqmyoe\n\tqYzi/CQAoerg9FCgac3zfUPgzk261dJstkrIH/eWXbAP/PYLg7pCkFbCrqDCP6AJIBNyiiXLUov\n\tFkRXYpPyfUZ3bAOGSvTAR+NLNytHzn0Jyz/q3q9c4uCXhnT02+ZqyrSyR5kEOWCz4X5xdau19Sa\n\treCaTCZmkeAhCCQOq2N0q6nBnVpWncPn35vDnAdgxiOzyYcBNP8T0c4p+fET9ClIcE1xQ9FvBbe\n\t9hcGSXZYgC7nL56VavLuB1VZQ4LxFK24rgc3mbu+0RemSvkbNK7zdwpTy1dZp8HGl4N1VZA6+ok\n\tGm",
        "X-Google-Smtp-Source": "AGHT+IH2yG60LIZeoGDumTCkWBhQExH1DkuBbUGJMMhylzEyaHO+s+8XJCUN6IlUXmwKz7ldzfRJYg==",
        "X-Received": "by 2002:a05:6000:2282:b0:3f3:1be5:ecbf with SMTP id\n\tffacd0b85a97d-425671a06aemr903770f8f.7.1759493910694; \n\tFri, 03 Oct 2025 05:18:30 -0700 (PDT)",
        "From": "Naushir Patuck <naush@raspberrypi.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "David Plowman <david.plowman@raspberrypi.com>,\n\tNick Hollinghurst <nick.hollinghurst@raspberrypi.com>,\n\tSena Asotani <aso.fam429@gmail.com>,\n\tNaushir Patuck <naush@raspberrypi.com>",
        "Subject": "[PATCH v2 1/4] ipa: rpi: pisp: Add decompand support using PiSP\n\thardware block",
        "Date": "Fri,  3 Oct 2025 13:15:52 +0100",
        "Message-ID": "<20251003121821.659081-2-naush@raspberrypi.com>",
        "X-Mailer": "git-send-email 2.43.0",
        "In-Reply-To": "<20251003121821.659081-1-naush@raspberrypi.com>",
        "References": "<20251003121821.659081-1-naush@raspberrypi.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: Sena Asotani <aso.fam429@gmail.com>\n\nThis patch integrates a new decompand algorithm that utilizes the PiSP\nFE hardware block available on Raspberry Pi 5. The implementation\nenables conversion of companded sensor data into linear format prior to\nISP processing.\n\nChanges include:\n- Implementation of decompand logic for controller and pipe interfaces\n- Enabling decompand block by \"rpi.decompand\" in tuning.json\n\nSigned-off-by: Sena Asotani <aso.fam429@gmail.com>\nSigned-off-by: Naushir Patuck <naush@raspberrypi.com>\nTested-by: Nick Hollinghurst <nick.hollinghurst@raspberrypi.com>\n---\n src/ipa/rpi/controller/decompand_status.h |  8 ++++\n src/ipa/rpi/controller/meson.build        |  1 +\n src/ipa/rpi/controller/rpi/decompand.cpp  | 58 +++++++++++++++++++++++\n src/ipa/rpi/controller/rpi/decompand.h    | 31 ++++++++++++\n src/ipa/rpi/pisp/pisp.cpp                 | 38 +++++++++++++++\n 5 files changed, 136 insertions(+)\n create mode 100644 src/ipa/rpi/controller/decompand_status.h\n create mode 100644 src/ipa/rpi/controller/rpi/decompand.cpp\n create mode 100644 src/ipa/rpi/controller/rpi/decompand.h",
    "diff": "diff --git a/src/ipa/rpi/controller/decompand_status.h b/src/ipa/rpi/controller/decompand_status.h\nnew file mode 100644\nindex 000000000000..2d9888dca4f3\n--- /dev/null\n+++ b/src/ipa/rpi/controller/decompand_status.h\n@@ -0,0 +1,8 @@\n+#pragma once\n+\n+#include \"libipa/pwl.h\"\n+\n+struct DecompandStatus {\n+\tuint32_t bitdepth;\n+\tlibcamera::ipa::Pwl decompandCurve;\n+};\ndiff --git a/src/ipa/rpi/controller/meson.build b/src/ipa/rpi/controller/meson.build\nindex 74b74888bbff..c13c48539d10 100644\n--- a/src/ipa/rpi/controller/meson.build\n+++ b/src/ipa/rpi/controller/meson.build\n@@ -14,6 +14,7 @@ rpi_ipa_controller_sources = files([\n     'rpi/cac.cpp',\n     'rpi/ccm.cpp',\n     'rpi/contrast.cpp',\n+    'rpi/decompand.cpp',\n     'rpi/denoise.cpp',\n     'rpi/dpc.cpp',\n     'rpi/geq.cpp',\ndiff --git a/src/ipa/rpi/controller/rpi/decompand.cpp b/src/ipa/rpi/controller/rpi/decompand.cpp\nnew file mode 100644\nindex 000000000000..2036750f82f4\n--- /dev/null\n+++ b/src/ipa/rpi/controller/rpi/decompand.cpp\n@@ -0,0 +1,58 @@\n+#include \"decompand.h\"\n+\n+#include <libcamera/base/log.h>\n+\n+#include \"../decompand_status.h\"\n+#include \"../histogram.h\"\n+\n+using namespace RPiController;\n+using namespace libcamera;\n+\n+LOG_DEFINE_CATEGORY(RPiDecompand)\n+\n+#define NAME \"rpi.decompand\"\n+\n+Decompand::Decompand(Controller *controller)\n+\t: Algorithm(controller)\n+{\n+}\n+\n+char const *Decompand::name() const\n+{\n+\treturn NAME;\n+}\n+\n+int Decompand::read(const libcamera::YamlObject &params)\n+{\n+\tconfig_.bitdepth = params[\"bitdepth\"].get<uint32_t>(0);\n+\tconfig_.decompandCurve = params[\"decompand_curve\"].get<ipa::Pwl>(ipa::Pwl{});\n+\treturn config_.decompandCurve.empty() ? -EINVAL : 0;\n+}\n+\n+void Decompand::initialise()\n+{\n+}\n+\n+void Decompand::switchMode(CameraMode const &cameraMode,\n+\t\t\t   [[maybe_unused]] Metadata *metadata)\n+{\n+\tmode_ = cameraMode;\n+}\n+\n+void Decompand::prepare(Metadata *imageMetadata)\n+{\n+\tDecompandStatus decompandStatus;\n+\n+\tif (config_.bitdepth == 0 || mode_.bitdepth == config_.bitdepth) {\n+\t\tdecompandStatus.decompandCurve = config_.decompandCurve;\n+\t\timageMetadata->set(\"decompand.status\", decompandStatus);\n+\t}\n+}\n+\n+/* Register algorithm with the system. */\n+static Algorithm *create(Controller *controller)\n+{\n+\treturn new Decompand(controller);\n+}\n+\n+static RegisterAlgorithm reg(NAME, &create);\ndiff --git a/src/ipa/rpi/controller/rpi/decompand.h b/src/ipa/rpi/controller/rpi/decompand.h\nnew file mode 100644\nindex 000000000000..38b26a21e6d5\n--- /dev/null\n+++ b/src/ipa/rpi/controller/rpi/decompand.h\n@@ -0,0 +1,31 @@\n+#pragma once\n+\n+#include <libipa/pwl.h>\n+\n+#include \"../decompand_status.h\"\n+\n+#include \"algorithm.h\"\n+\n+namespace RPiController {\n+\n+struct DecompandConfig {\n+\tuint32_t bitdepth;\n+\tlibcamera::ipa::Pwl decompandCurve;\n+};\n+\n+class Decompand : public Algorithm\n+{\n+public:\n+\tDecompand(Controller *controller = nullptr);\n+\tchar const *name() const override;\n+\tint read(const libcamera::YamlObject &params) override;\n+\tvoid initialise() override;\n+\tvoid switchMode(CameraMode const &cameraMode, Metadata *metadata) override;\n+\tvoid prepare(Metadata *imageMetadata) override;\n+\n+private:\n+\tCameraMode mode_;\n+\tDecompandConfig config_;\n+};\n+\n+} /* namespace RPiController */\ndiff --git a/src/ipa/rpi/pisp/pisp.cpp b/src/ipa/rpi/pisp/pisp.cpp\nindex 829b91258522..14ece12b0895 100644\n--- a/src/ipa/rpi/pisp/pisp.cpp\n+++ b/src/ipa/rpi/pisp/pisp.cpp\n@@ -32,6 +32,7 @@\n #include \"controller/cac_status.h\"\n #include \"controller/ccm_status.h\"\n #include \"controller/contrast_status.h\"\n+#include \"controller/decompand_status.h\"\n #include \"controller/denoise_algorithm.h\"\n #include \"controller/denoise_status.h\"\n #include \"controller/dpc_status.h\"\n@@ -113,6 +114,25 @@ int generateLut(const ipa::Pwl &pwl, uint32_t *lut, std::size_t lutSize,\n \treturn 0;\n }\n \n+int generateDecompandLut(const ipa::Pwl &pwl, Span<uint16_t> lut)\n+{\n+\tif (pwl.empty())\n+\t\treturn -EINVAL;\n+\n+\tconstexpr int step = 1024;\n+\tfor (std::size_t i = 0; i < lut.size(); ++i) {\n+\t\tint x = i * step;\n+\n+\t\tint y = pwl.eval(x);\n+\t\tif (y < 0)\n+\t\t\treturn -1;\n+\n+\t\tlut[i] = static_cast<uint16_t>(std::min(y, 65535));\n+\t}\n+\n+\treturn 0;\n+}\n+\n void packLscLut(uint32_t packed[NumLscVertexes][NumLscVertexes],\n \t\tdouble const rgb[3][NumLscVertexes][NumLscVertexes])\n {\n@@ -236,6 +256,7 @@ private:\n \tvoid applyLensShading(const AlscStatus *alscStatus,\n \t\t\t      pisp_be_global_config &global);\n \tvoid applyDPC(const DpcStatus *dpcStatus, pisp_be_global_config &global);\n+\tvoid applyDecompand(const DecompandStatus *decompandStatus);\n \tvoid applySdn(const SdnStatus *sdnStatus, pisp_be_global_config &global);\n \tvoid applyTdn(const TdnStatus *tdnStatus, const DeviceStatus *deviceStatus,\n \t\t      pisp_be_global_config &global);\n@@ -351,6 +372,11 @@ void IpaPiSP::platformPrepareIsp([[maybe_unused]] const PrepareParams &params,\n \t\tif (noiseStatus)\n \t\t\tapplyFocusStats(noiseStatus);\n \n+\t\tDecompandStatus *decompandStatus =\n+\t\t\trpiMetadata.getLocked<DecompandStatus>(\"decompand.status\");\n+\t\tif (decompandStatus)\n+\t\t\tapplyDecompand(decompandStatus);\n+\n \t\tBlackLevelStatus *blackLevelStatus =\n \t\t\trpiMetadata.getLocked<BlackLevelStatus>(\"black_level.status\");\n \t\tif (blackLevelStatus)\n@@ -702,6 +728,18 @@ void IpaPiSP::applyDPC(const DpcStatus *dpcStatus, pisp_be_global_config &global\n \tbe_->SetDpc(dpc);\n }\n \n+void IpaPiSP::applyDecompand(const DecompandStatus *decompandStatus)\n+{\n+\tpisp_fe_global_config feGlobal;\n+\tpisp_fe_decompand_config decompand = {};\n+\n+\tif (!generateDecompandLut(decompandStatus->decompandCurve, decompand.lut)) {\n+\t\tfe_->SetDecompand(decompand);\n+\t\tfeGlobal.enables |= PISP_FE_ENABLE_DECOMPAND;\n+\t\tfe_->SetGlobal(feGlobal);\n+\t}\n+}\n+\n void IpaPiSP::applySdn(const SdnStatus *sdnStatus, pisp_be_global_config &global)\n {\n \tpisp_be_sdn_config sdn = {};\n",
    "prefixes": [
        "v2",
        "1/4"
    ]
}