Show a patch.

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

{
    "id": 22070,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/22070/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/22070/",
    "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": "<20241125151430.2437285-4-stefan.klug@ideasonboard.com>",
    "date": "2024-11-25T15:14:12",
    "name": "[v2,3/8] libcamera: geometry: Add Rectangle::transformedBetween()",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "38aafa28cee053045da69adba1857f342af226fd",
    "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/22070/mbox/",
    "series": [
        {
            "id": 4818,
            "url": "https://patchwork.libcamera.org/api/1.1/series/4818/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4818",
            "date": "2024-11-25T15:14:09",
            "name": "rkisp1: Fix aspect ratio and ScalerCrop",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/4818/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/22070/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/22070/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 9E208C32A3\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 25 Nov 2024 15:14:46 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 57A846602C;\n\tMon, 25 Nov 2024 16:14:46 +0100 (CET)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id EFDE165FE3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 25 Nov 2024 16:14:42 +0100 (CET)",
            "from ideasonboard.com (unknown\n\t[IPv6:2a00:6020:448c:6c00:4cf:a935:de6f:a329])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 4B07B6B5;\n\tMon, 25 Nov 2024 16:14:21 +0100 (CET)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"m3/DmxC3\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1732547661;\n\tbh=PFLFr1z8SrdYOryUAxh70oJ0WUiBhP33FFItw/qivV0=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=m3/DmxC3M2cOA+SeTr2uDIDs9mY8kZsmYSvldybG76HEhYt9y8B1WozOf9c9WPdA3\n\tkpU+tSnAvLWRD1fLE5wp/zFppwE6RvcezEIU4arsN0Bfa/5XuYOWKqtFK378JU0IaV\n\teZfdjFVcFR6lwvU9m8N2ptDUgLnbagvUpUOhisJg=",
        "From": "Stefan Klug <stefan.klug@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "Stefan Klug <stefan.klug@ideasonboard.com>,\n\tPaul Elder <paul.elder@ideasonboard.com>",
        "Subject": "[PATCH v2 3/8] libcamera: geometry: Add\n\tRectangle::transformedBetween()",
        "Date": "Mon, 25 Nov 2024 16:14:12 +0100",
        "Message-ID": "<20241125151430.2437285-4-stefan.klug@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.43.0",
        "In-Reply-To": "<20241125151430.2437285-1-stefan.klug@ideasonboard.com>",
        "References": "<20241125151430.2437285-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": "Handling cropping and scaling within a complicated pipeline involves\ntransformations of rectangles between different coordinate systems. For\nexample the full input of the dewarper (0,0)/1920x1080 might correspond\nto the rectangle (0, 243)/2592x1458 in sensor coordinates (of a\n2592x1944 sensor). Add a function that allows the transformation of a\nrectangle defined in one reference frame (dewarper) into the coordinates\nof a second reference frame (sensor).\n\nSigned-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\nReviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n\n---\nChanges in v2:\n- Renamed mappedBetween() to transformedBetween()\n- Improved documentation\n- Collected tags\n---\n include/libcamera/geometry.h |  3 +++\n src/libcamera/geometry.cpp   | 37 ++++++++++++++++++++++++++++++++++++\n 2 files changed, 40 insertions(+)",
    "diff": "diff --git a/include/libcamera/geometry.h b/include/libcamera/geometry.h\nindex 9ca5865a3d0d..e5f0a843d314 100644\n--- a/include/libcamera/geometry.h\n+++ b/include/libcamera/geometry.h\n@@ -299,6 +299,9 @@ public:\n \t__nodiscard Rectangle scaledBy(const Size &numerator,\n \t\t\t\t       const Size &denominator) const;\n \t__nodiscard Rectangle translatedBy(const Point &point) const;\n+\n+\tRectangle transformedBetween(const Rectangle &source,\n+\t\t\t\t     const Rectangle &target) const;\n };\n \n bool operator==(const Rectangle &lhs, const Rectangle &rhs);\ndiff --git a/src/libcamera/geometry.cpp b/src/libcamera/geometry.cpp\nindex 90ccf8c19f97..2c9308cb25ee 100644\n--- a/src/libcamera/geometry.cpp\n+++ b/src/libcamera/geometry.cpp\n@@ -837,6 +837,43 @@ Rectangle Rectangle::translatedBy(const Point &point) const\n \treturn { x + point.x, y + point.y, width, height };\n }\n \n+/**\n+ * \\brief Transforms a Rectangle from one reference frame to another\n+ * \\param[in] source The \\a source reference frame\n+ * \\param[in] destination The \\a destination reference frame\n+ *\n+ * The params source and destinations specify two reference frames for the same\n+ * data. The rectangle is translated from the source reference frame into the\n+ * destination reference frame.\n+ *\n+ * For example, consider a sensor with a resolution of 4040x2360 pixels and a\n+ * assume a rectangle of (100, 100)/3840x2160 (sensorFrame) in sensor\n+ * coordinates is mapped to a rectangle (0,0)/(1920,1080) (displayFrame) in\n+ * display coordinates. This function can be used to transform an arbitrary\n+ * rectangle from display coordinates to sensor coordinates or vice versa:\n+ *\n+ * \\code{.cpp}\n+ * // Bottom right quarter in sensor coordinates\n+ * Rectangle sensorRect(2020, 100, 1920, 1080);\n+ * displayRect = sensorRect.transformedBetween(sensorFrame, displayFrame);\n+ * // displayRect is now (960, 540)/960x540\n+ * sensorRect = displayRect.transformedBetween(displayFrame, sensorFrame);\n+ * \\endcode\n+ */\n+Rectangle Rectangle::transformedBetween(const Rectangle &source,\n+\t\t\t\t\tconst Rectangle &destination) const\n+{\n+\tRectangle r;\n+\tdouble sx = static_cast<double>(destination.width) / source.width;\n+\tdouble sy = static_cast<double>(destination.height) / source.height;\n+\n+\tr.x = static_cast<int>((x - source.x) * sx) + destination.x;\n+\tr.y = static_cast<int>((y - source.y) * sy) + destination.y;\n+\tr.width = static_cast<int>(width * sx);\n+\tr.height = static_cast<int>(height * sy);\n+\treturn r;\n+}\n+\n /**\n  * \\brief Compare rectangles for equality\n  * \\return True if the two rectangles are equal, false otherwise\n",
    "prefixes": [
        "v2",
        "3/8"
    ]
}