00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef CVD_RGBA_H
00022 #define CVD_RGBA_H
00023
00024 #include <iostream>
00025 #include <cvd/internal/is_pod.h>
00026
00027 namespace CVD {
00028
00029
00031
00032
00033
00037 template <typename T>
00038 class Rgba
00039 {
00040 public:
00042 Rgba() {}
00048 Rgba(T r, T g, T b, T a) : red(r), green(g), blue(b), alpha(a) {}
00049
00050 T red;
00051 T green;
00052 T blue;
00053 T alpha;
00054
00057 Rgba<T>& operator=(const Rgba<T>& c)
00058 {red = c.red; green = c.green; blue = c.blue; alpha = c.alpha; return *this;}
00059
00062 template <typename T2>
00063 Rgba<T>& operator=(const Rgba<T2>& c){
00064 red = static_cast<T>(c.red);
00065 green = static_cast<T>(c.green);
00066 blue = static_cast<T>(c.blue);
00067 alpha = static_cast<T>(c.alpha);
00068 return *this;
00069 }
00070
00073 bool operator==(const Rgba<T>& c) const
00074 {return red == c.red && green == c.green && blue == c.blue && alpha == c.alpha;}
00075
00078 bool operator!=(const Rgba<T>& c) const
00079 {return red != c.red || green != c.green || blue != c.blue || alpha != c.alpha;}
00080
00081
00082 };
00083
00088 template <typename T>
00089 std::ostream& operator <<(std::ostream& os, const Rgba<T>& x)
00090 {
00091 return os << "(" << x.red << "," << x.green << ","
00092 << x.blue << "," << x.alpha << ")";
00093 }
00094
00099 inline std::ostream& operator <<(std::ostream& os, const Rgba<unsigned char>& x)
00100 {
00101 return os << "(" << static_cast<unsigned int>(x.red) << ","
00102 << static_cast<unsigned int>(x.green) << ","
00103 << static_cast<unsigned int>(x.blue) << ","
00104 << static_cast<unsigned int>(x.alpha) << ")";
00105 }
00106
00107 #ifndef DOXYGEN_IGNORE_INTERNAL
00108 namespace Internal
00109 {
00110 template<class C> struct is_POD<Rgba<C> >
00111 {
00112 enum { is_pod = is_POD<C>::is_pod };
00113 };
00114 }
00115 #endif
00116
00117
00118
00119 }
00120 #endif
00121