NDEVR
API Documentation

Represents a color in the RGB space with optional alpha transparency. More...

Inheritance diagram for RGBColor:
[legend]
Collaboration diagram for RGBColor:
[legend]

Public Member Functions

constexpr RGBColor ()
 Default constructor.
 RGBColor (const ACIColor &)
 Constructs an RGBColor by converting from an ACIColor.
 RGBColor (const fltp04 r, const fltp04 g, const fltp04 b, const fltp04 a=1.0f)
 Constructor to initialize color using floating-point values for each channel.
 RGBColor (const fltp08 r, const fltp08 g, const fltp08 b, const fltp08 a=1.0f)
 Constructs an RGBColor from double-precision floating-point channel values.
 RGBColor (const HSBColor &)
 Constructs an RGBColor by converting from an HSBColor.
 RGBColor (const HSLColor &)
 Constructs an RGBColor by converting from an HSLColor.
 RGBColor (const LABColor &)
 Constructs an RGBColor by converting from a LABColor.
constexpr RGBColor (const RGBColor &color)
 Copy constructor.
constexpr RGBColor (const sint04 r, const sint04 g, const sint04 b, const sint04 a=255)
 Constructs an RGBColor from signed integer channel values, clamping each to [0, 255].
constexpr RGBColor (const uint01 r, const uint01 g, const uint01 b, const uint01 a=255)
 Constructor to initialize color using integer values for each channel.
 RGBColor (const Vector< 1, fltp04 > &color)
 Constructs an RGBColor from a 1-dimensional single-precision float vector (grayscale).
 RGBColor (const Vector< 1, fltp08 > &color)
 Constructs an RGBColor from a 1-dimensional double-precision float vector (grayscale).
template<class t_type>
 RGBColor (const Vector< 1, t_type > &color)
 Constructs an RGBColor from a 1-dimensional vector, using the value as a grayscale intensity.
 RGBColor (const Vector< 2, fltp04 > &color)
 Constructs an RGBColor from a 2-dimensional single-precision float vector (grayscale + alpha).
 RGBColor (const Vector< 2, fltp08 > &color)
 Constructs an RGBColor from a 2-dimensional double-precision float vector (grayscale + alpha).
template<class t_type>
 RGBColor (const Vector< 2, t_type > &color)
 Constructs an RGBColor from a 2-dimensional vector (grayscale + alpha).
 RGBColor (const Vector< 3, fltp04 > &color)
 Constructs an RGBColor from a 3-dimensional single-precision float vector (RGB in [0,1]).
 RGBColor (const Vector< 3, fltp08 > &color)
 Constructs an RGBColor from a 3-dimensional double-precision float vector (RGB in [0,1]).
template<class t_type>
 RGBColor (const Vector< 3, t_type > &color)
 Constructs an RGBColor from a 3-dimensional vector (RGB).
 RGBColor (const Vector< 4, fltp04 > &color)
 Constructs an RGBColor from a 4-dimensional single-precision float vector (RGBA in [0,1]).
 RGBColor (const Vector< 4, fltp08 > &color)
 Constructs an RGBColor from a 4-dimensional double-precision float vector (RGBA in [0,1]).
template<class t_type>
 RGBColor (const Vector< 4, t_type > &color)
 Constructs an RGBColor from a 4-dimensional vector (RGBA).
 RGBColor (const XYZColor &)
 Constructs an RGBColor by converting from an XYZColor.
 RGBColor (uint04 value)
 Constructs an RGBColor from a packed 32-bit unsigned integer.
RGBColor contrastingColor () const
 Returns a color that contrasts well with this color for readability.
uint04 convertTo24BitColor () const
 Packs this color into a 24-bit unsigned integer (RGB only, no alpha).
uint04 convertToABGR32BitColor () const
 Packs this color into a 32-bit unsigned integer in ABGR byte order.
uint04 convertToRGBA32BitColor () const
 Packs this color into a 32-bit unsigned integer in RGBA byte order.
Vector< 3, fltp04get3F () const
 Gets the RGB channels as a 3-dimensional float vector normalized to [0, 1].
Vector< 4, fltp04get4F () const
 Gets all RGBA channels as a 4-dimensional float vector normalized to [0, 1].
fltp04 getF (uint01 channel) const
 Gets a channel value as a normalized float in [0, 1].
String getHexARGB () const
 Gets the hex string representation of this color in ARGB format (e.g., "#FFFF0000").
String getHexRGB () const
 Gets the hex string representation of this color in RGB format (e.g., "#FF0000").
String getHexRGBA () const
 Gets the hex string representation of this color in RGBA format (e.g., "#FF0000FF").
TranslatedString getName () const
 Gets the closest known name for this color as a translated string.
bool isLight () const
 Determines whether this color is perceptually light.
fltp04 luminance () const
 Returns the luminance of the color.
RGBColor opaque () const
 Returns a copy of this color with alpha set to 255 (fully opaque).
size_t operator() () const
 Functor operator that returns the packed 32-bit RGBA representation, useful as a hash.
constexpr RGBColoroperator= (const RGBColor &color)
 Copy assignment operator.
void setF (uint01 channel, fltp04 value)
 Sets a channel value from a normalized float in [0, 1].
Public Member Functions inherited from Vector< 4, uint01 >
constexpr decltype(auto) as () const
 Returns the vector as a new time of vector.
constexpr uint01 dimensionalIndex () const
 Used with template arguments MAX or MIN, Gets the dimensional index for the value that is either max or min.
constexpr uint01 dimensionalValue () const
 Used with template arguments MAX or MIN, Gets the dimensional value for the value that is either max or min.
constexpr t_magnitude_type magnitude () const
 Vectors are commonly used to model forces such as wind, sea current, gravity, and electromagnetism.
constexpr uint01 magnitudeSquared () const
 Vectors are commonly used to model forces such as wind, sea current, gravity, and electromagnetism.
constexpr Vector< t_dims, t_norm_type > normalized (Vector< t_dims, t_norm_type > value_if_nan=Constant< Vector< t_dims, t_norm_type > >::Invalid) const
 Gets the normalized, or unit length representation of this vector.
constexpr operator uint01 & ()
 For Single dimensional objects, they may also be considered a scaler, thus allow implicit conversion from a vector to a scaler when the dimension of the vector is 1.
constexpr Vector< t_dims, uint01operator- () const
 Negation operator.
constexpr Vector< t_dims, uint01 > & operator= (const uint01 &scaler)
 Assignment operator.
constexpr uint01operator[] (uint01 dimension_index)
 Accesses the value of a certain dimension.
constexpr uint01 product () const
 Returns the product, or value of each dimension multiplied together.
constexpr uint01 sum () const
 Returns the sum, or value of each dimension added together.

Static Public Member Functions

static RGBColor Average (const RGBColor &a, const RGBColor &b, const RGBColor &c)
 Computes the average of three colors in RGB space.
static RGBColor Average (const RGBColor &a, const RGBColor &b, fltp04 percent=0.5f)
 Computes a weighted average of two colors in RGB space.
static RGBColor AverageLAB (const RGBColor &a, const RGBColor &b, fltp04 percent=0.5f)
 Computes a weighted average of two colors in perceptually uniform LAB space.
static RGBColor create24BitColor (uint04 color_24)
 Creates an RGBColor from a packed 24-bit RGB color value.
static RGBColor CreateARGB32BitColor (uint04 color_32)
 Creates an RGBColor from a packed 32-bit ARGB color value.
static RGBColor CreateRGBA32BitColor (uint04 color_32)
 Creates an RGBColor from a packed 32-bit RGBA color value.
static RGBColor FromHexARGB (StringView hex)
 Creates an RGBColor from a hex string in ARGB format.
Static Public Member Functions inherited from Vector< 4, uint01 >
static constexpr uint01 NumberOfDimensions ()
 Number of dimensions in this vector class.
