From 2e6fcd4dd82789c697b293cd7612fdddf3a61a3f Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Fri, 18 Mar 2016 23:15:40 -0500 Subject: [PATCH] Upgrade tifffile --- skimage/external/test_tifffile.py | 4 +- skimage/external/tifffile/tifffile.c | 67 ++++++++++++++++----------- skimage/external/tifffile/tifffile.py | 39 +++++++--------- 3 files changed, 58 insertions(+), 52 deletions(-) diff --git a/skimage/external/test_tifffile.py b/skimage/external/test_tifffile.py index 537b2ea3..fcd158ee 100644 --- a/skimage/external/test_tifffile.py +++ b/skimage/external/test_tifffile.py @@ -34,9 +34,9 @@ def test_imread_uint16_big_endian(): def test_extension(): - from .tifffile.tifffile import decodelzw + from .tifffile.tifffile import decode_packbits import types - assert isinstance(decodelzw, types.BuiltinFunctionType), type(decodelzw) + assert isinstance(decode_packbits, types.BuiltinFunctionType), type(decode_packbits) class TestSave: diff --git a/skimage/external/tifffile/tifffile.c b/skimage/external/tifffile/tifffile.c index 6aa0eaa1..56300589 100644 --- a/skimage/external/tifffile/tifffile.c +++ b/skimage/external/tifffile/tifffile.c @@ -1,5 +1,3 @@ - - /* tifffile.c A Python C extension module for decoding PackBits and LZW encoded TIFF data. @@ -12,7 +10,13 @@ Refer to the tifffile.py module for documentation and tests. :Organization: Laboratory for Fluorescence Dynamics, University of California, Irvine -:Version: 2013.11.05 +:Version: 2015.08.17 + +Requirements +------------ +* `CPython 2.7 or 3.4 `_ +* `Numpy 1.9.2 `_ +* A Python distutils compatible C compiler (build) Install ------- @@ -28,8 +32,8 @@ Use this Python distutils setup script to build the extension module:: License ------- -Copyright (c) 2008-2014, Christoph Gohlke -Copyright (c) 2008-2014, The Regents of the University of California +Copyright (c) 2008-2015, Christoph Gohlke +Copyright (c) 2008-2015, The Regents of the University of California Produced at the Laboratory for Fluorescence Dynamics All rights reserved. @@ -58,7 +62,7 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#define _VERSION_ "2013.11.05" +#define _VERSION_ "2015.08.17" #define WIN32_LEAN_AND_MEAN #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION @@ -83,7 +87,7 @@ POSSIBILITY OF SUCH DAMAGE. #define NO_ERROR 0 #define VALUE_ERROR -1 -#ifdef _MSC_VER +#if defined(_MSC_VER) && _MSC_VER < 1600 typedef unsigned __int8 uint8_t; typedef unsigned __int16 uint16_t; typedef unsigned __int32 uint32_t; @@ -92,12 +96,10 @@ typedef unsigned __int64 uint64_t; typedef __int64 ssize_t; typedef signed __int64 intptr_t; typedef unsigned __int64 uintptr_t; -#define SSIZE_MAX (9223372036854775808) #else typedef int ssize_t; typedef _W64 signed int intptr_t; typedef _W64 unsigned int uintptr_t; -#define SSIZE_MAX (2147483648) #endif #else /* non MS compilers */ @@ -105,6 +107,14 @@ typedef _W64 unsigned int uintptr_t; #include #endif +#ifndef SSIZE_MAX +#ifdef _WIN64 +#define SSIZE_MAX (9223372036854775808L) +#else +#define SSIZE_MAX (2147483648) +#endif +#endif + #define SWAP2BYTES(x) \ ((((x) >> 8) & 0x00FF) | (((x) & 0x00FF) << 8)) @@ -641,7 +651,7 @@ py_decodelzw(PyObject *obj, PyObject *args) table_len = 258; bitw = 9; shr = 23; - mask = 4286578688; + mask = 4286578688u; bitcount = 0; result_len = 0; code = 0; @@ -673,16 +683,19 @@ py_decodelzw(PyObject *obj, PyObject *args) } bitw = 9; shr = 23; - mask = 4286578688; + mask = 4286578688u; - /* read next code */ - code = *((unsigned int *)((void *)(encoded + (bitcount / 8)))); - if (little_endian) - code = SWAP4BYTES(code); - code <<= bitcount % 8; - code &= mask; - code >>= shr; - bitcount += bitw; + /* read next code, skip clearcodes */ + /* TODO: bounds checking */ + do { + code = *((unsigned int *)((void *)(encoded + (bitcount / 8)))); + if (little_endian) + code = SWAP4BYTES(code); + code <<= bitcount % 8; + code &= mask; + code >>= shr; + bitcount += bitw; + } while (code == 256); if (code == 257) /* end of information */ break; @@ -760,17 +773,17 @@ py_decodelzw(PyObject *obj, PyObject *args) case 511: bitw = 10; shr = 22; - mask = 4290772992; + mask = 4290772992u; break; case 1023: bitw = 11; shr = 21; - mask = 4292870144; + mask = 4292870144u; break; case 2047: bitw = 12; shr = 20; - mask = 4293918720; + mask = 4293918720u; } } @@ -868,12 +881,12 @@ char module_doc[] = static PyMethodDef module_methods[] = { #if MSB - {"unpackints", (PyCFunction)py_unpackints, METH_VARARGS|METH_KEYWORDS, + {"unpack_ints", (PyCFunction)py_unpackints, METH_VARARGS|METH_KEYWORDS, py_unpackints_doc}, #endif - {"decodelzw", (PyCFunction)py_decodelzw, METH_VARARGS, + {"decode_lzw", (PyCFunction)py_decodelzw, METH_VARARGS, py_decodelzw_doc}, - {"decodepackbits", (PyCFunction)py_decodepackbits, METH_VARARGS, + {"decode_packbits", (PyCFunction)py_decodepackbits, METH_VARARGS, py_decodepackbits_doc}, {NULL, NULL, 0, NULL} /* Sentinel */ }; @@ -925,7 +938,8 @@ init_tifffile(void) PyObject *module; char *doc = (char *)PyMem_Malloc(sizeof(module_doc) + sizeof(_VERSION_)); - PyOS_snprintf(doc, sizeof(doc), module_doc, _VERSION_); + PyOS_snprintf(doc, sizeof(module_doc) + sizeof(_VERSION_), + module_doc, _VERSION_); #if PY_MAJOR_VERSION >= 3 moduledef.m_doc = doc; @@ -959,4 +973,3 @@ init_tifffile(void) return module; #endif } - diff --git a/skimage/external/tifffile/tifffile.py b/skimage/external/tifffile/tifffile.py index d4025112..4bd46f54 100644 --- a/skimage/external/tifffile/tifffile.py +++ b/skimage/external/tifffile/tifffile.py @@ -254,17 +254,13 @@ except ImportError: lzma = None try: - if __package__: - from . import _tifffile - else: - import _tifffile + from . import _tifffile except ImportError: warnings.warn( "failed to import the optional _tifffile C extension module.\n" - "Loading of some compressed images will be very slow.\n" + "Loading of some compressed images will be slow.\n" "Tifffile.c can be obtained at http://www.lfd.uci.edu/~gohlke/") - __version__ = '2016.02.22' __docformat__ = 'restructuredtext en' __all__ = ( @@ -3010,11 +3006,11 @@ class TiffSequence(object): Examples -------- - >>> tifs = TiffSequence("test.oif.files/*.tif") - >>> tifs.shape, tifs.axes + >>> tifs = TiffSequence("test.oif.files/*.tif") # doctest: +SKIP + >>> tifs.shape, tifs.axes # doctest: +SKIP ((2, 100), 'CT') - >>> data = tifs.asarray() - >>> data.shape + >>> data = tifs.asarray() # doctest: +SKIP + >>> data.shape # doctest: +SKIP (2, 100, 256, 256) """ @@ -3999,24 +3995,21 @@ def image_description(shape, colormaped=False, **metadata): def _replace_by(module_function, package=__package__, warn=False): """Try replace decorated function by module.function.""" - try: - from importlib import import_module - except ImportError: - warnings.warn('could not import module importlib') - return lambda func: func - def decorate(func, module_function=module_function, warn=warn): try: - module, function = module_function.split('.') - if package: - module = import_module('.' + module, package=package) + modname, function = module_function.split('.') + if package is None: + full_name = modname else: - module = import_module(module) - func, oldfunc = getattr(module, function), func + full_name = package + '.' + modname + if modname == '_tifffile': + func, oldfunc = getattr(_tifffile, function), func + else: + module = __import__(full_name, fromlist=[modname]) + func, oldfunc = getattr(module, function), func globals()['__old_' + func.__name__] = oldfunc except Exception: - if warn: - warnings.warn("failed to import %s" % module_function) + warnings.warn("failed to import %s" % module_function) return func return decorate