diff --git a/glymur/jp2k.py b/glymur/jp2k.py index 4efcb77..319bf46 100644 --- a/glymur/jp2k.py +++ b/glymur/jp2k.py @@ -167,15 +167,16 @@ class Jp2k(Jp2kBox): """ # A jp2-branded file cannot contain an "any ICC profile ftyp = self.box[1] - jp2h = [box for box in self.box if box.box_id == 'jp2h'][0] - colr = [box for box in jp2h.box if box.box_id == 'colr'][0] - if (((ftyp.brand == 'jp2 ') and - (colr.method not in (ENUMERATED_COLORSPACE, - RESTRICTED_ICC_PROFILE)))): - msg = "Color Specification box method must specify either an " - msg += "enumerated colorspace or a restricted ICC profile if the " - msg += "file type box brand is 'jp2 '." - warnings.warn(msg) + if ftyp.brand == 'jp2 ': + jp2h = [box for box in self.box if box.box_id == 'jp2h'][0] + colrs = [box for box in jp2h.box if box.box_id == 'colr'] + for colr in colrs: + if colr.method not in (ENUMERATED_COLORSPACE, + RESTRICTED_ICC_PROFILE): + msg = "Color Specification box method must specify either " + msg += "an enumerated colorspace or a restricted ICC " + msg += "profile if the file type box brand is 'jp2 '." + warnings.warn(msg) # pylint: disable-msg=W0221 diff --git a/glymur/test/test_conformance.py b/glymur/test/test_conformance.py index f9b94e9..ec179c2 100644 --- a/glymur/test/test_conformance.py +++ b/glymur/test/test_conformance.py @@ -26,11 +26,13 @@ except: try: opj_data_root = os.environ['OPJ_DATA_ROOT'] except KeyError: - opj_corpus_data_root = None + opj_data_root = None except: raise +@unittest.skipIf(format_corpus_data_root is None, + "FORMAT_CORPUS_DATA_ROOT environment variable not set") @unittest.skipIf(sys.hexversion < 0x03020000, "Requires features introduced in 3.2 (assertWarns)") class TestSuiteFormatCorpus(unittest.TestCase): @@ -41,8 +43,6 @@ class TestSuiteFormatCorpus(unittest.TestCase): def tearDown(self): pass - @unittest.skipIf(format_corpus_data_root is None, - "FORMAT_CORPUS_DATA_ROOT environment variable not set") def test_balloon_trunc1(self): # Has one byte shaved off of EOC marker. jfile = os.path.join(format_corpus_data_root, @@ -58,8 +58,6 @@ class TestSuiteFormatCorpus(unittest.TestCase): with self.assertRaises(OSError): 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): # Shortened by 5000 bytes. jfile = os.path.join(format_corpus_data_root, @@ -75,8 +73,6 @@ class TestSuiteFormatCorpus(unittest.TestCase): with self.assertRaises(OSError): 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): # Most of last tile is missing. jfile = os.path.join(format_corpus_data_root, @@ -92,8 +88,6 @@ class TestSuiteFormatCorpus(unittest.TestCase): #with self.assertRaises(OSError): # 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): # If 'jp2 ', then the method cannot be any icc profile. jfile = os.path.join(format_corpus_data_root, @@ -102,7 +96,22 @@ class TestSuiteFormatCorpus(unittest.TestCase): with self.assertWarns(UserWarning): 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, "Requires features introduced in 3.2 (assertWarns)") class TestSuiteOpj(unittest.TestCase): @@ -113,8 +122,6 @@ class TestSuiteOpj(unittest.TestCase): def tearDown(self): pass - @unittest.skipIf(opj_data_root is None, - "OPJ_DATA_ROOT environment variable not set") def test_jp2_brand_vs_any_icc_profile(self): # If 'jp2 ', then the method cannot be any icc profile. filename = os.path.join(opj_data_root,