Tests for endian issues in decoding 16bit tif images

This commit is contained in:
Eric Soroos 2013-10-21 05:19:52 +00:00
parent 366f9a5f35
commit 1945fecdb6
5 changed files with 47 additions and 0 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -105,3 +105,25 @@ def test_adobe_deflate_tiff():
assert_no_exception(lambda: im.load()) 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')

View File

@ -71,3 +71,28 @@ def test_xyres_tiff():
im.tag.tags[Y_RESOLUTION] = (72,) im.tag.tags[Y_RESOLUTION] = (72,)
im._setup() im._setup()
assert_equal(im.info['dpi'], (72., 72.)) 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')