Fixed GIF remapping to palette with duplicate entries #6548
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.
Addresses #6389
remap_palette
cannot map multiple palette indexes to the same output index, by its very definition. It accepts a list of palette indexes that it transforms to the position in the list. There cannot be more than one palette index at a given position in the list.If a palette is supplied when saving a GIF image,
im.save("out.gif", palette=...)
, and that palette has duplicate entries, then the following GifImagePlugin code will try to prepare a list that maps the first of the duplicated entries to multiple locations, leaving the rest of the duplicate entries to be not strictly defined in the behaviour ofremap_palette
.Pillow/src/PIL/GifImagePlugin.py
Lines 519 to 526 in ad7be55
This PR fixes that, by leaving the duplicated indexes as they are - setting
index
toNone
, the next loop in GifImagePluginPillow/src/PIL/GifImagePlugin.py
Lines 527 to 532 in ad7be55
will tell
remap_palette
to map the index to itself, leaving it untouched.