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:
parent
0ab37b44a1
commit
daa762bb06
1 changed files with 6 additions and 10 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue