Patch Detail
Show a patch.
GET /api/patches/22654/?format=api
{ "id": 22654, "url": "https://patchwork.libcamera.org/api/patches/22654/?format=api", "web_url": "https://patchwork.libcamera.org/patch/22654/", "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": "<20250128083530.351935-1-pobrn@protonmail.com>", "date": "2025-01-28T08:35:33", "name": "[RFC,v1] libcamera: {orientation, transform}FromRotation(): Return `std::optional`", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "4aa2c7118444088b78f25a729a45dad481482d23", "submitter": { "id": 133, "url": "https://patchwork.libcamera.org/api/people/133/?format=api", "name": "Pőcze Barnabás", "email": "pobrn@protonmail.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/22654/mbox/", "series": [ { "id": 4972, "url": "https://patchwork.libcamera.org/api/series/4972/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4972", "date": "2025-01-28T08:35:33", "name": "[RFC,v1] libcamera: {orientation, transform}FromRotation(): Return `std::optional`", "version": 1, "mbox": "https://patchwork.libcamera.org/series/4972/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/22654/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/22654/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 15A20BDB13\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 28 Jan 2025 08:35:43 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id EF0056855D;\n\tTue, 28 Jan 2025 09:35:41 +0100 (CET)", "from mail-40131.protonmail.ch (mail-40131.protonmail.ch\n\t[185.70.40.131])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 4B4B860353\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 28 Jan 2025 09:35:40 +0100 (CET)" ], "Authentication-Results": "lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=protonmail.com header.i=@protonmail.com\n\theader.b=\"eAWLKRhU\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com;\n\ts=protonmail3; t=1738053339; x=1738312539;\n\tbh=SZzYsjbndAcH1bdiBs3C+saYfKuX+GxHVP5A8hhVPvs=;\n\th=Date:To:From:Subject:Message-ID:Feedback-ID:From:To:Cc:Date:\n\tSubject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector:\n\tList-Unsubscribe:List-Unsubscribe-Post;\n\tb=eAWLKRhUD2P7xhTVD5cjGitwPAWt2HZ3fvg01Lr3GEy90xA/0FADiRdTjhC4aMoiL\n\t46L1pmxLLIatx4oaHst5O5ro7kbspiGatgUuGxlaP6MDlmuf0Ec/PgpByGa7KcODMd\n\tBDWNBBP2t8H96oj333dQcpR2Dm3ohvuPwonyafyOgnM7RT2DzREmGrdV0HGQgQ4FXi\n\t/Hl5P8WrqZaowCOBm8zTCaZ9HcUju0ik7TJs9HZ8nHgkMn1gk7eKV0PcdgQoJnpBnB\n\t5o67E966Np4DKtequo3rjH3TEwIIN3t5mFPK7Qdxi6zjO3EqOlSo5479UVjSnjgrpz\n\tiPklsa0mK7x1g==", "Date": "Tue, 28 Jan 2025 08:35:33 +0000", "To": "libcamera-devel@lists.libcamera.org", "From": "=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <pobrn@protonmail.com>", "Subject": "[RFC PATCH v1] libcamera: {orientation,\n\ttransform}FromRotation(): Return `std::optional`", "Message-ID": "<20250128083530.351935-1-pobrn@protonmail.com>", "Feedback-ID": "20568564:user:proton", "X-Pm-Message-ID": "1fb590a451157d0c9ae7e6aa7a5af1caede813a0", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=utf-8", "Content-Transfer-Encoding": "quoted-printable", "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": "Return an empty `std::optional` on failure instead of\nusing a separate out parameter for signalling success.\n\nSigned-off-by: Barnabás Pőcze <pobrn@protonmail.com>\n---\n include/libcamera/orientation.h | 3 ++-\n include/libcamera/transform.h | 4 +++-\n src/libcamera/orientation.cpp | 17 ++++-------------\n src/libcamera/sensor/camera_sensor_legacy.cpp | 8 ++++----\n src/libcamera/sensor/camera_sensor_raw.cpp | 8 ++++----\n src/libcamera/transform.cpp | 17 ++++-------------\n src/py/libcamera/py_transform.cpp | 15 +++++++--------\n 7 files changed, 28 insertions(+), 44 deletions(-)", "diff": "diff --git a/include/libcamera/orientation.h b/include/libcamera/orientation.h\nindex a3b40e636..4e5b0f570 100644\n--- a/include/libcamera/orientation.h\n+++ b/include/libcamera/orientation.h\n@@ -8,6 +8,7 @@\n #pragma once\n \n #include <iostream>\n+#include <optional>\n \n namespace libcamera {\n \n@@ -23,7 +24,7 @@ enum class Orientation {\n \tRotate90,\n };\n \n-Orientation orientationFromRotation(int angle, bool *success = nullptr);\n+std::optional<Orientation> orientationFromRotation(int angle);\n \n std::ostream &operator<<(std::ostream &out, const Orientation &orientation);\n \ndiff --git a/include/libcamera/transform.h b/include/libcamera/transform.h\nindex 4517412a8..4769dc2e9 100644\n--- a/include/libcamera/transform.h\n+++ b/include/libcamera/transform.h\n@@ -7,6 +7,8 @@\n \n #pragma once\n \n+#include <optional>\n+\n namespace libcamera {\n \n enum class Orientation;\n@@ -68,7 +70,7 @@ constexpr Transform operator~(Transform t)\n \treturn static_cast<Transform>(~static_cast<int>(t) & 7);\n }\n \n-Transform transformFromRotation(int angle, bool *success = nullptr);\n+std::optional<Transform> transformFromRotation(int angle);\n \n Transform operator/(const Orientation &o1, const Orientation &o2);\n Orientation operator*(const Orientation &o, const Transform &t);\ndiff --git a/src/libcamera/orientation.cpp b/src/libcamera/orientation.cpp\nindex 7d7d21ae8..9f118f834 100644\n--- a/src/libcamera/orientation.cpp\n+++ b/src/libcamera/orientation.cpp\n@@ -59,21 +59,15 @@ namespace libcamera {\n * \\brief Return the orientation representing a rotation of the given angle\n * clockwise\n * \\param[in] angle The angle of rotation in a clockwise sense. Negative values\n- * can be used to represent anticlockwise rotations\n- * \\param[out] success Set to `true` if the angle is a multiple of 90 degrees,\n- * otherwise `false`\n- * \\return The orientation corresponding to the rotation if \\a success was set\n- * to `true`, otherwise the `Rotate0` orientation\n+ * can be used to represent anticlockwise rotations. Must be a multiple of 90.\n+ * \\return The orientation corresponding to the rotation\n */\n-Orientation orientationFromRotation(int angle, bool *success)\n+std::optional<Orientation> orientationFromRotation(int angle)\n {\n \tangle = angle % 360;\n \tif (angle < 0)\n \t\tangle += 360;\n \n-\tif (success != nullptr)\n-\t\t*success = true;\n-\n \tswitch (angle) {\n \tcase 0:\n \t\treturn Orientation::Rotate0;\n@@ -85,10 +79,7 @@ Orientation orientationFromRotation(int angle, bool *success)\n \t\treturn Orientation::Rotate270;\n \t}\n \n-\tif (success != nullptr)\n-\t\t*success = false;\n-\n-\treturn Orientation::Rotate0;\n+\treturn {};\n }\n \n /**\ndiff --git a/src/libcamera/sensor/camera_sensor_legacy.cpp b/src/libcamera/sensor/camera_sensor_legacy.cpp\nindex b0c6abde4..d8c0bd41b 100644\n--- a/src/libcamera/sensor/camera_sensor_legacy.cpp\n+++ b/src/libcamera/sensor/camera_sensor_legacy.cpp\n@@ -602,15 +602,15 @@ int CameraSensorLegacy::initProperties()\n \t\t * Cache the Transform associated with the camera mounting\n \t\t * rotation for later use in computeTransform().\n \t\t */\n-\t\tbool success;\n-\t\tmountingOrientation_ = orientationFromRotation(propertyValue, &success);\n-\t\tif (!success) {\n+\t\tauto mountingOrientation = orientationFromRotation(propertyValue);\n+\t\tif (!mountingOrientation) {\n \t\t\tLOG(CameraSensor, Warning)\n \t\t\t\t<< \"Invalid rotation of \" << propertyValue\n \t\t\t\t<< \" degrees - ignoring\";\n-\t\t\tmountingOrientation_ = Orientation::Rotate0;\n \t\t}\n \n+\t\tmountingOrientation_ = mountingOrientation.value_or(Orientation::Rotate0);\n+\n \t\tproperties_.set(properties::Rotation, propertyValue);\n \t} else {\n \t\tLOG(CameraSensor, Warning)\ndiff --git a/src/libcamera/sensor/camera_sensor_raw.cpp b/src/libcamera/sensor/camera_sensor_raw.cpp\nindex ab75b1f82..3a069ef9d 100644\n--- a/src/libcamera/sensor/camera_sensor_raw.cpp\n+++ b/src/libcamera/sensor/camera_sensor_raw.cpp\n@@ -607,15 +607,15 @@ int CameraSensorRaw::initProperties()\n \t\t * Cache the Transform associated with the camera mounting\n \t\t * rotation for later use in computeTransform().\n \t\t */\n-\t\tbool success;\n-\t\tmountingOrientation_ = orientationFromRotation(propertyValue, &success);\n-\t\tif (!success) {\n+\t\tauto mountingOrientation = orientationFromRotation(propertyValue);\n+\t\tif (!mountingOrientation) {\n \t\t\tLOG(CameraSensor, Warning)\n \t\t\t\t<< \"Invalid rotation of \" << propertyValue\n \t\t\t\t<< \" degrees - ignoring\";\n-\t\t\tmountingOrientation_ = Orientation::Rotate0;\n \t\t}\n \n+\t\tmountingOrientation_ = mountingOrientation.value_or(Orientation::Rotate0);\n+\n \t\tproperties_.set(properties::Rotation, propertyValue);\n \t} else {\n \t\tLOG(CameraSensor, Warning)\ndiff --git a/src/libcamera/transform.cpp b/src/libcamera/transform.cpp\nindex 9fe8b5620..6636b23e4 100644\n--- a/src/libcamera/transform.cpp\n+++ b/src/libcamera/transform.cpp\n@@ -269,21 +269,15 @@ Transform operator-(Transform t)\n * \\brief Return the transform representing a rotation of the given angle\n * clockwise\n * \\param[in] angle The angle of rotation in a clockwise sense. Negative values\n- * can be used to represent anticlockwise rotations\n- * \\param[out] success Set to `true` if the angle is a multiple of 90 degrees,\n- * otherwise `false`\n- * \\return The transform corresponding to the rotation if \\a success was set to\n- * `true`, otherwise the `Identity` transform\n+ * can be used to represent anticlockwise rotations. Must be a multiple of 90.\n+ * \\return The transform corresponding to the rotation\n */\n-Transform transformFromRotation(int angle, bool *success)\n+std::optional<Transform> transformFromRotation(int angle)\n {\n \tangle = angle % 360;\n \tif (angle < 0)\n \t\tangle += 360;\n \n-\tif (success != nullptr)\n-\t\t*success = true;\n-\n \tswitch (angle) {\n \tcase 0:\n \t\treturn Transform::Identity;\n@@ -295,10 +289,7 @@ Transform transformFromRotation(int angle, bool *success)\n \t\treturn Transform::Rot270;\n \t}\n \n-\tif (success != nullptr)\n-\t\t*success = false;\n-\n-\treturn Transform::Identity;\n+\treturn {};\n }\n \n namespace {\ndiff --git a/src/py/libcamera/py_transform.cpp b/src/py/libcamera/py_transform.cpp\nindex 768260ffc..fc25d5a32 100644\n--- a/src/py/libcamera/py_transform.cpp\n+++ b/src/py/libcamera/py_transform.cpp\n@@ -24,19 +24,18 @@ void init_py_transform(py::module &m)\n \n \tpyTransform\n \t\t.def(py::init([](int rotation, bool hflip, bool vflip, bool transpose) {\n-\t\t\tbool ok;\n-\n-\t\t\tTransform t = transformFromRotation(rotation, &ok);\n-\t\t\tif (!ok)\n+\t\t\tauto t = transformFromRotation(rotation);\n+\t\t\tif (!t)\n \t\t\t\tthrow std::invalid_argument(\"Invalid rotation\");\n \n \t\t\tif (hflip)\n-\t\t\t\tt ^= Transform::HFlip;\n+\t\t\t\t*t ^= Transform::HFlip;\n \t\t\tif (vflip)\n-\t\t\t\tt ^= Transform::VFlip;\n+\t\t\t\t*t ^= Transform::VFlip;\n \t\t\tif (transpose)\n-\t\t\t\tt ^= Transform::Transpose;\n-\t\t\treturn t;\n+\t\t\t\t*t ^= Transform::Transpose;\n+\n+\t\t\treturn *t;\n \t\t}), py::arg(\"rotation\") = 0, py::arg(\"hflip\") = false,\n \t\t py::arg(\"vflip\") = false, py::arg(\"transpose\") = false)\n \t\t.def(py::init([](Transform &other) { return other; }))\n", "prefixes": [ "RFC", "v1" ] }