[v3,22/29] libcamera: Add transpose() function to size
diff mbox series

Message ID 20251125162851.2301793-23-stefan.klug@ideasonboard.com
State Accepted
Headers show
Series
  • Full dewarper support on imx8mp
Related show

Commit Message

Stefan Klug Nov. 25, 2025, 4:28 p.m. UTC
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 <stefan.klug@ideasonboard.com>

---

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(+)

Comments

Kieran Bingham Nov. 25, 2025, 4:54 p.m. UTC | #1
Quoting Stefan Klug (2025-11-25 16:28:34)
> 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 <stefan.klug@ideasonboard.com>

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

> 
> ---
> 
> 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) ||
> -- 
> 2.51.0
>

Patch
diff mbox series

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) ||