You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Issues of transparency continue to vex GIF handling. Not sure if I have a complete handle on this yet but will try.
In _write_multiple_frames() there is a call to _normalize_palette(), which calls .remap_palette() which calls convert("L") which changes .info["transparency"]. This happens after the fix of PR #6176. Also, .remap_palette() changes the palette but does not make a corresponding change to the transparency index. So here is a proposal (not yet a PR because it conflicts with PR #6176 and because I don't know if it's a good fix):
This changes .info["transparency"] to the remapped transparency index, if it was in the used palette to begin with. (More about this below... still a problem.)
Then in _write_multiple_frames() put the call to _normalize_palette() ahead of the set of encoderinfo:
I don't know if changing the order of these statements from PR #6176 cause a problem or not.
Another problem is: what if there is a transparency index (i.e. the Transparent Color Flag is set) but the index is to an unused color? My "fix" above to _normalize_palette() will not change im.info["transparency"] and may leave it referring to a color that is used and should not be transparent. This happens with that Tazspin.gif I used in Issue #6259. Only affects about 3 pixels there so it is not visible but could be a problem for some GIFs. Maybe there's an easy way to force the index to an unused color in this case?
BTW aniship.gif has no GCT, only LCTs (and they're all the same). The current 9.1.0 either with or without PR #6176 will create a reduced GCT of 8 slots (of used colors) but leaves the transparent color index at 14, pointing to a non-existent entry.
The text was updated successfully, but these errors were encountered:
For your first problem, I've pushed another commit to #6176, along the same lines of thoughts that you have. With that, and disposal=2, your image saves correctly.
Thank you. I must apologize about the code I posted at the top of this. I neglected the disposal=2 argument that I certainly did use to get the posted image with odd artifact. Your improved #6176 seems to do the trick, and more cleanly than what I was proposing.
What did you do?
Copied an animated GIF:
What did you expect to happen?
Hoped the copy would be something like the original aniship.gif:
What actually happened?
With PR #6176 applied, I get an artifact of (apropos of the nautical theme) aqua background on first frame:
What are your OS, Python and Pillow versions?
Discussion:
Issues of transparency continue to vex GIF handling. Not sure if I have a complete handle on this yet but will try.
In
_write_multiple_frames()
there is a call to_normalize_palette()
, which calls.remap_palette()
which callsconvert("L")
which changes.info["transparency"]
. This happens after the fix of PR #6176. Also,.remap_palette()
changes the palette but does not make a corresponding change to the transparency index. So here is a proposal (not yet a PR because it conflicts with PR #6176 and because I don't know if it's a good fix):Add a function:
Then in
_normalize_palette()
changeto:
This changes
.info["transparency"]
to the remapped transparency index, if it was in the used palette to begin with. (More about this below... still a problem.)Then in
_write_multiple_frames()
put the call to_normalize_palette()
ahead of the set ofencoderinfo
:I don't know if changing the order of these statements from PR #6176 cause a problem or not.
Another problem is: what if there is a transparency index (i.e. the Transparent Color Flag is set) but the index is to an unused color? My "fix" above to
_normalize_palette()
will not changeim.info["transparency"]
and may leave it referring to a color that is used and should not be transparent. This happens with that Tazspin.gif I used in Issue #6259. Only affects about 3 pixels there so it is not visible but could be a problem for some GIFs. Maybe there's an easy way to force the index to an unused color in this case?BTW aniship.gif has no GCT, only LCTs (and they're all the same). The current 9.1.0 either with or without PR #6176 will create a reduced GCT of 8 slots (of used colors) but leaves the transparent color index at 14, pointing to a non-existent entry.
The text was updated successfully, but these errors were encountered: