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