video: Support transparency with BMP palette

Check the palette entry against the transparency colour and skip writing
it to the display if it matches.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass
2025-10-01 20:15:16 -06:00
parent 5900eb7138
commit ff9d219391

View File

@@ -53,6 +53,20 @@ static u32 get_bmp_col_rgba8888(struct bmp_color_table_entry *cte)
(cte->blue << 16U) | 0xff << 24U);
}
/**
* matches_alpha() - Check if a palette entry matches the alpha color
*
* @ent: BMP palette entry
* @col: Alpha color to compare (RGB888 format)
* Return: true if the palette entry matches the alpha color
*/
static bool matches_alpha(struct bmp_color_table_entry *ent, u32 col)
{
u32 colour = (ent->red << 16) | (ent->green << 8) | ent->blue;
return colour == col;
}
/**
* write_pix8() - Write a pixel from a BMP image into the framebuffer
*
@@ -73,6 +87,10 @@ static void write_pix8(u8 *fb, uint bpix, enum video_format eformat,
{
struct bmp_color_table_entry *cte = &palette[*bmap];
/* Check for transparent pixel */
if (alpha && matches_alpha(cte, acol))
return;
if (bpix == 8) {
*fb++ = *bmap;
} else if (bpix == 16) {