Debian Codegraph @

cvd/bgrx.h

raw symbols SCIP
1 #ifndef CVD_INCLUDE_BGRX_H
2 #define CVD_INCLUDE_BGRX_H
3
4 #include <iostream>
5
6 namespace CVD
7 {
8
9 //////////////////////////////
10 // CVD::Bgrx
11 /// A colour consisting of red, green, blue and dummy components,
12 /// in the order bgr dummy in memory.
13 /// @param T The datatype of each component
14 /// @ingroup gImage
15 template <typename T>
16 class Bgrx
17 {
18 public:
19 /// Default constructor. Sets everything to 0.
20 explicit Bgrx()
21 : blue(0)
22 , green(0)
23 , red(0)
24 , dummy(0)
25 {
26 }
27
28 /// Constructs a colour as specified
29 /// @param r The red component
30 /// @param g The green component
31 /// @param b The blue component
32 explicit Bgrx(T b, T g, T r)
33 : blue(b)
34 , green(g)
35 , red(r)
36 , dummy(0)
37 {
38 }
39
40 T blue; ///< The blue component
41 T green; ///< The green component
42 T red; ///< The red component
43 T dummy; ///< The dummy
44
45 /// Assignment operator between two different storage types, using the standard casts as necessary
46 /// @param c The colour to copy from
47 template <typename T2>
48 Bgrx<T>& operator=(const Bgrx<T2>& c)
49 {
50 blue = static_cast<T>(c.blue);
51 green = static_cast<T>(c.green);
52 red = static_cast<T>(c.red);
53 return *this;
54 }
55
56 /// Logical equals operator. Returns true if each component is the same.
57 /// @param c Bgrx to compare with
58 bool operator==(const Bgrx<T>& c) const
59 {
60 return red == c.red && green == c.green && blue == c.blue;
61 }
62
63 /// Logical not-equals operator. Returns true unless each component is the same.
64 /// @param c Bgrx to compare with
65 bool operator!=(const Bgrx<T>& c) const
66 {
67 return red != c.red || green != c.green || blue != c.blue;
68 }
69
70 // T to_grey() const {return 0.3*red + 0.6*green + 0.1*blue;}
71 };
72
73 /// Write the colour to a stream in the format "(blue,green,red)"
74 /// @param os The stream
75 /// @param x The colour object
76 /// @relates Bgrx
77 template <typename T>
78 std::ostream& operator<<(std::ostream& os, const Bgrx<T>& x)
79 {
80 return os << "(" << x.blue << ","
81 << x.green << "," << x.red << ")";
82 }
83
84 /// Write the colour to a stream in the format "(blue,green,red)"
85 /// @param os The stream
86 /// @param x The colour object
87 /// @relates Bgrx
88 inline std::ostream& operator<<(std::ostream& os, const Bgrx<unsigned char>& x)
89 {
90 return os << "("
91 << static_cast<unsigned int>(x.blue) << ")"
92 << static_cast<unsigned int>(x.green) << ","
93 << static_cast<unsigned int>(x.red) << ",";
94 }
95
96 } // end namespace
97 #endif