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;
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;
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;
85 m_params.argb.alpha = (
unsigned short)(a * 0x101);
86 m_params.argb.red = (
unsigned short)(r * 0x101);
87 m_params.argb.green = (
unsigned short)(g * 0x101);
88 m_params.argb.blue = (
unsigned short)(b * 0x101);
89 m_params.argb.pad = 0;
94 int a = (rgba >> 24) & 0xff;
95 int r = (rgba >> 16) & 0xff;
96 int g = (rgba >> 8) & 0xff;
111 if (m_spec != Invalid && m_spec != Rgb)
113 toRgb().getRgba(r, g, b, a);
117 *r = m_params.argb.red >> 8;
118 *g = m_params.argb.green >> 8;
119 *b = m_params.argb.blue >> 8;
122 *a = m_params.argb.alpha >> 8;
129 getRgba(&r, &g, &b, &a);
131 int rgba = (a << 24) + (r << 16) + (g << 8) + b;
143 if (m_spec != Invalid && m_spec != Rgb)
144 return toRgb().getRed();
145 return m_params.argb.red >> 8;
150 if (m_spec != Invalid && m_spec != Rgb)
151 return toRgb().getGreen();
152 return m_params.argb.green >> 8;
157 if (m_spec != Invalid && m_spec != Rgb)
158 return toRgb().getBlue();
159 return m_params.argb.blue >> 8;
164 return m_params.argb.alpha >> 8;
170 setRgba(red, getGreen(), getBlue(), getAlpha());
172 m_params.argb.red = (
unsigned short)(red * 0x101);
178 setRgba(getRed(), green, getBlue(), getAlpha());
180 m_params.argb.green = (
unsigned short)(green * 0x101);
186 setRgba(getRed(), getGreen(), blue, getAlpha());
188 m_params.argb.blue = (
unsigned short)(blue * 0x101);
193 m_params.argb.alpha = (
unsigned short)(alpha * 0x101);
198 if (!isValid() || m_spec == Rgb)
210 if (m_params.ahsv.saturation == 0 || m_params.ahsv.hue == USHRT_MAX)
218 const double h = m_params.ahsv.hue == 36000 ? 0 : m_params.ahsv.hue / 6000.;
219 const double s = m_params.ahsv.saturation / double(USHRT_MAX);
220 const double v = m_params.ahsv.value / double(USHRT_MAX);
221 const int i = int(h);
222 const double f = h - i;
223 const double p = v * (1.0 - s);
227 const double q = v * (1.0 - (s * f));
232 colt.
m_params.
argb.red = (
unsigned short)(round(q * USHRT_MAX));
233 colt.
m_params.
argb.green = (
unsigned short)(round(v * USHRT_MAX));
234 colt.
m_params.
argb.blue = (
unsigned short)(round(p * USHRT_MAX));
237 colt.
m_params.
argb.red = (
unsigned short)(round(p * USHRT_MAX));
238 colt.
m_params.
argb.green = (
unsigned short)(round(q * USHRT_MAX));
239 colt.
m_params.
argb.blue = (
unsigned short)(round(v * USHRT_MAX));
242 colt.
m_params.
argb.red = (
unsigned short)(round(v * USHRT_MAX));
243 colt.
m_params.
argb.green = (
unsigned short)(round(p * USHRT_MAX));
244 colt.
m_params.
argb.blue = (
unsigned short)(round(q * USHRT_MAX));
250 const double t = v * (1.0 - (s * (1.0 - f)));
255 colt.
m_params.
argb.red = (
unsigned short)(round(v * USHRT_MAX));
256 colt.
m_params.
argb.green = (
unsigned short)(round(t * USHRT_MAX));
257 colt.
m_params.
argb.blue = (
unsigned short)(round(p * USHRT_MAX));
260 colt.
m_params.
argb.red = (
unsigned short)(round(p * USHRT_MAX));
261 colt.
m_params.
argb.green = (
unsigned short)(round(v * USHRT_MAX));
262 colt.
m_params.
argb.blue = (
unsigned short)(round(t * USHRT_MAX));
265 colt.
m_params.
argb.red = (
unsigned short)(round(t * USHRT_MAX));
266 colt.
m_params.
argb.green = (
unsigned short)(round(p * USHRT_MAX));
267 colt.
m_params.
argb.blue = (
unsigned short)(round(v * USHRT_MAX));
275 if (m_params.ahsl.saturation == 0 || m_params.ahsl.hue == USHRT_MAX)
280 else if (m_params.ahsl.lightness == 0)
288 const double h = m_params.ahsl.hue == 36000 ? 0 : m_params.ahsl.hue / 36000.;
289 const double s = m_params.ahsl.saturation / double(USHRT_MAX);
290 const double l = m_params.ahsl.lightness / double(USHRT_MAX);
294 temp2 = l * (double(1.0) + s);
296 temp2 = l + s - (l * s);
298 const double temp1 = (double(2.0) * l) - temp2;
299 double temp3[3] = { h + (double(1.0) / double(3.0)), h, h - (
double(1.0) / double(3.0)) };
301 for (
int i = 0; i != 3; ++i)
303 if (temp3[i] <
double(0.0))
304 temp3[i] +=
double(1.0);
305 else if (temp3[i] >
double(1.0))
306 temp3[i] -=
double(1.0);
308 const double sixtemp3 = temp3[i] * double(6.0);
309 if (sixtemp3 <
double(1.0))
310 colt.
m_params.
array[i+1] = (
unsigned short)(round((temp1 + (temp2 - temp1) * sixtemp3) * USHRT_MAX));
311 else if ((temp3[i] *
double(2.0)) < double(1.0))
312 colt.
m_params.
array[i+1] = (
unsigned short)(round(temp2 * USHRT_MAX));
313 else if ((temp3[i] *
double(3.0)) < double(2.0))
314 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));
316 colt.
m_params.
array[i+1] = (
unsigned short)(round(temp1 * USHRT_MAX));
326 const double c = m_params.acmyk.cyan / double(USHRT_MAX);
327 const double m = m_params.acmyk.magenta / double(USHRT_MAX);
328 const double y = m_params.acmyk.yellow / double(USHRT_MAX);
329 const double k = m_params.acmyk.black / double(USHRT_MAX);
331 colt.
m_params.
argb.red = (
unsigned short)(round((1.0 - (c * (1.0 - k) + k)) * USHRT_MAX));
332 colt.
m_params.
argb.green = (
unsigned short)(round((1.0 - (m * (1.0 - k) + k)) * USHRT_MAX));
333 colt.
m_params.
argb.blue = (
unsigned short)(round((1.0 - (y * (1.0 - k) + k)) * USHRT_MAX));
343 #define MAX_3(a, b, c) ( ( a > b && a > c) ? a : (b > c ? b : c) )
344 #define MIN_3(a, b, c) ( ( a < b && a < c) ? a : (b < c ? b : c) )
348 if (!isValid() || m_spec == Hsv)
352 return toRgb().
toHsv();
359 const double r = m_params.argb.red / double(USHRT_MAX);
360 const double g = m_params.argb.green / double(USHRT_MAX);
361 const double b = m_params.argb.blue / double(USHRT_MAX);
362 const double max =
MAX_3(r, g, b);
363 const double min =
MIN_3(r, g, b);
364 const double delta = max - min;
365 colt.
m_params.
ahsv.value = (
unsigned short)(round(max * USHRT_MAX));
367 if (fuzzyIsNull(delta))
377 colt.
m_params.
ahsv.saturation = (
unsigned short)(round((delta / max) * USHRT_MAX));
378 if (fuzzyCompare(r, max))
380 hue = ((g - b) /delta);
382 else if (fuzzyCompare(g, max))
384 hue = (2.0 + (b - r) / delta);
386 else if (fuzzyCompare(b, max))
388 hue = (4.0 + (r - g) / delta);
398 colt.
m_params.
ahsv.hue = (
unsigned short)(round(hue * 100));
406 if (!isValid() || m_spec == Hsl)
410 return toRgb().
toHsl();
417 const double r = m_params.argb.red / double(USHRT_MAX);
418 const double g = m_params.argb.green / double(USHRT_MAX);
419 const double b = m_params.argb.blue / double(USHRT_MAX);
420 const double max =
MAX_3(r, g, b);
421 const double min =
MIN_3(r, g, b);
422 const double delta = max - min;
423 const double delta2 = max + min;
424 const double lightness = double(0.5) * delta2;
425 colt.
m_params.
ahsl.lightness = (
unsigned short)(round(lightness * USHRT_MAX));
427 if (fuzzyIsNull(delta))
437 if (lightness <
double(0.5))
438 colt.
m_params.
ahsl.saturation = (
unsigned short)(round((delta / delta2) * USHRT_MAX));
440 colt.
m_params.
ahsl.saturation = (
unsigned short)(round((delta / (
double(2.0) - delta2)) * USHRT_MAX));
442 if (fuzzyCompare(r, max))
444 hue = ((g - b) /delta);
446 else if (fuzzyCompare(g, max))
448 hue = (2.0 + (b - r) / delta);
450 else if (fuzzyCompare(b, max))
452 hue = (4.0 + (r - g) / delta);
462 colt.
m_params.
ahsl.hue = (
unsigned short)(round(hue * 100));
470 if (!isValid() || m_spec == Cmyk)
481 const double r = m_params.argb.red / double(USHRT_MAX);
482 const double g = m_params.argb.green / double(USHRT_MAX);
483 const double b = m_params.argb.blue / double(USHRT_MAX);
489 const double k = vMin(c, vMin(m, y));
491 if (!fuzzyIsNull(k - 1))
493 c = (c - k) / (1.0 - k);
494 m = (m - k) / (1.0 - k);
495 y = (y - k) / (1.0 - k);
498 colt.
m_params.
acmyk.cyan = (
unsigned short)(round(c * USHRT_MAX));
499 colt.
m_params.
acmyk.magenta = (
unsigned short)(round(m * USHRT_MAX));
500 colt.
m_params.
acmyk.yellow = (
unsigned short)(round(y * USHRT_MAX));
501 colt.
m_params.
acmyk.black = (
unsigned short)(round(k * USHRT_MAX));
508 if (m_spec != Invalid && m_spec != Hsv)
509 return toHsv().getHsvHue();
510 return m_params.ahsv.hue == USHRT_MAX ? -1 : m_params.ahsv.hue / 100;
515 if (m_spec != Invalid && m_spec != Hsv)
516 return toHsv().getHsvSaturation();
517 return m_params.ahsv.saturation >> 8;
522 if (m_spec != Invalid && m_spec != Hsv)
523 return toHsv().getValue();
524 return m_params.ahsv.value >> 8;
532 if (m_spec != Invalid && m_spec != Hsv)
534 toHsv().getHsv(h, s, v, a);
538 *h = m_params.ahsv.hue == USHRT_MAX ? -1 : m_params.ahsv.hue / 100;
539 *s = m_params.ahsv.saturation >> 8;
540 *v = m_params.ahsv.value >> 8;
543 *a = m_params.ahsv.alpha >> 8;
548 if (h < -1 || (
unsigned int)s > 255 || (
unsigned int)v > 255 || (
unsigned int)a > 255)
556 m_params.ahsv.alpha = (
unsigned short)(a * 0x101);
557 m_params.ahsv.hue = (
unsigned short)(h == -1 ? USHRT_MAX : (h % 360) * 100);
558 m_params.ahsv.saturation = (
unsigned short)(s * 0x101);
559 m_params.ahsv.value = (
unsigned short)(v * 0x101);
560 m_params.ahsv.pad = 0;
565 if (m_spec != Invalid && m_spec != Cmyk)
566 return toCmyk().getCyan();
567 return m_params.acmyk.cyan >> 8;
572 if (m_spec != Invalid && m_spec != Cmyk)
573 return toCmyk().getMagenta();
574 return m_params.acmyk.magenta >> 8;
579 if (m_spec != Invalid && m_spec != Cmyk)
580 return toCmyk().getYellow();
581 return m_params.acmyk.yellow >> 8;
586 if (m_spec != Invalid && m_spec != Cmyk)
587 return toCmyk().getBlack();
588 return m_params.acmyk.black >> 8;
593 if (!c || !m || !y || !k)
596 if (m_spec != Invalid && m_spec != Cmyk)
598 toCmyk().getCmyk(c, m, y, k, a);
602 *c = m_params.acmyk.cyan >> 8;
603 *m = m_params.acmyk.magenta >> 8;
604 *y = m_params.acmyk.yellow >> 8;
605 *k = m_params.acmyk.black >> 8;
608 *a = m_params.acmyk.alpha >> 8;
624 m_params.acmyk.alpha = (
unsigned short)(a * 0x101);
625 m_params.acmyk.cyan = (
unsigned short)(c * 0x101);
626 m_params.acmyk.magenta = (
unsigned short)(m * 0x101);
627 m_params.acmyk.yellow = (
unsigned short)(y * 0x101);
628 m_params.acmyk.black = (
unsigned short)(k * 0x101);
633 if (m_spec != Invalid && m_spec != Hsl)
634 return toHsl().getHslHue();
635 return m_params.ahsl.hue == USHRT_MAX ? -1 : m_params.ahsl.hue / 100;
640 if (m_spec != Invalid && m_spec != Hsl)
641 return toHsl().getHslSaturation();
642 return m_params.ahsl.saturation >> 8;
647 if (m_spec != Invalid && m_spec != Hsl)
648 return toHsl().getLightness();
649 return m_params.ahsl.lightness >> 8;
657 if (m_spec != Invalid && m_spec != Hsl)
659 toHsl().getHsl(h, s, l, a);
663 *h = m_params.ahsl.hue == USHRT_MAX ? -1 : m_params.ahsl.hue / 100;
664 *s = m_params.ahsl.saturation >> 8;
665 *l = m_params.ahsl.lightness >> 8;
668 *a = m_params.ahsl.alpha >> 8;
673 if (h < -1 || (
unsigned short)s > 255 || (
unsigned short)l > 255 || (
unsigned short)a > 255)
681 m_params.ahsl.alpha = (
unsigned short)(a * 0x101);
682 m_params.ahsl.hue = (
unsigned short)(h == -1 ? USHRT_MAX : (h % 360) * 100);
683 m_params.ahsl.saturation = (
unsigned short)(s * 0x101);
684 m_params.ahsl.lightness = (
unsigned short)(l * 0x101);
685 m_params.ahsl.pad = 0;
690 if (m_spec == Hsl && m_spec == colt.
m_spec)
693 && ((((m_params.ahsl.hue % 36000) == (colt.
m_params.
ahsl.hue % 36000)))
695 && (abs(m_params.ahsl.saturation - colt.
m_params.
ahsl.saturation) < 50
696 || m_params.ahsl.lightness == 0
698 || m_params.ahsl.lightness == USHRT_MAX
700 && (abs(m_params.ahsl.lightness - colt.
m_params.
ahsl.lightness)) < 50);
704 return (m_spec == colt.
m_spec
707 && ((m_params.ahsv.hue % 36000) == (colt.
m_params.
ahsv.hue % 36000)))
bool operator==(const ColorTransform &colt) const
It compares the color tranforms are iqual.
te::color::ColorTransform toCmyk() const
It returns the color tranform in Cmyk spec.
int getRed() const
It returns the red component.
void getRgba(int *r, int *g, int *b, int *a=0) const
It gets the color value.
~ColorTransform()
Destructor.
union te::color::ColorTransform::@0 m_params
void setGreen(int green)
It sets the green component.
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).
int getCyan() const
It gets the cyan component of this color.
void setHsv(int h, int s, int v, int a=255)
It sets the h, s, v components of this color.
int getValue() const
It returns the value component of this color.
int getHslSaturation() const
It returns the saturation component of this color.
void invalidate()
Marks the color transform as invalid and sets all components to zero (alpha is set to fully opaque)...
te::da::Expression * operator==(const te::da::Expression &e1, const te::da::Expression &e2)
int getBlack() const
It gets the black component of this color.
void setAlpha(int alpha)
It sets the alpha component.
void getCmyk(int *c, int *m, int *y, int *k, int *a=0)
It gets the c, m, y, k components of this color.
void setColor(const RGBAColor &cor)
It sets the color.
int getLightness() const
It returns the lightness component of this color.
void setBlue(int blue)
It sets the blue component.
int getMagenta() const
It gets the magenta component of this color.
te::color::ColorTransform toRgb() const
It returns the color tranform in Rgb spec.
bool operator!=(const ColorTransform &colt) const
It compares the color tranforms are different.
struct te::color::ColorTransform::@0::@4 ahsl
int getHslHue() const
It returns the hue component of this color.
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
int getBlue() const
It returns the blue component.
int getGreen() const
It returns the green component.
int getRgba() const
It returns the color value (0xAARRGGBB).
void getHsl(int *h, int *s, int *l, int *a=0) const
It gets the h, s, l components of this color.
void setHsl(int h, int s, int l, int a=255)
It sets the h, s, l components of this color.
int getHsvSaturation() const
It returns the saturation component of this color.
int getHsvHue() const
It returns the hue 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 getAlpha() const
It returns the alpha component.
struct te::color::ColorTransform::@0::@3 acmyk
void setRed(int red)
It sets the red component.
te::color::RGBAColor getColor() const
It returns the RGBA color.
void setRgba(int r, int g, int b, int a)
It sets the color.
te::color::ColorTransform toHsv() const
It returns the color tranform in Hsv spec.
ColorTransform()
Default constructor of a new color.
struct te::color::ColorTransform::@0::@1 argb
struct te::color::ColorTransform::@0::@2 ahsv
int getBlue() const
It returns the blue component color value (a value from 0 to 255).
int getAlpha() const
It returns the alpha component color value (a value from 0 to 255).
void getHsv(int *h, int *s, int *v, int *a=0) const
It gets the h, s, v components of this color.
int getRed() const
It returns the red component color value (a value from 0 to 255).
int getYellow() const
It gets the yellow component of this color.
te::color::ColorTransform toHsl() const
It returns the color tranform in Hsl spec.
A class to transform RGBA color to HSV, HSL and CMYK.