Added negative test for writing with bad approximation. #202
This commit is contained in:
parent
d96d1ff150
commit
96cb70e5a5
2 changed files with 26 additions and 0 deletions
|
|
@ -1250,6 +1250,7 @@ def _validate_jp2_box_sequence(boxes):
|
|||
if boxes[1].brand == 'jpx ':
|
||||
_validate_jpx_box_sequence(boxes)
|
||||
else:
|
||||
# Validate the JP2 box IDs.
|
||||
count = _collect_box_count(boxes)
|
||||
for box_id in count.keys():
|
||||
if box_id not in JP2_IDS:
|
||||
|
|
@ -1257,6 +1258,19 @@ def _validate_jp2_box_sequence(boxes):
|
|||
msg += "brand be set to 'jpx '."
|
||||
raise IOError(msg.format(box_id))
|
||||
|
||||
_validate_jp2_colr(boxes)
|
||||
|
||||
def _validate_jp2_colr(boxes):
|
||||
"""
|
||||
Validate JP2 requirements on colour specification boxes.
|
||||
"""
|
||||
lst = [box for box in boxes if box.box_id == 'jp2h']
|
||||
jp2h = lst[0]
|
||||
for colr in [box for box in jp2h.box if box.box_id == 'colr']:
|
||||
if colr.approximation != 0:
|
||||
msg = "A JP2 colr box cannot have a non-zero approximation field."
|
||||
raise IOError(msg)
|
||||
|
||||
def _validate_jpx_box_sequence(boxes):
|
||||
"""Run through series of tests for JPX box legality."""
|
||||
_validate_label(boxes)
|
||||
|
|
|
|||
|
|
@ -453,6 +453,18 @@ class TestColourSpecificationBox(unittest.TestCase):
|
|||
with self.assertRaises(IOError):
|
||||
j2k.wrap(tfile.name, boxes=boxes)
|
||||
|
||||
@unittest.skipIf(os.name == "nt", "Temporary file issue on window.")
|
||||
def test_bad_approx_jp2_field(self):
|
||||
"""JP2 has requirements for approx field"""
|
||||
j2k = Jp2k(self.j2kfile)
|
||||
boxes = [self.jp2b, self.ftyp, self.jp2h, self.jp2c]
|
||||
colr = ColourSpecificationBox(colorspace=glymur.core.SRGB,
|
||||
approximation=1)
|
||||
boxes[2].box = [self.ihdr, colr]
|
||||
with tempfile.NamedTemporaryFile(suffix=".jp2") as tfile:
|
||||
with self.assertRaises(IOError):
|
||||
j2k.wrap(tfile.name, boxes=boxes)
|
||||
|
||||
def test_default_colr(self):
|
||||
"""basic colr instantiation"""
|
||||
colr = ColourSpecificationBox(colorspace=glymur.core.SRGB)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue