mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-08-14 09:14:45 +03:00
Add test for reading and writing uint16 TIFFs.
This commit is contained in:
parent
85c3f365de
commit
b7319abb60
BIN
Tests/images/uint16_1_4660.tif
Normal file
BIN
Tests/images/uint16_1_4660.tif
Normal file
Binary file not shown.
|
@ -450,6 +450,13 @@ 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_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__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
||||||
|
|
|
@ -106,6 +106,21 @@ class TestNumpy(PillowTestCase):
|
||||||
self._test_img_equals_nparray(img, np_img)
|
self._test_img_equals_nparray(img, np_img)
|
||||||
self.assertEqual(np_img.dtype, numpy.dtype('<u2'))
|
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 test_to_array(self):
|
||||||
|
|
||||||
def _to_array(mode, dtype):
|
def _to_array(mode, dtype):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user