Handling the case of signed data as well. #140.

This commit is contained in:
jevans 2013-11-14 20:53:29 -05:00
commit 09d96c1769
2 changed files with 22 additions and 4 deletions

View file

@ -1510,7 +1510,7 @@ class SIZsegment(Segment):
lst = [] lst = []
for bitdepth, signed in zip(self.bitdepth, self.signed): for bitdepth, signed in zip(self.bitdepth, self.signed):
if signed: if signed:
lst.append((bitdepth - 1) & 0x80) lst.append((bitdepth - 1) | 0x80)
else: else:
lst.append(bitdepth - 1) lst.append(bitdepth - 1)
self.ssiz = tuple(lst) self.ssiz = tuple(lst)

View file

@ -32,8 +32,6 @@ except:
raise raise
@unittest.skipIf(DATA_ROOT is None,
"OPJ_DATA_ROOT environment variable not set")
class TestCodestream(unittest.TestCase): class TestCodestream(unittest.TestCase):
"""Test suite for unusual codestream cases.""" """Test suite for unusual codestream cases."""
@ -43,6 +41,8 @@ class TestCodestream(unittest.TestCase):
def tearDown(self): def tearDown(self):
pass pass
@unittest.skipIf(DATA_ROOT is None,
"OPJ_DATA_ROOT environment variable not set")
@unittest.skipIf(os.name == "nt", "Temporary file issue on window.") @unittest.skipIf(os.name == "nt", "Temporary file issue on window.")
def test_reserved_marker_segment(self): def test_reserved_marker_segment(self):
"""Reserved marker segments are ok.""" """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].length, 3)
self.assertEqual(codestream.segment[2].data, b'\x00') 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, @unittest.skipIf(sys.hexversion < 0x03020000,
"Uses features introduced in 3.2.") "Uses features introduced in 3.2.")
@unittest.skipIf(os.name == "nt", "Temporary file issue on window.") @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].length, 3)
self.assertEqual(codestream.segment[2].data, b'\x00') 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): def test_psot_is_zero(self):
"""Psot=0 in SOT is perfectly legal. Issue #78.""" """Psot=0 in SOT is perfectly legal. Issue #78."""
filename = os.path.join(DATA_ROOT, filename = os.path.join(DATA_ROOT,
@ -117,7 +121,7 @@ class TestCodestream(unittest.TestCase):
self.assertEqual(codestream.segment[-1].marker_id, 'EOC') 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""" """ssiz attribute to be removed in future release"""
j = Jp2k(self.jp2file) j = Jp2k(self.jp2file)
codestream = j.get_codestream() codestream = j.get_codestream()
@ -128,6 +132,20 @@ class TestCodestream(unittest.TestCase):
self.assertEqual(codestream.segment[1].ssiz, (7, 7, 7)) 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): class TestCodestreamRepr(unittest.TestCase):
def setUp(self): def setUp(self):