28 #include <type_traits> 31 #include "Portability.h" 35 #ifndef DOXYGEN_SHOULD_SKIP_THIS 58 static_assert(std::is_floating_point<T>::value,
"T must be a floating point type.");
75 static constexpr HSV convertRgbToHsv(
Color4<T> color) {
78 std::tie(min, max) = std::minmax({ color.
r, color.
g, color.
b });
82 if ((max - min) > std::numeric_limits<T>::epsilon()) {
84 hue = std::fmod(60 * (color.
g - color.
b) / (max - min) + 360, 360);
85 }
else if (max == color.
g) {
86 hue = 60 * (color.
b - color.
r) / (max - min) + 120;
87 }
else if (max == color.
b) {
88 hue = 60 * (color.
r - color.
g) / (max - min) + 240;
94 T sat = (max < std::numeric_limits<T>::epsilon()) ? 0 : (1 - min / max);
97 return { hue, sat, val, color.
a };
103 static constexpr
Color4<T> convertHsvToRgb(HSV hsv) {
108 int i =
static_cast<int>(hue) % 6;
109 assert(0 <= i && i < 6);
113 T x = val * (1 - sat);
114 T y = val * (1 - (f * sat));
115 T z = val * (1 - ((1 - f) * sat));
212 return {
T(1),
T(1),
T(1), value };
221 return { value, value, value,
T(1) };
266 assert(0.0f <= percent && percent <= 1.0f);
267 HSV hsv = convertRgbToHsv(color);
268 hsv.v += hsv.v * percent;
271 hsv.s -= (hsv.v - 1);
280 return convertHsvToRgb(hsv);
294 assert(0.0f <= percent && percent <= 1.0f);
295 HSV hsv = convertRgbToHsv(color);
296 hsv.v -= hsv.v * percent;
297 return convertHsvToRgb(hsv);
322 return { r /
T(255), g /
T(255), b /
T(255), a /
T(255) };
332 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));
342 return fromRgba32(color.
r, color.
g, color.
b, color.
a);
353 static_cast<uint8_t
>(color.
r * 255),
354 static_cast<uint8_t>(color.
g * 255),
355 static_cast<uint8_t
>(color.
b * 255),
356 static_cast<uint8_t>(color.
a * 255)
361 #ifndef DOXYGEN_SHOULD_SKIP_THIS 418 #ifndef DOXYGEN_SHOULD_SKIP_THIS ColorBase< float > ColorF
Instantiation of ColoBase for float
Definition: Color.h:402
static constexpr Color4< T > lighter(Color4< T > color, T percent=T(0.5))
Compute a lighter color.
Definition: Color.h:265
static constexpr Color4< T > Gray(T value=T(0.5))
Gray predefined color.
Definition: Color.h:220
T a
Fourth coordinate in the (r,g,b,a) representation.
Definition: Vector.h:1086
static constexpr Color4< T > fromRgba32(uint32_t color)
Get a color from 32-bit value.
Definition: Color.h:331
The namespace for gf classes.
Definition: Action.h:35
A blue and light gray style.
T g
Second coordinate in the (r,g,b,a) representation.
Definition: Vector.h:1070
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:321
A 4D vector.
Definition: Vector.h:838
static constexpr Color4u toRgba32(Color4< T > color)
Convert a color to a 32-bit color.
Definition: Color.h:351
Predefined colors and utilities.
Definition: Color.h:57
T b
Third coordinate in the (r,g,b,a) representation.
Definition: Vector.h:1078
static constexpr Color4< T > fromRgb(T r, T g, T b)
Get an opaque color from 3 RGB floats in .
Definition: Color.h:308
static constexpr Color4< T > Opaque(T value=T(0.5))
Opaque predefined color.
Definition: Color.h:211
static constexpr Color4< T > darker(Color4< T > color, T percent=T(0.5))
Compute a darker color.
Definition: Color.h:293
T r
First coordinate in the (r,g,b,a) representation.
Definition: Vector.h:1062
static constexpr Color4< T > fromRgba32(Color4u color)
Get a color from a 32-bit color.
Definition: Color.h:341