Closes #62
This commit is contained in:
parent
2ca9c14724
commit
90c027e5ca
2 changed files with 29 additions and 0 deletions
|
|
@ -431,6 +431,15 @@ class Jp2k(Jp2kBox):
|
|||
msg += "must be the file type box."
|
||||
raise IOError(msg)
|
||||
|
||||
# jp2c must be preceeded by jp2h
|
||||
jp2h_lst = [idx for (idx, box) in enumerate(boxes) if box.id == 'jp2h']
|
||||
jp2h_idx = jp2h_lst[0]
|
||||
jp2c_lst = [idx for (idx, box) in enumerate(boxes) if box.id == 'jp2c']
|
||||
jp2c_idx = jp2c_lst[0]
|
||||
if jp2h_idx >= jp2c_idx:
|
||||
msg = "The codestream box must be preceeded by a jp2 header box."
|
||||
raise IOError(msg)
|
||||
|
||||
with open(filename, 'wb') as ofile:
|
||||
for box in boxes:
|
||||
if box.id != 'jp2c':
|
||||
|
|
|
|||
|
|
@ -289,6 +289,26 @@ class TestJp2Boxes(unittest.TestCase):
|
|||
with self.assertRaises(IOError):
|
||||
j2k.wrap(tfile.name, boxes=boxes)
|
||||
|
||||
def test_jp2h_not_preceeding_jp2c(self):
|
||||
j2k = Jp2k(self.raw_codestream)
|
||||
c = j2k.get_codestream()
|
||||
height = c.segment[1].Ysiz
|
||||
width = c.segment[1].Xsiz
|
||||
num_components = len(c.segment[1].XRsiz)
|
||||
|
||||
jP = JPEG2000SignatureBox()
|
||||
ftyp = FileTypeBox()
|
||||
jp2h = JP2HeaderBox()
|
||||
jp2c = ContiguousCodestreamBox()
|
||||
colr = ColourSpecificationBox(colorspace=glymur.core.SRGB)
|
||||
ihdr = ImageHeaderBox(height=height, width=width,
|
||||
num_components=num_components)
|
||||
jp2h.box = [ihdr, colr]
|
||||
boxes = [jP, ftyp, jp2c, jp2h]
|
||||
with tempfile.NamedTemporaryFile(suffix=".jp2") as tfile:
|
||||
#with self.assertRaises(IOError):
|
||||
j2k.wrap(tfile.name, boxes=boxes)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue