Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site













SourceForge.net Logo

Color

 

class Color : private AssignValueTypeNo<Color, COLOR_V, Moveable<Color> > 

Color type representing RGB color. All components are in the range 0 through 255. Null value is defined for Color. Color is Value compatible as a Rich-Value type (supports Value comparison, serialization etc.).

 

 

Constructor Detail

 

Color()

Default constructor. Leaves component values uninitialized.

 


 

Color(int r, int g, int b)

Constructor.

r

Red channel.

g

Green channel.

b

Blue channel.

 


 

Color(const Nuller&)

Null constructor.

 


 

Color(const Value& q)

Conversion from Value.

q

Value.

 


 

Color(Color (*fn)())

This constructor allows using a pointer to a function returning Colors instead of Colors in many places. Global functions returning Color are needed instead of global Color constants on many platforms, because often global variables are not allowed when using dynamic libraries.

fn

Pointer to a function returning Color.

 


 

Color(RGBA rgba)

Conversion from a RGBA structure rgba.

 


 

Color(int n, int)

Constructs a Color from an integer representation of that colors RGB code.

 

 

Public Member List

 

operator Value() const

Conversion to Value.

Return value

Value.

 


 

dword GetRaw() const

Return value

Platform specific dword representing the color.

 


 

int GetR() const

Return value

The red component.

 


 

int GetG() const

Return value

The green component.

 


 

int GetB() const

Return value

The blue component.

 


 

void SetNull()

Sets the Color to Null.

 


 

bool IsNullInstance() const

Return value

True if Color is Null. Used to implement IsNull for Color.

 


 

unsigned GetHashValue() const

Return value

Hash-value for Color.

 


 

