1 #ifndef CVD_CONVERT_PIXEL_TYPES_H 2 #define CVD_CONVERT_PIXEL_TYPES_H 5 #include <cvd/internal/builtin_components.h> 6 #include <cvd/internal/rgb_components.h> 7 #include <cvd/internal/scalar_convert.h> 10 #include <type_traits> 21 template <class From, class To, int CF = Pixel::Component<From>::count,
int CT = Pixel::Component<To>::count>
24 template <
class From,
class To>
27 static inline void convert(
const From& from, To& to)
29 to = scalar_convert<To, From>(from);
33 template <
class From,
class To,
int N>
36 typedef typename Pixel::Component<From>::type FromS;
37 typedef typename Pixel::Component<To>::type ToS;
38 static inline void convert(
const From& from, To& to)
40 for(
int i = 0; i < N; i++)
45 template <
class T,
int N>
48 static inline void convert(
const T& from, T& to)
54 template <
class T,
int N>
58 static inline void convert(
const array& from, array& to)
60 for(
int i = 0; i < N; i++)
65 template <
class Rgbish,
class Scalar>
68 static inline void convert(
const Rgbish& from, Scalar& to)
82 const double wr = 0.2989959716796875, wg = 0.587005615234375, wb = 0.1139984130859375;
96 to = scalar_convert<Scalar, typename Pixel::Component<Rgbish>::type,
double>(wr *
static_cast<double>(from.red) + wg * static_cast<double>(from.green) + wb *
static_cast<double>(from.blue));
109 template <
class P,
class Scalar>
112 static inline void convert(
const P& from, Scalar& to)
114 typedef typename Pixel::Component<P>::type T;
116 for(
unsigned int i = 1; i < Pixel::Component<P>::count; i++)
122 template <
class P,
class Scalar>
125 static inline void convert(
const P& from, Scalar& to)
127 typedef typename Pixel::Component<P>::type T;
130 for(
unsigned int i = 1; i < Pixel::Component<P>::count; i++)
139 template <
class P,
class Scalar>
142 static inline void convert(
const P& from, Scalar& to)
144 typedef typename Pixel::Component<P>::type T;
147 for(
unsigned int i = 1; i < Pixel::Component<P>::count; i++)
152 to = scalar_convert<Scalar, T, double>(sqrt(sum));
156 template <
class P,
class Scalar>
159 static inline void convert(
const P& from, Scalar& to)
161 typedef typename Pixel::Component<P>::type T;
164 for(
unsigned int i = 1; i < Pixel::Component<P>::count; i++)
169 to = scalar_convert<Scalar, T, double>(sum);
173 template <
class Scalar,
class Vec>
176 static inline void convert(
const Scalar& from, Vec& to)
178 typedef typename Pixel::Component<Vec>::type T;
180 for(
size_t i = 1; i < Pixel::Component<Vec>::count; i++)
185 template <
class Scalar,
class T>
188 static inline void convert(
const Scalar& from,
Rgba<T>& to)
190 to.
red = to.
green = to.
blue = scalar_convert<T, Scalar>(from);
195 template <
class A,
class B>
196 inline void RgbToRgb(
const A& from, B& to)
198 typedef typename Pixel::Component<A>::type T;
199 typedef typename Pixel::Component<B>::type S;
200 to.red = scalar_convert<S, T>(from.red);
201 to.green = scalar_convert<S, T>(from.green);
202 to.blue = scalar_convert<S, T>(from.blue);
205 template <
class A,
class B>
208 static inline void convert(
const A& from, B& to)
214 template <
class A,
class T>
217 static inline void convert(
const A& from,
Rgba<T>& to)
224 template <
class A,
class T>
227 static inline void convert(
const A& from,
Argb<T>& to)
234 template <
class S,
class T>
244 template <
class S,
class T>
263 template <
class S,
class T>
273 template <
class S,
class T>
278 template <
class S,
class T>
285 template <
class T,
class S>
295 template <
class T,
class S>
300 template <
class T,
class S>
317 template <
class T,
class S>
327 template <
class T,
class S>
332 template <
class T,
class S>
376 template <
class T,
class S>
381 template <
class T,
class S>
386 template <
class T,
class S>
396 template <
class T,
class S>
401 template <
class T,
class S>
413 template <
class T,
class S>
418 template <
class T,
class S>
428 template <
class T,
class S>
439 template <class From, class To, class Conv = typename DefaultConversion<From, To>::type,
440 bool both_pod = std::is_trivially_copyable<From>::value&& std::is_trivially_copyable<To>::value>
443 static inline void convert(
const From* from, To* to,
size_t count)
445 for(
size_t i = 0; i < count; i++)
446 Conv::convert(from[i], to[i]);
453 static inline void convert(
const T* from, T* to,
size_t count)
455 std::memcpy(to, from, count *
sizeof(T));
466 static const int is = std::numeric_limits<C>::is_specialized;
472 static const int is = std::numeric_limits<C>::is_specialized;
478 static const int is = std::numeric_limits<C>::is_specialized;
484 static const int is = std::numeric_limits<C>::is_specialized;
490 static const int is = std::numeric_limits<C>::is_specialized;
496 static const int is = 1;
T blue
The blue component.
Definition: rgba.h:47
A colour consisting of red, green and blue components.
Definition: rgb.h:25
All classes and functions are within the CVD namespace.
Definition: argb.h:6
Definition: convert_pixel_types.h:174
A colour consisting of red, green, blue and dummy components, in the order bgr dummy in memory...
Definition: bgrx.h:16
Definition: convert_pixel_types.h:22
A colour consisting of red, green, blue and alpha components.
Definition: argb.h:17
T alpha
The alpha component.
Definition: rgba.h:48
Definition: convert_pixel_types.h:257
A 32-bit colour.
Definition: rgb8.h:11
All pixel types which are DefaultConvertible can be converted freely from one to another.
Definition: convert_pixel_types.h:464
A colour consisting of red, green, blue and alpha components.
Definition: rgba.h:17
Definition: convert_pixel_types.h:186
Definition: convert_pixel_types.h:123
Definition: convert_pixel_types.h:206
T green
The green component.
Definition: rgba.h:46
Definition: convert_pixel_types.h:441
Definition: convert_pixel_types.h:66
Definition: builtin_components.h:38
Definition: convert_pixel_types.h:157
T red
The red component.
Definition: rgba.h:45
Definition: pixel_traits.h:16
T alpha
The alpha component.
Definition: argb.h:45
Definition: convert_pixel_types.h:140