diff --git a/Tests/images/multipage-lastframe.tif b/Tests/images/multipage-lastframe.tif new file mode 100644 index 000000000..aeba534e2 Binary files /dev/null and b/Tests/images/multipage-lastframe.tif differ diff --git a/Tests/images/test.tif b/Tests/images/multipage.tiff similarity index 100% rename from Tests/images/test.tif rename to Tests/images/multipage.tiff diff --git a/Tests/test_file_libtiff.py b/Tests/test_file_libtiff.py index b5df39d04..121ad5de2 100644 --- a/Tests/test_file_libtiff.py +++ b/Tests/test_file_libtiff.py @@ -312,6 +312,35 @@ class TestFileLibTiff(LibTiffTestCase): self.assertRaises(OSError, lambda: os.fstat(fn)) self.assertRaises(OSError, lambda: os.close(fn)) + def test_multipage(self): + # issue #862 + TiffImagePlugin.READ_LIBTIFF = True + im = Image.open('Tests/images/multipage.tiff') + # file is a multipage tiff, 10x10 green, 10x10 red, 20x20 blue + + im.seek(0) + self.assertEqual(im.size, (10,10)) + self.assertEqual(im.convert('RGB').getpixel((0,0)), (0,128,0)) + self.assertTrue(im.tag.next) + + im.seek(1) + self.assertEqual(im.size, (10,10)) + self.assertEqual(im.convert('RGB').getpixel((0,0)), (255,0,0)) + self.assertTrue(im.tag.next) + + im.seek(2) + self.assertFalse(im.tag.next) + self.assertEqual(im.size, (20,20)) + self.assertEqual(im.convert('RGB').getpixel((0,0)), (0,0,255)) + + TiffImagePlugin.READ_LIBTIFF = False + + def test__next(self): + TiffImagePlugin.READ_LIBTIFF = True + im = Image.open('Tests/images/lena.tif') + self.assertFalse(im.tag.next) + im.load() + self.assertFalse(im.tag.next) if __name__ == '__main__': unittest.main() diff --git a/Tests/test_file_tiff.py b/Tests/test_file_tiff.py index 9c832c206..464f1c314 100644 --- a/Tests/test_file_tiff.py +++ b/Tests/test_file_tiff.py @@ -1,6 +1,6 @@ from helper import unittest, PillowTestCase, lena, py3 -from PIL import Image +from PIL import Image, TiffImagePlugin class TestFileTiff(PillowTestCase): @@ -141,6 +141,32 @@ class TestFileTiff(PillowTestCase): self.assertEqual( im.getextrema(), (-3.140936851501465, 3.140684127807617)) + def test_multipage(self): + # issue #862 + im = Image.open('Tests/images/multipage.tiff') + # file is a multipage tiff, 10x10 green, 10x10 red, 20x20 blue + + im.seek(0) + self.assertEqual(im.size, (10,10)) + self.assertEqual(im.convert('RGB').getpixel((0,0)), (0,128,0)) + + im.seek(1) + im.load() + self.assertEqual(im.size, (10,10)) + self.assertEqual(im.convert('RGB').getpixel((0,0)), (255,0,0)) + + im.seek(2) + im.load() + self.assertEqual(im.size, (20,20)) + self.assertEqual(im.convert('RGB').getpixel((0,0)), (0,0,255)) + + def test_multipage_last_frame(self): + im = Image.open('Tests/images/multipage-lastframe.tif') + im.load() + self.assertEqual(im.size, (20,20)) + self.assertEqual(im.convert('RGB').getpixel((0,0)), (0,0,255)) + + def test___str__(self): # Arrange file = "Tests/images/pil136.tiff"