Merge pull request #1855 from hugovk/tiff-lzw

Test TIFF with LZW compression
This commit is contained in:
wiredfool 2016-04-29 20:43:10 +01:00
commit 12bfb976bd
2 changed files with 23 additions and 9 deletions

BIN
Tests/images/hopper_lzw.tif Normal file

Binary file not shown.

View File

@ -85,8 +85,10 @@ class TestFileTiff(PillowTestCase):
self.assertIsInstance(im.tag[Y_RESOLUTION][0], tuple) self.assertIsInstance(im.tag[Y_RESOLUTION][0], tuple)
# v2 api # v2 api
self.assertIsInstance(im.tag_v2[X_RESOLUTION], TiffImagePlugin.IFDRational) self.assertIsInstance(im.tag_v2[X_RESOLUTION],
self.assertIsInstance(im.tag_v2[Y_RESOLUTION], TiffImagePlugin.IFDRational) TiffImagePlugin.IFDRational)
self.assertIsInstance(im.tag_v2[Y_RESOLUTION],
TiffImagePlugin.IFDRational)
self.assertEqual(im.info['dpi'], (72., 72.)) self.assertEqual(im.info['dpi'], (72., 72.))
@ -340,8 +342,8 @@ class TestFileTiff(PillowTestCase):
def test_gray_semibyte_per_pixel(self): def test_gray_semibyte_per_pixel(self):
test_files = ( test_files = (
( (
24.8,#epsilon 24.8, # epsilon
(#group ( # group
"Tests/images/tiff_gray_2_4_bpp/hopper2.tif", "Tests/images/tiff_gray_2_4_bpp/hopper2.tif",
"Tests/images/tiff_gray_2_4_bpp/hopper2I.tif", "Tests/images/tiff_gray_2_4_bpp/hopper2I.tif",
"Tests/images/tiff_gray_2_4_bpp/hopper2R.tif", "Tests/images/tiff_gray_2_4_bpp/hopper2R.tif",
@ -349,8 +351,8 @@ class TestFileTiff(PillowTestCase):
) )
), ),
( (
7.3,#epsilon 7.3, # epsilon
(#group ( # group
"Tests/images/tiff_gray_2_4_bpp/hopper4.tif", "Tests/images/tiff_gray_2_4_bpp/hopper4.tif",
"Tests/images/tiff_gray_2_4_bpp/hopper4I.tif", "Tests/images/tiff_gray_2_4_bpp/hopper4I.tif",
"Tests/images/tiff_gray_2_4_bpp/hopper4R.tif", "Tests/images/tiff_gray_2_4_bpp/hopper4R.tif",
@ -424,16 +426,16 @@ class TestFileTiff(PillowTestCase):
im = Image.open('Tests/images/compression.tif') im = Image.open('Tests/images/compression.tif')
im.seek(0) im.seek(0)
self.assertEqual(im._compression,'tiff_ccitt') self.assertEqual(im._compression, 'tiff_ccitt')
self.assertEqual(im.size, (10, 10)) self.assertEqual(im.size, (10, 10))
im.seek(1) im.seek(1)
self.assertEqual(im._compression,'packbits') self.assertEqual(im._compression, 'packbits')
self.assertEqual(im.size, (10, 10)) self.assertEqual(im.size, (10, 10))
im.load() im.load()
im.seek(0) im.seek(0)
self.assertEqual(im._compression,'tiff_ccitt') self.assertEqual(im._compression, 'tiff_ccitt')
self.assertEqual(im.size, (10, 10)) self.assertEqual(im.size, (10, 10))
im.load() im.load()
@ -450,6 +452,18 @@ class TestFileTiff(PillowTestCase):
# Should not raise UnicodeDecodeError or anything else # Should not raise UnicodeDecodeError or anything else
im.save(outfile) im.save(outfile)
def test_lzw(self):
# Act
im = Image.open("Tests/images/hopper_lzw.tif")
# Assert
self.assertEqual(im.mode, 'RGB')
self.assertEqual(im.size, (128, 128))
self.assertEqual(im.format, "TIFF")
im2 = hopper()
self.assert_image_similar(im, im2, 5)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()