8 inline static uint8_t esp_scale(uint8_t i, uint8_t scale, uint8_t max_value = 255) {
return (max_value * i / scale); }
14 uint8_t first_color, second_color, third_color;
15 uint8_t first_bits = 0;
16 uint8_t second_bits = 0;
17 uint8_t third_bits = 0;
19 switch (color_bitness) {
37 first_color = right_bit_aligned ? esp_scale(((colorcode >> (second_bits + third_bits)) & ((1 << first_bits) - 1)),
38 ((1 << first_bits) - 1))
39 : esp_scale(((colorcode >> 16) & 0xFF), (1 << first_bits) - 1);
41 second_color = right_bit_aligned
42 ? esp_scale(((colorcode >> third_bits) & ((1 << second_bits) - 1)), ((1 << second_bits) - 1))
43 : esp_scale(((colorcode >> 8) & 0xFF), ((1 << second_bits) - 1));
45 third_color = (right_bit_aligned ? esp_scale(((colorcode >> 0) & ((1 << third_bits) - 1)), ((1 << third_bits) - 1))
46 : esp_scale(((colorcode >> 0) & 0xFF), (1 << third_bits) - 1));
50 switch (color_order) {
52 color_return.
r = first_color;
53 color_return.
g = second_color;
54 color_return.
b = third_color;
57 color_return.
b = first_color;
58 color_return.
g = second_color;
59 color_return.
r = third_color;
62 color_return.
g = first_color;
63 color_return.
r = second_color;
64 color_return.
b = third_color;
73 uint16_t red_color, green_color, blue_color;
75 red_color = esp_scale8(color.
red, ((1 << 3) - 1));
76 green_color = esp_scale8(color.
green, ((1 << 3) - 1));
77 blue_color = esp_scale8(color.
blue, (1 << 2) - 1);
79 switch (color_order) {
81 return red_color << 5 | green_color << 2 | blue_color;
83 return blue_color << 6 | green_color << 3 | red_color;
85 return green_color << 5 | red_color << 2 | blue_color;
90 uint16_t red_color, green_color, blue_color;
92 red_color = esp_scale8(color.
red, ((1 << 5) - 1));
93 green_color = esp_scale8(color.
green, ((1 << 6) - 1));
94 blue_color = esp_scale8(color.
blue, (1 << 5) - 1);
96 switch (color_order) {
98 return red_color << 11 | green_color << 5 | blue_color;
100 return blue_color << 11 | green_color << 5 | red_color;
102 return green_color << 10 | red_color << 5 | blue_color;
107 uint32_t gs4 = esp_scale8(color.
white, 15);
121 uint8_t closest_index = 0;
122 uint32_t minimum_dist2 = UINT32_MAX;
125 int16_t tgt_r = color.
r;
126 int16_t tgt_g = color.
g;
127 int16_t tgt_b = color.
b;
130 for (uint16_t i = 0; i < 256; i++) {
132 int16_t plt_r = (int16_t) palette[i * 3 + 0];
133 int16_t plt_g = (int16_t) palette[i * 3 + 1];
134 int16_t plt_b = (int16_t) palette[i * 3 + 2];
136 x = (uint32_t) std::abs(tgt_r - plt_r);
137 y = (uint32_t) std::abs(tgt_g - plt_g);
138 z = (uint32_t) std::abs(tgt_b - plt_b);
139 uint32_t dist2 = x * x + y * y + z * z;
140 if (dist2 < minimum_dist2) {
141 minimum_dist2 = dist2;
142 closest_index = (uint8_t) i;
145 return closest_index;
154 Color color =
Color(palette[index * 3 + 0], palette[index * 3 + 1], palette[index * 3 + 2], 0);
static uint16_t color_to_565(Color color, ColorOrder color_order=ColorOrder::COLOR_ORDER_RGB)
static uint32_t color_to_grayscale4(Color color)
static uint8_t color_to_332(Color color, ColorOrder color_order=ColorOrder::COLOR_ORDER_RGB)
static Color index8_to_color_palette888(uint8_t index, const uint8_t *palette)
static uint8_t color_to_index8_palette888(Color color, const uint8_t *palette)
Implementation of SPI Controller mode.
static Color to_color(uint32_t colorcode, ColorOrder color_order, ColorBitness color_bitness=ColorBitness::COLOR_BITNESS_888, bool right_bit_aligned=true)
static Color rgb332_to_color(uint8_t rgb332_color)