qualpal 3.3.0
Loading...
Searching...
No Matches
qualpal::colors::RGB Class Reference

RGB color representation with values in [0,1] range. More...

#include <colors.h>

Public Member Functions

 RGB ()
 Default constructor initializes RGB to black (0,0,0)
 
 RGB (const double r, const double g, const double b)
 Construct RGB from normalized values.
 
 RGB (const std::array< double, 3 > rgb)
 Construct RGB from array of normalized values.
 
 RGB (const std::string &hex)
 Construct RGB from hexadecimal color string.
 
 RGB (const char *hex)
 Construct RGB from hexadecimal color string literal.
 
 RGB (const HSL &hsl)
 Construct RGB from HSL color.
 
 RGB (const XYZ &xyz)
 Construct RGB from XYZ color.
 
 RGB (const Lab &lab)
 Construct RGB from Lab color.
 
 RGB (const LCHab &lch)
 Construct RGB from LCHab color.
 
bool operator== (const RGB &other) const
 Equality operator for RGB colors.
 
bool operator!= (const RGB &other) const
 Inequality operator for RGB colors.
 
std::string hex () const
 Convert RGB to hexadecimal string.
 
double r () const
 Get red component [0,1].
 
double g () const
 Get green component [0,1].
 
double b () const
 Get blue component [0,1].
 

Detailed Description

RGB color representation with values in [0,1] range.

Represents a color in the standard Red-Green-Blue (RGB) color space. All channel values are normalized to the range [0, 1].

Provides conversion constructors for HSL, XYZ, Lab, and LCHab color spaces. Also supports construction from hexadecimal color strings in "#RRGGBB" or "#RGB" format.

// Create RGB from normalized values
RGB red(1.0, 0.0, 0.0);
// Create from hex string (6-digit and 3-digit)
RGB blue("#0000ff");
RGB magenta("#f0f");
// Convert to hex
std::string hex = red.hex(); // "#ff0000"
RGB color representation with values in [0,1] range.
Definition colors.h:92
std::string hex() const
Convert RGB to hexadecimal string.
Exceptions
std::invalid_argumentif hex string format is invalid.
See also
HSL, XYZ, Lab, LCHab for conversions.

Definition at line 91 of file colors.h.

Constructor & Destructor Documentation

◆ RGB() [1/8]

qualpal::colors::RGB::RGB ( const double  r,
const double  g,
const double  b 
)

Construct RGB from normalized values.

Parameters
rRed component [0,1]
gGreen component [0,1]
bBlue component [0,1]

◆ RGB() [2/8]

qualpal::colors::RGB::RGB ( const std::array< double, 3 >  rgb)

Construct RGB from array of normalized values.

Parameters
rgbArray containing [r, g, b] values in [0,1]

◆ RGB() [3/8]

qualpal::colors::RGB::RGB ( const std::string &  hex)

Construct RGB from hexadecimal color string.

Parameters
hexHex color string in format "#RRGGBB" or "#RGB"
Exceptions
std::invalid_argumentif hex format is invalid
RGB red("#ff0000"); // 6-digit format
RGB blue("#00f"); // 3-digit format

◆ RGB() [4/8]

qualpal::colors::RGB::RGB ( const char *  hex)
inline

Construct RGB from hexadecimal color string literal.

Parameters
hexHex color string in format "#RRGGBB" or "#RGB"
Exceptions
std::invalid_argumentif hex format is invalid

Definition at line 135 of file colors.h.

◆ RGB() [5/8]

qualpal::colors::RGB::RGB ( const HSL hsl)

Construct RGB from HSL color.

Parameters
hslHSL color to convert from

◆ RGB() [6/8]

qualpal::colors::RGB::RGB ( const XYZ xyz)

Construct RGB from XYZ color.

Parameters
xyzXYZ color to convert from

◆ RGB() [7/8]

qualpal::colors::RGB::RGB ( const Lab lab)

Construct RGB from Lab color.

Parameters
labLab color to convert from

◆ RGB() [8/8]

qualpal::colors::RGB::RGB ( const LCHab lch)

Construct RGB from LCHab color.

Parameters
lchLCHab color to convert from

Member Function Documentation

◆ b()

double qualpal::colors::RGB::b ( ) const
inline

Get blue component [0,1].

Definition at line 196 of file colors.h.

◆ g()

double qualpal::colors::RGB::g ( ) const
inline

Get green component [0,1].

Definition at line 194 of file colors.h.

◆ hex()

std::string qualpal::colors::RGB::hex ( ) const

Convert RGB to hexadecimal string.

Returns
Hex color string in format "#rrggbb"
RGB red(1.0, 0.0, 0.0);
std::string hex = red.hex(); // "#ff0000"

◆ operator!=()

bool qualpal::colors::RGB::operator!= ( const RGB other) const
inline

Inequality operator for RGB colors.

Parameters
otherOther RGB color to compare with
Returns
true if RGB colors are not equal, false otherwise

Definition at line 178 of file colors.h.

◆ operator==()

bool qualpal::colors::RGB::operator== ( const RGB other) const
inline

Equality operator for RGB colors.

Parameters
otherOther RGB color to compare with
Returns
true if both RGB colors are equal, false otherwise

Definition at line 167 of file colors.h.

◆ r()

double qualpal::colors::RGB::r ( ) const
inline

Get red component [0,1].

Definition at line 192 of file colors.h.


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