From 9e87780ed3b2b1e6802c7fcfae60207c697717df Mon Sep 17 00:00:00 2001 From: jevans Date: Thu, 14 Nov 2013 20:07:15 -0500 Subject: [PATCH 1/2] Restored ssiz attribute to SIZsegment. #140 --- CHANGES.txt | 3 +-- glymur/codestream.py | 11 ++++++++++- glymur/test/test_codestream.py | 11 +++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 2dff6f3..dd11c27 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,6 +1,5 @@ -Oct 29, 2013 - Palette box now a 2D numpy array instead of a list of +Nov 11, 2013 - Palette box now a 2D numpy array instead of a list of 1D arrays. Super box constructors now take optional box list argument. - Removed ssiz attribute from SIZsegment class. Oct 29, 2013 - v0.5.9 Fixed bad library load on linux as a result of 0.5.8 diff --git a/glymur/codestream.py b/glymur/codestream.py index d01795f..4274b61 100644 --- a/glymur/codestream.py +++ b/glymur/codestream.py @@ -662,7 +662,7 @@ class Codestream(object): component_buffer) bitdepth = tuple(((x & 0x7f) + 1) for x in data[0::3]) - signed = tuple(((x & 0xb0) > 0) for x in data[0::3]) + signed = tuple(((x & 0x80) > 0) for x in data[0::3]) xrsiz = data[1::3] yrsiz = data[2::3] @@ -1506,6 +1506,15 @@ class SIZsegment(Segment): self.signed = signed self.xrsiz, self.yrsiz = xyrsiz + # ssiz attribute to be removed in 1.0.0 + lst = [] + for bitdepth, signed in zip(self.bitdepth, self.signed): + if signed: + lst.append((bitdepth - 1) & 0x80) + else: + lst.append(bitdepth - 1) + self.ssiz = tuple(lst) + num_tiles_x = (self.xsiz - self.xosiz) / (self.xtsiz - self.xtosiz) num_tiles_y = (self.ysiz - self.yosiz) / (self.ytsiz - self.ytosiz) numtiles = math.ceil(num_tiles_x) * math.ceil(num_tiles_y) diff --git a/glymur/test/test_codestream.py b/glymur/test/test_codestream.py index 76042b9..39e3b16 100644 --- a/glymur/test/test_codestream.py +++ b/glymur/test/test_codestream.py @@ -117,6 +117,17 @@ class TestCodestream(unittest.TestCase): self.assertEqual(codestream.segment[-1].marker_id, 'EOC') + def test_siz_segment_ssiz(self): + """ssiz attribute to be removed in future release""" + j = Jp2k(self.jp2file) + 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, (7, 7, 7)) + + class TestCodestreamRepr(unittest.TestCase): def setUp(self): From 09d96c17693048b0ec8b6610cd5f4f4247cb3075 Mon Sep 17 00:00:00 2001 From: jevans Date: Thu, 14 Nov 2013 20:53:29 -0500 Subject: [PATCH 2/2] 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):