mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-03-03 11:35:52 +03:00
Simplifications
This commit is contained in:
parent
0872cb4377
commit
2dbfabe6d5
|
@ -472,7 +472,7 @@ class TestFileGif(PillowTestCase):
|
||||||
except EOFError:
|
except EOFError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def test_partially_identical_frames(self):
|
def test_identical_frames(self):
|
||||||
duration_list = [1000, 1500, 2000, 4000]
|
duration_list = [1000, 1500, 2000, 4000]
|
||||||
|
|
||||||
out = self.tempfile("temp.gif")
|
out = self.tempfile("temp.gif")
|
||||||
|
@ -495,41 +495,25 @@ class TestFileGif(PillowTestCase):
|
||||||
# Assert that the new duration is the total of the identical frames
|
# Assert that the new duration is the total of the identical frames
|
||||||
self.assertEqual(reread.info["duration"], 4500)
|
self.assertEqual(reread.info["duration"], 4500)
|
||||||
|
|
||||||
def test_totally_identical_frames(self):
|
def test_identical_frames_to_single_frame(self):
|
||||||
duration_list = [1000, 1500, 2000, 4000]
|
for duration in ([1000, 1500, 2000, 4000], (1000, 1500, 2000, 4000), 8500):
|
||||||
|
out = self.tempfile("temp.gif")
|
||||||
|
im_list = [
|
||||||
|
Image.new("L", (100, 100), "#000"),
|
||||||
|
Image.new("L", (100, 100), "#000"),
|
||||||
|
Image.new("L", (100, 100), "#000"),
|
||||||
|
]
|
||||||
|
|
||||||
out = self.tempfile("temp.gif")
|
im_list[0].save(
|
||||||
|
out, save_all=True, append_images=im_list[1:], duration=duration
|
||||||
|
)
|
||||||
|
reread = Image.open(out)
|
||||||
|
|
||||||
image_path = "Tests/images/bc7-argb-8bpp_MipMaps-1.png"
|
# Assert that all frames were combined
|
||||||
im_list = [
|
self.assertEqual(reread.n_frames, 1)
|
||||||
Image.open(image_path),
|
|
||||||
Image.open(image_path),
|
|
||||||
Image.open(image_path),
|
|
||||||
Image.open(image_path),
|
|
||||||
]
|
|
||||||
mask = Image.new("RGBA", im_list[0].size, (255, 255, 255, 0))
|
|
||||||
|
|
||||||
frames = []
|
# Assert that the new duration is the total of the identical frames
|
||||||
for image in im_list:
|
self.assertEqual(reread.info["duration"], 8500)
|
||||||
frames.append(Image.alpha_composite(mask, image))
|
|
||||||
|
|
||||||
# duration as list
|
|
||||||
frames[0].save(
|
|
||||||
out,
|
|
||||||
save_all=True,
|
|
||||||
append_images=frames[1:],
|
|
||||||
optimize=False,
|
|
||||||
duration=duration_list,
|
|
||||||
loop=0,
|
|
||||||
transparency=0,
|
|
||||||
)
|
|
||||||
reread = Image.open(out)
|
|
||||||
|
|
||||||
# Assert that all four frames were combined
|
|
||||||
self.assertEqual(reread.n_frames, 1)
|
|
||||||
|
|
||||||
# Assert that the new duration is the total of the identical frames
|
|
||||||
self.assertEqual(reread.info["duration"], 8500)
|
|
||||||
|
|
||||||
def test_number_of_loops(self):
|
def test_number_of_loops(self):
|
||||||
number_of_loops = 2
|
number_of_loops = 2
|
||||||
|
|
|
@ -472,9 +472,6 @@ def _write_multiple_frames(im, fp, palette):
|
||||||
else:
|
else:
|
||||||
bbox = None
|
bbox = None
|
||||||
im_frames.append({"im": im_frame, "bbox": bbox, "encoderinfo": encoderinfo})
|
im_frames.append({"im": im_frame, "bbox": bbox, "encoderinfo": encoderinfo})
|
||||||
# see: https://github.com/python-pillow/Pillow/issues/4002
|
|
||||||
if len(im_frames) == 1 and "duration" in im_frames[0]["encoderinfo"]:
|
|
||||||
im.encoderinfo["duration"] = im_frames[0]["encoderinfo"]["duration"]
|
|
||||||
|
|
||||||
if len(im_frames) > 1:
|
if len(im_frames) > 1:
|
||||||
for frame_data in im_frames:
|
for frame_data in im_frames:
|
||||||
|
@ -492,6 +489,11 @@ def _write_multiple_frames(im, fp, palette):
|
||||||
offset = frame_data["bbox"][:2]
|
offset = frame_data["bbox"][:2]
|
||||||
_write_frame_data(fp, im_frame, offset, frame_data["encoderinfo"])
|
_write_frame_data(fp, im_frame, offset, frame_data["encoderinfo"])
|
||||||
return True
|
return True
|
||||||
|
elif "duration" in im.encoderinfo and isinstance(
|
||||||
|
im.encoderinfo["duration"], (list, tuple)
|
||||||
|
):
|
||||||
|
# Since multiple frames will not be written, add together the frame durations
|
||||||
|
im.encoderinfo["duration"] = sum(im.encoderinfo["duration"])
|
||||||
|
|
||||||
|
|
||||||
def _save_all(im, fp, filename):
|
def _save_all(im, fp, filename):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user