3es
0.7
|
A 32-bit integer colour class. More...
#include <3escolour.h>
Public Types | |
enum | Channels { A = 0, B = 1, G = 2, R = 3 } |
Channel index enumeration. More... | |
enum | Predefined { Gainsboro, LightGrey, Silver, DarkGrey, Grey, DimGrey, LightSlateGrey, SlateGrey, DarkSlateGrey, Black, White, Snow, Honeydew, MintCream, Azure, AliceBlue, GhostWhite, WhiteSmoke, Seashell, Beige, OldLace, FloralWhite, Ivory, AntiqueWhite, Linen, LavenderBlush, MistyRose, Pink, LightPink, HotPink, DeepPink, PaleVioletRed, MediumVioletRed, LightSalmon, Salmon, DarkSalmon, LightCoral, IndianRed, Crimson, FireBrick, DarkRed, Red, OrangeRed, Tomato, Coral, DarkOrange, Orange, Yellow, LightYellow, LemonChiffon, LightGoldenrodYellow, PapayaWhip, Moccasin, PeachPuff, PaleGoldenrod, Khaki, DarkKhaki, Gold, Cornsilk, BlanchedAlmond, Bisque, NavajoWhite, Wheat, BurlyWood, Tan, RosyBrown, SandyBrown, Goldenrod, DarkGoldenrod, Peru, Chocolate, SaddleBrown, Sienna, Brown, Maroon, DarkOliveGreen, Olive, OliveDrab, YellowGreen, LimeGreen, Lime, LawnGreen, Chartreuse, GreenYellow, SpringGreen, MediumSpringGreen, LightGreen, PaleGreen, DarkSeaGreen, MediumSeaGreen, SeaGreen, ForestGreen, Green, DarkGreen, MediumAquamarine, Aqua, Cyan, LightCyan, PaleTurquoise, Aquamarine, Turquoise, MediumTurquoise, DarkTurquoise, LightSeaGreen, CadetBlue, DarkCyan, Teal, LightSteelBlue, PowderBlue, LightBlue, SkyBlue, LightSkyBlue, DeepSkyBlue, DodgerBlue, CornflowerBlue, SteelBlue, RoyalBlue, Blue, MediumBlue, DarkBlue, Navy, MidnightBlue, Lavender, Thistle, Plum, Violet, Orchid, Fuchsia, Magenta, MediumOrchid, MediumPurple, BlueViolet, DarkViolet, DarkOrchid, DarkMagenta, Purple, Indigo, DarkSlateBlue, SlateBlue, MediumSlateBlue, PredefinedCount } |
Enumerates a set of predefined colours ("web safe" colours). | |
enum | ColourCycle { StandardCycle, DeuteranomalyCycle, ProtanomalyCycle, TritanomalyCycle, GreyCycle, CycleCount } |
Enumerates the various available colour cycles. More... | |
Public Member Functions | |
Colour (uint32_t c=0xffffffffu) | |
Construct a colour with the given numeric value. More... | |
Colour (const Colour &other) | |
Copy constructor. More... | |
Colour (const Colour &other, uint8_t a) | |
Partial copy constructor with new alpha value. More... | |
Colour (const Colour &other, int a) | |
Partial copy constructor with new alpha value. More... | |
Colour (const Colour &other, float a) | |
Partial copy constructor with new alpha value. More... | |
Colour (uint8_t r, uint8_t g, uint8_t b, uint8_t a=255u) | |
Explicit byte based RGBA colour channel initialisation constructor. More... | |
Colour (int r, int g, int b, int a=255) | |
Integer based RGBA colour channel initialisation constructor. More... | |
Colour (float r, float g, float b, float a=1.0f) | |
Floating point RGBA colour channel initialisation constructor. More... | |
float | rf () const |
Get red channel in floating point form. More... | |
float | gf () const |
Get green channel in floating point form. More... | |
float | bf () const |
Get blue channel in floating point form. More... | |
float | af () const |
Get alpha channel in floating point form. More... | |
void | setRf (float f) |
Set red channel from a floating point value. More... | |
void | setGf (float f) |
Set green channel from a floating point value. More... | |
void | setBf (float f) |
Set blue channel from a floating point value. More... | |
void | setAf (float f) |
Set alpha channel from a floating point value. More... | |
void | setf (float f, int index) |
Set a channel in floating point form. More... | |
float | getf (int index) const |
Get a channel in floating point form. More... | |
Colour | adjust (float factor) const |
Lighten or darken a colour by factor . More... | |
Colour | lighten () const |
Lighten the colour by 1.5. More... | |
Colour | darken () const |
Darken the colour by 0.5. More... | |
Colour & | operator= (const Colour &other) |
Assignment operator. More... | |
bool | operator== (const Colour &other) const |
Precise equality operator. More... | |
bool | operator!= (const Colour &other) const |
Precise inequality operator. More... | |
Static Public Member Functions | |
static void | rgbToHsv (float &h, float &s, float &v, const float r, const float g, const float b) |
Convert RGB to HSV form. More... | |
static void | hsvToRgb (float &r, float &g, float &b, const float h, const float s, const float v) |
Convert HSV to RGB form. More... | |
static void | hsvToRgb (uint8_t &r, uint8_t &g, uint8_t &b, const float h, const float s, const float v) |
Convert HSV to RGB form. More... | |
static const Colour & | cycle (unsigned number, ColourCycle cycle=StandardCycle) |
A utility function for colour cycling. More... | |
Public Attributes | |
union { | |
uint32_t c | |
Encoded colour value. | |
struct { | |
uint8_t a | |
Alpha channel. | |
uint8_t b | |
Blue channel. | |
uint8_t g | |
Green channel. | |
uint8_t r | |
Red channel. | |
} | |
uint8_t rgba [4] | |
Indexed channels. | |
}; | |
Static Public Attributes | |
static const Colour | Colours [PredefinedCount] |
The set of colours matching the Predefined enumeration. | |
static const int * | ColourCycles [CycleCount] |
A set of colours which can be cycled to highlight components. More... | |
static const int | CycleCounts [CycleCount] |
Number of colours in each ColourCycles entry. | |
A 32-bit integer colour class.
Storage is designed to allow colours to be written as unsigned hexadecimal integers as 0xRRGGBBAA regardless of the target Endian.
Enumerates the various available colour cycles.
Note: the colours cycles include sets which attempt to cater for various forms of colour blindness. These are not rigorously constructed and may not be as well suited as they are intended. Feel free to offer suggested improvements to these colours sets.
colourCycle()
|
inline |
Construct a colour with the given numeric value.
c | The integer colour representation: 0xRRGGBBAA. |
|
inline |
Copy constructor.
other | The colour to copy. |
|
inline |
Partial copy constructor with new alpha value.
other | The colour to copy RGB channels from. |
a | The new alpha channel value. |
References a.
|
inline |
Partial copy constructor with new alpha value.
other | The colour to copy RGB channels from. |
a | The new alpha channel value. |
References a.
|
inline |
Partial copy constructor with new alpha value.
other | The colour to copy RGB channels from. |
a | The new alpha channel value. |
References setAf().
|
inlineexplicit |
Explicit byte based RGBA colour channel initialisation constructor.
r | Red channel value [0, 255]. |
g | Red channel value [0, 255]. |
b | Red channel value [0, 255]. |
a | Red channel value [0, 255]. |
|
inline |
Integer based RGBA colour channel initialisation constructor.
r | Red channel value [0, 255]. |
g | Red channel value [0, 255]. |
b | Red channel value [0, 255]. |
a | Red channel value [0, 255]. |
|
inline |
Colour tes::Colour::adjust | ( | float | factor | ) | const |
Lighten or darken a colour by factor
.
Works in HSV space, multiplying the V value by factor
and clamping the result [0, 1].
|
inline |
Get alpha channel in floating point form.
References getf().
Referenced by tes::toVector().
|
inline |
Get blue channel in floating point form.
References getf().
Referenced by tes::toVector().
|
static |
A utility function for colour cycling.
This function returns a colour from the ColourCycle
, resolved to its actual Colours
element. The intended use is to periodically call this function with a monotonic, increasing number
value. This is then correctly clamped to the ColourCycle
range.
number | Any numeric value. It is clamped and wrapped to be in range (using modulus). |
cycle | The colour cycle to request a colour from. |
|
inline |
Darken the colour by 0.5.
|
inline |
|
inline |
Get green channel in floating point form.
References getf().
Referenced by tes::toVector().
|
static |
Convert HSV to RGB form.
[out] | r | Red channel [0, 1]. |
[out] | g | Green channel [0, 1]. |
[out] | b | Blue channel [0, 1]. |
h | The hue value [0, 360]. | |
s | The saturation value [0, 1]. | |
v | The colour value [0, 1]. |
|
static |
Convert HSV to RGB form.
[out] | r | Red channel [0, 255]. |
[out] | g | Green channel [0, 255]. |
[out] | b | Blue channel [0, 255]. |
h | The hue value [0, 360]. | |
s | The saturation value [0, 1]. | |
v | The colour value [0, 1]. |
|
inline |
Lighten the colour by 1.5.
|
inline |
Precise inequality operator.
other | The colour to compare to. |
other
. References c.
|
inline |
Precise equality operator.
other | The colour to compare to. |
other
. References c.
|
inline |
Get red channel in floating point form.
References getf().
Referenced by tes::toVector().
|
static |
Convert RGB to HSV form.
[out] | h | The hue value [0, 360]. |
[out] | s | The saturation value [0, 1]. |
[out] | v | The colour value [0, 1]. |
r | Red channel. | |
g | Green channel. | |
b | Blue channel. |
|
inline |
Set alpha channel from a floating point value.
f | Channel value [0, 1]. |
References setf().
Referenced by Colour(), and tes::toColour().
|
inline |
Set blue channel from a floating point value.
f | Channel value [0, 1]. |
References setf().
Referenced by Colour(), and tes::toColour().
|
inline |
|
inline |
Set green channel from a floating point value.
f | Channel value [0, 1]. |
References setf().
Referenced by Colour(), and tes::toColour().
|
inline |
Set red channel from a floating point value.
f | Channel value [0, 1]. |
References setf().
Referenced by Colour(), and tes::toColour().
|
static |
A set of colours which can be cycled to highlight components.
The colour set is initialised to try and provide sufficient contrast between each colour. Each element should be indexed into Colours
.