Patch Detail
Show a patch.
GET /api/1.1/patches/8822/?format=api
{ "id": 8822, "url": "https://patchwork.libcamera.org/api/1.1/patches/8822/?format=api", "web_url": "https://patchwork.libcamera.org/patch/8822/", "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": "<20200715102339.14025-1-laurent.pinchart@ideasonboard.com>", "date": "2020-07-15T10:23:39", "name": "[libcamera-devel] libcamera: geometry: Provide in-place versions of the Size helpers", "commit_ref": "d5446e9f327ab4eaef38249b0907f11fbf52be45", "pull_url": null, "state": "accepted", "archived": false, "hash": "d82e9a6353c4dd9d74130df6b84e3bcbe031c8e6", "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/8822/mbox/", "series": [ { "id": 1110, "url": "https://patchwork.libcamera.org/api/1.1/series/1110/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1110", "date": "2020-07-15T10:23:39", "name": "[libcamera-devel] libcamera: geometry: Provide in-place versions of the Size helpers", "version": 1, "mbox": "https://patchwork.libcamera.org/series/1110/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/8822/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/8822/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 A3CDBBD792\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 15 Jul 2020 10:23:50 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 36E6560962;\n\tWed, 15 Jul 2020 12:23:50 +0200 (CEST)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id A38B0605B1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 15 Jul 2020 12:23:49 +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 387AA564\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 15 Jul 2020 12:23:49 +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=\"uxtQ/++n\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1594808629;\n\tbh=Ht6z9Mkcwd6zF96PQLGq2D0XRlkyHqtpRbtpTFRDdLg=;\n\th=From:To:Subject:Date:From;\n\tb=uxtQ/++ntjwjitqCGdIToZ1yqnvIvowue3QlNjUOPaP9/+y3nBsa+scgPXBl6Cgj5\n\tkJvx9bsBe09iDkX99alpE+RYRHHHaFVNMsWeQiXkc53A8a2Zd4XrVNmIMalbfqQu9R\n\tMeMCGkQ5mynX3po9DVi0us747y5eaHgCT52w2wIQ=", "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Wed, 15 Jul 2020 13:23:39 +0300", "Message-Id": "<20200715102339.14025-1-laurent.pinchart@ideasonboard.com>", "X-Mailer": "git-send-email 2.27.0", "MIME-Version": "1.0", "Subject": "[libcamera-devel] [PATCH] libcamera: geometry: Provide in-place\n\tversions of the Size helpers", "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": "Add alignDownTo(), alignUpTo(), boundTo() and expandTo() helper\nfunctions to the Size class. These are in-place versions of the existing\nalignedDownTo(), alignedUpTo(), boundedTo() and expandedTo() functions.\n\nThe new helpers return a reference to the size, to allow chaining the\nfunctions. One can thus write\n\n\tsize.alignDownTo(16, 16).alignUpTo(32, 32)\n\t .boundTo({ 40, 80 }).expandTo({ 16, 80 });\n\ninstead of\n\n\tsize.alignDownTo(16, 16);\n\tsize.alignUpTo(32, 32);\n\tsize.boundTo({ 40, 80 });\n\tsize.expandTo({ 16, 80 });\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\nThis patch applies on top of the previously submitted geometry series.\n---\n include/libcamera/geometry.h | 28 ++++++++++++++++++++++\n src/libcamera/geometry.cpp | 46 ++++++++++++++++++++++++++++++++++++\n test/geometry.cpp | 34 ++++++++++++++++++++++++++\n 3 files changed, 108 insertions(+)", "diff": "diff --git a/include/libcamera/geometry.h b/include/libcamera/geometry.h\nindex 30aaa7a30fe2..d858f85cf1f0 100644\n--- a/include/libcamera/geometry.h\n+++ b/include/libcamera/geometry.h\n@@ -32,6 +32,34 @@ public:\n \tbool isNull() const { return !width && !height; }\n \tconst std::string toString() const;\n \n+\tSize &alignDownTo(unsigned int hAlignment, unsigned int vAlignment)\n+\t{\n+\t\twidth = width / hAlignment * hAlignment;\n+\t\theight = height / vAlignment * vAlignment;\n+\t\treturn *this;\n+\t}\n+\n+\tSize &alignUpTo(unsigned int hAlignment, unsigned int vAlignment)\n+\t{\n+\t\twidth = (width + hAlignment - 1) / hAlignment * hAlignment;\n+\t\theight = (height + vAlignment - 1) / vAlignment * vAlignment;\n+\t\treturn *this;\n+\t}\n+\n+\tSize &boundTo(const Size &bound)\n+\t{\n+\t\twidth = std::min(width, bound.width);\n+\t\theight = std::min(height, bound.height);\n+\t\treturn *this;\n+\t}\n+\n+\tSize &expandTo(const Size &expand)\n+\t{\n+\t\twidth = std::max(width, expand.width);\n+\t\theight = std::max(height, expand.height);\n+\t\treturn *this;\n+\t}\n+\n \tconstexpr Size alignedDownTo(unsigned int hAlignment,\n \t\t\t\t unsigned int vAlignment) const\n \t{\ndiff --git a/src/libcamera/geometry.cpp b/src/libcamera/geometry.cpp\nindex 3a3784df39e6..23181bdec969 100644\n--- a/src/libcamera/geometry.cpp\n+++ b/src/libcamera/geometry.cpp\n@@ -61,6 +61,52 @@ const std::string Size::toString() const\n \treturn std::to_string(width) + \"x\" + std::to_string(height);\n }\n \n+/**\n+ * \\fn Size::alignDownTo(unsigned int hAlignment, unsigned int vAlignment)\n+ * \\brief Align the size down horizontally and vertically in place\n+ * \\param[in] hAlignment Horizontal alignment\n+ * \\param[in] vAlignment Vertical alignment\n+ *\n+ * This functions rounds the width and height down to the nearest multiple of\n+ * \\a hAlignment and \\a vAlignment respectively.\n+ *\n+ * \\return A reference to this object\n+ */\n+\n+/**\n+ * \\fn Size::alignUpTo(unsigned int hAlignment, unsigned int vAlignment)\n+ * \\brief Align the size up horizontally and vertically in place\n+ * \\param[in] hAlignment Horizontal alignment\n+ * \\param[in] vAlignment Vertical alignment\n+ *\n+ * This functions rounds the width and height up to the nearest multiple of\n+ * \\a hAlignment and \\a vAlignment respectively.\n+ *\n+ * \\return A reference to this object\n+ */\n+\n+/**\n+ * \\fn Size::boundTo(const Size &bound)\n+ * \\brief Bound the size to \\a bound in place\n+ * \\param[in] bound The maximum size\n+ *\n+ * This function sets the width and height to the minimum of this size and the\n+ * \\a bound size.\n+ *\n+ * \\return A reference to this object\n+ */\n+\n+/**\n+ * \\fn Size::expandTo(const Size &expand)\n+ * \\brief Expand the size to \\a expand\n+ * \\param[in] expand The minimum size\n+ *\n+ * This function sets the width and height to the maximum of this size and the\n+ * \\a expand size.\n+ *\n+ * \\return A reference to this object\n+ */\n+\n /**\n * \\fn Size::alignedDownTo(unsigned int hAlignment, unsigned int vAlignment)\n * \\brief Align the size down horizontally and vertically\ndiff --git a/test/geometry.cpp b/test/geometry.cpp\nindex fd0132c03b02..1a9fc1b8e3ed 100644\n--- a/test/geometry.cpp\n+++ b/test/geometry.cpp\n@@ -46,6 +46,40 @@ protected:\n \t\t\treturn TestFail;\n \t\t}\n \n+\t\t/* Test alignDownTo(), alignUpTo(), boundTo() and expandTo() */\n+\t\tSize s(50, 50);\n+\n+\t\ts.alignDownTo(16, 16);\n+\t\tif (s != Size(48, 48)) {\n+\t\t\tcout << \"Size::alignDownTo() test failed\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\ts.alignUpTo(32, 32);\n+\t\tif (s != Size(64, 64)) {\n+\t\t\tcout << \"Size::alignUpTo() test failed\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\ts.boundTo({ 40, 40 });\n+\t\tif (s != Size(40, 40)) {\n+\t\t\tcout << \"Size::boundTo() test failed\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\ts.expandTo({ 50, 50 });\n+\t\tif (s != Size(50, 50)) {\n+\t\t\tcout << \"Size::expandTo() test failed\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\ts.alignDownTo(16, 16).alignUpTo(32, 32)\n+\t\t .boundTo({ 40, 80 }).expandTo({ 16, 80 });\n+\t\tif (s != Size(40, 80)) {\n+\t\t\tcout << \"Size chained in-place modifiers test failed\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n \t\t/* Test alignedDownTo(), alignedUpTo(), boundedTo() and expandedTo() */\n \t\tif (Size(0, 0).alignedDownTo(16, 8) != Size(0, 0) ||\n \t\t Size(1, 1).alignedDownTo(16, 8) != Size(0, 0) ||\n", "prefixes": [ "libcamera-devel" ] }