CoreComponents 3.0.0
A Modern C++ Toolkit
Loading...
Searching...
No Matches
Color Class Reference

ARGB color tuple (32 bit) More...

#include <cc/Color>

Public Member Functions

 Color ()
 Create an invalid color.
 
 Color (uint32_t w)
 Create a color from word w.
 
 Color (int w)
 
 Color (const char *s)
 
 Color (const String &s)
 Construct a color from color literal or name s.
 
template<class T >
 Color (T r, T g, T b, T a=0xFF)
 Compose a color from its components.
 
Color operator() (int percent) const
 Create a semi-transparent version of this color with percent opacity.
 
 operator bool () const
 Check if valid.
 
bool isValid () const
 Check if valid.
 
bool isOpaque () const
 Check if this color is fully opaque.
 
uint32_t alpha () const
 Return the alpha color component
 
uint32_t red () const
 Return the red color component
 
uint32_t green () const
 Return the green color component
 
uint32_t blue () const
 Return the blue color component
 
void applyOver (Color b)
 Alpha-blend color b over this color.
 
Color on (Color b) const
 Alpha-blend this color over b and return the result.
 
void mixIn (Color b, int percent)
 Mix color b into this color by percent.
 
Color mixedWith (Color b, int percent) const
 Return this color mixed with b by percent
 
Color lighter (int percent) const
 Return a lighter version of this color
 
Color darker (int percent) const
 Return a darker version of this color
 
Color premultiplied () const
 Translate from non-premultiplied to premultiplied representation.
 
Color normalized () const
 Translate from premultiplied to non-premultiplied representation.
 
void premultiply ()
 Translate from non-premultiplied to premultiplied representation.
 
void normalize ()
 Translate from premultiplied to non-premultiplied representation.
 
uint32_t value () const
 Convert to an unsigned 32-bit word.
 
uint32_tvalue ()
 Access underlying unsigned 32-bit word.
 
 operator uint32_t () const
 Access underlying unsigned 32-bit word.
 
String toString () const
 Stringify this color value.
 

Static Public Member Functions

static Color fromHue (double h)
 Get the full color of hue h.
 
static Color fromHsv (double h, double s, double v)
 Get color from a HSV tuple.
 
static Color fromHsl (double h, double s, double l)
 Get color from HSL tuple.
 
static Color blend (Color a, Color b)
 Alpha-blend color a over color b.
 

Static Public Attributes

static const Color Transparent { 0x00, 0x00, 0x00, 0x00 }
 Transparent color constant.
 
static const Color Black { 0x00, 0x00, 0x00 }
 Black color constant.
 
static const Color White { 0xFF, 0xFF, 0xFF }
 White color constant.
 
static const Color Red { 0xFF, 0x00, 0x00 }
 Red color constant.
 
static const Color Green { 0x00, 0xFF, 0x00 }
 Green color constant.
 
static const Color Blue { 0x00, 0x00, 0xFF }
 Blue color constant.
 
static constexpr int AlphaShift = 24
 Bit position of the alpha component within the 32 bit color word.
 
static constexpr int RedShift = 16
 Bit position of the red component within the 32 bit color word.
 
static constexpr int GreenShift = 8
 Bit position of the green component within the 32 bit color word.
 
static constexpr int BlueShift = 0
 Bit position of the blue component within the 32 bit color word.
 
static constexpr uint32_t RedMask = uint32_t(0xFF) << RedShift
 Bitmask for the red component of the 32 bit color word.
 
static constexpr uint32_t GreenMask = uint32_t(0xFF) << GreenShift
 Bitmask for the green component of the 32 bit color word.
 
static constexpr uint32_t BlueMask = uint32_t(0xFF) << BlueShift
 Bitmask for the blue component of the 32 bit color word.
 
static constexpr uint32_t AlphaMask = uint32_t(0xFF) << AlphaShift
 Bitmask for the alpha component of the 32 bit color word.
 

Detailed Description

ARGB color tuple (32 bit)

Constructor & Destructor Documentation

◆ Color() [1/4]

Color ( )

Create an invalid color.

◆ Color() [2/4]

Create a color from word w.

See also
RedMask, GreenMask, BlueMask, AlphaMask

◆ Color() [3/4]

Color ( const String & s)
explicit

Construct a color from color literal or name s.

