hyperion.ng/include/utils/ColorRgb.h

58 lines
1.5 KiB
C
Raw Normal View History

#pragma once
// STL includes
#include <cstdint>
#include <iostream>
struct ColorRgb;
2013-09-09 04:54:13 +02:00
///
/// 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 ColorRgb
{
2013-09-09 04:54:13 +02:00
/// The red color channel
uint8_t red;
2013-09-09 04:54:13 +02:00
/// The green color channel
uint8_t green;
2013-09-09 04:54:13 +02:00
/// The blue color channel
uint8_t blue;
2013-09-09 04:54:13 +02:00
/// 'Black' RgbColor (0, 0, 0)
static ColorRgb BLACK;
2013-09-09 04:54:13 +02:00
/// 'Red' RgbColor (255, 0, 0)
static ColorRgb RED;
2013-09-09 04:54:13 +02:00
/// 'Green' RgbColor (0, 255, 0)
static ColorRgb GREEN;
2013-09-09 04:54:13 +02:00
/// 'Blue' RgbColor (0, 0, 255)
static ColorRgb BLUE;
2013-09-09 04:54:13 +02:00
/// 'Yellow' RgbColor (255, 255, 0)
static ColorRgb YELLOW;
2013-09-09 04:54:13 +02:00
/// 'White' RgbColor (255, 255, 255)
static ColorRgb WHITE;
};
2013-09-09 04:54:13 +02:00
/// Assert to ensure that the size of the structure is 'only' 3 bytes
static_assert(sizeof(ColorRgb) == 3, "Incorrect size of ColorRgb");
2013-09-09 04:54:13 +02:00
///
/// Stream operator to write ColorRgb to an outputstream (format "'{'[red]','[green]','[blue]'}'")
2013-09-09 04:54:13 +02:00
///
/// @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 ColorRgb& color)
{
os << "{" << unsigned(color.red) << "," << unsigned(color.green) << "," << unsigned(color.blue) << "}";
return os;
}
/// Compare operator to check if a color is 'smaller' than another color
inline bool operator<(const ColorRgb & lhs, const ColorRgb & rhs)
{
return (lhs.red < rhs.red) && (lhs.green < rhs.green) && (lhs.blue < rhs.blue);
}