24static constexpr uint8_t COLORCONV_GRAY_THRESHOLD = 50;
39 const uint8_t level = (uint8_t) ((
rec601_luma(color) + 32u) >> 6);
40 return level > 3 ? 3 : level;
53template<
typename NATIVE_COLOR>
54constexpr NATIVE_COLOR
color_to_bwyr(
Color color, NATIVE_COLOR hw_black, NATIVE_COLOR hw_white, NATIVE_COLOR hw_yellow,
55 NATIVE_COLOR hw_red) {
60 const auto [min_rgb, max_rgb] = std::minmax({color.
r, color.
g, color.
b});
62 if ((max_rgb - min_rgb) < COLORCONV_GRAY_THRESHOLD) {
70 const bool r_on = (color.
r > 128);
71 const bool g_on = (color.
g > 128);
72 const bool b_on = (color.
b > 128);
76 return g_on ? hw_yellow : hw_red;
82 return (b_on && g_on) ? hw_white : hw_black;
98template<
typename NATIVE_COLOR>
99constexpr NATIVE_COLOR
color_to_bwr(
Color color, NATIVE_COLOR hw_black, NATIVE_COLOR hw_white, NATIVE_COLOR hw_red) {
100 const auto [min_rgb, max_rgb] = std::minmax({color.
r, color.
g, color.
b});
102 if ((max_rgb - min_rgb) < COLORCONV_GRAY_THRESHOLD) {
106 const int r = color.
r;
107 const int g = color.
g;
108 const int b = color.
b;
109 const int d_black = r * r + g * g + b * b;
110 const int d_white = (255 - r) * (255 - r) + (255 - g) * (255 - g) + (255 - b) * (255 - b);
111 const int d_red = (255 - r) * (255 - r) + g * g + b * b;
113 if (d_red < d_white && d_red < d_black) {
117 return d_white <= d_black ? hw_white : hw_black;
136template<
typename NATIVE_COLOR>
138 NATIVE_COLOR hw_yellow, NATIVE_COLOR hw_red, NATIVE_COLOR hw_green,
139 NATIVE_COLOR hw_blue) {
140 const auto [min_rgb, max_rgb] = std::minmax({color.
r, color.
g, color.
b});
142 if ((max_rgb - min_rgb) < COLORCONV_GRAY_THRESHOLD) {
146 const bool r_on = (color.
r > 128);
147 const bool g_on = (color.
g > 128);
148 const bool b_on = (color.
b > 128);
150 if (r_on && g_on && !b_on) {
153 if (r_on && !g_on && !b_on) {
156 if (!r_on && g_on && !b_on) {
159 if (!r_on && !g_on && b_on) {
163 if (!r_on && g_on && b_on) {
194template<
typename NATIVE_COLOR>
196 NATIVE_COLOR hw_yellow, NATIVE_COLOR hw_red, NATIVE_COLOR hw_green,
197 NATIVE_COLOR hw_blue, NATIVE_COLOR hw_orange) {
198 const auto [min_rgb, max_rgb] = std::minmax({color.
r, color.
g, color.
b});
200 if ((max_rgb - min_rgb) < COLORCONV_GRAY_THRESHOLD) {
204 const bool r_on = (color.
r > 128);
205 const bool g_on = (color.
g > 128);
206 const bool b_on = (color.
b > 128);
220 if (!r_on && g_on && !b_on) {
223 if (!r_on && !g_on && b_on) {
227 if (!r_on && g_on && b_on) {
color_to_mono() of an RGB565 value as ColorUtil::to_color() reads it, from table lookups instead of a...
constexpr uint8_t rec601_luma(Color color)
Rec.601 luma of an RGB color, for optimum perceptual brightness.
constexpr uint8_t color_to_mono(Color color)
Map an RGB color to a single monochrome bit: 1 = white, 0 = black.
BwrColor
Native color keys for black/white/red panels, for use with color_to_bwr.
constexpr NATIVE_COLOR color_to_bwyrgbo(Color color, NATIVE_COLOR hw_black, NATIVE_COLOR hw_white, NATIVE_COLOR hw_yellow, NATIVE_COLOR hw_red, NATIVE_COLOR hw_green, NATIVE_COLOR hw_blue, NATIVE_COLOR hw_orange)
Map RGB color to discrete BWYRGBO hex 7 color key.
constexpr uint8_t color_to_gray4(Color color)
Map RGB color to one of 4 discrete gray levels (2 bits per pixel)
constexpr NATIVE_COLOR color_to_bwr(Color color, NATIVE_COLOR hw_black, NATIVE_COLOR hw_white, NATIVE_COLOR hw_red)
Map RGB color to discrete BWR (black/white/red) 3 color key.
constexpr NATIVE_COLOR color_to_bwyrgb(Color color, NATIVE_COLOR hw_black, NATIVE_COLOR hw_white, NATIVE_COLOR hw_yellow, NATIVE_COLOR hw_red, NATIVE_COLOR hw_green, NATIVE_COLOR hw_blue)
Map RGB color to discrete BWYRGB hex 6 color key.
constexpr NATIVE_COLOR color_to_bwyr(Color color, NATIVE_COLOR hw_black, NATIVE_COLOR hw_white, NATIVE_COLOR hw_yellow, NATIVE_COLOR hw_red)
Map RGB color to discrete BWYR hex 4 color key.