@@ -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 */
@@ -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
- Add an orientationFromRotation() function Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> --- include/libcamera/orientation.h | 2 ++ src/libcamera/orientation.cpp | 36 +++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+)