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