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