[med-svn] [tifffile] 01/06: New upstream version 20170929

Andreas Tille tille at debian.org
Mon Feb 5 08:33:28 UTC 2018


This is an automated email from the git hooks/post-receive script.

tille pushed a commit to branch master
in repository tifffile.

commit 06ca50a1753985aee3b551f77e47038f27d6f97d
Author: Andreas Tille <tille at debian.org>
Date:   Mon Feb 5 09:24:10 2018 +0100

    New upstream version 20170929
---
 tifffile.c  | 38 +++++++++++++++++++------------
 tifffile.py | 75 ++++++++++++++++++++++++++++++++++++++++---------------------
 2 files changed, 73 insertions(+), 40 deletions(-)

diff --git a/tifffile.c b/tifffile.c
index 655977d..462fbef 100644
--- a/tifffile.c
+++ b/tifffile.c
@@ -5,11 +5,11 @@ Refer to the tifffile.py module for documentation and tests.
   `Christoph Gohlke <http://www.lfd.uci.edu/~gohlke/>`_
 :Organization:
   Laboratory for Fluorescence Dynamics, University of California, Irvine
-:Version: 2017.01.10
+:Version: 2017.10.05
 Requirements
 ------------
-* `CPython 2.7 or 3.5 <http://www.python.org>`_
-* `Numpy 1.11 <http://www.numpy.org>`_
+* `CPython 2.7 or 3.6 <http://www.python.org>`_
+* `Numpy 1.13 <http://www.numpy.org>`_
 * A Python distutils compatible C compiler  (build)
 * `stdint.h <https://github.com/chemeris/msinttypes/>`_ for msvc9 compiler
 Install
@@ -50,7 +50,7 @@ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 POSSIBILITY OF SUCH DAMAGE.
 */
-#define _VERSION_ "2017.01.10"
+#define _VERSION_ "2017.10.05"
 #define WIN32_LEAN_AND_MEAN
 #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
 #include "Python.h"
@@ -562,15 +562,21 @@ py_decodepackbits(PyObject* obj, PyObject* args)
 }
 /** Decode TIFF LZW encoded string. */
 char py_decodelzw_doc[] = "Return TIFF LZW decoded string.";
-/* TODO: fix reading beyond end of encoded */
 #define GET_NEXT_CODE \
-    code = *((uint32_t*)((void*)(encoded + (bitcount >> 3)))); \
-    if (little_endian) \
-        code = SWAP4BYTES(code); \
-    code <<= (uint32_t)(bitcount % 8); \
-    code &= mask; \
-    code >>= shr; \
-    bitcount += bitw; \
+    {  \
+        const uint8_t* bytes = (uint8_t*)((void*)(encoded + (bitcount>>3)));  \
+        code = (uint32_t) bytes[0];  \
+        code <<= 8;  \
+        code |= (uint32_t) bytes[1];  \
+        code <<= 8;  \
+        if ((bitcount + 24) <= encoded_size)  \
+            code |= (uint32_t) bytes[2];  \
+        code <<= 8;  \
+        code <<= (uint32_t)(bitcount % 8);  \
+        code &= mask;  \
+        code >>= shr;  \
+        bitcount += bitw;  \
+    }
 static PyObject*
 py_decodelzw(PyObject* obj, PyObject* args)
 {
@@ -602,9 +608,13 @@ py_decodelzw(PyObject* obj, PyObject* args)
     }
     */
     encoded_size *= 8;  /* bits */
+    if (*encoded == 0) {
+        /* TODO: old style LZW codes are written in reversed bit order */
+        PyErr_Format(PyExc_ValueError, "can not decode old-style LZW");
+        goto _fail;
+    }
     if ((*encoded != -128) || ((*(encoded+1) & 128))) {
-        PyErr_Format(PyExc_ValueError,
-            "strip must begin with CLEAR code");
+        PyErr_Format(PyExc_ValueError, "strip must begin with CLEAR code");
         goto _fail;
     }
     little_endian = (*(uint16_t*)encoded) & 128;
