mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-13 10:46:16 +03:00
Merge pull request #7521 from radarhere/gif_save_all
This commit is contained in:
commit
9eb93915c3
|
@ -856,7 +856,14 @@ def test_identical_frames(tmp_path):
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"duration", ([1000, 1500, 2000, 4000], (1000, 1500, 2000, 4000), 8500)
|
"duration",
|
||||||
|
(
|
||||||
|
[1000, 1500, 2000],
|
||||||
|
(1000, 1500, 2000),
|
||||||
|
# One more duration than the number of frames
|
||||||
|
[1000, 1500, 2000, 4000],
|
||||||
|
1500,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
def test_identical_frames_to_single_frame(duration, tmp_path):
|
def test_identical_frames_to_single_frame(duration, tmp_path):
|
||||||
out = str(tmp_path / "temp.gif")
|
out = str(tmp_path / "temp.gif")
|
||||||
|
@ -872,7 +879,7 @@ def test_identical_frames_to_single_frame(duration, tmp_path):
|
||||||
assert reread.n_frames == 1
|
assert reread.n_frames == 1
|
||||||
|
|
||||||
# Assert that the new duration is the total of the identical frames
|
# Assert that the new duration is the total of the identical frames
|
||||||
assert reread.info["duration"] == 8500
|
assert reread.info["duration"] == 4500
|
||||||
|
|
||||||
|
|
||||||
def test_loop_none(tmp_path):
|
def test_loop_none(tmp_path):
|
||||||
|
|
|
@ -624,28 +624,28 @@ def _write_multiple_frames(im, fp, palette):
|
||||||
bbox = None
|
bbox = None
|
||||||
im_frames.append({"im": im_frame, "bbox": bbox, "encoderinfo": encoderinfo})
|
im_frames.append({"im": im_frame, "bbox": bbox, "encoderinfo": encoderinfo})
|
||||||
|
|
||||||
if len(im_frames) > 1:
|
if len(im_frames) == 1:
|
||||||
for frame_data in im_frames:
|
if "duration" in im.encoderinfo:
|
||||||
im_frame = frame_data["im"]
|
# Since multiple frames will not be written, use the combined duration
|
||||||
if not frame_data["bbox"]:
|
im.encoderinfo["duration"] = im_frames[0]["encoderinfo"]["duration"]
|
||||||
# global header
|
return
|
||||||
for s in _get_global_header(im_frame, frame_data["encoderinfo"]):
|
|
||||||
fp.write(s)
|
|
||||||
offset = (0, 0)
|
|
||||||
else:
|
|
||||||
# compress difference
|
|
||||||
if not palette:
|
|
||||||
frame_data["encoderinfo"]["include_color_table"] = True
|
|
||||||
|
|
||||||
im_frame = im_frame.crop(frame_data["bbox"])
|
for frame_data in im_frames:
|
||||||
offset = frame_data["bbox"][:2]
|
im_frame = frame_data["im"]
|
||||||
_write_frame_data(fp, im_frame, offset, frame_data["encoderinfo"])
|
if not frame_data["bbox"]:
|
||||||
return True
|
# global header
|
||||||
elif "duration" in im.encoderinfo and isinstance(
|
for s in _get_global_header(im_frame, frame_data["encoderinfo"]):
|
||||||
im.encoderinfo["duration"], (list, tuple)
|
fp.write(s)
|
||||||
):
|
offset = (0, 0)
|
||||||
# Since multiple frames will not be written, add together the frame durations
|
else:
|
||||||
im.encoderinfo["duration"] = sum(im.encoderinfo["duration"])
|
# compress difference
|
||||||
|
if not palette:
|
||||||
|
frame_data["encoderinfo"]["include_color_table"] = True
|
||||||
|
|
||||||
|
im_frame = im_frame.crop(frame_data["bbox"])
|
||||||
|
offset = frame_data["bbox"][:2]
|
||||||
|
_write_frame_data(fp, im_frame, offset, frame_data["encoderinfo"])
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def _save_all(im, fp, filename):
|
def _save_all(im, fp, filename):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user