Patch Detail
Show a patch.
GET /api/patches/15586/?format=api
{ "id": 15586, "url": "https://patchwork.libcamera.org/api/patches/15586/?format=api", "web_url": "https://patchwork.libcamera.org/patch/15586/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/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": "<20220331120556.2147745-1-kieran.bingham@ideasonboard.com>", "date": "2022-03-31T12:05:56", "name": "[libcamera-devel] libcamera: geometry: Add Size members to clamp to a min/max", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "4fa5150d728d543e698672feb04402bdc1cb230f", "submitter": { "id": 4, "url": "https://patchwork.libcamera.org/api/people/4/?format=api", "name": "Kieran Bingham", "email": "kieran.bingham@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/15586/mbox/", "series": [ { "id": 3015, "url": "https://patchwork.libcamera.org/api/series/3015/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3015", "date": "2022-03-31T12:05:56", "name": "[libcamera-devel] libcamera: geometry: Add Size members to clamp to a min/max", "version": 1, "mbox": "https://patchwork.libcamera.org/series/3015/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/15586/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/15586/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 2A564C3256\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 31 Mar 2022 12:06:04 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 384D965633;\n\tThu, 31 Mar 2022 14:06:03 +0200 (CEST)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 15E666559A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 31 Mar 2022 14:06:01 +0200 (CEST)", "from Monstersaurus.local\n\t(cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 8956759D;\n\tThu, 31 Mar 2022 14:06:00 +0200 (CEST)" ], "DKIM-Signature": [ "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1648728363;\n\tbh=85HrKCwvFGkyTPd55ffsJniWjJclB4LUstQ25z0D1PE=;\n\th=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post:\n\tList-Help:List-Subscribe:From:Reply-To:From;\n\tb=RWrnU8r48SgVJhAwLoOhEEnEX0AAhYFihKS54XHCgkdnVWov5/srTmrDHN9/wXIwb\n\t6nfi9ISSrZDcQ2T6mpxkqDtB/qu2SzqMJJXxEYjmi4glUgBmiGYUaa8z4tZ/HCA42o\n\ty1ajdgRPpOHAQFogl0VNx0fjzq4fsnxfCUppWwE1CmyJSF1vbBKTytyZTePNcUOOWv\n\tsyGQlnmpfGV64A9SIdo9z0j3bLMxI5/vp0wcnbtGbdY6PpTun0ClD/kh64JXUxh2KV\n\tUYcMDKLz54qvaQJmiTA5sFDH0tHIBXEIBYViL4BXiuWFxs3nn4MK9A0uyRthlyRX2P\n\tWJ8PTfotyw0qw==", "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1648728360;\n\tbh=85HrKCwvFGkyTPd55ffsJniWjJclB4LUstQ25z0D1PE=;\n\th=From:To:Cc:Subject:Date:From;\n\tb=quwiCdo8X22IaKCZEyZ1XQ2M0AeGGloWt0Mhz/f2SmG7tI0r9HWnGma1K6Q8r/Dx5\n\tZnMm2mQFsWSWT7QOwMfZW1wU3m1m+Sv7Ad6dB79QUvh3CUexoJ53E9S3b2PoLmAB5S\n\tKgNkGvDg1hdMW3wXfY1otHuubXG7m3XuXx1GuwlE=" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"quwiCdo8\"; dkim-atps=neutral", "To": "libcamera devel <libcamera-devel@lists.libcamera.org>", "Date": "Thu, 31 Mar 2022 13:05:56 +0100", "Message-Id": "<20220331120556.2147745-1-kieran.bingham@ideasonboard.com>", "X-Mailer": "git-send-email 2.32.0", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH] libcamera: geometry: Add Size members to\n\tclamp to a min/max", "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>", "From": "Kieran Bingham via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>", "Reply-To": "Kieran Bingham <kieran.bingham@ideasonboard.com>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "Provide two new operations to support clamping a Size to a given\nminimum or maximum Size, or returning a const variant of the same\nrestriction.\n\nSigned-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n---\n\nI was expecting to use this for clamping the block width and height\nfor the AF hardware restrictions on the IPU3 ... but it turns out to be\nnot quite appropriate to use a Size there, as the clamped values are\nstored in an IPU3 struct directly.\n\nHowever, having made this - I think it is likely to be useful elsewhere\nso posting so it doesn't get lost.\n\nTests added, so it could be merged already even if there is no current\nuser yet. I expect it's more likely to get used if it exists, than if it\ndoesn't ;-)\n\n\n include/libcamera/geometry.h | 16 ++++++++++++++++\n src/libcamera/geometry.cpp | 21 +++++++++++++++++++++\n test/geometry.cpp | 24 ++++++++++++++++++++++--\n 3 files changed, 59 insertions(+), 2 deletions(-)", "diff": "diff --git a/include/libcamera/geometry.h b/include/libcamera/geometry.h\nindex 7838b6793617..a447beb55965 100644\n--- a/include/libcamera/geometry.h\n+++ b/include/libcamera/geometry.h\n@@ -93,6 +93,13 @@ public:\n \t\treturn *this;\n \t}\n \n+\tSize &clamp(const Size &minimum, const Size &maximum)\n+\t{\n+\t\twidth = std::clamp(width, minimum.width, maximum.width);\n+\t\theight = std::clamp(height, minimum.height, maximum.height);\n+\t\treturn *this;\n+\t}\n+\n \tSize &growBy(const Size &margins)\n \t{\n \t\twidth += margins.width;\n@@ -141,6 +148,15 @@ public:\n \t\t};\n \t}\n \n+\t__nodiscard constexpr Size clampedTo(const Size &minimum,\n+\t\t\t\t\t const Size &maximum) const\n+\t{\n+\t\treturn {\n+\t\t\tstd::clamp(width, minimum.width, maximum.width),\n+\t\t\tstd::clamp(height, minimum.height, maximum.height)\n+\t\t};\n+\t}\n+\n \t__nodiscard constexpr Size grownBy(const Size &margins) const\n \t{\n \t\treturn {\ndiff --git a/src/libcamera/geometry.cpp b/src/libcamera/geometry.cpp\nindex cb3c2de18d5e..7ac053a536c1 100644\n--- a/src/libcamera/geometry.cpp\n+++ b/src/libcamera/geometry.cpp\n@@ -173,6 +173,18 @@ const std::string Size::toString() const\n * \\return A reference to this object\n */\n \n+/**\n+ * \\fn Size::clamp(const Size &minimum, const Size &maximum)\n+ * \\brief Restrict the size to be constrained within the \\a minimum and \\a maximum\n+ * \\param[in] minimum The minimum size\n+ * \\param[in] maximum The maximum size\n+ *\n+ * This function restricts the width and height to the constraints of the \\a\n+ * minimum and the \\a maximum sizes given.\n+ *\n+ * \\return A reference to this object\n+ */\n+\n /**\n * \\fn Size::growBy(const Size &margins)\n * \\brief Grow the size by \\a margins in place\n@@ -231,6 +243,15 @@ const std::string Size::toString() const\n * height of this size and the \\a expand size\n */\n \n+/**\n+ * \\fn Size::clampedTo(const Size &minimum, const Size &maximum)\n+ * \\brief Restrict the size to be constrained within the \\a minimum and \\a maximum\n+ * \\param[in] minimum The minimum size\n+ * \\param[in] maximum The maximum size\n+ * \\return A size whose width and height match this size within the constraints\n+ * of the \\a minimum and \\a maximum sizes given.\n+ */\n+\n /**\n * \\fn Size::grownBy(const Size &margins)\n * \\brief Grow the size by \\a margins\ndiff --git a/test/geometry.cpp b/test/geometry.cpp\nindex 5125692496b3..1d3d3cad7174 100644\n--- a/test/geometry.cpp\n+++ b/test/geometry.cpp\n@@ -106,7 +106,7 @@ protected:\n \n \t\t/*\n \t\t * Test alignDownTo(), alignUpTo(), boundTo(), expandTo(),\n-\t\t * growBy() and shrinkBy()\n+\t\t * clamp() growBy() and shrinkBy()\n \t\t */\n \t\tSize s(50, 50);\n \n@@ -134,6 +134,18 @@ protected:\n \t\t\treturn TestFail;\n \t\t}\n \n+\t\ts.clamp({ 80, 120 }, { 160, 240 });\n+\t\tif (s != Size(80, 120)) {\n+\t\t\tcout << \"Size::clamp (minium) test failed\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\ts.clamp({ 20, 30 }, { 50, 50 });\n+\t\tif (s != Size(50, 50)) {\n+\t\t\tcout << \"Size::clamp (maximum) test failed\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n \t\ts.growBy({ 10, 20 });\n \t\tif (s != Size(60, 70)) {\n \t\t\tcout << \"Size::growBy() test failed\" << endl;\n@@ -162,7 +174,7 @@ protected:\n \n \t\t/*\n \t\t * Test alignedDownTo(), alignedUpTo(), boundedTo(),\n-\t\t * expandedTo(), grownBy() and shrunkBy()\n+\t\t * expandedTo(), clampedTo(), grownBy() and shrunkBy()\n \t\t */\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@@ -192,6 +204,14 @@ protected:\n \t\t\treturn TestFail;\n \t\t}\n \n+\t\tif (Size(0, 0).clampedTo({ 60, 40 }, { 80, 90 }) != Size(60, 40) ||\n+\t\t Size(100, 100).clampedTo({ 60, 40 }, { 80, 90 }) != Size(80, 90) ||\n+\t\t Size(30, 100).clampedTo({ 60, 40 }, { 80, 90 }) != Size(60, 90) ||\n+\t\t Size(100, 30).clampedTo({ 60, 40 }, { 80, 90 }) != Size(80, 40)) {\n+\t\t\tcout << \"Size::clampedTo() test failed\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n \t\tif (Size(0, 0).grownBy({ 10, 20 }) != Size(10, 20) ||\n \t\t Size(200, 50).grownBy({ 10, 20 }) != Size(210, 70)) {\n \t\t\tcout << \"Size::grownBy() test failed\" << endl;\n", "prefixes": [ "libcamera-devel" ] }