te::color::ColorTransform Class Reference

A class to transform RGBA color to HSV, HSL and CMYK. More...

#include <ColorTransform.h>

Public Types

enum  Spec {
  Invalid, Rgb, Hsv, Cmyk,
  Hsl
}
 

Public Member Functions

Initializer Methods

Methods related to instantiation and destruction.

 ColorTransform ()
 Default constructor of a new color. More...
 
 ColorTransform (const ColorTransform &colt)
 It initializes a new with the given color transform. More...
 
 ColorTransform (const RGBAColor &color)
 It initializes a new color with the given RGBAColor. More...
 
 ColorTransform (const int &rgba)
 It initializes a new color with the given rgba value. More...
 
 ColorTransform (const int r, const int g, const int b, const int a=255)
 It initializes a new color. More...
 
 ~ColorTransform ()
 Destructor. More...
 
te::color::ColorTransformoperator= (const ColorTransform &colt)
 Assigns a copy of a color transform and returns a reference to it. More...
 
void setRgba (int r, int g, int b, int a)
 It sets the color. More...
 
void setRgba (int rgba)
 It sets the color. More...
 
void setColor (const RGBAColor &cor)
 It sets the color. More...
 
void getRgba (int *r, int *g, int *b, int *a=0) const
 It gets the color value. More...
 
int getRgba () const
 It returns the color value (0xAARRGGBB). More...
 
te::color::RGBAColor getColor () const
 It returns the RGBA color. More...
 
int getRed () const
 It returns the red component. More...
 
int getGreen () const
 It returns the green component. More...
 
int getBlue () const
 It returns the blue component. More...
 
int getAlpha () const
 It returns the alpha component. More...
 
void setRed (int red)
 It sets the red component. More...
 
void setGreen (int green)
 It sets the green component. More...
 
void setBlue (int blue)
 It sets the blue component. More...
 
void setAlpha (int alpha)
 It sets the alpha component. More...
 
te::color::ColorTransform toRgb () const
 It returns the color tranform in Rgb spec. More...
 
te::color::ColorTransform toHsv () const
 It returns the color tranform in Hsv spec. More...
 
te::color::ColorTransform toHsl () const
 It returns the color tranform in Hsl spec. More...
 
te::color::ColorTransform toCmyk () const
 It returns the color tranform in Cmyk spec. More...
 
int getHsvHue () const
 It returns the hue component of this color. More...
 
int getHsvSaturation () const
 It returns the saturation component of this color. More...
 
int getValue () const
 It returns the value component of this color. More...
 
void getHsv (int *h, int *s, int *v, int *a=0) const
 It gets the h, s, v components of this color. More...
 
void setHsv (int h, int s, int v, int a=255)
 It sets the h, s, v components of this color. More...
 
int getCyan () const
 It gets the cyan component of this color. More...
 
int getMagenta () const
 It gets the magenta component of this color. More...
 
int getYellow () const
 It gets the yellow component of this color. More...
 
int getBlack () const
 It gets the black component of this color. More...
 
void getCmyk (int *c, int *m, int *y, int *k, int *a=0)
 It gets the c, m, y, k components of this color. More...
 
void setCmyk (int c, int m, int y, int k, int a=255)
 It sets the c, m, y, k components of this color. More...
 
int getHslHue () const
 It returns the hue component of this color. More...
 
int getHslSaturation () const
 It returns the saturation component of this color. More...
 
int getLightness () const
 It returns the lightness component of this color. More...
 
void getHsl (int *h, int *s, int *l, int *a=0) const
 It gets the h, s, l components of this color. More...
 
void setHsl (int h, int s, int l, int a=255)
 It sets the h, s, l components of this color. More...
 
bool operator== (const ColorTransform &colt) const
 It compares the color tranforms are iqual. More...
 
bool operator!= (const ColorTransform &colt) const
 It compares the color tranforms are different. More...
 

Private Member Functions

bool fuzzyCompare (double p1, double p2) const
 It compares the double valuea are iqual. More...
 
bool fuzzyIsNull (double d) const
 It verifies the double is null. More...
 
void invalidate ()
 Marks the color transform as invalid and sets all components to zero (alpha is set to fully opaque). More...
 
