Add test for reading and writing uint16 TIFFs.

This commit is contained in:
Bryant Mairs 2016-04-11 12:35:16 -07:00 committed by wiredfool
parent f51e90bf33
commit 7fb24e8af0
3 changed files with 22 additions and 0 deletions

Binary file not shown.

View File

@ -463,6 +463,13 @@ class TestFileTiff(PillowTestCase):
im2 = hopper()
self.assert_image_similar(im, im2, 5)
def test_open_tiff_uint16(self):
# Test an image of all '0' values
pixel_value = 0x1234
infile = "Tests/images/uint16_1_{}.tif".format(pixel_value)
im = Image.open(infile)
self.assertEqual(im.getpixel((0, 0)), pixel_value)
if __name__ == '__main__':
unittest.main()

View File

@ -110,6 +110,21 @@ class TestNumpy(PillowTestCase):
self._test_img_equals_nparray(img, np_img)
self.assertEqual(np_img.dtype, numpy.dtype('<u2'))
def test_save_tiff_uint16(self):
'''
Open a single-channel uint16 greyscale image and verify that it can be saved without
losing precision.
'''
tmpfile = self.tempfile("temp.tif")
pixel_value = 0x1234
filename = "Tests/images/uint16_1_4660.tif"
a = numpy.array([pixel_value] * 100, dtype=numpy.uint16)
a.shape = TestNumpy.TEST_IMAGE_SIZE
Image.fromarray(a).save(tmpfile)
im_test = Image.open(tmpfile)
im_good = Image.open(filename)
self.assert_image_equal(im_good, im_test)
def test_to_array(self):
def _to_array(mode, dtype):