Skip to content

Commit

Permalink
Tests for endian issues in decoding 16bit tif images
Browse files Browse the repository at this point in the history
  • Loading branch information
wiredfool committed Oct 21, 2013
1 parent 366f9a5 commit 1945fec
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 0 deletions.
Binary file added Tests/images/12bit.MM.cropped.tif
Binary file not shown.
Binary file added Tests/images/12bit.MM.deflate.tif
Binary file not shown.
Binary file added Tests/images/12bit.deflate.tif
Binary file not shown.
22 changes: 22 additions & 0 deletions Tests/test_file_libtiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

25 changes: 25 additions & 0 deletions Tests/test_file_tiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')



0 comments on commit 1945fec

Please sign in to comment.