| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
#ifndef CVD_RGB_H |
| 11 |
#define CVD_RGB_H |
| 12 |
|
| 13 |
#include <iostream> |
| 14 |
|
| 15 |
#include <cvd/byte.h> |
| 16 |
|
| 17 |
namespace CVD |
| 18 |
{ |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
template <class T> |
| 25 |
class Rgb |
| 26 |
{ |
| 27 |
public: |
| 28 |
Rgb() = default; |
| 29 |
Rgb(const Rgb&) = default; |
| 30 |
Rgb& operator=(const Rgb&) = default; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
inline Rgb(T r, T g, T b) |
| 37 |
: red(r) |
| 38 |
, green(g) |
| 39 |
, blue(b) |
| 40 |
{ |
| 41 |
} |
| 42 |
|
| 43 |
template <class S> |
| 44 |
inline explicit Rgb(const Rgb<S>& rgb) |
| 45 |
: red(static_cast<T>(rgb.red)) |
| 46 |
, green(static_cast<T>(rgb.green)) |
| 47 |
, blue(static_cast<T>(rgb.blue)) |
| 48 |
{ |
| 49 |
} |
| 50 |
|
| 51 |
T red; |
| 52 |
T green; |
| 53 |
T blue; |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
inline bool operator==(const Rgb<T>& c) const |
| 58 |
{ |
| 59 |
return red == c.red && green == c.green && blue == c.blue; |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
inline bool operator!=(const Rgb<T>& c) const |
| 65 |
{ |
| 66 |
return red != c.red || green != c.green || blue != c.blue; |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
template <class T2> |
| 72 |
inline Rgb<T>& operator=(const Rgb<T2>& c) |
| 73 |
{ |
| 74 |
red = static_cast<T>(c.red); |
| 75 |
green = static_cast<T>(c.green); |
| 76 |
blue = static_cast<T>(c.blue); |
| 77 |
return *this; |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
}; |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
template <class T> |
| 88 |
std::ostream& operator<<(std::ostream& os, const Rgb<T>& x) |
| 89 |
{ |
| 90 |
return os << "(" << x.red << "," << x.green << "," |
| 91 |
<< x.blue << ")"; |
| 92 |
} |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
inline std::ostream& operator<<(std::ostream& os, const Rgb<char>& x) |
| 99 |
{ |
| 100 |
return os << "(" << (int)(unsigned char)x.red << "," |
| 101 |
<< (int)(unsigned char)x.green << "," |
| 102 |
<< (int)(unsigned char)x.blue << ")"; |
| 103 |
} |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
inline std::ostream& operator<<(std::ostream& os, const Rgb<byte>& x) |
| 110 |
{ |
| 111 |
return os << "(" << static_cast<int>(x.red) << "," |
| 112 |
<< static_cast<int>(x.green) << "," |
| 113 |
<< static_cast<int>(x.blue) << ")"; |
| 114 |
} |
| 115 |
|
| 116 |
} |
| 117 |
#endif |