Show a patch.

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

{
    "id": 27022,
    "url": "https://patchwork.libcamera.org/api/patches/27022/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/27022/",
    "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": "<20260623-libipa-algorithms-v2-11-f97433f12e4e@ideasonboard.com>",
    "date": "2026-06-23T13:55:06",
    "name": "[v2,11/11] ipa: mali-c55: Port to use LscAlgorithm",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "9a2d040116c8563d470e11313145afd5e6d91bac",
    "submitter": {
        "id": 143,
        "url": "https://patchwork.libcamera.org/api/people/143/?format=api",
        "name": "Jacopo Mondi",
        "email": "jacopo.mondi@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/27022/mbox/",
    "series": [
        {
            "id": 6013,
            "url": "https://patchwork.libcamera.org/api/series/6013/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=6013",
            "date": "2026-06-23T13:54:55",
            "name": "ipa: libipa: Introduce libipa algorithms",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/6013/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/27022/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/27022/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 0312AC331D\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 23 Jun 2026 13:55:27 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id BD9376585E;\n\tTue, 23 Jun 2026 15:55:26 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 1B11F65858\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 23 Jun 2026 15:55:13 +0200 (CEST)",
            "from [192.168.1.7] (net-93-65-100-155.cust.vodafonedsl.it\n\t[93.65.100.155])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 5E9A63469;\n\tTue, 23 Jun 2026 15:54:34 +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=\"v6zg6A/U\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1782222874;\n\tbh=BxT2yEiyJfC5+/ybnd/IlEGCw4ff1zURxzBy5JYElNY=;\n\th=From:Date:Subject:References:In-Reply-To:To:Cc:From;\n\tb=v6zg6A/UuhRIqeZFiGuU+/AKiZj7ZAnZX9eMTbZRwpJa15LsbV3krkCJBfPkXm/Tg\n\txdK7KuIRbV2gyG290cTLhyqRFFEerTNfm4fETn9eStoT2VB4CARkOnFrcxMvsNHQVT\n\tyY312aXBIoUDSmkDpjHDKldDNadgaFzt9a8gNpak=",
        "From": "Jacopo Mondi <jacopo.mondi@ideasonboard.com>",
        "Date": "Tue, 23 Jun 2026 15:55:06 +0200",
        "Subject": "[PATCH v2 11/11] ipa: mali-c55: Port to use LscAlgorithm",
        "MIME-Version": "1.0",
        "Content-Type": "text/plain; charset=\"utf-8\"",
        "Content-Transfer-Encoding": "7bit",
        "Message-Id": "<20260623-libipa-algorithms-v2-11-f97433f12e4e@ideasonboard.com>",
        "References": "<20260623-libipa-algorithms-v2-0-f97433f12e4e@ideasonboard.com>",
        "In-Reply-To": "<20260623-libipa-algorithms-v2-0-f97433f12e4e@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "Jacopo Mondi <jacopo.mondi@ideasonboard.com>, \n\tKieran Bingham <kieran.bingham@ideasonboard.com>, \n\tDaniel Scally <dan.scally@ideasonboard.com>",
        "X-Mailer": "b4 0.14.3",
        "X-Developer-Signature": "v=1; a=openpgp-sha256; l=10863;\n\ti=jacopo.mondi@ideasonboard.com; h=from:subject:message-id;\n\tbh=BxT2yEiyJfC5+/ybnd/IlEGCw4ff1zURxzBy5JYElNY=;\n\tb=owEBbQKS/ZANAwAKAXI0Bo8WoVY8AcsmYgBqOpA9PttS+p9lIUx8x2GUKssM4rvdRccK/D9/t\n\tF0qg7kkuiGJAjMEAAEKAB0WIQS1xD1IgJogio9YOMByNAaPFqFWPAUCajqQPQAKCRByNAaPFqFW\n\tPERqD/963QsqO0eOikpiz9vFhX5HbnCw6eLBZ804BJI6Z18f7mzkBZa4n5i27YAsEwExzke86q3\n\tkq+MQvmlL5FVWGymEp/mT8Zz17LyYtmwTlQQmE5eDAhIrNFVvKesd/l4OgLZol+QG52KR74beiY\n\tZ4Z630LNHKuTNLp9TfpLdqcfercwhmd+2z5ZwpAc1RHomuA8qkCF53Dv0knUobPmZ9zA4nN6RLG\n\tObbDrW96GgYr4hFz7ZAlzPjwg8UzUGpfoc8/Fajk+HsZp+P1vodispNKd/w63lP8TQfMj+LUmtd\n\tYmTgCcFGMkT2zjo2r5+gL6xge4I6sMrbVHHNMmxArCGU7vvePZ4B22kDnQXXbnwf9TLOrvnIox6\n\tru3AWYGVrXHi5jGdSOPXblARMJNVdWcaSP/F0BUyW44s6YdPOeZ+xM5ozhiI+eb2pqceuS7h9yI\n\tGGZ+guqjNyb1mag1zvK7WVnMD2Zb3fgDHo4QQ5ZSr5ygd1pZxi93NyZJ9BskVF4pFMu2kLIRtZX\n\thSmbLHecd7bglQw+Pxzo8o98lL/gnC70FLd7/dx4WWjb1Xr2SAs5dUBAyOFK9D+6W+urAzpTesG\n\t4ej32JbCF8igkdXfaH0eGiqVheKMz9/JxDaP91KMc73XEK3p2ZjcConabdpC0yUcH0x9/RJ2NXX\n\t57TI4LZ6Q7y1fjg==",
        "X-Developer-Key": "i=jacopo.mondi@ideasonboard.com; a=openpgp;\n\tfpr=72392EDC88144A65C701EA9BA5826A2587AD026B",
        "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": "Port the Mali-C55 LSC algorithm to use libIPA LscAlgorithm.\n\nSigned-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\nReviewed-by: Daniel Scally <dan.scally@ideasonboard.com>\n---\n src/ipa/mali-c55/algorithms/lsc.cpp | 156 ++++++++++++++++++++++--------------\n src/ipa/mali-c55/algorithms/lsc.h   |  32 ++++++--\n src/ipa/mali-c55/ipa_context.h      |   3 +\n 3 files changed, 122 insertions(+), 69 deletions(-)",
    "diff": "diff --git a/src/ipa/mali-c55/algorithms/lsc.cpp b/src/ipa/mali-c55/algorithms/lsc.cpp\nindex 097239dcef3e..ad412bac2770 100644\n--- a/src/ipa/mali-c55/algorithms/lsc.cpp\n+++ b/src/ipa/mali-c55/algorithms/lsc.cpp\n@@ -9,38 +9,74 @@\n \n #include <libcamera/base/utils.h>\n \n-#include \"libcamera/internal/value_node.h\"\n-\n namespace libcamera {\n \n namespace ipa::mali_c55::algorithms {\n \n LOG_DEFINE_CATEGORY(MaliC55Lsc)\n \n-int Lsc::init([[maybe_unused]] IPAContext &context, const ValueNode &tuningData)\n+/* Gain values in [1, 5] range */\n+static constexpr unsigned int kMeshScale = 6;\n+\n+/* Mali-C55 hw supports configurable mesh sizes; we fix it to 32. */\n+static constexpr unsigned int kMeshSize = 32;\n+static constexpr unsigned int kGridSize = kMeshSize * kMeshSize;\n+\n+/* Per-colour component page offsets in the mesh table. */\n+static constexpr unsigned int kRedOffset = 0;\n+static constexpr unsigned int kGreenOffset = 1024;\n+static constexpr unsigned int kBlueOffset = 2048;\n+\n+/*\n+ * \\todo Clarify if Mali-C55 can support up to 4 colour temperatures.\n+ *\n+ * The uAPI only expose MALI_C55_NUM_MESH_SHADING_ELEMENTS (3072) gain elements,\n+ * which correspond to three pages of 1024 (32x32) entries.\n+ */\n+static constexpr unsigned int kMaxColourTemperatures = 3;\n+\n+/*\n+ * The LSC algorithm implementation only supports 32x32 grids. Create a list of\n+ * positions from the grid size.\n+ */\n+std::vector<double> Lsc::segmentsToPosition() const\n {\n-\tif (!tuningData.contains(\"meshScale\")) {\n-\t\tLOG(MaliC55Lsc, Error) << \"meshScale missing from tuningData\";\n-\t\treturn -EINVAL;\n-\t}\n+\tstd::vector<double> positions(kMeshSize);\n+\tfor (double i = 0.0; i < kMeshSize; ++i)\n+\t\tpositions[i] = i / (kMeshSize - 1);\n \n-\tmeshScale_ = tuningData[\"meshScale\"].get<uint32_t>(0);\n+\treturn positions;\n+}\n \n-\tconst ValueNode &sets = tuningData[\"sets\"];\n-\tif (!sets.isList()) {\n-\t\tLOG(MaliC55Lsc, Error) << \"LSC tables missing or invalid\";\n-\t\treturn -EINVAL;\n-\t}\n+int Lsc::init(IPAContext &context, const ValueNode &tuningData)\n+{\n+\tgridPos_ = segmentsToPosition();\n+\n+\treturn lscAlgo_.init(tuningData, context.ctrlMap, {\n+\t\t\t     .keys = { \"r\", \"g\", \"b\" },\n+\t\t\t     .numHCells = kMeshSize,\n+\t\t\t     .numVCells = kMeshSize,\n+\t\t\t     .sensorSize = context.sensorInfo.activeAreaSize\n+\t\t\t});\n+}\n \n-\tsize_t tableSize = 0;\n-\tfor (const auto &set : sets.asList()) {\n-\t\tuint32_t ct = set[\"ct\"].get<uint32_t>(0);\n+int Lsc::configure(IPAContext &context, const IPACameraSensorInfo &configInfo)\n+{\n+\tint ret = lscAlgo_.configure(context.activeState.lsc, configInfo.analogCrop,\n+\t\t\t\t     gridPos_, gridPos_);\n+\tif (ret)\n+\t\treturn ret;\n \n-\t\tif (!ct) {\n-\t\t\tLOG(MaliC55Lsc, Error) << \"Invalid colour temperature\";\n-\t\t\treturn -EINVAL;\n-\t\t}\n+\t/* Re-initialize the mesh tables and reserve space for enough entries. */\n+\tmesh_ = std::vector<uint32_t>(kGridSize * kMaxColourTemperatures);\n+\tcolourTemperatures_.clear();\n \n+\t/*\n+\t * Get the lsc tables per colour components and populate mesh_ with\n+\t * their content.\n+\t */\n+\tconst auto &components = lscAlgo_.getComponents();\n+\tfor (auto const &[ct, component] : components) {\n \t\tif (std::count(colourTemperatures_.begin(),\n \t\t\t       colourTemperatures_.end(), ct)) {\n \t\t\tLOG(MaliC55Lsc, Error)\n@@ -48,44 +84,29 @@ int Lsc::init([[maybe_unused]] IPAContext &context, const ValueNode &tuningData)\n \t\t\treturn -EINVAL;\n \t\t}\n \n-\t\tstd::vector<uint8_t> rTable =\n-\t\t\tset[\"r\"].get<std::vector<uint8_t>>().value_or(utils::defopt);\n-\t\tstd::vector<uint8_t> gTable =\n-\t\t\tset[\"g\"].get<std::vector<uint8_t>>().value_or(utils::defopt);\n-\t\tstd::vector<uint8_t> bTable =\n-\t\t\tset[\"b\"].get<std::vector<uint8_t>>().value_or(utils::defopt);\n-\n-\t\t/*\n-\t\t * Some validation to do; only 16x16 and 32x32 tables of\n-\t\t * coefficients are acceptable, and all tables across all of the\n-\t\t * sets must be the same size. The first time we encounter a\n-\t\t * table we check that it is an acceptable size and if so make\n-\t\t * sure all other tables are of equal size.\n-\t\t */\n-\t\tif (!tableSize) {\n-\t\t\tif (rTable.size() != 256 && rTable.size() != 1024) {\n-\t\t\t\tLOG(MaliC55Lsc, Error)\n-\t\t\t\t\t<< \"Invalid table size for colour temperature \" << ct;\n-\t\t\t\treturn -EINVAL;\n-\t\t\t}\n-\t\t\ttableSize = rTable.size();\n-\t\t}\n+\t\tstd::vector<uint8_t> rTable = component.at(\"r\");\n+\t\tstd::vector<uint8_t> gTable = component.at(\"g\");\n+\t\tstd::vector<uint8_t> bTable = component.at(\"b\");\n \n-\t\tif (rTable.size() != tableSize ||\n-\t\t    gTable.size() != tableSize ||\n-\t\t    bTable.size() != tableSize) {\n+\t\t/* Only 32x32 tables of coefficients are accepted. */\n+\t\tif (rTable.size() != kGridSize || gTable.size() != kGridSize ||\n+\t\t    bTable.size() != kGridSize) {\n \t\t\tLOG(MaliC55Lsc, Error)\n-\t\t\t\t<< \"Invalid or mismatched table size for colour temperature \" << ct;\n+\t\t\t\t<< \"Invalid table size for colour temperature \" << ct;\n \t\t\treturn -EINVAL;\n \t\t}\n \n-\t\tif (colourTemperatures_.size() >= 3) {\n+\t\tif (colourTemperatures_.size() >= kMaxColourTemperatures) {\n \t\t\tLOG(MaliC55Lsc, Error)\n \t\t\t\t<< \"A maximum of 3 colour temperatures are supported\";\n \t\t\treturn -EINVAL;\n \t\t}\n \n-\t\tfor (unsigned int i = 0; i < tableSize; i++) {\n+\t\t/*\n+\t\t * Create the mesh table entries by assembling up to 3 gains per\n+\t\t * colour temperature in a u32 word.\n+\t\t */\n+\t\tfor (unsigned int i = 0; i < kGridSize; i++) {\n \t\t\tmesh_[kRedOffset + i] |=\n \t\t\t\t(rTable[i] << (colourTemperatures_.size() * 8));\n \t\t\tmesh_[kGreenOffset + i] |=\n@@ -97,35 +118,36 @@ int Lsc::init([[maybe_unused]] IPAContext &context, const ValueNode &tuningData)\n \t\tcolourTemperatures_.push_back(ct);\n \t}\n \n-\t/*\n-\t * The mesh has either 16x16 or 32x32 nodes, we tell the driver which it\n-\t * is based on the number of values in the tuning data's table.\n-\t */\n-\tif (tableSize == 256)\n-\t\tmeshSize_ = 15;\n-\telse\n-\t\tmeshSize_ = 31;\n-\n \treturn 0;\n }\n \n+/**\n+ * \\copydoc libcamera::ipa::Algorithm::queueRequest\n+ */\n+void Lsc::queueRequest(IPAContext &context, [[maybe_unused]] const uint32_t frame,\n+\t\t       IPAFrameContext &frameContext, const ControlList &controls)\n+{\n+\tlscAlgo_.queueRequest(context.activeState.lsc, frameContext.lsc,\n+\t\t\t      controls);\n+}\n+\n void Lsc::fillConfigParamsBlock(MaliC55Params *params) const\n {\n \tauto block = params->block<MaliC55Blocks::MeshShadingConfig>();\n \n \tblock->mesh_show = false;\n-\tblock->mesh_scale = meshScale_;\n+\tblock->mesh_scale = kMeshScale;\n \tblock->mesh_page_r = 0;\n \tblock->mesh_page_g = 1;\n \tblock->mesh_page_b = 2;\n-\tblock->mesh_width = meshSize_;\n-\tblock->mesh_height = meshSize_;\n+\tblock->mesh_width = kMeshSize - 1;\n+\tblock->mesh_height = kMeshSize - 1;\n \n \tstd::copy(mesh_.begin(), mesh_.end(), block->mesh);\n }\n \n void Lsc::fillSelectionParamsBlock(MaliC55Params *params, uint8_t bank,\n-\t\t\t\t     uint8_t alpha) const\n+\t\t\t\t   uint8_t alpha) const\n {\n \tauto block = params->block<MaliC55Blocks::MeshShadingSel>();\n \n@@ -198,6 +220,18 @@ void Lsc::prepare(IPAContext &context, [[maybe_unused]] const uint32_t frame,\n \tfillConfigParamsBlock(params);\n }\n \n+/**\n+ * \\copydoc libcamera::ipa::Algorithm::process\n+ */\n+void Lsc::process([[maybe_unused]] IPAContext &context,\n+\t\t  [[maybe_unused]] const uint32_t frame,\n+\t\t  IPAFrameContext &frameContext,\n+\t\t  [[maybe_unused]] const mali_c55_stats_buffer *stats,\n+\t\t  ControlList &metadata)\n+{\n+\tlscAlgo_.process(frameContext.lsc, metadata);\n+}\n+\n REGISTER_IPA_ALGORITHM(Lsc, \"Lsc\")\n \n } /* namespace ipa::mali_c55::algorithms */\ndiff --git a/src/ipa/mali-c55/algorithms/lsc.h b/src/ipa/mali-c55/algorithms/lsc.h\nindex 3d35fd72bfa8..4544490b1b64 100644\n--- a/src/ipa/mali-c55/algorithms/lsc.h\n+++ b/src/ipa/mali-c55/algorithms/lsc.h\n@@ -5,10 +5,19 @@\n  * Mali-C55 Lens shading correction algorithm\n  */\n \n-#include <map>\n+#include <vector>\n #include <tuple>\n \n+#include <linux/media/arm/mali-c55-config.h>\n+\n+#include \"libcamera/internal/value_node.h\"\n+\n+#include \"libipa/fixedpoint.h\"\n+#include \"libipa/lsc.h\"\n+\n #include \"algorithm.h\"\n+#include \"ipa_context.h\"\n+#include \"params.h\"\n \n namespace libcamera {\n \n@@ -21,23 +30,30 @@ public:\n \t~Lsc() = default;\n \n \tint init(IPAContext &context, const ValueNode &tuningData) override;\n+\tint configure(IPAContext &context, const IPACameraSensorInfo &configInfo) override;\n+\tvoid queueRequest(IPAContext &context, const uint32_t frame,\n+\t\t\t  IPAFrameContext &frameContext,\n+\t\t\t  const ControlList &controls) override;\n \tvoid prepare(IPAContext &context, const uint32_t frame,\n \t\t     IPAFrameContext &frameContext,\n \t\t     MaliC55Params *params) override;\n+\tvoid process(IPAContext &context, const uint32_t frame,\n+\t\t     IPAFrameContext &frameContext,\n+\t\t     const mali_c55_stats_buffer *stats,\n+\t\t     ControlList &metadata) override;\n private:\n-\tstatic constexpr unsigned int kRedOffset = 0;\n-\tstatic constexpr unsigned int kGreenOffset = 1024;\n-\tstatic constexpr unsigned int kBlueOffset = 2048;\n-\n+\tstd::vector<double> segmentsToPosition() const;\n \tvoid fillConfigParamsBlock(MaliC55Params *params) const;\n \tvoid fillSelectionParamsBlock(MaliC55Params *params,\n \t\t\t\t      uint8_t bank, uint8_t alpha) const;\n \tstd::tuple<uint8_t, uint8_t> findBankAndAlpha(uint32_t ct) const;\n \n-\tstd::vector<uint32_t> mesh_ = std::vector<uint32_t>(3072);\n \tstd::vector<uint32_t> colourTemperatures_;\n-\tuint32_t meshScale_;\n-\tuint32_t meshSize_;\n+\tstd::vector<uint32_t> mesh_;\n+\n+\tstd::vector<double> gridPos_;\n+\n+\tLscAlgorithm<uint8_t, UQ<2, 6>> lscAlgo_;\n };\n \n } /* namespace ipa::mali_c55::algorithms */\ndiff --git a/src/ipa/mali-c55/ipa_context.h b/src/ipa/mali-c55/ipa_context.h\nindex 0daa5f8023a2..d924fb7ae7c0 100644\n--- a/src/ipa/mali-c55/ipa_context.h\n+++ b/src/ipa/mali-c55/ipa_context.h\n@@ -20,6 +20,7 @@\n #include \"libipa/awb.h\"\n #include \"libipa/ccm.h\"\n #include \"libipa/fixedpoint.h\"\n+#include \"libipa/lsc.h\"\n \n namespace libcamera {\n \n@@ -61,6 +62,7 @@ struct IPAActiveState {\n \n \tipa::awb::ActiveState awb;\n \tipa::ccm::ActiveState ccm;\n+\tipa::lsc::ActiveState lsc;\n };\n \n struct IPAFrameContext : public FrameContext {\n@@ -72,6 +74,7 @@ struct IPAFrameContext : public FrameContext {\n \n \tipa::awb::FrameContext awb;\n \tipa::ccm::FrameContext ccm;\n+\tipa::lsc::FrameContext lsc;\n };\n \n struct IPAContext {\n",
    "prefixes": [
        "v2",
        "11/11"
    ]
}