Added big endian Exif support. #104

This commit is contained in:
jevans 2013-10-26 19:23:33 -04:00
commit c4060f23c8
2 changed files with 28 additions and 3 deletions

View file

@ -34,8 +34,8 @@ class UUIDExif(object):
self.read_buffer = read_buffer
# Ignore the first six bytes.
# Next 8 should be (73, 73, 42, 8)
data = struct.unpack('<BBHI', read_buffer[6:14])
# Next 8 should be (73, 73, 42, 8) or (77, 77, 42, 8)
data = struct.unpack('<BB', read_buffer[6:8])
if data[0] == 73 and data[1] == 73:
# little endian
self.endian = '<'
@ -46,7 +46,7 @@ class UUIDExif(object):
msg = "Bad byte order indication: {0}".format(read_buffer[6:8])
raise RuntimeError(msg)
offset = data[3]
_, offset = struct.unpack(self.endian + 'HI', read_buffer[8:14])
# This is the 'Exif Image' portion.
exif = _ExifImageIfd(self.endian, read_buffer[6:], offset)

View file

@ -129,5 +129,30 @@ class TestUUIDExif(unittest.TestCase):
self.assertEqual(j.box[-1].box_id, 'uuid')
def test_big_endian(self):
"""Verify read of big-endian IFD."""
with tempfile.NamedTemporaryFile(suffix='.jp2', mode='wb') as tfile:
with open(self.jp2file, 'rb') as ifptr:
tfile.write(ifptr.read())
# Write L, T, UUID identifier.
tfile.write(struct.pack('>I4s', 52, b'uuid'))
tfile.write(b'JpgTiffExif->JP2')
tfile.write(b'Exif\x00\x00')
xbuffer = struct.pack('>BBHI', 77, 77, 42, 8)
tfile.write(xbuffer)
# We will write just a single tag.
tfile.write(struct.pack('>H', 1))
# The "Make" tag is tag no. 271.
tfile.write(struct.pack('>HHI4s', 271, 2, 3, b'HTC\x00'))
tfile.flush()
jp2 = glymur.Jp2k(tfile.name)
self.assertEqual(jp2.box[-1].data.ifds['Image']['Make'], "HTC")
if __name__ == "__main__":
unittest.main()