Color APIs
The color.hpp header provides two classes for performing color management, interpolation, and conversion - espp::Rgb and espp::Hsv which can be converted between each other. The RGB color space provides support for additive blending (which includes averaging, as opposed to light-model-based mixing) and is therefore suited for producing gradients.
Please see Computer Graphics and Geometric Modeling: Implementation and Algorithms, specifically section 8.6 for more information.
API Reference
Header File
Classes
-
class Rgb
Class representing a color using RGB color space.
Public Functions
-
explicit Rgb(const float &r, const float &g, const float &b)
Construct an Rgb object from the provided rgb values.
Note
If provided values outside the range [0,1], it will rescale them to be within the range [0,1] by dividing by 255.
- Parameters
r – Floating point value for the red channel, should be in range [0, 1]
g – Floating point value for the green channel, should be in range [0, 1]
b – Floating point value for the blue channel, should be in range [0, 1]
-
Rgb(const Rgb &rgb)
Copy-construct an Rgb object from the provided object.
Note
If provided values outside the range [0,1], it will rescale them to be within the range [0,1] by dividing by 255.
- Parameters
rgb – Rgb struct containing the values to copy.
-
explicit Rgb(const Hsv &hsv)
Construct an Rgb object from the provided Hsv object.
Note
This calls hsv.rgb() on the provided object, which means that invalid HSV data (not in the ranges [0,360], [0,1], and [0,1]) could lead to bad RGB data. The Rgb constructor will automatically convert the values to be in the proper range, but the perceived color will be changed.
- Parameters
hsv – Hsv object to copy.
-
explicit Rgb(const uint32_t &hex)
Construct an Rgb object from the provided hex value.
- Parameters
hex – Hex value to convert to RGB. The hex value should be in the format 0xRRGGBB.
-
Rgb &operator=(const Rgb &other) = default
Assign the values of the provided Rgb object to this Rgb object.
- Parameters
other – The Rgb object to copy.
-
Rgb &operator=(const Hsv &hsv)
Assign the values of the provided Hsv object to this Rgb object.
Note
This calls hsv.rgb() on the provided object, which means that invalid HSV data (not in the ranges [0,360], [0,1], and [0,1])
-
Rgb operator+(const Rgb &rhs) const
Perform additive color blending (averaging)
- Parameters
rhs – Other color to add to this color to create the resultant color
- Returns
Resultant color from blending this color with the
rhs
color.
-
Rgb &operator+=(const Rgb &rhs)
Perform additive color blending (averaging)
- Parameters
rhs – Other color to add to this color
-
Hsv hsv() const
Get a HSV representation of this RGB color.
- Returns
An HSV object containing the HSV representation.
-
uint32_t hex() const
Get the hex representation of this RGB color.
- Returns
The hex representation of this RGB color.
-
explicit Rgb(const float &r, const float &g, const float &b)
-
class Hsv
Class representing a color using HSV color space.
Public Functions
-
explicit Hsv(const float &h, const float &s, const float &v)
Construct a Hsv object from the provided values.
- Parameters
h – Hue - will be clamped to be in range [0, 360]
s – Saturation - will be clamped to be in range [0, 1]
v – Value - will be clamped to be in range [0, 1]
-
explicit Hsv(const Rgb &rgb)
Construct Hsv object from Rgb object. Calls rgb.hsv() to perform the conversion.
- Parameters
rgb – The Rgb object to convert and copy.
-
Hsv &operator=(const Hsv &other) = default
Assign the values of the provided Hsv object to this Hsv object.
- Parameters
other – The Hsv object to copy.
-
explicit Hsv(const float &h, const float &s, const float &v)