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