Show a patch.

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

{
    "id": 23948,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/23948/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/23948/",
    "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": "<20250724152936.99830-2-mzamazal@redhat.com>",
    "date": "2025-07-24T15:29:35",
    "name": "[v2,1/2] libcamera: geometry: Add Rectangle::croppedBy",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "791e4a0d55588a13a76da1f07d42a534ccf9eb2e",
    "submitter": {
        "id": 177,
        "url": "https://patchwork.libcamera.org/api/1.1/people/177/?format=api",
        "name": "Milan Zamazal",
        "email": "mzamazal@redhat.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/23948/mbox/",
    "series": [
        {
            "id": 5324,
            "url": "https://patchwork.libcamera.org/api/1.1/series/5324/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=5324",
            "date": "2025-07-24T15:29:34",
            "name": "Reduce statistics image area for GPU",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/5324/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/23948/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/23948/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 9B5A6C3237\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 24 Jul 2025 15:29:54 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 4728F6911B;\n\tThu, 24 Jul 2025 17:29:54 +0200 (CEST)",
            "from us-smtp-delivery-124.mimecast.com\n\t(us-smtp-delivery-124.mimecast.com [170.10.129.124])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 9D33F69111\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 24 Jul 2025 17:29:50 +0200 (CEST)",
            "from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com\n\t(ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63])\n\tby relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3,\n\tcipher=TLS_AES_256_GCM_SHA384) id us-mta-61-JaNl7-4HOTC8n0sBdV1g6Q-1;\n\tThu, 24 Jul 2025 11:29:47 -0400",
            "from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com\n\t(mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\tkey-exchange X25519 server-signature RSA-PSS (2048 bits)\n\tserver-digest SHA256) (No client certificate requested)\n\tby mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix)\n\twith ESMTPS id 6C234195FD06; Thu, 24 Jul 2025 15:29:46 +0000 (UTC)",
            "from mzamazal-thinkpadp1gen7.tpbc.com (unknown [10.44.32.255])\n\tby mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix)\n\twith ESMTP id D649F300018D; Thu, 24 Jul 2025 15:29:44 +0000 (UTC)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=redhat.com header.i=@redhat.com\n\theader.b=\"W4RR+Khb\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1753370989;\n\th=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n\tto:to:cc:cc:mime-version:mime-version:content-type:content-type:\n\tcontent-transfer-encoding:content-transfer-encoding:\n\tin-reply-to:in-reply-to:references:references;\n\tbh=GE3y2yYFnJuaa26K/nYhD5BmAa9VJfwt1rxoAuG+Ncs=;\n\tb=W4RR+KhbYqJznqtrZ/mhJ8gB4BB0iYKWaEj1Gj/kjVGn6xsfLESEZHtMzD726B6cSkjESy\n\t6ocmNudqOixfzmFDWFacSbYe3Qj716LPJiO3aAGu7Q8BQNSDH3cU7RAhHAWgGrJ9rm7VEi\n\tuDWwBBYtXm+v3y4L5E7oFly0ev+t6RI=",
        "X-MC-Unique": "JaNl7-4HOTC8n0sBdV1g6Q-1",
        "X-Mimecast-MFC-AGG-ID": "JaNl7-4HOTC8n0sBdV1g6Q_1753370986",
        "From": "Milan Zamazal <mzamazal@redhat.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "Milan Zamazal <mzamazal@redhat.com>,\n\tKieran Bingham <kieran.bingham@ideasonboard.com>",
        "Subject": "[PATCH v2 1/2] libcamera: geometry: Add Rectangle::croppedBy",
        "Date": "Thu, 24 Jul 2025 17:29:35 +0200",
        "Message-ID": "<20250724152936.99830-2-mzamazal@redhat.com>",
        "In-Reply-To": "<20250724152936.99830-1-mzamazal@redhat.com>",
        "References": "<20250724152936.99830-1-mzamazal@redhat.com>",
        "MIME-Version": "1.0",
        "X-Scanned-By": "MIMEDefang 3.4.1 on 10.30.177.4",
        "X-Mimecast-Spam-Score": "0",
        "X-Mimecast-MFC-PROC-ID": "uQ8MaXrYsMmA94Xmi2UWsIbltx7k-QACLuHT3heocB8_1753370986",
        "X-Mimecast-Originator": "redhat.com",
        "Content-Transfer-Encoding": "8bit",
        "content-type": "text/plain; charset=\"US-ASCII\"; x-default=true",
        "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": "Let's add a new Rectangle method that returns the coordinates of the\ncentral area of the original rectangle cropped by given\nnumerator/denominator fraction.  This is useful to specify a limited\narea of the image to operate on, for example computing statistics only\nfrom a reduced area for speedup.\n\nSigned-off-by: Milan Zamazal <mzamazal@redhat.com>\n---\n include/libcamera/geometry.h |  2 ++\n src/libcamera/geometry.cpp   | 19 +++++++++++++++++++\n test/geometry.cpp            |  9 +++++++++\n 3 files changed, 30 insertions(+)",
    "diff": "diff --git a/include/libcamera/geometry.h b/include/libcamera/geometry.h\nindex f322e3d5b..603c9a117 100644\n--- a/include/libcamera/geometry.h\n+++ b/include/libcamera/geometry.h\n@@ -297,6 +297,8 @@ public:\n \t[[nodiscard]] Rectangle scaledBy(const Size &numerator,\n \t\t\t\t\t const Size &denominator) const;\n \t[[nodiscard]] Rectangle translatedBy(const Point &point) const;\n+\t[[nodiscard]] Rectangle croppedBy(const unsigned int numerator,\n+\t\t\t\t\t  const unsigned int denominator) const;\n \n \tRectangle transformedBetween(const Rectangle &source,\n \t\t\t\t     const Rectangle &target) const;\ndiff --git a/src/libcamera/geometry.cpp b/src/libcamera/geometry.cpp\nindex 81cc8cd53..8ceb75698 100644\n--- a/src/libcamera/geometry.cpp\n+++ b/src/libcamera/geometry.cpp\n@@ -837,6 +837,25 @@ Rectangle Rectangle::translatedBy(const Point &point) const\n \treturn { x + point.x, y + point.y, width, height };\n }\n \n+/**\n+ * \\brief Return a central area crop of the rectangle\n+ * \\param[in] numerator The numerator of the crop factor\n+ * \\param[in] denominator The denominator of the crop factor\n+ *\n+ * The rectangle of the central part of the original rectangle is computed, of\n+ * numerator/denominator times the original width and height.\n+ *\n+ * \\return The cropped Rectangle coordinates\n+ */\n+Rectangle Rectangle::croppedBy(const unsigned int numerator,\n+\t\t\t       const unsigned int denominator) const\n+{\n+\tunsigned int w = static_cast<uint64_t>(width) * numerator / denominator;\n+\tunsigned int h = static_cast<uint64_t>(height) * numerator / denominator;\n+\n+\treturn Size(w, h).centeredTo(center());\n+}\n+\n /**\n  * \\brief Transform a Rectangle from one reference rectangle to another\n  * \\param[in] source The \\a source reference rectangle\ndiff --git a/test/geometry.cpp b/test/geometry.cpp\nindex 11df043b7..9864774f4 100644\n--- a/test/geometry.cpp\n+++ b/test/geometry.cpp\n@@ -466,6 +466,15 @@ protected:\n \t\t\treturn TestFail;\n \t\t}\n \n+\t\t/* Rectangle::croppedBy() tests */\n+\t\tif (Rectangle(Size(300, 100)).croppedBy(2, 3) !=\n+\t\t\t    Rectangle(50, 17, 200, 66) ||\n+\t\t    Rectangle(-100, 100, 300, 700).croppedBy(3, 7) !=\n+\t\t\t    Rectangle(-14, 300, 128, 300)) {\n+\t\t\tcout << \"Rectangle::croppedBy() test failed \" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n \t\t/* Rectangle::translateBy() tests */\n \t\tr = Rectangle(10, -20, 300, 400);\n \t\tr.translateBy(Point(-30, 40));\n",
    "prefixes": [
        "v2",
        "1/2"
    ]
}