From patchwork Tue Jul 18 10:52:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 18848 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 82AB4C32AB for ; Tue, 18 Jul 2023 10:52:31 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 44D61628D9; Tue, 18 Jul 2023 12:52:31 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1689677551; bh=yqDVuGpaamdkaEB2dVC3yi1+f1QsnW54T2hpQtgCfXo=; 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=JZ4APllopNXW5zCm5HQ1xTxYi8VqjaAIXX5hjBDJmmM9tudQanE6q365y7hxlFfUf yosE7jX+YiBQiCDzwpb4ErBvLTZ3y/QOlRIIR1gB4xTdC6mp6JckGi7K0rvqVFIFAb W2AGd/BQUoc041a2gpKmgTDI1NcWioyh/TrnHjvqS0OibcGNP/ganKp2mZDM2kJrS9 hSqWO5AiguC9mrvr+Ct448Rc4BKy3QaTNTRzRb3HLJqUTSfXB+uZdX7pJb8ADM+/WX /UlkGNaq9QSU/VAXiYIBx4JvD/AAOanyhmP4lrKTIGSe9U5DOGdUhhPmIgVbk6D1jt kjos4YxLwnCkw== 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 89BCD61E2B for ; Tue, 18 Jul 2023 12:52:27 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="WZgXf4rI"; 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 A4DB98D0; Tue, 18 Jul 2023 12:51:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1689677494; bh=yqDVuGpaamdkaEB2dVC3yi1+f1QsnW54T2hpQtgCfXo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WZgXf4rIaZwFcfr4xcmLH3nw9LlAKTcuECm144G1LgLPY16zSsHTn8AqhB6YnKT5K NLNGr7q2gPtOkU5fv0aqJqsa+MkqMFj4AJPvlijGK93Mr4Go+jEcW67+mryGsWkelr WbZ5/HmFeLQ73giIGHPlRHHJ7ToJg88oV7a2svcY= To: libcamera-devel@lists.libcamera.org Date: Tue, 18 Jul 2023 12:52:07 +0200 Message-Id: <20230718105210.83558-8-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 07/10] libcamera: transform: Add operations with 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 operations that allows to combine Transform with Orientation. - Transform operator/(Orientation1, Orientation2) allows to easily get back the Transform that needs to be applied to Orientation2 to get Orientation1 - Orientation operator*(Orientation1, Transform) allows to apply a Transform to an Orientation and obtain the combination of the two These two operations allow applications to use Transforms to manipulate the Orientation inside the CameraConfiguration, if they wish. Signed-off-by: Jacopo Mondi Reviewed-by: David Plowman --- include/libcamera/transform.h | 3 +++ src/libcamera/transform.cpp | 37 +++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/include/libcamera/transform.h b/include/libcamera/transform.h index 14f1db0e8572..847a1f94713c 100644 --- a/include/libcamera/transform.h +++ b/include/libcamera/transform.h @@ -74,6 +74,9 @@ Transform transformFromRotation(int angle, bool *success = nullptr); Transform transformFromOrientation(const Orientation &orientation); Orientation transformToOrientation(const Transform &transform); +Transform operator/(const Orientation &o1, const Orientation &o2); +Orientation operator*(const Orientation &o1, const Transform &t); + const char *transformToString(Transform t); } /* namespace libcamera */ diff --git a/src/libcamera/transform.cpp b/src/libcamera/transform.cpp index d192d63d9290..80cd804ca530 100644 --- a/src/libcamera/transform.cpp +++ b/src/libcamera/transform.cpp @@ -362,6 +362,43 @@ Orientation transformToOrientation(const Transform &transform) return Orientation::rotate0; } +/** + * \brief Return the Transform that applied to \a o2 gives \a o1 + * \param o1 The Orientation to obtain + * \param o2 The base Orientation + * + * This operation can be used to easily compute the Transform to apply to a + * base orientation \a o2 to get the desired orientation \a o1. + * + * The CameraSensor class uses this function to compute what Transform to apply + * to a camera with mounting rotation \a o2 (the base) to obtain the user + * requested orientation \a o1. + * + * \return A Transform that applied to \a o2 gives \a o1 + */ +Transform operator/(const Orientation &o1, const Orientation &o2) +{ + Transform t1 = transformFromOrientation(o1); + Transform t2 = transformFromOrientation(o2); + + return -t2 * t1; +} + +/** + * \brief Apply the Transform \a t on the base orientation \a o + * \param o The base orientation + * \param t The transform to apply on \a o + * \return The Orientation resulting from applying \a t on \a o + */ +Orientation operator*(const Orientation &o, const Transform &t) +{ + /* + * Apply a Transform corresponding to the base orientation first and + * then apply \a t to it. + */ + return transformToOrientation(transformFromOrientation(o) * t); +} + /** * \brief Return a character string describing the transform * \param[in] t The transform to be described.