summaryrefslogtreecommitdiff
path: root/include/libcamera/transform.h
diff options
context:
space:
mode:
authorDavid Plowman <david.plowman@raspberrypi.com>2020-09-07 08:15:58 +0100
committerKieran Bingham <kieran.bingham@ideasonboard.com>2020-09-29 11:43:06 +0100
commitedf19e4c72842704933c66f519e708107a14c47b (patch)
tree0e8e0dcef9beec2e764ef039def74af7dda1334f /include/libcamera/transform.h
parentd522ad2549dfbd494c4f47222951522abecaea01 (diff)
libcamera: Add Transform enum to represent 2D plane transforms.
We implement 2D transforms as an enum class with 8 elements, consisting of the usual 2D plane transformations (flips, rotations etc.). The transform is made up of 3 bits, indicating whether the transform includes: a transpose, a horizontal flip (mirror) and a vertical flip. Signed-off-by: David Plowman <david.plowman@raspberrypi.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Diffstat (limited to 'include/libcamera/transform.h')
-rw-r--r--include/libcamera/transform.h78
1 files changed, 78 insertions, 0 deletions
diff --git a/include/libcamera/transform.h b/include/libcamera/transform.h
new file mode 100644
index 00000000..71b43da7
--- /dev/null
+++ b/include/libcamera/transform.h
@@ -0,0 +1,78 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2020, Raspberry Pi (Trading) Limited
+ *
+ * transform.h - 2D plane transforms
+ */
+
+#ifndef __LIBCAMERA_TRANSFORM_H__
+#define __LIBCAMERA_TRANSFORM_H__
+
+#include <string>
+
+namespace libcamera {
+
+enum class Transform : int {
+ Identity = 0,
+ Rot0 = Identity,
+ HFlip = 1,
+ VFlip = 2,
+ HVFlip = HFlip | VFlip,
+ Rot180 = HVFlip,
+ Transpose = 4,
+ Rot270 = HFlip | Transpose,
+ Rot90 = VFlip | Transpose,
+ Rot180Transpose = HFlip | VFlip | Transpose
+};
+
+constexpr Transform operator&(Transform t0, Transform t1)
+{
+ return static_cast<Transform>(static_cast<int>(t0) & static_cast<int>(t1));
+}
+
+constexpr Transform operator|(Transform t0, Transform t1)
+{
+ return static_cast<Transform>(static_cast<int>(t0) | static_cast<int>(t1));
+}
+
+constexpr Transform operator^(Transform t0, Transform t1)
+{
+ return static_cast<Transform>(static_cast<int>(t0) ^ static_cast<int>(t1));
+}
+
+constexpr Transform &operator&=(Transform &t0, Transform t1)
+{
+ return t0 = t0 & t1;
+}
+
+constexpr Transform &operator|=(Transform &t0, Transform t1)
+{
+ return t0 = t0 | t1;
+}
+
+constexpr Transform &operator^=(Transform &t0, Transform t1)
+{
+ return t0 = t0 ^ t1;
+}
+
+Transform operator*(Transform t0, Transform t1);
+
+Transform operator-(Transform t);
+
+constexpr bool operator!(Transform t)
+{
+ return t == Transform::Identity;
+}
+
+constexpr Transform operator~(Transform t)
+{
+ return static_cast<Transform>(~static_cast<int>(t) & 7);
+}
+
+Transform transformFromRotation(int angle, bool *success = nullptr);
+
+const char *transformToString(Transform t);
+
+} /* namespace libcamera */
+
+#endif /* __LIBCAMERA_TRANSFORM_H__ */