From patchwork Thu Oct 19 14:01:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 19149 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id F180EC3272 for ; Thu, 19 Oct 2023 14:01:52 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9E6CA6298C; Thu, 19 Oct 2023 16:01:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1697724112; bh=qzATXSHm72d3aHaV/WK7YBAxRxoxUrHeW6c5YnGSVDo=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=mHL94N7H3lJYhKpsNi13VSxA0ge9yHWGtpo9K0xGiow4GXckOOKc2fmT9IArO39c3 itUnOk1nfc76tcSfgQnVoFKlW7EovYx2HCmF9WNePW8kvhR8pqQszRjb4+6aRph6X0 uxk/OsRaWNDGS2xpBQPTML7ATIlJSjv2GQKdrAV5PMXgCvqJg5P87BheuCl4E4iSCF Av6LhGQfg/q0gi8IX5mpM0MowyqADOBZZPIKrmKwtk+Xlk5C0UJxcMy9pg+Zs4tV1X JfxF2CwajSj3Ipc/JkTqfXf1rFlYE76D1MFvsxIAXJvDepcOHn3ccPdq85s9hZ1W8C XbdoPWZSnkBTQ== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 53A7762982 for ; Thu, 19 Oct 2023 16:01:50 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="GgZuOt6V"; dkim-atps=neutral Received: from uno.LocalDomain (93-61-96-190.ip145.fastwebnet.it [93.61.96.190]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 82E8E735; Thu, 19 Oct 2023 16:01:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1697724101; bh=qzATXSHm72d3aHaV/WK7YBAxRxoxUrHeW6c5YnGSVDo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GgZuOt6VBN7Y+bhOuRGHfZ0eqfHb4yTI93L78L5bvh/voQYqqz0uk95zyIjxTpoDQ gs0WEll/OBZZN+lveZPPgjflUMLuet/wPlF1ORFb/uQYJzOi5UDxwa439MQEmEczrD 0zoNlfh4u1ShvgS53elpB8G0KI6wgwyDb7uzNq3k= To: libcamera-devel@lists.libcamera.org Date: Thu, 19 Oct 2023 16:01:22 +0200 Message-ID: <20231019140133.32090-2-jacopo.mondi@ideasonboard.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231019140133.32090-1-jacopo.mondi@ideasonboard.com> References: <20231019140133.32090-1-jacopo.mondi@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 01/12] libcamera: camera_sensor: Cache rotationTransform_ X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jacopo Mondi via libcamera-devel From: Jacopo Mondi Reply-To: Jacopo Mondi Cc: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The rotationTransform_ depends on a V4L2 control whose value does not change for the whole lifetime of the camera. Instead of re-calculating it everytime the camera is configured, cache it at properties initialization time. Signed-off-by: Jacopo Mondi Reviewed-by: Umang Jain Reviewed-by: Laurent Pinchart Reviewed-by: David Plowman --- include/libcamera/internal/camera_sensor.h | 1 + src/libcamera/camera_sensor.cpp | 54 +++++++++++++--------- 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h index 06791c3c6425..0b2ece317b2a 100644 --- a/include/libcamera/internal/camera_sensor.h +++ b/include/libcamera/internal/camera_sensor.h @@ -112,6 +112,7 @@ private: Rectangle activeArea_; const BayerFormat *bayerFormat_; bool supportFlips_; + Transform rotationTransform_; ControlList properties_; diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index 7baa08b38140..e3826cebeeff 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -462,18 +462,36 @@ int CameraSensor::initProperties() const auto &rotationControl = controls.find(V4L2_CID_CAMERA_SENSOR_ROTATION); if (rotationControl != controls.end()) { + propertyValue = rotationControl->second.def().get(); + /* - * validateTransform() compensates for the mounting rotation. - * However, as a camera sensor can only compensate rotations - * by applying H/VFlips, only rotation of 180 degrees are - * automatically compensated. The other valid rotations (Rot90 - * and Rot270) require transposition, which the camera sensor - * cannot perform, so leave them untouched. + * Cache the Transform associated with the camera mounting + * rotation for later use in validateTransform(). + */ + bool success; + rotationTransform_ = transformFromRotation(propertyValue, &success); + if (!success) { + LOG(CameraSensor, Warning) + << "Invalid rotation of " << propertyValue + << " degrees - ignoring"; + rotationTransform_ = Transform::Identity; + } + + /* + * Adjust property::Rotation as validateTransform() compensates + * for the mounting rotation. However, as a camera sensor can + * only compensate rotations by applying H/VFlips, only rotation + * of 180 degrees are automatically compensated. The other valid + * rotations (Rot90 and Rot270) require transposition, which the + * camera sensor cannot perform, so leave them untouched. */ - propertyValue = rotationControl->second.def().get(); if (propertyValue == 180 && supportFlips_) propertyValue = 0; properties_.set(properties::Rotation, propertyValue); + } else { + LOG(CameraSensor, Warning) + << "Rotation control not available, default to 0 degrees"; + rotationTransform_ = Transform::Identity; } properties_.set(properties::PixelArraySize, pixelArraySize_); @@ -1123,21 +1141,11 @@ void CameraSensor::updateControlInfo() */ Transform CameraSensor::validateTransform(Transform *transform) const { - /* Adjust the requested transform to compensate the sensor mounting rotation. */ - const ControlInfoMap &controls = subdev_->controls(); - int rotation = 0; - - const auto &rotationControl = controls.find(V4L2_CID_CAMERA_SENSOR_ROTATION); - if (rotationControl != controls.end()) - rotation = rotationControl->second.def().get(); - - bool success; - Transform rotationTransform = transformFromRotation(rotation, &success); - if (!success) - LOG(CameraSensor, Warning) << "Invalid rotation of " << rotation - << " degrees - ignoring"; - - Transform combined = *transform * rotationTransform; + /* + * Combine the requested transform to compensate the sensor mounting + * rotation. + */ + Transform combined = *transform * rotationTransform_; /* * We combine the platform and user transform, but must "adjust away" @@ -1168,7 +1176,7 @@ Transform CameraSensor::validateTransform(Transform *transform) const * rise to this is the inverse of the rotation. (Recall that * combined = transform * rotationTransform.) */ - *transform = -rotationTransform; + *transform = -rotationTransform_; combined = Transform::Identity; } From patchwork Thu Oct 19 14:01:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 19150 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 0C73AC3275 for ; Thu, 19 Oct 2023 14:01:54 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2CBE662986; Thu, 19 Oct 2023 16:01:53 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1697724113; bh=hEUiGA6p2uTq7SwijDhe6oOdyARlL3Y27YjKeEsINPI=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=tI5sqJAHf2OfjhIFQiThJ+ofP1azcP1Q9TVip9qu03iZzfCJqQycBFHxZYdPTtNYd 0ptrno3EzPDioarKSaVvRiGZFRk8q705fmODzGtv3BEisJJrErdKP0Wqm45Y/KWNff F1wLE51zfkcXRJpVPPunuUOJxCr/6/iwq7TM3EZziNisV++sy5L4RoVji+DW5menEI U0yvWaKHeHpFwMNVJbJM0NCxkmH/m87Ze7wAnUKrDmOIXRWYBAxN0XZb9LOr8q/TRJ ToGHKYkgIoOs7tDamROkaZowFWR59D1m4sVIHzve7Sm0SKPR4EycbjbEfAhKv1Kg0N tPqtErWROTa+g== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 923BF6297F for ; Thu, 19 Oct 2023 16:01:50 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="oxmSxRnV"; dkim-atps=neutral Received: from uno.LocalDomain (93-61-96-190.ip145.fastwebnet.it [93.61.96.190]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 7D341276; Thu, 19 Oct 2023 16:01:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1697724102; bh=hEUiGA6p2uTq7SwijDhe6oOdyARlL3Y27YjKeEsINPI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oxmSxRnVzhOYlxMX+tsOlIjS/f+tHsyWhPgFctVfH4iE9Da6W/y+j86wxVNgCDi7z DdjTqZzcMFEVBfZE/ANeiETlWqMRoUG7pbk0R9mKFfd0jBNSN9drU64iln5HzN4Um7 32vIvVnnt03vrfqN6xeKtbX6UD+PDaWuR/ah7ckw= To: libcamera-devel@lists.libcamera.org Date: Thu, 19 Oct 2023 16:01:23 +0200 Message-ID: <20231019140133.32090-3-jacopo.mondi@ideasonboard.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231019140133.32090-1-jacopo.mondi@ideasonboard.com> References: <20231019140133.32090-1-jacopo.mondi@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 02/12] libcamera: camera: Introduce Orientation X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jacopo Mondi via libcamera-devel From: Jacopo Mondi Reply-To: Jacopo Mondi Cc: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Introduce the Orientation enumeration which describes the possible 2D transformations that can be applied to an image using two basic plane transformations. Add to the CameraConfiguration class a new member 'orientation' which is used to specify the image orientation in the memory buffers delivered to applications. The enumeration values follow the ones defined by the EXIF specification at revision 2.32, Tag 274 'orientation'. The newly introduced field is meant to replace CameraConfiguration::transform which is not removed yet not to break compilation. Signed-off-by: Jacopo Mondi Reviewed-by: David Plowman --- include/libcamera/camera.h | 2 ++ include/libcamera/meson.build | 1 + include/libcamera/orientation.h | 28 +++++++++++++++ src/libcamera/camera.cpp | 18 +++++++++- src/libcamera/meson.build | 1 + src/libcamera/orientation.cpp | 62 +++++++++++++++++++++++++++++++++ 6 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 include/libcamera/orientation.h create mode 100644 src/libcamera/orientation.cpp diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h index decf4ec0d4db..a4536c72a17e 100644 --- a/include/libcamera/camera.h +++ b/include/libcamera/camera.h @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -94,6 +95,7 @@ public: std::optional sensorConfig; Transform transform; + Orientation orientation; protected: CameraConfiguration(); diff --git a/include/libcamera/meson.build b/include/libcamera/meson.build index 408b7acf152c..a24c50d66a82 100644 --- a/include/libcamera/meson.build +++ b/include/libcamera/meson.build @@ -12,6 +12,7 @@ libcamera_public_headers = files([ 'framebuffer_allocator.h', 'geometry.h', 'logging.h', + 'orientation.h', 'pixel_format.h', 'request.h', 'stream.h', diff --git a/include/libcamera/orientation.h b/include/libcamera/orientation.h new file mode 100644 index 000000000000..ae19d4c44a55 --- /dev/null +++ b/include/libcamera/orientation.h @@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2023, Ideas On Board Oy + * + * orientation.h - Image orientation + */ + +#pragma once + +#include + +namespace libcamera { + +enum class Orientation { + /* EXIF tag 274 starts from '1' */ + Rotate0 = 1, + Rotate0Mirror, + Rotate180, + Rotate180Mirror, + Rotate90Mirror, + Rotate270, + Rotate270Mirror, + Rotate90, +}; + +std::ostream &operator<<(std::ostream &out, const Orientation &orientation); + +} /* namespace libcamera */ diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index b940647d8d09..59ee3c40dc8e 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -291,7 +291,8 @@ bool SensorConfiguration::isValid() const * \brief Create an empty camera configuration */ CameraConfiguration::CameraConfiguration() - : transform(Transform::Identity), config_({}) + : transform(Transform::Identity), orientation(Orientation::Rotate0), + config_({}) { } @@ -552,6 +553,21 @@ CameraConfiguration::Status CameraConfiguration::validateColorSpaces(ColorSpaceF * may adjust this field at its discretion if the selection is not supported. */ +/** + * \var CameraConfiguration::orientation + * \brief The desired orientation of the images produced by the camera + * + * The orientation field is a user-specified 2D plane transformation that + * specifies how the application wants the camera images to be rotated in + * the memory buffers. + * + * If the orientation requested by the application cannot be obtained, the + * camera will not rotate or flip the images, and the validate() function will + * Adjust this value to the native image orientation produced by the camera. + * + * By default the orientation field is set to Orientation::Rotate0. + */ + /** * \var CameraConfiguration::config_ * \brief The vector of stream configurations diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build index b24f82965764..d0e26f6b4141 100644 --- a/src/libcamera/meson.build +++ b/src/libcamera/meson.build @@ -34,6 +34,7 @@ libcamera_sources = files([ 'mapped_framebuffer.cpp', 'media_device.cpp', 'media_object.cpp', + 'orientation.cpp', 'pipeline_handler.cpp', 'pixel_format.cpp', 'process.cpp', diff --git a/src/libcamera/orientation.cpp b/src/libcamera/orientation.cpp new file mode 100644 index 000000000000..61f26cfda31b --- /dev/null +++ b/src/libcamera/orientation.cpp @@ -0,0 +1,62 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2023, Ideas On Board Oy + * + * orientation.cpp - Image orientation + */ + +#include + +#include +#include + +/** + * \file libcamera/orientation.h + * \brief Image orientation definition + */ + +namespace libcamera { + +/** + * \enum Orientation + * \brief The image orientation in a memory buffer + * + * The Orientation enumeration describes the orientation of the images + * produced by the camera pipeline as they get received by the application + * inside memory buffers. + * + * The image orientation expressed using the Orientation enumeration can be then + * inferred by applying to a naturally oriented image a multiple of a 90 degrees + * rotation in the clockwise direction from the origin and then by applying an + * optional horizontal mirroring. + * + * The enumeration numerical values follow the ones defined by the EXIF + * Specification version 2.32, Tag 274 "Orientation", while the names of the + * enumerated values report the rotation and mirroring operations performed. + * + * In example Orientation::Rotate90Mirror describes the image transformation + * obtained by rotating 90 degrees clockwise first and then applying an + * horizontal mirroring. + */ + +/** + * \brief Prints human-friendly names for Orientation items + * \param[in] out The output stream + * \param[in] orientation The Orientation item + * \return The output stream \a out + */ +std::ostream &operator<<(std::ostream &out, const Orientation &orientation) +{ + constexpr std::array orientationNames = { + "", /* Orientation starts counting from 1. */ + "Rotate0", "rotate0Flip", + "Rotate180", "rotate180Flip", + "Rotate90Mirror", "Rotate270", + "Rotate270Mirror", "Rotate90", + }; + + out << orientationNames[static_cast(orientation)]; + return out; +} + +} /* namespace libcamera */ From patchwork Thu Oct 19 14:01:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 19151 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 52E88C3272 for ; Thu, 19 Oct 2023 14:01:55 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2CF2A6298A; Thu, 19 Oct 2023 16:01:54 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1697724114; bh=vyVixfRAB1MoIguSxyUe4vvZ8DqCVVEBiQUjG4hWmss=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=AoDbRcERtShl6Ifj1GBWzxTcL3MYORnsB7tXPbaxC0Lt89/ZF5iF6i4MLU1eetDFB NnWa8fZgL+p57o/zPJUuV+c93qN/RTUgSk9RXNpdDUzSTs26p/uTCD5KNDow4crSkb KgmA0fQD8sagXrly3iPICrDcY9VAAbUJI6yyXrb4HH0v9JTWo4UG5mhFnEFb42n5WE TK/6VLyC9WwsiYI8HEZ40MwMZBlhxLgYRi9i1S7RtSYwov2URJvW4WupOVQG5Wk3iI 1HHqxBrH7TGhZVz+QM/r9UqgG8/jT5Sqz2A7SsxBzPc/fHQBSmmETICtm5Bw8e1CkG toVmKSx9RGVQA== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id F10B362984 for ; Thu, 19 Oct 2023 16:01:50 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Ei5HJ3L/"; dkim-atps=neutral Received: from uno.LocalDomain (93-61-96-190.ip145.fastwebnet.it [93.61.96.190]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id DB47110FF; Thu, 19 Oct 2023 16:01:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1697724103; bh=vyVixfRAB1MoIguSxyUe4vvZ8DqCVVEBiQUjG4hWmss=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ei5HJ3L/trJk5AMx8ZKC91V0Fy7v1yFeme3pPlujvAH2Ltr/6tboloYs7rVQUy5OS zgYb2xsYSUiCc31JUOHtaYjHannULdwbuuCQMoDEhpQkTJ1Mnlc3M0z94tJEXuIvlD Uwy9fNcJ4Qr3hM6Qr/RM84D1D18jTMudFxJwLKOg= To: libcamera-devel@lists.libcamera.org Date: Thu, 19 Oct 2023 16:01:24 +0200 Message-ID: <20231019140133.32090-4-jacopo.mondi@ideasonboard.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231019140133.32090-1-jacopo.mondi@ideasonboard.com> References: <20231019140133.32090-1-jacopo.mondi@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 03/12] Documentation: Add figures to document Orientation X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jacopo Mondi via libcamera-devel From: Jacopo Mondi Reply-To: Jacopo Mondi Cc: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add figures in Documentation/rotation/ to document the plane transformations defined by the Orientation enumeration. Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- Documentation/Doxyfile.in | 2 + Documentation/rotation/rotate0.svg | 132 ++++++++++++++++++++ Documentation/rotation/rotate0Mirror.svg | 135 +++++++++++++++++++++ Documentation/rotation/rotate180.svg | 135 +++++++++++++++++++++ Documentation/rotation/rotate180Mirror.svg | 135 +++++++++++++++++++++ Documentation/rotation/rotate270.svg | 135 +++++++++++++++++++++ Documentation/rotation/rotate270Mirror.svg | 135 +++++++++++++++++++++ Documentation/rotation/rotate90.svg | 135 +++++++++++++++++++++ Documentation/rotation/rotate90Mirror.svg | 135 +++++++++++++++++++++ src/libcamera/orientation.cpp | 17 +++ 10 files changed, 1096 insertions(+) create mode 100644 Documentation/rotation/rotate0.svg create mode 100644 Documentation/rotation/rotate0Mirror.svg create mode 100644 Documentation/rotation/rotate180.svg create mode 100644 Documentation/rotation/rotate180Mirror.svg create mode 100644 Documentation/rotation/rotate270.svg create mode 100644 Documentation/rotation/rotate270Mirror.svg create mode 100644 Documentation/rotation/rotate90.svg create mode 100644 Documentation/rotation/rotate90Mirror.svg diff --git a/Documentation/Doxyfile.in b/Documentation/Doxyfile.in index 697a14d1dfe2..67ee51afb6e3 100644 --- a/Documentation/Doxyfile.in +++ b/Documentation/Doxyfile.in @@ -78,6 +78,8 @@ EXPAND_ONLY_PREDEF = YES INCLUDE_PATH = "@TOP_SRCDIR@/include/libcamera" INCLUDE_FILE_PATTERNS = *.h +IMAGE_PATH = "@TOP_SRCDIR@/Documentation" + PREDEFINED = __DOXYGEN__ \ __cplusplus \ __attribute__(x)= \ diff --git a/Documentation/rotation/rotate0.svg b/Documentation/rotation/rotate0.svg new file mode 100644 index 000000000000..13cde16ada51 --- /dev/null +++ b/Documentation/rotation/rotate0.svg @@ -0,0 +1,132 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Documentation/rotation/rotate0Mirror.svg b/Documentation/rotation/rotate0Mirror.svg new file mode 100644 index 000000000000..a7edda873bf5 --- /dev/null +++ b/Documentation/rotation/rotate0Mirror.svg @@ -0,0 +1,135 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Documentation/rotation/rotate180.svg b/Documentation/rotation/rotate180.svg new file mode 100644 index 000000000000..d092a5322fb1 --- /dev/null +++ b/Documentation/rotation/rotate180.svg @@ -0,0 +1,135 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Documentation/rotation/rotate180Mirror.svg b/Documentation/rotation/rotate180Mirror.svg new file mode 100644 index 000000000000..d4a77d500d94 --- /dev/null +++ b/Documentation/rotation/rotate180Mirror.svg @@ -0,0 +1,135 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Documentation/rotation/rotate270.svg b/Documentation/rotation/rotate270.svg new file mode 100644 index 000000000000..13ea1e5df918 --- /dev/null +++ b/Documentation/rotation/rotate270.svg @@ -0,0 +1,135 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Documentation/rotation/rotate270Mirror.svg b/Documentation/rotation/rotate270Mirror.svg new file mode 100644 index 000000000000..6116f50aa96e --- /dev/null +++ b/Documentation/rotation/rotate270Mirror.svg @@ -0,0 +1,135 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Documentation/rotation/rotate90.svg b/Documentation/rotation/rotate90.svg new file mode 100644 index 000000000000..af6276383c79 --- /dev/null +++ b/Documentation/rotation/rotate90.svg @@ -0,0 +1,135 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Documentation/rotation/rotate90Mirror.svg b/Documentation/rotation/rotate90Mirror.svg new file mode 100644 index 000000000000..1760c46226ab --- /dev/null +++ b/Documentation/rotation/rotate90Mirror.svg @@ -0,0 +1,135 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/libcamera/orientation.cpp b/src/libcamera/orientation.cpp index 61f26cfda31b..5caf76f73865 100644 --- a/src/libcamera/orientation.cpp +++ b/src/libcamera/orientation.cpp @@ -37,6 +37,23 @@ namespace libcamera { * In example Orientation::Rotate90Mirror describes the image transformation * obtained by rotating 90 degrees clockwise first and then applying an * horizontal mirroring. + * + * \var CameraConfiguration::Rotate0 + * \image html rotation/rotate0.svg + * \var CameraConfiguration::Rotate0Mirror + * \image html rotation/rotate0Mirror.svg + * \var CameraConfiguration::Rotate180 + * \image html rotation/rotate180.svg + * \var CameraConfiguration::Rotate180Mirror + * \image html rotation/rotate180Mirror.svg + * \var CameraConfiguration::Rotate90Mirror + * \image html rotation/rotate90Mirror.svg + * \var CameraConfiguration::Rotate270 + * \image html rotation/rotate270.svg + * \var CameraConfiguration::Rotate270Mirror + * \image html rotation/rotate270Mirror.svg + * \var CameraConfiguration::Rotate90 + * \image html rotation/rotate90.svg */ /** From patchwork Thu Oct 19 14:01:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 19152 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 69959C32B6 for ; Thu, 19 Oct 2023 14:01:56 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0B4DD62988; Thu, 19 Oct 2023 16:01:55 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1697724115; bh=ez09PkZ4hoqGcybyDh8tQLfj8on8zVKYntI7Pbhg7iU=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=hmh1E0IyH29VoqYDUUgjxLDWiJtjhAgYpeN23sJ2qDESavs3purnXW2JIpNCebA27 gcuFzoAXGx2oeqlZk8UmzGnG0++JNiJQ3Gw9pFyToJy4zuOBKKNrNnjNvlMxi/AYGV oMryTikx1Uk7HJPCtlYf8j9nbVQ4cAecLYerBuimx3bqwg9GCYvsoL9GfkhEnp564j QT30BA328g5WDzh56Ac89Oj8aDuIu5QXOBBqGzT6hC0TnCTIadhXJI1xhaDgC+Vc3d cm08Ml9R11ctcBVLs2oM6WPR7RLcuMPehZtOMamiBNyQL9GoiKUQyjKQ7gsvpSg9k2 Jmmeylv6O1inQ== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6281961DD2 for ; Thu, 19 Oct 2023 16:01:51 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="fl+XKNeG"; dkim-atps=neutral Received: from uno.LocalDomain (93-61-96-190.ip145.fastwebnet.it [93.61.96.190]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 490A7735; Thu, 19 Oct 2023 16:01:43 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1697724103; bh=ez09PkZ4hoqGcybyDh8tQLfj8on8zVKYntI7Pbhg7iU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fl+XKNeGydxpskHCF1D4xdyMq6xly0K1PMzcyu8kX2BZ/pdV0PXTkLevTknFOJIEZ s3RB9PFMkNlR43Z84sKkWJFSCdsdJzvtNCnzotua1AzebnQCxj5NDHvTqzLDf3Xlv+ oUsHYY6fjOl2hrS2zNouj/K4CU9bhcg6CU9eqHFU= To: libcamera-devel@lists.libcamera.org Date: Thu, 19 Oct 2023 16:01:25 +0200 Message-ID: <20231019140133.32090-5-jacopo.mondi@ideasonboard.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231019140133.32090-1-jacopo.mondi@ideasonboard.com> References: <20231019140133.32090-1-jacopo.mondi@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 04/12] libcamera: properties: Make 'Rotation' the mounting rotation X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jacopo Mondi via libcamera-devel From: Jacopo Mondi Reply-To: Jacopo Mondi Cc: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Specify in the documentation that properties::Rotation specifies the mounting rotation of the camera module. This avoids confusion with the image orientation which is instead expressed by CameraConfiguration::orientation. For this reason, do not compensate the Rotation property when initializing the CameraSensor class but report the value of V4L2_CID_CAMERA_SENSOR_ROTATION or 0 if the control is not available. Signed-off-by: Jacopo Mondi Reviewed-by: David Plowman Reviewed-by: Laurent Pinchart --- src/libcamera/camera_sensor.cpp | 15 +++------------ src/libcamera/property_ids.yaml | 8 ++++---- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index e3826cebeeff..8ff72b424560 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -433,11 +433,11 @@ int CameraSensor::initProperties() /* Retrieve and register properties from the kernel interface. */ const ControlInfoMap &controls = subdev_->controls(); - int32_t propertyValue; const auto &orientation = controls.find(V4L2_CID_CAMERA_ORIENTATION); if (orientation != controls.end()) { int32_t v4l2Orientation = orientation->second.def().get(); + int32_t propertyValue; switch (v4l2Orientation) { default: @@ -462,7 +462,7 @@ int CameraSensor::initProperties() const auto &rotationControl = controls.find(V4L2_CID_CAMERA_SENSOR_ROTATION); if (rotationControl != controls.end()) { - propertyValue = rotationControl->second.def().get(); + int32_t propertyValue = rotationControl->second.def().get(); /* * Cache the Transform associated with the camera mounting @@ -477,20 +477,11 @@ int CameraSensor::initProperties() rotationTransform_ = Transform::Identity; } - /* - * Adjust property::Rotation as validateTransform() compensates - * for the mounting rotation. However, as a camera sensor can - * only compensate rotations by applying H/VFlips, only rotation - * of 180 degrees are automatically compensated. The other valid - * rotations (Rot90 and Rot270) require transposition, which the - * camera sensor cannot perform, so leave them untouched. - */ - if (propertyValue == 180 && supportFlips_) - propertyValue = 0; properties_.set(properties::Rotation, propertyValue); } else { LOG(CameraSensor, Warning) << "Rotation control not available, default to 0 degrees"; + properties_.set(properties::Rotation, 0); rotationTransform_ = Transform::Identity; } diff --git a/src/libcamera/property_ids.yaml b/src/libcamera/property_ids.yaml index 5bddafc29364..f35563842a5a 100644 --- a/src/libcamera/property_ids.yaml +++ b/src/libcamera/property_ids.yaml @@ -29,10 +29,10 @@ controls: - Rotation: type: int32_t description: | - The camera rotation is expressed as the angular difference in degrees - between two reference systems, one relative to the camera module, and - one defined on the external world scene to be captured when projected - on the image sensor pixel array. + The camera physical mounting rotation. It is expressed as the angular + difference in degrees between two reference systems, one relative to the + camera module, and one defined on the external world scene to be + captured when projected on the image sensor pixel array. A camera sensor has a 2-dimensional reference system 'Rc' defined by its pixel array read-out order. The origin is set to the first pixel From patchwork Thu Oct 19 14:01:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 19153 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 405B9C3275 for ; Thu, 19 Oct 2023 14:01:57 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8382D62997; Thu, 19 Oct 2023 16:01:55 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1697724115; bh=59rANWTuLJcpkVFdsDHrVnbnFXCHLU/KPzDNWI+oHEQ=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=uZU1ujmTVCkwdPWaQpvPNVTaVgWbim3eLkqtOLJ/UbjSfCIyLe0sz2ks1cfAYduAc 2jQkZjegsc2rdacQh8zLbuoF+DQcI0mr4ppuDGuCPQEa5rBUT5I87z+Ri9sUqkuR2U uOFoIQQhwdtAVrQqlakAxsLI52IDxDNk+oGOVFZG4wtdJCRRqf+DiKBfslH6zfAlvZ WbYPr2ycjpY4HoJagTctc9aWGNLYQYvDpX+Hd5SbUrK5gAUD1vL06dChWYKgm5FAwp OdFiGbOCZLnSmpj+Y3ZqKV/BM5PtHhrgmYxnGZeyQtD9Tk+dLnFjVlZedY/3bF7U6T MUumw3P6kktoQ== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C6D446297F for ; Thu, 19 Oct 2023 16:01:51 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="hC8aQGYi"; dkim-atps=neutral Received: from uno.LocalDomain (93-61-96-190.ip145.fastwebnet.it [93.61.96.190]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id B32CC276; Thu, 19 Oct 2023 16:01:43 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1697724103; bh=59rANWTuLJcpkVFdsDHrVnbnFXCHLU/KPzDNWI+oHEQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hC8aQGYirFBg8ijX8G55ZxIIaKBNotxaMxlRRIc1+6kI3ZdQBSINh2CijmkJryJRg 1/5yOMXuatNz4vqXu9P3bn/d0r0hO5tyxgxO6HYiiBJF6A/rU6jheCaTeeDf48p4hE CHBcvEIFzN+XbKB0NNTR2aoPCVHbEMSZIHT4E2Jk= To: libcamera-devel@lists.libcamera.org Date: Thu, 19 Oct 2023 16:01:26 +0200 Message-ID: <20231019140133.32090-6-jacopo.mondi@ideasonboard.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231019140133.32090-1-jacopo.mondi@ideasonboard.com> References: <20231019140133.32090-1-jacopo.mondi@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 05/12] libcamera: transform: Add functions to convert Orientation X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jacopo Mondi via libcamera-devel From: Jacopo Mondi Reply-To: Jacopo Mondi Cc: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add two helper functions to the transform.cpp file that allows to convert to and from an Orientation. Signed-off-by: Jacopo Mondi Reviewed-by: David Plowman --- include/libcamera/transform.h | 4 +++ src/libcamera/transform.cpp | 60 +++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/include/libcamera/transform.h b/include/libcamera/transform.h index 2a6838c78369..14f1db0e8572 100644 --- a/include/libcamera/transform.h +++ b/include/libcamera/transform.h @@ -11,6 +11,8 @@ namespace libcamera { +enum class Orientation; + enum class Transform : int { Identity = 0, Rot0 = Identity, @@ -69,6 +71,8 @@ constexpr Transform operator~(Transform t) } Transform transformFromRotation(int angle, bool *success = nullptr); +Transform transformFromOrientation(const Orientation &orientation); +Orientation transformToOrientation(const Transform &transform); const char *transformToString(Transform t); diff --git a/src/libcamera/transform.cpp b/src/libcamera/transform.cpp index 4668303d0676..c305940100bf 100644 --- a/src/libcamera/transform.cpp +++ b/src/libcamera/transform.cpp @@ -7,6 +7,8 @@ #include +#include + /** * \file transform.h * \brief Enum to represent and manipulate 2D plane transforms @@ -299,6 +301,64 @@ Transform transformFromRotation(int angle, bool *success) return Transform::Identity; } +/** + * \brief Return the transform representing \a orientation + * \param[in] orientation The orientation to convert + * \return The transform corresponding to \a orientation + */ +Transform transformFromOrientation(const Orientation &orientation) +{ + switch (orientation) { + case Orientation::Rotate0: + return Transform::Identity; + case Orientation::Rotate0Mirror: + return Transform::HFlip; + case Orientation::Rotate180: + return Transform::Rot180; + case Orientation::Rotate180Mirror: + return Transform::VFlip; + case Orientation::Rotate90Mirror: + return Transform::Transpose; + case Orientation::Rotate90: + return Transform::Rot90; + case Orientation::Rotate270Mirror: + return Transform::Rot180Transpose; + case Orientation::Rotate270: + return Transform::Rot270; + } + + return Transform::Identity; +} + +/** + * \brief Return the Orientation representing \a transform + * \param[in] transform The transform to convert + * \return The Orientation corresponding to \a transform + */ +Orientation transformToOrientation(const Transform &transform) +{ + switch (transform) { + case Transform::Identity: + return Orientation::Rotate0; + case Transform::HFlip: + return Orientation::Rotate0Mirror; + case Transform::VFlip: + return Orientation::Rotate180Mirror; + case Transform::Rot180: + return Orientation::Rotate180; + case Transform::Transpose: + return Orientation::Rotate90Mirror; + case Transform::Rot270: + return Orientation::Rotate270; + case Transform::Rot90: + return Orientation::Rotate90; + case Transform::Rot180Transpose: + return Orientation::Rotate270Mirror; + } + + return Orientation::Rotate0; +} + /** * \brief Return a character string describing the transform * \param[in] t The transform to be described. From patchwork Thu Oct 19 14:01:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 19154 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 26955C32B7 for ; Thu, 19 Oct 2023 14:01:58 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7F78A62994; Thu, 19 Oct 2023 16:01:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1697724116; bh=FVwpDtultkqHVui0Dl+p6CR0d+d7jC2U8XeXemUzN2g=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=e2CAyluJzygUIQxwxCCgmi1qEz+mzCBxXkHxxOe5E/pHlv1+erPy2tSvzPHSBvViv +SdoPM8Pkjf11IjaksqQp8RC7Vul10drP+S3sROx2c3wvX2fbn4ADxlUSyT5I4UjrP gV6RIaN25GLaSS+j3XRI1HlXwVefc9ZLt1hSO1uySlVehqSG8Ut7McGoue+jyTrc1j tNO3LgvT0BzgC4CSRxMqGBy+2qHppj11Nyzz6RXPCUVx7XhRYJfF3tcZZQsId4lHzN MdqvA8y3TWBr/yZzbvGq7JjCz/6lYIXKOd3hUHKT1QwsvbJGoRQhsFeMTmGQ7cvNGN 6vFiQRH9pK7fg== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 37CDA6298A for ; Thu, 19 Oct 2023 16:01:52 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="jFtV8zMi"; dkim-atps=neutral Received: from uno.LocalDomain (93-61-96-190.ip145.fastwebnet.it [93.61.96.190]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 2101510FF; Thu, 19 Oct 2023 16:01:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1697724104; bh=FVwpDtultkqHVui0Dl+p6CR0d+d7jC2U8XeXemUzN2g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jFtV8zMiubn6njWiJdbwCndk0+pxzNhAfjs6gdxCs2/Ti/B208UkuxmOxbJ8IgzsO rSMyfTqV+o3Ie/8ixfuR6rYkP6N6sec/5WYSWL4qC1kYXDVRcKSJ07e08IOPwF3a1q ebxpWuq0gILYPb7Mw+pyyxvWM4OJ7+F60WsewRwE= To: libcamera-devel@lists.libcamera.org Date: Thu, 19 Oct 2023 16:01:27 +0200 Message-ID: <20231019140133.32090-7-jacopo.mondi@ideasonboard.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231019140133.32090-1-jacopo.mondi@ideasonboard.com> References: <20231019140133.32090-1-jacopo.mondi@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 06/12] libcamera: transform: Invert operator*() operands X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jacopo Mondi via libcamera-devel From: Jacopo Mondi Reply-To: Jacopo Mondi Cc: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The current definition of operator*(Transform t1, Transform t0) follows the function composition notion, where t0 is applied first then t1 is applied last. In order to introduce operator*(Orientation, Transform) where a Transform is applied on top of an Orientation, invert the operand order of operator*(Transform, Transform) so that usage of operator* with both Orientation and Transform can be made associative. For example: Orientation o; Transform t = t1 * t2 Orientation o1 = o * t = o * (t1 * t2) = (o * t1) * t2 = o * t1 * t2 Signed-off-by: Jacopo Mondi Reviewed-by: David Plowman --- src/libcamera/camera_sensor.cpp | 4 ++-- src/libcamera/transform.cpp | 19 +++++++++++-------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index 8ff72b424560..521a19972808 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -1136,7 +1136,7 @@ Transform CameraSensor::validateTransform(Transform *transform) const * Combine the requested transform to compensate the sensor mounting * rotation. */ - Transform combined = *transform * rotationTransform_; + Transform combined = rotationTransform_ * *transform; /* * We combine the platform and user transform, but must "adjust away" @@ -1165,7 +1165,7 @@ Transform CameraSensor::validateTransform(Transform *transform) const * If the sensor can do no transforms, then combined must be * changed to the identity. The only user transform that gives * rise to this is the inverse of the rotation. (Recall that - * combined = transform * rotationTransform.) + * combined = rotationTransform * transform.) */ *transform = -rotationTransform_; combined = Transform::Identity; diff --git a/src/libcamera/transform.cpp b/src/libcamera/transform.cpp index c305940100bf..38735c525aa3 100644 --- a/src/libcamera/transform.cpp +++ b/src/libcamera/transform.cpp @@ -189,14 +189,17 @@ Input image | | goes to output image | | */ /** - * \brief Compose two transforms together - * \param[in] t1 The second transform - * \param[in] t0 The first transform + * \brief Compose two transforms by applying \a t0 first then \a t1 + * \param[in] t0 The first transform to apply + * \param[in] t1 The second transform to apply + * + * Compose two transforms by applying \a t1 after \a t0. The operation + * is conceptually equivalent to the canonical notion of function composition, + * with inverse order of operands. If in the canonical function composition + * notation "f * g" equals to "f(g())", the notation for Transforms composition + * "t0 * t1" equals to "t1(t0()))" where \a t0 is applied first, then \a t1. * - * Composing transforms follows the usual mathematical convention for - * composing functions. That is, when performing `t1 * t0`, \a t0 is applied - * first, and then \a t1. - * For example, `Transpose * HFlip` performs `HFlip` first and then the + * For example, `HFlip * Transpose` performs `HFlip` first and then the * `Transpose` yielding `Rot270`, as shown below. ~~~ A-B B-A B-D @@ -206,7 +209,7 @@ Input image | | -> HFLip -> | | -> Transpose -> | | = Rot270 * Note that composition is generally non-commutative for Transforms, * and not the same as XOR-ing the underlying bit representations. */ -Transform operator*(Transform t1, Transform t0) +Transform operator*(Transform t0, Transform t1) { /* * Reorder the operations so that we imagine doing t0's transpose From patchwork Thu Oct 19 14:01:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 19155 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 962AEC32B8 for ; Thu, 19 Oct 2023 14:01:58 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 15A6662986; Thu, 19 Oct 2023 16:01:57 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1697724117; bh=EpRqUS3MNglBuApYSlDj9tKTV7Wf+jE0I46bfdvTYrI=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=Hkubu3r8D6+tEyux9t2nzP9UBfuv0/Fcni0B9o5nSHWT04ED4MCb7lIMuyYCq9NkB 13UZpaYvVG851MdPzKG5Y1iuR07Df3pJlyzB/AnydOklEbHgoiyaNFcXFR/Xu5YW4h FtioFnJXRSGTXizthmyssZSjrZancshbZkNAJxo1KMmlSAJanpkZD9ocb3VeS7a4QW lZEtKVJSE+F87JSzfupx7yRct401QlCUO5TqisM9pZimnPnFp/f0mWRW57yFpWZL3e OIQEBtzSzxlXHoqNdlgpCkgxwTpbnAIw9fheYiliahQwGnSElejpKWRG+U/2ZYle1L 6LDb+78D/CzCg== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 955BA6298B for ; Thu, 19 Oct 2023 16:01:52 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="SR50dmBy"; dkim-atps=neutral Received: from uno.LocalDomain (93-61-96-190.ip145.fastwebnet.it [93.61.96.190]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 7FFB41211; Thu, 19 Oct 2023 16:01:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1697724104; bh=EpRqUS3MNglBuApYSlDj9tKTV7Wf+jE0I46bfdvTYrI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SR50dmByY1KrmeO1OLONOWYMi2bgsY8e6vzfCAfCG6FLf4ZAxAUcrkJ5cKFro5n8V 9X4c3qETKzjKsthHzWDQoBXoweSm3UrncJjOspD4T9pRg1hBMBOCYhOz4Ce+anOIY5 vdHuQrVUi6KvdkwyeD2YGrV4wzbGOln2XHXe1dLg= To: libcamera-devel@lists.libcamera.org Date: Thu, 19 Oct 2023 16:01:28 +0200 Message-ID: <20231019140133.32090-8-jacopo.mondi@ideasonboard.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231019140133.32090-1-jacopo.mondi@ideasonboard.com> References: <20231019140133.32090-1-jacopo.mondi@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 07/12] libcamera: transform: Add operations with Orientation X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jacopo Mondi via libcamera-devel From: Jacopo Mondi Reply-To: Jacopo Mondi Cc: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add two operations that allows to combine Transform with Orientation. - Transform operator/(const Orientation &o1, const Orientation &o2) allows to easily get back the Transform that needs to be applied to Orientation2 to get Orientation1 - Orientation operator*(const Orientation &o, const Transform &t) allows to apply a Transform to an Orientation and obtain the combination of the two These two operations allow applications to use Transforms to manipulate the Orientation inside the CameraConfiguration, if they wish. Signed-off-by: Jacopo Mondi Reviewed-by: David Plowman --- include/libcamera/transform.h | 3 +++ src/libcamera/transform.cpp | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/include/libcamera/transform.h b/include/libcamera/transform.h index 14f1db0e8572..847a1f94713c 100644 --- a/include/libcamera/transform.h +++ b/include/libcamera/transform.h @@ -74,6 +74,9 @@ Transform transformFromRotation(int angle, bool *success = nullptr); Transform transformFromOrientation(const Orientation &orientation); Orientation transformToOrientation(const Transform &transform); +Transform operator/(const Orientation &o1, const Orientation &o2); +Orientation operator*(const Orientation &o1, const Transform &t); + const char *transformToString(Transform t); } /* namespace libcamera */ diff --git a/src/libcamera/transform.cpp b/src/libcamera/transform.cpp index 38735c525aa3..85bc2d28b0cd 100644 --- a/src/libcamera/transform.cpp +++ b/src/libcamera/transform.cpp @@ -362,6 +362,39 @@ Orientation transformToOrientation(const Transform &transform) return Orientation::Rotate0; } +/** + * \brief Return the Transform that applied to \a o2 gives \a o1 + * \param o1 The Orientation to obtain + * \param o2 The base Orientation + * + * This operation can be used to easily compute the Transform to apply to a + * base orientation \a o2 to get the desired orientation \a o1. + * + * \return A Transform that applied to \a o2 gives \a o1 + */ +Transform operator/(const Orientation &o1, const Orientation &o2) +{ + Transform t1 = transformFromOrientation(o1); + Transform t2 = transformFromOrientation(o2); + + return -t2 * t1; +} + +/** + * \brief Apply the Transform \a t on the orientation \a o + * \param o The orientation + * \param t The transform to apply on \a o + * \return The Orientation resulting from applying \a t on \a o + */ +Orientation operator*(const Orientation &o, const Transform &t) +{ + /* + * Apply a Transform corresponding to the orientation first and + * then apply \a t to it. + */ + return transformToOrientation(transformFromOrientation(o) * t); +} + /** * \brief Return a character string describing the transform * \param[in] t The transform to be described. From patchwork Thu Oct 19 14:01:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 19156 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 8CB9BC3272 for ; Thu, 19 Oct 2023 14:02:00 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0788C62985; Thu, 19 Oct 2023 16:02:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1697724120; bh=MDEdF8Zm/uyI+9cj5qgwNyaQdBJJAz/15IywI44RK50=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=Fguc0KaaHlpQUVGIOBOYEDnUppKjP8nCQdmDUiS4crP8JVzHot4Zn5U9btxgHbXw4 EK/mN0LH1oiig0uZ6/WDkVQepG2dgmRPiGnDYXd519RRaL3Cn3XK6g4tBpuB5iCYSC yxvU1jX0SR/77CzQJKWBfLP9kvQXTB8J1Z1WFs/drCpCoWemXf8YgdHbXVBK6SHJBO 2qIiEn1PJdhXrhaWUogn24FGWECPfLTKaHQU9y6jhFWuiO7pxuOQunZCrxOa/zGfYp GN7r+U+PtPErXp2Xa9hoSfbZm9YZjY9jbtu2ROGTtj0Q2f8AJPjGLI4jNGUdBl26OA gZVVHFRhv2o1Q== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 06A066298F for ; Thu, 19 Oct 2023 16:01:53 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="nyMFxhZ8"; dkim-atps=neutral Received: from uno.LocalDomain (93-61-96-190.ip145.fastwebnet.it [93.61.96.190]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id DFBA3276; Thu, 19 Oct 2023 16:01:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1697724105; bh=MDEdF8Zm/uyI+9cj5qgwNyaQdBJJAz/15IywI44RK50=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nyMFxhZ8jrR+Q5shqdFvJWsYRuxNFcEuoXOgykxhejfxCGruH+Sby6Rs8jZExDctU 56H5a9in+nnYd0wnnd2HHop70bp1bbyNsKtiONBP8hh9UYW/5mZLBPUPshEROIb8a3 a86k8qQZeL+lozP3lWGAUeLcmCI87ih5meUZ5cns= To: libcamera-devel@lists.libcamera.org Date: Thu, 19 Oct 2023 16:01:29 +0200 Message-ID: <20231019140133.32090-9-jacopo.mondi@ideasonboard.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231019140133.32090-1-jacopo.mondi@ideasonboard.com> References: <20231019140133.32090-1-jacopo.mondi@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 08/12] test: Add unit test for Transform and Orientation X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jacopo Mondi via libcamera-devel From: Jacopo Mondi Reply-To: Jacopo Mondi Cc: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add a unit test for Transform and Orientation to validate the implementation of the operations between the two types. In particular, test that: o1 / o2 = t o2 * t = o1 Signed-off-by: Jacopo Mondi Reviewed-by: David Plowman Reviewed-by: Laurent Pinchart --- test/meson.build | 1 + test/transform.cpp | 329 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 330 insertions(+) create mode 100644 test/transform.cpp diff --git a/test/meson.build b/test/meson.build index b227be818419..189e1428485a 100644 --- a/test/meson.build +++ b/test/meson.build @@ -46,6 +46,7 @@ public_tests = [ {'name': 'public-api', 'sources': ['public-api.cpp']}, {'name': 'signal', 'sources': ['signal.cpp']}, {'name': 'span', 'sources': ['span.cpp']}, + {'name': 'transform', 'sources': ['transform.cpp']}, ] internal_tests = [ diff --git a/test/transform.cpp b/test/transform.cpp new file mode 100644 index 000000000000..fbc0308c5d45 --- /dev/null +++ b/test/transform.cpp @@ -0,0 +1,329 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2023, Ideas On Board Oy + * + * transform.cpp - Transform and Orientation tests + */ + +#include + +#include +#include + +#include "test.h" + +using namespace std; +using namespace libcamera; + +class TransformTest : public Test +{ +protected: + int run(); +}; + +int TransformTest::run() +{ + /* + * RotationTestEntry collects two Orientation and one Transform that + * gets combined to validate that (o1 / o2 = T) and (o1 = o2 * T) + * + * o1 / o2 = t computes the Transform to apply to o2 to obtain o1 + * o2 * t = o1 combines o2 with t by applying o2 first then t + * + * The comments on the (most complex) transform show how applying to + * an image with orientation o2 the Transform t allows to obtain o1. + * + * The image with basic rotation0 is assumed to be: + * + * AB + * CD + * + * And the Transform operators are: + * + * V = vertical flip + * H = horizontal flip + * T = transpose + * + * the operator '* (T|V)' applies V first then T. + */ + static const struct RotationTestEntry { + Orientation o1; + Orientation o2; + Transform t; + } testEntries[] = { + /* Test identities transforms first. */ + { + Orientation::Rotate0, Orientation::Rotate0, + Transform::Identity, + }, + { + Orientation::Rotate0Mirror, Orientation::Rotate0Mirror, + Transform::Identity, + }, + { + Orientation::Rotate180, Orientation::Rotate180, + Transform::Identity, + }, + { + Orientation::Rotate180Mirror, Orientation::Rotate180Mirror, + Transform::Identity, + }, + { + Orientation::Rotate90, Orientation::Rotate90, + Transform::Identity, + }, + { + Orientation::Rotate90Mirror, Orientation::Rotate90Mirror, + Transform::Identity, + }, + { + Orientation::Rotate270, Orientation::Rotate270, + Transform::Identity, + }, + { + Orientation::Rotate270Mirror, Orientation::Rotate270Mirror, + Transform::Identity, + }, + /* + * Combine 0 and 180 degrees rotation as they're the most common + * ones. + */ + { + /* + * o2 t o1 + * -------------------------- + * CD * (H|V) = BA AB + * BA CD CD + */ + Orientation::Rotate0, Orientation::Rotate180, + Transform::Rot180, + }, + { + /* + * o2 t o1 + * -------------------------- + * AB * (H|V) = CD DC + * CD AB BA + */ + Orientation::Rotate180, Orientation::Rotate0, + Transform::Rot180 + }, + /* Test that transpositions are handled correctly. */ + { + /* + * o2 t o1 + * -------------------------- + * AB * (T|V) = CD CA + * CD AB DB + */ + Orientation::Rotate90, Orientation::Rotate0, + Transform::Rot90, + }, + { + /* + * o2 t o1 + * -------------------------- + * CA * (T|H) = AC AB + * DB BD CD + */ + Orientation::Rotate0, Orientation::Rotate90, + Transform::Rot270, + }, + { + /* + * o2 t o1 + * -------------------------- + * AB * (T|H) = BA BD + * CD DC AC + */ + Orientation::Rotate270, Orientation::Rotate0, + Transform::Rot270, + }, + { + /* + * o2 t o1 + * -------------------------- + * BD * (T|V) = AC AB + * AC BD CD + */ + Orientation::Rotate0, Orientation::Rotate270, + Transform::Rot90, + }, + { + /* + * o2 t o1 + * -------------------------- + * CD * (T|H) = DC DA + * BA AB CB + */ + Orientation::Rotate90, Orientation::Rotate180, + Transform::Rot270, + }, + { + /* + * o2 t o1 + * -------------------------- + * DA * (T|V) = CB CD + * CB DA BA + */ + Orientation::Rotate180, Orientation::Rotate90, + Transform::Rot90, + }, + { + /* + * o2 t o1 + * -------------------------- + * CD * (T|V) = BA BC + * BA CD AD + */ + Orientation::Rotate270, Orientation::Rotate180, + Transform::Rot90, + }, + { + /* + * o2 t o1 + * -------------------------- + * BC * (T|H) = CB CD + * AD DA BA + */ + Orientation::Rotate180, Orientation::Rotate270, + Transform::Rot270, + }, + { + /* + * o2 t o1 + * -------------------------- + * DA * (V|H) = AD BC + * CB BC AD + */ + Orientation::Rotate270, Orientation::Rotate90, + Transform::Rot180, + }, + /* Test that mirroring is handled correctly. */ + { + Orientation::Rotate0, Orientation::Rotate0Mirror, + Transform::HFlip + }, + { + Orientation::Rotate0Mirror, Orientation::Rotate0, + Transform::HFlip + }, + { + Orientation::Rotate180, Orientation::Rotate180Mirror, + Transform::HFlip + }, + { + Orientation::Rotate180Mirror, Orientation::Rotate180, + Transform::HFlip + }, + { + Orientation::Rotate90, Orientation::Rotate90Mirror, + Transform::HFlip + }, + { + Orientation::Rotate90Mirror, Orientation::Rotate90, + Transform::HFlip + }, + { + Orientation::Rotate270, Orientation::Rotate270Mirror, + Transform::HFlip + }, + { + Orientation::Rotate270Mirror, Orientation::Rotate270, + Transform::HFlip + }, + { + Orientation::Rotate0, Orientation::Rotate0Mirror, + Transform::HFlip + }, + /* + * More exotic transforms which include Transpositions and + * mirroring. + */ + { + /* + * o2 t o1 + * ------------------ + * BC * (V) = AD + * AD BC + */ + Orientation::Rotate90Mirror, Orientation::Rotate270, + Transform::VFlip, + }, + { + /* + * o2 t o1 + * ------------------ + * CB * (T) = CD + * DA BA + */ + Orientation::Rotate180, Orientation::Rotate270Mirror, + Transform::Transpose, + }, + { + /* + * o2 t o1 + * ------------------ + * AD * (T) = AB + * BC DC + */ + Orientation::Rotate0, Orientation::Rotate90Mirror, + Transform::Transpose, + }, + { + /* + * o2 t o1 + * ------------------ + * AD * (V) = BC + * BC AD + */ + Orientation::Rotate270, Orientation::Rotate90Mirror, + Transform::VFlip, + }, + { + /* + * o2 t o1 + * ------------------ + * DA * (V) = CB + * CB DA + */ + Orientation::Rotate270Mirror, Orientation::Rotate90, + Transform::VFlip, + }, + { + /* + * o2 t o1 + * -------------------------- + * CB * (V|H) = BC AD + * DA AD BC + */ + Orientation::Rotate90Mirror, Orientation::Rotate270Mirror, + Transform::Rot180, + }, + }; + + for (const auto &entry : testEntries) { + Transform transform = entry.o1 / entry.o2; + if (transform != entry.t) { + cerr << "Failed to validate: " << entry.o1 + << " / " << entry.o2 + << " = " << transformToString(entry.t) << endl; + cerr << "Got back: " + << transformToString(transform) << endl; + return TestFail; + } + + Orientation adjusted = entry.o2 * entry.t; + if (adjusted != entry.o1) { + cerr << "Failed to validate: " << entry.o2 + << " * " << transformToString(entry.t) + << " = " << entry.o1 << endl; + cerr << "Got back: " << adjusted << endl; + return TestFail; + } + } + + return TestPass; +} + +TEST_REGISTER(TransformTest) From patchwork Thu Oct 19 14:01:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 19157 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 4362BC32B9 for ; Thu, 19 Oct 2023 14:02:01 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CA7856298F; Thu, 19 Oct 2023 16:02:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1697724120; bh=+BfuYw/ENojz8fu8+mWFKfDwzkpRGph1acjzgncgusI=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=tWbcH07oiVxohtKUZNEhks6K2/2Nn64Z7PYCCb5ZFC5QWljmegQa2WN0PFH08bWso zVkXnUOtvfzaZH0EgOFQgErbZ4GSDSm21ENCnWU7UUjBl5NcKJt00sOv3mOGXqc65u dOW8bXFB7I0ft+wU2/zHwieh0inj3al91pLpKOrxPSr8YYW7OUhlGScqcPr5Rg8Cjq nI6kArY4OdwlFUur5/4euJBPl4fZtgWLKBFYy9Ru9awRVJ8ttdAdUpJglGUlt9nHAW 7WZqZVfAWX9ZikKv3LUW6QLWP9FhQlqv6KPKUdfvZYkit0eCz+LI5XMh80AGcep9yL kJiKjt1Pp6FQQ== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 797E262990 for ; Thu, 19 Oct 2023 16:01:53 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="pDv5TBP5"; dkim-atps=neutral Received: from uno.LocalDomain (93-61-96-190.ip145.fastwebnet.it [93.61.96.190]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 547A6735; Thu, 19 Oct 2023 16:01:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1697724105; bh=+BfuYw/ENojz8fu8+mWFKfDwzkpRGph1acjzgncgusI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pDv5TBP5bc+IIAujaiH4h5A9hIGqHEfepySbgn1E9GbYvKanDz4q/Gn20wQaiKdKY sK03cqzlz9p1/fCN0GVrinDrdoL80bpoqgCvgkTZjmeyj/w6gR96wuEisZc2dm+USy i4qVNlejkmEWvEhSp6zYPWyTp/z0mZpjHPhFDr3A= To: libcamera-devel@lists.libcamera.org Date: Thu, 19 Oct 2023 16:01:30 +0200 Message-ID: <20231019140133.32090-10-jacopo.mondi@ideasonboard.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231019140133.32090-1-jacopo.mondi@ideasonboard.com> References: <20231019140133.32090-1-jacopo.mondi@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 09/12] py: libcamera: Define and use Orientation X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jacopo Mondi via libcamera-devel From: Jacopo Mondi Reply-To: Jacopo Mondi Cc: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Define an enumeration type for Orientation and expose the CameraConfiguration::orientation property in place of CameraConfiguration::transform. Signed-off-by: Jacopo Mondi Reviewed-by: Tomi Valkeinen Reviewed-by: Laurent Pinchart --- src/py/libcamera/py_enums.cpp | 10 ++++++++++ src/py/libcamera/py_main.cpp | 1 + 2 files changed, 11 insertions(+) diff --git a/src/py/libcamera/py_enums.cpp b/src/py/libcamera/py_enums.cpp index 803c4e7ee362..e25689c674ef 100644 --- a/src/py/libcamera/py_enums.cpp +++ b/src/py/libcamera/py_enums.cpp @@ -31,4 +31,14 @@ void init_py_enums(py::module &m) .value("String", ControlType::ControlTypeString) .value("Rectangle", ControlType::ControlTypeRectangle) .value("Size", ControlType::ControlTypeSize); + + py::enum_(m, "Orientation") + .value("Rotate0", Orientation::Rotate0) + .value("Rotate0Mirror", Orientation::Rotate0Mirror) + .value("Rotate180", Orientation::Rotate180) + .value("Rotate180Mirror", Orientation::Rotate180Mirror) + .value("Rotate90Mirror", Orientation::Rotate90Mirror) + .value("Rotate270", Orientation::Rotate270) + .value("Rotate270Mirror", Orientation::Rotate270Mirror) + .value("Rotate90", Orientation::Rotate90); } diff --git a/src/py/libcamera/py_main.cpp b/src/py/libcamera/py_main.cpp index d2ce372297db..aa35f0a24847 100644 --- a/src/py/libcamera/py_main.cpp +++ b/src/py/libcamera/py_main.cpp @@ -330,6 +330,7 @@ PYBIND11_MODULE(_libcamera, m) .def_property_readonly("empty", &CameraConfiguration::empty) .def_readwrite("sensor_config", &CameraConfiguration::sensorConfig) .def_readwrite("transform", &CameraConfiguration::transform); + .def_readwrite("orientation", &CameraConfiguration::orientation); pyCameraConfigurationStatus .value("Valid", CameraConfiguration::Valid) From patchwork Thu Oct 19 14:01:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 19158 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id B804FC32B6 for ; Thu, 19 Oct 2023 14:02:01 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 64B0A62990; Thu, 19 Oct 2023 16:02:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1697724121; bh=X5W7dPBJHtPxuRkJfOmUDyL8Vi4mF+RUj60jDCoL9Vs=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=2QYLCINNbzflTv5O1nCIIq08nFOnUfi3aBXcTe3fcfSSQAZXDXPaDRln3jGZOrAPs 0k4gjDGdk/EPPy54TXlpzTqlNgZRxp1iHUkvoWOp6xZLL5wUasH8FX72oU31oLi/hV ERU8KpAUtVGtjbnBXRAIzKgcVN/0IVDLj77nM5A6Iwsfp0SXZDMkPvTEJZ24679P1P BuBfzN0SfohV3tZ33w/X41rTGJTB0kP0xENYQb9pvAT7aE8s7s+5nP6JvygVJwrijT gCOr00/VBRPM5ybPjoSwK4o4hSwR3msbnyA31OCXFxp73VlZG6FT/T2/DAb7QUTWX1 rZgEGZqc+YI9Q== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D599F62985 for ; Thu, 19 Oct 2023 16:01:53 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="AfHsEahf"; dkim-atps=neutral Received: from uno.LocalDomain (93-61-96-190.ip145.fastwebnet.it [93.61.96.190]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id C579B10FF; Thu, 19 Oct 2023 16:01:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1697724106; bh=X5W7dPBJHtPxuRkJfOmUDyL8Vi4mF+RUj60jDCoL9Vs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AfHsEahf/qPAh+5I9WiCG9vykdeHPE/hiL5YhsAp2yUxEAX8EwQqBQjpe0WmuT9/s Y368tRjTxLNxRv+VQKJvMD2st552WNus1G3xpUJjr6dhI5odmmgl/s99tdqY/9GRmj 3MRcQHGuRsX0Qw6/MOA/8CeCQkhXwKtvdmqaDwmA= To: libcamera-devel@lists.libcamera.org Date: Thu, 19 Oct 2023 16:01:31 +0200 Message-ID: <20231019140133.32090-11-jacopo.mondi@ideasonboard.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231019140133.32090-1-jacopo.mondi@ideasonboard.com> References: <20231019140133.32090-1-jacopo.mondi@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 10/12] libcamera: Use CameraConfiguration::orientation X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jacopo Mondi via libcamera-devel From: Jacopo Mondi Reply-To: Jacopo Mondi Cc: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Replace the usage of CameraConfiguration::transform with the newly introduced CameraConfiguration::orientation. Rework and rename the CameraSensor::validateTransform(transform) to CameraSensor::computeTransform(orientation), that given the desired image orientation computes the Transform that pipeline handlers should apply to the sensor to obtain it. Port all pipeline handlers to use the newly introduced function. This commit breaks existing applications as it removes the public CameraConfiguration::transform in favour of CameraConfiguration::orientation. Signed-off-by: Jacopo Mondi Reviewed-by: David Plowman --- include/libcamera/camera.h | 2 - include/libcamera/internal/camera_sensor.h | 4 +- src/libcamera/camera.cpp | 16 +--- src/libcamera/camera_sensor.cpp | 92 +++++++++---------- src/libcamera/pipeline/ipu3/ipu3.cpp | 6 +- src/libcamera/pipeline/rkisp1/rkisp1.cpp | 8 +- .../pipeline/rpi/common/pipeline_base.cpp | 9 +- src/libcamera/pipeline/simple/simple.cpp | 6 +- src/libcamera/pipeline/uvcvideo/uvcvideo.cpp | 4 +- src/libcamera/pipeline/vimc/vimc.cpp | 4 +- src/py/libcamera/py_main.cpp | 1 - 11 files changed, 66 insertions(+), 86 deletions(-) diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h index a4536c72a17e..ae35792dfbee 100644 --- a/include/libcamera/camera.h +++ b/include/libcamera/camera.h @@ -24,7 +24,6 @@ #include #include #include -#include namespace libcamera { @@ -94,7 +93,6 @@ public: std::size_t size() const; std::optional sensorConfig; - Transform transform; Orientation orientation; protected: diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h index 0b2ece317b2a..bcdb2d834dc3 100644 --- a/include/libcamera/internal/camera_sensor.h +++ b/include/libcamera/internal/camera_sensor.h @@ -33,6 +33,8 @@ class SensorConfiguration; struct CameraSensorProperties; +enum class Orientation; + class CameraSensor : protected Loggable { public: @@ -76,7 +78,7 @@ public: CameraLens *focusLens() { return focusLens_.get(); } - Transform validateTransform(Transform *transform) const; + Transform computeTransform(Orientation *orientation) const; protected: std::string logPrefix() const override; diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index 59ee3c40dc8e..0ad1a4b50447 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -291,8 +291,7 @@ bool SensorConfiguration::isValid() const * \brief Create an empty camera configuration */ CameraConfiguration::CameraConfiguration() - : transform(Transform::Identity), orientation(Orientation::Rotate0), - config_({}) + : orientation(Orientation::Rotate0), config_({}) { } @@ -540,19 +539,6 @@ CameraConfiguration::Status CameraConfiguration::validateColorSpaces(ColorSpaceF * from the same image source. */ -/** - * \var CameraConfiguration::transform - * \brief User-specified transform to be applied to the image - * - * The transform is a user-specified 2D plane transform that will be applied - * to the camera images by the processing pipeline before being handed to - * the application. - * - * The usual 2D plane transforms are allowed here (horizontal/vertical - * flips, multiple of 90-degree rotations etc.), but the validate() function - * may adjust this field at its discretion if the selection is not supported. - */ - /** * \var CameraConfiguration::orientation * \brief The desired orientation of the images produced by the camera diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index 521a19972808..f175f8b56077 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -16,6 +16,7 @@ #include #include +#include #include #include @@ -466,7 +467,7 @@ int CameraSensor::initProperties() /* * Cache the Transform associated with the camera mounting - * rotation for later use in validateTransform(). + * rotation for later use in computeTransform(). */ bool success; rotationTransform_ = transformFromRotation(propertyValue, &success); @@ -1109,69 +1110,64 @@ void CameraSensor::updateControlInfo() */ /** - * \brief Validate a transform request against the sensor capabilities - * \param[inout] transform The requested transformation, updated to match - * the sensor capabilities + * \brief Compute the Transform that gives the requested \a orientation + * \param[inout] orientation The desired image orientation * - * The input \a transform is the transform that the caller wants, and it is - * adjusted according to the capabilities of the sensor to represent the - * "nearest" transform that can actually be delivered. + * This function computes the Transform that the pipeline handler should apply + * to the CameraSensor to obtain the requested \a orientation. * - * The returned Transform is the transform applied to the sensor in order to - * produce the input \a transform, It is also validated against the sensor's - * ability to perform horizontal and vertical flips. + * The intended caller of this function is the validate() implementation of + * pipeline handlers, that pass in the application requested + * CameraConfiguration::orientation and obtain a Transform to apply to the + * camera sensor, likely at configure() time. * - * For example, if the requested \a transform is Transform::Identity and the - * sensor rotation is 180 degrees, the output transform will be - * Transform::Rot180 to correct the images so that they appear to have - * Transform::Identity, but only if the sensor can apply horizontal and vertical - * flips. + * If the requested \a orientation cannot be obtained, the \a orientation + * parameter is adjusted to report the current image orientation and + * Transform::Identity is returned. * - * \return A Transform instance that represents which transformation has been - * applied to the camera sensor + * If the requested \a orientation can be obtained, the function computes a + * Transform and does not adjust \a orientation. + * + * Pipeline handlers are expected to verify if \a orientation has been + * adjusted by this function and set the CameraConfiguration::status to + * Adjusted accordingly. + * + * \return A Transform instance that applied to the CameraSensor produces images + * with \a orientation */ -Transform CameraSensor::validateTransform(Transform *transform) const +Transform CameraSensor::computeTransform(Orientation *orientation) const { + Orientation mountingOrientation = transformToOrientation(rotationTransform_); + /* - * Combine the requested transform to compensate the sensor mounting - * rotation. + * If we cannot do any flips we cannot change the native camera mounting + * orientation. */ - Transform combined = rotationTransform_ * *transform; + if (!supportFlips_) { + *orientation = mountingOrientation; + return Transform::Identity; + } /* - * We combine the platform and user transform, but must "adjust away" - * any combined result that includes a transposition, as we can't do - * those. In this case, flipping only the transpose bit is helpful to - * applications - they either get the transform they requested, or have - * to do a simple transpose themselves (they don't have to worry about - * the other possible cases). + * Now compute the required transform to obtain 'orientation' starting + * from the mounting rotation. + * + * As a note: + * orientation / mountingOrientation = transform + * mountingOrientation * transform = orientation */ - if (!!(combined & Transform::Transpose)) { - /* - * Flipping the transpose bit in "transform" flips it in the - * combined result too (as it's the last thing that happens), - * which is of course clearing it. - */ - *transform ^= Transform::Transpose; - combined &= ~Transform::Transpose; - } + Transform transform = *orientation / mountingOrientation; /* - * We also check if the sensor doesn't do h/vflips at all, in which - * case we clear them, and the application will have to do everything. + * If transform contains any Transpose we cannot do it, so adjust + * 'orientation' to report the image native orientation and return Identity. */ - if (!supportFlips_ && !!combined) { - /* - * If the sensor can do no transforms, then combined must be - * changed to the identity. The only user transform that gives - * rise to this is the inverse of the rotation. (Recall that - * combined = rotationTransform * transform.) - */ - *transform = -rotationTransform_; - combined = Transform::Identity; + if (!!(transform & Transform::Transpose)) { + *orientation = mountingOrientation; + return Transform::Identity; } - return combined; + return transform; } std::string CameraSensor::logPrefix() const diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index a81c817a1255..fa4bd0bb73e2 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -187,9 +187,9 @@ CameraConfiguration::Status IPU3CameraConfiguration::validate() * rotation and store the final combined transform that configure() will * need to apply to the sensor to save us working it out again. */ - Transform requestedTransform = transform; - combinedTransform_ = data_->cio2_.sensor()->validateTransform(&transform); - if (transform != requestedTransform) + Orientation requestedOrientation = orientation; + combinedTransform_ = data_->cio2_.sensor()->computeTransform(&orientation); + if (orientation != requestedOrientation) status = Adjusted; /* Cap the number of entries to the available streams. */ diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp index 6efa79f29f66..586b46d64630 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp @@ -481,9 +481,9 @@ CameraConfiguration::Status RkISP1CameraConfiguration::validate() status = Adjusted; } - Transform requestedTransform = transform; - Transform combined = sensor->validateTransform(&transform); - if (transform != requestedTransform) + Orientation requestedOrientation = orientation; + combinedTransform_ = data_->sensor_->computeTransform(&orientation); + if (orientation != requestedOrientation) status = Adjusted; /* @@ -595,8 +595,6 @@ CameraConfiguration::Status RkISP1CameraConfiguration::validate() if (sensorFormat_.size.isNull()) sensorFormat_.size = sensor->resolution(); - combinedTransform_ = combined; - return status; } diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp index 7c88b87e0608..da52d7fafcee 100644 --- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp @@ -174,9 +174,9 @@ CameraConfiguration::Status RPiCameraConfiguration::validate() * rotation and store the final combined transform that configure() will * need to apply to the sensor to save us working it out again. */ - Transform requestedTransform = transform; - combinedTransform_ = data_->sensor_->validateTransform(&transform); - if (transform != requestedTransform) + Orientation requestedOrientation = orientation; + combinedTransform_ = data_->sensor_->computeTransform(&orientation); + if (orientation != requestedOrientation) status = Adjusted; rawStreams_.clear(); @@ -1234,7 +1234,8 @@ int CameraData::configureIPA(const CameraConfiguration *config, ipa::RPi::Config } /* Always send the user transform to the IPA. */ - params.transform = static_cast(config->transform); + params.transform = + static_cast(transformFromOrientation(config->orientation)); /* Ready the IPA - it must know about the sensor resolution. */ ret = ipa_->configure(sensorInfo_, params, result); diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp index 05ba76bce630..911051b28498 100644 --- a/src/libcamera/pipeline/simple/simple.cpp +++ b/src/libcamera/pipeline/simple/simple.cpp @@ -889,9 +889,9 @@ CameraConfiguration::Status SimpleCameraConfiguration::validate() if (config_.empty()) return Invalid; - Transform requestedTransform = transform; - combinedTransform_ = sensor->validateTransform(&transform); - if (transform != requestedTransform) + Orientation requestedOrientation = orientation; + combinedTransform_ = sensor->computeTransform(&orientation); + if (orientation != requestedOrientation) status = Adjusted; /* Cap the number of entries to the available streams. */ diff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp index 38f48a5d9269..ed9c7f8801f9 100644 --- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp +++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp @@ -111,8 +111,8 @@ CameraConfiguration::Status UVCCameraConfiguration::validate() if (config_.empty()) return Invalid; - if (transform != Transform::Identity) { - transform = Transform::Identity; + if (orientation != Orientation::Rotate0) { + orientation = Orientation::Rotate0; status = Adjusted; } diff --git a/src/libcamera/pipeline/vimc/vimc.cpp b/src/libcamera/pipeline/vimc/vimc.cpp index 00e6f4c6a51f..5536941ac0d5 100644 --- a/src/libcamera/pipeline/vimc/vimc.cpp +++ b/src/libcamera/pipeline/vimc/vimc.cpp @@ -128,8 +128,8 @@ CameraConfiguration::Status VimcCameraConfiguration::validate() if (config_.empty()) return Invalid; - if (transform != Transform::Identity) { - transform = Transform::Identity; + if (orientation != Orientation::Rotate0) { + orientation = Orientation::Rotate0; status = Adjusted; } diff --git a/src/py/libcamera/py_main.cpp b/src/py/libcamera/py_main.cpp index aa35f0a24847..bce082186a8b 100644 --- a/src/py/libcamera/py_main.cpp +++ b/src/py/libcamera/py_main.cpp @@ -329,7 +329,6 @@ PYBIND11_MODULE(_libcamera, m) .def_property_readonly("size", &CameraConfiguration::size) .def_property_readonly("empty", &CameraConfiguration::empty) .def_readwrite("sensor_config", &CameraConfiguration::sensorConfig) - .def_readwrite("transform", &CameraConfiguration::transform); .def_readwrite("orientation", &CameraConfiguration::orientation); pyCameraConfigurationStatus From patchwork Thu Oct 19 14:01:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 19159 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 774DBC32BA for ; Thu, 19 Oct 2023 14:02:02 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 437C062992; Thu, 19 Oct 2023 16:02:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1697724122; bh=Bc1cx3+5KkrNkgSxu51mTmO/e8HEdedyOAAJ9VgfzTM=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=E240sUaNA6zWt3ek2KSDUdCux7VZXyBrwS7wbVheX/pcb0jbUagDsYLAPaXZ2lN1P pgxE2uh+h2ILJUsZN+n04bcsRkb7nYOqjOY5uF2Ih0n6vDAYAW5EUESdg7sNBmpaVP vpInLIT66+IEkxNSN6UDA/GZZb9BbIMHZRJhN4qoMvzXWM6IOV8h95X1pKTXGd/uVY fsBAoCmBKpDMgcHWV8zuKutAcuZ7nazQmvQkUAk4hgO/zwt2AWz/QBj7VZ6q4eJ9wE MkAluzWmM3ekpCidsDEygtT411hs5VBh3hIJUOtNVrHViAwHCOyuAQBqa+lQJuObKT 4HxrHQuiRlNFg== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4430B62992 for ; Thu, 19 Oct 2023 16:01:54 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="rxqeuSLP"; dkim-atps=neutral Received: from uno.LocalDomain (93-61-96-190.ip145.fastwebnet.it [93.61.96.190]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 308F61211; Thu, 19 Oct 2023 16:01:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1697724106; bh=Bc1cx3+5KkrNkgSxu51mTmO/e8HEdedyOAAJ9VgfzTM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rxqeuSLPgygtplafKhMKBlSQYqqp5M1DF2rs1zbFDF9S89OtdInXzT/Sup48Q3jn1 g727eOHamhndky6V5ff02b/GPkvPGNJC17KR9yq2iuXhjBnhPk2FQvipUQQpZpXyTW GvPadV2rjl9j0rI4HZiby5vhhTFKlG/11A4YKunc= To: libcamera-devel@lists.libcamera.org Date: Thu, 19 Oct 2023 16:01:32 +0200 Message-ID: <20231019140133.32090-12-jacopo.mondi@ideasonboard.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231019140133.32090-1-jacopo.mondi@ideasonboard.com> References: <20231019140133.32090-1-jacopo.mondi@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 11/12] apps: cam: Add option to set stream orientation X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jacopo Mondi via libcamera-devel From: Jacopo Mondi Reply-To: Jacopo Mondi Cc: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add a '--orientation|-o' option to the cam test application to set an orientation to the image stream. Supported values are the ones obtained by applying flips to the camera sensor: - rot0: no rotation - rot180: rotate 180 degrees - flip: vertical flip - mirror: horizontal flip Signed-off-by: Jacopo Mondi Reviewed-by: David Plowman --- src/apps/cam/camera_session.cpp | 18 ++++++++++++++++++ src/apps/cam/main.cpp | 5 +++++ src/apps/cam/main.h | 1 + 3 files changed, 24 insertions(+) diff --git a/src/apps/cam/camera_session.cpp b/src/apps/cam/camera_session.cpp index 066e397b5f47..8447f932dfc7 100644 --- a/src/apps/cam/camera_session.cpp +++ b/src/apps/cam/camera_session.cpp @@ -65,6 +65,24 @@ CameraSession::CameraSession(CameraManager *cm, return; } + if (options_.isSet(OptOrientation)) { + std::string orientOpt = options_[OptOrientation].toString(); + static const std::map orientations{ + { "rot0", libcamera::Orientation::Rotate0 }, + { "rot180", libcamera::Orientation::Rotate180 }, + { "mirror", libcamera::Orientation::Rotate0Mirror }, + { "flip", libcamera::Orientation::Rotate180Mirror }, + }; + + auto orientation = orientations.find(orientOpt); + if (orientation == orientations.end()) { + std::cerr << "Invalid orientation " << orientOpt << std::endl; + return; + } + + config->orientation = orientation->second; + } + /* Apply configuration if explicitly requested. */ if (StreamKeyValueParser::updateConfiguration(config.get(), options_[OptStream])) { diff --git a/src/apps/cam/main.cpp b/src/apps/cam/main.cpp index 5d8a57bc14e5..179cc3769b03 100644 --- a/src/apps/cam/main.cpp +++ b/src/apps/cam/main.cpp @@ -133,6 +133,11 @@ int CamApp::parseOptions(int argc, char *argv[]) "Capture until interrupted by user or until frames captured", "capture", ArgumentOptional, "count", false, OptCamera); + + parser.addOption(OptOrientation, OptionString, + "Desired image orientation (rot0, rot180, mirror, flip)", + "orientation", ArgumentRequired, "orientation", false, + OptCamera); #ifdef HAVE_KMS parser.addOption(OptDisplay, OptionString, "Display viewfinder through DRM/KMS on specified connector", diff --git a/src/apps/cam/main.h b/src/apps/cam/main.h index 526aecece3f3..4aa959b32e13 100644 --- a/src/apps/cam/main.h +++ b/src/apps/cam/main.h @@ -17,6 +17,7 @@ enum { OptList = 'l', OptListProperties = 'p', OptMonitor = 'm', + OptOrientation = 'o', OptSDL = 'S', OptStream = 's', OptListControls = 256, From patchwork Thu Oct 19 14:01:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 19160 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 26929C32BB for ; Thu, 19 Oct 2023 14:02:03 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C97D96299E; Thu, 19 Oct 2023 16:02:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1697724122; bh=jPUq1A9sUQKQYtv41RZ3i6l4nfYqyMpxL+pYMbxUW64=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=vNbr5zhaUmj8hQFNjna4l4Z9h851bA3ScD6HH0hUBNPUpTnlD5/6tx41D3TLCtjxM f0afQ5qDgkkA/xLgxy3CdK2txOb6Tw9vnplmX25xKVigCTKin/q8OtMgwoObMyNf3F Qe45L7pIkN8MY9GJPIgNnT0ypjqueY1MDnQpH+sULY23wFyKXVUCNyJzDYa6FdOlgc jDBjuOkFtRBeb5m3Ndkpjok4MRfrydESnKSPr49fLSMy/DZMHFfgSQLdWif5AEcZGQ BsQJuO4PCSLP0Efs6i9U/IiJFfOkGDsgwfLbcH3VIkhEGH/BBh4Q9EVMKsm4+ofsgn WchCmGNdz0K3Q== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9C1C862982 for ; Thu, 19 Oct 2023 16:01:54 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="qRy1LNiC"; dkim-atps=neutral Received: from uno.LocalDomain (93-61-96-190.ip145.fastwebnet.it [93.61.96.190]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 90D93735; Thu, 19 Oct 2023 16:01:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1697724106; bh=jPUq1A9sUQKQYtv41RZ3i6l4nfYqyMpxL+pYMbxUW64=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qRy1LNiCPY+mmNAnUrfPmGnwXlAv3nUeXWJCPXPl9svVGUHV6r7k2W9L5gpmGnEdt X5kdjSFntsi2JiHXi152h5DLMbh5t2L1wxp4TakwesKipLdUboQh88bAUPtlmjhaCw rfOhF08KCKyyQkCcBRmQ42fjZz8CEHyhM6/vBtw8= To: libcamera-devel@lists.libcamera.org Date: Thu, 19 Oct 2023 16:01:33 +0200 Message-ID: <20231019140133.32090-13-jacopo.mondi@ideasonboard.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231019140133.32090-1-jacopo.mondi@ideasonboard.com> References: <20231019140133.32090-1-jacopo.mondi@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 12/12] py: cam: Add option to set stream orientation X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jacopo Mondi via libcamera-devel From: Jacopo Mondi Reply-To: Jacopo Mondi Cc: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add a '--orientation|-o' option to the Python version of the cam test application to set an orientation to the image stream. Supported values are: - rot0: no rotation - rot180: rotate 180 degrees - flip: vertical flip - mirror: horizontal flip Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- src/py/cam/cam.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/py/cam/cam.py b/src/py/cam/cam.py index a2a115c164b4..06bd51aa5efe 100755 --- a/src/py/cam/cam.py +++ b/src/py/cam/cam.py @@ -23,6 +23,7 @@ class CameraContext: opt_metadata: bool opt_save_frames: bool opt_capture: int + opt_orientation: str stream_names: dict[libcam.Stream, str] streams: list[libcam.Stream] @@ -146,6 +147,21 @@ class CameraContext: if 'pixelformat' in stream_opts: stream_config.pixel_format = libcam.PixelFormat(stream_opts['pixelformat']) + if self.opt_orientation is not None: + orientation_map = { + 'rot0': libcam.Orientation.Rotate0, + 'rot180': libcam.Orientation.Rotate180, + 'mirror': libcam.Orientation.Rotate0Mirror, + 'flip': libcam.Orientation.Rotate180Mirror, + } + + orient = orientation_map.get(self.opt_orientation, None) + if orient is None: + print('Bad orientation: ', self.opt_orientation) + sys.exit(-1) + + camconfig.orientation = orient + stat = camconfig.validate() if stat == libcam.CameraConfiguration.Status.Invalid: @@ -385,6 +401,7 @@ def main(): parser.add_argument('--metadata', nargs=0, type=bool, action=CustomAction, help='Print the metadata for completed requests') parser.add_argument('--strict-formats', type=bool, nargs=0, action=CustomAction, help='Do not allow requested stream format(s) to be adjusted') parser.add_argument('-s', '--stream', nargs='+', action=CustomAction) + parser.add_argument('-o', '--orientation', help='Desired image orientation (rot0, rot180, mirror, flip)') args = parser.parse_args() cm = libcam.CameraManager.singleton() @@ -408,6 +425,10 @@ def main(): ctx.opt_metadata = args.metadata.get(cam_idx, False) ctx.opt_strict_formats = args.strict_formats.get(cam_idx, False) ctx.opt_stream = args.stream.get(cam_idx, ['role=viewfinder']) + if args.orientation is not None: + ctx.opt_orientation = args.orientation + else: + ctx.opt_orientation = None contexts.append(ctx) for ctx in contexts: From patchwork Sun Oct 22 22:41:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 19172 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 87E32BDCBD for ; Sun, 22 Oct 2023 22:42:04 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 68B2062988; Mon, 23 Oct 2023 00:42:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1698014521; bh=jsX2FEZlWfOPS/fLsvnAPP8EC7SPNUJ6IrVArWH9Si8=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=tPa1WZP/54VWTFrQIEi2KSifewZ3RMYww+h54v7vFk5Lmztq69IgRSuyFvoJoke+N pqt8pHuo00q72T0+igYJ2HDOnj+QhQFEaRhkZY15rvWAshfk5P7LsejKYOyOux+RWg go9tzDVRdDauVWP21lWGTtEnMe2fFgFH+FukvX3QWiEGmqCkxForjrAdnemiu6qbgv lhIPmlCl1Nxou+pL/KnGpvwWrnMRKBb45ge7fzXOsJuo/umSMEOF8/LwjTXpGJEi92 3tO43F7pinLZ44GJt/s1pkEO+m4M9DL0jt6s55DKskqo/DYN1nfj5NNroOW2EZTcPe JtMLfo9ymVvDw== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4795961DD0 for ; Mon, 23 Oct 2023 00:41:52 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="B4dKCUsX"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (213-243-189-158.bb.dnainternet.fi [213.243.189.158]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 98337749; Mon, 23 Oct 2023 00:41:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1698014501; bh=jsX2FEZlWfOPS/fLsvnAPP8EC7SPNUJ6IrVArWH9Si8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=B4dKCUsXd98pe8bKXHGIUvaNNGvaqH/mw1nV5s6ZUcm1XPUMw2XVJk3MUe30DQYFz xtmkcg2QLj/fU1rEJg/xyCHpLIRKhqUjD/yPNam4aF5aXLPazQUtrGLNxPEGUCULiw CWMVrgkFjPmdvvQxbT7V+oXSvNZVvqwqUwenhTfk= To: libcamera-devel@lists.libcamera.org Date: Mon, 23 Oct 2023 01:41:51 +0300 Message-ID: <20231022224159.30298-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231019140133.32090-1-jacopo.mondi@ideasonboard.com> References: <20231019140133.32090-1-jacopo.mondi@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 13/12] fixup! libcamera: camera: Introduce Orientation X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Cc: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" - Add an orientationFromRotation() function Signed-off-by: Laurent Pinchart --- include/libcamera/orientation.h | 2 ++ src/libcamera/orientation.cpp | 36 +++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/include/libcamera/orientation.h b/include/libcamera/orientation.h index ae19d4c44a55..9a2c2fb2fbb1 100644 --- a/include/libcamera/orientation.h +++ b/include/libcamera/orientation.h @@ -23,6 +23,8 @@ enum class Orientation { Rotate90, }; +Orientation orientationFromRotation(int angle, bool *success = nullptr); + std::ostream &operator<<(std::ostream &out, const Orientation &orientation); } /* namespace libcamera */ diff --git a/src/libcamera/orientation.cpp b/src/libcamera/orientation.cpp index 5caf76f73865..a6363df30861 100644 --- a/src/libcamera/orientation.cpp +++ b/src/libcamera/orientation.cpp @@ -56,6 +56,42 @@ namespace libcamera { * \image html rotation/rotate90.svg */ +/** + * \brief Return the orientation representing a rotation of the given angle + * clockwise + * \param[in] angle The angle of rotation in a clockwise sense. Negative values + * can be used to represent anticlockwise rotations + * \param[out] success Set to `true` if the angle is a multiple of 90 degrees, + * otherwise `false` + * \return The orientation corresponding to the rotation if \a success was set + * to `true`, otherwise the `Rotate0` orientation + */ +Orientation orientationFromRotation(int angle, bool *success) +{ + angle = angle % 360; + if (angle < 0) + angle += 360; + + if (success != nullptr) + *success = true; + + switch (angle) { + case 0: + return Orientation::Rotate0; + case 90: + return Orientation::Rotate90; + case 180: + return Orientation::Rotate180; + case 270: + return Orientation::Rotate270; + } + + if (success != nullptr) + *success = false; + + return Orientation::Rotate0; +} + /** * \brief Prints human-friendly names for Orientation items * \param[in] out The output stream From patchwork Sun Oct 22 22:41:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 19169 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id C0D96BDCBD for ; Sun, 22 Oct 2023 22:41:59 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 242FD61DD0; Mon, 23 Oct 2023 00:41:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1698014519; bh=orJ8axHWwuV4beDroUq04obZWoVZnL2DgJuABEWlhWU=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=zjlWtQDUoWawPv+IY4utUxan66HFx8SKmryIyyyeNgvNqCza/fCkdtIAVHjUAs2u9 l/jhV3TvRyRleLasAE1tC1qTdGwSrFyZigHLLXF8ifuvkRgqm8lm7MIX//Q+CiYw4y m2ic4q1xsgQ1tJ7jpsgmMEnwI8V6dnZoLW5vQPPP4PegMzdBUC33WO3YnOFbfzZacM KJiTpEudH23o4zhO3lKNUlTyIRg9qsNHg21UKv8xZF0lQB6Tz+9fpSkYMklyi4hu2W dCFvg8kc0eOOPkFGBLFaPPX2j+SS8PmRMLgoAjQk5oJQxXYRdnURd+QrsFxwjHbvsb YutKTFuv4SPqA== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 78B956297C for ; Mon, 23 Oct 2023 00:41:53 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="tmi+zouj"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (213-243-189-158.bb.dnainternet.fi [213.243.189.158]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id F057BD20; Mon, 23 Oct 2023 00:41:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1698014503; bh=orJ8axHWwuV4beDroUq04obZWoVZnL2DgJuABEWlhWU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tmi+zouj4l/5c8gvgs5ncw6LaYfHrkKCdd4ZX63gcB48hpGnIPLN0RUCLGcQ/dITB 2Wq7ZaPpFHOkmhdvkILBnGIihTuHR2hCcGQdG4KWql+cASoc3AsPUdNmpkDXf49OCV 0GLMR+4Kn2SyT+PGenHaNdbb+Jct4c5OOUvFi+QY= To: libcamera-devel@lists.libcamera.org Date: Mon, 23 Oct 2023 01:41:52 +0300 Message-ID: <20231022224159.30298-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231019140133.32090-1-jacopo.mondi@ideasonboard.com> References: <20231019140133.32090-1-jacopo.mondi@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 14/12] fixup! libcamera: camera: Introduce Orientation X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Cc: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" - Fix typos in orientation strings Signed-off-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- src/libcamera/orientation.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libcamera/orientation.cpp b/src/libcamera/orientation.cpp index a6363df30861..bd17dea948a9 100644 --- a/src/libcamera/orientation.cpp +++ b/src/libcamera/orientation.cpp @@ -102,8 +102,8 @@ std::ostream &operator<<(std::ostream &out, const Orientation &orientation) { constexpr std::array orientationNames = { "", /* Orientation starts counting from 1. */ - "Rotate0", "rotate0Flip", - "Rotate180", "rotate180Flip", + "Rotate0", "Rotate0Mirror", + "Rotate180", "Rotate180Mirror", "Rotate90Mirror", "Rotate270", "Rotate270Mirror", "Rotate90", }; From patchwork Sun Oct 22 22:41:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 19170 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 16815BDCBD for ; Sun, 22 Oct 2023 22:42:02 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 40F4062983; Mon, 23 Oct 2023 00:42:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1698014520; bh=LUNhbAXjOW94UFntPSFOgT7cG31w8QBMM2ruwKXQzps=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=Vdoq5X8d/mcWgVprhvkKlxJVxNs6/ZZlA7S1IsnNOZ2dWI2rYym/I57/1liAbNFh4 9/R0/2Jcx/vWYG0CxaVJXzMtEmA215FWABROgoaLUtZc5XeAdjSFT+qAhJVoFzWGwK 6gtC/lotyR0qcqPsDSGxTNwLId2DM9dJUKVQEElwfutkBoAS4eXQn2fGe0lUwc72dW 3mLVhUJB7nxLGib/x6F4+G7uTy5EmcmCnBsYtqHkCC2qavPvOkjw2APaZDOwym2VxQ fbFDneuotwHeV2qyRm8uozrv3Hi5H6ZN1bUfaKSz32yii4hYqBAUTJzKSHKdcl7349 OoyBQxe+qEPgg== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 878ED6297E for ; Mon, 23 Oct 2023 00:41:54 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="bECHtf0G"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (213-243-189-158.bb.dnainternet.fi [213.243.189.158]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 3D877EBA; Mon, 23 Oct 2023 00:41:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1698014504; bh=LUNhbAXjOW94UFntPSFOgT7cG31w8QBMM2ruwKXQzps=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bECHtf0GhReHEGGSbAGS7iqjRcy001NVIMtVL8NLutwDmO/ghmVR9Iz0a95KmQcwl B+fwiMCH5DonIA+dkZBUNwQu4T+/SjSAINMc8qOAoVamZ6SGuAALKEhjN74v60jdOi XBcssqpPeE0DDueJcO+XHDzOX+z96LRLmkHWPLMQ= To: libcamera-devel@lists.libcamera.org Date: Mon, 23 Oct 2023 01:41:53 +0300 Message-ID: <20231022224159.30298-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231019140133.32090-1-jacopo.mondi@ideasonboard.com> References: <20231019140133.32090-1-jacopo.mondi@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 15/12] fixup! libcamera: camera: Introduce Orientation X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Cc: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" - Minor documentation improvement Signed-off-by: Laurent Pinchart --- src/libcamera/orientation.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libcamera/orientation.cpp b/src/libcamera/orientation.cpp index bd17dea948a9..965f5a8b916a 100644 --- a/src/libcamera/orientation.cpp +++ b/src/libcamera/orientation.cpp @@ -34,8 +34,8 @@ namespace libcamera { * Specification version 2.32, Tag 274 "Orientation", while the names of the * enumerated values report the rotation and mirroring operations performed. * - * In example Orientation::Rotate90Mirror describes the image transformation - * obtained by rotating 90 degrees clockwise first and then applying an + * For example, Orientation::Rotate90Mirror describes the orientation obtained + * by rotating the image 90 degrees clockwise first and then applying a * horizontal mirroring. * * \var CameraConfiguration::Rotate0 From patchwork Sun Oct 22 22:41:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 19171 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 94AC7C327D for ; Sun, 22 Oct 2023 22:42:03 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id DB8CF6298B; Mon, 23 Oct 2023 00:42:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1698014520; bh=68riQlISkZJCXaML5fDwxRa+HhSre6E/lhJjRdCvqrY=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=Ut0REliPP/1mXBqj7GbZz2CpUcA2smVy6eid0ao7L5MrMqa1SjJk5Uxj1D+rOZ7/y q3N1M8f32DZ6DVXUUWThpi7knN5yHw2b4bnBl1s/JTaCpbCKRDBCK2JNPM5OHuvuCy 7+s3/sM8CK1wmmIULDd/e/aSwm5PBKm9wUsYvbTdRx4ImGIXdsAcUwMe0Rsw1dZNBe k8MbiZuCucGPpGR8SrDnQTxUxsDT+odejV115FQeNm9uqzDkMxFfbcQ6GIBs/j8Cyv uqkwUxAVOGDepHPDJ3oSPGCQDQMOY6odUgFVRKmBvvJevjeq/rRywTroiRWXMgMAyP KtKVwBW7pjHjw== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DBB046297F for ; Mon, 23 Oct 2023 00:41:55 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="QB2El6V9"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (213-243-189-158.bb.dnainternet.fi [213.243.189.158]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 80AC2749; Mon, 23 Oct 2023 00:41:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1698014505; bh=68riQlISkZJCXaML5fDwxRa+HhSre6E/lhJjRdCvqrY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QB2El6V9rNirFrmqLM4zT64Bqg0eoJBQ+pS7FZ8v+5MtVw0Yn5Tdlvu2XNRtuAPlB qEBKZU3LEpN5zNkvRvPtWiAT7BsxM2dWy4ESnlxQqzhqmVIZDIei7Q8X7EmMW7PcgO MIg4hQPl/0ldscf9nYxjetjCNIcWlsxrOOGvXBYs= To: libcamera-devel@lists.libcamera.org Date: Mon, 23 Oct 2023 01:41:54 +0300 Message-ID: <20231022224159.30298-4-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231019140133.32090-1-jacopo.mondi@ideasonboard.com> References: <20231019140133.32090-1-jacopo.mondi@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 16/12] fixup! libcamera: transform: Invert operator*() operands X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Cc: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" - Simplify documentation Signed-off-by: Laurent Pinchart --- src/libcamera/transform.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/libcamera/transform.cpp b/src/libcamera/transform.cpp index 85bc2d28b0cd..0ccdb42fa406 100644 --- a/src/libcamera/transform.cpp +++ b/src/libcamera/transform.cpp @@ -193,21 +193,18 @@ Input image | | goes to output image | | * \param[in] t0 The first transform to apply * \param[in] t1 The second transform to apply * - * Compose two transforms by applying \a t1 after \a t0. The operation - * is conceptually equivalent to the canonical notion of function composition, - * with inverse order of operands. If in the canonical function composition - * notation "f * g" equals to "f(g())", the notation for Transforms composition - * "t0 * t1" equals to "t1(t0()))" where \a t0 is applied first, then \a t1. - * - * For example, `HFlip * Transpose` performs `HFlip` first and then the - * `Transpose` yielding `Rot270`, as shown below. + * Compose two transforms into a transform that is equivalent to first applying + * \a t0 and then applying \a t1. For example, `HFlip * Transpose` performs + * `HFlip` first and then the `Transpose` yielding `Rot270`, as shown below. ~~~ A-B B-A B-D Input image | | -> HFLip -> | | -> Transpose -> | | = Rot270 C-D D-C A-C ~~~ - * Note that composition is generally non-commutative for Transforms, - * and not the same as XOR-ing the underlying bit representations. + * Note that composition is generally non-commutative for Transforms, and not + * the same as XOR-ing the underlying bit representations. + * + * \return A Transform equivalent to applying \a t0 and then \a t1 */ Transform operator*(Transform t0, Transform t1) { From patchwork Sun Oct 22 22:41:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 19173 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 47A34C32B6 for ; Sun, 22 Oct 2023 22:42:05 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 341E862989; Mon, 23 Oct 2023 00:42:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1698014522; bh=OgsJHvCDHBt6YExnCbz5embblPd0uwTb1ztXustayS4=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=e5H2h2gt/LMxBon9xXDPDo0gHrPfy0SbIrrfMSNV8woohPp2if7wnu/z4eVJTziBO tsPaPsRxIgmKWS/a7iB/EEb5YA5nhJSHFBMWNHBasHGv+3Z6rd4kGWhom1X5ehNg2/ 0mY4N5Ctzb/daB0z08zZb1pF8y/9KyWFI0wmPhuZ1pO1qZCEPbxrsfNcUKv6d9ISs3 DUNb6JcjJY2OVsUQp1C3Kb90UujQbccd+Q1s460UkKaBDhQak32wOJiwSp80cMHwab ZXX6LmGrcnN6jzhB/Fhj6UnpDQkVRNLcXnRrjPa9Qzw1aK5saDEeWs9NJbDaLS8W1w anH+P17d8fyVA== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 31C6362980 for ; Mon, 23 Oct 2023 00:41:57 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="rRCV0UWP"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (213-243-189-158.bb.dnainternet.fi [213.243.189.158]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id CA860749; Mon, 23 Oct 2023 00:41:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1698014507; bh=OgsJHvCDHBt6YExnCbz5embblPd0uwTb1ztXustayS4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rRCV0UWPL8bAa1IW4QvD373IBB8cBB4VjSsxVYew5pggSdVT3hi8SIm3pKeNsNMOY jrkRnOvOp5bhJdVgqPvE7TfXP4Vr4SS57+HK4ZWBt2g6bpRgMT19RcXu22YOjgZEem 7yAQWodfBFMUzzrR3pMp485AB4R5ZYfEbN81rDLk= To: libcamera-devel@lists.libcamera.org Date: Mon, 23 Oct 2023 01:41:55 +0300 Message-ID: <20231022224159.30298-5-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231019140133.32090-1-jacopo.mondi@ideasonboard.com> References: <20231019140133.32090-1-jacopo.mondi@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 17/12] fixup! libcamera: transform: Add operations with Orientation X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Cc: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" - Fix parameter name in declaration of operator*() Signed-off-by: Laurent Pinchart --- include/libcamera/transform.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/libcamera/transform.h b/include/libcamera/transform.h index 847a1f94713c..9eb10e156d0d 100644 --- a/include/libcamera/transform.h +++ b/include/libcamera/transform.h @@ -75,7 +75,7 @@ Transform transformFromOrientation(const Orientation &orientation); Orientation transformToOrientation(const Transform &transform); Transform operator/(const Orientation &o1, const Orientation &o2); -Orientation operator*(const Orientation &o1, const Transform &t); +Orientation operator*(const Orientation &o, const Transform &t); const char *transformToString(Transform t); From patchwork Sun Oct 22 22:41:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 19174 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id DD074C32B7 for ; Sun, 22 Oct 2023 22:42:05 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B6CF56298F; Mon, 23 Oct 2023 00:42:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1698014522; bh=uzytg9XPiIIZvWsxEtW22xjQfMJLrMSeMWhrIHuTI9s=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=wsIakGU5GxCRJjMNOEsrHkpEkjwk15HAqS+q23cJZ+Vv9+JWPYRBO7p6RpDHkQUW5 N5kciVoXR2h0z1LTgkFgz6QJXxr4MJkktkfxKxK7VeKngqxv+LP12bFDA2hdtgsd/0 kjJCGQGeuxqvW1Ekv77EFCauewGofdZi9sxMNEyf1B8duC52WBkrMLKqqJw29upnhM tesy+VGTsTLyrR40bxKf1Who0iZLsE/TnCnG0s57mmbn7fic2d4zh8xBy7n6z3y7i0 kkVhGwpoyX2TODWFJSr+iJlFPRXFQmyiTQZuQIgVKsdoCcHyMIdGMKti8+2uBczRZf mm7JpFECpQZxQ== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 76E2161DD0 for ; Mon, 23 Oct 2023 00:41:58 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="e3PGVhO7"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (213-243-189-158.bb.dnainternet.fi [213.243.189.158]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 21584749; Mon, 23 Oct 2023 00:41:48 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1698014508; bh=uzytg9XPiIIZvWsxEtW22xjQfMJLrMSeMWhrIHuTI9s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=e3PGVhO7N+QM2OhoFwQ1gBXJjd5cB+T260YFuZjjtM6eQ5U1T7Pk/o08NVEtxFclI r1qtYUzQBLsSs5L8irK/k9QI2N15bEmAHZURR0Uquz3pEdpMF5nSbyvd4ZbwcTskUS Zg40i5+3cWr7xoc7baF4prtjfq3/PRpBlm0ZbVPA= To: libcamera-devel@lists.libcamera.org Date: Mon, 23 Oct 2023 01:41:56 +0300 Message-ID: <20231022224159.30298-6-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231019140133.32090-1-jacopo.mondi@ideasonboard.com> References: <20231019140133.32090-1-jacopo.mondi@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 18/12] fixup! libcamera: Use CameraConfiguration::orientation X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Cc: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" - Use division operator in rpi pipeline handler Signed-off-by: Laurent Pinchart --- src/libcamera/pipeline/rpi/common/pipeline_base.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp index da52d7fafcee..ee222d060e4a 100644 --- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp @@ -1234,8 +1234,8 @@ int CameraData::configureIPA(const CameraConfiguration *config, ipa::RPi::Config } /* Always send the user transform to the IPA. */ - params.transform = - static_cast(transformFromOrientation(config->orientation)); + Transform transform = config->orientation / Orientation::Rotate0; + params.transform = static_cast(transform); /* Ready the IPA - it must know about the sensor resolution. */ ret = ipa_->configure(sensorInfo_, params, result); From patchwork Sun Oct 22 22:41:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 19175 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 391F3C32B8 for ; Sun, 22 Oct 2023 22:42:06 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 664DA6298D; Mon, 23 Oct 2023 00:42:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1698014523; bh=vTFhs4od3h0Y/PLNg5ahJow5rZArqfKXmk+S/CiZSmA=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=ucXVuL5z5xnuSQaDKhLBAl772odByM3+IczXG17HnBMSqfUlldokbgXsHqJKKYNYL Y1UbAJelqc0So3TnyXZbOvfPLKmJxfgY3s75WKJxkT4HYzURLZj+gSI5aHxcXDiws0 fnoeLaDxo4AkmhZKv95i6yYR7ZcMRmu8OvMw8+FZXVtVrMxDWVEfc27HnG7YmF8LAJ AohK1IbLf5KuRuPrq3Um6teiuDKhOUU+LXjbqHDbE5G49luQeEycqZIF9vuTWim5eu ZIoQLo5JnMum/3mO8KvtvNmJJX9dBjdLVc/fi1uoYiOnuY4Beqz3lyD/etoYa33FP6 /mjkA6nP/hLDA== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A29B26297F for ; Mon, 23 Oct 2023 00:41:59 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="bFBfwf6g"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (213-243-189-158.bb.dnainternet.fi [213.243.189.158]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 4F242749; Mon, 23 Oct 2023 00:41:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1698014509; bh=vTFhs4od3h0Y/PLNg5ahJow5rZArqfKXmk+S/CiZSmA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bFBfwf6gOAorqXaLrechhyPKwKUck2nSEGp2biKvIULP2tABTrDlaLCNbf4ArvGOX OaZqQa94zVwzgFiqUiUGkLcqe4QQxJ+0msKcdalcidnW8UtJGmFpwPXP9OOjOxHc4L N2FudP2I5/w4KvgsFgxZHNFrUUdmqz4+s/eNn9sU= To: libcamera-devel@lists.libcamera.org Date: Mon, 23 Oct 2023 01:41:57 +0300 Message-ID: <20231022224159.30298-7-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231019140133.32090-1-jacopo.mondi@ideasonboard.com> References: <20231019140133.32090-1-jacopo.mondi@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 19/12] libcamera: camera_sensor: Cache mounting orientation instead of transform X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Cc: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The cached rotationTransform_ value is used in computeTransform() only, to compute the mounting orientation. Cache the mounting orientation instead, removing the need for the intermediate conversion of the rotation to a transform. Signed-off-by: Laurent Pinchart --- include/libcamera/internal/camera_sensor.h | 3 ++- src/libcamera/camera_sensor.cpp | 18 ++++++++---------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h index bcdb2d834dc3..60a8b106d175 100644 --- a/include/libcamera/internal/camera_sensor.h +++ b/include/libcamera/internal/camera_sensor.h @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -114,7 +115,7 @@ private: Rectangle activeArea_; const BayerFormat *bayerFormat_; bool supportFlips_; - Transform rotationTransform_; + Orientation mountingOrientation_; ControlList properties_; diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index f175f8b56077..d92616722bc3 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -470,12 +470,12 @@ int CameraSensor::initProperties() * rotation for later use in computeTransform(). */ bool success; - rotationTransform_ = transformFromRotation(propertyValue, &success); + mountingOrientation_ = orientationFromRotation(propertyValue, &success); if (!success) { LOG(CameraSensor, Warning) << "Invalid rotation of " << propertyValue << " degrees - ignoring"; - rotationTransform_ = Transform::Identity; + mountingOrientation_ = Orientation::Rotate0; } properties_.set(properties::Rotation, propertyValue); @@ -483,7 +483,7 @@ int CameraSensor::initProperties() LOG(CameraSensor, Warning) << "Rotation control not available, default to 0 degrees"; properties_.set(properties::Rotation, 0); - rotationTransform_ = Transform::Identity; + mountingOrientation_ = Orientation::Rotate0; } properties_.set(properties::PixelArraySize, pixelArraySize_); @@ -1137,14 +1137,12 @@ void CameraSensor::updateControlInfo() */ Transform CameraSensor::computeTransform(Orientation *orientation) const { - Orientation mountingOrientation = transformToOrientation(rotationTransform_); - /* * If we cannot do any flips we cannot change the native camera mounting * orientation. */ if (!supportFlips_) { - *orientation = mountingOrientation; + *orientation = mountingOrientation_; return Transform::Identity; } @@ -1153,17 +1151,17 @@ Transform CameraSensor::computeTransform(Orientation *orientation) const * from the mounting rotation. * * As a note: - * orientation / mountingOrientation = transform - * mountingOrientation * transform = orientation + * orientation / mountingOrientation_ = transform + * mountingOrientation_ * transform = orientation */ - Transform transform = *orientation / mountingOrientation; + Transform transform = *orientation / mountingOrientation_; /* * If transform contains any Transpose we cannot do it, so adjust * 'orientation' to report the image native orientation and return Identity. */ if (!!(transform & Transform::Transpose)) { - *orientation = mountingOrientation; + *orientation = mountingOrientation_; return Transform::Identity; } From patchwork Sun Oct 22 22:41:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 19176 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 7F9A3C327D for ; Sun, 22 Oct 2023 22:42:06 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E0FEF62985; Mon, 23 Oct 2023 00:42:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1698014523; bh=qAXR8TS9CNRCG9Mlbp+xkNxza2p3RXintc1ku3gVvQ0=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=XFNmw48/yQ33Nfk4mOExjphiIJrcgmRwCN39JUYYFM5DIMf5vVWQGTiD0lTrLSGRf FvdVP5Xbl85PUJIZEvEM4kPVo3wbrJ2ysfC4MkIObTIoRlsTyQFMAY3wbEi9arvazo 8Ri7zLNNkjApWc+2cXjp/zISjzww5M1ER73NXQjdh1PgyQ4Ad9ak9dQ9HlQz6wEvcv oZvhawjvlkUYW/Hk0Wh150FxIGP/+oUWbHgmhyqkMHC4DruQ3e1nYjcP59klr7l/p2 dnTT6QtiE0fhO9/t0+eRjNjpuP+i9Lr+SpNS+9Hal62yT+oDI2+S145eN9LzUSJ/8l TekAA4Jkf/GlQ== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 00A596298D for ; Mon, 23 Oct 2023 00:42:00 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="JAfyinkf"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (213-243-189-158.bb.dnainternet.fi [213.243.189.158]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 9A1B4D20; Mon, 23 Oct 2023 00:41:50 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1698014510; bh=qAXR8TS9CNRCG9Mlbp+xkNxza2p3RXintc1ku3gVvQ0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JAfyinkf8lDm1tSbfC3HYRdzeAgcI1tkEfw9rFQYKaOGNlMWQR/QBFpJ4Gfg5SJCq Udfpgn1uvlewh0HtBvY5fFxqEuVnVb0TvQIfpXwp3EKQEmvv9ZN9iB0icfpj3GYCG/ jJTUaOUMAZia6CkCoghrHjbeEciU14VojwL3h8Q0= To: libcamera-devel@lists.libcamera.org Date: Mon, 23 Oct 2023 01:41:58 +0300 Message-ID: <20231022224159.30298-8-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231019140133.32090-1-jacopo.mondi@ideasonboard.com> References: <20231019140133.32090-1-jacopo.mondi@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 20/12] libcamera: transform: Fold transformToOrientation() in its only caller X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Cc: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The transformToOrientation() function is called from Orientation operator*(const Orientation &o, const Transform &t); only. Fold the code in the caller and drop the transformToOrientation() function to drop what can be considered as an ill-defined operation from the API. Signed-off-by: Laurent Pinchart --- include/libcamera/transform.h | 1 - src/libcamera/transform.cpp | 50 ++++++++++++++--------------------- 2 files changed, 20 insertions(+), 31 deletions(-) diff --git a/include/libcamera/transform.h b/include/libcamera/transform.h index 9eb10e156d0d..4998a6c04cb7 100644 --- a/include/libcamera/transform.h +++ b/include/libcamera/transform.h @@ -72,7 +72,6 @@ constexpr Transform operator~(Transform t) Transform transformFromRotation(int angle, bool *success = nullptr); Transform transformFromOrientation(const Orientation &orientation); -Orientation transformToOrientation(const Transform &transform); Transform operator/(const Orientation &o1, const Orientation &o2); Orientation operator*(const Orientation &o, const Transform &t); diff --git a/src/libcamera/transform.cpp b/src/libcamera/transform.cpp index 0ccdb42fa406..cd2717c28c3a 100644 --- a/src/libcamera/transform.cpp +++ b/src/libcamera/transform.cpp @@ -330,35 +330,6 @@ Transform transformFromOrientation(const Orientation &orientation) return Transform::Identity; } -/** - * \brief Return the Orientation representing \a transform - * \param[in] transform The transform to convert - * \return The Orientation corresponding to \a transform - */ -Orientation transformToOrientation(const Transform &transform) -{ - switch (transform) { - case Transform::Identity: - return Orientation::Rotate0; - case Transform::HFlip: - return Orientation::Rotate0Mirror; - case Transform::VFlip: - return Orientation::Rotate180Mirror; - case Transform::Rot180: - return Orientation::Rotate180; - case Transform::Transpose: - return Orientation::Rotate90Mirror; - case Transform::Rot270: - return Orientation::Rotate270; - case Transform::Rot90: - return Orientation::Rotate90; - case Transform::Rot180Transpose: - return Orientation::Rotate270Mirror; - } - - return Orientation::Rotate0; -} - /** * \brief Return the Transform that applied to \a o2 gives \a o1 * \param o1 The Orientation to obtain @@ -389,7 +360,26 @@ Orientation operator*(const Orientation &o, const Transform &t) * Apply a Transform corresponding to the orientation first and * then apply \a t to it. */ - return transformToOrientation(transformFromOrientation(o) * t); + switch (transformFromOrientation(o) * t) { + case Transform::Identity: + return Orientation::Rotate0; + case Transform::HFlip: + return Orientation::Rotate0Mirror; + case Transform::VFlip: + return Orientation::Rotate180Mirror; + case Transform::Rot180: + return Orientation::Rotate180; + case Transform::Transpose: + return Orientation::Rotate90Mirror; + case Transform::Rot270: + return Orientation::Rotate270; + case Transform::Rot90: + return Orientation::Rotate90; + case Transform::Rot180Transpose: + return Orientation::Rotate270Mirror; + } + + return Orientation::Rotate0; } /** From patchwork Sun Oct 22 22:41:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 19177 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id AFF74C32B9 for ; Sun, 22 Oct 2023 22:42:06 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 82F236299B; Mon, 23 Oct 2023 00:42:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1698014524; bh=MJ7wHvEOETCVJDNchxhDWGfJNlIODO9/4WptVnFI3Z0=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=fOTPeKoVonYRjs3nlGwUsVkBYmH1LE8reKjCjDYJGMVAWyuzPf9qdPnpEksin5y97 ycYIypn0xDj2q1ADKS4pFFIxRVC56wyMrz3lO5G6vQoCk0hCCJePfJtuI3uheZuQv9 BHHnpV2+p6rCR6wp8XWiwQB9uFHN1rBh+PYkOtQVqDYQZISno0AtSijjWoPjsbYch3 4REvzved3NV68CyFMEMqbmvVxjrbBdKw8Qr6vuFfAt2L2r7p+acNxqGW14sxuABXwl pnUgroqY4AYby7vFk/x8vjeFz9yV0TmyGI1quSw+k8lUfrhNjEq4ODDT8nKjnJ3TkT bU1h8dbhuYyPg== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4767D62990 for ; Mon, 23 Oct 2023 00:42:02 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="cjaBZRrz"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (213-243-189-158.bb.dnainternet.fi [213.243.189.158]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id E752CD20; Mon, 23 Oct 2023 00:41:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1698014512; bh=MJ7wHvEOETCVJDNchxhDWGfJNlIODO9/4WptVnFI3Z0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cjaBZRrzNFlG9EtRiY2DGVXq6YzJb6/tJZtWNFoaIzxQvkcAiIwazV7n8wRYc/MhO 0VxBjZg4Cm2O8yLWTi7eBbO5ST/wNEIeJCeSXmpgm/z989aU7K0eVTTSfXTfhWc9Xd LUM2dv66RdIZtr/gytK4tjC9XLqI2jbUrssNP4WM= To: libcamera-devel@lists.libcamera.org Date: Mon, 23 Oct 2023 01:41:59 +0300 Message-ID: <20231022224159.30298-9-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231019140133.32090-1-jacopo.mondi@ideasonboard.com> References: <20231019140133.32090-1-jacopo.mondi@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 21/12] libcamera: transform: Make the transformFromOrientation() function static X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Cc: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Now that the transformFromOrientation() function isn't used outside of transform.cpp, make it static to remove it from the public API. Signed-off-by: Laurent Pinchart --- include/libcamera/transform.h | 1 - src/libcamera/transform.cpp | 4 ++++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/include/libcamera/transform.h b/include/libcamera/transform.h index 4998a6c04cb7..44cb4c6fc974 100644 --- a/include/libcamera/transform.h +++ b/include/libcamera/transform.h @@ -71,7 +71,6 @@ constexpr Transform operator~(Transform t) } Transform transformFromRotation(int angle, bool *success = nullptr); -Transform transformFromOrientation(const Orientation &orientation); Transform operator/(const Orientation &o1, const Orientation &o2); Orientation operator*(const Orientation &o, const Transform &t); diff --git a/src/libcamera/transform.cpp b/src/libcamera/transform.cpp index cd2717c28c3a..fb2d55ac1931 100644 --- a/src/libcamera/transform.cpp +++ b/src/libcamera/transform.cpp @@ -301,6 +301,8 @@ Transform transformFromRotation(int angle, bool *success) return Transform::Identity; } +namespace { + /** * \brief Return the transform representing \a orientation * \param[in] orientation The orientation to convert @@ -330,6 +332,8 @@ Transform transformFromOrientation(const Orientation &orientation) return Transform::Identity; } +} /* namespace */ + /** * \brief Return the Transform that applied to \a o2 gives \a o1 * \param o1 The Orientation to obtain