Show a patch.

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

{
    "id": 27287,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/27287/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/27287/",
    "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": "<20260708-libipa-algorithms-v4-22-f0e99f035294@ideasonboard.com>",
    "date": "2026-07-08T09:25:09",
    "name": "[v4,22/35] ipa: libipa: lsc: Introduce LscAlgorithm",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "e645d7def433c24510f5980b95ad6a1a75704e6a",
    "submitter": {
        "id": 143,
        "url": "https://patchwork.libcamera.org/api/1.1/people/143/?format=api",
        "name": "Jacopo Mondi",
        "email": "jacopo.mondi@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/27287/mbox/",
    "series": [
        {
            "id": 6046,
            "url": "https://patchwork.libcamera.org/api/1.1/series/6046/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=6046",
            "date": "2026-07-08T09:24:47",
            "name": "ipa: libipa: Introduce libipa algorithms",
            "version": 4,
            "mbox": "https://patchwork.libcamera.org/series/6046/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/27287/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/27287/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 1A857C3318\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  8 Jul 2026 09:25:38 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id DC082660C7;\n\tWed,  8 Jul 2026 11:25:35 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id DF6346609A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  8 Jul 2026 11:25:11 +0200 (CEST)",
            "from [192.168.1.182] (93-46-82-201.ip106.fastwebnet.it\n\t[93.46.82.201])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 4F6B03FBB;\n\tWed,  8 Jul 2026 11:24:22 +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=\"aUfTV8+/\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1783502662;\n\tbh=ufGN47Y+M2apUceF3o/l4FY6OxM8VSz3Mf75D2CYr2A=;\n\th=From:Date:Subject:References:In-Reply-To:To:Cc:From;\n\tb=aUfTV8+/AEwblF3JJ65SXTFkTdJpsIdk/+9YKoh6+Q54A6KrTl5BapeLeeaTcpeSO\n\tgzfKlOkc/vwtj25amMjnsA7KtfqSugx6ey+UfVO398BmgzDJe+1uxWRBzo2fN8onof\n\tzdi1HXhhYtD7i3+Jtwy5vlJKumWcsxCsBADBN2VE=",
        "From": "Jacopo Mondi <jacopo.mondi@ideasonboard.com>",
        "Date": "Wed, 08 Jul 2026 11:25:09 +0200",
        "Subject": "[PATCH v4 22/35] ipa: libipa: lsc: Introduce LscAlgorithm",
        "MIME-Version": "1.0",
        "Content-Type": "text/plain; charset=\"utf-8\"",
        "Content-Transfer-Encoding": "7bit",
        "Message-Id": "<20260708-libipa-algorithms-v4-22-f0e99f035294@ideasonboard.com>",
        "References": "<20260708-libipa-algorithms-v4-0-f0e99f035294@ideasonboard.com>",
        "In-Reply-To": "<20260708-libipa-algorithms-v4-0-f0e99f035294@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org, \n\tStefan Klug <stefan.klug@ideasonboard.com>",
        "Cc": "Jacopo Mondi <jacopo.mondi@ideasonboard.com>",
        "X-Mailer": "b4 0.14.3",
        "X-Developer-Signature": "v=1; a=openpgp-sha256; l=9923;\n\ti=jacopo.mondi@ideasonboard.com; h=from:subject:message-id;\n\tbh=ufGN47Y+M2apUceF3o/l4FY6OxM8VSz3Mf75D2CYr2A=;\n\tb=owEBbQKS/ZANAwAKAXI0Bo8WoVY8AcsmYgBqThdudRhbcyWqR+U9zdnDdHB8Emni0MHXOgd4K\n\tucHOJzQwHyJAjMEAAEKAB0WIQS1xD1IgJogio9YOMByNAaPFqFWPAUCak4XbgAKCRByNAaPFqFW\n\tPNGnD/9nn3D+4WLLRqMoEC4wMkS3gwXsv9IrH9BkylSYYARwVIBryXMgGs7xpjpW/9TL4lolOra\n\tXi6BSOZXgVhfvDEfmZo7AUFrbnDNUPDWLRuymqbrUzi2Pnca+8ndCj3BO8oLh16Jo3NGOVg4swc\n\tY2jKc2WkfX1Q7gWxbt2sB8HbeOx+/3prz00Z3M5OS2eIUPSoqftry8InhplVDnZiO/mRR721oEB\n\t+SvG6CGM7eesnAsETjctjrb08Z2i/H0fR1TnOWMMp3PUVSSkpkmTAzWyfE+oP3LiBDuGV1gmNBx\n\tdNWXjJ6eZyI9HXQSuh+jq8lvZuCVyud7bcdrw8VeMeqFeZN0WnvavQflYcsPlW8stI+RZQ/EPgm\n\ttThf3SYohQ/sGPs5wp3J6e0v09fHsOgLSvIkBzVhEO8RqcPFC7a+T2NTNP/38mtNVl5uuGcy+gx\n\tptmhfTSQPIoJ7Di1RVXibgFfN82eVMQM1S6KD34MF+xsUY0oSI5JLWnFJU+BBQaFXo9sbuRfIfh\n\tiwOr+QPAJKUX58tAjOYilG2WiN4rPy+rK4wKUgBlvYSKXjnAirVWSuNOL6Op2Iv4E25m8gIkgQG\n\t7pLQ08oehxDEhvUh8dc8qMgG9hXUqFq6+1Mr/TWMpp5m0MLv8RV49Ysetu77EAzR0e4MYkQXp4I\n\txL7kmvtpPHkGD6Q==",
        "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": "Introduce the LscAlgorithm class that implements the LSC algorithm\nfor libipa.\n\nThe class uses two backends (LscPolynomial and LscTable) to perform\ntuning file parsing and re-scaling of the LSC gains.\n\nSigned-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n---\n src/ipa/libipa/lsc.cpp | 209 +++++++++++++++++++++++++++++++++++++++++++++++++\n src/ipa/libipa/lsc.h   |  42 ++++++++++\n 2 files changed, 251 insertions(+)",
    "diff": "diff --git a/src/ipa/libipa/lsc.cpp b/src/ipa/libipa/lsc.cpp\nindex 382cafc04ab4..cf748b766d1a 100644\n--- a/src/ipa/libipa/lsc.cpp\n+++ b/src/ipa/libipa/lsc.cpp\n@@ -7,6 +7,13 @@\n \n #include \"lsc.h\"\n \n+#include <libcamera/base/log.h>\n+\n+#include <libcamera/control_ids.h>\n+\n+#include \"lsc_polynomial.h\"\n+#include \"lsc_table.h\"\n+\n /**\n  * \\file lsc.h\n  * \\brief libipa LSC algorithm\n@@ -14,6 +21,8 @@\n \n namespace libcamera {\n \n+LOG_DEFINE_CATEGORY(Lsc)\n+\n namespace ipa {\n \n namespace lsc {\n@@ -39,6 +48,206 @@ namespace lsc {\n \n } /* namespace lsc */\n \n+/**\n+ * \\class LscAlgorithm\n+ * \\brief libIPA LSC algorithm implementation\n+ *\n+ * Due to the optical characteristics of the lens, the light intensity received\n+ * by the sensor is not uniform. The Lens Shading Correction algorithm applies\n+ * multipliers to all pixels to compensate for the lens shading effect.\n+ *\n+ * The LscAlgorithm implements the libipa Lens Shading Correction algorithm\n+ * using an implementation of the LscImplementation interface.\n+ *\n+ * It provides support for parsing the tuning file content and generates tables\n+ * of per-colour temperature gains that IPA algorithms can use to program their\n+ * LSC engine.\n+ *\n+ * The init() function parses the tuning file and loads the gain tables either\n+ * in tabular form (LscTable) or as radial polynomials (LscPolynomial). The gain\n+ * tables are organized per-colour temperature with per-colour components gain\n+ * vectors or polynomial coefficients.\n+ *\n+ * At LscAlgorithm::configure() time the LSC tables are re-sampled on the\n+ * sensor's crop rectangle in use to adapt them to the configuration in use for\n+ * a streaming session. Polynomial LSC tables support re-sampling and can be\n+ * applied to any sensor configuration. Grid-based LSC tables cannot currently\n+ * be re-sampled and the configuration as parsed from the tuning file is used\n+ * for all sensor configurations providing best-effort results.\n+ *\n+ * \\todo: Implement grid based re-sampling\n+ *\n+ * When the IPA algorithms wants to get access to the (re-sampled) tables to\n+ * program its LSC engine, it uses LscAlgorithm::interpolateComponents() to get\n+ * an LSC table interpolated by the LscAlgorithm class for the specified colour\n+ * temperature. If the algorithm wants to access the non-interpolated tables it\n+ * can retrieve them using LscAlgorithm::getComponents().\n+ */\n+\n+/**\n+ * \\param[in] tuningData The tuning data\n+ * \\param[in] sensorSize The physical sensor size\n+ * \\param[in] controls The IPA list of supported controls\n+ *\n+ * Parse \\a tuningData according to the settings specified in \\a descriptor to\n+ * populate the LSC data and registers LSC controls in \\a controls.\n+ *\n+ * \\return 0 on success, a negative error code otherwise\n+ */\n+int LscAlgorithm::init(const ValueNode &tuningData, const Size &sensorSize,\n+\t\t       ControlInfoMap::Map &controls)\n+{\n+\tpolynomial_ = false;\n+\n+\tstd::string type = tuningData[\"type\"].get<std::string>(\"table\");\n+\tif (type == \"table\") {\n+\t\timpl_ = std::make_unique<LscTable>();\n+\t\tLOG(Lsc, Debug) << \"Using table-based Lsc\";\n+\t} else if (type == \"polynomial\") {\n+\t\t/*\n+\t\t * \\todo: Most likely the reference frame should be native_size.\n+\t\t * Let's wait how the internal discussions progress.\n+\t\t */\n+\t\timpl_ = std::make_unique<LscPolynomial>(sensorSize);\n+\t\tpolynomial_ = true;\n+\t\tLOG(Lsc, Debug) << \"Using polynomial Lsc\";\n+\t} else {\n+\t\tLOG(Lsc, Error) << \"Unsupported Lsc algorithm '\"\n+\t\t\t\t<< type << \"'\";\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tconst ValueNode &yamlSets = tuningData[\"sets\"];\n+\tif (!yamlSets.isList()) {\n+\t\tLOG(Lsc, Error) << \"'sets' parameter not found in tuning file\";\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tint ret = impl_->parseLscData(yamlSets);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tcontrols[&controls::LensShadingCorrectionEnable] =\n+\t\tControlInfo(false, true, true);\n+\n+\treturn 0;\n+}\n+\n+/**\n+ * \\param[in] state The LSC active state\n+ * \\param[in] analogCrop The current sensor analog crop rectangle\n+ * \\param[in] xPos List of horizontal positions of the LSC grid nodes\n+ * \\param[in] yPos List of vertical positions of the LSC grid nodes\n+ *\n+ * Re-sample the LSC data for an \\a analogCrop.\n+ *\n+ * LSC tables are generated at tuning time using a known sensor configuration.\n+ * When a new streaming session is started, it might use a different sensor\n+ * configuration for which the LSC tables need to be adjusted to.\n+ *\n+ * This function re-generates the LSC tables to adapt them to a new sensor\n+ * configuration, specifically it re-samples the LSC data for a new \\a\n+ * analogCrop on a grid specified by \\a xPos and \\a yPos. Re-sampling of\n+ * LSC data is currently supported by polynomial-based LSC tables.\n+ *\n+ * \\sa LscImplementation::sampleForCrop\n+ *\n+ * \\return 0 on success, a negative error code otherwise\n+ */\n+int LscAlgorithm::configure(lsc::ActiveState &state, const Rectangle &analogCrop,\n+\t\t\t    const std::vector<double> &xPos,\n+\t\t\t    const std::vector<double> &yPos)\n+{\n+\tLOG(Lsc, Debug) << \"Sample Lsc data for \" << analogCrop;\n+\tlsc::ComponentsMap lscData =\n+\t\timpl_->sampleForCrop(analogCrop, xPos, yPos);\n+\n+\t/*\n+\t * Retain a copy of the components table.\n+\t *\n+\t * We could avoid a copy here if getComponents() could\n+\t * return sets_.data() but I wasn't able to work around the\n+\t * compiler refusing it.\n+\t */\n+\tlscData_ = lscData;\n+\n+\tsets_.setData(std::move(lscData));\n+\tstate.enabled = true;\n+\n+\treturn 0;\n+}\n+\n+/**\n+ * \\brief Queue a request to the lsc algorithm\n+ * \\param[in] state The lsc active state\n+ * \\param[in] context The lsc frame context\n+ * \\param[in] controls The list of controls associated with a Request\n+ *\n+ * Queue a new list of \\a controls to the lsc algorithm.\n+ * The only supported control is controls::LensShadingCorrectionEnable.\n+ */\n+void LscAlgorithm::queueRequest(lsc::ActiveState &state,\n+\t\t\t\tlsc::FrameContext &context,\n+\t\t\t\tconst ControlList &controls)\n+{\n+\tconst auto &lscEnable = controls.get(controls::LensShadingCorrectionEnable);\n+\tif (lscEnable && *lscEnable != state.enabled) {\n+\t\tstate.enabled = *lscEnable;\n+\n+\t\tLOG(Lsc, Debug)\n+\t\t\t<< (state.enabled ? \"Enabling\" : \"Disabling\") << \" Lsc\";\n+\n+\t\tcontext.update = true;\n+\t}\n+\n+\tcontext.enabled = state.enabled;\n+}\n+\n+/**\n+ * \\brief Populate the list of lsc metadata\n+ * \\param[in] context The lsc frame context\n+ * \\param[in] metadata The list of metadata\n+ *\n+ * Populates the list of \\a metadata with controls handled by the LscAlgorithm\n+ * class. The only supported metadata is controls::LensShadingCorrectionEnable.\n+ */\n+void LscAlgorithm::process(lsc::FrameContext &context, ControlList &metadata)\n+{\n+\tmetadata.set(controls::LensShadingCorrectionEnable, context.enabled);\n+}\n+\n+/**\n+ * \\fn LscAlgorithm::interpolateComponents\n+ * \\brief Interpolate the LSC tables for a given colour temperature\n+ * \\param[in] ct The colour temperature\n+ *\n+ * LSC tables are generated using different colour temperatures during the\n+ * tuning phase.\n+ *\n+ * This function returns the interpolated LSC data for a given \\a ct\n+ * colour temperature.\n+ *\n+ * IPA algorithm can use this function to obtain a list of gains per-colour\n+ * component to program their LSC engines with every time a significant enough\n+ * change in colour temperature is detected.\n+ *\n+ * Calling this function is only valid after LscAlgorithm::configure() has been\n+ * called. An empty components list is returned otherwise.\n+ *\n+ * \\return The LSC gains table interpolated for temperature \\a ct\n+ */\n+\n+/**\n+ * \\fn LscAlgorithm::getComponents\n+ *\n+ * Return the map of LSC data per colour temperature.\n+ *\n+ * Calling this function is only valid after LscAlgorithm::configure() has been\n+ * called. An empty components list is returned otherwise.\n+ *\n+ * \\return The map of LSC gains tables per colour-temperature\n+ */\n+\n } /* namespace ipa */\n \n } /* namespace libcamera */\ndiff --git a/src/ipa/libipa/lsc.h b/src/ipa/libipa/lsc.h\nindex 73519564feff..9a51d32c3464 100644\n--- a/src/ipa/libipa/lsc.h\n+++ b/src/ipa/libipa/lsc.h\n@@ -7,6 +7,17 @@\n \n #pragma once\n \n+#include <memory>\n+#include <vector>\n+\n+#include <libcamera/controls.h>\n+#include <libcamera/geometry.h>\n+\n+#include \"libcamera/internal/value_node.h\"\n+\n+#include \"interpolator.h\"\n+#include \"lsc_base.h\"\n+\n namespace libcamera {\n \n namespace ipa {\n@@ -24,6 +35,37 @@ struct FrameContext {\n \n } /* namespace lsc */\n \n+class LscAlgorithm\n+{\n+public:\n+\tint init(const ValueNode &tuningData, const Size &sensorSize,\n+\t\t ControlInfoMap::Map &controls);\n+\n+\tint configure(lsc::ActiveState &state, const Rectangle &analogCrop,\n+\t\t      const std::vector<double> &xPos,\n+\t\t      const std::vector<double> &yPos);\n+\n+\tvoid queueRequest(lsc::ActiveState &state, lsc::FrameContext &context,\n+\t\t\t  const ControlList &controls);\n+\tvoid process(lsc::FrameContext &context, ControlList &metadata);\n+\n+\tconst lsc::Components interpolateComponents(unsigned int ct)\n+\t{\n+\t\treturn sets_.getInterpolated(ct);\n+\t}\n+\n+\tconst lsc::ComponentsMap getComponents()\n+\t{\n+\t\treturn lscData_;\n+\t}\n+\n+private:\n+\tstd::unique_ptr<LscImplementation> impl_;\n+\tInterpolator<lsc::Components> sets_;\n+\tlsc::ComponentsMap lscData_;\n+\tbool polynomial_;\n+};\n+\n } /* namespace ipa */\n \n } /* namespace libcamera */\n",
    "prefixes": [
        "v4",
        "22/35"
    ]
}