qualpal 2.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 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.

The RGB class provides conversion between RGB and other color spaces including HSL, XYZ, and Lab. All RGB values are normalized to [0,1].

// Create RGB from normalized values
RGB red(1.0, 0.0, 0.0);
// Create from hex string
RGB blue("#0000ff");
// Convert to hex
std::string hex = red.hex(); // "#ff0000"
RGB color representation with values in [0,1] range.
Definition colors.h:84
std::string hex() const
Convert RGB to hexadecimal string.

Definition at line 83 of file colors.h.

Constructor & Destructor Documentation

◆ RGB() [1/7]

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/7]

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/7]

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/7]

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

Construct RGB from HSL color.

Parameters
hslHSL color to convert from

◆ RGB() [5/7]

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

Construct RGB from XYZ color.

Parameters
xyzXYZ color to convert from

◆ RGB() [6/7]

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

Construct RGB from Lab color.

Parameters
labLab color to convert from

◆ RGB() [7/7]

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 180 of file colors.h.

◆ g()

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

Get green component [0,1].

Definition at line 178 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 162 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 151 of file colors.h.

◆ r()

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

Get red component [0,1].

Definition at line 176 of file colors.h.


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