[Concept,11/22] video: Support transparency with 24bpp BMP image

Message ID 20251003165525.440173-12-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>

When the pixel colour matches the transparency colour, skip writing it
to the display.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/video/video_bmp.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
  

Patch

diff --git a/drivers/video/video_bmp.c b/drivers/video/video_bmp.c
index 88a327e4a6d..9c9d9b2091b 100644
--- a/drivers/video/video_bmp.c
+++ b/drivers/video/video_bmp.c
@@ -388,6 +388,15 @@  static int draw_bmp(struct udevice *dev, ulong bmp_image, int x, int y,
 					u8 red = bmap[0];
 					u8 green = bmap[1];
 					u8 blue = bmap[2];
+					u32 pixel_color = (red << 16) |
+						(green << 8) | blue;
+
+					bmap += 3;
+					/* Skip transparent pixels if alpha enabled */
+					if (alpha && pixel_color == acolour) {
+						fb += bpix / 8;
+						continue;
+					}
 
 					if (bpix == 16) {
 						/* 16bit 565RGB format */
@@ -423,7 +432,6 @@  static int draw_bmp(struct udevice *dev, ulong bmp_image, int x, int y,
 						*fb++ = blue;
 						*fb++ = 0;
 					}
-					bmap += 3;
 				}
 				fb -= priv->line_length + width * (bpix / 8);
 				bmap += (padded_width - width);