17constexpr float RgbToHue(
float r,
float g,
float b)
25 float c = h_max - h_min;
27 hue = (g - b) / c + (g < b ? 6 : 0);
29 hue = (b - r) / c + 2;
31 hue = (r - g) / c + 4;
38template<
typename DerivedT>
64 constexpr color4_base(
float nx,
float ny,
float nz,
float na) :
65 x(nx),
y(ny),
z(nz),
a(na)
70 x(nx),
y(ny),
z(nz),
a(1.0f)
76 a = alpha ? ((col >> 24) & 0xFF) / 255.0f : 1.0f;
77 x = ((col >> 16) & 0xFF) / 255.0f;
78 y = ((col >> 8) & 0xFF) / 255.0f;
79 z = ((col >> 0) & 0xFF) / 255.0f;
84 template<
typename OtherDerivedT>
85 requires(!std::is_same_v<DerivedT, OtherDerivedT>)
90 return ((
float *)
this)[index];
96 constexpr unsigned Pack(
bool Alpha =
true)
const
110 DerivedT col(
static_cast<const DerivedT &
>(*
this));
117 DerivedT col(
static_cast<const DerivedT &
>(*
this));
122 template<
typename UnpackT>
128 Result.x = ((Color >> 24) & 0xFF) / 255.0f;
129 Result.y = ((Color >> 16) & 0xFF) / 255.0f;
130 Result.z = ((Color >> 8) & 0xFF) / 255.0f;
131 Result.a = ((Color >> 0) & 0xFF) / 255.0f;
135 Result.x = ((Color >> 16) & 0xFF) / 255.0f;
136 Result.y = ((Color >> 8) & 0xFF) / 255.0f;
137 Result.z = ((Color >> 0) & 0xFF) / 255.0f;
156 col.
l = Darkest + col.
l * (1.0f - Darkest);
160 constexpr unsigned Pack(
bool Alpha =
true)
const
165 constexpr unsigned Pack(
float Darkest,
bool Alpha =
false)
const
168 col.
l = (
l - Darkest) / (1 - Darkest);
169 col.
l = std::clamp(col.
l, 0.0f, 1.0f);
170 return col.
Pack(Alpha);
209template<
typename T,
typename F>
220 float l = 0.5f * (Max + Min);
221 float s = (Max != 0.0f && Min != 1.0f) ? (c / (1 - (
absolute(2 * l - 1)))) : 0;
229 float h1 = hsl.
h * 6;
230 float c = (1.f -
absolute(2 * hsl.
l - 1)) * hsl.
s;
231 float x = c * (1.f -
absolute(std::fmod(h1, 2) - 1.f));
265 float m = hsl.
l - (c / 2);
272 float l = hsv.
v * (1 - hsv.
s * 0.5f);
273 return ColorHSLA(hsv.
h, (l == 0.0f || l == 1.0f) ? 0 : (hsv.
v - l) /
minimum(l, 1 - l), l, hsv.
a);
279 float v = hsl.
l + hsl.
s *
minimum(hsl.
l, 1 - hsl.
l);
280 return ColorHSVA(hsl.
h, v == 0.0f ? 0 : 2 - (2 * hsl.
l / v), v, hsl.
a);
298 return T(col.x *
s, col.y *
s, col.z *
s, col.a *
s);
304 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:151
static constexpr const float DARKEST_LGT
Definition color.h:150
constexpr unsigned Pack(float Darkest, bool Alpha=false) const
Definition color.h:165
constexpr color4_base()
Definition color.h:59
constexpr unsigned Pack(bool Alpha=true) const
Definition color.h:160
constexpr ColorHSLA()=default
constexpr ColorHSLA UnclampLighting(float Darkest) const
Definition color.h:153
constexpr color4_base()
Definition color.h:59
constexpr ColorHSVA()=default
constexpr ColorRGBA Multiply(const T &Factor) const
Definition color.h:198
constexpr color4_base()
Definition color.h:59
constexpr ColorRGBA()=default
constexpr ColorRGBA Multiply(const ColorRGBA &Other) const
Definition color.h:187
static constexpr UnpackT UnpackAlphaLast(unsigned Color, bool Alpha=true)
Definition color.h:123
float h
Definition color.h:44
float b
Definition color.h:52
float x
Definition color.h:44
constexpr color4_base(float nx, float ny, float nz, float na)
Definition color.h:64
color4_base(const color4_base< OtherDerivedT > &Other)=delete
constexpr bool operator!=(const color4_base &col) const
Definition color.h:94
constexpr color4_base(unsigned col, bool alpha=false)
Definition color.h:74
float z
Definition color.h:52
float r
Definition color.h:44
float l
Definition color.h:52
float w
Definition color.h:56
float s
Definition color.h:48
constexpr unsigned Pack(bool Alpha=true) const
Definition color.h:96
constexpr color4_base()
Definition color.h:59
float a
Definition color.h:56
constexpr DerivedT WithMultipliedAlpha(float alpha) const
Definition color.h:115
constexpr color4_base(float nx, float ny, float nz)
Definition color.h:69
constexpr float & operator[](int index)
Definition color.h:88
constexpr DerivedT WithAlpha(float alpha) const
Definition color.h:108
constexpr bool operator==(const color4_base &col) const
Definition color.h:93
float v
Definition color.h:52
constexpr unsigned PackAlphaLast(bool Alpha=true) const
Definition color.h:101
float y
Definition color.h:48
float g
Definition color.h:48
constexpr T color_invert(const T &col)
Definition color.h:302
constexpr float RgbToHue(float r, float g, float b)
Definition color.h:17
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:296
static SHA256_DIGEST s(const char *pSha256)
Definition mapbugs.cpp:37
constexpr T minimum(T a, T b)
Definition math.h:137
constexpr int round_to_int(float f)
Definition math.h:16
constexpr T maximum(T a, T b)
Definition math.h:147
constexpr int round_truncate(float f)
Definition math.h:21
constexpr T absolute(T a)
Definition math.h:157