libcvd
argb.h
1 #ifndef CVD_QT_ARGB_H
2 #define CVD_QT_ARGB_H
3 
4 #include <iostream>
5 
6 namespace CVD
7 {
8 
10 // CVD::Argb
11 // Template class to represent red, green, blue and alpha components
12 //
16 template <typename T>
17 class Argb
18 {
19  public:
21  explicit Argb()
22  : red(0)
23  , green(0)
24  , blue(0)
25  , alpha(0)
26  {
27  }
28 
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 
49  template <typename T2>
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 
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 
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  // T to_grey() const {return 0.3*red + 0.6*green + 0.1*blue;}
74 };
75 
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 
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 } // end namespace
100 #endif
All classes and functions are within the CVD namespace.
Definition: argb.h:6
bool operator==(const Argb< T > &c) const
Logical equals operator.
Definition: argb.h:61
A colour consisting of red, green, blue and alpha components.
Definition: argb.h:17
bool operator!=(const Argb< T > &c) const
Logical not-equals operator.
Definition: argb.h:68
Argb(T a, T r, T g, T b)
Constructs a colour as specified.
Definition: argb.h:34
T blue
The blue component.
Definition: argb.h:42
Argb< T > & operator=(const Argb< T2 > &c)
Assignment operator between two different storage types, using the standard casts as necessary...
Definition: argb.h:50
Argb()
Default constructor. Sets everything to 0.
Definition: argb.h:21
T red
The red component.
Definition: argb.h:44
T green
The green component.
Definition: argb.h:43
T alpha
The alpha component.
Definition: argb.h:45