From 8577c55d2293d4fc00724369ed4b98d65ac6a5c4 Mon Sep 17 00:00:00 2001 From: John Evans Date: Sat, 13 Jul 2013 15:29:58 -0400 Subject: [PATCH] Closes #74 --- docs/source/introduction.rst | 8 ++++---- glymur/lib/config.py | 7 ------- glymur/lib/openjpeg.py | 28 +++++++++++++++++++--------- glymur/lib/test/test_openjpeg.py | 18 +++++++++++++----- release.txt | 4 ++-- 5 files changed, 38 insertions(+), 27 deletions(-) diff --git a/docs/source/introduction.rst b/docs/source/introduction.rst index 40725d9..ffe21f7 100644 --- a/docs/source/introduction.rst +++ b/docs/source/introduction.rst @@ -18,9 +18,9 @@ Glymur works on Python 2.6, 2.7, and 3.3. Python 3.3 is strongly recommended. OpenJPEG Installation ===================== -The OpenJPEG library version must be either 1.5.1 or the trunk/development -version of OpenJPEG. Version 2.0.0 or versions earlier than 1.5.0 -are not supported. Furthermore, the 1.5.x version of OpenJPEG is +The OpenJPEG library version must be either 1.4, 1.5, or the trunk/development +version of OpenJPEG. Version 2.0.0 or versions earlier than 1.4.0 +are not supported. Furthermore, the 1.4 and 1.5 versions of OpenJPEG are currently only utilized for read-only purposes. For more information about OpenJPEG, please consult http://www.openjpeg.org. @@ -56,5 +56,5 @@ You can run the tests from within python as follows:: >>> glymur.runtests() Many tests are currently skipped; in fact most of them are skipped if you -are relying on OpenJPEG 1.5.1. But the important thing, though, is whether or +are relying on OpenJPEG 1.4 or 1.5. But the important thing, though, is whether or not any tests fail. diff --git a/glymur/lib/config.py b/glymur/lib/config.py index fc0e4cb..e6f87de 100644 --- a/glymur/lib/config.py +++ b/glymur/lib/config.py @@ -67,13 +67,6 @@ def load_openjpeg(libopenjpeg_path): except OSError: openjpeg_lib = None - if openjpeg_lib is not None: - # Must be at least 1.5.0 - openjpeg_lib.opj_version.restype = ctypes.c_char_p - version = openjpeg_lib.opj_version().decode('utf-8') - _, minor, _ = version.split('.') - if minor != '5': - openjpeg_lib = None return openjpeg_lib diff --git a/glymur/lib/openjpeg.py b/glymur/lib/openjpeg.py index ef16c0a..6a984b9 100644 --- a/glymur/lib/openjpeg.py +++ b/glymur/lib/openjpeg.py @@ -4,6 +4,7 @@ # pylint: disable=R0903 import ctypes +import sys from .config import glymur_config _, OPENJPEG = glymur_config() @@ -11,6 +12,20 @@ _, OPENJPEG = glymur_config() PATH_LEN = 4096 # maximum allowed size for filenames +def version(): + """Wrapper for opj_version library routine.""" + OPENJPEG.opj_version.restype = ctypes.c_char_p + library_version = OPENJPEG.opj_version() + if sys.hexversion >= 0x03000000: + return library_version.decode('utf-8') + else: + return library_version + +# Need to get the minor version, make sure we are at least at 1.4.x +#import pdb; pdb.set_trace() +_minor = version().split('.')[1] + + class EventMgrType(ctypes.Structure): """Message handler object. @@ -86,8 +101,10 @@ class DecompressionParametersType(ctypes.Structure): ("jpwl_max_tiles", ctypes.c_int), # cp_limit_decoding: whether decoding should be done on the # entire codestream or be limited to the main header - ("cp_limit_decoding", ctypes.c_int), - ("flags", ctypes.c_uint)] + ("cp_limit_decoding", ctypes.c_int)] + + if _minor != '4': + _fields_.append(("flags", ctypes.c_uint)) class ImageCompType(ctypes.Structure): @@ -204,10 +221,3 @@ def setup_decoder(dinfo, dparams): ctypes.POINTER(DecompressionParametersType)] OPENJPEG.opj_setup_decoder.argtypes = argtypes OPENJPEG.opj_setup_decoder(dinfo, dparams) - - -def version(): - """Wrapper for opj_version library routine.""" - OPENJPEG.opj_version.restype = ctypes.c_char_p - library_version = OPENJPEG.opj_version() - return library_version.decode('utf-8') diff --git a/glymur/lib/test/test_openjpeg.py b/glymur/lib/test/test_openjpeg.py index 1487866..aed03f2 100644 --- a/glymur/lib/test/test_openjpeg.py +++ b/glymur/lib/test/test_openjpeg.py @@ -1,5 +1,6 @@ #pylint: disable-all import ctypes +import re import sys if sys.hexversion < 0x02070000: @@ -21,13 +22,18 @@ class TestOpenJPEG(unittest.TestCase): pass def test_version(self): - v = glymur.lib._openjpeg.version() - parts = v.split('.') - self.assertEqual(parts[0], '1') - self.assertEqual(parts[1], '5') + version = glymur.lib._openjpeg.version() + regex = re.compile('1.[45].[0-9]') + if sys.hexversion <= 0x03020000: + self.assertRegexpMatches(version, regex) + else: + self.assertRegex(version, regex) def test_set_default_decoder_parameters(self): # Verify that we properly set the default decode parameters. + version = glymur.lib._openjpeg.version() + minor = int(version.split('.')[1]) + dp = glymur.lib._openjpeg.DecompressionParametersType() glymur.lib._openjpeg.set_default_decoder_parameters(ctypes.byref(dp)) @@ -41,4 +47,6 @@ class TestOpenJPEG(unittest.TestCase): self.assertEqual(dp.jpwl_exp_comps, 0) self.assertEqual(dp.jpwl_max_tiles, 0) self.assertEqual(dp.cp_limit_decoding, 0) - self.assertEqual(dp.flags, 0) + if minor > 4: + # Introduced in 1.5.x + self.assertEqual(dp.flags, 0) diff --git a/release.txt b/release.txt index 4f2b068..4ad8693 100644 --- a/release.txt +++ b/release.txt @@ -21,8 +21,8 @@ | Fedora 18 | | X | Ships with 1.5.1. 167 of 445 tests | | | | | should pass. | +------------+------------+------------+--------------------------------------+ -| Fedora 17 | X | | Ships with 1.4. Should error out | -| | | | gracefully. | +| Fedora 17 | X | | Ships with 1.4.0. 167 of 445 tests | +| | | | should pass. | +------------+------------+------------+--------------------------------------+ Pylint on entire package should be at least 0.95.