Patch Detail
Show a patch.
GET /api/patches/17891/?format=api
{ "id": 17891, "url": "https://patchwork.libcamera.org/api/patches/17891/?format=api", "web_url": "https://patchwork.libcamera.org/patch/17891/", "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": "<20221124121220.47000-6-jacopo@jmondi.org>", "date": "2022-11-24T12:12:16", "name": "[libcamera-devel,5/9] libcamera: camera_sensor: Validate Transform", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "6423a087092df07e767a8cb39a3481b636c16acb", "submitter": { "id": 3, "url": "https://patchwork.libcamera.org/api/people/3/?format=api", "name": "Jacopo Mondi", "email": "jacopo@jmondi.org" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/17891/mbox/", "series": [ { "id": 3638, "url": "https://patchwork.libcamera.org/api/series/3638/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3638", "date": "2022-11-24T12:12:11", "name": "libcamera: camera_sensor: Centralize flips handling", "version": 1, "mbox": "https://patchwork.libcamera.org/series/3638/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/17891/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/17891/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 04545C3286\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 24 Nov 2022 12:12:35 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 9C6BA63323;\n\tThu, 24 Nov 2022 13:12:34 +0100 (CET)", "from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net\n\t[IPv6:2001:4b98:dc4:8::222])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id AB9846331E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 24 Nov 2022 13:12:31 +0100 (CET)", "(Authenticated sender: jacopo@jmondi.org)\n\tby mail.gandi.net (Postfix) with ESMTPSA id CFF5F40004;\n\tThu, 24 Nov 2022 12:12:30 +0000 (UTC)" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1669291954;\n\tbh=ISbHCbvzW3SqlCAN6p1qOlLOTMF5PhOrgqUNBfFReCY=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=V+VNGJWKIicpROxAG3bkUBZ356WR0h8hRdHjnmS9b9VLiXzd6lePLCu8l6wcb+5pn\n\tPRVpjEIt9M9PhhAwURVM+Gd57YeazBnf3OMLsX4A4mHVyPRyjrW94JT/hBO7l/rEHM\n\t1XrM46Pvp7LRY6IAcrNOeZ+M20/JKhEeTVyzY+HTH/83ttxvqv3fOpdXowNxJQidzR\n\txHEbxtmDdPDjV7gEgtxxvo9OVG1j8+942wYoDjfMHWA923jY41wBvrrrayx3aWljaR\n\tUhXS09Uf9pt0IzAwJxZV/hClQ9BaLPPFX4HX+C75+/iTh7Crx1FScVnC0gzQlEX2xd\n\tjLVQFHCxNVuKQ==", "To": "libcamera-devel@lists.libcamera.org", "Date": "Thu, 24 Nov 2022 13:12:16 +0100", "Message-Id": "<20221124121220.47000-6-jacopo@jmondi.org>", "X-Mailer": "git-send-email 2.38.1", "In-Reply-To": "<20221124121220.47000-1-jacopo@jmondi.org>", "References": "<20221124121220.47000-1-jacopo@jmondi.org>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH 5/9] libcamera: camera_sensor: Validate\n\tTransform", "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": "Jacopo Mondi via libcamera-devel <libcamera-devel@lists.libcamera.org>", "Reply-To": "Jacopo Mondi <jacopo@jmondi.org>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "The two pipeline handlers that currently support Transform do so by\noperating H/V flips on the image sensor, instead of rotating on the ISP.\n\nAs the image sensor performs the actual rotation, centralize the code\nthat validates a requested Transform against the camera sensor rotation\nand capabilities in the CameraSensor class.\n\nThe implementation in the IPU3 pipeline handler was copied from the\nRaspberryPi implementation, and is now centralized in CameraSensor to\nmake it easier for other platforms that do not rotate on the ISP to\nimplement support for Transform using the CameraSensor class.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n include/libcamera/internal/camera_sensor.h | 4 ++\n src/libcamera/camera_sensor.cpp | 59 +++++++++++++++++++\n src/libcamera/pipeline/ipu3/ipu3.cpp | 45 ++------------\n .../pipeline/raspberrypi/raspberrypi.cpp | 59 +++----------------\n 4 files changed, 76 insertions(+), 91 deletions(-)", "diff": "diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h\nindex 878f3c28a3c9..bea52badaff7 100644\n--- a/include/libcamera/internal/camera_sensor.h\n+++ b/include/libcamera/internal/camera_sensor.h\n@@ -29,6 +29,8 @@ class BayerFormat;\n class CameraLens;\n class MediaEntity;\n \n+enum class Transform;\n+\n struct CameraSensorProperties;\n \n class CameraSensor : protected Loggable\n@@ -68,6 +70,8 @@ public:\n \n \tCameraLens *focusLens() { return focusLens_.get(); }\n \n+\tTransform validateTransform(Transform *transform) const;\n+\n protected:\n \tstd::string logPrefix() const override;\n \ndiff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp\nindex 3afcbc482095..a4ad0ba9a099 100644\n--- a/src/libcamera/camera_sensor.cpp\n+++ b/src/libcamera/camera_sensor.cpp\n@@ -982,6 +982,65 @@ void CameraSensor::updateControlInfo()\n * connected to the sensor\n */\n \n+/**\n+ * \\brief Validate a transform request against the sensor capabilities\n+ * \\param[inout] transform The requested transformation, updated to match\n+ * the sensor capabilities\n+ *\n+ * The requested \\a transform is adjusted against the sensor rotation and its\n+ * capabilities.\n+ *\n+ * In example, if the requested \\a transform is Transform::Identity and the\n+ * sensor rotation is 180 degrees, the resulting transform returned by the\n+ * function is Transform::Rot180 to automatically correct the image, but only if\n+ * the sensor can actually apply horizontal and vertical flips.\n+ *\n+ * \\return A Transform instance that represents how \\a transform is applied to\n+ * the camera sensor\n+ */\n+Transform CameraSensor::validateTransform(Transform *transform) const\n+{\n+\t/* Adjust the requested transform to the sensor rotation. */\n+\tint32_t rotation = properties().get(properties::Rotation).value_or(0);\n+\tbool success;\n+\n+\tTransform rotationTransform = transformFromRotation(rotation, &success);\n+\tif (!success)\n+\t\tLOG(CameraSensor, Warning) << \"Invalid rotation of \" << rotation\n+\t\t\t\t\t << \" degrees - ignoring\";\n+\n+\tTransform combined = *transform * rotationTransform;\n+\n+\t/*\n+\t * The camera sensor cannot do Transpose. Adjust any combined result\n+\t * that includes a transpose by flipping the transpose bit to notify\n+\t * applications they either get the transform they requested, or have\n+\t * to do a simple transpose themselves (they don't have to worry about\n+\t * the other possible cases).\n+\t */\n+\tif (!!(combined & Transform::Transpose)) {\n+\t\t/*\n+\t\t * Flipping the transpose bit in \"transform\" flips it in the\n+\t\t * combined result too (as it's the last thing that happens),\n+\t\t * which is of course clearing it.\n+\t\t */\n+\t\t*transform ^= Transform::Transpose;\n+\t\tcombined &= ~Transform::Transpose;\n+\t}\n+\n+\t/*\n+\t * If the sensor can do no transforms, then combined must be changed to\n+\t * the identity and the sensor rotation must be cleared from the\n+\t * requested \"transform\".\n+\t */\n+\tif (!supportFlips_ && !!combined) {\n+\t\t*transform = -rotationTransform;\n+\t\tcombined = Transform::Identity;\n+\t}\n+\n+\treturn combined;\n+}\n+\n std::string CameraSensor::logPrefix() const\n {\n \treturn \"'\" + entity_->name() + \"'\";\ndiff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\nindex e4d79ea44aed..a424ac914859 100644\n--- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n+++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n@@ -184,48 +184,15 @@ CameraConfiguration::Status IPU3CameraConfiguration::validate()\n \tif (config_.empty())\n \t\treturn Invalid;\n \n-\tTransform combined = transform * data_->rotationTransform_;\n-\n-\t/*\n-\t * We combine the platform and user transform, but must \"adjust away\"\n-\t * any combined result that includes a transposition, as we can't do\n-\t * those. In this case, flipping only the transpose bit is helpful to\n-\t * applications - they either get the transform they requested, or have\n-\t * to do a simple transpose themselves (they don't have to worry about\n-\t * the other possible cases).\n-\t */\n-\tif (!!(combined & Transform::Transpose)) {\n-\t\t/*\n-\t\t * Flipping the transpose bit in \"transform\" flips it in the\n-\t\t * combined result too (as it's the last thing that happens),\n-\t\t * which is of course clearing it.\n-\t\t */\n-\t\ttransform ^= Transform::Transpose;\n-\t\tcombined &= ~Transform::Transpose;\n-\t\tstatus = Adjusted;\n-\t}\n-\n \t/*\n-\t * We also check if the sensor doesn't do h/vflips at all, in which\n-\t * case we clear them, and the application will have to do everything.\n+\t * Validate the requested transform against the sensor capabilities and\n+\t * rotation and store the final combined transform that configure() will\n+\t * need to apply to the sensor to save us working it out again.\n \t */\n-\tif (!data_->supportsFlips_ && !!combined) {\n-\t\t/*\n-\t\t * If the sensor can do no transforms, then combined must be\n-\t\t * changed to the identity. The only user transform that gives\n-\t\t * rise to this is the inverse of the rotation. (Recall that\n-\t\t * combined = transform * rotationTransform.)\n-\t\t */\n-\t\ttransform = -data_->rotationTransform_;\n-\t\tcombined = Transform::Identity;\n+\tTransform requestedTransform = transform;\n+\tcombinedTransform_ = data_->cio2_.sensor()->validateTransform(&transform);\n+\tif (transform != requestedTransform)\n \t\tstatus = Adjusted;\n-\t}\n-\n-\t/*\n-\t * Store the final combined transform that configure() will need to\n-\t * apply to the sensor to save us working it out again.\n-\t */\n-\tcombinedTransform_ = combined;\n \n \t/* Cap the number of entries to the available streams. */\n \tif (config_.size() > kMaxStreams) {\ndiff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\nindex 087c71b65700..e83984985bce 100644\n--- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n+++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n@@ -366,59 +366,14 @@ CameraConfiguration::Status RPiCameraConfiguration::validate()\n \tstatus = validateColorSpaces(ColorSpaceFlag::StreamsShareColorSpace);\n \n \t/*\n-\t * What if the platform has a non-90 degree rotation? We can't even\n-\t * \"adjust\" the configuration and carry on. Alternatively, raising an\n-\t * error means the platform can never run. Let's just print a warning\n-\t * and continue regardless; the rotation is effectively set to zero.\n+\t * Validate the requested transform against the sensor capabilities and\n+\t * rotation and store the final combined transform that configure() will\n+\t * need to apply to the sensor to save us working it out again.\n \t */\n-\tint32_t rotation = data_->sensor_->properties().get(properties::Rotation).value_or(0);\n-\tbool success;\n-\tTransform rotationTransform = transformFromRotation(rotation, &success);\n-\tif (!success)\n-\t\tLOG(RPI, Warning) << \"Invalid rotation of \" << rotation\n-\t\t\t\t << \" degrees - ignoring\";\n-\tTransform combined = transform * rotationTransform;\n-\n-\t/*\n-\t * We combine the platform and user transform, but must \"adjust away\"\n-\t * any combined result that includes a transform, as we can't do those.\n-\t * In this case, flipping only the transpose bit is helpful to\n-\t * applications - they either get the transform they requested, or have\n-\t * to do a simple transpose themselves (they don't have to worry about\n-\t * the other possible cases).\n-\t */\n-\tif (!!(combined & Transform::Transpose)) {\n-\t\t/*\n-\t\t * Flipping the transpose bit in \"transform\" flips it in the\n-\t\t * combined result too (as it's the last thing that happens),\n-\t\t * which is of course clearing it.\n-\t\t */\n-\t\ttransform ^= Transform::Transpose;\n-\t\tcombined &= ~Transform::Transpose;\n-\t\tstatus = Adjusted;\n-\t}\n-\n-\t/*\n-\t * We also check if the sensor doesn't do h/vflips at all, in which\n-\t * case we clear them, and the application will have to do everything.\n-\t */\n-\tif (!data_->supportsFlips_ && !!combined) {\n-\t\t/*\n-\t\t * If the sensor can do no transforms, then combined must be\n-\t\t * changed to the identity. The only user transform that gives\n-\t\t * rise to this the inverse of the rotation. (Recall that\n-\t\t * combined = transform * rotationTransform.)\n-\t\t */\n-\t\ttransform = -rotationTransform;\n-\t\tcombined = Transform::Identity;\n+\tTransform requestedTransform = transform;\n+\tcombinedTransform_ = data_->sensor_->validateTransform(&transform);\n+\tif (transform != requestedTransform)\n \t\tstatus = Adjusted;\n-\t}\n-\n-\t/*\n-\t * Store the final combined transform that configure() will need to\n-\t * apply to the sensor to save us working it out again.\n-\t */\n-\tcombinedTransform_ = combined;\n \n \tunsigned int rawCount = 0, outCount = 0, count = 0, maxIndex = 0;\n \tstd::pair<int, Size> outSize[2];\n@@ -453,7 +408,7 @@ CameraConfiguration::Status RPiCameraConfiguration::validate()\n \t\t\tif (data_->flipsAlterBayerOrder_) {\n \t\t\t\tBayerFormat bayer = BayerFormat::fromV4L2PixelFormat(fourcc);\n \t\t\t\tbayer.order = data_->nativeBayerOrder_;\n-\t\t\t\tbayer = bayer.transform(combined);\n+\t\t\t\tbayer = bayer.transform(combinedTransform_);\n \t\t\t\tfourcc = bayer.toV4L2PixelFormat();\n \t\t\t}\n \n", "prefixes": [ "libcamera-devel", "5/9" ] }