hyperion.ng/include/utils/ColorRgbw.h

64 lines
1.9 KiB
C
Raw Normal View History

#pragma once
// STL includes
#include <cstdint>
#include <iostream>
///
/// Plain-Old-Data structure containing the red-green-blue color specification. Size of the
/// structure is exactly 3-bytes for easy writing to led-device
///
struct ColorRgbw
{
/// The red color channel
uint8_t red;
/// The green color channel
uint8_t green;
/// The blue color channel
uint8_t blue;
/// The white color channel
uint8_t white;
/// 'Black' RgbColor (0, 0, 0, 0)
static ColorRgbw BLACK;
/// 'Red' RgbColor (255, 0, 0, 0)
static ColorRgbw RED;
/// 'Green' RgbColor (0, 255, 0, 0)
static ColorRgbw GREEN;
/// 'Blue' RgbColor (0, 0, 255, 0)
static ColorRgbw BLUE;
/// 'Yellow' RgbColor (255, 255, 0, 0)
static ColorRgbw YELLOW;
/// 'White' RgbColor (0, 0, 0, 255)
static ColorRgbw WHITE;
};
/// Assert to ensure that the size of the structure is 'only' 4 bytes
static_assert(sizeof(ColorRgbw) == 4, "Incorrect size of ColorRgbw");
///
/// Stream operator to write ColorRgb to an outputstream (format "'{'[red]','[green]','[blue]'}'")
///
/// @param os The output stream
/// @param color The color to write
/// @return The output stream (with the color written to it)
///
inline std::ostream& operator<<(std::ostream& os, const ColorRgbw& color)
{
os << "{" << unsigned(color.red) << "," << unsigned(color.green) << "," << unsigned(color.blue) << "," << unsigned(color.white) << "}";
return os;
}
/// Compare operator to check if a color is 'smaller' than another color
inline bool operator<(const ColorRgbw & lhs, const ColorRgbw & rhs)
{
return (lhs.red < rhs.red) && (lhs.green < rhs.green) && (lhs.blue < rhs.blue) && (lhs.white < rhs.white);
}
/// Compare operator to check if a color is 'smaller' than or 'equal' to another color
inline bool operator<=(const ColorRgbw & lhs, const ColorRgbw & rhs)
{
return (lhs.red <= rhs.red) && (lhs.green <= rhs.green) && (lhs.blue <= rhs.blue) && (lhs.white < rhs.white);
}