18constexpr float RgbToHue(
float r,
float g,
float b)
20 float h_min = std::min({r, g, b});
21 float h_max = std::max({r, g, b});
26 float c = h_max - h_min;
28 hue = (g - b) / c + (g < b ? 6 : 0);
30 hue = (b - r) / c + 2;
32 hue = (r - g) / c + 4;
39template<
typename DerivedT>
65 constexpr color4_base(
float nx,
float ny,
float nz,
float na) :
66 x(nx),
y(ny),
z(nz),
a(na)
71 x(nx),
y(ny),
z(nz),
a(1.0f)
77 a = alpha ? ((col >> 24) & 0xFF) / 255.0f : 1.0f;
78 x = ((col >> 16) & 0xFF) / 255.0f;
79 y = ((col >> 8) & 0xFF) / 255.0f;
80 z = ((col >> 0) & 0xFF) / 255.0f;
85 template<
typename OtherDerivedT>
86 requires(!std::is_same_v<DerivedT, OtherDerivedT>)
91 return ((
float *)
this)[index];
97 constexpr unsigned Pack(
bool Alpha =
true)
const
111 DerivedT col(
static_cast<const DerivedT &
>(*
this));
118 DerivedT col(
static_cast<const DerivedT &
>(*
this));
123 template<
typename UnpackT>
129 Result.x = ((Color >> 24) & 0xFF) / 255.0f;
130 Result.y = ((Color >> 16) & 0xFF) / 255.0f;
131 Result.z = ((Color >> 8) & 0xFF) / 255.0f;
132 Result.a = ((Color >> 0) & 0xFF) / 255.0f;
136 Result.x = ((Color >> 16) & 0xFF) / 255.0f;
137 Result.y = ((Color >> 8) & 0xFF) / 255.0f;
138 Result.z = ((Color >> 0) & 0xFF) / 255.0f;
157 col.
l = Darkest + col.
l * (1.0f - Darkest);
161 constexpr unsigned Pack(
bool Alpha =
true)
const
166 constexpr unsigned Pack(
float Darkest,
bool Alpha =
false)
const
169 col.
l = (
l - Darkest) / (1 - Darkest);
170 col.
l = std::clamp(col.
l, 0.0f, 1.0f);
171 return col.
Pack(Alpha);
210template<
typename T,
typename F>
216 float Min = std::min({rgb.
r, rgb.
g, rgb.
b});
217 float Max = std::max({rgb.
r, rgb.
g, rgb.
b});
221 float l = 0.5f * (Max + Min);
222 float s = (Max != 0.0f && Min != 1.0f) ? (c / (1 - (
absolute(2 * l - 1)))) : 0;
230 float h1 = hsl.
h * 6;
231 float c = (1.f -
absolute(2 * hsl.
l - 1)) * hsl.
s;
232 float x = c * (1.f -
absolute(std::fmod(h1, 2) - 1.f));
266 float m = hsl.
l - (c / 2);
273 float l = hsv.
v * (1 - hsv.
s * 0.5f);
274 return ColorHSLA(hsv.
h, (l == 0.0f || l == 1.0f) ? 0 : (hsv.
v - l) / std::min(l, 1 - l), l, hsv.
a);
280 float v = hsl.
l + hsl.
s * std::min(hsl.
l, 1 - hsl.
l);
281 return ColorHSVA(hsl.
h, v == 0.0f ? 0 : 2 - (2 * hsl.
l / v), v, hsl.
a);
299 return T(col.x *
s, col.y *
s, col.z *
s, col.a *
s);
305 return T(1.0f - col.x, 1.0f - col.y, 1.0f - col.z, 1.0f - col.a);
static constexpr const float DARKEST_LGT7
Definition color.h:152
static constexpr const float DARKEST_LGT
Definition color.h:151
constexpr unsigned Pack(float Darkest, bool Alpha=false) const
Definition color.h:166
constexpr color4_base()
Definition color.h:60
constexpr unsigned Pack(bool Alpha=true) const
Definition color.h:161
constexpr ColorHSLA()=default
constexpr ColorHSLA UnclampLighting(float Darkest) const
Definition color.h:154
constexpr color4_base()
Definition color.h:60
constexpr ColorHSVA()=default
constexpr ColorRGBA Multiply(const T &Factor) const
Definition color.h:199
constexpr color4_base()
Definition color.h:60
constexpr ColorRGBA()=default
constexpr ColorRGBA Multiply(const ColorRGBA &Other) const
Definition color.h:188
static constexpr UnpackT UnpackAlphaLast(unsigned Color, bool Alpha=true)
Definition color.h:124
float h
Definition color.h:45
float b
Definition color.h:53
float x
Definition color.h:45
constexpr color4_base(float nx, float ny, float nz, float na)
Definition color.h:65
color4_base(const color4_base< OtherDerivedT > &Other)=delete
constexpr bool operator!=(const color4_base &col) const
Definition color.h:95
constexpr color4_base(unsigned col, bool alpha=false)
Definition color.h:75
float z
Definition color.h:53
float r
Definition color.h:45
float l
Definition color.h:53
float w
Definition color.h:57
float s
Definition color.h:49
constexpr unsigned Pack(bool Alpha=true) const
Definition color.h:97
constexpr color4_base()
Definition color.h:60
float a
Definition color.h:57
constexpr DerivedT WithMultipliedAlpha(float alpha) const
Definition color.h:116
constexpr color4_base(float nx, float ny, float nz)
Definition color.h:70
constexpr float & operator[](int index)
Definition color.h:89
constexpr DerivedT WithAlpha(float alpha) const
Definition color.h:109
constexpr bool operator==(const color4_base &col) const
Definition color.h:94
float v
Definition color.h:53
constexpr unsigned PackAlphaLast(bool Alpha=true) const
Definition color.h:102
float y
Definition color.h:49
float g
Definition color.h:49
constexpr T color_invert(const T &col)
Definition color.h:303
constexpr float RgbToHue(float r, float g, float b)
Definition color.h:18
std::optional< T > color_parse(const char *pStr)
Definition color.cpp:6
constexpr T color_cast(const F &)=delete
constexpr T color_scale(const T &col, float s)
Definition color.h:297
static SHA256_DIGEST s(const char *pSha256)
Definition mapbugs.cpp:38
constexpr int round_to_int(float f)
Definition math.h:17
constexpr int round_truncate(float f)
Definition math.h:22
constexpr T absolute(T a)
Definition math.h:138