Adjusted tests for newer JPX file. #205
This commit is contained in:
parent
02651a420d
commit
9399ef8496
7 changed files with 33 additions and 36 deletions
Binary file not shown.
|
|
@ -34,13 +34,13 @@ def goodstuff():
|
||||||
|
|
||||||
|
|
||||||
def jpxfile():
|
def jpxfile():
|
||||||
"""Shortcut for specifying path to 12-v6.4.jpx.
|
"""Shortcut for specifying path to heliov.jpx.
|
||||||
|
|
||||||
Returns
|
Returns
|
||||||
-------
|
-------
|
||||||
file : str
|
file : str
|
||||||
Platform-independent path to 12-v6.4.jpx
|
Platform-independent path to 12-v6.4.jpx
|
||||||
"""
|
"""
|
||||||
filename = pkg_resources.resource_filename(__name__, "12-v6.4.jpx")
|
filename = pkg_resources.resource_filename(__name__, "heliov.jpx")
|
||||||
return filename
|
return filename
|
||||||
|
|
||||||
|
|
|
||||||
BIN
glymur/data/heliov.jpx
Normal file
BIN
glymur/data/heliov.jpx
Normal file
Binary file not shown.
|
|
@ -678,8 +678,9 @@ class TestWrap(unittest.TestCase):
|
||||||
def test_jpx_to_jp2(self):
|
def test_jpx_to_jp2(self):
|
||||||
"""basic test for rewrapping a jpx file"""
|
"""basic test for rewrapping a jpx file"""
|
||||||
jpx = Jp2k(self.jpxfile)
|
jpx = Jp2k(self.jpxfile)
|
||||||
idx = [0, 1, 3, 6]
|
# Use only the signature, file type, header, and 1st codestream.
|
||||||
boxes = [jpx.box[idx] for idx in [0, 1, 3, 6]]
|
lst = [0, 1, 2, 5]
|
||||||
|
boxes = [jpx.box[idx] for idx in lst]
|
||||||
with tempfile.NamedTemporaryFile(suffix=".jp2") as tfile:
|
with tempfile.NamedTemporaryFile(suffix=".jp2") as tfile:
|
||||||
jp2 = jpx.wrap(tfile.name, boxes=boxes)
|
jp2 = jpx.wrap(tfile.name, boxes=boxes)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -451,6 +451,7 @@ class TestJPX(unittest.TestCase):
|
||||||
with tempfile.TemporaryFile() as tfile:
|
with tempfile.TemporaryFile() as tfile:
|
||||||
ftbl.write(tfile)
|
ftbl.write(tfile)
|
||||||
|
|
||||||
|
@unittest.skip("No such jpx file anymore.")
|
||||||
def test_jpx_rreq_mask_length_3(self):
|
def test_jpx_rreq_mask_length_3(self):
|
||||||
"""There are some JPX files with rreq mask length of 3."""
|
"""There are some JPX files with rreq mask length of 3."""
|
||||||
jpx = Jp2k(self.jpxfile)
|
jpx = Jp2k(self.jpxfile)
|
||||||
|
|
@ -479,12 +480,6 @@ class TestJPX(unittest.TestCase):
|
||||||
self.assertEqual(jpx.box[-1].box_id, b'grp ')
|
self.assertEqual(jpx.box[-1].box_id, b'grp ')
|
||||||
self.assertEqual(jpx.box[-1].box[0].box_id, 'free')
|
self.assertEqual(jpx.box[-1].box[0].box_id, 'free')
|
||||||
|
|
||||||
def test_free_box(self):
|
|
||||||
"""Verify that we can handle a free box."""
|
|
||||||
j = Jp2k(self.jpxfile)
|
|
||||||
self.assertEqual(j.box[16].box[0].box_id, 'free')
|
|
||||||
self.assertEqual(type(j.box[16].box[0]), glymur.jp2box.FreeBox)
|
|
||||||
|
|
||||||
def test_data_reference_requires_dtbl(self):
|
def test_data_reference_requires_dtbl(self):
|
||||||
"""The existance of a data reference box requires a ftbl box as well."""
|
"""The existance of a data reference box requires a ftbl box as well."""
|
||||||
flag = 0
|
flag = 0
|
||||||
|
|
@ -557,17 +552,17 @@ class TestJPX(unittest.TestCase):
|
||||||
self.assertEqual(jpx.box[-1].box[0].data_reference, (3,))
|
self.assertEqual(jpx.box[-1].box[0].data_reference, (3,))
|
||||||
|
|
||||||
def test_nlst(self):
|
def test_nlst(self):
|
||||||
"""Verify that we can handle a free box."""
|
"""Verify that we can handle a number list box."""
|
||||||
j = Jp2k(self.jpxfile)
|
j = Jp2k(self.jpxfile)
|
||||||
self.assertEqual(j.box[16].box[1].box[0].box_id, 'nlst')
|
nlst = j.box[12].box[0].box[0]
|
||||||
self.assertEqual(type(j.box[16].box[1].box[0]),
|
self.assertEqual(nlst.box_id, 'nlst')
|
||||||
glymur.jp2box.NumberListBox)
|
self.assertEqual(type(nlst), glymur.jp2box.NumberListBox)
|
||||||
|
|
||||||
# Two associations.
|
# Two associations.
|
||||||
self.assertEqual(len(j.box[16].box[1].box[0].associations), 2)
|
self.assertEqual(len(nlst.associations), 2)
|
||||||
|
|
||||||
# Codestream 0
|
# Codestream 0
|
||||||
self.assertEqual(j.box[16].box[1].box[0].associations[0], 1 << 24)
|
self.assertEqual(nlst.associations[0], 1 << 24)
|
||||||
|
|
||||||
# Compositing Layer 0
|
# Compositing Layer 0
|
||||||
self.assertEqual(j.box[16].box[1].box[0].associations[1], 2 << 24)
|
self.assertEqual(nlst.associations[1], 2 << 24)
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,24 @@ class TestJp2k(unittest.TestCase):
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def test_no_cxform_pclr_jpx(self):
|
||||||
|
"""Indices for pclr jpxfile if no color transform"""
|
||||||
|
j = Jp2k(self.jpxfile)
|
||||||
|
rgb = j.read()
|
||||||
|
idx = j.read(ignore_pclr_cmap_cdef=True)
|
||||||
|
nr, nc = 1024, 1024
|
||||||
|
self.assertEqual(rgb.shape, (nr, nc, 3))
|
||||||
|
self.assertEqual(idx.shape, (nr, nc))
|
||||||
|
|
||||||
|
# Should be able to manually reconstruct the RGB image from the palette
|
||||||
|
# and indices.
|
||||||
|
palette = j.box[2].box[2].palette
|
||||||
|
rgb_from_idx = np.zeros(rgb.shape, dtype=np.uint8)
|
||||||
|
for r in np.arange(nr):
|
||||||
|
for c in np.arange(nc):
|
||||||
|
rgb_from_idx[r, c] = palette[idx[r, c]]
|
||||||
|
np.testing.assert_array_equal(rgb, rgb_from_idx)
|
||||||
|
|
||||||
def test_repr(self):
|
def test_repr(self):
|
||||||
"""Verify that results of __repr__ are eval-able."""
|
"""Verify that results of __repr__ are eval-able."""
|
||||||
j = Jp2k(self.j2kfile)
|
j = Jp2k(self.j2kfile)
|
||||||
|
|
@ -92,23 +110,6 @@ class TestJp2k(unittest.TestCase):
|
||||||
with self.assertRaises(IOError):
|
with self.assertRaises(IOError):
|
||||||
Jp2k(filename)
|
Jp2k(filename)
|
||||||
|
|
||||||
def test_no_cxform_pclr_jpx(self):
|
|
||||||
"""Indices for pclr jpxfile if no color transform"""
|
|
||||||
j = Jp2k(self.jpxfile)
|
|
||||||
rgb = j.read()
|
|
||||||
idx = j.read(ignore_pclr_cmap_cdef=True)
|
|
||||||
self.assertEqual(rgb.shape, (1024, 1024, 3))
|
|
||||||
self.assertEqual(idx.shape, (1024, 1024))
|
|
||||||
|
|
||||||
# Should be able to manually reconstruct the RGB image from the palette
|
|
||||||
# and indices.
|
|
||||||
palette = j.box[3].box[2].palette
|
|
||||||
rgb_from_idx = np.zeros(rgb.shape, dtype=np.uint8)
|
|
||||||
for r in np.arange(1024):
|
|
||||||
for c in np.arange(1024):
|
|
||||||
rgb_from_idx[r, c] = palette[idx[r, c]]
|
|
||||||
np.testing.assert_array_equal(rgb, rgb_from_idx)
|
|
||||||
|
|
||||||
def test_file_not_present(self):
|
def test_file_not_present(self):
|
||||||
"""Should error out if reading from a file that does not exist"""
|
"""Should error out if reading from a file that does not exist"""
|
||||||
# Verify that we error out appropriately if not given an existing file
|
# Verify that we error out appropriately if not given an existing file
|
||||||
|
|
|
||||||
|
|
@ -78,8 +78,8 @@ class TestPrinting(unittest.TestCase):
|
||||||
with patch('sys.stdout', new=StringIO()) as fake_out:
|
with patch('sys.stdout', new=StringIO()) as fake_out:
|
||||||
print(jpx.box[-1])
|
print(jpx.box[-1])
|
||||||
actual = fake_out.getvalue().strip()
|
actual = fake_out.getvalue().strip()
|
||||||
lines = ["Unknown Box (b'grp ') @ (695609, 20)",
|
lines = ["Unknown Box (b'grp ') @ (1399071, 20)",
|
||||||
' Free Box (free) @ (695617, 12)']
|
' Free Box (free) @ (1399079, 12)']
|
||||||
expected = '\n'.join(lines)
|
expected = '\n'.join(lines)
|
||||||
self.assertEqual(actual, expected)
|
self.assertEqual(actual, expected)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue