[libcamera-devel] [PATCH v6 13/12] fixup! libcamera: camera: Introduce Orientation
Laurent Pinchart
laurent.pinchart at ideasonboard.com
Mon Oct 23 00:41:51 CEST 2023
- Add an orientationFromRotation() function
Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
---
include/libcamera/orientation.h | 2 ++
src/libcamera/orientation.cpp | 36 +++++++++++++++++++++++++++++++++
2 files changed, 38 insertions(+)
diff --git a/include/libcamera/orientation.h b/include/libcamera/orientation.h
index ae19d4c44a55..9a2c2fb2fbb1 100644
--- a/include/libcamera/orientation.h
+++ b/include/libcamera/orientation.h
@@ -23,6 +23,8 @@ enum class Orientation {
Rotate90,
};
+Orientation orientationFromRotation(int angle, bool *success = nullptr);
+
std::ostream &operator<<(std::ostream &out, const Orientation &orientation);
} /* namespace libcamera */
diff --git a/src/libcamera/orientation.cpp b/src/libcamera/orientation.cpp
index 5caf76f73865..a6363df30861 100644
--- a/src/libcamera/orientation.cpp
+++ b/src/libcamera/orientation.cpp
@@ -56,6 +56,42 @@ namespace libcamera {
* \image html rotation/rotate90.svg
*/
+/**
+ * \brief Return the orientation representing a rotation of the given angle
+ * clockwise
+ * \param[in] angle The angle of rotation in a clockwise sense. Negative values
+ * can be used to represent anticlockwise rotations
+ * \param[out] success Set to `true` if the angle is a multiple of 90 degrees,
+ * otherwise `false`
+ * \return The orientation corresponding to the rotation if \a success was set
+ * to `true`, otherwise the `Rotate0` orientation
+ */
+Orientation orientationFromRotation(int angle, bool *success)
+{
+ angle = angle % 360;
+ if (angle < 0)
+ angle += 360;
+
+ if (success != nullptr)
+ *success = true;
+
+ switch (angle) {
+ case 0:
+ return Orientation::Rotate0;
+ case 90:
+ return Orientation::Rotate90;
+ case 180:
+ return Orientation::Rotate180;
+ case 270:
+ return Orientation::Rotate270;
+ }
+
+ if (success != nullptr)
+ *success = false;
+
+ return Orientation::Rotate0;
+}
+
/**
* \brief Prints human-friendly names for Orientation items
* \param[in] out The output stream
--
Regards,
Laurent Pinchart
More information about the libcamera-devel
mailing list