Add tests for working with uint16 greyscale TIFFs.

This commit is contained in:
Bryant Mairs 2016-04-09 08:28:50 -07:00
parent d2a7de2c25
commit d6c9ac175e
2 changed files with 23 additions and 1 deletions

Binary file not shown.

View File

@ -3,7 +3,7 @@ import logging
import struct import struct
from helper import unittest, PillowTestCase, hopper, py3 from helper import unittest, PillowTestCase, hopper, py3
import numpy as np
from PIL import Image, TiffImagePlugin from PIL import Image, TiffImagePlugin
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -450,6 +450,28 @@ 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_save_greyscale_uint16_tiff(self):
'''
Save uint16 data as a greyscale uint16 TIFF.
'''
data = np.full([200, 200], 65535, np.uint16)
im = Image.fromarray(data)
outfile = self.tempfile("temp.tif")
im.save(outfile)
def test_roundtrip_greyscale_uint16_tiff(self):
'''
Confirm that all data saved to a uint16 TIFF is preserved.
Note: This will fail if test_save_greyscale_uint16_tiff() fails.
'''
data = np.full([200, 200], 65535, np.uint16)
im = Image.fromarray(data)
outfile = self.tempfile("temp.tif")
im.save(outfile)
out_im = Image.open(outfile)
self.assert_image_equal(im, out_im)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()