Removed box_is_XL parameter. #212
We only get around a 1% performance increase, which is not worth the increased complexitiy.
This commit is contained in:
parent
f15913cee6
commit
96db5e1a6a
1 changed files with 46 additions and 164 deletions
210
glymur/jp2box.py
210
glymur/jp2box.py
|
|
@ -160,7 +160,7 @@ class Jp2kBox(object):
|
|||
fptr.write(struct.pack('>I', end_pos - orig_pos))
|
||||
fptr.seek(end_pos)
|
||||
|
||||
def _parse_this_box(self, fptr, box_id, start, num_bytes, box_is_XL):
|
||||
def _parse_this_box(self, fptr, box_id, start, num_bytes):
|
||||
"""Parse the current box.
|
||||
|
||||
Parameters
|
||||
|
|
@ -172,10 +172,7 @@ class Jp2kBox(object):
|
|||
4-letter identifier for the current box.
|
||||
start, num_bytes : int
|
||||
Byte offset and length of the current box.
|
||||
box_is_XL : bool
|
||||
True if the box has an XL field. In this case, the start of the
|
||||
box is 16 bytes behind the start of the box payload instead of being
|
||||
8 bytes behind.
|
||||
|
||||
Returns
|
||||
-------
|
||||
box : Jp2kBox
|
||||
|
|
@ -195,7 +192,7 @@ class Jp2kBox(object):
|
|||
return box
|
||||
|
||||
try:
|
||||
box = parser(fptr, start, num_bytes, box_is_XL=box_is_XL)
|
||||
box = parser(fptr, start, num_bytes)
|
||||
except ValueError as err:
|
||||
msg = "Encountered an unrecoverable ValueError while parsing a {0} "
|
||||
msg += "box at byte offset {1}. The original error message was "
|
||||
|
|
@ -236,7 +233,6 @@ class Jp2kBox(object):
|
|||
warnings.warn(msg)
|
||||
return superbox
|
||||
|
||||
box_is_XL = False
|
||||
(box_length, box_id) = struct.unpack('>I4s', read_buffer)
|
||||
if box_length == 0:
|
||||
# The length of the box is presumed to last until the end of
|
||||
|
|
@ -247,14 +243,12 @@ class Jp2kBox(object):
|
|||
# The length of the box is in the XL field, a 64-bit value.
|
||||
read_buffer = fptr.read(8)
|
||||
num_bytes, = struct.unpack('>Q', read_buffer)
|
||||
box_is_XL = True
|
||||
|
||||
else:
|
||||
# The box_length value really is the length of the box!
|
||||
num_bytes = box_length
|
||||
|
||||
box = self._parse_this_box(fptr, box_id, start, num_bytes,
|
||||
box_is_XL)
|
||||
box = self._parse_this_box(fptr, box_id, start, num_bytes)
|
||||
|
||||
superbox.append(box)
|
||||
|
||||
|
|
@ -410,7 +404,7 @@ class ColourSpecificationBox(Jp2kBox):
|
|||
fptr.write(read_buffer)
|
||||
|
||||
@classmethod
|
||||
def parse(cls, fptr, offset, length, box_is_XL=False):
|
||||
def parse(cls, fptr, offset, length):
|
||||
"""Parse JPEG 2000 color specification box.
|
||||
|
||||
Parameters
|
||||
|
|
@ -421,16 +415,12 @@ class ColourSpecificationBox(Jp2kBox):
|
|||
Start position of box in bytes.
|
||||
length : int
|
||||
Length of the box in bytes.
|
||||
box_is_XL : bool
|
||||
True if the box has an XL field. In this case, the start of the
|
||||
box is 16 bytes behind the start of the box payload instead of being
|
||||
8 bytes behind.
|
||||
|
||||
Returns
|
||||
-------
|
||||
ColourSpecificationBox instance
|
||||
"""
|
||||
num_bytes = length - 16 if box_is_XL else length - 8
|
||||
num_bytes = offset + length - fptr.tell()
|
||||
read_buffer = fptr.read(num_bytes)
|
||||
# Read the brand, minor version.
|
||||
(method, precedence, approximation) = struct.unpack_from('>BBB',
|
||||
|
|
@ -666,7 +656,7 @@ class ChannelDefinitionBox(Jp2kBox):
|
|||
self.association[j]))
|
||||
|
||||
@classmethod
|
||||
def parse(cls, fptr, offset, length, box_is_XL=False):
|
||||
def parse(cls, fptr, offset, length):
|
||||
"""Parse component definition box.
|
||||
|
||||
Parameters
|
||||
|
|
@ -677,16 +667,12 @@ class ChannelDefinitionBox(Jp2kBox):
|
|||
Start position of box in bytes.
|
||||
length : int
|
||||
Length of the box in bytes.
|
||||
box_is_XL : bool
|
||||
True if the box has an XL field. In this case, the start of the
|
||||
box is 16 bytes behind the start of the box payload instead of being
|
||||
8 bytes behind.
|
||||
|
||||
Returns
|
||||
-------
|
||||
ComponentDefinitionBox instance
|
||||
"""
|
||||
num_bytes = length - 16 if box_is_XL else length - 8
|
||||
num_bytes = offset + length - fptr.tell()
|
||||
read_buffer = fptr.read(num_bytes)
|
||||
|
||||
# Read the number of components.
|
||||
|
|
@ -740,7 +726,7 @@ class CodestreamHeaderBox(Jp2kBox):
|
|||
self._write_superbox(fptr, b'jpch')
|
||||
|
||||
@classmethod
|
||||
def parse(cls, fptr, offset, length, box_is_XL=False):
|
||||
def parse(cls, fptr, offset, length):
|
||||
"""Parse codestream header box.
|
||||
|
||||
Parameters
|
||||
|
|
@ -751,10 +737,6 @@ class CodestreamHeaderBox(Jp2kBox):
|
|||
Start position of box in bytes.
|
||||
length : int
|
||||
Length of the box in bytes.
|
||||
box_is_XL : bool
|
||||
True if the box has an XL field. In this case, the start of the
|
||||
box is 16 bytes behind the start of the box payload instead of being
|
||||
8 bytes behind.
|
||||
|
||||
Returns
|
||||
-------
|
||||
|
|
@ -813,7 +795,7 @@ class ColourGroupBox(Jp2kBox):
|
|||
self._write_superbox(fptr, b'cgrp')
|
||||
|
||||
@classmethod
|
||||
def parse(cls, fptr, offset, length, box_is_XL=False):
|
||||
def parse(cls, fptr, offset, length):
|
||||
"""Parse colour group box.
|
||||
|
||||
Parameters
|
||||
|
|
@ -824,10 +806,6 @@ class ColourGroupBox(Jp2kBox):
|
|||
Start position of box in bytes.
|
||||
length : int
|
||||
Length of the box in bytes.
|
||||
box_is_XL : bool
|
||||
True if the box has an XL field. In this case, the start of the
|
||||
box is 16 bytes behind the start of the box payload instead of being
|
||||
8 bytes behind.
|
||||
|
||||
Returns
|
||||
-------
|
||||
|
|
@ -880,7 +858,7 @@ class CompositingLayerHeaderBox(Jp2kBox):
|
|||
self._write_superbox(fptr, b'jplh')
|
||||
|
||||
@classmethod
|
||||
def parse(cls, fptr, offset, length, box_is_XL=False):
|
||||
def parse(cls, fptr, offset, length):
|
||||
"""Parse compositing layer header box.
|
||||
|
||||
Parameters
|
||||
|
|
@ -891,10 +869,6 @@ class CompositingLayerHeaderBox(Jp2kBox):
|
|||
Start position of box in bytes.
|
||||
length : int
|
||||
Length of the box in bytes.
|
||||
box_is_XL : bool
|
||||
True if the box has an XL field. In this case, the start of the
|
||||
box is 16 bytes behind the start of the box payload instead of being
|
||||
8 bytes behind.
|
||||
|
||||
Returns
|
||||
-------
|
||||
|
|
@ -975,7 +949,7 @@ class ComponentMappingBox(Jp2kBox):
|
|||
fptr.write(write_buffer)
|
||||
|
||||
@classmethod
|
||||
def parse(cls, fptr, offset, length, box_is_XL=False):
|
||||
def parse(cls, fptr, offset, length):
|
||||
"""Parse component mapping box.
|
||||
|
||||
Parameters
|
||||
|
|
@ -986,16 +960,12 @@ class ComponentMappingBox(Jp2kBox):
|
|||
Start position of box in bytes.
|
||||
length : int
|
||||
Length of the box in bytes.
|
||||
box_is_XL : bool
|
||||
True if the box has an XL field. In this case, the start of the
|
||||
box is 16 bytes behind the start of the box payload instead of being
|
||||
8 bytes behind.
|
||||
|
||||
Returns
|
||||
-------
|
||||
ComponentMappingBox instance
|
||||
"""
|
||||
num_bytes = length - 16 if box_is_XL else length - 8
|
||||
num_bytes = offset + length - fptr.tell()
|
||||
num_components = int(num_bytes/4)
|
||||
|
||||
read_buffer = fptr.read(num_bytes)
|
||||
|
|
@ -1049,7 +1019,7 @@ class ContiguousCodestreamBox(Jp2kBox):
|
|||
return msg
|
||||
|
||||
@classmethod
|
||||
def parse(cls, fptr, offset=0, length=0, box_is_XL=False):
|
||||
def parse(cls, fptr, offset=0, length=0):
|
||||
"""Parse a codestream box.
|
||||
|
||||
Parameters
|
||||
|
|
@ -1060,10 +1030,6 @@ class ContiguousCodestreamBox(Jp2kBox):
|
|||
Start position of box in bytes.
|
||||
length : int
|
||||
Length of the box in bytes.
|
||||
box_is_XL : bool
|
||||
True if the box has an XL field. In this case, the start of the
|
||||
box is 16 bytes behind the start of the box payload instead of being
|
||||
8 bytes behind.
|
||||
|
||||
Returns
|
||||
-------
|
||||
|
|
@ -1151,7 +1117,7 @@ class DataReferenceBox(Jp2kBox):
|
|||
return msg
|
||||
|
||||
@classmethod
|
||||
def parse(cls, fptr, offset, length, box_is_XL=False):
|
||||
def parse(cls, fptr, offset, length):
|
||||
"""Parse data reference box.
|
||||
|
||||
Parameters
|
||||
|
|
@ -1162,16 +1128,12 @@ class DataReferenceBox(Jp2kBox):
|
|||
Start position of box in bytes.
|
||||
length : int
|
||||
Length of the box in bytes.
|
||||
box_is_XL : bool
|
||||
True if the box has an XL field. In this case, the start of the
|
||||
box is 16 bytes behind the start of the box payload instead of being
|
||||
8 bytes behind.
|
||||
|
||||
Returns
|
||||
-------
|
||||
DataReferenceBox instance
|
||||
"""
|
||||
num_bytes = length - 16 if box_is_XL else length - 8
|
||||
num_bytes = offset + length - fptr.tell()
|
||||
read_buffer = fptr.read(num_bytes)
|
||||
|
||||
# Read the number of data references
|
||||
|
|
@ -1281,7 +1243,7 @@ class FileTypeBox(Jp2kBox):
|
|||
fptr.write(item.encode())
|
||||
|
||||
@classmethod
|
||||
def parse(cls, fptr, offset, length, box_is_XL=False):
|
||||
def parse(cls, fptr, offset, length):
|
||||
"""Parse JPEG 2000 file type box.
|
||||
|
||||
Parameters
|
||||
|
|
@ -1292,16 +1254,12 @@ class FileTypeBox(Jp2kBox):
|
|||
Start position of box in bytes.
|
||||
length : int
|
||||
Length of the box in bytes.
|
||||
box_is_XL : bool
|
||||
True if the box has an XL field. In this case, the start of the
|
||||
box is 16 bytes behind the start of the box payload instead of being
|
||||
8 bytes behind.
|
||||
|
||||
Returns
|
||||
-------
|
||||
FileTypeBox instance
|
||||
"""
|
||||
num_bytes = length - 16 if box_is_XL else length - 8
|
||||
num_bytes = offset + length - fptr.tell()
|
||||
read_buffer = fptr.read(num_bytes)
|
||||
# Extract the brand, minor version.
|
||||
(brand, minor_version) = struct.unpack_from('>4sI', read_buffer, 0)
|
||||
|
|
@ -1398,7 +1356,7 @@ class FragmentListBox(Jp2kBox):
|
|||
fptr.write(write_buffer)
|
||||
|
||||
@classmethod
|
||||
def parse(cls, fptr, offset, length, box_is_XL=False):
|
||||
def parse(cls, fptr, offset, length):
|
||||
"""Parse JPX free box.
|
||||
|
||||
Parameters
|
||||
|
|
@ -1409,16 +1367,12 @@ class FragmentListBox(Jp2kBox):
|
|||
Start position of box in bytes.
|
||||
length : int
|
||||
Length of the box in bytes.
|
||||
box_is_XL : bool
|
||||
True if the box has an XL field. In this case, the start of the
|
||||
box is 16 bytes behind the start of the box payload instead of being
|
||||
8 bytes behind.
|
||||
|
||||
Returns
|
||||
-------
|
||||
FragmentListBox instance
|
||||
"""
|
||||
num_bytes = length - 16 if box_is_XL else length - 8
|
||||
num_bytes = offset + length - fptr.tell()
|
||||
read_buffer = fptr.read(num_bytes)
|
||||
num_fragments, = struct.unpack_from('>H', read_buffer, offset=0)
|
||||
|
||||
|
|
@ -1461,7 +1415,7 @@ class FragmentTableBox(Jp2kBox):
|
|||
return msg
|
||||
|
||||
@classmethod
|
||||
def parse(cls, fptr, offset, length, box_is_XL=False):
|
||||
def parse(cls, fptr, offset, length):
|
||||
"""Parse JPX fragment table superbox box.
|
||||
|
||||
Parameters
|
||||
|
|
@ -1472,10 +1426,6 @@ class FragmentTableBox(Jp2kBox):
|
|||
Start position of box in bytes.
|
||||
length : int
|
||||
Length of the box in bytes.
|
||||
box_is_XL : bool
|
||||
True if the box has an XL field. In this case, the start of the
|
||||
box is 16 bytes behind the start of the box payload instead of being
|
||||
8 bytes behind.
|
||||
|
||||
Returns
|
||||
-------
|
||||
|
|
@ -1536,7 +1486,7 @@ class FreeBox(Jp2kBox):
|
|||
return msg
|
||||
|
||||
@classmethod
|
||||
def parse(cls, fptr, offset, length, box_is_XL=False):
|
||||
def parse(cls, fptr, offset, length):
|
||||
"""Parse JPX free box.
|
||||
|
||||
Parameters
|
||||
|
|
@ -1547,10 +1497,6 @@ class FreeBox(Jp2kBox):
|
|||
Start position of box in bytes.
|
||||
length : int
|
||||
Length of the box in bytes.
|
||||
box_is_XL : bool
|
||||
True if the box has an XL field. In this case, the start of the
|
||||
box is 16 bytes behind the start of the box payload instead of being
|
||||
8 bytes behind.
|
||||
|
||||
Returns
|
||||
-------
|
||||
|
|
@ -1664,7 +1610,7 @@ class ImageHeaderBox(Jp2kBox):
|
|||
fptr.write(read_buffer)
|
||||
|
||||
@classmethod
|
||||
def parse(cls, fptr, offset, length, box_is_XL=False):
|
||||
def parse(cls, fptr, offset, length):
|
||||
"""Parse JPEG 2000 image header box.
|
||||
|
||||
Parameters
|
||||
|
|
@ -1675,10 +1621,6 @@ class ImageHeaderBox(Jp2kBox):
|
|||
Start position of box in bytes.
|
||||
length : int
|
||||
Length of the box in bytes.
|
||||
box_is_XL : bool
|
||||
True if the box has an XL field. In this case, the start of the
|
||||
box is 16 bytes behind the start of the box payload instead of being
|
||||
8 bytes behind.
|
||||
|
||||
Returns
|
||||
-------
|
||||
|
|
@ -1736,7 +1678,7 @@ class AssociationBox(Jp2kBox):
|
|||
return msg
|
||||
|
||||
@classmethod
|
||||
def parse(cls, fptr, offset, length, box_is_XL=False):
|
||||
def parse(cls, fptr, offset, length):
|
||||
"""Parse association box.
|
||||
|
||||
Parameters
|
||||
|
|
@ -1747,10 +1689,6 @@ class AssociationBox(Jp2kBox):
|
|||
Start position of box in bytes.
|
||||
length : int
|
||||
Length of the box in bytes.
|
||||
box_is_XL : bool
|
||||
True if the box has an XL field. In this case, the start of the
|
||||
box is 16 bytes behind the start of the box payload instead of being
|
||||
8 bytes behind.
|
||||
|
||||
Returns
|
||||
-------
|
||||
|
|
@ -1806,7 +1744,7 @@ class JP2HeaderBox(Jp2kBox):
|
|||
self._write_superbox(fptr, b'jp2h')
|
||||
|
||||
@classmethod
|
||||
def parse(cls, fptr, offset, length, box_is_XL=False):
|
||||
def parse(cls, fptr, offset, length):
|
||||
"""Parse JPEG 2000 header box.
|
||||
|
||||
Parameters
|
||||
|
|
@ -1817,10 +1755,6 @@ class JP2HeaderBox(Jp2kBox):
|
|||
Start position of box in bytes.
|
||||
length : int
|
||||
Length of the box in bytes.
|
||||
box_is_XL : bool
|
||||
True if the box has an XL field. In this case, the start of the
|
||||
box is 16 bytes behind the start of the box payload instead of being
|
||||
8 bytes behind.
|
||||
|
||||
Returns
|
||||
-------
|
||||
|
|
@ -1878,7 +1812,7 @@ class JPEG2000SignatureBox(Jp2kBox):
|
|||
fptr.write(struct.pack('>BBBB', *self.signature))
|
||||
|
||||
@classmethod
|
||||
def parse(cls, fptr, offset, length, box_is_XL=False):
|
||||
def parse(cls, fptr, offset, length):
|
||||
"""Parse JPEG 2000 signature box.
|
||||
|
||||
Parameters
|
||||
|
|
@ -1889,10 +1823,6 @@ class JPEG2000SignatureBox(Jp2kBox):
|
|||
Start position of box in bytes.
|
||||
length : int
|
||||
Length of the box in bytes.
|
||||
box_is_XL : bool
|
||||
True if the box has an XL field. In this case, the start of the
|
||||
box is 16 bytes behind the start of the box payload instead of being
|
||||
8 bytes behind.
|
||||
|
||||
Returns
|
||||
-------
|
||||
|
|
@ -2000,7 +1930,7 @@ class PaletteBox(Jp2kBox):
|
|||
fptr.write(write_buffer)
|
||||
|
||||
@classmethod
|
||||
def parse(cls, fptr, offset, length, box_is_XL=False):
|
||||
def parse(cls, fptr, offset, length):
|
||||
"""Parse palette box.
|
||||
|
||||
Parameters
|
||||
|
|
@ -2011,16 +1941,12 @@ class PaletteBox(Jp2kBox):
|
|||
Start position of box in bytes.
|
||||
length : int
|
||||
Length of the box in bytes.
|
||||
box_is_XL : bool
|
||||
True if the box has an XL field. In this case, the start of the
|
||||
box is 16 bytes behind the start of the box payload instead of being
|
||||
8 bytes behind.
|
||||
|
||||
Returns
|
||||
-------
|
||||
PaletteBox instance
|
||||
"""
|
||||
num_bytes = length - 16 if box_is_XL else length - 8
|
||||
num_bytes = offset + length - fptr.tell()
|
||||
read_buffer = fptr.read(num_bytes)
|
||||
nrows, ncols = struct.unpack_from('>HB', read_buffer, offset=0)
|
||||
|
||||
|
|
@ -2232,7 +2158,7 @@ class ReaderRequirementsBox(Jp2kBox):
|
|||
return msg
|
||||
|
||||
@classmethod
|
||||
def parse(cls, fptr, offset, length, box_is_XL=False):
|
||||
def parse(cls, fptr, offset, length):
|
||||
"""Parse reader requirements box.
|
||||
|
||||
Parameters
|
||||
|
|
@ -2243,16 +2169,12 @@ class ReaderRequirementsBox(Jp2kBox):
|
|||
Start position of box in bytes.
|
||||
length : int
|
||||
Length of the box in bytes.
|
||||
box_is_XL : bool
|
||||
True if the box has an XL field. In this case, the start of the
|
||||
box is 16 bytes behind the start of the box payload instead of being
|
||||
8 bytes behind.
|
||||
|
||||
Returns
|
||||
-------
|
||||
ReaderRequirementsBox instance
|
||||
"""
|
||||
num_bytes = length - 16 if box_is_XL else length - 8
|
||||
num_bytes = offset + length - fptr.tell()
|
||||
read_buffer = fptr.read(num_bytes)
|
||||
mask_length, = struct.unpack_from('>B', read_buffer, offset=0)
|
||||
|
||||
|
|
@ -2446,7 +2368,7 @@ class ResolutionBox(Jp2kBox):
|
|||
return msg
|
||||
|
||||
@classmethod
|
||||
def parse(cls, fptr, offset, length, box_is_XL=False):
|
||||
def parse(cls, fptr, offset, length):
|
||||
"""Parse Resolution box.
|
||||
|
||||
Parameters
|
||||
|
|
@ -2457,10 +2379,6 @@ class ResolutionBox(Jp2kBox):
|
|||
Start position of box in bytes.
|
||||
length : int
|
||||
Length of the box in bytes.
|
||||
box_is_XL : bool
|
||||
True if the box has an XL field. In this case, the start of the
|
||||
box is 16 bytes behind the start of the box payload instead of being
|
||||
8 bytes behind.
|
||||
|
||||
Returns
|
||||
-------
|
||||
|
|
@ -2514,7 +2432,7 @@ class CaptureResolutionBox(Jp2kBox):
|
|||
return msg
|
||||
|
||||
@classmethod
|
||||
def parse(cls, fptr, offset, length, box_is_XL=False):
|
||||
def parse(cls, fptr, offset, length):
|
||||
"""Parse CaptureResolutionBox.
|
||||
|
||||
Parameters
|
||||
|
|
@ -2525,10 +2443,6 @@ class CaptureResolutionBox(Jp2kBox):
|
|||
Start position of box in bytes.
|
||||
length : int
|
||||
Length of the box in bytes.
|
||||
box_is_XL : bool
|
||||
True if the box has an XL field. In this case, the start of the
|
||||
box is 16 bytes behind the start of the box payload instead of being
|
||||
8 bytes behind.
|
||||
|
||||
Returns
|
||||
-------
|
||||
|
|
@ -2581,7 +2495,7 @@ class DisplayResolutionBox(Jp2kBox):
|
|||
return msg
|
||||
|
||||
@classmethod
|
||||
def parse(cls, fptr, offset, length, box_is_XL=False):
|
||||
def parse(cls, fptr, offset, length):
|
||||
"""Parse display resolution box.
|
||||
|
||||
Parameters
|
||||
|
|
@ -2592,10 +2506,6 @@ class DisplayResolutionBox(Jp2kBox):
|
|||
Start position of box in bytes.
|
||||
length : int
|
||||
Length of the box in bytes.
|
||||
box_is_XL : bool
|
||||
True if the box has an XL field. In this case, the start of the
|
||||
box is 16 bytes behind the start of the box payload instead of being
|
||||
8 bytes behind.
|
||||
|
||||
Returns
|
||||
-------
|
||||
|
|
@ -2653,7 +2563,7 @@ class LabelBox(Jp2kBox):
|
|||
fptr.write(self.label.encode())
|
||||
|
||||
@classmethod
|
||||
def parse(cls, fptr, offset, length, box_is_XL=False):
|
||||
def parse(cls, fptr, offset, length):
|
||||
"""Parse Label box.
|
||||
|
||||
Parameters
|
||||
|
|
@ -2664,16 +2574,12 @@ class LabelBox(Jp2kBox):
|
|||
Start position of box in bytes.
|
||||
length : int
|
||||
Length of the box in bytes.
|
||||
box_is_XL : bool
|
||||
True if the box has an XL field. In this case, the start of the
|
||||
box is 16 bytes behind the start of the box payload instead of being
|
||||
8 bytes behind.
|
||||
|
||||
Returns
|
||||
-------
|
||||
LabelBox instance
|
||||
"""
|
||||
num_bytes = length - 16 if box_is_XL else length - 8
|
||||
num_bytes = offset + length - fptr.tell()
|
||||
read_buffer = fptr.read(num_bytes)
|
||||
label = read_buffer.decode('utf-8')
|
||||
return cls(label, length=length, offset=offset)
|
||||
|
|
@ -2728,7 +2634,7 @@ class NumberListBox(Jp2kBox):
|
|||
return msg
|
||||
|
||||
@classmethod
|
||||
def parse(cls, fptr, offset, length, box_is_XL=False):
|
||||
def parse(cls, fptr, offset, length):
|
||||
"""Parse number list box.
|
||||
|
||||
Parameters
|
||||
|
|
@ -2739,16 +2645,12 @@ class NumberListBox(Jp2kBox):
|
|||
Start position of box in bytes.
|
||||
length : int
|
||||
Length of the box in bytes.
|
||||
box_is_XL : bool
|
||||
True if the box has an XL field. In this case, the start of the
|
||||
box is 16 bytes behind the start of the box payload instead of being
|
||||
8 bytes behind.
|
||||
|
||||
Returns
|
||||
-------
|
||||
LabelBox instance
|
||||
"""
|
||||
num_bytes = length - 16 if box_is_XL else length - 8
|
||||
num_bytes = offset + length - fptr.tell()
|
||||
raw_data = fptr.read(num_bytes)
|
||||
num_associations = int(len(raw_data) / 4)
|
||||
lst = struct.unpack('>' + 'I' * num_associations, raw_data)
|
||||
|
|
@ -2836,7 +2738,7 @@ class XMLBox(Jp2kBox):
|
|||
fptr.write(read_buffer)
|
||||
|
||||
@classmethod
|
||||
def parse(cls, fptr, offset, length, box_is_XL=False):
|
||||
def parse(cls, fptr, offset, length):
|
||||
"""Parse XML box.
|
||||
|
||||
Parameters
|
||||
|
|
@ -2847,16 +2749,12 @@ class XMLBox(Jp2kBox):
|
|||
Start position of box in bytes.
|
||||
length : int
|
||||
Length of the box in bytes.
|
||||
box_is_XL : bool
|
||||
True if the box has an XL field. In this case, the start of the
|
||||
box is 16 bytes behind the start of the box payload instead of being
|
||||
8 bytes behind.
|
||||
|
||||
Returns
|
||||
-------
|
||||
XMLBox instance
|
||||
"""
|
||||
num_bytes = length - 16 if box_is_XL else length - 8
|
||||
num_bytes = offset + length - fptr.tell()
|
||||
read_buffer = fptr.read(num_bytes)
|
||||
try:
|
||||
text = read_buffer.decode('utf-8')
|
||||
|
|
@ -2940,7 +2838,7 @@ class UUIDListBox(Jp2kBox):
|
|||
return msg
|
||||
|
||||
@classmethod
|
||||
def parse(cls, fptr, offset, length, box_is_XL=False):
|
||||
def parse(cls, fptr, offset, length):
|
||||
"""Parse UUIDList box.
|
||||
|
||||
Parameters
|
||||
|
|
@ -2951,16 +2849,12 @@ class UUIDListBox(Jp2kBox):
|
|||
Start position of box in bytes.
|
||||
length : int
|
||||
Length of the box in bytes.
|
||||
box_is_XL : bool
|
||||
True if the box has an XL field. In this case, the start of the
|
||||
box is 16 bytes behind the start of the box payload instead of being
|
||||
8 bytes behind.
|
||||
|
||||
Returns
|
||||
-------
|
||||
UUIDListBox instance
|
||||
"""
|
||||
num_bytes = length - 16 if box_is_XL else length - 8
|
||||
num_bytes = offset + length - fptr.tell()
|
||||
read_buffer = fptr.read(num_bytes)
|
||||
|
||||
num_uuids, = struct.unpack_from('>H', read_buffer)
|
||||
|
|
@ -3004,7 +2898,7 @@ class UUIDInfoBox(Jp2kBox):
|
|||
return msg
|
||||
|
||||
@classmethod
|
||||
def parse(cls, fptr, offset, length, box_is_XL=False):
|
||||
def parse(cls, fptr, offset, length):
|
||||
"""Parse UUIDInfo super box.
|
||||
|
||||
Parameters
|
||||
|
|
@ -3015,10 +2909,6 @@ class UUIDInfoBox(Jp2kBox):
|
|||
Start position of box in bytes.
|
||||
length : int
|
||||
Length of the box in bytes.
|
||||
box_is_XL : bool
|
||||
True if the box has an XL field. In this case, the start of the
|
||||
box is 16 bytes behind the start of the box payload instead of being
|
||||
8 bytes behind.
|
||||
|
||||
Returns
|
||||
-------
|
||||
|
|
@ -3101,7 +2991,7 @@ class DataEntryURLBox(Jp2kBox):
|
|||
return msg
|
||||
|
||||
@classmethod
|
||||
def parse(cls, fptr, offset, length, box_is_XL=False):
|
||||
def parse(cls, fptr, offset, length):
|
||||
"""Parse data entry URL box.
|
||||
|
||||
Parameters
|
||||
|
|
@ -3112,16 +3002,12 @@ class DataEntryURLBox(Jp2kBox):
|
|||
Start position of box in bytes.
|
||||
length : int
|
||||
Length of the box in bytes.
|
||||
box_is_XL : bool
|
||||
True if the box has an XL field. In this case, the start of the
|
||||
box is 16 bytes behind the start of the box payload instead of being
|
||||
8 bytes behind.
|
||||
|
||||
Returns
|
||||
-------
|
||||
DataEntryURLbox instance
|
||||
"""
|
||||
num_bytes = length - 16 if box_is_XL else length - 8
|
||||
num_bytes = offset + length - fptr.tell()
|
||||
read_buffer = fptr.read(num_bytes)
|
||||
data = struct.unpack_from('>BBBB', read_buffer)
|
||||
version = data[0]
|
||||
|
|
@ -3278,7 +3164,7 @@ class UUIDBox(Jp2kBox):
|
|||
fptr.write(self.raw_data)
|
||||
|
||||
@classmethod
|
||||
def parse(cls, fptr, offset, length, box_is_XL=False):
|
||||
def parse(cls, fptr, offset, length):
|
||||
"""Parse UUID box.
|
||||
|
||||
Parameters
|
||||
|
|
@ -3289,16 +3175,12 @@ class UUIDBox(Jp2kBox):
|
|||
Start position of box in bytes.
|
||||
length : int
|
||||
Length of the box in bytes.
|
||||
box_is_XL : bool
|
||||
True if the box has an XL field. In this case, the start of the
|
||||
box is 16 bytes behind the start of the box payload instead of being
|
||||
8 bytes behind.
|
||||
|
||||
Returns
|
||||
-------
|
||||
UUIDBox instance
|
||||
"""
|
||||
num_bytes = length - 16 if box_is_XL else length - 8
|
||||
num_bytes = offset + length - fptr.tell()
|
||||
read_buffer = fptr.read(num_bytes)
|
||||
the_uuid = uuid.UUID(bytes=read_buffer[0:16])
|
||||
return cls(the_uuid, read_buffer[16:], length=length, offset=offset)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue