libcvd
la.h
1 #ifndef CVD_LA_H
2 #define CVD_LA_H
3 
4 #include <iostream>
5 
6 namespace CVD
7 {
8 
10 // CVD::La
11 // Template class to represent luminance and alpha components
12 //
16 template <typename T>
17 class La
18 {
19  public:
21  La() { }
25  La(T l, T a)
26  : luminance(l)
27  , alpha(a)
28  {
29  }
30 
32  T alpha;
33 
36  La<T>& operator=(const La<T>& c)
37  {
38  luminance = c.luminance;
39  alpha = c.alpha;
40  return *this;
41  }
42 
45  template <typename T2>
46  La<T>& operator=(const La<T2>& c)
47  {
48  luminance = static_cast<T>(c.luminance);
49  alpha = static_cast<T>(c.alpha);
50  return *this;
51  }
52 
55  bool operator==(const La<T>& c) const
56  {
57  return luminance == c.luminance && alpha == c.alpha;
58  }
59 
62  bool operator!=(const La<T>& c) const
63  {
64  return luminance != c.luminance || alpha != c.alpha;
65  }
66 };
67 
72 template <typename T>
73 std::ostream& operator<<(std::ostream& os, const La<T>& x)
74 {
75  return os << "(" << x.luminance << "," << x.alpha << ")";
76 }
77 
82 inline std::ostream& operator<<(std::ostream& os, const La<unsigned char>& x)
83 {
84  return os << "(" << static_cast<unsigned int>(x.luminance) << ","
85  << static_cast<unsigned int>(x.alpha) << ")";
86 }
87 
88 } // end namespace
89 #endif
La< T > & operator=(const La< T > &c)
Assignment operator.
Definition: la.h:36
La()
Default constructor. Does nothing.
Definition: la.h:21
All classes and functions are within the CVD namespace.
Definition: argb.h:6
A colour consisting of luminance and alpha components.
Definition: la.h:17
T luminance
The luminance component.
Definition: la.h:31
bool operator!=(const La< T > &c) const
Logical not-equals operator.
Definition: la.h:62
La(T l, T a)
Constructs a colour as specified.
Definition: la.h:25
bool operator==(const La< T > &c) const
Logical equals operator.
Definition: la.h:55
La< T > & operator=(const La< T2 > &c)
Assignment operator between two different storage types, using the standard casts as necessary...
Definition: la.h:46
T alpha
The alpha component.
Definition: la.h:32