From 77d2ab194a6f1d1b7d486c11b55bbff85a190f70 Mon Sep 17 00:00:00 2001 From: John Evans Date: Wed, 12 Mar 2014 19:21:35 -0400 Subject: [PATCH] Checking for ICC profile that is None. #183 --- glymur/jp2box.py | 15 +++++++++------ glymur/test/fixtures.py | 5 +++++ glymur/test/test_printing.py | 11 +++++++++++ 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/glymur/jp2box.py b/glymur/jp2box.py index a106ee4..c309a26 100644 --- a/glymur/jp2box.py +++ b/glymur/jp2box.py @@ -359,13 +359,16 @@ class ColourSpecificationBox(Jp2kBox): else: # 2.7 has trouble pretty-printing ordered dicts so we just have # to print as a regular dict in this case. - if sys.hexversion < 0x03000000: - icc_profile = dict(self.icc_profile) + if self.icc_profile is None: + msg += '\n ICC Profile: None' else: - icc_profile = self.icc_profile - dispvalue = pprint.pformat(icc_profile) - lines = [' ' * 8 + y for y in dispvalue.split('\n')] - msg += '\n ICC Profile:\n{0}'.format('\n'.join(lines)) + if sys.hexversion < 0x03000000: + icc_profile = dict(self.icc_profile) + else: + icc_profile = self.icc_profile + dispvalue = pprint.pformat(icc_profile) + lines = [' ' * 8 + y for y in dispvalue.split('\n')] + msg += '\n ICC Profile:\n{0}'.format('\n'.join(lines)) return msg diff --git a/glymur/test/fixtures.py b/glymur/test/fixtures.py index 63f5837..b47f211 100644 --- a/glymur/test/fixtures.py +++ b/glymur/test/fixtures.py @@ -582,3 +582,8 @@ issue_182_cmap = """Component Mapping Box (cmap) @ (130, 24) Component 0 ==> palette column 0 Component 1 ==> palette column 0 Component 2 ==> 2""" + +issue_183_colr = """Colour Specification Box (colr) @ (62, 12) + Method: restricted ICC profile + Precedence: 0 + ICC Profile: None""" diff --git a/glymur/test/test_printing.py b/glymur/test/test_printing.py index 3dd58f5..6a819ac 100644 --- a/glymur/test/test_printing.py +++ b/glymur/test/test_printing.py @@ -920,6 +920,17 @@ class TestPrinting(unittest.TestCase): actual = fake_out.getvalue().strip() self.assertEqual(actual, fixtures.issue_182_cmap) + def test_issue183(self): + filename = opj_data_file('input/nonregression/orb-blue10-lin-jp2.jp2') + + with warnings.catch_warnings(): + # Ignore warning about bad pclr box. + warnings.simplefilter("ignore") + jp2 = Jp2k(filename) + with patch('sys.stdout', new=StringIO()) as fake_out: + print(jp2.box[2].box[1]) + actual = fake_out.getvalue().strip() + self.assertEqual(actual, fixtures.issue_183_colr) @unittest.skipIf(sys.hexversion < 0x03000000, "Ordered dicts not printing well in 2.7")