From patchwork Tue Nov 25 16:28:34 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 25201 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 EEE9BC3338 for ; Tue, 25 Nov 2025 16:30:02 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 787A260B33; Tue, 25 Nov 2025 17:30:02 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Sly7K4cR"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E55D060AD0 for ; Tue, 25 Nov 2025 17:29:59 +0100 (CET) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:bae1:340c:573c:570b]) by perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 05586524; Tue, 25 Nov 2025 17:27:50 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1764088071; bh=Whf6J85kiCqddzmN8XRL2gX9/PkNgMqHWeAhj82Lx8U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Sly7K4cR5Ss17L9PT4HkSWMnH1MP3dS7r/1rQ4n3+BUiXXYtbW4tXITgNGOJEakhY FjKZCPhwqry8HuqTQ0gmRpnWqxw/UtYgodYJyp2HxQD6WMDt2HxvqOh9qqjyj+IXyE aVHwHteN+bgHLnSIo96S9FAi2LKX5xyfunLAaYaE= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug Subject: [PATCH v3 22/29] libcamera: Add transpose() function to size Date: Tue, 25 Nov 2025 17:28:34 +0100 Message-ID: <20251125162851.2301793-23-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251125162851.2301793-1-stefan.klug@ideasonboard.com> References: <20251125162851.2301793-1-stefan.klug@ideasonboard.com> MIME-Version: 1.0 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add a transpose() function to size that applies the Transformation::Transpose operation in the size. This is useful when handling orientation adjustments. Signed-off-by: Stefan Klug Reviewed-by: Kieran Bingham --- Changes in v3: - Added test case --- include/libcamera/geometry.h | 6 ++++++ src/libcamera/geometry.cpp | 10 ++++++++++ test/geometry.cpp | 5 +++++ 3 files changed, 21 insertions(+) diff --git a/include/libcamera/geometry.h b/include/libcamera/geometry.h index d9378efeca8c..572a07e2cf92 100644 --- a/include/libcamera/geometry.h +++ b/include/libcamera/geometry.h @@ -108,6 +108,12 @@ public: return *this; } + Size &transpose() + { + std::swap(width, height); + return *this; + } + [[nodiscard]] constexpr Size alignedDownTo(unsigned int hAlignment, unsigned int vAlignment) const { diff --git a/src/libcamera/geometry.cpp b/src/libcamera/geometry.cpp index de76d0c12a8c..2763967a6e57 100644 --- a/src/libcamera/geometry.cpp +++ b/src/libcamera/geometry.cpp @@ -209,6 +209,16 @@ std::string Size::toString() const * \return A reference to this object */ +/** + * \fn Size::transpose() + * \brief Transpose the size in place + * + * This function swaps width and height of this size. This effectively applies + * the \a Transform::Transpose transformation on this size. + * + * \return A reference to this object + */ + /** * \fn Size::alignedDownTo(unsigned int hAlignment, unsigned int vAlignment) * \brief Align the size down horizontally and vertically diff --git a/test/geometry.cpp b/test/geometry.cpp index 11df043b733b..a50b643b7ee6 100644 --- a/test/geometry.cpp +++ b/test/geometry.cpp @@ -203,6 +203,11 @@ protected: return TestFail; } + if (Size(200, 50).transpose() != Size(50, 200)) { + cout << "Size::transpose() test failed" << endl; + return TestFail; + } + /* Aspect ratio tests */ if (Size(0, 0).boundedToAspectRatio(Size(4, 3)) != Size(0, 0) || Size(1920, 1440).boundedToAspectRatio(Size(16, 9)) != Size(1920, 1080) ||