Only compare to previous frame when checking for duplicate GIF frames while saving #6787
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves #6785
When saving GIFs, a
disposal
value of 2 means that after the frame, we should "Restore to background color".For that scenario, GifImagePlugin correctly compares the new frame to the background color, so that the new frame is optimised by only including the parts that differ from the background color.
Pillow/src/PIL/GifImagePlugin.py
Lines 601 to 618 in 4c9ed12
However, GifImagePlugin then decides that if there is no difference, the frame is identical to the previous frame.
Pillow/src/PIL/GifImagePlugin.py
Lines 619 to 620 in 4c9ed12
That is not true when
disposal
is 2. It would be true ifdisposal
weren't 2, and we were comparing this frame to the previous frame, but we are instead comparing it to the background color.So this PR instead only compares the previous frame with this frame when checking for duplicate frames.