CRgbaColor Class Reference
[GUI Utility Classes and Modules]

Search Toolkit Book for CRgbaColor

#include <rgba_color.hpp>

List of all members.


Detailed Description

class CRgbaColor provides a simple abstraction for managing colors.

Definition at line 51 of file rgba_color.hpp.

Public Member Functions

 CRgbaColor ()
 default ctor
 CRgbaColor (const float *color, size_t size)
 construct around a given float array
 CRgbaColor (float r, float g, float b)
 construct with explicit (floating point) RGB values
 CRgbaColor (float r, float g, float b, float a)
 construct with explicit (floating point) RGB+alpha values
 CRgbaColor (unsigned char r, unsigned char g, unsigned char b)
 construct with explicit (unsigned char) RGB values.
 CRgbaColor (unsigned char r, unsigned char g, unsigned char b, unsigned char a)
 construct with explicit (unsigned char) RGB+alpha values.
 CRgbaColor (int r, int g, int b)
 construct with explicit (int) RGB values.
 CRgbaColor (int r, int g, int b, int a)
 construct with explicit (int) RGB+alpha values.
 CRgbaColor (const string &s)
 construct from a string encoded in the form "r g b"
virtual ~CRgbaColor ()
 virtual dtor
void Set (float r, float g, float b)
 set the values from explicit (floating point) RGB values
void Set (float r, float g, float b, float a)
 set the values from explicit (floating point) RGB+alpha values
void Set (unsigned char r, unsigned char g, unsigned char b)
 set the values from explicit (unsigned char) RGB values.
void Set (unsigned char r, unsigned char g, unsigned char b, unsigned char a)
 set the values from explicit (unsigned char) RGB+alpha values.
void SetRed (float r)
 Set specific channels from floating point values.
void SetGreen (float r)
void SetBlue (float r)
void SetAlpha (float r)
void SetRed (unsigned char r)
 Set specific channels from floating unsigned char values.
void SetGreen (unsigned char r)
void SetBlue (unsigned char r)
void SetAlpha (unsigned char r)
float GetRed (void) const
 Get specific channels in floating point values.
float GetGreen (void) const
float GetBlue (void) const
float GetAlpha (void) const
unsigned char GetRedUC (void) const
 Get specific channels in unsigned char values.
unsigned char GetGreenUC (void) const
unsigned char GetBlueUC (void) const
unsigned char GetAlphaUC (void) const
const float * GetColorArray (void) const
 Access the color array directly.
virtual void PrintTo (CNcbiOstream &strm) const
 print the color to a stream in the form "r g b"
virtual void PrintTo (CNcbiOstream &strm, bool printAlpha, bool uchars=true) const
virtual string ToString (bool printAlpha=true, bool uchars=true) const
 Return a string representation of the current color.
virtual void FromString (const string &str)
 Assign color values encoded in a string.
CRgbaColoroperator+= (const CRgbaColor &c1)
CRgbaColoroperator *= (float f)
void Lighten (float scale)
void Darken (float scale)
CRgbaColor ContrastingColor (bool onlyBW=true) const
 Return a color guaranteed to contrast nicely with this color.

Static Public Member Functions

static const char * ColorStrFromName (const string &desc)
 return a mapped color string from a named color
static CRgbaColor GetColor (const string &color_type)
 return a color based on a string.
static CRgbaColor Interpolate (const CRgbaColor &color1, const CRgbaColor &color2, float alpha)
 Interpolate two colors.
static CRgbaColor Invert (const CRgbaColor &color1)
 returns XOR complementary color, alpha is not affected
static CRgbaColor RotateColor (const CRgbaColor &c, float degrees)
 Rotate the hue of the color by degrees.
static float Brightness (const CRgbaColor &rgb)
 return the brightness or luminance of the color.
static float ColorDistance (const CRgbaColor &c1, const CRgbaColor &c2)
 returns the distance in the RGB color cube between the two colors, scaled to a range [0, 1].
Color space conversion functions.
static void RgbToHsv (const CRgbaColor &rgb, float &h, float &s, float &v)
 convert RGB to HSV.
static CRgbaColor HsvToRgb (float h, float s, float v)
static void RgbToYuv (const CRgbaColor &rgb, float &y, float &u, float &v)
 convert RGB to YUV.
static bool YuvToRgb (float y, float u, float v, CRgbaColor &rgb)
 Not all possible input values of y, u and v will make a valid RGB color.

Private Member Functions

