Merge pull request #1 from radarhere/gif_test

Test that background colours read are equal to saved colours
This commit is contained in:
Riley Lahd 2019-03-14 17:53:08 -06:00 committed by GitHub
commit aa5874d3c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -317,18 +317,20 @@ class TestFileGif(PillowTestCase):
def test_dispose2_diff(self): def test_dispose2_diff(self):
out = self.tempfile('temp.gif') out = self.tempfile('temp.gif')
# 4 backgrounds: White, Grey, Black, Red # 4 backgrounds: White, Grey, Black, Red
im_list = [ backgrounds = [(255, 255, 255), (153, 153, 153), (0, 0, 0), (255, 0, 0)]
Image.new('RGB', (100, 100), '#fff'),
Image.new('RGB', (100, 100), '#999'), im_list = []
Image.new('RGB', (100, 100), '#000'), for background in backgrounds:
Image.new('RGB', (100, 100), '#f00'), img = Image.new('RGB', (100, 100), background)
]
# Red circle in center of each frame # Red circle in center of each frame
for img in im_list:
d = ImageDraw.Draw(img) d = ImageDraw.Draw(img)
d.ellipse([(40, 40), (60, 60)], fill='#f00') d.ellipse([(40, 40), (60, 60)], fill='#f00')
im_list.append(img)
im_list[0].save( im_list[0].save(
out, out,
save_all=True, save_all=True,
@ -337,24 +339,16 @@ class TestFileGif(PillowTestCase):
) )
img = Image.open(out) img = Image.open(out)
top_left_pixels = []
center_pixels = []
for i in range(3): for i, background in enumerate(backgrounds):
img.seek(i)
rgb_img = img.convert('RGB') rgb_img = img.convert('RGB')
# Get pixel in top left
r, g, b = rgb_img.getpixel((1, 1)) # Check top left pixel matches background
top_left_pixels += [(r, g, b)] self.assertEqual(rgb_img.getpixel((0, 0)), background)
# Get pixel in center
r, g, b = rgb_img.getpixel((50, 50)) # Center remains red every frame
center_pixels += [(r, g, b)] self.assertEqual(rgb_img.getpixel((50, 50)), (255, 0, 0))
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")