This commit is contained in:
jevans 2013-06-24 19:16:03 -04:00
commit 046b86d0ed
2 changed files with 26 additions and 0 deletions

View file

@ -440,6 +440,12 @@ class Jp2k(Jp2kBox):
msg = "The codestream box must be preceeded by a jp2 header box."
raise IOError(msg)
jp2h = boxes[jp2h_idx]
if jp2h.box[0].id != 'ihdr':
msg = "The first box in the jp2 header box must be the image "
msg += "header box."
raise IOError(msg)
with open(filename, 'wb') as ofile:
for box in boxes:
if box.id != 'jp2c':

View file

@ -266,6 +266,26 @@ class TestJp2Boxes(unittest.TestCase):
with self.assertRaises(IOError):
j2k.wrap(tfile.name, boxes=boxes)
def test_ihdr_not_first_in_jp2h(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 = [colr, ihdr]
boxes = [jP, ftyp, jp2h, jp2c]
with tempfile.NamedTemporaryFile(suffix=".jp2") as tfile:
with self.assertRaises(IOError):
j2k.wrap(tfile.name, boxes=boxes)
if __name__ == "__main__":
unittest.main()