Show a patch.

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

{
    "id": 24527,
    "url": "https://patchwork.libcamera.org/api/patches/24527/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/24527/",
    "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": "<20250930122726.1837524-29-stefan.klug@ideasonboard.com>",
    "date": "2025-09-30T12:26:49",
    "name": "[v1,28/33] libcamera: dw100_vertexmap: Implement parametric dewarping",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "ead0cec0feb01ed56cc35fcdd57fe73a7a0ff09d",
    "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/24527/mbox/",
    "series": [
        {
            "id": 5468,
            "url": "https://patchwork.libcamera.org/api/series/5468/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=5468",
            "date": "2025-09-30T12:26:21",
            "name": "Full dewarper support on imx8mp",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/5468/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/24527/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/24527/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 0BC29C328C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 30 Sep 2025 13:32:02 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id ABB676B5F0;\n\tTue, 30 Sep 2025 15:32:01 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 366626B599\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 30 Sep 2025 15:31:59 +0200 (CEST)",
            "from ideasonboard.com (unknown [94.31.94.171])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id F3C7E16A;\n\tTue, 30 Sep 2025 15:30:30 +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=\"Ox2pzvk+\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1759239031;\n\tbh=ik1IurfUDpB0uQeOKgQlWDtvXgq2Tn5bYtZcu9frmRo=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=Ox2pzvk+ubytkKJwdyZKMvX2oidZxP3+ICCJggwaPa3hN9hrXQPxojB+Fc5ItlNaf\n\tCIuQqZfPtQpHQ+zhrTWxp4NHItZhi7VIMmVJ1jSrWT7qulHidhbV910+urTX6zPe5l\n\t3jcXKsubXpCBBb1alPXnMLfnrUurH1uI0reHry5k=",
        "From": "Stefan Klug <stefan.klug@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "Stefan Klug <stefan.klug@ideasonboard.com>",
        "Subject": "[PATCH v1 28/33] libcamera: dw100_vertexmap: Implement parametric\n\tdewarping",
        "Date": "Tue, 30 Sep 2025 14:26:49 +0200",
        "Message-ID": "<20250930122726.1837524-29-stefan.klug@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.48.1",
        "In-Reply-To": "<20250930122726.1837524-1-stefan.klug@ideasonboard.com>",
        "References": "<20250930122726.1837524-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": "Implement functions to allow lens dewarping based on the common lens\ndewarp model used e.g. by OpenCV\n\nSee https://docs.opencv.org/3.4/da/d54/group__imgproc__transform.html#ga7dfb72c9cf9780a347fbe3d1c47e5d5a\n\nSigned-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n---\n .../converter/converter_dw100_vertexmap.h     | 17 ++++\n .../converter/converter_dw100_vertexmap.cpp   | 87 +++++++++++++++++++\n 2 files changed, 104 insertions(+)",
    "diff": "diff --git a/include/libcamera/internal/converter/converter_dw100_vertexmap.h b/include/libcamera/internal/converter/converter_dw100_vertexmap.h\nindex 9c6e0ffa4513..7a12c4cb7a50 100644\n--- a/include/libcamera/internal/converter/converter_dw100_vertexmap.h\n+++ b/include/libcamera/internal/converter/converter_dw100_vertexmap.h\n@@ -12,6 +12,9 @@\n #include <libcamera/geometry.h>\n #include <libcamera/transform.h>\n \n+#include \"libcamera/internal/matrix.h\"\n+#include \"libcamera/internal/vector.h\"\n+\n namespace libcamera {\n \n class Dw100VertexMap\n@@ -57,11 +60,20 @@ public:\n \tvoid setMode(const ScaleMode mode) { mode_ = mode; }\n \tScaleMode mode() const { return mode_; }\n \n+\tint loadDewarpParams(const YamlObject &dict);\n+\tint setDewarpParams(const Matrix<double, 3, 3> &cm, const Span<const double> &coeffs);\n+\tbool dewarpParamsValid() { return dewarpParamsValid_; }\n+\n+\tvoid setLensDewarpEnable(bool enable) { lensDewarpEnable_ = enable; }\n+\tbool lensDewarpEnable() { return lensDewarpEnable_; }\n+\n \tstd::vector<uint32_t> getVertexMap();\n \n private:\n \tint getVerticesForLength(const int length);\n \n+\tVector<double, 2> dewarpPoint(const Vector<double, 2> &p);\n+\n \tRectangle scalerCrop_;\n \tRectangle sensorCrop_;\n \tTransform transform_ = Transform::Identity;\n@@ -75,6 +87,11 @@ private:\n \tdouble effectiveScaleY_;\n \tPoint effectiveOffset_;\n \tRectangle effectiveScalerCrop_;\n+\n+\tMatrix<double, 3, 3> dewarpM_ = Matrix<double, 3, 3>::identity();\n+\tstd::array<double, 12> dewarpCoeffs_;\n+\tbool lensDewarpEnable_ = true;\n+\tbool dewarpParamsValid_ = false;\n };\n \n } /* namespace libcamera */\ndiff --git a/src/libcamera/converter/converter_dw100_vertexmap.cpp b/src/libcamera/converter/converter_dw100_vertexmap.cpp\nindex 10d9e34d98c5..5581d53e57c7 100644\n--- a/src/libcamera/converter/converter_dw100_vertexmap.cpp\n+++ b/src/libcamera/converter/converter_dw100_vertexmap.cpp\n@@ -66,6 +66,14 @@ Vector2d point2Vec2d(const Point &p)\n \treturn { { static_cast<double>(p.x), static_cast<double>(p.y) } };\n }\n \n+void transformPoint(const Rectangle &from, const Rectangle &to, Vector2d &p)\n+{\n+\tdouble sx = to.width / static_cast<double>(from.width);\n+\tdouble sy = to.height / static_cast<double>(from.height);\n+\tp.x() = (p.x() - from.x) * sx + to.x;\n+\tp.y() = (p.y() - from.y) * sy + to.y;\n+}\n+\n } /* namespace */\n \n /**\n@@ -344,6 +352,17 @@ std::vector<uint32_t> Dw100VertexMap::getVertexMap()\n \t\t\tp.x() += localScalerCrop.x;\n \t\t\tp.y() += localScalerCrop.y;\n \n+\t\t\tif (dewarpParamsValid_ && lensDewarpEnable_) {\n+\t\t\t\t/*\n+\t\t\t\t * We are in localScalerCrop coordinates.\n+\t\t\t\t * Tranform to sensor coordinates.\n+\t\t\t\t */\n+\t\t\t\ttransformPoint(localScalerCrop, effectiveScalerCrop_, p);\n+\t\t\t\tp = dewarpPoint(p);\n+\t\t\t\t/* tarnsform back to localScalerCrop */\n+\t\t\t\ttransformPoint(effectiveScalerCrop_, localScalerCrop, p);\n+\t\t\t}\n+\n \t\t\t/* Convert to fixed point */\n \t\t\tuint32_t v = static_cast<uint32_t>(p.y() * 16) << 16 |\n \t\t\t\t     (static_cast<uint32_t>(p.x() * 16) & 0xffff);\n@@ -354,6 +373,74 @@ std::vector<uint32_t> Dw100VertexMap::getVertexMap()\n \treturn res;\n }\n \n+int Dw100VertexMap::loadDewarpParams(const YamlObject &dict)\n+{\n+\tMatrix<double, 3, 3> m;\n+\tconst auto &cm = dict[\"cm\"].get<Matrix<double, 3, 3>>();\n+\tif (!cm) {\n+\t\tLOG(Converter, Error) << \"Dewarp parameters are missing 'cm' value\";\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tm = *cm;\n+\n+\tconst auto &coeffs = dict[\"coefficients\"].getList<double>();\n+\tif (!coeffs) {\n+\t\tLOG(Converter, Error) << \"Dewarp parameters 'coefficients' value is not a list\";\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tconst Span<const double> span{ *coeffs };\n+\treturn setDewarpParams(m, span);\n+}\n+\n+int Dw100VertexMap::setDewarpParams(const Matrix<double, 3, 3> &cm, const Span<const double> &coeffs)\n+{\n+\tdewarpM_ = cm;\n+\tdewarpCoeffs_.fill(0.0);\n+\n+\tif (coeffs.size() != 4 && coeffs.size() != 5 &&\n+\t    coeffs.size() != 8 && coeffs.size() != 12) {\n+\t\tLOG(Converter, Error) << \"Dewarp 'coefficients' must have 4, 5, 8 or 12 values\";\n+\t\tdewarpParamsValid_ = false;\n+\t\treturn -EINVAL;\n+\t}\n+\tstd::copy(coeffs.begin(), coeffs.end(), dewarpCoeffs_.begin());\n+\n+\tdewarpParamsValid_ = true;\n+\treturn 0;\n+}\n+\n+Vector2d Dw100VertexMap::dewarpPoint(const Vector2d &p)\n+{\n+\tdouble x, y;\n+\tdouble k1 = dewarpCoeffs_[0];\n+\tdouble k2 = dewarpCoeffs_[1];\n+\tdouble p1 = dewarpCoeffs_[2];\n+\tdouble p2 = dewarpCoeffs_[3];\n+\tdouble k3 = dewarpCoeffs_[4];\n+\tdouble k4 = dewarpCoeffs_[5];\n+\tdouble k5 = dewarpCoeffs_[6];\n+\tdouble k6 = dewarpCoeffs_[7];\n+\tdouble s1 = dewarpCoeffs_[8];\n+\tdouble s2 = dewarpCoeffs_[9];\n+\tdouble s3 = dewarpCoeffs_[10];\n+\tdouble s4 = dewarpCoeffs_[11];\n+\n+\ty = (p.y() - dewarpM_[1][2]) / dewarpM_[1][1];\n+\tx = (p.x() - dewarpM_[0][2] - y * dewarpM_[0][1]) / dewarpM_[0][0];\n+\n+\tdouble r2 = x * x + y * y;\n+\tdouble d = (1 + k1 * r2 + k2 * r2 * r2 + k3 * r2 * r2 * r2) /\n+\t\t   (1 + k4 * r2 + k5 * r2 * r2 + k6 * r2 * r2 * r2);\n+\tx = x * d + 2 * p1 * x * y + p2 * (r2 + 2 * x * x) + s1 * r2 + s2 * r2 * r2;\n+\ty = y * d + 2 * p2 * x * y + p1 * (r2 + 2 * y * y) + s3 * r2 + s4 * r2 * r2;\n+\n+\tVector2d ret{ { x * dewarpM_[0][0] + y * dewarpM_[0][1] + dewarpM_[0][2],\n+\t\t\ty * dewarpM_[1][1] + dewarpM_[1][2] } };\n+\treturn ret;\n+}\n+\n int Dw100VertexMap::getVerticesForLength(const int length)\n {\n \treturn (length + kDw100BlockSize - 1) / kDw100BlockSize + 1;\n",
    "prefixes": [
        "v1",
        "28/33"
    ]
}