static constexpr uint01 Type ()
 Returns the type of this class.

Static Public Attributes

static const uint01 a_pos = 3
 The index of the alpha channel in the RGBA color struct.
static const uint01 b_pos = 2
 The index of the blue channel in the RGBA color struct.
static const uint01 g_pos = 1
 The index of the green channel in the RGBA color struct.
static const uint01 r_pos = 0
 The index of the red channel in the RGBA color struct.

Additional Inherited Members

Protected Attributes inherited from Vector< 4, uint01 >
uint01 m_values [t_dims]
 The values[t dims].

Detailed Description

Represents a color in the RGB space with optional alpha transparency.

Extends the Vector class to include specific methods for RGB manipulation, providing flexibility for use in graphics and image processing applications.

See also
HSBColor, HSLColor, LABColor, XYZColor, ACIColor, ColorPalettes

Definition at line 56 of file RGBColor.h.

Constructor & Destructor Documentation

◆ RGBColor() [1/24]

RGBColor::RGBColor ( )
inlineconstexpr

Default constructor.

Initializes all channels to 0 (transparent black).

Definition at line 68 of file RGBColor.h.

Referenced by RGBColor(), Average(), Average(), AverageLAB(), contrastingColor(), create24BitColor(), CreateARGB32BitColor(), CreateRGBA32BitColor(), FromHexARGB(), opaque(), and operator=().

◆ RGBColor() [2/24]

RGBColor::RGBColor ( uint04 value)
inlineexplicit

Constructs an RGBColor from a packed 32-bit unsigned integer.

Parameters
[in]valuePacked 32-bit RGBA color value.

Definition at line 75 of file RGBColor.h.

◆ RGBColor() [3/24]

RGBColor::RGBColor ( const sint04 r,
const sint04 g,
const sint04 b,
const sint04 a = 255 )
inlineconstexpr

Constructs an RGBColor from signed integer channel values, clamping each to [0, 255].

Parameters
[in]rRed channel value.
[in]gGreen channel value.
[in]bBlue channel value.
[in]aAlpha channel value (default is 255, fully opaque).

Definition at line 85 of file RGBColor.h.

References cast(), and clip().

◆ RGBColor() [4/24]

RGBColor::RGBColor ( const uint01 r,
const uint01 g,
const uint01 b,
const uint01 a = 255 )
inlineconstexpr

Constructor to initialize color using integer values for each channel.

Parameters
rRed channel value (0-255).
gGreen channel value (0-255).
bBlue channel value (0-255).
aAlpha channel value (0-255, default is 255).

Definition at line 99 of file RGBColor.h.

◆ RGBColor() [5/24]

RGBColor::RGBColor ( const fltp04 r,
const fltp04 g,
const fltp04 b,
const fltp04 a = 1.0f )

Constructor to initialize color using floating-point values for each channel.

Parameters
rRed channel value (0.0f-1.0f).
gGreen channel value (0.0f-1.0f).
bBlue channel value (0.0f-1.0f).
aAlpha channel value (0.0f-1.0f, default is 1.0f).

◆ RGBColor() [6/24]

RGBColor::RGBColor ( const fltp08 r,
const fltp08 g,
const fltp08 b,
const fltp08 a = 1.0f )

Constructs an RGBColor from double-precision floating-point channel values.

Parameters
[in]rRed channel value (0.0-1.0).
[in]gGreen channel value (0.0-1.0).
[in]bBlue channel value (0.0-1.0).
[in]aAlpha channel value (0.0-1.0, default is 1.0).

◆ RGBColor() [7/24]

RGBColor::RGBColor ( const RGBColor & color)
inlineconstexpr

Copy constructor.

Parameters
[in]colorThe RGBColor to copy.

Definition at line 122 of file RGBColor.h.

References RGBColor().

◆ RGBColor() [8/24]

template<class t_type>
RGBColor::RGBColor ( const Vector< 1, t_type > & color)
inline

Constructs an RGBColor from a 1-dimensional vector, using the value as a grayscale intensity.

Parameters
[in]colorSingle-channel vector used for R, G, and B. Alpha defaults to 255.

Definition at line 131 of file RGBColor.h.

◆ RGBColor() [9/24]

template<class t_type>
RGBColor::RGBColor ( const Vector< 2, t_type > & color)
inline

Constructs an RGBColor from a 2-dimensional vector (grayscale + alpha).

Parameters
[in]colorTwo-channel vector where [0] is used as grayscale for R, G, B and [1] is alpha.

Definition at line 139 of file RGBColor.h.

References cast().

◆ RGBColor() [10/24]

template<class t_type>
RGBColor::RGBColor ( const Vector< 3, t_type > & color)
inline

Constructs an RGBColor from a 3-dimensional vector (RGB).

Alpha defaults to 255.

Parameters
[in]colorThree-channel vector providing R, G, and B values.

Definition at line 147 of file RGBColor.h.

References Vector< 4, uint01 >::as().

◆ RGBColor() [11/24]

template<class t_type>
RGBColor::RGBColor ( const Vector< 4, t_type > & color)
inline

Constructs an RGBColor from a 4-dimensional vector (RGBA).

Parameters
[in]colorFour-channel vector providing R, G, B, and A values.

Definition at line 155 of file RGBColor.h.

References Vector< 4, uint01 >::as().

◆ RGBColor() [12/24]

RGBColor::RGBColor ( const Vector< 4, fltp04 > & color)
explicit

Constructs an RGBColor from a 4-dimensional single-precision float vector (RGBA in [0,1]).

Parameters
[in]colorFour-channel float vector providing R, G, B, and A values.

◆ RGBColor() [13/24]

RGBColor::RGBColor ( const Vector< 4, fltp08 > & color)
explicit

Constructs an RGBColor from a 4-dimensional double-precision float vector (RGBA in [0,1]).

Parameters
[in]colorFour-channel double vector providing R, G, B, and A values.

◆ RGBColor() [14/24]

RGBColor::RGBColor ( const Vector< 3, fltp04 > & color)
explicit

Constructs an RGBColor from a 3-dimensional single-precision float vector (RGB in [0,1]).

Parameters
[in]colorThree-channel float vector providing R, G, and B values.

◆ RGBColor() [15/24]

RGBColor::RGBColor ( const Vector< 3, fltp08 > & color)
explicit

Constructs an RGBColor from a 3-dimensional double-precision float vector (RGB in [0,1]).

Parameters
[in]colorThree-channel double vector providing R, G, and B values.

◆ RGBColor() [16/24]

RGBColor::RGBColor ( const Vector< 2, fltp04 > & color)
explicit

Constructs an RGBColor from a 2-dimensional single-precision float vector (grayscale + alpha).

Parameters
[in]colorTwo-channel float vector where [0] is grayscale and [1] is alpha.

◆ RGBColor() [17/24]

RGBColor::RGBColor ( const Vector< 2, fltp08 > & color)
explicit

Constructs an RGBColor from a 2-dimensional double-precision float vector (grayscale + alpha).

Parameters
[in]colorTwo-channel double vector where [0] is grayscale and [1] is alpha.

◆ RGBColor() [18/24]

RGBColor::RGBColor ( const Vector< 1, fltp04 > & color)
explicit

Constructs an RGBColor from a 1-dimensional single-precision float vector (grayscale).

Parameters
[in]colorSingle-channel float vector used as grayscale intensity.

◆ RGBColor() [19/24]

RGBColor::RGBColor ( const Vector< 1, fltp08 > & color)
explicit

Constructs an RGBColor from a 1-dimensional double-precision float vector (grayscale).

Parameters
[in]colorSingle-channel double vector used as grayscale intensity.

◆ RGBColor() [20/24]

RGBColor::RGBColor ( const ACIColor & )
explicit

Constructs an RGBColor by converting from an ACIColor.

