pep8 work.

This commit is contained in:
John Evans 2013-06-27 16:35:55 -04:00
commit 62e7afa118
5 changed files with 25 additions and 18 deletions

View file

@ -119,7 +119,6 @@ and add it after the JP2 header box, but before the codestream box ::
. (truncated) . (truncated)
. .
Work with XMP UUIDs? Work with XMP UUIDs?
==================== ====================
The example JP2 file shipped with glymur has an XMP UUID. :: The example JP2 file shipped with glymur has an XMP UUID. ::

View file

@ -20,6 +20,7 @@ def nemo():
file = pkg_resources.resource_filename(__name__, "nemo.jp2") file = pkg_resources.resource_filename(__name__, "nemo.jp2")
return file return file
def goodstuff(): def goodstuff():
"""Shortcut for specifying path to goodstuff.j2k. """Shortcut for specifying path to goodstuff.j2k.

View file

@ -216,7 +216,7 @@ class ColourSpecificationBox(Jp2kBox):
msg += "colorspaces is not supported at this time." msg += "colorspaces is not supported at this time."
raise NotImplementedError(msg) raise NotImplementedError(msg)
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)
f.write(struct.pack('>I', length)) f.write(struct.pack('>I', length))
f.write('colr'.encode()) f.write('colr'.encode())
buffer = struct.pack('>BBBI', buffer = struct.pack('>BBBI',
@ -806,12 +806,12 @@ class ImageHeaderBox(Jp2kBox):
def _write(self, f): def _write(self, f):
"""Write an Image Header box to file. """Write an Image Header box to file.
""" """
f.write(struct.pack('>I', 22)) f.write(struct.pack('>I', 22))
f.write('ihdr'.encode()) f.write('ihdr'.encode())
# 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
bit_depth_signedness |= self.bits_per_component - 1 bit_depth_signedness |= self.bits_per_component - 1
buffer = struct.pack('>IIHBBBB', buffer = struct.pack('>IIHBBBB',
self.height, self.height,
self.width, self.width,
@ -960,7 +960,7 @@ class JP2HeaderBox(Jp2kBox):
""" """
# Write the contained boxes, then come back and write the length. # Write the contained boxes, then come back and write the length.
orig_pos = f.tell() orig_pos = f.tell()
f.write(struct.pack('>I', 0)) f.write(struct.pack('>I', 0))
f.write('jp2h'.encode()) f.write('jp2h'.encode())
for box in self.box: for box in self.box:
box._write(f) box._write(f)

View file

@ -27,12 +27,12 @@ class TestChannelDefinition(unittest.TestCase):
# Write the first component back out to file. # Write the first component back out to file.
with tempfile.NamedTemporaryFile(suffix=".j2k", delete=False) as tfile: with tempfile.NamedTemporaryFile(suffix=".j2k", delete=False) as tfile:
grey_j2k = Jp2k(tfile.name, 'wb') grey_j2k = Jp2k(tfile.name, 'wb')
grey_j2k.write(data[:,:,0]) grey_j2k.write(data[:, :, 0])
cls.one_plane = tfile.name cls.one_plane = tfile.name
# Write the first two components back out to file. # Write the first two components back out to file.
with tempfile.NamedTemporaryFile(suffix=".j2k", delete=False) as tfile: with tempfile.NamedTemporaryFile(suffix=".j2k", delete=False) as tfile:
grey_j2k = Jp2k(tfile.name, 'wb') grey_j2k = Jp2k(tfile.name, 'wb')
grey_j2k.write(data[:,:,0:1]) grey_j2k.write(data[:, :, 0:1])
cls.two_planes = tfile.name cls.two_planes = tfile.name
# Write four components back out to file. # Write four components back out to file.
with tempfile.NamedTemporaryFile(suffix=".j2k", delete=False) as tfile: with tempfile.NamedTemporaryFile(suffix=".j2k", delete=False) as tfile:
@ -58,13 +58,13 @@ class TestChannelDefinition(unittest.TestCase):
height = c.segment[1].Ysiz height = c.segment[1].Ysiz
width = c.segment[1].Xsiz width = c.segment[1].Xsiz
num_components = len(c.segment[1].XRsiz) num_components = len(c.segment[1].XRsiz)
self.jP = JPEG2000SignatureBox() self.jP = JPEG2000SignatureBox()
self.ftyp = FileTypeBox() self.ftyp = FileTypeBox()
self.jp2h = JP2HeaderBox() self.jp2h = JP2HeaderBox()
self.jp2c = ContiguousCodestreamBox() self.jp2c = ContiguousCodestreamBox()
self.ihdr = ImageHeaderBox(height=height, width=width, self.ihdr = ImageHeaderBox(height=height, width=width,
num_components=num_components) num_components=num_components)
self.colr_rgb = ColourSpecificationBox(colorspace=glymur.core.SRGB) self.colr_rgb = ColourSpecificationBox(colorspace=glymur.core.SRGB)
self.colr_gr = ColourSpecificationBox(colorspace=glymur.core.GREYSCALE) self.colr_gr = ColourSpecificationBox(colorspace=glymur.core.GREYSCALE)
@ -168,7 +168,7 @@ class TestChannelDefinition(unittest.TestCase):
"""A greyscale image with alpha layer must specify Y""" """A greyscale image with alpha layer must specify Y"""
j2k = Jp2k(self.two_planes) j2k = Jp2k(self.two_planes)
# This cdef box # This cdef box
cdef = glymur.jp2box.ChannelDefinitionBox(index=[0, 1], cdef = glymur.jp2box.ChannelDefinitionBox(index=[0, 1],
channel_type=[1, 1], channel_type=[1, 1],
association=[0, 1]) association=[0, 1])
@ -228,6 +228,7 @@ class TestChannelDefinition(unittest.TestCase):
channel_type=[0, 0], channel_type=[0, 0],
association=[1, 2, 3]) association=[1, 2, 3])
class TestXML(unittest.TestCase): class TestXML(unittest.TestCase):
def setUp(self): def setUp(self):
@ -258,7 +259,7 @@ class TestXML(unittest.TestCase):
</country> </country>
</data>""" </data>"""
with tempfile.NamedTemporaryFile(suffix=".xml", delete=False) as tfile: with tempfile.NamedTemporaryFile(suffix=".xml", delete=False) as tfile:
tfile.write(raw_xml) tfile.write(raw_xml)
tfile.flush() tfile.flush()
self.xmlfile = tfile.name self.xmlfile = tfile.name
@ -267,13 +268,13 @@ class TestXML(unittest.TestCase):
height = c.segment[1].Ysiz height = c.segment[1].Ysiz
width = c.segment[1].Xsiz width = c.segment[1].Xsiz
num_components = len(c.segment[1].XRsiz) num_components = len(c.segment[1].XRsiz)
self.jP = JPEG2000SignatureBox() self.jP = JPEG2000SignatureBox()
self.ftyp = FileTypeBox() self.ftyp = FileTypeBox()
self.jp2h = JP2HeaderBox() self.jp2h = JP2HeaderBox()
self.jp2c = ContiguousCodestreamBox() self.jp2c = ContiguousCodestreamBox()
self.ihdr = ImageHeaderBox(height=height, width=width, self.ihdr = ImageHeaderBox(height=height, width=width,
num_components=num_components) num_components=num_components)
self.colr = ColourSpecificationBox(colorspace=glymur.core.SRGB) self.colr = ColourSpecificationBox(colorspace=glymur.core.SRGB)
def tearDown(self): def tearDown(self):
@ -340,13 +341,13 @@ class TestColourSpecificationBox(unittest.TestCase):
height = c.segment[1].Ysiz height = c.segment[1].Ysiz
width = c.segment[1].Xsiz width = c.segment[1].Xsiz
num_components = len(c.segment[1].XRsiz) num_components = len(c.segment[1].XRsiz)
self.jP = JPEG2000SignatureBox() self.jP = JPEG2000SignatureBox()
self.ftyp = FileTypeBox() self.ftyp = FileTypeBox()
self.jp2h = JP2HeaderBox() self.jp2h = JP2HeaderBox()
self.jp2c = ContiguousCodestreamBox() self.jp2c = ContiguousCodestreamBox()
self.ihdr = ImageHeaderBox(height=height, width=width, self.ihdr = ImageHeaderBox(height=height, width=width,
num_components=num_components) num_components=num_components)
def tearDown(self): def tearDown(self):
pass pass
@ -444,7 +445,7 @@ class TestJp2Boxes(unittest.TestCase):
def verify_wrapped_raw(self, jp2file): def verify_wrapped_raw(self, jp2file):
# Shared method by at least two tests. # Shared method by at least two tests.
jp2 = Jp2k(jp2file) jp2 = Jp2k(jp2file)
self.assertEqual(len(jp2.box), 4) self.assertEqual(len(jp2.box), 4)
self.assertEqual(jp2.box[0].id, 'jP ') self.assertEqual(jp2.box[0].id, 'jP ')
@ -497,6 +498,13 @@ class TestJp2Boxes(unittest.TestCase):
j2k.wrap(tfile.name) j2k.wrap(tfile.name)
self.verify_wrapped_raw(tfile.name) self.verify_wrapped_raw(tfile.name)
def test_wrap_jp2(self):
j2k = Jp2k(self.j2kfile)
with tempfile.NamedTemporaryFile(suffix=".jp2") as tfile:
jp2 = j2k.wrap(tfile.name)
boxes = [box.id for box in jp2.box]
self.assertEqual(boxes, ['jP ', 'ftyp', 'jp2h', 'jp2c'])
def test_default_layout_but_with_specified_boxes(self): def test_default_layout_but_with_specified_boxes(self):
j2k = Jp2k(self.j2kfile) j2k = Jp2k(self.j2kfile)
boxes = [JPEG2000SignatureBox(), boxes = [JPEG2000SignatureBox(),
@ -534,7 +542,6 @@ class TestJp2Boxes(unittest.TestCase):
with self.assertRaises(IOError): with self.assertRaises(IOError):
j2k.wrap(tfile.name, boxes=boxes) j2k.wrap(tfile.name, boxes=boxes)
def test_first_2_boxes_not_jP_and_ftyp(self): def test_first_2_boxes_not_jP_and_ftyp(self):
j2k = Jp2k(self.j2kfile) j2k = Jp2k(self.j2kfile)
c = j2k.get_codestream() c = j2k.get_codestream()

View file

@ -173,7 +173,7 @@ class TestJp2k(unittest.TestCase):
with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile:
ofile = Jp2k(tfile.name, 'wb') ofile = Jp2k(tfile.name, 'wb')
with self.assertRaises(IOError): with self.assertRaises(IOError):
ofile.write(expdata[:,:,0], mct=True) ofile.write(expdata[:, :, 0], mct=True)
def test_write_cprl(self): def test_write_cprl(self):
# Issue 17 # Issue 17