Show a patch.

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

{
    "id": 24540,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/24540/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/24540/",
    "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": "<20251001091143.2051905-1-naush@raspberrypi.com>",
    "date": "2025-10-01T09:11:23",
    "name": "ipa: rpi: pisp: Add decompand support using PiSP hardware block",
    "commit_ref": null,
    "pull_url": null,
    "state": "rejected",
    "archived": false,
    "hash": "f9ab938c25cb65a0efd827195280fe97669add23",
    "submitter": {
        "id": 34,
        "url": "https://patchwork.libcamera.org/api/1.1/people/34/?format=api",
        "name": "Naushir Patuck",
        "email": "naush@raspberrypi.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/24540/mbox/",
    "series": [
        {
            "id": 5471,
            "url": "https://patchwork.libcamera.org/api/1.1/series/5471/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=5471",
            "date": "2025-10-01T09:11:23",
            "name": "ipa: rpi: pisp: Add decompand support using PiSP hardware block",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/5471/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/24540/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/24540/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 566D7C324C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  1 Oct 2025 09:11:51 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E11446B5F0;\n\tWed,  1 Oct 2025 11:11:49 +0200 (CEST)",
            "from mail-wr1-x436.google.com (mail-wr1-x436.google.com\n\t[IPv6:2a00:1450:4864:20::436])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 7332169318\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  1 Oct 2025 11:11:48 +0200 (CEST)",
            "by mail-wr1-x436.google.com with SMTP id\n\tffacd0b85a97d-3fd2dee5c00so189513f8f.0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 01 Oct 2025 02:11:48 -0700 (PDT)",
            "from NAUSH-P-DELL.pitowers.org ([93.93.133.154])\n\tby smtp.gmail.com with ESMTPSA id\n\tffacd0b85a97d-40fb9c32734sm26743332f8f.25.2025.10.01.02.11.46\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tWed, 01 Oct 2025 02:11:47 -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=\"kA5nijiF\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google; t=1759309907; x=1759914707;\n\tdarn=lists.libcamera.org; \n\th=content-transfer-encoding:mime-version:message-id:date:subject:cc\n\t:to:from:from:to:cc:subject:date:message-id:reply-to;\n\tbh=IVoMSQ9NqKSYjvVxbeL+oHW0AnGWWAyEI8GVF0//jK4=;\n\tb=kA5nijiF89taASF02V5UwNdv4SpvyJTp8mDP5eAAr4axIWOUurMBQ1ish09PKfG+MU\n\tKf9SU/0S1Le+A5R5i/PHxmLjIWX/3d6tSgvb0h+dV3bf6KWpVBvvcw+eDB34YVDJrJfV\n\tZr7UTv8uOs+X4Pp1ayCeKHEt2n0HyqpQOajb/nF09JOPKE4Ku70TJNfHjj9Npd+S+SFU\n\tOge8Y5Vb915Z9FqhCIB5hQPnLg4iytGmvX3jtV8VQMsVb2oUzFAZynU4kfaPlQdyrtD2\n\tbqkCkhVzgNUuaspwHIDmqj7zINUvn0fHYi+rxnebLoueqmm7dmk3QWYuNnhrlDFjzRZH\n\tfKkQ==",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1759309907; x=1759914707;\n\th=content-transfer-encoding:mime-version:message-id:date:subject:cc\n\t:to:from:x-gm-message-state:from:to:cc:subject:date:message-id\n\t:reply-to;\n\tbh=IVoMSQ9NqKSYjvVxbeL+oHW0AnGWWAyEI8GVF0//jK4=;\n\tb=VzwZRLSoXKObAVb1zZAP3E49lYQn74QaAx5dWZCWhUFnDpIk/ZTB304dn9RhQG2aHU\n\tgwS7LKfZDqyuLxk5bMtidGdYfgytvFzGoAMsPseggJF2B5dtB6Lb2yWZv89nV8EwquMq\n\t9HPQl85Xl0FsvXWw5YPV+Hc4LGpQtiAUPL8YbNpkY8CuAmbJCW2XSw0tlxqqH3+Ii8QC\n\tKBP1p//QRma7ck9RAy2bLdAsYeG3W4z8ns7TK9q/iZWLpZl5zjZntg0vTcABQ7r/G1/A\n\t4lQbrJAfAjgryJ5xDeGKDceV6iC+9sHUeLEJgPM5sKqIn+Tn5K1w1n/owK964mIhGlpX\n\t9C+Q==",
        "X-Gm-Message-State": "AOJu0YxXa03UFBJi9+xSMdX8Fl1OtX0RL7wHfYw625/NrDqbzZ9XNUyr\n\tB9V1eynStrbvux5ppdyfEZoXdiTjEZwtEwceCsUIGTzgSZMzN5hwELsaJV6Oo4QnexT18yUkVx9\n\tOzhL2",
        "X-Gm-Gg": "ASbGnctyYrqQOUcr/q/aAYuGlwntBxXM838HIVBiE8Me2asFQQvdWSBhu125ORts1WZ\n\tVblAKaQrDoF/tCt8gull2tNLTbCk16gDepStU92ZBh3xyanGstck2lAOy5WAwRoh04rte2uvC5L\n\tO/MJnxEua8EkYp6waCOlYi5aUeIXNmhTALg4EHKipU3jzxMbCpO6UahEuKEpPduvINcaaNJIBX4\n\tmozr6GjV/HPppeKm/Ed94+LHzTyF60BYoEjYsON/YnD5XIWvppnZ0IoC0PGQ3bQp2WmT25GpGOk\n\tTmQwyTTKJrlnK5C50xis52h4f4wR7i4wG0MsHn2Kd4L+GHPmz/hsC+C3tVAYLfruOfeWLUbJ2FP\n\tl9dn/+SIjm8gbLK590KI3kG6GHjfiJ8fDArIWUD5UAT+nz8FmsD4nquTw8yNcdBAUEQ==",
        "X-Google-Smtp-Source": "AGHT+IFUVjg8zXjzWUXL4mXvBFmklEZOK1EUB13ipgaywuZPC9Rk/RxrpY56qX7R6GphuTp7UwQBCQ==",
        "X-Received": "by 2002:a05:6000:1a8e:b0:3f3:1695:7c49 with SMTP id\n\tffacd0b85a97d-4255780bfa4mr1121731f8f.7.1759309907477; \n\tWed, 01 Oct 2025 02:11:47 -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] ipa: rpi: pisp: Add decompand support using PiSP hardware\n\tblock",
        "Date": "Wed,  1 Oct 2025 10:11:23 +0100",
        "Message-ID": "<20251001091143.2051905-1-naush@raspberrypi.com>",
        "X-Mailer": "git-send-email 2.43.0",
        "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>\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                 | 40 ++++++++++++++++\n 5 files changed, 138 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..911b04bc0da0\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([[maybe_unused]] 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 (Algorithm *)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..5ef35946efa5\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 = NULL);\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..e75c87df1924 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, uint16_t *lut, std::size_t lutSize = 65)\n+{\n+\tif (pwl.empty())\n+\t\treturn -EINVAL;\n+\n+\tconstexpr int step = 1024;\n+\tfor (std::size_t i = 0; i < lutSize; ++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,20 @@ 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+\tfe_->GetGlobal(feGlobal);\n+\n+\tif (!generateDecompandLut(decompandStatus->decompandCurve, decompand.lut, PISP_FE_DECOMPAND_LUT_SIZE)) {\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": []
}