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

Convert subsequent GIF frames to RGB or RGBA #5857

merged 4 commits into from Dec 6, 2021


Copy link

@radarhere radarhere commented Nov 29, 2021

Resolves #1525
Resolves #1717
Resolves #1692
Resolves #1742
Resolves #2543
Resolves #2893
Resolves #4977
Resolves #5734
Resolves #5781
Resolves #5819
Resolves #5837

Each GIF frame can have its own palette, and each of those palettes can have up to 256 colors. So the second frame of a GIF image may have 512 colors, the third 768 colors, and so on.
However, Pillow keeps a GIF image as P (or L) mode as it loads new frames. P mode images can only have 256 colors at most.
This has lead to many issues complaining about colors in subsequent GIF frames.

This PR instead changes GIF images to RGB or RGBA once you seek to a subsequent frame.

Internally, this is done by simply converting the two P mode images to RGB(A), and then pasting one onto the other.

This finishes the thoughts I started in #3735. It also reverts part of #5333, since those changes are no longer necessary.

@radarhere radarhere added the GIF label Nov 29, 2021
@@ -340,12 +366,16 @@ def test_dispose_background():
def test_dispose_background_transparency():
with"Tests/images/dispose_bgnd_transparency.gif") as img:
px = img.convert("RGBA").load()
px = img.load()
Copy link
Member Author

@radarhere radarhere Nov 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is now already an RGBA image.

Copy link

@hugovk hugovk commented Dec 6, 2021

Resolving 11 issues at once, must be a record!

@hugovk hugovk merged commit 94ca035 into python-pillow:main Dec 6, 2021
3 checks passed
@radarhere radarhere deleted the gif branch Dec 6, 2021
radarhere added a commit to radarhere/Pillow that referenced this issue Dec 6, 2021
@radarhere radarhere mentioned this pull request Jan 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment