32 if(fields.size() != 3 && fields.size() != 4) {
33 throw std::invalid_argument(
"Wrong number of components for RGBA color");
37 *utils::from_chars<uint8_t>(fields[0]),
38 *utils::from_chars<uint8_t>(fields[1]),
39 *utils::from_chars<uint8_t>(fields[2]),
40 fields.size() == 4 ? *utils::from_chars<uint8_t>(fields[3]) :
ALPHA_OPAQUE
52 if(fields.size() != 3) {
53 throw std::invalid_argument(
"Wrong number of components for RGB color");
57 *utils::from_chars<uint8_t>(fields[0]),
58 *utils::from_chars<uint8_t>(fields[1]),
59 *utils::from_chars<uint8_t>(fields[2]),
71 throw std::invalid_argument(
"Color hex string should be exactly 6 digits (leading '#' optional)");
74 if(std::any_of(
c.begin(),
c.end(), [](
const char& ch) { return std::isxdigit(ch) == 0; })) {
75 throw std::invalid_argument(
"Color hex string contains invalid characters");
78 auto temp_c = *utils::from_chars<uint32_t>(
c, 16);
81 static_cast<uint8_t
>((0x00FFFFFF & temp_c) >> 16),
82 static_cast<uint8_t
>((0x00FFFFFF & temp_c) >> 8),
83 static_cast<uint8_t
>((0x00FFFFFF & temp_c)),
93 << std::hex << std::setfill(
'0')
94 << std::setw(2) <<
static_cast<int>(r)
95 << std::setw(2) <<
static_cast<int>(
g)
96 << std::setw(2) <<
static_cast<int>(
b);
99 h << std::setw(2) << static_cast<int>(a);
107 std::ostringstream color;
109 color << static_cast<int>(r) <<
','
110 <<
static_cast<int>(
g) <<
','
111 <<
static_cast<int>(
b) <<
','
112 <<
static_cast<int>(a);
119 std::ostringstream color;
121 color << static_cast<int>(r) <<
','
122 <<
static_cast<int>(
g) <<
','
123 <<
static_cast<int>(
b);
constexpr uint8_t ALPHA_OPAQUE
std::vector< std::string_view > split_view(std::string_view s, const char sep, const int flags)
The basic class for representing 8-bit RGB or RGBA colour values.
static color_t from_hex_string(std::string_view c)
Creates a new color_t object from a string variable in hex format.
std::string to_hex_string() const
Returns the stored color in rrggbb hex format.
static color_t from_rgb_string(std::string_view c)
Creates a new opaque color_t object from a string variable in "R,G,B" format.
static constexpr color_t null_color()
Definition of a 'null' color - fully transparent black.
std::string to_rgb_string() const
Returns the stored color as an "R,G,B" string.
static color_t from_rgba_string(std::string_view c)
Creates a new color_t object from a string variable in "R,G,B,A" format.
std::string to_rgba_string() const
Returns the stored color as an "R,G,B,A" string.