Debian Codegraph @

cvd/internal/pixel_traits.h

raw symbols SCIP
1 #ifndef CVD_PIXEL_TRAITS_H_
2 #define CVD_PIXEL_TRAITS_H_
3
4 #include <limits>
5
6 #if defined(CVD_HAVE_TOON)
7 #include <TooN/TooN.h>
8 #endif
9
10 namespace CVD
11 {
12 namespace Pixel
13 {
14
15 template <class T, int LIFT = 0>
16 struct traits
17 {
18 static_assert(std::numeric_limits<T>::is_specialized == true, "Traits not defined for this type");
19 using element_type = T;
20 using wider_type = decltype(T {} * T {});
21 typedef float float_type;
22 static const bool integral = true;
23 static const bool is_signed = std::numeric_limits<T>::is_signed;
24 static_assert(std::numeric_limits<T>::is_integer == true, "Library bug, we shouldn't be here");
25 static const int bits_used = std::numeric_limits<T>::digits;
26 static const T max_intensity = std::numeric_limits<T>::max();
27 };
28
29 template <int LIFT>
30 struct traits<float, LIFT>
31 {
32 using element_type = float;
33 typedef float wider_type;
34 typedef float float_type;
35 static const bool integral = false;
36 static const bool is_signed = true;
37 static const float max_intensity;
38 };
39
40 template <int LIFT>
41 const float traits<float, LIFT>::max_intensity = 1.0f;
42
43 template <int LIFT>
44 struct traits<double, LIFT>
45 {
46 using element_type = double;
47 typedef double wider_type;
48 typedef double float_type;
49 static const bool integral = false;
50 static const bool is_signed = true;
51 static const double max_intensity;
52 };
53
54 template <int LIFT>
55 const double traits<double, LIFT>::max_intensity = 1.0;
56
57 template <int LIFT>
58 struct traits<long double, LIFT>
59 {
60 using element_type = long double;
61 typedef long double wider_type;
62 typedef long double float_type;
63 static const bool integral = false;
64 static const bool is_signed = true;
65 static const long double max_intensity;
66 };
67
68 #if defined(CVD_HAVE_TOON)
69 template <int N>
70 struct traits<TooN::Vector<N>>
71 {
72 typedef TooN::Vector<N> wider_type;
73 typedef TooN::Vector<N> float_type;
74 static const bool integral = false;
75 static const bool is_signed = true;
76 static const TooN::Vector<N> max_intensity;
77 };
78 template <int N>
79 const TooN::Vector<N> traits<TooN::Vector<N>>::max_intensity = TooN::Vector<N>(1.0);
80
81 template <int N, int M>
82 struct traits<TooN::Matrix<N, M>>
83 {
84 typedef TooN::Matrix<N, M> wider_type;
85 typedef TooN::Matrix<N, M> float_type;
86 static const bool integral = false;
87 static const bool is_signed = true;
88 };
89
90 #endif
91
92 template <int LIFT>
93 const long double traits<long double, LIFT>::max_intensity = 1.0;
94
95 template <class C>
96 struct indirect_type
97 {
98 typedef C type;
99 };
100
101 template <class C, int N, int LIFT>
102 struct traits<C[N], LIFT>
103 {
104 typedef typename indirect_type<typename traits<C>::wider_type[N]>::type wider_type;
105 typedef typename indirect_type<typename traits<C>::float_type[N]>::type float_type;
106 };
107 }
108 }
109
110 #endif