From d6c9ac175e2903e86d226cccd09247a7bcda7a3e Mon Sep 17 00:00:00 2001
From: Bryant Mairs <bryant@intelinair.com>
Date: Sat, 9 Apr 2016 08:28:50 -0700
Subject: [PATCH] Add tests for working with uint16 greyscale TIFFs.

---
 Tests/images/uint16_greyscale.tif | Bin 0 -> 2461526 bytes
 Tests/test_file_tiff.py           |  24 +++++++++++++++++++++++-
 2 files changed, 23 insertions(+), 1 deletion(-)
 create mode 100644 Tests/images/uint16_greyscale.tif

diff --git a/Tests/images/uint16_greyscale.tif b/Tests/images/uint16_greyscale.tif
new file mode 100644
index 0000000000000000000000000000000000000000..c5d2ddd20e5a823434507f0c0f987baef1bbbb9c
GIT binary patch
diff --git a/Tests/test_file_tiff.py b/Tests/test_file_tiff.py
index 84fdd0f4965..f8f88d9160e 100644
--- a/Tests/test_file_tiff.py
+++ b/Tests/test_file_tiff.py
@@ -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__)
@@ -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)
+
 if __name__ == '__main__':
     unittest.main()
 
