From daa762bb061bbb5ddb90030ac422b28101b2892d Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Wed, 12 Aug 2020 17:09:37 +0100 Subject: [PATCH] LibGfx: correctly handle transparency between GIF frames This fixes an issue where transparent pixels in GIF animation frames have their alpha values incorrectly set to zero, allowing the background behind the GIF to show through, instead of the previous animation frame. Additionally, transparent pixels are now correctly identified based on their index matching the image transparency index, instead of their color values. --- Libraries/LibGfx/GIFLoader.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/Libraries/LibGfx/GIFLoader.cpp b/Libraries/LibGfx/GIFLoader.cpp index 8304c97b7c..814018c24e 100644 --- a/Libraries/LibGfx/GIFLoader.cpp +++ b/Libraries/LibGfx/GIFLoader.cpp @@ -292,11 +292,6 @@ static bool decode_frames_up_to_index(GIFLoadingContext& context, size_t frame_i } int pixel_index = 0; - RGB transparent_color { 0, 0, 0 }; - if (image.transparent) { - transparent_color = context.logical_screen.color_map[image.transparency_index]; - } - while (true) { Optional code = decoder.next_code(); if (!code.has_value()) { @@ -321,13 +316,14 @@ static bool decode_frames_up_to_index(GIFLoadingContext& context, size_t frame_i Color c = Color(rgb.r, rgb.g, rgb.b); - if (image.transparent) { - if (rgb.r == transparent_color.r && rgb.g == transparent_color.g && rgb.b == transparent_color.b) { - c.set_alpha(0); - } + if (image.transparent && color == image.transparency_index) { + c.set_alpha(0); + } + + if (!image.transparent || image.disposal_method == ImageDescriptor::DisposalMethod::None || color != image.transparency_index) { + image.bitmap->set_pixel(x, y, c); } - image.bitmap->set_pixel(x, y, c); ++pixel_index; } }