void x_Clamp ()

Private Attributes

float m_Rgba [4]


Constructor & Destructor Documentation

CRgbaColor::CRgbaColor  ) 
 

default ctor

Definition at line 134 of file rgba_color.cpp.

References m_Rgba.

Referenced by ContrastingColor(), GetColor(), HsvToRgb(), and YuvToRgb().

CRgbaColor::CRgbaColor const float *  color,
size_t  size
 

construct around a given float array

Definition at line 147 of file rgba_color.cpp.

References f(), and m_Rgba.

CRgbaColor::CRgbaColor float  r,
float  g,
float  b
 

construct with explicit (floating point) RGB values

Definition at line 156 of file rgba_color.cpp.

References m_Rgba, and x_Clamp().

CRgbaColor::CRgbaColor float  r,
float  g,
float  b,
float  a
 

construct with explicit (floating point) RGB+alpha values

Definition at line 166 of file rgba_color.cpp.

References m_Rgba, and x_Clamp().

CRgbaColor::CRgbaColor unsigned char  r,
unsigned char  g,
unsigned char  b
 

construct with explicit (unsigned char) RGB values.

These are normalized to 0-1 internally.

Definition at line 201 of file rgba_color.cpp.

References m_Rgba.

CRgbaColor::CRgbaColor unsigned char  r,
unsigned char  g,
unsigned char  b,
unsigned char  a
 

construct with explicit (unsigned char) RGB+alpha values.

These are normalized from 0-1 internally.

Definition at line 210 of file rgba_color.cpp.

References m_Rgba.

CRgbaColor::CRgbaColor int  r,
int  g,
int  b
 

construct with explicit (int) RGB values.

These are normalized to 0-1 internally. The values should be in the rane of 0-255.

Definition at line 176 of file rgba_color.cpp.

References _ASSERT, and m_Rgba.

CRgbaColor::CRgbaColor int  r,
int  g,
int  b,
int  a
 

construct with explicit (int) RGB+alpha values.

These are normalized from 0-1 internally. The values should be in the rane of 0-255.

Definition at line 188 of file rgba_color.cpp.

References _ASSERT, and m_Rgba.

CRgbaColor::CRgbaColor const string &  s  )  [explicit]
 

construct from a string encoded in the form "r g b"

Definition at line 141 of file rgba_color.cpp.

References FromString().

CRgbaColor::~CRgbaColor  )  [virtual]
 

virtual dtor

Definition at line 220 of file rgba_color.cpp.


Member Function Documentation

float CRgbaColor::Brightness const CRgbaColor rgb  )  [static]
 

return the brightness or luminance of the color.

Same as Y in RgbToYuv

See also:
RgbToYuv

Definition at line 1394 of file rgba_color.cpp.

References GetBlue(), GetGreen(), and GetRed().

Referenced by ContrastingColor(), operator<(), and RgbToYuv().

float CRgbaColor::ColorDistance const CRgbaColor c1,
const CRgbaColor c2
[static]
 

returns the distance in the RGB color cube between the two colors, scaled to a range [0, 1].

Definition at line 1418 of file rgba_color.cpp.

References f(), GetBlue(), GetGreen(), and GetRed().

const char * CRgbaColor::ColorStrFromName const string &  desc  )  [static]
 

return a mapped color string from a named color

Definition at line 1291 of file rgba_color.cpp.

Referenced by FromString().

CRgbaColor CRgbaColor::ContrastingColor bool  onlyBW = true  )  const
 

Return a color guaranteed to contrast nicely with this color.

Parameters:
onlyBW true - only return black or white, otherwise pick from all colors.
Returns:
A color that will show up well against this color.

Definition at line 1427 of file rgba_color.cpp.

References Brightness(), CRgbaColor(), f(), HsvToRgb(), and RgbToHsv().

Referenced by CRnaCdsGroup::x_DrawFeatureBar().

void CRgbaColor::Darken float  scale  ) 
 

Definition at line 513 of file rgba_color.cpp.

References _ASSERT, f(), and m_Rgba.

Referenced by CRnaCdsGroup::x_DrawFeatureBar(), and CAlnMultiHeader::x_RenderBox().

void CRgbaColor::FromString const string &  str  )  [virtual]
 

Assign color values encoded in a string.

This function is responsible for all string-based processing; all other string-based interfaces funnel through this. The formats accepted include, in order of parsing:

1. A named color, such as "red", "blue", "green", "salmon", etc. There are approximately 750 named colors that are currently understood.

