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.