1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-02 11:22:24 +01:00

Add font anti-aliasing for grayscale display (#7934)

This commit is contained in:
Yoonji Park
2024-12-09 20:13:21 +09:00
committed by GitHub
parent 440080a753
commit 132a096ae7

View File

@@ -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_r = (float) color.r - (float) background.r;
auto diff_g = (float) color.g - (float) background.g; auto diff_g = (float) color.g - (float) background.g;
auto diff_b = (float) color.b - (float) background.b; 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_r = (float) background.r;
auto b_g = (float) background.g; 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_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++) { for (int glyph_x = x_at + scan_x1; glyph_x != max_x; glyph_x++) {
uint8_t pixel = 0; 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); display->draw_pixel_at(glyph_x, glyph_y, color);
} else if (pixel != 0) { } else if (pixel != 0) {
auto on = (float) pixel / (float) bpp_max; auto on = (float) pixel / (float) bpp_max;
auto blended = auto blended = Color((uint8_t) (diff_r * on + b_r), (uint8_t) (diff_g * on + b_g),
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_b * on + b_b), (uint8_t) (diff_w * on + b_w));
display->draw_pixel_at(glyph_x, glyph_y, blended); display->draw_pixel_at(glyph_x, glyph_y, blended);
} }
} }