Debian Codegraph @

cvd/la.h

raw symbols SCIP
1 #ifndef CVD_LA_H
2 #define CVD_LA_H
3
4 #include <iostream>
5
6 namespace CVD
7 {
8
9 //////////////////////////////
10 // CVD::La
11 // Template class to represent luminance and alpha components
12 //
13 /// A colour consisting of luminance and alpha components
14 /// @param T The datatype of each component
15 /// @ingroup gImage
16 template <typename T>
17 class La
18 {
19 public:
20 /// Default constructor. Does nothing.
21 La() { }
22 /// Constructs a colour as specified
23 /// @param l The luminance component
24 /// @param a The alpha component
25 La(T l, T a)
26 : luminance(l)
27 , alpha(a)
28 {
29 }
30
31 T luminance; ///< The luminance component
32 T alpha; ///< The alpha component
33
34 /// Assignment operator
35 /// @param c The colour to copy from
36 La<T>& operator=(const La<T>& c)
37 {
38 luminance = c.luminance;
39 alpha = c.alpha;
40 return *this;
41 }
42
43 /// Assignment operator between two different storage types, using the standard casts as necessary
44 /// @param c The colour to copy from
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
53 /// Logical equals operator. Returns true if each component is the same.
54 /// @param c La to compare with
55 bool operator==(const La<T>& c) const
56 {
57 return luminance == c.luminance && alpha == c.alpha;
58 }
59
60 /// Logical not-equals operator. Returns true unless each component is the same.
61 /// @param c La to compare with
62 bool operator!=(const La<T>& c) const
63 {
64 return luminance != c.luminance || alpha != c.alpha;
65 }
66 };
67
68 /// Write the colour to a stream in the format "(luminance,alpha)"
69 /// @param os The stream
70 /// @param x The colour object
71 /// @relates La
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
78 /// Write the colour to a stream in the format "(luminance,alpha)"
79 /// @param os The stream
80 /// @param x The colour object
81 /// @relates La
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