Sourceforge.net - The VCF's Project Host
   The VCF Website Home   |   Online Discussion Forums   |   Sourceforge.net Project Page   

VCF::Color Class Reference

The Color class is used to represent a given color with 4 values, with each value representing a separate red, green, blue, and alpha color component (RGBA). More...

#include <vcf/GraphicsKit/Color.h>

Inheritance diagram for VCF::Color:

VCF::Object List of all members.

Public Types

enum  ColorPackScheme { cpsARGB = 0, cpsRGB, cpsABGR, cpsBGR }
 this enum defines the way color is stored when compressed into a 32/64 bit integer value. More...
enum  ColorType {
  ctRGB = 0, ctHSL, ctHSV, ctHWB,
  ctYUV, ctLab, ctCMY
}
 An enum that indicates the color type of three double values. More...
enum  MaxFactor { xFF = 0xFF, xFFFF = 0xFFFF }
 the factor used when ranging the color components with integers. More...

Public Member Functions

 Color ()
 default ctor
 Color (const Color &color)
 the copy ctor
 Color (const double &val1, const double &val2, const double &val3, ColorType type=ctRGB)
 Initializes a color based on the double values (type: double) of its three components in a specified color coordinates sytem.
 Color (const double &val1, const double &val2, const double &val3, const double &a, ColorType type=ctRGB)
 Color (const uint8 &val1, const uint8 &val2, const uint8 &val3, ColorType type=ctRGB)
 Initializes a color based on the integer values (called range values) of its three components in a specified color coordinates sytem.
 Color (const uint8 &val1, const uint8 &val2, const uint8 &val3, const uint8 &a, ColorType type=ctRGB)
 Color (const uint16 &val1, const uint16 &val2, const uint16 &val3, ColorType type=ctRGB)
 Initializes a color based on the values (type: unsigned short) of its three components in a specified color coordinates sytem.
 Color (const uint16 &val1, const uint16 &val2, const uint16 &val3, const uint16 &a, ColorType type=ctRGB)
 Color (const uint32 &color, const ColorPackScheme &cps=cpsRGB)
 this is a constructor helping us in the conversion from an uint32 ( as in COLORREF ) into which the color components have been packed (4 x 8bits).
 Color (const unsigned long &color, const ColorPackScheme &cps=cpsRGB)
 this is a constructor helping us in the conversion from an unsigned long ( as in COLORREF ) into which the color components have been packed (4 x 8bits).
 Color (const uint64 &color, const ColorPackScheme &cps=cpsRGB)
 this is a constructor halping us in the conversion from an uint64 ( similarly as in COLORREF) into which the color components have been packed (4 x 16bits).
 Color (const String &colorName)
 extract a color from its color name.
virtual ~Color ()
double getRed () const
double getGreen () const
double getBlue () const
double getAlpha () const
void setRed (const double &red)
void setGreen (const double &green)
void setBlue (const double &blue)
void setAlpha (const double &alpha)
void getRGB (double &r, double &g, double &b) const
 gets the color components of a color.
void getRGBA (double &r, double &g, double &b, double &a) const
void getRGB8 (uint8 &r, uint8 &g, uint8 &b) const
void getRGBA8 (uint8 &r, uint8 &g, uint8 &b, uint8 &a) const
void getRGB16 (uint16 &r, uint16 &g, uint16 &b) const
void getRGBA16 (uint16 &r, uint16 &g, uint16 &b, uint16 &a) const
uint32 getRGBPack8 (const ColorPackScheme &cps=cpsRGB) const
 packs into a uint32 integer the color components using 8bits for each component.
uint64 getRGBPack16 (const ColorPackScheme &cps=cpsRGB) const
 packs into a uint64 integer the color components using 16bits for each component.
uint32 getColorRef32 () const
 same as getRGBPack8, but with the parameter cpsABGR specified.
uint64 getColorRef64 () const
 same as getRGBPack16, but with the parameter cpsABGR specified.
