From 3efcf0b46a1ebe98b77b1bf5603bc85cbfd1816a Mon Sep 17 00:00:00 2001 From: John Evans Date: Wed, 21 Aug 2013 12:13:26 -0400 Subject: [PATCH 01/22] restrict email notifications, closes #107 --- .travis.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.travis.yml b/.travis.yml index 30dd864..a8a0d1b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,6 +12,11 @@ before_install: # command to install dependencies install: - pip install . --use-mirrors + # command to run tests script: - "python -m unittest discover" + +notifications: + email: + - john.g.evans.ne@gmail.com From 8a8cccb8abd5abc3496d6bfec57ad81a08727c55 Mon Sep 17 00:00:00 2001 From: jevans Date: Wed, 28 Aug 2013 21:35:22 -0400 Subject: [PATCH 02/22] Refactored OPJ_DATA_ROOT handling into a fixture. Closes #108 --- glymur/test/fixtures.py | 14 + glymur/test/test_icc.py | 15 +- glymur/test/test_jp2k.py | 24 +- glymur/test/test_opj_suite.py | 925 +++++++++++++--------------- glymur/test/test_opj_suite_neg.py | 22 +- glymur/test/test_opj_suite_write.py | 36 +- glymur/test/test_printing.py | 84 ++- 7 files changed, 501 insertions(+), 619 deletions(-) diff --git a/glymur/test/fixtures.py b/glymur/test/fixtures.py index eec9e22..4c99ade 100644 --- a/glymur/test/fixtures.py +++ b/glymur/test/fixtures.py @@ -1,6 +1,7 @@ """ Test fixtures common to more than one test point. """ +import os import re import sys import warnings @@ -27,6 +28,19 @@ if glymur.lib.openjp2.OPENJP2 is not None: NO_READ_BACKEND_MSG = "Matplotlib with the PIL backend must be available in " NO_READ_BACKEND_MSG += "order to run the tests in this suite." +try: + OPJ_DATA_ROOT = os.environ['OPJ_DATA_ROOT'] +except KeyError: + OPJ_DATA_ROOT = None +except: + raise + + +def opj_data_file(relative_file_name): + """Compact way of forming a full filename from OpenJPEG's test suite.""" + jfile = os.path.join(OPJ_DATA_ROOT, relative_file_name) + return jfile + try: from matplotlib.pyplot import imread diff --git a/glymur/test/test_icc.py b/glymur/test/test_icc.py index bf589a5..8668999 100644 --- a/glymur/test/test_icc.py +++ b/glymur/test/test_icc.py @@ -20,16 +20,10 @@ else: import numpy as np from glymur import Jp2k - -try: - DATA_ROOT = os.environ['OPJ_DATA_ROOT'] -except KeyError: - DATA_ROOT = None -except: - raise +from .fixtures import OPJ_DATA_ROOT, opj_data_file -@unittest.skipIf(DATA_ROOT is None, +@unittest.skipIf(OPJ_DATA_ROOT is None, "OPJ_DATA_ROOT environment variable not set") class TestICC(unittest.TestCase): """ICC profile tests""" @@ -42,7 +36,7 @@ class TestICC(unittest.TestCase): def test_file5(self): """basic ICC profile""" - filename = os.path.join(DATA_ROOT, 'input/conformance/file5.jp2') + filename = opj_data_file('input/conformance/file5.jp2') j = Jp2k(filename) profile = j.box[3].box[1].icc_profile self.assertEqual(profile['Size'], 546) @@ -75,8 +69,7 @@ class TestICC(unittest.TestCase): "Uses features introduced in 3.2.") def test_invalid_profile_header(self): """invalid ICC header data should cause UserWarning""" - jfile = os.path.join(DATA_ROOT, - 'input/nonregression/orb-blue10-lin-jp2.jp2') + jfile = opj_data_file('input/nonregression/orb-blue10-lin-jp2.jp2') # assertWarns in Python 3.3 (python2.7/pylint issue) # pylint: disable=E1101 diff --git a/glymur/test/test_jp2k.py b/glymur/test/test_jp2k.py index ea19199..699fef7 100644 --- a/glymur/test/test_jp2k.py +++ b/glymur/test/test_jp2k.py @@ -25,10 +25,6 @@ if sys.hexversion < 0x02070000: else: import unittest -if sys.hexversion <= 0x03030000: - from mock import patch -else: - from unittest.mock import patch import warnings import numpy as np @@ -39,13 +35,7 @@ from glymur import Jp2k from .fixtures import OPENJP2_IS_V2_OFFICIAL from .fixtures import OPENJPEG_VERSION - -try: - DATA_ROOT = os.environ['OPJ_DATA_ROOT'] -except KeyError: - DATA_ROOT = None -except: - raise +from .fixtures import OPJ_DATA_ROOT, opj_data_file # Doc tests should be run as well. @@ -380,7 +370,7 @@ class TestJp2k(unittest.TestCase): j2k = Jp2k(self.j2kfile) j2k.read() - @unittest.skipIf(DATA_ROOT is None, + @unittest.skipIf(OPJ_DATA_ROOT is None, "OPJ_DATA_ROOT environment variable not set") def test_read_differing_subsamples(self): """should error out with read used on differently subsampled images""" @@ -388,7 +378,7 @@ class TestJp2k(unittest.TestCase): # on an image with differing subsamples # # Issue 86. - filename = os.path.join(DATA_ROOT, 'input/conformance/p0_05.j2k') + filename = opj_data_file('input/conformance/p0_05.j2k') j = Jp2k(filename) with self.assertRaises(RuntimeError): j.read() @@ -1039,7 +1029,7 @@ class TestJp2k15(unittest.TestCase): j2k = Jp2k(self.j2kfile) j2k.read() - @unittest.skipIf(DATA_ROOT is None, + @unittest.skipIf(OPJ_DATA_ROOT is None, "OPJ_DATA_ROOT environment variable not set") def test_read_differing_subsamples(self): """should error out with read used on differently subsampled images""" @@ -1047,7 +1037,7 @@ class TestJp2k15(unittest.TestCase): # on an image with differing subsamples # # Issue 86. - filename = os.path.join(DATA_ROOT, 'input/conformance/p0_05.j2k') + filename = opj_data_file('input/conformance/p0_05.j2k') j = Jp2k(filename) with self.assertRaises(RuntimeError): j.read() @@ -1347,7 +1337,8 @@ class TestJp2k15(unittest.TestCase): self.assertEqual(jasoc.box[3].box[1].box_id, 'xml ') @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") - @unittest.skipIf(re.match('1\.[345]\.\d', OPENJPEG_VERSION) is not None, + @unittest.skipIf(re.match(r"""1\.[345]\.\d""", + OPENJPEG_VERSION) is not None, "Segfault on official v1.x series.") def test_openjpeg_library_message(self): """Verify the error message produced by the openjpeg library""" @@ -1426,6 +1417,5 @@ class TestJp2k15(unittest.TestCase): self.assertFalse('Make' in exif['Image'].keys()) - if __name__ == "__main__": unittest.main() diff --git a/glymur/test/test_opj_suite.py b/glymur/test/test_opj_suite.py index c622f44..93e9745 100644 --- a/glymur/test/test_opj_suite.py +++ b/glymur/test/test_opj_suite.py @@ -30,7 +30,6 @@ suite. # unittest2 is python2.6 only (pylint/python-2.7) # pylint: disable=F0401 -import os import re import sys @@ -46,22 +45,13 @@ import numpy as np from glymur import Jp2k import glymur -from .fixtures import OPENJPEG_VERSION -from .fixtures import OPENJP2_IS_V2_OFFICIAL -from .fixtures import mse, peak_tolerance, read_pgx - - -try: - data_root = os.environ['OPJ_DATA_ROOT'] -except KeyError: - data_root = None -except: - raise +from .fixtures import OPENJPEG_VERSION, OPENJP2_IS_V2_OFFICIAL, OPJ_DATA_ROOT +from .fixtures import mse, peak_tolerance, read_pgx, opj_data_file @unittest.skipIf(glymur.lib.openjp2.OPENJP2 is None, "Missing openjp2 library.") -@unittest.skipIf(data_root is None, +@unittest.skipIf(OPJ_DATA_ROOT is None, "OPJ_DATA_ROOT environment variable not set") class TestSuite(unittest.TestCase): @@ -72,78 +62,74 @@ class TestSuite(unittest.TestCase): pass def test_ETS_C0P0_p0_01_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p0_01.j2k') + jfile = opj_data_file('input/conformance/p0_01.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read(rlevel=0) - pgxfile = os.path.join(data_root, 'baseline/conformance/c0p0_01.pgx') + pgxfile = opj_data_file('baseline/conformance/c0p0_01.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata, pgxdata) def test_ETS_C0P0_p0_02_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p0_02.j2k') + jfile = opj_data_file('input/conformance/p0_02.j2k') jp2k = Jp2k(jfile) with warnings.catch_warnings(): # Invalid marker ID. warnings.simplefilter("ignore") jpdata = jp2k.read(rlevel=0) - pgxfile = os.path.join(data_root, 'baseline/conformance/c0p0_02.pgx') + pgxfile = opj_data_file('baseline/conformance/c0p0_02.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata, pgxdata) @unittest.skip("Known failure in OPENJPEG test suite.") def test_ETS_C0P0_p0_03_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p0_03.j2k') + jfile = opj_data_file('input/conformance/p0_03.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read(rlevel=0) - pgxfile = os.path.join(data_root, 'baseline/conformance/c0p0_03r0.pgx') + pgxfile = opj_data_file('baseline/conformance/c0p0_03r0.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata, pgxdata) def test_ETS_C0P0_p0_03_j2k_r1(self): - jfile = os.path.join(data_root, 'input/conformance/p0_03.j2k') + jfile = opj_data_file('input/conformance/p0_03.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read(rlevel=1) - pgxfile = os.path.join(data_root, - 'baseline/conformance/c0p0_03r1.pgx') + pgxfile = opj_data_file('baseline/conformance/c0p0_03r1.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata, pgxdata) @unittest.skip("Known failure in OPENJPEG test suite.") def test_ETS_C0P0_p0_04_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p0_04.j2k') + jfile = opj_data_file('input/conformance/p0_04.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read(rlevel=3) - pgxfile = os.path.join(data_root, - 'baseline/conformance/c0p0_04.pgx') + pgxfile = opj_data_file('baseline/conformance/c0p0_04.pgx') pgxdata = read_pgx(pgxfile) self.assertTrue(peak_tolerance(jpdata[:, :, 2], pgxdata) < 33) self.assertTrue(mse(jpdata[:, :, 2], pgxdata) < 55.8) def test_ETS_C0P0_p0_05_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p0_05.j2k') + jfile = opj_data_file('input/conformance/p0_05.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read_bands(rlevel=3) - pgxfile = os.path.join(data_root, - 'baseline/conformance/c0p0_05.pgx') + pgxfile = opj_data_file('baseline/conformance/c0p0_05.pgx') pgxdata = read_pgx(pgxfile) self.assertTrue(peak_tolerance(jpdata[0], pgxdata) < 54) self.assertTrue(mse(jpdata[0], pgxdata) < 68) @unittest.skip("8-bit pgx data vs 12-bit j2k data") def test_ETS_C0P0_p0_06_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p0_06.j2k') + jfile = opj_data_file('input/conformance/p0_06.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read_bands(rlevel=3) - pgxfile = os.path.join(data_root, - 'baseline/conformance/c0p0_06.pgx') + pgxfile = opj_data_file('baseline/conformance/c0p0_06.pgx') pgxdata = read_pgx(pgxfile) tol = peak_tolerance(jpdata[0], pgxdata) self.assertTrue(tol < 109) @@ -152,12 +138,11 @@ class TestSuite(unittest.TestCase): @unittest.skip("Known failure in OPENJPEG test suite.") def test_ETS_C0P0_p0_07_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p0_07.j2k') + jfile = opj_data_file('input/conformance/p0_07.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read() - pgxfile = os.path.join(data_root, - 'baseline/conformance/c0p0_07.pgx') + pgxfile = opj_data_file('baseline/conformance/c0p0_07.pgx') pgxdata = read_pgx(pgxfile) self.assertTrue(peak_tolerance(jpdata[:, :, 0], pgxdata) < 10) @@ -165,24 +150,22 @@ class TestSuite(unittest.TestCase): @unittest.skip("8-bit pgx data vs 12-bit j2k data") def test_ETS_C0P0_p0_08_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p0_08.j2k') + jfile = opj_data_file('input/conformance/p0_08.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read(rlevel=5) - pgxfile = os.path.join(data_root, - 'baseline/conformance/c0p0_08.pgx') + pgxfile = opj_data_file('baseline/conformance/c0p0_08.pgx') pgxdata = read_pgx(pgxfile) self.assertTrue(peak_tolerance(jpdata[:, :, 0], pgxdata) < 7) self.assertTrue(mse(jpdata[:, :, 0], pgxdata) < 6.72) def test_ETS_C0P0_p0_09_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p0_09.j2k') + jfile = opj_data_file('input/conformance/p0_09.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read(rlevel=2) - pgxfile = os.path.join(data_root, - 'baseline/conformance/c0p0_09.pgx') + pgxfile = opj_data_file('baseline/conformance/c0p0_09.pgx') pgxdata = read_pgx(pgxfile) self.assertTrue(peak_tolerance(jpdata, pgxdata) < 4) @@ -190,129 +173,118 @@ class TestSuite(unittest.TestCase): @unittest.skip("Known failure in OPENJPEG test suite.") def test_ETS_C0P0_p0_10_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p0_10.j2k') + jfile = opj_data_file('input/conformance/p0_10.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read(rlevel=0) - pgxfile = os.path.join(data_root, - 'baseline/conformance/c0p0_10.pgx') + pgxfile = opj_data_file('baseline/conformance/c0p0_10.pgx') pgxdata = read_pgx(pgxfile) self.assertTrue(peak_tolerance(jpdata[:, :, 0], pgxdata) < 10) self.assertTrue(mse(jpdata[:, :, 0], pgxdata) < 2.84) def test_ETS_C0P0_p0_11_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p0_11.j2k') + jfile = opj_data_file('input/conformance/p0_11.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read(rlevel=0) - pgxfile = os.path.join(data_root, - 'baseline/conformance/c0p0_11.pgx') + pgxfile = opj_data_file('baseline/conformance/c0p0_11.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata, pgxdata) @unittest.skip("fprintf stderr output in r2343.") def test_ETS_C0P0_p0_12_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p0_12.j2k') + jfile = opj_data_file('input/conformance/p0_12.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read(rlevel=0) - pgxfile = os.path.join(data_root, - 'baseline/conformance/c0p0_12.pgx') + pgxfile = opj_data_file('baseline/conformance/c0p0_12.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata, pgxdata) @unittest.skip("Known failure in OPENJPEG test suite.") def test_ETS_C0P0_p0_13_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p0_13.j2k') + jfile = opj_data_file('input/conformance/p0_13.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read(rlevel=0) - pgxfile = os.path.join(data_root, - 'baseline/conformance/c0p0_13.pgx') + pgxfile = opj_data_file('baseline/conformance/c0p0_13.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata[:, :, 0], pgxdata) @unittest.skip("Known failure in OPENJPEG test suite.") def test_ETS_C0P0_p0_14_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p0_14.j2k') + jfile = opj_data_file('input/conformance/p0_14.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read(rlevel=2) - pgxfile = os.path.join(data_root, - 'baseline/conformance/c0p0_14.pgx') + pgxfile = opj_data_file('baseline/conformance/c0p0_14.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata[:, :, 0], pgxdata) @unittest.skip("Known failure in OPENJPEG test suite.") def test_ETS_C0P0_p0_15_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p0_15.j2k') + jfile = opj_data_file('input/conformance/p0_15.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read(rlevel=0) - pgxfile = os.path.join(data_root, - 'baseline/conformance/c0p0_15r0.pgx') + pgxfile = opj_data_file('baseline/conformance/c0p0_15r0.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata, pgxdata) def test_ETS_C0P0_p0_15_j2k_r1(self): - jfile = os.path.join(data_root, 'input/conformance/p0_15.j2k') + jfile = opj_data_file('input/conformance/p0_15.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read(rlevel=1) - pgxfile = os.path.join(data_root, - 'baseline/conformance/c0p0_15r1.pgx') + pgxfile = opj_data_file('baseline/conformance/c0p0_15r1.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata, pgxdata) def test_ETS_C0P0_p0_16_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p0_16.j2k') + jfile = opj_data_file('input/conformance/p0_16.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read(rlevel=0) - pgxfile = os.path.join(data_root, - 'baseline/conformance/c0p0_16.pgx') + pgxfile = opj_data_file('baseline/conformance/c0p0_16.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata, pgxdata) def test_ETS_C0P1_p1_01_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p1_01.j2k') + jfile = opj_data_file('input/conformance/p1_01.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read(rlevel=0) - pgxfile = os.path.join(data_root, - 'baseline/conformance/c0p1_01.pgx') + pgxfile = opj_data_file('baseline/conformance/c0p1_01.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata, pgxdata) @unittest.skip("Known failure in OPENJPEG test suite operation.") def test_ETS_C0P1_p1_02_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p1_02.j2k') + jfile = opj_data_file('input/conformance/p1_02.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read(rlevel=3) - pgxfile = os.path.join(data_root, - 'baseline/conformance/c0p1_02.pgx') + pgxfile = opj_data_file('baseline/conformance/c0p1_02.pgx') pgxdata = read_pgx(pgxfile) self.assertTrue(peak_tolerance(jpdata[:, :, 0], pgxdata) < 35) self.assertTrue(mse(jpdata[:, :, 0], pgxdata) < 74) def test_ETS_C0P1_p1_03_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p1_03.j2k') + jfile = opj_data_file('input/conformance/p1_03.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read_bands(rlevel=3) - pgxfile = os.path.join(data_root, - 'baseline/conformance/c0p1_03.pgx') + pgxfile = opj_data_file('baseline/conformance/c0p1_03.pgx') pgxdata = read_pgx(pgxfile) self.assertTrue(peak_tolerance(jpdata[0], pgxdata) < 28) @@ -320,12 +292,11 @@ class TestSuite(unittest.TestCase): @unittest.skip("Known failure in OPENJPEG test suite operation.") def test_ETS_C0P1_p1_04_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p1_04.j2k') + jfile = opj_data_file('input/conformance/p1_04.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read(rlevel=0) - pgxfile = os.path.join(data_root, - 'baseline/conformance/c0p1_04r0.pgx') + pgxfile = opj_data_file('baseline/conformance/c0p1_04r0.pgx') pgxdata = read_pgx(pgxfile) print(peak_tolerance(jpdata, pgxdata)) @@ -334,12 +305,11 @@ class TestSuite(unittest.TestCase): @unittest.skip("Known failure in OPENJPEG test suite, precision issue.") def test_ETS_C0P1_p1_04_j2k_r3(self): - jfile = os.path.join(data_root, 'input/conformance/p1_04.j2k') + jfile = opj_data_file('input/conformance/p1_04.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read(rlevel=3) - pgxfile = os.path.join(data_root, - 'baseline/conformance/c0p1_04r3.pgx') + pgxfile = opj_data_file('baseline/conformance/c0p1_04r3.pgx') pgxdata = read_pgx(pgxfile) print(peak_tolerance(jpdata, pgxdata)) @@ -348,12 +318,11 @@ class TestSuite(unittest.TestCase): @unittest.skip("Known failure in OPENJPEG test suite operation.") def test_ETS_C0P1_p1_05_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p1_05.j2k') + jfile = opj_data_file('input/conformance/p1_05.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read(rlevel=4) - pgxfile = os.path.join(data_root, - 'baseline/conformance/c0p1_05.pgx') + pgxfile = opj_data_file('baseline/conformance/c0p1_05.pgx') pgxdata = read_pgx(pgxfile) print(peak_tolerance(jpdata[:, :, 0], pgxdata)) @@ -363,12 +332,11 @@ class TestSuite(unittest.TestCase): @unittest.skip("Known failure in OPENJPEG test suite operation.") def test_ETS_C0P1_p1_06_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p1_06.j2k') + jfile = opj_data_file('input/conformance/p1_06.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read(rlevel=1) - pgxfile = os.path.join(data_root, - 'baseline/conformance/c0p1_06.pgx') + pgxfile = opj_data_file('baseline/conformance/c0p1_06.pgx') pgxdata = read_pgx(pgxfile) print(peak_tolerance(jpdata[:, :, 0], pgxdata)) @@ -378,388 +346,387 @@ class TestSuite(unittest.TestCase): @unittest.skip("fprintf stderr output in r2345.") def test_ETS_C0P1_p1_07_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p1_07.j2k') + jfile = opj_data_file('input/conformance/p1_07.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read_bands(rlevel=0) - pgxfile = os.path.join(data_root, - 'baseline/conformance/c0p1_07.pgx') + pgxfile = opj_data_file('baseline/conformance/c0p1_07.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata[0], pgxdata) def test_ETS_C1P0_p0_01_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p0_01.j2k') + jfile = opj_data_file('input/conformance/p0_01.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read(rlevel=0) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_01_0.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p0_01_0.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata, pgxdata) def test_ETS_C1P0_p0_02_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p0_02.j2k') + jfile = opj_data_file('input/conformance/p0_02.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read(rlevel=0) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_02_0.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p0_02_0.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata, pgxdata) def test_ETS_C1P0_p0_03_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p0_03.j2k') + jfile = opj_data_file('input/conformance/p0_03.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read(rlevel=0) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_03_0.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p0_03_0.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata, pgxdata) def test_ETS_C1P0_p0_04_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p0_04.j2k') + jfile = opj_data_file('input/conformance/p0_04.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read(rlevel=0) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_04_0.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p0_04_0.pgx') pgxdata = read_pgx(pgxfile) self.assertTrue(peak_tolerance(jpdata[:, :, 0], pgxdata) < 5) self.assertTrue(mse(jpdata[:, :, 0], pgxdata) < 0.776) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_04_1.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p0_04_1.pgx') pgxdata = read_pgx(pgxfile) self.assertTrue(peak_tolerance(jpdata[:, :, 1], pgxdata) < 4) self.assertTrue(mse(jpdata[:, :, 1], pgxdata) < 0.626) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_04_2.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p0_04_2.pgx') pgxdata = read_pgx(pgxfile) self.assertTrue(peak_tolerance(jpdata[:, :, 2], pgxdata) < 6) self.assertTrue(mse(jpdata[:, :, 2], pgxdata) < 1.07) def test_ETS_C1P0_p0_05_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p0_05.j2k') + jfile = opj_data_file('input/conformance/p0_05.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read_bands() - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_05_0.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p0_05_0.pgx') pgxdata = read_pgx(pgxfile) self.assertTrue(peak_tolerance(jpdata[0], pgxdata) < 2) self.assertTrue(mse(jpdata[0], pgxdata) < 0.302) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_05_1.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p0_05_1.pgx') pgxdata = read_pgx(pgxfile) self.assertTrue(peak_tolerance(jpdata[1], pgxdata) < 2) self.assertTrue(mse(jpdata[1], pgxdata) < 0.307) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_05_2.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p0_05_2.pgx') pgxdata = read_pgx(pgxfile) self.assertTrue(peak_tolerance(jpdata[2], pgxdata) < 2) self.assertTrue(mse(jpdata[2], pgxdata) < 0.269) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_05_3.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p0_05_3.pgx') pgxdata = read_pgx(pgxfile) self.assertTrue(peak_tolerance(jpdata[3], pgxdata) == 0) self.assertTrue(mse(jpdata[3], pgxdata) == 0) def test_ETS_C1P0_p0_06_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p0_06.j2k') + jfile = opj_data_file('input/conformance/p0_06.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read_bands() - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_06_0.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p0_06_0.pgx') pgxdata = read_pgx(pgxfile) self.assertTrue(peak_tolerance(jpdata[0], pgxdata) < 635) self.assertTrue(mse(jpdata[0], pgxdata) < 11287) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_06_1.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p0_06_1.pgx') pgxdata = read_pgx(pgxfile) self.assertTrue(peak_tolerance(jpdata[1], pgxdata) < 403) self.assertTrue(mse(jpdata[1], pgxdata) < 6124) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_06_2.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p0_06_2.pgx') pgxdata = read_pgx(pgxfile) self.assertTrue(peak_tolerance(jpdata[2], pgxdata) < 378) self.assertTrue(mse(jpdata[2], pgxdata) < 3968) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_06_3.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p0_06_3.pgx') pgxdata = read_pgx(pgxfile) self.assertTrue(peak_tolerance(jpdata[3], pgxdata) == 0) self.assertTrue(mse(jpdata[3], pgxdata) == 0) @unittest.skip("Known failure in OPENJPEG test suite operation.") def test_ETS_C1P0_p0_07_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p0_07.j2k') + jfile = opj_data_file('input/conformance/p0_07.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read() - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_07_0.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p0_07_0.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata[:, :, 0], pgxdata) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_07_1.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p0_07_1.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata[:, : 1], pgxdata) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_07_2.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p0_07_2.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata[:, : 2], pgxdata) def test_ETS_C1P0_p0_08_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p0_08.j2k') + jfile = opj_data_file('input/conformance/p0_08.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read(rlevel=1) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_08_0.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p0_08_0.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata[:, :, 0], pgxdata) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_08_1.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p0_08_1.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata[:, :, 1], pgxdata) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_08_2.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p0_08_2.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata[:, :, 2], pgxdata) def test_ETS_C1P0_p0_09_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p0_09.j2k') + jfile = opj_data_file('input/conformance/p0_09.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read(rlevel=0) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_09_0.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p0_09_0.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata, pgxdata) def test_ETS_C1P0_p0_10_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p0_10.j2k') + jfile = opj_data_file('input/conformance/p0_10.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read(rlevel=0) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_10_0.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p0_10_0.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata[:, :, 0], pgxdata) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_10_1.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p0_10_1.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata[:, :, 1], pgxdata) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_10_2.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p0_10_2.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata[:, :, 2], pgxdata) def test_ETS_C1P0_p0_11_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p0_11.j2k') + jfile = opj_data_file('input/conformance/p0_11.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read(rlevel=0) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_11_0.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p0_11_0.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata, pgxdata) @unittest.skip("fprintf stderr output in r2343.") def test_ETS_C1P0_p0_12_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p0_12.j2k') + jfile = opj_data_file('input/conformance/p0_12.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read(rlevel=0) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_12_0.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p0_12_0.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata, pgxdata) @unittest.skip("fprintf stderr output in r2343.") def test_ETS_C1P0_p0_13_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p0_13.j2k') + jfile = opj_data_file('input/conformance/p0_13.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read(rlevel=0) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_13_0.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p0_13_0.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata[:, :, 0], pgxdata) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_13_1.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p0_13_1.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata[:, :, 1], pgxdata) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_13_2.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p0_13_2.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata[:, :, 2], pgxdata) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_13_3.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p0_13_3.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata[:, :, 3], pgxdata) def test_ETS_C1P0_p0_14_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p0_14.j2k') + jfile = opj_data_file('input/conformance/p0_14.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read(rlevel=0) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_14_0.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p0_14_0.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata[:, :, 0], pgxdata) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_14_1.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p0_14_1.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata[:, :, 1], pgxdata) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_14_2.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p0_14_2.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata[:, :, 2], pgxdata) def test_ETS_C1P0_p0_15_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p0_15.j2k') + jfile = opj_data_file('input/conformance/p0_15.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read(rlevel=0) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_15_0.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p0_15_0.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata, pgxdata) def test_ETS_C1P0_p0_16_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p0_16.j2k') + jfile = opj_data_file('input/conformance/p0_16.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read(rlevel=0) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_16_0.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p0_16_0.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata, pgxdata) def test_ETS_C1P1_p1_01_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p1_01.j2k') + jfile = opj_data_file('input/conformance/p1_01.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read(rlevel=0) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p1_01_0.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p1_01_0.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata, pgxdata) def test_ETS_C1P1_p1_02_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p1_02.j2k') + jfile = opj_data_file('input/conformance/p1_02.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read(rlevel=0) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p1_02_0.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p1_02_0.pgx') pgxdata = read_pgx(pgxfile) self.assertTrue(peak_tolerance(jpdata[:, :, 0], pgxdata) < 5) self.assertTrue(mse(jpdata[:, :, 0], pgxdata) < 0.765) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p1_02_1.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p1_02_1.pgx') pgxdata = read_pgx(pgxfile) self.assertTrue(peak_tolerance(jpdata[:, :, 1], pgxdata) < 4) self.assertTrue(mse(jpdata[:, :, 1], pgxdata) < 0.616) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p1_02_2.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p1_02_2.pgx') pgxdata = read_pgx(pgxfile) self.assertTrue(peak_tolerance(jpdata[:, :, 2], pgxdata) < 6) self.assertTrue(mse(jpdata[:, :, 2], pgxdata) < 1.051) def test_ETS_C1P1_p1_03_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p1_03.j2k') + jfile = opj_data_file('input/conformance/p1_03.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read_bands() - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p1_03_0.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p1_03_0.pgx') pgxdata = read_pgx(pgxfile) self.assertTrue(peak_tolerance(jpdata[0], pgxdata) < 2) self.assertTrue(mse(jpdata[0], pgxdata) < 0.3) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p1_03_1.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p1_03_1.pgx') pgxdata = read_pgx(pgxfile) self.assertTrue(peak_tolerance(jpdata[1], pgxdata) < 2) self.assertTrue(mse(jpdata[1], pgxdata) < 0.21) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p1_03_2.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p1_03_2.pgx') pgxdata = read_pgx(pgxfile) self.assertTrue(peak_tolerance(jpdata[2], pgxdata) <= 1) self.assertTrue(mse(jpdata[2], pgxdata) < 0.2) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p1_03_3.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p1_03_3.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata[3], pgxdata) def test_ETS_C1P1_p1_04_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p1_04.j2k') + jfile = opj_data_file('input/conformance/p1_04.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read() - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p1_04_0.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p1_04_0.pgx') pgxdata = read_pgx(pgxfile) self.assertTrue(peak_tolerance(jpdata, pgxdata) < 624) self.assertTrue(mse(jpdata, pgxdata) < 3080) @unittest.skip("fprintf stderr output in r2343.") def test_ETS_C1P1_p1_05_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p1_05.j2k') + jfile = opj_data_file('input/conformance/p1_05.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read() - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p1_05_0.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p1_05_0.pgx') pgxdata = read_pgx(pgxfile) self.assertTrue(peak_tolerance(jpdata[:, :, 0], pgxdata) < 40) self.assertTrue(mse(jpdata[:, :, 0], pgxdata) < 8.458) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p1_05_1.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p1_05_1.pgx') pgxdata = read_pgx(pgxfile) self.assertTrue(peak_tolerance(jpdata[:, :, 1], pgxdata) < 40) self.assertTrue(mse(jpdata[:, :, 1], pgxdata) < 9.816) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p1_05_2.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p1_05_2.pgx') pgxdata = read_pgx(pgxfile) self.assertTrue(peak_tolerance(jpdata[:, :, 2], pgxdata) < 40) self.assertTrue(mse(jpdata[:, :, 2], pgxdata) < 10.154) @unittest.skip("fprintf stderr output in r2343.") def test_ETS_C1P1_p1_06_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p1_06.j2k') + jfile = opj_data_file('input/conformance/p1_06.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read() - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p1_06_0.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p1_06_0.pgx') pgxdata = read_pgx(pgxfile) self.assertTrue(peak_tolerance(jpdata[:, :, 0], pgxdata) < 2) self.assertTrue(mse(jpdata[:, :, 0], pgxdata) < 0.6) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p1_06_1.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p1_06_1.pgx') pgxdata = read_pgx(pgxfile) self.assertTrue(peak_tolerance(jpdata[:, :, 1], pgxdata) < 2) self.assertTrue(mse(jpdata[:, :, 1], pgxdata) < 0.6) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p1_06_2.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p1_06_2.pgx') pgxdata = read_pgx(pgxfile) self.assertTrue(peak_tolerance(jpdata[:, :, 2], pgxdata) < 2) self.assertTrue(mse(jpdata[:, :, 2], pgxdata) < 0.6) @unittest.skip("fprintf stderr output in r2343.") def test_ETS_C1P1_p1_07_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p1_07.j2k') + jfile = opj_data_file('input/conformance/p1_07.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read_bands() - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p1_07_0.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p1_07_0.pgx') pgxdata = read_pgx(pgxfile) self.assertTrue(peak_tolerance(jpdata[0], pgxdata) <= 0) self.assertTrue(mse(jpdata[0], pgxdata) <= 0) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p1_07_1.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p1_07_1.pgx') pgxdata = read_pgx(pgxfile) self.assertTrue(peak_tolerance(jpdata[1], pgxdata) <= 0) self.assertTrue(mse(jpdata[1], pgxdata) <= 0) def test_ETS_JP2_file1(self): - jfile = os.path.join(data_root, 'input/conformance/file1.jp2') + jfile = opj_data_file('input/conformance/file1.jp2') jp2k = Jp2k(jfile) jpdata = jp2k.read() self.assertEqual(jpdata.shape, (512, 768, 3)) def test_ETS_JP2_file2(self): - jfile = os.path.join(data_root, 'input/conformance/file2.jp2') + jfile = opj_data_file('input/conformance/file2.jp2') jp2k = Jp2k(jfile) jpdata = jp2k.read() self.assertEqual(jpdata.shape, (640, 480, 3)) def test_ETS_JP2_file3(self): - jfile = os.path.join(data_root, 'input/conformance/file3.jp2') + jfile = opj_data_file('input/conformance/file3.jp2') jp2k = Jp2k(jfile) jpdata = jp2k.read_bands() self.assertEqual(jpdata[0].shape, (640, 480)) @@ -767,59 +734,56 @@ class TestSuite(unittest.TestCase): self.assertEqual(jpdata[2].shape, (320, 240)) def test_ETS_JP2_file4(self): - jfile = os.path.join(data_root, 'input/conformance/file4.jp2') + jfile = opj_data_file('input/conformance/file4.jp2') jp2k = Jp2k(jfile) jpdata = jp2k.read() self.assertEqual(jpdata.shape, (512, 768)) def test_ETS_JP2_file5(self): - jfile = os.path.join(data_root, 'input/conformance/file5.jp2') + jfile = opj_data_file('input/conformance/file5.jp2') jp2k = Jp2k(jfile) jpdata = jp2k.read() self.assertEqual(jpdata.shape, (512, 768, 3)) def test_ETS_JP2_file6(self): - jfile = os.path.join(data_root, 'input/conformance/file6.jp2') + jfile = opj_data_file('input/conformance/file6.jp2') jp2k = Jp2k(jfile) jpdata = jp2k.read() self.assertEqual(jpdata.shape, (512, 768)) def test_ETS_JP2_file7(self): - jfile = os.path.join(data_root, 'input/conformance/file7.jp2') + jfile = opj_data_file('input/conformance/file7.jp2') jp2k = Jp2k(jfile) jpdata = jp2k.read() self.assertEqual(jpdata.shape, (640, 480, 3)) def test_ETS_JP2_file8(self): - jfile = os.path.join(data_root, 'input/conformance/file8.jp2') + jfile = opj_data_file('input/conformance/file8.jp2') jp2k = Jp2k(jfile) jpdata = jp2k.read() self.assertEqual(jpdata.shape, (400, 700)) def test_ETS_JP2_file9(self): - jfile = os.path.join(data_root, 'input/conformance/file9.jp2') + jfile = opj_data_file('input/conformance/file9.jp2') jp2k = Jp2k(jfile) jpdata = jp2k.read() self.assertEqual(jpdata.shape, (512, 768, 3)) def test_NR_DEC_Bretagne2_j2k_1_decode(self): - jfile = os.path.join(data_root, - 'input/nonregression/Bretagne2.j2k') + jfile = opj_data_file('input/nonregression/Bretagne2.j2k') jp2 = Jp2k(jfile) jp2.read() self.assertTrue(True) def test_NR_DEC__00042_j2k_2_decode(self): - jfile = os.path.join(data_root, - 'input/nonregression/_00042.j2k') + jfile = opj_data_file('input/nonregression/_00042.j2k') jp2 = Jp2k(jfile) jp2.read() self.assertTrue(True) @unittest.skip("fprintf stderr output in r2343.") def test_NR_DEC_123_j2c_3_decode(self): - jfile = os.path.join(data_root, - 'input/nonregression/123.j2c') + jfile = opj_data_file('input/nonregression/123.j2c') jp2 = Jp2k(jfile) jp2.read() self.assertTrue(True) @@ -827,8 +791,7 @@ class TestSuite(unittest.TestCase): @unittest.skipIf(sys.hexversion < 0x03020000, "Uses features introduced in 3.2.") def test_NR_DEC_broken_jp2_4_decode(self): - jfile = os.path.join(data_root, - 'input/nonregression/broken.jp2') + jfile = opj_data_file('input/nonregression/broken.jp2') with self.assertWarns(UserWarning): # colr box has bad length. jp2 = Jp2k(jfile) @@ -838,7 +801,7 @@ class TestSuite(unittest.TestCase): def test_NR_DEC_broken2_jp2_5_decode(self): # Null pointer access - jfile = os.path.join(data_root, 'input/nonregression/broken2.jp2') + jfile = opj_data_file('input/nonregression/broken2.jp2') with self.assertRaises(IOError): with warnings.catch_warnings(): # Invalid marker ID. @@ -849,7 +812,7 @@ class TestSuite(unittest.TestCase): @unittest.skipIf(sys.hexversion < 0x03020000, "Uses features introduced in 3.2.") def test_NR_DEC_broken3_jp2_6_decode(self): - jfile = os.path.join(data_root, 'input/nonregression/broken3.jp2') + jfile = opj_data_file('input/nonregression/broken3.jp2') with self.assertWarns(UserWarning): # colr box has bad length. j = Jp2k(jfile) @@ -858,7 +821,7 @@ class TestSuite(unittest.TestCase): j.read() def test_NR_DEC_broken4_jp2_7_decode(self): - jfile = os.path.join(data_root, 'input/nonregression/broken4.jp2') + jfile = opj_data_file('input/nonregression/broken4.jp2') with self.assertRaises(IOError): with warnings.catch_warnings(): # invalid number of subbands, bad marker ID @@ -868,105 +831,97 @@ class TestSuite(unittest.TestCase): @unittest.skip("fprintf stderr output in r2343.") def test_NR_DEC_bug_j2c_8_decode(self): - jfile = os.path.join(data_root, 'input/nonregression/bug.j2c') + jfile = opj_data_file('input/nonregression/bug.j2c') Jp2k(jfile).read() self.assertTrue(True) def test_NR_DEC_buxI_j2k_9_decode(self): - jfile = os.path.join(data_root, 'input/nonregression/buxI.j2k') + jfile = opj_data_file('input/nonregression/buxI.j2k') Jp2k(jfile).read() self.assertTrue(True) def test_NR_DEC_buxR_j2k_10_decode(self): - jfile = os.path.join(data_root, 'input/nonregression/buxR.j2k') + jfile = opj_data_file('input/nonregression/buxR.j2k') Jp2k(jfile).read() self.assertTrue(True) def test_NR_DEC_Cannotreaddatawithnosizeknown_j2k_11_decode(self): relpath = 'input/nonregression/Cannotreaddatawithnosizeknown.j2k' - jfile = os.path.join(data_root, relpath) + jfile = opj_data_file(relpath) Jp2k(jfile).read() self.assertTrue(True) def test_NR_DEC_cthead1_j2k_12_decode(self): - jfile = os.path.join(data_root, 'input/nonregression/cthead1.j2k') + jfile = opj_data_file('input/nonregression/cthead1.j2k') Jp2k(jfile).read() self.assertTrue(True) def test_NR_DEC_CT_Phillips_JPEG2K_Decompr_Problem_j2k_13_decode(self): relpath = 'input/nonregression/CT_Phillips_JPEG2K_Decompr_Problem.j2k' - jfile = os.path.join(data_root, relpath) + jfile = opj_data_file(relpath) Jp2k(jfile).read() self.assertTrue(True) @unittest.skip("fprintf stderr output in r2343.") def test_NR_DEC_illegalcolortransform_j2k_14_decode(self): # Stream too short, expected SOT. - jfile = os.path.join(data_root, - 'input/nonregression/illegalcolortransform.j2k') + jfile = opj_data_file('input/nonregression/illegalcolortransform.j2k') Jp2k(jfile).read() self.assertTrue(True) def test_NR_DEC_j2k32_j2k_15_decode(self): - jfile = os.path.join(data_root, 'input/nonregression/j2k32.j2k') + jfile = opj_data_file('input/nonregression/j2k32.j2k') Jp2k(jfile).read() self.assertTrue(True) def test_NR_DEC_kakadu_v4_4_openjpegv2_broken_j2k_16_decode(self): relpath = 'input/nonregression/kakadu_v4-4_openjpegv2_broken.j2k' - jfile = os.path.join(data_root, relpath) + jfile = opj_data_file(relpath) Jp2k(jfile).read() self.assertTrue(True) def test_NR_DEC_MarkerIsNotCompliant_j2k_17_decode(self): - jfile = os.path.join(data_root, - 'input/nonregression/MarkerIsNotCompliant.j2k') + jfile = opj_data_file('input/nonregression/MarkerIsNotCompliant.j2k') Jp2k(jfile).read() self.assertTrue(True) def test_NR_DEC_Marrin_jp2_18_decode(self): - jfile = os.path.join(data_root, - 'input/nonregression/Marrin.jp2') + jfile = opj_data_file('input/nonregression/Marrin.jp2') Jp2k(jfile).read() self.assertTrue(True) def test_NR_DEC_merged_jp2_19_decode(self): - jfile = os.path.join(data_root, - 'input/nonregression/merged.jp2') + jfile = opj_data_file('input/nonregression/merged.jp2') Jp2k(jfile).read_bands() self.assertTrue(True) def test_NR_DEC_movie_00000_j2k_20_decode(self): - jfile = os.path.join(data_root, - 'input/nonregression/movie_00000.j2k') + jfile = opj_data_file('input/nonregression/movie_00000.j2k') Jp2k(jfile).read() self.assertTrue(True) def test_NR_DEC_movie_00001_j2k_21_decode(self): - jfile = os.path.join(data_root, 'input/nonregression/movie_00001.j2k') + jfile = opj_data_file('input/nonregression/movie_00001.j2k') Jp2k(jfile).read() self.assertTrue(True) def test_NR_DEC_movie_00002_j2k_22_decode(self): - jfile = os.path.join(data_root, 'input/nonregression/movie_00002.j2k') + jfile = opj_data_file('input/nonregression/movie_00002.j2k') Jp2k(jfile).read() self.assertTrue(True) def test_NR_DEC_orb_blue_lin_j2k_j2k_23_decode(self): - jfile = os.path.join(data_root, - 'input/nonregression/orb-blue10-lin-j2k.j2k') + jfile = opj_data_file('input/nonregression/orb-blue10-lin-j2k.j2k') Jp2k(jfile).read() self.assertTrue(True) def test_NR_DEC_orb_blue_win_j2k_j2k_24_decode(self): - jfile = os.path.join(data_root, - 'input/nonregression/orb-blue10-win-j2k.j2k') + jfile = opj_data_file('input/nonregression/orb-blue10-win-j2k.j2k') Jp2k(jfile).read() self.assertTrue(True) def test_NR_DEC_orb_blue_lin_jp2_25_decode(self): - jfile = os.path.join(data_root, - 'input/nonregression/orb-blue10-lin-jp2.jp2') + jfile = opj_data_file('input/nonregression/orb-blue10-lin-jp2.jp2') with warnings.catch_warnings(): # This file has an invalid ICC profile warnings.simplefilter("ignore") @@ -974,28 +929,24 @@ class TestSuite(unittest.TestCase): self.assertTrue(True) def test_NR_DEC_orb_blue_win_jp2_26_decode(self): - jfile = os.path.join(data_root, - 'input/nonregression/orb-blue10-win-jp2.jp2') + jfile = opj_data_file('input/nonregression/orb-blue10-win-jp2.jp2') Jp2k(jfile).read() self.assertTrue(True) def test_NR_DEC_relax_jp2_27_decode(self): - jfile = os.path.join(data_root, - 'input/nonregression/relax.jp2') + jfile = opj_data_file('input/nonregression/relax.jp2') Jp2k(jfile).read() self.assertTrue(True) def test_NR_DEC_test_lossless_j2k_28_decode(self): - jfile = os.path.join(data_root, - 'input/nonregression/test_lossless.j2k') + jfile = opj_data_file('input/nonregression/test_lossless.j2k') Jp2k(jfile).read() self.assertTrue(True) @unittest.skipIf(OPENJP2_IS_V2_OFFICIAL, "Test known to fail in v2.0.0 official") def test_NR_DEC_text_GBR_jp2_29_decode(self): - jfile = os.path.join(data_root, - 'input/nonregression/text_GBR.jp2') + jfile = opj_data_file('input/nonregression/text_GBR.jp2') with warnings.catch_warnings(): # brand is 'jp2 ', but has any icc profile. warnings.simplefilter("ignore") @@ -1004,38 +955,33 @@ class TestSuite(unittest.TestCase): self.assertTrue(True) def test_NR_DEC_pacs_ge_j2k_30_decode(self): - jfile = os.path.join(data_root, - 'input/nonregression/pacs.ge.j2k') + jfile = opj_data_file('input/nonregression/pacs.ge.j2k') Jp2k(jfile).read() self.assertTrue(True) @unittest.skipIf(OPENJP2_IS_V2_OFFICIAL, "Test known to fail in v2.0.0 official") def test_NR_DEC_kodak_2layers_lrcp_j2c_31_decode(self): - jfile = os.path.join(data_root, - 'input/nonregression/kodak_2layers_lrcp.j2c') + jfile = opj_data_file('input/nonregression/kodak_2layers_lrcp.j2c') Jp2k(jfile).read() self.assertTrue(True) @unittest.skipIf(OPENJP2_IS_V2_OFFICIAL, "Test known to fail in v2.0.0 official") def test_NR_DEC_kodak_2layers_lrcp_j2c_32_decode(self): - jfile = os.path.join(data_root, - 'input/nonregression/kodak_2layers_lrcp.j2c') + jfile = opj_data_file('input/nonregression/kodak_2layers_lrcp.j2c') Jp2k(jfile).read(layer=2) self.assertTrue(True) def test_NR_DEC_issue104_jpxstream_jp2_33_decode(self): - jfile = os.path.join(data_root, - 'input/nonregression/issue104_jpxstream.jp2') + jfile = opj_data_file('input/nonregression/issue104_jpxstream.jp2') Jp2k(jfile).read() self.assertTrue(True) @unittest.skipIf(OPENJP2_IS_V2_OFFICIAL, "Test known to fail in v2.0.0 official") def test_NR_DEC_mem_b2ace68c_1381_jp2_34_decode(self): - jfile = os.path.join(data_root, - 'input/nonregression/mem-b2ace68c-1381.jp2') + jfile = opj_data_file('input/nonregression/mem-b2ace68c-1381.jp2') with warnings.catch_warnings(): # This file has a bad pclr box, we test for this elsewhere. warnings.simplefilter("ignore") @@ -1046,14 +992,13 @@ class TestSuite(unittest.TestCase): @unittest.skipIf(OPENJP2_IS_V2_OFFICIAL, "Test known to fail in v2.0.0 official") def test_NR_DEC_mem_b2b86b74_2753_jp2_35_decode(self): - jfile = os.path.join(data_root, - 'input/nonregression/mem-b2b86b74-2753.jp2') + jfile = opj_data_file('input/nonregression/mem-b2b86b74-2753.jp2') Jp2k(jfile).read() self.assertTrue(True) def test_NR_DEC_gdal_fuzzer_unchecked_num_resolutions_jp2_36_decode(self): f = 'input/nonregression/gdal_fuzzer_unchecked_numresolutions.jp2' - jfile = os.path.join(data_root, f) + jfile = opj_data_file(f) with warnings.catch_warnings(): # Invalid number of resolutions. warnings.simplefilter("ignore") @@ -1067,7 +1012,7 @@ class TestSuite(unittest.TestCase): lst = ('input', 'nonregression', 'gdal_fuzzer_assert_in_opj_j2k_read_SQcd_SQcc.patch.jp2') - jfile = os.path.join(data_root, '/'.join(lst)) + jfile = opj_data_file('/'.join(lst)) with warnings.catch_warnings(): # Invalid component number. warnings.simplefilter("ignore") @@ -1079,7 +1024,7 @@ class TestSuite(unittest.TestCase): "Test not in done in v2.0.0 official") def test_NR_DEC_gdal_fuzzer_check_number_of_tiles_jp2_38_decode(self): relpath = 'input/nonregression/gdal_fuzzer_check_number_of_tiles.jp2' - jfile = os.path.join(data_root, relpath) + jfile = opj_data_file(relpath) with warnings.catch_warnings(): # Invalid number of tiles. warnings.simplefilter("ignore") @@ -1091,7 +1036,7 @@ class TestSuite(unittest.TestCase): "Test not in done in v2.0.0 official") def test_NR_DEC_gdal_fuzzer_check_comp_dx_dy_jp2_39_decode(self): relpath = 'input/nonregression/gdal_fuzzer_check_comp_dx_dy.jp2' - jfile = os.path.join(data_root, relpath) + jfile = opj_data_file(relpath) with warnings.catch_warnings(): # Invalid subsampling value warnings.simplefilter("ignore") @@ -1099,7 +1044,7 @@ class TestSuite(unittest.TestCase): Jp2k(jfile).read() def test_NR_DEC_file_409752_jp2_40_decode(self): - jfile = os.path.join(data_root, 'input/nonregression/file409752.jp2') + jfile = opj_data_file('input/nonregression/file409752.jp2') with self.assertRaises(RuntimeError): Jp2k(jfile).read() @@ -1111,69 +1056,68 @@ class TestSuite(unittest.TestCase): # Has an 'XML ' box instead of 'xml '. Yes that is pedantic, but it # really does deserve a warning. relpath = 'input/nonregression/issue188_beach_64bitsbox.jp2' - jfile = os.path.join(data_root, relpath) + jfile = opj_data_file(relpath) with self.assertWarns(UserWarning): Jp2k(jfile).read() @unittest.skipIf(OPENJP2_IS_V2_OFFICIAL, "Test not in done in v2.0.0 official") def test_NR_DEC_issue206_image_000_jp2_42_decode(self): - jfile = os.path.join(data_root, - 'input/nonregression/issue206_image-000.jp2') + jfile = opj_data_file('input/nonregression/issue206_image-000.jp2') Jp2k(jfile).read() self.assertTrue(True) def test_NR_DEC_p1_04_j2k_43_decode(self): - jfile = os.path.join(data_root, 'input/conformance/p1_04.j2k') + jfile = opj_data_file('input/conformance/p1_04.j2k') jp2k = Jp2k(jfile) ssdata = jp2k.read(area=(0, 0, 1024, 1024)) odata = jp2k.read() np.testing.assert_array_equal(ssdata, odata) def test_NR_DEC_p1_04_j2k_44_decode(self): - jfile = os.path.join(data_root, 'input/conformance/p1_04.j2k') + jfile = opj_data_file('input/conformance/p1_04.j2k') jp2k = Jp2k(jfile) ssdata = jp2k.read(area=(640, 512, 768, 640)) odata = jp2k.read() np.testing.assert_array_equal(ssdata, odata[640:768, 512:640]) def test_NR_DEC_p1_04_j2k_45_decode(self): - jfile = os.path.join(data_root, 'input/conformance/p1_04.j2k') + jfile = opj_data_file('input/conformance/p1_04.j2k') jp2k = Jp2k(jfile) ssdata = jp2k.read(area=(896, 896, 1024, 1024)) odata = jp2k.read() np.testing.assert_array_equal(ssdata, odata[896:1024, 896:1024]) def test_NR_DEC_p1_04_j2k_46_decode(self): - jfile = os.path.join(data_root, 'input/conformance/p1_04.j2k') + jfile = opj_data_file('input/conformance/p1_04.j2k') jp2k = Jp2k(jfile) ssdata = jp2k.read(area=(500, 100, 800, 300)) odata = jp2k.read() np.testing.assert_array_equal(ssdata, odata[500:800, 100:300]) def test_NR_DEC_p1_04_j2k_47_decode(self): - jfile = os.path.join(data_root, 'input/conformance/p1_04.j2k') + jfile = opj_data_file('input/conformance/p1_04.j2k') jp2k = Jp2k(jfile) ssdata = jp2k.read(area=(520, 260, 600, 360)) odata = jp2k.read() np.testing.assert_array_equal(ssdata, odata[520:600, 260:360]) def test_NR_DEC_p1_04_j2k_48_decode(self): - jfile = os.path.join(data_root, 'input/conformance/p1_04.j2k') + jfile = opj_data_file('input/conformance/p1_04.j2k') jp2k = Jp2k(jfile) ssdata = jp2k.read(area=(520, 260, 660, 360)) odata = jp2k.read() np.testing.assert_array_equal(ssdata, odata[520:660, 260:360]) def test_NR_DEC_p1_04_j2k_49_decode(self): - jfile = os.path.join(data_root, 'input/conformance/p1_04.j2k') + jfile = opj_data_file('input/conformance/p1_04.j2k') jp2k = Jp2k(jfile) ssdata = jp2k.read(area=(520, 360, 600, 400)) odata = jp2k.read() np.testing.assert_array_equal(ssdata, odata[520:600, 360:400]) def test_NR_DEC_p1_04_j2k_50_decode(self): - jfile = os.path.join(data_root, 'input/conformance/p1_04.j2k') + jfile = opj_data_file('input/conformance/p1_04.j2k') jp2k = Jp2k(jfile) ssdata = jp2k.read(area=(0, 0, 1024, 1024), rlevel=2) odata = jp2k.read(rlevel=2) @@ -1181,70 +1125,70 @@ class TestSuite(unittest.TestCase): np.testing.assert_array_equal(ssdata, odata[0:256, 0:256]) def test_NR_DEC_p1_04_j2k_51_decode(self): - jfile = os.path.join(data_root, 'input/conformance/p1_04.j2k') + jfile = opj_data_file('input/conformance/p1_04.j2k') jp2k = Jp2k(jfile) ssdata = jp2k.read(area=(640, 512, 768, 640), rlevel=2) odata = jp2k.read(rlevel=2) np.testing.assert_array_equal(ssdata, odata[160:192, 128:160]) def test_NR_DEC_p1_04_j2k_52_decode(self): - jfile = os.path.join(data_root, 'input/conformance/p1_04.j2k') + jfile = opj_data_file('input/conformance/p1_04.j2k') jp2k = Jp2k(jfile) ssdata = jp2k.read(area=(896, 896, 1024, 1024), rlevel=2) odata = jp2k.read(rlevel=2) np.testing.assert_array_equal(ssdata, odata[224:352, 224:352]) def test_NR_DEC_p1_04_j2k_53_decode(self): - jfile = os.path.join(data_root, 'input/conformance/p1_04.j2k') + jfile = opj_data_file('input/conformance/p1_04.j2k') jp2k = Jp2k(jfile) ssdata = jp2k.read(area=(500, 100, 800, 300), rlevel=2) odata = jp2k.read(rlevel=2) np.testing.assert_array_equal(ssdata, odata[125:200, 25:75]) def test_NR_DEC_p1_04_j2k_54_decode(self): - jfile = os.path.join(data_root, 'input/conformance/p1_04.j2k') + jfile = opj_data_file('input/conformance/p1_04.j2k') jp2k = Jp2k(jfile) ssdata = jp2k.read(area=(520, 260, 600, 360), rlevel=2) odata = jp2k.read(rlevel=2) np.testing.assert_array_equal(ssdata, odata[130:150, 65:90]) def test_NR_DEC_p1_04_j2k_55_decode(self): - jfile = os.path.join(data_root, 'input/conformance/p1_04.j2k') + jfile = opj_data_file('input/conformance/p1_04.j2k') jp2k = Jp2k(jfile) ssdata = jp2k.read(area=(520, 260, 660, 360), rlevel=2) odata = jp2k.read(rlevel=2) np.testing.assert_array_equal(ssdata, odata[130:165, 65:90]) def test_NR_DEC_p1_04_j2k_56_decode(self): - jfile = os.path.join(data_root, 'input/conformance/p1_04.j2k') + jfile = opj_data_file('input/conformance/p1_04.j2k') jp2k = Jp2k(jfile) ssdata = jp2k.read(area=(520, 360, 600, 400), rlevel=2) odata = jp2k.read(rlevel=2) np.testing.assert_array_equal(ssdata, odata[130:150, 90:100]) def test_NR_DEC_p1_04_j2k_57_decode(self): - jfile = os.path.join(data_root, 'input/conformance/p1_04.j2k') + jfile = opj_data_file('input/conformance/p1_04.j2k') jp2k = Jp2k(jfile) tdata = jp2k.read(tile=63) # last tile odata = jp2k.read() np.testing.assert_array_equal(tdata, odata[896:1024, 896:1024]) def test_NR_DEC_p1_04_j2k_58_decode(self): - jfile = os.path.join(data_root, 'input/conformance/p1_04.j2k') + jfile = opj_data_file('input/conformance/p1_04.j2k') jp2k = Jp2k(jfile) tdata = jp2k.read(tile=63, rlevel=2) # last tile odata = jp2k.read(rlevel=2) np.testing.assert_array_equal(tdata, odata[224:256, 224:256]) def test_NR_DEC_p1_04_j2k_59_decode(self): - jfile = os.path.join(data_root, 'input/conformance/p1_04.j2k') + jfile = opj_data_file('input/conformance/p1_04.j2k') jp2k = Jp2k(jfile) tdata = jp2k.read(tile=12) # 2nd row, 5th column odata = jp2k.read() np.testing.assert_array_equal(tdata, odata[128:256, 512:640]) def test_NR_DEC_p1_04_j2k_60_decode(self): - jfile = os.path.join(data_root, 'input/conformance/p1_04.j2k') + jfile = opj_data_file('input/conformance/p1_04.j2k') jp2k = Jp2k(jfile) tdata = jp2k.read(tile=12, rlevel=1) # 2nd row, 5th column odata = jp2k.read(rlevel=1) @@ -1252,7 +1196,7 @@ class TestSuite(unittest.TestCase): @unittest.skip("fprintf stderr output in r2343.") def test_NR_DEC_p1_06_j2k_61_decode(self): - jfile = os.path.join(data_root, 'input/conformance/p1_06.j2k') + jfile = opj_data_file('input/conformance/p1_06.j2k') jp2k = Jp2k(jfile) ssdata = jp2k.read(area=(0, 0, 12, 12)) odata = jp2k.read() @@ -1260,7 +1204,7 @@ class TestSuite(unittest.TestCase): @unittest.skip("fprintf stderr output in r2343.") def test_NR_DEC_p1_06_j2k_62_decode(self): - jfile = os.path.join(data_root, 'input/conformance/p1_06.j2k') + jfile = opj_data_file('input/conformance/p1_06.j2k') jp2k = Jp2k(jfile) ssdata = jp2k.read(area=(1, 8, 8, 11)) odata = jp2k.read() @@ -1268,7 +1212,7 @@ class TestSuite(unittest.TestCase): @unittest.skip("fprintf stderr output in r2343.") def test_NR_DEC_p1_06_j2k_63_decode(self): - jfile = os.path.join(data_root, 'input/conformance/p1_06.j2k') + jfile = opj_data_file('input/conformance/p1_06.j2k') jp2k = Jp2k(jfile) ssdata = jp2k.read(area=(9, 9, 12, 12)) odata = jp2k.read() @@ -1276,7 +1220,7 @@ class TestSuite(unittest.TestCase): @unittest.skip("fprintf stderr output in r2343.") def test_NR_DEC_p1_06_j2k_64_decode(self): - jfile = os.path.join(data_root, 'input/conformance/p1_06.j2k') + jfile = opj_data_file('input/conformance/p1_06.j2k') jp2k = Jp2k(jfile) ssdata = jp2k.read(area=(10, 4, 12, 10)) odata = jp2k.read() @@ -1284,7 +1228,7 @@ class TestSuite(unittest.TestCase): @unittest.skip("fprintf stderr output in r2343.") def test_NR_DEC_p1_06_j2k_65_decode(self): - jfile = os.path.join(data_root, 'input/conformance/p1_06.j2k') + jfile = opj_data_file('input/conformance/p1_06.j2k') jp2k = Jp2k(jfile) ssdata = jp2k.read(area=(3, 3, 9, 9)) odata = jp2k.read() @@ -1292,7 +1236,7 @@ class TestSuite(unittest.TestCase): @unittest.skip("fprintf stderr output in r2343.") def test_NR_DEC_p1_06_j2k_66_decode(self): - jfile = os.path.join(data_root, 'input/conformance/p1_06.j2k') + jfile = opj_data_file('input/conformance/p1_06.j2k') jp2k = Jp2k(jfile) ssdata = jp2k.read(area=(4, 4, 7, 7)) odata = jp2k.read() @@ -1300,7 +1244,7 @@ class TestSuite(unittest.TestCase): @unittest.skip("fprintf stderr output in r2343.") def test_NR_DEC_p1_06_j2k_67_decode(self): - jfile = os.path.join(data_root, 'input/conformance/p1_06.j2k') + jfile = opj_data_file('input/conformance/p1_06.j2k') jp2k = Jp2k(jfile) ssdata = jp2k.read(area=(4, 4, 5, 5)) odata = jp2k.read() @@ -1308,7 +1252,7 @@ class TestSuite(unittest.TestCase): @unittest.skip("fprintf stderr output in r2343.") def test_NR_DEC_p1_06_j2k_68_decode(self): - jfile = os.path.join(data_root, 'input/conformance/p1_06.j2k') + jfile = opj_data_file('input/conformance/p1_06.j2k') jp2k = Jp2k(jfile) ssdata = jp2k.read(area=(0, 0, 12, 12), rlevel=1) odata = jp2k.read(rlevel=1) @@ -1316,51 +1260,51 @@ class TestSuite(unittest.TestCase): @unittest.skip("fprintf stderr output in r2343.") def test_NR_DEC_p1_06_j2k_69_decode(self): - jfile = os.path.join(data_root, 'input/conformance/p1_06.j2k') + jfile = opj_data_file('input/conformance/p1_06.j2k') jp2k = Jp2k(jfile) ssdata = jp2k.read(area=(1, 8, 8, 11), rlevel=1) self.assertEqual(ssdata.shape, (3, 2, 3)) def test_NR_DEC_p1_06_j2k_70_decode(self): - jfile = os.path.join(data_root, 'input/conformance/p1_06.j2k') + jfile = opj_data_file('input/conformance/p1_06.j2k') jp2k = Jp2k(jfile) ssdata = jp2k.read(area=(9, 9, 12, 12), rlevel=1) self.assertEqual(ssdata.shape, (1, 1, 3)) def test_NR_DEC_p1_06_j2k_71_decode(self): - jfile = os.path.join(data_root, 'input/conformance/p1_06.j2k') + jfile = opj_data_file('input/conformance/p1_06.j2k') jp2k = Jp2k(jfile) ssdata = jp2k.read(area=(10, 4, 12, 10), rlevel=1) self.assertEqual(ssdata.shape, (1, 3, 3)) def test_NR_DEC_p1_06_j2k_72_decode(self): - jfile = os.path.join(data_root, 'input/conformance/p1_06.j2k') + jfile = opj_data_file('input/conformance/p1_06.j2k') jp2k = Jp2k(jfile) ssdata = jp2k.read(area=(3, 3, 9, 9), rlevel=1) self.assertEqual(ssdata.shape, (3, 3, 3)) def test_NR_DEC_p1_06_j2k_73_decode(self): - jfile = os.path.join(data_root, 'input/conformance/p1_06.j2k') + jfile = opj_data_file('input/conformance/p1_06.j2k') jp2k = Jp2k(jfile) ssdata = jp2k.read(area=(4, 4, 7, 7), rlevel=1) self.assertEqual(ssdata.shape, (2, 2, 3)) def test_NR_DEC_p1_06_j2k_74_decode(self): - jfile = os.path.join(data_root, 'input/conformance/p1_06.j2k') + jfile = opj_data_file('input/conformance/p1_06.j2k') jp2k = Jp2k(jfile) ssdata = jp2k.read(area=(4, 4, 5, 5), rlevel=1) self.assertEqual(ssdata.shape, (1, 1, 3)) def test_NR_DEC_p1_06_j2k_75_decode(self): # Image size would be 0 x 0. - jfile = os.path.join(data_root, 'input/conformance/p1_06.j2k') + jfile = opj_data_file('input/conformance/p1_06.j2k') jp2k = Jp2k(jfile) with self.assertRaises((IOError, OSError)): jp2k.read(area=(9, 9, 12, 12), rlevel=2) @unittest.skip("fprintf stderr output in r2343.") def test_NR_DEC_p1_06_j2k_76_decode(self): - jfile = os.path.join(data_root, 'input/conformance/p1_06.j2k') + jfile = opj_data_file('input/conformance/p1_06.j2k') jp2k = Jp2k(jfile) fulldata = jp2k.read() tiledata = jp2k.read(tile=0) @@ -1368,7 +1312,7 @@ class TestSuite(unittest.TestCase): @unittest.skip("fprintf stderr output in r2343.") def test_NR_DEC_p1_06_j2k_77_decode(self): - jfile = os.path.join(data_root, 'input/conformance/p1_06.j2k') + jfile = opj_data_file('input/conformance/p1_06.j2k') jp2k = Jp2k(jfile) fulldata = jp2k.read() tiledata = jp2k.read(tile=5) @@ -1376,7 +1320,7 @@ class TestSuite(unittest.TestCase): @unittest.skip("fprintf stderr output in r2343.") def test_NR_DEC_p1_06_j2k_78_decode(self): - jfile = os.path.join(data_root, 'input/conformance/p1_06.j2k') + jfile = opj_data_file('input/conformance/p1_06.j2k') jp2k = Jp2k(jfile) fulldata = jp2k.read() with warnings.catch_warnings(): @@ -1386,7 +1330,7 @@ class TestSuite(unittest.TestCase): @unittest.skip("fprintf stderr output in r2343.") def test_NR_DEC_p1_06_j2k_79_decode(self): - jfile = os.path.join(data_root, 'input/conformance/p1_06.j2k') + jfile = opj_data_file('input/conformance/p1_06.j2k') jp2k = Jp2k(jfile) fulldata = jp2k.read() with warnings.catch_warnings(): @@ -1397,7 +1341,7 @@ class TestSuite(unittest.TestCase): @unittest.skip("fprintf stderr output in r2343.") def test_NR_DEC_p1_06_j2k_80_decode(self): # Just read the data, don't bother verifying. - jfile = os.path.join(data_root, 'input/conformance/p1_06.j2k') + jfile = opj_data_file('input/conformance/p1_06.j2k') jp2k = Jp2k(jfile) with warnings.catch_warnings(): warnings.simplefilter("ignore") @@ -1406,7 +1350,7 @@ class TestSuite(unittest.TestCase): @unittest.skip("fprintf stderr output in r2343.") def test_NR_DEC_p1_06_j2k_81_decode(self): # Just read the data, don't bother verifying. - jfile = os.path.join(data_root, 'input/conformance/p1_06.j2k') + jfile = opj_data_file('input/conformance/p1_06.j2k') jp2k = Jp2k(jfile) with warnings.catch_warnings(): warnings.simplefilter("ignore") @@ -1415,7 +1359,7 @@ class TestSuite(unittest.TestCase): @unittest.skip("fprintf stderr output in r2343.") def test_NR_DEC_p1_06_j2k_82_decode(self): # Just read the data, don't bother verifying. - jfile = os.path.join(data_root, 'input/conformance/p1_06.j2k') + jfile = opj_data_file('input/conformance/p1_06.j2k') jp2k = Jp2k(jfile) with warnings.catch_warnings(): warnings.simplefilter("ignore") @@ -1424,7 +1368,7 @@ class TestSuite(unittest.TestCase): @unittest.skip("fprintf stderr output in r2343.") def test_NR_DEC_p1_06_j2k_83_decode(self): # tile size is 3x3. Reducing two levels results in no data. - jfile = os.path.join(data_root, 'input/conformance/p1_06.j2k') + jfile = opj_data_file('input/conformance/p1_06.j2k') jp2k = Jp2k(jfile) with warnings.catch_warnings(): warnings.simplefilter("ignore") @@ -1434,96 +1378,96 @@ class TestSuite(unittest.TestCase): @unittest.skip("fprintf stderr output in r2343.") def test_NR_DEC_p1_06_j2k_84_decode(self): # Just read the data, don't bother verifying. - jfile = os.path.join(data_root, 'input/conformance/p1_06.j2k') + jfile = opj_data_file('input/conformance/p1_06.j2k') jp2k = Jp2k(jfile) jp2k.read(rlevel=4) def test_NR_DEC_p0_04_j2k_85_decode(self): - jfile = os.path.join(data_root, 'input/conformance/p0_04.j2k') + jfile = opj_data_file('input/conformance/p0_04.j2k') jp2k = Jp2k(jfile) ssdata = jp2k.read(area=(0, 0, 256, 256)) fulldata = jp2k.read() np.testing.assert_array_equal(fulldata[0:256, 0:256], ssdata) def test_NR_DEC_p0_04_j2k_86_decode(self): - jfile = os.path.join(data_root, 'input/conformance/p0_04.j2k') + jfile = opj_data_file('input/conformance/p0_04.j2k') jp2k = Jp2k(jfile) ssdata = jp2k.read(area=(0, 128, 128, 256)) fulldata = jp2k.read() np.testing.assert_array_equal(fulldata[0:128, 128:256], ssdata) def test_NR_DEC_p0_04_j2k_87_decode(self): - jfile = os.path.join(data_root, 'input/conformance/p0_04.j2k') + jfile = opj_data_file('input/conformance/p0_04.j2k') jp2k = Jp2k(jfile) ssdata = jp2k.read(area=(10, 50, 200, 120)) fulldata = jp2k.read() np.testing.assert_array_equal(fulldata[10:200, 50:120], ssdata) def test_NR_DEC_p0_04_j2k_88_decode(self): - jfile = os.path.join(data_root, 'input/conformance/p0_04.j2k') + jfile = opj_data_file('input/conformance/p0_04.j2k') jp2k = Jp2k(jfile) ssdata = jp2k.read(area=(150, 10, 210, 190)) fulldata = jp2k.read() np.testing.assert_array_equal(fulldata[150:210, 10:190], ssdata) def test_NR_DEC_p0_04_j2k_89_decode(self): - jfile = os.path.join(data_root, 'input/conformance/p0_04.j2k') + jfile = opj_data_file('input/conformance/p0_04.j2k') jp2k = Jp2k(jfile) ssdata = jp2k.read(area=(80, 100, 150, 200)) fulldata = jp2k.read() np.testing.assert_array_equal(fulldata[80:150, 100:200], ssdata) def test_NR_DEC_p0_04_j2k_90_decode(self): - jfile = os.path.join(data_root, 'input/conformance/p0_04.j2k') + jfile = opj_data_file('input/conformance/p0_04.j2k') jp2k = Jp2k(jfile) ssdata = jp2k.read(area=(20, 150, 50, 200)) fulldata = jp2k.read() np.testing.assert_array_equal(fulldata[20:50, 150:200], ssdata) def test_NR_DEC_p0_04_j2k_91_decode(self): - jfile = os.path.join(data_root, 'input/conformance/p0_04.j2k') + jfile = opj_data_file('input/conformance/p0_04.j2k') jp2k = Jp2k(jfile) ssdata = jp2k.read(area=(0, 0, 256, 256), rlevel=2) fulldata = jp2k.read(rlevel=2) np.testing.assert_array_equal(fulldata[0:64, 0:64], ssdata) def test_NR_DEC_p0_04_j2k_92_decode(self): - jfile = os.path.join(data_root, 'input/conformance/p0_04.j2k') + jfile = opj_data_file('input/conformance/p0_04.j2k') jp2k = Jp2k(jfile) ssdata = jp2k.read(area=(0, 128, 128, 256), rlevel=2) fulldata = jp2k.read(rlevel=2) np.testing.assert_array_equal(fulldata[0:32, 32:64], ssdata) def test_NR_DEC_p0_04_j2k_93_decode(self): - jfile = os.path.join(data_root, 'input/conformance/p0_04.j2k') + jfile = opj_data_file('input/conformance/p0_04.j2k') jp2k = Jp2k(jfile) ssdata = jp2k.read(area=(10, 50, 200, 120), rlevel=2) fulldata = jp2k.read(rlevel=2) np.testing.assert_array_equal(fulldata[3:50, 13:30], ssdata) def test_NR_DEC_p0_04_j2k_94_decode(self): - jfile = os.path.join(data_root, 'input/conformance/p0_04.j2k') + jfile = opj_data_file('input/conformance/p0_04.j2k') jp2k = Jp2k(jfile) ssdata = jp2k.read(area=(150, 10, 210, 190), rlevel=2) fulldata = jp2k.read(rlevel=2) np.testing.assert_array_equal(fulldata[38:53, 3:48], ssdata) def test_NR_DEC_p0_04_j2k_95_decode(self): - jfile = os.path.join(data_root, 'input/conformance/p0_04.j2k') + jfile = opj_data_file('input/conformance/p0_04.j2k') jp2k = Jp2k(jfile) ssdata = jp2k.read(area=(80, 100, 150, 200), rlevel=2) fulldata = jp2k.read(rlevel=2) np.testing.assert_array_equal(fulldata[20:38, 25:50], ssdata) def test_NR_DEC_p0_04_j2k_96_decode(self): - jfile = os.path.join(data_root, 'input/conformance/p0_04.j2k') + jfile = opj_data_file('input/conformance/p0_04.j2k') jp2k = Jp2k(jfile) ssdata = jp2k.read(area=(20, 150, 50, 200), rlevel=2) fulldata = jp2k.read(rlevel=2) np.testing.assert_array_equal(fulldata[5:13, 38:50], ssdata) -@unittest.skipIf(data_root is None, +@unittest.skipIf(OPJ_DATA_ROOT is None, "OPJ_DATA_ROOT environment variable not set") class TestSuiteDump(unittest.TestCase): @@ -1534,7 +1478,7 @@ class TestSuiteDump(unittest.TestCase): pass def test_NR_p0_01_dump(self): - jfile = os.path.join(data_root, 'input/conformance/p0_01.j2k') + jfile = opj_data_file('input/conformance/p0_01.j2k') c = Jp2k(jfile).get_codestream(header_only=False) # Segment IDs. @@ -1601,7 +1545,7 @@ class TestSuiteDump(unittest.TestCase): self.assertEqual(c.segment[4].tnsot, 1) def test_NR_p0_02_dump(self): - jfile = os.path.join(data_root, 'input/conformance/p0_02.j2k') + jfile = opj_data_file('input/conformance/p0_02.j2k') c = Jp2k(jfile).get_codestream(header_only=False) # SIZ: Image and tile size @@ -1707,7 +1651,7 @@ class TestSuiteDump(unittest.TestCase): self.assertEqual(c.segment[-1].marker_id, 'EOC') def test_NR_p0_03_dump(self): - jfile = os.path.join(data_root, 'input/conformance/p0_03.j2k') + jfile = opj_data_file('input/conformance/p0_03.j2k') c = Jp2k(jfile).get_codestream(header_only=False) # SIZ: Image and tile size @@ -1824,7 +1768,7 @@ class TestSuiteDump(unittest.TestCase): self.assertEqual(c.segment[13].marker_id, 'SOD') def test_NR_p0_04_dump(self): - jfile = os.path.join(data_root, 'input/conformance/p0_04.j2k') + jfile = opj_data_file('input/conformance/p0_04.j2k') c = Jp2k(jfile).get_codestream(header_only=False) # SIZ: Image and tile size @@ -1932,7 +1876,7 @@ class TestSuiteDump(unittest.TestCase): self.assertEqual(c.segment[8].marker_id, 'SOD') def test_NR_p0_05_dump(self): - jfile = os.path.join(data_root, 'input/conformance/p0_05.j2k') + jfile = opj_data_file('input/conformance/p0_05.j2k') c = Jp2k(jfile).get_codestream(header_only=False) # SIZ: Image and tile size @@ -2076,7 +2020,7 @@ class TestSuiteDump(unittest.TestCase): self.assertEqual(c.segment[11].marker_id, 'SOD') def test_NR_p0_06_dump(self): - jfile = os.path.join(data_root, 'input/conformance/p0_06.j2k') + jfile = opj_data_file('input/conformance/p0_06.j2k') c = Jp2k(jfile).get_codestream(header_only=False) # SIZ: Image and tile size @@ -2213,7 +2157,7 @@ class TestSuiteDump(unittest.TestCase): self.assertEqual(c.segment[11].marker_id, 'SOD') def test_NR_p0_07_dump(self): - jfile = os.path.join(data_root, 'input/conformance/p0_07.j2k') + jfile = opj_data_file('input/conformance/p0_07.j2k') c = Jp2k(jfile).get_codestream(header_only=False) # SIZ: Image and tile size @@ -2298,7 +2242,7 @@ class TestSuiteDump(unittest.TestCase): self.assertEqual(c.segment[8].marker_id, 'SOD') def test_NR_p0_08_dump(self): - jfile = os.path.join(data_root, 'input/conformance/p0_08.j2k') + jfile = opj_data_file('input/conformance/p0_08.j2k') c = Jp2k(jfile).get_codestream(header_only=False) # SIZ: Image and tile size @@ -2451,7 +2395,7 @@ class TestSuiteDump(unittest.TestCase): self.assertEqual(c.segment[10].tnsot, 1) # unknown def test_NR_p0_09_dump(self): - jfile = os.path.join(data_root, 'input/conformance/p0_09.j2k') + jfile = opj_data_file('input/conformance/p0_09.j2k') c = Jp2k(jfile).get_codestream(header_only=False) # SIZ: Image and tile size @@ -2531,7 +2475,7 @@ class TestSuiteDump(unittest.TestCase): self.assertEqual(c.segment[7].marker_id, 'EOC') def test_NR_p0_10_dump(self): - jfile = os.path.join(data_root, 'input/conformance/p0_10.j2k') + jfile = opj_data_file('input/conformance/p0_10.j2k') c = Jp2k(jfile).get_codestream(header_only=False) # SIZ: Image and tile size @@ -2672,7 +2616,7 @@ class TestSuiteDump(unittest.TestCase): self.assertEqual(c.segment[22].marker_id, 'EOC') def test_NR_p0_11_dump(self): - jfile = os.path.join(data_root, 'input/conformance/p0_11.j2k') + jfile = opj_data_file('input/conformance/p0_11.j2k') c = Jp2k(jfile).get_codestream(header_only=False) # SIZ: Image and tile size @@ -2753,7 +2697,7 @@ class TestSuiteDump(unittest.TestCase): self.assertEqual(c.segment[-1].marker_id, 'EOC') def test_NR_p0_12_dump(self): - jfile = os.path.join(data_root, 'input/conformance/p0_12.j2k') + jfile = opj_data_file('input/conformance/p0_12.j2k') c = Jp2k(jfile).get_codestream(header_only=False) # SIZ: Image and tile size @@ -2835,7 +2779,7 @@ class TestSuiteDump(unittest.TestCase): self.assertEqual(c.segment[-1].marker_id, 'EOC') def test_NR_p0_13_dump(self): - jfile = os.path.join(data_root, 'input/conformance/p0_13.j2k') + jfile = opj_data_file('input/conformance/p0_13.j2k') c = Jp2k(jfile).get_codestream(header_only=False) # SIZ: Image and tile size @@ -2961,7 +2905,7 @@ class TestSuiteDump(unittest.TestCase): self.assertEqual(c.segment[12].marker_id, 'EOC') def test_NR_p0_14_dump(self): - jfile = os.path.join(data_root, 'input/conformance/p0_14.j2k') + jfile = opj_data_file('input/conformance/p0_14.j2k') c = Jp2k(jfile).get_codestream(header_only=False) # SIZ: Image and tile size @@ -3037,7 +2981,7 @@ class TestSuiteDump(unittest.TestCase): self.assertEqual(c.segment[7].marker_id, 'EOC') def test_NR_p0_15_dump(self): - jfile = os.path.join(data_root, 'input/conformance/p0_15.j2k') + jfile = opj_data_file('input/conformance/p0_15.j2k') c = Jp2k(jfile).get_codestream(header_only=False) # SIZ: Image and tile size @@ -3191,7 +3135,7 @@ class TestSuiteDump(unittest.TestCase): self.assertEqual(c.segment[85].marker_id, 'EOC') def test_NR_p0_16_dump(self): - jfile = os.path.join(data_root, 'input/conformance/p0_16.j2k') + jfile = opj_data_file('input/conformance/p0_16.j2k') c = Jp2k(jfile).get_codestream(header_only=False) # SIZ: Image and tile size @@ -3259,7 +3203,7 @@ class TestSuiteDump(unittest.TestCase): self.assertEqual(c.segment[6].marker_id, 'EOC') def test_NR_p1_01_dump(self): - jfile = os.path.join(data_root, 'input/conformance/p1_01.j2k') + jfile = opj_data_file('input/conformance/p1_01.j2k') c = Jp2k(jfile).get_codestream(header_only=False) # SIZ: Image and tile size @@ -3359,7 +3303,7 @@ class TestSuiteDump(unittest.TestCase): self.assertEqual(c.segment[-1].marker_id, 'EOC') def test_NR_p1_02_dump(self): - jfile = os.path.join(data_root, 'input/conformance/p1_02.j2k') + jfile = opj_data_file('input/conformance/p1_02.j2k') c = Jp2k(jfile).get_codestream(header_only=False) # SIZ: Image and tile size @@ -3473,7 +3417,7 @@ class TestSuiteDump(unittest.TestCase): self.assertEqual(c.segment[10].marker_id, 'EOC') def test_NR_p1_03_dump(self): - jfile = os.path.join(data_root, 'input/conformance/p1_03.j2k') + jfile = opj_data_file('input/conformance/p1_03.j2k') c = Jp2k(jfile).get_codestream(header_only=False) # SIZ: Image and tile size @@ -3620,7 +3564,7 @@ class TestSuiteDump(unittest.TestCase): self.assertEqual(c.segment[13].marker_id, 'EOC') def test_NR_p1_04_dump(self): - jfile = os.path.join(data_root, 'input/conformance/p1_04.j2k') + jfile = opj_data_file('input/conformance/p1_04.j2k') c = Jp2k(jfile).get_codestream(header_only=False) # SIZ: Image and tile size @@ -3747,7 +3691,7 @@ class TestSuiteDump(unittest.TestCase): self.assertEqual(c.segment[-1].marker_id, 'EOC') def test_NR_p1_05_dump(self): - jfile = os.path.join(data_root, 'input/conformance/p1_05.j2k') + jfile = opj_data_file('input/conformance/p1_05.j2k') c = Jp2k(jfile).get_codestream(header_only=False) # SIZ: Image and tile size @@ -3835,7 +3779,7 @@ class TestSuiteDump(unittest.TestCase): self.assertEqual(c.segment[-1].marker_id, 'EOC') def test_NR_p1_06_dump(self): - jfile = os.path.join(data_root, 'input/conformance/p1_06.j2k') + jfile = opj_data_file('input/conformance/p1_06.j2k') c = Jp2k(jfile).get_codestream(header_only=False) # SIZ: Image and tile size @@ -3928,7 +3872,7 @@ class TestSuiteDump(unittest.TestCase): self.assertEqual(c.segment[-1].marker_id, 'EOC') def test_NR_p1_07_dump(self): - jfile = os.path.join(data_root, 'input/conformance/p1_07.j2k') + jfile = opj_data_file('input/conformance/p1_07.j2k') c = Jp2k(jfile).get_codestream(header_only=False) # SIZ: Image and tile size @@ -4021,7 +3965,7 @@ class TestSuiteDump(unittest.TestCase): self.assertEqual(c.segment[-1].marker_id, 'EOC') def test_NR_file1_dump(self): - jfile = os.path.join(data_root, 'input/conformance/file1.jp2') + jfile = opj_data_file('input/conformance/file1.jp2') jp2 = Jp2k(jfile) ids = [box.box_id for box in jp2.box] @@ -4071,7 +4015,7 @@ class TestSuiteDump(unittest.TestCase): '{http://www.jpeg.org/jpx/1.0/xml}EVENT']) def test_NR_file2_dump(self): - jfile = os.path.join(data_root, 'input/conformance/file2.jp2') + jfile = opj_data_file('input/conformance/file2.jp2') jp2 = Jp2k(jfile) ids = [box.box_id for box in jp2.box] @@ -4118,7 +4062,7 @@ class TestSuiteDump(unittest.TestCase): # Cr components being subsampled 2x in both the horizontal and # vertical directions. The components are stored in the standard # order. - jfile = os.path.join(data_root, 'input/conformance/file3.jp2') + jfile = opj_data_file('input/conformance/file3.jp2') jp2 = Jp2k(jfile) ids = [box.box_id for box in jp2.box] @@ -4165,7 +4109,7 @@ class TestSuiteDump(unittest.TestCase): def test_NR_file4_dump(self): # One 8-bit component in the sRGB-grey colourspace. - jfile = os.path.join(data_root, 'input/conformance/file4.jp2') + jfile = opj_data_file('input/conformance/file4.jp2') jp2 = Jp2k(jfile) ids = [box.box_id for box in jp2.box] @@ -4207,7 +4151,7 @@ class TestSuiteDump(unittest.TestCase): # the RCT. The colourspace is specified using both a Restricted ICC # profile and using the JPX-defined enumerated code for the ROMM-RGB # colourspace. - jfile = os.path.join(data_root, 'input/conformance/file5.jp2') + jfile = opj_data_file('input/conformance/file5.jp2') jp2 = Jp2k(jfile) ids = [box.box_id for box in jp2.box] @@ -4256,7 +4200,7 @@ class TestSuiteDump(unittest.TestCase): glymur.core.ROMM_RGB) def test_NR_file6_dump(self): - jfile = os.path.join(data_root, 'input/conformance/file6.jp2') + jfile = opj_data_file('input/conformance/file6.jp2') jp2 = Jp2k(jfile) ids = [box.box_id for box in jp2.box] @@ -4300,7 +4244,7 @@ class TestSuiteDump(unittest.TestCase): # the RCT. The colourspace is specified using both a Restricted ICC # profile and using the JPX-defined enumerated code for the e-sRGB # colourspace. - jfile = os.path.join(data_root, 'input/conformance/file7.jp2') + jfile = opj_data_file('input/conformance/file7.jp2') jp2 = Jp2k(jfile) ids = [box.box_id for box in jp2.box] @@ -4356,7 +4300,7 @@ class TestSuiteDump(unittest.TestCase): def test_NR_file8_dump(self): # One 8-bit component in a gamma 1.8 space. The colourspace is # specified using a Restricted ICC profile. - jfile = os.path.join(data_root, 'input/conformance/file8.jp2') + jfile = opj_data_file('input/conformance/file8.jp2') jp2 = Jp2k(jfile) ids = [box.box_id for box in jp2.box] @@ -4410,7 +4354,7 @@ class TestSuiteDump(unittest.TestCase): def test_NR_file9_dump(self): # Colormap - jfile = os.path.join(data_root, 'input/conformance/file9.jp2') + jfile = opj_data_file('input/conformance/file9.jp2') jp2 = Jp2k(jfile) ids = [box.box_id for box in jp2.box] @@ -4469,7 +4413,7 @@ class TestSuiteDump(unittest.TestCase): def test_NR_00042_j2k_dump(self): # Profile 3. - jfile = os.path.join(data_root, 'input/nonregression/_00042.j2k') + jfile = opj_data_file('input/nonregression/_00042.j2k') jp2k = Jp2k(jfile) c = jp2k.get_codestream(header_only=False) @@ -4622,7 +4566,7 @@ class TestSuiteDump(unittest.TestCase): def test_Bretagne2_j2k_dump(self): # Profile 3. - jfile = os.path.join(data_root, 'input/nonregression/Bretagne2.j2k') + jfile = opj_data_file('input/nonregression/Bretagne2.j2k') jp2k = Jp2k(jfile) c = jp2k.get_codestream(header_only=False) @@ -4679,7 +4623,7 @@ class TestSuiteDump(unittest.TestCase): self.assertEqual(ids, expected) def test_NR_buxI_j2k_dump(self): - jfile = os.path.join(data_root, 'input/nonregression/buxI.j2k') + jfile = opj_data_file('input/nonregression/buxI.j2k') jp2k = Jp2k(jfile) c = jp2k.get_codestream(header_only=False) @@ -4732,7 +4676,7 @@ class TestSuiteDump(unittest.TestCase): self.assertEqual(ids, expected) def test_NR_buxR_j2k_dump(self): - jfile = os.path.join(data_root, 'input/nonregression/buxR.j2k') + jfile = opj_data_file('input/nonregression/buxR.j2k') jp2k = Jp2k(jfile) c = jp2k.get_codestream(header_only=False) @@ -4789,7 +4733,7 @@ class TestSuiteDump(unittest.TestCase): 'Cannotreaddatawithnosizeknown.j2k'] path = '/'.join(lst) - jfile = os.path.join(data_root, path) + jfile = opj_data_file(path) jp2k = Jp2k(jfile) c = jp2k.get_codestream() @@ -4850,9 +4794,8 @@ class TestSuiteDump(unittest.TestCase): self.assertEqual(c.segment[3].exponent, [16] + [17, 17, 18] * 11) def test_NR_CT_Phillips_JPEG2K_Decompr_Problem_dump(self): - jfile = os.path.join(data_root, - 'input/nonregression/' - + 'CT_Phillips_JPEG2K_Decompr_Problem.j2k') + jfile = opj_data_file('input/nonregression/' + + 'CT_Phillips_JPEG2K_Decompr_Problem.j2k') jp2k = Jp2k(jfile) c = jp2k.get_codestream() @@ -4922,8 +4865,7 @@ class TestSuiteDump(unittest.TestCase): self.assertEqual(c.segment[4].ccme.decode('latin-1'), "Kakadu-3.2") def test_NR_cthead1_dump(self): - jfile = os.path.join(data_root, - 'input/nonregression/cthead1.j2k') + jfile = opj_data_file('input/nonregression/cthead1.j2k') jp2k = Jp2k(jfile) c = jp2k.get_codestream() @@ -4998,8 +4940,7 @@ class TestSuiteDump(unittest.TestCase): @unittest.skip("fprintf stderr output in r2343.") def test_NR_illegalcolortransform_dump(self): - jfile = os.path.join(data_root, - 'input/nonregression/illegalcolortransform.j2k') + jfile = opj_data_file('input/nonregression/illegalcolortransform.j2k') jp2k = Jp2k(jfile) c = jp2k.get_codestream() @@ -5060,7 +5001,7 @@ class TestSuiteDump(unittest.TestCase): self.assertEqual(c.segment[3].exponent, [16] + [17, 17, 18] * 11) def test_NR_j2k32_dump(self): - jfile = os.path.join(data_root, 'input/nonregression/j2k32.j2k') + jfile = opj_data_file('input/nonregression/j2k32.j2k') jp2k = Jp2k(jfile) c = jp2k.get_codestream() @@ -5127,9 +5068,8 @@ class TestSuiteDump(unittest.TestCase): self.assertEqual(len(c.segment[4].ccme), 36) def test_NR_kakadu_v4_4_openjpegv2_broken_dump(self): - jfile = os.path.join(data_root, - 'input/nonregression/' - + 'kakadu_v4-4_openjpegv2_broken.j2k') + jfile = opj_data_file('input/nonregression/' + + 'kakadu_v4-4_openjpegv2_broken.j2k') jp2k = Jp2k(jfile) c = jp2k.get_codestream() @@ -5213,8 +5153,7 @@ class TestSuiteDump(unittest.TestCase): self.assertEqual(c.segment[5].ccme.decode('latin-1'), expected) def test_NR_MarkerIsNotCompliant_j2k_dump(self): - jfile = os.path.join(data_root, - 'input/nonregression/MarkerIsNotCompliant.j2k') + jfile = opj_data_file('input/nonregression/MarkerIsNotCompliant.j2k') jp2k = Jp2k(jfile) c = jp2k.get_codestream() @@ -5273,8 +5212,7 @@ class TestSuiteDump(unittest.TestCase): 17, 18, 17, 17, 18, 17, 17, 18]) def test_NR_movie_00000(self): - jfile = os.path.join(data_root, - 'input/nonregression/movie_00000.j2k') + jfile = opj_data_file('input/nonregression/movie_00000.j2k') jp2k = Jp2k(jfile) c = jp2k.get_codestream() @@ -5331,8 +5269,7 @@ class TestSuiteDump(unittest.TestCase): [8, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10]) def test_NR_movie_00001(self): - jfile = os.path.join(data_root, - 'input/nonregression/movie_00001.j2k') + jfile = opj_data_file('input/nonregression/movie_00001.j2k') jp2k = Jp2k(jfile) c = jp2k.get_codestream() @@ -5389,8 +5326,7 @@ class TestSuiteDump(unittest.TestCase): [8, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10]) def test_NR_movie_00002(self): - jfile = os.path.join(data_root, - 'input/nonregression/movie_00002.j2k') + jfile = opj_data_file('input/nonregression/movie_00002.j2k') jp2k = Jp2k(jfile) c = jp2k.get_codestream() @@ -5447,8 +5383,7 @@ class TestSuiteDump(unittest.TestCase): [8, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10]) def test_NR_orb_blue10_lin_j2k_dump(self): - jfile = os.path.join(data_root, - 'input/nonregression/orb-blue10-lin-j2k.j2k') + jfile = opj_data_file('input/nonregression/orb-blue10-lin-j2k.j2k') jp2k = Jp2k(jfile) c = jp2k.get_codestream() @@ -5508,8 +5443,7 @@ class TestSuiteDump(unittest.TestCase): [8, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10]) def test_NR_orb_blue10_win_j2k_dump(self): - jfile = os.path.join(data_root, - 'input/nonregression/orb-blue10-win-j2k.j2k') + jfile = opj_data_file('input/nonregression/orb-blue10-win-j2k.j2k') jp2k = Jp2k(jfile) c = jp2k.get_codestream() @@ -5569,7 +5503,7 @@ class TestSuiteDump(unittest.TestCase): [8, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10]) def test_NR_pacs_ge_j2k_dump(self): - jfile = os.path.join(data_root, 'input/nonregression/pacs.ge.j2k') + jfile = opj_data_file('input/nonregression/pacs.ge.j2k') jp2k = Jp2k(jfile) c = jp2k.get_codestream() @@ -5637,8 +5571,7 @@ class TestSuiteDump(unittest.TestCase): "Kakadu-2.0.2") def test_NR_test_lossless_j2k_dump(self): - jfile = os.path.join(data_root, - 'input/nonregression/test_lossless.j2k') + jfile = opj_data_file('input/nonregression/test_lossless.j2k') jp2k = Jp2k(jfile) c = jp2k.get_codestream() @@ -5707,7 +5640,7 @@ class TestSuiteDump(unittest.TestCase): "ClearCanvas DICOM OpenJPEG") def test_NR_123_j2c_dump(self): - jfile = os.path.join(data_root, 'input/nonregression/123.j2c') + jfile = opj_data_file('input/nonregression/123.j2c') jp2k = Jp2k(jfile) c = jp2k.get_codestream() @@ -5769,7 +5702,7 @@ class TestSuiteDump(unittest.TestCase): [16] + [17, 17, 18] * 11) def test_NR_bug_j2c_dump(self): - jfile = os.path.join(data_root, 'input/nonregression/bug.j2c') + jfile = opj_data_file('input/nonregression/bug.j2c') jp2k = Jp2k(jfile) c = jp2k.get_codestream() @@ -5831,8 +5764,7 @@ class TestSuiteDump(unittest.TestCase): [16] + [17, 17, 18] * 11) def test_NR_kodak_2layers_lrcp_j2c_dump(self): - jfile = os.path.join(data_root, - 'input/nonregression/kodak_2layers_lrcp.j2c') + jfile = opj_data_file('input/nonregression/kodak_2layers_lrcp.j2c') jp2k = Jp2k(jfile) c = jp2k.get_codestream() @@ -5905,8 +5837,7 @@ class TestSuiteDump(unittest.TestCase): @unittest.skipIf(sys.hexversion < 0x03020000, "Uses features introduced in 3.2.") def test_NR_broken_jp2_dump(self): - jfile = os.path.join(data_root, - 'input/nonregression/broken.jp2') + jfile = opj_data_file('input/nonregression/broken.jp2') with self.assertWarns(UserWarning): # colr box has bad length. jp2 = Jp2k(jfile) @@ -6033,7 +5964,7 @@ class TestSuiteDump(unittest.TestCase): "Uses features introduced in 3.2, 'assertWarns'.") def test_NR_broken2_jp2_dump(self): # Invalid marker ID on codestream. - jfile = os.path.join(data_root, 'input/nonregression/broken2.jp2') + jfile = opj_data_file('input/nonregression/broken2.jp2') with self.assertWarns(UserWarning): jp2 = Jp2k(jfile) @@ -6042,8 +5973,7 @@ class TestSuiteDump(unittest.TestCase): @unittest.skipIf(sys.hexversion < 0x03020000, "Uses features introduced in 3.2.") def test_NR_broken3_jp2_dump(self): - jfile = os.path.join(data_root, - 'input/nonregression/broken3.jp2') + jfile = opj_data_file('input/nonregression/broken3.jp2') with self.assertWarns(UserWarning): # colr box has bad length. jp2 = Jp2k(jfile) @@ -6170,15 +6100,14 @@ class TestSuiteDump(unittest.TestCase): "Uses features introduced in 3.2, 'assertWarns'") def test_NR_broken4_jp2_dump(self): # Has an invalid marker in the main header - jfile = os.path.join(data_root, 'input/nonregression/broken4.jp2') + jfile = opj_data_file('input/nonregression/broken4.jp2') with self.assertWarns(UserWarning): jp2 = Jp2k(jfile) self.assertEqual(jp2.box[-1].main_header.segment[-1].marker_id, 'QCC') def test_NR_file409752(self): - jfile = os.path.join(data_root, - 'input/nonregression/file409752.jp2') + jfile = opj_data_file('input/nonregression/file409752.jp2') jp2 = Jp2k(jfile) ids = [box.box_id for box in jp2.box] @@ -6279,7 +6208,7 @@ class TestSuiteDump(unittest.TestCase): def test_NR_gdal_fuzzer_assert_in_opj_j2k_read_SQcd_SQcc_patch_jp2(self): lst = ['input', 'nonregression', 'gdal_fuzzer_assert_in_opj_j2k_read_SQcd_SQcc.patch.jp2'] - jfile = os.path.join(data_root, '/'.join(lst)) + jfile = opj_data_file('/'.join(lst)) with self.assertWarns(UserWarning): Jp2k(jfile) @@ -6287,7 +6216,7 @@ class TestSuiteDump(unittest.TestCase): "Uses features introduced in 3.2.") def test_NR_gdal_fuzzer_check_comp_dx_dy_jp2_dump(self): lst = ['input', 'nonregression', 'gdal_fuzzer_check_comp_dx_dy.jp2'] - jfile = os.path.join(data_root, '/'.join(lst)) + jfile = opj_data_file('/'.join(lst)) with self.assertWarns(UserWarning): Jp2k(jfile) @@ -6297,7 +6226,7 @@ class TestSuiteDump(unittest.TestCase): # Has an impossible tiling setup. lst = ['input', 'nonregression', 'gdal_fuzzer_check_number_of_tiles.jp2'] - jfile = os.path.join(data_root, '/'.join(lst)) + jfile = opj_data_file('/'.join(lst)) with self.assertWarns(UserWarning): Jp2k(jfile) @@ -6307,13 +6236,12 @@ class TestSuiteDump(unittest.TestCase): # Has an invalid number of resolutions. lst = ['input', 'nonregression', 'gdal_fuzzer_unchecked_numresolutions.jp2'] - jfile = os.path.join(data_root, '/'.join(lst)) + jfile = opj_data_file('/'.join(lst)) with self.assertWarns(UserWarning): Jp2k(jfile) def test_NR_issue104_jpxstream_dump(self): - jfile = os.path.join(data_root, - 'input/nonregression/issue104_jpxstream.jp2') + jfile = opj_data_file('input/nonregression/issue104_jpxstream.jp2') jp2 = Jp2k(jfile) ids = [box.box_id for box in jp2.box] @@ -6427,7 +6355,7 @@ class TestSuiteDump(unittest.TestCase): def test_NR_issue188_beach_64bitsbox(self): lst = ['input', 'nonregression', 'issue188_beach_64bitsbox.jp2'] - jfile = os.path.join(data_root, '/'.join(lst)) + jfile = opj_data_file('/'.join(lst)) with warnings.catch_warnings(): # There's a warning for an unknown box. We explicitly test for # that down below. @@ -6525,8 +6453,7 @@ class TestSuiteDump(unittest.TestCase): self.assertEqual(c.segment[3].guard_bits, 1) def test_NR_issue206_image_000_dump(self): - jfile = os.path.join(data_root, - 'input/nonregression/issue206_image-000.jp2') + jfile = opj_data_file('input/nonregression/issue206_image-000.jp2') jp2 = Jp2k(jfile) ids = [box.box_id for box in jp2.box] @@ -6626,8 +6553,7 @@ class TestSuiteDump(unittest.TestCase): self.assertEqual(c.segment[3].exponent, [8] + [9, 9, 10] * 5) def test_NR_Marrin_jp2_dump(self): - jfile = os.path.join(data_root, - 'input/nonregression/Marrin.jp2') + jfile = opj_data_file('input/nonregression/Marrin.jp2') jp2 = Jp2k(jfile) ids = [box.box_id for box in jp2.box] @@ -6740,8 +6666,7 @@ class TestSuiteDump(unittest.TestCase): "Kakadu-v5.2.1") def test_NR_mem_b2ace68c_1381_dump(self): - jfile = os.path.join(data_root, - 'input/nonregression/mem-b2ace68c-1381.jp2') + jfile = opj_data_file('input/nonregression/mem-b2ace68c-1381.jp2') with warnings.catch_warnings(): # This file has a bad pclr box, we test for this elsewhere. warnings.simplefilter("ignore") @@ -6858,8 +6783,7 @@ class TestSuiteDump(unittest.TestCase): self.assertEqual(c.segment[3].exponent, [1] + [2, 2, 3] * 5) def test_NR_mem_b2b86b74_2753_dump(self): - jfile = os.path.join(data_root, - 'input/nonregression/mem-b2b86b74-2753.jp2') + jfile = opj_data_file('input/nonregression/mem-b2b86b74-2753.jp2') jp2 = Jp2k(jfile) ids = [box.box_id for box in jp2.box] @@ -6973,7 +6897,7 @@ class TestSuiteDump(unittest.TestCase): self.assertEqual(c.segment[3].exponent, [4] + [5, 5, 6] * 5) def test_NR_merged_dump(self): - jfile = os.path.join(data_root, 'input/nonregression/merged.jp2') + jfile = opj_data_file('input/nonregression/merged.jp2') jp2 = Jp2k(jfile) ids = [box.box_id for box in jp2.box] @@ -7077,8 +7001,7 @@ class TestSuiteDump(unittest.TestCase): self.assertEqual(c.segment[4].ppod, podvals) def test_NR_orb_blue10_lin_jp2_dump(self): - jfile = os.path.join(data_root, - 'input/nonregression/orb-blue10-lin-jp2.jp2') + jfile = opj_data_file('input/nonregression/orb-blue10-lin-jp2.jp2') with warnings.catch_warnings(): # This file has an invalid ICC profile warnings.simplefilter("ignore") @@ -7177,8 +7100,7 @@ class TestSuiteDump(unittest.TestCase): [8, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10]) def test_NR_orb_blue10_win_jp2_dump(self): - jfile = os.path.join(data_root, - 'input/nonregression/orb-blue10-win-jp2.jp2') + jfile = opj_data_file('input/nonregression/orb-blue10-win-jp2.jp2') with warnings.catch_warnings(): # This file has an invalid ICC profile warnings.simplefilter("ignore") @@ -7277,8 +7199,7 @@ class TestSuiteDump(unittest.TestCase): [8, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10]) def test_NR_text_GBR_dump(self): - jfile = os.path.join(data_root, - 'input/nonregression/text_GBR.jp2') + jfile = opj_data_file('input/nonregression/text_GBR.jp2') with warnings.catch_warnings(): # brand is 'jp2 ', but has any icc profile. warnings.simplefilter("ignore") @@ -7391,7 +7312,7 @@ class TestSuiteDump(unittest.TestCase): @unittest.skipIf(glymur.lib.openjpeg.OPENJPEG is None, "Missing openjpeg library.") -@unittest.skipIf(data_root is None, +@unittest.skipIf(OPJ_DATA_ROOT is None, "OPJ_DATA_ROOT environment variable not set") class TestSuite15(unittest.TestCase): """Suite of tests for libopenjpeg 1.5.1""" @@ -7414,16 +7335,16 @@ class TestSuite15(unittest.TestCase): pass def test_ETS_C0P0_p0_01_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p0_01.j2k') + jfile = opj_data_file('input/conformance/p0_01.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read(rlevel=0) - pgxfile = os.path.join(data_root, 'baseline/conformance/c0p0_01.pgx') + pgxfile = opj_data_file('baseline/conformance/c0p0_01.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata, pgxdata) def test_ETS_C0P0_p0_02_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p0_02.j2k') + jfile = opj_data_file('input/conformance/p0_02.j2k') with warnings.catch_warnings(): # There's a 0xff30 marker segment. Not illegal, but we don't # really know what to do with it. Just ignore. @@ -7431,79 +7352,74 @@ class TestSuite15(unittest.TestCase): jp2k = Jp2k(jfile) jpdata = jp2k.read(rlevel=0) - pgxfile = os.path.join(data_root, 'baseline/conformance/c0p0_02.pgx') + pgxfile = opj_data_file('baseline/conformance/c0p0_02.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata, pgxdata) def test_ETS_C0P0_p0_09_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p0_09.j2k') + jfile = opj_data_file('input/conformance/p0_09.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read(rlevel=2) - pgxfile = os.path.join(data_root, - 'baseline/conformance/c0p0_09.pgx') + pgxfile = opj_data_file('baseline/conformance/c0p0_09.pgx') pgxdata = read_pgx(pgxfile) self.assertTrue(peak_tolerance(jpdata, pgxdata) < 4) self.assertTrue(mse(jpdata, pgxdata) < 1.47) def test_ETS_C0P0_p0_11_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p0_11.j2k') + jfile = opj_data_file('input/conformance/p0_11.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read(rlevel=0) - pgxfile = os.path.join(data_root, - 'baseline/conformance/c0p0_11.pgx') + pgxfile = opj_data_file('baseline/conformance/c0p0_11.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata, pgxdata) @unittest.skip("fprintf stderr output in r2343.") def test_ETS_C0P0_p0_12_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p0_12.j2k') + jfile = opj_data_file('input/conformance/p0_12.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read(rlevel=0) - pgxfile = os.path.join(data_root, - 'baseline/conformance/c0p0_12.pgx') + pgxfile = opj_data_file('baseline/conformance/c0p0_12.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata, pgxdata) def test_ETS_C0P0_p0_16_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p0_16.j2k') + jfile = opj_data_file('input/conformance/p0_16.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read(rlevel=0) - pgxfile = os.path.join(data_root, - 'baseline/conformance/c0p0_16.pgx') + pgxfile = opj_data_file('baseline/conformance/c0p0_16.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata, pgxdata) def test_ETS_C0P1_p1_01_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p1_01.j2k') + jfile = opj_data_file('input/conformance/p1_01.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read(rlevel=0) - pgxfile = os.path.join(data_root, - 'baseline/conformance/c0p1_01.pgx') + pgxfile = opj_data_file('baseline/conformance/c0p1_01.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata, pgxdata) def test_ETS_C1P0_p0_01_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p0_01.j2k') + jfile = opj_data_file('input/conformance/p0_01.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read(rlevel=0) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_01_0.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p0_01_0.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata, pgxdata) def test_ETS_C1P0_p0_02_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p0_02.j2k') + jfile = opj_data_file('input/conformance/p0_02.j2k') with warnings.catch_warnings(): # There's a 0xff30 marker segment. Not illegal, but we don't # really know what to do with it. Just ignore. @@ -7511,293 +7427,293 @@ class TestSuite15(unittest.TestCase): jp2k = Jp2k(jfile) jpdata = jp2k.read(rlevel=0) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_02_0.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p0_02_0.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata, pgxdata) def test_ETS_C1P0_p0_03_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p0_03.j2k') + jfile = opj_data_file('input/conformance/p0_03.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read(rlevel=0) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_03_0.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p0_03_0.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata, pgxdata) def test_ETS_C1P0_p0_04_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p0_04.j2k') + jfile = opj_data_file('input/conformance/p0_04.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read(rlevel=0) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_04_0.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p0_04_0.pgx') pgxdata = read_pgx(pgxfile) self.assertTrue(peak_tolerance(jpdata[:, :, 0], pgxdata) < 5) self.assertTrue(mse(jpdata[:, :, 0], pgxdata) < 0.776) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_04_1.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p0_04_1.pgx') pgxdata = read_pgx(pgxfile) self.assertTrue(peak_tolerance(jpdata[:, :, 1], pgxdata) < 4) self.assertTrue(mse(jpdata[:, :, 1], pgxdata) < 0.626) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_04_2.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p0_04_2.pgx') pgxdata = read_pgx(pgxfile) self.assertTrue(peak_tolerance(jpdata[:, :, 2], pgxdata) < 6) self.assertTrue(mse(jpdata[:, :, 2], pgxdata) < 1.07) def test_ETS_C1P0_p0_08_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p0_08.j2k') + jfile = opj_data_file('input/conformance/p0_08.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read(rlevel=1) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_08_0.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p0_08_0.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata[:, :, 0], pgxdata) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_08_1.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p0_08_1.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata[:, :, 1], pgxdata) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_08_2.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p0_08_2.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata[:, :, 2], pgxdata) def test_ETS_C1P0_p0_09_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p0_09.j2k') + jfile = opj_data_file('input/conformance/p0_09.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read(rlevel=0) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_09_0.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p0_09_0.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata, pgxdata) def test_ETS_C1P0_p0_10_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p0_10.j2k') + jfile = opj_data_file('input/conformance/p0_10.j2k') jp2k = Jp2k(jfile) with warnings.catch_warnings(): # This file has an invalid ICC profile warnings.simplefilter("ignore") jpdata = jp2k.read(rlevel=0) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_10_0.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p0_10_0.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata[:, :, 0], pgxdata) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_10_1.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p0_10_1.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata[:, :, 1], pgxdata) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_10_2.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p0_10_2.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata[:, :, 2], pgxdata) def test_ETS_C1P0_p0_11_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p0_11.j2k') + jfile = opj_data_file('input/conformance/p0_11.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read(rlevel=0) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_11_0.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p0_11_0.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata, pgxdata) @unittest.skip("fprintf stderr output in r2343.") def test_ETS_C1P0_p0_12_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p0_12.j2k') + jfile = opj_data_file('input/conformance/p0_12.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read(rlevel=0) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_12_0.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p0_12_0.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata, pgxdata) @unittest.skip("fprintf stderr output in r2343.") def test_ETS_C1P0_p0_13_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p0_13.j2k') + jfile = opj_data_file('input/conformance/p0_13.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read(rlevel=0) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_13_0.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p0_13_0.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata[:, :, 0], pgxdata) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_13_1.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p0_13_1.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata[:, :, 1], pgxdata) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_13_2.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p0_13_2.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata[:, :, 2], pgxdata) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_13_3.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p0_13_3.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata[:, :, 3], pgxdata) def test_ETS_C1P0_p0_14_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p0_14.j2k') + jfile = opj_data_file('input/conformance/p0_14.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read(rlevel=0) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_14_0.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p0_14_0.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata[:, :, 0], pgxdata) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_14_1.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p0_14_1.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata[:, :, 1], pgxdata) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_14_2.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p0_14_2.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata[:, :, 2], pgxdata) def test_ETS_C1P0_p0_15_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p0_15.j2k') + jfile = opj_data_file('input/conformance/p0_15.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read(rlevel=0) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_15_0.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p0_15_0.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata, pgxdata) def test_ETS_C1P0_p0_16_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p0_16.j2k') + jfile = opj_data_file('input/conformance/p0_16.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read(rlevel=0) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_16_0.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p0_16_0.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata, pgxdata) def test_ETS_C1P1_p1_01_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p1_01.j2k') + jfile = opj_data_file('input/conformance/p1_01.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read(rlevel=0) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p1_01_0.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p1_01_0.pgx') pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata, pgxdata) def test_ETS_C1P1_p1_02_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p1_02.j2k') + jfile = opj_data_file('input/conformance/p1_02.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read(rlevel=0) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p1_02_0.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p1_02_0.pgx') pgxdata = read_pgx(pgxfile) self.assertTrue(peak_tolerance(jpdata[:, :, 0], pgxdata) < 5) self.assertTrue(mse(jpdata[:, :, 0], pgxdata) < 0.765) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p1_02_1.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p1_02_1.pgx') pgxdata = read_pgx(pgxfile) self.assertTrue(peak_tolerance(jpdata[:, :, 1], pgxdata) < 4) self.assertTrue(mse(jpdata[:, :, 1], pgxdata) < 0.616) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p1_02_2.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p1_02_2.pgx') pgxdata = read_pgx(pgxfile) self.assertTrue(peak_tolerance(jpdata[:, :, 2], pgxdata) < 6) self.assertTrue(mse(jpdata[:, :, 2], pgxdata) < 1.051) def test_ETS_C1P1_p1_04_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p1_04.j2k') + jfile = opj_data_file('input/conformance/p1_04.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read() - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p1_04_0.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p1_04_0.pgx') pgxdata = read_pgx(pgxfile) self.assertTrue(peak_tolerance(jpdata, pgxdata) < 624) self.assertTrue(mse(jpdata, pgxdata) < 3080) @unittest.skip("fprintf stderr output in r2343.") def test_ETS_C1P1_p1_05_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p1_05.j2k') + jfile = opj_data_file('input/conformance/p1_05.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read() - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p1_05_0.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p1_05_0.pgx') pgxdata = read_pgx(pgxfile) self.assertTrue(peak_tolerance(jpdata[:, :, 0], pgxdata) < 40) self.assertTrue(mse(jpdata[:, :, 0], pgxdata) < 8.458) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p1_05_1.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p1_05_1.pgx') pgxdata = read_pgx(pgxfile) self.assertTrue(peak_tolerance(jpdata[:, :, 1], pgxdata) < 40) self.assertTrue(mse(jpdata[:, :, 1], pgxdata) < 9.816) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p1_05_2.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p1_05_2.pgx') pgxdata = read_pgx(pgxfile) self.assertTrue(peak_tolerance(jpdata[:, :, 2], pgxdata) < 40) self.assertTrue(mse(jpdata[:, :, 2], pgxdata) < 10.154) @unittest.skip("fprintf stderr output in r2343.") def test_ETS_C1P1_p1_06_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p1_06.j2k') + jfile = opj_data_file('input/conformance/p1_06.j2k') jp2k = Jp2k(jfile) jpdata = jp2k.read() - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p1_06_0.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p1_06_0.pgx') pgxdata = read_pgx(pgxfile) self.assertTrue(peak_tolerance(jpdata[:, :, 0], pgxdata) < 2) self.assertTrue(mse(jpdata[:, :, 0], pgxdata) < 0.6) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p1_06_1.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p1_06_1.pgx') pgxdata = read_pgx(pgxfile) self.assertTrue(peak_tolerance(jpdata[:, :, 1], pgxdata) < 2) self.assertTrue(mse(jpdata[:, :, 1], pgxdata) < 0.6) - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p1_06_2.pgx') + pgxfile = opj_data_file('baseline/conformance/c1p1_06_2.pgx') pgxdata = read_pgx(pgxfile) self.assertTrue(peak_tolerance(jpdata[:, :, 2], pgxdata) < 2) self.assertTrue(mse(jpdata[:, :, 2], pgxdata) < 0.6) def test_ETS_JP2_file1(self): - jfile = os.path.join(data_root, 'input/conformance/file1.jp2') + jfile = opj_data_file('input/conformance/file1.jp2') jp2k = Jp2k(jfile) jpdata = jp2k.read() self.assertEqual(jpdata.shape, (512, 768, 3)) def test_ETS_JP2_file2(self): - jfile = os.path.join(data_root, 'input/conformance/file2.jp2') + jfile = opj_data_file('input/conformance/file2.jp2') jp2k = Jp2k(jfile) jpdata = jp2k.read() self.assertEqual(jpdata.shape, (640, 480, 3)) def test_ETS_JP2_file4(self): - jfile = os.path.join(data_root, 'input/conformance/file4.jp2') + jfile = opj_data_file('input/conformance/file4.jp2') jp2k = Jp2k(jfile) jpdata = jp2k.read() self.assertEqual(jpdata.shape, (512, 768)) def test_ETS_JP2_file5(self): """ETS_JP2_file5""" - jfile = os.path.join(data_root, 'input/conformance/file5.jp2') + jfile = opj_data_file('input/conformance/file5.jp2') jp2k = Jp2k(jfile) jpdata = jp2k.read() self.assertEqual(jpdata.shape, (512, 768, 3)) def test_ETS_JP2_file6(self): """ETS_JP2_file6""" - jfile = os.path.join(data_root, 'input/conformance/file6.jp2') + jfile = opj_data_file('input/conformance/file6.jp2') jp2k = Jp2k(jfile) jpdata = jp2k.read() self.assertEqual(jpdata.shape, (512, 768)) def test_ETS_JP2_file7(self): """ETS_JP2_file7""" - jfile = os.path.join(data_root, 'input/conformance/file7.jp2') + jfile = opj_data_file('input/conformance/file7.jp2') jp2k = Jp2k(jfile) jpdata = jp2k.read() self.assertEqual(jpdata.shape, (640, 480, 3)) def test_ETS_JP2_file8(self): """ETS_JP2_file8""" - jfile = os.path.join(data_root, 'input/conformance/file8.jp2') + jfile = opj_data_file('input/conformance/file8.jp2') jp2k = Jp2k(jfile) jpdata = jp2k.read() self.assertEqual(jpdata.shape, (400, 700)) def test_ETS_JP2_file9(self): """ETS_JP2_file9""" - jfile = os.path.join(data_root, 'input/conformance/file9.jp2') + jfile = opj_data_file('input/conformance/file9.jp2') jp2k = Jp2k(jfile) jpdata = jp2k.read() if re.match(r'[01]\.3', OPENJPEG_VERSION): @@ -7808,14 +7724,14 @@ class TestSuite15(unittest.TestCase): def test_NR_DEC_Bretagne2_j2k_1_decode(self): """test_NR_DEC_Bretagne2_j2k_1_decode""" - jfile = os.path.join(data_root, 'input/nonregression/Bretagne2.j2k') + jfile = opj_data_file('input/nonregression/Bretagne2.j2k') jp2 = Jp2k(jfile) jp2.read() self.assertTrue(True) def test_NR_DEC__00042_j2k_2_decode(self): """NR_DEC__00042_j2k_2_decode""" - jfile = os.path.join(data_root, 'input/nonregression/_00042.j2k') + jfile = opj_data_file('input/nonregression/_00042.j2k') jp2 = Jp2k(jfile) jp2.read() self.assertTrue(True) @@ -7823,7 +7739,7 @@ class TestSuite15(unittest.TestCase): @unittest.skip("fprintf stderr output in r2343.") def test_NR_DEC_123_j2c_3_decode(self): """NR_DEC_123_j2c_3_decode""" - jfile = os.path.join(data_root, 'input/nonregression/123.j2c') + jfile = opj_data_file('input/nonregression/123.j2c') jp2 = Jp2k(jfile) jp2.read() self.assertTrue(True) @@ -7832,7 +7748,7 @@ class TestSuite15(unittest.TestCase): "Uses features introduced in 3.2.") def test_NR_DEC_broken_jp2_4_decode(self): """NR_DEC_broken_jp2_4_decode""" - jfile = os.path.join(data_root, 'input/nonregression/broken.jp2') + jfile = opj_data_file('input/nonregression/broken.jp2') with self.assertWarns(UserWarning): # colr box has bad length. jp2 = Jp2k(jfile) @@ -7845,7 +7761,7 @@ class TestSuite15(unittest.TestCase): def test_NR_DEC_broken2_jp2_5_decode(self): """NR_DEC_broken2_jp2_5_decode""" # Null pointer access - jfile = os.path.join(data_root, 'input/nonregression/broken2.jp2') + jfile = opj_data_file('input/nonregression/broken2.jp2') with self.assertRaises(ValueError): with warnings.catch_warnings(): # Library warning, invalid number of subbands. @@ -7857,7 +7773,7 @@ class TestSuite15(unittest.TestCase): "Uses features introduced in 3.2.") def test_NR_DEC_broken3_jp2_6_decode(self): """NR_DEC_broken3_jp2_6_decode""" - jfile = os.path.join(data_root, 'input/nonregression/broken3.jp2') + jfile = opj_data_file('input/nonregression/broken3.jp2') with self.assertWarns(UserWarning): # colr box has bad length. j = Jp2k(jfile) @@ -7870,7 +7786,7 @@ class TestSuite15(unittest.TestCase): def test_NR_DEC_broken4_jp2_7_decode(self): """NR_DEC_broken4_jp2_7_decode""" # Null pointer access - jfile = os.path.join(data_root, 'input/nonregression/broken4.jp2') + jfile = opj_data_file('input/nonregression/broken4.jp2') with self.assertRaises(ValueError): with warnings.catch_warnings(): # Library warning, invalid number of subbands. @@ -7881,60 +7797,59 @@ class TestSuite15(unittest.TestCase): @unittest.skip("fprintf stderr output in r2343.") def test_NR_DEC_bug_j2c_8_decode(self): """NR_DEC_bug_j2c_8_decode""" - jfile = os.path.join(data_root, 'input/nonregression/bug.j2c') + jfile = opj_data_file('input/nonregression/bug.j2c') Jp2k(jfile).read() self.assertTrue(True) def test_NR_DEC_buxI_j2k_9_decode(self): """NR_DEC_buxI_j2k_9_decode""" - jfile = os.path.join(data_root, 'input/nonregression/buxI.j2k') + jfile = opj_data_file('input/nonregression/buxI.j2k') Jp2k(jfile).read() self.assertTrue(True) def test_NR_DEC_buxR_j2k_10_decode(self): """NR_DEC_buxR_j2k_10_decode""" - jfile = os.path.join(data_root, 'input/nonregression/buxR.j2k') + jfile = opj_data_file('input/nonregression/buxR.j2k') Jp2k(jfile).read() self.assertTrue(True) def test_NR_DEC_Cannotreaddatawithnosizeknown_j2k_11_decode(self): """NR_DEC_Cannotreaddatawithnosizeknown_j2k_11_decode""" relpath = 'input/nonregression/Cannotreaddatawithnosizeknown.j2k' - jfile = os.path.join(data_root, relpath) + jfile = opj_data_file(relpath) Jp2k(jfile).read() self.assertTrue(True) def test_NR_DEC_cthead1_j2k_12_decode(self): """NR_DEC_cthead1_j2k_12_decode""" - jfile = os.path.join(data_root, 'input/nonregression/cthead1.j2k') + jfile = opj_data_file('input/nonregression/cthead1.j2k') Jp2k(jfile).read() self.assertTrue(True) def test_NR_DEC_CT_Phillips_JPEG2K_Decompr_Problem_j2k_13_decode(self): """NR_DEC_CT_Phillips_JPEG2K_Decompr_Problem_j2k_13_decode""" relpath = 'input/nonregression/CT_Phillips_JPEG2K_Decompr_Problem.j2k' - jfile = os.path.join(data_root, relpath) + jfile = opj_data_file(relpath) Jp2k(jfile).read() self.assertTrue(True) @unittest.skip("fprintf stderr output in r2343.") def test_NR_DEC_illegalcolortransform_j2k_14_decode(self): """Stream too short, expected SOT.""" - jfile = os.path.join(data_root, - 'input/nonregression/illegalcolortransform.j2k') + jfile = opj_data_file('input/nonregression/illegalcolortransform.j2k') Jp2k(jfile).read() self.assertTrue(True) def test_NR_DEC_j2k32_j2k_15_decode(self): """NR_DEC_j2k32_j2k_15_decode""" - jfile = os.path.join(data_root, 'input/nonregression/j2k32.j2k') + jfile = opj_data_file('input/nonregression/j2k32.j2k') Jp2k(jfile).read() self.assertTrue(True) def test_NR_DEC_kakadu_v4_4_openjpegv2_broken_j2k_16_decode(self): """NR_DEC_kakadu_v4_4_openjpegv2_broken_j2k_16_decode""" relpath = 'input/nonregression/kakadu_v4-4_openjpegv2_broken.j2k' - jfile = os.path.join(data_root, relpath) + jfile = opj_data_file(relpath) with warnings.catch_warnings(): # This file has an invalid ICC profile warnings.simplefilter("ignore") @@ -7943,55 +7858,49 @@ class TestSuite15(unittest.TestCase): def test_NR_DEC_MarkerIsNotCompliant_j2k_17_decode(self): """NR_DEC_MarkerIsNotCompliant_j2k_17_decode""" - jfile = os.path.join(data_root, - 'input/nonregression/MarkerIsNotCompliant.j2k') + jfile = opj_data_file('input/nonregression/MarkerIsNotCompliant.j2k') Jp2k(jfile).read() self.assertTrue(True) def test_NR_DEC_Marrin_jp2_18_decode(self): """NR_DEC_Marrin_jp2_18_decode""" - jfile = os.path.join(data_root, 'input/nonregression/Marrin.jp2') + jfile = opj_data_file('input/nonregression/Marrin.jp2') Jp2k(jfile).read() self.assertTrue(True) def test_NR_DEC_movie_00000_j2k_20_decode(self): """test_NR_DEC_movie_00000_j2k_20_decode""" - jfile = os.path.join(data_root, - 'input/nonregression/movie_00000.j2k') + jfile = opj_data_file('input/nonregression/movie_00000.j2k') Jp2k(jfile).read() self.assertTrue(True) def test_NR_DEC_movie_00001_j2k_21_decode(self): """NR_DEC_movie_00001_j2k_21_decode""" - jfile = os.path.join(data_root, - 'input/nonregression/movie_00001.j2k') + jfile = opj_data_file('input/nonregression/movie_00001.j2k') Jp2k(jfile).read() self.assertTrue(True) def test_NR_DEC_movie_00002_j2k_22_decode(self): """NR_DEC_movie_00002_j2k_22_decode""" - jfile = os.path.join(data_root, 'input/nonregression/movie_00002.j2k') + jfile = opj_data_file('input/nonregression/movie_00002.j2k') Jp2k(jfile).read() self.assertTrue(True) def test_NR_DEC_orb_blue_lin_j2k_j2k_23_decode(self): """NR_DEC_orb_blue_lin_j2k_j2k_23_decode""" - jfile = os.path.join(data_root, - 'input/nonregression/orb-blue10-lin-j2k.j2k') + jfile = opj_data_file('input/nonregression/orb-blue10-lin-j2k.j2k') Jp2k(jfile).read() self.assertTrue(True) def test_NR_DEC_orb_blue_win_j2k_j2k_24_decode(self): """NR_DEC_orb_blue_win_j2k_j2k_24_decode""" - jfile = os.path.join(data_root, - 'input/nonregression/orb-blue10-win-j2k.j2k') + jfile = opj_data_file('input/nonregression/orb-blue10-win-j2k.j2k') Jp2k(jfile).read() self.assertTrue(True) def test_nc_dec_orb_blue_lin_jp2_25_decode(self): """NR-DEC-orb-blue-lin.jp2-25-decode""" - jfile = os.path.join(data_root, - 'input/nonregression/orb-blue10-lin-jp2.jp2') + jfile = opj_data_file('input/nonregression/orb-blue10-lin-jp2.jp2') with warnings.catch_warnings(): # This file has an invalid ICC profile warnings.simplefilter("ignore") @@ -8000,35 +7909,31 @@ class TestSuite15(unittest.TestCase): def test_nr_dec_orb_blue_win_jp2_26_decode(self): """NR-DEC-orb-blue-win.jp2-26-decode""" - jfile = os.path.join(data_root, - 'input/nonregression/orb-blue10-win-jp2.jp2') + jfile = opj_data_file('input/nonregression/orb-blue10-win-jp2.jp2') Jp2k(jfile).read() self.assertTrue(True) def test_nr_dec_relax_jp2_27_decode(self): """NR-DEC-relax.jp2-27-decode""" - jfile = os.path.join(data_root, - 'input/nonregression/relax.jp2') + jfile = opj_data_file('input/nonregression/relax.jp2') Jp2k(jfile).read() self.assertTrue(True) def test_nr_dec_test_lossless_j2k_28_decode(self): """NR-DEC-test-lossless.j2k-28-decode""" - jfile = os.path.join(data_root, - 'input/nonregression/test_lossless.j2k') + jfile = opj_data_file('input/nonregression/test_lossless.j2k') Jp2k(jfile).read() self.assertTrue(True) def test_nr_dec_issue104_jpxstream_jp2_33_decode(self): """NR-DEC-issue104-jpxstream.jp2-33-decode""" - jfile = os.path.join(data_root, - 'input/nonregression/issue104_jpxstream.jp2') + jfile = opj_data_file('input/nonregression/issue104_jpxstream.jp2') Jp2k(jfile).read() self.assertTrue(True) def test_nr_dec_file_409752_jp2_40_decode(self): """NR-DEC-file-409752.jp2-40-decode""" - jfile = os.path.join(data_root, 'input/nonregression/file409752.jp2') + jfile = opj_data_file('input/nonregression/file409752.jp2') j = Jp2k(jfile) with self.assertRaises(RuntimeError): j.read() diff --git a/glymur/test/test_opj_suite_neg.py b/glymur/test/test_opj_suite_neg.py index e8675aa..66115a2 100644 --- a/glymur/test/test_opj_suite_neg.py +++ b/glymur/test/test_opj_suite_neg.py @@ -23,23 +23,17 @@ else: import numpy as np from .fixtures import read_image, NO_READ_BACKEND, NO_READ_BACKEND_MSG +from .fixtures import OPJ_DATA_ROOT, opj_data_file from glymur import Jp2k import glymur -try: - DATA_ROOT = os.environ['OPJ_DATA_ROOT'] -except KeyError: - DATA_ROOT = None -except: - raise - @unittest.skipIf(glymur.lib.openjp2.OPENJP2 is None, "Missing openjp2 library.") @unittest.skipIf(NO_READ_BACKEND, NO_READ_BACKEND_MSG) -@unittest.skipIf(DATA_ROOT is None, - "OPJ_DATA_ROOT environment variable not set") +@unittest.skipIf(OPJ_DATA_ROOT is None, + "OPJ_OPJ_DATA_ROOT environment variable not set") class TestSuiteNegative(unittest.TestCase): """Test suite for certain negative tests from openjpeg suite.""" @@ -54,7 +48,7 @@ class TestSuiteNegative(unittest.TestCase): def test_psnr_with_cratios(self): """Using psnr with cratios options is not allowed.""" # Not an OpenJPEG test, but close. - infile = os.path.join(DATA_ROOT, 'input/nonregression/Bretagne1.ppm') + infile = opj_data_file('input/nonregression/Bretagne1.ppm') data = read_image(infile) with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile: j = Jp2k(tfile.name, 'wb') @@ -64,7 +58,7 @@ class TestSuiteNegative(unittest.TestCase): def test_nr_marker_not_compliant(self): """non-compliant marker, should still be able to read""" relpath = 'input/nonregression/MarkerIsNotCompliant.j2k' - jfile = os.path.join(DATA_ROOT, relpath) + jfile = opj_data_file(relpath) jp2k = Jp2k(jfile) jp2k.get_codestream(header_only=False) self.assertTrue(True) @@ -74,7 +68,7 @@ class TestSuiteNegative(unittest.TestCase): def test_nr_illegalclrtransform(self): """EOC marker is bad""" relpath = 'input/nonregression/illegalcolortransform.j2k' - jfile = os.path.join(DATA_ROOT, relpath) + jfile = opj_data_file(relpath) jp2k = Jp2k(jfile) with self.assertWarns(UserWarning): codestream = jp2k.get_codestream(header_only=False) @@ -87,7 +81,7 @@ class TestSuiteNegative(unittest.TestCase): def test_nr_cannotreadwnosizeknown(self): """not sure exactly what is wrong with this file""" relpath = 'input/nonregression/Cannotreaddatawithnosizeknown.j2k' - jfile = os.path.join(DATA_ROOT, relpath) + jfile = opj_data_file(relpath) jp2k = Jp2k(jfile) jp2k.get_codestream(header_only=False) self.assertTrue(True) @@ -118,7 +112,7 @@ class TestSuiteNegative(unittest.TestCase): # Verify that a warning is issued if we read past the end of a box # This file has a palette (pclr) box whose length is impossibly # short. - infile = os.path.join(DATA_ROOT, + infile = os.path.join(OPJ_DATA_ROOT, 'input/nonregression/mem-b2ace68c-1381.jp2') with self.assertWarns(UserWarning): Jp2k(infile) diff --git a/glymur/test/test_opj_suite_write.py b/glymur/test/test_opj_suite_write.py index e6f1575..479cb1f 100644 --- a/glymur/test/test_opj_suite_write.py +++ b/glymur/test/test_opj_suite_write.py @@ -19,23 +19,17 @@ else: import unittest from .fixtures import read_image, NO_READ_BACKEND, NO_READ_BACKEND_MSG +from .fixtures import OPJ_DATA_ROOT, opj_data_file from glymur import Jp2k import glymur -try: - data_root = os.environ['OPJ_DATA_ROOT'] -except KeyError: - data_root = None -except: - raise - @unittest.skipIf(os.name == "nt", "no write support on windows, period") @unittest.skipIf(glymur.lib.openjp2.OPENJP2 is None, "Missing openjp2 library.") @unittest.skipIf(NO_READ_BACKEND, NO_READ_BACKEND_MSG) -@unittest.skipIf(data_root is None, +@unittest.skipIf(OPJ_DATA_ROOT is None, "OPJ_DATA_ROOT environment variable not set") class TestSuiteWrite(unittest.TestCase): """Tests for writing with openjp2 backend. @@ -51,7 +45,7 @@ class TestSuiteWrite(unittest.TestCase): def test_NR_ENC_Bretagne1_ppm_1_encode(self): """NR-ENC-Bretagne1.ppm-1-encode""" - infile = os.path.join(data_root, 'input/nonregression/Bretagne1.ppm') + infile = opj_data_file('input/nonregression/Bretagne1.ppm') data = read_image(infile) with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile: j = Jp2k(tfile.name, 'wb') @@ -115,7 +109,7 @@ class TestSuiteWrite(unittest.TestCase): def test_NR_ENC_Bretagne1_ppm_2_encode(self): """NR-ENC-Bretagne1.ppm-2-encode""" - infile = os.path.join(data_root, 'input/nonregression/Bretagne1.ppm') + infile = opj_data_file('input/nonregression/Bretagne1.ppm') data = read_image(infile) with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile: j = Jp2k(tfile.name, 'wb') @@ -180,7 +174,7 @@ class TestSuiteWrite(unittest.TestCase): def test_NR_ENC_Bretagne1_ppm_3_encode(self): """NR-ENC-Bretagne1.ppm-3-encode""" - infile = os.path.join(data_root, 'input/nonregression/Bretagne1.ppm') + infile = opj_data_file('input/nonregression/Bretagne1.ppm') data = read_image(infile) with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile: j = Jp2k(tfile.name, 'wb') @@ -247,7 +241,7 @@ class TestSuiteWrite(unittest.TestCase): def test_NR_ENC_Bretagne2_ppm_4_encode(self): """NR-ENC-Bretagne2.ppm-4-encode""" - infile = os.path.join(data_root, 'input/nonregression/Bretagne2.ppm') + infile = opj_data_file('input/nonregression/Bretagne2.ppm') data = read_image(infile) with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile: j = Jp2k(tfile.name, 'wb') @@ -316,7 +310,7 @@ class TestSuiteWrite(unittest.TestCase): def test_NR_ENC_Bretagne2_ppm_5_encode(self): """NR-ENC-Bretagne2.ppm-5-encode""" - infile = os.path.join(data_root, 'input/nonregression/Bretagne2.ppm') + infile = opj_data_file('input/nonregression/Bretagne2.ppm') data = read_image(infile) with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile: j = Jp2k(tfile.name, 'wb') @@ -379,7 +373,7 @@ class TestSuiteWrite(unittest.TestCase): def test_NR_ENC_Bretagne2_ppm_6_encode(self): """NR-ENC-Bretagne2.ppm-6-encode""" - infile = os.path.join(data_root, 'input/nonregression/Bretagne2.ppm') + infile = opj_data_file('input/nonregression/Bretagne2.ppm') data = read_image(infile) with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile: j = Jp2k(tfile.name, 'wb') @@ -447,7 +441,7 @@ class TestSuiteWrite(unittest.TestCase): def test_NR_ENC_Bretagne2_ppm_7_encode(self): """NR-ENC-Bretagne2.ppm-7-encode""" - infile = os.path.join(data_root, 'input/nonregression/Bretagne2.ppm') + infile = opj_data_file('input/nonregression/Bretagne2.ppm') data = read_image(infile) with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile: j = Jp2k(tfile.name, 'wb') @@ -514,7 +508,7 @@ class TestSuiteWrite(unittest.TestCase): def test_NR_ENC_Bretagne2_ppm_8_encode(self): """NR-ENC-Bretagne2.ppm-8-encode""" - infile = os.path.join(data_root, 'input/nonregression/Bretagne2.ppm') + infile = opj_data_file('input/nonregression/Bretagne2.ppm') data = read_image(infile) with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile: j = Jp2k(tfile.name, 'wb') @@ -578,7 +572,7 @@ class TestSuiteWrite(unittest.TestCase): def test_NR_ENC_Cevennes1_bmp_9_encode(self): """NR-ENC-Cevennes1.bmp-9-encode""" - infile = os.path.join(data_root, 'input/nonregression/Cevennes1.bmp') + infile = opj_data_file('input/nonregression/Cevennes1.bmp') data = read_image(infile) with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile: j = Jp2k(tfile.name, 'wb') @@ -641,7 +635,7 @@ class TestSuiteWrite(unittest.TestCase): def test_NR_ENC_Cevennes2_ppm_10_encode(self): """NR-ENC-Cevennes2.ppm-10-encode""" - infile = os.path.join(data_root, 'input/nonregression/Cevennes2.ppm') + infile = opj_data_file('input/nonregression/Cevennes2.ppm') data = read_image(infile) with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile: j = Jp2k(tfile.name, 'wb') @@ -704,8 +698,7 @@ class TestSuiteWrite(unittest.TestCase): def test_NR_ENC_Rome_bmp_11_encode(self): """NR-ENC-Rome.bmp-11-encode""" - data = read_image(os.path.join(data_root, - 'input/nonregression/Rome.bmp')) + data = read_image(opj_data_file('input/nonregression/Rome.bmp')) with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: jp2 = Jp2k(tfile.name, 'wb') jp2.write(data, psnr=[30, 35, 50], prog='LRCP', numres=3) @@ -804,8 +797,7 @@ class TestSuiteWrite(unittest.TestCase): """NR-ENC-random-issue-0005.tif-12-encode""" # opj_decompress has trouble reading it, but that is not an issue here. # The nature of the image itself seems to give the compressor trouble. - infile = os.path.join(data_root, - 'input/nonregression/random-issue-0005.tif') + infile = opj_data_file('input/nonregression/random-issue-0005.tif') data = read_image(infile) with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile: j = Jp2k(tfile.name, 'wb') diff --git a/glymur/test/test_printing.py b/glymur/test/test_printing.py index f533aa4..8591b1b 100644 --- a/glymur/test/test_printing.py +++ b/glymur/test/test_printing.py @@ -32,13 +32,7 @@ else: import glymur from glymur import Jp2k - -try: - DATA_ROOT = os.environ['OPJ_DATA_ROOT'] -except KeyError: - DATA_ROOT = None -except: - raise +from .fixtures import OPJ_DATA_ROOT, opj_data_file @unittest.skipIf(os.name == "nt", "Temporary file issue on window.") @@ -287,11 +281,11 @@ class TestPrinting(unittest.TestCase): expected = '\n'.join(lines) self.assertEqual(actual, expected) - @unittest.skipIf(DATA_ROOT is None, + @unittest.skipIf(OPJ_DATA_ROOT is None, "OPJ_DATA_ROOT environment variable not set") def test_icc_profile(self): """verify printing of colr box with ICC profile""" - filename = os.path.join(DATA_ROOT, 'input/nonregression/text_GBR.jp2') + filename = opj_data_file('input/nonregression/text_GBR.jp2') with warnings.catch_warnings(): # brand is 'jp2 ', but has any icc profile. warnings.simplefilter("ignore") @@ -356,11 +350,11 @@ class TestPrinting(unittest.TestCase): expected = '\n'.join(lines) self.assertEqual(actual, expected) - @unittest.skipIf(DATA_ROOT is None, + @unittest.skipIf(OPJ_DATA_ROOT is None, "OPJ_DATA_ROOT environment variable not set") def test_crg(self): """verify printing of CRG segment""" - filename = os.path.join(DATA_ROOT, 'input/conformance/p0_03.j2k') + filename = opj_data_file('input/conformance/p0_03.j2k') j = glymur.Jp2k(filename) codestream = j.get_codestream() with patch('sys.stdout', new=StringIO()) as fake_out: @@ -371,11 +365,11 @@ class TestPrinting(unittest.TestCase): expected = '\n'.join(lines) self.assertEqual(actual, expected) - @unittest.skipIf(DATA_ROOT is None, + @unittest.skipIf(OPJ_DATA_ROOT is None, "OPJ_DATA_ROOT environment variable not set") def test_rgn(self): """verify printing of RGN segment""" - filename = os.path.join(DATA_ROOT, 'input/conformance/p0_03.j2k') + filename = opj_data_file('input/conformance/p0_03.j2k') j = glymur.Jp2k(filename) codestream = j.get_codestream(header_only=False) with patch('sys.stdout', new=StringIO()) as fake_out: @@ -388,11 +382,11 @@ class TestPrinting(unittest.TestCase): expected = '\n'.join(lines) self.assertEqual(actual, expected) - @unittest.skipIf(DATA_ROOT is None, + @unittest.skipIf(OPJ_DATA_ROOT is None, "OPJ_DATA_ROOT environment variable not set") def test_sop(self): """verify printing of SOP segment""" - filename = os.path.join(DATA_ROOT, 'input/conformance/p0_03.j2k') + filename = opj_data_file('input/conformance/p0_03.j2k') j = glymur.Jp2k(filename) codestream = j.get_codestream(header_only=False) with patch('sys.stdout', new=StringIO()) as fake_out: @@ -403,11 +397,11 @@ class TestPrinting(unittest.TestCase): expected = '\n'.join(lines) self.assertEqual(actual, expected) - @unittest.skipIf(DATA_ROOT is None, + @unittest.skipIf(OPJ_DATA_ROOT is None, "OPJ_DATA_ROOT environment variable not set") def test_cme(self): """Test printing a CME or comment marker segment.""" - filename = os.path.join(DATA_ROOT, 'input/conformance/p0_02.j2k') + filename = opj_data_file('input/conformance/p0_02.j2k') j = glymur.Jp2k(filename) codestream = j.get_codestream() # 2nd to last segment in the main header @@ -431,11 +425,11 @@ class TestPrinting(unittest.TestCase): expected = '\n'.join(lines) self.assertEqual(actual, expected) - @unittest.skipIf(DATA_ROOT is None, + @unittest.skipIf(OPJ_DATA_ROOT is None, "OPJ_DATA_ROOT environment variable not set") def test_plt_segment(self): """verify printing of PLT segment""" - filename = os.path.join(DATA_ROOT, 'input/conformance/p0_07.j2k') + filename = opj_data_file('input/conformance/p0_07.j2k') j = glymur.Jp2k(filename) codestream = j.get_codestream(header_only=False) with patch('sys.stdout', new=StringIO()) as fake_out: @@ -450,11 +444,11 @@ class TestPrinting(unittest.TestCase): expected = '\n'.join(lines) self.assertEqual(actual, expected) - @unittest.skipIf(DATA_ROOT is None, + @unittest.skipIf(OPJ_DATA_ROOT is None, "OPJ_DATA_ROOT environment variable not set") def test_pod_segment(self): """verify printing of POD segment""" - filename = os.path.join(DATA_ROOT, 'input/conformance/p0_13.j2k') + filename = opj_data_file('input/conformance/p0_13.j2k') j = glymur.Jp2k(filename) codestream = j.get_codestream() with patch('sys.stdout', new=StringIO()) as fake_out: @@ -480,11 +474,11 @@ class TestPrinting(unittest.TestCase): expected = '\n'.join(lines) self.assertEqual(actual, expected) - @unittest.skipIf(DATA_ROOT is None, + @unittest.skipIf(OPJ_DATA_ROOT is None, "OPJ_DATA_ROOT environment variable not set") def test_ppm_segment(self): """verify printing of PPM segment""" - filename = os.path.join(DATA_ROOT, 'input/conformance/p1_03.j2k') + filename = opj_data_file('input/conformance/p1_03.j2k') j = glymur.Jp2k(filename) codestream = j.get_codestream() with patch('sys.stdout', new=StringIO()) as fake_out: @@ -498,11 +492,11 @@ class TestPrinting(unittest.TestCase): expected = '\n'.join(lines) self.assertEqual(actual, expected) - @unittest.skipIf(DATA_ROOT is None, + @unittest.skipIf(OPJ_DATA_ROOT is None, "OPJ_DATA_ROOT environment variable not set") def test_ppt_segment(self): """verify printing of ppt segment""" - filename = os.path.join(DATA_ROOT, 'input/conformance/p1_06.j2k') + filename = opj_data_file('input/conformance/p1_06.j2k') j = glymur.Jp2k(filename) codestream = j.get_codestream(header_only=False) with patch('sys.stdout', new=StringIO()) as fake_out: @@ -610,11 +604,11 @@ class TestPrinting(unittest.TestCase): expected = '\n'.join(lines) self.assertEqual(actual, expected) - @unittest.skipIf(DATA_ROOT is None, + @unittest.skipIf(OPJ_DATA_ROOT is None, "OPJ_DATA_ROOT environment variable not set") def test_tlm_segment(self): """verify printing of TLM segment""" - filename = os.path.join(DATA_ROOT, 'input/conformance/p0_15.j2k') + filename = opj_data_file('input/conformance/p0_15.j2k') j = glymur.Jp2k(filename) codestream = j.get_codestream() with patch('sys.stdout', new=StringIO()) as fake_out: @@ -704,11 +698,11 @@ class TestPrinting(unittest.TestCase): @unittest.skipIf(sys.hexversion < 0x02070000, "Differences in XML printing between 2.6 and 2.7") - @unittest.skipIf(DATA_ROOT is None, + @unittest.skipIf(OPJ_DATA_ROOT is None, "OPJ_DATA_ROOT environment variable not set") def test_xml(self): """verify printing of XML box""" - filename = os.path.join(DATA_ROOT, 'input/conformance/file1.jp2') + filename = opj_data_file('input/conformance/file1.jp2') j = glymur.Jp2k(filename) with patch('sys.stdout', new=StringIO()) as fake_out: print(j.box[2]) @@ -735,11 +729,11 @@ class TestPrinting(unittest.TestCase): expected = '\n'.join(lines) self.assertEqual(actual, expected) - @unittest.skipIf(DATA_ROOT is None, + @unittest.skipIf(OPJ_DATA_ROOT is None, "OPJ_DATA_ROOT environment variable not set") def test_channel_definition(self): """verify printing of cdef box""" - filename = os.path.join(DATA_ROOT, 'input/conformance/file2.jp2') + filename = opj_data_file('input/conformance/file2.jp2') j = glymur.Jp2k(filename) with patch('sys.stdout', new=StringIO()) as fake_out: print(j.box[2].box[2]) @@ -751,11 +745,11 @@ class TestPrinting(unittest.TestCase): expected = '\n'.join(lines) self.assertEqual(actual, expected) - @unittest.skipIf(DATA_ROOT is None, + @unittest.skipIf(OPJ_DATA_ROOT is None, "OPJ_DATA_ROOT environment variable not set") def test_component_mapping(self): """verify printing of cmap box""" - filename = os.path.join(DATA_ROOT, 'input/conformance/file9.jp2') + filename = opj_data_file('input/conformance/file9.jp2') j = glymur.Jp2k(filename) with patch('sys.stdout', new=StringIO()) as fake_out: print(j.box[2].box[2]) @@ -767,11 +761,11 @@ class TestPrinting(unittest.TestCase): expected = '\n'.join(lines) self.assertEqual(actual, expected) - @unittest.skipIf(DATA_ROOT is None, + @unittest.skipIf(OPJ_DATA_ROOT is None, "OPJ_DATA_ROOT environment variable not set") def test_palette7(self): """verify printing of pclr box""" - filename = os.path.join(DATA_ROOT, 'input/conformance/file9.jp2') + filename = opj_data_file('input/conformance/file9.jp2') j = glymur.Jp2k(filename) with patch('sys.stdout', new=StringIO()) as fake_out: print(j.box[2].box[1]) @@ -781,11 +775,11 @@ class TestPrinting(unittest.TestCase): expected = '\n'.join(lines) self.assertEqual(actual, expected) - @unittest.skipIf(DATA_ROOT is None, + @unittest.skipIf(OPJ_DATA_ROOT is None, "OPJ_DATA_ROOT environment variable not set") def test_rreq(self): """verify printing of reader requirements box""" - filename = os.path.join(DATA_ROOT, 'input/conformance/file7.jp2') + filename = opj_data_file('input/conformance/file7.jp2') j = glymur.Jp2k(filename) with patch('sys.stdout', new=StringIO()) as fake_out: print(j.box[2]) @@ -805,11 +799,11 @@ class TestPrinting(unittest.TestCase): expected = '\n'.join(lines) self.assertEqual(actual, expected) - @unittest.skipIf(DATA_ROOT is None, + @unittest.skipIf(OPJ_DATA_ROOT is None, "OPJ_DATA_ROOT environment variable not set") def test_differing_subsamples(self): """verify printing of SIZ with different subsampling... Issue 86.""" - filename = os.path.join(DATA_ROOT, 'input/conformance/p0_05.j2k') + filename = opj_data_file('input/conformance/p0_05.j2k') j = glymur.Jp2k(filename) codestream = j.get_codestream() with patch('sys.stdout', new=StringIO()) as fake_out: @@ -828,11 +822,11 @@ class TestPrinting(unittest.TestCase): expected = '\n'.join(lines) self.assertEqual(actual, expected) - @unittest.skipIf(DATA_ROOT is None, + @unittest.skipIf(OPJ_DATA_ROOT is None, "OPJ_DATA_ROOT environment variable not set") def test_palette_box(self): """Verify that palette (pclr) boxes are printed without error.""" - filename = os.path.join(DATA_ROOT, 'input/conformance/file9.jp2') + filename = opj_data_file('input/conformance/file9.jp2') j = glymur.Jp2k(filename) with patch('sys.stdout', new=StringIO()) as fake_out: print(j.box[2].box[1]) @@ -921,13 +915,13 @@ class TestPrinting(unittest.TestCase): @unittest.skipIf(sys.hexversion < 0x03000000, "Ordered dicts not printing well in 2.7") - @unittest.skipIf(DATA_ROOT is None, + @unittest.skipIf(OPJ_DATA_ROOT is None, "OPJ_DATA_ROOT environment variable not set") def test_jpx_approx_icc_profile(self): """verify jpx with approx field equal to zero""" # ICC profiles may be used in JP2, but the approximation field should # be zero unless we have jpx. This file does both. - filename = os.path.join(DATA_ROOT, 'input/nonregression/text_GBR.jp2') + filename = opj_data_file('input/nonregression/text_GBR.jp2') with warnings.catch_warnings(): # brand is 'jp2 ', but has any icc profile. warnings.simplefilter("ignore") @@ -966,11 +960,11 @@ class TestPrinting(unittest.TestCase): expected = '\n'.join(lines) self.assertEqual(actual, expected) - @unittest.skipIf(DATA_ROOT is None, + @unittest.skipIf(OPJ_DATA_ROOT is None, "OPJ_DATA_ROOT environment variable not set") def test_uuid(self): """verify printing of UUID box""" - filename = os.path.join(DATA_ROOT, 'input/nonregression/text_GBR.jp2') + filename = opj_data_file('input/nonregression/text_GBR.jp2') with warnings.catch_warnings(): # brand is 'jp2 ', but has any icc profile. warnings.simplefilter("ignore") From 80cb2585b164add8ac5535bc4751ab1b51e43c9c Mon Sep 17 00:00:00 2001 From: jevans Date: Thu, 5 Sep 2013 21:34:52 -0400 Subject: [PATCH 03/22] OPENJPEG_VERSION is now the version of the software, not the library. For #110 --- glymur/test/fixtures.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/glymur/test/fixtures.py b/glymur/test/fixtures.py index 4c99ade..933222a 100644 --- a/glymur/test/fixtures.py +++ b/glymur/test/fixtures.py @@ -10,10 +10,12 @@ import numpy as np import glymur -# Need to know the openjpeg version. If openjpeg is not installed, we use -# '0.0.0' +# Need to know the version of the openjpeg software. If openjpeg is not +# installed, we use # '0.0.0' OPENJPEG_VERSION = '0.0.0' -if glymur.lib.openjpeg.OPENJPEG is not None: +if glymur.lib.openjp2.OPENJP2 is not None: + OPENJPEG_VERSION = glymur.lib.openjp2.version() +elif glymur.lib.openjpeg.OPENJPEG is not None: OPENJPEG_VERSION = glymur.lib.openjpeg.version() # Need to know of the libopenjp2 version is the official 2.0.0 release and NOT From 02c186107dea1fa6f2e5b7accb3e7c127fb31bc7 Mon Sep 17 00:00:00 2001 From: jevans Date: Thu, 5 Sep 2013 21:39:05 -0400 Subject: [PATCH 04/22] Removing duplicated tests. #110 --- glymur/test/test_opj_suite.py | 639 +--------------------------------- 1 file changed, 9 insertions(+), 630 deletions(-) diff --git a/glymur/test/test_opj_suite.py b/glymur/test/test_opj_suite.py index 93e9745..c6dfbda 100644 --- a/glymur/test/test_opj_suite.py +++ b/glymur/test/test_opj_suite.py @@ -49,8 +49,9 @@ from .fixtures import OPENJPEG_VERSION, OPENJP2_IS_V2_OFFICIAL, OPJ_DATA_ROOT from .fixtures import mse, peak_tolerance, read_pgx, opj_data_file -@unittest.skipIf(glymur.lib.openjp2.OPENJP2 is None, - "Missing openjp2 library.") +@unittest.skipIf(glymur.lib.openjp2.OPENJP2 is None and + glymur.lib.openjpeg.OPENJPEG is None, + "Missing openjpeg libraries.") @unittest.skipIf(OPJ_DATA_ROOT is None, "OPJ_DATA_ROOT environment variable not set") class TestSuite(unittest.TestCase): @@ -725,6 +726,8 @@ class TestSuite(unittest.TestCase): jpdata = jp2k.read() self.assertEqual(jpdata.shape, (640, 480, 3)) + @unittest.skipIf(re.match(r"""1\.[0125]\.\d""", OPENJPEG_VERSION), + "Functionality not implemented for 1.x") def test_ETS_JP2_file3(self): jfile = opj_data_file('input/conformance/file3.jp2') jp2k = Jp2k(jfile) @@ -1034,6 +1037,8 @@ class TestSuite(unittest.TestCase): @unittest.skipIf(OPENJP2_IS_V2_OFFICIAL, "Test not in done in v2.0.0 official") + @unittest.skipIf(re.match(r"""1\.[0125]\.\d""", OPENJPEG_VERSION), + "Segfaults 1.5") def test_NR_DEC_gdal_fuzzer_check_comp_dx_dy_jp2_39_decode(self): relpath = 'input/nonregression/gdal_fuzzer_check_comp_dx_dy.jp2' jfile = opj_data_file(relpath) @@ -1050,6 +1055,8 @@ class TestSuite(unittest.TestCase): @unittest.skipIf(OPENJP2_IS_V2_OFFICIAL, "Test not in done in v2.0.0 official") + @unittest.skipIf(re.match(r"""1\.[0125]\.\d""", OPENJPEG_VERSION), + "Segfaults 1.5") @unittest.skipIf(sys.hexversion < 0x03020000, "Uses features introduced in 3.2.") def test_NR_DEC_issue188_beach_64bitsbox_jp2_41_decode(self): @@ -7310,633 +7317,5 @@ class TestSuiteDump(unittest.TestCase): [8, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10]) -@unittest.skipIf(glymur.lib.openjpeg.OPENJPEG is None, - "Missing openjpeg library.") -@unittest.skipIf(OPJ_DATA_ROOT is None, - "OPJ_DATA_ROOT environment variable not set") -class TestSuite15(unittest.TestCase): - """Suite of tests for libopenjpeg 1.5.1""" - - @classmethod - def setUpClass(cls): - # Monkey patch the package so as to use OPENJPEG instead of OPENJP2 - cls.openjp2 = glymur.lib.openjp2.OPENJP2 - glymur.lib.openjp2.OPENJP2 = None - - @classmethod - def tearDownClass(cls): - # Restore OPENJP2 - glymur.lib.openjp2.OPENJP2 = cls.openjp2 - - def setUp(self): - pass - - def tearDown(self): - pass - - def test_ETS_C0P0_p0_01_j2k(self): - jfile = opj_data_file('input/conformance/p0_01.j2k') - jp2k = Jp2k(jfile) - jpdata = jp2k.read(rlevel=0) - - pgxfile = opj_data_file('baseline/conformance/c0p0_01.pgx') - pgxdata = read_pgx(pgxfile) - np.testing.assert_array_equal(jpdata, pgxdata) - - def test_ETS_C0P0_p0_02_j2k(self): - jfile = opj_data_file('input/conformance/p0_02.j2k') - with warnings.catch_warnings(): - # There's a 0xff30 marker segment. Not illegal, but we don't - # really know what to do with it. Just ignore. - warnings.simplefilter("ignore") - jp2k = Jp2k(jfile) - jpdata = jp2k.read(rlevel=0) - - pgxfile = opj_data_file('baseline/conformance/c0p0_02.pgx') - pgxdata = read_pgx(pgxfile) - np.testing.assert_array_equal(jpdata, pgxdata) - - def test_ETS_C0P0_p0_09_j2k(self): - jfile = opj_data_file('input/conformance/p0_09.j2k') - jp2k = Jp2k(jfile) - jpdata = jp2k.read(rlevel=2) - - pgxfile = opj_data_file('baseline/conformance/c0p0_09.pgx') - pgxdata = read_pgx(pgxfile) - - self.assertTrue(peak_tolerance(jpdata, pgxdata) < 4) - self.assertTrue(mse(jpdata, pgxdata) < 1.47) - - def test_ETS_C0P0_p0_11_j2k(self): - jfile = opj_data_file('input/conformance/p0_11.j2k') - jp2k = Jp2k(jfile) - jpdata = jp2k.read(rlevel=0) - - pgxfile = opj_data_file('baseline/conformance/c0p0_11.pgx') - pgxdata = read_pgx(pgxfile) - - np.testing.assert_array_equal(jpdata, pgxdata) - - @unittest.skip("fprintf stderr output in r2343.") - def test_ETS_C0P0_p0_12_j2k(self): - jfile = opj_data_file('input/conformance/p0_12.j2k') - jp2k = Jp2k(jfile) - jpdata = jp2k.read(rlevel=0) - - pgxfile = opj_data_file('baseline/conformance/c0p0_12.pgx') - pgxdata = read_pgx(pgxfile) - - np.testing.assert_array_equal(jpdata, pgxdata) - - def test_ETS_C0P0_p0_16_j2k(self): - jfile = opj_data_file('input/conformance/p0_16.j2k') - jp2k = Jp2k(jfile) - jpdata = jp2k.read(rlevel=0) - - pgxfile = opj_data_file('baseline/conformance/c0p0_16.pgx') - pgxdata = read_pgx(pgxfile) - - np.testing.assert_array_equal(jpdata, pgxdata) - - def test_ETS_C0P1_p1_01_j2k(self): - jfile = opj_data_file('input/conformance/p1_01.j2k') - jp2k = Jp2k(jfile) - jpdata = jp2k.read(rlevel=0) - - pgxfile = opj_data_file('baseline/conformance/c0p1_01.pgx') - pgxdata = read_pgx(pgxfile) - - np.testing.assert_array_equal(jpdata, pgxdata) - - def test_ETS_C1P0_p0_01_j2k(self): - jfile = opj_data_file('input/conformance/p0_01.j2k') - jp2k = Jp2k(jfile) - jpdata = jp2k.read(rlevel=0) - - pgxfile = opj_data_file('baseline/conformance/c1p0_01_0.pgx') - pgxdata = read_pgx(pgxfile) - - np.testing.assert_array_equal(jpdata, pgxdata) - - def test_ETS_C1P0_p0_02_j2k(self): - jfile = opj_data_file('input/conformance/p0_02.j2k') - with warnings.catch_warnings(): - # There's a 0xff30 marker segment. Not illegal, but we don't - # really know what to do with it. Just ignore. - warnings.simplefilter("ignore") - jp2k = Jp2k(jfile) - jpdata = jp2k.read(rlevel=0) - - pgxfile = opj_data_file('baseline/conformance/c1p0_02_0.pgx') - pgxdata = read_pgx(pgxfile) - - np.testing.assert_array_equal(jpdata, pgxdata) - - def test_ETS_C1P0_p0_03_j2k(self): - jfile = opj_data_file('input/conformance/p0_03.j2k') - jp2k = Jp2k(jfile) - jpdata = jp2k.read(rlevel=0) - - pgxfile = opj_data_file('baseline/conformance/c1p0_03_0.pgx') - pgxdata = read_pgx(pgxfile) - - np.testing.assert_array_equal(jpdata, pgxdata) - - def test_ETS_C1P0_p0_04_j2k(self): - jfile = opj_data_file('input/conformance/p0_04.j2k') - jp2k = Jp2k(jfile) - jpdata = jp2k.read(rlevel=0) - - pgxfile = opj_data_file('baseline/conformance/c1p0_04_0.pgx') - pgxdata = read_pgx(pgxfile) - self.assertTrue(peak_tolerance(jpdata[:, :, 0], pgxdata) < 5) - self.assertTrue(mse(jpdata[:, :, 0], pgxdata) < 0.776) - - pgxfile = opj_data_file('baseline/conformance/c1p0_04_1.pgx') - pgxdata = read_pgx(pgxfile) - self.assertTrue(peak_tolerance(jpdata[:, :, 1], pgxdata) < 4) - self.assertTrue(mse(jpdata[:, :, 1], pgxdata) < 0.626) - - pgxfile = opj_data_file('baseline/conformance/c1p0_04_2.pgx') - pgxdata = read_pgx(pgxfile) - self.assertTrue(peak_tolerance(jpdata[:, :, 2], pgxdata) < 6) - self.assertTrue(mse(jpdata[:, :, 2], pgxdata) < 1.07) - - def test_ETS_C1P0_p0_08_j2k(self): - jfile = opj_data_file('input/conformance/p0_08.j2k') - jp2k = Jp2k(jfile) - jpdata = jp2k.read(rlevel=1) - - pgxfile = opj_data_file('baseline/conformance/c1p0_08_0.pgx') - pgxdata = read_pgx(pgxfile) - np.testing.assert_array_equal(jpdata[:, :, 0], pgxdata) - - pgxfile = opj_data_file('baseline/conformance/c1p0_08_1.pgx') - pgxdata = read_pgx(pgxfile) - np.testing.assert_array_equal(jpdata[:, :, 1], pgxdata) - - pgxfile = opj_data_file('baseline/conformance/c1p0_08_2.pgx') - pgxdata = read_pgx(pgxfile) - np.testing.assert_array_equal(jpdata[:, :, 2], pgxdata) - - def test_ETS_C1P0_p0_09_j2k(self): - jfile = opj_data_file('input/conformance/p0_09.j2k') - jp2k = Jp2k(jfile) - jpdata = jp2k.read(rlevel=0) - - pgxfile = opj_data_file('baseline/conformance/c1p0_09_0.pgx') - pgxdata = read_pgx(pgxfile) - np.testing.assert_array_equal(jpdata, pgxdata) - - def test_ETS_C1P0_p0_10_j2k(self): - jfile = opj_data_file('input/conformance/p0_10.j2k') - jp2k = Jp2k(jfile) - with warnings.catch_warnings(): - # This file has an invalid ICC profile - warnings.simplefilter("ignore") - jpdata = jp2k.read(rlevel=0) - - pgxfile = opj_data_file('baseline/conformance/c1p0_10_0.pgx') - pgxdata = read_pgx(pgxfile) - np.testing.assert_array_equal(jpdata[:, :, 0], pgxdata) - - pgxfile = opj_data_file('baseline/conformance/c1p0_10_1.pgx') - pgxdata = read_pgx(pgxfile) - np.testing.assert_array_equal(jpdata[:, :, 1], pgxdata) - - pgxfile = opj_data_file('baseline/conformance/c1p0_10_2.pgx') - pgxdata = read_pgx(pgxfile) - np.testing.assert_array_equal(jpdata[:, :, 2], pgxdata) - - def test_ETS_C1P0_p0_11_j2k(self): - jfile = opj_data_file('input/conformance/p0_11.j2k') - jp2k = Jp2k(jfile) - jpdata = jp2k.read(rlevel=0) - - pgxfile = opj_data_file('baseline/conformance/c1p0_11_0.pgx') - pgxdata = read_pgx(pgxfile) - np.testing.assert_array_equal(jpdata, pgxdata) - - @unittest.skip("fprintf stderr output in r2343.") - def test_ETS_C1P0_p0_12_j2k(self): - jfile = opj_data_file('input/conformance/p0_12.j2k') - jp2k = Jp2k(jfile) - jpdata = jp2k.read(rlevel=0) - - pgxfile = opj_data_file('baseline/conformance/c1p0_12_0.pgx') - pgxdata = read_pgx(pgxfile) - np.testing.assert_array_equal(jpdata, pgxdata) - - @unittest.skip("fprintf stderr output in r2343.") - def test_ETS_C1P0_p0_13_j2k(self): - jfile = opj_data_file('input/conformance/p0_13.j2k') - jp2k = Jp2k(jfile) - jpdata = jp2k.read(rlevel=0) - - pgxfile = opj_data_file('baseline/conformance/c1p0_13_0.pgx') - pgxdata = read_pgx(pgxfile) - np.testing.assert_array_equal(jpdata[:, :, 0], pgxdata) - - pgxfile = opj_data_file('baseline/conformance/c1p0_13_1.pgx') - pgxdata = read_pgx(pgxfile) - np.testing.assert_array_equal(jpdata[:, :, 1], pgxdata) - - pgxfile = opj_data_file('baseline/conformance/c1p0_13_2.pgx') - pgxdata = read_pgx(pgxfile) - np.testing.assert_array_equal(jpdata[:, :, 2], pgxdata) - - pgxfile = opj_data_file('baseline/conformance/c1p0_13_3.pgx') - pgxdata = read_pgx(pgxfile) - np.testing.assert_array_equal(jpdata[:, :, 3], pgxdata) - - def test_ETS_C1P0_p0_14_j2k(self): - jfile = opj_data_file('input/conformance/p0_14.j2k') - jp2k = Jp2k(jfile) - jpdata = jp2k.read(rlevel=0) - - pgxfile = opj_data_file('baseline/conformance/c1p0_14_0.pgx') - pgxdata = read_pgx(pgxfile) - np.testing.assert_array_equal(jpdata[:, :, 0], pgxdata) - - pgxfile = opj_data_file('baseline/conformance/c1p0_14_1.pgx') - pgxdata = read_pgx(pgxfile) - np.testing.assert_array_equal(jpdata[:, :, 1], pgxdata) - - pgxfile = opj_data_file('baseline/conformance/c1p0_14_2.pgx') - pgxdata = read_pgx(pgxfile) - np.testing.assert_array_equal(jpdata[:, :, 2], pgxdata) - - def test_ETS_C1P0_p0_15_j2k(self): - jfile = opj_data_file('input/conformance/p0_15.j2k') - jp2k = Jp2k(jfile) - jpdata = jp2k.read(rlevel=0) - - pgxfile = opj_data_file('baseline/conformance/c1p0_15_0.pgx') - pgxdata = read_pgx(pgxfile) - np.testing.assert_array_equal(jpdata, pgxdata) - - def test_ETS_C1P0_p0_16_j2k(self): - jfile = opj_data_file('input/conformance/p0_16.j2k') - jp2k = Jp2k(jfile) - jpdata = jp2k.read(rlevel=0) - - pgxfile = opj_data_file('baseline/conformance/c1p0_16_0.pgx') - pgxdata = read_pgx(pgxfile) - np.testing.assert_array_equal(jpdata, pgxdata) - - def test_ETS_C1P1_p1_01_j2k(self): - jfile = opj_data_file('input/conformance/p1_01.j2k') - jp2k = Jp2k(jfile) - jpdata = jp2k.read(rlevel=0) - - pgxfile = opj_data_file('baseline/conformance/c1p1_01_0.pgx') - pgxdata = read_pgx(pgxfile) - np.testing.assert_array_equal(jpdata, pgxdata) - - def test_ETS_C1P1_p1_02_j2k(self): - jfile = opj_data_file('input/conformance/p1_02.j2k') - jp2k = Jp2k(jfile) - jpdata = jp2k.read(rlevel=0) - - pgxfile = opj_data_file('baseline/conformance/c1p1_02_0.pgx') - pgxdata = read_pgx(pgxfile) - self.assertTrue(peak_tolerance(jpdata[:, :, 0], pgxdata) < 5) - self.assertTrue(mse(jpdata[:, :, 0], pgxdata) < 0.765) - - pgxfile = opj_data_file('baseline/conformance/c1p1_02_1.pgx') - pgxdata = read_pgx(pgxfile) - self.assertTrue(peak_tolerance(jpdata[:, :, 1], pgxdata) < 4) - self.assertTrue(mse(jpdata[:, :, 1], pgxdata) < 0.616) - - pgxfile = opj_data_file('baseline/conformance/c1p1_02_2.pgx') - pgxdata = read_pgx(pgxfile) - self.assertTrue(peak_tolerance(jpdata[:, :, 2], pgxdata) < 6) - self.assertTrue(mse(jpdata[:, :, 2], pgxdata) < 1.051) - - def test_ETS_C1P1_p1_04_j2k(self): - jfile = opj_data_file('input/conformance/p1_04.j2k') - jp2k = Jp2k(jfile) - jpdata = jp2k.read() - - pgxfile = opj_data_file('baseline/conformance/c1p1_04_0.pgx') - pgxdata = read_pgx(pgxfile) - self.assertTrue(peak_tolerance(jpdata, pgxdata) < 624) - self.assertTrue(mse(jpdata, pgxdata) < 3080) - - @unittest.skip("fprintf stderr output in r2343.") - def test_ETS_C1P1_p1_05_j2k(self): - jfile = opj_data_file('input/conformance/p1_05.j2k') - jp2k = Jp2k(jfile) - jpdata = jp2k.read() - - pgxfile = opj_data_file('baseline/conformance/c1p1_05_0.pgx') - pgxdata = read_pgx(pgxfile) - self.assertTrue(peak_tolerance(jpdata[:, :, 0], pgxdata) < 40) - self.assertTrue(mse(jpdata[:, :, 0], pgxdata) < 8.458) - - pgxfile = opj_data_file('baseline/conformance/c1p1_05_1.pgx') - pgxdata = read_pgx(pgxfile) - self.assertTrue(peak_tolerance(jpdata[:, :, 1], pgxdata) < 40) - self.assertTrue(mse(jpdata[:, :, 1], pgxdata) < 9.816) - - pgxfile = opj_data_file('baseline/conformance/c1p1_05_2.pgx') - pgxdata = read_pgx(pgxfile) - self.assertTrue(peak_tolerance(jpdata[:, :, 2], pgxdata) < 40) - self.assertTrue(mse(jpdata[:, :, 2], pgxdata) < 10.154) - - @unittest.skip("fprintf stderr output in r2343.") - def test_ETS_C1P1_p1_06_j2k(self): - jfile = opj_data_file('input/conformance/p1_06.j2k') - jp2k = Jp2k(jfile) - jpdata = jp2k.read() - - pgxfile = opj_data_file('baseline/conformance/c1p1_06_0.pgx') - pgxdata = read_pgx(pgxfile) - self.assertTrue(peak_tolerance(jpdata[:, :, 0], pgxdata) < 2) - self.assertTrue(mse(jpdata[:, :, 0], pgxdata) < 0.6) - - pgxfile = opj_data_file('baseline/conformance/c1p1_06_1.pgx') - pgxdata = read_pgx(pgxfile) - self.assertTrue(peak_tolerance(jpdata[:, :, 1], pgxdata) < 2) - self.assertTrue(mse(jpdata[:, :, 1], pgxdata) < 0.6) - - pgxfile = opj_data_file('baseline/conformance/c1p1_06_2.pgx') - pgxdata = read_pgx(pgxfile) - self.assertTrue(peak_tolerance(jpdata[:, :, 2], pgxdata) < 2) - self.assertTrue(mse(jpdata[:, :, 2], pgxdata) < 0.6) - - def test_ETS_JP2_file1(self): - jfile = opj_data_file('input/conformance/file1.jp2') - jp2k = Jp2k(jfile) - jpdata = jp2k.read() - self.assertEqual(jpdata.shape, (512, 768, 3)) - - def test_ETS_JP2_file2(self): - jfile = opj_data_file('input/conformance/file2.jp2') - jp2k = Jp2k(jfile) - jpdata = jp2k.read() - self.assertEqual(jpdata.shape, (640, 480, 3)) - - def test_ETS_JP2_file4(self): - jfile = opj_data_file('input/conformance/file4.jp2') - jp2k = Jp2k(jfile) - jpdata = jp2k.read() - self.assertEqual(jpdata.shape, (512, 768)) - - def test_ETS_JP2_file5(self): - """ETS_JP2_file5""" - jfile = opj_data_file('input/conformance/file5.jp2') - jp2k = Jp2k(jfile) - jpdata = jp2k.read() - self.assertEqual(jpdata.shape, (512, 768, 3)) - - def test_ETS_JP2_file6(self): - """ETS_JP2_file6""" - jfile = opj_data_file('input/conformance/file6.jp2') - jp2k = Jp2k(jfile) - jpdata = jp2k.read() - self.assertEqual(jpdata.shape, (512, 768)) - - def test_ETS_JP2_file7(self): - """ETS_JP2_file7""" - jfile = opj_data_file('input/conformance/file7.jp2') - jp2k = Jp2k(jfile) - jpdata = jp2k.read() - self.assertEqual(jpdata.shape, (640, 480, 3)) - - def test_ETS_JP2_file8(self): - """ETS_JP2_file8""" - jfile = opj_data_file('input/conformance/file8.jp2') - jp2k = Jp2k(jfile) - jpdata = jp2k.read() - self.assertEqual(jpdata.shape, (400, 700)) - - def test_ETS_JP2_file9(self): - """ETS_JP2_file9""" - jfile = opj_data_file('input/conformance/file9.jp2') - jp2k = Jp2k(jfile) - jpdata = jp2k.read() - if re.match(r'[01]\.3', OPENJPEG_VERSION): - # Version 1.3 reads in the image as the palette indices. - self.assertEqual(jpdata.shape, (512, 768)) - else: - self.assertEqual(jpdata.shape, (512, 768, 3)) - - def test_NR_DEC_Bretagne2_j2k_1_decode(self): - """test_NR_DEC_Bretagne2_j2k_1_decode""" - jfile = opj_data_file('input/nonregression/Bretagne2.j2k') - jp2 = Jp2k(jfile) - jp2.read() - self.assertTrue(True) - - def test_NR_DEC__00042_j2k_2_decode(self): - """NR_DEC__00042_j2k_2_decode""" - jfile = opj_data_file('input/nonregression/_00042.j2k') - jp2 = Jp2k(jfile) - jp2.read() - self.assertTrue(True) - - @unittest.skip("fprintf stderr output in r2343.") - def test_NR_DEC_123_j2c_3_decode(self): - """NR_DEC_123_j2c_3_decode""" - jfile = opj_data_file('input/nonregression/123.j2c') - jp2 = Jp2k(jfile) - jp2.read() - self.assertTrue(True) - - @unittest.skipIf(sys.hexversion < 0x03020000, - "Uses features introduced in 3.2.") - def test_NR_DEC_broken_jp2_4_decode(self): - """NR_DEC_broken_jp2_4_decode""" - jfile = opj_data_file('input/nonregression/broken.jp2') - with self.assertWarns(UserWarning): - # colr box has bad length. - jp2 = Jp2k(jfile) - with self.assertRaises(ValueError): - jp2.read() - self.assertTrue(True) - - @unittest.skipIf(re.match(r'[01]\.[34]', OPENJPEG_VERSION), - "Segfaults openjpeg 1.4 and earlier.") - def test_NR_DEC_broken2_jp2_5_decode(self): - """NR_DEC_broken2_jp2_5_decode""" - # Null pointer access - jfile = opj_data_file('input/nonregression/broken2.jp2') - with self.assertRaises(ValueError): - with warnings.catch_warnings(): - # Library warning, invalid number of subbands. - warnings.simplefilter("ignore") - Jp2k(jfile).read() - self.assertTrue(True) - - @unittest.skipIf(sys.hexversion < 0x03020000, - "Uses features introduced in 3.2.") - def test_NR_DEC_broken3_jp2_6_decode(self): - """NR_DEC_broken3_jp2_6_decode""" - jfile = opj_data_file('input/nonregression/broken3.jp2') - with self.assertWarns(UserWarning): - # colr box has bad length. - j = Jp2k(jfile) - - with self.assertRaises(ValueError): - j.read() - - @unittest.skipIf(re.match(r'[01]\.[34]', OPENJPEG_VERSION), - "Segfaults openjpeg 1.4 and earlier.") - def test_NR_DEC_broken4_jp2_7_decode(self): - """NR_DEC_broken4_jp2_7_decode""" - # Null pointer access - jfile = opj_data_file('input/nonregression/broken4.jp2') - with self.assertRaises(ValueError): - with warnings.catch_warnings(): - # Library warning, invalid number of subbands. - warnings.simplefilter("ignore") - Jp2k(jfile).read() - self.assertTrue(True) - - @unittest.skip("fprintf stderr output in r2343.") - def test_NR_DEC_bug_j2c_8_decode(self): - """NR_DEC_bug_j2c_8_decode""" - jfile = opj_data_file('input/nonregression/bug.j2c') - Jp2k(jfile).read() - self.assertTrue(True) - - def test_NR_DEC_buxI_j2k_9_decode(self): - """NR_DEC_buxI_j2k_9_decode""" - jfile = opj_data_file('input/nonregression/buxI.j2k') - Jp2k(jfile).read() - self.assertTrue(True) - - def test_NR_DEC_buxR_j2k_10_decode(self): - """NR_DEC_buxR_j2k_10_decode""" - jfile = opj_data_file('input/nonregression/buxR.j2k') - Jp2k(jfile).read() - self.assertTrue(True) - - def test_NR_DEC_Cannotreaddatawithnosizeknown_j2k_11_decode(self): - """NR_DEC_Cannotreaddatawithnosizeknown_j2k_11_decode""" - relpath = 'input/nonregression/Cannotreaddatawithnosizeknown.j2k' - jfile = opj_data_file(relpath) - Jp2k(jfile).read() - self.assertTrue(True) - - def test_NR_DEC_cthead1_j2k_12_decode(self): - """NR_DEC_cthead1_j2k_12_decode""" - jfile = opj_data_file('input/nonregression/cthead1.j2k') - Jp2k(jfile).read() - self.assertTrue(True) - - def test_NR_DEC_CT_Phillips_JPEG2K_Decompr_Problem_j2k_13_decode(self): - """NR_DEC_CT_Phillips_JPEG2K_Decompr_Problem_j2k_13_decode""" - relpath = 'input/nonregression/CT_Phillips_JPEG2K_Decompr_Problem.j2k' - jfile = opj_data_file(relpath) - Jp2k(jfile).read() - self.assertTrue(True) - - @unittest.skip("fprintf stderr output in r2343.") - def test_NR_DEC_illegalcolortransform_j2k_14_decode(self): - """Stream too short, expected SOT.""" - jfile = opj_data_file('input/nonregression/illegalcolortransform.j2k') - Jp2k(jfile).read() - self.assertTrue(True) - - def test_NR_DEC_j2k32_j2k_15_decode(self): - """NR_DEC_j2k32_j2k_15_decode""" - jfile = opj_data_file('input/nonregression/j2k32.j2k') - Jp2k(jfile).read() - self.assertTrue(True) - - def test_NR_DEC_kakadu_v4_4_openjpegv2_broken_j2k_16_decode(self): - """NR_DEC_kakadu_v4_4_openjpegv2_broken_j2k_16_decode""" - relpath = 'input/nonregression/kakadu_v4-4_openjpegv2_broken.j2k' - jfile = opj_data_file(relpath) - with warnings.catch_warnings(): - # This file has an invalid ICC profile - warnings.simplefilter("ignore") - Jp2k(jfile).read() - self.assertTrue(True) - - def test_NR_DEC_MarkerIsNotCompliant_j2k_17_decode(self): - """NR_DEC_MarkerIsNotCompliant_j2k_17_decode""" - jfile = opj_data_file('input/nonregression/MarkerIsNotCompliant.j2k') - Jp2k(jfile).read() - self.assertTrue(True) - - def test_NR_DEC_Marrin_jp2_18_decode(self): - """NR_DEC_Marrin_jp2_18_decode""" - jfile = opj_data_file('input/nonregression/Marrin.jp2') - Jp2k(jfile).read() - self.assertTrue(True) - - def test_NR_DEC_movie_00000_j2k_20_decode(self): - """test_NR_DEC_movie_00000_j2k_20_decode""" - jfile = opj_data_file('input/nonregression/movie_00000.j2k') - Jp2k(jfile).read() - self.assertTrue(True) - - def test_NR_DEC_movie_00001_j2k_21_decode(self): - """NR_DEC_movie_00001_j2k_21_decode""" - jfile = opj_data_file('input/nonregression/movie_00001.j2k') - Jp2k(jfile).read() - self.assertTrue(True) - - def test_NR_DEC_movie_00002_j2k_22_decode(self): - """NR_DEC_movie_00002_j2k_22_decode""" - jfile = opj_data_file('input/nonregression/movie_00002.j2k') - Jp2k(jfile).read() - self.assertTrue(True) - - def test_NR_DEC_orb_blue_lin_j2k_j2k_23_decode(self): - """NR_DEC_orb_blue_lin_j2k_j2k_23_decode""" - jfile = opj_data_file('input/nonregression/orb-blue10-lin-j2k.j2k') - Jp2k(jfile).read() - self.assertTrue(True) - - def test_NR_DEC_orb_blue_win_j2k_j2k_24_decode(self): - """NR_DEC_orb_blue_win_j2k_j2k_24_decode""" - jfile = opj_data_file('input/nonregression/orb-blue10-win-j2k.j2k') - Jp2k(jfile).read() - self.assertTrue(True) - - def test_nc_dec_orb_blue_lin_jp2_25_decode(self): - """NR-DEC-orb-blue-lin.jp2-25-decode""" - jfile = opj_data_file('input/nonregression/orb-blue10-lin-jp2.jp2') - with warnings.catch_warnings(): - # This file has an invalid ICC profile - warnings.simplefilter("ignore") - Jp2k(jfile).read() - self.assertTrue(True) - - def test_nr_dec_orb_blue_win_jp2_26_decode(self): - """NR-DEC-orb-blue-win.jp2-26-decode""" - jfile = opj_data_file('input/nonregression/orb-blue10-win-jp2.jp2') - Jp2k(jfile).read() - self.assertTrue(True) - - def test_nr_dec_relax_jp2_27_decode(self): - """NR-DEC-relax.jp2-27-decode""" - jfile = opj_data_file('input/nonregression/relax.jp2') - Jp2k(jfile).read() - self.assertTrue(True) - - def test_nr_dec_test_lossless_j2k_28_decode(self): - """NR-DEC-test-lossless.j2k-28-decode""" - jfile = opj_data_file('input/nonregression/test_lossless.j2k') - Jp2k(jfile).read() - self.assertTrue(True) - - def test_nr_dec_issue104_jpxstream_jp2_33_decode(self): - """NR-DEC-issue104-jpxstream.jp2-33-decode""" - jfile = opj_data_file('input/nonregression/issue104_jpxstream.jp2') - Jp2k(jfile).read() - self.assertTrue(True) - - def test_nr_dec_file_409752_jp2_40_decode(self): - """NR-DEC-file-409752.jp2-40-decode""" - jfile = opj_data_file('input/nonregression/file409752.jp2') - j = Jp2k(jfile) - with self.assertRaises(RuntimeError): - j.read() - if __name__ == "__main__": unittest.main() From 21ef942104a38719176eae4542f4492841ed46a8 Mon Sep 17 00:00:00 2001 From: jevans Date: Fri, 6 Sep 2013 11:07:40 -0400 Subject: [PATCH 05/22] Can get full run with test_opj_suite refactoring. #110 test_opj_suite refactored to not repeat tests. --- glymur/test/test_jp2k.py | 2 + glymur/test/test_opj_suite.py | 1214 +++++++++++++++++---------------- 2 files changed, 619 insertions(+), 597 deletions(-) diff --git a/glymur/test/test_jp2k.py b/glymur/test/test_jp2k.py index 699fef7..442ae67 100644 --- a/glymur/test/test_jp2k.py +++ b/glymur/test/test_jp2k.py @@ -752,6 +752,8 @@ class TestJp2k(unittest.TestCase): self.assertFalse('Make' in exif['Image'].keys()) +@unittest.skipIf(glymur.lib.openjp2.OPENJP2 is not None, + "Don't bother if openjp2 is present.") @unittest.skipIf(glymur.lib.openjpeg.OPENJPEG is None, "Missing openjpeg library.") class TestJp2k15(unittest.TestCase): diff --git a/glymur/test/test_opj_suite.py b/glymur/test/test_opj_suite.py index c6dfbda..3c6b5d2 100644 --- a/glymur/test/test_opj_suite.py +++ b/glymur/test/test_opj_suite.py @@ -114,29 +114,6 @@ class TestSuite(unittest.TestCase): self.assertTrue(peak_tolerance(jpdata[:, :, 2], pgxdata) < 33) self.assertTrue(mse(jpdata[:, :, 2], pgxdata) < 55.8) - def test_ETS_C0P0_p0_05_j2k(self): - jfile = opj_data_file('input/conformance/p0_05.j2k') - jp2k = Jp2k(jfile) - jpdata = jp2k.read_bands(rlevel=3) - - pgxfile = opj_data_file('baseline/conformance/c0p0_05.pgx') - pgxdata = read_pgx(pgxfile) - self.assertTrue(peak_tolerance(jpdata[0], pgxdata) < 54) - self.assertTrue(mse(jpdata[0], pgxdata) < 68) - - @unittest.skip("8-bit pgx data vs 12-bit j2k data") - def test_ETS_C0P0_p0_06_j2k(self): - jfile = opj_data_file('input/conformance/p0_06.j2k') - jp2k = Jp2k(jfile) - jpdata = jp2k.read_bands(rlevel=3) - - pgxfile = opj_data_file('baseline/conformance/c0p0_06.pgx') - pgxdata = read_pgx(pgxfile) - tol = peak_tolerance(jpdata[0], pgxdata) - self.assertTrue(tol < 109) - m = mse(jpdata[0], pgxdata) - self.assertTrue(m < 743) - @unittest.skip("Known failure in OPENJPEG test suite.") def test_ETS_C0P0_p0_07_j2k(self): jfile = opj_data_file('input/conformance/p0_07.j2k') @@ -280,17 +257,6 @@ class TestSuite(unittest.TestCase): self.assertTrue(peak_tolerance(jpdata[:, :, 0], pgxdata) < 35) self.assertTrue(mse(jpdata[:, :, 0], pgxdata) < 74) - def test_ETS_C0P1_p1_03_j2k(self): - jfile = opj_data_file('input/conformance/p1_03.j2k') - jp2k = Jp2k(jfile) - jpdata = jp2k.read_bands(rlevel=3) - - pgxfile = opj_data_file('baseline/conformance/c0p1_03.pgx') - pgxdata = read_pgx(pgxfile) - - self.assertTrue(peak_tolerance(jpdata[0], pgxdata) < 28) - self.assertTrue(mse(jpdata[0], pgxdata) < 18.8) - @unittest.skip("Known failure in OPENJPEG test suite operation.") def test_ETS_C0P1_p1_04_j2k(self): jfile = opj_data_file('input/conformance/p1_04.j2k') @@ -406,56 +372,6 @@ class TestSuite(unittest.TestCase): self.assertTrue(peak_tolerance(jpdata[:, :, 2], pgxdata) < 6) self.assertTrue(mse(jpdata[:, :, 2], pgxdata) < 1.07) - def test_ETS_C1P0_p0_05_j2k(self): - jfile = opj_data_file('input/conformance/p0_05.j2k') - jp2k = Jp2k(jfile) - jpdata = jp2k.read_bands() - - pgxfile = opj_data_file('baseline/conformance/c1p0_05_0.pgx') - pgxdata = read_pgx(pgxfile) - self.assertTrue(peak_tolerance(jpdata[0], pgxdata) < 2) - self.assertTrue(mse(jpdata[0], pgxdata) < 0.302) - - pgxfile = opj_data_file('baseline/conformance/c1p0_05_1.pgx') - pgxdata = read_pgx(pgxfile) - self.assertTrue(peak_tolerance(jpdata[1], pgxdata) < 2) - self.assertTrue(mse(jpdata[1], pgxdata) < 0.307) - - pgxfile = opj_data_file('baseline/conformance/c1p0_05_2.pgx') - pgxdata = read_pgx(pgxfile) - self.assertTrue(peak_tolerance(jpdata[2], pgxdata) < 2) - self.assertTrue(mse(jpdata[2], pgxdata) < 0.269) - - pgxfile = opj_data_file('baseline/conformance/c1p0_05_3.pgx') - pgxdata = read_pgx(pgxfile) - self.assertTrue(peak_tolerance(jpdata[3], pgxdata) == 0) - self.assertTrue(mse(jpdata[3], pgxdata) == 0) - - def test_ETS_C1P0_p0_06_j2k(self): - jfile = opj_data_file('input/conformance/p0_06.j2k') - jp2k = Jp2k(jfile) - jpdata = jp2k.read_bands() - - pgxfile = opj_data_file('baseline/conformance/c1p0_06_0.pgx') - pgxdata = read_pgx(pgxfile) - self.assertTrue(peak_tolerance(jpdata[0], pgxdata) < 635) - self.assertTrue(mse(jpdata[0], pgxdata) < 11287) - - pgxfile = opj_data_file('baseline/conformance/c1p0_06_1.pgx') - pgxdata = read_pgx(pgxfile) - self.assertTrue(peak_tolerance(jpdata[1], pgxdata) < 403) - self.assertTrue(mse(jpdata[1], pgxdata) < 6124) - - pgxfile = opj_data_file('baseline/conformance/c1p0_06_2.pgx') - pgxdata = read_pgx(pgxfile) - self.assertTrue(peak_tolerance(jpdata[2], pgxdata) < 378) - self.assertTrue(mse(jpdata[2], pgxdata) < 3968) - - pgxfile = opj_data_file('baseline/conformance/c1p0_06_3.pgx') - pgxdata = read_pgx(pgxfile) - self.assertTrue(peak_tolerance(jpdata[3], pgxdata) == 0) - self.assertTrue(mse(jpdata[3], pgxdata) == 0) - @unittest.skip("Known failure in OPENJPEG test suite operation.") def test_ETS_C1P0_p0_07_j2k(self): jfile = opj_data_file('input/conformance/p0_07.j2k') @@ -500,23 +416,6 @@ class TestSuite(unittest.TestCase): pgxdata = read_pgx(pgxfile) np.testing.assert_array_equal(jpdata, pgxdata) - def test_ETS_C1P0_p0_10_j2k(self): - jfile = opj_data_file('input/conformance/p0_10.j2k') - jp2k = Jp2k(jfile) - jpdata = jp2k.read(rlevel=0) - - pgxfile = opj_data_file('baseline/conformance/c1p0_10_0.pgx') - pgxdata = read_pgx(pgxfile) - np.testing.assert_array_equal(jpdata[:, :, 0], pgxdata) - - pgxfile = opj_data_file('baseline/conformance/c1p0_10_1.pgx') - pgxdata = read_pgx(pgxfile) - np.testing.assert_array_equal(jpdata[:, :, 1], pgxdata) - - pgxfile = opj_data_file('baseline/conformance/c1p0_10_2.pgx') - pgxdata = read_pgx(pgxfile) - np.testing.assert_array_equal(jpdata[:, :, 2], pgxdata) - def test_ETS_C1P0_p0_11_j2k(self): jfile = opj_data_file('input/conformance/p0_11.j2k') jp2k = Jp2k(jfile) @@ -622,30 +521,6 @@ class TestSuite(unittest.TestCase): self.assertTrue(peak_tolerance(jpdata[:, :, 2], pgxdata) < 6) self.assertTrue(mse(jpdata[:, :, 2], pgxdata) < 1.051) - def test_ETS_C1P1_p1_03_j2k(self): - jfile = opj_data_file('input/conformance/p1_03.j2k') - jp2k = Jp2k(jfile) - jpdata = jp2k.read_bands() - - pgxfile = opj_data_file('baseline/conformance/c1p1_03_0.pgx') - pgxdata = read_pgx(pgxfile) - self.assertTrue(peak_tolerance(jpdata[0], pgxdata) < 2) - self.assertTrue(mse(jpdata[0], pgxdata) < 0.3) - - pgxfile = opj_data_file('baseline/conformance/c1p1_03_1.pgx') - pgxdata = read_pgx(pgxfile) - self.assertTrue(peak_tolerance(jpdata[1], pgxdata) < 2) - self.assertTrue(mse(jpdata[1], pgxdata) < 0.21) - - pgxfile = opj_data_file('baseline/conformance/c1p1_03_2.pgx') - pgxdata = read_pgx(pgxfile) - self.assertTrue(peak_tolerance(jpdata[2], pgxdata) <= 1) - self.assertTrue(mse(jpdata[2], pgxdata) < 0.2) - - pgxfile = opj_data_file('baseline/conformance/c1p1_03_3.pgx') - pgxdata = read_pgx(pgxfile) - np.testing.assert_array_equal(jpdata[3], pgxdata) - def test_ETS_C1P1_p1_04_j2k(self): jfile = opj_data_file('input/conformance/p1_04.j2k') jp2k = Jp2k(jfile) @@ -802,16 +677,6 @@ class TestSuite(unittest.TestCase): jp2.read() self.assertTrue(True) - def test_NR_DEC_broken2_jp2_5_decode(self): - # Null pointer access - jfile = opj_data_file('input/nonregression/broken2.jp2') - with self.assertRaises(IOError): - with warnings.catch_warnings(): - # Invalid marker ID. - warnings.simplefilter("ignore") - Jp2k(jfile).read() - self.assertTrue(True) - @unittest.skipIf(sys.hexversion < 0x03020000, "Uses features introduced in 3.2.") def test_NR_DEC_broken3_jp2_6_decode(self): @@ -823,15 +688,6 @@ class TestSuite(unittest.TestCase): with self.assertRaises(IOError): j.read() - def test_NR_DEC_broken4_jp2_7_decode(self): - jfile = opj_data_file('input/nonregression/broken4.jp2') - with self.assertRaises(IOError): - with warnings.catch_warnings(): - # invalid number of subbands, bad marker ID - warnings.simplefilter("ignore") - Jp2k(jfile).read() - self.assertTrue(True) - @unittest.skip("fprintf stderr output in r2343.") def test_NR_DEC_bug_j2c_8_decode(self): jfile = opj_data_file('input/nonregression/bug.j2c') @@ -877,12 +733,6 @@ class TestSuite(unittest.TestCase): Jp2k(jfile).read() self.assertTrue(True) - def test_NR_DEC_kakadu_v4_4_openjpegv2_broken_j2k_16_decode(self): - relpath = 'input/nonregression/kakadu_v4-4_openjpegv2_broken.j2k' - jfile = opj_data_file(relpath) - Jp2k(jfile).read() - self.assertTrue(True) - def test_NR_DEC_MarkerIsNotCompliant_j2k_17_decode(self): jfile = opj_data_file('input/nonregression/MarkerIsNotCompliant.j2k') Jp2k(jfile).read() @@ -893,11 +743,6 @@ class TestSuite(unittest.TestCase): Jp2k(jfile).read() self.assertTrue(True) - def test_NR_DEC_merged_jp2_19_decode(self): - jfile = opj_data_file('input/nonregression/merged.jp2') - Jp2k(jfile).read_bands() - self.assertTrue(True) - def test_NR_DEC_movie_00000_j2k_20_decode(self): jfile = opj_data_file('input/nonregression/movie_00000.j2k') Jp2k(jfile).read() @@ -946,369 +791,11 @@ class TestSuite(unittest.TestCase): Jp2k(jfile).read() self.assertTrue(True) - @unittest.skipIf(OPENJP2_IS_V2_OFFICIAL, - "Test known to fail in v2.0.0 official") - def test_NR_DEC_text_GBR_jp2_29_decode(self): - jfile = opj_data_file('input/nonregression/text_GBR.jp2') - with warnings.catch_warnings(): - # brand is 'jp2 ', but has any icc profile. - warnings.simplefilter("ignore") - jp2 = Jp2k(jfile) - jp2.read() - self.assertTrue(True) - def test_NR_DEC_pacs_ge_j2k_30_decode(self): jfile = opj_data_file('input/nonregression/pacs.ge.j2k') Jp2k(jfile).read() self.assertTrue(True) - @unittest.skipIf(OPENJP2_IS_V2_OFFICIAL, - "Test known to fail in v2.0.0 official") - def test_NR_DEC_kodak_2layers_lrcp_j2c_31_decode(self): - jfile = opj_data_file('input/nonregression/kodak_2layers_lrcp.j2c') - Jp2k(jfile).read() - self.assertTrue(True) - - @unittest.skipIf(OPENJP2_IS_V2_OFFICIAL, - "Test known to fail in v2.0.0 official") - def test_NR_DEC_kodak_2layers_lrcp_j2c_32_decode(self): - jfile = opj_data_file('input/nonregression/kodak_2layers_lrcp.j2c') - Jp2k(jfile).read(layer=2) - self.assertTrue(True) - - def test_NR_DEC_issue104_jpxstream_jp2_33_decode(self): - jfile = opj_data_file('input/nonregression/issue104_jpxstream.jp2') - Jp2k(jfile).read() - self.assertTrue(True) - - @unittest.skipIf(OPENJP2_IS_V2_OFFICIAL, - "Test known to fail in v2.0.0 official") - def test_NR_DEC_mem_b2ace68c_1381_jp2_34_decode(self): - jfile = opj_data_file('input/nonregression/mem-b2ace68c-1381.jp2') - with warnings.catch_warnings(): - # This file has a bad pclr box, we test for this elsewhere. - warnings.simplefilter("ignore") - j = Jp2k(jfile) - j.read() - self.assertTrue(True) - - @unittest.skipIf(OPENJP2_IS_V2_OFFICIAL, - "Test known to fail in v2.0.0 official") - def test_NR_DEC_mem_b2b86b74_2753_jp2_35_decode(self): - jfile = opj_data_file('input/nonregression/mem-b2b86b74-2753.jp2') - Jp2k(jfile).read() - self.assertTrue(True) - - def test_NR_DEC_gdal_fuzzer_unchecked_num_resolutions_jp2_36_decode(self): - f = 'input/nonregression/gdal_fuzzer_unchecked_numresolutions.jp2' - jfile = opj_data_file(f) - with warnings.catch_warnings(): - # Invalid number of resolutions. - warnings.simplefilter("ignore") - j = Jp2k(jfile) - with self.assertRaises(IOError): - j.read() - - @unittest.skipIf(OPENJP2_IS_V2_OFFICIAL, - "Test not in done in v2.0.0 official") - def test_NR_DEC_jp2_36_decode(self): - lst = ('input', - 'nonregression', - 'gdal_fuzzer_assert_in_opj_j2k_read_SQcd_SQcc.patch.jp2') - jfile = opj_data_file('/'.join(lst)) - with warnings.catch_warnings(): - # Invalid component number. - warnings.simplefilter("ignore") - j = Jp2k(jfile) - with self.assertRaises(IOError): - j.read() - - @unittest.skipIf(OPENJP2_IS_V2_OFFICIAL, - "Test not in done in v2.0.0 official") - def test_NR_DEC_gdal_fuzzer_check_number_of_tiles_jp2_38_decode(self): - relpath = 'input/nonregression/gdal_fuzzer_check_number_of_tiles.jp2' - jfile = opj_data_file(relpath) - with warnings.catch_warnings(): - # Invalid number of tiles. - warnings.simplefilter("ignore") - j = Jp2k(jfile) - with self.assertRaises(IOError): - j.read() - - @unittest.skipIf(OPENJP2_IS_V2_OFFICIAL, - "Test not in done in v2.0.0 official") - @unittest.skipIf(re.match(r"""1\.[0125]\.\d""", OPENJPEG_VERSION), - "Segfaults 1.5") - def test_NR_DEC_gdal_fuzzer_check_comp_dx_dy_jp2_39_decode(self): - relpath = 'input/nonregression/gdal_fuzzer_check_comp_dx_dy.jp2' - jfile = opj_data_file(relpath) - with warnings.catch_warnings(): - # Invalid subsampling value - warnings.simplefilter("ignore") - with self.assertRaises(IOError): - Jp2k(jfile).read() - - def test_NR_DEC_file_409752_jp2_40_decode(self): - jfile = opj_data_file('input/nonregression/file409752.jp2') - with self.assertRaises(RuntimeError): - Jp2k(jfile).read() - - @unittest.skipIf(OPENJP2_IS_V2_OFFICIAL, - "Test not in done in v2.0.0 official") - @unittest.skipIf(re.match(r"""1\.[0125]\.\d""", OPENJPEG_VERSION), - "Segfaults 1.5") - @unittest.skipIf(sys.hexversion < 0x03020000, - "Uses features introduced in 3.2.") - def test_NR_DEC_issue188_beach_64bitsbox_jp2_41_decode(self): - # Has an 'XML ' box instead of 'xml '. Yes that is pedantic, but it - # really does deserve a warning. - relpath = 'input/nonregression/issue188_beach_64bitsbox.jp2' - jfile = opj_data_file(relpath) - with self.assertWarns(UserWarning): - Jp2k(jfile).read() - - @unittest.skipIf(OPENJP2_IS_V2_OFFICIAL, - "Test not in done in v2.0.0 official") - def test_NR_DEC_issue206_image_000_jp2_42_decode(self): - jfile = opj_data_file('input/nonregression/issue206_image-000.jp2') - Jp2k(jfile).read() - self.assertTrue(True) - - def test_NR_DEC_p1_04_j2k_43_decode(self): - jfile = opj_data_file('input/conformance/p1_04.j2k') - jp2k = Jp2k(jfile) - ssdata = jp2k.read(area=(0, 0, 1024, 1024)) - odata = jp2k.read() - np.testing.assert_array_equal(ssdata, odata) - - def test_NR_DEC_p1_04_j2k_44_decode(self): - jfile = opj_data_file('input/conformance/p1_04.j2k') - jp2k = Jp2k(jfile) - ssdata = jp2k.read(area=(640, 512, 768, 640)) - odata = jp2k.read() - np.testing.assert_array_equal(ssdata, odata[640:768, 512:640]) - - def test_NR_DEC_p1_04_j2k_45_decode(self): - jfile = opj_data_file('input/conformance/p1_04.j2k') - jp2k = Jp2k(jfile) - ssdata = jp2k.read(area=(896, 896, 1024, 1024)) - odata = jp2k.read() - np.testing.assert_array_equal(ssdata, odata[896:1024, 896:1024]) - - def test_NR_DEC_p1_04_j2k_46_decode(self): - jfile = opj_data_file('input/conformance/p1_04.j2k') - jp2k = Jp2k(jfile) - ssdata = jp2k.read(area=(500, 100, 800, 300)) - odata = jp2k.read() - np.testing.assert_array_equal(ssdata, odata[500:800, 100:300]) - - def test_NR_DEC_p1_04_j2k_47_decode(self): - jfile = opj_data_file('input/conformance/p1_04.j2k') - jp2k = Jp2k(jfile) - ssdata = jp2k.read(area=(520, 260, 600, 360)) - odata = jp2k.read() - np.testing.assert_array_equal(ssdata, odata[520:600, 260:360]) - - def test_NR_DEC_p1_04_j2k_48_decode(self): - jfile = opj_data_file('input/conformance/p1_04.j2k') - jp2k = Jp2k(jfile) - ssdata = jp2k.read(area=(520, 260, 660, 360)) - odata = jp2k.read() - np.testing.assert_array_equal(ssdata, odata[520:660, 260:360]) - - def test_NR_DEC_p1_04_j2k_49_decode(self): - jfile = opj_data_file('input/conformance/p1_04.j2k') - jp2k = Jp2k(jfile) - ssdata = jp2k.read(area=(520, 360, 600, 400)) - odata = jp2k.read() - np.testing.assert_array_equal(ssdata, odata[520:600, 360:400]) - - def test_NR_DEC_p1_04_j2k_50_decode(self): - jfile = opj_data_file('input/conformance/p1_04.j2k') - jp2k = Jp2k(jfile) - ssdata = jp2k.read(area=(0, 0, 1024, 1024), rlevel=2) - odata = jp2k.read(rlevel=2) - - np.testing.assert_array_equal(ssdata, odata[0:256, 0:256]) - - def test_NR_DEC_p1_04_j2k_51_decode(self): - jfile = opj_data_file('input/conformance/p1_04.j2k') - jp2k = Jp2k(jfile) - ssdata = jp2k.read(area=(640, 512, 768, 640), rlevel=2) - odata = jp2k.read(rlevel=2) - np.testing.assert_array_equal(ssdata, odata[160:192, 128:160]) - - def test_NR_DEC_p1_04_j2k_52_decode(self): - jfile = opj_data_file('input/conformance/p1_04.j2k') - jp2k = Jp2k(jfile) - ssdata = jp2k.read(area=(896, 896, 1024, 1024), rlevel=2) - odata = jp2k.read(rlevel=2) - np.testing.assert_array_equal(ssdata, odata[224:352, 224:352]) - - def test_NR_DEC_p1_04_j2k_53_decode(self): - jfile = opj_data_file('input/conformance/p1_04.j2k') - jp2k = Jp2k(jfile) - ssdata = jp2k.read(area=(500, 100, 800, 300), rlevel=2) - odata = jp2k.read(rlevel=2) - np.testing.assert_array_equal(ssdata, odata[125:200, 25:75]) - - def test_NR_DEC_p1_04_j2k_54_decode(self): - jfile = opj_data_file('input/conformance/p1_04.j2k') - jp2k = Jp2k(jfile) - ssdata = jp2k.read(area=(520, 260, 600, 360), rlevel=2) - odata = jp2k.read(rlevel=2) - np.testing.assert_array_equal(ssdata, odata[130:150, 65:90]) - - def test_NR_DEC_p1_04_j2k_55_decode(self): - jfile = opj_data_file('input/conformance/p1_04.j2k') - jp2k = Jp2k(jfile) - ssdata = jp2k.read(area=(520, 260, 660, 360), rlevel=2) - odata = jp2k.read(rlevel=2) - np.testing.assert_array_equal(ssdata, odata[130:165, 65:90]) - - def test_NR_DEC_p1_04_j2k_56_decode(self): - jfile = opj_data_file('input/conformance/p1_04.j2k') - jp2k = Jp2k(jfile) - ssdata = jp2k.read(area=(520, 360, 600, 400), rlevel=2) - odata = jp2k.read(rlevel=2) - np.testing.assert_array_equal(ssdata, odata[130:150, 90:100]) - - def test_NR_DEC_p1_04_j2k_57_decode(self): - jfile = opj_data_file('input/conformance/p1_04.j2k') - jp2k = Jp2k(jfile) - tdata = jp2k.read(tile=63) # last tile - odata = jp2k.read() - np.testing.assert_array_equal(tdata, odata[896:1024, 896:1024]) - - def test_NR_DEC_p1_04_j2k_58_decode(self): - jfile = opj_data_file('input/conformance/p1_04.j2k') - jp2k = Jp2k(jfile) - tdata = jp2k.read(tile=63, rlevel=2) # last tile - odata = jp2k.read(rlevel=2) - np.testing.assert_array_equal(tdata, odata[224:256, 224:256]) - - def test_NR_DEC_p1_04_j2k_59_decode(self): - jfile = opj_data_file('input/conformance/p1_04.j2k') - jp2k = Jp2k(jfile) - tdata = jp2k.read(tile=12) # 2nd row, 5th column - odata = jp2k.read() - np.testing.assert_array_equal(tdata, odata[128:256, 512:640]) - - def test_NR_DEC_p1_04_j2k_60_decode(self): - jfile = opj_data_file('input/conformance/p1_04.j2k') - jp2k = Jp2k(jfile) - tdata = jp2k.read(tile=12, rlevel=1) # 2nd row, 5th column - odata = jp2k.read(rlevel=1) - np.testing.assert_array_equal(tdata, odata[64:128, 256:320]) - - @unittest.skip("fprintf stderr output in r2343.") - def test_NR_DEC_p1_06_j2k_61_decode(self): - jfile = opj_data_file('input/conformance/p1_06.j2k') - jp2k = Jp2k(jfile) - ssdata = jp2k.read(area=(0, 0, 12, 12)) - odata = jp2k.read() - np.testing.assert_array_equal(ssdata, odata[0:12, 0:12]) - - @unittest.skip("fprintf stderr output in r2343.") - def test_NR_DEC_p1_06_j2k_62_decode(self): - jfile = opj_data_file('input/conformance/p1_06.j2k') - jp2k = Jp2k(jfile) - ssdata = jp2k.read(area=(1, 8, 8, 11)) - odata = jp2k.read() - np.testing.assert_array_equal(ssdata, odata[1:8, 8:11]) - - @unittest.skip("fprintf stderr output in r2343.") - def test_NR_DEC_p1_06_j2k_63_decode(self): - jfile = opj_data_file('input/conformance/p1_06.j2k') - jp2k = Jp2k(jfile) - ssdata = jp2k.read(area=(9, 9, 12, 12)) - odata = jp2k.read() - np.testing.assert_array_equal(ssdata, odata[9:12, 9:12]) - - @unittest.skip("fprintf stderr output in r2343.") - def test_NR_DEC_p1_06_j2k_64_decode(self): - jfile = opj_data_file('input/conformance/p1_06.j2k') - jp2k = Jp2k(jfile) - ssdata = jp2k.read(area=(10, 4, 12, 10)) - odata = jp2k.read() - np.testing.assert_array_equal(ssdata, odata[10:12, 4:10]) - - @unittest.skip("fprintf stderr output in r2343.") - def test_NR_DEC_p1_06_j2k_65_decode(self): - jfile = opj_data_file('input/conformance/p1_06.j2k') - jp2k = Jp2k(jfile) - ssdata = jp2k.read(area=(3, 3, 9, 9)) - odata = jp2k.read() - np.testing.assert_array_equal(ssdata, odata[3:9, 3:9]) - - @unittest.skip("fprintf stderr output in r2343.") - def test_NR_DEC_p1_06_j2k_66_decode(self): - jfile = opj_data_file('input/conformance/p1_06.j2k') - jp2k = Jp2k(jfile) - ssdata = jp2k.read(area=(4, 4, 7, 7)) - odata = jp2k.read() - np.testing.assert_array_equal(ssdata, odata[4:7, 4:7]) - - @unittest.skip("fprintf stderr output in r2343.") - def test_NR_DEC_p1_06_j2k_67_decode(self): - jfile = opj_data_file('input/conformance/p1_06.j2k') - jp2k = Jp2k(jfile) - ssdata = jp2k.read(area=(4, 4, 5, 5)) - odata = jp2k.read() - np.testing.assert_array_equal(ssdata, odata[4:5, 4: 5]) - - @unittest.skip("fprintf stderr output in r2343.") - def test_NR_DEC_p1_06_j2k_68_decode(self): - jfile = opj_data_file('input/conformance/p1_06.j2k') - jp2k = Jp2k(jfile) - ssdata = jp2k.read(area=(0, 0, 12, 12), rlevel=1) - odata = jp2k.read(rlevel=1) - np.testing.assert_array_equal(ssdata, odata[0:6, 0:6]) - - @unittest.skip("fprintf stderr output in r2343.") - def test_NR_DEC_p1_06_j2k_69_decode(self): - jfile = opj_data_file('input/conformance/p1_06.j2k') - jp2k = Jp2k(jfile) - ssdata = jp2k.read(area=(1, 8, 8, 11), rlevel=1) - self.assertEqual(ssdata.shape, (3, 2, 3)) - - def test_NR_DEC_p1_06_j2k_70_decode(self): - jfile = opj_data_file('input/conformance/p1_06.j2k') - jp2k = Jp2k(jfile) - ssdata = jp2k.read(area=(9, 9, 12, 12), rlevel=1) - self.assertEqual(ssdata.shape, (1, 1, 3)) - - def test_NR_DEC_p1_06_j2k_71_decode(self): - jfile = opj_data_file('input/conformance/p1_06.j2k') - jp2k = Jp2k(jfile) - ssdata = jp2k.read(area=(10, 4, 12, 10), rlevel=1) - self.assertEqual(ssdata.shape, (1, 3, 3)) - - def test_NR_DEC_p1_06_j2k_72_decode(self): - jfile = opj_data_file('input/conformance/p1_06.j2k') - jp2k = Jp2k(jfile) - ssdata = jp2k.read(area=(3, 3, 9, 9), rlevel=1) - self.assertEqual(ssdata.shape, (3, 3, 3)) - - def test_NR_DEC_p1_06_j2k_73_decode(self): - jfile = opj_data_file('input/conformance/p1_06.j2k') - jp2k = Jp2k(jfile) - ssdata = jp2k.read(area=(4, 4, 7, 7), rlevel=1) - self.assertEqual(ssdata.shape, (2, 2, 3)) - - def test_NR_DEC_p1_06_j2k_74_decode(self): - jfile = opj_data_file('input/conformance/p1_06.j2k') - jp2k = Jp2k(jfile) - ssdata = jp2k.read(area=(4, 4, 5, 5), rlevel=1) - self.assertEqual(ssdata.shape, (1, 1, 3)) - - def test_NR_DEC_p1_06_j2k_75_decode(self): - # Image size would be 0 x 0. - jfile = opj_data_file('input/conformance/p1_06.j2k') - jp2k = Jp2k(jfile) - with self.assertRaises((IOError, OSError)): - jp2k.read(area=(9, 9, 12, 12), rlevel=2) - @unittest.skip("fprintf stderr output in r2343.") def test_NR_DEC_p1_06_j2k_76_decode(self): jfile = opj_data_file('input/conformance/p1_06.j2k') @@ -1389,90 +876,6 @@ class TestSuite(unittest.TestCase): jp2k = Jp2k(jfile) jp2k.read(rlevel=4) - def test_NR_DEC_p0_04_j2k_85_decode(self): - jfile = opj_data_file('input/conformance/p0_04.j2k') - jp2k = Jp2k(jfile) - ssdata = jp2k.read(area=(0, 0, 256, 256)) - fulldata = jp2k.read() - np.testing.assert_array_equal(fulldata[0:256, 0:256], ssdata) - - def test_NR_DEC_p0_04_j2k_86_decode(self): - jfile = opj_data_file('input/conformance/p0_04.j2k') - jp2k = Jp2k(jfile) - ssdata = jp2k.read(area=(0, 128, 128, 256)) - fulldata = jp2k.read() - np.testing.assert_array_equal(fulldata[0:128, 128:256], ssdata) - - def test_NR_DEC_p0_04_j2k_87_decode(self): - jfile = opj_data_file('input/conformance/p0_04.j2k') - jp2k = Jp2k(jfile) - ssdata = jp2k.read(area=(10, 50, 200, 120)) - fulldata = jp2k.read() - np.testing.assert_array_equal(fulldata[10:200, 50:120], ssdata) - - def test_NR_DEC_p0_04_j2k_88_decode(self): - jfile = opj_data_file('input/conformance/p0_04.j2k') - jp2k = Jp2k(jfile) - ssdata = jp2k.read(area=(150, 10, 210, 190)) - fulldata = jp2k.read() - np.testing.assert_array_equal(fulldata[150:210, 10:190], ssdata) - - def test_NR_DEC_p0_04_j2k_89_decode(self): - jfile = opj_data_file('input/conformance/p0_04.j2k') - jp2k = Jp2k(jfile) - ssdata = jp2k.read(area=(80, 100, 150, 200)) - fulldata = jp2k.read() - np.testing.assert_array_equal(fulldata[80:150, 100:200], ssdata) - - def test_NR_DEC_p0_04_j2k_90_decode(self): - jfile = opj_data_file('input/conformance/p0_04.j2k') - jp2k = Jp2k(jfile) - ssdata = jp2k.read(area=(20, 150, 50, 200)) - fulldata = jp2k.read() - np.testing.assert_array_equal(fulldata[20:50, 150:200], ssdata) - - def test_NR_DEC_p0_04_j2k_91_decode(self): - jfile = opj_data_file('input/conformance/p0_04.j2k') - jp2k = Jp2k(jfile) - ssdata = jp2k.read(area=(0, 0, 256, 256), rlevel=2) - fulldata = jp2k.read(rlevel=2) - np.testing.assert_array_equal(fulldata[0:64, 0:64], ssdata) - - def test_NR_DEC_p0_04_j2k_92_decode(self): - jfile = opj_data_file('input/conformance/p0_04.j2k') - jp2k = Jp2k(jfile) - ssdata = jp2k.read(area=(0, 128, 128, 256), rlevel=2) - fulldata = jp2k.read(rlevel=2) - np.testing.assert_array_equal(fulldata[0:32, 32:64], ssdata) - - def test_NR_DEC_p0_04_j2k_93_decode(self): - jfile = opj_data_file('input/conformance/p0_04.j2k') - jp2k = Jp2k(jfile) - ssdata = jp2k.read(area=(10, 50, 200, 120), rlevel=2) - fulldata = jp2k.read(rlevel=2) - np.testing.assert_array_equal(fulldata[3:50, 13:30], ssdata) - - def test_NR_DEC_p0_04_j2k_94_decode(self): - jfile = opj_data_file('input/conformance/p0_04.j2k') - jp2k = Jp2k(jfile) - ssdata = jp2k.read(area=(150, 10, 210, 190), rlevel=2) - fulldata = jp2k.read(rlevel=2) - np.testing.assert_array_equal(fulldata[38:53, 3:48], ssdata) - - def test_NR_DEC_p0_04_j2k_95_decode(self): - jfile = opj_data_file('input/conformance/p0_04.j2k') - jp2k = Jp2k(jfile) - ssdata = jp2k.read(area=(80, 100, 150, 200), rlevel=2) - fulldata = jp2k.read(rlevel=2) - np.testing.assert_array_equal(fulldata[20:38, 25:50], ssdata) - - def test_NR_DEC_p0_04_j2k_96_decode(self): - jfile = opj_data_file('input/conformance/p0_04.j2k') - jp2k = Jp2k(jfile) - ssdata = jp2k.read(area=(20, 150, 50, 200), rlevel=2) - fulldata = jp2k.read(rlevel=2) - np.testing.assert_array_equal(fulldata[5:13, 38:50], ssdata) - @unittest.skipIf(OPJ_DATA_ROOT is None, "OPJ_DATA_ROOT environment variable not set") @@ -7317,5 +6720,622 @@ class TestSuiteDump(unittest.TestCase): [8, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10]) +@unittest.skipIf(re.match(r"""1\.\d.\d""", OPENJPEG_VERSION), + "Feature not supported in glymur until openjpeg 2.0") +class TestSuite_bands(unittest.TestCase): + """Runs tests introduced in version 1.x but only pass in glymur with 2.0 + + The deal here is that the feature works with 1.x, but glymur only supports + it with version 2.0. + """ + + def setUp(self): + pass + + def tearDown(self): + pass + + def test_ETS_C0P0_p0_05_j2k(self): + jfile = opj_data_file('input/conformance/p0_05.j2k') + jp2k = Jp2k(jfile) + jpdata = jp2k.read_bands(rlevel=3) + + pgxfile = opj_data_file('baseline/conformance/c0p0_05.pgx') + pgxdata = read_pgx(pgxfile) + self.assertTrue(peak_tolerance(jpdata[0], pgxdata) < 54) + self.assertTrue(mse(jpdata[0], pgxdata) < 68) + + @unittest.skip("8-bit pgx data vs 12-bit j2k data") + def test_ETS_C0P0_p0_06_j2k(self): + jfile = opj_data_file('input/conformance/p0_06.j2k') + jp2k = Jp2k(jfile) + jpdata = jp2k.read_bands(rlevel=3) + + pgxfile = opj_data_file('baseline/conformance/c0p0_06.pgx') + pgxdata = read_pgx(pgxfile) + tol = peak_tolerance(jpdata[0], pgxdata) + self.assertTrue(tol < 109) + m = mse(jpdata[0], pgxdata) + self.assertTrue(m < 743) + + def test_ETS_C0P1_p1_03_j2k(self): + jfile = opj_data_file('input/conformance/p1_03.j2k') + jp2k = Jp2k(jfile) + jpdata = jp2k.read_bands(rlevel=3) + + pgxfile = opj_data_file('baseline/conformance/c0p1_03.pgx') + pgxdata = read_pgx(pgxfile) + + self.assertTrue(peak_tolerance(jpdata[0], pgxdata) < 28) + self.assertTrue(mse(jpdata[0], pgxdata) < 18.8) + + def test_ETS_C1P1_p1_03_j2k(self): + jfile = opj_data_file('input/conformance/p1_03.j2k') + jp2k = Jp2k(jfile) + jpdata = jp2k.read_bands() + + pgxfile = opj_data_file('baseline/conformance/c1p1_03_0.pgx') + pgxdata = read_pgx(pgxfile) + self.assertTrue(peak_tolerance(jpdata[0], pgxdata) < 2) + self.assertTrue(mse(jpdata[0], pgxdata) < 0.3) + + pgxfile = opj_data_file('baseline/conformance/c1p1_03_1.pgx') + pgxdata = read_pgx(pgxfile) + self.assertTrue(peak_tolerance(jpdata[1], pgxdata) < 2) + self.assertTrue(mse(jpdata[1], pgxdata) < 0.21) + + pgxfile = opj_data_file('baseline/conformance/c1p1_03_2.pgx') + pgxdata = read_pgx(pgxfile) + self.assertTrue(peak_tolerance(jpdata[2], pgxdata) <= 1) + self.assertTrue(mse(jpdata[2], pgxdata) < 0.2) + + pgxfile = opj_data_file('baseline/conformance/c1p1_03_3.pgx') + pgxdata = read_pgx(pgxfile) + np.testing.assert_array_equal(jpdata[3], pgxdata) + + def test_ETS_C1P0_p0_05_j2k(self): + jfile = opj_data_file('input/conformance/p0_05.j2k') + jp2k = Jp2k(jfile) + jpdata = jp2k.read_bands() + + pgxfile = opj_data_file('baseline/conformance/c1p0_05_0.pgx') + pgxdata = read_pgx(pgxfile) + self.assertTrue(peak_tolerance(jpdata[0], pgxdata) < 2) + self.assertTrue(mse(jpdata[0], pgxdata) < 0.302) + + pgxfile = opj_data_file('baseline/conformance/c1p0_05_1.pgx') + pgxdata = read_pgx(pgxfile) + self.assertTrue(peak_tolerance(jpdata[1], pgxdata) < 2) + self.assertTrue(mse(jpdata[1], pgxdata) < 0.307) + + pgxfile = opj_data_file('baseline/conformance/c1p0_05_2.pgx') + pgxdata = read_pgx(pgxfile) + self.assertTrue(peak_tolerance(jpdata[2], pgxdata) < 2) + self.assertTrue(mse(jpdata[2], pgxdata) < 0.269) + + pgxfile = opj_data_file('baseline/conformance/c1p0_05_3.pgx') + pgxdata = read_pgx(pgxfile) + self.assertTrue(peak_tolerance(jpdata[3], pgxdata) == 0) + self.assertTrue(mse(jpdata[3], pgxdata) == 0) + + def test_ETS_C1P0_p0_06_j2k(self): + jfile = opj_data_file('input/conformance/p0_06.j2k') + jp2k = Jp2k(jfile) + jpdata = jp2k.read_bands() + + pgxfile = opj_data_file('baseline/conformance/c1p0_06_0.pgx') + pgxdata = read_pgx(pgxfile) + self.assertTrue(peak_tolerance(jpdata[0], pgxdata) < 635) + self.assertTrue(mse(jpdata[0], pgxdata) < 11287) + + pgxfile = opj_data_file('baseline/conformance/c1p0_06_1.pgx') + pgxdata = read_pgx(pgxfile) + self.assertTrue(peak_tolerance(jpdata[1], pgxdata) < 403) + self.assertTrue(mse(jpdata[1], pgxdata) < 6124) + + pgxfile = opj_data_file('baseline/conformance/c1p0_06_2.pgx') + pgxdata = read_pgx(pgxfile) + self.assertTrue(peak_tolerance(jpdata[2], pgxdata) < 378) + self.assertTrue(mse(jpdata[2], pgxdata) < 3968) + + pgxfile = opj_data_file('baseline/conformance/c1p0_06_3.pgx') + pgxdata = read_pgx(pgxfile) + self.assertTrue(peak_tolerance(jpdata[3], pgxdata) == 0) + self.assertTrue(mse(jpdata[3], pgxdata) == 0) + + def test_NR_DEC_merged_jp2_19_decode(self): + jfile = opj_data_file('input/nonregression/merged.jp2') + Jp2k(jfile).read_bands() + self.assertTrue(True) + + +@unittest.skipIf(re.match(r"""1\.\d.\d""", OPENJPEG_VERSION), + "Tests not passing until 2.0") +class TestSuite2point0(unittest.TestCase): + """Runs tests introduced in version 2.0 or that pass only in 2.0""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def test_ETS_C1P0_p0_10_j2k(self): + jfile = opj_data_file('input/conformance/p0_10.j2k') + jp2k = Jp2k(jfile) + jpdata = jp2k.read(rlevel=0) + + pgxfile = opj_data_file('baseline/conformance/c1p0_10_0.pgx') + pgxdata = read_pgx(pgxfile) + np.testing.assert_array_equal(jpdata[:, :, 0], pgxdata) + + pgxfile = opj_data_file('baseline/conformance/c1p0_10_1.pgx') + pgxdata = read_pgx(pgxfile) + np.testing.assert_array_equal(jpdata[:, :, 1], pgxdata) + + pgxfile = opj_data_file('baseline/conformance/c1p0_10_2.pgx') + pgxdata = read_pgx(pgxfile) + np.testing.assert_array_equal(jpdata[:, :, 2], pgxdata) + + def test_NR_DEC_broken2_jp2_5_decode(self): + # Null pointer access + jfile = opj_data_file('input/nonregression/broken2.jp2') + with self.assertRaises(IOError): + with warnings.catch_warnings(): + # Invalid marker ID. + warnings.simplefilter("ignore") + Jp2k(jfile).read() + self.assertTrue(True) + + def test_NR_DEC_broken4_jp2_7_decode(self): + jfile = opj_data_file('input/nonregression/broken4.jp2') + with self.assertRaises(IOError): + with warnings.catch_warnings(): + # invalid number of subbands, bad marker ID + warnings.simplefilter("ignore") + Jp2k(jfile).read() + self.assertTrue(True) + + def test_NR_DEC_kakadu_v4_4_openjpegv2_broken_j2k_16_decode(self): + # This test actually passes in 1.5, but produces unpleasant warning + # messages that cannot be turned off? + relpath = 'input/nonregression/kakadu_v4-4_openjpegv2_broken.j2k' + jfile = opj_data_file(relpath) + Jp2k(jfile).read() + self.assertTrue(True) + + +@unittest.skipIf(OPENJP2_IS_V2_OFFICIAL, + "Test not in done in v2.0.0 official") +@unittest.skipIf(re.match(r"""1\.\d.\d""", OPENJPEG_VERSION), + "Tests not introduced until 2.1") +class TestSuite2point1(unittest.TestCase): + """Runs tests introduced in version 2.0+ or that pass only in 2.0+""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def test_NR_DEC_text_GBR_jp2_29_decode(self): + jfile = opj_data_file('input/nonregression/text_GBR.jp2') + with warnings.catch_warnings(): + # brand is 'jp2 ', but has any icc profile. + warnings.simplefilter("ignore") + jp2 = Jp2k(jfile) + jp2.read() + self.assertTrue(True) + + def test_NR_DEC_kodak_2layers_lrcp_j2c_31_decode(self): + jfile = opj_data_file('input/nonregression/kodak_2layers_lrcp.j2c') + Jp2k(jfile).read() + self.assertTrue(True) + + def test_NR_DEC_kodak_2layers_lrcp_j2c_32_decode(self): + jfile = opj_data_file('input/nonregression/kodak_2layers_lrcp.j2c') + Jp2k(jfile).read(layer=2) + self.assertTrue(True) + + def test_NR_DEC_issue104_jpxstream_jp2_33_decode(self): + jfile = opj_data_file('input/nonregression/issue104_jpxstream.jp2') + Jp2k(jfile).read() + self.assertTrue(True) + + def test_NR_DEC_mem_b2ace68c_1381_jp2_34_decode(self): + jfile = opj_data_file('input/nonregression/mem-b2ace68c-1381.jp2') + with warnings.catch_warnings(): + # This file has a bad pclr box, we test for this elsewhere. + warnings.simplefilter("ignore") + j = Jp2k(jfile) + j.read() + self.assertTrue(True) + + def test_NR_DEC_mem_b2b86b74_2753_jp2_35_decode(self): + jfile = opj_data_file('input/nonregression/mem-b2b86b74-2753.jp2') + Jp2k(jfile).read() + self.assertTrue(True) + + def test_NR_DEC_gdal_fuzzer_unchecked_num_resolutions_jp2_36_decode(self): + f = 'input/nonregression/gdal_fuzzer_unchecked_numresolutions.jp2' + jfile = opj_data_file(f) + with warnings.catch_warnings(): + # Invalid number of resolutions. + warnings.simplefilter("ignore") + j = Jp2k(jfile) + with self.assertRaises(IOError): + j.read() + + def test_NR_DEC_gdal_fuzzer_check_number_of_tiles_jp2_38_decode(self): + relpath = 'input/nonregression/gdal_fuzzer_check_number_of_tiles.jp2' + jfile = opj_data_file(relpath) + with warnings.catch_warnings(): + # Invalid number of tiles. + warnings.simplefilter("ignore") + j = Jp2k(jfile) + with self.assertRaises(IOError): + j.read() + + def test_NR_DEC_gdal_fuzzer_check_comp_dx_dy_jp2_39_decode(self): + relpath = 'input/nonregression/gdal_fuzzer_check_comp_dx_dy.jp2' + jfile = opj_data_file(relpath) + with warnings.catch_warnings(): + # Invalid subsampling value + warnings.simplefilter("ignore") + with self.assertRaises(IOError): + Jp2k(jfile).read() + + def test_NR_DEC_file_409752_jp2_40_decode(self): + jfile = opj_data_file('input/nonregression/file409752.jp2') + with self.assertRaises(RuntimeError): + Jp2k(jfile).read() + + @unittest.skipIf(sys.hexversion < 0x03020000, + "Uses features introduced in 3.2.") + def test_NR_DEC_issue188_beach_64bitsbox_jp2_41_decode(self): + # Has an 'XML ' box instead of 'xml '. Yes that is pedantic, but it + # really does deserve a warning. + relpath = 'input/nonregression/issue188_beach_64bitsbox.jp2' + jfile = opj_data_file(relpath) + with self.assertWarns(UserWarning): + Jp2k(jfile).read() + + def test_NR_DEC_issue206_image_000_jp2_42_decode(self): + jfile = opj_data_file('input/nonregression/issue206_image-000.jp2') + Jp2k(jfile).read() + self.assertTrue(True) + + def test_NR_DEC_p1_04_j2k_43_decode(self): + jfile = opj_data_file('input/conformance/p1_04.j2k') + jp2k = Jp2k(jfile) + ssdata = jp2k.read(area=(0, 0, 1024, 1024)) + odata = jp2k.read() + np.testing.assert_array_equal(ssdata, odata) + + def test_NR_DEC_p1_04_j2k_44_decode(self): + jfile = opj_data_file('input/conformance/p1_04.j2k') + jp2k = Jp2k(jfile) + ssdata = jp2k.read(area=(640, 512, 768, 640)) + odata = jp2k.read() + np.testing.assert_array_equal(ssdata, odata[640:768, 512:640]) + + def test_NR_DEC_p1_04_j2k_45_decode(self): + jfile = opj_data_file('input/conformance/p1_04.j2k') + jp2k = Jp2k(jfile) + ssdata = jp2k.read(area=(896, 896, 1024, 1024)) + odata = jp2k.read() + np.testing.assert_array_equal(ssdata, odata[896:1024, 896:1024]) + + def test_NR_DEC_p1_04_j2k_46_decode(self): + jfile = opj_data_file('input/conformance/p1_04.j2k') + jp2k = Jp2k(jfile) + ssdata = jp2k.read(area=(500, 100, 800, 300)) + odata = jp2k.read() + np.testing.assert_array_equal(ssdata, odata[500:800, 100:300]) + + def test_NR_DEC_p1_04_j2k_47_decode(self): + jfile = opj_data_file('input/conformance/p1_04.j2k') + jp2k = Jp2k(jfile) + ssdata = jp2k.read(area=(520, 260, 600, 360)) + odata = jp2k.read() + np.testing.assert_array_equal(ssdata, odata[520:600, 260:360]) + + def test_NR_DEC_p1_04_j2k_48_decode(self): + jfile = opj_data_file('input/conformance/p1_04.j2k') + jp2k = Jp2k(jfile) + ssdata = jp2k.read(area=(520, 260, 660, 360)) + odata = jp2k.read() + np.testing.assert_array_equal(ssdata, odata[520:660, 260:360]) + + def test_NR_DEC_p1_04_j2k_49_decode(self): + jfile = opj_data_file('input/conformance/p1_04.j2k') + jp2k = Jp2k(jfile) + ssdata = jp2k.read(area=(520, 360, 600, 400)) + odata = jp2k.read() + np.testing.assert_array_equal(ssdata, odata[520:600, 360:400]) + + def test_NR_DEC_p1_04_j2k_50_decode(self): + jfile = opj_data_file('input/conformance/p1_04.j2k') + jp2k = Jp2k(jfile) + ssdata = jp2k.read(area=(0, 0, 1024, 1024), rlevel=2) + odata = jp2k.read(rlevel=2) + + np.testing.assert_array_equal(ssdata, odata[0:256, 0:256]) + + def test_NR_DEC_p1_04_j2k_51_decode(self): + jfile = opj_data_file('input/conformance/p1_04.j2k') + jp2k = Jp2k(jfile) + ssdata = jp2k.read(area=(640, 512, 768, 640), rlevel=2) + odata = jp2k.read(rlevel=2) + np.testing.assert_array_equal(ssdata, odata[160:192, 128:160]) + + def test_NR_DEC_p1_04_j2k_52_decode(self): + jfile = opj_data_file('input/conformance/p1_04.j2k') + jp2k = Jp2k(jfile) + ssdata = jp2k.read(area=(896, 896, 1024, 1024), rlevel=2) + odata = jp2k.read(rlevel=2) + np.testing.assert_array_equal(ssdata, odata[224:352, 224:352]) + + def test_NR_DEC_p1_04_j2k_53_decode(self): + jfile = opj_data_file('input/conformance/p1_04.j2k') + jp2k = Jp2k(jfile) + ssdata = jp2k.read(area=(500, 100, 800, 300), rlevel=2) + odata = jp2k.read(rlevel=2) + np.testing.assert_array_equal(ssdata, odata[125:200, 25:75]) + + def test_NR_DEC_p1_04_j2k_54_decode(self): + jfile = opj_data_file('input/conformance/p1_04.j2k') + jp2k = Jp2k(jfile) + ssdata = jp2k.read(area=(520, 260, 600, 360), rlevel=2) + odata = jp2k.read(rlevel=2) + np.testing.assert_array_equal(ssdata, odata[130:150, 65:90]) + + def test_NR_DEC_p1_04_j2k_55_decode(self): + jfile = opj_data_file('input/conformance/p1_04.j2k') + jp2k = Jp2k(jfile) + ssdata = jp2k.read(area=(520, 260, 660, 360), rlevel=2) + odata = jp2k.read(rlevel=2) + np.testing.assert_array_equal(ssdata, odata[130:165, 65:90]) + + def test_NR_DEC_p1_04_j2k_56_decode(self): + jfile = opj_data_file('input/conformance/p1_04.j2k') + jp2k = Jp2k(jfile) + ssdata = jp2k.read(area=(520, 360, 600, 400), rlevel=2) + odata = jp2k.read(rlevel=2) + np.testing.assert_array_equal(ssdata, odata[130:150, 90:100]) + + def test_NR_DEC_p1_04_j2k_57_decode(self): + jfile = opj_data_file('input/conformance/p1_04.j2k') + jp2k = Jp2k(jfile) + tdata = jp2k.read(tile=63) # last tile + odata = jp2k.read() + np.testing.assert_array_equal(tdata, odata[896:1024, 896:1024]) + + def test_NR_DEC_p1_04_j2k_58_decode(self): + jfile = opj_data_file('input/conformance/p1_04.j2k') + jp2k = Jp2k(jfile) + tdata = jp2k.read(tile=63, rlevel=2) # last tile + odata = jp2k.read(rlevel=2) + np.testing.assert_array_equal(tdata, odata[224:256, 224:256]) + + def test_NR_DEC_p1_04_j2k_59_decode(self): + jfile = opj_data_file('input/conformance/p1_04.j2k') + jp2k = Jp2k(jfile) + tdata = jp2k.read(tile=12) # 2nd row, 5th column + odata = jp2k.read() + np.testing.assert_array_equal(tdata, odata[128:256, 512:640]) + + def test_NR_DEC_p1_04_j2k_60_decode(self): + jfile = opj_data_file('input/conformance/p1_04.j2k') + jp2k = Jp2k(jfile) + tdata = jp2k.read(tile=12, rlevel=1) # 2nd row, 5th column + odata = jp2k.read(rlevel=1) + np.testing.assert_array_equal(tdata, odata[64:128, 256:320]) + + def test_NR_DEC_jp2_36_decode(self): + lst = ('input', + 'nonregression', + 'gdal_fuzzer_assert_in_opj_j2k_read_SQcd_SQcc.patch.jp2') + jfile = opj_data_file('/'.join(lst)) + with warnings.catch_warnings(): + # Invalid component number. + warnings.simplefilter("ignore") + j = Jp2k(jfile) + with self.assertRaises(IOError): + j.read() + + @unittest.skip("fprintf stderr output in r2343.") + def test_NR_DEC_p1_06_j2k_61_decode(self): + jfile = opj_data_file('input/conformance/p1_06.j2k') + jp2k = Jp2k(jfile) + ssdata = jp2k.read(area=(0, 0, 12, 12)) + odata = jp2k.read() + np.testing.assert_array_equal(ssdata, odata[0:12, 0:12]) + + @unittest.skip("fprintf stderr output in r2343.") + def test_NR_DEC_p1_06_j2k_62_decode(self): + jfile = opj_data_file('input/conformance/p1_06.j2k') + jp2k = Jp2k(jfile) + ssdata = jp2k.read(area=(1, 8, 8, 11)) + odata = jp2k.read() + np.testing.assert_array_equal(ssdata, odata[1:8, 8:11]) + + @unittest.skip("fprintf stderr output in r2343.") + def test_NR_DEC_p1_06_j2k_63_decode(self): + jfile = opj_data_file('input/conformance/p1_06.j2k') + jp2k = Jp2k(jfile) + ssdata = jp2k.read(area=(9, 9, 12, 12)) + odata = jp2k.read() + np.testing.assert_array_equal(ssdata, odata[9:12, 9:12]) + + @unittest.skip("fprintf stderr output in r2343.") + def test_NR_DEC_p1_06_j2k_64_decode(self): + jfile = opj_data_file('input/conformance/p1_06.j2k') + jp2k = Jp2k(jfile) + ssdata = jp2k.read(area=(10, 4, 12, 10)) + odata = jp2k.read() + np.testing.assert_array_equal(ssdata, odata[10:12, 4:10]) + + @unittest.skip("fprintf stderr output in r2343.") + def test_NR_DEC_p1_06_j2k_65_decode(self): + jfile = opj_data_file('input/conformance/p1_06.j2k') + jp2k = Jp2k(jfile) + ssdata = jp2k.read(area=(3, 3, 9, 9)) + odata = jp2k.read() + np.testing.assert_array_equal(ssdata, odata[3:9, 3:9]) + + @unittest.skip("fprintf stderr output in r2343.") + def test_NR_DEC_p1_06_j2k_66_decode(self): + jfile = opj_data_file('input/conformance/p1_06.j2k') + jp2k = Jp2k(jfile) + ssdata = jp2k.read(area=(4, 4, 7, 7)) + odata = jp2k.read() + np.testing.assert_array_equal(ssdata, odata[4:7, 4:7]) + + @unittest.skip("fprintf stderr output in r2343.") + def test_NR_DEC_p1_06_j2k_67_decode(self): + jfile = opj_data_file('input/conformance/p1_06.j2k') + jp2k = Jp2k(jfile) + ssdata = jp2k.read(area=(4, 4, 5, 5)) + odata = jp2k.read() + np.testing.assert_array_equal(ssdata, odata[4:5, 4: 5]) + + @unittest.skip("fprintf stderr output in r2343.") + def test_NR_DEC_p1_06_j2k_68_decode(self): + jfile = opj_data_file('input/conformance/p1_06.j2k') + jp2k = Jp2k(jfile) + ssdata = jp2k.read(area=(0, 0, 12, 12), rlevel=1) + odata = jp2k.read(rlevel=1) + np.testing.assert_array_equal(ssdata, odata[0:6, 0:6]) + + @unittest.skip("fprintf stderr output in r2343.") + def test_NR_DEC_p1_06_j2k_69_decode(self): + jfile = opj_data_file('input/conformance/p1_06.j2k') + jp2k = Jp2k(jfile) + ssdata = jp2k.read(area=(1, 8, 8, 11), rlevel=1) + self.assertEqual(ssdata.shape, (3, 2, 3)) + + def test_NR_DEC_p1_06_j2k_70_decode(self): + jfile = opj_data_file('input/conformance/p1_06.j2k') + jp2k = Jp2k(jfile) + ssdata = jp2k.read(area=(9, 9, 12, 12), rlevel=1) + self.assertEqual(ssdata.shape, (1, 1, 3)) + + def test_NR_DEC_p1_06_j2k_71_decode(self): + jfile = opj_data_file('input/conformance/p1_06.j2k') + jp2k = Jp2k(jfile) + ssdata = jp2k.read(area=(10, 4, 12, 10), rlevel=1) + self.assertEqual(ssdata.shape, (1, 3, 3)) + + def test_NR_DEC_p1_06_j2k_72_decode(self): + jfile = opj_data_file('input/conformance/p1_06.j2k') + jp2k = Jp2k(jfile) + ssdata = jp2k.read(area=(3, 3, 9, 9), rlevel=1) + self.assertEqual(ssdata.shape, (3, 3, 3)) + + def test_NR_DEC_p1_06_j2k_73_decode(self): + jfile = opj_data_file('input/conformance/p1_06.j2k') + jp2k = Jp2k(jfile) + ssdata = jp2k.read(area=(4, 4, 7, 7), rlevel=1) + self.assertEqual(ssdata.shape, (2, 2, 3)) + + def test_NR_DEC_p1_06_j2k_74_decode(self): + jfile = opj_data_file('input/conformance/p1_06.j2k') + jp2k = Jp2k(jfile) + ssdata = jp2k.read(area=(4, 4, 5, 5), rlevel=1) + self.assertEqual(ssdata.shape, (1, 1, 3)) + + def test_NR_DEC_p1_06_j2k_75_decode(self): + # Image size would be 0 x 0. + jfile = opj_data_file('input/conformance/p1_06.j2k') + jp2k = Jp2k(jfile) + with self.assertRaises((IOError, OSError)): + jp2k.read(area=(9, 9, 12, 12), rlevel=2) + + def test_NR_DEC_p0_04_j2k_85_decode(self): + jfile = opj_data_file('input/conformance/p0_04.j2k') + jp2k = Jp2k(jfile) + ssdata = jp2k.read(area=(0, 0, 256, 256)) + fulldata = jp2k.read() + np.testing.assert_array_equal(fulldata[0:256, 0:256], ssdata) + + def test_NR_DEC_p0_04_j2k_86_decode(self): + jfile = opj_data_file('input/conformance/p0_04.j2k') + jp2k = Jp2k(jfile) + ssdata = jp2k.read(area=(0, 128, 128, 256)) + fulldata = jp2k.read() + np.testing.assert_array_equal(fulldata[0:128, 128:256], ssdata) + + def test_NR_DEC_p0_04_j2k_87_decode(self): + jfile = opj_data_file('input/conformance/p0_04.j2k') + jp2k = Jp2k(jfile) + ssdata = jp2k.read(area=(10, 50, 200, 120)) + fulldata = jp2k.read() + np.testing.assert_array_equal(fulldata[10:200, 50:120], ssdata) + + def test_NR_DEC_p0_04_j2k_88_decode(self): + jfile = opj_data_file('input/conformance/p0_04.j2k') + jp2k = Jp2k(jfile) + ssdata = jp2k.read(area=(150, 10, 210, 190)) + fulldata = jp2k.read() + np.testing.assert_array_equal(fulldata[150:210, 10:190], ssdata) + + def test_NR_DEC_p0_04_j2k_89_decode(self): + jfile = opj_data_file('input/conformance/p0_04.j2k') + jp2k = Jp2k(jfile) + ssdata = jp2k.read(area=(80, 100, 150, 200)) + fulldata = jp2k.read() + np.testing.assert_array_equal(fulldata[80:150, 100:200], ssdata) + + def test_NR_DEC_p0_04_j2k_90_decode(self): + jfile = opj_data_file('input/conformance/p0_04.j2k') + jp2k = Jp2k(jfile) + ssdata = jp2k.read(area=(20, 150, 50, 200)) + fulldata = jp2k.read() + np.testing.assert_array_equal(fulldata[20:50, 150:200], ssdata) + + def test_NR_DEC_p0_04_j2k_91_decode(self): + jfile = opj_data_file('input/conformance/p0_04.j2k') + jp2k = Jp2k(jfile) + ssdata = jp2k.read(area=(0, 0, 256, 256), rlevel=2) + fulldata = jp2k.read(rlevel=2) + np.testing.assert_array_equal(fulldata[0:64, 0:64], ssdata) + + def test_NR_DEC_p0_04_j2k_92_decode(self): + jfile = opj_data_file('input/conformance/p0_04.j2k') + jp2k = Jp2k(jfile) + ssdata = jp2k.read(area=(0, 128, 128, 256), rlevel=2) + fulldata = jp2k.read(rlevel=2) + np.testing.assert_array_equal(fulldata[0:32, 32:64], ssdata) + + def test_NR_DEC_p0_04_j2k_93_decode(self): + jfile = opj_data_file('input/conformance/p0_04.j2k') + jp2k = Jp2k(jfile) + ssdata = jp2k.read(area=(10, 50, 200, 120), rlevel=2) + fulldata = jp2k.read(rlevel=2) + np.testing.assert_array_equal(fulldata[3:50, 13:30], ssdata) + + def test_NR_DEC_p0_04_j2k_94_decode(self): + jfile = opj_data_file('input/conformance/p0_04.j2k') + jp2k = Jp2k(jfile) + ssdata = jp2k.read(area=(150, 10, 210, 190), rlevel=2) + fulldata = jp2k.read(rlevel=2) + np.testing.assert_array_equal(fulldata[38:53, 3:48], ssdata) + + def test_NR_DEC_p0_04_j2k_95_decode(self): + jfile = opj_data_file('input/conformance/p0_04.j2k') + jp2k = Jp2k(jfile) + ssdata = jp2k.read(area=(80, 100, 150, 200), rlevel=2) + fulldata = jp2k.read(rlevel=2) + np.testing.assert_array_equal(fulldata[20:38, 25:50], ssdata) + + def test_NR_DEC_p0_04_j2k_96_decode(self): + jfile = opj_data_file('input/conformance/p0_04.j2k') + jp2k = Jp2k(jfile) + ssdata = jp2k.read(area=(20, 150, 50, 200), rlevel=2) + fulldata = jp2k.read(rlevel=2) + np.testing.assert_array_equal(fulldata[5:13, 38:50], ssdata) + + if __name__ == "__main__": unittest.main() From 0bb875bfff9a166f9ac9ba0a81583285d5687ad3 Mon Sep 17 00:00:00 2001 From: jevans Date: Fri, 6 Sep 2013 12:25:56 -0400 Subject: [PATCH 06/22] test_jp2k refactored to not duplicate tests. #110 --- glymur/test/test_jp2k.py | 1499 +++++++++++++++----------------------- 1 file changed, 590 insertions(+), 909 deletions(-) diff --git a/glymur/test/test_jp2k.py b/glymur/test/test_jp2k.py index 442ae67..edefb7f 100644 --- a/glymur/test/test_jp2k.py +++ b/glymur/test/test_jp2k.py @@ -120,10 +120,164 @@ class TestJp2kBadXmlFile(unittest.TestCase): self.assertIsNone(jp2k.box[3].xml) +@unittest.skipIf(glymur.lib.openjp2.OPENJP2 is None and not OPENJP2_IS_V2_OFFICIAL, + "Missing openjp2 library version 2.0+.") +class TestJp2k_2_1(unittest.TestCase): + """Test suite for version 2.0+ of openjpeg software""" + + def setUp(self): + self.jp2file = glymur.data.nemo() + self.j2kfile = glymur.data.goodstuff() + + def tearDown(self): + pass + + @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") + def test_grey_with_extra_component(self): + """version 2.0 cannot write gray + extra""" + with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: + j = Jp2k(tfile.name, 'wb') + data = np.zeros((128, 128, 2), dtype=np.uint8) + j.write(data) + self.assertEqual(j.box[2].box[0].height, 128) + self.assertEqual(j.box[2].box[0].width, 128) + self.assertEqual(j.box[2].box[0].num_components, 2) + self.assertEqual(j.box[2].box[1].colorspace, + glymur.core.GREYSCALE) + + @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") + def test_rgb_with_extra_component(self): + """v2.0+ should be able to write extra components""" + with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: + j = Jp2k(tfile.name, 'wb') + data = np.zeros((128, 128, 4), dtype=np.uint8) + j.write(data) + self.assertEqual(j.box[2].box[0].height, 128) + self.assertEqual(j.box[2].box[0].width, 128) + self.assertEqual(j.box[2].box[0].num_components, 4) + self.assertEqual(j.box[2].box[1].colorspace, glymur.core.SRGB) + + @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") + def test_openjpeg_library_message(self): + """Verify the error message produced by the openjpeg library""" + # This will confirm that the error callback mechanism is working. + with open(self.jp2file, 'rb') as fptr: + data = fptr.read() + with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: + # Codestream starts at byte 3127. SIZ marker at 3137. + # COD marker at 3186. Subsampling at 3180. + tfile.write(data[0:3179]) + + # Make the DY bytes of the SIZ segment zero. That means that + # a subsampling factor is zero, which is illegal. + tfile.write(b'\x00') + tfile.write(data[3180:3182]) + tfile.write(b'\x00') + tfile.write(data[3184:3186]) + tfile.write(b'\x00') + + tfile.write(data[3186:]) + tfile.flush() + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + j = Jp2k(tfile.name) + regexp = re.compile(r'''OpenJPEG\slibrary\serror:\s+ + Invalid\svalues\sfor\scomp\s=\s0\s+ + :\sdx=1\sdy=0''', re.VERBOSE) + if sys.hexversion < 0x03020000: + with self.assertRaisesRegexp((IOError, OSError), regexp): + j.read(rlevel=1) + else: + with self.assertRaisesRegex((IOError, OSError), regexp): + j.read(rlevel=1) + + +@unittest.skipIf(re.match(r"""1\.\d.\d""", OPENJPEG_VERSION), + "Not tested for 1.x") +class TestJp2k_2_0(unittest.TestCase): + """Test suite requiring at least version 2.0""" + + def setUp(self): + self.jp2file = glymur.data.nemo() + self.j2kfile = glymur.data.goodstuff() + + def tearDown(self): + pass + + @unittest.skipIf(not OPENJP2_IS_V2_OFFICIAL, + "Behavior is specific to 2.0 official.") + @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") + def test_extra_components_on_v2(self): + """must error out in 1.x with extra components.""" + # Extra components seems to require 2.0+. Verify that we error out. + with self.assertRaises(OSError): + with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: + j = Jp2k(tfile.name, 'wb') + data = np.zeros((128, 128, 4), dtype=np.uint8) + j.write(data) + + @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") + def test_unrecognized_jp2_clrspace(self): + """We only allow RGB and GRAYSCALE. Should error out with others""" + with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: + j = Jp2k(tfile.name, 'wb') + with self.assertRaises(IOError): + data = np.zeros((128, 128, 3), dtype=np.uint8) + j.write(data, colorspace='cmyk') + + @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") + def test_asoc_label_box(self): + """Test asoc and label box""" + # Construct a fake file with an asoc and a label box, as + # OpenJPEG doesn't have such a file. + data = Jp2k(self.jp2file).read(rlevel=1) + with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: + j = Jp2k(tfile.name, 'wb') + j.write(data) + + with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile2: + + # Offset of the codestream is where we start. + read_buffer = tfile.read(77) + tfile2.write(read_buffer) + + # read the rest of the file, it's the codestream. + codestream = tfile.read() + + # Write the asoc superbox. + # Length = 36, id is 'asoc'. + write_buffer = struct.pack('>I4s', int(56), b'asoc') + tfile2.write(write_buffer) + + # Write the contained label box + write_buffer = struct.pack('>I4s', int(13), b'lbl ') + tfile2.write(write_buffer) + tfile2.write('label'.encode()) + + # Write the xml box + # Length = 36, id is 'xml '. + write_buffer = struct.pack('>I4s', int(35), b'xml ') + tfile2.write(write_buffer) + + write_buffer = 'this is a test' + write_buffer = write_buffer.encode() + tfile2.write(write_buffer) + + # Now append the codestream. + tfile2.write(codestream) + tfile2.flush() + + jasoc = Jp2k(tfile2.name) + self.assertEqual(jasoc.box[3].box_id, 'asoc') + self.assertEqual(jasoc.box[3].box[0].box_id, 'lbl ') + self.assertEqual(jasoc.box[3].box[0].label, 'label') + self.assertEqual(jasoc.box[3].box[1].box_id, 'xml ') + + @unittest.skipIf(glymur.lib.openjp2.OPENJP2 is None, "Missing openjp2 library.") -class TestJp2k(unittest.TestCase): - """Test suite for version 2.0/2.0+ of openjpeg""" +class TestJp2k_1_x(unittest.TestCase): + """Test suite for versions up to 1.5.1 of openjpeg but no further""" def setUp(self): self.jp2file = glymur.data.nemo() @@ -159,20 +313,6 @@ class TestJp2k(unittest.TestCase): with self.assertRaises(IOError): j.read(rlevel=6) - def test_not_jpeg2000(self): - """Should error out appropriately if not given a JPEG 2000 file.""" - filename = pkg_resources.resource_filename(glymur.__name__, "jp2k.py") - with self.assertRaises(IOError): - Jp2k(filename) - - def test_file_not_present(self): - """Should error out if reading from a file that does not exist""" - # Verify that we error out appropriately if not given an existing file - # at all. - with self.assertRaises(OSError): - filename = 'this file does not actually exist on the file system.' - Jp2k(filename) - @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") def test_write_with_jp2_in_caps(self): """should be able to write with JP2 suffix.""" @@ -358,671 +498,446 @@ class TestJp2k(unittest.TestCase): self.assertEqual(new_jp2.box[j].length, baseline_jp2.box[j].length) + @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") + def test_cblkh_different_than_width(self): + """Verify that we can set a code block size where height does not equal + width. + """ + data = np.zeros((128, 128), dtype=np.uint8) + with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile: + j = Jp2k(tfile.name, 'wb') + + # The code block dimensions are given as rows x columns. + j.write(data, cbsize=(16, 32)) + + codestream = j.get_codestream() + + # Code block size is reported as XY in the codestream. + self.assertEqual(tuple(codestream.segment[2].spcod[5:7]), (3, 2)) + + @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") + def test_too_many_dimensions(self): + """OpenJP2 only allows 2D or 3D images.""" + with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile: + j = Jp2k(tfile.name, 'wb') + with self.assertRaises(IOError): + data = np.zeros((128, 128, 2, 2), dtype=np.uint8) + j.write(data) + + @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") + def test_2d_rgb(self): + """RGB must have at least 3 components.""" + with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: + j = Jp2k(tfile.name, 'wb') + with self.assertRaises(IOError): + data = np.zeros((128, 128, 2), dtype=np.uint8) + j.write(data, colorspace='rgb') + + @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") + def test_colorspace_with_j2k(self): + """Specifying a colorspace with J2K does not make sense""" + with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile: + j = Jp2k(tfile.name, 'wb') + with self.assertRaises(IOError): + data = np.zeros((128, 128, 3), dtype=np.uint8) + j.write(data, colorspace='rgb') + + @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") + def test_specify_rgb(self): + """specify RGB explicitly""" + with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: + j = Jp2k(tfile.name, 'wb') + data = np.zeros((128, 128, 3), dtype=np.uint8) + j.write(data, colorspace='rgb') + self.assertEqual(j.box[2].box[1].colorspace, glymur.core.SRGB) + + @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") + def test_specify_gray(self): + """test gray explicitly specified (that's GRAY, not GREY)""" + with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: + j = Jp2k(tfile.name, 'wb') + data = np.zeros((128, 128), dtype=np.uint8) + j.write(data, colorspace='gray') + self.assertEqual(j.box[2].box[1].colorspace, + glymur.core.GREYSCALE) + + @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") + def test_specify_grey(self): + """test grey explicitly specified""" + with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: + j = Jp2k(tfile.name, 'wb') + data = np.zeros((128, 128), dtype=np.uint8) + j.write(data, colorspace='grey') + self.assertEqual(j.box[2].box[1].colorspace, + glymur.core.GREYSCALE) + + @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") + def test_grey_with_two_extra_comps(self): + """should be able to write gray + two extra components""" + with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: + j = Jp2k(tfile.name, 'wb') + data = np.zeros((128, 128, 3), dtype=np.uint8) + j.write(data, colorspace='gray') + self.assertEqual(j.box[2].box[0].height, 128) + self.assertEqual(j.box[2].box[0].width, 128) + self.assertEqual(j.box[2].box[0].num_components, 3) + self.assertEqual(j.box[2].box[1].colorspace, + glymur.core.GREYSCALE) + + def test_specify_ycc(self): + """Should reject YCC""" + with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: + j = Jp2k(tfile.name, 'wb') + with self.assertRaises(IOError): + data = np.zeros((128, 128, 3), dtype=np.uint8) + j.write(data, colorspace='ycc') + + @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") + def test_write_with_jp2_in_caps(self): + """should be able to write with JP2 suffix.""" + j2k = Jp2k(self.j2kfile) + expdata = j2k.read() + with tempfile.NamedTemporaryFile(suffix='.JP2') as tfile: + ofile = Jp2k(tfile.name, 'wb') + ofile.write(expdata) + actdata = ofile.read() + np.testing.assert_array_equal(actdata, expdata) + + @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") + def test_write_srgb_without_mct(self): + """should be able to write RGB without specifying mct""" + j2k = Jp2k(self.j2kfile) + expdata = j2k.read() + with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: + ofile = Jp2k(tfile.name, 'wb') + ofile.write(expdata, mct=False) + actdata = ofile.read() + np.testing.assert_array_equal(actdata, expdata) + + codestream = ofile.get_codestream() + self.assertEqual(codestream.segment[2].spcod[3], 0) # no mct + + @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") + def test_write_grayscale_with_mct(self): + """MCT usage makes no sense for grayscale images.""" + j2k = Jp2k(self.j2kfile) + expdata = j2k.read() + with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: + ofile = Jp2k(tfile.name, 'wb') + with self.assertRaises(IOError): + ofile.write(expdata[:, :, 0], mct=True) + + @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") + def test_write_cprl(self): + """Must be able to write a CPRL progression order file""" + # Issue 17 + j = Jp2k(self.jp2file) + expdata = j.read(rlevel=1) + with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: + ofile = Jp2k(tfile.name, 'wb') + ofile.write(expdata, prog='CPRL') + actdata = ofile.read() + np.testing.assert_array_equal(actdata, expdata) + + codestream = ofile.get_codestream() + self.assertEqual(codestream.segment[2].spcod[0], glymur.core.CPRL) + + +@unittest.skipIf(glymur.lib.openjp2.OPENJP2 is not None, + "Don't bother if openjp2 is present.") +@unittest.skipIf(glymur.lib.openjpeg.OPENJPEG is None, + "Missing openjpeg library.") +class TestJp2k15(unittest.TestCase): + """Test suite for openjpeg 1.x, not appropriate for 2.x""" + + def setUp(self): + self.jp2file = glymur.data.nemo() + self.j2kfile = glymur.data.goodstuff() + + def tearDown(self): + pass + + def test_area(self): + """Area option not allowed for 1.5.1. + """ + j2k = Jp2k(self.j2kfile) + with self.assertRaises(TypeError): + j2k.read(area=(0, 0, 100, 100)) + + def test_tile(self): + """tile option not allowed for 1.5.1. + """ + j2k = Jp2k(self.j2kfile) + with self.assertRaises(TypeError): + j2k.read(tile=0) + + def test_layer(self): + """layer option not allowed for 1.5.1. + """ + j2k = Jp2k(self.j2kfile) + with self.assertRaises(TypeError): + j2k.read(layer=1) + + @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") + def test_2d_rgb(self): + """RGB must have at least 3 components.""" + with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: + j = Jp2k(tfile.name, 'wb') + with self.assertRaises(IOError): + data = np.zeros((128, 128, 2), dtype=np.uint8) + j.write(data, colorspace='rgb') + + + @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") + def test_xml_with_trailing_nulls(self): + """ElementTree doesn't like trailing null chars after valid XML text""" + with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: + with open(self.jp2file, 'rb') as ifile: + # Everything up until the jp2c box. + write_buffer = ifile.read(77) + tfile.write(write_buffer) + + # Write the xml box + # Length = 36, id is 'xml '. + write_buffer = struct.pack('>I4s', int(36), b'xml ') + tfile.write(write_buffer) + + write_buffer = 'this is a test' + chr(0) + write_buffer = write_buffer.encode() + tfile.write(write_buffer) + + # Get the rest of the input file. + write_buffer = ifile.read() + tfile.write(write_buffer) + tfile.flush() + + jp2k = Jp2k(tfile.name) + + self.assertEqual(jp2k.box[3].box_id, 'xml ') + self.assertEqual(jp2k.box[3].offset, 77) + self.assertEqual(jp2k.box[3].length, 36) + self.assertEqual(ET.tostring(jp2k.box[3].xml.getroot()), + b'this is a test') + + @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") + @unittest.skipIf(re.match(r"""1\.[345]\.\d""", + OPENJPEG_VERSION) is not None, + "Segfault on official v1.x series.") + def test_openjpeg_library_message(self): + """Verify the error message produced by the openjpeg library""" + # This will confirm that the error callback mechanism is working. + with open(self.jp2file, 'rb') as fptr: + data = fptr.read() + with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: + # Codestream starts at byte 3127. SIZ marker at 3137. + # COD marker at 3186. Subsampling at 3180. + tfile.write(data[0:3179]) + + # Make the DY bytes of the SIZ segment zero. That means that + # a subsampling factor is zero, which is illegal. + tfile.write(b'\x00') + tfile.write(data[3180:3182]) + tfile.write(b'\x00') + tfile.write(data[3184:3186]) + tfile.write(b'\x00') + + tfile.write(data[3186:]) + tfile.flush() + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + j = Jp2k(tfile.name) + regexp = re.compile(r'''OpenJPEG\slibrary\serror:\s+ + Invalid\svalues\sfor\scomp\s=\s0\s+ + :\sdx=1\sdy=0''', re.VERBOSE) + if sys.hexversion < 0x03020000: + with self.assertRaisesRegexp((IOError, OSError), regexp): + j.read(rlevel=1) + else: + with self.assertRaisesRegex((IOError, OSError), regexp): + j.read(rlevel=1) + + +@unittest.skipIf(re.match(r"""1\.[012]\.\d""", OPENJPEG_VERSION), + "Unsupported version of openjpeg.") +class TestJp2k(unittest.TestCase): + """Test suite for openjpeg software starting at 1.3""" + + def setUp(self): + self.jp2file = glymur.data.nemo() + self.j2kfile = glymur.data.goodstuff() + + def tearDown(self): + pass + + def test_rlevel_max(self): + """Verify that rlevel=-1 gets us the lowest resolution image""" + j = Jp2k(self.j2kfile) + thumbnail1 = j.read(rlevel=-1) + thumbnail2 = j.read(rlevel=5) + np.testing.assert_array_equal(thumbnail1, thumbnail2) + self.assertEqual(thumbnail1.shape, (25, 15, 3)) + + def test_rlevel_too_high(self): + """Should error out appropriately if reduce level too high""" + j = Jp2k(self.jp2file) + with self.assertRaises(IOError): + j.read(rlevel=6) + + def test_not_jpeg2000(self): + """Should error out appropriately if not given a JPEG 2000 file.""" + filename = pkg_resources.resource_filename(glymur.__name__, "jp2k.py") + with self.assertRaises(IOError): + Jp2k(filename) + + def test_file_not_present(self): + """Should error out if reading from a file that does not exist""" + # Verify that we error out appropriately if not given an existing file + # at all. + with self.assertRaises(OSError): + filename = 'this file does not actually exist on the file system.' + Jp2k(filename) + + def test_jp2_boxes(self): + """Verify the boxes of a JP2 file. Basic jp2 test.""" + jp2k = Jp2k(self.jp2file) + + # top-level boxes + self.assertEqual(len(jp2k.box), 6) + + self.assertEqual(jp2k.box[0].box_id, 'jP ') + self.assertEqual(jp2k.box[0].offset, 0) + self.assertEqual(jp2k.box[0].length, 12) + self.assertEqual(jp2k.box[0].longname, 'JPEG 2000 Signature') + + self.assertEqual(jp2k.box[1].box_id, 'ftyp') + self.assertEqual(jp2k.box[1].offset, 12) + self.assertEqual(jp2k.box[1].length, 20) + self.assertEqual(jp2k.box[1].longname, 'File Type') + + self.assertEqual(jp2k.box[2].box_id, 'jp2h') + self.assertEqual(jp2k.box[2].offset, 32) + self.assertEqual(jp2k.box[2].length, 45) + self.assertEqual(jp2k.box[2].longname, 'JP2 Header') + + self.assertEqual(jp2k.box[3].box_id, 'uuid') + self.assertEqual(jp2k.box[3].offset, 77) + self.assertEqual(jp2k.box[3].length, 638) + + self.assertEqual(jp2k.box[4].box_id, 'uuid') + self.assertEqual(jp2k.box[4].offset, 715) + self.assertEqual(jp2k.box[4].length, 2412) + + self.assertEqual(jp2k.box[5].box_id, 'jp2c') + self.assertEqual(jp2k.box[5].offset, 3127) + self.assertEqual(jp2k.box[5].length, 1132296) + + # jp2h super box + self.assertEqual(len(jp2k.box[2].box), 2) + + self.assertEqual(jp2k.box[2].box[0].box_id, 'ihdr') + self.assertEqual(jp2k.box[2].box[0].offset, 40) + self.assertEqual(jp2k.box[2].box[0].length, 22) + self.assertEqual(jp2k.box[2].box[0].longname, 'Image Header') + self.assertEqual(jp2k.box[2].box[0].height, 1456) + self.assertEqual(jp2k.box[2].box[0].width, 2592) + self.assertEqual(jp2k.box[2].box[0].num_components, 3) + self.assertEqual(jp2k.box[2].box[0].bits_per_component, 8) + self.assertEqual(jp2k.box[2].box[0].signed, False) + self.assertEqual(jp2k.box[2].box[0].compression, 7) + self.assertEqual(jp2k.box[2].box[0].colorspace_unknown, False) + self.assertEqual(jp2k.box[2].box[0].ip_provided, False) + + self.assertEqual(jp2k.box[2].box[1].box_id, 'colr') + self.assertEqual(jp2k.box[2].box[1].offset, 62) + self.assertEqual(jp2k.box[2].box[1].length, 15) + self.assertEqual(jp2k.box[2].box[1].longname, 'Colour Specification') + self.assertEqual(jp2k.box[2].box[1].precedence, 0) + self.assertEqual(jp2k.box[2].box[1].approximation, 0) + self.assertEqual(jp2k.box[2].box[1].colorspace, glymur.core.SRGB) + self.assertIsNone(jp2k.box[2].box[1].icc_profile) + + def test_j2k_box(self): + """A J2K/J2C file must not have any boxes.""" + # Verify that a J2K file has no boxes. + jp2k = Jp2k(self.j2kfile) + self.assertEqual(len(jp2k.box), 0) + + @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") + def test_64bit_xl_field(self): + """XL field should be supported""" + # Verify that boxes with the XL field are properly read. + # Don't have such a file on hand, so we create one. Copy our example + # file, but making the codestream have a 64-bit XL field. + with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: + with open(self.jp2file, 'rb') as ifile: + # Everything up until the jp2c box. + write_buffer = ifile.read(3127) + tfile.write(write_buffer) + + # The L field must be 1 in order to signal the presence of the + # XL field. The actual length of the jp2c box increased by 8 + # (8 bytes for the XL field). + length = 1 + typ = b'jp2c' + xlen = 1133427 + 8 + write_buffer = struct.pack('>I4sQ', int(length), typ, xlen) + tfile.write(write_buffer) + + # Get the rest of the input file (minus the 8 bytes for L and + # T. + ifile.seek(8, 1) + write_buffer = ifile.read() + tfile.write(write_buffer) + tfile.flush() + + jp2k = Jp2k(tfile.name) + + self.assertEqual(jp2k.box[5].box_id, 'jp2c') + self.assertEqual(jp2k.box[5].offset, 3127) + self.assertEqual(jp2k.box[5].length, 1133427 + 8) + + @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") + def test_length_field_is_zero(self): + """L=0 (length field in box header) is allowed""" + # Verify that boxes with the L field as zero are correctly read. + # This should only happen in the last box of a JPEG 2000 file. + # Our example image has its last box at byte 588458. + baseline_jp2 = Jp2k(self.jp2file) + with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: + with open(self.jp2file, 'rb') as ifile: + # Everything up until the jp2c box. + write_buffer = ifile.read(588458) + tfile.write(write_buffer) + + length = 0 + typ = b'uuid' + write_buffer = struct.pack('>I4s', int(length), typ) + tfile.write(write_buffer) + + # Get the rest of the input file (minus the 8 bytes for L and + # T. + ifile.seek(8, 1) + write_buffer = ifile.read() + tfile.write(write_buffer) + tfile.flush() + + new_jp2 = Jp2k(tfile.name) + + # The top level boxes in each file should match. + for j in range(len(baseline_jp2.box)): + self.assertEqual(new_jp2.box[j].box_id, + baseline_jp2.box[j].box_id) + self.assertEqual(new_jp2.box[j].offset, + baseline_jp2.box[j].offset) + self.assertEqual(new_jp2.box[j].length, + baseline_jp2.box[j].length) + def test_basic_jp2(self): """Just a very basic test that reading a JP2 file does not error out. """ j2k = Jp2k(self.jp2file) j2k.read(rlevel=1) - def test_basic_j2k(self): - """Just a very basic test that reading a J2K file does not error out. - """ - j2k = Jp2k(self.j2kfile) - j2k.read() - - @unittest.skipIf(OPJ_DATA_ROOT is None, - "OPJ_DATA_ROOT environment variable not set") - def test_read_differing_subsamples(self): - """should error out with read used on differently subsampled images""" - # Verify that we error out appropriately if we use the read method - # on an image with differing subsamples - # - # Issue 86. - filename = opj_data_file('input/conformance/p0_05.j2k') - j = Jp2k(filename) - with self.assertRaises(RuntimeError): - j.read() - - def test_empty_box_with_j2k(self): - """Verify that the list of boxes in a J2C/J2K file is present, but - empty. - """ - j = Jp2k(self.j2kfile) - self.assertEqual(j.box, []) - - @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") - def test_cblkh_different_than_width(self): - """Verify that we can set a code block size where height does not equal - width. - """ - data = np.zeros((128, 128), dtype=np.uint8) - with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile: - j = Jp2k(tfile.name, 'wb') - - # The code block dimensions are given as rows x columns. - j.write(data, cbsize=(16, 32)) - - codestream = j.get_codestream() - - # Code block size is reported as XY in the codestream. - self.assertEqual(tuple(codestream.segment[2].spcod[5:7]), (3, 2)) - - @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") - def test_too_many_dimensions(self): - """OpenJP2 only allows 2D or 3D images.""" - with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile: - j = Jp2k(tfile.name, 'wb') - with self.assertRaises(IOError): - data = np.zeros((128, 128, 2, 2), dtype=np.uint8) - j.write(data) - - @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") - def test_unrecognized_jp2_clrspace(self): - """We only allow RGB and GRAYSCALE. Should error out with others""" - with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: - j = Jp2k(tfile.name, 'wb') - with self.assertRaises(IOError): - data = np.zeros((128, 128, 3), dtype=np.uint8) - j.write(data, colorspace='cmyk') - - @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") - def test_2d_rgb(self): - """RGB must have at least 3 components.""" - with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: - j = Jp2k(tfile.name, 'wb') - with self.assertRaises(IOError): - data = np.zeros((128, 128, 2), dtype=np.uint8) - j.write(data, colorspace='rgb') - - @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") - def test_colorspace_with_j2k(self): - """Specifying a colorspace with J2K does not make sense""" - with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile: - j = Jp2k(tfile.name, 'wb') - with self.assertRaises(IOError): - data = np.zeros((128, 128, 3), dtype=np.uint8) - j.write(data, colorspace='rgb') - - @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") - def test_specify_rgb(self): - """specify RGB explicitly""" - with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: - j = Jp2k(tfile.name, 'wb') - data = np.zeros((128, 128, 3), dtype=np.uint8) - j.write(data, colorspace='rgb') - self.assertEqual(j.box[2].box[1].colorspace, glymur.core.SRGB) - - @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") - def test_specify_gray(self): - """test gray explicitly specified (that's GRAY, not GREY)""" - with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: - j = Jp2k(tfile.name, 'wb') - data = np.zeros((128, 128), dtype=np.uint8) - j.write(data, colorspace='gray') - self.assertEqual(j.box[2].box[1].colorspace, - glymur.core.GREYSCALE) - - @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") - def test_specify_grey(self): - """test grey explicitly specified""" - with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: - j = Jp2k(tfile.name, 'wb') - data = np.zeros((128, 128), dtype=np.uint8) - j.write(data, colorspace='grey') - self.assertEqual(j.box[2].box[1].colorspace, - glymur.core.GREYSCALE) - - @unittest.skipIf(OPENJP2_IS_V2_OFFICIAL, - "Does not seem to work on official v2.0.0 release.") - @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") - def test_grey_with_extra_component(self): - """version 2.0 cannot write gray + extra""" - with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: - j = Jp2k(tfile.name, 'wb') - data = np.zeros((128, 128, 2), dtype=np.uint8) - j.write(data) - self.assertEqual(j.box[2].box[0].height, 128) - self.assertEqual(j.box[2].box[0].width, 128) - self.assertEqual(j.box[2].box[0].num_components, 2) - self.assertEqual(j.box[2].box[1].colorspace, - glymur.core.GREYSCALE) - - @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") - def test_grey_with_two_extra_comps(self): - """should be able to write gray + two extra components""" - with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: - j = Jp2k(tfile.name, 'wb') - data = np.zeros((128, 128, 3), dtype=np.uint8) - j.write(data, colorspace='gray') - self.assertEqual(j.box[2].box[0].height, 128) - self.assertEqual(j.box[2].box[0].width, 128) - self.assertEqual(j.box[2].box[0].num_components, 3) - self.assertEqual(j.box[2].box[1].colorspace, - glymur.core.GREYSCALE) - - @unittest.skipIf(OPENJP2_IS_V2_OFFICIAL, - "Does not seem to work on official v2.0.0 release.") - @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") - def test_rgb_with_extra_component(self): - """v2.0+ should be able to write extra components""" - with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: - j = Jp2k(tfile.name, 'wb') - data = np.zeros((128, 128, 4), dtype=np.uint8) - j.write(data) - self.assertEqual(j.box[2].box[0].height, 128) - self.assertEqual(j.box[2].box[0].width, 128) - self.assertEqual(j.box[2].box[0].num_components, 4) - self.assertEqual(j.box[2].box[1].colorspace, glymur.core.SRGB) - - @unittest.skipIf(OPENJP2_IS_V2_OFFICIAL is False, - "Test is specific for v2.0.0 release") - @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") - def test_extra_components_on_v2(self): - """must error out in 1.x with extra components.""" - # Extra components seems to require 2.0+. Verify that we error out. - with self.assertRaises(IOError): - with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: - j = Jp2k(tfile.name, 'wb') - data = np.zeros((128, 128, 4), dtype=np.uint8) - j.write(data) - - def test_specify_ycc(self): - """Should reject YCC""" - with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: - j = Jp2k(tfile.name, 'wb') - with self.assertRaises(IOError): - data = np.zeros((128, 128, 3), dtype=np.uint8) - j.write(data, colorspace='ycc') - - @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") - def test_uinf_ulst_url_boxes(self): - """Verify that we can read UINF, ULST, and URL boxes""" - # Verify that we can read UINF, ULST, and URL boxes. I don't have - # easy access to such a file, and there's no such file in the - # openjpeg repository, so I'll fake one. - with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: - with open(self.jp2file, 'rb') as ifile: - # Everything up until the jp2c box. - write_buffer = ifile.read(77) - tfile.write(write_buffer) - - # Write the UINF superbox - # Length = 50, id is uinf. - write_buffer = struct.pack('>I4s', int(50), b'uinf') - tfile.write(write_buffer) - - # Write the ULST box. - # Length is 26, 1 UUID, hard code that UUID as zeros. - write_buffer = struct.pack('>I4sHIIII', int(26), b'ulst', - int(1), int(0), int(0), int(0), - int(0)) - tfile.write(write_buffer) - - # Write the URL box. - # Length is 16, version is one byte, flag is 3 bytes, url - # is the rest. - write_buffer = struct.pack('>I4sBBBB', - int(16), b'url ', - int(0), int(0), int(0), int(0)) - tfile.write(write_buffer) - write_buffer = struct.pack('>ssss', b'a', b'b', b'c', b'd') - tfile.write(write_buffer) - - # Get the rest of the input file. - write_buffer = ifile.read() - tfile.write(write_buffer) - tfile.flush() - - jp2k = Jp2k(tfile.name) - - self.assertEqual(jp2k.box[3].box_id, 'uinf') - self.assertEqual(jp2k.box[3].offset, 77) - self.assertEqual(jp2k.box[3].length, 50) - - self.assertEqual(jp2k.box[3].box[0].box_id, 'ulst') - self.assertEqual(jp2k.box[3].box[0].offset, 85) - self.assertEqual(jp2k.box[3].box[0].length, 26) - ulst = [] - ulst.append(uuid.UUID('00000000-0000-0000-0000-000000000000')) - self.assertEqual(jp2k.box[3].box[0].ulst, ulst) - - self.assertEqual(jp2k.box[3].box[1].box_id, 'url ') - self.assertEqual(jp2k.box[3].box[1].offset, 111) - self.assertEqual(jp2k.box[3].box[1].length, 16) - self.assertEqual(jp2k.box[3].box[1].version, 0) - self.assertEqual(jp2k.box[3].box[1].flag, (0, 0, 0)) - self.assertEqual(jp2k.box[3].box[1].url, 'abcd') - - @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") - def test_xml_with_trailing_nulls(self): - """ElementTree doesn't like trailing null chars after valid XML text""" - with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: - with open(self.jp2file, 'rb') as ifile: - # Everything up until the jp2c box. - write_buffer = ifile.read(77) - tfile.write(write_buffer) - - # Write the xml box - # Length = 36, id is 'xml '. - write_buffer = struct.pack('>I4s', int(36), b'xml ') - tfile.write(write_buffer) - - write_buffer = 'this is a test' + chr(0) - write_buffer = write_buffer.encode() - tfile.write(write_buffer) - - # Get the rest of the input file. - write_buffer = ifile.read() - tfile.write(write_buffer) - tfile.flush() - - jp2k = Jp2k(tfile.name) - - self.assertEqual(jp2k.box[3].box_id, 'xml ') - self.assertEqual(jp2k.box[3].offset, 77) - self.assertEqual(jp2k.box[3].length, 36) - self.assertEqual(ET.tostring(jp2k.box[3].xml.getroot()), - b'this is a test') - - @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") - def test_asoc_label_box(self): - """Test asoc and label box""" - # Construct a fake file with an asoc and a label box, as - # OpenJPEG doesn't have such a file. - data = Jp2k(self.jp2file).read(rlevel=1) - with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: - j = Jp2k(tfile.name, 'wb') - j.write(data) - - with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile2: - - # Offset of the codestream is where we start. - read_buffer = tfile.read(77) - tfile2.write(read_buffer) - - # read the rest of the file, it's the codestream. - codestream = tfile.read() - - # Write the asoc superbox. - # Length = 36, id is 'asoc'. - write_buffer = struct.pack('>I4s', int(56), b'asoc') - tfile2.write(write_buffer) - - # Write the contained label box - write_buffer = struct.pack('>I4s', int(13), b'lbl ') - tfile2.write(write_buffer) - tfile2.write('label'.encode()) - - # Write the xml box - # Length = 36, id is 'xml '. - write_buffer = struct.pack('>I4s', int(35), b'xml ') - tfile2.write(write_buffer) - - write_buffer = 'this is a test' - write_buffer = write_buffer.encode() - tfile2.write(write_buffer) - - # Now append the codestream. - tfile2.write(codestream) - tfile2.flush() - - jasoc = Jp2k(tfile2.name) - self.assertEqual(jasoc.box[3].box_id, 'asoc') - self.assertEqual(jasoc.box[3].box[0].box_id, 'lbl ') - self.assertEqual(jasoc.box[3].box[0].label, 'label') - self.assertEqual(jasoc.box[3].box[1].box_id, 'xml ') - - @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") - @unittest.skipIf(OPENJP2_IS_V2_OFFICIAL, - "Segfault on official v2.0.0 release.") - def test_openjpeg_library_message(self): - """Verify the error message produced by the openjpeg library""" - # This will confirm that the error callback mechanism is working. - with open(self.jp2file, 'rb') as fptr: - data = fptr.read() - with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: - # Codestream starts at byte 3127. SIZ marker at 3137. - # COD marker at 3186. Subsampling at 3180. - tfile.write(data[0:3179]) - - # Make the DY bytes of the SIZ segment zero. That means that - # a subsampling factor is zero, which is illegal. - tfile.write(b'\x00') - tfile.write(data[3180:3182]) - tfile.write(b'\x00') - tfile.write(data[3184:3186]) - tfile.write(b'\x00') - - tfile.write(data[3186:]) - tfile.flush() - with warnings.catch_warnings(): - warnings.simplefilter("ignore") - j = Jp2k(tfile.name) - regexp = re.compile(r'''OpenJPEG\slibrary\serror:\s+ - Invalid\svalues\sfor\scomp\s=\s0\s+ - :\sdx=1\sdy=0''', re.VERBOSE) - if sys.hexversion < 0x03020000: - with self.assertRaisesRegexp((IOError, OSError), regexp): - j.read(rlevel=1) - else: - with self.assertRaisesRegex((IOError, OSError), regexp): - j.read(rlevel=1) - - def test_xmp_attribute(self): - """Verify the XMP packet in the shipping example file can be read.""" - j = Jp2k(self.jp2file) - xmp = j.box[4].data - ns0 = '{http://www.w3.org/1999/02/22-rdf-syntax-ns#}' - ns1 = '{http://ns.adobe.com/xap/1.0/}' - name = '{0}RDF/{0}Description'.format(ns0) - elt = xmp.find(name) - attr_value = elt.attrib['{0}CreatorTool'.format(ns1)] - self.assertEqual(attr_value, 'glymur') - - @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") - def test_unrecognized_exif_tag(self): - """An unrecognized exif tag should be handled gracefully.""" - with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: - shutil.copyfile(self.jp2file, tfile.name) - - # The Exif UUID starts at byte 77. There are 8 bytes for the L and - # T fields, then 16 bytes for the UUID identifier, then 6 exif - # header bytes, then 8 bytes for the TIFF header, then 2 bytes - # the the Image IFD number of tags, where we finally find the first - # tag, "Make" (271). We'll corrupt it by changing it into 171, - # which does not correspond to any known Exif Image tag. - with open(tfile.name, 'r+b') as fptr: - fptr.seek(117) - write_buffer = struct.pack('I4sQ', int(length), typ, xlen) - tfile.write(write_buffer) - - # Get the rest of the input file (minus the 8 bytes for L and - # T. - ifile.seek(8, 1) - write_buffer = ifile.read() - tfile.write(write_buffer) - tfile.flush() - - jp2k = Jp2k(tfile.name) - - self.assertEqual(jp2k.box[5].box_id, 'jp2c') - self.assertEqual(jp2k.box[5].offset, 3127) - self.assertEqual(jp2k.box[5].length, 1133427 + 8) - - @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") - def test_length_field_is_zero(self): - """L=0 (length field in box header) is allowed""" - # Verify that boxes with the L field as zero are correctly read. - # This should only happen in the last box of a JPEG 2000 file. - # Our example image has its last box at byte 588458. - baseline_jp2 = Jp2k(self.jp2file) - with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: - with open(self.jp2file, 'rb') as ifile: - # Everything up until the jp2c box. - write_buffer = ifile.read(588458) - tfile.write(write_buffer) - - length = 0 - typ = b'uuid' - write_buffer = struct.pack('>I4s', int(length), typ) - tfile.write(write_buffer) - - # Get the rest of the input file (minus the 8 bytes for L and - # T. - ifile.seek(8, 1) - write_buffer = ifile.read() - tfile.write(write_buffer) - tfile.flush() - - new_jp2 = Jp2k(tfile.name) - - # The top level boxes in each file should match. - for j in range(len(baseline_jp2.box)): - self.assertEqual(new_jp2.box[j].box_id, - baseline_jp2.box[j].box_id) - self.assertEqual(new_jp2.box[j].offset, - baseline_jp2.box[j].offset) - self.assertEqual(new_jp2.box[j].length, - baseline_jp2.box[j].length) - - def test_basic_jp2(self): - """This test is only useful when openjp2 is not available - and OPJ_DATA_ROOT is not set. We need at least one - working JP2 test. - """ - j2k = Jp2k(self.jp2file) - j2k.read(rlevel=1) - def test_basic_j2k(self): """This test is only useful when openjp2 is not available and OPJ_DATA_ROOT is not set. We need at least one @@ -1051,154 +966,6 @@ class TestJp2k15(unittest.TestCase): j = Jp2k(self.j2kfile) self.assertEqual(j.box, []) - @unittest.skip("Writing requires openjp2 library at the moment.") - @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") - def test_cblkh_different_than_width(self): - """Verify that we can set a code block size where height does not equal - width. - """ - data = np.zeros((128, 128), dtype=np.uint8) - with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile: - j = Jp2k(tfile.name, 'wb') - - # The code block dimensions are given as rows x columns. - j.write(data, cbsize=(16, 32)) - - codestream = j.get_codestream() - - # Code block size is reported as XY in the codestream. - self.assertEqual(tuple(codestream.segment[2].spcod[5:7]), (3, 2)) - - @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") - def test_too_many_dimensions(self): - """OpenJP2 only allows 2D or 3D images.""" - with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile: - j = Jp2k(tfile.name, 'wb') - with self.assertRaises(IOError): - data = np.zeros((128, 128, 2, 2), dtype=np.uint8) - j.write(data) - - @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") - def test_unrecognized_jp2_clrspace(self): - """We only allow RGB and GRAYSCALE. Should error out with others""" - with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: - j = Jp2k(tfile.name, 'wb') - with self.assertRaises(IOError): - data = np.zeros((128, 128, 3), dtype=np.uint8) - j.write(data, colorspace='cmyk') - - @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") - def test_2d_rgb(self): - """RGB must have at least 3 components.""" - with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: - j = Jp2k(tfile.name, 'wb') - with self.assertRaises(IOError): - data = np.zeros((128, 128, 2), dtype=np.uint8) - j.write(data, colorspace='rgb') - - @unittest.skip("Writing requires openjp2 library at the moment.") - @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") - def test_colorspace_with_j2k(self): - """Specifying a colorspace with J2K does not make sense""" - with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile: - j = Jp2k(tfile.name, 'wb') - with self.assertRaises(IOError): - data = np.zeros((128, 128, 3), dtype=np.uint8) - j.write(data, colorspace='rgb') - - @unittest.skip("Writing requires openjp2 library at the moment.") - @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") - def test_specify_rgb(self): - """specify RGB explicitly""" - with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: - j = Jp2k(tfile.name, 'wb') - data = np.zeros((128, 128, 3), dtype=np.uint8) - j.write(data, colorspace='rgb') - self.assertEqual(j.box[2].box[1].colorspace, glymur.core.SRGB) - - @unittest.skip("Writing requires openjp2 library at the moment.") - @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") - def test_specify_gray(self): - """test gray explicitly specified (that's GRAY, not GREY)""" - with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: - j = Jp2k(tfile.name, 'wb') - data = np.zeros((128, 128), dtype=np.uint8) - j.write(data, colorspace='gray') - self.assertEqual(j.box[2].box[1].colorspace, - glymur.core.GREYSCALE) - - @unittest.skip("Writing requires openjp2 library at the moment.") - @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") - def test_specify_grey(self): - """test grey explicitly specified""" - with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: - j = Jp2k(tfile.name, 'wb') - data = np.zeros((128, 128), dtype=np.uint8) - j.write(data, colorspace='grey') - self.assertEqual(j.box[2].box[1].colorspace, - glymur.core.GREYSCALE) - - @unittest.skip("Writing requires openjp2 library at the moment.") - @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") - def test_grey_with_extra_component(self): - """version 2.0 cannot write gray + extra""" - with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: - j = Jp2k(tfile.name, 'wb') - data = np.zeros((128, 128, 2), dtype=np.uint8) - j.write(data) - self.assertEqual(j.box[2].box[0].height, 128) - self.assertEqual(j.box[2].box[0].width, 128) - self.assertEqual(j.box[2].box[0].num_components, 2) - self.assertEqual(j.box[2].box[1].colorspace, - glymur.core.GREYSCALE) - - @unittest.skip("Writing requires openjp2 library at the moment.") - @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") - def test_grey_with_two_extra_comps(self): - """should be able to write gray + two extra components""" - with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: - j = Jp2k(tfile.name, 'wb') - data = np.zeros((128, 128, 3), dtype=np.uint8) - j.write(data, colorspace='gray') - self.assertEqual(j.box[2].box[0].height, 128) - self.assertEqual(j.box[2].box[0].width, 128) - self.assertEqual(j.box[2].box[0].num_components, 3) - self.assertEqual(j.box[2].box[1].colorspace, - glymur.core.GREYSCALE) - - @unittest.skip("Writing requires openjp2 library at the moment.") - @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") - def test_rgb_with_extra_component(self): - """v2.0+ should be able to write extra components""" - with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: - j = Jp2k(tfile.name, 'wb') - data = np.zeros((128, 128, 4), dtype=np.uint8) - j.write(data) - self.assertEqual(j.box[2].box[0].height, 128) - self.assertEqual(j.box[2].box[0].width, 128) - self.assertEqual(j.box[2].box[0].num_components, 4) - self.assertEqual(j.box[2].box[1].colorspace, glymur.core.SRGB) - - @unittest.skip("Writing requires openjp2 library at the moment.") - @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") - def test_extra_components_on_v2(self): - """must error out in 1.x with extra components.""" - # Extra components seems to require 2.0+. Verify that we error out. - with self.assertRaises(IOError): - with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: - j = Jp2k(tfile.name, 'wb') - data = np.zeros((128, 128, 4), dtype=np.uint8) - j.write(data) - - @unittest.skip("Writing requires openjp2 library at the moment.") - def test_specify_ycc(self): - """Should reject YCC""" - with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: - j = Jp2k(tfile.name, 'wb') - with self.assertRaises(IOError): - data = np.zeros((128, 128, 3), dtype=np.uint8) - j.write(data, colorspace='ycc') - @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") def test_uinf_ulst_url_boxes(self): """Verify that we can read UINF, ULST, and URL boxes""" @@ -1289,92 +1056,6 @@ class TestJp2k15(unittest.TestCase): self.assertEqual(ET.tostring(jp2k.box[3].xml.getroot()), b'this is a test') - @unittest.skip("Writing requires openjp2 library at the moment.") - @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") - def test_asoc_label_box(self): - """Test asoc and label box""" - # Construct a fake file with an asoc and a label box, as - # OpenJPEG doesn't have such a file. - data = Jp2k(self.jp2file).read(rlevel=1) - with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: - j = Jp2k(tfile.name, 'wb') - j.write(data) - - with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile2: - - # Offset of the codestream is where we start. - read_buffer = tfile.read(77) - tfile2.write(read_buffer) - - # read the rest of the file, it's the codestream. - codestream = tfile.read() - - # Write the asoc superbox. - # Length = 36, id is 'asoc'. - write_buffer = struct.pack('>I4s', int(56), b'asoc') - tfile2.write(write_buffer) - - # Write the contained label box - write_buffer = struct.pack('>I4s', int(13), b'lbl ') - tfile2.write(write_buffer) - tfile2.write('label'.encode()) - - # Write the xml box - # Length = 36, id is 'xml '. - write_buffer = struct.pack('>I4s', int(35), b'xml ') - tfile2.write(write_buffer) - - write_buffer = 'this is a test' - write_buffer = write_buffer.encode() - tfile2.write(write_buffer) - - # Now append the codestream. - tfile2.write(codestream) - tfile2.flush() - - jasoc = Jp2k(tfile2.name) - self.assertEqual(jasoc.box[3].box_id, 'asoc') - self.assertEqual(jasoc.box[3].box[0].box_id, 'lbl ') - self.assertEqual(jasoc.box[3].box[0].label, 'label') - self.assertEqual(jasoc.box[3].box[1].box_id, 'xml ') - - @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") - @unittest.skipIf(re.match(r"""1\.[345]\.\d""", - OPENJPEG_VERSION) is not None, - "Segfault on official v1.x series.") - def test_openjpeg_library_message(self): - """Verify the error message produced by the openjpeg library""" - # This will confirm that the error callback mechanism is working. - with open(self.jp2file, 'rb') as fptr: - data = fptr.read() - with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: - # Codestream starts at byte 3127. SIZ marker at 3137. - # COD marker at 3186. Subsampling at 3180. - tfile.write(data[0:3179]) - - # Make the DY bytes of the SIZ segment zero. That means that - # a subsampling factor is zero, which is illegal. - tfile.write(b'\x00') - tfile.write(data[3180:3182]) - tfile.write(b'\x00') - tfile.write(data[3184:3186]) - tfile.write(b'\x00') - - tfile.write(data[3186:]) - tfile.flush() - with warnings.catch_warnings(): - warnings.simplefilter("ignore") - j = Jp2k(tfile.name) - regexp = re.compile(r'''OpenJPEG\slibrary\serror:\s+ - Invalid\svalues\sfor\scomp\s=\s0\s+ - :\sdx=1\sdy=0''', re.VERBOSE) - if sys.hexversion < 0x03020000: - with self.assertRaisesRegexp((IOError, OSError), regexp): - j.read(rlevel=1) - else: - with self.assertRaisesRegex((IOError, OSError), regexp): - j.read(rlevel=1) - def test_xmp_attribute(self): """Verify the XMP packet in the shipping example file can be read.""" j = Jp2k(self.jp2file) From ed1ca36040a14d37eb80a0e4d30a57561c933b85 Mon Sep 17 00:00:00 2001 From: jevans Date: Mon, 9 Sep 2013 21:09:33 -0400 Subject: [PATCH 07/22] Added preliminary 1.5.1 write routine. --- glymur/jp2k.py | 213 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 207 insertions(+), 6 deletions(-) diff --git a/glymur/jp2k.py b/glymur/jp2k.py index bd90dfe..154db4f 100644 --- a/glymur/jp2k.py +++ b/glymur/jp2k.py @@ -280,9 +280,6 @@ class Jp2k(Jp2kBox): Corresponds to cparameters_t type in openjp2 headers. colorspace : int Either CLRSPC_SRGB or CLRSPC_GRAY - mct : bool, optional - Specifies usage of the multi component transform. If not - specified, defaults to True if the colorspace is RGB. """ if 'cratios' in kwargs and 'psnr' in kwargs: @@ -380,11 +377,215 @@ class Jp2k(Jp2kBox): glymur.LibraryNotFoundError If glymur is unable to load the openjp2 library. """ - if opj2.OPENJP2 is None: - raise LibraryNotFoundError("You must have the openjp2 library " - "installed before using this " + if opj2.OPENJP2 is not None: + img = self._write_openjp2(img_array, verbose=verbose, **kwargs) + elif opj.OPENJPEG is not None: + img = self._write_openjpeg(img_array, verbose=verbose, **kwargs) + else: + raise LibraryNotFoundError("You must have version 1.5 of OpenJPEG " + "or more recent before using this " "functionality.") + def _write_openjpeg(self, img_array, verbose=False, **kwargs): + """ + """ + if codeblock is not None: + if (np.prod(codeblock) > 4096) or (np.any(np.array(codeblock) < 4)) or (np.any(np.array(codeblock) > 1024)): + msg = 'Size of code block error. ' + msg += 'Restriction: width*height <= 4096, ' + msg += '4 <= width, height <= 1024' + raise(RuntimeError(msg)) + + if cratio is not None and len(cratio) >= opj.MAX_NUM_LAYERS: + msg = 'Maximum number of layers is %d.' % opj.MAX_NUM_LAYERS + raise(RuntimeError(msg)) + + if psnr is not None and len(psnr) >= opj.MAX_NUM_LAYERS: + msg = 'Maximum number of layers is %d.' % opj.MAX_NUM_LAYERS + raise(RuntimeError(msg)) + + if cratio is not None and psnr is not None: + msg = 'Psnr and cratio parameters cannot be specified together.' + raise(RuntimeError(msg)) + + + cparams = opj.cparameters_t() + + opj.set_default_encoder_parameters(ctypes.byref(cparams)) + + # Set default to lossless until we know otherwise. + cparams.tcp_rates[0] = 0 + cparams.tcp_numlayers = 1 + cparams.cp_disto_alloc = 1 + + outfile = self.jp2k_file + nelts = opj.OPJ_PATH_LEN - len(outfile) + outfile += b'0'*nelts + cparams.outfile = outfile + + numrows = data.shape[0] + numcols = data.shape[1] + numlayers = data.shape[2] + + if codeblock is not None: + cparams.cblockw_init = codeblock[0] + cparams.cblockh_init = codeblock[1] + + if comment is None: + comment = 'Created by OpenJPEG version %s' % opj.version() + cparams.cp_comment = ctypes.c_char_p(comment) + + + if cratio is not None: + cparams.tcp_numlayers = len(cratio) + for j in range(0,len(cratio)): + cparams.tcp_rates[j] = cratio[j] + cparams.cp_disto_alloc = 1 + + if eph: + cparams.csty = cparams.csty | 0x04 + + if modeswitch is not None: + cparams.mode = modeswitch + + if numres is not None: + cparams.numresolution = numres + + if origin is not None: + cparams.image_offset_x0 = origin[0] + cparams.image_offset_y0 = origin[1] + + if progorder is not None: + cparams.prog_order = opj.progression_order[progorder] + + if precinct is not None: + cparams.csty = cparams.csty | 0x01 + cparams.res_spec = len(precinct) + for j in range(0,len(precinct)): + cparams.prcw_init[j] = precinct[j][0] + cparams.prch_init[j] = precinct[j][1] + + if psnr is not None: + cparams.tcp_numlayers = len(psnr) + for j in range(0,len(psnr)): + cparams.tcp_distoratio[j] = psnr[j] + cparams.cp_fixed_quality = 1 + + if sop: + cparams.csty = cparams.csty | 0x02 + + if tile is not None: + cparams.tile_size_on = 1 + cparams.cp_tdx = tile[0] + cparams.cp_tdy = tile[1] + + # comment = what? + cmptparms = opj.image_cmptparm_t_from_np(data) + image = opj.image_create(cmptparms) + + # set image offset and reference grid + image.contents.x0 = cparams.image_offset_x0 + image.contents.y0 = cparams.image_offset_y0 + image.contents.x1 = image.contents.x0 + (numcols - 1) * cparams.subsampling_dx + 1 + image.contents.y1 = image.contents.y0 + (numrows - 1) * cparams.subsampling_dy + 1 + + # Stage the image data to the openjpeg data structure. + for k in range(0,numlayers): + layer = np.ascontiguousarray(data[:,:,k], dtype=np.int32) + dest = image.contents.comps[k].data + src = layer.ctypes.data + ctypes.memmove(dest, src, layer.nbytes) + + # set multi-component transform? + if image.contents.numcomps == 3: + cparams.tcp_mct = chr(1) + else: + cparams.tcp_mct = chr(0) + + # set encode format + #cinfo = opj.create_compress(opj.codec_format[self.file_format]) + cinfo = opj.create_compress(self.file_format) + + event_mgr = opj.event_mgr_t(None, None, None) + opj.set_event_mgr(cparams, ctypes.byref(event_mgr), None) + + opj.setup_encoder(cinfo, ctypes.byref(cparams), image) + + # open a byte stream for writing + # allocate memory for all tiles + cio = opj.cio_open(cinfo) + + opj.encode(cinfo, cio, image) + pos = opj.cio_tell(cio) + + ss = ctypes.string_at(cio.contents.buffer, pos) + f = open(self.jp2k_file,'wb') + f.write(ss) + f.close() + opj.cio_close(cio); + + opj.destroy_compress(cinfo); + opj.image_destroy(image); + + self.parse() + + + def _write_openjp2(self, img_array, verbose=False, **kwargs): + """Write image data to a JP2/JPX/J2k file. Intended usage of the + various parameters follows that of OpenJPEG's opj_compress utility. + + This method can only be used to create JPEG 2000 images that can fit + in memory. + + Parameters + ---------- + img_array : ndarray + Image data to be written to file. + cbsize : tuple, optional + Code block size (DY, DX). + colorspace : str, optional + Either 'rgb' or 'gray'. + cratios : iterable + Compression ratios for successive layers. + eph : bool, optional + If true, write SOP marker after each header packet. + grid_offset : tuple, optional + Offset (DY, DX) of the origin of the image in the reference grid. + mct : bool, optional + Specifies usage of the multi component transform. If not + specified, defaults to True if the colorspace is RGB. + modesw : int, optional + Mode switch. + 1 = BYPASS(LAZY) + 2 = RESET + 4 = RESTART(TERMALL) + 8 = VSC + 16 = ERTERM(SEGTERM) + 32 = SEGMARK(SEGSYM) + numres : int, optional + Number of resolutions. + prog : str, optional + Progression order, one of "LRCP" "RLCP", "RPCL", "PCRL", "CPRL". + psnr : iterable, optional + Different PSNR for successive layers. + psizes : list, optional + List of precinct sizes. Each precinct size tuple is defined in + (height x width). + sop : bool, optional + If true, write SOP marker before each packet. + subsam : tuple, optional + Subsampling factors (dy, dx). + tilesize : tuple, optional + Numeric tuple specifying tile size in terms of (numrows, numcols), + not (X, Y). + verbose : bool, optional + Print informational messages produced by the OpenJPEG library. + + Raises + ------ + glymur.LibraryNotFoundError + If glymur is unable to load the openjp2 library. + """ cparams, colorspace = self._process_write_inputs(img_array, **kwargs) if img_array.ndim == 2: From d070cc414464ad6ff1c0894e3a936f5afec49b13 Mon Sep 17 00:00:00 2001 From: jevans Date: Tue, 10 Sep 2013 20:11:32 -0400 Subject: [PATCH 08/22] Filled in more of openjpeg write definitions. #111 --- glymur/jp2k.py | 4 +- glymur/lib/openjpeg.py | 426 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 419 insertions(+), 11 deletions(-) diff --git a/glymur/jp2k.py b/glymur/jp2k.py index 154db4f..bb2fe43 100644 --- a/glymur/jp2k.py +++ b/glymur/jp2k.py @@ -409,7 +409,7 @@ class Jp2k(Jp2kBox): raise(RuntimeError(msg)) - cparams = opj.cparameters_t() + cparams = opj.CompressionParametersType() opj.set_default_encoder_parameters(ctypes.byref(cparams)) @@ -506,7 +506,7 @@ class Jp2k(Jp2kBox): #cinfo = opj.create_compress(opj.codec_format[self.file_format]) cinfo = opj.create_compress(self.file_format) - event_mgr = opj.event_mgr_t(None, None, None) + event_mgr = opj.EventMgrType(None, None, None) opj.set_event_mgr(cparams, ctypes.byref(event_mgr), None) opj.setup_encoder(cinfo, ctypes.byref(cparams), image) diff --git a/glymur/lib/openjpeg.py b/glymur/lib/openjpeg.py index 704cf9c..6e7b858 100644 --- a/glymur/lib/openjpeg.py +++ b/glymur/lib/openjpeg.py @@ -6,10 +6,16 @@ import ctypes import sys +import numpy as np + from .config import glymur_config _, OPENJPEG = glymur_config() -PATH_LEN = 4096 # maximum allowed size for filenames +# Maximum number of tile parts expected by JPWL: increase at your will +JPWL_MAX_NO_TILESPECS = 16 + +J2K_MAXRLVLS = 33 # Number of maximum resolution level authorized +PATH_LEN = 4096 # maximum allowed size for filenames def version(): @@ -52,14 +58,8 @@ class CommonStructType(ctypes.Structure): ("mj2_handle", ctypes.c_void_p)] -class DecompressionInfoType(ctypes.Structure): - """This is for decompression contexts. - - Corresponds to dinfo_t type in openjpeg headers. - """ - pass - - +STREAM_READ = 0x0001 # The stream was opened for reading. +STREAM_WRITE = 0x0002 # The stream was opened for writing. class CioType(ctypes.Structure): """Byte input-output stream (CIO) @@ -80,6 +80,266 @@ class CioType(ctypes.Structure): ("bp", ctypes.c_char_p)] +class CompressionInfoType(CommonStructType): + """Common fields between JPEG-2000 compression and decompression contexts. + This is for compression contexts. Corresponds to common_struct_t. + """ + pass + + +class PocType(ctypes.Structure): + """Progression order changes.""" + _fields_ = [("resno", ctypes.c_int), + # Resolution num start, Component num start, given by POC + ("compno0", ctypes.c_int), + + # Layer num end,Resolution num end, Component num end, given by POC + ("layno1", ctypes.c_int), + ("resno1", ctypes.c_int), + ("compno1", ctypes.c_int), + + # Layer num start,Precinct num start, Precinct num end + ("layno0", ctypes.c_int), + ("precno0", ctypes.c_int), + ("precno1", ctypes.c_int), + + # Progression order enum + # OPJ_PROG_ORDER prg1,prg; + ("prg1", ctypes.c_int), + ("prg", ctypes.c_int), + + # Progression order string + # char progorder[5]; + ("progorder", ctypes.c_char * 5), + + # Tile number + # int tile; + ("tile", ctypes.c_int), + + # /** Start and end values for Tile width and height*/ + # int tx0,tx1,ty0,ty1; + ("tx0", ctypes.c_int), + ("tx1", ctypes.c_int), + ("ty0", ctypes.c_int), + ("ty1", ctypes.c_int), + + # /** Start value, initialised in pi_initialise_encode*/ + # int layS, resS, compS, prcS; + ("layS", ctypes.c_int), + ("resS", ctypes.c_int), + ("compS", ctypes.c_int), + ("prcS", ctypes.c_int), + + # /** End value, initialised in pi_initialise_encode */ + # int layE, resE, compE, prcE; + ("layE", ctypes.c_int), + ("resE", ctypes.c_int), + ("compE", ctypes.c_int), + ("prcE", ctypes.c_int), + + # Start and end values of Tile width and height, initialised in + # pi_initialise_encode int txS,txE,tyS,tyE,dx,dy; + ("txS", ctypes.c_int), + ("txE", ctypes.c_int), + ("tyS", ctypes.c_int), + ("tyE", ctypes.c_int), + ("dx", ctypes.c_int), + ("dy", ctypes.c_int), + + # Temporary values for Tile parts, initialised in pi_create_encode + # int lay_t, res_t, comp_t, prc_t,tx0_t,ty0_t; + ("lay_t", ctypes.c_int), + ("res_t", ctypes.c_int), + ("comp_t", ctypes.c_int), + ("prc_t", ctypes.c_int), + ("tx0_t", ctypes.c_int), + ("ty0_t", ctypes.c_int)] + + +class CompressionParametersType(ctypes.Structure): + """Compression parameters. + + Corresponds to cparameters_t type in openjp2 headers. + """ + _fields_ = [ + # size of tile: + # tile_size_on = false (not in argument) or + # = true (in argument) + ("tile_size_on", ctypes.c_int), + + # XTOsiz, YTOsiz + ("cp_tx0", ctypes.c_int), + ("cp_ty0", ctypes.c_int), + + # XTsiz, YTsiz + ("cp_tdx", ctypes.c_int), + ("cp_tdy", ctypes.c_int), + + # allocation by rate/distortion + ("cp_disto_alloc", ctypes.c_int), + + # allocation by fixed layer + ("cp_fixed_alloc", ctypes.c_int), + + # add fixed_quality + ("cp_fixed_quality", ctypes.c_int), + + # fixed layer + ("cp_matrice", ctypes.c_void_p), + + # comment for coding + ("cp_comment", ctypes.c_char_p), + + # csty : coding style + ("csty", ctypes.c_int), + + # progression order (default OPJ_LRCP) + ("prog_order", ctypes.c_int), + + # progression order changes + ("poc", PocType * 32), + + # number of progression order changes (POC), default to 0 + ("numpocs", ctypes.c_uint), + + # number of layers + ("tcp_numlayers", ctypes.c_int), + + # rates of layers + ("tcp_rates", ctypes.c_float * 100), + + # different psnr for successive layers + ("tcp_distoratio", ctypes.c_float * 100), + + # number of resolutions + ("numresolution", ctypes.c_int), + + # initial code block width, default to 64 + ("cblockw_init", ctypes.c_int), + + # initial code block height, default to 64 + ("cblockh_init", ctypes.c_int), + + # mode switch (cblk_style) + ("mode", ctypes.c_int), + + # 1 : use the irreversible DWT 9-7 + # 0 : use lossless compression (default) + ("irreversible", ctypes.c_int), + + # region of interest: affected component in [0..3], -1 means no ROI + ("roi_compno", ctypes.c_int), + + # region of interest: upshift value + ("roi_shift", ctypes.c_int), + + # number of precinct size specifications + ("res_spec", ctypes.c_int), + + # initial precinct width + ("prcw_init", ctypes.c_int * J2K_MAXRLVLS), + + # initial precinct height + ("prch_init", ctypes.c_int * J2K_MAXRLVLS), + + # input file name + ("infile", ctypes.c_char * PATH_LEN), + + # output file name + ("outfile", ctypes.c_char * PATH_LEN), + + # DEPRECATED. + ("index_on", ctypes.c_int), + + # DEPRECATED. + ("index", ctypes.c_char * PATH_LEN), + + # subimage encoding: origin image offset in x direction + # subimage encoding: origin image offset in y direction + ("image_offset_x0", ctypes.c_int), + ("image_offset_y0", ctypes.c_int), + + # subsampling value for dx + # subsampling value for dy + ("subsampling_dx", ctypes.c_int), + ("subsampling_dy", ctypes.c_int), + + # input file format 0: PGX, 1: PxM, 2: BMP 3:TIF + # output file format 0: J2K, 1: JP2, 2: JPT + ("decod_format", ctypes.c_int), + ("cod_format", ctypes.c_int), + + # JPWL encoding parameters + # enables writing of EPC in MH, thus activating JPWL + ("jpwl_epc_on", ctypes.c_int), + + # error protection method for MH (0,1,16,32,37-128) + ("jpwl_hprot_mh", ctypes.c_int), + + # tile number of header protection specification (>=0) + ("jpwl_hprot_tph_tileno", ctypes.c_int * JPWL_MAX_NO_TILESPECS), + + # error protection methods for TPHs (0,1,16,32,37-128) + ("jpwl_hprot_tph", ctypes.c_int * JPWL_MAX_NO_TILESPECS), + + # tile number of packet protection specification (>=0) + ("jpwl_pprot_tileno", ctypes.c_int * JPWL_MAX_NO_TILESPECS), + + # packet number of packet protection specification (>=0) + ("jpwl_pprot_packno", ctypes.c_int * JPWL_MAX_NO_TILESPECS), + + # error protection methods for packets (0,1,16,32,37-128) + ("jpwl_pprot", ctypes.c_int * JPWL_MAX_NO_TILESPECS), + + # enables writing of ESD, (0=no/1/2 bytes) + ("jpwl_sens_size", ctypes.c_int), + + # sensitivity addressing size (0=auto/2/4 bytes) + ("jpwl_sens_addr", ctypes.c_int), + + # sensitivity range (0-3) + ("jpwl_sens_range", ctypes.c_int), + + # sensitivity method for MH (-1=no,0-7) + ("jpwl_sens_mh", ctypes.c_int), + + # tile number of sensitivity specification (>=0) + ("jpwl_sens_tph_tileno", ctypes.c_int * JPWL_MAX_NO_TILESPECS), + + # sensitivity methods for TPHs (-1=no,0-7) + ("jpwl_sens_tph", ctypes.c_int * JPWL_MAX_NO_TILESPECS), + + # Digital Cinema compliance 0-not compliant, 1-compliant + ("cp_cinema", ctypes.c_int), + + # Maximum rate for each component. + # If == 0, component size limitation is not considered + ("max_comp_size", ctypes.c_int), + + # Profile name + ("cp_rsiz", ctypes.c_int), + + # Tile part generation + ("tp_on", ctypes.c_uint8), + + # Flag for Tile part generation + ("tp_flag", ctypes.c_uint8), + + # MCT (multiple component transform) + ("tcp_mct", ctypes.c_uint8), + + # Enable JPIP indexing + ("jpip_on", ctypes.c_int)] + + +class DecompressionInfoType(ctypes.Structure): + """This is for decompression contexts. + + Corresponds to dinfo_t type in openjpeg headers. + """ + pass + + class DecompressionParametersType(ctypes.Structure): """Decompression parameters. @@ -111,6 +371,37 @@ class DecompressionParametersType(ctypes.Structure): _fields_.append(("flags", ctypes.c_uint)) +class ImageCmptparmType(ctypes.Structure): + """Component parameters structure used by the opj_image_create function. + """ + _fields_ = [ + # XRsiz: horizontal separation of a sample of ith component with + # respect to the reference grid + ("dx", ctypes.c_int), + + # YRsiz: vertical separation of a sample of ith component with + # respect to the reference grid */ + ("dy", ctypes.c_int), + + # data width, height + ("w", ctypes.c_int), + ("h", ctypes.c_int), + + # x component offset compared to the whole image + # y component offset compared to the whole image + ("x0", ctypes.c_int), + ("y0", ctypes.c_int), + + # precision + ('prec', ctypes.c_int), + + # imgae depth in bits + ('bpp', ctypes.c_int), + + # signed (1) / unsigned (0) + ('sgnd', ctypes.c_int)] + + class ImageCompType(ctypes.Structure): """Defines a single image component. @@ -166,6 +457,17 @@ def cio_close(cio): OPENJPEG.opj_cio_close(cio) +def create_compress(fmt): + """Wrapper for openjpeg library function opj_create_compress. + + Creates a J2K/JPT/JP2 compression structure. + """ + OPENJPEG.opj_create_compress.argtypes = [ctypes.c_int] + OPENJPEG.opj_create_compress.restype = ctypes.POINTER(CompressionInfoType) + cinfo = OPENJPEG.opj_create_compress(fmt) + return cinfo + + def create_decompress(fmt): """Wraps openjpeg library function opj_create_decompress. """ @@ -186,6 +488,39 @@ def decode(dinfo, cio): return image +def destroy_compress(cinfo): + """Wrapper for openjpeg library function opj_destroy_compress. + + Release resources for a compressor handle. + """ + argtypes = [ctypes.POINTER(CompressionInfoType)] + OPENJPEG.opj_destroy_compress.argtypes = argtypes + OPENJPEG.opj_destroy_compress(cinfo) + + +def encode(cinfo, cio, image): + """Wrapper for openjpeg library function opj_encode. + + Encodes an image into a JPEG-2000 codestream. + + Parameters + ---------- + cinfo : compression handle + + cio : output buffer stream + + image : image to encode + """ + argtypes = [ctypes.POINTER(CompressionInfoType), + ctypes.POINTER(CioType), + ctypes.POINTER(ImageType)] + OPENJPEG.opj_encode.argtypes = argtypes + OPENJPEG.opj_encode.restype = ctypes.c_int + status = OPENJPEG.opj_encode(cinfo, cio, image) + if not status: + raise RuntimeError("opj_encode failed") + + def destroy_decompress(dinfo): """Wraps openjpeg library function opj_destroy_decompress.""" argtypes = [ctypes.POINTER(DecompressionInfoType)] @@ -193,12 +528,76 @@ def destroy_decompress(dinfo): OPENJPEG.opj_destroy_decompress(dinfo) +def image_cmptparm_t_from_np(np_image): + """Return appropriate image_cmptparm_t based on given numpy array. + """ + try: + num_comps = np_image.shape[2] + except IndexError: + num_comps = 1 + + cmpt_parm_array_t = ImageCmptparmType * num_comps + tarr = cmpt_parm_array_t() + + if np_image.dtype == np.uint8: + prec = 8 + bpp = 8 + sgnd = 0 + elif np_image.dtype == np.int8: + prec = 8 + bpp = 8 + sgnd = 1 + elif np_image.dtype == np.uint16: + prec = 16 + bpp = 16 + sgnd = 0 + elif np_image.dtype == np.int16: + prec = 16 + bpp = 16 + sgnd = 1 + else: + raise(TypeError("unhandled")) + + for j in range(0, num_comps): + tarr[j].dx = 1 + tarr[j].dy = 1 + tarr[j].w = np_image.shape[1] + tarr[j].h = np_image.shape[0] + tarr[j].x0 = 0 + tarr[j].y0 = 0 + tarr[j].prec = prec + tarr[j].bpp = bpp + tarr[j].sgnd = sgnd + + return(tarr) + + +def image_create(cmptparms, cspace): + """Wrapper for openjpeg library function opj_image_create. + """ + OPENJPEG.opj_image_create.argtypes = [ctypes.c_int, + ctypes.POINTER(ImageCmptparmType), + ctypes.c_int] + OPENJPEG.opj_image_create.restype = ctypes.POINTER(ImageType) + + image = OPENJPEG.opj_image_create(len(cmptparms), cmptparms, cspace) + return(image) + + def image_destroy(image): """Wraps openjpeg library function opj_image_destroy.""" OPENJPEG.opj_image_destroy.argtypes = [ctypes.POINTER(ImageType)] OPENJPEG.opj_image_destroy(image) +def set_default_encoder_parameters(cparams_p): + """Wrapper for openjpeg library function opj_set_default_encoder_parameters. + """ + argtypes = [ctypes.POINTER(CompressionParametersType)] + OPENJPEG.opj_set_default_encoder_parameters.argtypes = argtypes + OPENJPEG.opj_set_default_encoder_parameters(cparams_p) + + def set_default_decoder_parameters(dparams_p): """Wrapper for opj_set_default_decoder_parameters. """ @@ -219,6 +618,15 @@ def set_event_mgr(dinfo, event_mgr, context=None): event_mgr, context) +def setup_encoder(cinfo, cparameters, image): + """Wrapper for openjpeg library function opj_setup_decoder.""" + argtypes = [ctypes.POINTER(CompressionInfoType), + ctypes.POINTER(CompressionParametersType), + ctypes.POINTER(ImageType)] + OPENJPEG.opj_setup_encoder.argtypes = argtypes + OPENJPEG.opj_setup_encoder(cinfo, cparameters, image) + + def setup_decoder(dinfo, dparams): """Wrapper for openjpeg library function opj_setup_decoder.""" argtypes = [ctypes.POINTER(DecompressionInfoType), From 516d3ca55b8f2f29ed6551211c13d5c9e9380928 Mon Sep 17 00:00:00 2001 From: John Evans Date: Wed, 11 Sep 2013 06:43:36 -0400 Subject: [PATCH 09/22] Don't bother trying to write with versions below 1.5. #111 --- glymur/test/test_jp2k.py | 3 +++ glymur/test/test_opj_suite_write.py | 8 +++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/glymur/test/test_jp2k.py b/glymur/test/test_jp2k.py index edefb7f..8e4a74c 100644 --- a/glymur/test/test_jp2k.py +++ b/glymur/test/test_jp2k.py @@ -679,6 +679,9 @@ class TestJp2k15(unittest.TestCase): j2k.read(layer=1) @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") + @unittest.skipIf(re.match(r"""1\.[01234]\.\d""", + OPENJPEG_VERSION) is not None, + "Writing only supported with openjpeg version 1.5+.") def test_2d_rgb(self): """RGB must have at least 3 components.""" with tempfile.NamedTemporaryFile(suffix='.jp2') as tfile: diff --git a/glymur/test/test_opj_suite_write.py b/glymur/test/test_opj_suite_write.py index 479cb1f..e187d34 100644 --- a/glymur/test/test_opj_suite_write.py +++ b/glymur/test/test_opj_suite_write.py @@ -10,6 +10,7 @@ suite. # pylint: disable=F0401 import os +import re import sys import tempfile @@ -19,15 +20,16 @@ else: import unittest from .fixtures import read_image, NO_READ_BACKEND, NO_READ_BACKEND_MSG -from .fixtures import OPJ_DATA_ROOT, opj_data_file +from .fixtures import OPJ_DATA_ROOT, OPENJPEG_VERSION, opj_data_file from glymur import Jp2k import glymur @unittest.skipIf(os.name == "nt", "no write support on windows, period") -@unittest.skipIf(glymur.lib.openjp2.OPENJP2 is None, - "Missing openjp2 library.") +@unittest.skipIf(re.match(r"""1\.[01234]\.\d""", + OPENJPEG_VERSION) is not None, + "Writing only supported with openjpeg version 1.5+.") @unittest.skipIf(NO_READ_BACKEND, NO_READ_BACKEND_MSG) @unittest.skipIf(OPJ_DATA_ROOT is None, "OPJ_DATA_ROOT environment variable not set") From 5626f3f460f990bdf6347b2f5dc3ba2ca192683d Mon Sep 17 00:00:00 2001 From: jevans Date: Wed, 11 Sep 2013 20:29:47 -0400 Subject: [PATCH 10/22] Updated for OpenSUSE 12.3. Simplified the Fedora explanations. #111 --- docs/source/detailed_installation.rst | 56 +++++++++------------------ 1 file changed, 19 insertions(+), 37 deletions(-) diff --git a/docs/source/detailed_installation.rst b/docs/source/detailed_installation.rst index dab4c3f..879d2a1 100644 --- a/docs/source/detailed_installation.rst +++ b/docs/source/detailed_installation.rst @@ -80,60 +80,42 @@ MacPorts supplies both OpenJPEG 1.5.0 and OpenJPEG 2.0.0. Linux ----- +For the most part, you only need python and numpy to run glymur. In order to +run as many tests as possible, however, the following Python packages may also +need to be installed. + + * setuptools + * matplotlib + * pillow + * contextlib2 (python 2.7 only) + * mock (python 2.7 only) + +OpenSUSE 12.3 +''''''''''''' +Ships with Python 3.3 and 2.7. You should use pip to install Pillow. Fedora 19 ''''''''' -Fedora 18 ships with Python 3.3 and all the necessary RPMs are available to -run the maximum number of tests. - - * python3 - * python3-numpy - * python3-setuptools - * python3-matplotlib (for running tests) - * python3-matplotlib-tk (or whichever matplotlib backend you prefer) - * python3-pillow (for running tests) +Ships with Python 3.3 and 2.7. All packages available as RPMs. Fedora 18 ''''''''' -Fedora 18 ships with Python 3.3 and the following RPMs are available to -meet the minimal set of requirements for running glymur. - - * python3 - * python3-numpy - * python3-setuptools - -For running the maximal number of tests, you also need - - * python3-matplotlib - * python3-matplotlib-tk (or whichever matplotlib backend you prefer) - -Pillow is also needed in order to run the maximum number of tests, so -go ahead and install Pillow via pip since Pillow is not available -in Fedora 18 default repositories:: +Fedora 18 ships with Python 3.3 and 2.7. Most packages are available as +standard RPMS, but you should use pip to install Pillow as it is not available +in the Fedora 18 default repositories:: $ yum install python3-devel # pip needs this in order to compile Pillow $ yum install python3-pip $ pip-python3 install Pillow --user - $ export PYTHONPATH=$HOME/.local/lib/python3.3/site-packages:$PYTHONPATH Fedora 17 ''''''''' -Fedora 17 ships with Python 2.7 and OpenJPEG 1.4. You should have the -following RPMs installed. - - * python - * python-mock - * python-pip - * python-setuptools - * numpy - * matplotlib (optional) - -In addition, you must install contextlib2 and Pillow via pip. :: +Fedora 17 ships with Python 2.7 and OpenJPEG 1.4. You must install contextlib2 +and Pillow via pip. :: $ yum install python-devel # pip needs this in order to compile Pillow $ pip-python install Pillow --user $ pip-python install contextlib2 --user - $ export PYTHONPATH=$HOME/.local/lib/python2.7/site-packages:$PYTHONPATH Windows ------- From 5b401e1e2da5cb4aff6fdd39ef1af381525da152 Mon Sep 17 00:00:00 2001 From: jevans Date: Wed, 11 Sep 2013 20:30:54 -0400 Subject: [PATCH 11/22] Writing works with 1.5, two failures with 3.3. #111 --- glymur/jp2k.py | 133 +++++++++-------------------------------- glymur/lib/openjpeg.py | 58 +++++++++++------- 2 files changed, 64 insertions(+), 127 deletions(-) diff --git a/glymur/jp2k.py b/glymur/jp2k.py index bb2fe43..413179b 100644 --- a/glymur/jp2k.py +++ b/glymur/jp2k.py @@ -15,14 +15,14 @@ else: import ctypes import math import os +import re import struct import warnings import numpy as np from .codestream import Codestream -from .core import SRGB -from .core import GREYSCALE +from .core import SRGB, GREYSCALE from .core import PROGRESSION_ORDER from .core import ENUMERATED_COLORSPACE, RESTRICTED_ICC_PROFILE from .jp2box import Jp2kBox @@ -33,6 +33,13 @@ from .lib import openjpeg as opj from .lib import openjp2 as opj2 from .lib import c as libc +if opj.OPENJPEG is None and opj2.OPENJP2 is None: + OPENJPEG_VERSION = '0.0.0' +elif opj2.OPENJP2 is None: + OPENJPEG_VERSION = opj.version() +else: + OPENJPEG_VERSION = opj2.version() + class Jp2k(Jp2kBox): """JPEG 2000 file. @@ -185,7 +192,10 @@ class Jp2k(Jp2kBox): cparams : CompressionParametersType(ctypes.Structure) Corresponds to cparameters_t type in openjp2 headers. """ - cparams = opj2.set_default_encoder_parameters() + if re.match(r"""1\.\d\.\d""", OPENJPEG_VERSION): + cparams = opj.set_default_encoder_parameters() + else: + cparams = opj2.set_default_encoder_parameters() outfile = self.filename.encode() num_pad_bytes = opj2.PATH_LEN - len(outfile) @@ -389,99 +399,18 @@ class Jp2k(Jp2kBox): def _write_openjpeg(self, img_array, verbose=False, **kwargs): """ """ - if codeblock is not None: - if (np.prod(codeblock) > 4096) or (np.any(np.array(codeblock) < 4)) or (np.any(np.array(codeblock) > 1024)): - msg = 'Size of code block error. ' - msg += 'Restriction: width*height <= 4096, ' - msg += '4 <= width, height <= 1024' - raise(RuntimeError(msg)) + cparams, colorspace = self._process_write_inputs(img_array, **kwargs) - if cratio is not None and len(cratio) >= opj.MAX_NUM_LAYERS: - msg = 'Maximum number of layers is %d.' % opj.MAX_NUM_LAYERS - raise(RuntimeError(msg)) + if img_array.ndim == 2: + # Force the image to be 3D. Just makes things easier later on. + numrows, numcols = img_array.shape + img_array = img_array.reshape(numrows, numcols, 1) - if psnr is not None and len(psnr) >= opj.MAX_NUM_LAYERS: - msg = 'Maximum number of layers is %d.' % opj.MAX_NUM_LAYERS - raise(RuntimeError(msg)) + comptparms = _populate_comptparms(img_array, cparams) - if cratio is not None and psnr is not None: - msg = 'Psnr and cratio parameters cannot be specified together.' - raise(RuntimeError(msg)) + image = opj.image_create(comptparms, colorspace) - - cparams = opj.CompressionParametersType() - - opj.set_default_encoder_parameters(ctypes.byref(cparams)) - - # Set default to lossless until we know otherwise. - cparams.tcp_rates[0] = 0 - cparams.tcp_numlayers = 1 - cparams.cp_disto_alloc = 1 - - outfile = self.jp2k_file - nelts = opj.OPJ_PATH_LEN - len(outfile) - outfile += b'0'*nelts - cparams.outfile = outfile - - numrows = data.shape[0] - numcols = data.shape[1] - numlayers = data.shape[2] - - if codeblock is not None: - cparams.cblockw_init = codeblock[0] - cparams.cblockh_init = codeblock[1] - - if comment is None: - comment = 'Created by OpenJPEG version %s' % opj.version() - cparams.cp_comment = ctypes.c_char_p(comment) - - - if cratio is not None: - cparams.tcp_numlayers = len(cratio) - for j in range(0,len(cratio)): - cparams.tcp_rates[j] = cratio[j] - cparams.cp_disto_alloc = 1 - - if eph: - cparams.csty = cparams.csty | 0x04 - - if modeswitch is not None: - cparams.mode = modeswitch - - if numres is not None: - cparams.numresolution = numres - - if origin is not None: - cparams.image_offset_x0 = origin[0] - cparams.image_offset_y0 = origin[1] - - if progorder is not None: - cparams.prog_order = opj.progression_order[progorder] - - if precinct is not None: - cparams.csty = cparams.csty | 0x01 - cparams.res_spec = len(precinct) - for j in range(0,len(precinct)): - cparams.prcw_init[j] = precinct[j][0] - cparams.prch_init[j] = precinct[j][1] - - if psnr is not None: - cparams.tcp_numlayers = len(psnr) - for j in range(0,len(psnr)): - cparams.tcp_distoratio[j] = psnr[j] - cparams.cp_fixed_quality = 1 - - if sop: - cparams.csty = cparams.csty | 0x02 - - if tile is not None: - cparams.tile_size_on = 1 - cparams.cp_tdx = tile[0] - cparams.cp_tdy = tile[1] - - # comment = what? - cmptparms = opj.image_cmptparm_t_from_np(data) - image = opj.image_create(cmptparms) + numrows, numcols, numlayers = img_array.shape # set image offset and reference grid image.contents.x0 = cparams.image_offset_x0 @@ -491,23 +420,16 @@ class Jp2k(Jp2kBox): # Stage the image data to the openjpeg data structure. for k in range(0,numlayers): - layer = np.ascontiguousarray(data[:,:,k], dtype=np.int32) + layer = np.ascontiguousarray(img_array[:,:,k], dtype=np.int32) dest = image.contents.comps[k].data src = layer.ctypes.data ctypes.memmove(dest, src, layer.nbytes) - # set multi-component transform? - if image.contents.numcomps == 3: - cparams.tcp_mct = chr(1) - else: - cparams.tcp_mct = chr(0) - # set encode format - #cinfo = opj.create_compress(opj.codec_format[self.file_format]) - cinfo = opj.create_compress(self.file_format) + cinfo = opj.create_compress(cparams.codec_fmt) event_mgr = opj.EventMgrType(None, None, None) - opj.set_event_mgr(cparams, ctypes.byref(event_mgr), None) + #opj.set_event_mgr(cparams, ctypes.byref(event_mgr), None) opj.setup_encoder(cinfo, ctypes.byref(cparams), image) @@ -519,7 +441,7 @@ class Jp2k(Jp2kBox): pos = opj.cio_tell(cio) ss = ctypes.string_at(cio.contents.buffer, pos) - f = open(self.jp2k_file,'wb') + f = open(self.filename,'wb') f.write(ss) f.close() opj.cio_close(cio); @@ -1408,7 +1330,10 @@ def _populate_comptparms(img_array, cparams): comp_prec = 16 numrows, numcols, num_comps = img_array.shape - comptparms = (opj2.ImageComptParmType * num_comps)() + if re.match(r"""1\.\d\.\d""", OPENJPEG_VERSION): + comptparms = (opj.ImageComptParmType * num_comps)() + else: + comptparms = (opj2.ImageComptParmType * num_comps)() for j in range(num_comps): comptparms[j].dx = cparams.subsampling_dx comptparms[j].dy = cparams.subsampling_dy diff --git a/glymur/lib/openjpeg.py b/glymur/lib/openjpeg.py index 6e7b858..3ea424a 100644 --- a/glymur/lib/openjpeg.py +++ b/glymur/lib/openjpeg.py @@ -371,7 +371,7 @@ class DecompressionParametersType(ctypes.Structure): _fields_.append(("flags", ctypes.c_uint)) -class ImageCmptparmType(ctypes.Structure): +class ImageComptParmType(ctypes.Structure): """Component parameters structure used by the opj_image_create function. """ _fields_ = [ @@ -395,7 +395,7 @@ class ImageCmptparmType(ctypes.Structure): # precision ('prec', ctypes.c_int), - # imgae depth in bits + # image depth in bits ('bpp', ctypes.c_int), # signed (1) / unsigned (0) @@ -403,22 +403,19 @@ class ImageCmptparmType(ctypes.Structure): class ImageCompType(ctypes.Structure): - """Defines a single image component. - - Corresponds to image_comp_t type in openjpeg. - """ - _fields_ = [("dx", ctypes.c_int), - ("dy", ctypes.c_int), - ("w", ctypes.c_int), - ("h", ctypes.c_int), - ("x0", ctypes.c_int), - ("y0", ctypes.c_int), - ("prec", ctypes.c_int), - ("bpp", ctypes.c_int), - ("sgnd", ctypes.c_int), - ("resno_decoded", ctypes.c_int), - ("factor", ctypes.c_int), - ("data", ctypes.POINTER(ctypes.c_int))] + """Defines a single image component. """ + _fields_ = [("dx", ctypes.c_int), + ("dy", ctypes.c_int), + ("w", ctypes.c_int), + ("h", ctypes.c_int), + ("x0", ctypes.c_int), + ("y0", ctypes.c_int), + ("prec", ctypes.c_int), + ("bpp", ctypes.c_int), + ("sgnd", ctypes.c_int), + ("resno_decoded", ctypes.c_int), + ("factor", ctypes.c_int), + ("data", ctypes.POINTER(ctypes.c_int))] class ImageType(ctypes.Structure): @@ -437,16 +434,22 @@ class ImageType(ctypes.Structure): ("icc_profile_len", ctypes.c_int)] -def cio_open(cinfo, src): +def cio_open(cinfo, src=None): """Wrapper for openjpeg library function opj_cio_open.""" argtypes = [ctypes.POINTER(CommonStructType), ctypes.c_char_p, ctypes.c_int] OPENJPEG.opj_cio_open.argtypes = argtypes OPENJPEG.opj_cio_open.restype = ctypes.POINTER(CioType) + if src is None: + length = 0 + else: + length = len(src) + cio = OPENJPEG.opj_cio_open(ctypes.cast(cinfo, ctypes.POINTER(CommonStructType)), - src, len(src)) + src, + length) return cio @@ -457,6 +460,13 @@ def cio_close(cio): OPENJPEG.opj_cio_close(cio) +def cio_tell(cio): + """Get position in byte stream.""" + OPENJPEG.cio_tell.argtypes = [ctypes.POINTER(CioType)] + OPENJPEG.cio_tell.restype = ctypes.c_int + pos = OPENJPEG.cio_tell(cio) + return pos + def create_compress(fmt): """Wrapper for openjpeg library function opj_create_compress. @@ -576,7 +586,7 @@ def image_create(cmptparms, cspace): """Wrapper for openjpeg library function opj_image_create. """ OPENJPEG.opj_image_create.argtypes = [ctypes.c_int, - ctypes.POINTER(ImageCmptparmType), + ctypes.POINTER(ImageComptParmType), ctypes.c_int] OPENJPEG.opj_image_create.restype = ctypes.POINTER(ImageType) @@ -590,12 +600,14 @@ def image_destroy(image): OPENJPEG.opj_image_destroy(image) -def set_default_encoder_parameters(cparams_p): +def set_default_encoder_parameters(): """Wrapper for openjpeg library function opj_set_default_encoder_parameters. """ + cparams = CompressionParametersType() argtypes = [ctypes.POINTER(CompressionParametersType)] OPENJPEG.opj_set_default_encoder_parameters.argtypes = argtypes - OPENJPEG.opj_set_default_encoder_parameters(cparams_p) + OPENJPEG.opj_set_default_encoder_parameters(ctypes.byref(cparams)) + return cparams def set_default_decoder_parameters(dparams_p): From d132a98a80976b7d64289f02aaa32a63d59af0d3 Mon Sep 17 00:00:00 2001 From: John Evans Date: Thu, 12 Sep 2013 06:40:13 -0400 Subject: [PATCH 12/22] Updated changelog for 1.5 write support. --- CHANGES.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index 9a71f81..96b8173 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,5 @@ +Sep 12, 2013 - v0.4.2r Added write support for 1.5.x. + Aug 21, 2013 - v0.4.1 Fixed segfault with openjpeg 1.x when rlevel=-1 Aug 18, 2013 - v0.4.0 Added append method. From cc10537c14412c322496cfb22fce3538fc436c70 Mon Sep 17 00:00:00 2001 From: jevans Date: Thu, 12 Sep 2013 21:07:58 -0400 Subject: [PATCH 13/22] Using existing openjp2 handlers for now. #112 Seems a little greasy, but it works. Probably should think about a separate error handler, though. --- glymur/jp2k.py | 91 +++++++++++++++++++++++------------------- glymur/lib/openjp2.py | 2 +- glymur/lib/openjpeg.py | 3 +- 3 files changed, 53 insertions(+), 43 deletions(-) diff --git a/glymur/jp2k.py b/glymur/jp2k.py index 413179b..72fc4ff 100644 --- a/glymur/jp2k.py +++ b/glymur/jp2k.py @@ -428,8 +428,13 @@ class Jp2k(Jp2kBox): # set encode format cinfo = opj.create_compress(cparams.codec_fmt) - event_mgr = opj.EventMgrType(None, None, None) - #opj.set_event_mgr(cparams, ctypes.byref(event_mgr), None) + event_mgr = opj.EventMgrType() + _info_handler = _INFO_CALLBACK if verbose else None + event_mgr.info_handler = _info_handler + event_mgr.warning_handler = ctypes.cast(_WARNING_CALLBACK, + ctypes.c_void_p) + event_mgr.error_handler = ctypes.cast(_ERROR_CALLBACK, + ctypes.c_void_p) opj.setup_encoder(cinfo, ctypes.byref(cparams), image) @@ -437,7 +442,9 @@ class Jp2k(Jp2kBox): # allocate memory for all tiles cio = opj.cio_open(cinfo) - opj.encode(cinfo, cio, image) + if not opj.encode(cinfo, cio, image): + raise IOError("Encode error.") + pos = opj.cio_tell(cio) ss = ctypes.string_at(cio.contents.buffer, pos) @@ -773,41 +780,45 @@ class Jp2k(Jp2kBox): raise IOError(msg) with ExitStack() as stack: - # Set decoding parameters. - dparameters = opj.DecompressionParametersType() - opj.set_default_decoder_parameters(ctypes.byref(dparameters)) - dparameters.cp_reduce = rlevel - dparameters.decod_format = self._codec_format + try: + # Set decoding parameters. + dparameters = opj.DecompressionParametersType() + opj.set_default_decoder_parameters(ctypes.byref(dparameters)) + dparameters.cp_reduce = rlevel + dparameters.decod_format = self._codec_format + + infile = self.filename.encode() + nelts = opj.PATH_LEN - len(infile) + infile += b'0' * nelts + dparameters.infile = infile + + dinfo = opj.create_decompress(dparameters.decod_format) + + event_mgr = opj.EventMgrType() + info_handler = ctypes.cast(_INFO_CALLBACK, ctypes.c_void_p) + event_mgr.info_handler = info_handler if verbose else None + event_mgr.warning_handler = ctypes.cast(_WARNING_CALLBACK, + ctypes.c_void_p) + event_mgr.error_handler = ctypes.cast(_ERROR_CALLBACK, + ctypes.c_void_p) + opj.set_event_mgr(dinfo, ctypes.byref(event_mgr)) + + opj.setup_decoder(dinfo, dparameters) + + with open(self.filename, 'rb') as fptr: + src = fptr.read() + cio = opj.cio_open(dinfo, src) + + image = opj.decode(dinfo, cio) + + stack.callback(opj.image_destroy, image) + stack.callback(opj.destroy_decompress, dinfo) + stack.callback(opj.cio_close, cio) + + data = extract_image_cube(image) - infile = self.filename.encode() - nelts = opj.PATH_LEN - len(infile) - infile += b'0' * nelts - dparameters.infile = infile - - dinfo = opj.create_decompress(dparameters.decod_format) - - event_mgr = opj.EventMgrType() - info_handler = ctypes.cast(_INFO_CALLBACK, ctypes.c_void_p) - event_mgr.info_handler = info_handler if verbose else None - event_mgr.warning_handler = ctypes.cast(_WARNING_CALLBACK, - ctypes.c_void_p) - event_mgr.error_handler = ctypes.cast(_ERROR_CALLBACK, - ctypes.c_void_p) - opj.set_event_mgr(dinfo, ctypes.byref(event_mgr)) - - opj.setup_decoder(dinfo, dparameters) - - with open(self.filename, 'rb') as fptr: - src = fptr.read() - cio = opj.cio_open(dinfo, src) - - image = opj.decode(dinfo, cio) - - stack.callback(opj.image_destroy, image) - stack.callback(opj.destroy_decompress, dinfo) - stack.callback(opj.cio_close, cio) - - data = extract_image_cube(image) + except ValueError: + opj2.check_error(0) if data.shape[2] == 1: # The third dimension has just a single layer. Make the image @@ -1465,18 +1476,18 @@ _CMPFUNC = ctypes.CFUNCTYPE(ctypes.c_void_p, ctypes.c_char_p, ctypes.c_void_p) def _default_error_handler(msg, _): - """Default error handler callback for openjpeg library.""" + """Default error handler callback for libopenjp2.""" msg = "OpenJPEG library error: {0}".format(msg.decode('utf-8').rstrip()) opj2.set_error_message(msg) def _default_info_handler(msg, _): - """Default info handler callback for openjpeg library.""" + """Default info handler callback.""" print("[INFO] {0}".format(msg.decode('utf-8').rstrip())) def _default_warning_handler(library_msg, _): - """Default warning handler callback for openjpeg library.""" + """Default warning handler callback.""" library_msg = library_msg.decode('utf-8').rstrip() msg = "OpenJPEG library warning: {0}".format(library_msg) warnings.warn(msg) diff --git a/glymur/lib/openjp2.py b/glymur/lib/openjp2.py index f0f72c0..8c0ae32 100644 --- a/glymur/lib/openjp2.py +++ b/glymur/lib/openjp2.py @@ -685,7 +685,7 @@ def check_error(status): raise IOError("OpenJPEG function failure.") # These library functions all return an error status. Circumvent that and -# force # them to raise an exception. +# force them to raise an exception. FCNS = ['opj_decode', 'opj_decode_tile_data', 'opj_end_compress', 'opj_encode', 'opj_end_decompress', 'opj_get_decoded_tile', 'opj_read_header', 'opj_read_tile_header', 'opj_set_decode_area', diff --git a/glymur/lib/openjpeg.py b/glymur/lib/openjpeg.py index 3ea424a..5b1183f 100644 --- a/glymur/lib/openjpeg.py +++ b/glymur/lib/openjpeg.py @@ -527,8 +527,7 @@ def encode(cinfo, cio, image): OPENJPEG.opj_encode.argtypes = argtypes OPENJPEG.opj_encode.restype = ctypes.c_int status = OPENJPEG.opj_encode(cinfo, cio, image) - if not status: - raise RuntimeError("opj_encode failed") + return status def destroy_decompress(dinfo): From cc729dd579b828eb05e3f3a1c9e25bc301fa0373 Mon Sep 17 00:00:00 2001 From: jevans Date: Sat, 14 Sep 2013 21:46:58 -0400 Subject: [PATCH 14/22] Added version module. Closes #113 --- glymur/__init__.py | 3 ++ glymur/jp2k.py | 22 ++++++------ glymur/test/fixtures.py | 7 ---- glymur/test/test_config.py | 6 ++-- glymur/test/test_jp2k.py | 11 ++---- glymur/test/test_opj_suite.py | 18 ++++++---- glymur/test/test_opj_suite_write.py | 4 +-- glymur/version.py | 53 +++++++++++++++++++++++++++++ setup.py | 3 +- 9 files changed, 88 insertions(+), 39 deletions(-) create mode 100644 glymur/version.py diff --git a/glymur/__init__.py b/glymur/__init__.py index cc80a72..bf2f625 100644 --- a/glymur/__init__.py +++ b/glymur/__init__.py @@ -2,6 +2,9 @@ """ import sys +from glymur import version +__version__ = version.version + from .jp2k import Jp2k from .jp2dump import jp2dump diff --git a/glymur/jp2k.py b/glymur/jp2k.py index 72fc4ff..f3127bc 100644 --- a/glymur/jp2k.py +++ b/glymur/jp2k.py @@ -1,4 +1,8 @@ -"""Access to JPEG2000 files. +"""This file is part of glymur, a Python interface for accessing JPEG 2000. + +http://glymur.readthedocs.org + +Copyright 2013 John Evans License: MIT """ @@ -31,15 +35,9 @@ from .jp2box import ColourSpecificationBox, ContiguousCodestreamBox from .jp2box import ImageHeaderBox from .lib import openjpeg as opj from .lib import openjp2 as opj2 +from . import version from .lib import c as libc -if opj.OPENJPEG is None and opj2.OPENJP2 is None: - OPENJPEG_VERSION = '0.0.0' -elif opj2.OPENJP2 is None: - OPENJPEG_VERSION = opj.version() -else: - OPENJPEG_VERSION = opj2.version() - class Jp2k(Jp2kBox): """JPEG 2000 file. @@ -192,7 +190,7 @@ class Jp2k(Jp2kBox): cparams : CompressionParametersType(ctypes.Structure) Corresponds to cparameters_t type in openjp2 headers. """ - if re.match(r"""1\.\d\.\d""", OPENJPEG_VERSION): + if version.openjpeg_version_tuple[0] == 1: cparams = opj.set_default_encoder_parameters() else: cparams = opj2.set_default_encoder_parameters() @@ -998,8 +996,8 @@ class Jp2k(Jp2kBox): glymur.LibraryNotFoundError If glymur is unable to load the openjp2 library. """ - if opj2.OPENJP2 is None: - raise LibraryNotFoundError("You must have the development version " + if version.openjpeg_version_tuple[0] < 2: + raise LibraryNotFoundError("You must have at least version 2.0.0" "of OpenJP2 installed before using " "this functionality.") @@ -1341,7 +1339,7 @@ def _populate_comptparms(img_array, cparams): comp_prec = 16 numrows, numcols, num_comps = img_array.shape - if re.match(r"""1\.\d\.\d""", OPENJPEG_VERSION): + if version.openjpeg_version_tuple[0] == 1: comptparms = (opj.ImageComptParmType * num_comps)() else: comptparms = (opj2.ImageComptParmType * num_comps)() diff --git a/glymur/test/fixtures.py b/glymur/test/fixtures.py index 933222a..b872f1d 100644 --- a/glymur/test/fixtures.py +++ b/glymur/test/fixtures.py @@ -10,13 +10,6 @@ import numpy as np import glymur -# Need to know the version of the openjpeg software. If openjpeg is not -# installed, we use # '0.0.0' -OPENJPEG_VERSION = '0.0.0' -if glymur.lib.openjp2.OPENJP2 is not None: - OPENJPEG_VERSION = glymur.lib.openjp2.version() -elif glymur.lib.openjpeg.OPENJPEG is not None: - OPENJPEG_VERSION = glymur.lib.openjpeg.version() # Need to know of the libopenjp2 version is the official 2.0.0 release and NOT # the 2.0+ development version. diff --git a/glymur/test/test_config.py b/glymur/test/test_config.py index af95bd3..16af663 100644 --- a/glymur/test/test_config.py +++ b/glymur/test/test_config.py @@ -117,8 +117,10 @@ class TestConfig(unittest.TestCase): """ with patch('glymur.lib.openjp2.OPENJP2', new=None): with patch('glymur.lib.openjpeg.OPENJPEG', new=None): - with self.assertRaises(glymur.jp2k.LibraryNotFoundError): - glymur.Jp2k(self.jp2file).read_bands() + with patch('glymur.version.openjpeg_version_tuple', + new=(0, 0, 0)): + with self.assertRaises(glymur.jp2k.LibraryNotFoundError): + glymur.Jp2k(self.jp2file).read_bands() @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") def test_write_without_library(self): diff --git a/glymur/test/test_jp2k.py b/glymur/test/test_jp2k.py index 8e4a74c..bbf551b 100644 --- a/glymur/test/test_jp2k.py +++ b/glymur/test/test_jp2k.py @@ -34,7 +34,6 @@ import glymur from glymur import Jp2k from .fixtures import OPENJP2_IS_V2_OFFICIAL -from .fixtures import OPENJPEG_VERSION from .fixtures import OPJ_DATA_ROOT, opj_data_file @@ -192,7 +191,7 @@ class TestJp2k_2_1(unittest.TestCase): j.read(rlevel=1) -@unittest.skipIf(re.match(r"""1\.\d.\d""", OPENJPEG_VERSION), +@unittest.skipIf(glymur.version.openjpeg_version_tuple[0] < 2, "Not tested for 1.x") class TestJp2k_2_0(unittest.TestCase): """Test suite requiring at least version 2.0""" @@ -679,8 +678,7 @@ class TestJp2k15(unittest.TestCase): j2k.read(layer=1) @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") - @unittest.skipIf(re.match(r"""1\.[01234]\.\d""", - OPENJPEG_VERSION) is not None, + @unittest.skipIf(glymur.version.openjpeg_version_tuple[1] < 5, "Writing only supported with openjpeg version 1.5+.") def test_2d_rgb(self): """RGB must have at least 3 components.""" @@ -723,8 +721,7 @@ class TestJp2k15(unittest.TestCase): b'this is a test') @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") - @unittest.skipIf(re.match(r"""1\.[345]\.\d""", - OPENJPEG_VERSION) is not None, + @unittest.skipIf(glymur.version.openjpeg_version_tuple[0] < 2, "Segfault on official v1.x series.") def test_openjpeg_library_message(self): """Verify the error message produced by the openjpeg library""" @@ -760,8 +757,6 @@ class TestJp2k15(unittest.TestCase): j.read(rlevel=1) -@unittest.skipIf(re.match(r"""1\.[012]\.\d""", OPENJPEG_VERSION), - "Unsupported version of openjpeg.") class TestJp2k(unittest.TestCase): """Test suite for openjpeg software starting at 1.3""" diff --git a/glymur/test/test_opj_suite.py b/glymur/test/test_opj_suite.py index 3c6b5d2..36f0a7b 100644 --- a/glymur/test/test_opj_suite.py +++ b/glymur/test/test_opj_suite.py @@ -45,7 +45,7 @@ import numpy as np from glymur import Jp2k import glymur -from .fixtures import OPENJPEG_VERSION, OPENJP2_IS_V2_OFFICIAL, OPJ_DATA_ROOT +from .fixtures import OPENJP2_IS_V2_OFFICIAL, OPJ_DATA_ROOT from .fixtures import mse, peak_tolerance, read_pgx, opj_data_file @@ -601,7 +601,7 @@ class TestSuite(unittest.TestCase): jpdata = jp2k.read() self.assertEqual(jpdata.shape, (640, 480, 3)) - @unittest.skipIf(re.match(r"""1\.[0125]\.\d""", OPENJPEG_VERSION), + @unittest.skipIf(glymur.version.openjpeg_version_tuple[0] < 2, "Functionality not implemented for 1.x") def test_ETS_JP2_file3(self): jfile = opj_data_file('input/conformance/file3.jp2') @@ -6720,7 +6720,7 @@ class TestSuiteDump(unittest.TestCase): [8, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10]) -@unittest.skipIf(re.match(r"""1\.\d.\d""", OPENJPEG_VERSION), +@unittest.skipIf(glymur.version.openjpeg_version_tuple[0] == 1, "Feature not supported in glymur until openjpeg 2.0") class TestSuite_bands(unittest.TestCase): """Runs tests introduced in version 1.x but only pass in glymur with 2.0 @@ -6849,7 +6849,7 @@ class TestSuite_bands(unittest.TestCase): self.assertTrue(True) -@unittest.skipIf(re.match(r"""1\.\d.\d""", OPENJPEG_VERSION), +@unittest.skipIf(glymur.version.openjpeg_version_tuple[0] == 1, "Tests not passing until 2.0") class TestSuite2point0(unittest.TestCase): """Runs tests introduced in version 2.0 or that pass only in 2.0""" @@ -6901,13 +6901,19 @@ class TestSuite2point0(unittest.TestCase): # messages that cannot be turned off? relpath = 'input/nonregression/kakadu_v4-4_openjpegv2_broken.j2k' jfile = opj_data_file(relpath) - Jp2k(jfile).read() + if glymur.version.openjpeg_version_tuple[0] < 2: + with warnings.catch_warnings(): + # Incorrect warning issued about tile parts. + warnings.simplefilter("ignore") + Jp2k(jfile).read() + else: + Jp2k(jfile).read() self.assertTrue(True) @unittest.skipIf(OPENJP2_IS_V2_OFFICIAL, "Test not in done in v2.0.0 official") -@unittest.skipIf(re.match(r"""1\.\d.\d""", OPENJPEG_VERSION), +@unittest.skipIf(glymur.version.openjpeg_version_tuple[0] == 1, "Tests not introduced until 2.1") class TestSuite2point1(unittest.TestCase): """Runs tests introduced in version 2.0+ or that pass only in 2.0+""" diff --git a/glymur/test/test_opj_suite_write.py b/glymur/test/test_opj_suite_write.py index e187d34..2f699e6 100644 --- a/glymur/test/test_opj_suite_write.py +++ b/glymur/test/test_opj_suite_write.py @@ -20,7 +20,7 @@ else: import unittest from .fixtures import read_image, NO_READ_BACKEND, NO_READ_BACKEND_MSG -from .fixtures import OPJ_DATA_ROOT, OPENJPEG_VERSION, opj_data_file +from .fixtures import OPJ_DATA_ROOT, opj_data_file from glymur import Jp2k import glymur @@ -28,7 +28,7 @@ import glymur @unittest.skipIf(os.name == "nt", "no write support on windows, period") @unittest.skipIf(re.match(r"""1\.[01234]\.\d""", - OPENJPEG_VERSION) is not None, + glymur.version.openjpeg_version) is not None, "Writing only supported with openjpeg version 1.5+.") @unittest.skipIf(NO_READ_BACKEND, NO_READ_BACKEND_MSG) @unittest.skipIf(OPJ_DATA_ROOT is None, diff --git a/glymur/version.py b/glymur/version.py new file mode 100644 index 0000000..256ed4e --- /dev/null +++ b/glymur/version.py @@ -0,0 +1,53 @@ +# This file is part of glymur, a Python interface for accessing JPEG 2000. +# +# http://glymur.readthedocs.org +# +# Copyright 2013 John Evans +# +# License: MIT + +import sys +import numpy as np +from distutils.version import StrictVersion + +from .lib import openjpeg as opj +from .lib import openjp2 as opj2 + +version = "0.4.1" +_sv = StrictVersion(version) +version_tuple = _sv.version + + +if opj.OPENJPEG is None and opj2.OPENJP2 is None: + openjpeg_version = '0.0.0' +elif opj2.OPENJP2 is None: + openjpeg_version = opj.version() +else: + openjpeg_version = opj2.version() + +_sv = StrictVersion(openjpeg_version) +openjpeg_version_tuple = _sv.version + +__doc__ = """\ +This is glymur **{glymur_version}** + +* OPENJPEG version: **{openjpeg}** +""".format(glymur_version=version, + openjpeg=openjpeg_version) + +info = """\ +Summary of glymur configuration +------------------------------- + +glymur {glymur} +OPENJPEG {openjpeg} +Python {python} +sys.platform {platform} +sys.maxsize {maxsize} +numpy {numpy} +""".format(glymur=version, + openjpeg=openjpeg_version, + python=sys.version, + platform=sys.platform, + maxsize=sys.maxsize, + numpy=np.__version__) diff --git a/setup.py b/setup.py index ff533a7..8e6233c 100644 --- a/setup.py +++ b/setup.py @@ -13,8 +13,7 @@ kwargs = {'name': 'Glymur', 'package_data': {'glymur': ['data/*.jp2', 'data/*.j2k']}, 'scripts': ['bin/jp2dump'], 'license': 'MIT', - 'test_suite': 'glymur.test', - 'platforms': ['darwin']} + 'test_suite': 'glymur.test'} instllrqrs = ['numpy>=1.4.1'] if sys.hexversion < 0x03030000: From 427a4946b7654b83532bec759f8aacf7361aae87 Mon Sep 17 00:00:00 2001 From: John Evans Date: Sun, 15 Sep 2013 11:15:02 -0400 Subject: [PATCH 15/22] Added ExitStack to write/1.5 workflow. Closes #114 Some pylint work. --- glymur/jp2k.py | 164 +++++++++++++++++-------------------------------- 1 file changed, 58 insertions(+), 106 deletions(-) diff --git a/glymur/jp2k.py b/glymur/jp2k.py index f3127bc..03ffc71 100644 --- a/glymur/jp2k.py +++ b/glymur/jp2k.py @@ -19,7 +19,6 @@ else: import ctypes import math import os -import re import struct import warnings @@ -386,132 +385,85 @@ class Jp2k(Jp2kBox): If glymur is unable to load the openjp2 library. """ if opj2.OPENJP2 is not None: - img = self._write_openjp2(img_array, verbose=verbose, **kwargs) + self._write_openjp2(img_array, verbose=verbose, **kwargs) elif opj.OPENJPEG is not None: - img = self._write_openjpeg(img_array, verbose=verbose, **kwargs) + self._write_openjpeg(img_array, verbose=verbose, **kwargs) else: - raise LibraryNotFoundError("You must have version 1.5 of OpenJPEG " - "or more recent before using this " + raise LibraryNotFoundError("You must have at least version 1.5 of " + "OpenJPEG before using this " "functionality.") def _write_openjpeg(self, img_array, verbose=False, **kwargs): """ + Write JPEG 2000 file using OpenJPEG 1.5 interface. """ cparams, colorspace = self._process_write_inputs(img_array, **kwargs) if img_array.ndim == 2: # Force the image to be 3D. Just makes things easier later on. - numrows, numcols = img_array.shape - img_array = img_array.reshape(numrows, numcols, 1) + img_array = img_array.reshape(img_array.shape[0], + img_array.shape[1], + 1) comptparms = _populate_comptparms(img_array, cparams) - image = opj.image_create(comptparms, colorspace) + with ExitStack() as stack: + image = opj.image_create(comptparms, colorspace) + stack.callback(opj.image_destroy, image) - numrows, numcols, numlayers = img_array.shape + numrows, numcols, numlayers = img_array.shape - # set image offset and reference grid - image.contents.x0 = cparams.image_offset_x0 - image.contents.y0 = cparams.image_offset_y0 - image.contents.x1 = image.contents.x0 + (numcols - 1) * cparams.subsampling_dx + 1 - image.contents.y1 = image.contents.y0 + (numrows - 1) * cparams.subsampling_dy + 1 + # set image offset and reference grid + image.contents.x0 = cparams.image_offset_x0 + image.contents.y0 = cparams.image_offset_y0 + image.contents.x1 = image.contents.x0 \ + + (numcols - 1) * cparams.subsampling_dx + 1 + image.contents.y1 = image.contents.y0 \ + + (numrows - 1) * cparams.subsampling_dy + 1 - # Stage the image data to the openjpeg data structure. - for k in range(0,numlayers): - layer = np.ascontiguousarray(img_array[:,:,k], dtype=np.int32) - dest = image.contents.comps[k].data - src = layer.ctypes.data - ctypes.memmove(dest, src, layer.nbytes) + # Stage the image data to the openjpeg data structure. + for k in range(0, numlayers): + layer = np.ascontiguousarray(img_array[:, :, k], + dtype=np.int32) + dest = image.contents.comps[k].data + src = layer.ctypes.data + ctypes.memmove(dest, src, layer.nbytes) - # set encode format - cinfo = opj.create_compress(cparams.codec_fmt) + cinfo = opj.create_compress(cparams.codec_fmt) + stack.callback(opj.destroy_compress, cinfo) - event_mgr = opj.EventMgrType() - _info_handler = _INFO_CALLBACK if verbose else None - event_mgr.info_handler = _info_handler - event_mgr.warning_handler = ctypes.cast(_WARNING_CALLBACK, - ctypes.c_void_p) - event_mgr.error_handler = ctypes.cast(_ERROR_CALLBACK, - ctypes.c_void_p) + # Setup the info, warning, and error handlers. + # Always use the warning and error handler. Use of an info + # handler is optional. + event_mgr = opj.EventMgrType() + _info_handler = _INFO_CALLBACK if verbose else None + event_mgr.info_handler = _info_handler + event_mgr.warning_handler = ctypes.cast(_WARNING_CALLBACK, + ctypes.c_void_p) + event_mgr.error_handler = ctypes.cast(_ERROR_CALLBACK, + ctypes.c_void_p) - opj.setup_encoder(cinfo, ctypes.byref(cparams), image) + opj.setup_encoder(cinfo, ctypes.byref(cparams), image) - # open a byte stream for writing - # allocate memory for all tiles - cio = opj.cio_open(cinfo) - - if not opj.encode(cinfo, cio, image): - raise IOError("Encode error.") + cio = opj.cio_open(cinfo) + stack.callback(opj.cio_close, cio) - pos = opj.cio_tell(cio) + if not opj.encode(cinfo, cio, image): + raise IOError("Encode error.") - ss = ctypes.string_at(cio.contents.buffer, pos) - f = open(self.filename,'wb') - f.write(ss) - f.close() - opj.cio_close(cio); + pos = opj.cio_tell(cio) - opj.destroy_compress(cinfo); - opj.image_destroy(image); + blob = ctypes.string_at(cio.contents.buffer, pos) + fptr = open(self.filename, 'wb') + stack.callback(fptr.close) + fptr.write(blob) self.parse() def _write_openjp2(self, img_array, verbose=False, **kwargs): - """Write image data to a JP2/JPX/J2k file. Intended usage of the - various parameters follows that of OpenJPEG's opj_compress utility. - - This method can only be used to create JPEG 2000 images that can fit - in memory. - - Parameters - ---------- - img_array : ndarray - Image data to be written to file. - cbsize : tuple, optional - Code block size (DY, DX). - colorspace : str, optional - Either 'rgb' or 'gray'. - cratios : iterable - Compression ratios for successive layers. - eph : bool, optional - If true, write SOP marker after each header packet. - grid_offset : tuple, optional - Offset (DY, DX) of the origin of the image in the reference grid. - mct : bool, optional - Specifies usage of the multi component transform. If not - specified, defaults to True if the colorspace is RGB. - modesw : int, optional - Mode switch. - 1 = BYPASS(LAZY) - 2 = RESET - 4 = RESTART(TERMALL) - 8 = VSC - 16 = ERTERM(SEGTERM) - 32 = SEGMARK(SEGSYM) - numres : int, optional - Number of resolutions. - prog : str, optional - Progression order, one of "LRCP" "RLCP", "RPCL", "PCRL", "CPRL". - psnr : iterable, optional - Different PSNR for successive layers. - psizes : list, optional - List of precinct sizes. Each precinct size tuple is defined in - (height x width). - sop : bool, optional - If true, write SOP marker before each packet. - subsam : tuple, optional - Subsampling factors (dy, dx). - tilesize : tuple, optional - Numeric tuple specifying tile size in terms of (numrows, numcols), - not (X, Y). - verbose : bool, optional - Print informational messages produced by the OpenJPEG library. - - Raises - ------ - glymur.LibraryNotFoundError - If glymur is unable to load the openjp2 library. + """ + Write JPEG 2000 file using OpenJPEG 1.5 interface. """ cparams, colorspace = self._process_write_inputs(img_array, **kwargs) @@ -784,14 +736,14 @@ class Jp2k(Jp2kBox): opj.set_default_decoder_parameters(ctypes.byref(dparameters)) dparameters.cp_reduce = rlevel dparameters.decod_format = self._codec_format - + infile = self.filename.encode() nelts = opj.PATH_LEN - len(infile) infile += b'0' * nelts dparameters.infile = infile - + dinfo = opj.create_decompress(dparameters.decod_format) - + event_mgr = opj.EventMgrType() info_handler = ctypes.cast(_INFO_CALLBACK, ctypes.c_void_p) event_mgr.info_handler = info_handler if verbose else None @@ -800,19 +752,19 @@ class Jp2k(Jp2kBox): event_mgr.error_handler = ctypes.cast(_ERROR_CALLBACK, ctypes.c_void_p) opj.set_event_mgr(dinfo, ctypes.byref(event_mgr)) - + opj.setup_decoder(dinfo, dparameters) - + with open(self.filename, 'rb') as fptr: src = fptr.read() cio = opj.cio_open(dinfo, src) - + image = opj.decode(dinfo, cio) - + stack.callback(opj.image_destroy, image) stack.callback(opj.destroy_decompress, dinfo) stack.callback(opj.cio_close, cio) - + data = extract_image_cube(image) except ValueError: From 293d796b916f753e7a758b1c3fea27c18b1764af Mon Sep 17 00:00:00 2001 From: John Evans Date: Sun, 15 Sep 2013 11:57:04 -0400 Subject: [PATCH 16/22] Streamlined the advanced installation instructions a bit. Closes #115 Linux users don't need as much hand-holding. --- docs/source/detailed_installation.rst | 106 +++++++++++--------------- 1 file changed, 46 insertions(+), 60 deletions(-) diff --git a/docs/source/detailed_installation.rst b/docs/source/detailed_installation.rst index 879d2a1..7fb5b3b 100644 --- a/docs/source/detailed_installation.rst +++ b/docs/source/detailed_installation.rst @@ -1,31 +1,33 @@ ---------------------------------- Advanced Installation Instructions ---------------------------------- +Most users won't need to read this! You've been warned... '''''''''''''''''''''' Glymur Configuration '''''''''''''''''''''' The default glymur installation process relies upon OpenJPEG version -1.X being properly installed on your system. This will, however, only -give you you basic read capabilities, so if you wish to take advantage -of more of glymur's features, you should install version 2.0 or -compile OpenJPEG as a shared library (named *openjp2* instead of -*openjpeg*) from the developmental source that you can retrieve via -subversion. As of this time of writing, svn revision 2345 works. +1.X being properly installed on your system. If you have version 1.5 you can +both read and write JPEG 2000 files, but you may wish to install version 2.0 +or the 2.0+ version from OpenJPEG's development trunk for better performance. +If you do that, you should compile it as a shared library (named *openjp2* +instead of *openjpeg*) from the developmental source that you can retrieve +via subversion. As of this time of writing, svn revision 2345 works. You should also download the test data for the purpose of configuring -and running OpenJPEG's test suite, check their instructions for all -this. You should set the **OPJ_DATA_ROOT** environment variable -for the purpose of running Glymur's test suite. :: +and running OpenJPEG's test suite, check their instructions for all this. +You should set the **OPJ_DATA_ROOT** environment variable for the purpose +of running Glymur's test suite. :: $ svn co http://openjpeg.googlecode.com/svn/data $ export OPJ_DATA_ROOT=`pwd`/data -Glymur uses ctypes (for the moment) to access the openjp2 library, and -because ctypes access libraries in a platform-dependent manner, it is +Glymur uses ctypes to access the openjp2/openjpeg libraries, +and because ctypes accesses libraries in a platform-dependent manner, it is recommended that you create a configuration file to help Glymur properly find -the openjp2 library. The configuration format is the same as used by Python's -configparser module, i.e. :: +the openjpeg or openjp2 libraries (linux users don't need to bother if you are +using OpenJPEG as provided by your package manager). The configuration +format is the same as used by Python's configparser module, i.e. :: [library] openjp2: /opt/openjp2-svn/lib/libopenjp2.so @@ -37,7 +39,8 @@ to the configuration file would normally be :: $HOME/.config/glymur/glymurrc -but if you have **$XDG_CONFIG_HOME** defined, the path will be :: +but if you have the **XDG_CONFIG_HOME** environment variable defined, +the path will be :: $XDG_CONFIG_HOME/glymur/glymurrc @@ -52,12 +55,11 @@ You may also include a line for the version 1.x openjpeg library if you have it installed in a non-standard place, i.e. :: [library] - openjp2: /opt/openjp2-svn/lib/libopenjp2.so openjpeg: /not/the/usual/location/lib/libopenjpeg.so -''''''''''''''''''''''''''''''''''''''''''' -Package Management Suggestions for Testing -''''''''''''''''''''''''''''''''''''''''''' +'''''''''''''''''''''''''''''' +Package Management Suggestions +'''''''''''''''''''''''''''''' You only need to read this section if you want detailed platform-specific instructions on running as many tests as possible or wish to @@ -67,8 +69,8 @@ packages/RPMs/ports/whatever without going through pip. Mac OS X -------- -All the necessary packages are available to use glymur with Python 3.3 via -MacPorts. You should install the following set of ports: +All the necessary packages are available to use glymur with Python 2.6, 2.7, +and 3.3 via MacPorts. You should install the following set of ports: * python33 * py33-numpy @@ -80,54 +82,38 @@ MacPorts supplies both OpenJPEG 1.5.0 and OpenJPEG 2.0.0. Linux ----- -For the most part, you only need python and numpy to run glymur. In order to -run as many tests as possible, however, the following Python packages may also -need to be installed. +For the most part, you only need python and numpy to run glymur, so on +just about all distributions you are already set to go (and you don't +need to mess around with a configuration file, as the openjpeg shared +libraries are found in the usual places thanks to your package manager). +In order to run as many tests as possible, however, the following Python +packages may also need to be installed. Consult your package manager +documentation or use pip. * setuptools * matplotlib * pillow - * contextlib2 (python 2.7 only) - * mock (python 2.7 only) + * contextlib2 (python 2.6, 2.7 only) + * mock (python 2.6, 2.7 only) + * ordereddict (python 2.6 only) -OpenSUSE 12.3 -''''''''''''' -Ships with Python 3.3 and 2.7. You should use pip to install Pillow. - -Fedora 19 -''''''''' -Ships with Python 3.3 and 2.7. All packages available as RPMs. - -Fedora 18 -''''''''' -Fedora 18 ships with Python 3.3 and 2.7. Most packages are available as -standard RPMS, but you should use pip to install Pillow as it is not available -in the Fedora 18 default repositories:: - - $ yum install python3-devel # pip needs this in order to compile Pillow - $ yum install python3-pip - $ pip-python3 install Pillow --user - -Fedora 17 -''''''''' -Fedora 17 ships with Python 2.7 and OpenJPEG 1.4. You must install contextlib2 -and Pillow via pip. :: - - $ yum install python-devel # pip needs this in order to compile Pillow - $ pip-python install Pillow --user - $ pip-python install contextlib2 --user +Glymur's been tested on the following linux platforms without any unexpected +difficulties: + + * OpenSUSE 12.3 + * Fedora 17, 18, 19 + * Raspian + * Travis CI (currently Ubuntu 12.04?) + * CentOS 6.4 Windows ------- 32-bit WinPython 2.7.5 seemed to work with OpenJPEG 1.X, 2.0, and the development version, but still required contextlib2 and mock to be installed via pip. WinPython 3.3.2, however, seems to have trouble -with OpenJPEG 2.0, so I would suggest using the development version -there (I'm unwilling to spend ANY more time trying to figure out what -the problem is there). - -At the moment I do not have access to a win32 machine, and -64-bit windows is completely untested. +with OpenJPEG 2.0, so I would suggest using the development version with +that configuration. I no longer have any access to a windows machine, +so I cannot currently offer much guidance here. ''''''' @@ -137,8 +123,8 @@ Testing There are two environment variables you may wish to set before running the tests. - * **OPJ_DATA_ROOT** - points to directory for OpenJPEG test data - * **FORMAT_CORPUS_ROOT** - points to directory for format-corpus repository (see https://github.com/openplanets/format-corpus if you wish, but you really don't need to bother with this) + * **OPJ_DATA_ROOT** - points to directory for OpenJPEG test data (see above) + * **FORMAT_CORPUS_DATA_ROOT** - points to directory for format-corpus repository (see https://github.com/openplanets/format-corpus if you wish, but you really don't need to bother with this) Setting these two environment variables is not required, as any tests using either of them will be skipped. @@ -157,7 +143,7 @@ or from the command line. :: Quite a few tests are currently skipped. These include tests whose OpenJPEG counterparts are already failing, and others which do pass but still produce heaps of output on stderr. Rather than let this swamp -the signal (that most of the tests are actually passing), they've been +the signal (that most of those tests are actually passing), they've been filtered out for now. There are also more skipped tests on Python 2.7 than on Python 3.3. The important part is whether or not any test errors are reported at the end. From fe6c607e67e1b532619462576b89b8ed2d058680 Mon Sep 17 00:00:00 2001 From: John Evans Date: Sun, 15 Sep 2013 12:33:29 -0400 Subject: [PATCH 17/22] Openjpeg 1.3 reads this image as indices, not RGB. #116 --- glymur/test/test_opj_suite.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/glymur/test/test_opj_suite.py b/glymur/test/test_opj_suite.py index 36f0a7b..a5daf3e 100644 --- a/glymur/test/test_opj_suite.py +++ b/glymur/test/test_opj_suite.py @@ -645,7 +645,11 @@ class TestSuite(unittest.TestCase): jfile = opj_data_file('input/conformance/file9.jp2') jp2k = Jp2k(jfile) jpdata = jp2k.read() - self.assertEqual(jpdata.shape, (512, 768, 3)) + if re.match(r"""1\.3""", glymur.version.openjpeg_version): + # Version 1.3 reads the indexed image as indices, not as RGB. + self.assertEqual(jpdata.shape, (512, 768)) + else: + self.assertEqual(jpdata.shape, (512, 768, 3)) def test_NR_DEC_Bretagne2_j2k_1_decode(self): jfile = opj_data_file('input/nonregression/Bretagne2.j2k') From 7622b940739e4b1dd049603a5d7915ea27e41123 Mon Sep 17 00:00:00 2001 From: John Evans Date: Sun, 15 Sep 2013 12:34:00 -0400 Subject: [PATCH 18/22] Fixed typo in error message. #116 --- glymur/jp2k.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glymur/jp2k.py b/glymur/jp2k.py index 03ffc71..00b71c2 100644 --- a/glymur/jp2k.py +++ b/glymur/jp2k.py @@ -949,7 +949,7 @@ class Jp2k(Jp2kBox): If glymur is unable to load the openjp2 library. """ if version.openjpeg_version_tuple[0] < 2: - raise LibraryNotFoundError("You must have at least version 2.0.0" + raise LibraryNotFoundError("You must have at least version 2.0.0 " "of OpenJP2 installed before using " "this functionality.") From bc1421bb19473845f6c7bf382aec51deb4388c18 Mon Sep 17 00:00:00 2001 From: John Evans Date: Mon, 16 Sep 2013 06:33:23 -0400 Subject: [PATCH 19/22] Qualified on 1.3, 1.4. Closes #116 --- glymur/test/test_conformance.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/glymur/test/test_conformance.py b/glymur/test/test_conformance.py index 3c7c9c4..5f53b5f 100644 --- a/glymur/test/test_conformance.py +++ b/glymur/test/test_conformance.py @@ -12,6 +12,7 @@ These tests deal with JPX/JP2/J2K images in the format-corpus repository. import os from os.path import join +import re import sys if sys.hexversion < 0x02070000: @@ -19,6 +20,7 @@ if sys.hexversion < 0x02070000: else: import unittest +import glymur from glymur import Jp2k try: @@ -39,6 +41,9 @@ except KeyError: class TestSuiteFormatCorpus(unittest.TestCase): """Test suite for files in format corpus repository.""" + @unittest.skipIf(re.match(r"""1\.[0123]""", + glymur.version.openjpeg_version) is not None, + "Needs 1.3+ to catch this.") def test_balloon_trunc1(self): """Has one byte shaved off of EOC marker.""" jfile = os.path.join(FORMAT_CORPUS_DATA_ROOT, @@ -54,6 +59,9 @@ class TestSuiteFormatCorpus(unittest.TestCase): with self.assertRaises(OSError): j2k.read(rlevel=-1) + @unittest.skipIf(re.match(r"""1\.[01234]""", + glymur.version.openjpeg_version) is not None, + "Needs 1.4+ to catch this.") def test_balloon_trunc2(self): """Shortened by 5000 bytes.""" jfile = os.path.join(FORMAT_CORPUS_DATA_ROOT, From 8e29ab955868eaae0c67736ba2773da9376fdbeb Mon Sep 17 00:00:00 2001 From: jevans Date: Mon, 16 Sep 2013 19:14:55 -0400 Subject: [PATCH 20/22] Minor doc fixes. --- docs/source/introduction.rst | 5 ++--- docs/source/roadmap.rst | 6 ------ 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/docs/source/introduction.rst b/docs/source/introduction.rst index 0a59ebd..37dcb5a 100644 --- a/docs/source/introduction.rst +++ b/docs/source/introduction.rst @@ -20,7 +20,7 @@ OpenJPEG Installation ===================== Glymur will read JPEG 2000 images with versions 1.3, 1.4, 1.5, 2.0, and the trunk/development version of OpenJPEG. Writing images is -only supported with the 2.0 series, however, and the trunk/development +only supported with the 1.5 or better, however, and the trunk/development version is strongly recommended. For more information about OpenJPEG, please consult http://www.openjpeg.org. @@ -55,6 +55,5 @@ You can run the tests from within python as follows:: >>> import glymur >>> glymur.runtests() -Many tests are currently skipped; in fact most of them are skipped if you -are relying on OpenJPEG 1.X. The important thing, though, is whether or +Many tests are currently skipped, but the The important thing is whether or not any tests fail. diff --git a/docs/source/roadmap.rst b/docs/source/roadmap.rst index 7f50a87..f9216a3 100644 --- a/docs/source/roadmap.rst +++ b/docs/source/roadmap.rst @@ -1,9 +1,3 @@ ------------- -Known Issues ------------- - - * WinPython 3.3.2 and OpenJPEG 2.0 don't seem to want to play well together. If you do not need write support, just use OpenJPEG 1.5 instead. If you do need write support, try the development version of OpenJPEG. - ------- Roadmap ------- From 52ef9cb8ed212215abc8da3f0e9d789c33f743a3 Mon Sep 17 00:00:00 2001 From: jevans Date: Mon, 16 Sep 2013 19:43:37 -0400 Subject: [PATCH 21/22] Releasing 0.5.0. --- CHANGES.txt | 2 +- docs/source/conf.py | 4 ++-- glymur/version.py | 8 ++++---- setup.py | 5 ++++- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 96b8173..35b355e 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,4 @@ -Sep 12, 2013 - v0.4.2r Added write support for 1.5.x. +Sep 16, 2013 - v0.5.0 Added write support for 1.5.x. Added version module. Aug 21, 2013 - v0.4.1 Fixed segfault with openjpeg 1.x when rlevel=-1 diff --git a/docs/source/conf.py b/docs/source/conf.py index c5dccb4..6b9eb18 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -76,9 +76,9 @@ copyright = u'2013, John Evans' # built documents. # # The short X.Y version. -version = '0.4' +version = '0.5' # The full version, including alpha/beta/rc tags. -release = '0.4.1' +release = '0.5.0' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/glymur/version.py b/glymur/version.py index 256ed4e..9b6499d 100644 --- a/glymur/version.py +++ b/glymur/version.py @@ -8,13 +8,13 @@ import sys import numpy as np -from distutils.version import StrictVersion +from distutils.version import LooseVersion from .lib import openjpeg as opj from .lib import openjp2 as opj2 -version = "0.4.1" -_sv = StrictVersion(version) +version = "0.5.0rc2" +_sv = LooseVersion(version) version_tuple = _sv.version @@ -25,7 +25,7 @@ elif opj2.OPENJP2 is None: else: openjpeg_version = opj2.version() -_sv = StrictVersion(openjpeg_version) +_sv = LooseVersion(openjpeg_version) openjpeg_version_tuple = _sv.version __doc__ = """\ diff --git a/setup.py b/setup.py index 8e6233c..8d62705 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,6 @@ from setuptools import setup, find_packages import sys kwargs = {'name': 'Glymur', - 'version': '0.4.1', 'description': 'Tools for accessing JPEG2000 files', 'long_description': open('README.md').read(), 'author': 'John Evans', @@ -38,4 +37,8 @@ clssfrs = ["Programming Language :: Python", "Intended Audience :: Information Technology", "Topic :: Software Development :: Libraries :: Python Modules"] kwargs['classifiers'] = clssfrs + +import glymur +kwargs['version'] = glymur.version.version + setup(**kwargs) From cb523e56542815e296eb563c8bc01da6e85b5d0e Mon Sep 17 00:00:00 2001 From: jevans Date: Mon, 16 Sep 2013 19:44:37 -0400 Subject: [PATCH 22/22] Releasing 0.5.0 --- glymur/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glymur/version.py b/glymur/version.py index 9b6499d..740d610 100644 --- a/glymur/version.py +++ b/glymur/version.py @@ -13,7 +13,7 @@ from distutils.version import LooseVersion from .lib import openjpeg as opj from .lib import openjp2 as opj2 -version = "0.5.0rc2" +version = "0.5.0" _sv = LooseVersion(version) version_tuple = _sv.version