mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-27 10:26:19 +03:00
Resolved GifImagePlugin FIXME
This commit is contained in:
parent
f28084ae3e
commit
b06669f670
|
@ -340,51 +340,58 @@ def _save(im, fp, filename, save_all=False):
|
||||||
im.encoderinfo["optimize"] = im.encoderinfo.get("optimize", True)
|
im.encoderinfo["optimize"] = im.encoderinfo.get("optimize", True)
|
||||||
|
|
||||||
if save_all:
|
if save_all:
|
||||||
previous = None
|
# To specify duration, add the time in milliseconds to getdata(),
|
||||||
|
# e.g. getdata(im_frame, duration=1000)
|
||||||
first_frame = None
|
|
||||||
append_images = im.encoderinfo.get("append_images", [])
|
|
||||||
if "duration" in im.encoderinfo:
|
if "duration" in im.encoderinfo:
|
||||||
duration = im.encoderinfo["duration"]
|
duration = im.encoderinfo["duration"]
|
||||||
else:
|
else:
|
||||||
duration = None
|
duration = None
|
||||||
|
im_frames = []
|
||||||
|
append_images = im.encoderinfo.get("append_images", [])
|
||||||
frame_count = 0
|
frame_count = 0
|
||||||
for imSequence in [im]+append_images:
|
for imSequence in [im]+append_images:
|
||||||
for im_frame in ImageSequence.Iterator(imSequence):
|
for im_frame in ImageSequence.Iterator(imSequence):
|
||||||
encoderinfo = im.encoderinfo.copy()
|
|
||||||
im_frame = _convert_mode(im_frame)
|
im_frame = _convert_mode(im_frame)
|
||||||
|
|
||||||
|
encoderinfo = im.encoderinfo.copy()
|
||||||
if isinstance(duration, (list, tuple)):
|
if isinstance(duration, (list, tuple)):
|
||||||
encoderinfo["duration"] = duration[frame_count]
|
encoderinfo['duration'] = duration[frame_count]
|
||||||
frame_count += 1
|
frame_count += 1
|
||||||
|
|
||||||
# To specify duration, add the time in milliseconds to getdata(),
|
if im_frames:
|
||||||
# e.g. getdata(im_frame, duration=1000)
|
|
||||||
if not previous:
|
|
||||||
# global header
|
|
||||||
first_frame = getheader(im_frame, palette, encoderinfo)[0]
|
|
||||||
first_frame += getdata(im_frame, (0, 0), **encoderinfo)
|
|
||||||
else:
|
|
||||||
if first_frame:
|
|
||||||
for s in first_frame:
|
|
||||||
fp.write(s)
|
|
||||||
first_frame = None
|
|
||||||
|
|
||||||
# delta frame
|
# delta frame
|
||||||
delta = ImageChops.subtract_modulo(im_frame, previous)
|
previous = im_frames[-1]
|
||||||
|
delta = ImageChops.subtract_modulo(im_frame,
|
||||||
|
previous['im_frame'])
|
||||||
bbox = delta.getbbox()
|
bbox = delta.getbbox()
|
||||||
|
if not bbox:
|
||||||
if bbox:
|
# This frame is identical to the previous frame
|
||||||
# compress difference
|
if duration:
|
||||||
encoderinfo['include_color_table'] = True
|
previous['encoderinfo']['duration'] += encoderinfo['duration']
|
||||||
for s in getdata(im_frame.crop(bbox),
|
continue
|
||||||
bbox[:2], **encoderinfo):
|
else:
|
||||||
fp.write(s)
|
bbox = None
|
||||||
else:
|
im_frames.append({
|
||||||
# FIXME: what should we do in this case?
|
"im_frame":im_frame,
|
||||||
pass
|
"bbox":bbox,
|
||||||
previous = im_frame
|
"encoderinfo":encoderinfo
|
||||||
if first_frame:
|
})
|
||||||
|
if len(im_frames) < 2:
|
||||||
save_all = False
|
save_all = False
|
||||||
|
else:
|
||||||
|
for data in im_frames:
|
||||||
|
if data['bbox'] is None:
|
||||||
|
# global header
|
||||||
|
header = getheader(data['im_frame'], palette, data['encoderinfo'])[0]
|
||||||
|
for s in header + getdata(data['im_frame'],
|
||||||
|
(0, 0), **data['encoderinfo']):
|
||||||
|
fp.write(s)
|
||||||
|
else:
|
||||||
|
# compress difference
|
||||||
|
data['encoderinfo']['include_color_table'] = True
|
||||||
|
for s in getdata(data['im_frame'].crop(data['bbox']),
|
||||||
|
data['bbox'][:2], **data['encoderinfo']):
|
||||||
|
fp.write(s)
|
||||||
if not save_all:
|
if not save_all:
|
||||||
header = getheader(im_out, palette, im.encoderinfo)[0]
|
header = getheader(im_out, palette, im.encoderinfo)[0]
|
||||||
for s in header:
|
for s in header:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user