Skip to content

Commit

Permalink
Merge pull request #1 from radarhere/gif_test
Browse files Browse the repository at this point in the history
Test that background colours read are equal to saved colours
  • Loading branch information
sircinnamon authored Mar 14, 2019
2 parents 85a07bb + 0b630e0 commit aa5874d
Showing 1 changed file with 18 additions and 24 deletions.
42 changes: 18 additions & 24 deletions Tests/test_file_gif.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,18 +317,20 @@ def test_save_dispose(self):

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:
backgrounds = [(255, 255, 255), (153, 153, 153), (0, 0, 0), (255, 0, 0)]

im_list = []
for background in backgrounds:
img = Image.new('RGB', (100, 100), background)

# Red circle in center of each frame
d = ImageDraw.Draw(img)
d.ellipse([(40, 40), (60, 60)], fill='#f00')

im_list.append(img)

im_list[0].save(
out,
save_all=True,
Expand All @@ -337,24 +339,16 @@ def test_dispose2_diff(self):
)

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')
# 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)

# Check top left pixel matches background
self.assertEqual(rgb_img.getpixel((0, 0)), background)

# Center remains red every frame
self.assertEqual(rgb_img.getpixel((50, 50)), (255, 0, 0))

def test_iss634(self):
img = Image.open("Tests/images/iss634.gif")
Expand Down

0 comments on commit aa5874d

Please sign in to comment.