Patch Detail
Show a patch.
GET /api/1.1/patches/21346/?format=api
{ "id": 21346, "url": "https://patchwork.libcamera.org/api/1.1/patches/21346/?format=api", "web_url": "https://patchwork.libcamera.org/patch/21346/", "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": "<20240924124525.95189-1-jacopo.mondi@ideasonboard.com>", "date": "2024-09-24T12:45:24", "name": "libcamera: geometry: Rename Rectangle's top-left corner", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": true, "hash": "e51fba20146d747efde88fde7ccad95e8411a382", "submitter": { "id": 143, "url": "https://patchwork.libcamera.org/api/1.1/people/143/?format=api", "name": "Jacopo Mondi", "email": "jacopo.mondi@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/21346/mbox/", "series": [ { "id": 4619, "url": "https://patchwork.libcamera.org/api/1.1/series/4619/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4619", "date": "2024-09-24T12:45:24", "name": "libcamera: geometry: Rename Rectangle's top-left corner", "version": 1, "mbox": "https://patchwork.libcamera.org/series/4619/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/21346/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/21346/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 D92C5C0F1B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 24 Sep 2024 12:45:43 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 12AB66350F;\n\tTue, 24 Sep 2024 14:45:43 +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 3F0D763500\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 24 Sep 2024 14:45:42 +0200 (CEST)", "from ideasonboard.com (93-61-96-190.ip145.fastwebnet.it\n\t[93.61.96.190])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id F24D7594;\n\tTue, 24 Sep 2024 14:44:14 +0200 (CEST)" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"kId6pI35\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1727181855;\n\tbh=Qv8b7hs9PX+UMvju6yrZ9fxPpLe9aZj+H+V+yJLyZlc=;\n\th=From:To:Cc:Subject:Date:From;\n\tb=kId6pI35VB4s1GQaKcdsdOqtoDktHGUhA83vj4a7Gvdzz3cpegZ5OwddFQR1RENNY\n\tr9dpm0cD9updWw5EkrluSFMVHIaghtmp/SXi9c2H+q5OekCKEuhr7Og1b+UQa9VDm0\n\tY59MPS2/e6kvXqDvYGJodCna6Yoci/9JU93nK98c=", "From": "Jacopo Mondi <jacopo.mondi@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Cc": "Jacopo Mondi <jacopo.mondi@ideasonboard.com>,\n\tchenghaoyang@google.com", "Subject": "[PATCH] libcamera: geometry: Rename Rectangle's top-left corner", "Date": "Tue, 24 Sep 2024 14:45:24 +0200", "Message-ID": "<20240924124525.95189-1-jacopo.mondi@ideasonboard.com>", "X-Mailer": "git-send-email 2.46.1", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "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>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "The libcamera::Rectangle class should allow defining rectangles\nregardless of the reference system where an instance is used in.\n\nHowever the class documentation assumes the reference system origin\npoint to be in the visual top-left side and that rectangles are\nconstructed by specifying the top-left corner position and sizes.\n\nHowever this is ambiguous when using a different reference system as,\nin example, constructing a rectangle (x, y, w, h) in the following\nscenario, with the origin corner in the top-left position, would require\na negative decrement along the y-axis.\n\n ^\n |\n y| o------------------\n | | | h\n | | |\n | -------------------\n | w\n ------------------------------->\n (0,0) x\n\nTo remove ambiguities, drop references to the visual top-left corner and\ndefine the rectangle's origin corner as the corner closer to the\nreference system origin point, and specify the horizontal and vertical\ndimensions always increment along their respective axis, as in the\nfollowing example.\n\n ^\n |\n | -------------------\n | ^ | h\n | | |\n y| o---->-------------\n | w\n ------------------------------->\n (0,0) x\n\n (0,0) x\n ------------------------------>\n | w\n y| o---->-------------\n | | | h\n | v |\n | -------------------\n |\n V\n\nAlso rename for consistency the Rectangle::topLeft() function to\nRectangle::origin() and update its in-tree users.\n\nSigned-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n---\n include/libcamera/geometry.h | 2 +-\n src/ipa/ipu3/algorithms/af.cpp | 2 +-\n src/libcamera/geometry.cpp | 85 ++++++++++++++-----\n .../pipeline/rpi/common/pipeline_base.cpp | 4 +-\n src/py/libcamera/py_geometry.cpp | 2 +-\n test/geometry.cpp | 8 +-\n 6 files changed, 75 insertions(+), 28 deletions(-)\n\n--\n2.46.1", "diff": "diff --git a/include/libcamera/geometry.h b/include/libcamera/geometry.h\nindex 3e6f0f5d7fab..07cb0a7866fe 100644\n--- a/include/libcamera/geometry.h\n+++ b/include/libcamera/geometry.h\n@@ -277,7 +277,7 @@ public:\n \t\treturn { width, height };\n \t}\n\n-\tPoint topLeft() const\n+\tPoint origin() const\n \t{\n \t\treturn { x, y };\n \t}\ndiff --git a/src/ipa/ipu3/algorithms/af.cpp b/src/ipa/ipu3/algorithms/af.cpp\nindex cf68fb59c49b..1b707e9dd9ab 100644\n--- a/src/ipa/ipu3/algorithms/af.cpp\n+++ b/src/ipa/ipu3/algorithms/af.cpp\n@@ -155,7 +155,7 @@ int Af::configure(IPAContext &context, const IPAConfigInfo &configInfo)\n \t * - Return the AF ROI as metadata in the Request\n \t */\n \tRectangle roi = gridSize.centeredTo(bds.center());\n-\tPoint start = roi.topLeft();\n+\tPoint start = roi.origin();\n\n \t/* x_start and y_start should be even */\n \tgrid.x_start = utils::alignDown(start.x, 2);\ndiff --git a/src/libcamera/geometry.cpp b/src/libcamera/geometry.cpp\nindex 000151364c7f..45ba81a99920 100644\n--- a/src/libcamera/geometry.cpp\n+++ b/src/libcamera/geometry.cpp\n@@ -593,11 +593,39 @@ std::ostream &operator<<(std::ostream &out, const SizeRange &sr)\n * \\brief Describe a rectangle's position and dimensions\n *\n * Rectangles are used to identify an area of an image. They are specified by\n- * the coordinates of top-left corner and their horizontal and vertical size.\n+ * the coordinates of the corner closer to the reference system's origin point\n+ * and by horizontal and vertical increments from there.\n *\n- * The measure unit of the rectangle coordinates and size, as well as the\n- * reference point from which the Rectangle::x and Rectangle::y displacements\n- * refers to, are defined by the context were rectangle is used.\n+ * The corner closer to the reference system's origin point is the rectangle's\n+ * origin corner.\n+ *\n+ * \\verbatim\n+\n+ o = origin corner\n+\n+ ^\n+ |\n+ | -------------------\n+ | ^ |\n+ | | |\n+ | o---->-------------\n+ |\n+ ------------------------------->\n+ (0,0)\n+\n+ (0,0)\n+ ------------------------------->\n+ |\n+ | o---->-------------\n+ | | |\n+ | v |\n+ | -------------------\n+ |\n+ V\n+ \\endverbatim\n+ *\n+ * The measure unit of the rectangle coordinates and size are defined by the\n+ * context were the rectangle is used.\n */\n\n /**\n@@ -608,35 +636,50 @@ std::ostream &operator<<(std::ostream &out, const SizeRange &sr)\n /**\n * \\fn Rectangle::Rectangle(int x, int y, const Size &size)\n * \\brief Construct a Rectangle with the given position and size\n- * \\param[in] x The horizontal coordinate of the top-left corner\n- * \\param[in] y The vertical coordinate of the top-left corner\n+ * \\param[in] x The horizontal coordinate of the origin corner\n+ * \\param[in] y The vertical coordinate of the origin corner\n * \\param[in] size The size\n+ *\n+ * The rectangle's origin corner is the corner closer to the reference system\n+ * origin point (0, 0).\n */\n\n /**\n * \\fn Rectangle::Rectangle(int x, int y, unsigned int width, unsigned int height)\n * \\brief Construct a Rectangle with the given position and size\n- * \\param[in] x The horizontal coordinate of the top-left corner\n- * \\param[in] y The vertical coordinate of the top-left corner\n+ * \\param[in] x The horizontal coordinate of the origin corner\n+ * \\param[in] y The vertical coordinate of the origin corner\n * \\param[in] width The width\n * \\param[in] height The height\n+ *\n+ * The rectangle's origin corner is the corner closer to the reference system\n+ * origin point (0, 0).\n */\n\n /**\n * \\fn Rectangle::Rectangle(const Size &size)\n- * \\brief Construct a Rectangle of \\a size with its top left corner located\n+ * \\brief Construct a Rectangle of \\a size with its origin corner located\n * at (0,0)\n * \\param[in] size The desired Rectangle size\n+ *\n+ * The rectangle's origin corner is the corner closer to the reference system\n+ * origin point (0, 0).\n */\n\n /**\n * \\var Rectangle::x\n- * \\brief The horizontal coordinate of the rectangle's top-left corner\n+ * \\brief The horizontal coordinate of the rectangle's origin corner\n+ *\n+ * The rectangle's origin corner is the corner closer to the reference system\n+ * origin point (0, 0).\n */\n\n /**\n * \\var Rectangle::y\n- * \\brief The vertical coordinate of the rectangle's top-left corner\n+ * \\brief The vertical coordinate of the rectangle's origin corner\n+ *\n+ * The rectangle's origin corner is the corner closer to the reference system\n+ * origin point (0, 0).\n */\n\n /**\n@@ -683,9 +726,13 @@ Point Rectangle::center() const\n */\n\n /**\n- * \\fn Point Rectangle::topLeft() const\n- * \\brief Retrieve the coordinates of the top left corner of this Rectangle\n- * \\return The Rectangle's top left corner\n+ * \\fn Point Rectangle::origin() const\n+ * \\brief Retrieve the coordinates of the origin corner of this Rectangle\n+ *\n+ * The rectangle's origin corner is the corner closer to the reference system\n+ * origin point (0, 0).\n+ *\n+ * \\return The Rectangle's origin corner\n */\n\n /**\n@@ -740,15 +787,15 @@ Rectangle &Rectangle::translateBy(const Point &point)\n */\n Rectangle Rectangle::boundedTo(const Rectangle &bound) const\n {\n-\tint topLeftX = std::max(x, bound.x);\n-\tint topLeftY = std::max(y, bound.y);\n+\tint originX = std::max(x, bound.x);\n+\tint originY = std::max(y, bound.y);\n \tint bottomRightX = std::min<int>(x + width, bound.x + bound.width);\n \tint bottomRightY = std::min<int>(y + height, bound.y + bound.height);\n\n-\tunsigned int newWidth = std::max(bottomRightX - topLeftX, 0);\n-\tunsigned int newHeight = std::max(bottomRightY - topLeftY, 0);\n+\tunsigned int newWidth = std::max(bottomRightX - originX, 0);\n+\tunsigned int newHeight = std::max(bottomRightY - originY, 0);\n\n-\treturn { topLeftX, topLeftY, newWidth, newHeight };\n+\treturn { originX, originY, newWidth, newHeight };\n }\n\n /**\ndiff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\nindex 3041fd1ed9fd..8d2440026689 100644\n--- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n+++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n@@ -1289,7 +1289,7 @@ Rectangle CameraData::scaleIspCrop(const Rectangle &ispCrop) const\n \t */\n \tRectangle nativeCrop = ispCrop.scaledBy(sensorInfo_.analogCrop.size(),\n \t\t\t\t\t\tsensorInfo_.outputSize);\n-\tnativeCrop.translateBy(sensorInfo_.analogCrop.topLeft());\n+\tnativeCrop.translateBy(sensorInfo_.analogCrop.origin());\n \treturn nativeCrop;\n }\n\n@@ -1303,7 +1303,7 @@ void CameraData::applyScalerCrop(const ControlList &controls)\n \t\t\tnativeCrop = { 0, 0, 1, 1 };\n\n \t\t/* Create a version of the crop scaled to ISP (camera mode) pixels. */\n-\t\tRectangle ispCrop = nativeCrop.translatedBy(-sensorInfo_.analogCrop.topLeft());\n+\t\tRectangle ispCrop = nativeCrop.translatedBy(-sensorInfo_.analogCrop.origin());\n \t\tispCrop.scaleBy(sensorInfo_.outputSize, sensorInfo_.analogCrop.size());\n\n \t\t/*\ndiff --git a/src/py/libcamera/py_geometry.cpp b/src/py/libcamera/py_geometry.cpp\nindex c7e303609427..8dee365b25dd 100644\n--- a/src/py/libcamera/py_geometry.cpp\n+++ b/src/py/libcamera/py_geometry.cpp\n@@ -105,7 +105,7 @@ void init_py_geometry(py::module &m)\n \t\t.def_property_readonly(\"is_null\", &Rectangle::isNull)\n \t\t.def_property_readonly(\"center\", &Rectangle::center)\n \t\t.def_property_readonly(\"size\", &Rectangle::size)\n-\t\t.def_property_readonly(\"topLeft\", &Rectangle::topLeft)\n+\t\t.def_property_readonly(\"origin\", &Rectangle::origin)\n \t\t.def(\"scale_by\", &Rectangle::scaleBy)\n \t\t.def(\"translate_by\", &Rectangle::translateBy)\n \t\t.def(\"bounded_to\", &Rectangle::boundedTo)\ndiff --git a/test/geometry.cpp b/test/geometry.cpp\nindex 64169206ad16..a4ee6f6e167a 100644\n--- a/test/geometry.cpp\n+++ b/test/geometry.cpp\n@@ -363,16 +363,16 @@ protected:\n \t\t\treturn TestFail;\n \t\t}\n\n-\t\t/* Rectangle::size(), Rectangle::topLeft() and Rectangle::center() tests */\n+\t\t/* Rectangle::size(), Rectangle::origin() and Rectangle::center() tests */\n \t\tif (Rectangle(-1, -2, 3, 4).size() != Size(3, 4) ||\n \t\t Rectangle(0, 0, 100000, 200000).size() != Size(100000, 200000)) {\n \t\t\tcout << \"Rectangle::size() test failed\" << endl;\n \t\t\treturn TestFail;\n \t\t}\n\n-\t\tif (Rectangle(1, 2, 3, 4).topLeft() != Point(1, 2) ||\n-\t\t Rectangle(-1, -2, 3, 4).topLeft() != Point(-1, -2)) {\n-\t\t\tcout << \"Rectangle::topLeft() test failed\" << endl;\n+\t\tif (Rectangle(1, 2, 3, 4).origin() != Point(1, 2) ||\n+\t\t Rectangle(-1, -2, 3, 4).origin() != Point(-1, -2)) {\n+\t\t\tcout << \"Rectangle::origin() test failed\" << endl;\n \t\t\treturn TestFail;\n \t\t}\n\n", "prefixes": [] }