Skip to content

Commit

Permalink
Upgrade tifffile
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 committed Mar 19, 2016
1 parent cc5d574 commit 2e6fcd4
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 53 deletions.
4 changes: 2 additions & 2 deletions skimage/external/test_tifffile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
69 changes: 41 additions & 28 deletions skimage/external/tifffile/tifffile.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


/* tifffile.c
A Python C extension module for decoding PackBits and LZW encoded TIFF data.
Expand All @@ -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 <http://www.python.org>`_
* `Numpy 1.9.2 <http://www.numpy.org>`_
* A Python distutils compatible C compiler (build)
Install
-------
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -92,19 +96,25 @@ 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 */
#include <stdint.h>
#include <limits.h>
#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))

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -673,16 +683,19 @@ py_decodelzw(PyObject *obj, PyObject *args)
}
bitw = 9;
shr = 23;
mask = 4286578688;

/* 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;
mask = 4286578688u;

/* 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;
Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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 */
};
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -959,4 +973,3 @@ init_tifffile(void)
return module;
#endif
}

39 changes: 16 additions & 23 deletions skimage/external/tifffile/tifffile.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,17 +254,13 @@
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__ = (
Expand Down Expand Up @@ -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)
"""
Expand Down Expand Up @@ -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:
full_name = package + '.' + modname
if modname == '_tifffile':
func, oldfunc = getattr(_tifffile, function), func
else:
module = import_module(module)
func, oldfunc = getattr(module, function), func
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
Expand Down

0 comments on commit 2e6fcd4

Please sign in to comment.