2016-05-31 22:55:56 +02:00
|
|
|
#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)
|
2020-08-08 13:22:37 +02:00
|
|
|
static const ColorRgbw BLACK;
|
2016-05-31 22:55:56 +02:00
|
|
|
/// 'Red' RgbColor (255, 0, 0, 0)
|
2020-08-08 13:22:37 +02:00
|
|
|
static const ColorRgbw RED;
|
2016-05-31 22:55:56 +02:00
|
|
|
/// 'Green' RgbColor (0, 255, 0, 0)
|
2020-08-08 13:22:37 +02:00
|
|
|
static const ColorRgbw GREEN;
|
2016-05-31 22:55:56 +02:00
|
|
|
/// 'Blue' RgbColor (0, 0, 255, 0)
|
2020-08-08 13:22:37 +02:00
|
|
|
static const ColorRgbw BLUE;
|
2016-05-31 22:55:56 +02:00
|
|
|
/// 'Yellow' RgbColor (255, 255, 0, 0)
|
2020-08-08 13:22:37 +02:00
|
|
|
static const ColorRgbw YELLOW;
|
2016-05-31 22:55:56 +02:00
|
|
|
/// 'White' RgbColor (0, 0, 0, 255)
|
2020-08-08 13:22:37 +02:00
|
|
|
static const ColorRgbw WHITE;
|
2016-05-31 22:55:56 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/// 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)
|
|
|
|
{
|
2020-08-08 13:22:37 +02:00
|
|
|
os << "{"
|
|
|
|
<< color.red << ","
|
|
|
|
<< color.green << ","
|
|
|
|
<< color.blue << ","
|
|
|
|
<< color.white <<
|
|
|
|
"}";
|
|
|
|
|
2016-05-31 22:55:56 +02:00
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
2020-08-08 13:22:37 +02:00
|
|
|
/// Compare operator to check if a color is 'equal' 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;
|
|
|
|
}
|
2016-05-31 22:55:56 +02:00
|
|
|
|
|
|
|
/// Compare operator to check if a color is 'smaller' than another color
|
|
|
|
inline bool operator<(const ColorRgbw & lhs, const ColorRgbw & rhs)
|
|
|
|
{
|
2020-08-08 13:22:37 +02:00
|
|
|
return lhs.red < rhs.red &&
|
|
|
|
lhs.green < rhs.green &&
|
|
|
|
lhs.blue < rhs.blue &&
|
|
|
|
lhs.white < rhs.white;
|
2016-05-31 22:55:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Compare operator to check if a color is 'smaller' than or 'equal' to another color
|
|
|
|
inline bool operator<=(const ColorRgbw & lhs, const ColorRgbw & rhs)
|
|
|
|
{
|
2020-08-08 13:22:37 +02:00
|
|
|
return lhs < rhs || lhs == rhs;
|
2016-05-31 22:55:56 +02:00
|
|
|
}
|