Closes #59
This commit is contained in:
parent
046b86d0ed
commit
47f42fdb88
3 changed files with 29 additions and 1 deletions
|
|
@ -168,7 +168,7 @@ class ColourSpecificationBox(Jp2kBox):
|
|||
"""
|
||||
def __init__(self, method=ENUMERATED_COLORSPACE, precedence=0,
|
||||
approximation=0, colorspace=None, icc_profile=None, **kwargs):
|
||||
Jp2kBox.__init__(self, id='', longname='Colour Specification')
|
||||
Jp2kBox.__init__(self, id='colr', longname='Colour Specification')
|
||||
|
||||
if colorspace is not None and icc_profile is not None:
|
||||
raise IOError("colorspace and icc_profile cannot both be set.")
|
||||
|
|
|
|||
|
|
@ -440,12 +440,20 @@ class Jp2k(Jp2kBox):
|
|||
msg = "The codestream box must be preceeded by a jp2 header box."
|
||||
raise IOError(msg)
|
||||
|
||||
# 1st jp2 header box must be ihdr
|
||||
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)
|
||||
|
||||
# colr must be present in jp2 header box.
|
||||
jp2hb = jp2h.box
|
||||
colr_lst = [j for (j, box) in enumerate(jp2h.box) if box.id == 'colr']
|
||||
if len(colr_lst) == 0:
|
||||
msg = "The jp2 header box must contain a color definition box."
|
||||
raise IOError(msg)
|
||||
|
||||
with open(filename, 'wb') as ofile:
|
||||
for box in boxes:
|
||||
if box.id != 'jp2c':
|
||||
|
|
|
|||
|
|
@ -286,6 +286,26 @@ class TestJp2Boxes(unittest.TestCase):
|
|||
with self.assertRaises(IOError):
|
||||
j2k.wrap(tfile.name, boxes=boxes)
|
||||
|
||||
def test_colr_box_not_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 = [ihdr]
|
||||
boxes = [jP, ftyp, jp2h, jp2c, colr]
|
||||
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