Parameters
[in]colorThe ACI color to convert from.

◆ RGBColor() [21/24]

RGBColor::RGBColor ( const HSBColor & )
explicit

Constructs an RGBColor by converting from an HSBColor.

Parameters
[in]colorThe HSB color to convert from.

◆ RGBColor() [22/24]

RGBColor::RGBColor ( const HSLColor & )
explicit

Constructs an RGBColor by converting from an HSLColor.

Parameters
[in]colorThe HSL color to convert from.

◆ RGBColor() [23/24]

RGBColor::RGBColor ( const XYZColor & )
explicit

Constructs an RGBColor by converting from an XYZColor.

Parameters
[in]colorThe XYZ color to convert from.

◆ RGBColor() [24/24]

RGBColor::RGBColor ( const LABColor & )
explicit

Constructs an RGBColor by converting from a LABColor.

Parameters
[in]colorThe LAB color to convert from.

Member Function Documentation

◆ Average() [1/2]

RGBColor RGBColor::Average ( const RGBColor & a,
const RGBColor & b,
const RGBColor & c )
static

Computes the average of three colors in RGB space.

Parameters
[in]aThe first color.
[in]bThe second color.
[in]cThe third color.
Returns
The averaged RGBColor.

References RGBColor().

◆ Average() [2/2]

RGBColor RGBColor::Average ( const RGBColor & a,
const RGBColor & b,
fltp04 percent = 0.5f )
static

Computes a weighted average of two colors in RGB space.

Parameters
[in]aThe first color.
[in]bThe second color.
[in]percentThe blend factor where 0.0 returns a and 1.0 returns b (default is 0.5).
Returns
The averaged RGBColor.

References RGBColor().

◆ AverageLAB()

RGBColor RGBColor::AverageLAB ( const RGBColor & a,
const RGBColor & b,
fltp04 percent = 0.5f )
static

Computes a weighted average of two colors in perceptually uniform LAB space.

Parameters
[in]aThe first color.
[in]bThe second color.
[in]percentThe blend factor where 0.0 returns a and 1.0 returns b (default is 0.5).
Returns
The averaged RGBColor after conversion back from LAB space.

References RGBColor().

◆ contrastingColor()

RGBColor RGBColor::contrastingColor ( ) const

Returns a color that contrasts well with this color for readability.

Returns
An RGBColor suitable for use as a foreground against this color as background.

References RGBColor().

◆ convertTo24BitColor()

uint04 RGBColor::convertTo24BitColor ( ) const

Packs this color into a 24-bit unsigned integer (RGB only, no alpha).

Returns
The packed 24-bit RGB color value.

◆ convertToABGR32BitColor()

uint04 RGBColor::convertToABGR32BitColor ( ) const

Packs this color into a 32-bit unsigned integer in ABGR byte order.

Returns
The packed 32-bit ABGR color value.

◆ convertToRGBA32BitColor()

uint04 RGBColor::convertToRGBA32BitColor ( ) const

Packs this color into a 32-bit unsigned integer in RGBA byte order.

Returns
The packed 32-bit RGBA color value.

Referenced by operator()().

◆ create24BitColor()

RGBColor RGBColor::create24BitColor ( uint04 color_24)
static

Creates an RGBColor from a packed 24-bit RGB color value.

Alpha defaults to 255.

Parameters
[in]color_24The packed 24-bit color in RGB byte order.
Returns
The corresponding RGBColor.

References RGBColor().

◆ CreateARGB32BitColor()

RGBColor RGBColor::CreateARGB32BitColor ( uint04 color_32)
static

Creates an RGBColor from a packed 32-bit ARGB color value.

Parameters
[in]color_32The packed 32-bit color in ARGB byte order.
Returns
The corresponding RGBColor.

References RGBColor().

◆ CreateRGBA32BitColor()

RGBColor RGBColor::CreateRGBA32BitColor ( uint04 color_32)
static

