Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GIF transparency not applied correctly #3433

Closed
zewt opened this issue Oct 24, 2018 · 5 comments
Closed

GIF transparency not applied correctly #3433

zewt opened this issue Oct 24, 2018 · 5 comments
Labels
Projects

Comments

@zewt
Copy link
Contributor

zewt commented Oct 24, 2018

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.

test

@Artheau
Copy link

Artheau commented Mar 8, 2019

Another fix is described in #3665

@aclark4life aclark4life added this to Backlog in Pillow May 11, 2019
@aclark4life aclark4life moved this from Backlog to In progress in Pillow May 11, 2019
@hugovk
Copy link
Member

hugovk commented Jun 30, 2019

Another fix is described in #3665

PR #3708 has been merged which fixed #3665.

Is this issue still valid?

@zewt
Copy link
Contributor Author

zewt commented Jul 1, 2019

From the title ("GIF deltas from background colour"), it sounds unrelated. This is an issue with the core processing of GIF transparency, not background dispose.

(I haven't received any responses to this other than three variations of "can this be closed?" for 8 months, so I don't think anyone cares about this. I'd rather not spend a bunch of time refreshing my memory on this unless there's some actual interest in it beyond people looking for tickets to close.)

@radarhere
Copy link
Member

Testing, I find that #5125 fixed the issue where the second frame middle pixel was not blue.

@radarhere
Copy link
Member

Reading img.n_pixels changed the image, since the image wasn't being reset when decoding frame 0 after rewinding.

If this was the test_n_frames_invariant from your PR, #3434, I find that it passes even with Pillow 5.3.0, which was available at the time this issue was created.

If this was test_rewind from your PR, I find that it was also fixed by #5125

Pillow automation moved this from In progress to Closed Feb 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Pillow
  
Closed
Development

Successfully merging a pull request may close this issue.

4 participants