dithering m8 dithering.
Instead of adding noise try using this code.
uint8_t RED_THRESH[] = {
1, 7, 3, 5, 0, 8, 2, 6,
7, 1, 5, 3, 8, 0, 6, 2,
3, 5, 0, 8, 2, 6, 1, 7,
5, 3, 8, 0, 6, 2, 7, 1,
0, 8, 2, 6, 1, 7, 3, 5,
8, 0, 6, 2, 7, 1, 5, 3,
2, 6, 1, 7, 3, 5, 0, 8,
6, 2, 7, 1, 5, 3, 8, 0
};
uint8_t GREEN_THRESH[] = {
1, 3, 2, 2, 3, 1, 2, 2,
2, 2, 0, 4, 2, 2, 4, 0,
3, 1, 2, 2, 1, 3, 2, 2,
2, 2, 4, 0, 2, 2, 0, 4,
1, 3, 2, 2, 3, 1, 2, 2,
2, 2, 0, 4, 2, 2, 4, 0,
3, 1, 2, 2, 1, 3, 2, 2,
2, 2, 4, 0, 2, 2, 0, 4
};
uint8_t BLUE_THRESH[] = {
5, 3, 8, 0, 6, 2, 7, 1,
3, 5, 0, 8, 2, 6, 1, 7,
8, 0, 6, 2, 7, 1, 5, 3,
0, 8, 2, 6, 1, 7, 3, 5,
6, 2, 7, 1, 5, 3, 8, 0,
2, 6, 1, 7, 3, 5, 0, 8,
7, 1, 5, 3, 8, 0, 6, 2,
1, 7, 3, 5, 0, 8, 2, 6
};
uint8_t closest_rb(uint8_t c)
{
return c >> 3 << 3;
}
uint8_t closest_g(uint8_t c)
{
return c >> 2 << 2;
}
void rgb565_dither_pixel(uint16_t x, uint16_t y, lv_color_t *col)
{
uint8_t threshold_id = (uint8_t)(((y & 7) << 3) + (x & 7));
col->red = closest_rb(((col->red & 0xF8) + RED_THRESH[threshold_id]) & 0xFF) & 0xF8;
col->green = closest_g(((col->green & 0xFC) + GREEN_THRESH[threshold_id]) & 0xFF) & 0xFC;
col->blue = closest_rb(((col->blue & 0xF8) + BLUE_THRESH[threshold_id]) & 0xFF) & 0xF8;
}
void lv_rgb565_dither(uint8_t *buf, uint16_t width, uint16_t height, lv_color_format_t format) {
lv_color_t *color;
uint8_t *p;
for (uint16_t y=0; y < height; y++) {
for (uint16_t x=0; x < width; x++) {
if (format == LV_COLOR_FORMAT_RGB888) {
p = &buf[height * y + x];
color = (lv_color_t *)p;
} else if ((format == LV_COLOR_FORMAT_ARGB8888) || (format == LV_COLOR_FORMAT_XRGB8888)) {
p = &buf[height * y + x + 1];
color = (lv_color_t *)p;
} else {
continue;
}
rgb565_dither_pixel(x, y, color);
}
}
}
Turns this
into this