bool isValid () const
 It checks if the color is valid. More...
 
int round (double d) const
 It rounds the double value to int value. More...
 
template<typename T >
const T & vMin (const T &a, const T &b) const
 

Private Attributes

union {
   struct {
      unsigned short   alpha
 
      unsigned short   black
 
      unsigned short   cyan
 
      unsigned short   magenta
 
      unsigned short   yellow
 
   }   acmyk
 
   struct {
      unsigned short   alpha
 
      unsigned short   hue
 
      unsigned short   lightness
 
      unsigned short   pad
 
      unsigned short   saturation
 
   }   ahsl
 
   struct {
      unsigned short   alpha
 
      unsigned short   hue
 
      unsigned short   pad
 
      unsigned short   saturation
 
      unsigned short   value
 
   }   ahsv
 
   struct {
      unsigned short   alpha
 
      unsigned short   blue
 
      unsigned short   green
 
      unsigned short   pad
 
      unsigned short   red
 
   }   argb
 
   unsigned short   array [5]
 
m_params
 
Spec m_spec
 

Detailed Description

A class to transform RGBA color to HSV, HSL and CMYK.

Definition at line 50 of file ColorTransform.h.

Member Enumeration Documentation

Enumerator
Invalid 
Rgb 
Hsv 
Cmyk 
Hsl 

Definition at line 54 of file ColorTransform.h.

Constructor & Destructor Documentation

te::color::ColorTransform::ColorTransform ( )

Default constructor of a new color.

Definition at line 29 of file ColorTransform.cpp.

References invalidate().

te::color::ColorTransform::ColorTransform ( const ColorTransform colt)

It initializes a new with the given color transform.

Parameters
coltThe color transform.

Definition at line 34 of file ColorTransform.cpp.

References m_params, and m_spec.

te::color::ColorTransform::ColorTransform ( const RGBAColor color)

It initializes a new color with the given RGBAColor.

Parameters
colorThe RGBAColor.

Definition at line 40 of file ColorTransform.cpp.

References te::color::RGBAColor::getAlpha(), te::color::RGBAColor::getBlue(), te::color::RGBAColor::getGreen(), and te::color::RGBAColor::getRed().

te::color::ColorTransform::ColorTransform ( const int &  rgba)

It initializes a new color with the given rgba value.

Parameters
rgbaThe rgba value.

Definition at line 50 of file ColorTransform.cpp.

te::color::ColorTransform::ColorTransform ( const int  r,
const int  g,
const int  b,
const int  a = 255 
)

It initializes a new color.

Parameters
rRed component (range from 0 to 255).
gGreen component (range from 0 to 255).
bBlue component (range from 0 to 255).
aAlpha component. A range from 0 to 255 (see the macro TE_OPAQUE and TE_TRANSPARENT for the values of totally transparent and totally opaque).

Definition at line 60 of file ColorTransform.cpp.

te::color::ColorTransform::~ColorTransform ( )

Destructor.

Definition at line 70 of file ColorTransform.cpp.

Member Function Documentation

bool te::color::ColorTransform::fuzzyCompare ( double  p1,
double  p2 
) const
inlineprivate

It compares the double valuea are iqual.

Parameters
p1First value.
p2Second value.
Returns
True if values are equal.

Definition at line 524 of file ColorTransform.h.

References vMin().

bool te::color::ColorTransform::fuzzyIsNull ( double  d) const
inlineprivate

It verifies the double is null.

Parameters
dValue to be verified.
Returns
True if value is null.

Definition at line 529 of file ColorTransform.h.

int te::color::ColorTransform::getAlpha ( ) const

It returns the alpha component.

Returns
The alpha component.

Definition at line 162 of file ColorTransform.cpp.

Referenced by te::qt::widgets::colorbar::ColorBar::wheelEvent().

int te::color::ColorTransform::getBlack ( ) const

It gets the black component of this color.

Note
The color is implicitly converted to Cmyk.

Definition at line 584 of file ColorTransform.cpp.

int te::color::ColorTransform::getBlue ( ) const

It returns the blue component.

Returns
The blue component.

Definition at line 155 of file ColorTransform.cpp.

Referenced by te::qt::widgets::colorbar::ColorBar::wheelEvent().

void te::color::ColorTransform::getCmyk ( int *  c,
int *  m,
int *  y,
int *  k,
int *  a = 0 
)

It gets the c, m, y, k components of this color.

Parameters
cThe cyan component.
mThe magenta component.
yThe yellow component.
kThe black component.
aThe alpha component.
Note
The color is implicitly converted to Cmyk.

Definition at line 591 of file ColorTransform.cpp.

te::color::RGBAColor te::color::ColorTransform::getColor ( ) const

It returns the RGBA color.

Returns
The RGBA color.

Definition at line 135 of file ColorTransform.cpp.

int te::color::ColorTransform::getCyan ( ) const

It gets the cyan component of this color.

Note
The color is implicitly converted to Cmyk.

Definition at line 563 of file ColorTransform.cpp.

int te::color::ColorTransform::getGreen ( ) const

It returns the green component.

Returns
The green component.

Definition at line 148 of file ColorTransform.cpp.

Referenced by te::qt::widgets::colorbar::ColorBar::wheelEvent().

void te::color::ColorTransform::getHsl ( int *  h,
int *  s,
int *  l,
int *  a = 0 
) const

It gets the h, s, l components of this color.

Parameters
hThe cyan component.
sThe magenta component.
lThe yellow component.
aThe alpha component.
Note
The color is implicitly converted to HSL.

Definition at line 652 of file ColorTransform.cpp.

Referenced by te::qt::widgets::colorbar::ColorBar::wheelEvent().

int te::color::ColorTransform::getHslHue ( ) const

It returns the hue component of this color.

Returns
The hue value.
Note
The color is implicitly converted to HSL.

Definition at line 631 of file ColorTransform.cpp.

int te::color::ColorTransform::getHslSaturation ( ) const

It returns the saturation component of this color.

Returns
The saturation value.
Note
The color is implicitly converted to HSL.

Definition at line 638 of file ColorTransform.cpp.

void te::color::ColorTransform::getHsv ( int *  h,
int *  s,
int *  v,
int *  a = 0 
) const

It gets the h, s, v components of this color.

Parameters
hThe hue component.
sThe saturation component.
vThe value component.
aThe alpha component.
Note
The color is implicitly converted to HSV.

Definition at line 527 of file ColorTransform.cpp.

int te::color::ColorTransform::getHsvHue ( ) const

It returns the hue component of this color.

Returns
The hue value.
Note
The color is implicitly converted to HSV.

Definition at line 506 of file ColorTransform.cpp.

int te::color::ColorTransform::getHsvSaturation ( ) const

It returns the saturation component of this color.

Returns
The saturation value.
Note
The color is implicitly converted to HSV.

Definition at line 513 of file ColorTransform.cpp.

int te::color::ColorTransform::getLightness ( ) const

It returns the lightness component of this color.

Returns
The lightness value.
Note
The color is implicitly converted to HSL.

Definition at line 645 of file ColorTransform.cpp.

int te::color::ColorTransform::getMagenta ( ) const

It gets the magenta component of this color.

Note
The color is implicitly converted to Cmyk.

Definition at line 570 of file ColorTransform.cpp.

int te::color::ColorTransform::getRed ( ) const

It returns the red component.

Returns
The red component.

Definition at line 141 of file ColorTransform.cpp.

Referenced by te::qt::widgets::colorbar::ColorBar::wheelEvent().

void te::color::ColorTransform::getRgba ( int *  r,
int *  g,
int *  b,
int *  a = 0 
) const

It gets the color value.

Parameters
rRed component.
gGreen component.
bBlue component.
aAlpha component.

Definition at line 106 of file ColorTransform.cpp.

Referenced by te::se::GenerateRandomColor().

int te::color::ColorTransform::getRgba ( ) const

It returns the color value (0xAARRGGBB).

Returns
It returns a number of 4 bytes. The values are on the following order: alpha, red, green and blue. The alpha is the most significant byte.

Definition at line 125 of file ColorTransform.cpp.

int te::color::ColorTransform::getValue ( ) const

It returns the value component of this color.

Returns
The value.
Note
The color is implicitly converted to HSV.

Definition at line 520 of file ColorTransform.cpp.

int te::color::ColorTransform::getYellow ( ) const

It gets the yellow component of this color.

Note
The color is implicitly converted to Cmyk.

Definition at line 577 of file ColorTransform.cpp.

void te::color::ColorTransform::invalidate ( )
inlineprivate

Marks the color transform as invalid and sets all components to zero (alpha is set to fully opaque).

Definition at line 504 of file ColorTransform.h.

References Invalid, m_params, and m_spec.

Referenced by ColorTransform().

bool te::color::ColorTransform::isValid ( ) const
inlineprivate

It checks if the color is valid.

Returns
True if valid color.

Definition at line 514 of file ColorTransform.h.

References Invalid, and m_spec.

bool te::color::ColorTransform::operator!= ( const ColorTransform colt) const

It compares the color tranforms are different.

Parameters
coltThe color transform to be compared.
Returns
Returns true if this color transform has not the same properties.

Definition at line 715 of file ColorTransform.cpp.

References operator==().

te::color::ColorTransform & te::color::ColorTransform::operator= ( const ColorTransform colt)

Assigns a copy of a color transform and returns a reference to it.

Parameters
colorThe color transfom to be copied.
Returns
Returns a reference to it.

Definition at line 74 of file ColorTransform.cpp.

References m_params, and m_spec.

bool te::color::ColorTransform::operator== ( const ColorTransform colt) const

It compares the color tranforms are iqual.

Parameters
coltThe color transform to be compared.
Returns
Returns true if this color transform has the same properties.

Definition at line 688 of file ColorTransform.cpp.

References ahsl, ahsv, argb, m_params, and m_spec.

int te::color::ColorTransform::round ( double  d) const
inlineprivate

It rounds the double value to int value.

Returns
The int value rounded.

Definition at line 519 of file ColorTransform.h.

void te::color::ColorTransform::setAlpha ( int  alpha)

It sets the alpha component.

Definition at line 191 of file ColorTransform.cpp.

void te::color::ColorTransform::setBlue ( int  blue)

It sets the blue component.

Definition at line 183 of file ColorTransform.cpp.

void te::color::ColorTransform::setCmyk ( int  c,
int  m,
int  y,
int  k,
int  a = 255 
)

It sets the c, m, y, k components of this color.

Parameters
cThe cyan component.
mThe magenta component.
yThe yellow component.
kThe black component.
aThe alpha component.
Note
The color is converted to Cmyk.

Definition at line 611 of file ColorTransform.cpp.

void te::color::ColorTransform::setColor ( const RGBAColor cor)

It sets the color.

Parameters
corThe RGBA color.

Definition at line 101 of file ColorTransform.cpp.

References te::color::RGBAColor::getRgba().

void te::color::ColorTransform::setGreen ( int  green)

It sets the green component.

Definition at line 175 of file ColorTransform.cpp.

void te::color::ColorTransform::setHsl ( int  h,
int  s,
int  l,
int  a = 255 
)

It sets the h, s, l components of this color.

Parameters
hThe cyan component.
sThe magenta component.
lThe yellow component.
aThe alpha component.
Note
The color is converted to HSL.

Definition at line 671 of file ColorTransform.cpp.

Referenced by te::qt::widgets::colorbar::ColorBar::wheelEvent().

void te::color::ColorTransform::setHsv ( int  h,
int  s,
int  v,
int  a = 255 
)

It sets the h, s, v components of this color.

Parameters
hThe hue component.
sThe saturation component.
vThe value component.
aThe alpha component.
Note
The color is converted to HSV.

Definition at line 546 of file ColorTransform.cpp.

Referenced by te::se::GenerateRandomColor().

void te::color::ColorTransform::setRed ( int  red)

It sets the red component.

Definition at line 167 of file ColorTransform.cpp.

void te::color::ColorTransform::setRgba ( int  r,
int  g,
int  b,
int  a 
)

It sets the color.

Parameters
rRed component (range from 0 to 255).
gGreen component (range from 0 to 255).
bBlue component (range from 0 to 255).
aAlpha component. A range from 0 to 255 (see the macro TE_OPAQUE and TE_TRANSPARENT for the values of totally transparent and totally opaque).

Definition at line 82 of file ColorTransform.cpp.

void te::color::ColorTransform::setRgba ( int  rgba)

It sets the color.

Parameters
rgbaThe color represented by a number of 4 bytes, where the values ??are in the following order: alpha, red, green and blue. The alpha is the most significant byte.

Definition at line 92 of file ColorTransform.cpp.

te::color::ColorTransform te::color::ColorTransform::toCmyk ( ) const

It returns the color tranform in Cmyk spec.

Returns
The color transform in Cmyk spec.
Note
If spec is not CMYK, it creates and returns an equivalent.

Definition at line 468 of file ColorTransform.cpp.

References acmyk, m_params, m_spec, and toCmyk().

Referenced by toCmyk().

te::color::ColorTransform te::color::ColorTransform::toHsl ( ) const

It returns the color tranform in Hsl spec.

Returns
The color transform in Hsl spec.
Note
If spec is not HSL, it creates and returns an equivalent.

Definition at line 404 of file ColorTransform.cpp.

References ahsl, m_params, m_spec, MAX_3, MIN_3, and toHsl().

Referenced by toHsl().

te::color::ColorTransform te::color::ColorTransform::toHsv ( ) const

It returns the color tranform in Hsv spec.

Returns
The color transform in Hsv spec.
Note
If spec is not HSV, it creates and returns an equivalent.

Definition at line 346 of file ColorTransform.cpp.

References ahsv, m_params, m_spec, MAX_3, MIN_3, and toHsv().

Referenced by toHsv().

te::color::ColorTransform te::color::ColorTransform::toRgb ( ) const

It returns the color tranform in Rgb spec.

Returns
The color transform in Rgb spec.
Note
If spec is not RGB, it creates and returns an equivalent.

Definition at line 196 of file ColorTransform.cpp.

References argb, array, m_params, and m_spec.

template<typename T >
const T& te::color::ColorTransform::vMin ( const T &  a,
const T &  b 
) const
inlineprivate

Definition at line 456 of file ColorTransform.h.

Referenced by fuzzyCompare().

Member Data Documentation

struct { ... } te::color::ColorTransform::acmyk

Referenced by toCmyk().

struct { ... } te::color::ColorTransform::ahsl

Referenced by operator==(), and toHsl().

struct { ... } te::color::ColorTransform::ahsv

Referenced by operator==(), and toHsv().

unsigned short te::color::ColorTransform::alpha

Definition at line 466 of file ColorTransform.h.

struct { ... } te::color::ColorTransform::argb

Referenced by operator==(), and toRgb().

unsigned short te::color::ColorTransform::array[5]

Definition at line 500 of file ColorTransform.h.

Referenced by toRgb().

unsigned short te::color::ColorTransform::black

Definition at line 488 of file ColorTransform.h.

unsigned short te::color::ColorTransform::blue

Definition at line 469 of file ColorTransform.h.

unsigned short te::color::ColorTransform::cyan

Definition at line 485 of file ColorTransform.h.

unsigned short te::color::ColorTransform::green

Definition at line 468 of file ColorTransform.h.

unsigned short te::color::ColorTransform::hue

Definition at line 476 of file ColorTransform.h.

unsigned short te::color::ColorTransform::lightness

Definition at line 496 of file ColorTransform.h.

union { ... } te::color::ColorTransform::m_params
Spec te::color::ColorTransform::m_spec
private
unsigned short te::color::ColorTransform::magenta

Definition at line 486 of file ColorTransform.h.

unsigned short te::color::ColorTransform::pad

Definition at line 470 of file ColorTransform.h.

unsigned short te::color::ColorTransform::red

Definition at line 467 of file ColorTransform.h.

unsigned short te::color::ColorTransform::saturation

Definition at line 477 of file ColorTransform.h.

unsigned short te::color::ColorTransform::value

Definition at line 478 of file ColorTransform.h.

unsigned short te::color::ColorTransform::yellow

Definition at line 487 of file ColorTransform.h.


The documentation for this class was generated from the following files: