Merge pull request #2092 from wiredfool/bigendian-fixes

Test fix for bigendian machines
This commit is contained in:
Hugo 2016-08-29 12:50:33 +03:00 committed by GitHub
commit 03db2263e3
2 changed files with 14 additions and 11 deletions

View File

@ -463,13 +463,20 @@ class TestFileTiff(PillowTestCase):
im2 = hopper() im2 = hopper()
self.assert_image_similar(im, im2, 5) self.assert_image_similar(im, im2, 5)
def test_open_tiff_uint16(self): def test_roundtrip_tiff_uint16(self):
# Test an image of all '0' values # Test an image of all '0' values
pixel_value = 0x1234 pixel_value = 0x1234
infile = "Tests/images/uint16_1_4660.tif" infile = "Tests/images/uint16_1_4660.tif"
im = Image.open(infile) im = Image.open(infile)
self.assertEqual(im.getpixel((0, 0)), pixel_value) self.assertEqual(im.getpixel((0, 0)), pixel_value)
tmpfile = self.tempfile("temp.tif")
im.save(tmpfile)
reloaded = Image.open(tmpfile)
self.assert_image_equal(im, reloaded)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

@ -1,6 +1,7 @@
from __future__ import print_function from __future__ import print_function
import sys import sys
from helper import unittest, PillowTestCase, hopper from helper import unittest, PillowTestCase, hopper
import sys
from PIL import Image from PIL import Image
@ -137,19 +138,14 @@ class TestNumpy(PillowTestCase):
numpy.testing.assert_array_equal(arr, arr_back) numpy.testing.assert_array_equal(arr, arr_back)
def test_save_tiff_uint16(self): def test_save_tiff_uint16(self):
''' # Tests that we're getting the pixel value in the right byte order.
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 pixel_value = 0x1234
filename = "Tests/images/uint16_1_4660.tif"
a = numpy.array([pixel_value] * TEST_IMAGE_SIZE[0] * TEST_IMAGE_SIZE[1], dtype=numpy.uint16) a = numpy.array([pixel_value] * TEST_IMAGE_SIZE[0] * TEST_IMAGE_SIZE[1], dtype=numpy.uint16)
a.shape = TEST_IMAGE_SIZE a.shape = TEST_IMAGE_SIZE
Image.fromarray(a).save(tmpfile) img = Image.fromarray(a)
im_test = Image.open(tmpfile)
im_good = Image.open(filename) img_px = img.load()
self.assert_image_equal(im_good, im_test) self.assertEqual(img_px[0,0], pixel_value)
@unittest.skipIf(SKIP_NUMPY_ON_PYPY, "numpy.array(Image) is flaky on PyPy") @unittest.skipIf(SKIP_NUMPY_ON_PYPY, "numpy.array(Image) is flaky on PyPy")
def test_to_array(self): def test_to_array(self):