[PATCH] gui: bmp: add support for alpha channel
Ahmad Fatoum
a.fatoum at barebox.org
Sun Jun 1 05:15:51 PDT 2025
Apparently, 32-bit bitmaps are a thing and at least Debian Bookworm's
ImageMagick 6.9.11-60 generates them by default, unless
-alpha deactivate is passed to convert.
We don't pass that and thus barebox complains when asked to display them:
barebox at STM32MP157C-DK2:/ splash /logo/barebox-logo-64.bmp
bmp: illegal bits per pixel value: 32
As we already have alpha blending support in use for PNG and QOI, just
have the bitmap parser make use of it as well.
Signed-off-by: Ahmad Fatoum <a.fatoum at barebox.org>
---
lib/gui/bmp.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/lib/gui/bmp.c b/lib/gui/bmp.c
index bbc623dba329..6eea337cd004 100644
--- a/lib/gui/bmp.c
+++ b/lib/gui/bmp.c
@@ -96,7 +96,7 @@ static int bmp_renderer(struct screen *sc, struct surface *s, struct image *img)
image += bits_per_pixel >> 3;
}
}
- } else if (bits_per_pixel == 24) {
+ } else if (bits_per_pixel == 24 || bits_per_pixel == 32) {
int x, y;
for (y = 0; y < height; y++) {
@@ -106,12 +106,11 @@ static int bmp_renderer(struct screen *sc, struct surface *s, struct image *img)
adr = buf + (y + starty) * sc->info->line_length +
startx * (sc->info->bits_per_pixel >> 3);
for (x = 0; x < width; x++) {
- char *pixel;
+ u8 *pixel = image;
+ u8 alpha = bits_per_pixel == 32 ? pixel[3] : 255;
- pixel = image;
-
- gu_set_rgb_pixel(sc->info, adr, pixel[2], pixel[1],
- pixel[0]);
+ gu_set_rgba_pixel(sc->info, adr,
+ pixel[2], pixel[1], pixel[0], alpha);
adr += sc->info->bits_per_pixel >> 3;
image += bits_per_pixel >> 3;
--
2.39.5
More information about the barebox
mailing list