summaryrefslogtreecommitdiff
path: root/src/ipa/libipa/vector.h
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2024-11-16 21:02:52 +0200
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2024-11-26 19:05:18 +0200
commitbc10ffca97fffe6d5ee9a7a054fb05bba13607a8 (patch)
treef4a8fc6c31b5d221dfd32871823d372b29ca8fa4 /src/ipa/libipa/vector.h
parent6089b5bc9429e707e9b535feef6c0d9557622895 (diff)
ipa: libipa: vector: Add r(), g() and b() accessors
The Vector class can be useful to represent RGB pixel values. Add r(), g() and b() accessors, similar to x(), y() and z(), along with an RGB type that aliases Vector<T, 3>. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Milan Zamazal <mzamazal@redhat.com>
Diffstat (limited to 'src/ipa/libipa/vector.h')
-rw-r--r--src/ipa/libipa/vector.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/ipa/libipa/vector.h b/src/ipa/libipa/vector.h
index b91e50b2..3168835b 100644
--- a/src/ipa/libipa/vector.h
+++ b/src/ipa/libipa/vector.h
@@ -126,6 +126,31 @@ public:
#endif /* __DOXYGEN__ */
constexpr T &z() { return data_[2]; }
+#ifndef __DOXYGEN__
+ template<bool Dependent = false, typename = std::enable_if_t<Dependent || Rows >= 1>>
+#endif /* __DOXYGEN__ */
+ constexpr const T &r() const { return data_[0]; }
+#ifndef __DOXYGEN__
+ template<bool Dependent = false, typename = std::enable_if_t<Dependent || Rows >= 2>>
+#endif /* __DOXYGEN__ */
+ constexpr const T &g() const { return data_[1]; }
+#ifndef __DOXYGEN__
+ template<bool Dependent = false, typename = std::enable_if_t<Dependent || Rows >= 3>>
+#endif /* __DOXYGEN__ */
+ constexpr const T &b() const { return data_[2]; }
+#ifndef __DOXYGEN__
+ template<bool Dependent = false, typename = std::enable_if_t<Dependent || Rows >= 1>>
+#endif /* __DOXYGEN__ */
+ constexpr T &r() { return data_[0]; }
+#ifndef __DOXYGEN__
+ template<bool Dependent = false, typename = std::enable_if_t<Dependent || Rows >= 2>>
+#endif /* __DOXYGEN__ */
+ constexpr T &g() { return data_[1]; }
+#ifndef __DOXYGEN__
+ template<bool Dependent = false, typename = std::enable_if_t<Dependent || Rows >= 3>>
+#endif /* __DOXYGEN__ */
+ constexpr T &b() { return data_[2]; }
+
constexpr double length2() const
{
double ret = 0;
@@ -143,6 +168,9 @@ private:
std::array<T, Rows> data_;
};
+template<typename T>
+using RGB = Vector<T, 3>;
+
template<typename T, unsigned int Rows, unsigned int Cols>
Vector<T, Rows> operator*(const Matrix<T, Rows, Cols> &m, const Vector<T, Cols> &v)
{