Debian Codegraph @

cvd/internal/pixel_operations.h

raw symbols SCIP
1
2 #ifndef CVD_PIXEL_OPERATIONS_H_
3 #define CVD_PIXEL_OPERATIONS_H_
4
5 #include <cmath>
6 #include <cvd/internal/builtin_components.h>
7 #include <cvd/internal/convert_pixel_types.h>
8 #include <cvd/internal/pixel_traits.h>
9 #include <cvd/internal/rgb_components.h>
10
11 namespace CVD
12 {
13
14 namespace Pixel
15 {
16
17 // operations::assign<DestType>(dest,src)
18 template <class T, unsigned int N = Component<T>::count>
19 struct operations
20 {
21 inline static void assign(T& lhs, const T& rhs) { memcpy(&lhs, &rhs, sizeof(T)); }
22 template <class S>
23 inline static void assign(T& lhs, const S& rhs)
24 {
25 for(unsigned int i = 0; i < N; i++)
26 Component<T>::get(lhs, i) = (typename Component<T>::type)Component<S>::get(rhs, i);
27 }
28 template <class S>
29 inline static void add(T& lhs, const S& rhs)
30 {
31 for(unsigned int i = 0; i < N; ++i)
32 Component<T>::get(lhs, i) += Component<S>::get(rhs, i);
33 }
34 template <class S>
35 inline static void subtract(T& lhs, const S& rhs)
36 {
37 for(unsigned int i = 0; i < N; ++i)
38 Component<T>::get(lhs, i) -= Component<S>::get(rhs, i);
39 }
40 template <class S>
41 inline static void multiply(T& lhs, const S& rhs)
42 {
43 for(unsigned int i = 0; i < N; ++i)
44 Component<T>::get(lhs, i) = (typename Component<T>::type)(Component<T>::get(lhs, i) * rhs);
45 }
46 template <class S>
47 inline static void divide(T& lhs, const S& rhs)
48 {
49 for(unsigned int i = 0; i < N; ++i)
50 Component<T>::get(lhs, i) = (typename Component<T>::type)(Component<T>::get(lhs, i) / rhs);
51 }
52 inline static bool equal(const T& a, const T& b) { return memcmp(&a, &b, sizeof(T)) == 0; }
53 inline static void zero(T& t) { memset(&t, 0, sizeof(T)); }
54 };
55
56 template <class T>
57 struct operations<T, 1>
58 {
59 template <class S>
60 inline static void assign(T& lhs, const S& rhs) { lhs = (T)rhs; }
61 template <class S>
62 inline static void add(T& lhs, const S& rhs) { lhs += rhs; }
63 template <class S>
64 inline static void subtract(T& lhs, const S& rhs) { lhs -= rhs; }
65 template <class S>
66 inline static void multiply(T& lhs, const S& rhs) { lhs = (T)(lhs * rhs); }
67 template <class S>
68 inline static void divide(T& lhs, const S& rhs) { lhs = (T)(lhs / rhs); }
69 inline static bool equal(const T& a, const T& b) { return a == b; }
70 inline static void zero(T& t) { t = T(); }
71 };
72
73 };
74
75 };
76
77 #endif