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

Use previous disposal method in GIF load_end #5125

Merged
merged 1 commit into from Dec 29, 2020

Conversation

@radarhere
Copy link
Member

@radarhere radarhere commented Dec 23, 2020

Resolves #3153

Animated GIFs have subsequent frames encoded as cropped portions of the image. How the image data from previous frames is treated is called the 'disposal method'.

When GifImagePlugin reads disposal_method, it sets up what should happen to this frame's image data and then uses that when seeking to the next frame - in short, the current disposal_method is not something that affects the appearance of this frame, but the next one.

Which is why this

def load_end(self):
ImageFile.ImageFile.load_end(self)
# if the disposal method is 'do not dispose', transparent
# pixels should show the content of the previous frame
if self._prev_im and self.disposal_method == 1:

is incorrect. This PR changes load_end to use the previous disposal_method, instead of the current one.

I've added a test case. The second frame of 'Tests/images/dispose_none_load_end.gif' is tested to equal 'Tests/images/dispose_none_load_end_second.gif'. You can verify this should be case by just opening up 'Tests/images/dispose_none_load_end.gif' in an image viewer.

@radarhere radarhere added the GIF label Dec 23, 2020
@radarhere radarhere changed the title Use previous disposal method in load_end Use previous disposal method in GIF load_end Dec 23, 2020
@hugovk hugovk merged commit cd446e6 into python-pillow:master Dec 29, 2020
50 checks passed
@radarhere radarhere deleted the disposal_method branch Dec 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

2 participants