void setRGB (const double &r, const double &g, const double &b)
 sets the color starting from the known color components.
void setRGBA (const double &r, const double &g, const double &b, const double &a)
void setRGB8 (const uint8 &r, const uint8 &g, const uint8 &b)
void setRGBA8 (const uint8 &r, const uint8 &g, const uint8 &b, const uint8 &a)
void setRGB16 (const uint16 &r, const uint16 &g, const uint16 &b)
void setRGBA16 (const uint16 &r, const uint16 &g, const uint16 &b, const uint16 &a)
ColorsetRGBPack8 (const uint32 &rgb, const ColorPackScheme &cps=cpsRGB)
 sets the color starting from the known color components that have been packed into a single uint32 integer (4 x 8bits).
ColorsetRGBPack16 (const uint64 &rgb, const ColorPackScheme &cps=cpsRGB)
 sets the color starting from the known color components that have been packed into a single uint64 integer (4 x 16bits).
ColorsetColorRef32 (const uint32 &rgb)
 same as setRGBPack8, but with the parameter cpsABGR specified.
ColorsetColorRef64 (const uint64 &rgb)
 same as setRGBPack16, but with the parameter cpsABGR specified.
void getHSV (double &h, double &s, double &v) const
void setHSV (const double &h, const double &s, const double &v)
void getHSL (double &h, double &l, double &s) const
void setHSL (const double &h, const double &l, const double &s)
void getCMYK (double &c, double &m, double &y, double &k) const
void setCMYK (const double &c, const double &m, const double &y, const double &k)
void getLab () const
void setLab ()
void getYUV () const
void setYUV ()
virtual void copyColor (const Color *source)
virtual void copyColor (const Color &source)
virtual void copy (Object *source)
 Copies the data from source to this object.
Coloroperator= (const Color *clr)
Coloroperator= (const Color &clr)
bool operator== (const Color &clr) const
bool operator!= (const Color &clr) const
bool operator< (const Color &clr) const
bool operator<= (const Color &clr) const
bool operator> (const Color &clr) const
bool operator>= (const Color &clr) const
virtual bool isEqual (const Color *color) const
virtual String toString () const
 overrides the Object's base class member function.
virtual void setFromString (const String &val)
 provides a simple to initialize the object from a string.
String toHexCode8 (const ColorPackScheme &cps=cpsRGB, const ColorType &ct=ctRGB)
 generates a String with the internal representation of the color in hexadecimal format with 8bits per component.
String toHexCode16 (const ColorPackScheme &cps=cpsRGB, const ColorType &ct=ctRGB)
void changeHSV (const double &percentH, const double &percentS, const double &percentV)
void changeHSL (const double &percentH, const double &percentS, const double &percentL)
void changeHWB (const double &percentH, const double &percentW, const double &percentB)
void changeHue (const double &deltaH)
int getLuminosity () const
 compute the luminosity as an RGB color.
void setLuminosity (const int &luminosity)
 set the luminosity of a color.
Colorinvert ()
 change the color to its complement (inverted)
Color getInverted () const
 compute the complement of the color
void getInvertedRGB (double &r, double &g, double &b) const
 compute the inverted color of a color, given its components.
void getInvertedRGB8 (uint8 &r, uint8 &g, uint8 &b) const
 compute the inverted components of a color, given its components in 8 bit.
void getInvertedRGB16 (uint16 &r, uint16 &g, uint16 &b) const
 compute the inverted components of a color, given its components in 16 bit.
Colorbrighter ()
 makes the color brighter
Colordarker ()
 makes the color brighter
virtual Objectclone (bool deep)

Static Public Member Functions

static ColorgetColor (const int &gray)
 gets a gray color from the map of internet colors.
static ColorgetColor (const String &colorName)
 gets a color from the map of internet colors.
static ColorgetColorMatch (const Color &color)
 gets a color from the map with the closest match a given color.
