forked from edrosten/libcvd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
builtin_components.h
106 lines (80 loc) · 2.17 KB
/
builtin_components.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
#ifndef CVD_BUILTIN_TRAITS_H_
#define CVD_BUILTIN_TRAITS_H_
#include <limits>
#include <cstddef>
#if defined (CVD_HAVE_TOON)
#include <TooN/TooN.h>
#endif
namespace CVD
{
namespace Pixel
{
//The "Component" class gives us information about the pixel components,
//ie how many components there are and whay the type is.
//We use a 2 layer thing here so that Component is only properly defined
//for builtin types, unless explicitly overridden.
template<class P, int spp> struct component_base {
template<bool x> struct component_base_only_for_basic_types;
static const int fail = sizeof(component_base_only_for_basic_types<false>);
};
template<class P> struct component_base<P, 1>
{
};
//template <class P, int primitive = std::numeric_limits<P>::is_specialized> struct Component;
template<class P> struct Component
{
typedef P type;
static const size_t count = 1;
static const P& get(const P& pixel, size_t)
{
return pixel;
}
static P& get(P& pixel, size_t)
{
return pixel;
}
};
template<class P, int I> struct Component<P[I]>
{
typedef P type;
static const size_t count=I;
static const P& get(const P pixel[I], size_t i)
{
return pixel[i];
}
static inline P& get(P pixel[I], size_t i)
{
return pixel[i];
}
};
#if defined (CVD_HAVE_TOON)
template<int N, typename P> struct Component<TooN::Vector<N, P> >
{
typedef P type;
static const size_t count=N;
static inline const P & get(const TooN::Vector<N, P>& pixel, size_t i)
{
return pixel[i];
}
static inline P& get(TooN::Vector<N, P>& pixel, size_t i)
{
return pixel[i];
}
};
template<int N, int M, typename P> struct Component<TooN::Matrix<N,M, P> >
{
typedef P type;
static const size_t count=N*M;
static const P& get(const TooN::Matrix<N,M,P>& pixel, size_t i)
{
return pixel[i/M][i%M];
}
static inline P& get(TooN::Matrix<N,M,P>& pixel, size_t i)
{
return pixel[i/M][i%M];
}
};
#endif
}
}
#endif