Show a patch.

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

{
    "id": 8739,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/8739/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/8739/",
    "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": "<20200710082455.10953-1-laurent.pinchart@ideasonboard.com>",
    "date": "2020-07-10T08:24:55",
    "name": "[libcamera-devel] libcamera: geometry: Add helper functions to the Size class",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "f7ef3931e0c8303f23126450c0a56de087438712",
    "submitter": {
        "id": 2,
        "url": "https://patchwork.libcamera.org/api/1.1/people/2/?format=api",
        "name": "Laurent Pinchart",
        "email": "laurent.pinchart@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/8739/mbox/",
    "series": [
        {
            "id": 1094,
            "url": "https://patchwork.libcamera.org/api/1.1/series/1094/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1094",
            "date": "2020-07-10T08:24:55",
            "name": "[libcamera-devel] libcamera: geometry: Add helper functions to the Size class",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/1094/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/8739/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/8739/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 046C6BD790\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 10 Jul 2020 08:25:07 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 57292613B1;\n\tFri, 10 Jul 2020 10:25:06 +0200 (CEST)",
            "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 DEC5F611BA\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 10 Jul 2020 10:25:04 +0200 (CEST)",
            "from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 501BA2C0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 10 Jul 2020 10:25:04 +0200 (CEST)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"A1pSLmC+\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1594369504;\n\tbh=VoWMPcbGxxtRGcKC7m2FZWSZlhpUrdmsx1YueyZdWz0=;\n\th=From:To:Subject:Date:From;\n\tb=A1pSLmC+g4HhR57tLImEtDlzVUw/l62PKkecgym6L1Qypcbio41PlZg+jqxnzQODg\n\tjSS0X3fRJ0SUKuNV4g/KFsl972GfAu8HUwMYzkT7ahojLMPKFsOzRYh2ksKYPc6p4Z\n\tlBEOUZcVPv2eEoyarPDIqT21KIfl+uOwaBWgw9mE=",
        "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Fri, 10 Jul 2020 11:24:55 +0300",
        "Message-Id": "<20200710082455.10953-1-laurent.pinchart@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.27.0",
        "MIME-Version": "1.0",
        "Subject": "[libcamera-devel] [PATCH] libcamera: geometry: Add helper functions\n\tto the Size class",
        "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": "Pipeline handlers commonly have to calculate the minimum or maximum of\nmultiple sizes, or align a size's width and height. Add helper functions\nto the Size class to perform those tasks.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n include/libcamera/geometry.h | 25 +++++++++++++++++++++++++\n src/libcamera/geometry.cpp   | 26 ++++++++++++++++++++++++++\n test/geometry.cpp            | 22 ++++++++++++++++++++++\n 3 files changed, 73 insertions(+)",
    "diff": "diff --git a/include/libcamera/geometry.h b/include/libcamera/geometry.h\nindex 7d4b8bcfe3d8..c1411290f163 100644\n--- a/include/libcamera/geometry.h\n+++ b/include/libcamera/geometry.h\n@@ -8,6 +8,7 @@\n #ifndef __LIBCAMERA_GEOMETRY_H__\n #define __LIBCAMERA_GEOMETRY_H__\n \n+#include <algorithm>\n #include <string>\n \n namespace libcamera {\n@@ -43,6 +44,30 @@ struct Size {\n \n \tbool isNull() const { return !width && !height; }\n \tconst std::string toString() const;\n+\n+\tSize alignedTo(unsigned int hAlignment, unsigned int vAlignment) const\n+\t{\n+\t\treturn {\n+\t\t\t(width + hAlignment - 1) / hAlignment * hAlignment,\n+\t\t\t(height + vAlignment - 1) / vAlignment * vAlignment\n+\t\t};\n+\t}\n+\n+\tSize boundedTo(const Size &bound) const\n+\t{\n+\t\treturn {\n+\t\t\tstd::min(width, bound.width),\n+\t\t\tstd::min(height, bound.height)\n+\t\t};\n+\t}\n+\n+\tSize expandedTo(const Size &expand) const\n+\t{\n+\t\treturn {\n+\t\t\tstd::max(width, expand.width),\n+\t\t\tstd::max(height, expand.height)\n+\t\t};\n+\t}\n };\n \n bool operator==(const Size &lhs, const Size &rhs);\ndiff --git a/src/libcamera/geometry.cpp b/src/libcamera/geometry.cpp\nindex 24c44fb43acf..d647c5efbdb1 100644\n--- a/src/libcamera/geometry.cpp\n+++ b/src/libcamera/geometry.cpp\n@@ -122,6 +122,32 @@ const std::string Size::toString() const\n \treturn std::to_string(width) + \"x\" + std::to_string(height);\n }\n \n+/**\n+ * \\fn Size::alignedTo(unsigned int hAlignment, unsigned int vAlignment)\n+ * \\brief Align the size horizontally and vertically\n+ * \\param[in] hAlignment Horizontal alignment\n+ * \\param[in] vAlignment Vertical alignment\n+ * \\return A Size whose width and height are equal to the width and height of\n+ * this size aligned to the next multiple of \\a hAlignment and \\a vAlignment\n+ * respectively\n+ */\n+\n+/**\n+ * \\fn Size::boundedTo(const Size &bound)\n+ * \\brief Bound the size to \\a bound\n+ * \\param[in] bound The maximum size\n+ * \\return A Size whose width and height are the minimum of the width and\n+ * height of this size and the \\a bound size\n+ */\n+\n+/**\n+ * \\fn Size::expandedTo(const Size &expand)\n+ * \\brief Expand the size to \\a expand\n+ * \\param[in] expand The minimum size\n+ * \\return A Size whose width and height are the maximum of the width and\n+ * height of this size and the \\a expand size\n+ */\n+\n /**\n  * \\brief Compare sizes for equality\n  * \\return True if the two sizes are equal, false otherwise\ndiff --git a/test/geometry.cpp b/test/geometry.cpp\nindex 904ad92c9448..5ef7cb7c9014 100644\n--- a/test/geometry.cpp\n+++ b/test/geometry.cpp\n@@ -46,6 +46,28 @@ protected:\n \t\t\treturn TestFail;\n \t\t}\n \n+\t\t/* Test alignedTo(), boundedTo() and expandedTo() */\n+\t\tif (Size(0, 0).alignedTo(16, 8) != Size(0, 0) ||\n+\t\t    Size(1, 1).alignedTo(16, 8) != Size(16, 8) ||\n+\t\t    Size(16, 8).alignedTo(16, 8) != Size(16, 8)) {\n+\t\t\tcout << \"Size::alignedTo() test failed\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\tif (Size(0, 0).boundedTo({ 100, 100 }) != Size(0, 0) ||\n+\t\t    Size(200, 50).boundedTo({ 100, 100 }) != Size(100, 50) ||\n+\t\t    Size(50, 200).boundedTo({ 100, 100 }) != Size(50, 100)) {\n+\t\t\tcout << \"Size::boundedTo() test failed\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\tif (Size(0, 0).expandedTo({ 100, 100 }) != Size(100, 100) ||\n+\t\t    Size(200, 50).expandedTo({ 100, 100 }) != Size(200, 100) ||\n+\t\t    Size(50, 200).expandedTo({ 100, 100 }) != Size(100, 200)) {\n+\t\t\tcout << \"Size::expandedTo() test failed\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n \t\t/* Test Size equality and inequality. */\n \t\tif (!compare(Size(100, 100), Size(100, 100), &operator==, \"==\", true))\n \t\t\treturn TestFail;\n",
    "prefixes": [
        "libcamera-devel"
    ]
}