-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
GIF decoder does not correctly handle images with different palettes #1717
Description
This is the cause (or one cause) of #1692 and #1525, but I thought it would be better to open a new bug that starts with an explanation instead of "this particular image doesn't work".
GIF defines a "logical screen" that can contain pixels from an unlimited number of images, each of which can have its own local palette of up to 256 colors. This means that there is no limit (other than 16,777,216 + 1 transparent) to the number of colors that can appear simultaneously on the screen.
I think that Pillow currently represents the logical screen as an array of palette indexes, renders images onto it in palette-index space, and replaces the palette for the whole screen with the local palette of the most recently rendered image. That works for GIFs that have only one palette or completely overwrite the logical screen on every frame, but it fails in general.
The simplest solution is probably to convert the "screen" to RGBA when combining images with different palettes, unless the last image covers the whole screen and doesn't have a transparent index.