forked from edrosten/libcvd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpixel_traits.h
216 lines (185 loc) · 6.2 KB
/
pixel_traits.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#ifndef CVD_PIXEL_TRAITS_H_
#define CVD_PIXEL_TRAITS_H_
#include <limits>
#if defined (CVD_HAVE_TOON)
#include <TooN/TooN.h>
#endif
namespace CVD {
namespace Pixel {
//This is required for MIPSPro, since it is able to deduce more than gcc 3.3
//before a template is instantiated
template<class T> struct traits_error
{
};
// LIFT is a dummy parameter to lift the partial specialisations of traits
// on various types into templates again. Then the visibility of static const
// members is sorted out by the compiler correctly.
template<class T, int LIFT=0> struct traits: public traits_error<T>
{
static const bool integral=traits_error<T>::Error_trait_not_defined_for_this_class;
};
template<int LIFT> struct traits<unsigned char, LIFT>
{
typedef int wider_type;
typedef float float_type;
static const bool integral = true;
static const bool is_signed = false;
static const int bits_used = 8;
static const unsigned char max_intensity=(1 << bits_used) - 1;
};
template<int LIFT> struct traits<char, LIFT>
{
typedef int wider_type;
typedef float float_type;
static const bool integral = true;
static const bool is_signed = std::numeric_limits<char>::is_signed;
static const int bits_used = std::numeric_limits<char>::digits;
static const char max_intensity=(1 << bits_used) - 1;
};
template<int LIFT> struct traits<signed char, LIFT>
{
typedef int wider_type;
typedef float float_type;
static const bool integral = true;
static const bool is_signed = false;
static const int bits_used = 7;
static const signed char max_intensity=(1 << bits_used) - 1;
};
template<int LIFT> struct traits<short, LIFT>
{
typedef int wider_type;
typedef float float_type;
static const bool integral = true;
static const bool is_signed = true;
static const int bits_used = 15;
static const short max_intensity=(1 << bits_used) - 1;
};
template<int LIFT> struct traits<unsigned short, LIFT>
{
typedef int wider_type;
typedef float float_type;
static const bool integral = true;
static const bool is_signed = false;
static const int bits_used = 16;
static const unsigned short max_intensity=(1 << bits_used) - 1;
};
template<int LIFT> struct traits<int, LIFT>
{
typedef int wider_type;
typedef float float_type;
static const bool integral = true;
static const bool is_signed = true;
static const int bits_used = 16;
static const int max_intensity=(1 << bits_used) - 1;
};
template<int LIFT> struct traits<unsigned int, LIFT>
{
typedef unsigned int wider_type;
typedef float float_type;
static const bool integral = true;
static const bool is_signed = false;
static const int bits_used = 16;
static const unsigned int max_intensity=(1 << bits_used) - 1;
};
template<int LIFT> struct traits<long, LIFT>
{
typedef int wider_type;
typedef float float_type;
static const bool integral = true;
static const bool is_signed = true;
static const int bits_used = 16;
static const long max_intensity=(1 << bits_used) - 1;
};
template<int LIFT> struct traits<long long, LIFT>
{
typedef long long wider_type;
typedef double float_type;
static const bool integral = true;
static const bool is_signed = true;
static const int bits_used = 31;
static const long long max_intensity=(1ll << bits_used) - 1ll;
};
template<int LIFT> struct traits<unsigned long long, LIFT>
{
typedef unsigned long long wider_type;
typedef double float_type;
static const bool integral = true;
static const bool is_signed = false;
static const int bits_used = 31;
static const unsigned long long max_intensity=(1ull << bits_used) - 1ull;
};
template<int LIFT> struct traits<unsigned long, LIFT>
{
typedef unsigned int wider_type;
typedef float float_type;
static const bool integral = true;
static const bool is_signed = false;
static const int bits_used = 16;
static const long max_intensity=(1 << bits_used) - 1;
};
template<int LIFT> struct traits<float, LIFT>
{
typedef float wider_type;
typedef float float_type;
static const bool integral = false;
static const bool is_signed = true;
static const float max_intensity;
};
template<int LIFT> const float traits<float, LIFT>::max_intensity = 1.0f;
template<int LIFT> struct traits<double, LIFT>
{
typedef double wider_type;
typedef double float_type;
static const bool integral = false;
static const bool is_signed = true;
static const double max_intensity;
};
template<int LIFT> const double traits<double, LIFT>::max_intensity = 1.0;
template<int LIFT> struct traits<long double, LIFT>
{
typedef long double wider_type;
typedef long double float_type;
static const bool integral = false;
static const bool is_signed = true;
static const long double max_intensity;
};
template<int LIFT> struct traits<bool, LIFT>
{
typedef int wider_type; // int holds a sum of many bools
typedef float float_type; // which floating point type can hold them?
static const bool integral = true; // bool is integral
static const bool is_signed = false; // bool is unsigned
static const int bits_used = 1; // only one bit
static const bool max_intensity= true; // the 'high' value
};
#if defined (CVD_HAVE_TOON)
template<int N> struct traits<TooN::Vector<N> >
{
typedef TooN::Vector<N> wider_type;
typedef TooN::Vector<N> float_type;
static const bool integral = false;
static const bool is_signed = true;
static const TooN::Vector<N> max_intensity;
};
template <int N> const TooN::Vector<N> traits<TooN::Vector<N> >::max_intensity = TooN::Vector<N>(1.0);
template<int N, int M> struct traits<TooN::Matrix<N,M> >
{
typedef TooN::Matrix<N,M> wider_type;
typedef TooN::Matrix<N,M> float_type;
static const bool integral = false;
static const bool is_signed = true;
};
#endif
template<int LIFT> const long double traits<long double, LIFT>::max_intensity = 1.0;
template<class C> struct indirect_type
{
typedef C type;
};
template<class C, int N, int LIFT> struct traits<C[N], LIFT>
{
typedef typename indirect_type<typename traits<C>::wider_type[N]>::type wider_type;
typedef typename indirect_type<typename traits<C>::float_type[N]>::type float_type;
};
}
}
#endif