[Image-SIG] Animated GIF problem

Noboru Uchida noboru.uchida.777 at gmail.com
Sun Nov 16 19:30:15 CET 2008

Some more explanation.

At least, when the disposal method is 2 or 3, C implemantation
object is destroyed and replaced with a new one
when seeking to next frame.
So, palette needs be passed to it, even when the same palette is used.

Another problem.

wxPython's demo example AG00028_.gif can't be played properly.
In this GIF, A man is hola-hooping, and only
small part around hoop should be redrawn.

1st frame's disposal method is 1, and it indicates to
keep whole image remained.
After 2nd frame, small part should be redrawn,
whose disposal methods are 2.

The problem is, PIL throws away previous image and
fills *entire* image with the background color,
when disposal method 2 is indicated.

I'm not quite familier with Animated GIFs, but I think
only the rectangle which is occupied by the previous frame
should be filled when disposal method 2 is indicated, isn't it?

> Hi. Excuse my poor English.
> * Problem:
> Some animated GIFs can't be played properly.
> You can see this using "player.py" sample script and
> Animated GIF files, which doesn't have per-frame palettes.
> When playing back Animated GIFs, you can use Image.seek(),
> then you call Image.paste() or something.
> I found this is not enough for animated GIF file, which doesn't have
> per-frame local palette informations.
> In such a file, the global palette *must* be used to render GIF frame,
> but the global palette doesn't seem properly used by PIL.
> As a result, after second frame, rendering results are broken.
> * Reason:
> 1. In GifImageFile._open(), ImagePalette instance for
> the global palette is created using ImagePalette.raw(),
> and saved as "global_palette" variable.
> 2. In GifImageFile.seek(), when GIF file doesn't have per-flame local
> palette, global palette is set to "palette" variable.
> This is not a copy. Now both "palette" and "global_palette"
> point to same ImagePalette instance.
> 3. In Image.load(), palette.dirty, palette.mode and palette.rawmode
> are overwritten (why?).
> 4. When seeking to second frame, and second frame doesn't have local
> palette, variable "palette" is set to "global_palette".
> But, this time, "global_palette" is already overwritten in step 3.
> 5. In Image.load(), this time, palette.dirty is None. More over,
> palette.rawmode is broken because of step 3.
> As a result, proper palette information seems not given to C
> implementation code.
> * Workaround:
> After seek(), I can manually fix palette information as following:
> image.palette.dirty = 1
> image.palette.rawmode = "RGB"
> and do loading/rendering jobs.
> But, I think this should be done in PIL code, not users' one.

More information about the Image-SIG mailing list