[Concept,12/22] video: Support transparency with BMP palette

Message ID 20251003165525.440173-13-sjg@u-boot.org
State New
Headers
Series video: Enhancements to support a pointer |

Commit Message

Simon Glass Oct. 3, 2025, 4:55 p.m. UTC
  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(+)
  

Patch

diff --git a/drivers/video/video_bmp.c b/drivers/video/video_bmp.c
index 9c9d9b2091b..ebdf73e25a9 100644
--- a/drivers/video/video_bmp.c
+++ b/drivers/video/video_bmp.c
@@ -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) {