static const String getColorNameFromMap (const Color &color)
 gets the name of the color from the map with the closest match a given color.
static void createColorMap ()
 creates the map of internet colors.
static Color getColorContrast (const Color &color, double deltaL=0.3)
 computes a color with increased contrast.

Friends

class ColorSpace

Detailed Description

The Color class is used to represent a given color with 4 values, with each value representing a separate red, green, blue, and alpha color component (RGBA).

Each value is stored as a double with a valid range of 0.0 to 1.0. A variety of functions a provided to convert the color to and from other color representations, such as CMY(K), HSL, and HSV.


Member Enumeration Documentation

enum VCF::Color::ColorPackScheme
 

this enum defines the way color is stored when compressed into a 32/64 bit integer value.

Sadly not everyone stores this the same way so this will indicate how the bits are arranged

Enumerator:
cpsARGB  Alpha value, Red value, Green Value, and Blue value.

Seen in a 32 bit number as 0xAARRGGBB

cpsRGB  Red value, Green Value, and Blue value.

Seen in a 32 bit number as 0x00RRGGBB

cpsABGR  Alpha value, Blue value, Green Value, and Red value.

This is the default in Win32 systems (i.e. inverted). Seen in a 32 bit number as 0xAABBGGRR

cpsBGR  Blue value, Green Value, and Red value.

This is the default in Win32 systems (i.e. inverted). Seen in a 32 bit number as 0x00BBGGRR

enum VCF::Color::ColorType
 

An enum that indicates the color type of three double values.

Enumerator:
ctRGB  Assuming three color values, a, b, and c, which represent red, green, and blue values respectively, with each value bounded by 0.0 to 1.0 inclusive.
ctHSL  Assuming three color values, a, b, and c, which represent Hue, Luminance, and Saturation values respectively, with each value bounded by 0.0 to 1.0 inclusive.
ctHSV  Assuming three color values, a, b, and c, which represent Hue, Saturation, and Value values respectively, with each value bounded by 0.0 to 1.0 inclusive.
ctHWB 
ctYUV 
ctLab 
ctCMY 

enum VCF::Color::MaxFactor
 

the factor used when ranging the color components with integers.

Enumerator:
xFF 
xFFFF 


Constructor & Destructor Documentation

VCF::Color::Color  )  [inline]
 

default ctor

VCF::Color::Color const Color color  )  [inline]
 

the copy ctor

VCF::Color::Color const double &  val1,
const double &  val2,
const double &  val3,
ColorType  type = ctRGB
[inline]
 

Initializes a color based on the double values (type: double) of its three components in a specified color coordinates sytem.

The values, in double (4 bytes), are directly translated into the internal color components (in double). Usage: Color color = Color( 1.0, 1.0, 0.5 ); Color color2 = Color( color.getRed(), color.getGreen(), color.getBlue() );

Parameters:
ColorType indicates the coordinates used in the color space. By default the RGB (red, green, and blue) system is used.
See also:
ColorType

VCF::Color::Color const double &  val1,
const double &  val2,
const double &  val3,
const double &  a,
ColorType  type = ctRGB
[inline]
 

VCF::Color::Color const uint8 val1,
const uint8 val2,
const uint8 val3,
ColorType  type = ctRGB
[inline]
 

Initializes a color based on the integer values (called range values) of its three components in a specified color coordinates sytem.

The values are divided by 0xFF (255 - 1 byte) before being translated into the internal color components (in double). This conversion introduces a 'discreteness' in the color values that can be perceived by the human eye when drawing a a color gradient. Usage: Color color = Color( (uint8)255, 255, 128 );

Parameters:
ColorType indicates the coordinates used in the color space. By default the RGB (red, green, and blue) system is used.
See also:
ColorType

VCF::Color::Color const uint8 val1,
const uint8 val2,
const uint8 val3,
const uint8 a,
ColorType  type = ctRGB
[inline]
 

VCF::Color::Color const uint16 val1,
const uint16 val2,
const uint16 val3,
ColorType  type = ctRGB
[inline]
 

Initializes a color based on the values (type: unsigned short) of its three components in a specified color coordinates sytem.

The values are divided by 0xFFFF (65535 - 2 bytes) before being translated into the internal color components (in double). Usage: Color color = Color( (uint16)0xFFFF, 0xFFFF, 0x7FFF );

Parameters:
ColorType indicates the coordinates system used in the color space. By default the RGB (red, green, and blue) system is used.
See also:
ColorType

VCF::Color::Color const uint16 val1,
const uint16 val2,
const uint16 val3,
const uint16 a,
ColorType  type = ctRGB
[inline]
 

VCF::Color::Color const uint32 color,
const ColorPackScheme cps = cpsRGB
[inline]
 

this is a constructor helping us in the conversion from an uint32 ( as in COLORREF ) into which the color components have been packed (4 x 8bits).

Under Win32 it is necessary to specify the cpsABGR parameter.

Parameters:
the system used to pack the color components.
See also:
ColorFormat

VCF::Color::Color const unsigned long &  color,
const ColorPackScheme cps = cpsRGB
[inline]
 

this is a constructor helping us in the conversion from an unsigned long ( as in COLORREF ) into which the color components have been packed (4 x 8bits).

Under Win32 it is necessary to specify the cpsABGR parameter.

Parameters:
the system used to pack the color components.
See also:
ColorFormat

VCF::Color::Color const uint64 color,
const ColorPackScheme cps = cpsRGB
[inline]
 

this is a constructor halping us in the conversion from an uint64 ( similarly as in COLORREF) into which the color components have been packed (4 x 16bits).

Under Win32 it is necessary to specify the cpsABGR parameter.

Parameters:
the system used to pack the color components.
See also:
ColorFormat

VCF::Color::Color const String colorName  ) 
 

extract a color from its color name.

An internal map is used for this.

virtual VCF::Color::~Color  )  [inline, virtual]
 


Member Function Documentation

Color& VCF::Color::brighter  ) 
 

makes the color brighter

Returns:
Color& the color itself.

void VCF::Color::changeHSL const double &  percentH,
const double &  percentS,
const double &  percentL
[inline]
 

void VCF::Color::changeHSV const double &  percentH,
const double &  percentS,
const double &  percentV
[inline]
 

void VCF::Color::changeHue const double &  deltaH  )  [inline]
 

void VCF::Color::changeHWB const double &  percentH,
const double &  percentW,
const double &  percentB
[inline]
 

virtual Object* VCF::Color::clone bool  deep  )  [inline, virtual]
 

virtual void VCF::Color::copy Object source  )  [inline, virtual]
 

Copies the data from source to this object.

This is the equivalent of operator=()

Reimplemented from VCF::Object.

void VCF::Color::copyColor const Color source  )  [inline, virtual]
 

void VCF::Color::copyColor const Color source  )  [inline, virtual]
 

static void VCF::Color::createColorMap  )  [static]
 

creates the map of internet colors.

Color& VCF::Color::darker  ) 
 

makes the color brighter

Returns:
Color& the color itself.

double VCF::Color::getAlpha  )  const [inline]
 

double VCF::Color::getBlue  )  const [inline]
 

void VCF::Color::getCMYK double &  c,
double &  m,
double &  y,
double &  k
const [inline]
 

static Color* VCF::Color::getColor const String colorName  )  [static]
 

gets a color from the map of internet colors.

Parameters:
const String& colorName the name of the color.
Returns:
Color* a pointer to the color in the map.

static Color* VCF::Color::getColor const int &  gray  )  [static]
 

gets a gray color from the map of internet colors.

Parameters:
const int& gray, a gray value between 0 (black) and 255 (white)
Returns:
Color* a pointer to the color in the map.

static Color VCF::Color::getColorContrast const Color color,
double  deltaL = 0.3
[static]
 

computes a color with increased contrast.

