diff --git a/Tests/images/12bit.MM.cropped.tif b/Tests/images/12bit.MM.cropped.tif new file mode 100644 index 000000000..c4c24e2eb Binary files /dev/null and b/Tests/images/12bit.MM.cropped.tif differ diff --git a/Tests/images/12bit.MM.deflate.tif b/Tests/images/12bit.MM.deflate.tif new file mode 100644 index 000000000..90a62e94f Binary files /dev/null and b/Tests/images/12bit.MM.deflate.tif differ diff --git a/Tests/images/12bit.deflate.tif b/Tests/images/12bit.deflate.tif new file mode 100644 index 000000000..4f9f4ec06 Binary files /dev/null and b/Tests/images/12bit.deflate.tif differ diff --git a/Tests/test_file_libtiff.py b/Tests/test_file_libtiff.py index 037fc022d..d4767c95a 100644 --- a/Tests/test_file_libtiff.py +++ b/Tests/test_file_libtiff.py @@ -105,3 +105,25 @@ def test_adobe_deflate_tiff(): assert_no_exception(lambda: im.load()) +def test_little_endian(): + im = Image.open('Tests/images/12bit.deflate.tif') + assert_equal(im.getpixel((0,0)), 480) + assert_equal(im.mode, 'I;16') + + b = im.tobytes() + # Bytes are in image native order (little endian) + assert_equal(b[0], b'\xe0') + assert_equal(b[1], b'\x01') + +def test_big_endian(): + im = Image.open('Tests/images/12bit.MM.deflate.tif') + + assert_equal(im.getpixel((0,0)), 480) + assert_equal(im.mode, 'I;16B') + + b = im.tobytes() + + # Bytes are in image native order (big endian) + assert_equal(b[0], b'\x01') + assert_equal(b[1], b'\xe0') + diff --git a/Tests/test_file_tiff.py b/Tests/test_file_tiff.py index ddca24876..c88e103b4 100644 --- a/Tests/test_file_tiff.py +++ b/Tests/test_file_tiff.py @@ -71,3 +71,28 @@ def test_xyres_tiff(): im.tag.tags[Y_RESOLUTION] = (72,) im._setup() assert_equal(im.info['dpi'], (72., 72.)) + + +def test_little_endian(): + im = Image.open('Tests/images/12bit.cropped.tif') + assert_equal(im.getpixel((0,0)), 480) + assert_equal(im.mode, 'I;16') + + b = im.tobytes() + # Bytes are in image native order (little endian) + assert_equal(b[0], b'\xe0') + assert_equal(b[1], b'\x01') + +def test_big_endian(): + im = Image.open('Tests/images/12bit.MM.cropped.tif') + assert_equal(im.getpixel((0,0)), 480) + assert_equal(im.mode, 'I;16B') + + b = im.tobytes() + + # Bytes are in image native order (big endian) + assert_equal(b[0], b'\x01') + assert_equal(b[1], b'\xe0') + + +