Validation check now allows for multiple colr boxes. Closes #77
jp2h superboxes can contain multiple colr boxes, so we need to check each one for validity.
This commit is contained in:
parent
097549fd66
commit
ee2b3b9c0e
2 changed files with 28 additions and 20 deletions
|
|
@ -167,15 +167,16 @@ class Jp2k(Jp2kBox):
|
||||||
"""
|
"""
|
||||||
# A jp2-branded file cannot contain an "any ICC profile
|
# A jp2-branded file cannot contain an "any ICC profile
|
||||||
ftyp = self.box[1]
|
ftyp = self.box[1]
|
||||||
jp2h = [box for box in self.box if box.box_id == 'jp2h'][0]
|
if ftyp.brand == 'jp2 ':
|
||||||
colr = [box for box in jp2h.box if box.box_id == 'colr'][0]
|
jp2h = [box for box in self.box if box.box_id == 'jp2h'][0]
|
||||||
if (((ftyp.brand == 'jp2 ') and
|
colrs = [box for box in jp2h.box if box.box_id == 'colr']
|
||||||
(colr.method not in (ENUMERATED_COLORSPACE,
|
for colr in colrs:
|
||||||
RESTRICTED_ICC_PROFILE)))):
|
if colr.method not in (ENUMERATED_COLORSPACE,
|
||||||
msg = "Color Specification box method must specify either an "
|
RESTRICTED_ICC_PROFILE):
|
||||||
msg += "enumerated colorspace or a restricted ICC profile if the "
|
msg = "Color Specification box method must specify either "
|
||||||
msg += "file type box brand is 'jp2 '."
|
msg += "an enumerated colorspace or a restricted ICC "
|
||||||
warnings.warn(msg)
|
msg += "profile if the file type box brand is 'jp2 '."
|
||||||
|
warnings.warn(msg)
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable-msg=W0221
|
# pylint: disable-msg=W0221
|
||||||
|
|
|
||||||
|
|
@ -26,11 +26,13 @@ except:
|
||||||
try:
|
try:
|
||||||
opj_data_root = os.environ['OPJ_DATA_ROOT']
|
opj_data_root = os.environ['OPJ_DATA_ROOT']
|
||||||
except KeyError:
|
except KeyError:
|
||||||
opj_corpus_data_root = None
|
opj_data_root = None
|
||||||
except:
|
except:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
|
@unittest.skipIf(format_corpus_data_root is None,
|
||||||
|
"FORMAT_CORPUS_DATA_ROOT environment variable not set")
|
||||||
@unittest.skipIf(sys.hexversion < 0x03020000,
|
@unittest.skipIf(sys.hexversion < 0x03020000,
|
||||||
"Requires features introduced in 3.2 (assertWarns)")
|
"Requires features introduced in 3.2 (assertWarns)")
|
||||||
class TestSuiteFormatCorpus(unittest.TestCase):
|
class TestSuiteFormatCorpus(unittest.TestCase):
|
||||||
|
|
@ -41,8 +43,6 @@ class TestSuiteFormatCorpus(unittest.TestCase):
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@unittest.skipIf(format_corpus_data_root is None,
|
|
||||||
"FORMAT_CORPUS_DATA_ROOT environment variable not set")
|
|
||||||
def test_balloon_trunc1(self):
|
def test_balloon_trunc1(self):
|
||||||
# Has one byte shaved off of EOC marker.
|
# Has one byte shaved off of EOC marker.
|
||||||
jfile = os.path.join(format_corpus_data_root,
|
jfile = os.path.join(format_corpus_data_root,
|
||||||
|
|
@ -58,8 +58,6 @@ class TestSuiteFormatCorpus(unittest.TestCase):
|
||||||
with self.assertRaises(OSError):
|
with self.assertRaises(OSError):
|
||||||
j2k.read(rlevel=-1)
|
j2k.read(rlevel=-1)
|
||||||
|
|
||||||
@unittest.skipIf(format_corpus_data_root is None,
|
|
||||||
"FORMAT_CORPUS_DATA_ROOT environment variable not set")
|
|
||||||
def test_balloon_trunc2(self):
|
def test_balloon_trunc2(self):
|
||||||
# Shortened by 5000 bytes.
|
# Shortened by 5000 bytes.
|
||||||
jfile = os.path.join(format_corpus_data_root,
|
jfile = os.path.join(format_corpus_data_root,
|
||||||
|
|
@ -75,8 +73,6 @@ class TestSuiteFormatCorpus(unittest.TestCase):
|
||||||
with self.assertRaises(OSError):
|
with self.assertRaises(OSError):
|
||||||
j2k.read(rlevel=-1)
|
j2k.read(rlevel=-1)
|
||||||
|
|
||||||
@unittest.skipIf(format_corpus_data_root is None,
|
|
||||||
"FORMAT_CORPUS_DATA_ROOT environment variable not set")
|
|
||||||
def test_balloon_trunc3(self):
|
def test_balloon_trunc3(self):
|
||||||
# Most of last tile is missing.
|
# Most of last tile is missing.
|
||||||
jfile = os.path.join(format_corpus_data_root,
|
jfile = os.path.join(format_corpus_data_root,
|
||||||
|
|
@ -92,8 +88,6 @@ class TestSuiteFormatCorpus(unittest.TestCase):
|
||||||
#with self.assertRaises(OSError):
|
#with self.assertRaises(OSError):
|
||||||
# j2k.read(rlevel=-1)
|
# j2k.read(rlevel=-1)
|
||||||
|
|
||||||
@unittest.skipIf(format_corpus_data_root is None,
|
|
||||||
"FORMAT_CORPUS_DATA_ROOT environment variable not set")
|
|
||||||
def test_jp2_brand_vs_any_icc_profile(self):
|
def test_jp2_brand_vs_any_icc_profile(self):
|
||||||
# If 'jp2 ', then the method cannot be any icc profile.
|
# If 'jp2 ', then the method cannot be any icc profile.
|
||||||
jfile = os.path.join(format_corpus_data_root,
|
jfile = os.path.join(format_corpus_data_root,
|
||||||
|
|
@ -102,7 +96,22 @@ class TestSuiteFormatCorpus(unittest.TestCase):
|
||||||
with self.assertWarns(UserWarning):
|
with self.assertWarns(UserWarning):
|
||||||
j2k = Jp2k(jfile)
|
j2k = Jp2k(jfile)
|
||||||
|
|
||||||
|
def test_jp2_brand_vs_any_icc_profile_multiple_colr(self):
|
||||||
|
# Has colr box, one that conforms, one that does not.
|
||||||
|
|
||||||
|
# Wrong 'brand' field; contains two versions of ICC profile: one
|
||||||
|
# embedded using "Any ICC" method; other embedded using "Restricted
|
||||||
|
# ICC" method, with description ("Modified eciRGB v2") and profileClass
|
||||||
|
# ("Input Device") changed relative to original profile.
|
||||||
|
lst = [format_corpus_data_root, 'jp2k-test', 'icc',
|
||||||
|
'balloon_eciRGBv2_ps_adobeplugin_jp2compatible.jpf']
|
||||||
|
jfile = os.path.join(*lst)
|
||||||
|
with self.assertWarns(UserWarning):
|
||||||
|
j2k = Jp2k(jfile)
|
||||||
|
|
||||||
|
|
||||||
|
@unittest.skipIf(opj_data_root is None,
|
||||||
|
"OPJ_DATA_ROOT environment variable not set")
|
||||||
@unittest.skipIf(sys.hexversion < 0x03020000,
|
@unittest.skipIf(sys.hexversion < 0x03020000,
|
||||||
"Requires features introduced in 3.2 (assertWarns)")
|
"Requires features introduced in 3.2 (assertWarns)")
|
||||||
class TestSuiteOpj(unittest.TestCase):
|
class TestSuiteOpj(unittest.TestCase):
|
||||||
|
|
@ -113,8 +122,6 @@ class TestSuiteOpj(unittest.TestCase):
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@unittest.skipIf(opj_data_root is None,
|
|
||||||
"OPJ_DATA_ROOT environment variable not set")
|
|
||||||
def test_jp2_brand_vs_any_icc_profile(self):
|
def test_jp2_brand_vs_any_icc_profile(self):
|
||||||
# If 'jp2 ', then the method cannot be any icc profile.
|
# If 'jp2 ', then the method cannot be any icc profile.
|
||||||
filename = os.path.join(opj_data_root,
|
filename = os.path.join(opj_data_root,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue