libcvd
bgrx.h
1 #ifndef CVD_INCLUDE_BGRX_H
2 #define CVD_INCLUDE_BGRX_H
3 
4 #include <iostream>
5 
6 namespace CVD
7 {
8 
10 // CVD::Bgrx
15 template <typename T>
16 class Bgrx
17 {
18  public:
20  explicit Bgrx()
21  : blue(0)
22  , green(0)
23  , red(0)
24  , dummy(0)
25  {
26  }
27 
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;
41  T green;
42  T red;
43  T dummy;
44 
47  template <typename T2>
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 
58  bool operator==(const Bgrx<T>& c) const
59  {
60  return red == c.red && green == c.green && blue == c.blue;
61  }
62 
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 
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 
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
Bgrx(T b, T g, T r)
Constructs a colour as specified.
Definition: bgrx.h:32
T dummy
The dummy.
Definition: bgrx.h:43
All classes and functions are within the CVD namespace.
Definition: argb.h:6
A colour consisting of red, green, blue and dummy components, in the order bgr dummy in memory...
Definition: bgrx.h:16
T blue
The blue component.
Definition: bgrx.h:40
bool operator!=(const Bgrx< T > &c) const
Logical not-equals operator.
Definition: bgrx.h:65
T red
The red component.
Definition: bgrx.h:42
Bgrx< T > & operator=(const Bgrx< T2 > &c)
Assignment operator between two different storage types, using the standard casts as necessary...
Definition: bgrx.h:48
Bgrx()
Default constructor. Sets everything to 0.
Definition: bgrx.h:20
T green
The green component.
Definition: bgrx.h:41
bool operator==(const Bgrx< T > &c) const
Logical equals operator.
Definition: bgrx.h:58