diff --git a/tifffile.py b/tifffile.py
index ba4bbbc..33b77a9 100644
--- a/tifffile.py
+++ b/tifffile.py
@@ -32,12 +32,12 @@
 """Read image and meta data from (bio) TIFF® files. Save numpy arrays as TIFF.
 Image and metadata can be read from TIFF, BigTIFF, OME-TIFF, STK, LSM, NIH,
 SGI, ImageJ, MicroManager, FluoView, SEQ and GEL files.
-Only a subset of the TIFF specification is supported, mainly uncompressed
-and losslessly compressed 2**(0 to 6) bit integer, 16, 32 and 64-bit float,
-grayscale and RGB(A) images, which are commonly used in bio-scientific imaging.
-Specifically, reading JPEG and CCITT compressed image data, chroma subsampling,
-or EXIF, IPTC, and XMP metadata is not implemented. Only primary info
-records are read for STK, FluoView, MicroManager, and NIH Image formats.
+Tifffile is not a general purpose TIFF library. Only a subset of the TIFF
+specification is supported, mainly uncompressed and losslessly compressed
+2**(0 to 6) bit integer, 16, 32 and 64-bit float, grayscale and RGB(A) images,
+which are commonly used in bio-scientific imaging. Specifically, reading image
+trees defined via SubIFDs, JPEG and CCITT compression, chroma subsampling,
+or IPTC and XMP metadata are not implemented.
 TIFF®, the tagged Image File Format, is a trademark and under control of
 Adobe Systems Incorporated. BigTIFF allows for files greater than 4 GB.
 STK, LSM, FluoView, SGI, SEQ, GEL, and OME-TIFF, are custom extensions
@@ -50,7 +50,7 @@ For command line usage run C{python -m tifffile --help}
   `Christoph Gohlke <http://www.lfd.uci.edu/~gohlke/>`_
 :Organization:
   Laboratory for Fluorescence Dynamics, University of California, Irvine
-:Version: 2017.09.14
+:Version: 2017.09.29
 Requirements
 ------------
 * `CPython 3.6 64-bit <http://www.python.org>`_
@@ -60,11 +60,11 @@ Requirements
   (recommended for faster decoding of PackBits and LZW encoded strings)
 Revisions
 ---------
-2017.09.14 (tentative)
+2017.09.29 (tentative)
     Many backwards incompatible changes improving speed and resource usage:
     Pass 2268 tests.
     Add detail argument to __str__ function. Remove info functions.
-    Fix potential bug correcting offsets of large LSM files with positions.
+    Fix potential issue correcting offsets of large LSM files with positions.
     Remove TiffFile iterator interface; use TiffFile.pages instead.
     Do not make tag values available as TiffPage attributes.
     Use str (not bytes) type for tag and metadata strings (WIP).
@@ -247,7 +247,6 @@ Notes
 -----
 The API is not stable yet and might change between revisions.
 Tested on little-endian platforms only.
-TIFF trees defined via sub_ifds tags are not supported.
 Other Python packages and modules for reading bio-scientific TIFF files:
 *  `python-bioformats <https://github.com/CellProfiler/python-bioformats>`_
 *  `Imread <https://github.com/luispedro/imread>`_
@@ -261,7 +260,7 @@ Other Python packages and modules for reading bio-scientific TIFF files:
 Acknowledgements
 ----------------
 *   Egor Zindy, University of Manchester, for lsm_scan_info specifics.
-*   Wim Lewis for a bug fix and some read_lsm functions.
+*   Wim Lewis for a bug fix and some LSM functions.
 *   Hadrien Mary for help on reading MicroManager files.
 *   Christian Kliche for help writing tiled and color-mapped files.
 References
@@ -289,10 +288,12 @@ References
     http://www.cipa.jp/std/documents/e/DC-008-Translation-2016-E.pdf
 Examples
 --------
+>>> # write and read numpy array
 >>> data = numpy.random.rand(5, 301, 219)
 >>> imsave('temp.tif', data)
 >>> image = imread('temp.tif')
 >>> numpy.testing.assert_array_equal(image, data)
+>>> # iterate over pages and tags
 >>> with TiffFile('temp.tif') as tif:
 ...     images = tif.asarray()
 ...     for page in tif.pages:
@@ -329,7 +330,7 @@ except ImportError:
         import backports.lzma as lzma
     except ImportError:
         lzma = None
-__version__ = '2017.09.14'
+__version__ = '2017.09.29'
 __docformat__ = 'restructuredtext en'
 __all__ = (
     'imsave', 'imread', 'imshow', 'memmap',
@@ -352,10 +353,12 @@ def imread(files, **kwargs):
         The first image series is returned if no arguments are provided.
     Examples
     --------
+    >>> # get image from first page
     >>> imsave('temp.tif', numpy.random.rand(3, 4, 301, 219))
     >>> im = imread('temp.tif', key=0)
     >>> im.shape
     (4, 301, 219)
+    >>> # get images from sequence of files
     >>> ims = imread(['temp.tif', 'temp.tif'])
     >>> ims.shape
     (2, 3, 4, 301, 219)
@@ -407,6 +410,10 @@ def imsave(file, data=None, shape=None, dtype=None, bigsize=2**32-2**25,
     of image data in the file.
     Examples
     --------
+    >>> # save a RGB image
+    >>> data = numpy.random.randint(0, 255, (256, 256, 3), 'uint8')
+    >>> imsave('temp.tif', data, photometric='rgb')
+    >>> # save a random array and metadata, using compression
     >>> data = numpy.random.rand(2, 5, 3, 301, 219)
     >>> imsave('temp.tif', data, compress=6, metadata={'axes': 'TZCYX'})
     """
