From patchwork Fri Sep 1 15:02:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 18968 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 706D2C32B1 for ; Fri, 1 Sep 2023 15:02:53 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1C66B628EA; Fri, 1 Sep 2023 17:02:53 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1693580573; 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=pnUO5sCc0yVcdFK4NUYq9puRbahTfOOgtHNPcA0oG1exlmNMDsm9vBIE84Zd8f4WO XijgQH9gGGmhQX3qn14EWgpPF7YRamnCIDXgOxJRknlRTtKeTPyhu9NPZBkpC/VLD1 PIUbgk+wAJpwTRlDHoUG3nEZpWsWhpxHKR67w4HsPt+VA2sBxwntZG8qPNM15Ojujx 5NiEJQuzGgUvZO/n2MCxQmyfh5s4/+7LN7WvhYAeBJYymxqdsRd1LBwZnYxWx9Ht2j 5h5j3Zzvx8FsRU0Fi/sQFJKr/ACCrwmr4YXupneNiLAXFlfJFR5emjD0nk1AdOyokW iM9CCvKqR+AZw== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E717B628E8 for ; Fri, 1 Sep 2023 17:02:50 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="IKo2s78U"; 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 6F0EA15E9; Fri, 1 Sep 2023 17:01:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1693580487; bh=C071+c9sKX4BUUndlfeOERBWDFRvAPyBmpu+wDpWu2E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IKo2s78UuanEo5YDXv5GpRKhRj4nSxo5PNedQ+vaMS62uwapqk4je0otrfN/qTvIM 3tbL6Sjj3/d6JkXuc9olY2x1yIBq3xlUTlj/zr/BUme8QIr6f5eb9LC7xIgXekdZKm 62F94SVzVACwQwg5CWmf+Cl67k9WyRf+CVy7Wbno= To: libcamera-devel@lists.libcamera.org Date: Fri, 1 Sep 2023 17:02:08 +0200 Message-Id: <20230901150215.11585-6-jacopo.mondi@ideasonboard.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230901150215.11585-1-jacopo.mondi@ideasonboard.com> References: <20230901150215.11585-1-jacopo.mondi@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 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..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.