1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 06:57:44 +00:00

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.
This commit is contained in:
Peter Nelson 2020-08-12 17:09:37 +01:00 committed by Andreas Kling
parent 0ab37b44a1
commit daa762bb06

View file

@ -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<u16> 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;
}
}