Patch Detail
Show a patch.
GET /api/1.1/patches/21256/?format=api
{ "id": 21256, "url": "https://patchwork.libcamera.org/api/1.1/patches/21256/?format=api", "web_url": "https://patchwork.libcamera.org/patch/21256/", "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": "<20240913075750.35115-8-stefan.klug@ideasonboard.com>", "date": "2024-09-13T07:57:25", "name": "[v2,7/9] ipa: libipa: Add lsc polynomial class", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "f83ae17972aca445767ce77c2d43f0df02b411eb", "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/21256/mbox/", "series": [ { "id": 4587, "url": "https://patchwork.libcamera.org/api/1.1/series/4587/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4587", "date": "2024-09-13T07:57:18", "name": "Implement polynomial lsc support", "version": 2, "mbox": "https://patchwork.libcamera.org/series/4587/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/21256/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/21256/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 D83E9C324C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 13 Sep 2024 07:58:16 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 88B3C6350A;\n\tFri, 13 Sep 2024 09:58:16 +0200 (CEST)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 58C216350C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 13 Sep 2024 09:58:13 +0200 (CEST)", "from ideasonboard.com (213-229-8-243.static.upcbusiness.at\n\t[213.229.8.243])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 56A535A5;\n\tFri, 13 Sep 2024 09:56:54 +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=\"IrFMZqik\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1726214214;\n\tbh=iED+IJGiCgic69/fCg92a8nSNxF/IcTI1qcNqQjkSCk=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=IrFMZqikgQwG9uN7YBA+R33i0TuOx0bddlr+dRaHqgpk+5g6RSTHn7Kx2iIjo2NWM\n\tkDSpwqJBt/Yt/nlmUoliugONjrSKAZPQfqjPdAArMVGukMAMzePHuJq8WlYvFIHDaw\n\tOx3/SkDSymb5h4xFCgbXYQvSD0ENP3g3PdJIqcEg=", "From": "Stefan Klug <stefan.klug@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Cc": "Stefan Klug <stefan.klug@ideasonboard.com>", "Subject": "[PATCH v2 7/9] ipa: libipa: Add lsc polynomial class", "Date": "Fri, 13 Sep 2024 09:57:25 +0200", "Message-ID": "<20240913075750.35115-8-stefan.klug@ideasonboard.com>", "X-Mailer": "git-send-email 2.43.0", "In-Reply-To": "<20240913075750.35115-1-stefan.klug@ideasonboard.com>", "References": "<20240913075750.35115-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 basic class to represent polynomials as specified in the DNG spec\nfor vignetting correction.\n\nSigned-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n---\n src/ipa/libipa/lsc_polynomial.cpp | 81 +++++++++++++++++++++++\n src/ipa/libipa/lsc_polynomial.h | 104 ++++++++++++++++++++++++++++++\n src/ipa/libipa/meson.build | 2 +\n 3 files changed, 187 insertions(+)\n create mode 100644 src/ipa/libipa/lsc_polynomial.cpp\n create mode 100644 src/ipa/libipa/lsc_polynomial.h", "diff": "diff --git a/src/ipa/libipa/lsc_polynomial.cpp b/src/ipa/libipa/lsc_polynomial.cpp\nnew file mode 100644\nindex 000000000000..abbbcb6a724c\n--- /dev/null\n+++ b/src/ipa/libipa/lsc_polynomial.cpp\n@@ -0,0 +1,81 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2024, Ideas On Board\n+ *\n+ * Polynomal class to represent lens shading correction\n+ */\n+\n+#include \"lsc_polynomial.h\"\n+\n+#include <libcamera/base/log.h>\n+\n+/**\n+ * \\file lsc_polynomial.h\n+ * \\brief LscPolynomial class\n+ */\n+\n+namespace libcamera {\n+\n+LOG_DEFINE_CATEGORY(LscPolynomial)\n+\n+namespace ipa {\n+\n+/**\n+ * \\class LscPolynomial\n+ * \\brief Class for handling even polynomial used in lens shading correction\n+ *\n+ * Shading artifacts of camera lenses can be modeled using even radial\n+ * polynomials. This class implements a polynomial with 5 coefficients which\n+ * follows the definition of the FixVignetteRadial opcode in the Adobe DNG\n+ * specification.\n+ */\n+\n+/**\n+ * \\fn LscPolynomial::LscPolynomial(double cx = 0.0, double cy = 0.0, double k0 = 0.0,\n+\t\t double k1 = 0.0, double k2 = 0.0, double k3 = 0.0,\n+\t\t double k4 = 0.0)\n+ * \\brief Construct a polynomial using the given coefficients\n+ * \\param cx Center-x relative to the image in normalized coordinates (0..1)\n+ * \\param cy Center-y relative to the image in normalized coordinates (0..1)\n+ * \\param k0 Coefficient of the polynomial\n+ * \\param k1 Coefficient of the polynomial\n+ * \\param k2 Coefficient of the polynomial\n+ * \\param k3 Coefficient of the polynomial\n+ * \\param k4 Coefficient of the polynomial\n+ */\n+\n+/**\n+ * \\fn LscPolynomial::sampleAtNormalizedPixelPos(double x, double y)\n+ * \\brief Sample the polynomial at the given normalized pixel position\n+ *\n+ * This functions samples the polynomial at the given pixel position divided by\n+ * the value returned by getM().\n+ *\n+ * \\param x x position in normalized coordinates\n+ * \\param y y position in normalized coordinates\n+ * \\return The sampled value\n+ */\n+\n+/**\n+ * \\fn LscPolynomial::getM()\n+ * \\brief Get the value m as described in the dng specification\n+ *\n+ * Returns m according to dng spec. m represents the Euclidean distance\n+ * (in pixels) from the optical center to the farthest pixel in the\n+ * image.\n+ *\n+ * \\return The sampled value\n+ */\n+\n+/**\n+ * \\fn LscPolynomial::setReferenceImageSize(const Size &size)\n+ * \\brief Set the reference image size\n+ *\n+ * Set the reference image size that is used for subsequent calls to getM() and\n+ * sampleAtNormalizedPixelPos()\n+ *\n+ * \\param size THe size of the reference image\n+ */\n+\n+} // namespace ipa\n+} // namespace libcamera\ndiff --git a/src/ipa/libipa/lsc_polynomial.h b/src/ipa/libipa/lsc_polynomial.h\nnew file mode 100644\nindex 000000000000..890199017590\n--- /dev/null\n+++ b/src/ipa/libipa/lsc_polynomial.h\n@@ -0,0 +1,104 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2024, Ideas On Board\n+ *\n+ * Helper for radial polynomial used in lens shading correction.\n+ */\n+#pragma once\n+\n+#include <algorithm>\n+#include <array>\n+#include <assert.h>\n+#include <cmath>\n+\n+#include <libcamera/base/log.h>\n+#include <libcamera/base/span.h>\n+\n+#include \"libcamera/internal/yaml_parser.h\"\n+\n+namespace libcamera {\n+\n+LOG_DECLARE_CATEGORY(LscPolynomial)\n+\n+namespace ipa {\n+\n+class LscPolynomial\n+{\n+public:\n+\tLscPolynomial(double cx = 0.0, double cy = 0.0, double k0 = 0.0,\n+\t\t double k1 = 0.0, double k2 = 0.0, double k3 = 0.0,\n+\t\t double k4 = 0.0)\n+\t\t: cx_(cx), cy_(cy),\n+\t\t coefficients_({ k0, k1, k2, k3, k4 })\n+\t{\n+\t}\n+\n+\tdouble sampleAtNormalizedPixelPos(double x, double y) const\n+\t{\n+\t\tdouble dx = x - cnx_;\n+\t\tdouble dy = y - cny_;\n+\t\tdouble r = sqrt(dx * dx + dy * dy);\n+\t\tdouble res = 1.0;\n+\t\tfor (unsigned int i = 0; i < coefficients_.size(); i++) {\n+\t\t\tres += coefficients_[i] * std::pow(r, (i + 1) * 2);\n+\t\t}\n+\t\treturn res;\n+\t}\n+\n+\tdouble getM() const\n+\t{\n+\t\tdouble cpx = imageSize_.width * cx_;\n+\t\tdouble cpy = imageSize_.height * cy_;\n+\t\tdouble mx = std::max(cpx, std::fabs(imageSize_.width - cpx));\n+\t\tdouble my = std::max(cpy, std::fabs(imageSize_.height - cpy));\n+\n+\t\treturn sqrt(mx * mx + my * my);\n+\t}\n+\n+\tvoid setReferenceImageSize(const Size &size)\n+\t{\n+\t\timageSize_ = size;\n+\n+\t\t/* Calculate normalized centers */\n+\t\tdouble m = getM();\n+\t\tcnx_ = (size.width * cx_) / m;\n+\t\tcny_ = (size.height * cy_) / m;\n+\t}\n+\n+private:\n+\tdouble cx_;\n+\tdouble cy_;\n+\tdouble cnx_;\n+\tdouble cny_;\n+\tstd::array<double, 5> coefficients_;\n+\n+\tSize imageSize_;\n+};\n+\n+} /* namespace ipa */\n+\n+#ifndef __DOXYGEN__\n+\n+template<>\n+struct YamlObject::Getter<ipa::LscPolynomial> {\n+\tstd::optional<ipa::LscPolynomial> get(const YamlObject &obj) const\n+\t{\n+\t\tstd::optional<double> cx = obj[\"cx\"].get<double>();\n+\t\tstd::optional<double> cy = obj[\"cy\"].get<double>();\n+\t\tstd::optional<double> k0 = obj[\"k0\"].get<double>();\n+\t\tstd::optional<double> k1 = obj[\"k1\"].get<double>();\n+\t\tstd::optional<double> k2 = obj[\"k2\"].get<double>();\n+\t\tstd::optional<double> k3 = obj[\"k3\"].get<double>();\n+\t\tstd::optional<double> k4 = obj[\"k4\"].get<double>();\n+\n+\t\tif (!(cx && cy && k0 && k1 && k2 && k3 && k4))\n+\t\t\tLOG(LscPolynomial, Error)\n+\t\t\t\t<< \"Polynomial is missing a parameter\";\n+\n+\t\treturn ipa::LscPolynomial(*cx, *cy, *k0, *k1, *k2, *k3, *k4);\n+\t}\n+};\n+\n+#endif\n+\n+} /* namespace libcamera */\ndiff --git a/src/ipa/libipa/meson.build b/src/ipa/libipa/meson.build\nindex 3740178b2909..e78cbcd63633 100644\n--- a/src/ipa/libipa/meson.build\n+++ b/src/ipa/libipa/meson.build\n@@ -8,6 +8,7 @@ libipa_headers = files([\n 'fc_queue.h',\n 'histogram.h',\n 'interpolator.h',\n+ 'lsc_polynomial.h',\n 'matrix.h',\n 'module.h',\n 'pwl.h',\n@@ -22,6 +23,7 @@ libipa_sources = files([\n 'fc_queue.cpp',\n 'histogram.cpp',\n 'interpolator.cpp',\n+ 'lsc_polynomial.cpp',\n 'matrix.cpp',\n 'module.cpp',\n 'pwl.cpp',\n", "prefixes": [ "v2", "7/9" ] }