Added default ImageHeaderBox case.

This commit is contained in:
John Evans 2013-06-22 07:48:44 -04:00
commit dd1c20480c
2 changed files with 54 additions and 21 deletions

View file

@ -684,30 +684,47 @@ class ImageHeaderBox(Jp2kBox):
Bits per component. Bits per component.
signed : bool signed : bool
False if the image components are unsigned. False if the image components are unsigned.
compression : nt compression : int
The compression type, should be 7 if JP2. The compression type, should be 7 if JP2.
cspace_unknown : int cspace_unknown : bool
0 if the color space is known and correctly specified. false if the color space is known and correctly specified.
ip_provided : int ip_provided : bool
0 if the file does not contain intellectual propery rights information. false if the file does not contain intellectual propery rights information.
""" """
def __init__(self, **kwargs): def __init__(self, *pargs, **kwargs):
Jp2kBox.__init__(self, id='', longname='Image Header') """
Examples
--------
>>> import glymur
>>> box = glymur.jp2box.ImageHeaderBox([512, 256, 3])
"""
Jp2kBox.__init__(self, id='ihdr', longname='Image Header')
self.__dict__.update(**kwargs) self.__dict__.update(**kwargs)
if len(pargs) == 1:
self.height = pargs[0][0]
self.width = pargs[0][1]
self.num_components = pargs[0][2]
self.bits_per_component = 8
self.signed = False
self.compression = 7
self.cspace_unknown = False
self.ip_provided = False
def __str__(self): def __str__(self):
lst = [Jp2kBox.__str__(self)] msg = Jp2kBox.__str__(self)
lst.append('Size: [{0} {1} {2}]'.format(self.height, self.width, msg = "{0}"
self.num_components)) msg += '\n Size: [{1} {2} {3}]'
lst.append('Bitdepth: {0}'.format(self.bits_per_component)) msg += '\n Bitdepth: {4}'
lst.append('Signed: {0}'.format(self.signed)) msg += '\n Signed: {5}'
if self.compression == 7: msg += '\n Compression: {6}'
lst.append('Compression: wavelet') msg += '\n Colorspace Unknown: {7}'
if self.cspace_unknown: msg = msg.format(Jp2kBox.__str__(self),
lst.append('Colorspace Unknown: True') self.height, self.width, self.num_components,
else: self.bits_per_component,
lst.append('Colorspace Unknown: False') self.signed,
return '\n '.join(lst) 'wavelet' if self.compression == 7 else 'unknown',
self.cspace_unknown)
return msg
@staticmethod @staticmethod
def _parse(f, id, offset, length): def _parse(f, id, offset, length):
@ -741,8 +758,8 @@ class ImageHeaderBox(Jp2kBox):
kwargs['bits_per_component'] = (params[3] & 0x7f) + 1 kwargs['bits_per_component'] = (params[3] & 0x7f) + 1
kwargs['signed'] = (params[3] & 0x80) > 1 kwargs['signed'] = (params[3] & 0x80) > 1
kwargs['compression'] = params[4] kwargs['compression'] = params[4]
kwargs['cspace_unknown'] = params[5] kwargs['cspace_unknown'] = True if params[5] else False
kwargs['ip_provided'] = params[6] kwargs['ip_provided'] = True if params[6] else False
box = ImageHeaderBox(**kwargs) box = ImageHeaderBox(**kwargs)
return box return box

View file

@ -1,3 +1,4 @@
import doctest
import unittest import unittest
import numpy as np import numpy as np
@ -5,6 +6,11 @@ import pkg_resources
import glymur import glymur
# Doc tests should be run as well.
def load_tests(loader, tests, ignore):
tests.addTests(doctest.DocTestSuite('glymur.jp2box'))
return tests
@unittest.skipIf(glymur.lib.openjp2._OPENJP2 is None, @unittest.skipIf(glymur.lib.openjp2._OPENJP2 is None,
"Missing openjp2 library.") "Missing openjp2 library.")
class TestJp2Boxes(unittest.TestCase): class TestJp2Boxes(unittest.TestCase):
@ -28,6 +34,16 @@ class TestJp2Boxes(unittest.TestCase):
self.assertEqual(b.minor_version, 0) self.assertEqual(b.minor_version, 0)
self.assertEqual(b.compatibility_box, ['jp2 ']) self.assertEqual(b.compatibility_box, ['jp2 '])
def test_default_ImageHeaderBox(self):
# Should be able to instantiate an image header box.
b = glymur.jp2box.ImageHeaderBox([512, 256, 3])
self.assertEqual(b.height, 512)
self.assertEqual(b.width, 256)
self.assertEqual(b.num_components, 3)
self.assertEqual(b.bits_per_component, 8)
self.assertFalse(b.signed)
self.assertFalse(b.cspace_unknown)
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()