{"id":27282,"url":"https://patchwork.libcamera.org/api/1.1/patches/27282/?format=json","web_url":"https://patchwork.libcamera.org/patch/27282/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","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-17-f0e99f035294@ideasonboard.com>","date":"2026-07-08T09:25:04","name":"[v4,17/35] ipa: libipa: lsc_table: Move LscTable from RkISP1","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"05114358910132388e9f515fd1351ba509f93c7c","submitter":{"id":143,"url":"https://patchwork.libcamera.org/api/1.1/people/143/?format=json","name":"Jacopo Mondi","email":"jacopo.mondi@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/27282/mbox/","series":[{"id":6046,"url":"https://patchwork.libcamera.org/api/1.1/series/6046/?format=json","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/27282/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/27282/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 E8769C3301\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  8 Jul 2026 09:25:34 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5E30F660D4;\n\tWed,  8 Jul 2026 11:25:28 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 843E466098\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  8 Jul 2026 11:25:10 +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 D6B543FA9;\n\tWed,  8 Jul 2026 11:24:20 +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=\"ThCHzeJp\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1783502661;\n\tbh=Xx5zJIB1zkJdCGevazKOxH+Pfpu5Y2Nin5HQC5SwJro=;\n\th=From:Date:Subject:References:In-Reply-To:To:Cc:From;\n\tb=ThCHzeJpEmF+8qQ8XSl2uCQL4lkQ0JJW56p2mbO69W0nH0AfYpv4xJf9GxhfljFwa\n\tnYdkQiIz0vXWgdJeqTgfzsELlfRHCeqAgekd3GrC4FLxdaRWmKl+uhPfX0rGR+2Sy/\n\tW4mIHdzz90ZSJbENMrSGW92VMBUAyINxszYpAtCw=","From":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","Date":"Wed, 08 Jul 2026 11:25:04 +0200","Subject":"[PATCH v4 17/35] ipa: libipa: lsc_table: Move LscTable from RkISP1","MIME-Version":"1.0","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"7bit","Message-Id":"<20260708-libipa-algorithms-v4-17-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>, \n\tKieran Bingham <kieran.bingham@ideasonboard.com>","X-Mailer":"b4 0.14.3","X-Developer-Signature":"v=1; a=openpgp-sha256; l=8313;\n\ti=jacopo.mondi@ideasonboard.com; h=from:subject:message-id;\n\tbh=Xx5zJIB1zkJdCGevazKOxH+Pfpu5Y2Nin5HQC5SwJro=;\n\tb=owEBbQKS/ZANAwAKAXI0Bo8WoVY8AcsmYgBqThduqIbkb0U3Vr5oNmGseVXHF+68C13ByJi+F\n\tkIEP9ccmTqJAjMEAAEKAB0WIQS1xD1IgJogio9YOMByNAaPFqFWPAUCak4XbgAKCRByNAaPFqFW\n\tPIaWEACl1jutFdnoDXNaGSAITKlrzw84E1nkOKbWPN5oqk1tHq53cbdsiyBoJFyTb9j38ZawqZs\n\tUJMyWjYnxzmLWl3X6E5jFaIHVurnUWI0XrUVpv3rigu34HgD38HS1PdSv+VVUCFFQ+ztujR+P/J\n\txc40L+kwTIf9TKrMi4wSLGCYfhCMK+SL2amZ9dv/B2nWCE7IvGRWreMKObFKFQhTPpe+tYietzk\n\tyVHXhwu/PArifXEDAPrgWI289MremB0cKwX/FB1ZcYkyaP/dJB74LKNHBWxQ8FE9plTi5uTL9PT\n\tTYUrRj6/BSyNncjX8mvbqnc00RQlNrO7Qarn6M+pmFuxQcEQL/BAt8Fr9283Ccrq6CE+eYm/Xf+\n\tpA7x4OgmfDdpuUYHWW9cCnsyJFb9A4MxJI0divG07tpi48O0CZo/9KcgI7GrqaLUwvATzynzWa2\n\txiJX3cBn+Y/xS5TRtFVjvfnuSo+LRgmTjaPvc96VXxr6dxpKOojjp2E6F4kTrk6abD1+nb9dSh6\n\tRVP0MKa2umu9F0wRbrRRUpJtXtAG+NX83A0dOYQ1LJgYOXE8MCSUi5ryPkgMKNQkiEOqwLsoRY6\n\tSGUiZDKnFw+x0WjQcnxnmx8ysrgZQ8Ok7bUNkGYiV7RupV4vQ/eoStrOuhyVpCesWvtZ6qNQFPg\n\tCQLaqyAJpNa02Qg==","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":"Move the LscTableImpl class to libipa from RkISP1.\n\nRename the class from LscTableImpl to a simpler LscTable.\nThe class is copied verbatim, only documntation has been added.\n\nThe implementation still contains RkISP1 specific data which will be\nremoved once the class is generalized.\n\nSigned-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n---\n src/ipa/libipa/lsc_table.cpp      | 95 +++++++++++++++++++++++++++++++++++++++\n src/ipa/libipa/lsc_table.h        | 50 +++++++++++++++++++++\n src/ipa/libipa/meson.build        |  2 +\n src/ipa/rkisp1/algorithms/lsc.cpp | 81 +--------------------------------\n 4 files changed, 149 insertions(+), 79 deletions(-)","diff":"diff --git a/src/ipa/libipa/lsc_table.cpp b/src/ipa/libipa/lsc_table.cpp\nnew file mode 100644\nindex 000000000000..47dff156963a\n--- /dev/null\n+++ b/src/ipa/libipa/lsc_table.cpp\n@@ -0,0 +1,95 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2026, Ideas On Board\n+ *\n+ * Table-based LSC implementation\n+ */\n+\n+#include \"lsc_table.h\"\n+\n+/* \\todo Remove RkISP1 from libipa. */\n+#include \"linux/rkisp1-config.h\"\n+\n+namespace libcamera {\n+\n+LOG_DEFINE_CATEGORY(LscTable)\n+\n+namespace ipa {\n+\n+/**\n+ * \\class LscTable\n+ * \\brief Table based LSC algorithm implementation\n+ *\n+ * Table based LSC algorithm implementation. The LSCTable class implements LSC\n+ * support using tabular LSC data.\n+ *\n+ * \\sa LscImplementation\n+ */\n+\n+/**\n+ * \\brief Parse tabular LSC data\n+ * \\param[in] sets The tuning file content\n+ *\n+ * Parse the LSC data in tabular form from the \\a sets tuning data.\n+ *\n+ * \\return 0 on success or a negative error number otherwise\n+ */\n+int LscTable::parseLscData(const ValueNode &sets)\n+{\n+\tfor (const auto &set : sets.asList()) {\n+\t\tuint32_t ct = set[\"ct\"].get<uint32_t>(0);\n+\n+\t\tif (lscData_.count(ct)) {\n+\t\t\tLOG(LscTable, Error)\n+\t\t\t\t<< \"Multiple sets found for color temperature \"\n+\t\t\t\t<< ct;\n+\t\t\treturn -EINVAL;\n+\t\t}\n+\n+\t\tlsc::Components components;\n+\t\tcomponents.r = parseTable(set, \"r\");\n+\t\tcomponents.gr = parseTable(set, \"gr\");\n+\t\tcomponents.gb = parseTable(set, \"gb\");\n+\t\tcomponents.b = parseTable(set, \"b\");\n+\n+\t\tif (components.r.empty() || components.gr.empty() ||\n+\t\t    components.gb.empty() || components.b.empty()) {\n+\t\t\tLOG(LscTable, Error)\n+\t\t\t\t<< \"Set for color temperature \" << ct\n+\t\t\t\t<< \" is missing tables\";\n+\t\t\treturn -EINVAL;\n+\t\t}\n+\n+\t\tlscData_.emplace(ct, std::move(components));\n+\t}\n+\n+\tif (lscData_.empty()) {\n+\t\tLOG(LscTable, Error) << \"Failed to load any sets\";\n+\t\treturn -EINVAL;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+std::vector<uint16_t> LscTable::parseTable(const ValueNode &tuningData,\n+\t\t\t\t\t   const char *prop)\n+{\n+\tstatic constexpr unsigned int kLscNumSamples =\n+\t\tRKISP1_CIF_ISP_LSC_SAMPLES_MAX * RKISP1_CIF_ISP_LSC_SAMPLES_MAX;\n+\n+\tstd::vector<uint16_t> table =\n+\t\ttuningData[prop].get<std::vector<uint16_t>>().value_or(utils::defopt);\n+\tif (table.size() != kLscNumSamples) {\n+\t\tLOG(LscTable, Error)\n+\t\t\t<< \"Invalid '\" << prop << \"' values: expected \"\n+\t\t\t<< kLscNumSamples\n+\t\t\t<< \" elements, got \" << table.size();\n+\t\treturn {};\n+\t}\n+\n+\treturn table;\n+}\n+\n+} /* namespace ipa */\n+\n+} /* namespace libcamera */\ndiff --git a/src/ipa/libipa/lsc_table.h b/src/ipa/libipa/lsc_table.h\nnew file mode 100644\nindex 000000000000..0983b78c3f6b\n--- /dev/null\n+++ b/src/ipa/libipa/lsc_table.h\n@@ -0,0 +1,50 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2026, Ideas On Board\n+ *\n+ * Table-based Lsc implementation\n+ */\n+#pragma once\n+\n+#include <vector>\n+\n+#include <libcamera/base/log.h>\n+#include <libcamera/base/span.h>\n+\n+#include <libcamera/geometry.h>\n+\n+#include \"libcamera/internal/value_node.h\"\n+\n+#include \"lsc_base.h\"\n+\n+namespace libcamera {\n+\n+LOG_DECLARE_CATEGORY(LscTable)\n+\n+namespace ipa {\n+\n+class LscTable : public LscImplementation\n+{\n+public:\n+\tint parseLscData(const ValueNode &sets) override;\n+\n+\tlsc::ComponentsMap\n+\tsampleForCrop([[maybe_unused]] const Rectangle &cropRectangle,\n+\t\t      [[maybe_unused]] Span<const double> xSizes,\n+\t\t      [[maybe_unused]] Span<const double> ySizes) override\n+\t{\n+\t\tLOG(LscTable, Warning)\n+\t\t\t<< \"Tabular LSC data doesn't support resampling\";\n+\t\treturn lscData_;\n+\t}\n+\n+private:\n+\tstd::vector<uint16_t> parseTable(const ValueNode &tuningData,\n+\t\t\t\t\t const char *prop);\n+\n+\tlsc::ComponentsMap lscData_;\n+};\n+\n+} /* namespace ipa */\n+\n+} /* namespace libcamera */\ndiff --git a/src/ipa/libipa/meson.build b/src/ipa/libipa/meson.build\nindex 96611e90ee1e..95d398d99fd6 100644\n--- a/src/ipa/libipa/meson.build\n+++ b/src/ipa/libipa/meson.build\n@@ -16,6 +16,7 @@ libipa_headers = files([\n     'interpolator.h',\n     'lsc_base.h',\n     'lsc_polynomial.h',\n+    'lsc_table.h',\n     'lux.h',\n     'module.h',\n     'pwl.h',\n@@ -39,6 +40,7 @@ libipa_sources = files([\n     'interpolator.cpp',\n     'lsc_base.cpp',\n     'lsc_polynomial.cpp',\n+    'lsc_table.cpp',\n     'lux.cpp',\n     'module.cpp',\n     'pwl.cpp',\ndiff --git a/src/ipa/rkisp1/algorithms/lsc.cpp b/src/ipa/rkisp1/algorithms/lsc.cpp\nindex b161798763cb..f32c46084dd1 100644\n--- a/src/ipa/rkisp1/algorithms/lsc.cpp\n+++ b/src/ipa/rkisp1/algorithms/lsc.cpp\n@@ -17,6 +17,7 @@\n #include \"libcamera/internal/value_node.h\"\n \n #include \"libipa/lsc_polynomial.h\"\n+#include \"libipa/lsc_table.h\"\n #include \"linux/rkisp1-config.h\"\n \n /**\n@@ -33,84 +34,6 @@ namespace {\n \n constexpr int kColourTemperatureQuantization = 10;\n \n-class LscTableImpl : public LscImplementation\n-{\n-public:\n-\tint parseLscData(const ValueNode &sets) override;\n-\n-\tlsc::ComponentsMap\n-\tsampleForCrop([[maybe_unused]] const Rectangle &cropRectangle,\n-\t\t      [[maybe_unused]] Span<const double> xSizes,\n-\t\t      [[maybe_unused]] Span<const double> ySizes) override\n-\t{\n-\t\tLOG(RkISP1Lsc, Warning)\n-\t\t\t<< \"Tabular LSC data doesn't support resampling\";\n-\t\treturn lscData_;\n-\t}\n-\n-private:\n-\tstd::vector<uint16_t> parseTable(const ValueNode &tuningData,\n-\t\t\t\t\t const char *prop);\n-\n-\tlsc::ComponentsMap lscData_;\n-};\n-\n-int LscTableImpl::parseLscData(const ValueNode &sets)\n-{\n-\tfor (const auto &set : sets.asList()) {\n-\t\tuint32_t ct = set[\"ct\"].get<uint32_t>(0);\n-\n-\t\tif (lscData_.count(ct)) {\n-\t\t\tLOG(RkISP1Lsc, Error)\n-\t\t\t\t<< \"Multiple sets found for color temperature \"\n-\t\t\t\t<< ct;\n-\t\t\treturn -EINVAL;\n-\t\t}\n-\n-\t\tlsc::Components components;\n-\t\tcomponents.r = parseTable(set, \"r\");\n-\t\tcomponents.gr = parseTable(set, \"gr\");\n-\t\tcomponents.gb = parseTable(set, \"gb\");\n-\t\tcomponents.b = parseTable(set, \"b\");\n-\n-\t\tif (components.r.empty() || components.gr.empty() ||\n-\t\t    components.gb.empty() || components.b.empty()) {\n-\t\t\tLOG(RkISP1Lsc, Error)\n-\t\t\t\t<< \"Set for color temperature \" << ct\n-\t\t\t\t<< \" is missing tables\";\n-\t\t\treturn -EINVAL;\n-\t\t}\n-\n-\t\tlscData_.emplace(ct, std::move(components));\n-\t}\n-\n-\tif (lscData_.empty()) {\n-\t\tLOG(RkISP1Lsc, Error) << \"Failed to load any sets\";\n-\t\treturn -EINVAL;\n-\t}\n-\n-\treturn 0;\n-}\n-\n-std::vector<uint16_t> LscTableImpl::parseTable(const ValueNode &tuningData,\n-\t\t\t\t\t\t const char *prop)\n-{\n-\tstatic constexpr unsigned int kLscNumSamples =\n-\t\tRKISP1_CIF_ISP_LSC_SAMPLES_MAX * RKISP1_CIF_ISP_LSC_SAMPLES_MAX;\n-\n-\tstd::vector<uint16_t> table =\n-\t\ttuningData[prop].get<std::vector<uint16_t>>().value_or(utils::defopt);\n-\tif (table.size() != kLscNumSamples) {\n-\t\tLOG(RkISP1Lsc, Error)\n-\t\t\t<< \"Invalid '\" << prop << \"' values: expected \"\n-\t\t\t<< kLscNumSamples\n-\t\t\t<< \" elements, got \" << table.size();\n-\t\treturn {};\n-\t}\n-\n-\treturn table;\n-}\n-\n std::vector<double> parseSizes(const ValueNode &tuningData,\n \t\t\t       const char *prop)\n {\n@@ -190,7 +113,7 @@ int LensShadingCorrection::init([[maybe_unused]] IPAContext &context,\n \tstd::string type = tuningData[\"type\"].get<std::string>(\"table\");\n \tif (type == \"table\") {\n \t\tLOG(RkISP1Lsc, Debug) << \"Loading tabular LSC data.\";\n-\t\talgo_ = std::make_unique<LscTableImpl>();\n+\t\talgo_ = std::make_unique<LscTable>();\n \t\tret = algo_->parseLscData(sets);\n \t} else if (type == \"polynomial\") {\n \t\tLOG(RkISP1Lsc, Debug) << \"Loading polynomial LSC data.\";\n","prefixes":["v4","17/35"]}