Refactored dtbl box to use just a single file read. #212
This commit is contained in:
parent
1485bda7ff
commit
bb4e5cfe16
1 changed files with 21 additions and 10 deletions
|
|
@ -15,6 +15,7 @@ References
|
||||||
|
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
import datetime
|
import datetime
|
||||||
|
import io
|
||||||
import math
|
import math
|
||||||
import os
|
import os
|
||||||
import pprint
|
import pprint
|
||||||
|
|
@ -1160,22 +1161,32 @@ class DataReferenceBox(Jp2kBox):
|
||||||
-------
|
-------
|
||||||
DataReferenceBox instance
|
DataReferenceBox instance
|
||||||
"""
|
"""
|
||||||
|
num_bytes = length - 16 if box_is_XL else length - 8
|
||||||
|
read_buffer = fptr.read(num_bytes)
|
||||||
|
|
||||||
# Read the number of data references
|
# Read the number of data references
|
||||||
read_buffer = fptr.read(2)
|
ndr, = struct.unpack_from('>H', read_buffer, offset=0)
|
||||||
ndr, = struct.unpack('>H', read_buffer)
|
|
||||||
|
# Need to keep track of where the next url box starts.
|
||||||
|
box_offset = 2
|
||||||
|
|
||||||
# Read each data entry url box.
|
|
||||||
data_entry_url_box_list = []
|
data_entry_url_box_list = []
|
||||||
for _ in range(ndr):
|
for j in range(ndr):
|
||||||
start = fptr.tell()
|
|
||||||
read_buffer = fptr.read(8)
|
|
||||||
(box_length, box_id) = struct.unpack('>I4s', read_buffer)
|
|
||||||
if sys.hexversion >= 0x03000000:
|
|
||||||
box_id = box_id.decode('utf-8')
|
|
||||||
|
|
||||||
box = DataEntryURLBox.parse(fptr, start, box_length)
|
# Create an in-memory binary stream for each URL box.
|
||||||
|
box_fptr = io.BytesIO(read_buffer[box_offset:])
|
||||||
|
box_buffer = box_fptr.read(8)
|
||||||
|
(box_length, box_id) = struct.unpack_from('>I4s', box_buffer,
|
||||||
|
offset=0)
|
||||||
|
box = DataEntryURLBox.parse(box_fptr, 0, box_length)
|
||||||
|
|
||||||
|
# Need to adjust the box start to that of the "real" file.
|
||||||
|
box.start = offset + box_offset
|
||||||
data_entry_url_box_list.append(box)
|
data_entry_url_box_list.append(box)
|
||||||
|
|
||||||
|
# Point to the next embedded URL box.
|
||||||
|
box_offset += box_length
|
||||||
|
|
||||||
return cls(data_entry_url_box_list, length=length, offset=offset)
|
return cls(data_entry_url_box_list, length=length, offset=offset)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue