From patchwork Thu Oct 19 14:01:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 19154 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 26955C32B7 for ; Thu, 19 Oct 2023 14:01:58 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7F78A62994; Thu, 19 Oct 2023 16:01:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1697724116; bh=FVwpDtultkqHVui0Dl+p6CR0d+d7jC2U8XeXemUzN2g=; 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=e2CAyluJzygUIQxwxCCgmi1qEz+mzCBxXkHxxOe5E/pHlv1+erPy2tSvzPHSBvViv +SdoPM8Pkjf11IjaksqQp8RC7Vul10drP+S3sROx2c3wvX2fbn4ADxlUSyT5I4UjrP gV6RIaN25GLaSS+j3XRI1HlXwVefc9ZLt1hSO1uySlVehqSG8Ut7McGoue+jyTrc1j tNO3LgvT0BzgC4CSRxMqGBy+2qHppj11Nyzz6RXPCUVx7XhRYJfF3tcZZQsId4lHzN MdqvA8y3TWBr/yZzbvGq7JjCz/6lYIXKOd3hUHKT1QwsvbJGoRQhsFeMTmGQ7cvNGN 6vFiQRH9pK7fg== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 37CDA6298A for ; Thu, 19 Oct 2023 16:01:52 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="jFtV8zMi"; 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 2101510FF; Thu, 19 Oct 2023 16:01:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1697724104; bh=FVwpDtultkqHVui0Dl+p6CR0d+d7jC2U8XeXemUzN2g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jFtV8zMiubn6njWiJdbwCndk0+pxzNhAfjs6gdxCs2/Ti/B208UkuxmOxbJ8IgzsO rSMyfTqV+o3Ie/8ixfuR6rYkP6N6sec/5WYSWL4qC1kYXDVRcKSJ07e08IOPwF3a1q ebxpWuq0gILYPb7Mw+pyyxvWM4OJ7+F60WsewRwE= To: libcamera-devel@lists.libcamera.org Date: Thu, 19 Oct 2023 16:01:27 +0200 Message-ID: <20231019140133.32090-7-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 06/12] libcamera: transform: Invert operator*() operands 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" The current definition of operator*(Transform t1, Transform t0) follows the function composition notion, where t0 is applied first then t1 is applied last. In order to introduce operator*(Orientation, Transform) where a Transform is applied on top of an Orientation, invert the operand order of operator*(Transform, Transform) so that usage of operator* with both Orientation and Transform can be made associative. For example: Orientation o; Transform t = t1 * t2 Orientation o1 = o * t = o * (t1 * t2) = (o * t1) * t2 = o * t1 * t2 Signed-off-by: Jacopo Mondi Reviewed-by: David Plowman --- src/libcamera/camera_sensor.cpp | 4 ++-- src/libcamera/transform.cpp | 19 +++++++++++-------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index 8ff72b424560..521a19972808 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -1136,7 +1136,7 @@ Transform CameraSensor::validateTransform(Transform *transform) const * Combine the requested transform to compensate the sensor mounting * rotation. */ - Transform combined = *transform * rotationTransform_; + Transform combined = rotationTransform_ * *transform; /* * We combine the platform and user transform, but must "adjust away" @@ -1165,7 +1165,7 @@ Transform CameraSensor::validateTransform(Transform *transform) const * If the sensor can do no transforms, then combined must be * changed to the identity. The only user transform that gives * rise to this is the inverse of the rotation. (Recall that - * combined = transform * rotationTransform.) + * combined = rotationTransform * transform.) */ *transform = -rotationTransform_; combined = Transform::Identity; diff --git a/src/libcamera/transform.cpp b/src/libcamera/transform.cpp index c305940100bf..38735c525aa3 100644 --- a/src/libcamera/transform.cpp +++ b/src/libcamera/transform.cpp @@ -189,14 +189,17 @@ Input image | | goes to output image | | */ /** - * \brief Compose two transforms together - * \param[in] t1 The second transform - * \param[in] t0 The first transform + * \brief Compose two transforms by applying \a t0 first then \a t1 + * \param[in] t0 The first transform to apply + * \param[in] t1 The second transform to apply + * + * Compose two transforms by applying \a t1 after \a t0. The operation + * is conceptually equivalent to the canonical notion of function composition, + * with inverse order of operands. If in the canonical function composition + * notation "f * g" equals to "f(g())", the notation for Transforms composition + * "t0 * t1" equals to "t1(t0()))" where \a t0 is applied first, then \a t1. * - * Composing transforms follows the usual mathematical convention for - * composing functions. That is, when performing `t1 * t0`, \a t0 is applied - * first, and then \a t1. - * For example, `Transpose * HFlip` performs `HFlip` first and then the + * For example, `HFlip * Transpose` performs `HFlip` first and then the * `Transpose` yielding `Rot270`, as shown below. ~~~ A-B B-A B-D @@ -206,7 +209,7 @@ Input image | | -> HFLip -> | | -> Transpose -> | | = Rot270 * Note that composition is generally non-commutative for Transforms, * and not the same as XOR-ing the underlying bit representations. */ -Transform operator*(Transform t1, Transform t0) +Transform operator*(Transform t0, Transform t1) { /* * Reorder the operations so that we imagine doing t0's transpose