libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
Color Class Reference

General-purpose RGBA color. More...

#include <color.h>

Collaboration diagram for Color:

Public Member Functions

 Color ()=default
 Default constructor. Creates an invalid (all-zero) color.
 
 Color (uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
 Constructs a color from RGBA components.
 
bool isValid () const
 Returns true if this color was explicitly constructed.
 
uint8_t r () const
 Returns the red component.
 
uint8_t g () const
 Returns the green component.
 
uint8_t b () const
 Returns the blue component.
 
uint8_t a () const
 Returns the alpha component.
 
void setR (uint8_t val)
 Sets the red component.
 
void setG (uint8_t val)
 Sets the green component.
 
void setB (uint8_t val)
 Sets the blue component.
 
void setA (uint8_t val)
 Sets the alpha component.
 
String toHex (bool includeAlpha=false) const
 Converts this color to a hex string.
 
Color lerp (const Color &other, double t) const
 Linearly interpolates between this color and another.
 
Color inverted () const
 Returns the RGB-inverted color (255 - each channel).
 
double luminance () const
 Returns the perceptual luminance (0.0 to 1.0).
 
Color contrastingBW () const
 Returns black or white, whichever contrasts best.
 
Color complementary () const
 Returns the complementary color (hue rotated 180 degrees).
 
bool operator== (const Color &other) const
 Equality operator.
 
bool operator!= (const Color &other) const
 Inequality operator.
 

Static Public Member Functions

static Color fromHex (const String &hex)
 Creates a Color from a hex string.
 

Static Public Attributes

static const Color Black
 
static const Color White
 
static const Color Red
 
static const Color Green
 
static const Color Blue
 
static const Color Yellow
 
static const Color Cyan
 
static const Color Magenta
 
static const Color DarkGray
 
static const Color LightGray
 
static const Color Orange
 
static const Color Transparent
 
static const Color Ignored
 

Detailed Description

General-purpose RGBA color.

A simple value type storing red, green, blue, and alpha channels as uint8_t values. Provides named color constants, hex conversion, and linear interpolation.

Member Function Documentation

◆ complementary()

Color Color::complementary ( ) const

Returns the complementary color (hue rotated 180 degrees).

Converts to HSL, rotates hue by 180 degrees, and converts back. Saturation, lightness, and alpha are preserved.

◆ contrastingBW()

Color Color::contrastingBW ( ) const
inline

Returns black or white, whichever contrasts best.

Uses perceptual luminance to decide. Alpha is preserved.

◆ fromHex()

static Color Color::fromHex ( const String hex)
static

Creates a Color from a hex string.

Accepts "#RRGGBB" or "#RRGGBBAA" format.

Parameters
hexThe hex string.
Returns
The parsed Color, or an invalid Color on failure.

◆ inverted()

Color Color::inverted ( ) const
inline

Returns the RGB-inverted color (255 - each channel).

Alpha is preserved.

◆ lerp()

Color Color::lerp ( const Color other,
double  t 
) const

Linearly interpolates between this color and another.

Parameters
otherThe target color.
tThe interpolation factor (0.0 = this, 1.0 = other).
Returns
The interpolated color.

◆ luminance()

double Color::luminance ( ) const
inline

Returns the perceptual luminance (0.0 to 1.0).

Uses the Rec. 709 luminance coefficients.

◆ toHex()

String Color::toHex ( bool  includeAlpha = false) const

Converts this color to a hex string.

Parameters
includeAlphaIf true, includes the alpha channel.
Returns
The hex string in "#RRGGBB" or "#RRGGBBAA" format.

The documentation for this class was generated from the following file: