2013-07-26 22:38:34 +02:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
// STL includes
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
// Forward class declaration
|
|
|
|
struct RgbColor;
|
|
|
|
|
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
|
|
|
|
///
|
2013-07-26 22:38:34 +02:00
|
|
|
struct RgbColor
|
|
|
|
{
|
2013-09-09 04:54:13 +02:00
|
|
|
/// The red color channel
|
2013-07-26 22:38:34 +02:00
|
|
|
uint8_t red;
|
2013-09-09 04:54:13 +02:00
|
|
|
/// The green color channel
|
2013-07-26 22:38:34 +02:00
|
|
|
uint8_t green;
|
2013-09-09 04:54:13 +02:00
|
|
|
/// The blue color channel
|
2013-07-26 22:38:34 +02:00
|
|
|
uint8_t blue;
|
|
|
|
|
2013-09-09 04:54:13 +02:00
|
|
|
/// 'Black' RgbColor (0, 0, 0)
|
2013-07-26 22:38:34 +02:00
|
|
|
static RgbColor BLACK;
|
2013-09-09 04:54:13 +02:00
|
|
|
/// 'Red' RgbColor (255, 0, 0)
|
2013-07-26 22:38:34 +02:00
|
|
|
static RgbColor RED;
|
2013-09-09 04:54:13 +02:00
|
|
|
/// 'Green' RgbColor (0, 255, 0)
|
2013-07-26 22:38:34 +02:00
|
|
|
static RgbColor GREEN;
|
2013-09-09 04:54:13 +02:00
|
|
|
/// 'Blue' RgbColor (0, 0, 255)
|
2013-07-26 22:38:34 +02:00
|
|
|
static RgbColor BLUE;
|
2013-09-09 04:54:13 +02:00
|
|
|
/// 'Yellow' RgbColor (255, 255, 0)
|
2013-07-26 22:38:34 +02:00
|
|
|
static RgbColor YELLOW;
|
2013-09-09 04:54:13 +02:00
|
|
|
/// 'White' RgbColor (255, 255, 255)
|
2013-07-26 22:38:34 +02:00
|
|
|
static RgbColor WHITE;
|
2013-08-13 11:10:45 +02:00
|
|
|
|
2013-09-09 04:54:13 +02:00
|
|
|
///
|
|
|
|
/// Checks is this exactly matches another color
|
|
|
|
///
|
|
|
|
/// @param other The other color
|
|
|
|
///
|
|
|
|
/// @return True if the colors are identical
|
|
|
|
///
|
2013-08-21 16:09:40 +02:00
|
|
|
inline bool operator==(const RgbColor& other) const
|
|
|
|
{
|
|
|
|
return red == other.red && green == other.green && blue == other.blue;
|
|
|
|
}
|
2013-07-26 22:38:34 +02:00
|
|
|
};
|
|
|
|
|
2013-09-09 04:54:13 +02:00
|
|
|
/// Assert to ensure that the size of the structure is 'only' 3 bytes
|
2013-08-13 11:10:45 +02:00
|
|
|
static_assert(sizeof(RgbColor) == 3, "Incorrect size of RgbColor");
|
|
|
|
|
2013-09-09 04:54:13 +02:00
|
|
|
///
|
|
|
|
/// Stream operator to write RgbColor 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)
|
|
|
|
///
|
2013-07-26 22:38:34 +02:00
|
|
|
inline std::ostream& operator<<(std::ostream& os, const RgbColor& color)
|
|
|
|
{
|
|
|
|
os << "{" << unsigned(color.red) << "," << unsigned(color.green) << "," << unsigned(color.blue) << "}";
|
|
|
|
return os;
|
|
|
|
}
|