mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 17:36:18 +03:00
Enabled seeking in MPO files.
Note to self: either put the offset in the load_seek() definition or the tile definition, not both.
This commit is contained in:
parent
6605bf22e5
commit
832e11bed5
|
@ -49,14 +49,21 @@ class MpoImageFile(JpegImagePlugin.JpegImageFile):
|
|||
self.__fp.seek(self.__mpoffsets[0]) # get ready to read first frame
|
||||
self.__frame = 0
|
||||
self.offset = 0
|
||||
# for now we can only handle reading and individual frame extraction
|
||||
self.readonly = 1
|
||||
|
||||
def load_seek(self, pos):
|
||||
self.__fp.seek(pos)
|
||||
|
||||
def seek(self, frame):
|
||||
if frame < 0 or frame >= self.__framecount:
|
||||
raise EOFError("no more images in MPO file")
|
||||
else:
|
||||
self.fp = self.__fp
|
||||
self.fp.seek(self.__mpoffsets[frame])
|
||||
self.offset = self.__mpoffsets[frame]
|
||||
self.tile = [
|
||||
("jpeg", (0, 0) + self.size, self.offset, (self.mode, ""))
|
||||
]
|
||||
self.__frame = frame
|
||||
|
||||
def tell(self):
|
||||
|
|
|
@ -73,6 +73,20 @@ class TestFileMpo(PillowTestCase):
|
|||
# and this one, too
|
||||
im.seek(0)
|
||||
self.assertEqual(im.tell(), 0)
|
||||
|
||||
def test_image_grab(self):
|
||||
for test_file in test_files:
|
||||
im = Image.open(test_file)
|
||||
self.assertEqual(im.tell(), 0)
|
||||
im0 = im.tobytes()
|
||||
im.seek(1)
|
||||
self.assertEqual(im.tell(), 1)
|
||||
im1 = im.tobytes()
|
||||
im.seek(0)
|
||||
self.assertEqual(im.tell(), 0)
|
||||
im0 = im.tobytes()
|
||||
self.assertEqual(im0, im02)
|
||||
self.assertNotEqual(im0, im1)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
Loading…
Reference in New Issue
Block a user