[Concept,12/22] video: Support transparency with BMP palette
Commit Message
From: Simon Glass <sjg@chromium.org>
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>
---
drivers/video/video_bmp.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
@@ -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) {