Creates an RGBColor from a packed 32-bit RGBA color value.

Parameters
[in]color_32The packed 32-bit color in RGBA byte order.
Returns
The corresponding RGBColor.

References RGBColor().

◆ FromHexARGB()

RGBColor RGBColor::FromHexARGB ( StringView hex)
static

Creates an RGBColor from a hex string in ARGB format.

Parameters
[in]hexThe hex string to parse (e.g., "#FFFF0000" or "FFFF0000").
Returns
The corresponding RGBColor.

References RGBColor().

◆ get3F()

Vector< 3, fltp04 > RGBColor::get3F ( ) const

Gets the RGB channels as a 3-dimensional float vector normalized to [0, 1].

Returns
A Vector<3, fltp04> containing the normalized R, G, and B values.

◆ get4F()

Vector< 4, fltp04 > RGBColor::get4F ( ) const

Gets all RGBA channels as a 4-dimensional float vector normalized to [0, 1].

Returns
A Vector<4, fltp04> containing the normalized R, G, B, and A values.

◆ getF()

fltp04 RGBColor::getF ( uint01 channel) const
inline

Gets a channel value as a normalized float in [0, 1].

Parameters
[in]channelThe channel index (r_pos, g_pos, b_pos, or a_pos).
Returns
The channel value normalized to the range [0.0, 1.0].

Definition at line 240 of file RGBColor.h.

References inverse_255, and Vector< 4, uint01 >::m_values.

◆ getHexARGB()

String RGBColor::getHexARGB ( ) const

Gets the hex string representation of this color in ARGB format (e.g., "#FFFF0000").

Returns
A String containing the hex ARGB representation.

◆ getHexRGB()

String RGBColor::getHexRGB ( ) const

Gets the hex string representation of this color in RGB format (e.g., "#FF0000").

Returns
A String containing the hex RGB representation.

◆ getHexRGBA()

String RGBColor::getHexRGBA ( ) const

Gets the hex string representation of this color in RGBA format (e.g., "#FF0000FF").

Returns
A String containing the hex RGBA representation.

◆ getName()

TranslatedString RGBColor::getName ( ) const

Gets the closest known name for this color as a translated string.

Returns
A TranslatedString containing the human-readable color name.

◆ isLight()

bool RGBColor::isLight ( ) const

Determines whether this color is perceptually light.

Returns
True if the color is considered light, false otherwise.

◆ luminance()

fltp04 RGBColor::luminance ( ) const

Returns the luminance of the color.

Returns
Luminance as a floating-point value.

◆ opaque()

RGBColor RGBColor::opaque ( ) const
inline

Returns a copy of this color with alpha set to 255 (fully opaque).

Returns
A new RGBColor with the same RGB channels and full opacity.

Definition at line 230 of file RGBColor.h.

References RGBColor(), b_pos, g_pos, Vector< 4, uint01 >::m_values, and r_pos.

◆ operator()()

size_t RGBColor::operator() ( ) const
inline

Functor operator that returns the packed 32-bit RGBA representation, useful as a hash.

Returns
The packed 32-bit RGBA color value as a size_t.

Definition at line 322 of file RGBColor.h.

References convertToRGBA32BitColor().

◆ operator=()

RGBColor & RGBColor::operator= ( const RGBColor & color)
inlineconstexpr

Copy assignment operator.

Parameters
[in]colorThe RGBColor to assign from.
Returns
A reference to this color after assignment.

Definition at line 331 of file RGBColor.h.

References RGBColor(), Vector< t_dims, t_type >::m_values, and Vector< 4, uint01 >::m_values.

◆ setF()

void RGBColor::setF ( uint01 channel,
fltp04 value )
inline

Sets a channel value from a normalized float in [0, 1].

Parameters
[in]channelThe channel index (r_pos, g_pos, b_pos, or a_pos).
[in]valueThe normalized float value to set.

Definition at line 249 of file RGBColor.h.

References cast(), and Vector< 4, uint01 >::m_values.


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