DGtal  1.2.0
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 inline
135 double
136 DGtal::Color::r() const
137 {
138  return ((double) myRed)/255.0;
139 }
140 
141 inline
142 double
143 DGtal::Color::g() const
144 {
145  return ((double) myGreen)/255.0;
146 }
147 
148 inline
149 double
150 DGtal::Color::b() const
151 {
152  return ((double) myBlue)/255.0;
153 }
154 
155 inline
156 double
157 DGtal::Color::a() const
158 {
159  return ((double) myAlpha)/255.0;
160 }
161 
162 inline
163 DGtal::uint32_t
164 DGtal::Color::getRGB() const
165 {
166  return (((DGtal::uint32_t) myRed) << 16)
167  | (((DGtal::uint32_t) myGreen) << 8)
168  | ((DGtal::uint32_t) myBlue);
169 }
170 
171 inline
172 DGtal::uint32_t
173 DGtal::Color::getRGBA() const
174 {
175  return (((DGtal::uint32_t) myRed) << 24)
176  | (((DGtal::uint32_t) myGreen) << 16)
177  | (((DGtal::uint32_t) myBlue)<< 8)
178  | ((DGtal::uint32_t) myAlpha);
179 }
180 
181 inline
182 bool
183 DGtal::Color::valid() const
184 {
185  return (*this) != Color::None;
186 }
187 
188 // //
189 ///////////////////////////////////////////////////////////////////////////////
190 
191