Closes #60
This commit is contained in:
parent
b095ad9720
commit
046b86d0ed
2 changed files with 26 additions and 0 deletions
|
|
@ -440,6 +440,12 @@ class Jp2k(Jp2kBox):
|
||||||
msg = "The codestream box must be preceeded by a jp2 header box."
|
msg = "The codestream box must be preceeded by a jp2 header box."
|
||||||
raise IOError(msg)
|
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:
|
with open(filename, 'wb') as ofile:
|
||||||
for box in boxes:
|
for box in boxes:
|
||||||
if box.id != 'jp2c':
|
if box.id != 'jp2c':
|
||||||
|
|
|
||||||
|
|
@ -266,6 +266,26 @@ 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_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__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue