mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-03-13 09:15:46 +03:00
Closing only single frame TIFF images
This commit is contained in:
parent
58484db509
commit
b69b70198f
|
@ -970,6 +970,7 @@ class TiffImageFile(ImageFile.ImageFile):
|
||||||
self.__frame += 1
|
self.__frame += 1
|
||||||
self.fp.seek(self._frame_pos[frame])
|
self.fp.seek(self._frame_pos[frame])
|
||||||
self.tag_v2.load(self.fp)
|
self.tag_v2.load(self.fp)
|
||||||
|
self.__next = self.tag_v2.next
|
||||||
# fill the legacy tag/ifd entries
|
# fill the legacy tag/ifd entries
|
||||||
self.tag = self.ifd = ImageFileDirectory_v1.from_v2(self.tag_v2)
|
self.tag = self.ifd = ImageFileDirectory_v1.from_v2(self.tag_v2)
|
||||||
self.__frame = frame
|
self.__frame = frame
|
||||||
|
@ -1009,6 +1010,12 @@ class TiffImageFile(ImageFile.ImageFile):
|
||||||
return self._load_libtiff()
|
return self._load_libtiff()
|
||||||
return super(TiffImageFile, self).load()
|
return super(TiffImageFile, self).load()
|
||||||
|
|
||||||
|
def load_end(self):
|
||||||
|
# allow closing if we're on the first frame, there's no next
|
||||||
|
# This is the ImageFile.load path only, libtiff specific below.
|
||||||
|
if self.__frame == 0 and not self.__next:
|
||||||
|
self._exclusive_fp = True
|
||||||
|
|
||||||
def _load_libtiff(self):
|
def _load_libtiff(self):
|
||||||
""" Overload method triggered when we detect a compressed tiff
|
""" Overload method triggered when we detect a compressed tiff
|
||||||
Calls out to libtiff """
|
Calls out to libtiff """
|
||||||
|
@ -1087,15 +1094,13 @@ class TiffImageFile(ImageFile.ImageFile):
|
||||||
self.readonly = 0
|
self.readonly = 0
|
||||||
# libtiff closed the fp in a, we need to close self.fp, if possible
|
# libtiff closed the fp in a, we need to close self.fp, if possible
|
||||||
if hasattr(self.fp, 'close'):
|
if hasattr(self.fp, 'close'):
|
||||||
if not self.__next:
|
if self.__frame == 0 and not self.__next:
|
||||||
self.fp.close()
|
self.fp.close()
|
||||||
self.fp = None # might be shared
|
self.fp = None # might be shared
|
||||||
|
|
||||||
if err < 0:
|
if err < 0:
|
||||||
raise IOError(err)
|
raise IOError(err)
|
||||||
|
|
||||||
self.load_end()
|
|
||||||
|
|
||||||
return Image.Image.load(self)
|
return Image.Image.load(self)
|
||||||
|
|
||||||
def _setup(self):
|
def _setup(self):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user