28 #include <type_traits> 34 #ifndef DOXYGEN_SHOULD_SKIP_THIS 57 static_assert(std::is_floating_point<T>::value,
"T must be a floating point type.");
74 static constexpr HSV convertRgbToHsv(
Color4<T> color) {
77 std::tie(min, max) = std::minmax({ color.
r, color.
g, color.
b });
81 if ((max - min) > std::numeric_limits<T>::epsilon()) {
83 hue = std::fmod(
T(60) * (color.
g - color.
b) / (max - min) +
T(360),
T(360));
84 }
else if (max == color.
g) {
85 hue =
T(60) * (color.
b - color.
r) / (max - min) +
T(120);
86 }
else if (max == color.
b) {
87 hue =
T(60) * (color.
r - color.
g) / (max - min) +
T(240);
93 T sat = (max < std::numeric_limits<T>::epsilon()) ?
T(0) : (
T(1) - min / max);
96 return { hue, sat, val, color.
a };
102 static constexpr
Color4<T> convertHsvToRgb(HSV hsv) {
103 T hue = hsv.h /
T(60);
107 int i =
static_cast<int>(hue) % 6;
108 assert(0 <= i && i < 6);
110 T f = hue -
static_cast<T>(i);
112 T x = val * (
T(1) - sat);
113 T y = val * (
T(1) - (f * sat));
114 T z = val * (
T(1) - ((
T(1) - f) * sat));
211 return {
T(1),
T(1),
T(1), value };
220 return { value, value, value,
T(1) };
265 assert(0.0f <= percent && percent <= 1.0f);
266 HSV hsv = convertRgbToHsv(color);
267 hsv.v += hsv.v * percent;
270 hsv.s -= (hsv.v - 1);
279 return convertHsvToRgb(hsv);
293 assert(0.0f <= percent && percent <= 1.0f);
294 HSV hsv = convertRgbToHsv(color);
295 hsv.v -= hsv.v * percent;
296 return convertHsvToRgb(hsv);
321 return { r /
T(255), g /
T(255), b /
T(255), a /
T(255) };
331 return fromRgba32(static_cast<uint8_t>(color >> 24), static_cast<uint8_t>(color >> 16), static_cast<uint8_t>(color >> 8), static_cast<uint8_t>(color));
341 return fromRgba32(color.
r, color.
g, color.
b, color.
a);
352 static_cast<uint8_t
>(color.
r * 255),
353 static_cast<uint8_t>(color.
g * 255),
354 static_cast<uint8_t
>(color.
b * 255),
355 static_cast<uint8_t>(color.
a * 255)
360 #ifndef DOXYGEN_SHOULD_SKIP_THIS 417 #ifndef DOXYGEN_SHOULD_SKIP_THIS static constexpr Color4< T > lighter(Color4< T > color, T percent=T(0.5))
Compute a lighter color.
Definition: Color.h:264
static constexpr Color4< T > Gray(T value=T(0.5))
Gray predefined color.
Definition: Color.h:219
T a
Fourth coordinate in the (r,g,b,a) representation.
Definition: Vector.h:1107
ColorBase< float > ColorF
Instantiation of ColoBase for float
Definition: Color.h:401
static constexpr Color4< T > fromRgba32(uint32_t color)
Get a color from 32-bit value.
Definition: Color.h:330
The namespace for gf classes.
Definition: Action.h:35
T g
Second coordinate in the (r,g,b,a) representation.
Definition: Vector.h:1091
static constexpr Color4< T > fromRgba32(uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
Get a color from 4 8-bit channels.
Definition: Color.h:320
A 4D vector.
Definition: Vector.h:852
static constexpr Color4u toRgba32(Color4< T > color)
Convert a color to a 32-bit color.
Definition: Color.h:350
Predefined colors and utilities.
Definition: Color.h:56
T b
Third coordinate in the (r,g,b,a) representation.
Definition: Vector.h:1099
static constexpr Color4< T > fromRgb(T r, T g, T b)
Get an opaque color from 3 RGB floats in .
Definition: Color.h:307
static constexpr Color4< T > Opaque(T value=T(0.5))
Opaque predefined color.
Definition: Color.h:210
static constexpr Color4< T > darker(Color4< T > color, T percent=T(0.5))
Compute a darker color.
Definition: Color.h:292
T r
First coordinate in the (r,g,b,a) representation.
Definition: Vector.h:1083
static constexpr Color4< T > fromRgba32(Color4u color)
Get a color from a 32-bit color.
Definition: Color.h:340