hyperion.ng/include/utils/RgbColor.h

65 lines
1.6 KiB
C
Raw Normal View History

#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
///
struct RgbColor
{
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 RgbColor BLACK;
2013-09-09 04:54:13 +02:00
/// 'Red' RgbColor (255, 0, 0)
static RgbColor RED;
2013-09-09 04:54:13 +02:00
/// 'Green' RgbColor (0, 255, 0)
static RgbColor GREEN;
2013-09-09 04:54:13 +02:00
/// 'Blue' RgbColor (0, 0, 255)
static RgbColor BLUE;
2013-09-09 04:54:13 +02:00
/// 'Yellow' RgbColor (255, 255, 0)
static RgbColor YELLOW;
2013-09-09 04:54:13 +02:00
/// 'White' RgbColor (255, 255, 255)
static RgbColor WHITE;
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-09-09 04:54:13 +02:00
/// Assert to ensure that the size of the structure is 'only' 3 bytes
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)
///
inline std::ostream& operator<<(std::ostream& os, const RgbColor& color)
{
os << "{" << unsigned(color.red) << "," << unsigned(color.green) << "," << unsigned(color.blue) << "}";
return os;
}