Parameters:
const Color& color the given color.
double deltaL, the assigned fractional increase in luminosity.
Returns:
Color the computed color.

static Color* VCF::Color::getColorMatch const Color color  )  [static]
 

gets a color from the map with the closest match a given color.

Parameters:
const Color& color the given color.
Returns:
Color* a pointer to the color in the map.

static const String VCF::Color::getColorNameFromMap const Color color  )  [static]
 

gets the name of the color from the map with the closest match a given color.

Parameters:
const Color& color the given color.
Returns:
const String the name of the matching color in the map. The name is equal to ColorNames::unknownColorName() if not found.

uint32 VCF::Color::getColorRef32  )  const [inline]
 

same as getRGBPack8, but with the parameter cpsABGR specified.

introduced to make life easier to win32 users and less confusing.

uint64 VCF::Color::getColorRef64  )  const [inline]
 

same as getRGBPack16, but with the parameter cpsABGR specified.

introduced to make life easier to win32 users and less confusing.

double VCF::Color::getGreen  )  const [inline]
 

void VCF::Color::getHSL double &  h,
double &  l,
double &  s
const [inline]
 

void VCF::Color::getHSV double &  h,
double &  s,
double &  v
const [inline]
 

Color VCF::Color::getInverted  )  const [inline]
 

compute the complement of the color

Returns:
Color& the computed color.

void VCF::Color::getInvertedRGB double &  r,
double &  g,
double &  b
const [inline]
 

compute the inverted color of a color, given its components.

void VCF::Color::getInvertedRGB16 uint16 r,
uint16 g,
uint16 b
const [inline]
 

compute the inverted components of a color, given its components in 16 bit.

void VCF::Color::getInvertedRGB8 uint8 r,
uint8 g,
uint8 b
const [inline]
 

compute the inverted components of a color, given its components in 8 bit.

void VCF::Color::getLab  )  const [inline]
 

int VCF::Color::getLuminosity  )  const [inline]
 

compute the luminosity as an RGB color.

double VCF::Color::getRed  )  const [inline]
 

void VCF::Color::getRGB double &  r,
double &  g,
double &  b
const [inline]
 

gets the color components of a color.

void VCF::Color::getRGB16 uint16 r,
uint16 g,
uint16 b
const [inline]
 

void VCF::Color::getRGB8 uint8 r,
uint8 g,
uint8 b
const [inline]
 

void VCF::Color::getRGBA double &  r,
double &  g,
double &  b,
double &  a
const [inline]
 

void VCF::Color::getRGBA16 uint16 r,
uint16 g,
uint16 b,
uint16 a
const [inline]
 

void VCF::Color::getRGBA8 uint8 r,
uint8 g,
uint8 b,
uint8 a
const [inline]
 

uint64 VCF::Color::getRGBPack16 const ColorPackScheme cps = cpsRGB  )  const [inline]
 

packs into a uint64 integer the color components using 16bits for each component.

uint32 VCF::Color::getRGBPack8 const ColorPackScheme cps = cpsRGB  )  const [inline]
 

packs into a uint32 integer the color components using 8bits for each component.

void VCF::Color::getYUV  )  const [inline]
 

Color & VCF::Color::invert  )  [inline]
 

change the color to its complement (inverted)

Returns:
Color& the color itself.

virtual bool VCF::Color::isEqual const Color color  )  const [inline, virtual]
 

bool VCF::Color::operator!= const Color clr  )  const [inline]
 

bool VCF::Color::operator< const Color clr  )  const [inline]
 

windows stores its color format in the following scheme 0x00BBGGRR: so b is more important (because in the intel architecture the rightmost byte is the most important)

bool VCF::Color::operator<= const Color clr  )  const [inline]
 

Color& VCF::Color::operator= const Color clr  )  [inline]
 

Color& VCF::Color::operator= const Color clr  )  [inline]
 

bool VCF::Color::operator== const Color clr  )  const [inline]
 