@@ -455,12 +462,14 @@ def memmap(filename, shape=None, dtype=None, page=None, series=0, mode='r+',
         Additional parameters passed to imsave() or TiffFile().
     Examples
     --------
+    >>> # create an empty TIFF file and write to memory-mapped image
     >>> im = memmap('temp.tif', shape=(256, 256), dtype='float32')
     >>> im[255, 255] = 1.0
     >>> im.flush()
     >>> im.shape, im.dtype
     ((256, 256), dtype('float32'))
     >>> del im
+    >>> # memory-map image data in a TIFF file
     >>> im = memmap('temp.tif', page=0)
     >>> im[255, 255]
     1.0
@@ -517,8 +526,12 @@ class TiffWriter(object):
     """Write numpy arrays to TIFF file.
     TiffWriter instances must be closed using the 'close' method, which is
     automatically called when using the 'with' context manager.
+    TiffWriter's main purpose is saving nD numpy array's as TIFF,
+    not to create any possible TIFF format. Specifically, JPEG compression,
+    SubIFDs, ExifIFD, or GPSIFD tags are not supported.
     Examples
     --------
+    >>> # successively append images to BigTIFF file
     >>> data = numpy.random.rand(2, 5, 3, 301, 219)
     >>> with TiffWriter('temp.tif', bigtiff=True) as tif:
     ...     for i in range(data.shape[0]):
@@ -527,9 +540,9 @@ class TiffWriter(object):
     def __init__(self, file, bigtiff=False, byteorder=None,
                  software='tifffile.py', append=False, imagej=False):
         """Open a TIFF file for writing.
-        An empty TIFF file is created if the file does not exist, else the file
-        is overwritten unless 'append' is true.
-        Use bigtiff=True when creating files larger than 4 GB.
+        An empty TIFF file is created if the file does not exist, else the
+        file is overwritten with an empty empty TIFF file unless 'append'
+        is true. Use bigtiff=True when creating files larger than 4 GB.
         Parameters
         ----------
         file : str, binary stream, or FileHandle
@@ -1374,13 +1387,13 @@ class TiffWriter(object):
     def __exit__(self, exc_type, exc_value, traceback):
         self.close()
 class TiffFile(object):
-    """Read image and metadata from TIFF, STK, LSM, and FluoView files.
+    """Read image and metadata from TIFF file.
     TiffFile instances must be closed using the 'close' method, which is
     automatically called when using the 'with' context manager.
     Attributes
     ----------
     pages : TiffPages
-        Sequence of TIFF pages from file.
+        Sequence of TIFF pages in file.
     series : list of TiffPageSeries
         Sequences of closely related TIFF pages. These are computed
         from OME, LSM, ImageJ, etc. metadata or based on similarity
@@ -1397,10 +1410,11 @@ class TiffFile(object):
     All attributes are read-only.
     Examples
     --------
+    >>> # read image array from TIFF file
     >>> imsave('temp.tif', numpy.random.rand(5, 301, 219))
     >>> with TiffFile('temp.tif') as tif:
     ...     data = tif.asarray()
-    ...     data.shape
+    >>> data.shape
     (5, 301, 219)
     """
     def __init__(self, arg, name=None, offset=None, size=None,
@@ -3643,8 +3657,8 @@ class TiffPageSeries(object):
             ('Offset=%i' % self.offset) if self.offset else '') if s)
         return 'TiffPageSeries %i  %s' % (self.index, s)
 class TiffSequence(object):
-    """Sequence of image files.
-    The data in all files must match.
+    """Sequence of TIFF files.
+    The image data in all files must match shape, dtype, etc.
     Attributes
     ----------
     files : list
@@ -3655,6 +3669,7 @@ class TiffSequence(object):
         Labels of axes in shape.
     Examples
     --------
+    >>> # read image stack from sequence of TIFF files
     >>> imsave('temp_C001T001.tif', numpy.random.rand(64, 64))
     >>> imsave('temp_C001T002.tif', numpy.random.rand(64, 64))
     >>> tifs = TiffSequence("temp_C001*.tif")
@@ -3736,7 +3751,7 @@ class TiffSequence(object):
     def close(self):
         pass
     def asarray(self, out=None, *args, **kwargs):
-        """Read image data from all files and return as single numpy array.
+        """Read image data from all files and return as numpy array.
         The args and kwargs parameters are passed to the imread function.
         Raise IndexError or ValueError if image shapes do not match.
         """
@@ -5616,7 +5631,8 @@ class TIFF(object):
     PRINT_LINE_WIDTH = 100
     # Max number of lines to print
     PRINT_MAX_LINES = 512
-def read_tags(fh, byteorder, offsetsize, tagnames, customtags=None):
+def read_tags(fh, byteorder, offsetsize, tagnames,
+              customtags=None, maxifds=None):
     """Read tags from chain of IFDs and return as list of dicts.
     The file handle position must be at a valid IFD header.
     """
@@ -5638,10 +5654,12 @@ def read_tags(fh, byteorder, offsetsize, tagnames, customtags=None):
         raise ValueError("invalid offset size")
     if customtags is None:
         customtags = {}
+    if maxifds is None:
+        maxifds = 2**32
     result = []
     unpack = struct.unpack
     offset = fh.tell()
-    while True:
+    while len(result) < maxifds:
         # loop over IFDs
         try:
             tagno = unpack(tagnoformat, fh.read(tagnosize))[0]
@@ -5697,17 +5715,22 @@ def read_tags(fh, byteorder, offsetsize, tagnames, customtags=None):
             warnings.warn("invalid page offset (%i)" % offset)
             break
         fh.seek(offset)
+    if maxifds == 1:
+        result = result[0]
     return result
 def read_exif_ifd(fh, byteorder, dtype, count, offsetsize):
     """Read EXIF tags from file and return as dict."""
-    return read_tags(fh, byteorder, offsetsize, TIFF.EXIF_TAGS)
+    tags = read_tags(fh, byteorder, offsetsize, TIFF.EXIF_TAGS, maxifds=1)
+    if 'ExifVersion' in tags:
+        tags['ExifVersion'] = bytes2str(tags['ExifVersion'])
+    return tags
 def read_gps_ifd(fh, byteorder, dtype, count, offsetsize):
     """Read GPS tags from file and return as dict."""
-    return read_tags(fh, byteorder, offsetsize, TIFF.GPS_TAGS)
+    return read_tags(fh, byteorder, offsetsize, TIFF.GPS_TAGS, maxifds=1)
 def read_interoperability_ifd(fh, byteorder, dtype, count, offsetsize):
     """Read Interoperability tags from file and return as dict."""
     tag_names = {1: 'InteroperabilityIndex'}
-    return read_tags(fh, byteorder, offsetsize, tag_names)
+    return read_tags(fh, byteorder, offsetsize, tag_names, maxifds=1)
 def read_bytes(fh, byteorder, dtype, count, offsetsize):
     """Read tag data from file and return as byte string."""
     dtype = 'b' if dtype[-1] == 's' else byteorder+dtype[-1]

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/tifffile.git



More information about the debian-med-commit mailing list