@@ -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);
@@ -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::rotate0Flip:
+ return Transform::HFlip;
+ case Orientation::rotate180:
+ return Transform::Rot180;
+ case Orientation::rotate180Flip:
+ return Transform::VFlip;
+ case Orientation::rotate90Flip:
+ return Transform::Transpose;
+ case Orientation::rotate90:
+ return Transform::Rot90;
+ case Orientation::rotate270Flip:
+ 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::rotate0Flip;
+ case Transform::VFlip:
+ return Orientation::rotate180Flip;
+ case Transform::Rot180:
+ return Orientation::rotate180;
+ case Transform::Transpose:
+ return Orientation::rotate90Flip;
+ case Transform::Rot270:
+ return Orientation::rotate270;
+ case Transform::Rot90:
+ return Orientation::rotate90;
+ case Transform::Rot180Transpose:
+ return Orientation::rotate270Flip;
+ }
+
+ return Orientation::rotate0;
+}
+
/**
* \brief Return a character string describing the transform
* \param[in] t The transform to be described.