Upgrade tifffile

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