utility 2026.1.9
A comprehensive C++ utilities library tailored for the development of modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
utility::graphic::Color< Type > Class Template Reference

RGBA color with arithmetic type components. More...

#include <headers/utility/graphic/color.hpp>

Collaboration diagram for utility::graphic::Color< Type >:

Public Member Functions

 Color (void)
 Default constructor creating opaque black.
 
 Color (Type red, Type green, Type blue)
 Construct color with RGB values (fully opaque).
 
 Color (Type red, Type green, Type blue, Type alpha)
 Construct color with RGBA values.
 
 Color (const Color &other)
 Copy constructor.
 
 Color (Color &&other) noexcept
 Move constructor.
 
Coloroperator= (const Color &other)
 Copy assignment operator.
 
Coloroperator= (Color &&other) noexcept
 Move assignment operator.
 
void setRed (Type red)
 Set the red component.
 
Type getRed (void) const
 Get the red component.
 
void setGreen (Type green)
 Set the green component.
 
Type getGreen (void) const
 Get the green component.
 
void setBlue (Type blue)
 Set the blue component.
 
Type getBlue (void) const
 Get the blue component.
 
void setAlpha (Type alpha)
 Set the alpha (opacity) component.
 
Type getAlpha (void) const
 Get the alpha (opacity) component.
 
void setRGBA (Type red, Type green, Type blue, Type alpha)
 Set all RGBA components.
 
bool operator== (const Color &other) const
 Equality comparison.
 
bool operator!= (const Color &other) const
 Inequality comparison.
 
Color operator+ (const Color &other) const
 Component-wise color addition (clamped).
 
Color operator- (const Color &other) const
 Component-wise color subtraction (clamped).
 
Color operator* (Type scalar) const
 Scalar multiplication of color components.
 
Color grayscale (void) const
 Convert color to grayscale using luminance formula.
 
Color inverted (void) const
 Invert the color (keeping alpha unchanged).
 
Color lerp (const Color &other, Type t) const
 Linearly interpolate between this color and another.
 
Color blendOver (const Color &background) const
 Alpha blend this color over another background color.
 
Color lighter (Type factor) const
 Create a lighter version of this color.
 
Color darker (Type factor) const
 Create a darker version of this color.
 
Color withAlpha (Type alpha) const
 Return a copy with a different alpha value.
 
bool isOpaque (void) const
 Check whether alpha is fully opaque.
 
bool isTransparent (void) const
 Check whether alpha is fully transparent.
 
double alpha01 (void) const
 Get alpha normalized to [0, 1].
 
bool operator< (const Color &other) const
 Less-than operator for Color.
 

Static Protected Member Functions

static Type clamp (Type value)
 Clamp a value to valid range based on type.
 
static Type clampWide (long long value)
 Clamp a wide accumulator into the component range.
 
static constexpr Type maxValue ()
 Get the maximum value for the type.
 

Protected Attributes

Type _red
 Red component.
 
Type _green
 Green component.
 
Type _blue
 Blue component.
 
Type _alpha
 Alpha (opacity) component.
 

Detailed Description

template<CanBeColorComponent Type>
class utility::graphic::Color< Type >

RGBA color with arithmetic type components.

Template Parameters
TypeArithmetic type for color components (typically float or uint8_t)

Components are expected to be normalized: [0.0, 1.0] for floating-point types or [0, 255] for integral types.

Definition at line 60 of file color.hpp.

Constructor & Destructor Documentation

◆ Color() [1/5]

template<CanBeColorComponent Type>
utility::graphic::Color< Type >::Color ( void  )
inline

Default constructor creating opaque black.

Definition at line 134 of file color.hpp.

Here is the caller graph for this function:

◆ Color() [2/5]

template<CanBeColorComponent Type>
utility::graphic::Color< Type >::Color ( Type  red,
Type  green,
Type  blue 
)
inline

Construct color with RGB values (fully opaque).

Parameters
redRed component.
greenGreen component.
blueBlue component.

Definition at line 148 of file color.hpp.

Here is the call graph for this function:

◆ Color() [3/5]

template<CanBeColorComponent Type>
utility::graphic::Color< Type >::Color ( Type  red,
Type  green,
Type  blue,
Type  alpha 
)
inline

Construct color with RGBA values.

Parameters
redRed component.
greenGreen component.
blueBlue component.
alphaAlpha (opacity) component.

Definition at line 163 of file color.hpp.

Here is the call graph for this function:

◆ Color() [4/5]

template<CanBeColorComponent Type>
utility::graphic::Color< Type >::Color ( const Color< Type > &  other)
inline

Copy constructor.

Parameters
otherThe color to copy from.

Definition at line 175 of file color.hpp.

◆ Color() [5/5]

template<CanBeColorComponent Type>
utility::graphic::Color< Type >::Color ( Color< Type > &&  other)
inlinenoexcept

Move constructor.

Parameters
otherThe color to move from.

Definition at line 187 of file color.hpp.

Member Function Documentation

◆ alpha01()

