00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00022
00023
00024
00025
00026
00027
00028
00030 #ifndef CVD_RGB_H
00031 #define CVD_RGB_H
00032
00033 #include <iostream>
00034
00035 #include <cvd/byte.h>
00036
00037 #include <cvd/internal/is_pod.h>
00038
00039 namespace CVD {
00040
00045 template <class T>
00046 class Rgb
00047 {
00048 public:
00050 Rgb() {}
00055 inline Rgb(T r, T g, T b) : red(r),green(g),blue(b) {}
00056 template <class S> inline explicit Rgb(const Rgb<S>& rgb) : red(static_cast<T>(rgb.red)), green(static_cast<T>(rgb.green)), blue(static_cast<T>(rgb.blue)) {}
00057
00058 T red;
00059 T green;
00060 T blue;
00061
00064 inline Rgb<T>& operator=(const Rgb<T>& c)
00065 {red = c.red; green = c.green; blue = c.blue; return *this;}
00066
00069 inline bool operator==(const Rgb<T>& c) const
00070 {return red == c.red && green == c.green && blue == c.blue;}
00071
00074 inline bool operator!=(const Rgb<T>& c) const
00075 {return red != c.red || green != c.green || blue != c.blue;}
00076
00079 template <class T2>
00080 inline Rgb<T>& operator=(const Rgb<T2>& c){ red = c.red; green=c.green; blue=c.blue; return *this;}
00081
00082
00083 };
00084
00089 template <class T>
00090 std::ostream& operator <<(std::ostream& os, const Rgb<T>& x)
00091 {
00092 return os << "(" << x.red << "," << x.green << ","
00093 << x.blue << ")";
00094 }
00095
00100 inline std::ostream& operator <<(std::ostream& os, const Rgb<char>& x)
00101 {
00102 return os << "(" << (int)(unsigned char)x.red << ","
00103 << (int)(unsigned char)x.green << ","
00104 << (int)(unsigned char)x.blue << ")";
00105 }
00106
00111 inline std::ostream& operator <<(std::ostream& os, const Rgb<byte>& x)
00112 {
00113 return os << "(" << static_cast<int>(x.red) << ","
00114 << static_cast<int>(x.green) << ","
00115 << static_cast<int>(x.blue) << ")";
00116 }
00117
00118 #ifndef DOXYGEN_IGNORE_INTERNAL
00119 namespace Internal
00120 {
00121 template<class C> struct is_POD<Rgb<C> >
00122 {
00123 enum { is_pod = is_POD<C>::is_pod };
00124 };
00125 }
00126 #endif
00127
00128
00129 }
00130 #endif