libepaper 2.0.0
A C++23 library for controlling Waveshare e-paper displays on Raspberry Pi, featuring transparent sleep/wake management and a fluent builder API.
Loading...
Searching...
No Matches
color.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4
5namespace epaper {
6
50struct RGB {
51 std::uint8_t b;
52 std::uint8_t g;
53 std::uint8_t r;
54
58 constexpr RGB() : b(0), g(0), r(0) {}
59
67 constexpr RGB(std::uint8_t red, std::uint8_t green, std::uint8_t blue) : b(blue), g(green), r(red) {}
68
72 constexpr auto operator==(const RGB &other) const noexcept -> bool = default;
73
79 [[nodiscard]] constexpr auto to_grayscale() const noexcept -> std::uint8_t {
80 return static_cast<std::uint8_t>((0.299 * static_cast<double>(r)) + (0.587 * static_cast<double>(g)) +
81 (0.114 * static_cast<double>(b)));
82 }
83};
84
131struct RGBA {
132 std::uint8_t a;
133 std::uint8_t b;
134 std::uint8_t g;
135 std::uint8_t r;
136
140 constexpr RGBA() : a(255), b(0), g(0), r(0) {}
141
150 constexpr RGBA(std::uint8_t red, std::uint8_t green, std::uint8_t blue, std::uint8_t alpha = 255)
151 : a(alpha), b(blue), g(green), r(red) {}
152
158 constexpr explicit RGBA(const RGB &rgb) : a(255), b(rgb.b), g(rgb.g), r(rgb.r) {}
159
163 constexpr auto operator==(const RGBA &other) const noexcept -> bool = default;
164
170 [[nodiscard]] constexpr auto to_rgb() const noexcept -> RGB { return RGB{r, g, b}; }
171
177 [[nodiscard]] constexpr auto to_grayscale() const noexcept -> std::uint8_t {
178 return static_cast<std::uint8_t>((0.299 * static_cast<double>(r)) + (0.587 * static_cast<double>(g)) +
179 (0.114 * static_cast<double>(b)));
180 }
181};
182
183// Predefined colors
184namespace colors {
185constexpr RGB Black{0, 0, 0};
186constexpr RGB White{255, 255, 255};
187constexpr RGB Red{255, 0, 0};
188constexpr RGB Green{0, 255, 0};
189constexpr RGB Blue{0, 0, 255};
190constexpr RGB Yellow{255, 255, 0};
191constexpr RGB Cyan{0, 255, 255};
192constexpr RGB Magenta{255, 0, 255};
193constexpr RGB Gray{128, 128, 128};
194constexpr RGB DarkGray{64, 64, 64};
195constexpr RGB LightGray{192, 192, 192};
196} // namespace colors
197
198} // namespace epaper
constexpr RGB Blue
Definition color.hpp:189
constexpr RGB Yellow
Definition color.hpp:190
constexpr RGB DarkGray
Definition color.hpp:194
constexpr RGB Cyan
Definition color.hpp:191
constexpr RGB Magenta
Definition color.hpp:192
constexpr RGB LightGray
Definition color.hpp:195
constexpr RGB Black
Definition color.hpp:185
constexpr RGB White
Definition color.hpp:186
constexpr RGB Red
Definition color.hpp:187
constexpr RGB Green
Definition color.hpp:188
constexpr RGB Gray
Definition color.hpp:193
Definition color.hpp:5
Definition color.hpp:131
std::uint8_t b
Blue component (0-255)
Definition color.hpp:133
constexpr RGBA(const RGB &rgb)
Construct RGBA from RGB (fully opaque).
Definition color.hpp:158
std::uint8_t a
Alpha component (0-255, 0=transparent, 255=opaque)
Definition color.hpp:132
std::uint8_t g
Green component (0-255)
Definition color.hpp:134
std::uint8_t r
Red component (0-255)
Definition color.hpp:135
constexpr RGBA(std::uint8_t red, std::uint8_t green, std::uint8_t blue, std::uint8_t alpha=255)
Construct RGBA color from components.
Definition color.hpp:150
constexpr auto to_grayscale() const noexcept -> std::uint8_t
Convert to grayscale using standard luminance formula.
Definition color.hpp:177
constexpr RGBA()
Default constructor initializes to transparent black.
Definition color.hpp:140
constexpr auto to_rgb() const noexcept -> RGB
Convert to RGB (discards alpha channel).
Definition color.hpp:170
constexpr auto operator==(const RGBA &other) const noexcept -> bool=default
Equality comparison.
Definition color.hpp:50
constexpr auto to_grayscale() const noexcept -> std::uint8_t
Convert to grayscale using standard luminance formula.
Definition color.hpp:79
std::uint8_t g
Green component (0-255)
Definition color.hpp:52
constexpr RGB()
Default constructor initializes to black.
Definition color.hpp:58
constexpr auto operator==(const RGB &other) const noexcept -> bool=default
Equality comparison.
constexpr RGB(std::uint8_t red, std::uint8_t green, std::uint8_t blue)
Construct RGB color from components.
Definition color.hpp:67
std::uint8_t r
Red component (0-255)
Definition color.hpp:53
std::uint8_t b
Blue component (0-255)
Definition color.hpp:51