From 47b8dad0038bb7edff8cd067110fd0c7b4d87f6c Mon Sep 17 00:00:00 2001 From: John Evans Date: Sat, 8 Mar 2014 07:46:12 -0500 Subject: [PATCH] Check for supplying cinema2k/4k with other options. #139 --- glymur/jp2k.py | 4 ++++ glymur/test/test_opj_suite_write.py | 25 +++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/glymur/jp2k.py b/glymur/jp2k.py index e861053..d17195d 100644 --- a/glymur/jp2k.py +++ b/glymur/jp2k.py @@ -422,6 +422,10 @@ class Jp2k(Jp2kBox): Either CLRSPC_SRGB or CLRSPC_GRAY """ + if ('cinema2k' in kwargs or 'cinema4k' in kwargs) and len(set(kwargs)) > 1: + msg = "Cannot specify cinema2k/cinema4k along with other options." + raise IOError(msg) + if 'cratios' in kwargs and 'psnr' in kwargs: msg = "Cannot specify cratios and psnr together." raise IOError(msg) diff --git a/glymur/test/test_opj_suite_write.py b/glymur/test/test_opj_suite_write.py index 0e7f2d3..6539e21 100644 --- a/glymur/test/test_opj_suite_write.py +++ b/glymur/test/test_opj_suite_write.py @@ -35,8 +35,8 @@ import glymur class TestSuiteWrite(unittest.TestCase): """Tests for writing with openjp2 backend. - These tests roughly correspond with those tests with similar names in the - OpenJPEG test suite. + These tests either roughly correspond with those tests with similar names + in the OpenJPEG test suite or are closely associated. """ def setUp(self): pass @@ -44,6 +44,26 @@ class TestSuiteWrite(unittest.TestCase): 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]) + def check_cinema4k_codestream(self, codestream, image_size): """Common out for cinema2k tests.""" # SIZ: Image and tile size @@ -1052,5 +1072,6 @@ class TestSuiteWrite(unittest.TestCase): glymur.core.WAVELET_XFORM_5X3_REVERSIBLE) self.assertEqual(len(codestream.segment[2].spcod), 9) + if __name__ == "__main__": unittest.main()