33 Color(uint8_t
r, uint8_t
g, uint8_t
b, uint8_t
a = 255)
51 return {
static_cast<uint8_t
>(
r * 255),
static_cast<uint8_t
>(
g * 255),
52 static_cast<uint8_t
>(
b * 255),
static_cast<uint8_t
>(
a * 255) };
62 if (hex.empty() || hex[0] !=
'#' || (hex.length() != 7 && hex.length() != 9)) {
66 uint8_t
r = std::stoi(hex.substr(1, 2),
nullptr, 16);
67 uint8_t
g = std::stoi(hex.substr(3, 2),
nullptr, 16);
68 uint8_t
b = std::stoi(hex.substr(5, 2),
nullptr, 16);
71 if (hex.length() == 9) {
72 a = std::stoi(hex.substr(7, 2),
nullptr, 16);
75 return {
r,
g,
b,
a };
84 return {
static_cast<uint8_t
>(
r + (255 -
r) * percentage),
85 static_cast<uint8_t
>(
g + (255 -
g) * percentage),
86 static_cast<uint8_t
>(
b + (255 -
b) * percentage),
a };
95 return {
static_cast<uint8_t
>(
r * (1 - percentage)),
96 static_cast<uint8_t
>(
g * (1 - percentage)),
static_cast<uint8_t
>(
b * (1 - percentage)),
106 float alpha =
a / 255.0F;
107 return {
static_cast<uint8_t
>(
r * alpha + color.
r * (1 - alpha)),
108 static_cast<uint8_t
>(
g * alpha + color.
g * (1 - alpha)),
109 static_cast<uint8_t
>(
b * alpha + color.
b * (1 - alpha)), 255 };
117 return {
static_cast<uint8_t
>(255 -
r),
static_cast<uint8_t
>(255 -
g),
118 static_cast<uint8_t
>(255 -
b),
a };
126 auto gray =
static_cast<uint8_t
>(0.299F *
r + 0.587F *
g + 0.114F *
b);
127 return { gray, gray, gray,
a };
137 return {
r,
g,
b, alpha };
const Color lightslategrey
const Color darkturquoise
const Color blanchedalmond
const Color lightseagreen
const Color mediumseagreen
const Color mediumslateblue
const Color cornflowerblue
const Color lightgoldenrodyellow
const Color palevioletred
const Color rebeccapurple
const Color paleturquoise
const Color mediumaquamarine
const Color darkslategrey
const Color darkslateblue
const Color darkolivegreen
const Color lavenderblush
const Color lightslategray
const Color mediumspringgreen
const Color mediumvioletred
const Color darkslategray
const Color mediumturquoise
const Color darkgoldenrod
const Color lightsteelblue
const Color palegoldenrod
RGBA color struct with 8-bit channels.
Color with_alpha(uint8_t alpha) const
Adjust the alpha of a color.
Color blend(const Color &color) const
Blend two colors together using alpha blending.
static Color from_float(float r, float g, float b, float a=1.0F)
From float RGBA values (0.0-1.0) to Color.
Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
Construct a Color from RGBA values.
Color invert() const
Invert a color.
static Color from_hex(const std::string &hex)
From a hex string (e.g. "#RRGGBBAA") to a Color.
Color grayscale() const
Convert a color to grayscale.
Color()
Construct a default Color (black, fully opaque).
Color darken(float percentage) const
Darken a color by a given percentage.
Color lighten(float percentage) const
Lighten a color by a given percentage.