mirror of
https://github.com/esphome/esphome.git
synced 2024-12-20 16:18:49 +01:00
Add font anti-aliasing for grayscale display (#7934)
This commit is contained in:
parent
440080a753
commit
132a096ae7
@ -133,9 +133,11 @@ void Font::print(int x_start, int y_start, display::Display *display, Color colo
|
||||
auto diff_r = (float) color.r - (float) background.r;
|
||||
auto diff_g = (float) color.g - (float) background.g;
|
||||
auto diff_b = (float) color.b - (float) background.b;
|
||||
auto diff_w = (float) color.w - (float) background.w;
|
||||
auto b_r = (float) background.r;
|
||||
auto b_g = (float) background.g;
|
||||
auto b_b = (float) background.g;
|
||||
auto b_b = (float) background.b;
|
||||
auto b_w = (float) background.w;
|
||||
for (int glyph_y = y_start + scan_y1; glyph_y != max_y; glyph_y++) {
|
||||
for (int glyph_x = x_at + scan_x1; glyph_x != max_x; glyph_x++) {
|
||||
uint8_t pixel = 0;
|
||||
@ -153,8 +155,8 @@ void Font::print(int x_start, int y_start, display::Display *display, Color colo
|
||||
display->draw_pixel_at(glyph_x, glyph_y, color);
|
||||
} else if (pixel != 0) {
|
||||
auto on = (float) pixel / (float) bpp_max;
|
||||
auto blended =
|
||||
Color((uint8_t) (diff_r * on + b_r), (uint8_t) (diff_g * on + b_g), (uint8_t) (diff_b * on + b_b));
|
||||
auto blended = Color((uint8_t) (diff_r * on + b_r), (uint8_t) (diff_g * on + b_g),
|
||||
(uint8_t) (diff_b * on + b_b), (uint8_t) (diff_w * on + b_w));
|
||||
display->draw_pixel_at(glyph_x, glyph_y, blended);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user