Patch Detail
Show a patch.
GET /api/1.1/patches/21304/?format=api
{ "id": 21304, "url": "https://patchwork.libcamera.org/api/1.1/patches/21304/?format=api", "web_url": "https://patchwork.libcamera.org/patch/21304/", "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": "<20240920133941.90629-10-stefan.klug@ideasonboard.com>", "date": "2024-09-20T13:39:24", "name": "[v3,9/9] ipa: rkisp1: Add polynomial LSC loader", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "91a663a21c9de66cde812132aec12d39300a3712", "submitter": { "id": 184, "url": "https://patchwork.libcamera.org/api/1.1/people/184/?format=api", "name": "Stefan Klug", "email": "stefan.klug@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/21304/mbox/", "series": [ { "id": 4609, "url": "https://patchwork.libcamera.org/api/1.1/series/4609/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4609", "date": "2024-09-20T13:39:15", "name": "Implement polynomial lsc support", "version": 3, "mbox": "https://patchwork.libcamera.org/series/4609/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/21304/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/21304/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 4CF8DC32D8\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 20 Sep 2024 13:40:19 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 42E8963510;\n\tFri, 20 Sep 2024 15:40:18 +0200 (CEST)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 5DF8C63502\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 20 Sep 2024 15:40:11 +0200 (CEST)", "from ideasonboard.com (unknown\n\t[IPv6:2a00:6020:448c:6c00:8ade:938d:48b1:cede])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 65AF64CE;\n\tFri, 20 Sep 2024 15:38:47 +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=\"aniidPLx\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1726839527;\n\tbh=bL8P88cMLhEykIBRCXzVvPhnOtUJCkIgkJjzYoUkSRA=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=aniidPLxybw/ZkgdQEkU4kHuO8gz6ChiRzREkA/b0Ivh4TuMkTwcKrISjosfyOUbT\n\tdQQVPIoMElQv3qAjh4QT8nNq+yrCmY07gm/0RUSFL3+UYD9TRllUg+RAmYy62kHY/w\n\tCDu5aP0Pq/XjQS3aMgOXXGA+6OnnIZODFMYOS6KE=", "From": "Stefan Klug <stefan.klug@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Cc": "Stefan Klug <stefan.klug@ideasonboard.com>", "Subject": "[PATCH v3 9/9] ipa: rkisp1: Add polynomial LSC loader", "Date": "Fri, 20 Sep 2024 15:39:24 +0200", "Message-ID": "<20240920133941.90629-10-stefan.klug@ideasonboard.com>", "X-Mailer": "git-send-email 2.43.0", "In-Reply-To": "<20240920133941.90629-1-stefan.klug@ideasonboard.com>", "References": "<20240920133941.90629-1-stefan.klug@ideasonboard.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": "Add a loader that is capable of loading polynomial coefficients from the\ntuning files. The polynomial is sampled at load time to reduce the\ncomputational overhead at runtime.\n\nSigned-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n\n---\nChanges in v3:\n- Fixes bug with lsc table beeing rotated by 90 degrees\n- Added documentation on sizesListToPositions()\n- Refactored loader selection code\n---\n src/ipa/rkisp1/algorithms/lsc.cpp | 147 +++++++++++++++++++++++++++++-\n 1 file changed, 145 insertions(+), 2 deletions(-)", "diff": "diff --git a/src/ipa/rkisp1/algorithms/lsc.cpp b/src/ipa/rkisp1/algorithms/lsc.cpp\nindex 44c97f0e1a10..e210b32ff380 100644\n--- a/src/ipa/rkisp1/algorithms/lsc.cpp\n+++ b/src/ipa/rkisp1/algorithms/lsc.cpp\n@@ -16,6 +16,7 @@\n \n #include \"libcamera/internal/yaml_parser.h\"\n \n+#include \"libipa/lsc_polynomial.h\"\n #include \"linux/rkisp1-config.h\"\n \n /**\n@@ -70,6 +71,132 @@ namespace ipa::rkisp1::algorithms {\n \n LOG_DEFINE_CATEGORY(RkISP1Lsc)\n \n+class LscPolynomialLoader\n+{\n+public:\n+\tLscPolynomialLoader(const Size &sensorSize,\n+\t\t\t const Rectangle &cropRectangle,\n+\t\t\t const std::vector<double> &xSizes,\n+\t\t\t const std::vector<double> &ySizes)\n+\t\t: sensorSize_(sensorSize),\n+\t\t cropRectangle_(cropRectangle),\n+\t\t xSizes_(xSizes),\n+\t\t ySizes_(ySizes)\n+\t{\n+\t}\n+\n+\tint parseLscData(const YamlObject &yamlSets,\n+\t\t\t std::map<unsigned int, LensShadingCorrection::Components> &lscData)\n+\t{\n+\t\tconst auto &sets = yamlSets.asList();\n+\t\tfor (const auto &yamlSet : sets) {\n+\t\t\tstd::optional<LscPolynomial> pr, pgr, pgb, pb;\n+\t\t\tuint32_t ct = yamlSet[\"ct\"].get<uint32_t>(0);\n+\n+\t\t\tif (lscData.count(ct)) {\n+\t\t\t\tLOG(RkISP1Lsc, Error)\n+\t\t\t\t\t<< \"Multiple sets found for \"\n+\t\t\t\t\t<< \"color temperature \" << ct;\n+\t\t\t\treturn -EINVAL;\n+\t\t\t}\n+\n+\t\t\tLensShadingCorrection::Components &set = lscData[ct];\n+\t\t\tpr = yamlSet[\"r\"].get<LscPolynomial>();\n+\t\t\tpgr = yamlSet[\"gr\"].get<LscPolynomial>();\n+\t\t\tpgb = yamlSet[\"gb\"].get<LscPolynomial>();\n+\t\t\tpb = yamlSet[\"b\"].get<LscPolynomial>();\n+\n+\t\t\tif (!(pr || pgr || pgb || pb)) {\n+\t\t\t\tLOG(RkISP1Lsc, Error)\n+\t\t\t\t\t<< \"Failed to parse polynomial for \"\n+\t\t\t\t\t<< \"colour temperature \" << ct;\n+\t\t\t\treturn -EINVAL;\n+\t\t\t}\n+\n+\t\t\tset.ct = ct;\n+\t\t\tpr->setReferenceImageSize(sensorSize_);\n+\t\t\tpgr->setReferenceImageSize(sensorSize_);\n+\t\t\tpgb->setReferenceImageSize(sensorSize_);\n+\t\t\tpb->setReferenceImageSize(sensorSize_);\n+\t\t\tset.r = samplePolynomial(*pr);\n+\t\t\tset.gr = samplePolynomial(*pgr);\n+\t\t\tset.gb = samplePolynomial(*pgb);\n+\t\t\tset.b = samplePolynomial(*pb);\n+\t\t}\n+\n+\t\tif (lscData.empty()) {\n+\t\t\tLOG(RkISP1Lsc, Error) << \"Failed to load any sets\";\n+\t\t\treturn -EINVAL;\n+\t\t}\n+\n+\t\treturn 0;\n+\t}\n+\n+private:\n+\t/*\n+\t * The lsc grid has custom spacing defined on half the range (see\n+\t * parseSizes() for details). For easier handling this function converts\n+\t * the spaces vector to positions and mirrors them. E.g.:\n+\t *\n+\t * input: | 0.2 | 0.3 |\n+\t * output: 0.0 0.2 0.5 0.8 1.0\n+\t */\n+\tstd::vector<double> sizesListToPositions(const std::vector<double> &sizes)\n+\t{\n+\t\tconst int half = sizes.size();\n+\t\tstd::vector<double> res(half * 2 + 1);\n+\t\tdouble x = 0.0;\n+\n+\t\tres[half] = 0.5;\n+\t\tfor (int i = 1; i <= half; i++) {\n+\t\t\tx += sizes[half - i];\n+\t\t\tres[half - i] = 0.5 - x;\n+\t\t\tres[half + i] = 0.5 + x;\n+\t\t}\n+\n+\t\treturn res;\n+\t}\n+\n+\tstd::vector<uint16_t> samplePolynomial(const LscPolynomial &poly)\n+\t{\n+\t\tconstexpr int k = RKISP1_CIF_ISP_LSC_SAMPLES_MAX;\n+\n+\t\tdouble m = poly.getM();\n+\t\tdouble x0 = cropRectangle_.x / m;\n+\t\tdouble y0 = cropRectangle_.y / m;\n+\t\tdouble w = cropRectangle_.width / m;\n+\t\tdouble h = cropRectangle_.height / m;\n+\t\tstd::vector<uint16_t> res;\n+\n+\t\tassert(xSizes_.size() * 2 + 1 == k);\n+\t\tassert(ySizes_.size() * 2 + 1 == k);\n+\n+\t\tres.reserve(k * k);\n+\n+\t\tstd::vector<double> xPos(sizesListToPositions(xSizes_));\n+\t\tstd::vector<double> yPos(sizesListToPositions(ySizes_));\n+\n+\t\tfor (int y = 0; y < k; y++) {\n+\t\t\tfor (int x = 0; x < k; x++) {\n+\t\t\t\tdouble xp = x0 + xPos[x] * w;\n+\t\t\t\tdouble yp = y0 + yPos[y] * h;\n+\t\t\t\tint v = static_cast<int>(\n+\t\t\t\t\tpoly.sampleAtNormalizedPixelPos(xp, yp) *\n+\t\t\t\t\t1024);\n+\n+\t\t\t\tv = std::min(std::max(v, 1024), 4095);\n+\t\t\t\tres.push_back(v);\n+\t\t\t}\n+\t\t}\n+\t\treturn res;\n+\t}\n+\n+\tSize sensorSize_;\n+\tRectangle cropRectangle_;\n+\tconst std::vector<double> &xSizes_;\n+\tconst std::vector<double> &ySizes_;\n+};\n+\n class LscTableLoader\n {\n public:\n@@ -192,8 +319,24 @@ int LensShadingCorrection::init([[maybe_unused]] IPAContext &context,\n \n \tstd::map<unsigned int, Components> lscData;\n \tint res = 0;\n-\tauto loader = LscTableLoader();\n-\tres = loader.parseLscData(yamlSets, lscData);\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\tauto loader = LscTableLoader();\n+\t\tres = loader.parseLscData(yamlSets, lscData);\n+\t} else if (type == \"polynomial\") {\n+\t\tLOG(RkISP1Lsc, Debug) << \"Loading polynomial LSC data.\";\n+\t\tauto loader = LscPolynomialLoader(context.sensorInfo.activeAreaSize,\n+\t\t\t\t\t\t context.sensorInfo.analogCrop,\n+\t\t\t\t\t\t xSize_,\n+\t\t\t\t\t\t ySize_);\n+\t\tres = loader.parseLscData(yamlSets, lscData);\n+\t} else {\n+\t\tLOG(RkISP1Lsc, Error) << \"Unsupported LSC data type '\"\n+\t\t\t\t << type << \"'\";\n+\t\tres = -EINVAL;\n+\t}\n+\n \tif (res)\n \t\treturn res;\n \n", "prefixes": [ "v3", "9/9" ] }