26 constexpr Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255) noexcept
27 : r(r), g(g), b(b), a(a) {}
39 return {r, g, b, newAlpha};
49 [[nodiscard]] static
Color fromHSV(
float h,
float s,
float v,
50 uint8_t a = 255) noexcept;
52 [[nodiscard]] static
Color fromHex(uint32_t hex) noexcept;
55 std::ostringstream ss;
56 ss <<
"Color(" <<
static_cast<int>(r) <<
", " <<
static_cast<int>(g)
57 <<
", " <<
static_cast<int>(b) <<
", " <<
static_cast<int>(a) <<
")";
62 return r == other.r && g == other.g && b == other.b && a == other.a;
66 return !(*
this == other);
70 return Color{
static_cast<uint8_t
>(
Clamp(r + other.r, 0, 255)),
71 static_cast<uint8_t
>(
Clamp(g + other.g, 0, 255)),
72 static_cast<uint8_t
>(
Clamp(b + other.b, 0, 255)),
73 static_cast<uint8_t
>(
Clamp(a + other.a, 0, 255))};
77 return Color{
static_cast<uint8_t
>(
78 Clamp(
static_cast<int>(r * scalar), 0, 255)),
80 Clamp(
static_cast<int>(g * scalar), 0, 255)),
82 Clamp(
static_cast<int>(b * scalar), 0, 255)),
84 Clamp(
static_cast<int>(a * scalar), 0, 255))};
87 uint8_t
GetR()
const {
return r; }
88 uint8_t
GetG()
const {
return g; }
89 uint8_t
GetB()
const {
return b; }
90 uint8_t
GetA()
const {
return a; }
94 return {
static_cast<float>(r) / 255.0f,
static_cast<float>(g) / 255.0f,
95 static_cast<float>(b) / 255.0f,
static_cast<float>(a) / 255.0f};
static const Color Transparent
constexpr Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a=255) noexcept
Color srgbToLinear() const noexcept
Color linearToSrgb() const noexcept
constexpr Color operator*(float scalar) const noexcept
static Color fromHSV(float h, float s, float v, uint8_t a=255) noexcept
Builds a color from hue/saturation/value in [0,1].
constexpr Color operator+(const Color &other) const noexcept
constexpr Color()=default
Color premultiplied() const noexcept
Scales RGB by alpha, for premultiplied-alpha blending.
std::string toString() const
constexpr Color withAlpha(uint8_t newAlpha) const noexcept
Returns a copy with alpha replaced.
Vector4D normalize() const noexcept
Converts to a Vector4D with each channel in [0,1].
constexpr bool operator!=(const Color &other) const noexcept
constexpr Color clamped() const noexcept
Clamps every channel into [0, 255].
static Color fromHex(uint32_t hex) noexcept
Builds a color from a 0xRRGGBB or 0xAARRGGBB packed value.
constexpr bool operator==(const Color &other) const noexcept
Vectors, matrices, quaternions, colors, AABBs, and random helpers.
constexpr const T & Clamp(const T &value, T min, T max)
Clamps value into [min, max].
Root namespace for everything the engine exposes.