GIF: Fix the previous frame not always being decoded in _seek.

_seek checked whether self.im is None, but if we've decoded a frame
and then seeked back to 0, self.im will be set to the previously
decoded frame.  Instead, check if self.tile has data, which means
_seek set up a tile to decode and it hasn't been decoded yet.
This commit is contained in:
Glenn Maynard 2018-10-24 00:53:21 -05:00 committed by Andrew Murray
parent b5806c7e15
commit 87e54b47ab
3 changed files with 21 additions and 1 deletions

BIN
Tests/images/rewind.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 142 B

View File

@ -293,6 +293,26 @@ class TestFileGif(PillowTestCase):
self.assertEqual(color, expected_colors[frame][x], self.assertEqual(color, expected_colors[frame][x],
'frame %i, x %i' % (frame, x)) 'frame %i, x %i' % (frame, x))
def test_rewind(self):
img = Image.open("Tests/images/rewind.gif")
# Seek forwards to frame 2. This will decode frames 0 and 1.
img.seek(2)
# Seek back to frame 1. This will rewind to frame 0, then seek
# to frame 1.
img.seek(1)
# Read data. This should decode frame 0 and then frame 1.
img.getpixel((0,1))
expected_colors = [(2, 3), (3, 1)]
for x in range(2):
for y in range(2):
color = img.getpixel((x,y))
self.assertEqual(color, expected_colors[x][y],
'%ix%i' % (x, y))
def test_dispose_previous(self): def test_dispose_previous(self):
img = Image.open("Tests/images/dispose_prev.gif") img = Image.open("Tests/images/dispose_prev.gif")
try: try:

View File

@ -144,7 +144,7 @@ class GifImageFile(ImageFile.ImageFile):
self.disposal_method = 0 self.disposal_method = 0
else: else:
# ensure that the previous frame was loaded # ensure that the previous frame was loaded
if not self.im: if self.tile:
self.load() self.load()
if frame != self.__frame + 1: if frame != self.__frame + 1: