DGtal  0.9.2
Color.ih
1 /**
2  * This program is free software: you can redistribute it and/or modify
3  * it under the terms of the GNU Lesser General Public License as
4  * published by the Free Software Foundation, either version 3 of the
5  * License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program. If not, see <http://www.gnu.org/licenses/>.
14  *
15  **/
16 
17 /**
18  * @file Color.ih
19  * @author Bertrand Kerautret (\c kerautre@loria.fr )
20  * LORIA (CNRS, UMR 7503), University of Nancy, France
21  *
22  * @date 2011/07/17
23  *
24  * Implementation of inline methods defined in Color.h
25  *
26  * This file is part of the DGtal library.
27  */
28 
29 ///////////////////////////////////////////////////////////////////////////////
30 // IMPLEMENTATION of inline methods.
31 ///////////////////////////////////////////////////////////////////////////////
32 
33 //////////////////////////////////////////////////////////////////////////////
34 #include <cstdlib>
35 //////////////////////////////////////////////////////////////////////////////
36 
37 
38 
39 ///////////////////////////////////////////////////////////////////////////////
40 // Implementation of inline methods //
41 
42 
43 ///////////////////////////////////////////////////////////////////////////////
44 // Implementation of inline functions and external operators //
45 
46 /**
47  * Overloads 'operator<<' for displaying objects of class 'Color'.
48  * @param out the output stream where the object is written.
49  * @param object the object of class 'Color' to write.
50  * @return the output stream after the writing.
51  */
52 inline
53 std::ostream&
54 DGtal::operator<< ( std::ostream & out,
55  const Color & object )
56 {
57  object.selfDisplay ( out );
58  return out;
59 }
60 
61 inline
62 DGtal::Color
63 DGtal::operator*( const double coeff,
64  const Color & aColor )
65  {
66  Color c=aColor*coeff;
67  return c;
68  }
69 
70 inline DGtal::Color &
71 DGtal::Color::setRGBi( const unsigned char aRedValue,
72  const unsigned char aGreenValue,
73  const unsigned char aBlueValue,
74  const unsigned char aAlphaValue ) {
75  myRed = aRedValue;
76  myGreen = aGreenValue;
77  myBlue = aBlueValue;
78  myAlpha = aAlphaValue;
79  return *this;
80 }
81 
82 
83 inline void
84 DGtal::Color::red( const unsigned char aRedValue )
85 {
86  myRed = aRedValue;
87 }
88 
89 inline void
90 DGtal::Color::green( unsigned char aGreenValue )
91 {
92  myGreen = aGreenValue;
93 }
94 
95 inline void
96 DGtal::Color::blue( unsigned char aBlueValue )
97 {
98  myBlue = aBlueValue;
99 }
100 
101 inline void
102 DGtal::Color::alpha( unsigned char aAlphaValue )
103 {
104  myAlpha = aAlphaValue;
105 }
106 
107 inline
108 unsigned char
109 DGtal::Color::red() const
110 {
111  return myRed;
112 }
113 
114 inline
115 unsigned char
116 DGtal::Color::green() const
117 {
118  return myGreen;
119 }
120 
121 inline
122 unsigned char
123 DGtal::Color::blue() const
124 {
125  return myBlue;
126 }
127 
128 inline
129 unsigned char
130 DGtal::Color::alpha() const
131 {
132  return myAlpha;
133 }
134 
135 inline
136 DGtal::uint32_t
137 DGtal::Color::getRGB() const
138 {
139  return (((DGtal::uint32_t) myRed) << 16)
140  | (((DGtal::uint32_t) myGreen) << 8)
141  | ((DGtal::uint32_t) myBlue);
142 }
143 
144 inline
145 DGtal::uint32_t
146 DGtal::Color::getRGBA() const
147 {
148  return (((DGtal::uint32_t) myRed) << 24)
149  | (((DGtal::uint32_t) myGreen) << 16)
150  | (((DGtal::uint32_t) myBlue)<< 16)
151  | ((DGtal::uint32_t) myAlpha);
152 }
153 
154 inline
155 bool
156 DGtal::Color::valid() const
157 {
158  return (*this) != Color::None;
159 }
160 
161 // //
162 ///////////////////////////////////////////////////////////////////////////////
163 
164