From 9e8b507fad362d51c0f12d08adb9b668ca58bed9 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Tue, 9 May 2023 16:26:31 +0200 Subject: [PATCH] LibGfx/WebP: Do not add alpha channel for animated images without alpha In practice, it looks like e.g. the animaged webp file on https://mathiasbynens.be/demo/animated-webp has the header flag set, because 2 of the frames have alpha, but they're composited on top of the final bitmap, but the final bitmap isn't transparent there. So that image still gets a useless alpha channel. Oh well. --- Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp b/Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp index e5b9715d47..83051dc58e 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp @@ -583,7 +583,8 @@ static ErrorOr decode_webp_animation_frame(WebPLoadingCont dbgln_if(WEBP_DEBUG, "start_frame {} context.current_frame {}", start_frame, context.current_frame); if (context.state < WebPLoadingContext::State::BitmapDecoded) { start_frame = 0; - context.bitmap = TRY(Bitmap::create(BitmapFormat::BGRA8888, { context.vp8x_header.width, context.vp8x_header.height })); + auto format = context.vp8x_header.has_alpha ? BitmapFormat::BGRA8888 : BitmapFormat::BGRx8888; + context.bitmap = TRY(Bitmap::create(format, { context.vp8x_header.width, context.vp8x_header.height })); context.bitmap->fill(clear_color); } else if (frame_index < context.current_frame) { start_frame = 0;