mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-11 17:56:18 +03:00
Added _min_frame property
This commit is contained in:
parent
f61b70aa8f
commit
c8b65f4efd
|
@ -78,6 +78,8 @@ class ImageFile(Image.Image):
|
|||
def __init__(self, fp=None, filename=None):
|
||||
Image.Image.__init__(self)
|
||||
|
||||
self._min_frame = 0
|
||||
|
||||
self.tile = None
|
||||
self.readonly = 1 # until we know better
|
||||
|
||||
|
@ -276,11 +278,11 @@ class ImageFile(Image.Image):
|
|||
# pass
|
||||
|
||||
def _seek_check(self, frame):
|
||||
if (frame < 0 or
|
||||
if (frame < self._min_frame or
|
||||
# Only check upper limit on frames if additional seek operations
|
||||
# are not required to do so
|
||||
(not (hasattr(self, "_n_frames") and self._n_frames is None) and
|
||||
frame >= self.n_frames)):
|
||||
frame >= self.n_frames+self._min_frame)):
|
||||
raise EOFError("attempt to seek outside sequence")
|
||||
|
||||
return self.tell() != frame
|
||||
|
|
|
@ -124,7 +124,8 @@ class PsdImageFile(ImageFile.ImageFile):
|
|||
|
||||
# keep the file open
|
||||
self._fp = self.fp
|
||||
self.frame = 0
|
||||
self.frame = 1
|
||||
self._min_frame = 1
|
||||
|
||||
@property
|
||||
def n_frames(self):
|
||||
|
@ -140,8 +141,6 @@ class PsdImageFile(ImageFile.ImageFile):
|
|||
|
||||
# seek to given layer (1..max)
|
||||
try:
|
||||
if layer == 0:
|
||||
raise IndexError
|
||||
name, mode, bbox, tile = self.layers[layer-1]
|
||||
self.mode = mode
|
||||
self.tile = tile
|
||||
|
|
|
@ -34,26 +34,23 @@ class TestImagePsd(PillowTestCase):
|
|||
|
||||
def test_eoferror(self):
|
||||
im = Image.open(test_file)
|
||||
# PSD seek index starts at 1 rather than 0
|
||||
n_frames = im.n_frames+1
|
||||
|
||||
n_frames = im.n_frames
|
||||
while True:
|
||||
n_frames -= 1
|
||||
try:
|
||||
# PSD seek index starts at 1 rather than 0
|
||||
im.seek(n_frames+1)
|
||||
break
|
||||
except EOFError:
|
||||
self.assertLess(im.tell(), n_frames)
|
||||
# Test seeking past the last frame
|
||||
self.assertRaises(EOFError, im.seek, n_frames)
|
||||
self.assertLess(im.tell(), n_frames)
|
||||
|
||||
# Test that seeking to the last frame does not raise an error
|
||||
im.seek(n_frames-1)
|
||||
|
||||
def test_seek_tell(self):
|
||||
im = Image.open(test_file)
|
||||
|
||||
layer_number = im.tell()
|
||||
self.assertEqual(layer_number, 0)
|
||||
self.assertEqual(layer_number, 1)
|
||||
|
||||
im.seek(0)
|
||||
layer_number = im.tell()
|
||||
self.assertEqual(layer_number, 0)
|
||||
self.assertRaises(EOFError, im.seek, 0)
|
||||
|
||||
im.seek(1)
|
||||
layer_number = im.tell()
|
||||
|
|
Loading…
Reference in New Issue
Block a user