From 093f9c49fb46dd76e81e68683311576f23c6c376 Mon Sep 17 00:00:00 2001 From: jevans Date: Sat, 15 Mar 2014 22:09:49 -0400 Subject: [PATCH] Got 2.0.0 working again. #139 --- glymur/jp2k.py | 3 ++- glymur/lib/openjp2.py | 22 +++++++++++++++++----- glymur/test/test_opj_suite.py | 4 +++- glymur/test/test_opj_suite_write.py | 1 - 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/glymur/jp2k.py b/glymur/jp2k.py index 1239821..5d39ed5 100644 --- a/glymur/jp2k.py +++ b/glymur/jp2k.py @@ -20,6 +20,7 @@ from collections import Counter import ctypes import math import os +import re import struct from uuid import UUID import warnings @@ -166,7 +167,7 @@ class Jp2k(Jp2kBox): fps : int Frames per second, should be either 24 or 48. """ - if version.openjpeg_version_tuple[0] == 1: + if re.match("(1.5|2.0)", version.openjpeg_version) is not None: msg = "Writing Cinema2K or Cinema4K files is not supported with " msg += 'openjpeg library versions less than 2.0.1.' raise IOError(msg) diff --git a/glymur/lib/openjp2.py b/glymur/lib/openjp2.py index 39dd5a4..2da8d75 100644 --- a/glymur/lib/openjp2.py +++ b/glymur/lib/openjp2.py @@ -10,6 +10,20 @@ import sys from .config import glymur_config OPENJP2, OPENJPEG = glymur_config() +def version(): + """Wrapper for opj_version library routine.""" + OPENJP2.opj_version.restype = ctypes.c_char_p + library_version = OPENJP2.opj_version() + if sys.hexversion >= 0x03000000: + return library_version.decode('utf-8') + else: + return library_version + +if OPENJP2 is not None: + _MAJOR, _MINOR, _PATCH = version().split('.') +else: + _MINOR = 0 + ERROR_MSG_LST = [] # Map certain atomic OpenJPEG datatypes to the ctypes equivalents. @@ -391,12 +405,10 @@ class ImageCompType(ctypes.Structure): ("factor", ctypes.c_uint32), # image component data - ("data", ctypes.POINTER(ctypes.c_int32)), - - # alpha channel - # TODO: exclude for 2.0, 1.5 - ("alpha", ctypes.c_uint16)] + ("data", ctypes.POINTER(ctypes.c_int32))] + if _MINOR == '1': + _fields_.append(("alpha", ctypes.c_uint16)) class ImageType(ctypes.Structure): """Defines image data and characteristics. diff --git a/glymur/test/test_opj_suite.py b/glymur/test/test_opj_suite.py index 5cc9250..28e9a0f 100644 --- a/glymur/test/test_opj_suite.py +++ b/glymur/test/test_opj_suite.py @@ -461,7 +461,9 @@ class TestSuite(unittest.TestCase): def test_NR_DEC_illegalcolortransform_j2k_14_decode(self): # Stream too short, expected SOT. jfile = opj_data_file('input/nonregression/illegalcolortransform.j2k') - Jp2k(jfile).read() + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + Jp2k(jfile).read() self.assertTrue(True) def test_NR_DEC_j2k32_j2k_15_decode(self): diff --git a/glymur/test/test_opj_suite_write.py b/glymur/test/test_opj_suite_write.py index 91afd8d..c92c500 100644 --- a/glymur/test/test_opj_suite_write.py +++ b/glymur/test/test_opj_suite_write.py @@ -222,7 +222,6 @@ class TestSuiteWriteCinema(unittest.TestCase): codestream = j.get_codestream() self.check_cinema2k_codestream(codestream, (1998, 1080)) - @unittest.skipIf(not _HAS_SKIMAGE_FREEIMAGE_SUPPORT, "Cannot read input image without scikit-image/freeimage") @unittest.skipIf(os.name == "nt", "Temporary file issue on window.")