Debian Codegraph @

cvd/argb.h

raw symbols SCIP
1 #ifndef CVD_QT_ARGB_H
2 #define CVD_QT_ARGB_H
3
4 #include <iostream>
5
6 namespace CVD
7 {
8
9 //////////////////////////////
10 // CVD::Argb
11 // Template class to represent red, green, blue and alpha components
12 //
13 /// A colour consisting of red, green, blue and alpha components
14 /// @param T The datatype of each component
15 /// @ingroup gImage
16 template <typename T>
17 class Argb
18 {
19 public:
20 /// Default constructor. Sets everything to 0.
21 explicit Argb()
22 : red(0)
23 , green(0)
24 , blue(0)
25 , alpha(0)
26 {
27 }
28
29 /// Constructs a colour as specified
30 /// @param r The red component
31 /// @param g The green component
32 /// @param b The blue component
33 /// @param a The alpha component
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; ///< The blue component
43 T green; ///< The green component
44 T red; ///< The red component
45 T alpha; ///< The alpha component
46
47 /// Assignment operator between two different storage types, using the standard casts as necessary
48 /// @param c The colour to copy from
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 /// Logical equals operator. Returns true if each component is the same.
60 /// @param c Argb to compare with
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 /// Logical not-equals operator. Returns true unless each component is the same.
67 /// @param c Argb to compare with
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
76 /// Write the colour to a stream in the format "(red,green,blue,alpha)"
77 /// @param os The stream
78 /// @param x The colour object
79 /// @relates Argb
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 /// Write the colour to a stream in the format "(red,green,blue,alpha)"
88 /// @param os The stream
89 /// @param x The colour object
90 /// @relates Argb
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