Skip to content

Instantly share code, notes, and snippets.

@jpstroop
Created June 26, 2016 00:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpstroop/1703ee27b368e67661bd6f00f74f28c7 to your computer and use it in GitHub Desktop.
Save jpstroop/1703ee27b368e67661bd6f00f74f28c7 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
from io import open
from collections import deque
IHDR = b'\x69\x68\x64\x72' # See I.5.3.1 Image Header box
with open('tests/fixtures/images/color.jp2', 'rb') as jp2:
window = deque([], 4)
while bytes(b''.join(window)) != IHDR:
window.append(jp2.read(1))
# The image header box is the only place in the spec where height comes
# first. Go figure.
image_height = int.from_bytes(jp2.read(4), byteorder='big', signed=False)
image_width = int.from_bytes(jp2.read(4), byteorder='big', signed=False)
print(image_width, image_height)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment