ColorTransform.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/color/ColorTransform.cpp
22 
23  \brief Implementation of the color transform concept.
24 */
25 
26 // TerraLib
27 #include "ColorTransform.h"
28 
30 {
31  invalidate();
32 }
33 
35 {
36  m_spec = colt.m_spec;
37  m_params = colt.m_params;
38 }
39 
41 {
42  m_spec = Rgb;
43  m_params.argb.alpha = (unsigned short)(color.getAlpha() * 0x101);
44  m_params.argb.red = (unsigned short)(color.getRed() * 0x101);
45  m_params.argb.green = (unsigned short)(color.getGreen() * 0x101);
46  m_params.argb.blue = (unsigned short)(color.getBlue() * 0x101);
47  m_params.argb.pad = 0;
48 }
49 
51 {
52  m_spec = Rgb;
53  m_params.argb.alpha = (unsigned short)(((rgba >> 24) & 0xFF) * 0x101);
54  m_params.argb.red = (unsigned short)(((rgba >> 16) & 0xFF) * 0x101);
55  m_params.argb.green = (unsigned short)(((rgba >> 8) & 0xFF) * 0x101);
56  m_params.argb.blue = (unsigned short)((rgba & 0xFF) * 0x101);
57  m_params.argb.pad = 0;
58 }
59 
60 te::color::ColorTransform::ColorTransform(const int r, const int g, const int b, const int a)
61 {
62  m_spec = Rgb;
63  m_params.argb.alpha = (unsigned short)(a * 0x101);
64  m_params.argb.red = (unsigned short)(r * 0x101);
65  m_params.argb.green = (unsigned short)(g * 0x101);
66  m_params.argb.blue = (unsigned short)(b * 0x101);
67  m_params.argb.pad = 0;
68 }
69 
71 
73  const ColorTransform &colt) = default;
74 
75 void te::color::ColorTransform::setRgba(int r, int g, int b, int a)
76 {
77  m_spec = Rgb;
78  m_params.argb.alpha = (unsigned short)(a * 0x101);
79  m_params.argb.red = (unsigned short)(r * 0x101);
80  m_params.argb.green = (unsigned short)(g * 0x101);
81  m_params.argb.blue = (unsigned short)(b * 0x101);
82  m_params.argb.pad = 0;
83 }
84 
86 {
87  int a = (rgba >> 24) & 0xff;
88  int r = (rgba >> 16) & 0xff;
89  int g = (rgba >> 8) & 0xff;
90  int b = rgba & 0xff;
91  setRgba(r, g, b, a);
92 }
93 
95 {
96  setRgba(cor.getRgba());
97 }
98 
99 void te::color::ColorTransform::getRgba(int* r, int* g, int* b, int* a) const
100 {
101  if (!r || !g || !b)
102  return;
103 
104  if (m_spec != Invalid && m_spec != Rgb)
105  {
106  toRgb().getRgba(r, g, b, a);
107  return;
108  }
109 
110  *r = m_params.argb.red >> 8;
111  *g = m_params.argb.green >> 8;
112  *b = m_params.argb.blue >> 8;
113 
114  if (a)
115  *a = m_params.argb.alpha >> 8;
116 }
117 
119 {
120  int r, g, b, a;
121 
122  getRgba(&r, &g, &b, &a);
123 
124  int rgba = (a << 24) + (r << 16) + (g << 8) + b;
125  return rgba;
126 }
127 
129 {
130  RGBAColor cor = getRgba();
131  return cor;
132 }
133 
135 {
136  if (m_spec != Invalid && m_spec != Rgb)
137  return toRgb().getRed();
138  return m_params.argb.red >> 8;
139 }
140 
142 {
143  if (m_spec != Invalid && m_spec != Rgb)
144  return toRgb().getGreen();
145  return m_params.argb.green >> 8;
146 }
147 
149 {
150  if (m_spec != Invalid && m_spec != Rgb)
151  return toRgb().getBlue();
152  return m_params.argb.blue >> 8;
153 }
154 
156 {
157  return m_params.argb.alpha >> 8;
158 }
159 
161 {
162  if (m_spec != Rgb)
163  setRgba(red, getGreen(), getBlue(), getAlpha());
164  else
165  m_params.argb.red = (unsigned short)(red * 0x101);
166 }
167 
169 {
170  if (m_spec != Rgb)
171  setRgba(getRed(), green, getBlue(), getAlpha());
172  else
173  m_params.argb.green = (unsigned short)(green * 0x101);
174 }
175 
177 {
178  if (m_spec != Rgb)
179  setRgba(getRed(), getGreen(), blue, getAlpha());
180  else
181  m_params.argb.blue = (unsigned short)(blue * 0x101);
182 }
183 
185 {
186  m_params.argb.alpha = (unsigned short)(alpha * 0x101);
187 }
188 
190 {
191  if (!isValid() || m_spec == Rgb)
192  return *this;
193 
194  ColorTransform colt;
195  colt.m_spec = Rgb;
196  colt.m_params.argb.alpha = m_params.argb.alpha;
197  colt.m_params.argb.pad = 0;
198 
199  switch (m_spec)
200  {
201  case Hsv:
202  {
203  if (m_params.ahsv.saturation == 0 || m_params.ahsv.hue == USHRT_MAX)
204  {
205  // achromatic case
206  colt.m_params.argb.red = colt.m_params.argb.green = colt.m_params.argb.blue = m_params.ahsv.value;
207  break;
208  }
209 
210  // chromatic case
211  const double h = m_params.ahsv.hue == 36000 ? 0 : m_params.ahsv.hue / 6000.;
212  const double s = m_params.ahsv.saturation / double(USHRT_MAX);
213  const double v = m_params.ahsv.value / double(USHRT_MAX);
214  const int i = int(h);
215  const double f = h - i;
216  const double p = v * (1.0 - s);
217 
218  if (i & 1)
219  {
220  const double q = v * (1.0 - (s * f));
221 
222  switch (i)
223  {
224  case 1:
225  colt.m_params.argb.red = (unsigned short)(round(q * USHRT_MAX));
226  colt.m_params.argb.green = (unsigned short)(round(v * USHRT_MAX));
227  colt.m_params.argb.blue = (unsigned short)(round(p * USHRT_MAX));
228  break;
229  case 3:
230  colt.m_params.argb.red = (unsigned short)(round(p * USHRT_MAX));
231  colt.m_params.argb.green = (unsigned short)(round(q * USHRT_MAX));
232  colt.m_params.argb.blue = (unsigned short)(round(v * USHRT_MAX));
233  break;
234  case 5:
235  colt.m_params.argb.red = (unsigned short)(round(v * USHRT_MAX));
236  colt.m_params.argb.green = (unsigned short)(round(p * USHRT_MAX));
237  colt.m_params.argb.blue = (unsigned short)(round(q * USHRT_MAX));
238  break;
239  }
240  }
241  else
242  {
243  const double t = v * (1.0 - (s * (1.0 - f)));
244 
245  switch (i)
246  {
247  case 0:
248  colt.m_params.argb.red = (unsigned short)(round(v * USHRT_MAX));
249  colt.m_params.argb.green = (unsigned short)(round(t * USHRT_MAX));
250  colt.m_params.argb.blue = (unsigned short)(round(p * USHRT_MAX));
251  break;
252  case 2:
253  colt.m_params.argb.red = (unsigned short)(round(p * USHRT_MAX));
254  colt.m_params.argb.green = (unsigned short)(round(v * USHRT_MAX));
255  colt.m_params.argb.blue = (unsigned short)(round(t * USHRT_MAX));
256  break;
257  case 4:
258  colt.m_params.argb.red = (unsigned short)(round(t * USHRT_MAX));
259  colt.m_params.argb.green = (unsigned short)(round(p * USHRT_MAX));
260  colt.m_params.argb.blue = (unsigned short)(round(v * USHRT_MAX));
261  break;
262  }
263  }
264  break;
265  }
266  case Hsl:
267  {
268  if (m_params.ahsl.saturation == 0 || m_params.ahsl.hue == USHRT_MAX)
269  {
270  // achromatic case
271  colt.m_params.argb.red = colt.m_params.argb.green = colt.m_params.argb.blue = m_params.ahsl.lightness;
272  }
273  else if (m_params.ahsl.lightness == 0)
274  {
275  // lightness 0
276  colt.m_params.argb.red = colt.m_params.argb.green = colt.m_params.argb.blue = 0;
277  }
278  else
279  {
280  // chromatic case
281  const double h = m_params.ahsl.hue == 36000 ? 0 : m_params.ahsl.hue / 36000.;
282  const double s = m_params.ahsl.saturation / double(USHRT_MAX);
283  const double l = m_params.ahsl.lightness / double(USHRT_MAX);
284 
285  double temp2;
286  if (l < double(0.5))
287  temp2 = l * (double(1.0) + s);
288  else
289  temp2 = l + s - (l * s);
290 
291  const double temp1 = (double(2.0) * l) - temp2;
292  double temp3[3] = { h + (double(1.0) / double(3.0)), h, h - (double(1.0) / double(3.0)) };
293 
294  for (int i = 0; i != 3; ++i)
295  {
296  if (temp3[i] < double(0.0))
297  temp3[i] += double(1.0);
298  else if (temp3[i] > double(1.0))
299  temp3[i] -= double(1.0);
300 
301  const double sixtemp3 = temp3[i] * double(6.0);
302  if (sixtemp3 < double(1.0))
303  colt.m_params.array[i+1] = (unsigned short)(round((temp1 + (temp2 - temp1) * sixtemp3) * USHRT_MAX));
304  else if ((temp3[i] * double(2.0)) < double(1.0))
305  colt.m_params.array[i+1] = (unsigned short)(round(temp2 * USHRT_MAX));
306  else if ((temp3[i] * double(3.0)) < double(2.0))
307  colt.m_params.array[i+1] = (unsigned short)(round((temp1 + (temp2 -temp1) * (double(2.0) /double(3.0) - temp3[i]) * double(6.0)) * USHRT_MAX));
308  else
309  colt.m_params.array[i+1] = (unsigned short)(round(temp1 * USHRT_MAX));
310  }
311  colt.m_params.argb.red = colt.m_params.argb.red == 1 ? 0 : colt.m_params.argb.red;
312  colt.m_params.argb.green = colt.m_params.argb.green == 1 ? 0 : colt.m_params.argb.green;
313  colt.m_params.argb.blue = colt.m_params.argb.blue == 1 ? 0 : colt.m_params.argb.blue;
314  }
315  break;
316  }
317  case Cmyk:
318  {
319  const double c = m_params.acmyk.cyan / double(USHRT_MAX);
320  const double m = m_params.acmyk.magenta / double(USHRT_MAX);
321  const double y = m_params.acmyk.yellow / double(USHRT_MAX);
322  const double k = m_params.acmyk.black / double(USHRT_MAX);
323 
324  colt.m_params.argb.red = (unsigned short)(round((1.0 - (c * (1.0 - k) + k)) * USHRT_MAX));
325  colt.m_params.argb.green = (unsigned short)(round((1.0 - (m * (1.0 - k) + k)) * USHRT_MAX));
326  colt.m_params.argb.blue = (unsigned short)(round((1.0 - (y * (1.0 - k) + k)) * USHRT_MAX));
327  break;
328  }
329  default:
330  break;
331  }
332 
333  return colt;
334 }
335 
336 #define MAX_3(a, b, c) ( ( a > b && a > c) ? a : (b > c ? b : c) )
337 #define MIN_3(a, b, c) ( ( a < b && a < c) ? a : (b < c ? b : c) )
338 
340 {
341  if (!isValid() || m_spec == Hsv)
342  return *this;
343 
344  if (m_spec != Rgb)
345  return toRgb().toHsv();
346 
347  ColorTransform colt;
348  colt.m_spec = Hsv;
349  colt.m_params.ahsv.alpha = m_params.argb.alpha;
350  colt.m_params.ahsv.pad = 0;
351 
352  const double r = m_params.argb.red / double(USHRT_MAX);
353  const double g = m_params.argb.green / double(USHRT_MAX);
354  const double b = m_params.argb.blue / double(USHRT_MAX);
355  const double max = MAX_3(r, g, b);
356  const double min = MIN_3(r, g, b);
357  const double delta = max - min;
358  colt.m_params.ahsv.value = (unsigned short)(round(max * USHRT_MAX));
359 
360  if (fuzzyIsNull(delta))
361  {
362  // achromatic case, hue is undefined
363  colt.m_params.ahsv.hue = USHRT_MAX;
364  colt.m_params.ahsv.saturation = 0;
365  }
366  else
367  {
368  // chromatic case
369  double hue = 0;
370  colt.m_params.ahsv.saturation = (unsigned short)(round((delta / max) * USHRT_MAX));
371  if (fuzzyCompare(r, max))
372  {
373  hue = ((g - b) /delta);
374  }
375  else if (fuzzyCompare(g, max))
376  {
377  hue = (2.0 + (b - r) / delta);
378  }
379  else if (fuzzyCompare(b, max))
380  {
381  hue = (4.0 + (r - g) / delta);
382  }
383  else
384  {
385 // "internal error"
386  }
387  hue *= 60.0;
388 
389  if (hue < 0.0)
390  hue += 360.0;
391  colt.m_params.ahsv.hue = (unsigned short)(round(hue * 100));
392  }
393 
394  return colt;
395 }
396 
398 {
399  if (!isValid() || m_spec == Hsl)
400  return *this;
401 
402  if (m_spec != Rgb)
403  return toRgb().toHsl();
404 
405  ColorTransform colt;
406  colt.m_spec = Hsl;
407  colt.m_params.ahsl.alpha = m_params.argb.alpha;
408  colt.m_params.ahsl.pad = 0;
409 
410  const double r = m_params.argb.red / double(USHRT_MAX);
411  const double g = m_params.argb.green / double(USHRT_MAX);
412  const double b = m_params.argb.blue / double(USHRT_MAX);
413  const double max = MAX_3(r, g, b);
414  const double min = MIN_3(r, g, b);
415  const double delta = max - min;
416  const double delta2 = max + min;
417  const double lightness = double(0.5) * delta2;
418  colt.m_params.ahsl.lightness = (unsigned short)(round(lightness * USHRT_MAX));
419 
420  if (fuzzyIsNull(delta))
421  {
422  // achromatic case, hue is undefined
423  colt.m_params.ahsl.hue = 0;
424  colt.m_params.ahsl.saturation = 0;
425  }
426  else
427  {
428  // chromatic case
429  double hue = 0;
430  if (lightness < double(0.5))
431  colt.m_params.ahsl.saturation = (unsigned short)(round((delta / delta2) * USHRT_MAX));
432  else
433  colt.m_params.ahsl.saturation = (unsigned short)(round((delta / (double(2.0) - delta2)) * USHRT_MAX));
434 
435  if (fuzzyCompare(r, max))
436  {
437  hue = ((g - b) /delta);
438  }
439  else if (fuzzyCompare(g, max))
440  {
441  hue = (2.0 + (b - r) / delta);
442  }
443  else if (fuzzyCompare(b, max))
444  {
445  hue = (4.0 + (r - g) / delta);
446  }
447  else
448  {
449 // "internal error"
450  }
451 
452  hue *= 60.0;
453  if (hue < 0.0)
454  hue += 360.0;
455  colt.m_params.ahsl.hue = (unsigned short)(round(hue * 100));
456  }
457 
458  return colt;
459 }
460 
462 {
463  if (!isValid() || m_spec == Cmyk)
464  return *this;
465 
466  if (m_spec != Rgb)
467  return toRgb().toCmyk();
468 
469  ColorTransform colt;
470  colt.m_spec = Cmyk;
471  colt.m_params.acmyk.alpha = m_params.argb.alpha;
472 
473  // rgb -> cmy
474  const double r = m_params.argb.red / double(USHRT_MAX);
475  const double g = m_params.argb.green / double(USHRT_MAX);
476  const double b = m_params.argb.blue / double(USHRT_MAX);
477  double c = 1.0 - r;
478  double m = 1.0 - g;
479  double y = 1.0 - b;
480 
481  // cmy -> cmyk
482  const double k = vMin(c, vMin(m, y));
483 
484  if (!fuzzyIsNull(k - 1))
485  {
486  c = (c - k) / (1.0 - k);
487  m = (m - k) / (1.0 - k);
488  y = (y - k) / (1.0 - k);
489  }
490 
491  colt.m_params.acmyk.cyan = (unsigned short)(round(c * USHRT_MAX));
492  colt.m_params.acmyk.magenta = (unsigned short)(round(m * USHRT_MAX));
493  colt.m_params.acmyk.yellow = (unsigned short)(round(y * USHRT_MAX));
494  colt.m_params.acmyk.black = (unsigned short)(round(k * USHRT_MAX));
495 
496  return colt;
497 }
498 
500 {
501  if (m_spec != Invalid && m_spec != Hsv)
502  return toHsv().getHsvHue();
503  return m_params.ahsv.hue == USHRT_MAX ? -1 : m_params.ahsv.hue / 100;
504 }
505 
507 {
508  if (m_spec != Invalid && m_spec != Hsv)
509  return toHsv().getHsvSaturation();
510  return m_params.ahsv.saturation >> 8;
511 }
512 
514 {
515  if (m_spec != Invalid && m_spec != Hsv)
516  return toHsv().getValue();
517  return m_params.ahsv.value >> 8;
518 }
519 
520 void te::color::ColorTransform::getHsv(int *h, int *s, int *v, int *a) const
521 {
522  if (!h || !s || !v)
523  return;
524 
525  if (m_spec != Invalid && m_spec != Hsv)
526  {
527  toHsv().getHsv(h, s, v, a);
528  return;
529  }
530 
531  *h = m_params.ahsv.hue == USHRT_MAX ? -1 : m_params.ahsv.hue / 100;
532  *s = m_params.ahsv.saturation >> 8;
533  *v = m_params.ahsv.value >> 8;
534 
535  if (a)
536  *a = m_params.ahsv.alpha >> 8;
537 }
538 
539 void te::color::ColorTransform::setHsv(int h, int s, int v, int a)
540 {
541  if (h < -1 || (unsigned int)s > 255 || (unsigned int)v > 255 || (unsigned int)a > 255)
542  {
543  //"HSV parameters out of range"
544  invalidate();
545  return;
546  }
547 
548  m_spec = Hsv;
549  m_params.ahsv.alpha = (unsigned short)(a * 0x101);
550  m_params.ahsv.hue = (unsigned short)(h == -1 ? USHRT_MAX : (h % 360) * 100);
551  m_params.ahsv.saturation = (unsigned short)(s * 0x101);
552  m_params.ahsv.value = (unsigned short)(v * 0x101);
553  m_params.ahsv.pad = 0;
554 }
555 
557 {
558  if (m_spec != Invalid && m_spec != Cmyk)
559  return toCmyk().getCyan();
560  return m_params.acmyk.cyan >> 8;
561 }
562 
564 {
565  if (m_spec != Invalid && m_spec != Cmyk)
566  return toCmyk().getMagenta();
567  return m_params.acmyk.magenta >> 8;
568 }
569 
571 {
572  if (m_spec != Invalid && m_spec != Cmyk)
573  return toCmyk().getYellow();
574  return m_params.acmyk.yellow >> 8;
575 }
576 
578 {
579  if (m_spec != Invalid && m_spec != Cmyk)
580  return toCmyk().getBlack();
581  return m_params.acmyk.black >> 8;
582 }
583 
584 void te::color::ColorTransform::getCmyk(int *c, int *m, int *y, int *k, int *a)
585 {
586  if (!c || !m || !y || !k)
587  return;
588 
589  if (m_spec != Invalid && m_spec != Cmyk)
590  {
591  toCmyk().getCmyk(c, m, y, k, a);
592  return;
593  }
594 
595  *c = m_params.acmyk.cyan >> 8;
596  *m = m_params.acmyk.magenta >> 8;
597  *y = m_params.acmyk.yellow >> 8;
598  *k = m_params.acmyk.black >> 8;
599 
600  if (a)
601  *a = m_params.acmyk.alpha >> 8;
602 }
603 
604 void te::color::ColorTransform::setCmyk(int c, int m, int y, int k, int a)
605 {
606  if (c < 0 || c > 255
607  || m < 0 || m > 255
608  || y < 0 || y > 255
609  || k < 0 || k > 255
610  || a < 0 || a > 255)
611  {
612  //"CMYK parameters out of range"
613  return;
614  }
615 
616  m_spec = Cmyk;
617  m_params.acmyk.alpha = (unsigned short)(a * 0x101);
618  m_params.acmyk.cyan = (unsigned short)(c * 0x101);
619  m_params.acmyk.magenta = (unsigned short)(m * 0x101);
620  m_params.acmyk.yellow = (unsigned short)(y * 0x101);
621  m_params.acmyk.black = (unsigned short)(k * 0x101);
622 }
623 
625 {
626  if (m_spec != Invalid && m_spec != Hsl)
627  return toHsl().getHslHue();
628  return m_params.ahsl.hue == USHRT_MAX ? -1 : m_params.ahsl.hue / 100;
629 }
630 
632 {
633  if (m_spec != Invalid && m_spec != Hsl)
634  return toHsl().getHslSaturation();
635  return m_params.ahsl.saturation >> 8;
636 }
637 
639 {
640  if (m_spec != Invalid && m_spec != Hsl)
641  return toHsl().getLightness();
642  return m_params.ahsl.lightness >> 8;
643 }
644 
645 void te::color::ColorTransform::getHsl(int *h, int *s, int *l, int *a) const
646 {
647  if (!h || !s || !l)
648  return;
649 
650  if (m_spec != Invalid && m_spec != Hsl)
651  {
652  toHsl().getHsl(h, s, l, a);
653  return;
654  }
655 
656  *h = m_params.ahsl.hue == USHRT_MAX ? -1 : m_params.ahsl.hue / 100;
657  *s = m_params.ahsl.saturation >> 8;
658  *l = m_params.ahsl.lightness >> 8;
659 
660  if (a)
661  *a = m_params.ahsl.alpha >> 8;
662 }
663 
664 void te::color::ColorTransform::setHsl(int h, int s, int l, int a)
665 {
666  if (h < -1 || (unsigned short)s > 255 || (unsigned short)l > 255 || (unsigned short)a > 255)
667  {
668  //"HSV parameters out of range"
669  invalidate();
670  return;
671  }
672 
673  m_spec = Hsl;
674  m_params.ahsl.alpha = (unsigned short)(a * 0x101);
675  m_params.ahsl.hue = (unsigned short)(h == -1 ? USHRT_MAX : (h % 360) * 100);
676  m_params.ahsl.saturation = (unsigned short)(s * 0x101);
677  m_params.ahsl.lightness = (unsigned short)(l * 0x101);
678  m_params.ahsl.pad = 0;
679 }
680 
682 {
683  if (m_spec == Hsl && m_spec == colt.m_spec)
684  {
685  return (m_params.argb.alpha == colt.m_params.argb.alpha
686  && ((((m_params.ahsl.hue % 36000) == (colt.m_params.ahsl.hue % 36000)))
687  || (m_params.ahsl.hue == colt.m_params.ahsl.hue))
688  && (abs(m_params.ahsl.saturation - colt.m_params.ahsl.saturation) < 50
689  || m_params.ahsl.lightness == 0
690  || colt.m_params.ahsl.lightness == 0
691  || m_params.ahsl.lightness == USHRT_MAX
692  || colt.m_params.ahsl.lightness == USHRT_MAX)
693  && (abs(m_params.ahsl.lightness - colt.m_params.ahsl.lightness)) < 50);
694  }
695  else
696  {
697  return (m_spec == colt.m_spec
698  && m_params.argb.alpha == colt.m_params.argb.alpha
699  && (((m_spec == Hsv)
700  && ((m_params.ahsv.hue % 36000) == (colt.m_params.ahsv.hue % 36000)))
701  || (m_params.ahsv.hue == colt.m_params.ahsv.hue))
702  && m_params.argb.green == colt.m_params.argb.green
703  && m_params.argb.blue == colt.m_params.argb.blue
704  && m_params.argb.pad == colt.m_params.argb.pad);
705  }
706 }
707 
709 {
710  return !operator==(colt);
711 }
712 
void getHsl(int *h, int *s, int *l, int *a=0) const
It gets the h, s, l components of this color.
int getValue() const
It returns the value component of this color.
void getRgba(int *r, int *g, int *b, int *a=0) const
It gets the color value.
Definition: RGBAColor.h:327
#define MIN_3(a, b, c)
int getHsvHue() const
It returns the hue component of this color.
union te::color::ColorTransform::@0 m_params
~ColorTransform()
Destructor.
bool isValid() const
It checks if the color is valid.
struct te::color::ColorTransform::@0::@1 argb
int getHslSaturation() const
It returns the saturation component of this color.
te::color::ColorTransform & operator=(const ColorTransform &colt)
Assigns a copy of a color transform and returns a reference to it.
int getRed() const
It returns the red component color value (a value from 0 to 255).
Definition: RGBAColor.h:307
void setRgba(int r, int g, int b, int a)
It sets the color.
int getLightness() const
It returns the lightness component of this color.
bool operator!=(const ColorTransform &colt) const
It compares the color tranforms are different.
int getBlue() const
It returns the blue component color value (a value from 0 to 255).
Definition: RGBAColor.h:317
void setCmyk(int c, int m, int y, int k, int a=255)
It sets the c, m, y, k components of this color.
int getGreen() const
It returns the green component color value (a value from 0 to 255).
Definition: RGBAColor.h:312
int round(double d) const
It rounds the double value to int value.
ColorTransform()
Default constructor of a new color.
int getHsvSaturation() const
It returns the saturation component of this color.
void getRgba(int *r, int *g, int *b, int *a=0) const
It gets the color value.
int getRed() const
It returns the red component.
int getAlpha() const
It returns the alpha component.
void setColor(const RGBAColor &cor)
It sets the color.
void setHsv(int h, int s, int v, int a=255)
It sets the h, s, v components of this color.
bool fuzzyIsNull(double d) const
It verifies the double is null.
void setBlue(int blue)
It sets the blue component.
int b
Definition: TsRtree.cpp:32
te::color::RGBAColor getColor() const
It returns the RGBA color.
void invalidate()
Marks the color transform as invalid and sets all components to zero (alpha is set to fully opaque)...
void setGreen(int green)
It sets the green component.
te::color::ColorTransform toHsv() const
It returns the color tranform in Hsv spec.
#define MAX_3(a, b, c)
int getAlpha() const
It returns the alpha component color value (a value from 0 to 255).
Definition: RGBAColor.h:322
int getHslHue() const
It returns the hue component of this color.
te::color::ColorTransform toRgb() const
It returns the color tranform in Rgb spec.
te::gm::Polygon * p
bool fuzzyCompare(double p1, double p2) const
It compares the double valuea are iqual.
void setAlpha(int alpha)
It sets the alpha component.
int getBlack() const
It gets the black component of this color.
void setHsl(int h, int s, int l, int a=255)
It sets the h, s, l components of this color.
void getCmyk(int *c, int *m, int *y, int *k, int *a=0)
It gets the c, m, y, k components of this color.
struct te::color::ColorTransform::@0::@2 ahsv
int getYellow() const
It gets the yellow component of this color.
int getRgba() const
It returns the color value (0xAARRGGBB).
A class to transform .
unsigned short array[5]
const T & vMin(const T &a, const T &b) const
te::color::ColorTransform toHsl() const
It returns the color tranform in Hsl spec.
int getCyan() const
It gets the cyan component of this color.
int getMagenta() const
It gets the magenta component of this color.
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
Definition: RGBAColor.h:57
te::color::ColorTransform toCmyk() const
It returns the color tranform in Cmyk spec.
void getHsv(int *h, int *s, int *v, int *a=0) const
It gets the h, s, v components of this color.
bool operator==(const ColorTransform &colt) const
It compares the color tranforms are iqual.
A class to transform RGBA color to HSV, HSL and CMYK.
int getBlue() const
It returns the blue component.
void setRed(int red)
It sets the red component.
struct te::color::ColorTransform::@0::@3 acmyk
int getGreen() const
It returns the green component.
struct te::color::ColorTransform::@0::@4 ahsl