Add test for disposal mode 2 gifs

This commit is contained in:
Riley Lahd 2019-03-14 14:40:31 -06:00
parent c57bfb9a7b
commit 96c5a4c543

View File

@ -1,6 +1,6 @@
from .helper import unittest, PillowTestCase, hopper, netpbm_available from .helper import unittest, PillowTestCase, hopper, netpbm_available
from PIL import Image, ImagePalette, GifImagePlugin from PIL import Image, ImagePalette, GifImagePlugin, ImageDraw
from io import BytesIO from io import BytesIO
@ -315,6 +315,55 @@ class TestFileGif(PillowTestCase):
img.seek(img.tell() + 1) img.seek(img.tell() + 1)
self.assertEqual(img.disposal_method, i+1) self.assertEqual(img.disposal_method, i+1)
def test_dispose2_diff(self):
out = self.tempfile('temp.gif')
# 4 backgrounds: White, Grey, Black, Red
im_list = [
Image.new('RGB', (100, 100), '#fff'),
Image.new('RGB', (100, 100), '#999'),
Image.new('RGB', (100, 100), '#000'),
Image.new('RGB', (100, 100), '#f00'),
]
# Red circle in center of each frame
for img in im_list:
d = ImageDraw.Draw(img)
d.ellipse([(40,40),(60,60)], fill='#f00')
# check per frame disposal
im_list[0].save(
out,
save_all=True,
append_images=im_list[1:],
disposal=2
)
img = Image.open(out)
top_left_pixels = []
center_pixels = []
# # Get pixel in top left
# rgb_img = img.convert('RGB')
# r, g, b = rgb_img.getpixel((1,1))
# top_left_pixels += [(r,g,b)]
# r, g, b = rgb_img.getpixel((50,50))
# center_pixels += [(r,g,b)]
for i in range(3):
rgb_img = img.convert('RGB')
# Get pixel in top left
r, g, b = rgb_img.getpixel((1,1))
top_left_pixels += [(r,g,b)]
# Get pixel in center
r, g, b = rgb_img.getpixel((50,50))
center_pixels += [(r,g,b)]
for prev in top_left_pixels[:i]:
# Change background every frame
self.assertNotEqual((r,g,b), prev)
for prev in center_pixels[:i]:
# Center remains red every frame
self.assertEqual((r,g,b), (255,0,0))
img.seek(img.tell() + 1)
def test_iss634(self): def test_iss634(self):
img = Image.open("Tests/images/iss634.gif") img = Image.open("Tests/images/iss634.gif")
# seek to the second frame # seek to the second frame