Show a patch.

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

{
    "id": 21302,
    "url": "https://patchwork.libcamera.org/api/patches/21302/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/21302/",
    "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": "<20240920133941.90629-8-stefan.klug@ideasonboard.com>",
    "date": "2024-09-20T13:39:22",
    "name": "[v3,7/9] ipa: libipa: Add lsc polynomial class",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "4576b4b2b0dfac069cc3ae413fb5c28282199377",
    "submitter": {
        "id": 184,
        "url": "https://patchwork.libcamera.org/api/people/184/?format=api",
        "name": "Stefan Klug",
        "email": "stefan.klug@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/21302/mbox/",
    "series": [
        {
            "id": 4609,
            "url": "https://patchwork.libcamera.org/api/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/21302/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/21302/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 4E117C3257\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 20 Sep 2024 13:40:14 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id EA07E63509;\n\tFri, 20 Sep 2024 15:40:13 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 09B1663509\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 20 Sep 2024 15:40:05 +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 156EF8D4;\n\tFri, 20 Sep 2024 15:38:41 +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=\"QezgWwBu\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1726839521;\n\tbh=QY84XvVsQpnLAl0zHcYpr4dVqavgW9DRNFbhQ8Dt8+k=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=QezgWwBuJOE15p6TRZmcCvZLcUawXinF9WtvjlCjD1W0pOs8IJJvpicOzHV3F1CFa\n\t/eTgxMGZlp+FqdK7MFlF11unKnPfpfcjwEP0szUeVw0iyPusuuwDvGbp+baocGzzgV\n\twnnwsPlICrwWeuLxn/SAj9CfPaY6Jlk0BGOQ2lWo=",
        "From": "Stefan Klug <stefan.klug@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "Stefan Klug <stefan.klug@ideasonboard.com>,\n\tKieran Bingham <kieran.bingham@ideasonboard.com>",
        "Subject": "[PATCH v3 7/9] ipa: libipa: Add lsc polynomial class",
        "Date": "Fri, 20 Sep 2024 15:39:22 +0200",
        "Message-ID": "<20240920133941.90629-8-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 basic class to represent polynomials as specified in the DNG spec\nfor vignetting correction.\n\nSigned-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n---\n\nChanges in v3:\n- Fixed typos\n- Fixed unintialized variables\n- Collected tags\n---\n src/ipa/libipa/lsc_polynomial.cpp |  81 +++++++++++++++++++++++\n src/ipa/libipa/lsc_polynomial.h   | 105 ++++++++++++++++++++++++++++++\n src/ipa/libipa/meson.build        |   2 +\n 3 files changed, 188 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..f607d86c54c3\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+ * Polynomial 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 polynomials 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..c898faeb13db\n--- /dev/null\n+++ b/src/ipa/libipa/lsc_polynomial.h\n@@ -0,0 +1,105 @@\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), cnx_(0), cny_(0),\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\tassert(!size.isNull());\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": [
        "v3",
        "7/9"
    ]
}