1 #include "lxgui/gui_color.hpp"
3 #include "lxgui/utils.hpp"
4 #include "lxgui/utils_string.hpp"
22 std::istringstream ss(s);
27 float ma = std::max(std::max(
r,
g),
b);
28 float mi = std::min(std::min(
r,
g),
b);
37 float delta = ma - mi;
40 output.l = 0.5f * sum;
42 output.s = delta / sum;
44 output.s = delta / (2.0f - sum);
47 output.h = 60.0f * (
g -
b) / delta + 0.0f;
49 output.h = 60.0f * (
b -
r) / delta + 120.0f;
51 output.h = 60.0f * (
r -
g) / delta + 240.0f;
54 output.h = output.h + 360.0f;
55 else if (output.h > 360.0f)
56 output.h = output.h - 360.0f;
70 output.h = 60.0f * std::fmod((
g -
b) / (cmax - cmin), 6.0f);
71 }
else if (
g >
r &&
g >
b) {
74 output.h = 60.0f * ((
b -
r) / (cmax - cmin) + 2.0f);
75 }
else if (
b >
r &&
b >
g) {
78 output.h = 60.0f * ((
r -
g) / (cmax - cmin) + 4.0f);
86 output.s = (cmax - cmin) / cmax;
92 float h2_to_rgb(
float v1,
float v2,
float h) noexcept {
99 return v1 + (v2 - v1) * h / 60.0f;
103 return v1 + (v2 - v1) * (4.0f - h / 60.0f);
123 float v1 = 2.0f *
hls.
l - v2;
135 const channel x = t * (1.0f - std::abs(std::fmod(
hsv.
h / 60.0f, 2.0f) - 1.0f));
138 const channel low = std::clamp(m, 0.0f, 1.0f);
139 const channel mid = std::clamp(
x + m, 0.0f, 1.0f);
140 const channel hig = std::clamp(t + m, 0.0f, 1.0f);
144 else if (
hsv.
h < 120.0f)
146 else if (
hsv.
h < 180.0f)
148 else if (
hsv.
h < 240.0f)
150 else if (
hsv.
h < 300.0f)
157 return (r == c.r && g == c.g && b == c.b && a == c.a);
161 return (r != c.r || g != c.g || b != c.b || a != c.a);
193 return color(c1.r + c2.r, c1.g + c2.g, c1.b + c2.b, c1.a + c2.a);
197 return color(c1.r - c2.r, c1.g - c2.g, c1.b - c2.b, c1.a - c2.a);
201 return color(c1.r * c2.r, c1.g * c2.g, c1.b * c2.b, c1.a * c2.a);
205 return color(c1.r * f, c1.g * f, c1.b * f, c1.a);
209 return color(f * c2.r, f * c2.g, f * c2.b, c2.a);
213 return stream << static_cast<std::size_t>(std::round(255.0f * c.
r)) <<
", "
214 <<
static_cast<std::size_t
>(std::round(255.0f * c.
g)) <<
", "
215 <<
static_cast<std::size_t
>(std::round(255.0f * c.
b)) <<
", "
216 <<
static_cast<std::size_t
>(std::round(255.0f * c.
a));
220 auto pos = stream.tellg();
222 stream >> start_char;
223 if (start_char ==
'#') {
226 stream >> h[0] >> h[1];
227 c.
r = utils::hex_to_uint(h) / 255.0f;
228 stream >> h[0] >> h[1];
229 c.
g = utils::hex_to_uint(h) / 255.0f;
230 stream >> h[0] >> h[1];
231 c.
b = utils::hex_to_uint(h) / 255.0f;
233 pos = stream.tellg();
236 if (std::isalnum(h[0]) != 0 && !stream.eof()) {
238 if (std::isalnum(h[1]) != 0) {
239 c.
a = utils::hex_to_uint(h) / 255.0f;
250 stream >> c.
r >> delim >> c.
g >> delim >> c.
b >> delim >> c.
a;
Holds a single color (float RGBA, 128 bits)
void operator*=(const color &c) noexcept
bool operator==(const color &c) const noexcept
hsv to_hsv() const noexcept
static color from_hls(const hls &hls) noexcept
static color from_hsv(const hsv &hsv) noexcept
constexpr color()=default
bool operator!=(const color &c) const noexcept
void operator-=(const color &c) noexcept
hls to_hls() const noexcept
void operator+=(const color &c) noexcept
std::ostream & operator<<(std::ostream &stream, const color &c)
std::istream & operator>>(std::istream &stream, color &c)
float h2_to_rgb(float v1, float v2, float h) noexcept
color operator+(const color &c1, const color &c2) noexcept
color operator*(const color &c1, const color &c2) noexcept
color operator-(const color &c1, const color &c2) noexcept