hueplusplus  1.0.0
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 
28 namespace 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 
47 struct 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 {
65  XY xy;
67  float brightness;
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 
77 struct ColorGamut
78 {
85 
87  bool contains(const XY& xy) const;
90  XY corrected(const XY& xy) const;
91 };
92 
94 namespace gamut
95 {
97 constexpr ColorGamut gamutA {{0.704f, 0.296f}, {0.2151f, 0.7106f}, {0.138f, 0.08f}};
99 constexpr ColorGamut gamutB {{0.675f, 0.322f}, {0.409f, 0.518f}, {0.167f, 0.04f}};
101 constexpr ColorGamut gamutC {{0.692f, 0.308f}, {0.17f, 0.7f}, {0.153f, 0.048f}};
105 constexpr ColorGamut maxGamut {{1.f, 0.f}, {0.f, 1.f}, {0.f, 0.f}};
106 } // namespace gamut
107 
109 struct 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 
133  HueSaturation toHueSaturation() const;
134 
140  static RGB fromXY(const XYBrightness& xy);
148  static RGB fromXY(const XYBrightness& xy, const ColorGamut& gamut);
149 };
150 
155 unsigned int kelvinToMired(unsigned int kelvin);
156 
161 unsigned int miredToKelvin(unsigned int mired);
162 } // namespace hueplusplus
163 
164 #endif
bool operator!=(const XYBrightness &other) const
Definition: ColorUnits.h:70
bool operator!=(const HueSaturation &other) const
Definition: ColorUnits.h:43
Color in RGB.
Definition: ColorUnits.h:109
Namespace for the hueplusplus library.
Definition: Action.h:27
constexpr ColorGamut maxGamut
Maximal gamut to be used when unknown.
Definition: ColorUnits.h:105
bool operator!=(const XY &other) const
Definition: ColorUnits.h:55
float y
y coordinate in CIE, 0 to 1
Definition: ColorUnits.h:52
uint8_t r
Red amount from 0 to 255.
Definition: ColorUnits.h:112
bool operator==(const RGB &other) const
Definition: ColorUnits.h:118
bool operator==(const XY &other) const
Definition: ColorUnits.h:54
unsigned int miredToKelvin(unsigned int mired)
Const function that converts Mired to Kelvin.
Definition: ColorUnits.cpp:243
int hue
Color hue.
Definition: ColorUnits.h:36
int saturation
Color saturation.
Definition: ColorUnits.h:40
constexpr ColorGamut gamutC
Gamut C, used by newer Extended Color Lights.
Definition: ColorUnits.h:101
uint8_t b
Blue amount from 0 to 255.
Definition: ColorUnits.h:116
bool operator==(const XYBrightness &other) const
Definition: ColorUnits.h:69
Color and brightness in CIE.
Definition: ColorUnits.h:62
XY blueCorner
Blue corner in the color triangle.
Definition: ColorUnits.h:84
XY redCorner
Red corner in the color triangle.
Definition: ColorUnits.h:80
uint8_t g
Green amount from 0 to 255.
Definition: ColorUnits.h:114
bool operator!=(const RGB &other) const
Definition: ColorUnits.h:119
XY greenCorner
Green corner in the color triangle.
Definition: ColorUnits.h:82
Color in CIE x and y coordinates.
Definition: ColorUnits.h:47
float brightness
Brightness from 0 to 1.
Definition: ColorUnits.h:67
Triangle of representable colors in CIE.
Definition: ColorUnits.h:77
bool operator==(const HueSaturation &other) const
Definition: ColorUnits.h:42
XY xy
XY color.
Definition: ColorUnits.h:65
constexpr ColorGamut gamutA
Gamut A, used by most Color Lights.
Definition: ColorUnits.h:97
Color in hue and saturation.
Definition: ColorUnits.h:31
unsigned int kelvinToMired(unsigned int kelvin)
Const function that converts Kelvin to Mired.
Definition: ColorUnits.cpp:238
float x
x coordinate in CIE, 0 to 1
Definition: ColorUnits.h:50
constexpr ColorGamut gamutB
Gamut B, used by older Extended Color Lights.
Definition: ColorUnits.h:99