class Color : private AssignValueTypeNo<Color, COLOR_V, Moveable<Color> >
class Color : private AssignValueTypeNo<Color, COLOR_V, Moveable<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.).
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. |
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 c) const
|
Return value |
True if Color is equal to c. |
bool operator!=(Color c) const
|
Return value |
True if Color is equal to c. |
void Serialize(Stream& s)
Serialization.
Color()
Default constructor. Leaves component values uninitialized.
Color(int r, int g, int b)
Constructor.
Color(const Nuller&)
Null constructor.
operator Value() const
Conversion to Value.
Color(const Value& q)
Conversion from 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. |
static Color FromRaw(dword co)
Creates a Color based on a platform specific raw dword value.
operator COLORREF() const
Win32 specific.
Return COLORREF for Color.
static Color FromCR(COLORREF cr)
Win32 specific.
Creates Color from COLORREF.
operator dword() const
struct GrayColor
This simple utility class provides constructor that sets all components to the same value producing the gray color.
Derived from Color
GrayColor(int level)
Constructor.
Utility functions
int GetRValue(dword c)
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.
|
Return value |
Platform specific value. |
unsigned GetHashValue(Color c)
Returns a hash value for the color.
Color Nvl(Color a, Color b)
Returns first parameter if it is not Null, second otherwise.
|
Return value |
a if not Null, b otherwise. |
template <> String AsString(const Color& c)
template <> String AsString(const Color& c)
Converts Color to textual form.
|
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].
|
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.
|
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 constants
Predefined colors are represented by functions that return the predefined color value.
Color Black()
Color Gray()
Color LtGray()
Color WhiteGray()
Color White()
Color Red()
Color Green()
Color Brown()
Color Blue()
Color Magenta()
Color Cyan()
Color Yellow()
Color LtRed()
Color LtGreen()
Color LtYellow()
Color LtBlue()
Color LtMagenta()
Color LtCyan()
|