MEPP2 Project
Color.inl
Go to the documentation of this file.
1 // Copyright (c) 2012-2019 University of Lyon and CNRS (France).
2 // All rights reserved.
3 //
4 // This file is part of MEPP2; you can redistribute it and/or modify
5 // it under the terms of the GNU Lesser General Public License as
6 // published by the Free Software Foundation; either version 3 of
7 // the License, or (at your option) any later version.
8 //
9 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
10 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
11 #include <boost/algorithm/clamp.hpp>
12 #include <algorithm>
13 
14 
15 inline
17  : redComponent((unsigned char)0), greenComponent((unsigned char)0),
18  blueComponent((unsigned char)0), alphaComponent((unsigned char)255)
19 {
20 }
21 
22 inline
23 FEVV::Color::Color(const unsigned char _redValue,
24  const unsigned char _greenValue,
25  const unsigned char _blueValue,
26  const unsigned char _alphaValue)
27  : redComponent(_redValue), greenComponent(_greenValue),
28  blueComponent(_blueValue), alphaComponent(_alphaValue)
29 {
30 }
31 
32 inline
33 FEVV::Color::Color(const unsigned char _grayValue,
34  const unsigned char _alphaValue)
35  : redComponent(_grayValue), greenComponent(_grayValue),
36  blueComponent(_grayValue), alphaComponent(_alphaValue)
37 {
38 }
39 
40 inline
41 FEVV::Color::Color(const Color &_color)
42  : redComponent(_color.redComponent), greenComponent(_color.greenComponent),
43  blueComponent(_color.blueComponent), alphaComponent(_color.alphaComponent)
44 {
45 }
46 
48 
49 inline
51 FEVV::Color::setRGB(const unsigned char _redValue,
52  const unsigned char _greenValue,
53  const unsigned char _blueValue)
54 {
55  redComponent = _redValue;
56  greenComponent = _greenValue;
57  blueComponent = _blueValue;
58  alphaComponent = 255;
59 
60  return *this;
61 }
62 
63 inline
65 FEVV::Color::setRGBA(const unsigned char _redValue,
66  const unsigned char _greenValue,
67  const unsigned char _blueValue,
68  const unsigned char _alphaValue)
69 {
70  redComponent = _redValue;
71  greenComponent = _greenValue;
72  blueComponent = _blueValue;
73  alphaComponent = _alphaValue;
74 
75  return *this;
76 }
77 
78 inline
79 void
80 FEVV::Color::red(const unsigned char _redValue)
81 {
82  redComponent = _redValue;
83 }
84 
85 inline
86 void
87 FEVV::Color::green(const unsigned char _greenValue)
88 {
89  greenComponent = _greenValue;
90 }
91 
92 inline
93 void
94 FEVV::Color::blue(const unsigned char _blueValue)
95 {
96  blueComponent = _blueValue;
97 }
98 
99 inline
100 void
101 FEVV::Color::alpha(const unsigned char _alphaValue)
102 {
103  alphaComponent = _alphaValue;
104 }
105 
106 inline
107 unsigned char
109 {
110  return redComponent;
111 }
112 
113 inline
114 unsigned char
116 {
117  return greenComponent;
118 }
119 
120 inline
121 unsigned char
123 {
124  return blueComponent;
125 }
126 
127 inline
128 unsigned char
130 {
131  return alphaComponent;
132 }
133 
135 
136 inline
137 bool
138 FEVV::Color::operator==(const Color &_color) const
139 {
140  return redComponent == _color.redComponent &&
141  greenComponent == _color.greenComponent &&
142  blueComponent == _color.blueComponent &&
143  alphaComponent == _color.alphaComponent;
144 }
145 
146 inline
147 bool
148 FEVV::Color::operator!=(const Color &_color) const
149 {
150  return redComponent != _color.redComponent ||
151  greenComponent != _color.greenComponent ||
152  blueComponent != _color.blueComponent ||
153  alphaComponent != _color.alphaComponent;
154 }
155 
156 inline
157 bool
158 FEVV::Color::operator<(const Color &_color) const
159 {
160  if(redComponent < _color.redComponent)
161  {
162  return true;
163  }
164  else if(redComponent == _color.redComponent)
165  {
166  if(greenComponent < _color.greenComponent)
167  {
168  return true;
169  }
170  else if(greenComponent == _color.greenComponent)
171  {
172  if(blueComponent < _color.blueComponent)
173  {
174  return true;
175  }
176  else if(blueComponent == _color.blueComponent)
177  {
178  return alphaComponent < _color.alphaComponent;
179  }
180  }
181  }
182  return false;
183 }
184 
185 inline
186 FEVV::Color &
188 {
189  redComponent = _color.redComponent;
190  greenComponent = _color.greenComponent;
191  blueComponent = _color.blueComponent;
192  alphaComponent = _color.alphaComponent;
193 
194  return *this;
195 }
196 
197 inline
200 {
201  Color c;
202 
203  c.redComponent = (unsigned char)boost::algorithm::clamp(
204  (unsigned int)redComponent + (unsigned int)_color.redComponent, 0, 255);
205  c.greenComponent = (unsigned char)boost::algorithm::clamp(
206  (unsigned int)greenComponent + (unsigned int)_color.greenComponent,
207  0,
208  255);
209  c.blueComponent = (unsigned char)boost::algorithm::clamp(
210  (unsigned int)blueComponent + (unsigned int)_color.blueComponent, 0, 255);
211  c.alphaComponent = (unsigned char)std::max(
212  (unsigned int)alphaComponent, (unsigned int)_color.alphaComponent);
213 
214  return c;
215 }
216 
217 inline
218 FEVV::Color &
220 {
221  redComponent = (unsigned char)boost::algorithm::clamp(
222  (unsigned int)redComponent + (unsigned int)_color.redComponent, 0, 255);
223  greenComponent = (unsigned char)boost::algorithm::clamp(
224  (unsigned int)greenComponent + (unsigned int)_color.greenComponent,
225  0,
226  255);
227  blueComponent = (unsigned char)boost::algorithm::clamp(
228  (unsigned int)blueComponent + (unsigned int)_color.blueComponent, 0, 255);
229  alphaComponent = (unsigned char)std::max((unsigned int)alphaComponent,
230  (unsigned int)_color.alphaComponent);
231 
232  return *this;
233 }
234 
235 inline
238 {
239  Color c;
240 
241  c.redComponent = (unsigned char)boost::algorithm::clamp(
242  (unsigned int)redComponent - (unsigned int)_color.redComponent, 0, 255);
243  c.greenComponent = (unsigned char)boost::algorithm::clamp(
244  (unsigned int)greenComponent - (unsigned int)_color.greenComponent,
245  0,
246  255);
247  c.blueComponent = (unsigned char)boost::algorithm::clamp(
248  (unsigned int)blueComponent - (unsigned int)_color.blueComponent, 0, 255);
249  c.alphaComponent = (unsigned char)std::min(
250  (unsigned int)alphaComponent, (unsigned int)_color.alphaComponent);
251 
252  return c;
253 }
254 
255 inline
256 FEVV::Color &
258 {
259  redComponent = (unsigned char)boost::algorithm::clamp(
260  (unsigned int)redComponent - (unsigned int)_color.redComponent, 0, 255);
261  greenComponent = (unsigned char)boost::algorithm::clamp(
262  (unsigned int)greenComponent - (unsigned int)_color.greenComponent,
263  0,
264  255);
265  blueComponent = (unsigned char)boost::algorithm::clamp(
266  (unsigned int)blueComponent - (unsigned int)_color.blueComponent, 0, 255);
267  alphaComponent = (unsigned char)std::min((unsigned int)alphaComponent,
268  (unsigned int)_color.alphaComponent);
269 
270  return *this;
271 }
272 
273 inline
275 {
276  Color c;
277 
278  c.redComponent = (unsigned char)boost::algorithm::clamp(
279  (unsigned int)redComponent * _scale, 0, 255);
280  c.greenComponent = (unsigned char)boost::algorithm::clamp(
281  (unsigned int)greenComponent * _scale, 0, 255);
282  c.blueComponent = (unsigned char)boost::algorithm::clamp(
283  (unsigned int)blueComponent * _scale, 0, 255);
284  c.alphaComponent = alphaComponent;
285 
286  return c;
287 }
288 
289 inline
290 FEVV::Color &
291 FEVV::Color::operator*=(const double _scale)
292 {
293  redComponent = (unsigned char)boost::algorithm::clamp(
294  (unsigned int)redComponent * _scale, 0, 255);
295  greenComponent = (unsigned char)boost::algorithm::clamp(
296  (unsigned int)greenComponent * _scale, 0, 255);
297  blueComponent = (unsigned char)boost::algorithm::clamp(
298  (unsigned int)blueComponent * _scale, 0, 255);
299 
300  return *this;
301 }
302 
304 
305 inline
306 void
307 FEVV::Color::selfDisplay(std::ostream &_out) const
308 {
309  _out << "[Color] RGBA(" << (unsigned int)redComponent << ","
310  << (unsigned int)greenComponent << "," << (unsigned int)blueComponent
311  << "," << (unsigned int)alphaComponent << ")";
312 }
313 
315 
316 inline
318 {
319  return Color(0, 0, 0, 0);
320 }
321 
322 inline
324 {
325  return Color(0, 0, 0);
326 }
327 
328 inline
330 {
331  return Color(255, 255, 255);
332 }
333 
334 inline
336 {
337  return Color(244, 67, 54);
338 }
339 
340 inline
342 {
343  return Color(233, 30, 99);
344 }
345 
346 inline
348 {
349  return Color(156, 39, 176);
350 }
351 
352 inline
354 {
355  return Color(103, 58, 183);
356 }
357 
358 inline
360 {
361  return Color(63, 81, 181);
362 }
363 
364 inline
366 {
367  return Color(33, 150, 243);
368 }
369 
370 inline
372 {
373  return Color(3, 169, 244);
374 }
375 
376 inline
378 {
379  return Color(0, 188, 212);
380 }
381 
382 inline
384 {
385  return Color(0, 150, 136);
386 }
387 
388 inline
390 {
391  return Color(76, 175, 80);
392 }
393 
394 inline
396 {
397  return Color(139, 195, 74);
398 }
399 
400 inline
402 {
403  return Color(205, 220, 57);
404 }
405 
406 inline
408 {
409  return Color(255, 235, 59);
410 }
411 
412 inline
414 {
415  return Color(255, 193, 7);
416 }
417 
418 inline
420 {
421  return Color(243, 156, 18);
422 }
423 
424 inline
426 {
427  return Color(255, 87, 34);
428 }
429 
430 inline
432 {
433  return Color(121, 85, 72);
434 }
435 
436 inline
438 {
439  return Color(158, 158, 158);
440 }
441 
442 inline
444 {
445  return Color(96, 125, 139);
446 }
447 
449 
450 
451 inline
453 {
454  return Color(26, 188, 156);
455 }
456 
457 inline
459 {
460  return Color(22, 160, 133);
461 }
462 
463 inline
465 {
466  return Color(46, 204, 113);
467 }
468 
469 inline
471 {
472  return Color(39, 174, 96);
473 }
474 
475 inline
477 {
478  return Color(41, 128, 185);
479 }
480 
481 inline
483 {
484  return Color(41, 128, 185);
485 }
486 
487 inline
489 {
490  return Color(155, 89, 182);
491 }
492 
493 inline
495 {
496  return Color(142, 68, 173);
497 }
498 
499 inline
501 {
502  return Color(52, 73, 94);
503 }
504 
505 inline
507 {
508  return Color(44, 62, 80);
509 }
510 
511 inline
513 {
514  return Color(241, 196, 15);
515 }
516 
517 inline
519 {
520  return Color(230, 126, 34);
521 }
522 
523 inline
525 {
526  return Color(211, 84, 0);
527 }
528 
529 inline
531 {
532  return Color(231, 76, 60);
533 }
534 
535 inline
537 {
538  return Color(192, 57, 43);
539 }
540 
541 inline
543 {
544  return Color(236, 240, 241);
545 }
546 
547 inline
549 {
550  return Color(189, 195, 199);
551 }
552 
553 inline
555 {
556  return Color(149, 165, 166);
557 }
558 
559 inline
561 {
562  return Color(127, 140, 141);
563 }
564 
FEVV::Color::red
unsigned char red() const
Definition: Color.inl:108
FEVV::Color::Indigo
static Color Indigo(void)
Definition: Color.inl:359
FEVV::Color::Brown
static Color Brown(void)
Definition: Color.inl:431
FEVV::Color::setRGB
Color & setRGB(const unsigned char _redValue, const unsigned char _greenValue, const unsigned char _blueValue)
Definition: Color.inl:51
FEVV::Color::Pomegranate
static Color Pomegranate(void)
Definition: Color.inl:536
FEVV::Color::Alizarin
static Color Alizarin(void)
Definition: Color.inl:530
FEVV::Color::Teal
static Color Teal(void)
Definition: Color.inl:383
FEVV::Color::MidnightBlue
static Color MidnightBlue(void)
Definition: Color.inl:506
FEVV::Color::blue
unsigned char blue() const
Definition: Color.inl:122
FEVV::Color::Silver
static Color Silver(void)
Definition: Color.inl:548
FEVV::Color::Yellow
static Color Yellow(void)
Definition: Color.inl:407
FEVV::Color::operator-=
Color & operator-=(const Color &_color)
Definition: Color.inl:257
FEVV::Color::Lime
static Color Lime(void)
Definition: Color.inl:401
FEVV::Color::Pink
static Color Pink(void)
Definition: Color.inl:341
FEVV::Color::green
unsigned char green() const
Definition: Color.inl:115
FEVV::Color::Wisteria
static Color Wisteria(void)
Definition: Color.inl:494
FEVV::Color::blueComponent
unsigned char blueComponent
Definition: Color.hpp:227
FEVV::Color::PeterRiver
static Color PeterRiver(void)
Definition: Color.inl:476
FEVV::Color::operator*
Color operator*(const double _scale)
Definition: Color.inl:274
FEVV::Color::Amber
static Color Amber(void)
Definition: Color.inl:413
FEVV::Color::operator=
Color & operator=(const Color &_color)
Definition: Color.inl:187
FEVV::Color::Cyan
static Color Cyan(void)
Definition: Color.inl:377
FEVV::Color::BlueGrey
static Color BlueGrey(void)
Definition: Color.inl:443
FEVV::Color::WetAsphalt
static Color WetAsphalt(void)
Definition: Color.inl:500
FEVV::Color::operator-
Color operator-(const Color &_color)
Definition: Color.inl:237
FEVV::Color::Grey
static Color Grey(void)
Definition: Color.inl:437
FEVV::Color::Turquoise
static Color Turquoise(void)
Definition: Color.inl:452
FEVV::Color::LightBlue
static Color LightBlue(void)
Definition: Color.inl:371
FEVV::Color::Emerald
static Color Emerald(void)
Definition: Color.inl:464
FEVV::Color::setRGBA
Color & setRGBA(const unsigned char _redValue, const unsigned char _greenValue, const unsigned char _blueValue, const unsigned char _alphaValue=255)
Definition: Color.inl:65
FEVV::Color::None
static Color None(void)
Definition: Color.inl:317
FEVV::Color
Definition: Color.hpp:18
FEVV::Color::Purple
static Color Purple(void)
Definition: Color.inl:347
FEVV::Color::selfDisplay
void selfDisplay(std::ostream &out) const
Definition: Color.inl:307
FEVV::Color::Pumpkin
static Color Pumpkin(void)
Definition: Color.inl:524
FEVV::Color::GreenSea
static Color GreenSea(void)
Definition: Color.inl:458
FEVV::Color::DeepOrange
static Color DeepOrange(void)
Definition: Color.inl:425
FEVV::Color::BelizeHole
static Color BelizeHole(void)
Definition: Color.inl:482
FEVV::Color::Black
static Color Black(void)
Definition: Color.inl:323
FEVV::Color::LightGreen
static Color LightGreen(void)
Definition: Color.inl:395
FEVV::Color::SunFlower
static Color SunFlower(void)
Definition: Color.inl:512
FEVV::Color::redComponent
unsigned char redComponent
Definition: Color.hpp:225
FEVV::Color::Red
static Color Red(void)
Definition: Color.inl:335
FEVV::Color::alphaComponent
unsigned char alphaComponent
Definition: Color.hpp:228
FEVV::Color::White
static Color White(void)
Definition: Color.inl:329
FEVV::Color::operator+=
Color & operator+=(const Color &_color)
Definition: Color.inl:219
FEVV::Color::operator*=
Color & operator*=(const double _scale)
Definition: Color.inl:291
FEVV::Color::Amethyst
static Color Amethyst(void)
Definition: Color.inl:488
FEVV::Color::Carrot
static Color Carrot(void)
Definition: Color.inl:518
FEVV::Color::greenComponent
unsigned char greenComponent
Definition: Color.hpp:226
FEVV::Color::alpha
unsigned char alpha() const
Definition: Color.inl:129
FEVV::Color::Orange
static Color Orange(void)
Definition: Color.inl:419
FEVV::Color::Asbestos
static Color Asbestos(void)
Definition: Color.inl:560
FEVV::Color::Color
Color()
Definition: Color.inl:16
FEVV::Color::DeepPurple
static Color DeepPurple(void)
Definition: Color.inl:353
FEVV::Color::operator+
Color operator+(const Color &_color)
Definition: Color.inl:199
FEVV::Color::Nephritis
static Color Nephritis(void)
Definition: Color.inl:470
FEVV::Color::operator<
bool operator<(const Color &_color) const
Definition: Color.inl:158
FEVV::Color::operator==
bool operator==(const Color &_color) const
Definition: Color.inl:138
FEVV::Color::Green
static Color Green(void)
Definition: Color.inl:389
FEVV::Color::Clouds
static Color Clouds(void)
Definition: Color.inl:542
FEVV::Color::Concrete
static Color Concrete(void)
Definition: Color.inl:554
FEVV::Color::operator!=
bool operator!=(const Color &_color) const
Definition: Color.inl:148
FEVV::Color::Blue
static Color Blue(void)
Definition: Color.inl:365