17inline 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>
98 a = alpha ? ((col >> 24) & 0xFF) / 255.0f : 1.0f;
99 x = ((col >> 16) & 0xFF) / 255.0f;
100 y = ((col >> 8) & 0xFF) / 255.0f;
101 z = ((col >> 0) & 0xFF) / 255.0f;
108 return ((
float *)
this)[index];
114 unsigned Pack(
bool Alpha =
true)
const
128 DerivedT col(
static_cast<const DerivedT &
>(*
this));
135 DerivedT col(
static_cast<const DerivedT &
>(*
this));
142 DerivedT Color(
static_cast<const DerivedT &
>(*
this));
150 template<
typename UnpackT>
156 Result.x = ((Color >> 24) & 0xFF) / 255.0f;
157 Result.y = ((Color >> 16) & 0xFF) / 255.0f;
158 Result.z = ((Color >> 8) & 0xFF) / 255.0f;
159 Result.a = ((Color >> 0) & 0xFF) / 255.0f;
163 Result.x = ((Color >> 16) & 0xFF) / 255.0f;
164 Result.y = ((Color >> 8) & 0xFF) / 255.0f;
165 Result.z = ((Color >> 0) & 0xFF) / 255.0f;
184 col.
l = Darkest + col.
l * (1.0f - Darkest);
188 unsigned Pack(
bool Alpha =
true)
const
193 unsigned Pack(
float Darkest,
bool Alpha =
false)
const
196 col.
l = (
l - Darkest) / (1 - Darkest);
197 col.
l = clamp(col.
l, 0.0f, 1.0f);
198 return col.
Pack(Alpha);
216template<
typename T,
typename F>
227 float l = 0.5f * (Max + Min);
228 float s = (Max != 0.0f && Min != 1.0f) ? (c / (1 - (
absolute(2 * l - 1)))) : 0;
238 float h1 = hsl.
h * 6;
239 float c = (1.f -
absolute(2 * hsl.
l - 1)) * hsl.
s;
240 float x = c * (1.f -
absolute(std::fmod(h1, 2) - 1.f));
271 float m = hsl.
l - (c / 2);
278 float l = hsv.
v * (1 - hsv.
s * 0.5f);
279 return ColorHSLA(hsv.
h, (l == 0.0f || l == 1.0f) ? 0 : (hsv.
v - l) /
minimum(l, 1 - l), l, hsv.
a);
285 float v = hsl.
l + hsl.
s *
minimum(hsl.
l, 1 - hsl.
l);
286 return ColorHSVA(hsl.
h, v == 0.0f ? 0 : 2 - (2 * hsl.
l / v), v, hsl.
a);
292 return color_cast<ColorRGBA>(color_cast<ColorHSLA>(hsv));
298 return color_cast<ColorHSVA>(color_cast<ColorHSLA>(rgb));
304 return T(col.x *
s, col.y *
s, col.z *
s, col.a *
s);
310 return T(1.0f - col.x, 1.0f - col.y, 1.0f - col.z, 1.0f - col.a);
ColorHSLA UnclampLighting(float Darkest) const
Definition: color.h:181
static constexpr const float DARKEST_LGT7
Definition: color.h:179
static constexpr const float DARKEST_LGT
Definition: color.h:178
ColorHSLA()
Definition: color.h:176
unsigned Pack(bool Alpha=true) const
Definition: color.h:188
unsigned Pack(float Darkest, bool Alpha=false) const
Definition: color.h:193
ColorHSVA()
Definition: color.h:206
ColorRGBA()
Definition: color.h:213
color4_base(float nx, float ny, float nz)
Definition: color.h:88
DerivedT WithAlpha(float alpha) const
Definition: color.h:126
float h
Definition: color.h:44
unsigned PackAlphaLast(bool Alpha=true) const
Definition: color.h:119
color4_base()
Definition: color.h:59
float b
Definition: color.h:52
float x
Definition: color.h:44
float z
Definition: color.h:52
static UnpackT UnpackAlphaLast(unsigned Color, bool Alpha=true)
Definition: color.h:151
float & operator[](int index)
Definition: color.h:106
float r
Definition: color.h:44
float l
Definition: color.h:52
bool operator!=(const color4_base &col) const
Definition: color.h:112
float w
Definition: color.h:56
color4_base(const vec4 &v4)
Definition: color.h:64
color4_base(const vec3 &v3)
Definition: color.h:72
float s
Definition: color.h:48
float a
Definition: color.h:56
unsigned Pack(bool Alpha=true) const
Definition: color.h:114
bool operator==(const color4_base &col) const
Definition: color.h:111
vec4 v4() const
Definition: color.h:104
float v
Definition: color.h:52
DerivedT Multiply(const DerivedT &Other) const
Definition: color.h:140
float y
Definition: color.h:48
float g
Definition: color.h:48
color4_base(float nx, float ny, float nz, float na)
Definition: color.h:80
DerivedT WithMultipliedAlpha(float alpha) const
Definition: color.h:133
color4_base(unsigned col, bool alpha=false)
Definition: color.h:96
T z
Definition: vmath.h:194
T x
Definition: vmath.h:186
T y
Definition: vmath.h:190
T r
Definition: vmath.h:186
T g
Definition: vmath.h:190
T b
Definition: vmath.h:194
T w
Definition: vmath.h:318
T z
Definition: vmath.h:314
T y
Definition: vmath.h:310
T x
Definition: vmath.h:306
float RgbToHue(float r, float g, float b)
Definition: color.h:17
T color_invert(const T &col)
Definition: color.h:308
T color_cast(const F &)=delete
std::optional< T > color_parse(const char *pStr)
Definition: color.cpp:5
T color_scale(const T &col, float s)
Definition: color.h:302
static SHA256_DIGEST s(const char *pSha256)
Definition: mapbugs.cpp:37
constexpr T minimum(T a, T b)
Definition: math.h:120
constexpr int round_to_int(float f)
Definition: math.h:14
constexpr T maximum(T a, T b)
Definition: math.h:130
constexpr int round_truncate(float f)
Definition: math.h:19
constexpr T absolute(T a)
Definition: math.h:140
vector3_base< float > vec3
Definition: vmath.h:294
vector4_base< float > vec4
Definition: vmath.h:388