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
ColorBase< float > ColorF
Instantiation of ColoBase for float
Definition: Color.h:401
@ Transparent
The cell is transparent.
constexpr ZeroType Zero
Constant to represent "zero".
Definition: Types.h:93
The namespace for gf classes.
Predefined colors and utilities.
Definition: Color.h:56
static constexpr Color4< T > Violet
Violet predefined color.
Definition: Color.h:246
static constexpr Color4< T > Yellow
Yellow predefined color.
Definition: Color.h:198
static constexpr Color4< T > Transparent
Transparent (black) predefined color.
Definition: Color.h:203
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 > Green
Green predefined color.
Definition: Color.h:178
static constexpr Color4< T > White
White predefined color.
Definition: Color.h:168
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
static constexpr Color4< T > Azure
Azure predefined color.
Definition: Color.h:251
static constexpr Color4< T > Gray(T value=T(0.5))
Gray predefined color.
Definition: Color.h:219
static constexpr Color4< T > Orange
Orange predefined color.
Definition: Color.h:226
static constexpr Color4< T > fromRgba32(Color4u color)
Get a color from a 32-bit color.
Definition: Color.h:340
static constexpr Color4< T > fromRgba32(uint32_t color)
Get a color from 32-bit value.
Definition: Color.h:330
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 > Opaque(T value=T(0.5))
Opaque predefined color.
Definition: Color.h:210
static constexpr Color4u toRgba32(Color4< T > color)
Convert a color to a 32-bit color.
Definition: Color.h:350
static constexpr Color4< T > darker(Color4< T > color, T percent=T(0.5))
Compute a darker color.
Definition: Color.h:292
static constexpr Color4< T > Cyan
Cyan predefined color.
Definition: Color.h:188
static constexpr Color4< T > Red
Red predefined color.
Definition: Color.h:173
static constexpr Color4< T > Black
Black predefined color.
Definition: Color.h:163
static constexpr Color4< T > Blue
Blue predefined color.
Definition: Color.h:183
static constexpr Color4< T > Magenta
Magenta predefined color.
Definition: Color.h:193
static constexpr Color4< T > Chartreuse
Chartreuse predefined color.
Definition: Color.h:236
static constexpr Color4< T > Spring
Spring (green) predefined color.
Definition: Color.h:241
static constexpr Color4< T > Rose
Rose predefined color.
Definition: Color.h:231
A 4D vector.
Definition: Vector.h:852