Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Tests/images/uint16_greyscale.tif
Binary file not shown.
24 changes: 23 additions & 1 deletion Tests/test_file_tiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import struct

from helper import unittest, PillowTestCase, hopper, py3

import numpy as np
from PIL import Image, TiffImagePlugin

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -450,6 +450,28 @@ def test_save_tiff_with_jpegtables(self):
# Should not raise UnicodeDecodeError or anything else
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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test doesn't actually test the code changes, as it doesn't run through any of the numpy code. It's only testing round tripping of a saved image.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does numpy need to be involved? This is a uint16 TIFF that's being resaved. This test failed previously because it both threw a TypeError saying it could save uint16 TIFFs and because the data it saved was wrong, it only saved the image as a uint8 image. This test checks for both of those things.

if __name__ == '__main__':
unittest.main()

Expand Down