Patch Detail
Show a patch.
GET /api/1.1/patches/8776/?format=api
{ "id": 8776, "url": "https://patchwork.libcamera.org/api/1.1/patches/8776/?format=api", "web_url": "https://patchwork.libcamera.org/patch/8776/", "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": "<20200714104212.48683-2-jacopo@jmondi.org>", "date": "2020-07-14T10:41:53", "name": "[libcamera-devel,01/20] libcamera: geometry: Add helper functions to the Size class", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "91372a1809245e6e1e1689817ab3b3c8b1582d01", "submitter": { "id": 3, "url": "https://patchwork.libcamera.org/api/1.1/people/3/?format=api", "name": "Jacopo Mondi", "email": "jacopo@jmondi.org" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/8776/mbox/", "series": [ { "id": 1104, "url": "https://patchwork.libcamera.org/api/1.1/series/1104/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1104", "date": "2020-07-14T10:41:52", "name": "libcamera: ipu3: Rework pipe configuration", "version": 1, "mbox": "https://patchwork.libcamera.org/series/1104/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/8776/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/8776/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 5E019BD792\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 14 Jul 2020 10:38:50 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 38DCF607DE;\n\tTue, 14 Jul 2020 12:38:49 +0200 (CEST)", "from relay10.mail.gandi.net (relay10.mail.gandi.net\n\t[217.70.178.230])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 159CD60486\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 14 Jul 2020 12:38:48 +0200 (CEST)", "from uno.lan (93-34-118-233.ip49.fastwebnet.it [93.34.118.233])\n\t(Authenticated sender: jacopo@jmondi.org)\n\tby relay10.mail.gandi.net (Postfix) with ESMTPSA id 4151024000F;\n\tTue, 14 Jul 2020 10:38:47 +0000 (UTC)" ], "From": "Jacopo Mondi <jacopo@jmondi.org>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Tue, 14 Jul 2020 12:41:53 +0200", "Message-Id": "<20200714104212.48683-2-jacopo@jmondi.org>", "X-Mailer": "git-send-email 2.27.0", "In-Reply-To": "<20200714104212.48683-1-jacopo@jmondi.org>", "References": "<20200714104212.48683-1-jacopo@jmondi.org>", "MIME-Version": "1.0", "Subject": "[libcamera-devel] [PATCH 01/20] libcamera: geometry: Add helper\n\tfunctions to 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": "From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nPipeline 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>\nReviewed-by: Jacopo Mondi <jacopo@jmondi.org>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n---\n include/libcamera/geometry.h | 33 +++++++++++++++++++++++++++++++++\n src/libcamera/geometry.cpp | 36 ++++++++++++++++++++++++++++++++++++\n test/geometry.cpp | 29 +++++++++++++++++++++++++++++\n 3 files changed, 98 insertions(+)", "diff": "diff --git a/include/libcamera/geometry.h b/include/libcamera/geometry.h\nindex 7d4b8bcfe3d8..d217cfd50c86 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,38 @@ struct Size {\n \n \tbool isNull() const { return !width && !height; }\n \tconst std::string toString() const;\n+\n+\tSize alignedDownTo(unsigned int hAlignment, unsigned int vAlignment) const\n+\t{\n+\t\treturn {\n+\t\t\twidth / hAlignment * hAlignment,\n+\t\t\theight / vAlignment * vAlignment\n+\t\t};\n+\t}\n+\n+\tSize alignedUpTo(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..4594f9ff435f 100644\n--- a/src/libcamera/geometry.cpp\n+++ b/src/libcamera/geometry.cpp\n@@ -122,6 +122,42 @@ const std::string Size::toString() const\n \treturn std::to_string(width) + \"x\" + std::to_string(height);\n }\n \n+/**\n+ * \\fn Size::alignedDownTo(unsigned int hAlignment, unsigned int vAlignment)\n+ * \\brief Align the size down 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 rounded down to the nearest multiple of \\a hAlignment and\n+ * \\a vAlignment respectively\n+ */\n+\n+/**\n+ * \\fn Size::alignedUpTo(unsigned int hAlignment, unsigned int vAlignment)\n+ * \\brief Align the size up 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 rounded up to the nearest multiple of \\a hAlignment and\n+ * \\a vAlignment 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..fd0132c03b02 100644\n--- a/test/geometry.cpp\n+++ b/test/geometry.cpp\n@@ -46,6 +46,35 @@ protected:\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+\t\t Size(16, 8).alignedDownTo(16, 8) != Size(16, 8)) {\n+\t\t\tcout << \"Size::alignedDownTo() test failed\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\tif (Size(0, 0).alignedUpTo(16, 8) != Size(0, 0) ||\n+\t\t Size(1, 1).alignedUpTo(16, 8) != Size(16, 8) ||\n+\t\t Size(16, 8).alignedUpTo(16, 8) != Size(16, 8)) {\n+\t\t\tcout << \"Size::alignedUpTo() 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", "01/20" ] }