2. HTML-format colors, such as "#f0f0dd", or "f0f0dd". These are accepted with or without the leading '#'.

3. Bracketed or non-bracketed triplets or quadruplets of integers, in any of the formats below (mix and match spaces or commas as separators, with or without '[]' or '()'):

123 123 123 123, 123, 123 [123 123 123] (123, 123, 123) (123 123 123) [123, 123, 123]

Definition at line 400 of file rgba_color.cpp.

References ColorStrFromName().

Referenced by CRgbaColor().

float CRgbaColor::GetAlpha void   )  const
 

Definition at line 334 of file rgba_color.cpp.

References m_Rgba.

Referenced by CRgbaGradColorTable::FillGradient(), operator *(), operator+(), operator==(), CGraphPanel::PrepareContext(), CHitMatrixRenderer::Render(), CGlBackground::SetDarkColor(), ToString(), CSeqTextPane::x_Render(), and CAlnMultiRenderer::x_Render().

unsigned char CRgbaColor::GetAlphaUC void   )  const
 

Definition at line 358 of file rgba_color.cpp.

References m_Rgba.

Referenced by ConvertColor(), ToString(), and CColorPickerValidator::TransferToWindow().

float CRgbaColor::GetBlue void   )  const
 

Definition at line 328 of file rgba_color.cpp.

References m_Rgba.

Referenced by Brightness(), ColorDistance(), CRgbaGradColorTable::FillGradient(), operator *(), operator+(), operator<(), operator==(), CGraphPanel::PrepareContext(), CHitMatrixRenderer::Render(), RgbToHsv(), RgbToYuv(), CGlBackground::SetDarkColor(), ToString(), CSeqGraphicRenderer::x_Draw(), CSeqTextPane::x_Render(), CAlnMultiRenderer::x_Render(), CHitMatrixGraph::x_RenderHits(), CAlnMultiRenderer::x_RenderMasterRow(), and CHitMatrixGraph::x_RenderPath().

unsigned char CRgbaColor::GetBlueUC void   )  const
 

Definition at line 352 of file rgba_color.cpp.

References m_Rgba.

Referenced by ConvertColor(), ToString(), and CColorPickerValidator::TransferToWindow().

CRgbaColor CRgbaColor::GetColor const string &  color_type  )  [static]
 

return a color based on a string.

This function will understand two forms of color type:

  • color names - things like 'red', 'powder blue', etc.
  • color triplets or quads - RGB(A) values encoded as '128 128 128' tokens include ' ,[', so all of the following are valid: 128 128 128 [128 128 128] 128, 128, 128 [128, 128, 128]

Definition at line 1286 of file rgba_color.cpp.

References CRgbaColor().

Referenced by CPVecPolygon::CPVecPolygon(), CColorTableMethod::Load(), s_CreateDefaultColorTable(), and CTemplateScoringMethod::x_GetColor().

const float * CRgbaColor::GetColorArray void   )  const
 

Access the color array directly.

Definition at line 479 of file rgba_color.cpp.

References m_Rgba.

Referenced by CGlLight::Apply(), CGlMaterial::Apply(), CGlBackground::Draw(), and IPhyloTreeRenderer::x_RenderNode().

float CRgbaColor::GetGreen void   )  const
 

Definition at line 322 of file rgba_color.cpp.

References m_Rgba.

Referenced by Brightness(), ColorDistance(), CRgbaGradColorTable::FillGradient(), operator *(), operator+(), operator==(), CGraphPanel::PrepareContext(), CHitMatrixRenderer::Render(), RgbToHsv(), CGlBackground::SetDarkColor(), ToString(), CSeqGraphicRenderer::x_Draw(), CSeqTextPane::x_Render(), CAlnMultiRenderer::x_Render(), CHitMatrixGraph::x_RenderHits(), CAlnMultiRenderer::x_RenderMasterRow(), and CHitMatrixGraph::x_RenderPath().

unsigned char CRgbaColor::GetGreenUC void   )  const
 

Definition at line 346 of file rgba_color.cpp.

References m_Rgba.

Referenced by ConvertColor(), ToString(), and CColorPickerValidator::TransferToWindow().

float CRgbaColor::GetRed void   )  const
 

Get specific channels in floating point values.

Definition at line 316 of file rgba_color.cpp.

References m_Rgba.

Referenced by Brightness(), ColorDistance(), CRgbaGradColorTable::FillGradient(), operator *(), operator+(), operator==(), CGraphPanel::PrepareContext(), CHitMatrixRenderer::Render(), RgbToHsv(), RgbToYuv(), CGlBackground::SetDarkColor(), ToString(), CSeqGraphicRenderer::x_Draw(), CSeqTextPane::x_Render(), CAlnMultiRenderer::x_Render(), CHitMatrixGraph::x_RenderHits(), CAlnMultiRenderer::x_RenderMasterRow(), and CHitMatrixGraph::x_RenderPath().

unsigned char CRgbaColor::GetRedUC void   )  const
 

Get specific channels in unsigned char values.

Definition at line 340 of file rgba_color.cpp.

References m_Rgba.

Referenced by ConvertColor(), ToString(), and CColorPickerValidator::TransferToWindow().

CRgbaColor CRgbaColor::HsvToRgb float  h,
float  s,
float  v
[static]
 

Definition at line 1332 of file rgba_color.cpp.

References CRgbaColor(), and f().

Referenced by ContrastingColor(), and RotateColor().

CRgbaColor CRgbaColor::Interpolate const CRgbaColor color1,
const CRgbaColor color2,
float  alpha
[static]
 

Interpolate two colors.

The resulting color returned is ( (color1 * alpha) + (color2 * (1 - alpha) )

Definition at line 485 of file rgba_color.cpp.

References _ASSERT, and f().

Referenced by CGradientPanel::OnPaint(), CGradientColorPanel::OnPaint(), CAlignSmearGlyph::x_Draw(), and CRnaCdsGroup::x_DrawFeatureBar().

CRgbaColor CRgbaColor::Invert const CRgbaColor color1  )  [static]
 

returns XOR complementary color, alpha is not affected

Definition at line 494 of file rgba_color.cpp.

References color, and f().

void CRgbaColor::Lighten float  scale  ) 
 

Definition at line 504 of file rgba_color.cpp.

References _ASSERT, f(), and m_Rgba.

Referenced by CRenderingContext::Draw3DFletch(), CRenderingContext::Draw3DTriangle(), CRenderingContext::DrawDisk(), CLDBlockGlyph::x_Draw(), CRnaCdsGroup::x_DrawFeatureBar(), CAlnMultiHeader::x_RenderBox(), and IPhyloTreeRenderer::x_RenderNode().

CRgbaColor & CRgbaColor::operator *= float  f  ) 
 

Definition at line 81 of file rgba_color.cpp.

References m_Rgba.

CRgbaColor & CRgbaColor::operator+= const CRgbaColor c1  ) 
 

Definition at line 60 of file rgba_color.cpp.

References m_Rgba, and x_Clamp().

void CRgbaColor::PrintTo CNcbiOstream strm,
bool  printAlpha,
bool  uchars = true
const [virtual]
 

Definition at line 370 of file rgba_color.cpp.

References ToString().

void CRgbaColor::PrintTo CNcbiOstream strm  )  const [virtual]
 

print the color to a stream in the form "r g b"

Definition at line 364 of file rgba_color.cpp.

void CRgbaColor::RgbToHsv const CRgbaColor rgb,
float &  h,
float &  s,
float &  v
[static]
 

convert RGB to HSV.

Parameters:
h Hue. range 0 - 360.
s Saturation. range 0 - 1.0
v Value. range 0 - 1.0

Definition at line 1302 of file rgba_color.cpp.

References GetBlue(), GetGreen(), and GetRed().

Referenced by ContrastingColor(), and RotateColor().

void CRgbaColor::RgbToYuv const CRgbaColor rgb,
float &  y,
float &  u,
float &  v
[static]
 

convert RGB to YUV.

Parameters:
y luminance or brightness. range [0, 1]
u difference between blue component and luminance. range [-.5, .5]
v difference between red component and luminance. range [-.5, .5]

Definition at line 1369 of file rgba_color.cpp.

References Brightness(), GetBlue(), and GetRed().

CRgbaColor CRgbaColor::RotateColor const CRgbaColor c,
float  degrees
[static]
 

Rotate the hue of the color by degrees.

Definition at line 1400 of file rgba_color.cpp.

References HsvToRgb(), and RgbToHsv().

Referenced by GetRandomColor().

void CRgbaColor::Set unsigned char  r,
unsigned char  g,
unsigned char  b,
unsigned char  a
 

set the values from explicit (unsigned char) RGB+alpha values.

These are normalized internally to the range 0-1.

