|
|
@ -52,8 +52,9 @@ def parse_colr(data):
|
|
|
|
elif enumCS == 17:
|
|
|
|
elif enumCS == 17:
|
|
|
|
return "L"
|
|
|
|
return "L"
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
raise Exception("only sRGB and greyscale color space is supported, "
|
|
|
|
raise Exception(
|
|
|
|
"got %d" % enumCS)
|
|
|
|
"only sRGB and greyscale color space is supported, " "got %d" % enumCS
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def parse_resc(data):
|
|
|
|
def parse_resc(data):
|
|
|
@ -69,9 +70,8 @@ def parse_res(data):
|
|
|
|
byteStart = 0
|
|
|
|
byteStart = 0
|
|
|
|
boxLengthValue = 1 # dummy value for while loop condition
|
|
|
|
boxLengthValue = 1 # dummy value for while loop condition
|
|
|
|
while byteStart < noBytes and boxLengthValue != 0:
|
|
|
|
while byteStart < noBytes and boxLengthValue != 0:
|
|
|
|
boxLengthValue, boxType, byteEnd, boxContents = \
|
|
|
|
boxLengthValue, boxType, byteEnd, boxContents = getBox(data, byteStart, noBytes)
|
|
|
|
getBox(data, byteStart, noBytes)
|
|
|
|
if boxType == b"resc":
|
|
|
|
if boxType == b'resc':
|
|
|
|
|
|
|
|
hdpi, vdpi = parse_resc(boxContents)
|
|
|
|
hdpi, vdpi = parse_resc(boxContents)
|
|
|
|
break
|
|
|
|
break
|
|
|
|
return hdpi, vdpi
|
|
|
|
return hdpi, vdpi
|
|
|
@ -83,13 +83,12 @@ def parse_jp2h(data):
|
|
|
|
byteStart = 0
|
|
|
|
byteStart = 0
|
|
|
|
boxLengthValue = 1 # dummy value for while loop condition
|
|
|
|
boxLengthValue = 1 # dummy value for while loop condition
|
|
|
|
while byteStart < noBytes and boxLengthValue != 0:
|
|
|
|
while byteStart < noBytes and boxLengthValue != 0:
|
|
|
|
boxLengthValue, boxType, byteEnd, boxContents = \
|
|
|
|
boxLengthValue, boxType, byteEnd, boxContents = getBox(data, byteStart, noBytes)
|
|
|
|
getBox(data, byteStart, noBytes)
|
|
|
|
if boxType == b"ihdr":
|
|
|
|
if boxType == b'ihdr':
|
|
|
|
|
|
|
|
width, height = parse_ihdr(boxContents)
|
|
|
|
width, height = parse_ihdr(boxContents)
|
|
|
|
elif boxType == b'colr':
|
|
|
|
elif boxType == b"colr":
|
|
|
|
colorspace = parse_colr(boxContents)
|
|
|
|
colorspace = parse_colr(boxContents)
|
|
|
|
elif boxType == b'res ':
|
|
|
|
elif boxType == b"res ":
|
|
|
|
hdpi, vdpi = parse_res(boxContents)
|
|
|
|
hdpi, vdpi = parse_res(boxContents)
|
|
|
|
byteStart = byteEnd
|
|
|
|
byteStart = byteEnd
|
|
|
|
return (width, height, colorspace, hdpi, vdpi)
|
|
|
|
return (width, height, colorspace, hdpi, vdpi)
|
|
|
@ -101,9 +100,8 @@ def parsejp2(data):
|
|
|
|
boxLengthValue = 1 # dummy value for while loop condition
|
|
|
|
boxLengthValue = 1 # dummy value for while loop condition
|
|
|
|
width, height, colorspace, hdpi, vdpi = None, None, None, None, None
|
|
|
|
width, height, colorspace, hdpi, vdpi = None, None, None, None, None
|
|
|
|
while byteStart < noBytes and boxLengthValue != 0:
|
|
|
|
while byteStart < noBytes and boxLengthValue != 0:
|
|
|
|
boxLengthValue, boxType, byteEnd, boxContents = \
|
|
|
|
boxLengthValue, boxType, byteEnd, boxContents = getBox(data, byteStart, noBytes)
|
|
|
|
getBox(data, byteStart, noBytes)
|
|
|
|
if boxType == b"jp2h":
|
|
|
|
if boxType == b'jp2h':
|
|
|
|
|
|
|
|
width, height, colorspace, hdpi, vdpi = parse_jp2h(boxContents)
|
|
|
|
width, height, colorspace, hdpi, vdpi = parse_jp2h(boxContents)
|
|
|
|
break
|
|
|
|
break
|
|
|
|
byteStart = byteEnd
|
|
|
|
byteStart = byteEnd
|
|
|
@ -119,6 +117,7 @@ def parsejp2(data):
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
if __name__ == "__main__":
|
|
|
|
import sys
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
width, height, colorspace = parsejp2(open(sys.argv[1]).read())
|
|
|
|
width, height, colorspace = parsejp2(open(sys.argv[1]).read())
|
|
|
|
sys.stdout.write("width = %d" % width)
|
|
|
|
sys.stdout.write("width = %d" % width)
|
|
|
|
sys.stdout.write("height = %d" % height)
|
|
|
|
sys.stdout.write("height = %d" % height)
|
|
|
|