Changed static methods into class methods. #136
Since the static methods were being used as constructors, they really did deserve to be class methods.
This commit is contained in:
parent
9840b66cae
commit
900a44f00b
1 changed files with 105 additions and 126 deletions
231
glymur/jp2box.py
231
glymur/jp2box.py
|
|
@ -390,8 +390,8 @@ class ColourSpecificationBox(Jp2kBox):
|
||||||
self.colorspace)
|
self.colorspace)
|
||||||
fptr.write(read_buffer)
|
fptr.write(read_buffer)
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def parse(fptr, offset, length):
|
def parse(cls, fptr, offset, length):
|
||||||
"""Parse JPEG 2000 color specification box.
|
"""Parse JPEG 2000 color specification box.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
|
|
@ -434,14 +434,13 @@ class ColourSpecificationBox(Jp2kBox):
|
||||||
profile = _ICCProfile(fptr.read(numbytes))
|
profile = _ICCProfile(fptr.read(numbytes))
|
||||||
icc_profile = profile.header
|
icc_profile = profile.header
|
||||||
|
|
||||||
box = ColourSpecificationBox(method=method,
|
return cls(method=method,
|
||||||
precedence=precedence,
|
precedence=precedence,
|
||||||
approximation=approximation,
|
approximation=approximation,
|
||||||
colorspace=colorspace,
|
colorspace=colorspace,
|
||||||
icc_profile=icc_profile,
|
icc_profile=icc_profile,
|
||||||
length=length,
|
length=length,
|
||||||
offset=offset)
|
offset=offset)
|
||||||
return box
|
|
||||||
|
|
||||||
|
|
||||||
class _ICCProfile(object):
|
class _ICCProfile(object):
|
||||||
|
|
@ -643,8 +642,8 @@ class ChannelDefinitionBox(Jp2kBox):
|
||||||
self.channel_type[j],
|
self.channel_type[j],
|
||||||
self.association[j]))
|
self.association[j]))
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def parse(fptr, offset, length):
|
def parse(cls, fptr, offset, length):
|
||||||
"""Parse component definition box.
|
"""Parse component definition box.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
|
|
@ -670,11 +669,10 @@ class ChannelDefinitionBox(Jp2kBox):
|
||||||
channel_type = data[1:num_components * 6:3]
|
channel_type = data[1:num_components * 6:3]
|
||||||
association = data[2:num_components * 6:3]
|
association = data[2:num_components * 6:3]
|
||||||
|
|
||||||
box = ChannelDefinitionBox(index=tuple(index),
|
return cls(index=tuple(index),
|
||||||
channel_type=tuple(channel_type),
|
channel_type=tuple(channel_type),
|
||||||
association=tuple(association),
|
association=tuple(association),
|
||||||
length=length, offset=offset)
|
length=length, offset=offset)
|
||||||
return box
|
|
||||||
|
|
||||||
|
|
||||||
class CodestreamHeaderBox(Jp2kBox):
|
class CodestreamHeaderBox(Jp2kBox):
|
||||||
|
|
@ -712,8 +710,8 @@ class CodestreamHeaderBox(Jp2kBox):
|
||||||
"""
|
"""
|
||||||
self._write_superbox(fptr)
|
self._write_superbox(fptr)
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def parse(fptr, offset, length):
|
def parse(cls, fptr, offset, length):
|
||||||
"""Parse codestream header box.
|
"""Parse codestream header box.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
|
|
@ -729,7 +727,7 @@ class CodestreamHeaderBox(Jp2kBox):
|
||||||
-------
|
-------
|
||||||
CodestreamHeaderBox instance
|
CodestreamHeaderBox instance
|
||||||
"""
|
"""
|
||||||
box = CodestreamHeaderBox(length=length, offset=offset)
|
box = cls(length=length, offset=offset)
|
||||||
|
|
||||||
# The codestream header box is a superbox, so go ahead and parse its
|
# The codestream header box is a superbox, so go ahead and parse its
|
||||||
# child boxes.
|
# child boxes.
|
||||||
|
|
@ -781,8 +779,8 @@ class ColourGroupBox(Jp2kBox):
|
||||||
self._validate(writing=True)
|
self._validate(writing=True)
|
||||||
self._write_superbox(fptr)
|
self._write_superbox(fptr)
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def parse(fptr, offset, length):
|
def parse(cls, fptr, offset, length):
|
||||||
"""Parse colour group box.
|
"""Parse colour group box.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
|
|
@ -798,7 +796,7 @@ class ColourGroupBox(Jp2kBox):
|
||||||
-------
|
-------
|
||||||
ColourGroupBox instance
|
ColourGroupBox instance
|
||||||
"""
|
"""
|
||||||
box = ColourGroupBox(length=length, offset=offset)
|
box = cls(length=length, offset=offset)
|
||||||
|
|
||||||
# The colour group box is a superbox, so go ahead and parse its
|
# The colour group box is a superbox, so go ahead and parse its
|
||||||
# child boxes.
|
# child boxes.
|
||||||
|
|
@ -844,8 +842,8 @@ class CompositingLayerHeaderBox(Jp2kBox):
|
||||||
"""
|
"""
|
||||||
self._write_superbox(fptr)
|
self._write_superbox(fptr)
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def parse(fptr, offset, length):
|
def parse(cls, fptr, offset, length):
|
||||||
"""Parse compositing layer header box.
|
"""Parse compositing layer header box.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
|
|
@ -861,7 +859,7 @@ class CompositingLayerHeaderBox(Jp2kBox):
|
||||||
-------
|
-------
|
||||||
CompositingLayerHeaderBox instance
|
CompositingLayerHeaderBox instance
|
||||||
"""
|
"""
|
||||||
box = CompositingLayerHeaderBox(length=length, offset=offset)
|
box = cls(length=length, offset=offset)
|
||||||
|
|
||||||
# This box is a superbox, so go ahead and parse its # child boxes.
|
# This box is a superbox, so go ahead and parse its # child boxes.
|
||||||
box.box = box.parse_superbox(fptr)
|
box.box = box.parse_superbox(fptr)
|
||||||
|
|
@ -935,8 +933,8 @@ class ComponentMappingBox(Jp2kBox):
|
||||||
self.palette_index[j])
|
self.palette_index[j])
|
||||||
fptr.write(write_buffer)
|
fptr.write(write_buffer)
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def parse(fptr, offset, length):
|
def parse(cls, fptr, offset, length):
|
||||||
"""Parse component mapping box.
|
"""Parse component mapping box.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
|
|
@ -962,9 +960,8 @@ class ComponentMappingBox(Jp2kBox):
|
||||||
mapping_type = data[1:num_bytes:3]
|
mapping_type = data[1:num_bytes:3]
|
||||||
palette_index = data[2:num_bytes:3]
|
palette_index = data[2:num_bytes:3]
|
||||||
|
|
||||||
box = ComponentMappingBox(component_index, mapping_type, palette_index,
|
return cls(component_index, mapping_type, palette_index,
|
||||||
length=length, offset=offset)
|
length=length, offset=offset)
|
||||||
return box
|
|
||||||
|
|
||||||
|
|
||||||
class ContiguousCodestreamBox(Jp2kBox):
|
class ContiguousCodestreamBox(Jp2kBox):
|
||||||
|
|
@ -1006,8 +1003,8 @@ class ContiguousCodestreamBox(Jp2kBox):
|
||||||
|
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def parse(fptr, offset=0, length=0):
|
def parse(cls, fptr, offset=0, length=0):
|
||||||
"""Parse a codestream box.
|
"""Parse a codestream box.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
|
|
@ -1024,9 +1021,7 @@ class ContiguousCodestreamBox(Jp2kBox):
|
||||||
ContiguousCodestreamBox instance
|
ContiguousCodestreamBox instance
|
||||||
"""
|
"""
|
||||||
main_header = Codestream(fptr, length, header_only=True)
|
main_header = Codestream(fptr, length, header_only=True)
|
||||||
box = ContiguousCodestreamBox(main_header, length=length,
|
return cls(main_header, length=length, offset=offset)
|
||||||
offset=offset)
|
|
||||||
return box
|
|
||||||
|
|
||||||
|
|
||||||
class DataReferenceBox(Jp2kBox):
|
class DataReferenceBox(Jp2kBox):
|
||||||
|
|
@ -1106,8 +1101,8 @@ class DataReferenceBox(Jp2kBox):
|
||||||
msg = 'glymur.jp2box.DataReferenceBox()'
|
msg = 'glymur.jp2box.DataReferenceBox()'
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def parse(fptr, offset, length):
|
def parse(cls, fptr, offset, length):
|
||||||
"""Parse Label box.
|
"""Parse Label box.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
|
|
@ -1139,8 +1134,7 @@ class DataReferenceBox(Jp2kBox):
|
||||||
box = DataEntryURLBox.parse(fptr, start, box_length)
|
box = DataEntryURLBox.parse(fptr, start, box_length)
|
||||||
data_entry_url_box_list.append(box)
|
data_entry_url_box_list.append(box)
|
||||||
|
|
||||||
return DataReferenceBox(data_entry_url_box_list,
|
return cls(data_entry_url_box_list, length=length, offset=offset)
|
||||||
length=length, offset=offset)
|
|
||||||
|
|
||||||
|
|
||||||
class FileTypeBox(Jp2kBox):
|
class FileTypeBox(Jp2kBox):
|
||||||
|
|
@ -1223,8 +1217,8 @@ class FileTypeBox(Jp2kBox):
|
||||||
for item in self.compatibility_list:
|
for item in self.compatibility_list:
|
||||||
fptr.write(item.encode())
|
fptr.write(item.encode())
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def parse(fptr, offset, length):
|
def parse(cls, fptr, offset, length):
|
||||||
"""Parse JPEG 2000 file type box.
|
"""Parse JPEG 2000 file type box.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
|
|
@ -1259,10 +1253,9 @@ class FileTypeBox(Jp2kBox):
|
||||||
|
|
||||||
compatibility_list = compatibility_list
|
compatibility_list = compatibility_list
|
||||||
|
|
||||||
box = FileTypeBox(brand=brand, minor_version=minor_version,
|
return cls(brand=brand, minor_version=minor_version,
|
||||||
compatibility_list=compatibility_list,
|
compatibility_list=compatibility_list,
|
||||||
length=length, offset=offset)
|
length=length, offset=offset)
|
||||||
return box
|
|
||||||
|
|
||||||
|
|
||||||
class FragmentListBox(Jp2kBox):
|
class FragmentListBox(Jp2kBox):
|
||||||
|
|
@ -1338,8 +1331,8 @@ class FragmentListBox(Jp2kBox):
|
||||||
self.data_reference[j])
|
self.data_reference[j])
|
||||||
fptr.write(write_buffer)
|
fptr.write(write_buffer)
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def parse(fptr, offset, length):
|
def parse(cls, fptr, offset, length):
|
||||||
"""Parse JPX free box.
|
"""Parse JPX free box.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
|
|
@ -1363,8 +1356,8 @@ class FragmentListBox(Jp2kBox):
|
||||||
frag_offset = lst[0::3]
|
frag_offset = lst[0::3]
|
||||||
frag_len = lst[1::3]
|
frag_len = lst[1::3]
|
||||||
data_reference = lst[2::3]
|
data_reference = lst[2::3]
|
||||||
return FragmentListBox(frag_offset, frag_len, data_reference,
|
return cls(frag_offset, frag_len, data_reference,
|
||||||
length=length, offset=offset)
|
length=length, offset=offset)
|
||||||
|
|
||||||
|
|
||||||
class FragmentTableBox(Jp2kBox):
|
class FragmentTableBox(Jp2kBox):
|
||||||
|
|
@ -1395,8 +1388,8 @@ class FragmentTableBox(Jp2kBox):
|
||||||
msg = self._str_superbox()
|
msg = self._str_superbox()
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def parse(fptr, offset, length):
|
def parse(cls, fptr, offset, length):
|
||||||
"""Parse JPX fragment table superbox box.
|
"""Parse JPX fragment table superbox box.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
|
|
@ -1412,7 +1405,7 @@ class FragmentTableBox(Jp2kBox):
|
||||||
-------
|
-------
|
||||||
FragmentTableBox instance
|
FragmentTableBox instance
|
||||||
"""
|
"""
|
||||||
box = FragmentTableBox(length=length, offset=offset)
|
box = cls(length=length, offset=offset)
|
||||||
|
|
||||||
# The FragmentTable box is a superbox, so go ahead and parse its child
|
# The FragmentTable box is a superbox, so go ahead and parse its child
|
||||||
# boxes.
|
# boxes.
|
||||||
|
|
@ -1466,8 +1459,8 @@ class FreeBox(Jp2kBox):
|
||||||
|
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def parse(fptr, offset, length):
|
def parse(cls, fptr, offset, length):
|
||||||
"""Parse JPX free box.
|
"""Parse JPX free box.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
|
|
@ -1483,7 +1476,7 @@ class FreeBox(Jp2kBox):
|
||||||
-------
|
-------
|
||||||
FreeBox instance
|
FreeBox instance
|
||||||
"""
|
"""
|
||||||
return FreeBox(length=length, offset=offset)
|
return cls(length=length, offset=offset)
|
||||||
|
|
||||||
|
|
||||||
class ImageHeaderBox(Jp2kBox):
|
class ImageHeaderBox(Jp2kBox):
|
||||||
|
|
@ -1590,8 +1583,8 @@ class ImageHeaderBox(Jp2kBox):
|
||||||
1 if self.ip_provided else 0)
|
1 if self.ip_provided else 0)
|
||||||
fptr.write(read_buffer)
|
fptr.write(read_buffer)
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def parse(fptr, offset, length):
|
def parse(cls, fptr, offset, length):
|
||||||
"""Parse JPEG 2000 image header box.
|
"""Parse JPEG 2000 image header box.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
|
|
@ -1619,14 +1612,13 @@ class ImageHeaderBox(Jp2kBox):
|
||||||
colorspace_unknown = True if params[5] else False
|
colorspace_unknown = True if params[5] else False
|
||||||
ip_provided = True if params[6] else False
|
ip_provided = True if params[6] else False
|
||||||
|
|
||||||
box = ImageHeaderBox(height, width, num_components=num_components,
|
return cls(height, width, num_components=num_components,
|
||||||
bits_per_component=bits_per_component,
|
bits_per_component=bits_per_component,
|
||||||
signed=signed,
|
signed=signed,
|
||||||
compression=compression,
|
compression=compression,
|
||||||
colorspace_unknown=colorspace_unknown,
|
colorspace_unknown=colorspace_unknown,
|
||||||
ip_provided=ip_provided,
|
ip_provided=ip_provided,
|
||||||
length=length, offset=offset)
|
length=length, offset=offset)
|
||||||
return box
|
|
||||||
|
|
||||||
|
|
||||||
class AssociationBox(Jp2kBox):
|
class AssociationBox(Jp2kBox):
|
||||||
|
|
@ -1659,8 +1651,8 @@ class AssociationBox(Jp2kBox):
|
||||||
msg = self._str_superbox()
|
msg = self._str_superbox()
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def parse(fptr, offset, length):
|
def parse(cls, fptr, offset, length):
|
||||||
"""Parse association box.
|
"""Parse association box.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
|
|
@ -1676,7 +1668,7 @@ class AssociationBox(Jp2kBox):
|
||||||
-------
|
-------
|
||||||
AssociationBox instance
|
AssociationBox instance
|
||||||
"""
|
"""
|
||||||
box = AssociationBox(length=length, offset=offset)
|
box = cls(length=length, offset=offset)
|
||||||
|
|
||||||
# The Association box is a superbox, so go ahead and parse its child
|
# The Association box is a superbox, so go ahead and parse its child
|
||||||
# boxes.
|
# boxes.
|
||||||
|
|
@ -1725,8 +1717,8 @@ class JP2HeaderBox(Jp2kBox):
|
||||||
"""
|
"""
|
||||||
self._write_superbox(fptr)
|
self._write_superbox(fptr)
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def parse(fptr, offset, length):
|
def parse(cls, fptr, offset, length):
|
||||||
"""Parse JPEG 2000 header box.
|
"""Parse JPEG 2000 header box.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
|
|
@ -1742,7 +1734,7 @@ class JP2HeaderBox(Jp2kBox):
|
||||||
-------
|
-------
|
||||||
JP2HeaderBox instance
|
JP2HeaderBox instance
|
||||||
"""
|
"""
|
||||||
box = JP2HeaderBox(length=length, offset=offset)
|
box = cls(length=length, offset=offset)
|
||||||
|
|
||||||
# The JP2 header box is a superbox, so go ahead and parse its child
|
# The JP2 header box is a superbox, so go ahead and parse its child
|
||||||
# boxes.
|
# boxes.
|
||||||
|
|
@ -1793,8 +1785,8 @@ class JPEG2000SignatureBox(Jp2kBox):
|
||||||
fptr.write(b'jP ')
|
fptr.write(b'jP ')
|
||||||
fptr.write(struct.pack('>BBBB', *self.signature))
|
fptr.write(struct.pack('>BBBB', *self.signature))
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def parse(fptr, offset, length):
|
def parse(cls, fptr, offset, length):
|
||||||
"""Parse JPEG 2000 signature box.
|
"""Parse JPEG 2000 signature box.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
|
|
@ -1813,9 +1805,7 @@ class JPEG2000SignatureBox(Jp2kBox):
|
||||||
read_buffer = fptr.read(4)
|
read_buffer = fptr.read(4)
|
||||||
signature = struct.unpack('>BBBB', read_buffer)
|
signature = struct.unpack('>BBBB', read_buffer)
|
||||||
|
|
||||||
box = JPEG2000SignatureBox(signature=signature, length=length,
|
return cls(signature=signature, length=length, offset=offset)
|
||||||
offset=offset)
|
|
||||||
return box
|
|
||||||
|
|
||||||
|
|
||||||
class PaletteBox(Jp2kBox):
|
class PaletteBox(Jp2kBox):
|
||||||
|
|
@ -1920,8 +1910,8 @@ class PaletteBox(Jp2kBox):
|
||||||
write_buffer = struct.pack(fmt, *row)
|
write_buffer = struct.pack(fmt, *row)
|
||||||
fptr.write(write_buffer)
|
fptr.write(write_buffer)
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def parse(fptr, offset, length):
|
def parse(cls, fptr, offset, length):
|
||||||
"""Parse palette box.
|
"""Parse palette box.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
|
|
@ -1966,7 +1956,7 @@ class PaletteBox(Jp2kBox):
|
||||||
palette[j] = struct.unpack_from(fmt, read_buffer,
|
palette[j] = struct.unpack_from(fmt, read_buffer,
|
||||||
offset=j * row_nbytes)
|
offset=j * row_nbytes)
|
||||||
|
|
||||||
return PaletteBox(palette, bps, signed, length=length, offset=offset)
|
return cls(palette, bps, signed, length=length, offset=offset)
|
||||||
|
|
||||||
|
|
||||||
# Map rreq codes to display text.
|
# Map rreq codes to display text.
|
||||||
|
|
@ -2132,8 +2122,8 @@ class ReaderRequirementsBox(Jp2kBox):
|
||||||
|
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def parse(fptr, offset, length):
|
def parse(cls, fptr, offset, length):
|
||||||
"""Parse reader requirements box.
|
"""Parse reader requirements box.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
|
|
@ -2179,10 +2169,9 @@ class ReaderRequirementsBox(Jp2kBox):
|
||||||
msg += 'The box contents will not be interpreted.'
|
msg += 'The box contents will not be interpreted.'
|
||||||
warnings.warn(msg.format(mask_length), UserWarning)
|
warnings.warn(msg.format(mask_length), UserWarning)
|
||||||
|
|
||||||
box = ReaderRequirementsBox(fuam, dcm, standard_flag, standard_mask,
|
return cls(fuam, dcm, standard_flag, standard_mask,
|
||||||
vendor_feature, vendor_mask,
|
vendor_feature, vendor_mask,
|
||||||
length=length, offset=offset)
|
length=length, offset=offset)
|
||||||
return box
|
|
||||||
|
|
||||||
|
|
||||||
def _parse_rreq3(fptr, length, offset):
|
def _parse_rreq3(fptr, length, offset):
|
||||||
|
|
@ -2340,8 +2329,8 @@ class ResolutionBox(Jp2kBox):
|
||||||
msg = self._str_superbox()
|
msg = self._str_superbox()
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def parse(fptr, offset, length):
|
def parse(cls, fptr, offset, length):
|
||||||
"""Parse Resolution box.
|
"""Parse Resolution box.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
|
|
@ -2357,7 +2346,7 @@ class ResolutionBox(Jp2kBox):
|
||||||
-------
|
-------
|
||||||
ResolutionBox instance
|
ResolutionBox instance
|
||||||
"""
|
"""
|
||||||
box = ResolutionBox(length=length, offset=offset)
|
box = cls(length=length, offset=offset)
|
||||||
|
|
||||||
# The JP2 header box is a superbox, so go ahead and parse its child
|
# The JP2 header box is a superbox, so go ahead and parse its child
|
||||||
# boxes.
|
# boxes.
|
||||||
|
|
@ -2404,8 +2393,8 @@ class CaptureResolutionBox(Jp2kBox):
|
||||||
msg += '\n HCR: {0}'.format(self.horizontal_resolution)
|
msg += '\n HCR: {0}'.format(self.horizontal_resolution)
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def parse(fptr, offset, length):
|
def parse(cls, fptr, offset, length):
|
||||||
"""Parse CaptureResolutionBox.
|
"""Parse CaptureResolutionBox.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
|
|
@ -2426,9 +2415,7 @@ class CaptureResolutionBox(Jp2kBox):
|
||||||
vres = rn1 / rd1 * math.pow(10, re1)
|
vres = rn1 / rd1 * math.pow(10, re1)
|
||||||
hres = rn2 / rd2 * math.pow(10, re2)
|
hres = rn2 / rd2 * math.pow(10, re2)
|
||||||
|
|
||||||
box = CaptureResolutionBox(vres, hres, length=length, offset=offset)
|
return cls(vres, hres, length=length, offset=offset)
|
||||||
|
|
||||||
return box
|
|
||||||
|
|
||||||
|
|
||||||
class DisplayResolutionBox(Jp2kBox):
|
class DisplayResolutionBox(Jp2kBox):
|
||||||
|
|
@ -2469,8 +2456,8 @@ class DisplayResolutionBox(Jp2kBox):
|
||||||
msg += '\n HDR: {0}'.format(self.horizontal_resolution)
|
msg += '\n HDR: {0}'.format(self.horizontal_resolution)
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def parse(fptr, offset, length):
|
def parse(cls, fptr, offset, length):
|
||||||
"""Parse display resolution box.
|
"""Parse display resolution box.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
|
|
@ -2492,9 +2479,7 @@ class DisplayResolutionBox(Jp2kBox):
|
||||||
vres = rn1 / rd1 * math.pow(10, re1)
|
vres = rn1 / rd1 * math.pow(10, re1)
|
||||||
hres = rn2 / rd2 * math.pow(10, re2)
|
hres = rn2 / rd2 * math.pow(10, re2)
|
||||||
|
|
||||||
box = DisplayResolutionBox(vres, hres, length=length, offset=offset)
|
return cls(vres, hres, length=length, offset=offset)
|
||||||
|
|
||||||
return box
|
|
||||||
|
|
||||||
|
|
||||||
class LabelBox(Jp2kBox):
|
class LabelBox(Jp2kBox):
|
||||||
|
|
@ -2539,8 +2524,8 @@ class LabelBox(Jp2kBox):
|
||||||
fptr.write(b'lbl ')
|
fptr.write(b'lbl ')
|
||||||
fptr.write(self.label.encode())
|
fptr.write(self.label.encode())
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def parse(fptr, offset, length):
|
def parse(cls, fptr, offset, length):
|
||||||
"""Parse Label box.
|
"""Parse Label box.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
|
|
@ -2559,8 +2544,7 @@ class LabelBox(Jp2kBox):
|
||||||
num_bytes = offset + length - fptr.tell()
|
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')
|
||||||
box = LabelBox(label, length=length, offset=offset)
|
return cls(label, length=length, offset=offset)
|
||||||
return box
|
|
||||||
|
|
||||||
|
|
||||||
class NumberListBox(Jp2kBox):
|
class NumberListBox(Jp2kBox):
|
||||||
|
|
@ -2611,8 +2595,8 @@ class NumberListBox(Jp2kBox):
|
||||||
msg = 'glymur.jp2box.NumberListBox()'
|
msg = 'glymur.jp2box.NumberListBox()'
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def parse(fptr, offset, length):
|
def parse(cls, fptr, offset, length):
|
||||||
"""Parse number list box.
|
"""Parse number list box.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
|
|
@ -2632,8 +2616,7 @@ class NumberListBox(Jp2kBox):
|
||||||
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)
|
||||||
box = NumberListBox(lst, length=length, offset=offset)
|
return cls(lst, length=length, offset=offset)
|
||||||
return box
|
|
||||||
|
|
||||||
def write(self, fptr):
|
def write(self, fptr):
|
||||||
"""Write a NumberList box to file.
|
"""Write a NumberList box to file.
|
||||||
|
|
@ -2716,8 +2699,8 @@ class XMLBox(Jp2kBox):
|
||||||
fptr.write(b'xml ')
|
fptr.write(b'xml ')
|
||||||
fptr.write(read_buffer)
|
fptr.write(read_buffer)
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def parse(fptr, offset, length):
|
def parse(cls, fptr, offset, length):
|
||||||
"""Parse XML box.
|
"""Parse XML box.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
|
|
@ -2778,8 +2761,7 @@ class XMLBox(Jp2kBox):
|
||||||
warnings.warn(msg, UserWarning)
|
warnings.warn(msg, UserWarning)
|
||||||
xml = None
|
xml = None
|
||||||
|
|
||||||
box = XMLBox(xml=xml, length=length, offset=offset)
|
return cls(xml=xml, length=length, offset=offset)
|
||||||
return box
|
|
||||||
|
|
||||||
|
|
||||||
class UUIDListBox(Jp2kBox):
|
class UUIDListBox(Jp2kBox):
|
||||||
|
|
@ -2817,8 +2799,8 @@ class UUIDListBox(Jp2kBox):
|
||||||
msg += '\n UUID[{0}]: {1}'.format(j, uuid_item)
|
msg += '\n UUID[{0}]: {1}'.format(j, uuid_item)
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def parse(fptr, offset, length):
|
def parse(cls, fptr, offset, length):
|
||||||
"""Parse UUIDList box.
|
"""Parse UUIDList box.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
|
|
@ -2842,8 +2824,7 @@ class UUIDListBox(Jp2kBox):
|
||||||
read_buffer = fptr.read(16)
|
read_buffer = fptr.read(16)
|
||||||
ulst.append(uuid.UUID(bytes=read_buffer))
|
ulst.append(uuid.UUID(bytes=read_buffer))
|
||||||
|
|
||||||
box = UUIDListBox(ulst, length=length, offset=offset)
|
return cls(ulst, length=length, offset=offset)
|
||||||
return box
|
|
||||||
|
|
||||||
|
|
||||||
class UUIDInfoBox(Jp2kBox):
|
class UUIDInfoBox(Jp2kBox):
|
||||||
|
|
@ -2876,8 +2857,8 @@ class UUIDInfoBox(Jp2kBox):
|
||||||
msg = self._str_superbox()
|
msg = self._str_superbox()
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def parse(fptr, offset, length):
|
def parse(cls, fptr, offset, length):
|
||||||
"""Parse UUIDInfo super box.
|
"""Parse UUIDInfo super box.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
|
|
@ -2894,7 +2875,7 @@ class UUIDInfoBox(Jp2kBox):
|
||||||
UUIDInfoBox instance
|
UUIDInfoBox instance
|
||||||
"""
|
"""
|
||||||
|
|
||||||
box = UUIDInfoBox(length=length, offset=offset)
|
box = cls(length=length, offset=offset)
|
||||||
|
|
||||||
# The UUIDInfo box is a superbox, so go ahead and parse its child
|
# The UUIDInfo box is a superbox, so go ahead and parse its child
|
||||||
# boxes.
|
# boxes.
|
||||||
|
|
@ -2969,8 +2950,8 @@ class DataEntryURLBox(Jp2kBox):
|
||||||
self.url)
|
self.url)
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def parse(fptr, offset, length):
|
def parse(cls, fptr, offset, length):
|
||||||
"""Parse data entry URL box.
|
"""Parse data entry URL box.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
|
|
@ -2994,8 +2975,7 @@ class DataEntryURLBox(Jp2kBox):
|
||||||
numbytes = offset + length - fptr.tell()
|
numbytes = offset + length - fptr.tell()
|
||||||
read_buffer = fptr.read(numbytes)
|
read_buffer = fptr.read(numbytes)
|
||||||
url = read_buffer.decode('utf-8').rstrip(chr(0))
|
url = read_buffer.decode('utf-8').rstrip(chr(0))
|
||||||
box = DataEntryURLBox(version, flag, url, length=length, offset=offset)
|
return cls(version, flag, url, length=length, offset=offset)
|
||||||
return box
|
|
||||||
|
|
||||||
|
|
||||||
class UnknownBox(Jp2kBox):
|
class UnknownBox(Jp2kBox):
|
||||||
|
|
@ -3144,8 +3124,8 @@ class UUIDBox(Jp2kBox):
|
||||||
fptr.write(self.uuid.bytes)
|
fptr.write(self.uuid.bytes)
|
||||||
fptr.write(self.raw_data)
|
fptr.write(self.raw_data)
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def parse(fptr, offset, length):
|
def parse(cls, fptr, offset, length):
|
||||||
"""Parse UUID box.
|
"""Parse UUID box.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
|
|
@ -3167,8 +3147,7 @@ class UUIDBox(Jp2kBox):
|
||||||
|
|
||||||
numbytes = offset + length - fptr.tell()
|
numbytes = offset + length - fptr.tell()
|
||||||
read_buffer = fptr.read(numbytes)
|
read_buffer = fptr.read(numbytes)
|
||||||
box = UUIDBox(the_uuid, read_buffer, length=length, offset=offset)
|
return cls(the_uuid, read_buffer, length=length, offset=offset)
|
||||||
return box
|
|
||||||
|
|
||||||
|
|
||||||
# Map each box ID to the corresponding class.
|
# Map each box ID to the corresponding class.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue