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