Glymur 0.13.7__py3-none-any.whl → 0.13.8__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {Glymur-0.13.7.dist-info → Glymur-0.13.8.dist-info}/METADATA +2 -1
- Glymur-0.13.8.dist-info/RECORD +25 -0
- glymur/_iccprofile.py +73 -72
- glymur/codestream.py +385 -308
- glymur/config.py +15 -14
- glymur/core.py +18 -22
- glymur/jp2box.py +732 -573
- glymur/jp2k.py +185 -149
- glymur/jp2kr.py +59 -45
- glymur/lib/openjp2.py +198 -285
- glymur/lib/tiff.py +1152 -1156
- glymur/options.py +33 -28
- glymur/tiff.py +105 -103
- glymur/version.py +1 -1
- Glymur-0.13.7.dist-info/RECORD +0 -25
- {Glymur-0.13.7.dist-info → Glymur-0.13.8.dist-info}/LICENSE.txt +0 -0
- {Glymur-0.13.7.dist-info → Glymur-0.13.8.dist-info}/WHEEL +0 -0
- {Glymur-0.13.7.dist-info → Glymur-0.13.8.dist-info}/entry_points.txt +0 -0
- {Glymur-0.13.7.dist-info → Glymur-0.13.8.dist-info}/top_level.txt +0 -0
glymur/codestream.py
CHANGED
|
@@ -14,23 +14,28 @@ import numpy as np
|
|
|
14
14
|
|
|
15
15
|
# local imports
|
|
16
16
|
from .core import (
|
|
17
|
-
LRCP,
|
|
18
|
-
|
|
17
|
+
LRCP,
|
|
18
|
+
RLCP,
|
|
19
|
+
RPCL,
|
|
20
|
+
PCRL,
|
|
21
|
+
CPRL,
|
|
22
|
+
WAVELET_XFORM_9X7_IRREVERSIBLE,
|
|
23
|
+
WAVELET_XFORM_5X3_REVERSIBLE,
|
|
19
24
|
)
|
|
20
25
|
from .lib import openjp2 as opj2
|
|
21
26
|
|
|
22
27
|
|
|
23
28
|
_PROGRESSION_ORDER_DISPLAY = {
|
|
24
|
-
LRCP:
|
|
25
|
-
RLCP:
|
|
26
|
-
RPCL:
|
|
27
|
-
PCRL:
|
|
28
|
-
CPRL:
|
|
29
|
+
LRCP: "LRCP",
|
|
30
|
+
RLCP: "RLCP",
|
|
31
|
+
RPCL: "RPCL",
|
|
32
|
+
PCRL: "PCRL",
|
|
33
|
+
CPRL: "CPRL",
|
|
29
34
|
}
|
|
30
35
|
|
|
31
36
|
_WAVELET_XFORM_DISPLAY = {
|
|
32
|
-
WAVELET_XFORM_9X7_IRREVERSIBLE:
|
|
33
|
-
WAVELET_XFORM_5X3_REVERSIBLE:
|
|
37
|
+
WAVELET_XFORM_9X7_IRREVERSIBLE: "9-7 irreversible",
|
|
38
|
+
WAVELET_XFORM_5X3_REVERSIBLE: "5-3 reversible",
|
|
34
39
|
}
|
|
35
40
|
|
|
36
41
|
_NO_PROFILE = 0
|
|
@@ -95,24 +100,24 @@ _PROFILE_IMF_8K_R = 0x0900
|
|
|
95
100
|
|
|
96
101
|
# How to display the codestream profile.
|
|
97
102
|
_CAPABILITIES_DISPLAY = {
|
|
98
|
-
_PROFILE_NONE:
|
|
99
|
-
_PROFILE_0:
|
|
100
|
-
_PROFILE_1:
|
|
101
|
-
_PROFILE_PART2:
|
|
102
|
-
_PROFILE_CINEMA_2K:
|
|
103
|
-
_PROFILE_CINEMA_4K:
|
|
104
|
-
_PROFILE_CINEMA_S2K:
|
|
105
|
-
_PROFILE_CINEMA_S4K:
|
|
106
|
-
_PROFILE_CINEMA_LTS:
|
|
107
|
-
_PROFILE_BC_SINGLE:
|
|
108
|
-
_PROFILE_BC_MULTI:
|
|
109
|
-
_PROFILE_BC_MULTI_R:
|
|
110
|
-
_PROFILE_IMF_2K:
|
|
111
|
-
_PROFILE_IMF_4K:
|
|
112
|
-
_PROFILE_IMF_8K:
|
|
113
|
-
_PROFILE_IMF_2K_R:
|
|
114
|
-
_PROFILE_IMF_4K_R:
|
|
115
|
-
_PROFILE_IMF_8K_R:
|
|
103
|
+
_PROFILE_NONE: "no profile",
|
|
104
|
+
_PROFILE_0: "0",
|
|
105
|
+
_PROFILE_1: "1",
|
|
106
|
+
_PROFILE_PART2: "at least 1 extension defined in 15444-2 (Part-2)",
|
|
107
|
+
_PROFILE_CINEMA_2K: "2K cinema",
|
|
108
|
+
_PROFILE_CINEMA_4K: "4K cinema",
|
|
109
|
+
_PROFILE_CINEMA_S2K: "scalable 2K cinema",
|
|
110
|
+
_PROFILE_CINEMA_S4K: "scalable 4K cinema",
|
|
111
|
+
_PROFILE_CINEMA_LTS: "long term storage cinema",
|
|
112
|
+
_PROFILE_BC_SINGLE: "single tile broadcast",
|
|
113
|
+
_PROFILE_BC_MULTI: "multi tile broadcast",
|
|
114
|
+
_PROFILE_BC_MULTI_R: "multi tile reversible broadcast",
|
|
115
|
+
_PROFILE_IMF_2K: "2K single tile lossy IMF",
|
|
116
|
+
_PROFILE_IMF_4K: "4K single tile lossy IMF",
|
|
117
|
+
_PROFILE_IMF_8K: "8K single tile lossy IMF",
|
|
118
|
+
_PROFILE_IMF_2K_R: "2K single/multi tile reversible IMF",
|
|
119
|
+
_PROFILE_IMF_4K_R: "4K single/multi tile reversible IMF",
|
|
120
|
+
_PROFILE_IMF_8K_R: "8K single/multi tile reversible IMF",
|
|
116
121
|
}
|
|
117
122
|
|
|
118
123
|
_KNOWN_PROFILES = _CAPABILITIES_DISPLAY.keys()
|
|
@@ -140,6 +145,7 @@ class Codestream(object):
|
|
|
140
145
|
15444-1:2004 - Information technology -- JPEG 2000 image coding system:
|
|
141
146
|
Core coding system
|
|
142
147
|
"""
|
|
148
|
+
|
|
143
149
|
# These two begin their lives as class attributes that usually become
|
|
144
150
|
# instance attributes. The reason why isn't important for users; it's only
|
|
145
151
|
# important for testing purposes.
|
|
@@ -168,65 +174,62 @@ class Codestream(object):
|
|
|
168
174
|
# We really don't know what to do with them, so they are treated as if
|
|
169
175
|
# they are reserved markers.
|
|
170
176
|
self.parse_marker_segment_fcn = {
|
|
171
|
-
|
|
172
177
|
# The following are definitively reserved markers according to
|
|
173
178
|
# table A-1 in ISO/IEC FCD15444-1.
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
179
|
+
0xFF30: self._parse_reserved_marker,
|
|
180
|
+
0xFF31: self._parse_reserved_marker,
|
|
181
|
+
0xFF32: self._parse_reserved_marker,
|
|
182
|
+
0xFF33: self._parse_reserved_marker,
|
|
183
|
+
0xFF34: self._parse_reserved_marker,
|
|
184
|
+
0xFF35: self._parse_reserved_marker,
|
|
185
|
+
0xFF36: self._parse_reserved_marker,
|
|
186
|
+
0xFF37: self._parse_reserved_marker,
|
|
187
|
+
0xFF38: self._parse_reserved_marker,
|
|
188
|
+
0xFF39: self._parse_reserved_marker,
|
|
189
|
+
0xFF3A: self._parse_reserved_marker,
|
|
190
|
+
0xFF3B: self._parse_reserved_marker,
|
|
191
|
+
0xFF3C: self._parse_reserved_marker,
|
|
192
|
+
0xFF3D: self._parse_reserved_marker,
|
|
193
|
+
0xFF3E: self._parse_reserved_marker,
|
|
194
|
+
0xFF3F: self._parse_reserved_marker,
|
|
191
195
|
# 0xff4f: SOC (already encountered by the time we get here)
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
196
|
+
0xFF50: self._parse_cap_segment,
|
|
197
|
+
0xFF51: self._parse_siz_segment,
|
|
198
|
+
0xFF52: self._parse_cod_segment,
|
|
199
|
+
0xFF53: self._parse_coc_segment,
|
|
200
|
+
0xFF54: self._parse_reserved_segment,
|
|
201
|
+
0xFF55: self._parse_tlm_segment,
|
|
202
|
+
0xFF56: self._parse_reserved_segment,
|
|
203
|
+
0xFF57: self._parse_reserved_segment,
|
|
204
|
+
0xFF58: self._parse_plt_segment,
|
|
205
|
+
0xFF59: self._parse_reserved_segment,
|
|
206
|
+
0xFF5A: self._parse_reserved_segment,
|
|
207
|
+
0xFF5B: self._parse_reserved_segment,
|
|
208
|
+
0xFF5C: self._parse_qcd_segment,
|
|
209
|
+
0xFF5D: self._parse_qcc_segment,
|
|
210
|
+
0xFF5E: self._parse_rgn_segment,
|
|
211
|
+
0xFF5F: self._parse_pod_segment,
|
|
212
|
+
0xFF60: self._parse_ppm_segment,
|
|
213
|
+
0xFF61: self._parse_ppt_segment,
|
|
214
|
+
0xFF62: self._parse_reserved_segment,
|
|
215
|
+
0xFF63: self._parse_crg_segment,
|
|
216
|
+
0xFF64: self._parse_cme_segment,
|
|
217
|
+
0xFF65: self._parse_reserved_segment,
|
|
218
|
+
0xFF66: self._parse_reserved_segment,
|
|
219
|
+
0xFF67: self._parse_reserved_segment,
|
|
220
|
+
0xFF68: self._parse_reserved_segment,
|
|
221
|
+
0xFF69: self._parse_reserved_segment,
|
|
222
|
+
0xFF6A: self._parse_reserved_segment,
|
|
223
|
+
0xFF6B: self._parse_reserved_segment,
|
|
224
|
+
0xFF6C: self._parse_reserved_segment,
|
|
225
|
+
0xFF6D: self._parse_reserved_segment,
|
|
226
|
+
0xFF6E: self._parse_reserved_segment,
|
|
227
|
+
0xFF6F: self._parse_reserved_segment,
|
|
228
|
+
0xFF90: self._parse_sot_segment,
|
|
225
229
|
# 0xff91: SOP (only found in bit stream)
|
|
226
230
|
# 0xff92: EPH (only found in bit stream)
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
231
|
+
0xFF93: self._parse_sod_marker,
|
|
232
|
+
0xFFD9: self._parse_eoc_marker,
|
|
230
233
|
}
|
|
231
234
|
|
|
232
235
|
self.offset = fptr.tell()
|
|
@@ -254,27 +257,27 @@ class Codestream(object):
|
|
|
254
257
|
read_buffer = fptr.read(2)
|
|
255
258
|
|
|
256
259
|
try:
|
|
257
|
-
self._marker_id, = struct.unpack(
|
|
260
|
+
(self._marker_id,) = struct.unpack(">H", read_buffer)
|
|
258
261
|
except struct.error as e:
|
|
259
262
|
msg = (
|
|
260
263
|
f"Unable to read an expected marker in the codestream "
|
|
261
|
-
f
|
|
264
|
+
f'at byte offset {fptr.tell()}. "{e}".'
|
|
262
265
|
)
|
|
263
266
|
raise J2KParseError(msg)
|
|
264
267
|
|
|
265
|
-
if self._marker_id <
|
|
268
|
+
if self._marker_id < 0xFF00:
|
|
266
269
|
offset = fptr.tell() - 2
|
|
267
270
|
msg = (
|
|
268
|
-
f
|
|
269
|
-
f
|
|
270
|
-
f
|
|
271
|
-
f
|
|
271
|
+
f"Invalid codestream marker at byte offset {offset}. It "
|
|
272
|
+
f"must be must be greater than 0xff00, but "
|
|
273
|
+
f"found 0x{self._marker_id:04x} instead. Codestream "
|
|
274
|
+
f"parsing will cease."
|
|
272
275
|
)
|
|
273
276
|
raise ValueError(msg)
|
|
274
277
|
|
|
275
278
|
self._offset = fptr.tell() - 2
|
|
276
279
|
|
|
277
|
-
if self._marker_id ==
|
|
280
|
+
if self._marker_id == 0xFF90 and self.header_only:
|
|
278
281
|
# Start-of-tile (SOT) means that we are out of the main header
|
|
279
282
|
# and there is no need to go further.
|
|
280
283
|
break
|
|
@@ -286,13 +289,13 @@ class Codestream(object):
|
|
|
286
289
|
|
|
287
290
|
self.segment.append(segment)
|
|
288
291
|
|
|
289
|
-
if self._marker_id ==
|
|
292
|
+
if self._marker_id == 0xFFD9:
|
|
290
293
|
# end of codestream, should break.
|
|
291
294
|
break
|
|
292
295
|
|
|
293
296
|
# If the marker ID is SOD, then we need to seek past the tile part
|
|
294
297
|
# bit stream.
|
|
295
|
-
if self._marker_id ==
|
|
298
|
+
if self._marker_id == 0xFF93:
|
|
296
299
|
|
|
297
300
|
if self._parse_tpart_flag and not self.header_only:
|
|
298
301
|
# But first parse the tile part bit stream for SOP and
|
|
@@ -320,14 +323,18 @@ class Codestream(object):
|
|
|
320
323
|
offset = fptr.tell() - 2
|
|
321
324
|
|
|
322
325
|
read_buffer = fptr.read(2)
|
|
323
|
-
length, = struct.unpack(
|
|
326
|
+
(length,) = struct.unpack(">H", read_buffer)
|
|
324
327
|
if length > 0:
|
|
325
328
|
data = fptr.read(length - 2)
|
|
326
329
|
else:
|
|
327
330
|
data = None
|
|
328
331
|
|
|
329
|
-
segment = Segment(
|
|
330
|
-
|
|
332
|
+
segment = Segment(
|
|
333
|
+
marker_id=f"0x{self._marker_id:x}",
|
|
334
|
+
offset=offset,
|
|
335
|
+
length=length,
|
|
336
|
+
data=data
|
|
337
|
+
)
|
|
331
338
|
return segment
|
|
332
339
|
|
|
333
340
|
def _parse_tile_part_bit_stream(self, fptr, sod_marker, tile_length):
|
|
@@ -338,14 +345,14 @@ class Codestream(object):
|
|
|
338
345
|
count = min(tile_length, len(read_buffer))
|
|
339
346
|
packet = np.frombuffer(read_buffer, dtype=np.uint8, count=count)
|
|
340
347
|
|
|
341
|
-
indices = np.where(packet ==
|
|
348
|
+
indices = np.where(packet == 0xFF)
|
|
342
349
|
for idx in indices[0]:
|
|
343
350
|
try:
|
|
344
351
|
if packet[idx + 1] == 0x91 and (idx < (len(packet) - 5)):
|
|
345
352
|
offset = sod_marker.offset + 2 + idx
|
|
346
353
|
length = 4
|
|
347
|
-
nsop = packet[(idx + 4):(idx + 6)].view(
|
|
348
|
-
if sys.byteorder ==
|
|
354
|
+
nsop = packet[(idx + 4):(idx + 6)].view("uint16")[0]
|
|
355
|
+
if sys.byteorder == "little":
|
|
349
356
|
nsop = nsop.byteswap()
|
|
350
357
|
segment = SOPsegment(nsop, length, offset)
|
|
351
358
|
self.segment.append(segment)
|
|
@@ -358,13 +365,13 @@ class Codestream(object):
|
|
|
358
365
|
continue
|
|
359
366
|
|
|
360
367
|
def __str__(self):
|
|
361
|
-
msg =
|
|
368
|
+
msg = "Codestream:\n"
|
|
362
369
|
for segment in self.segment:
|
|
363
370
|
strs = str(segment)
|
|
364
371
|
|
|
365
372
|
# Add indentation
|
|
366
|
-
strs = [(
|
|
367
|
-
msg +=
|
|
373
|
+
strs = [(" " + x + "\n") for x in strs.split("\n")]
|
|
374
|
+
msg += "".join(strs)
|
|
368
375
|
return msg.rstrip()
|
|
369
376
|
|
|
370
377
|
def _parse_cme_segment(self, fptr):
|
|
@@ -383,7 +390,7 @@ class Codestream(object):
|
|
|
383
390
|
offset = fptr.tell() - 2
|
|
384
391
|
|
|
385
392
|
read_buffer = fptr.read(4)
|
|
386
|
-
data = struct.unpack(
|
|
393
|
+
data = struct.unpack(">HH", read_buffer)
|
|
387
394
|
length = data[0]
|
|
388
395
|
rcme = data[1]
|
|
389
396
|
ccme = fptr.read(length - 4)
|
|
@@ -405,19 +412,19 @@ class Codestream(object):
|
|
|
405
412
|
"""
|
|
406
413
|
kwargs = {}
|
|
407
414
|
offset = fptr.tell() - 2
|
|
408
|
-
kwargs[
|
|
415
|
+
kwargs["offset"] = offset
|
|
409
416
|
|
|
410
417
|
read_buffer = fptr.read(2)
|
|
411
|
-
length, = struct.unpack(
|
|
412
|
-
kwargs[
|
|
418
|
+
(length,) = struct.unpack(">H", read_buffer)
|
|
419
|
+
kwargs["length"] = length
|
|
413
420
|
|
|
414
|
-
fmt =
|
|
421
|
+
fmt = ">B" if self._csiz <= 255 else ">H"
|
|
415
422
|
nbytes = 1 if self._csiz <= 255 else 2
|
|
416
423
|
read_buffer = fptr.read(nbytes)
|
|
417
|
-
ccoc, = struct.unpack(fmt, read_buffer)
|
|
424
|
+
(ccoc,) = struct.unpack(fmt, read_buffer)
|
|
418
425
|
|
|
419
426
|
read_buffer = fptr.read(1)
|
|
420
|
-
scoc, = struct.unpack(
|
|
427
|
+
(scoc,) = struct.unpack(">B", read_buffer)
|
|
421
428
|
|
|
422
429
|
numbytes = offset + 2 + length - fptr.tell()
|
|
423
430
|
read_buffer = fptr.read(numbytes)
|
|
@@ -443,11 +450,11 @@ class Codestream(object):
|
|
|
443
450
|
offset = fptr.tell() - 2
|
|
444
451
|
|
|
445
452
|
read_buffer = fptr.read(2)
|
|
446
|
-
length, = struct.unpack(
|
|
453
|
+
(length,) = struct.unpack(">H", read_buffer)
|
|
447
454
|
|
|
448
455
|
read_buffer = fptr.read(length - 2)
|
|
449
456
|
|
|
450
|
-
lst = struct.unpack_from(
|
|
457
|
+
lst = struct.unpack_from(">BBHBBBBBB", read_buffer, offset=0)
|
|
451
458
|
scod, prog, nlayers, mct, nr, xcb, ycb, cstyle, xform = lst
|
|
452
459
|
|
|
453
460
|
if len(read_buffer) > 10:
|
|
@@ -463,10 +470,20 @@ class Codestream(object):
|
|
|
463
470
|
else:
|
|
464
471
|
cls._parse_tpart_flag = False
|
|
465
472
|
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
473
|
+
return CODsegment(
|
|
474
|
+
scod,
|
|
475
|
+
prog,
|
|
476
|
+
nlayers,
|
|
477
|
+
mct,
|
|
478
|
+
nr,
|
|
479
|
+
xcb,
|
|
480
|
+
ycb,
|
|
481
|
+
cstyle,
|
|
482
|
+
xform,
|
|
483
|
+
precinct_size,
|
|
484
|
+
length=length,
|
|
485
|
+
offset=offset
|
|
486
|
+
)
|
|
470
487
|
|
|
471
488
|
def _parse_crg_segment(self, fptr):
|
|
472
489
|
"""Parse the CRG marker segment.
|
|
@@ -484,10 +501,10 @@ class Codestream(object):
|
|
|
484
501
|
offset = fptr.tell() - 2
|
|
485
502
|
|
|
486
503
|
read_buffer = fptr.read(2)
|
|
487
|
-
length, = struct.unpack(
|
|
504
|
+
(length,) = struct.unpack(">H", read_buffer)
|
|
488
505
|
|
|
489
506
|
read_buffer = fptr.read(4 * self._csiz)
|
|
490
|
-
data = struct.unpack(
|
|
507
|
+
data = struct.unpack(">" + "HH" * self._csiz, read_buffer)
|
|
491
508
|
xcrg = data[0::2]
|
|
492
509
|
ycrg = data[1::2]
|
|
493
510
|
|
|
@@ -530,7 +547,7 @@ class Codestream(object):
|
|
|
530
547
|
offset = fptr.tell() - 2
|
|
531
548
|
|
|
532
549
|
read_buffer = fptr.read(3)
|
|
533
|
-
length, zplt = struct.unpack(
|
|
550
|
+
length, zplt = struct.unpack(">HB", read_buffer)
|
|
534
551
|
|
|
535
552
|
numbytes = length - 3
|
|
536
553
|
read_buffer = fptr.read(numbytes)
|
|
@@ -539,7 +556,7 @@ class Codestream(object):
|
|
|
539
556
|
packet_len = []
|
|
540
557
|
plen = 0
|
|
541
558
|
for byte in iplt:
|
|
542
|
-
plen |=
|
|
559
|
+
plen |= byte & 0x7F
|
|
543
560
|
if byte & 0x80:
|
|
544
561
|
# Continue by or-ing in the next byte.
|
|
545
562
|
plen <<= 7
|
|
@@ -567,13 +584,13 @@ class Codestream(object):
|
|
|
567
584
|
offset = fptr.tell() - 2
|
|
568
585
|
|
|
569
586
|
read_buffer = fptr.read(2)
|
|
570
|
-
length, = struct.unpack(
|
|
587
|
+
(length,) = struct.unpack(">H", read_buffer)
|
|
571
588
|
|
|
572
589
|
n = ((length - 2) / 7) if self._csiz < 257 else ((length - 2) / 9)
|
|
573
590
|
n = int(n)
|
|
574
591
|
nbytes = n * 7 if self._csiz < 257 else n * 9
|
|
575
592
|
read_buffer = fptr.read(nbytes)
|
|
576
|
-
fmt =
|
|
593
|
+
fmt = ">" + "BBHBBB" * n if self._csiz < 257 else ">" + "BHHBHB" * n
|
|
577
594
|
pod_params = struct.unpack(fmt, read_buffer)
|
|
578
595
|
|
|
579
596
|
return PODsegment(pod_params, length, offset)
|
|
@@ -594,7 +611,7 @@ class Codestream(object):
|
|
|
594
611
|
offset = fptr.tell() - 2
|
|
595
612
|
|
|
596
613
|
read_buffer = fptr.read(3)
|
|
597
|
-
length, zppm = struct.unpack(
|
|
614
|
+
length, zppm = struct.unpack(">HB", read_buffer)
|
|
598
615
|
|
|
599
616
|
numbytes = length - 3
|
|
600
617
|
read_buffer = fptr.read(numbytes)
|
|
@@ -620,7 +637,7 @@ class Codestream(object):
|
|
|
620
637
|
offset = fptr.tell() - 2
|
|
621
638
|
|
|
622
639
|
read_buffer = fptr.read(3)
|
|
623
|
-
length, zppt = struct.unpack(
|
|
640
|
+
length, zppt = struct.unpack(">HB", read_buffer)
|
|
624
641
|
length = length
|
|
625
642
|
zppt = zppt
|
|
626
643
|
|
|
@@ -646,15 +663,17 @@ class Codestream(object):
|
|
|
646
663
|
offset = fptr.tell() - 2
|
|
647
664
|
|
|
648
665
|
read_buffer = fptr.read(2)
|
|
649
|
-
length, = struct.unpack(
|
|
666
|
+
(length,) = struct.unpack(">H", read_buffer)
|
|
650
667
|
|
|
651
668
|
read_buffer = fptr.read(length - 2)
|
|
652
|
-
fmt =
|
|
669
|
+
fmt = ">HB" if cls._csiz > 256 else ">BB"
|
|
653
670
|
mantissa_exponent_offset = 3 if cls._csiz > 256 else 2
|
|
654
671
|
cqcc, sqcc = struct.unpack_from(fmt, read_buffer)
|
|
655
672
|
if cqcc >= cls._csiz:
|
|
656
|
-
msg = (
|
|
657
|
-
|
|
673
|
+
msg = (
|
|
674
|
+
"Invalid QCC component number ({cqcc}), "
|
|
675
|
+
"the actual number of components is only {cls._csiz}."
|
|
676
|
+
)
|
|
658
677
|
warnings.warn(msg, UserWarning)
|
|
659
678
|
|
|
660
679
|
spqcc = read_buffer[mantissa_exponent_offset:]
|
|
@@ -677,7 +696,7 @@ class Codestream(object):
|
|
|
677
696
|
offset = fptr.tell() - 2
|
|
678
697
|
|
|
679
698
|
read_buffer = fptr.read(3)
|
|
680
|
-
length, sqcd = struct.unpack(
|
|
699
|
+
length, sqcd = struct.unpack(">HB", read_buffer)
|
|
681
700
|
spqcd = fptr.read(length - 3)
|
|
682
701
|
|
|
683
702
|
return QCDsegment(sqcd, spqcd, length, offset)
|
|
@@ -699,10 +718,10 @@ class Codestream(object):
|
|
|
699
718
|
offset = fptr.tell() - 2
|
|
700
719
|
|
|
701
720
|
read_buffer = fptr.read(2)
|
|
702
|
-
length, = struct.unpack(
|
|
721
|
+
(length,) = struct.unpack(">H", read_buffer)
|
|
703
722
|
|
|
704
723
|
nbytes = 3 if cls._csiz < 257 else 4
|
|
705
|
-
fmt =
|
|
724
|
+
fmt = ">BBB" if cls._csiz < 257 else ">HBB"
|
|
706
725
|
read_buffer = fptr.read(nbytes)
|
|
707
726
|
data = struct.unpack(fmt, read_buffer)
|
|
708
727
|
|
|
@@ -730,16 +749,19 @@ class Codestream(object):
|
|
|
730
749
|
offset = fptr.tell() - 2
|
|
731
750
|
|
|
732
751
|
read_buffer = fptr.read(2)
|
|
733
|
-
length, = struct.unpack(
|
|
752
|
+
(length,) = struct.unpack(">H", read_buffer)
|
|
734
753
|
read_buffer = fptr.read(length - 2)
|
|
735
754
|
|
|
736
|
-
pcap, = struct.unpack(
|
|
755
|
+
(pcap,) = struct.unpack(">I", read_buffer[:4])
|
|
737
756
|
|
|
738
757
|
n = (length - 6) // 2
|
|
739
|
-
ccap = struct.unpack(
|
|
758
|
+
ccap = struct.unpack(">" + "H" * n, read_buffer[4:])
|
|
740
759
|
|
|
741
760
|
segment = CAPsegment(
|
|
742
|
-
pcap=pcap,
|
|
761
|
+
pcap=pcap,
|
|
762
|
+
ccap=ccap,
|
|
763
|
+
length=length,
|
|
764
|
+
offset=offset,
|
|
743
765
|
)
|
|
744
766
|
|
|
745
767
|
return segment
|
|
@@ -761,10 +783,10 @@ class Codestream(object):
|
|
|
761
783
|
offset = fptr.tell() - 2
|
|
762
784
|
|
|
763
785
|
read_buffer = fptr.read(2)
|
|
764
|
-
length, = struct.unpack(
|
|
786
|
+
(length,) = struct.unpack(">H", read_buffer)
|
|
765
787
|
|
|
766
788
|
read_buffer = fptr.read(length - 2)
|
|
767
|
-
data = struct.unpack_from(
|
|
789
|
+
data = struct.unpack_from(">HIIIIIIIIH", read_buffer)
|
|
768
790
|
|
|
769
791
|
rsiz = data[0]
|
|
770
792
|
|
|
@@ -781,18 +803,20 @@ class Codestream(object):
|
|
|
781
803
|
# Csiz is the number of components
|
|
782
804
|
Csiz = data[9]
|
|
783
805
|
|
|
784
|
-
|
|
785
|
-
|
|
806
|
+
format = ">" + "B" * (length - 36 - 2)
|
|
807
|
+
data = struct.unpack_from(format, read_buffer, offset=36)
|
|
786
808
|
|
|
787
|
-
bitdepth = tuple(((x &
|
|
809
|
+
bitdepth = tuple(((x & 0x7F) + 1) for x in data[0::3])
|
|
788
810
|
signed = tuple(((x & 0x80) > 0) for x in data[0::3])
|
|
789
811
|
xrsiz = data[1::3]
|
|
790
812
|
yrsiz = data[2::3]
|
|
791
813
|
|
|
792
814
|
for j, subsampling in enumerate(zip(xrsiz, yrsiz)):
|
|
793
815
|
if 0 in subsampling:
|
|
794
|
-
msg = (
|
|
795
|
-
|
|
816
|
+
msg = (
|
|
817
|
+
f"Invalid subsampling value for component {j}: "
|
|
818
|
+
f"dx={subsampling[0]}, dy={subsampling[1]}."
|
|
819
|
+
)
|
|
796
820
|
warnings.warn(msg, UserWarning)
|
|
797
821
|
|
|
798
822
|
try:
|
|
@@ -811,17 +835,17 @@ class Codestream(object):
|
|
|
811
835
|
warnings.warn(msg, UserWarning)
|
|
812
836
|
|
|
813
837
|
kwargs = {
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
838
|
+
"rsiz": rsiz,
|
|
839
|
+
"xysiz": xysiz,
|
|
840
|
+
"xyosiz": xyosiz,
|
|
841
|
+
"xytsiz": xytsiz,
|
|
842
|
+
"xytosiz": xytosiz,
|
|
843
|
+
"Csiz": Csiz,
|
|
844
|
+
"bitdepth": bitdepth,
|
|
845
|
+
"signed": signed,
|
|
846
|
+
"xyrsiz": (xrsiz, yrsiz),
|
|
847
|
+
"length": length,
|
|
848
|
+
"offset": offset,
|
|
825
849
|
}
|
|
826
850
|
segment = SIZsegment(**kwargs)
|
|
827
851
|
|
|
@@ -865,7 +889,7 @@ class Codestream(object):
|
|
|
865
889
|
offset = fptr.tell() - 2
|
|
866
890
|
|
|
867
891
|
read_buffer = fptr.read(10)
|
|
868
|
-
data = struct.unpack(
|
|
892
|
+
data = struct.unpack(">HHIBB", read_buffer)
|
|
869
893
|
|
|
870
894
|
length = data[0]
|
|
871
895
|
isot = data[1]
|
|
@@ -905,21 +929,22 @@ class Codestream(object):
|
|
|
905
929
|
offset = fptr.tell() - 2
|
|
906
930
|
|
|
907
931
|
read_buffer = fptr.read(2)
|
|
908
|
-
length, = struct.unpack(
|
|
932
|
+
(length,) = struct.unpack(">H", read_buffer)
|
|
909
933
|
|
|
910
934
|
read_buffer = fptr.read(length - 2)
|
|
911
|
-
ztlm, stlm = struct.unpack_from(
|
|
935
|
+
ztlm, stlm = struct.unpack_from(">BB", read_buffer)
|
|
912
936
|
st = (stlm >> 4) & 0x3
|
|
913
937
|
sp = (stlm >> 6) & 0x1
|
|
914
938
|
|
|
915
939
|
nbytes = length - 4
|
|
916
940
|
ntiles = nbytes / (st + (sp + 1) * 2)
|
|
917
941
|
|
|
918
|
-
fmt = {0:
|
|
919
|
-
fmt += {0:
|
|
942
|
+
fmt = {0: "", 1: "B", 2: "H"}[st]
|
|
943
|
+
fmt += {0: "H", 1: "I"}[sp]
|
|
944
|
+
|
|
945
|
+
format = ">" + fmt * int(ntiles)
|
|
946
|
+
data = struct.unpack_from(format, read_buffer, offset=2)
|
|
920
947
|
|
|
921
|
-
data = struct.unpack_from('>' + fmt * int(ntiles), read_buffer,
|
|
922
|
-
offset=2)
|
|
923
948
|
if st == 0:
|
|
924
949
|
ttlm = None
|
|
925
950
|
ptlm = data
|
|
@@ -930,9 +955,8 @@ class Codestream(object):
|
|
|
930
955
|
return TLMsegment(ztlm, ttlm, ptlm, length, offset)
|
|
931
956
|
|
|
932
957
|
def _parse_reserved_marker(self, fptr):
|
|
933
|
-
"""Marker range between 0xff30 and 0xff39.
|
|
934
|
-
""
|
|
935
|
-
the_id = f'0x{self._marker_id:x}'
|
|
958
|
+
"""Marker range between 0xff30 and 0xff39."""
|
|
959
|
+
the_id = f"0x{self._marker_id:x}"
|
|
936
960
|
segment = Segment(marker_id=the_id, offset=self._offset, length=0)
|
|
937
961
|
return segment
|
|
938
962
|
|
|
@@ -953,15 +977,18 @@ class Segment(object):
|
|
|
953
977
|
Uninterpreted buffer of raw bytes, only used where a segment is not
|
|
954
978
|
well understood.
|
|
955
979
|
"""
|
|
956
|
-
|
|
980
|
+
|
|
981
|
+
def __init__(self, marker_id="", offset=-1, length=-1, data=None):
|
|
957
982
|
self.marker_id = marker_id
|
|
958
983
|
self.offset = offset
|
|
959
984
|
self.length = length
|
|
960
985
|
self.data = data
|
|
961
986
|
|
|
962
987
|
def __str__(self):
|
|
963
|
-
msg = (
|
|
964
|
-
|
|
988
|
+
msg = (
|
|
989
|
+
f"{self.marker_id} marker segment @ "
|
|
990
|
+
f"({self.offset}, {self.length})"
|
|
991
|
+
)
|
|
965
992
|
return msg
|
|
966
993
|
|
|
967
994
|
|
|
@@ -983,8 +1010,9 @@ class CAPsegment(Segment):
|
|
|
983
1010
|
ccap : 16-bit unsigned int
|
|
984
1011
|
The precise meaning depends on the related parts of ISO/IEC 15444-k.
|
|
985
1012
|
"""
|
|
1013
|
+
|
|
986
1014
|
def __init__(self, pcap, ccap, length, offset):
|
|
987
|
-
super().__init__(marker_id=
|
|
1015
|
+
super().__init__(marker_id="CAP")
|
|
988
1016
|
self.pcap = pcap
|
|
989
1017
|
self.ccap = ccap
|
|
990
1018
|
self.length = length
|
|
@@ -993,17 +1021,18 @@ class CAPsegment(Segment):
|
|
|
993
1021
|
def __str__(self):
|
|
994
1022
|
msg = Segment.__str__(self)
|
|
995
1023
|
|
|
996
|
-
msg +=
|
|
1024
|
+
msg += "\n"
|
|
997
1025
|
|
|
998
1026
|
# have to cast to uint64 because, you know, stupid windows
|
|
999
1027
|
parts = [
|
|
1000
|
-
k
|
|
1028
|
+
k
|
|
1029
|
+
for k in range(32)
|
|
1001
1030
|
if np.bitwise_and(np.uint64(self.pcap), np.uint64(1 << (32 - k)))
|
|
1002
1031
|
]
|
|
1003
1032
|
|
|
1004
1033
|
for b in parts:
|
|
1005
|
-
msg += f
|
|
1006
|
-
msg += f
|
|
1034
|
+
msg += f" Pcap: Part {b} (ISO/IEC 15444-{b})\n"
|
|
1035
|
+
msg += f" Ccap: {self.ccap}"
|
|
1007
1036
|
|
|
1008
1037
|
return msg
|
|
1009
1038
|
|
|
@@ -1035,8 +1064,9 @@ class COCsegment(Segment):
|
|
|
1035
1064
|
15444-1:2004 - Information technology -- JPEG 2000 image coding system:
|
|
1036
1065
|
Core coding system
|
|
1037
1066
|
"""
|
|
1067
|
+
|
|
1038
1068
|
def __init__(self, ccoc, scoc, spcoc, length, offset):
|
|
1039
|
-
super().__init__(marker_id=
|
|
1069
|
+
super().__init__(marker_id="COC")
|
|
1040
1070
|
self.ccoc = ccoc
|
|
1041
1071
|
self.scoc = scoc
|
|
1042
1072
|
self.spcoc = spcoc
|
|
@@ -1054,22 +1084,22 @@ class COCsegment(Segment):
|
|
|
1054
1084
|
def __str__(self):
|
|
1055
1085
|
msg = Segment.__str__(self)
|
|
1056
1086
|
|
|
1057
|
-
msg +=
|
|
1087
|
+
msg += "\n"
|
|
1058
1088
|
|
|
1059
1089
|
partition = 0 if self.scoc == 0 else 1
|
|
1060
1090
|
width = int(self.code_block_size[0])
|
|
1061
1091
|
height = int(self.code_block_size[1])
|
|
1062
1092
|
xform = _WAVELET_XFORM_DISPLAY[self.spcoc[4]]
|
|
1063
1093
|
msg += (
|
|
1064
|
-
f
|
|
1065
|
-
f
|
|
1066
|
-
f
|
|
1067
|
-
f
|
|
1068
|
-
f
|
|
1069
|
-
f
|
|
1070
|
-
f
|
|
1071
|
-
f
|
|
1072
|
-
f
|
|
1094
|
+
f" Associated component: {self.ccoc}\n"
|
|
1095
|
+
f" Coding style for this component: "
|
|
1096
|
+
f"Entropy coder, PARTITION = {partition}\n"
|
|
1097
|
+
f" Coding style parameters:\n"
|
|
1098
|
+
f" Number of decomposition levels: {self.spcoc[0]}\n"
|
|
1099
|
+
f" Code block height, width: ({width} x {height})\n"
|
|
1100
|
+
f" Wavelet transform: {xform}\n"
|
|
1101
|
+
f" Precinct size: {self.precinct_size.tolist()}\n"
|
|
1102
|
+
f" {_context_string(self.spcoc[3])}"
|
|
1073
1103
|
)
|
|
1074
1104
|
|
|
1075
1105
|
return msg
|
|
@@ -1115,9 +1145,23 @@ class CODsegment(Segment):
|
|
|
1115
1145
|
pargs = (scod, prog, nlayers, mct, nr, xcb, ycb, cstyle, xform,
|
|
1116
1146
|
precinct_size)
|
|
1117
1147
|
"""
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1148
|
+
|
|
1149
|
+
def __init__(
|
|
1150
|
+
self,
|
|
1151
|
+
scod,
|
|
1152
|
+
prog_order,
|
|
1153
|
+
num_layers,
|
|
1154
|
+
mct,
|
|
1155
|
+
nr,
|
|
1156
|
+
xcb,
|
|
1157
|
+
ycb,
|
|
1158
|
+
cstyle,
|
|
1159
|
+
xform,
|
|
1160
|
+
precinct_size,
|
|
1161
|
+
length=0,
|
|
1162
|
+
offset=0,
|
|
1163
|
+
):
|
|
1164
|
+
super().__init__(marker_id="COD")
|
|
1121
1165
|
self.scod = scod
|
|
1122
1166
|
self.length = length
|
|
1123
1167
|
self.offset = offset
|
|
@@ -1138,57 +1182,58 @@ class CODsegment(Segment):
|
|
|
1138
1182
|
warnings.warn(msg, UserWarning)
|
|
1139
1183
|
self.prog_order = prog_order
|
|
1140
1184
|
|
|
1141
|
-
if xform not in [
|
|
1142
|
-
|
|
1185
|
+
if xform not in [
|
|
1186
|
+
WAVELET_XFORM_9X7_IRREVERSIBLE, WAVELET_XFORM_5X3_REVERSIBLE
|
|
1187
|
+
]:
|
|
1143
1188
|
msg = f"Invalid wavelet transform in COD segment: {xform}."
|
|
1144
1189
|
warnings.warn(msg, UserWarning)
|
|
1145
1190
|
|
|
1146
|
-
self.code_block_size = 4 * 2
|
|
1191
|
+
self.code_block_size = 4 * 2**ycb, 4 * 2**xcb
|
|
1147
1192
|
|
|
1148
1193
|
if precinct_size is None:
|
|
1149
|
-
self.precinct_size = np.array(((2
|
|
1194
|
+
self.precinct_size = np.array(((2**15, 2**15)))
|
|
1150
1195
|
else:
|
|
1151
1196
|
self.precinct_size = np.array(precinct_size)
|
|
1152
1197
|
|
|
1153
1198
|
def __str__(self):
|
|
1154
1199
|
msg = Segment.__str__(self)
|
|
1155
1200
|
|
|
1156
|
-
msg +=
|
|
1201
|
+
msg += "\n"
|
|
1157
1202
|
msg += (
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1203
|
+
" Coding style:\n"
|
|
1204
|
+
" Entropy coder, {with_without} partitions\n"
|
|
1205
|
+
" SOP marker segments: {sop}\n"
|
|
1206
|
+
" EPH marker segments: {eph}\n"
|
|
1207
|
+
" Coding style parameters:\n"
|
|
1208
|
+
" Progression order: {prog}\n"
|
|
1209
|
+
" Number of layers: {num_layers}\n"
|
|
1210
|
+
" Multiple component transformation usage: {mct}\n"
|
|
1211
|
+
" Number of decomposition levels: {num_dlevels}\n"
|
|
1212
|
+
" Code block height, width: ({cbh} x {cbw})\n"
|
|
1213
|
+
" Wavelet transform: {xform}\n"
|
|
1214
|
+
" Precinct size: {precinct_size}\n"
|
|
1215
|
+
" {code_block_context}"
|
|
1171
1216
|
)
|
|
1172
1217
|
|
|
1173
1218
|
if self.mct == 0:
|
|
1174
|
-
mct_str =
|
|
1219
|
+
mct_str = "no transform specified"
|
|
1175
1220
|
elif self.mct & 0x01:
|
|
1176
|
-
mct_str =
|
|
1221
|
+
mct_str = "reversible"
|
|
1177
1222
|
elif self.mct & 0x02:
|
|
1178
|
-
mct_str =
|
|
1223
|
+
mct_str = "irreversible"
|
|
1179
1224
|
else:
|
|
1180
|
-
mct_str =
|
|
1225
|
+
mct_str = "unknown"
|
|
1181
1226
|
|
|
1182
1227
|
try:
|
|
1183
1228
|
progression_order = _PROGRESSION_ORDER_DISPLAY[self.prog_order]
|
|
1184
1229
|
except KeyError:
|
|
1185
|
-
progression_order = f
|
|
1230
|
+
progression_order = f"{self.prog_order} (invalid)"
|
|
1186
1231
|
try:
|
|
1187
1232
|
xform = _WAVELET_XFORM_DISPLAY[self.xform]
|
|
1188
1233
|
except KeyError:
|
|
1189
|
-
xform = f
|
|
1234
|
+
xform = f"{self.xform} (invalid)"
|
|
1190
1235
|
msg = msg.format(
|
|
1191
|
-
with_without=
|
|
1236
|
+
with_without="with" if (self.scod & 1) else "without",
|
|
1192
1237
|
sop=((self.scod & 2) > 0),
|
|
1193
1238
|
eph=((self.scod & 4) > 0),
|
|
1194
1239
|
prog=progression_order,
|
|
@@ -1199,7 +1244,7 @@ class CODsegment(Segment):
|
|
|
1199
1244
|
cbw=int(self.code_block_size[1]),
|
|
1200
1245
|
xform=xform,
|
|
1201
1246
|
precinct_size=self.precinct_size.tolist(),
|
|
1202
|
-
code_block_context=_context_string(self.cstyle)
|
|
1247
|
+
code_block_context=_context_string(self.cstyle),
|
|
1203
1248
|
)
|
|
1204
1249
|
|
|
1205
1250
|
return msg
|
|
@@ -1229,18 +1274,19 @@ class CMEsegment(Segment):
|
|
|
1229
1274
|
15444-1:2004 - Information technology -- JPEG 2000 image coding system:
|
|
1230
1275
|
Core coding system
|
|
1231
1276
|
"""
|
|
1277
|
+
|
|
1232
1278
|
def __init__(self, rcme, ccme, length=-1, offset=-1):
|
|
1233
|
-
super().__init__(marker_id=
|
|
1279
|
+
super().__init__(marker_id="CME")
|
|
1234
1280
|
self.rcme = rcme
|
|
1235
1281
|
self.ccme = ccme
|
|
1236
1282
|
self.length = length
|
|
1237
1283
|
self.offset = offset
|
|
1238
1284
|
|
|
1239
1285
|
def __str__(self):
|
|
1240
|
-
msg = Segment.__str__(self) +
|
|
1286
|
+
msg = Segment.__str__(self) + "\n"
|
|
1241
1287
|
if self.rcme == 1:
|
|
1242
1288
|
# latin-1 string
|
|
1243
|
-
msg += ' "{ccme}"'.format(ccme=self.ccme.decode(
|
|
1289
|
+
msg += ' "{ccme}"'.format(ccme=self.ccme.decode("latin-1"))
|
|
1244
1290
|
else:
|
|
1245
1291
|
msg += " binary data (rcme = {rcme}): {nbytes} bytes"
|
|
1246
1292
|
msg = msg.format(rcme=self.rcme, nbytes=len(self.ccme))
|
|
@@ -1262,8 +1308,9 @@ class CRGsegment(Segment):
|
|
|
1262
1308
|
xcrg, ycrg : int sequences
|
|
1263
1309
|
Horizontal, vertical offset for each component
|
|
1264
1310
|
"""
|
|
1311
|
+
|
|
1265
1312
|
def __init__(self, xcrg, ycrg, length, offset):
|
|
1266
|
-
super().__init__(marker_id=
|
|
1313
|
+
super().__init__(marker_id="CRG")
|
|
1267
1314
|
self.xcrg = xcrg
|
|
1268
1315
|
self.ycrg = ycrg
|
|
1269
1316
|
self.length = length
|
|
@@ -1271,9 +1318,9 @@ class CRGsegment(Segment):
|
|
|
1271
1318
|
|
|
1272
1319
|
def __str__(self):
|
|
1273
1320
|
msg = Segment.__str__(self)
|
|
1274
|
-
msg +=
|
|
1321
|
+
msg += "\n Vertical, Horizontal offset: "
|
|
1275
1322
|
for j in range(len(self.xcrg)):
|
|
1276
|
-
msg +=
|
|
1323
|
+
msg += " ({0:.2f}, {1:.2f})".format(
|
|
1277
1324
|
self.ycrg[j] / 65535.0, self.xcrg[j] / 65535.0
|
|
1278
1325
|
)
|
|
1279
1326
|
return msg
|
|
@@ -1299,8 +1346,9 @@ class EOCsegment(Segment):
|
|
|
1299
1346
|
15444-1:2004 - Information technology -- JPEG 2000 image coding system:
|
|
1300
1347
|
Core coding system
|
|
1301
1348
|
"""
|
|
1349
|
+
|
|
1302
1350
|
def __init__(self, length, offset):
|
|
1303
|
-
super().__init__(marker_id=
|
|
1351
|
+
super().__init__(marker_id="EOC")
|
|
1304
1352
|
self.length = length
|
|
1305
1353
|
self.offset = offset
|
|
1306
1354
|
|
|
@@ -1336,8 +1384,9 @@ class PODsegment(Segment):
|
|
|
1336
1384
|
15444-1:2004 - Information technology -- JPEG 2000 image coding system:
|
|
1337
1385
|
Core coding system
|
|
1338
1386
|
"""
|
|
1387
|
+
|
|
1339
1388
|
def __init__(self, pod_params, length, offset):
|
|
1340
|
-
super().__init__(marker_id=
|
|
1389
|
+
super().__init__(marker_id="POD")
|
|
1341
1390
|
|
|
1342
1391
|
self.rspod = pod_params[0::6]
|
|
1343
1392
|
self.cspod = pod_params[1::6]
|
|
@@ -1350,21 +1399,23 @@ class PODsegment(Segment):
|
|
|
1350
1399
|
|
|
1351
1400
|
def __str__(self):
|
|
1352
1401
|
msg = Segment.__str__(self)
|
|
1353
|
-
msg +=
|
|
1354
|
-
|
|
1355
|
-
submsg = (
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1402
|
+
msg += "\n"
|
|
1403
|
+
|
|
1404
|
+
submsg = (
|
|
1405
|
+
" Progression change {0}:\n"
|
|
1406
|
+
" Resolution index start: {1}\n"
|
|
1407
|
+
" Component index start: {2}\n"
|
|
1408
|
+
" Layer index end: {3}\n"
|
|
1409
|
+
" Resolution index end: {4}\n"
|
|
1410
|
+
" Component index end: {5}\n"
|
|
1411
|
+
" Progression order: {6}\n"
|
|
1412
|
+
)
|
|
1362
1413
|
for j in range(len(self.rspod)):
|
|
1363
1414
|
|
|
1364
1415
|
try:
|
|
1365
1416
|
progorder = _PROGRESSION_ORDER_DISPLAY[self.ppod[j]]
|
|
1366
1417
|
except KeyError:
|
|
1367
|
-
progorder = f
|
|
1418
|
+
progorder = f"invalid value: {self.ppod[j]}"
|
|
1368
1419
|
|
|
1369
1420
|
msg += submsg.format(
|
|
1370
1421
|
j,
|
|
@@ -1373,7 +1424,7 @@ class PODsegment(Segment):
|
|
|
1373
1424
|
self.lyepod[j],
|
|
1374
1425
|
self.repod[j],
|
|
1375
1426
|
self.cdpod[j],
|
|
1376
|
-
progorder
|
|
1427
|
+
progorder,
|
|
1377
1428
|
)
|
|
1378
1429
|
|
|
1379
1430
|
return msg.rstrip()
|
|
@@ -1402,8 +1453,9 @@ class PLTsegment(Segment):
|
|
|
1402
1453
|
15444-1:2004 - Information technology -- JPEG 2000 image coding system:
|
|
1403
1454
|
Core coding system
|
|
1404
1455
|
"""
|
|
1456
|
+
|
|
1405
1457
|
def __init__(self, zplt, iplt, length, offset):
|
|
1406
|
-
super().__init__(marker_id=
|
|
1458
|
+
super().__init__(marker_id="PLT")
|
|
1407
1459
|
self.zplt = zplt
|
|
1408
1460
|
self.iplt = iplt
|
|
1409
1461
|
self.length = length
|
|
@@ -1411,10 +1463,7 @@ class PLTsegment(Segment):
|
|
|
1411
1463
|
|
|
1412
1464
|
def __str__(self):
|
|
1413
1465
|
msg = Segment.__str__(self)
|
|
1414
|
-
msg +=
|
|
1415
|
-
f"\n Index: {self.zplt}"
|
|
1416
|
-
f"\n Iplt: {self.iplt}"
|
|
1417
|
-
)
|
|
1466
|
+
msg += f"\n Index: {self.zplt}" f"\n Iplt: {self.iplt}"
|
|
1418
1467
|
|
|
1419
1468
|
return msg
|
|
1420
1469
|
|
|
@@ -1440,8 +1489,9 @@ class PPMsegment(Segment):
|
|
|
1440
1489
|
15444-1:2004 - Information technology -- JPEG 2000 image coding system:
|
|
1441
1490
|
Core coding system
|
|
1442
1491
|
"""
|
|
1492
|
+
|
|
1443
1493
|
def __init__(self, zppm, data, length, offset):
|
|
1444
|
-
super().__init__(marker_id=
|
|
1494
|
+
super().__init__(marker_id="PPM")
|
|
1445
1495
|
self.zppm = zppm
|
|
1446
1496
|
|
|
1447
1497
|
# both Nppm and Ippms information stored in data
|
|
@@ -1453,8 +1503,8 @@ class PPMsegment(Segment):
|
|
|
1453
1503
|
def __str__(self):
|
|
1454
1504
|
msg = Segment.__str__(self)
|
|
1455
1505
|
msg += (
|
|
1456
|
-
f
|
|
1457
|
-
f
|
|
1506
|
+
f"\n Index: {self.zppm}"
|
|
1507
|
+
f"\n Data: {len(self.data)} uninterpreted bytes"
|
|
1458
1508
|
)
|
|
1459
1509
|
return msg
|
|
1460
1510
|
|
|
@@ -1482,8 +1532,9 @@ class PPTsegment(Segment):
|
|
|
1482
1532
|
15444-1:2004 - Information technology -- JPEG 2000 image coding system:
|
|
1483
1533
|
Core coding system
|
|
1484
1534
|
"""
|
|
1535
|
+
|
|
1485
1536
|
def __init__(self, zppt, ippt, length, offset):
|
|
1486
|
-
super().__init__(marker_id=
|
|
1537
|
+
super().__init__(marker_id="PPT")
|
|
1487
1538
|
self.zppt = zppt
|
|
1488
1539
|
self.ippt = ippt
|
|
1489
1540
|
self.length = length
|
|
@@ -1492,8 +1543,8 @@ class PPTsegment(Segment):
|
|
|
1492
1543
|
def __str__(self):
|
|
1493
1544
|
msg = Segment.__str__(self)
|
|
1494
1545
|
msg += (
|
|
1495
|
-
f
|
|
1496
|
-
f
|
|
1546
|
+
f"\n Index: {self.zppt}"
|
|
1547
|
+
f"\n Packet headers: {len(self.ippt)} uninterpreted bytes"
|
|
1497
1548
|
)
|
|
1498
1549
|
return msg
|
|
1499
1550
|
|
|
@@ -1527,27 +1578,27 @@ class QCCsegment(Segment):
|
|
|
1527
1578
|
15444-1:2004 - Information technology -- JPEG 2000 image coding system:
|
|
1528
1579
|
Core coding system
|
|
1529
1580
|
"""
|
|
1581
|
+
|
|
1530
1582
|
def __init__(self, cqcc, sqcc, spqcc, length, offset):
|
|
1531
|
-
super().__init__(marker_id=
|
|
1583
|
+
super().__init__(marker_id="QCC")
|
|
1532
1584
|
self.cqcc = cqcc
|
|
1533
1585
|
self.sqcc = sqcc
|
|
1534
1586
|
self.spqcc = spqcc
|
|
1535
1587
|
self.length = length
|
|
1536
1588
|
self.offset = offset
|
|
1537
1589
|
|
|
1538
|
-
self.mantissa, self.exponent = parse_quantization(self.spqcc,
|
|
1539
|
-
|
|
1540
|
-
self.guard_bits = (self.sqcc & 0xe0) >> 5
|
|
1590
|
+
self.mantissa, self.exponent = parse_quantization(self.spqcc, self.sqcc)
|
|
1591
|
+
self.guard_bits = (self.sqcc & 0xE0) >> 5
|
|
1541
1592
|
|
|
1542
1593
|
def __str__(self):
|
|
1543
1594
|
msg = Segment.__str__(self)
|
|
1544
1595
|
|
|
1545
|
-
msg += f
|
|
1596
|
+
msg += f"\n Associated Component: {self.cqcc}"
|
|
1546
1597
|
msg += _print_quantization_style(self.sqcc)
|
|
1547
|
-
msg += f
|
|
1598
|
+
msg += f"{self.guard_bits} guard bits"
|
|
1548
1599
|
|
|
1549
1600
|
step_size = zip(self.mantissa, self.exponent)
|
|
1550
|
-
msg +=
|
|
1601
|
+
msg += "\n Step size: " + str(list(step_size))
|
|
1551
1602
|
return msg
|
|
1552
1603
|
|
|
1553
1604
|
|
|
@@ -1578,8 +1629,9 @@ class QCDsegment(Segment):
|
|
|
1578
1629
|
15444-1:2004 - Information technology -- JPEG 2000 image coding system:
|
|
1579
1630
|
Core coding system
|
|
1580
1631
|
"""
|
|
1632
|
+
|
|
1581
1633
|
def __init__(self, sqcd, spqcd, length, offset):
|
|
1582
|
-
super().__init__(marker_id=
|
|
1634
|
+
super().__init__(marker_id="QCD")
|
|
1583
1635
|
|
|
1584
1636
|
self.sqcd = sqcd
|
|
1585
1637
|
self.spqcd = spqcd
|
|
@@ -1589,17 +1641,17 @@ class QCDsegment(Segment):
|
|
|
1589
1641
|
mantissa, exponent = parse_quantization(self.spqcd, self.sqcd)
|
|
1590
1642
|
self.mantissa = mantissa
|
|
1591
1643
|
self.exponent = exponent
|
|
1592
|
-
self.guard_bits = (self.sqcd &
|
|
1644
|
+
self.guard_bits = (self.sqcd & 0xE0) >> 5
|
|
1593
1645
|
|
|
1594
1646
|
def __str__(self):
|
|
1595
1647
|
msg = Segment.__str__(self)
|
|
1596
1648
|
|
|
1597
1649
|
msg += _print_quantization_style(self.sqcd)
|
|
1598
1650
|
|
|
1599
|
-
msg += f
|
|
1651
|
+
msg += f"{self.guard_bits} guard bits"
|
|
1600
1652
|
|
|
1601
1653
|
step_size = zip(self.mantissa, self.exponent)
|
|
1602
|
-
msg +=
|
|
1654
|
+
msg += "\n Step size: " + str(list(step_size))
|
|
1603
1655
|
return msg
|
|
1604
1656
|
|
|
1605
1657
|
|
|
@@ -1628,8 +1680,9 @@ class RGNsegment(Segment):
|
|
|
1628
1680
|
15444-1:2004 - Information technology -- JPEG 2000 image coding system:
|
|
1629
1681
|
Core coding system
|
|
1630
1682
|
"""
|
|
1683
|
+
|
|
1631
1684
|
def __init__(self, crgn, srgn, sprgn, length=-1, offset=-1):
|
|
1632
|
-
super().__init__(marker_id=
|
|
1685
|
+
super().__init__(marker_id="RGN")
|
|
1633
1686
|
self.length = length
|
|
1634
1687
|
self.offset = offset
|
|
1635
1688
|
self.crgn = crgn
|
|
@@ -1640,9 +1693,9 @@ class RGNsegment(Segment):
|
|
|
1640
1693
|
msg = Segment.__str__(self)
|
|
1641
1694
|
|
|
1642
1695
|
msg += (
|
|
1643
|
-
f
|
|
1644
|
-
f
|
|
1645
|
-
f
|
|
1696
|
+
f"\n Associated component: {self.crgn}"
|
|
1697
|
+
f"\n ROI style: {self.srgn}"
|
|
1698
|
+
f"\n Parameter: {self.sprgn}"
|
|
1646
1699
|
)
|
|
1647
1700
|
|
|
1648
1701
|
return msg
|
|
@@ -1686,10 +1739,22 @@ class SIZsegment(Segment):
|
|
|
1686
1739
|
15444-1:2004 - Information technology -- JPEG 2000 image coding system:
|
|
1687
1740
|
Core coding system
|
|
1688
1741
|
"""
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1742
|
+
|
|
1743
|
+
def __init__(
|
|
1744
|
+
self,
|
|
1745
|
+
rsiz=-1,
|
|
1746
|
+
xysiz=None,
|
|
1747
|
+
xyosiz=-1,
|
|
1748
|
+
xytsiz=-1,
|
|
1749
|
+
xytosiz=-1,
|
|
1750
|
+
Csiz=-1,
|
|
1751
|
+
bitdepth=None,
|
|
1752
|
+
signed=None,
|
|
1753
|
+
xyrsiz=-1,
|
|
1754
|
+
length=-1,
|
|
1755
|
+
offset=-1,
|
|
1756
|
+
):
|
|
1757
|
+
super().__init__(marker_id="SIZ", length=length, offset=offset)
|
|
1693
1758
|
|
|
1694
1759
|
self.rsiz = rsiz
|
|
1695
1760
|
self.xsiz, self.ysiz = xysiz
|
|
@@ -1727,36 +1792,40 @@ class SIZsegment(Segment):
|
|
|
1727
1792
|
|
|
1728
1793
|
def __str__(self):
|
|
1729
1794
|
msg = Segment.__str__(self)
|
|
1730
|
-
msg +=
|
|
1795
|
+
msg += "\n"
|
|
1731
1796
|
|
|
1732
1797
|
msg += (
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1798
|
+
" Profile: {profile}\n"
|
|
1799
|
+
" Reference Grid Height, Width: ({height} x {width})\n"
|
|
1800
|
+
" Vertical, Horizontal Reference Grid Offset: ({goy} x {gox})\n" # noqa : E501
|
|
1801
|
+
" Reference Tile Height, Width: ({tileh} x {tilew})\n"
|
|
1802
|
+
" Vertical, Horizontal Reference Tile Offset: ({toy} x {tox})\n" # noqa : E501
|
|
1803
|
+
" Bitdepth: {bitdepth}\n"
|
|
1804
|
+
" Signed: {signed}\n"
|
|
1805
|
+
" Vertical, Horizontal Subsampling: {subsampling}"
|
|
1741
1806
|
)
|
|
1742
1807
|
try:
|
|
1743
1808
|
profile = _CAPABILITIES_DISPLAY[self.rsiz]
|
|
1744
1809
|
except KeyError:
|
|
1745
1810
|
if np.bitwise_and(self.rsiz, 16384):
|
|
1746
1811
|
# HTJ2K profile that is uninterpreted
|
|
1747
|
-
profile = f
|
|
1812
|
+
profile = f"{self.rsiz}"
|
|
1748
1813
|
else:
|
|
1749
1814
|
# profile unknown
|
|
1750
|
-
profile = f
|
|
1815
|
+
profile = f"{self.rsiz} (invalid)"
|
|
1751
1816
|
msg = msg.format(
|
|
1752
1817
|
profile=profile,
|
|
1753
|
-
height=self.ysiz,
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1818
|
+
height=self.ysiz,
|
|
1819
|
+
width=self.xsiz,
|
|
1820
|
+
goy=self.yosiz,
|
|
1821
|
+
gox=self.xosiz,
|
|
1822
|
+
tileh=self.ytsiz,
|
|
1823
|
+
tilew=self.xtsiz,
|
|
1824
|
+
toy=self.ytosiz,
|
|
1825
|
+
tox=self.xtosiz,
|
|
1757
1826
|
bitdepth=self.bitdepth,
|
|
1758
1827
|
signed=self.signed,
|
|
1759
|
-
subsampling=tuple(zip(self.yrsiz, self.xrsiz))
|
|
1828
|
+
subsampling=tuple(zip(self.yrsiz, self.xrsiz)),
|
|
1760
1829
|
)
|
|
1761
1830
|
|
|
1762
1831
|
return msg
|
|
@@ -1782,8 +1851,9 @@ class SOCsegment(Segment):
|
|
|
1782
1851
|
15444-1:2004 - Information technology -- JPEG 2000 image coding system:
|
|
1783
1852
|
Core coding system
|
|
1784
1853
|
"""
|
|
1854
|
+
|
|
1785
1855
|
def __init__(self, **kwargs):
|
|
1786
|
-
super().__init__(marker_id=
|
|
1856
|
+
super().__init__(marker_id="SOC")
|
|
1787
1857
|
self.__dict__.update(**kwargs)
|
|
1788
1858
|
|
|
1789
1859
|
def __repr__(self):
|
|
@@ -1811,8 +1881,9 @@ class SODsegment(Segment):
|
|
|
1811
1881
|
15444-1:2004 - Information technology -- JPEG 2000 image coding system:
|
|
1812
1882
|
Core coding system
|
|
1813
1883
|
"""
|
|
1884
|
+
|
|
1814
1885
|
def __init__(self, length, offset):
|
|
1815
|
-
super().__init__(marker_id=
|
|
1886
|
+
super().__init__(marker_id="SOD")
|
|
1816
1887
|
self.length = length
|
|
1817
1888
|
self.offset = offset
|
|
1818
1889
|
|
|
@@ -1837,8 +1908,9 @@ class EPHsegment(Segment):
|
|
|
1837
1908
|
15444-1:2004 - Information technology -- JPEG 2000 image coding system:
|
|
1838
1909
|
Core coding system
|
|
1839
1910
|
"""
|
|
1911
|
+
|
|
1840
1912
|
def __init__(self, length, offset):
|
|
1841
|
-
super().__init__(marker_id=
|
|
1913
|
+
super().__init__(marker_id="EPH")
|
|
1842
1914
|
self.length = length
|
|
1843
1915
|
self.offset = offset
|
|
1844
1916
|
|
|
@@ -1864,15 +1936,16 @@ class SOPsegment(Segment):
|
|
|
1864
1936
|
15444-1:2004 - Information technology -- JPEG 2000 image coding system:
|
|
1865
1937
|
Core coding system
|
|
1866
1938
|
"""
|
|
1939
|
+
|
|
1867
1940
|
def __init__(self, nsop, length, offset):
|
|
1868
|
-
super().__init__(marker_id=
|
|
1941
|
+
super().__init__(marker_id="SOP")
|
|
1869
1942
|
self.nsop = nsop
|
|
1870
1943
|
self.length = length
|
|
1871
1944
|
self.offset = offset
|
|
1872
1945
|
|
|
1873
1946
|
def __str__(self):
|
|
1874
1947
|
msg = Segment.__str__(self)
|
|
1875
|
-
msg += f
|
|
1948
|
+
msg += f"\n Nsop: {self.nsop}"
|
|
1876
1949
|
return msg
|
|
1877
1950
|
|
|
1878
1951
|
|
|
@@ -1904,8 +1977,9 @@ class SOTsegment(Segment):
|
|
|
1904
1977
|
15444-1:2004 - Information technology -- JPEG 2000 image coding system:
|
|
1905
1978
|
Core coding system
|
|
1906
1979
|
"""
|
|
1980
|
+
|
|
1907
1981
|
def __init__(self, isot, psot, tpsot, tnsot, length=-1, offset=-1):
|
|
1908
|
-
super().__init__(marker_id=
|
|
1982
|
+
super().__init__(marker_id="SOT")
|
|
1909
1983
|
self.isot = isot
|
|
1910
1984
|
self.psot = psot
|
|
1911
1985
|
self.tpsot = tpsot
|
|
@@ -1916,10 +1990,10 @@ class SOTsegment(Segment):
|
|
|
1916
1990
|
def __str__(self):
|
|
1917
1991
|
msg = Segment.__str__(self)
|
|
1918
1992
|
msg += (
|
|
1919
|
-
f
|
|
1920
|
-
f
|
|
1921
|
-
f
|
|
1922
|
-
f
|
|
1993
|
+
f"\n Tile part index: {self.isot}"
|
|
1994
|
+
f"\n Tile part length: {self.psot}"
|
|
1995
|
+
f"\n Tile part instance: {self.tpsot}"
|
|
1996
|
+
f"\n Number of tile parts: {self.tnsot}"
|
|
1923
1997
|
)
|
|
1924
1998
|
return msg
|
|
1925
1999
|
|
|
@@ -1950,8 +2024,9 @@ class TLMsegment(Segment):
|
|
|
1950
2024
|
15444-1:2004 - Information technology -- JPEG 2000 image coding system:
|
|
1951
2025
|
Core coding system
|
|
1952
2026
|
"""
|
|
2027
|
+
|
|
1953
2028
|
def __init__(self, ztlm, ttlm, ptlm, length, offset):
|
|
1954
|
-
super().__init__(marker_id=
|
|
2029
|
+
super().__init__(marker_id="TLM")
|
|
1955
2030
|
self.length = length
|
|
1956
2031
|
self.offset = offset
|
|
1957
2032
|
self.ztlm = ztlm
|
|
@@ -1962,9 +2037,9 @@ class TLMsegment(Segment):
|
|
|
1962
2037
|
msg = Segment.__str__(self)
|
|
1963
2038
|
with np.printoptions(threshold=4):
|
|
1964
2039
|
msg += (
|
|
1965
|
-
f
|
|
1966
|
-
f
|
|
1967
|
-
f
|
|
2040
|
+
f"\n Index: {self.ztlm}"
|
|
2041
|
+
f"\n Tile number: {self.ttlm}"
|
|
2042
|
+
f"\n Length: {self.ptlm}"
|
|
1968
2043
|
)
|
|
1969
2044
|
|
|
1970
2045
|
return msg
|
|
@@ -1977,27 +2052,29 @@ def _parse_precinct_size(spcod):
|
|
|
1977
2052
|
for item in spcod:
|
|
1978
2053
|
ep2 = (item & 0xF0) >> 4
|
|
1979
2054
|
ep1 = item & 0x0F
|
|
1980
|
-
precinct_size.append((2
|
|
2055
|
+
precinct_size.append((2**ep1, 2**ep2))
|
|
1981
2056
|
return np.array(precinct_size)
|
|
1982
2057
|
|
|
1983
2058
|
|
|
1984
2059
|
def _context_string(context):
|
|
1985
2060
|
"""Produce a string to represent the code block context"""
|
|
1986
|
-
msg =
|
|
1987
|
-
lines = [
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
2061
|
+
msg = "Code block context:\n "
|
|
2062
|
+
lines = [
|
|
2063
|
+
"Selective arithmetic coding bypass: {0}",
|
|
2064
|
+
"Reset context probabilities on coding pass boundaries: {1}",
|
|
2065
|
+
"Termination on each coding pass: {2}",
|
|
2066
|
+
"Vertically stripe causal context: {3}",
|
|
2067
|
+
"Predictable termination: {4}",
|
|
2068
|
+
"Segmentation symbols: {5}",
|
|
2069
|
+
]
|
|
2070
|
+
msg += "\n ".join(lines)
|
|
1994
2071
|
msg = msg.format(
|
|
1995
2072
|
((context & 0x01) > 0),
|
|
1996
2073
|
((context & 0x02) > 0),
|
|
1997
2074
|
((context & 0x04) > 0),
|
|
1998
2075
|
((context & 0x08) > 0),
|
|
1999
2076
|
((context & 0x10) > 0),
|
|
2000
|
-
((context & 0x20) > 0)
|
|
2077
|
+
((context & 0x20) > 0),
|
|
2001
2078
|
)
|
|
2002
2079
|
return msg
|
|
2003
2080
|
|
|
@@ -2019,17 +2096,17 @@ def parse_quantization(read_buffer, sqcd):
|
|
|
2019
2096
|
exponent = []
|
|
2020
2097
|
mantissa = []
|
|
2021
2098
|
|
|
2022
|
-
if sqcd &
|
|
2023
|
-
data = struct.unpack(
|
|
2099
|
+
if sqcd & 0x1F == 0: # no quantization
|
|
2100
|
+
data = struct.unpack(">" + "B" * numbytes, read_buffer)
|
|
2024
2101
|
for j in range(len(data)):
|
|
2025
2102
|
exponent.append(data[j] >> 3)
|
|
2026
2103
|
mantissa.append(0)
|
|
2027
2104
|
else:
|
|
2028
|
-
fmt =
|
|
2105
|
+
fmt = ">" + "H" * int(numbytes / 2)
|
|
2029
2106
|
data = struct.unpack(fmt, read_buffer)
|
|
2030
2107
|
for j in range(len(data)):
|
|
2031
2108
|
exponent.append(data[j] >> 11)
|
|
2032
|
-
mantissa.append(data[j] &
|
|
2109
|
+
mantissa.append(data[j] & 0x07FF)
|
|
2033
2110
|
|
|
2034
2111
|
return mantissa, exponent
|
|
2035
2112
|
|
|
@@ -2037,11 +2114,11 @@ def parse_quantization(read_buffer, sqcd):
|
|
|
2037
2114
|
def _print_quantization_style(sqcc):
|
|
2038
2115
|
"""Only to be used with QCC and QCD segments."""
|
|
2039
2116
|
|
|
2040
|
-
msg =
|
|
2041
|
-
if sqcc &
|
|
2042
|
-
msg +=
|
|
2043
|
-
elif sqcc &
|
|
2044
|
-
msg +=
|
|
2045
|
-
elif sqcc &
|
|
2046
|
-
msg +=
|
|
2117
|
+
msg = "\n Quantization style: "
|
|
2118
|
+
if sqcc & 0x1F == 0:
|
|
2119
|
+
msg += "no quantization, "
|
|
2120
|
+
elif sqcc & 0x1F == 1:
|
|
2121
|
+
msg += "scalar implicit, "
|
|
2122
|
+
elif sqcc & 0x1F == 2:
|
|
2123
|
+
msg += "scalar explicit, "
|
|
2047
2124
|
return msg
|