bool operator==(Color cconst

c

Color to compare with.

Return value

True if Color is equal to c.

 


 

bool operator!=(Color cconst

c

Color to compare with.

Return value

True if Color is not equal to c.

 


 

void Serialize(Stream& s)

Serializes the color to the Stream s.

 


 

static Color FromRaw(dword co)

Creates a Color based on a platform specific raw dword value.

co

Raw dword value.

Return value

Color.

 


 

operator COLORREF() const

Win32 specific.

Return COLORREF for Color.

Return value

COLORREF.

 


 

static Color FromCR(COLORREF cr)

Win32 specific.

Creates Color from COLORREF.

cr

COLORREF.

Return value

Color.

 


 

operator dword() const

Not available on Win32

Return value

GetRaw().

 


 

operator RGBA() const

Returns a RGBA structure containing the color information.

 

 

 

 

Utility functions

 

int GetRValue(dword c)

Returns red component from a platform specific value.

c

Platform specific value.

Return value

Red component.

 


 

int GetGValue(dword c)

Returns green component from a platform specific value.

c

Platform specific value.

Return value

Green component.

 


 

int GetBValue(dword c)

Returns blue component from a platform specific value.

c

Platform specific value.

Return value

Blue component.

 


 

dword RGB(byte r, byte g, byte b)

Calculates platform specific value from components.

r

Red component.

g

Green component.

b

Blue component.

Return value

Platform specific value.

 


 

unsigned GetHashValue(Color c)

Returns a hash value for the color.

c

Color.

Return value

Hash value.

 


 

Color Nvl(Color a, Color b)

Returns first parameter if it is not Null, second otherwise.

a

Color.

b

Color.

Return value

a if not Null, b otherwise.

 


 

template <> String AsString(const Color& c)

Converts Color to textual form.

c

Color.

Return value

Textual form.

 


 

void RGBtoHSV(double r, double g, double b, double& h, double& s, double& v)

Transforms an [R,G,B] color triplet (each of the components is supposed to be in the range [0..1]) into an [H,S,V] triplet (again all components are in the range [0..1]). This effectively transforms the RGB cube to a cone in which color selection more intuitively matches our our visual perception (hue corresponds to the tint of the color, saturation to the richness of the color hue and value corresponds to luminance or brightness).

 

The mathematical formula used to convert between the two color spaces are:

 

v = max(r, g, b)

s = 1 - min(r, g, b) / v

h = (x - min(r, g, b)) / (max(r, g, b) - min(r, g, b))

 

where x is the color component which is neither minimum nor maximum. There are six combinations for this, in every even h is taken, in every odd 1-h. The six combinations correspond to six points on the color wheel forming the base of the HSV cone - pure red, yellow, green, cyan, blue, and magenta. The color component ranges along the circumference are the following (capital letters denote maximum component value, minuscule letters minimum): Rgb -> RGb -> rGb -> rGB -> rgB -> RgB.

 

An easy way to visualize the HSV transform based on the RGB cube is: imagine a slight deformation of the cube where the tip of the cone corresponds to the black RBG cube vertex, the opposite (white) RGB cube vertex corresponds to the center of the base circle of the HSV cone and the remaining six RGB cube vertices get projected on the circumference of the cone base as explained in the preceding paragraph.

 

r

input red component [0..1]

g

input green component [0..1]

b

input blue component [0..1]

h

output hue [0..1], i.e. color tint

s

output saturation [0..1]. Maximum saturation (1) corresponds to the "purest" basic color (one of the six), whereas minimum saturation (0) is gray or white.

v

output brightness [0..1].

 


 

void HSVtoRGB(double h, double s, double v, double& r, double& g, double& b)

Transformes an HSV triplet (each of the components is supposed to lie in the interval [0..1]) into an RGB triplet (again with component ranges [0..1]). This projects the HSV cone (as explained in the preceding section) back onto the RGB cube.

h

input hue, i.e. color tint [0..1]

s

input saturation, i.e. color "purity" [0..1]

v

value - luminance or brightness [0..1]

r

output red component [0..1]

g

output green component [0..1]

b

output blue component [0..1]

 


 

Color HsvColorf(double h, double s, double v)

Converts an HSV color triplet into a Color object. The H, S, and V components are supposed to be in the range [0..1].

h

input hue [0..1]

s

input saturation [0..1]

v

input value aka brightness [0..1]

Return value

the Color object with the given HSV components

 


 

Color Blend(Color c1, Color c2, int alpha = 128)

Blends two colors.

c1

First color.

c2

Second color.

alpha

Blending factor in the range 0..255.

Return value

Blended color - (255 - alpha) / 255.0 * c1 + alpha / 255.0 * c2.

 


 

String ColorToHtml(Color color)

Converts Color to the textual format used in HTML (into hexadecimal form like #ffffff for white).

color

Color.

Return value

HTML text.

 


 

Color GrayColor(int a = 128)

Returns a gray color of intensity a.

 


 

int Grayscale(const Color& c)

Converts a color c to grayscale.

 


 

bool IsDark(Color c)

True if c grayscale level is lower than 80.

 


 

bool IsLight(Color c)

True if c grayscale is higher than 175 (255 - 80).

 


 

Color StraightColor(RGBA rgba)

Converts a RGBA structure rgba to a Color.

 

 

Color constants

 

Predefined colors are represented by functions that return the predefined color value.

 

 

Color Black()

Black.

 


 

Color Gray()

Gray.

 


 

Color LtGray()

Light gray.

 


 

Color WhiteGray()

White gray.

 


 

Color White()

White.

 


 

Color Red()

Red.

 


 

Color Green()

Green.

 


 

Color Brown()

Brown.

 


 

Color Blue()

Blue.

 


 

Color Magenta()

Magenta.

 


 

Color Cyan()

Cyan.

 


 

Color Yellow()

Yellow.

 


 

Color LtRed()

Light red.

 


 

Color LtGreen()

Light green.

 


 

Color LtYellow()

Light yellow.

 


 

Color LtBlue()

Light blue.

 


 

Color LtMagenta()

Light magenta.

 


 

Color LtCyan()

Light cyan.

 

 

Last edit by cxl on 06/20/2015. Do you want to contribute?. T++