boxes all done, codestream printing is broken though

This commit is contained in:
jevans 2015-01-29 20:38:00 -05:00
commit 7ac25f2935
2 changed files with 104 additions and 65 deletions

View file

@ -2577,13 +2577,21 @@ class CaptureResolutionBox(Jp2kBox):
return msg return msg
def __str__(self): def __str__(self):
msg = Jp2kBox.__str__(self) title = Jp2kBox.__str__(self)
if _printoptions['short'] is True: if _printoptions['short'] is True:
return msg return title
msg += '\n VCR: {0}'.format(self.vertical_resolution) lst = []
msg += '\n HCR: {0}'.format(self.horizontal_resolution) text = 'VCR: {0}'.format(self.vertical_resolution)
return msg lst.append(text)
text = 'HCR: {0}'.format(self.horizontal_resolution)
lst.append(text)
text = '\n'.join(lst)
body = self._indent(text)
text = '\n'.join([title, body])
return text
@classmethod @classmethod
def parse(cls, fptr, offset, length): def parse(cls, fptr, offset, length):
@ -2643,13 +2651,21 @@ class DisplayResolutionBox(Jp2kBox):
return msg return msg
def __str__(self): def __str__(self):
msg = Jp2kBox.__str__(self) title = Jp2kBox.__str__(self)
if _printoptions['short'] is True: if _printoptions['short'] is True:
return msg return title
msg += '\n VDR: {0}'.format(self.vertical_resolution) lst = []
msg += '\n HDR: {0}'.format(self.horizontal_resolution) text = 'VDR: {0}'.format(self.vertical_resolution)
return msg lst.append(text)
text = 'HDR: {0}'.format(self.horizontal_resolution)
lst.append(text)
text = '\n'.join(lst)
body = self._indent(text)
text = '\n'.join([title, body])
return text
@classmethod @classmethod
def parse(cls, fptr, offset, length): def parse(cls, fptr, offset, length):
@ -2703,12 +2719,15 @@ class LabelBox(Jp2kBox):
self.offset = offset self.offset = offset
def __str__(self): def __str__(self):
msg = Jp2kBox.__str__(self) title = Jp2kBox.__str__(self)
if _printoptions['short'] is True: if _printoptions['short'] is True:
return msg return title
msg += '\n Label: {0}'.format(self.label) text = 'Label: {0}'.format(self.label)
return msg body = self._indent(text)
text = '\n'.join([title, body])
return text
def __repr__(self): def __repr__(self):
msg = 'glymur.jp2box.LabelBox("{0}")'.format(self.label) msg = 'glymur.jp2box.LabelBox("{0}")'.format(self.label)
@ -2771,25 +2790,30 @@ class NumberListBox(Jp2kBox):
self.offset = offset self.offset = offset
def __str__(self): def __str__(self):
msg = Jp2kBox.__str__(self) title = Jp2kBox.__str__(self)
if _printoptions['short'] is True: if _printoptions['short'] is True:
return msg return title
lst = []
for j, association in enumerate(self.associations): for j, association in enumerate(self.associations):
msg += '\n Association[{0}]: '.format(j) text = 'Association[{0}]: '.format(j)
if association == 0: if association == 0:
msg += 'the rendered result' text += 'the rendered result'
elif (association >> 24) == 1: elif (association >> 24) == 1:
idx = association & 0x00FFFFFF idx = association & 0x00FFFFFF
msg += 'codestream {0}' text += 'codestream {0}'.format(idx)
msg = msg.format(idx)
elif (association >> 24) == 2: elif (association >> 24) == 2:
idx = association & 0x00FFFFFF idx = association & 0x00FFFFFF
msg += 'compositing layer {0}' text += 'compositing layer {0}'.format(idx)
msg = msg.format(idx)
else: else:
msg += 'unrecognized' text += 'unrecognized'
return msg lst.append(text)
body = '\n'.join(lst)
body = self._indent(body)
text = '\n'.join([title, body])
return text
def __repr__(self): def __repr__(self):
msg = 'glymur.jp2box.NumberListBox(associations={0})' msg = 'glymur.jp2box.NumberListBox(associations={0})'
@ -2874,21 +2898,22 @@ class XMLBox(Jp2kBox):
return "glymur.jp2box.XMLBox(xml={0})".format(self.xml) return "glymur.jp2box.XMLBox(xml={0})".format(self.xml)
def __str__(self): def __str__(self):
msg = Jp2kBox.__str__(self) title = Jp2kBox.__str__(self)
if _printoptions['short'] is True: if _printoptions['short'] is True:
return msg return title
if _printoptions['xml'] is False: if _printoptions['xml'] is False:
return msg return title
msg += '\n'
if self.xml is not None: if self.xml is not None:
xmlstring = ET.tostring(self.xml, body = ET.tostring(self.xml,
encoding='utf-8', encoding='utf-8',
pretty_print=True).decode('utf-8') pretty_print=True).decode('utf-8')
else: else:
xmlstring = 'None' body = 'None'
msg += self._indent(xmlstring) body = self._indent(body)
return msg
text = '\n'.join([title, body])
return text
def write(self, fptr): def write(self, fptr):
"""Write an XML box to file. """Write an XML box to file.
@ -2995,13 +3020,19 @@ class UUIDListBox(Jp2kBox):
return msg return msg
def __str__(self): def __str__(self):
msg = Jp2kBox.__str__(self) title = Jp2kBox.__str__(self)
if _printoptions['short'] is True: if _printoptions['short'] is True:
return msg return title
lst = []
for j, uuid_item in enumerate(self.ulst): for j, uuid_item in enumerate(self.ulst):
msg += '\n UUID[{0}]: {1}'.format(j, uuid_item) text = 'UUID[{0}]: {1}'.format(j, uuid_item)
return msg lst.append(text)
body = '\n'.join(lst)
body = self._indent(body)
text = '\n'.join([title, body])
return text
@classmethod @classmethod
def parse(cls, fptr, offset, length): def parse(cls, fptr, offset, length):
@ -3147,20 +3178,21 @@ class DataEntryURLBox(Jp2kBox):
return msg return msg
def __str__(self): def __str__(self):
msg = Jp2kBox.__str__(self) title = Jp2kBox.__str__(self)
if _printoptions['short'] is True: if _printoptions['short'] is True:
return msg return title
msg += '\n ' lst = ['Version: {0}',
lines = ['Version: {0}',
'Flag: {1} {2} {3}', 'Flag: {1} {2} {3}',
'URL: "{4}"'] 'URL: "{4}"']
msg += '\n '.join(lines) body = '\n'.join(lst)
msg = msg.format(self.version, body = body.format(self.version,
self.flag[0], self.flag[1], self.flag[2], self.flag[0], self.flag[1], self.flag[2],
self.url) self.url)
return msg body = self._indent(body)
text = '\n'.join([title, body])
return text
@classmethod @classmethod
def parse(cls, fptr, offset, length): def parse(cls, fptr, offset, length):
@ -3299,38 +3331,44 @@ class UUIDBox(Jp2kBox):
return msg.format(repr(self.uuid), len(self.raw_data)) return msg.format(repr(self.uuid), len(self.raw_data))
def __str__(self): def __str__(self):
msg = Jp2kBox.__str__(self) title = Jp2kBox.__str__(self)
if _printoptions['short'] is True: if _printoptions['short'] is True:
return msg return title
msg = '{0}\n UUID: {1}'.format(msg, self.uuid) text = 'UUID: {0}'.format(self.uuid)
if self.uuid == UUID('be7acfcb-97a9-42e8-9c71-999491e3afac'): if self.uuid == UUID('be7acfcb-97a9-42e8-9c71-999491e3afac'):
msg += ' (XMP)' text += ' (XMP)'
elif self.uuid.bytes == b'JpgTiffExif->JP2': elif self.uuid.bytes == b'JpgTiffExif->JP2':
msg += ' (EXIF)' text += ' (EXIF)'
else: else:
msg += ' (unknown)' text += ' (unknown)'
lst = [text]
if (((_printoptions['xml'] is False) and if (((_printoptions['xml'] is False) and
(self.uuid == UUID('be7acfcb-97a9-42e8-9c71-999491e3afac')))): (self.uuid == UUID('be7acfcb-97a9-42e8-9c71-999491e3afac')))):
# If it's an XMP UUID, don't print the XML contents. # If it's an XMP UUID, don't print the XML contents.
return msg pass
if self.uuid == UUID('be7acfcb-97a9-42e8-9c71-999491e3afac'): elif self.uuid == UUID('be7acfcb-97a9-42e8-9c71-999491e3afac'):
line = '\n UUID Data:\n{0}' line = 'UUID Data:\n{0}'
xmlstring = ET.tostring(self.data, xmlstring = ET.tostring(self.data,
encoding='utf-8', encoding='utf-8',
pretty_print=True).decode('utf-8') pretty_print=True).decode('utf-8')
# indent it a bit text = line.format(xmlstring)
xmlstring = self._indent(xmlstring.rstrip()) lst.append(text)
msg += line.format(xmlstring)
elif self.uuid.bytes == b'JpgTiffExif->JP2': elif self.uuid.bytes == b'JpgTiffExif->JP2':
msg += '\n UUID Data: {0}'.format(str(self.data)) text = 'UUID Data: {0}'.format(str(self.data))
lst.append(text)
else: else:
line = '\n UUID Data: {0} bytes' text = 'UUID Data: {0} bytes'.format(len(self.raw_data))
msg += line.format(len(self.raw_data)) lst.append(text)
return msg body = '\n'.join(lst)
body = self._indent(body)
text = '\n'.join([title, body])
return text
def write(self, fptr): def write(self, fptr):
"""Write a UUID box to file. """Write a UUID box to file.

View file

@ -1125,6 +1125,7 @@ class TestJp2dump(unittest.TestCase):
def test_suppress_xml(self): def test_suppress_xml(self):
"""Verify dumping with -x, suppress XML.""" """Verify dumping with -x, suppress XML."""
self.maxDiff = None
actual = self.run_jp2dump(['', '-x', self.jp2file]) actual = self.run_jp2dump(['', '-x', self.jp2file])
# shave off the XML and non-main-header segments # shave off the XML and non-main-header segments