template<CanBeColorComponent Type>
double utility::graphic::Color< Type >::alpha01 ( void  ) const
inline

Get alpha normalized to [0, 1].

Returns
Alpha as double regardless of component type.

Definition at line 514 of file color.hpp.

Here is the call graph for this function:

◆ blendOver()

template<CanBeColorComponent Type>
Color utility::graphic::Color< Type >::blendOver ( const Color< Type > &  background) const
inline

Alpha blend this color over another background color.

Parameters
backgroundThe background color.
Returns
Blended color.

Definition at line 436 of file color.hpp.

Here is the call graph for this function:

◆ clamp()

template<CanBeColorComponent Type>
static Type utility::graphic::Color< Type >::clamp ( Type  value)
inlinestaticprotected

Clamp a value to valid range based on type.

Parameters
valueThe value to clamp.
Returns
Clamped value.

Definition at line 89 of file color.hpp.

Here is the caller graph for this function:

◆ clampWide()

template<CanBeColorComponent Type>
static Type utility::graphic::Color< Type >::clampWide ( long long  value)
inlinestaticprotected

Clamp a wide accumulator into the component range.

Integral arithmetic is performed in a wider type to avoid wrapping before clamping (e.g. 200+200 would truncate to 144 as uint8_t).

Parameters
valueThe wide value to clamp.
Returns
Clamped component.

Definition at line 106 of file color.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ darker()

template<CanBeColorComponent Type>
Color utility::graphic::Color< Type >::darker ( Type  factor) const
inline

Create a darker version of this color.

Parameters
factorDarkening factor (0 = no change, 1 = black).
Returns
Darkened color.

Definition at line 476 of file color.hpp.

Here is the call graph for this function:

◆ getAlpha()

template<CanBeColorComponent Type>
Type utility::graphic::Color< Type >::getAlpha ( void  ) const
inline

Get the alpha (opacity) component.

Returns
Alpha value.

Definition at line 297 of file color.hpp.

Here is the caller graph for this function:

◆ getBlue()

template<CanBeColorComponent Type>
Type utility::graphic::Color< Type >::getBlue ( void  ) const
inline

Get the blue component.

Returns
Blue value.

Definition at line 279 of file color.hpp.

Here is the caller graph for this function:

◆ getGreen()

template<CanBeColorComponent Type>
Type utility::graphic::Color< Type >::getGreen ( void  ) const
inline

Get the green component.

Returns
Green value.

Definition at line 261 of file color.hpp.

Here is the caller graph for this function:

◆ getRed()

template<CanBeColorComponent Type>
Type utility::graphic::Color< Type >::getRed ( void  ) const
inline

Get the red component.

Returns
Red value.

Definition at line 243 of file color.hpp.

Here is the caller graph for this function:

◆ grayscale()

template<CanBeColorComponent Type>
Color utility::graphic::Color< Type >::grayscale ( void  ) const
inline

Convert color to grayscale using luminance formula.

Returns
Grayscale version of this color.

Definition at line 381 of file color.hpp.

Here is the call graph for this function:

◆ inverted()

template<CanBeColorComponent Type>
Color utility::graphic::Color< Type >::inverted ( void  ) const
inline

Invert the color (keeping alpha unchanged).

Returns
Inverted color.

Definition at line 399 of file color.hpp.

Here is the call graph for this function:

◆ isOpaque()

template<CanBeColorComponent Type>
bool utility::graphic::Color< Type >::isOpaque ( void  ) const
inline

Check whether alpha is fully opaque.

Returns
True when alpha equals max component value.

Definition at line 496 of file color.hpp.

Here is the call graph for this function:

◆ isTransparent()

template<CanBeColorComponent Type>
bool utility::graphic::Color< Type >::isTransparent ( void  ) const
inline

Check whether alpha is fully transparent.

Returns
True when alpha equals zero.

Definition at line 505 of file color.hpp.

◆ lerp()

template<CanBeColorComponent Type>
Color utility::graphic::Color< Type >::lerp ( const Color< Type > &  other,
Type  t 
) const
inline

Linearly interpolate between this color and another.

Parameters
otherThe target color.
tInterpolation factor [0, 1].
Returns
Interpolated color.

Definition at line 411 of file color.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ lighter()

template<CanBeColorComponent Type>
Color utility::graphic::Color< Type >::lighter ( Type  factor) const
inline

Create a lighter version of this color.

Parameters
factorLightening factor (0 = no change, 1 = white).
Returns
Lightened color.

Definition at line 464 of file color.hpp.

Here is the call graph for this function:

◆ maxValue()

template<CanBeColorComponent Type>
static constexpr Type utility::graphic::Color< Type >::maxValue ( )
inlinestaticconstexprprotected

Get the maximum value for the type.

Returns
Maximum value (1.0 for float, 255 for uint8_t).

Definition at line 121 of file color.hpp.

Here is the caller graph for this function:

◆ operator!=()

template<CanBeColorComponent Type>
bool utility::graphic::Color< Type >::operator!= ( const Color< Type > &  other) const
inline

