[libcamera-devel,v6,05/12] libcamera: transform: Add functions to convert Orientation
diff mbox series

Message ID 20231019140133.32090-6-jacopo.mondi@ideasonboard.com
State Accepted
Headers show
Series
  • libcamera: Replace CameraConfiguration::transform
Related show

Commit Message

Jacopo Mondi Oct. 19, 2023, 2:01 p.m. UTC
Add two helper functions to the transform.cpp file that allows to
convert to and from an Orientation.

Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: David Plowman <david.plowman@raspberrypi.com>
---
 include/libcamera/transform.h |  4 +++
 src/libcamera/transform.cpp   | 60 +++++++++++++++++++++++++++++++++++
 2 files changed, 64 insertions(+)

Patch
diff mbox series

diff --git a/include/libcamera/transform.h b/include/libcamera/transform.h
index 2a6838c78369..14f1db0e8572 100644
--- a/include/libcamera/transform.h
+++ b/include/libcamera/transform.h
@@ -11,6 +11,8 @@ 
 
 namespace libcamera {
 
+enum class Orientation;
+
 enum class Transform : int {
 	Identity = 0,
 	Rot0 = Identity,
@@ -69,6 +71,8 @@  constexpr Transform operator~(Transform t)
 }
 
 Transform transformFromRotation(int angle, bool *success = nullptr);
+Transform transformFromOrientation(const Orientation &orientation);
+Orientation transformToOrientation(const Transform &transform);
 
 const char *transformToString(Transform t);
 
diff --git a/src/libcamera/transform.cpp b/src/libcamera/transform.cpp
index 4668303d0676..c305940100bf 100644
--- a/src/libcamera/transform.cpp
+++ b/src/libcamera/transform.cpp
@@ -7,6 +7,8 @@ 
 
 #include <libcamera/transform.h>
 
+#include <libcamera/orientation.h>
+
 /**
  * \file transform.h
  * \brief Enum to represent and manipulate 2D plane transforms
@@ -299,6 +301,64 @@  Transform transformFromRotation(int angle, bool *success)
 	return Transform::Identity;
 }
 
+/**
+ * \brief Return the transform representing \a orientation
+ * \param[in] orientation The orientation to convert
+ * \return The transform corresponding to \a orientation
+ */
+Transform transformFromOrientation(const Orientation &orientation)
+{
+	switch (orientation) {
+	case Orientation::Rotate0:
+		return Transform::Identity;
+	case Orientation::Rotate0Mirror:
+		return Transform::HFlip;
+	case Orientation::Rotate180:
+		return Transform::Rot180;
+	case Orientation::Rotate180Mirror:
+		return Transform::VFlip;
+	case Orientation::Rotate90Mirror:
+		return Transform::Transpose;
+	case Orientation::Rotate90:
+		return Transform::Rot90;
+	case Orientation::Rotate270Mirror:
+		return Transform::Rot180Transpose;
+	case Orientation::Rotate270:
+		return Transform::Rot270;
+	}
+
+	return Transform::Identity;
+}
+
+/**
+ * \brief Return the Orientation representing \a transform
+ * \param[in] transform The transform to convert
+ * \return The Orientation corresponding to \a transform
+ */
+Orientation transformToOrientation(const Transform &transform)
+{
+	switch (transform) {
+	case Transform::Identity:
+		return Orientation::Rotate0;
+	case Transform::HFlip:
+		return Orientation::Rotate0Mirror;
+	case Transform::VFlip:
+		return Orientation::Rotate180Mirror;
+	case Transform::Rot180:
+		return Orientation::Rotate180;
+	case Transform::Transpose:
+		return Orientation::Rotate90Mirror;
+	case Transform::Rot270:
+		return Orientation::Rotate270;
+	case Transform::Rot90:
+		return Orientation::Rotate90;
+	case Transform::Rot180Transpose:
+		return Orientation::Rotate270Mirror;
+	}
+
+	return Orientation::Rotate0;
+}
+
 /**
  * \brief Return a character string describing the transform
  * \param[in] t The transform to be described.