diff --git a/glymur/test/test_opj_suite_write.py b/glymur/test/test_opj_suite_write.py index eb113ee..5b1e349 100644 --- a/glymur/test/test_opj_suite_write.py +++ b/glymur/test/test_opj_suite_write.py @@ -27,45 +27,7 @@ from . import fixtures from glymur import Jp2k import glymur -@unittest.skipIf(NO_SKIMAGE_FREEIMAGE_SUPPORT, - "Cannot read input image without scikit-image/freeimage") -@unittest.skipIf(os.name == "nt", "no write support on windows, period") -@unittest.skipIf(re.match(r'''(1|2.0.0)''', - glymur.version.openjpeg_version) is not None, - "Uses features not supported until 2.0.1") -@unittest.skipIf(OPJ_DATA_ROOT is None, - "OPJ_DATA_ROOT environment variable not set") -class TestSuiteWriteCinema(unittest.TestCase): - """Tests for writing with openjp2 backend. - - These tests either roughly correspond with those tests with similar names - in the OpenJPEG test suite or are closely associated. - """ - def setUp(self): - pass - - def tearDown(self): - pass - - def test_cinema2K_with_others(self): - """Can't specify cinema2k with any other options.""" - relfile = 'input/nonregression/X_5_2K_24_235_CBR_STEM24_000.tif' - infile = opj_data_file(relfile) - data = skimage.io.imread(infile) - with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile: - j = Jp2k(tfile.name, 'wb') - with self.assertRaises(IOError): - j.write(data, cinema2k=48, cratios=[200, 100, 50]) - - def test_cinema4K_with_others(self): - """Can't specify cinema4k with any other options.""" - relfile = 'input/nonregression/ElephantDream_4K.tif' - infile = opj_data_file(relfile) - data = skimage.io.imread(infile) - with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile: - j = Jp2k(tfile.name, 'wb') - with self.assertRaises(IOError): - j.write(data, cinema4k=True, cratios=[200, 100, 50]) +class CinemaBase(unittest.TestCase): def check_cinema4k_codestream(self, codestream, image_size): """Common out for cinema2k tests.""" @@ -151,7 +113,57 @@ class TestSuiteWriteCinema(unittest.TestCase): - @unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG) +@unittest.skipIf(NO_SKIMAGE_FREEIMAGE_SUPPORT, + "Cannot read input image without scikit-image/freeimage") +@unittest.skipIf(os.name == "nt", "no write support on windows, period") +@unittest.skipIf(re.match(r'''(1|2.0.0)''', + glymur.version.openjpeg_version) is not None, + "Uses features not supported until 2.0.1") +@unittest.skipIf(OPJ_DATA_ROOT is None, + "OPJ_DATA_ROOT environment variable not set") +class WriteCinema(CinemaBase): + """Tests for writing with openjp2 backend. + + These tests either roughly correspond with those tests with similar names + in the OpenJPEG test suite or are closely associated. + """ + def test_cinema2K_with_others(self): + """Can't specify cinema2k with any other options.""" + relfile = 'input/nonregression/X_5_2K_24_235_CBR_STEM24_000.tif' + infile = opj_data_file(relfile) + data = skimage.io.imread(infile) + with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile: + j = Jp2k(tfile.name, 'wb') + with self.assertRaises(IOError): + j.write(data, cinema2k=48, cratios=[200, 100, 50]) + + def test_cinema4K_with_others(self): + """Can't specify cinema4k with any other options.""" + relfile = 'input/nonregression/ElephantDream_4K.tif' + infile = opj_data_file(relfile) + data = skimage.io.imread(infile) + with tempfile.NamedTemporaryFile(suffix='.j2k') as tfile: + j = Jp2k(tfile.name, 'wb') + with self.assertRaises(IOError): + j.write(data, cinema4k=True, cratios=[200, 100, 50]) + + +@unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG) +@unittest.skipIf(NO_SKIMAGE_FREEIMAGE_SUPPORT, + "Cannot read input image without scikit-image/freeimage") +@unittest.skipIf(os.name == "nt", "no write support on windows, period") +@unittest.skipIf(re.match(r'''(1|2.0.0)''', + glymur.version.openjpeg_version) is not None, + "Uses features not supported until 2.0.1") +@unittest.skipIf(OPJ_DATA_ROOT is None, + "OPJ_DATA_ROOT environment variable not set") +class WriteCinemaWarns(CinemaBase): + """Tests for writing with openjp2 backend. + + These tests either roughly correspond with those tests with similar names + in the OpenJPEG test suite or are closely associated. These tests issue + warnings. + """ def test_NR_ENC_ElephantDream_4K_tif_21_encode(self): relfile = 'input/nonregression/ElephantDream_4K.tif' infile = opj_data_file(relfile) @@ -166,8 +178,6 @@ class TestSuiteWriteCinema(unittest.TestCase): codestream = j.get_codestream() self.check_cinema4k_codestream(codestream, (4096, 2160)) - - @unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG) def test_NR_ENC_X_5_2K_24_235_CBR_STEM24_000_tif_19_encode(self): relfile = 'input/nonregression/X_5_2K_24_235_CBR_STEM24_000.tif' infile = opj_data_file(relfile) @@ -180,8 +190,6 @@ class TestSuiteWriteCinema(unittest.TestCase): codestream = j.get_codestream() self.check_cinema2k_codestream(codestream, (2048, 857)) - - @unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG) def test_NR_ENC_X_6_2K_24_FULL_CBR_CIRCLE_000_tif_20_encode(self): relfile = 'input/nonregression/X_6_2K_24_FULL_CBR_CIRCLE_000.tif' infile = opj_data_file(relfile) @@ -194,8 +202,6 @@ class TestSuiteWriteCinema(unittest.TestCase): codestream = j.get_codestream() self.check_cinema2k_codestream(codestream, (2048, 1080)) - - @unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG) def test_NR_ENC_X_6_2K_24_FULL_CBR_CIRCLE_000_tif_17_encode(self): relfile = 'input/nonregression/X_6_2K_24_FULL_CBR_CIRCLE_000.tif' infile = opj_data_file(relfile) @@ -208,8 +214,6 @@ class TestSuiteWriteCinema(unittest.TestCase): codestream = j.get_codestream() self.check_cinema2k_codestream(codestream, (2048, 1080)) - - @unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG) def test_NR_ENC_X_5_2K_24_235_CBR_STEM24_000_tif_16_encode(self): relfile = 'input/nonregression/X_5_2K_24_235_CBR_STEM24_000.tif' infile = opj_data_file(relfile) @@ -224,8 +228,6 @@ class TestSuiteWriteCinema(unittest.TestCase): codestream = j.get_codestream() self.check_cinema2k_codestream(codestream, (2048, 857)) - - @unittest.skipIf(WARNING_INFRASTRUCTURE_ISSUE, WARNING_INFRASTRUCTURE_MSG) def test_NR_ENC_X_4_2K_24_185_CBR_WB_000_tif_18_encode(self): relfile = 'input/nonregression/X_4_2K_24_185_CBR_WB_000.tif' infile = opj_data_file(relfile) @@ -241,6 +243,7 @@ class TestSuiteWriteCinema(unittest.TestCase): codestream = j.get_codestream() self.check_cinema2k_codestream(codestream, (1998, 1080)) + @unittest.skipIf(NO_SKIMAGE_FREEIMAGE_SUPPORT, "Cannot read input image without scikit-image/freeimage") @unittest.skipIf(os.name == "nt", "Temporary file issue on window.") diff --git a/glymur/test/test_printing.py b/glymur/test/test_printing.py index ea47a14..49bbe6d 100644 --- a/glymur/test/test_printing.py +++ b/glymur/test/test_printing.py @@ -882,155 +882,6 @@ class TestPrintingOpjDataRootWarns(unittest.TestCase): actual = fake_out.getvalue().strip() self.assertEqual(actual, fixtures.issue_186_progression_order) - def test_crg(self): - """verify printing of CRG segment""" - 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: - print(codestream.segment[-5]) - actual = fake_out.getvalue().strip() - lines = ['CRG marker segment @ (87, 6)', - ' Vertical, Horizontal offset: (0.50, 1.00)'] - expected = '\n'.join(lines) - self.assertEqual(actual, expected) - - def test_rgn(self): - """verify printing of RGN segment""" - 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: - print(codestream.segment[12]) - actual = fake_out.getvalue().strip() - lines = ['RGN marker segment @ (310, 5)', - ' Associated component: 0', - ' ROI style: 0', - ' Parameter: 7'] - expected = '\n'.join(lines) - self.assertEqual(actual, expected) - - def test_sop(self): - """verify printing of SOP segment""" - 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: - print(codestream.segment[-2]) - actual = fake_out.getvalue().strip() - lines = ['SOP marker segment @ (12836, 4)', - ' Nsop: 15'] - expected = '\n'.join(lines) - self.assertEqual(actual, expected) - - def test_cme(self): - """Test printing a CME or comment marker segment.""" - 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 - with patch('sys.stdout', new=StringIO()) as fake_out: - print(codestream.segment[-2]) - actual = fake_out.getvalue().strip() - lines = ['CME marker segment @ (85, 45)', - ' "Creator: AV-J2K (c) 2000,2001 Algo Vision"'] - expected = '\n'.join(lines) - self.assertEqual(actual, expected) - - def test_plt_segment(self): - """verify printing of PLT segment""" - 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: - print(codestream.segment[49935]) - actual = fake_out.getvalue().strip() - - lines = ['PLT marker segment @ (7871146, 38)', - ' Index: 0', - ' Iplt: [9, 122, 19, 30, 27, 9, 41, 62, 18, 29, 261,' - + ' 55, 82, 299, 93, 941, 951, 687, 1729, 1443, 1008, 2168,' - + ' 2188, 2223]'] - expected = '\n'.join(lines) - self.assertEqual(actual, expected) - - def test_pod_segment(self): - """verify printing of POD segment""" - 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: - print(codestream.segment[8]) - actual = fake_out.getvalue().strip() - - lines = ['POD marker segment @ (878, 20)', - ' Progression change 0:', - ' Resolution index start: 0', - ' Component index start: 0', - ' Layer index end: 1', - ' Resolution index end: 33', - ' Component index end: 128', - ' Progression order: RLCP', - ' Progression change 1:', - ' Resolution index start: 0', - ' Component index start: 128', - ' Layer index end: 1', - ' Resolution index end: 33', - ' Component index end: 257', - ' Progression order: CPRL'] - - expected = '\n'.join(lines) - self.assertEqual(actual, expected) - - def test_ppm_segment(self): - """verify printing of PPM segment""" - 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: - print(codestream.segment[9]) - actual = fake_out.getvalue().strip() - - lines = ['PPM marker segment @ (213, 43712)', - ' Index: 0', - ' Data: 43709 uninterpreted bytes'] - - expected = '\n'.join(lines) - self.assertEqual(actual, expected) - - def test_ppt_segment(self): - """verify printing of ppt segment""" - 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: - print(codestream.segment[6]) - actual = fake_out.getvalue().strip() - - lines = ['PPT marker segment @ (155, 109)', - ' Index: 0', - ' Packet headers: 106 uninterpreted bytes'] - - expected = '\n'.join(lines) - self.assertEqual(actual, expected) - - def test_tlm_segment(self): - """verify printing of TLM segment""" - 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: - print(codestream.segment[10]) - actual = fake_out.getvalue().strip() - - lines = ['TLM marker segment @ (268, 28)', - ' Index: 0', - ' Tile number: (0, 1, 2, 3)', - ' Length: (4267, 2117, 4080, 2081)'] - - expected = '\n'.join(lines) - self.assertEqual(actual, expected) - def test_xml(self): """verify printing of XML box""" filename = opj_data_file('input/conformance/file1.jp2') @@ -1072,17 +923,6 @@ class TestPrintingOpjDataRootWarns(unittest.TestCase): expected = '\n'.join(lines) self.assertEqual(actual, expected) - def test_componentmapping_box_alpha(self): - """Verify __repr__ method on cmap box.""" - cmap = glymur.jp2box.ComponentMappingBox(component_index=(0, 0, 0), - mapping_type=(1, 1, 1), - palette_index=(0, 1, 2)) - newbox = eval(repr(cmap)) - self.assertEqual(newbox.box_id, 'cmap') - self.assertEqual(newbox.component_index, (0, 0, 0)) - self.assertEqual(newbox.mapping_type, (1, 1, 1)) - self.assertEqual(newbox.palette_index, (0, 1, 2)) - def test_palette7(self): """verify printing of pclr box""" filename = opj_data_file('input/conformance/file9.jp2') @@ -1106,27 +946,6 @@ class TestPrintingOpjDataRootWarns(unittest.TestCase): actual = fake_out.getvalue().strip() self.assertEqual(actual, fixtures.text_GBR_rreq) - def test_differing_subsamples(self): - """verify printing of SIZ with different subsampling... Issue 86.""" - 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: - print(codestream.segment[1]) - actual = fake_out.getvalue().strip() - lines = ['SIZ marker segment @ (2, 50)', - ' Profile: 0', - ' Reference Grid Height, Width: (1024 x 1024)', - ' Vertical, Horizontal Reference Grid Offset: (0 x 0)', - ' Reference Tile Height, Width: (1024 x 1024)', - ' Vertical, Horizontal Reference Tile Offset: (0 x 0)', - ' Bitdepth: (8, 8, 8, 8)', - ' Signed: (False, False, False, False)', - ' Vertical, Horizontal Subsampling: ' - + '((1, 1), (1, 1), (2, 2), (2, 2))'] - expected = '\n'.join(lines) - self.assertEqual(actual, expected) - def test_palette_box(self): """Verify that palette (pclr) boxes are printed without error.""" filename = opj_data_file('input/conformance/file9.jp2')