Skip to content

Save as RGB(A) when APNG frames have different palettes - #9870

Merged
radarhere merged 7 commits into
python-pillow:mainfrom
DSeaStar:fix/apng-differing-palettes
Aug 17, 2026
Merged

Save as RGB(A) when APNG frames have different palettes#9870
radarhere merged 7 commits into
python-pillow:mainfrom
DSeaStar:fix/apng-differing-palettes

Conversation

@DSeaStar

@DSeaStar DSeaStar commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Helps #9868

APNG has a single PLTE. Saving several P frames with different palettes previously wrote only the first frame's palette, so later frames rendered with the wrong colors.

When the collected palettes differ, the animation is now saved as RGB so each frame keeps its colors. Frames that share one palette stay indexed.

Test plan

  • Tests/test_file_apng.py::test_apng_save_p_frames_with_different_palettes
  • Tests/test_file_apng.py::test_apng_save_p_frames_with_same_palette
  • Full Tests/test_file_apng.py (49 passed)

APNG has a single PLTE, so saving P-mode frames with different palettes
silently rendered every frame with the first palette. Promote the
animation to RGB when palettes differ so each frame keeps its colors.

Fixes python-pillow#9868
@radarhere

Copy link
Copy Markdown
Member

#9868 (comment)

Bug

  1. Saving multiple P images as an animated PNG only uses the palette from the first frame.
    ...

Enhancements

  1. If there are less than 256 colours in total, you would like the palettes combined into one.
  2. If there are more than 256 colours in total, you would like all frames to use RGB(A). ...
  3. You would like pixels unchanged in the next frame to be changed to transparent.

This doesn't address the first and third enhancements. I'm still interested in merging this, but it doesn't resolve the issue completely.

@radarhere

Copy link
Copy Markdown
Member

I've created DSeaStar#1 with some suggestions.

@radarhere radarhere changed the title Use RGB when APNG frames have different palettes Save as RGB(A) when APNG frames have different palettes Aug 15, 2026
@radarhere
radarhere merged commit 7d6012b into python-pillow:main Aug 17, 2026
66 of 67 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants