From patchwork Tue Jul 18 10:52:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 18846 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 8164FC32AA for ; Tue, 18 Jul 2023 10:52:29 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1F767628CE; Tue, 18 Jul 2023 12:52:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1689677549; bh=C071+c9sKX4BUUndlfeOERBWDFRvAPyBmpu+wDpWu2E=; 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=bbo3ihS5c4vGjlVtv5cc/9i6HlqD17VskmKh7Bniyjf2ayzI2fJj4BRGq/JWGawyu 3kTNQCN8YP+LE3DAYV6ZQTnzr78qxvQQBuoVTf02MvTu0L2z4Fp6irF1/qdvlA3s6f J1MrSsVMyHHa9jnXmCArmil5acJj01uwrao9b+w7ivgZftDQahmD+qiZ220wYrbGks DMQl0XaJHFX9U+a1J1OSIM72IvA+wWAihbToKIUQOyJ593QXAdeWNG8EqxMxgx6f6m POzYivpNHCwPomba0VX+T344rd54jFgkgvFSwlfb6ZLZcVeUApmWVwTd1Ea5CYfn+x e9E2FJh10DB+Q== 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 F02E9628C3 for ; Tue, 18 Jul 2023 12:52:25 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="NEbPxVH/"; dkim-atps=neutral Received: from uno.localdomain (mob-5-90-54-150.net.vodafone.it [5.90.54.150]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id E8A608D0; Tue, 18 Jul 2023 12:51:31 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1689677492; bh=C071+c9sKX4BUUndlfeOERBWDFRvAPyBmpu+wDpWu2E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NEbPxVH/oJlAG6YlhMKYXSK6pI4SCfmF9796T3SPHwN4fFJ4arB/IOn29vYSisoGs 3fwT7sZveSp+add6Ounsuy9qaRvqGLKKGi+Mmxm43dKxdAqfrn4rJ60YKiym9BopEK 257Jjl9iVwKQBAt/zsv7u0kklKH8mP+ESD401gQo= To: libcamera-devel@lists.libcamera.org Date: Tue, 18 Jul 2023 12:52:05 +0200 Message-Id: <20230718105210.83558-6-jacopo.mondi@ideasonboard.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230718105210.83558-1-jacopo.mondi@ideasonboard.com> References: <20230718105210.83558-1-jacopo.mondi@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 05/10] 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..c70cac3f14ee 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::rotate0Flip: + return Transform::HFlip; + case Orientation::rotate180: + return Transform::Rot180; + case Orientation::rotate180Flip: + return Transform::VFlip; + case Orientation::rotate90Flip: + return Transform::Transpose; + case Orientation::rotate90: + return Transform::Rot90; + case Orientation::rotate270Flip: + 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::rotate0Flip; + case Transform::VFlip: + return Orientation::rotate180Flip; + case Transform::Rot180: + return Orientation::rotate180; + case Transform::Transpose: + return Orientation::rotate90Flip; + case Transform::Rot270: + return Orientation::rotate270; + case Transform::Rot90: + return Orientation::rotate90; + case Transform::Rot180Transpose: + return Orientation::rotate270Flip; + } + + return Orientation::rotate0; +} + /** * \brief Return a character string describing the transform * \param[in] t The transform to be described.