24static constexpr uint8_t COLORCONV_GRAY_THRESHOLD = 50;
32 const uint8_t level = (uint8_t) ((
rec601_luma(color) + 32u) >> 6);
33 return level > 3 ? 3 : level;
46template<
typename NATIVE_COLOR>
47constexpr NATIVE_COLOR
color_to_bwyr(
Color color, NATIVE_COLOR hw_black, NATIVE_COLOR hw_white, NATIVE_COLOR hw_yellow,
48 NATIVE_COLOR hw_red) {
53 const auto [min_rgb, max_rgb] = std::minmax({color.
r, color.
g, color.
b});
55 if ((max_rgb - min_rgb) < COLORCONV_GRAY_THRESHOLD) {
63 const bool r_on = (color.
r > 128);
64 const bool g_on = (color.
g > 128);
65 const bool b_on = (color.
b > 128);
69 return g_on ? hw_yellow : hw_red;
75 return (b_on && g_on) ? hw_white : hw_black;
91template<
typename NATIVE_COLOR>
92constexpr NATIVE_COLOR
color_to_bwr(
Color color, NATIVE_COLOR hw_black, NATIVE_COLOR hw_white, NATIVE_COLOR hw_red) {
112template<
typename NATIVE_COLOR>
114 NATIVE_COLOR hw_yellow, NATIVE_COLOR hw_red, NATIVE_COLOR hw_green,
115 NATIVE_COLOR hw_blue) {
116 const auto [min_rgb, max_rgb] = std::minmax({color.
r, color.
g, color.
b});
118 if ((max_rgb - min_rgb) < COLORCONV_GRAY_THRESHOLD) {
122 const bool r_on = (color.
r > 128);
123 const bool g_on = (color.
g > 128);
124 const bool b_on = (color.
b > 128);
126 if (r_on && g_on && !b_on) {
129 if (r_on && !g_on && !b_on) {
132 if (!r_on && g_on && !b_on) {
135 if (!r_on && !g_on && b_on) {
139 if (!r_on && g_on && b_on) {
170template<
typename NATIVE_COLOR>
172 NATIVE_COLOR hw_yellow, NATIVE_COLOR hw_red, NATIVE_COLOR hw_green,
173 NATIVE_COLOR hw_blue, NATIVE_COLOR hw_orange) {
174 const auto [min_rgb, max_rgb] = std::minmax({color.
r, color.
g, color.
b});
176 if ((max_rgb - min_rgb) < COLORCONV_GRAY_THRESHOLD) {
180 const bool r_on = (color.
r > 128);
181 const bool g_on = (color.
g > 128);
182 const bool b_on = (color.
b > 128);
196 if (!r_on && g_on && !b_on) {
199 if (!r_on && !g_on && b_on) {
203 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.
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.