Definition at line 254 of file rgba_color.cpp.

References m_Rgba.

void CRgbaColor::Set unsigned char  r,
unsigned char  g,
unsigned char  b
 

set the values from explicit (unsigned char) RGB values.

These are normalized internally to the range 0-1.

Definition at line 245 of file rgba_color.cpp.

References m_Rgba.

void CRgbaColor::Set float  r,
float  g,
float  b,
float  a
 

set the values from explicit (floating point) RGB+alpha values

Definition at line 235 of file rgba_color.cpp.

References m_Rgba, and x_Clamp().

void CRgbaColor::Set float  r,
float  g,
float  b
 

set the values from explicit (floating point) RGB values

Definition at line 225 of file rgba_color.cpp.

References m_Rgba, and x_Clamp().

Referenced by CGlMaterial::Init(), CGlLight::Init(), CColorPickerValidator::TransferFromWindow(), CPhyloTreeScheme::x_DefaultScheme(), CSimpleScoringMethod::x_Init(), and CQualityScoringMethod::x_Init().

void CRgbaColor::SetAlpha unsigned char  r  ) 
 

Definition at line 310 of file rgba_color.cpp.

References m_Rgba.

void CRgbaColor::SetAlpha float  r  ) 
 

Definition at line 303 of file rgba_color.cpp.

References clamp(), and m_Rgba.

Referenced by CGlBackground::SetDarkColor().

void CRgbaColor::SetBlue unsigned char  r  ) 
 

Definition at line 297 of file rgba_color.cpp.

References m_Rgba.

void CRgbaColor::SetBlue float  r  ) 
 

Definition at line 290 of file rgba_color.cpp.

References clamp(), and m_Rgba.

Referenced by CGlBackground::SetDarkColor().

void CRgbaColor::SetGreen unsigned char  r  ) 
 

Definition at line 284 of file rgba_color.cpp.

References m_Rgba.

void CRgbaColor::SetGreen float  r  ) 
 

Definition at line 277 of file rgba_color.cpp.

References clamp(), and m_Rgba.

Referenced by CGlBackground::SetDarkColor().

void CRgbaColor::SetRed unsigned char  r  ) 
 

Set specific channels from floating unsigned char values.

These are normalized internally to the range 0-1.

Definition at line 271 of file rgba_color.cpp.

References m_Rgba.

void CRgbaColor::SetRed float  r  ) 
 

Set specific channels from floating point values.

Definition at line 264 of file rgba_color.cpp.

References clamp(), and m_Rgba.

Referenced by CGlBackground::SetDarkColor().

string CRgbaColor::ToString bool  printAlpha = true,
bool  uchars = true
const [virtual]
 

Return a string representation of the current color.

Definition at line 377 of file rgba_color.cpp.

References GetAlpha(), GetAlphaUC(), GetBlue(), GetBlueUC(), GetGreen(), GetGreenUC(), GetRed(), and GetRedUC().

Referenced by PrintTo(), CColorTableMethod::Save(), and CTestSettings::SaveCurrentSettings().

void CRgbaColor::x_Clamp  )  [inline, private]
 

Definition at line 51 of file rgba_color.cpp.

References clamp(), and m_Rgba.

Referenced by CRgbaColor(), operator+=(), and Set().

bool CRgbaColor::YuvToRgb float  y,
float  u,
float  v,
CRgbaColor rgb
[static]
 

Not all possible input values of y, u and v will make a valid RGB color.

in that case the RGB values are clamped to [0, 1].

Returns:
false if clipping occurs. see http://developer.apple.com/quicktime/icefloe/dispatch027.html

Definition at line 1377 of file rgba_color.cpp.

References CRgbaColor(), and g().


Member Data Documentation

float CRgbaColor::m_Rgba[4] [private]
 

Definition at line 254 of file rgba_color.hpp.

Referenced by CRgbaColor(), Darken(), GetAlpha(), GetAlphaUC(), GetBlue(), GetBlueUC(), GetColorArray(), GetGreen(), GetGreenUC(), GetRed(), GetRedUC(), Lighten(), operator *=(), operator+=(), Set(), SetAlpha(), SetBlue(), SetGreen(), SetRed(), and x_Clamp().


The documentation for this class was generated from the following files:
Generated on Mon Dec 7 13:50:10 2009 for NCBI C++ ToolKit by  doxygen 1.4.6
Modified on Mon Dec 07 16:23:53 2009 by modify_doxy.py rev. 173732