Inequality comparison.

Parameters
otherThe color to compare with.
Returns
True if any component is not equal, false otherwise.

Definition at line 333 of file color.hpp.

◆ operator*()

template<CanBeColorComponent Type>
Color utility::graphic::Color< Type >::operator* ( Type  scalar) const
inline

Scalar multiplication of color components.

Parameters
scalarThe scalar to multiply by.
Returns
Result of scalar multiplication.

Definition at line 369 of file color.hpp.

Here is the call graph for this function:

◆ operator+()

template<CanBeColorComponent Type>
Color utility::graphic::Color< Type >::operator+ ( const Color< Type > &  other) const
inline

Component-wise color addition (clamped).

Parameters
otherThe color to add.
Returns
Result of color addition.

Definition at line 343 of file color.hpp.

Here is the call graph for this function:

◆ operator-()

template<CanBeColorComponent Type>
Color utility::graphic::Color< Type >::operator- ( const Color< Type > &  other) const
inline

Component-wise color subtraction (clamped).

Parameters
otherThe color to subtract.
Returns
Result of color subtraction.

Definition at line 356 of file color.hpp.

Here is the call graph for this function:

◆ operator<()

template<CanBeColorComponent Type>
bool utility::graphic::Color< Type >::operator< ( const Color< Type > &  other) const
inline

Less-than operator for Color.

Parameters
otherThe other Color to compare with.
Returns
True if this color is less than the other, false otherwise.

Definition at line 525 of file color.hpp.

◆ operator=() [1/2]

template<CanBeColorComponent Type>
Color & utility::graphic::Color< Type >::operator= ( Color< Type > &&  other)
inlinenoexcept

Move assignment operator.

Parameters
otherThe color to move from.
Returns
Reference to this color.

Definition at line 216 of file color.hpp.

◆ operator=() [2/2]

template<CanBeColorComponent Type>
Color & utility::graphic::Color< Type >::operator= ( const Color< Type > &  other)
inline

Copy assignment operator.

Parameters
otherThe color to copy from.
Returns
Reference to this color.

Definition at line 200 of file color.hpp.

◆ operator==()

template<CanBeColorComponent Type>
bool utility::graphic::Color< Type >::operator== ( const Color< Type > &  other) const
inline

Equality comparison.

Parameters
otherThe color to compare with.
Returns
True if all components are equal, false otherwise.

Definition at line 322 of file color.hpp.

◆ setAlpha()

template<CanBeColorComponent Type>
void utility::graphic::Color< Type >::setAlpha ( Type  alpha)
inline

Set the alpha (opacity) component.

Parameters
alphaNew alpha value (will be clamped to valid range).

Definition at line 288 of file color.hpp.

Here is the call graph for this function:

◆ setBlue()

template<CanBeColorComponent Type>
void utility::graphic::Color< Type >::setBlue ( Type  blue)
inline

Set the blue component.

Parameters
blueNew blue value (will be clamped to valid range).

Definition at line 270 of file color.hpp.

Here is the call graph for this function:

◆ setGreen()

template<CanBeColorComponent Type>
void utility::graphic::Color< Type >::setGreen ( Type  green)
inline

Set the green component.

Parameters
greenNew green value (will be clamped to valid range).

Definition at line 252 of file color.hpp.

Here is the call graph for this function:

◆ setRed()

template<CanBeColorComponent Type>
void utility::graphic::Color< Type >::setRed ( Type  red)
inline

Set the red component.

Parameters
redNew red value (will be clamped to valid range).

Definition at line 234 of file color.hpp.

Here is the call graph for this function:

◆ setRGBA()

template<CanBeColorComponent Type>
void utility::graphic::Color< Type >::setRGBA ( Type  red,
Type  green,
Type  blue,
Type  alpha 
)
inline

Set all RGBA components.

Parameters
redRed component.
greenGreen component.
blueBlue component.
alphaAlpha component.

Definition at line 309 of file color.hpp.

Here is the call graph for this function:

◆ withAlpha()

template<CanBeColorComponent Type>
Color utility::graphic::Color< Type >::withAlpha ( Type  alpha) const
inline

Return a copy with a different alpha value.

Parameters
alphaAlpha value to apply (clamped).
Returns
New color with updated alpha.

Definition at line 487 of file color.hpp.

Here is the call graph for this function:

Member Data Documentation

◆ _alpha

template<CanBeColorComponent Type>
Type utility::graphic::Color< Type >::_alpha
protected

Alpha (opacity) component.

Definition at line 82 of file color.hpp.

◆ _blue

template<CanBeColorComponent Type>
Type utility::graphic::Color< Type >::_blue
protected

Blue component.

Definition at line 77 of file color.hpp.

◆ _green

template<CanBeColorComponent Type>
Type utility::graphic::Color< Type >::_green
protected

Green component.

Definition at line 72 of file color.hpp.

◆ _red

template<CanBeColorComponent Type>
Type utility::graphic::Color< Type >::_red
protected

Red component.

Definition at line 67 of file color.hpp.


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