lib: Implement anti-aliased text rendering

Transition the bootsplash text renderer from 1-bit monochrome bitmaps
to 8-bit alpha maps to support text smoothing (anti-aliasing).

Key changes:
- Update fonts.h to declare font_table as a 2D uint8_t array containing
  alpha intensity values (0-255) for each pixel.
- Update draw_char() to perform alpha blending by mixing the text color
  with the existing background pixel using the formula:
  Result = (Color * Alpha + BG * (255 - Alpha)) / 255.
- Regenerate the font table data to reflect the new 8-bit format and
  updated character widths.

Change-Id: I9d4dde74d86fd552b30523f3b8ff34fb8fdba782
Signed-off-by: Subrata Banik <subratabanik@google.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/91179
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Kapil Porwal <kapilporwal@google.com>
This commit is contained in:
Subrata Banik 2026-02-12 16:49:42 +05:30
commit 5ea25c7ca2
3 changed files with 9216 additions and 464 deletions

File diff suppressed because it is too large Load diff

View file

@ -10,7 +10,7 @@
#define FONT_END_CHAR 126 /* ASCII ~ */
#define FONT_NUM_CHARS (FONT_END_CHAR - FONT_START_CHAR + 1)
extern const uint32_t font_table[FONT_NUM_CHARS][CONFIG_FONT_HEIGHT];
extern const uint8_t font_widths[];
extern const uint8_t font_table[FONT_NUM_CHARS][CONFIG_FONT_WIDTH * CONFIG_FONT_HEIGHT];
extern const uint8_t font_widths[FONT_NUM_CHARS];
#endif // __FONTS_H__

View file

@ -7,8 +7,8 @@
#include "fonts/fonts.h"
#include "render_bmp.h"
/* Maps an unsigned character to the font table index */
static const uint32_t *get_glyph_data(unsigned char c)
/* Maps an unsigned character to the 8-bit alpha map (smoothing data) */
static const uint8_t *get_glyph_data(unsigned char c)
{
/* Range check using macros generated by Python */
if (c < FONT_START_CHAR || c > FONT_END_CHAR)
@ -65,23 +65,35 @@ static void draw_char(struct logo_config *config, unsigned char c, uint32_t x, u
{
size_t pixel_size = sizeof(struct blt_pixel);
uint8_t *fb = (uint8_t *)config->framebuffer_base;
const uint32_t *glyph = get_glyph_data(c);
const uint8_t *glyph = get_glyph_data(c);
uint8_t actual_width = get_glyph_width(c);
for (int row = 0; row < CONFIG_FONT_HEIGHT; row++) {
uint32_t row_data = glyph[row];
for (int col = 0; col < actual_width; col++) {
uint32_t mask = (1 << (CONFIG_FONT_HEIGHT - 1));
if (row_data & (mask >> col)) {
uint32_t fb_x, fb_y;
get_rotated_text_coords(config, x, y, row, col, &fb_x, &fb_y);
/* Get the 8-bit alpha value (0-255) for this pixel */
uint8_t alpha = glyph[row * CONFIG_FONT_WIDTH + col];
if (fb_x < config->horizontal_resolution &&
fb_y < config->vertical_resolution) {
struct blt_pixel *pixel = (struct blt_pixel *)
(fb + (fb_y * config->bytes_per_scanline) + (fb_x * pixel_size));
*pixel = color;
if (alpha == 0)
continue;
uint32_t fb_x, fb_y;
get_rotated_text_coords(config, x, y, row, col, &fb_x, &fb_y);
if (fb_x < config->horizontal_resolution &&
fb_y < config->vertical_resolution) {
struct blt_pixel *bg = (struct blt_pixel *)
(fb + (fb_y * config->bytes_per_scanline) + (fb_x * pixel_size));
if (alpha == 255) {
/* Fully opaque: just overwrite */
*bg = color;
} else {
/* Perform Alpha Blending */
bg->Red = (uint8_t)((color.Red * alpha + bg->Red * (255 - alpha)) / 255);
bg->Green = (uint8_t)((color.Green * alpha + bg->Green * (255 - alpha)) / 255);
bg->Blue = (uint8_t)((color.Blue * alpha + bg->Blue * (255 - alpha)) / 255);
}
}
}