Created
June 26, 2016 00:38
-
-
Save jpstroop/1703ee27b368e67661bd6f00f74f28c7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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