bool VCF::Color::operator> const Color clr  )  const [inline]
 

windows stores its color format in the following scheme 0x00BBGGRR: so b is more important (because in the intel architecture the rightmost byte is the most important)

bool VCF::Color::operator>= const Color clr  )  const [inline]
 

void VCF::Color::setAlpha const double &  alpha  )  [inline]
 

void VCF::Color::setBlue const double &  blue  )  [inline]
 

void VCF::Color::setCMYK const double &  c,
const double &  m,
const double &  y,
const double &  k
[inline]
 

Color & VCF::Color::setColorRef32 const uint32 rgb  )  [inline]
 

same as setRGBPack8, but with the parameter cpsABGR specified.

Introduced to make life easier to win32 users and less confusing.

Color & VCF::Color::setColorRef64 const uint64 rgb  )  [inline]
 

same as setRGBPack16, but with the parameter cpsABGR specified.

Introduced to make life easier to win32 users and less confusing.

virtual void VCF::Color::setFromString const String val  )  [inline, virtual]
 

provides a simple to initialize the object from a string.

Reimplemented from VCF::Object.

void VCF::Color::setGreen const double &  green  )  [inline]
 

void VCF::Color::setHSL const double &  h,
const double &  l,
const double &  s
[inline]
 

void VCF::Color::setHSV const double &  h,
const double &  s,
const double &  v
[inline]
 

void VCF::Color::setLab  )  [inline]
 

void VCF::Color::setLuminosity const int &  luminosity  )  [inline]
 

set the luminosity of a color.

Parameters:
const int& luminosity, the desired luminosity expressed in a [0, ColorSpace::HSLMax] scale.

void VCF::Color::setRed const double &  red  )  [inline]
 

void VCF::Color::setRGB const double &  r,
const double &  g,
const double &  b
[inline]
 

sets the color starting from the known color components.

void VCF::Color::setRGB16 const uint16 r,
const uint16 g,
const uint16 b
[inline]
 

void VCF::Color::setRGB8 const uint8 r,
const uint8 g,
const uint8 b
[inline]
 

void VCF::Color::setRGBA const double &  r,
const double &  g,
const double &  b,
const double &  a
[inline]
 

void VCF::Color::setRGBA16 const uint16 r,
const uint16 g,
const uint16 b,
const uint16 a
[inline]
 

void VCF::Color::setRGBA8 const uint8 r,
const uint8 g,
const uint8 b,
const uint8 a
[inline]
 

Color & VCF::Color::setRGBPack16 const uint64 rgb,
const ColorPackScheme cps = cpsRGB
[inline]
 

sets the color starting from the known color components that have been packed into a single uint64 integer (4 x 16bits).

Color & VCF::Color::setRGBPack8 const uint32 rgb,
const ColorPackScheme cps = cpsRGB
[inline]
 

sets the color starting from the known color components that have been packed into a single uint32 integer (4 x 8bits).

void VCF::Color::setYUV  )  [inline]
 

String VCF::Color::toHexCode16 const ColorPackScheme cps = cpsRGB,
const ColorType ct = ctRGB
 

String VCF::Color::toHexCode8 const ColorPackScheme cps = cpsRGB,
const ColorType ct = ctRGB
 

generates a String with the internal representation of the color in hexadecimal format with 8bits per component.

Parameters:
const ColorPackScheme& cps. With a value of cpsABGR we use an inverted scheme, as it is in the Intel architecture. The default is not inverted. Example: the scheme 0x00RRGGBB would appear as BBGGRR00 with Intel architecture.
const ColorType& ct. The color space used to extract the components. The default is ctRGB, the RGB color space.

virtual String VCF::Color::toString  )  const [inline, virtual]
 

overrides the Object's base class member function.

gives a string representation of the color in a simple format.

Reimplemented from VCF::Object.


Friends And Related Function Documentation

friend class ColorSpace [friend]
 


The documentation for this class was generated from the following file:
   Comments or Suggestions?    License Information