From 09d96c17693048b0ec8b6610cd5f4f4247cb3075 Mon Sep 17 00:00:00 2001 From: jevans Date: Thu, 14 Nov 2013 20:53:29 -0500 Subject: [PATCH] Handling the case of signed data as well. #140. --- glymur/codestream.py | 2 +- glymur/test/test_codestream.py | 24 +++++++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/glymur/codestream.py b/glymur/codestream.py index 4274b61..fc94d32 100644 --- a/glymur/codestream.py +++ b/glymur/codestream.py @@ -1510,7 +1510,7 @@ class SIZsegment(Segment): lst = [] for bitdepth, signed in zip(self.bitdepth, self.signed): if signed: - lst.append((bitdepth - 1) & 0x80) + lst.append((bitdepth - 1) | 0x80) else: lst.append(bitdepth - 1) self.ssiz = tuple(lst) diff --git a/glymur/test/test_codestream.py b/glymur/test/test_codestream.py index 39e3b16..768bf7f 100644 --- a/glymur/test/test_codestream.py +++ b/glymur/test/test_codestream.py @@ -32,8 +32,6 @@ except: raise -@unittest.skipIf(DATA_ROOT is None, - "OPJ_DATA_ROOT environment variable not set") class TestCodestream(unittest.TestCase): """Test suite for unusual codestream cases.""" @@ -43,6 +41,8 @@ class TestCodestream(unittest.TestCase): def tearDown(self): pass + @unittest.skipIf(DATA_ROOT is None, + "OPJ_DATA_ROOT environment variable not set") @unittest.skipIf(os.name == "nt", "Temporary file issue on window.") def test_reserved_marker_segment(self): """Reserved marker segments are ok.""" @@ -74,6 +74,8 @@ class TestCodestream(unittest.TestCase): self.assertEqual(codestream.segment[2].length, 3) self.assertEqual(codestream.segment[2].data, b'\x00') + @unittest.skipIf(DATA_ROOT is None, + "OPJ_DATA_ROOT environment variable not set") @unittest.skipIf(sys.hexversion < 0x03020000, "Uses features introduced in 3.2.") @unittest.skipIf(os.name == "nt", "Temporary file issue on window.") @@ -105,6 +107,8 @@ class TestCodestream(unittest.TestCase): self.assertEqual(codestream.segment[2].length, 3) self.assertEqual(codestream.segment[2].data, b'\x00') + @unittest.skipIf(DATA_ROOT is None, + "OPJ_DATA_ROOT environment variable not set") def test_psot_is_zero(self): """Psot=0 in SOT is perfectly legal. Issue #78.""" filename = os.path.join(DATA_ROOT, @@ -117,7 +121,7 @@ class TestCodestream(unittest.TestCase): self.assertEqual(codestream.segment[-1].marker_id, 'EOC') - def test_siz_segment_ssiz(self): + def test_siz_segment_ssiz_unsigned(self): """ssiz attribute to be removed in future release""" j = Jp2k(self.jp2file) codestream = j.get_codestream() @@ -128,6 +132,20 @@ class TestCodestream(unittest.TestCase): self.assertEqual(codestream.segment[1].ssiz, (7, 7, 7)) + @unittest.skipIf(DATA_ROOT is None, + "OPJ_DATA_ROOT environment variable not set") + def test_siz_segment_ssiz_signed(self): + """ssiz attribute to be removed in future release""" + filename = os.path.join(DATA_ROOT, 'input/conformance/p0_03.j2k') + j = Jp2k(filename) + codestream = j.get_codestream() + + # The ssiz attribute was simply a tuple of raw bytes. + # The first 7 bits are interpreted as the bitdepth, the MSB determines + # whether or not it is signed. + self.assertEqual(codestream.segment[1].ssiz, (131,)) + + class TestCodestreamRepr(unittest.TestCase): def setUp(self):