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 diff --git a/CHANGES.txt b/CHANGES.txt index 8a4fe86..9a71f81 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,5 @@ +Aug 21, 2013 - v0.4.1 Fixed segfault with openjpeg 1.x when rlevel=-1 + Aug 18, 2013 - v0.4.0 Added append method. Aug 15, 2013 - v0.3.2 Fixed test bug where missing Pillow package caused test diff --git a/docs/source/conf.py b/docs/source/conf.py index fb2a685..c5dccb4 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -78,7 +78,7 @@ copyright = u'2013, John Evans' # The short X.Y version. version = '0.4' # The full version, including alpha/beta/rc tags. -release = '0.4.0' +release = '0.4.1' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/docs/source/detailed_installation.rst b/docs/source/detailed_installation.rst index 126efaa..dab4c3f 100644 --- a/docs/source/detailed_installation.rst +++ b/docs/source/detailed_installation.rst @@ -137,13 +137,14 @@ In addition, you must install contextlib2 and Pillow via pip. :: Windows ------- -32-bit WinPython 2.7.5 seems to work with OpenJPEG 1.X, 2.0, and the -development version, but still requires contextlib2 and mock to be +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. diff --git a/docs/source/how_do_i.rst b/docs/source/how_do_i.rst index 110ca81..cc0b227 100644 --- a/docs/source/how_do_i.rst +++ b/docs/source/how_do_i.rst @@ -55,8 +55,7 @@ Consider the following XML file `data.xml` : :: -The **append** method can add an XML box (only XML boxes are currently -allowed):: +The **append** method can add an XML box as shown below:: >>> import shutil >>> import glymur @@ -108,8 +107,8 @@ two additional boxes (image header and color specification) contained in the JP2 header superbox. XML boxes are not in the minimal set of box requirements for the JP2 format, so -in order to add an XML box into the mix, we'll need to specify all of the -boxes. If you already have a JP2 jacket in place, you can just reuse it, +in order to add an XML box into the mix before the codestream box, we'll need to +re-specify all of the boxes. If you already have a JP2 jacket in place, you can just reuse that, though. Take the following example content in an XML file `favorites.xml` : :: @@ -117,7 +116,8 @@ though. Take the following example content in an XML file `favorites.xml` : :: Light Ale -and add it after the JP2 header box, but before the codestream box :: +In order to add the XML after the JP2 header box, but before the codestream box, +the following will work. :: >>> boxes = jp2.box # The box attribute is the list of JP2 boxes >>> xmlbox = glymur.jp2box.XMLBox(filename='favorites.xml') diff --git a/glymur/test/fixtures.py b/glymur/test/fixtures.py index eec9e22..933222a 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 @@ -9,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 @@ -27,6 +30,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..edefb7f 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. @@ -130,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() @@ -169,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.""" @@ -368,669 +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(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 = os.path.join(DATA_ROOT, '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 @@ -1039,7 +946,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 +954,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() @@ -1059,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""" @@ -1297,91 +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('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) @@ -1426,6 +1100,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..3c6b5d2 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,14 @@ 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 +from .fixtures import OPENJPEG_VERSION, OPENJP2_IS_V2_OFFICIAL, OPJ_DATA_ROOT +from .fixtures import mse, peak_tolerance, read_pgx, opj_data_file -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(data_root is None, +@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): @@ -72,92 +63,64 @@ 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') - jp2k = Jp2k(jfile) - jpdata = jp2k.read_bands(rlevel=3) - - pgxfile = os.path.join(data_root, - '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') - jp2k = Jp2k(jfile) - jpdata = jp2k.read_bands(rlevel=3) - - pgxfile = os.path.join(data_root, - '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 = 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 +128,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,142 +151,119 @@ 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') - jp2k = Jp2k(jfile) - jpdata = jp2k.read_bands(rlevel=3) - - pgxfile = os.path.join(data_root, - '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 = 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 +272,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 +285,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 +299,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 +313,298 @@ 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') - jp2k = Jp2k(jfile) - jpdata = jp2k.read_bands() - - pgxfile = os.path.join(data_root, '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') - 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') - 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') - 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') - jp2k = Jp2k(jfile) - jpdata = jp2k.read_bands() - - pgxfile = os.path.join(data_root, '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') - 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') - 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') - 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') - jp2k = Jp2k(jfile) - jpdata = jp2k.read(rlevel=0) - - pgxfile = os.path.join(data_root, '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') - pgxdata = read_pgx(pgxfile) - np.testing.assert_array_equal(jpdata[:, :, 1], pgxdata) - - pgxfile = os.path.join(data_root, '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') - jp2k = Jp2k(jfile) - jpdata = jp2k.read_bands() - - pgxfile = os.path.join(data_root, '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') - 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') - 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') - 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)) + @unittest.skipIf(re.match(r"""1\.[0125]\.\d""", OPENJPEG_VERSION), + "Functionality not implemented for 1.x") 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 +612,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 +669,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) @@ -836,20 +677,10 @@ class TestSuite(unittest.TestCase): jp2.read() self.assertTrue(True) - def test_NR_DEC_broken2_jp2_5_decode(self): - # Null pointer access - jfile = os.path.join(data_root, '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): - 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) @@ -857,116 +688,88 @@ class TestSuite(unittest.TestCase): with self.assertRaises(IOError): j.read() - def test_NR_DEC_broken4_jp2_7_decode(self): - jfile = os.path.join(data_root, '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 = 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') - 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('input/nonregression/j2k32.j2k') 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') - 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,393 +777,28 @@ 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') - 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 = 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') - 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') - 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') - 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') - 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 = os.path.join(data_root, - '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) - 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 = os.path.join(data_root, '/'.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 = os.path.join(data_root, 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") - 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) - 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 = os.path.join(data_root, '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(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 = os.path.join(data_root, 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') - 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') - 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') - 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') - 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') - 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') - 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') - 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') - 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') - 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 = os.path.join(data_root, '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') - 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') - 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') - 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') - 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') - 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') - 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') - 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') - 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') - 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 = os.path.join(data_root, '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 = os.path.join(data_root, '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 = os.path.join(data_root, '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 = os.path.join(data_root, '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 = os.path.join(data_root, '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 = os.path.join(data_root, '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 = os.path.join(data_root, '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 = os.path.join(data_root, '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 = os.path.join(data_root, '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') - 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') - 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') - 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') - 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') - 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') - 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 +806,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 +814,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 +824,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 +835,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 +844,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 +853,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 +862,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 +872,12 @@ 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') - 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') - 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') - 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') - 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') - 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') - 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') - 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') - 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') - 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') - 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') - 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') - 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 +888,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 +955,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 +1061,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 +1178,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 +1286,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 +1430,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 +1567,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 +1652,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 +1805,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 +1885,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 +2026,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 +2107,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 +2189,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 +2315,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 +2391,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 +2545,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 +2613,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 +2713,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 +2827,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 +2974,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 +3101,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 +3189,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 +3282,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 +3375,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 +3425,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 +3472,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 +3519,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 +3561,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 +3610,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 +3654,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 +3710,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 +3764,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 +3823,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 +3976,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 +4033,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 +4086,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 +4143,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 +4204,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 +4275,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 +4350,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 +4411,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 +4478,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 +4563,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 +4622,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 +4679,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 +4736,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 +4793,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 +4853,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 +4913,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 +4981,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 +5050,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 +5112,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 +5174,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 +5247,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 +5374,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 +5383,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 +5510,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 +5618,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 +5626,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 +5636,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 +5646,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 +5765,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 +5863,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 +5963,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 +6076,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 +6193,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 +6307,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 +6411,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 +6510,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 +6609,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") @@ -7389,23 +6720,14 @@ 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(data_root is None, - "OPJ_DATA_ROOT environment variable not set") -class TestSuite15(unittest.TestCase): - """Suite of tests for libopenjpeg 1.5.1""" +@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 - @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 + The deal here is that the feature works with 1.x, but glymur only supports + it with version 2.0. + """ def setUp(self): pass @@ -7413,625 +6735,607 @@ class TestSuite15(unittest.TestCase): def tearDown(self): pass - def test_ETS_C0P0_p0_01_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p0_01.j2k') + def test_ETS_C0P0_p0_05_j2k(self): + jfile = opj_data_file('input/conformance/p0_05.j2k') jp2k = Jp2k(jfile) - jpdata = jp2k.read(rlevel=0) + jpdata = jp2k.read_bands(rlevel=3) - pgxfile = os.path.join(data_root, 'baseline/conformance/c0p0_01.pgx') + pgxfile = opj_data_file('baseline/conformance/c0p0_05.pgx') pgxdata = read_pgx(pgxfile) - np.testing.assert_array_equal(jpdata, pgxdata) + self.assertTrue(peak_tolerance(jpdata[0], pgxdata) < 54) + self.assertTrue(mse(jpdata[0], pgxdata) < 68) - def test_ETS_C0P0_p0_02_j2k(self): - jfile = os.path.join(data_root, '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 = os.path.join(data_root, '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') + @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(rlevel=2) + jpdata = jp2k.read_bands(rlevel=3) - pgxfile = os.path.join(data_root, - 'baseline/conformance/c0p0_09.pgx') + 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) - 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') + def test_ETS_C0P1_p1_03_j2k(self): + jfile = opj_data_file('input/conformance/p1_03.j2k') jp2k = Jp2k(jfile) - jpdata = jp2k.read(rlevel=0) + jpdata = jp2k.read_bands(rlevel=3) - pgxfile = os.path.join(data_root, - 'baseline/conformance/c0p0_11.pgx') + pgxfile = opj_data_file('baseline/conformance/c0p1_03.pgx') pgxdata = read_pgx(pgxfile) - np.testing.assert_array_equal(jpdata, pgxdata) + self.assertTrue(peak_tolerance(jpdata[0], pgxdata) < 28) + self.assertTrue(mse(jpdata[0], pgxdata) < 18.8) - @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') + def test_ETS_C1P1_p1_03_j2k(self): + jfile = opj_data_file('input/conformance/p1_03.j2k') jp2k = Jp2k(jfile) - jpdata = jp2k.read(rlevel=0) + jpdata = jp2k.read_bands() - pgxfile = os.path.join(data_root, - 'baseline/conformance/c0p0_12.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) - np.testing.assert_array_equal(jpdata, pgxdata) + 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) - def test_ETS_C0P0_p0_16_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p0_16.j2k') + 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(rlevel=0) + jpdata = jp2k.read_bands() - pgxfile = os.path.join(data_root, - 'baseline/conformance/c0p0_16.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) - np.testing.assert_array_equal(jpdata, pgxdata) + 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) - def test_ETS_C0P1_p1_01_j2k(self): - jfile = os.path.join(data_root, 'input/conformance/p1_01.j2k') + 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(rlevel=0) + jpdata = jp2k.read_bands() - pgxfile = os.path.join(data_root, - 'baseline/conformance/c0p1_01.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) - 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') - 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_06_1.pgx') pgxdata = read_pgx(pgxfile) + self.assertTrue(peak_tolerance(jpdata[1], pgxdata) < 403) + self.assertTrue(mse(jpdata[1], pgxdata) < 6124) - 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') - 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 = os.path.join(data_root, 'baseline/conformance/c1p0_02_0.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) - 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') - 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_06_3.pgx') pgxdata = read_pgx(pgxfile) + self.assertTrue(peak_tolerance(jpdata[3], pgxdata) == 0) + self.assertTrue(mse(jpdata[3], pgxdata) == 0) - np.testing.assert_array_equal(jpdata, pgxdata) + 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_ETS_C1P0_p0_04_j2k(self): - jfile = os.path.join(data_root, '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') - pgxdata = read_pgx(pgxfile) - self.assertTrue(peak_tolerance(jpdata[:, :, 0], pgxdata) < 5) - self.assertTrue(mse(jpdata[:, :, 0], pgxdata) < 0.776) +@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""" - pgxfile = os.path.join(data_root, '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) + def setUp(self): + pass - pgxfile = os.path.join(data_root, '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') - jp2k = Jp2k(jfile) - jpdata = jp2k.read(rlevel=1) - - pgxfile = os.path.join(data_root, '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') - pgxdata = read_pgx(pgxfile) - np.testing.assert_array_equal(jpdata[:, :, 1], pgxdata) - - pgxfile = os.path.join(data_root, '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') - jp2k = Jp2k(jfile) - jpdata = jp2k.read(rlevel=0) - - pgxfile = os.path.join(data_root, 'baseline/conformance/c1p0_09_0.pgx') - pgxdata = read_pgx(pgxfile) - np.testing.assert_array_equal(jpdata, pgxdata) + def tearDown(self): + pass 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) + 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') - jp2k = Jp2k(jfile) - jpdata = jp2k.read(rlevel=0) - - pgxfile = os.path.join(data_root, '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') - jp2k = Jp2k(jfile) - jpdata = jp2k.read(rlevel=0) - - pgxfile = os.path.join(data_root, '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') - jp2k = Jp2k(jfile) - jpdata = jp2k.read(rlevel=0) - - pgxfile = os.path.join(data_root, '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') - pgxdata = read_pgx(pgxfile) - np.testing.assert_array_equal(jpdata[:, :, 1], pgxdata) - - pgxfile = os.path.join(data_root, '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') - 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') - jp2k = Jp2k(jfile) - jpdata = jp2k.read(rlevel=0) - - pgxfile = os.path.join(data_root, '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') - pgxdata = read_pgx(pgxfile) - np.testing.assert_array_equal(jpdata[:, :, 1], pgxdata) - - pgxfile = os.path.join(data_root, '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') - jp2k = Jp2k(jfile) - jpdata = jp2k.read(rlevel=0) - - pgxfile = os.path.join(data_root, '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') - jp2k = Jp2k(jfile) - jpdata = jp2k.read(rlevel=0) - - pgxfile = os.path.join(data_root, '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') - jp2k = Jp2k(jfile) - jpdata = jp2k.read(rlevel=0) - - pgxfile = os.path.join(data_root, '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') - jp2k = Jp2k(jfile) - jpdata = jp2k.read(rlevel=0) - - pgxfile = os.path.join(data_root, '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') - 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') - 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') - jp2k = Jp2k(jfile) - jpdata = jp2k.read() - - pgxfile = os.path.join(data_root, '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') - jp2k = Jp2k(jfile) - jpdata = jp2k.read() - - pgxfile = os.path.join(data_root, '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') - 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') - 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') - jp2k = Jp2k(jfile) - jpdata = jp2k.read() - - pgxfile = os.path.join(data_root, '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') - 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') - 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') - 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') - 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') - 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') - 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') - 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') - 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') - 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') - 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 = os.path.join(data_root, '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') - 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 = os.path.join(data_root, '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 = os.path.join(data_root, '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 = os.path.join(data_root, 'input/nonregression/broken2.jp2') - with self.assertRaises(ValueError): + jfile = opj_data_file('input/nonregression/broken2.jp2') + with self.assertRaises(IOError): with warnings.catch_warnings(): - # Library warning, invalid number of subbands. + # 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): - """NR_DEC_broken3_jp2_6_decode""" - jfile = os.path.join(data_root, '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 = os.path.join(data_root, 'input/nonregression/broken4.jp2') - with self.assertRaises(ValueError): + jfile = opj_data_file('input/nonregression/broken4.jp2') + with self.assertRaises(IOError): with warnings.catch_warnings(): - # Library warning, invalid number of subbands. + # 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): - """NR_DEC_bug_j2c_8_decode""" - jfile = os.path.join(data_root, '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') - 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') - 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) - 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') - 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) - 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') - 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') - 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""" + # 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 = os.path.join(data_root, relpath) + 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(): - # This file has an invalid ICC profile + # brand is 'jp2 ', but has any icc profile. warnings.simplefilter("ignore") - Jp2k(jfile).read() + jp2 = Jp2k(jfile) + jp2.read() self.assertTrue(True) - 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') + 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_Marrin_jp2_18_decode(self): - """NR_DEC_Marrin_jp2_18_decode""" - jfile = os.path.join(data_root, 'input/nonregression/Marrin.jp2') + 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_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') - 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') - 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') - 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') - 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') - 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') + 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 an invalid ICC profile + # This file has a bad pclr box, we test for this elsewhere. warnings.simplefilter("ignore") - Jp2k(jfile).read() + j = Jp2k(jfile) + j.read() self.assertTrue(True) - 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') + 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_relax_jp2_27_decode(self): - """NR-DEC-relax.jp2-27-decode""" - jfile = os.path.join(data_root, - 'input/nonregression/relax.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_test_lossless_j2k_28_decode(self): - """NR-DEC-test-lossless.j2k-28-decode""" - jfile = os.path.join(data_root, - 'input/nonregression/test_lossless.j2k') - Jp2k(jfile).read() - self.assertTrue(True) + 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_issue104_jpxstream_jp2_33_decode(self): - """NR-DEC-issue104-jpxstream.jp2-33-decode""" - jfile = os.path.join(data_root, - 'input/nonregression/issue104_jpxstream.jp2') - Jp2k(jfile).read() - self.assertTrue(True) + 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): - """NR-DEC-file-409752.jp2-40-decode""" - jfile = os.path.join(data_root, 'input/nonregression/file409752.jp2') - j = Jp2k(jfile) + def test_NR_DEC_file_409752_jp2_40_decode(self): + jfile = opj_data_file('input/nonregression/file409752.jp2') with self.assertRaises(RuntimeError): - j.read() + 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() 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") diff --git a/setup.py b/setup.py index 6249662..ff533a7 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup, find_packages import sys kwargs = {'name': 'Glymur', - 'version': '0.4.0', + 'version': '0.4.1', 'description': 'Tools for accessing JPEG2000 files', 'long_description': open('README.md').read(), 'author': 'John Evans',