-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Description
The attached animated GIF image is decoded incorrectly (testing with master). This was exported by Photoshop and is decoded correctly by ffmpeg and other decoders.
The file is 3x1 pixels and three frames: XBX GBG XBX (X: transparent, G: green, B: blue).
Pillow decodes it as: XBX GXG XBX, leaving pixel 1x0 in the second frame transparent when it should be blue.
The issue seems to be that the transparent color index isn't handled correctly. It should leave the existing pixel in the buffer unchanged. Instead, the decoder overwrites the pixel with the transparent index, changing the blue pixel to transparent. There's a special case for dispose mode 1 in load_end, but it's a little odd. (The dispose mode only affects the next frame, but this is affecting the current frame, and it doesn't do anything with other dispose modes.)
I'll send a PR shortly to fix this. It adds two tests using this image: one for this issue, and one for an issue that came up while implementing this. (Reading img.n_pixels changed the image, since the image wasn't being reset when decoding frame 0 after rewinding. This didn't matter before, since the decoder overwrote the whole image, but it matters now.) The load_end special case is removed, since the compositing happens in the decoder. Background dispose clears to the transparency color if one is set, which matches other decoders.
If anyone's interested in trying to make the decoder work everywhere, it might be useful to check other projects for comprehensive GIF tests. There's probably one in Chromium.
