Small cleanups in jp2box.py
This commit is contained in:
parent
02f02ce154
commit
d89be23af2
1 changed files with 10 additions and 22 deletions
|
|
@ -381,8 +381,7 @@ class ColourSpecificationBox(Jp2kBox):
|
||||||
"""
|
"""
|
||||||
self._write_validate()
|
self._write_validate()
|
||||||
length = 15 if self.icc_profile is None else 11 + len(self.icc_profile)
|
length = 15 if self.icc_profile is None else 11 + len(self.icc_profile)
|
||||||
fptr.write(struct.pack('>I', length))
|
fptr.write(struct.pack('>I4s', length, b'colr'))
|
||||||
fptr.write(b'colr')
|
|
||||||
|
|
||||||
read_buffer = struct.pack('>BBBI',
|
read_buffer = struct.pack('>BBBI',
|
||||||
self.method,
|
self.method,
|
||||||
|
|
@ -634,8 +633,7 @@ class ChannelDefinitionBox(Jp2kBox):
|
||||||
"""
|
"""
|
||||||
self._validate(writing=True)
|
self._validate(writing=True)
|
||||||
num_components = len(self.association)
|
num_components = len(self.association)
|
||||||
fptr.write(struct.pack('>I', 8 + 2 + num_components * 6))
|
fptr.write(struct.pack('>I4s', 8 + 2 + num_components * 6, b'cdef'))
|
||||||
fptr.write(b'cdef')
|
|
||||||
fptr.write(struct.pack('>H', num_components))
|
fptr.write(struct.pack('>H', num_components))
|
||||||
for j in range(num_components):
|
for j in range(num_components):
|
||||||
fptr.write(struct.pack('>' + 'H' * 3,
|
fptr.write(struct.pack('>' + 'H' * 3,
|
||||||
|
|
@ -1076,8 +1074,7 @@ class DataReferenceBox(Jp2kBox):
|
||||||
|
|
||||||
# Very similar to the say a superbox is written.
|
# Very similar to the say a superbox is written.
|
||||||
orig_pos = fptr.tell()
|
orig_pos = fptr.tell()
|
||||||
fptr.write(struct.pack('>I', 0))
|
fptr.write(struct.pack('>I4s', 0, b'dtbl'))
|
||||||
fptr.write(b'dtbl')
|
|
||||||
|
|
||||||
# Write the number of data entry url boxes.
|
# Write the number of data entry url boxes.
|
||||||
write_buffer = struct.pack('>H', len(self.DR))
|
write_buffer = struct.pack('>H', len(self.DR))
|
||||||
|
|
@ -1212,8 +1209,7 @@ class FileTypeBox(Jp2kBox):
|
||||||
"""
|
"""
|
||||||
self._validate(writing=True)
|
self._validate(writing=True)
|
||||||
length = 16 + 4*len(self.compatibility_list)
|
length = 16 + 4*len(self.compatibility_list)
|
||||||
fptr.write(struct.pack('>I', length))
|
fptr.write(struct.pack('>I4s', length, b'ftyp'))
|
||||||
fptr.write(b'ftyp')
|
|
||||||
fptr.write(self.brand.encode())
|
fptr.write(self.brand.encode())
|
||||||
fptr.write(struct.pack('>I', self.minor_version))
|
fptr.write(struct.pack('>I', self.minor_version))
|
||||||
|
|
||||||
|
|
@ -1252,8 +1248,6 @@ class FileTypeBox(Jp2kBox):
|
||||||
entry = entry.decode('utf-8')
|
entry = entry.decode('utf-8')
|
||||||
compatibility_list.append(entry)
|
compatibility_list.append(entry)
|
||||||
|
|
||||||
compatibility_list = compatibility_list
|
|
||||||
|
|
||||||
return cls(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)
|
||||||
|
|
@ -1322,8 +1316,7 @@ class FragmentListBox(Jp2kBox):
|
||||||
self._validate(writing=True)
|
self._validate(writing=True)
|
||||||
num_items = len(self.fragment_offset)
|
num_items = len(self.fragment_offset)
|
||||||
length = 8 + 2 + num_items * 14
|
length = 8 + 2 + num_items * 14
|
||||||
fptr.write(struct.pack('>I', length))
|
fptr.write(struct.pack('>I4s', length, b'flst'))
|
||||||
fptr.write(b'flst')
|
|
||||||
fptr.write(struct.pack('>H', num_items))
|
fptr.write(struct.pack('>H', num_items))
|
||||||
for j in range(num_items):
|
for j in range(num_items):
|
||||||
write_buffer = struct.pack('>QIH',
|
write_buffer = struct.pack('>QIH',
|
||||||
|
|
@ -1570,8 +1563,7 @@ class ImageHeaderBox(Jp2kBox):
|
||||||
def write(self, fptr):
|
def write(self, fptr):
|
||||||
"""Write an Image Header box to file.
|
"""Write an Image Header box to file.
|
||||||
"""
|
"""
|
||||||
fptr.write(struct.pack('>I', 22))
|
fptr.write(struct.pack('>I4s', 22, b'ihdr'))
|
||||||
fptr.write(b'ihdr')
|
|
||||||
|
|
||||||
# signedness and bps are stored together in a single byte
|
# signedness and bps are stored together in a single byte
|
||||||
bit_depth_signedness = 0x80 if self.signed else 0x00
|
bit_depth_signedness = 0x80 if self.signed else 0x00
|
||||||
|
|
@ -1784,8 +1776,7 @@ class JPEG2000SignatureBox(Jp2kBox):
|
||||||
def write(self, fptr):
|
def write(self, fptr):
|
||||||
"""Write a JPEG 2000 Signature box to file.
|
"""Write a JPEG 2000 Signature box to file.
|
||||||
"""
|
"""
|
||||||
fptr.write(struct.pack('>I', 12))
|
fptr.write(struct.pack('>I4s', 12, b'jP '))
|
||||||
fptr.write(b'jP ')
|
|
||||||
fptr.write(struct.pack('>BBBB', *self.signature))
|
fptr.write(struct.pack('>BBBB', *self.signature))
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
@ -2533,8 +2524,7 @@ class LabelBox(Jp2kBox):
|
||||||
"""Write a Label box to file.
|
"""Write a Label box to file.
|
||||||
"""
|
"""
|
||||||
length = 8 + len(self.label.encode())
|
length = 8 + len(self.label.encode())
|
||||||
fptr.write(struct.pack('>I', length))
|
fptr.write(struct.pack('>I4s', length, b'lbl '))
|
||||||
fptr.write(b'lbl ')
|
|
||||||
fptr.write(self.label.encode())
|
fptr.write(self.label.encode())
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
@ -2634,8 +2624,7 @@ class NumberListBox(Jp2kBox):
|
||||||
def write(self, fptr):
|
def write(self, fptr):
|
||||||
"""Write a NumberList box to file.
|
"""Write a NumberList box to file.
|
||||||
"""
|
"""
|
||||||
fptr.write(struct.pack('>I', len(self.associations) * 4 + 8))
|
fptr.write(struct.pack('>I4s', len(self.associations) * 4 + 8, b'nlst'))
|
||||||
fptr.write(b'nlst')
|
|
||||||
|
|
||||||
fmt = '>' + 'I' * len(self.associations)
|
fmt = '>' + 'I' * len(self.associations)
|
||||||
write_buffer = struct.pack(fmt, *self.associations)
|
write_buffer = struct.pack(fmt, *self.associations)
|
||||||
|
|
@ -2708,8 +2697,7 @@ class XMLBox(Jp2kBox):
|
||||||
# AssertionError on 2.6
|
# AssertionError on 2.6
|
||||||
read_buffer = ET.tostring(self.xml.getroot(), encoding='utf-8')
|
read_buffer = ET.tostring(self.xml.getroot(), encoding='utf-8')
|
||||||
|
|
||||||
fptr.write(struct.pack('>I', len(read_buffer) + 8))
|
fptr.write(struct.pack('>I4s', len(read_buffer) + 8, b'xml '))
|
||||||
fptr.write(b'xml ')
|
|
||||||
fptr.write(read_buffer)
|
fptr.write(read_buffer)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue