hueplusplus 1.2.0
Loading...
Searching...
No Matches
ColorUnits.h
Go to the documentation of this file.
1
23#ifndef INCLUDE_HUEPLUSPLUS_UNITS_H
24#define INCLUDE_HUEPLUSPLUS_UNITS_H
25
26#include <cstdint>
27
28namespace hueplusplus
29{
32{
36 int hue;
41
42 bool operator==(const HueSaturation& other) const { return hue == other.hue && saturation == other.saturation; }
43 bool operator!=(const HueSaturation& other) const { return !(*this == other); }
44};
45
47struct XY
48{
50 float x;
52 float y;
53
54 bool operator==(const XY& other) const { return x == other.x && y == other.y; }
55 bool operator!=(const XY& other) const { return !(*this == other); }
56};
57
63{
68
69 bool operator==(const XYBrightness& other) const { return xy == other.xy && brightness == other.brightness; }
70 bool operator!=(const XYBrightness& other) const { return !(*this == other); }
71};
72
78{
85
87 bool contains(const XY& xy) const;
90 XY corrected(const XY& xy) const;
91};
92
94namespace gamut
95{
97constexpr ColorGamut gamutA {{0.704f, 0.296f}, {0.2151f, 0.7106f}, {0.138f, 0.08f}};
99constexpr ColorGamut gamutB {{0.675f, 0.322f}, {0.409f, 0.518f}, {0.167f, 0.04f}};
101constexpr ColorGamut gamutC {{0.692f, 0.308f}, {0.17f, 0.7f}, {0.153f, 0.048f}};
105constexpr ColorGamut maxGamut {{1.f, 0.f}, {0.f, 1.f}, {0.f, 0.f}};
106} // namespace gamut
107
109struct RGB
110{
112 uint8_t r;
114 uint8_t g;
116 uint8_t b;
117
118 bool operator==(const RGB& other) const { return r == other.r && g == other.g && b == other.b; }
119 bool operator!=(const RGB& other) const { return !(*this == other); }
120
124 XYBrightness toXY() const;
128 XYBrightness toXY(const ColorGamut& gamut) const;
129
134
140 static RGB fromXY(const XYBrightness& xy);
148 static RGB fromXY(const XYBrightness& xy, const ColorGamut& gamut);
149};
150
155unsigned int kelvinToMired(unsigned int kelvin);
156
161unsigned int miredToKelvin(unsigned int mired);
162} // namespace hueplusplus
163
164#endif
constexpr ColorGamut gamutC
Gamut C, used by newer Extended Color Lights.
Definition ColorUnits.h:101
constexpr ColorGamut maxGamut
Maximal gamut to be used when unknown.
Definition ColorUnits.h:105
constexpr ColorGamut gamutB
Gamut B, used by older Extended Color Lights.
Definition ColorUnits.h:99
constexpr ColorGamut gamutA
Gamut A, used by most Color Lights.
Definition ColorUnits.h:97
Namespace for the hueplusplus library.
Definition Action.h:28
unsigned int kelvinToMired(unsigned int kelvin)
Const function that converts Kelvin to Mired.
Definition ColorUnits.cpp:238
unsigned int miredToKelvin(unsigned int mired)
Const function that converts Mired to Kelvin.
Definition ColorUnits.cpp:243
Triangle of representable colors in CIE.
Definition ColorUnits.h:78
bool contains(const XY &xy) const
Check whether xy is representable.
Definition ColorUnits.cpp:60
XY greenCorner
Green corner in the color triangle.
Definition ColorUnits.h:82
XY blueCorner
Blue corner in the color triangle.
Definition ColorUnits.h:84
XY corrected(const XY &xy) const
Correct xy to closest representable color.
Definition ColorUnits.cpp:66
XY redCorner
Red corner in the color triangle.
Definition ColorUnits.h:80
Color in hue and saturation.
Definition ColorUnits.h:32
bool operator==(const HueSaturation &other) const
Definition ColorUnits.h:42
int saturation
Color saturation.
Definition ColorUnits.h:40
int hue
Color hue.
Definition ColorUnits.h:36
bool operator!=(const HueSaturation &other) const
Definition ColorUnits.h:43
Color in RGB.
Definition ColorUnits.h:110
uint8_t g
Green amount from 0 to 255.
Definition ColorUnits.h:114
bool operator==(const RGB &other) const
Definition ColorUnits.h:118
uint8_t b
Blue amount from 0 to 255.
Definition ColorUnits.h:116
static RGB fromXY(const XYBrightness &xy)
Create from XYBrightness.
Definition ColorUnits.cpp:183
XYBrightness toXY() const
Convert to XYBrightness without clamping.
Definition ColorUnits.cpp:109
bool operator!=(const RGB &other) const
Definition ColorUnits.h:119
HueSaturation toHueSaturation() const
Convert to HueSaturation.
Definition ColorUnits.cpp:145
uint8_t r
Red amount from 0 to 255.
Definition ColorUnits.h:112
Color and brightness in CIE.
Definition ColorUnits.h:63
float brightness
Brightness from 0 to 1.
Definition ColorUnits.h:67
bool operator==(const XYBrightness &other) const
Definition ColorUnits.h:69
XY xy
XY color.
Definition ColorUnits.h:65
bool operator!=(const XYBrightness &other) const
Definition ColorUnits.h:70
Color in CIE x and y coordinates.
Definition ColorUnits.h:48
float y
y coordinate in CIE, 0 to 1
Definition ColorUnits.h:52
bool operator==(const XY &other) const
Definition ColorUnits.h:54
bool operator!=(const XY &other) const
Definition ColorUnits.h:55
float x
x coordinate in CIE, 0 to 1
Definition ColorUnits.h:50