summaryrefslogtreecommitdiff
path: root/hacks/dump_dpx.py
blob: 1cab96e25ea2585b4017dd5261af59da48eeb3f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/python3

import sys
import struct

f = open(sys.argv[1], 'rb')

dpx = f.read(768)
magic = dpx[0:4]
if magic == b'XPDS':
    print('Little-endian')
    endian = '<'
elif magic == b'SDPX':
    print('Big-endian')
    endian = '>'
else:
    print('Unrecognised magic word', file=sys.stderr)
    sys.exit(1)

image = f.read(640)
im = dict()
(im['orientation'],
 im['number_elements'],
 im['pixels_per_line'],
 im['lines_per_element'],
 im['data_sign'],
 im['low_data'],
 im['low_quantity'],
 im['high_data'],
 im['high_quantity'],
 im['descriptor'],
 im['transfer'],
 im['colorimetric']) = struct.unpack('%shhiiiififBBB' % endian, image[0:35])

transfer = { 0: 'user-defined', 1: 'printing density', 2: 'linear', 3: 'logarithmic', 4: 'unspecified video', 5: 'SMPTE 240M', 6: 'CCIR 709-1', 7: 'CCIR601-2 system B or G',
             8: 'CCIR 601-2 system M', 9: 'NTSC composite video', 10: 'PAL composite video', 11: 'Z linear', 12: 'Z homogeneous' }

for k, v in im.items():
    if k == 'transfer':
        v = transfer[v]
    print('%s: %s' % (k, v))