17static constexpr uint8_t COLORCONV_GRAY_THRESHOLD = 50;
21 return (uint8_t) ((77u * color.
r + 150u * color.
g + 29u * color.
b + 128u) >> 8);
37 const uint8_t level = (uint8_t) ((
rec601_luma(color) + 32u) >> 6);
38 return level > 3 ? 3 : level;
51template<
typename NATIVE_COLOR>
52constexpr NATIVE_COLOR
color_to_bwyr(
Color color, NATIVE_COLOR hw_black, NATIVE_COLOR hw_white, NATIVE_COLOR hw_yellow,
53 NATIVE_COLOR hw_red) {
58 const auto [min_rgb, max_rgb] = std::minmax({color.
r, color.
g, color.
b});
60 if ((max_rgb - min_rgb) < COLORCONV_GRAY_THRESHOLD) {
68 const bool r_on = (color.
r > 128);
69 const bool g_on = (color.
g > 128);
70 const bool b_on = (color.
b > 128);
74 return g_on ? hw_yellow : hw_red;
80 return (b_on && g_on) ? hw_white : hw_black;
96template<
typename NATIVE_COLOR>
97constexpr NATIVE_COLOR
color_to_bwr(
Color color, NATIVE_COLOR hw_black, NATIVE_COLOR hw_white, NATIVE_COLOR hw_red) {
117template<
typename NATIVE_COLOR>
119 NATIVE_COLOR hw_yellow, NATIVE_COLOR hw_red, NATIVE_COLOR hw_green,
120 NATIVE_COLOR hw_blue) {
121 const auto [min_rgb, max_rgb] = std::minmax({color.
r, color.
g, color.
b});
123 if ((max_rgb - min_rgb) < COLORCONV_GRAY_THRESHOLD) {
127 const bool r_on = (color.
r > 128);
128 const bool g_on = (color.
g > 128);
129 const bool b_on = (color.
b > 128);
131 if (r_on && g_on && !b_on) {
134 if (r_on && !g_on && !b_on) {
137 if (!r_on && g_on && !b_on) {
140 if (!r_on && !g_on && b_on) {
144 if (!r_on && g_on && b_on) {
175template<
typename NATIVE_COLOR>
177 NATIVE_COLOR hw_yellow, NATIVE_COLOR hw_red, NATIVE_COLOR hw_green,
178 NATIVE_COLOR hw_blue, NATIVE_COLOR hw_orange) {
179 const auto [min_rgb, max_rgb] = std::minmax({color.
r, color.
g, color.
b});
181 if ((max_rgb - min_rgb) < COLORCONV_GRAY_THRESHOLD) {
185 const bool r_on = (color.
r > 128);
186 const bool g_on = (color.
g > 128);
187 const bool b_on = (color.
b > 128);
201 if (!r_on && g_on && !b_on) {
204 if (!r_on && !g_on && b_on) {
208 if (!r_on && g_on && b_on) {
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 rec601_luma(Color color)
Rec.601 luma (0.299/0.587/0.114 weights, scaled by 256) for optimum perceptual brightness.
constexpr uint8_t color_to_gray4(Color color)
Map RGB color to one of 4 discrete gray levels (2 bits per pixel)
constexpr uint8_t color_to_mono(Color color)
Map RGB color to a single monochrome bit.
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.