Parameters
sColor specification to parse Color literals can be either SVG color names (e.g. 'AliceBlue') or literal RGB tuples (#RRGGBB, #RRGGBBAA, #RGB, #RGBA).

◆ Color() [4/4]

template<class T >
Color ( T r,
T g,
T b,
T a = 0xFF )

Compose a color from its components.

Parameters
rRed component (0..0xFF)
gGreen component (0..0xFF)
bBlue component (0..0xFF)
aOpacity component (0..0xFF)

Member Function Documentation

◆ fromHue()

static Color fromHue ( double h)
static

Get the full color of hue h.

Parameters
hHue in range [0, 360]

◆ fromHsv()

Color fromHsv ( double h,
double s,
double v )
static

Get color from a HSV tuple.

Parameters
hHue in range [0, 360]
sSaturation in range [0, 1]
vValue in range [0, 1]

◆ fromHsl()

Color fromHsl ( double h,
double s,
double l )
static

Get color from HSL tuple.

Parameters
hHue in range [0, 360]
sSaturation in range [0, 1]
lLuminance in range [0, 1]

◆ blend()

static Color blend ( Color a,
Color b )
static

Alpha-blend color a over color b.

◆ operator()()

Color operator() ( int percent) const

Create a semi-transparent version of this color with percent opacity.

◆ operator bool()

operator bool ( ) const
explicit

Check if valid.

A color is considered invalid, if alpha is zero and either red, green or blue is non-zero.

◆ isValid()

bool isValid ( ) const

Check if valid.

A color is considered invalid, if alpha is zero and either red, green or blue is non-zero.

◆ isOpaque()

bool isOpaque ( ) const

Check if this color is fully opaque.

◆ alpha()

uint32_t alpha ( ) const

Return the alpha color component

◆ red()

uint32_t red ( ) const

Return the red color component

◆ green()

uint32_t green ( ) const

Return the green color component

◆ blue()

uint32_t blue ( ) const

Return the blue color component

◆ applyOver()

void applyOver ( Color b)

Alpha-blend color b over this color.

◆ on()

Color on ( Color b) const

Alpha-blend this color over b and return the result.

◆ mixIn()

void mixIn ( Color b,
int percent )

Mix color b into this color by percent.

◆ mixedWith()

Color mixedWith ( Color b,
int percent ) const

Return this color mixed with b by percent

◆ lighter()

Color lighter ( int percent) const

Return a lighter version of this color

◆ darker()

Color darker ( int percent) const

Return a darker version of this color

◆ premultiplied()

Color premultiplied ( ) const

Translate from non-premultiplied to premultiplied representation.

◆ normalized()

Color normalized ( ) const

Translate from premultiplied to non-premultiplied representation.

◆ premultiply()

void premultiply ( )

Translate from non-premultiplied to premultiplied representation.

◆ normalize()

void normalize ( )

Translate from premultiplied to non-premultiplied representation.

◆ value() [1/2]

uint32_t value ( ) const

Convert to an unsigned 32-bit word.

◆ value() [2/2]

uint32_t & value ( )

Access underlying unsigned 32-bit word.

◆ operator uint32_t()

operator uint32_t ( ) const

Access underlying unsigned 32-bit word.

◆ toString()

String toString ( ) const

Stringify this color value.

Member Data Documentation

◆ Transparent

const Color Transparent { 0x00, 0x00, 0x00, 0x00 }
static

Transparent color constant.

◆ Black

const Color Black { 0x00, 0x00, 0x00 }
static

Black color constant.

◆ White

const Color White { 0xFF, 0xFF, 0xFF }
static

White color constant.

◆ Red

const Color Red { 0xFF, 0x00, 0x00 }
static

Red color constant.

◆ Green

const Color Green { 0x00, 0xFF, 0x00 }
static

Green color constant.

◆ Blue

const Color Blue { 0x00, 0x00, 0xFF }
static

Blue color constant.

◆ AlphaShift

constexpr int AlphaShift = 24
staticconstexpr

Bit position of the alpha component within the 32 bit color word.

◆ RedShift

constexpr int RedShift = 16
staticconstexpr

Bit position of the red component within the 32 bit color word.

◆ GreenShift

constexpr int GreenShift = 8
staticconstexpr

Bit position of the green component within the 32 bit color word.

◆ BlueShift

constexpr int BlueShift = 0
staticconstexpr

Bit position of the blue component within the 32 bit color word.

◆ RedMask

constexpr uint32_t RedMask = uint32_t(0xFF) << RedShift
staticconstexpr

Bitmask for the red component of the 32 bit color word.

◆ GreenMask

constexpr uint32_t GreenMask = uint32_t(0xFF) << GreenShift
staticconstexpr

Bitmask for the green component of the 32 bit color word.

◆ BlueMask

constexpr uint32_t BlueMask = uint32_t(0xFF) << BlueShift
staticconstexpr

Bitmask for the blue component of the 32 bit color word.

◆ AlphaMask

constexpr uint32_t AlphaMask = uint32_t(0xFF) << AlphaShift
staticconstexpr

Bitmask for the alpha component of the 32 bit color word.