From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH] gui: bmp: add support for alpha channel
Date: Sun, 1 Jun 2025 14:15:51 +0200 [thread overview]
Message-ID: <20250601121551.343612-1-a.fatoum@barebox.org> (raw)
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@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@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
next reply other threads:[~2025-06-01 12:32 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-01 12:15 Ahmad Fatoum [this message]
2025-06-02 7:52 ` Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250601121551.343612-1-a.fatoum@barebox.org \
--to=a.fatoum@barebox.org \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox