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

◆ Spec

Enumerator
Invalid 
Rgb 
Hsv 
Cmyk 
Hsl 

Definition at line 54 of file ColorTransform.h.

Constructor & Destructor Documentation

◆ ColorTransform() [1/5]

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

Default constructor of a new color.

◆ ColorTransform() [2/5]

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

It initializes a new with the given color transform.

Parameters
coltThe color transform.

◆ ColorTransform() [3/5]

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

It initializes a new color with the given RGBAColor.

Parameters
colorThe RGBAColor.

◆ ColorTransform() [4/5]

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

It initializes a new color with the given rgba value.

Parameters
rgbaThe rgba value.

◆ ColorTransform() [5/5]

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).

◆ ~ColorTransform()

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

Destructor.

Member Function Documentation

◆ fuzzyCompare()

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().

◆ fuzzyIsNull()

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.

◆ getAlpha()

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

It returns the alpha component.

Returns
The alpha component.

◆ getBlack()

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

It gets the black component of this color.

Note
The color is implicitly converted to Cmyk.

◆ getBlue()

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

It returns the blue component.

Returns
The blue component.

◆ getCmyk()

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.

◆ getColor()

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

It returns the RGBA color.

Returns
The RGBA color.

◆ getCyan()

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

It gets the cyan component of this color.

Note
The color is implicitly converted to Cmyk.

◆ getGreen()

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

It returns the green component.

Returns
The green component.

◆ getHsl()

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.

◆ getHslHue()

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.

◆ getHslSaturation()

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.

◆ getHsv()

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.

◆ getHsvHue()

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.

◆ getHsvSaturation()

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.

◆ getLightness()

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.

◆ getMagenta()

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

It gets the magenta component of this color.

Note
The color is implicitly converted to Cmyk.

◆ getRed()

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

It returns the red component.

Returns
The red component.

◆ getRgba() [1/2]

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.

◆ getRgba() [2/2]

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.

◆ getValue()

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.

◆ getYellow()

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

It gets the yellow component of this color.

Note
The color is implicitly converted to Cmyk.

◆ invalidate()

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.

◆ isValid()

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.

◆ operator!=()

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.

◆ 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.

◆ operator==()

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.

◆ round()

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.

◆ setAlpha()

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

It sets the alpha component.

◆ setBlue()

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

It sets the blue component.

◆ setCmyk()

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.

◆ setColor()

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

It sets the color.

Parameters
corThe RGBA color.

◆ setGreen()

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

It sets the green component.

◆ setHsl()

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.

◆ setHsv()

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.

◆ setRed()

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

It sets the red component.

◆ setRgba() [1/2]

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).

◆ setRgba() [2/2]

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.

◆ toCmyk()

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.

◆ toHsl()

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.

◆ toHsv()

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.

◆ toRgb()

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.

◆ vMin()

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

◆ acmyk

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

◆ ahsl

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

◆ ahsv

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

◆ alpha

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

Definition at line 466 of file ColorTransform.h.

◆ argb

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

◆ array

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

Definition at line 500 of file ColorTransform.h.

◆ black

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

Definition at line 488 of file ColorTransform.h.

◆ blue

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

Definition at line 469 of file ColorTransform.h.

◆ cyan

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

Definition at line 485 of file ColorTransform.h.

◆ green

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

Definition at line 468 of file ColorTransform.h.

◆ hue

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

Definition at line 476 of file ColorTransform.h.

◆ lightness

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

Definition at line 496 of file ColorTransform.h.

◆ m_params

union { ... } te::color::ColorTransform::m_params

Referenced by invalidate().

◆ m_spec

Spec te::color::ColorTransform::m_spec
private

Definition at line 460 of file ColorTransform.h.

Referenced by invalidate(), and isValid().

◆ magenta

unsigned short te::color::ColorTransform::magenta

Definition at line 486 of file ColorTransform.h.

◆ pad

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

Definition at line 470 of file ColorTransform.h.

◆ red

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

Definition at line 467 of file ColorTransform.h.

◆ saturation

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

Definition at line 477 of file ColorTransform.h.

◆ value

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

Definition at line 478 of file ColorTransform.h.

◆ yellow

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

Definition at line 487 of file ColorTransform.h.


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