RSTools 3.1.0
Versatile C++20 utility library
Loading...
Searching...
No Matches
RST::Color::Color Struct Reference

8-bit RGBA color, packed in 4 bytes. More...

#include <RST/color/Color.hpp>

Public Member Functions

constexpr Color () noexcept
 Opaque black.
 
constexpr Color (std::uint8_t red, std::uint8_t green, std::uint8_t blue, std::uint8_t alpha=255) noexcept
 
constexpr Color (std::uint32_t hex) noexcept
 From a 0xRRGGBBAA value.
 
constexpr std::uint32_t toHex () const noexcept
 Packed as 0xRRGGBBAA.
 
constexpr std::uint32_t toRgb () const noexcept
 Packed as 0xRRGGBB, without alpha.
 
constexpr std::array< float, 4 > toFloat () const noexcept
 Components in [0, 1].
 
Hsv toHsv () const noexcept
 
std::string toHexString (bool withAlpha=true) const
 Formats as #RRGGBBAA, or #RRGGBB without alpha.
 
constexpr Color withAlpha (std::uint8_t alpha) const noexcept
 
constexpr Color inverted () const noexcept
 Inverts red, green and blue, keeping alpha.
 
constexpr Color grayscale () const noexcept
 Gray of the same luminance, keeping alpha.
 
constexpr bool operator== (const Color &) const noexcept=default
 

Static Public Member Functions

static constexpr Color fromRgb (std::uint32_t rgb, std::uint8_t alpha=255) noexcept
 From a 0xRRGGBB value and a separate alpha.
 
static constexpr Color fromFloat (float red, float green, float blue, float alpha=1.f) noexcept
 From components in [0, 1], clamped.
 
static Color fromHsv (const Hsv &hsv) noexcept
 
static constexpr std::optional< Color > fromHexString (std::string_view text) noexcept
 Parses #RGB, #RGBA, #RRGGBB or #RRGGBBAA, with or without the #.
 

Public Attributes

std::uint8_t r
 
std::uint8_t g
 
std::uint8_t b
 
std::uint8_t a
 

Detailed Description

8-bit RGBA color, packed in 4 bytes.

Constructor & Destructor Documentation

◆ Color() [1/3]

constexpr RST::Color::Color::Color ( )
inlineconstexprnoexcept

Opaque black.

◆ Color() [2/3]

constexpr RST::Color::Color::Color ( std::uint8_t  red,
std::uint8_t  green,
std::uint8_t  blue,
std::uint8_t  alpha = 255 
)
inlineconstexprnoexcept

◆ Color() [3/3]

constexpr RST::Color::Color::Color ( std::uint32_t  hex)
inlineconstexprnoexcept

From a 0xRRGGBBAA value.

Member Function Documentation

◆ fromRgb()

static constexpr Color RST::Color::Color::fromRgb ( std::uint32_t  rgb,
std::uint8_t  alpha = 255 
)
inlinestaticconstexprnoexcept

From a 0xRRGGBB value and a separate alpha.

◆ fromFloat()

static constexpr Color RST::Color::Color::fromFloat ( float  red,
float  green,
float  blue,
float  alpha = 1.f 
)
inlinestaticconstexprnoexcept

From components in [0, 1], clamped.

◆ fromHsv()

static Color RST::Color::Color::fromHsv ( const Hsv &  hsv)
staticnoexcept

◆ fromHexString()

static constexpr std::optional< Color > RST::Color::Color::fromHexString ( std::string_view  text)
inlinestaticconstexprnoexcept

Parses #RGB, #RGBA, #RRGGBB or #RRGGBBAA, with or without the #.

◆ toHex()

constexpr std::uint32_t RST::Color::Color::toHex ( ) const
inlineconstexprnoexcept

Packed as 0xRRGGBBAA.

◆ toRgb()

constexpr std::uint32_t RST::Color::Color::toRgb ( ) const
inlineconstexprnoexcept

Packed as 0xRRGGBB, without alpha.

◆ toFloat()

constexpr std::array< float, 4 > RST::Color::Color::toFloat ( ) const
inlineconstexprnoexcept

Components in [0, 1].

◆ toHsv()

Hsv RST::Color::Color::toHsv ( ) const
noexcept

◆ toHexString()

std::string RST::Color::Color::toHexString ( bool  withAlpha = true) const

Formats as #RRGGBBAA, or #RRGGBB without alpha.

◆ withAlpha()

constexpr Color RST::Color::Color::withAlpha ( std::uint8_t  alpha) const
inlineconstexprnoexcept

◆ inverted()

constexpr Color RST::Color::Color::inverted ( ) const
inlineconstexprnoexcept

Inverts red, green and blue, keeping alpha.

◆ grayscale()

constexpr Color RST::Color::Color::grayscale ( ) const
inlineconstexprnoexcept

Gray of the same luminance, keeping alpha.

◆ operator==()

constexpr bool RST::Color::Color::operator== ( const Color &  ) const
constexprdefaultnoexcept

Member Data Documentation

◆ r

std::uint8_t RST::Color::Color::r

◆ g

std::uint8_t RST::Color::Color::g

◆ b

std::uint8_t RST::Color::Color::b

◆ a

std::uint8_t RST::Color::Color::a

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