From patchwork Fri Jul 14 14:15:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 18827 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 934AFC32AA for ; Fri, 14 Jul 2023 14:16:14 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3E9B7628D2; Fri, 14 Jul 2023 16:16:14 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1689344174; bh=J/w04h4LDd4HFy1aAx56ROTbTphrUdqJB5fqO1IyhZU=; 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=Y9KKVbhCkPSo7oCds3PmBZq6Bh90Hek44gikK1Tsr/5CAXhlyh0R/1W03aUOMZjTk kOFqTbpwboFssLAT33S2LYVd+7dqimRGXrLWueFJtk7kmf/w9rADwWj8bRH3Yfl5dI okixHME0+OWwJPJPNmdkcuxpI0VsJ3LihVNHVVL5NykykCsk9BnSYPT56+20/4qSHe 3Le8wnHzKgtLFqzP0aCTAlNlgTMg0Rq+fA9kUjc/HanELnjJAqZ2jA8qHXRb5+0edm tdVdUGCOXcFapQQEW2XWKBYqfTNoGNxQ/eSnrhxMMIjrNdK3ABD2UFFULpFhllX9mJ +o9szbE5SUKpA== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D0063628CB for ; Fri, 14 Jul 2023 16:16:11 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="OtmqRZhN"; dkim-atps=neutral Received: from uno.localdomain (mob-5-90-9-92.net.vodafone.it [5.90.9.92]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 68F6257E; Fri, 14 Jul 2023 16:15:20 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1689344121; bh=J/w04h4LDd4HFy1aAx56ROTbTphrUdqJB5fqO1IyhZU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OtmqRZhNumqImemGJ03HKIfeHWx6mzL5XSwMat5jlK/t/SZTbeoCrOYEjhUJykpZB yVY4PVdsPp+NuA9PMNv3cDxkcnYAO6bUe13/zHqlev1aEjzFJ64/FnAMRDCpkpVr9l bGX/ZRnPghZzPErdc0YLyl0rtH7Tkwp/wsYhEROE= To: libcamera-devel@lists.libcamera.org Date: Fri, 14 Jul 2023 16:15:45 +0200 Message-Id: <20230714141549.11085-6-jacopo.mondi@ideasonboard.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230714141549.11085-1-jacopo.mondi@ideasonboard.com> References: <20230714141549.11085-1-jacopo.mondi@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 5/9] 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. As transform.h now needs to include camera.h remove "#include " from camera.h to avoid a cyclic inclusion loop. Adjust all files that need to include transform.h directly and didn't do so because it was implicitly included by camera.h. Signed-off-by: Jacopo Mondi Reviewed-by: David Plowman --- include/libcamera/camera.h | 3 +- include/libcamera/transform.h | 4 ++ src/libcamera/camera.cpp | 1 + src/libcamera/pipeline/uvcvideo/uvcvideo.cpp | 1 + src/libcamera/transform.cpp | 58 ++++++++++++++++++++ 5 files changed, 66 insertions(+), 1 deletion(-) -- 2.40.1 diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h index 8132ef2506a4..55359d53f2ab 100644 --- a/include/libcamera/camera.h +++ b/include/libcamera/camera.h @@ -22,7 +22,6 @@ #include #include #include -#include namespace libcamera { @@ -31,6 +30,8 @@ class FrameBufferAllocator; class PipelineHandler; class Request; +enum class Transform; + class CameraConfiguration { public: diff --git a/include/libcamera/transform.h b/include/libcamera/transform.h index 2a6838c78369..573adf18715d 100644 --- a/include/libcamera/transform.h +++ b/include/libcamera/transform.h @@ -9,6 +9,8 @@ #include +#include + namespace libcamera { enum class Transform : int { @@ -69,6 +71,8 @@ constexpr Transform operator~(Transform t) } Transform transformFromRotation(int angle, bool *success = nullptr); +Transform transformFromOrientation(const CameraConfiguration::Orientation &orientation); +CameraConfiguration::Orientation transformToOrientation(const Transform &transform); const char *transformToString(Transform t); diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index c8bb56d4af7f..af842e70dcb0 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include "libcamera/internal/camera.h" #include "libcamera/internal/camera_controls.h" diff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp index 38f48a5d9269..02a6117c7955 100644 --- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp +++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include "libcamera/internal/camera.h" #include "libcamera/internal/device_enumerator.h" diff --git a/src/libcamera/transform.cpp b/src/libcamera/transform.cpp index 4668303d0676..03d2b52e7f38 100644 --- a/src/libcamera/transform.cpp +++ b/src/libcamera/transform.cpp @@ -299,6 +299,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 CameraConfiguration::Orientation &orientation) +{ + switch (orientation) { + case CameraConfiguration::rotate0: + return Transform::Identity; + case CameraConfiguration::rotate0Flip: + return Transform::HFlip; + case CameraConfiguration::rotate180: + return Transform::Rot180; + case CameraConfiguration::rotate180Flip: + return Transform::VFlip; + case CameraConfiguration::rotate90Flip: + return Transform::Transpose; + case CameraConfiguration::rotate90: + return Transform::Rot90; + case CameraConfiguration::rotate270Flip: + return Transform::Rot180Transpose; + case CameraConfiguration::rotate270: + return Transform::Rot270; + } + + return Transform::Identity; +} + +/** + * \brief Return the CameraConfiguration::Orientation representing \a transform + * \param[in] transform The transform to convert + * \return The Orientation corresponding to \a transform + */ +CameraConfiguration::Orientation transformToOrientation(const Transform &transform) +{ + switch (transform) { + case Transform::Identity: + return CameraConfiguration::rotate0; + case Transform::HFlip: + return CameraConfiguration::rotate0Flip; + case Transform::VFlip: + return CameraConfiguration::rotate180Flip; + case Transform::Rot180: + return CameraConfiguration::rotate180; + case Transform::Transpose: + return CameraConfiguration::rotate90Flip; + case Transform::Rot270: + return CameraConfiguration::rotate270; + case Transform::Rot90: + return CameraConfiguration::rotate90; + case Transform::Rot180Transpose: + return CameraConfiguration::rotate270Flip; + } + + return CameraConfiguration::rotate0; +} + /** * \brief Return a character string describing the transform * \param[in] t The transform to be described.