Show a patch.

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

{
    "id": 9702,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/9702/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/9702/",
    "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": "<20200922100400.30766-5-david.plowman@raspberrypi.com>",
    "date": "2020-09-22T10:03:58",
    "name": "[libcamera-devel,4/6] libcamera: Add geometry helper functions",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "2657ec42bc099ed467b71fd7e8b6e98afb3b999b",
    "submitter": {
        "id": 42,
        "url": "https://patchwork.libcamera.org/api/1.1/people/42/?format=api",
        "name": "David Plowman",
        "email": "david.plowman@raspberrypi.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/9702/mbox/",
    "series": [
        {
            "id": 1308,
            "url": "https://patchwork.libcamera.org/api/1.1/series/1308/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1308",
            "date": "2020-09-22T10:03:54",
            "name": "Digital zoom",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/1308/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/9702/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/9702/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 58221BF01C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 22 Sep 2020 10:04:13 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 0BDEF62FE2;\n\tTue, 22 Sep 2020 12:04:13 +0200 (CEST)",
            "from mail-wm1-x333.google.com (mail-wm1-x333.google.com\n\t[IPv6:2a00:1450:4864:20::333])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D52DE62FD4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 22 Sep 2020 12:04:10 +0200 (CEST)",
            "by mail-wm1-x333.google.com with SMTP id s13so2683910wmh.4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 22 Sep 2020 03:04:10 -0700 (PDT)",
            "from pi4-davidp.lan (plowpeople3.plus.com. [80.229.223.72])\n\tby smtp.gmail.com with ESMTPSA id\n\tg14sm26369595wrv.25.2020.09.22.03.04.09\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tTue, 22 Sep 2020 03:04:09 -0700 (PDT)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=raspberrypi.com header.i=@raspberrypi.com\n\theader.b=\"MT6g2cud\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=from:to:cc:subject:date:message-id:in-reply-to:references\n\t:mime-version:content-transfer-encoding;\n\tbh=F6UgUxLglMFwqKHvcjbNLJCpNLX9Vnk/4za5rmYDkjI=;\n\tb=MT6g2cudWwvq7NTFIG7LeLTt6yT51wLSmUQyWjzZQ5xOYX18EkZyoUWc7BdoeEtFdI\n\t8eGa1ShQqLANXg+MFr+cRI+UHJeuHTP4VBLp3EKSA2xHR4u7RpFQZjq6RYwk6lScGs4z\n\t5x4/dEkgOL1EzzEn2zt5dHpGoE1d5+hwvP/98LsRWwFuuSJvjSFU03Sl+kvyJI/QLWLG\n\tl0N2GoZmqtNyyAioKPbtzCVaIEqdKOIE/39Z9hs8igv2VqYPlhmIPflC55BlvYEwnCGq\n\twjRkepiDmFaUH8lOWYRDCdUB8g48AhwDTYURxruPmTThEUJfOqKTUIKu9ryeUVfmSgka\n\t8shA==",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references:mime-version:content-transfer-encoding;\n\tbh=F6UgUxLglMFwqKHvcjbNLJCpNLX9Vnk/4za5rmYDkjI=;\n\tb=qtZZlljEfYxezKNED5X4dR8bpVNpKgJXiEbQAyF8OGlHTC081vnP1bxr6S1QzaqWVM\n\tM2PWuQrjQUEmql0GCa84DnoR+46atLNwPOXC39AhSq94Rqmv72rzV8wW+0dPBNLZccvg\n\tgfIpK2RhiHUAesxOtWG1EI+9ByPYgZNdYYWm1TLaGa2TypbU4QoQ7vtokHniuHYbzDSj\n\tpFKxqjuSU7oPHGw47UYY1xUcN+7vUDjnCJglef7J0vZ9xW5bn6bBg81wujBxiDhlATZR\n\ttp6DTHhvyMf2BytaiV2KskXWoqnDM7EdV+uP89+keLBw2sYtBzUSTINtULMwPmwlrb/J\n\tEL8g==",
        "X-Gm-Message-State": "AOAM531xg7XkDuaWOuAz3BvHE3kOEfSILGchG5OOgD2PdAWCOIPprHS1\n\tD9PrB1Wge4zQnQcrOSD3I8oOh2LRaHHFpw==",
        "X-Google-Smtp-Source": "ABdhPJwUtFfXJ8VprskvmsrnAY0d/22lr7W82zobIyMDF+2/pbpl8SEznotOmbeUguj4TcvwEeOlJQ==",
        "X-Received": "by 2002:a1c:6445:: with SMTP id y66mr185760wmb.12.1600769050205; \n\tTue, 22 Sep 2020 03:04:10 -0700 (PDT)",
        "From": "David Plowman <david.plowman@raspberrypi.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Tue, 22 Sep 2020 11:03:58 +0100",
        "Message-Id": "<20200922100400.30766-5-david.plowman@raspberrypi.com>",
        "X-Mailer": "git-send-email 2.20.1",
        "In-Reply-To": "<20200922100400.30766-1-david.plowman@raspberrypi.com>",
        "References": "<20200922100400.30766-1-david.plowman@raspberrypi.com>",
        "MIME-Version": "1.0",
        "Subject": "[libcamera-devel] [PATCH 4/6] libcamera: Add geometry helper\n\tfunctions",
        "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>",
        "Content-Type": "text/plain; charset=\"us-ascii\"",
        "Content-Transfer-Encoding": "7bit",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "These functions are aimed at making it easier to calculate cropping\nrectangles, particularly in order to implement digital zoom.\n\nSigned-off-by: David Plowman <david.plowman@raspberrypi.com>\n---\n include/libcamera/geometry.h |  20 ++++++\n src/libcamera/geometry.cpp   | 131 +++++++++++++++++++++++++++++++++++\n 2 files changed, 151 insertions(+)",
    "diff": "diff --git a/include/libcamera/geometry.h b/include/libcamera/geometry.h\nindex 02fb63c..0447ee3 100644\n--- a/include/libcamera/geometry.h\n+++ b/include/libcamera/geometry.h\n@@ -13,6 +13,8 @@\n \n namespace libcamera {\n \n+class Rectangle;\n+\n class Size\n {\n public:\n@@ -93,8 +95,17 @@ public:\n \t\t\tstd::max(height, expand.height)\n \t\t};\n \t}\n+\n+\tSize alignedDownToAspectRatio(const Size &ratio) const;\n+\tSize alignedUpToAspectRatio(const Size &ratio) const;\n+\n+\tRectangle centredTo(const Rectangle &region,\n+\t\t\t    int offsetX = 0, int offsetY = 0) const;\n };\n \n+Size operator*(const Size &size, float f);\n+Size operator/(const Size &size, float f);\n+\n bool operator==(const Size &lhs, const Size &rhs);\n bool operator<(const Size &lhs, const Size &rhs);\n \n@@ -176,6 +187,11 @@ public:\n \t{\n \t}\n \n+\tconstexpr explicit Rectangle(const Size &size)\n+\t\t: x(0), y(0), width(size.width), height(size.height)\n+\t{\n+\t}\n+\n \tint x;\n \tint y;\n \tunsigned int width;\n@@ -183,6 +199,10 @@ public:\n \n \tbool isNull() const { return !width && !height; }\n \tconst std::string toString() const;\n+\n+\tSize size() const;\n+\n+\tRectangle boundedTo(const Rectangle &boundary) 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 b12e1a6..0c058dd 100644\n--- a/src/libcamera/geometry.cpp\n+++ b/src/libcamera/geometry.cpp\n@@ -143,6 +143,90 @@ const std::string Size::toString() const\n  * height of this size and the \\a expand size\n  */\n \n+/**\n+ * \\brief Align down to the aspect ratio given by \\a ratio\n+ * \\param[in] ratio The size whose aspect ratio to align down to\n+ * \\return A Size whose width and height are equal to the width and height\n+ * of this Size aligned down to the aspect ratio of \\a ratio\n+ */\n+Size Size::alignedDownToAspectRatio(const Size &ratio) const\n+{\n+\tSize result;\n+\n+\tuint64_t ratio1 = static_cast<uint64_t>(width) *\n+\t\t\t  static_cast<uint64_t>(ratio.height);\n+\tuint64_t ratio2 = static_cast<uint64_t>(ratio.width) *\n+\t\t\t  static_cast<uint64_t>(height);\n+\n+\tif (ratio1 > ratio2)\n+\t\treturn { static_cast<unsigned int>(ratio2 / ratio.height), height };\n+\telse\n+\t\treturn { width, static_cast<unsigned int>(ratio1 / ratio.width) };\n+}\n+\n+/**\n+ * \\brief Align up to the aspect ratio given by \\a ratio\n+ * \\param[in] ratio The size whose aspect ratio to align up to\n+ * \\return A Size whose width and height are equal to the width and height\n+ * of this Size aligned up to the aspect ratio of \\a ratio\n+ */\n+Size Size::alignedUpToAspectRatio(const Size &ratio) const\n+{\n+\tSize result;\n+\n+\tuint64_t ratio1 = static_cast<uint64_t>(width) *\n+\t\t\t  static_cast<uint64_t>(ratio.height);\n+\tuint64_t ratio2 = static_cast<uint64_t>(ratio.width) *\n+\t\t\t  static_cast<uint64_t>(height);\n+\n+\tif (ratio1 < ratio2)\n+\t\treturn { static_cast<unsigned int>(ratio2 / ratio.height), height };\n+\telse\n+\t\treturn { width, static_cast<unsigned int>(ratio1 / ratio.width) };\n+}\n+\n+/**\n+ * \\brief Centre a rectangle of this size within another rectangular region,\n+ * with optional offsets\n+ * \\param[in] region The rectangular region relative to which the returned\n+ * rectangle can be position\n+ * \\param[in] offsetX The X offset of the mid-point of the returned rectangle\n+ * relative to the mid-point of the region\n+ * \\param[in] offsetY The Y offset of the mid-point of the returned rectangle\n+ * relative to the mid-point of the region\n+ *\n+ * A Rectangle of this object's size is positioned within the Rectangle\n+ * given by \\a region. It is positioned so that its mid-point coincides\n+ * with the mid-point of \\a region, and is then further offset by the\n+ * values \\a offsetX and \\a offsetY.\n+ *\n+ * \\return A Rectangle with the horizontal and vertical sizes of\n+ * this Size instance, centred with offsets within a region\n+ */\n+Rectangle Size::centredTo(const Rectangle &region, int offsetX, int offsetY) const\n+{\n+\tint x = (region.width - width) / 2 + region.x + offsetX;\n+\tint y = (region.height - height) / 2 + region.y + offsetY;\n+\n+\treturn Rectangle(x, y, width, height);\n+}\n+\n+/**\n+ * \\brief Scale size up by the given factor\n+ */\n+Size operator*(const Size &size, float f)\n+{\n+\treturn Size(size.width * f, size.height * f);\n+}\n+\n+/**\n+ * \\brief Scale size down by the given factor\n+ */\n+Size operator/(const Size &size, float f)\n+{\n+\treturn Size(size.width / f, size.height / f);\n+}\n+\n /**\n  * \\brief Compare sizes for equality\n  * \\return True if the two sizes are equal, false otherwise\n@@ -365,6 +449,12 @@ bool operator==(const SizeRange &lhs, const SizeRange &rhs)\n  * \\param[in] height The height\n  */\n \n+/**\n+ * \\fn Rectangle::Rectangle(const Size &size)\n+ * \\brief Construct a Rectangle with zero offsets and the given size\n+ * \\param[in] size The desired Rectangle size\n+ */\n+\n /**\n  * \\var Rectangle::x\n  * \\brief The horizontal coordinate of the rectangle's top-left corner\n@@ -404,6 +494,47 @@ const std::string Rectangle::toString() const\n \treturn ss.str();\n }\n \n+/**\n+ * \\brief Retrieve the size of this rectangle\n+ * \\return A Size reporting the Rectangle horizontal and vertical sizes\n+ */\n+Size Rectangle::size() const\n+{\n+\treturn Size(width, height);\n+}\n+\n+/**\n+ * \\brief Bound a Rectangle so as not to exceeed another Rectangle\n+ * \\param[in] boundary The limit that the returned Rectangle will not exceed\n+ *\n+ * The Rectangle is bounded so that it does not exceeed the given \\a boundary.\n+ * This process involves translating the Rectangle if any of its edges\n+ * lie beyond \\a boundary, so that those edges then lie along the boundary\n+ * instead.\n+ *\n+ * If either width or height are larger than \\a bounary, then the returned\n+ * Rectangle is clipped to be no larger. But other than this, the\n+ * Rectangle is not clipped or reduced in size, merely translated.\n+ *\n+ * We note that this is not a conventional Rectangle intersection function.\n+ *\n+ * \\return A Rectangle that does not extend beyond a boundary Rectangle\n+ */\n+Rectangle Rectangle::boundedTo(const Rectangle &boundary) const\n+{\n+\tRectangle result(*this);\n+\n+\tresult.width = std::min(result.width, boundary.width);\n+\tresult.x = std::clamp<int>(result.x, boundary.x,\n+\t\t\t\t   boundary.x + boundary.width - result.width);\n+\n+\tresult.height = std::min(result.height, boundary.height);\n+\tresult.y = std::clamp<int>(result.y, boundary.y,\n+\t\t\t\t   boundary.y + boundary.height - result.height);\n+\n+\treturn result;\n+}\n+\n /**\n  * \\brief Compare rectangles for equality\n  * \\return True if the two rectangles are equal, false otherwise\n",
    "prefixes": [
        "libcamera-devel",
        "4/6"
    ]
}