Merge pull request #5443 from radarhere/fp

This commit is contained in:
Hugo van Kemenade 2021-05-09 20:39:44 +03:00 committed by GitHub
commit 23f848ea54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 3 deletions

View File

@ -578,6 +578,17 @@ class TestFileLibTiff(LibTiffTestCase):
TiffImagePlugin.READ_LIBTIFF = False
def test_multipage_seek_backwards(self):
TiffImagePlugin.READ_LIBTIFF = True
with Image.open("Tests/images/multipage.tiff") as im:
im.seek(1)
im.load()
im.seek(0)
assert im.convert("RGB").getpixel((0, 0)) == (0, 128, 0)
TiffImagePlugin.READ_LIBTIFF = False
def test__next(self):
TiffImagePlugin.READ_LIBTIFF = True
with Image.open("Tests/images/hopper.tif") as im:

View File

@ -1053,6 +1053,11 @@ class TiffImageFile(ImageFile.ImageFile):
def _seek(self, frame):
self.fp = self.__fp
# reset buffered io handle in case fp
# was passed to libtiff, invalidating the buffer
self.fp.tell()
while len(self._frame_pos) <= frame:
if not self.__next:
raise EOFError("no more images in TIFF file")
@ -1060,9 +1065,6 @@ class TiffImageFile(ImageFile.ImageFile):
f"Seeking to frame {frame}, on frame {self.__frame}, "
f"__next {self.__next}, location: {self.fp.tell()}"
)
# reset buffered io handle in case fp
# was passed to libtiff, invalidating the buffer
self.fp.tell()
self.fp.seek(self.__next)
self._frame_pos.append(self.__next)
logger.debug("Loading tags, location: %s" % self.fp.tell())