[LIBTIFF] Update to version 4.0.10. CORE-15854
authorThomas Faber <thomas.faber@reactos.org>
Mon, 11 Mar 2019 19:33:40 +0000 (20:33 +0100)
committerThomas Faber <thomas.faber@reactos.org>
Tue, 26 Mar 2019 09:14:47 +0000 (10:14 +0100)
57 files changed:
dll/3rdparty/libtiff/CMakeLists.txt
dll/3rdparty/libtiff/mkg3states.c
dll/3rdparty/libtiff/tif_aux.c
dll/3rdparty/libtiff/tif_close.c
dll/3rdparty/libtiff/tif_codec.c
dll/3rdparty/libtiff/tif_color.c
dll/3rdparty/libtiff/tif_compress.c
dll/3rdparty/libtiff/tif_dir.c
dll/3rdparty/libtiff/tif_dirinfo.c
dll/3rdparty/libtiff/tif_dirread.c
dll/3rdparty/libtiff/tif_dirwrite.c
dll/3rdparty/libtiff/tif_dumpmode.c
dll/3rdparty/libtiff/tif_error.c
dll/3rdparty/libtiff/tif_extension.c
dll/3rdparty/libtiff/tif_fax3.c
dll/3rdparty/libtiff/tif_flush.c
dll/3rdparty/libtiff/tif_getimage.c
dll/3rdparty/libtiff/tif_jbig.c
dll/3rdparty/libtiff/tif_jpeg.c
dll/3rdparty/libtiff/tif_luv.c
dll/3rdparty/libtiff/tif_lzma.c
dll/3rdparty/libtiff/tif_lzw.c
dll/3rdparty/libtiff/tif_next.c
dll/3rdparty/libtiff/tif_ojpeg.c
dll/3rdparty/libtiff/tif_open.c
dll/3rdparty/libtiff/tif_packbits.c
dll/3rdparty/libtiff/tif_pixarlog.c
dll/3rdparty/libtiff/tif_predict.c
dll/3rdparty/libtiff/tif_print.c
dll/3rdparty/libtiff/tif_read.c
dll/3rdparty/libtiff/tif_stream.cxx
dll/3rdparty/libtiff/tif_strip.c
dll/3rdparty/libtiff/tif_swab.c
dll/3rdparty/libtiff/tif_thunder.c
dll/3rdparty/libtiff/tif_tile.c
dll/3rdparty/libtiff/tif_unix.c
dll/3rdparty/libtiff/tif_version.c
dll/3rdparty/libtiff/tif_warning.c
dll/3rdparty/libtiff/tif_webp.c [new file with mode: 0644]
dll/3rdparty/libtiff/tif_win32.c
dll/3rdparty/libtiff/tif_write.c
dll/3rdparty/libtiff/tif_zip.c
dll/3rdparty/libtiff/tif_zstd.c [new file with mode: 0644]
media/doc/3rd Party Files.txt
sdk/include/reactos/libs/libtiff/t4.h
sdk/include/reactos/libs/libtiff/tif_config.wince.h
sdk/include/reactos/libs/libtiff/tif_dir.h
sdk/include/reactos/libs/libtiff/tif_fax3.h
sdk/include/reactos/libs/libtiff/tif_predict.h
sdk/include/reactos/libs/libtiff/tiff.h
sdk/include/reactos/libs/libtiff/tiffconf.h
sdk/include/reactos/libs/libtiff/tiffconf.vc.h
sdk/include/reactos/libs/libtiff/tiffconf.wince.h
sdk/include/reactos/libs/libtiff/tiffio.h
sdk/include/reactos/libs/libtiff/tiffio.hxx
sdk/include/reactos/libs/libtiff/tiffiop.h
sdk/include/reactos/libs/libtiff/tiffvers.h

index 6c28292..476e2b1 100644 (file)
@@ -47,9 +47,11 @@ list(APPEND SOURCE
     tif_tile.c
     tif_version.c
     tif_warning.c
     tif_tile.c
     tif_version.c
     tif_warning.c
+    #tif_webp.c
     tif_win32.c
     tif_write.c
     tif_zip.c
     tif_win32.c
     tif_write.c
     tif_zip.c
+    #tif_zstd.c
     precomp.h)
 
 add_library(libtiff SHARED ${SOURCE} libtiff.def)
     precomp.h)
 
 add_library(libtiff SHARED ${SOURCE} libtiff.def)
index 16ad3c2..54fc059 100644 (file)
@@ -1,5 +1,3 @@
-/* "$Id: mkg3states.c,v 1.12 2015-06-21 01:09:09 bfriesen Exp $ */
-
 /*
  * Copyright (c) 1991-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
 /*
  * Copyright (c) 1991-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
index 1f29630..f70f533 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id: tif_aux.c,v 1.31 2017-11-17 20:21:00 erouault Exp $ */
-
 /*
  * Copyright (c) 1991-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
 /*
  * Copyright (c) 1991-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
index fffae4a..4b0ea59 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id: tif_close.c,v 1.21 2016-01-23 21:20:34 erouault Exp $ */
-
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
index 136a483..693cedb 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id: tif_codec.c,v 1.17 2015-08-19 02:31:04 bfriesen Exp $ */
-
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
@@ -73,6 +71,12 @@ static int NotConfigured(TIFF*, int);
 #ifndef LZMA_SUPPORT
 #define TIFFInitLZMA NotConfigured
 #endif
 #ifndef LZMA_SUPPORT
 #define TIFFInitLZMA NotConfigured
 #endif
+#ifndef ZSTD_SUPPORT
+#define TIFFInitZSTD NotConfigured
+#endif
+#ifndef WEBP_SUPPORT
+#define TIFFInitWebP NotConfigured
+#endif
 
 /*
  * Compression schemes statically built into the library.
 
 /*
  * Compression schemes statically built into the library.
@@ -100,6 +104,8 @@ TIFFCodec _TIFFBuiltinCODECS[] = {
     { "SGILog",                COMPRESSION_SGILOG,     TIFFInitSGILog },
     { "SGILog24",      COMPRESSION_SGILOG24,   TIFFInitSGILog },
     { "LZMA",          COMPRESSION_LZMA,       TIFFInitLZMA },
     { "SGILog",                COMPRESSION_SGILOG,     TIFFInitSGILog },
     { "SGILog24",      COMPRESSION_SGILOG24,   TIFFInitSGILog },
     { "LZMA",          COMPRESSION_LZMA,       TIFFInitLZMA },
+    { "ZSTD",          COMPRESSION_ZSTD,       TIFFInitZSTD },
+    { "WEBP",          COMPRESSION_WEBP,       TIFFInitWebP },
     { NULL,             0,                      NULL }
 };
 
     { NULL,             0,                      NULL }
 };
 
index 54d542c..592c6c1 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id: tif_color.c,v 1.24 2017-05-29 10:12:54 erouault Exp $ */
-
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
@@ -168,7 +166,7 @@ TIFFCIELabToRGBInit(TIFFCIELabToRGB* cielab,
 }
 
 /* 
 }
 
 /* 
- * Convert color value from the YCbCr space to CIE XYZ.
+ * Convert color value from the YCbCr space to RGB.
  * The colorspace conversion algorithm comes from the IJG v5a code;
  * see below for more information on how it works.
  */
  * The colorspace conversion algorithm comes from the IJG v5a code;
  * see below for more information on how it works.
  */
index ce3a73f..bba6dea 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id: tif_compress.c,v 1.25 2016-10-25 20:04:22 erouault Exp $ */
-
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
index e38bb23..66c4079 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id: tif_dir.c,v 1.131 2017-07-11 21:38:04 erouault Exp $ */
-
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
@@ -863,14 +861,24 @@ _TIFFVGetField(TIFF* tif, uint32 tag, va_list ap)
        const TIFFField* fip = TIFFFindField(tif, tag, TIFF_ANY);
        if( fip == NULL ) /* cannot happen since TIFFGetField() already checks it */
            return 0;
        const TIFFField* fip = TIFFFindField(tif, tag, TIFF_ANY);
        if( fip == NULL ) /* cannot happen since TIFFGetField() already checks it */
            return 0;
+
+       /*
+        * We want to force the custom code to be used for custom
+        * fields even if the tag happens to match a well known 
+        * one - important for reinterpreted handling of standard
+        * tag values in custom directories (i.e. EXIF) 
+        */
+       if (fip->field_bit == FIELD_CUSTOM) {
+               standard_tag = 0;
+       }
        
        
-        if( tag == TIFFTAG_NUMBEROFINKS )
+        if( standard_tag == TIFFTAG_NUMBEROFINKS )
         {
             int i;
             for (i = 0; i < td->td_customValueCount; i++) {
                 uint16 val;
                 TIFFTagValue *tv = td->td_customValues + i;
         {
             int i;
             for (i = 0; i < td->td_customValueCount; i++) {
                 uint16 val;
                 TIFFTagValue *tv = td->td_customValues + i;
-                if (tv->info->field_tag != tag)
+                if (tv->info->field_tag != standard_tag)
                     continue;
                 if( tv->value == NULL )
                     return 0;
                     continue;
                 if( tv->value == NULL )
                     return 0;
@@ -892,16 +900,6 @@ _TIFFVGetField(TIFF* tif, uint32 tag, va_list ap)
             return 0;
         }
 
             return 0;
         }
 
-       /*
-        * We want to force the custom code to be used for custom
-        * fields even if the tag happens to match a well known 
-        * one - important for reinterpreted handling of standard
-        * tag values in custom directories (i.e. EXIF) 
-        */
-       if (fip->field_bit == FIELD_CUSTOM) {
-               standard_tag = 0;
-       }
-
        switch (standard_tag) {
                case TIFFTAG_SUBFILETYPE:
                        *va_arg(ap, uint32*) = td->td_subfiletype;
        switch (standard_tag) {
                case TIFFTAG_SUBFILETYPE:
                        *va_arg(ap, uint32*) = td->td_subfiletype;
@@ -1067,6 +1065,9 @@ _TIFFVGetField(TIFF* tif, uint32 tag, va_list ap)
                        if (td->td_samplesperpixel - td->td_extrasamples > 1) {
                                *va_arg(ap, uint16**) = td->td_transferfunction[1];
                                *va_arg(ap, uint16**) = td->td_transferfunction[2];
                        if (td->td_samplesperpixel - td->td_extrasamples > 1) {
                                *va_arg(ap, uint16**) = td->td_transferfunction[1];
                                *va_arg(ap, uint16**) = td->td_transferfunction[2];
+                       } else {
+                               *va_arg(ap, uint16**) = NULL;
+                               *va_arg(ap, uint16**) = NULL;
                        }
                        break;
                case TIFFTAG_REFERENCEBLACKWHITE:
                        }
                        break;
                case TIFFTAG_REFERENCEBLACKWHITE:
index bf1eebf..24f05aa 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id: tif_dirinfo.c,v 1.127 2017-06-01 12:44:04 erouault Exp $ */
-
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
@@ -979,6 +977,8 @@ _TIFFCheckFieldIsValidForCodec(TIFF *tif, ttag_t tag)
            case TIFFTAG_CONSECUTIVEBADFAXLINES:
            case TIFFTAG_GROUP3OPTIONS:
            case TIFFTAG_GROUP4OPTIONS:
            case TIFFTAG_CONSECUTIVEBADFAXLINES:
            case TIFFTAG_GROUP3OPTIONS:
            case TIFFTAG_GROUP4OPTIONS:
+           /* LERC */
+           case TIFFTAG_LERC_PARAMETERS:
                break;
            default:
                return 1;
                break;
            default:
                return 1;
@@ -1054,7 +1054,18 @@ _TIFFCheckFieldIsValidForCodec(TIFF *tif, ttag_t tag)
                if (tag == TIFFTAG_PREDICTOR)
                    return 1;
                break;
                if (tag == TIFFTAG_PREDICTOR)
                    return 1;
                break;
-
+           case COMPRESSION_ZSTD:
+               if (tag == TIFFTAG_PREDICTOR)
+                   return 1;
+               break;
+           case COMPRESSION_LERC:
+               if (tag == TIFFTAG_LERC_PARAMETERS)
+                   return 1;
+               break;
+                 case COMPRESSION_WEBP:
+               if (tag == TIFFTAG_PREDICTOR)
+                               return 1;
+               break;
        }
        return 0;
 }
        }
        return 0;
 }
index 5352fcd..ad33d62 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id: tif_dirread.c,v 1.218 2017-09-09 21:44:42 erouault Exp $ */
-
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
@@ -167,6 +165,7 @@ static int TIFFFetchStripThing(TIFF* tif, TIFFDirEntry* dir, uint32 nstrips, uin
 static int TIFFFetchSubjectDistance(TIFF*, TIFFDirEntry*);
 static void ChopUpSingleUncompressedStrip(TIFF*);
 static uint64 TIFFReadUInt64(const uint8 *value);
 static int TIFFFetchSubjectDistance(TIFF*, TIFFDirEntry*);
 static void ChopUpSingleUncompressedStrip(TIFF*);
 static uint64 TIFFReadUInt64(const uint8 *value);
+static int _TIFFGetMaxColorChannels(uint16 photometric);
 
 static int _TIFFFillStrilesInternal( TIFF *tif, int loadStripByteCount );
 
 
 static int _TIFFFillStrilesInternal( TIFF *tif, int loadStripByteCount );
 
@@ -776,7 +775,7 @@ static enum TIFFReadDirEntryErr TIFFReadDirEntryIfd8(TIFF* tif, TIFFDirEntry* di
 static enum TIFFReadDirEntryErr TIFFReadDirEntryDataAndRealloc(
                     TIFF* tif, uint64 offset, tmsize_t size, void** pdest)
 {
 static enum TIFFReadDirEntryErr TIFFReadDirEntryDataAndRealloc(
                     TIFF* tif, uint64 offset, tmsize_t size, void** pdest)
 {
-#if SIZEOF_VOIDP == 8 || SIZEOF_SIZE_T == 8
+#if SIZEOF_SIZE_T == 8
         tmsize_t threshold = INITIAL_THRESHOLD;
 #endif
         tmsize_t already_read = 0;
         tmsize_t threshold = INITIAL_THRESHOLD;
 #endif
         tmsize_t already_read = 0;
@@ -797,7 +796,7 @@ static enum TIFFReadDirEntryErr TIFFReadDirEntryDataAndRealloc(
             void* new_dest;
             tmsize_t bytes_read;
             tmsize_t to_read = size - already_read;
             void* new_dest;
             tmsize_t bytes_read;
             tmsize_t to_read = size - already_read;
-#if SIZEOF_VOIDP == 8 || SIZEOF_SIZE_T == 8
+#if SIZEOF_SIZE_T == 8
             if( to_read >= threshold && threshold < MAX_THRESHOLD )
             {
                 to_read = threshold;
             if( to_read >= threshold && threshold < MAX_THRESHOLD )
             {
                 to_read = threshold;
@@ -3506,6 +3505,35 @@ static void TIFFReadDirEntryOutputErr(TIFF* tif, enum TIFFReadDirEntryErr err, c
        }
 }
 
        }
 }
 
+/*
+ * Return the maximum number of color channels specified for a given photometric
+ * type. 0 is returned if photometric type isn't supported or no default value
+ * is defined by the specification.
+ */
+static int _TIFFGetMaxColorChannels( uint16 photometric )
+{
+    switch (photometric) {
+       case PHOTOMETRIC_PALETTE:
+       case PHOTOMETRIC_MINISWHITE:
+       case PHOTOMETRIC_MINISBLACK:
+            return 1;
+       case PHOTOMETRIC_YCBCR:
+       case PHOTOMETRIC_RGB:
+       case PHOTOMETRIC_CIELAB:
+       case PHOTOMETRIC_LOGLUV:
+       case PHOTOMETRIC_ITULAB:
+       case PHOTOMETRIC_ICCLAB:
+            return 3;
+       case PHOTOMETRIC_SEPARATED:
+       case PHOTOMETRIC_MASK:
+            return 4;
+       case PHOTOMETRIC_LOGL:
+       case PHOTOMETRIC_CFA:
+       default:
+            return 0;
+    }
+}
+
 /*
  * Read the next TIFF directory from a file and convert it to the internal
  * format. We read directories sequentially.
 /*
  * Read the next TIFF directory from a file and convert it to the internal
  * format. We read directories sequentially.
@@ -3522,6 +3550,7 @@ TIFFReadDirectory(TIFF* tif)
        uint32 fii=FAILED_FII;
         toff_t nextdiroff;
     int bitspersample_read = FALSE;
        uint32 fii=FAILED_FII;
         toff_t nextdiroff;
     int bitspersample_read = FALSE;
+        int color_channels;
 
        tif->tif_diroff=tif->tif_nextdiroff;
        if (!TIFFCheckDirOffset(tif,tif->tif_nextdiroff))
 
        tif->tif_diroff=tif->tif_nextdiroff;
        if (!TIFFCheckDirOffset(tif,tif->tif_nextdiroff))
@@ -4026,6 +4055,37 @@ TIFFReadDirectory(TIFF* tif)
                        }
                }
        }
                        }
                }
        }
+
+       /*
+        * Make sure all non-color channels are extrasamples.
+        * If it's not the case, define them as such.
+        */
+        color_channels = _TIFFGetMaxColorChannels(tif->tif_dir.td_photometric);
+        if (color_channels && tif->tif_dir.td_samplesperpixel - tif->tif_dir.td_extrasamples > color_channels) {
+                uint16 old_extrasamples;
+                uint16 *new_sampleinfo;
+
+                TIFFWarningExt(tif->tif_clientdata,module, "Sum of Photometric type-related "
+                    "color channels and ExtraSamples doesn't match SamplesPerPixel. "
+                    "Defining non-color channels as ExtraSamples.");
+
+                old_extrasamples = tif->tif_dir.td_extrasamples;
+                tif->tif_dir.td_extrasamples = (uint16) (tif->tif_dir.td_samplesperpixel - color_channels);
+
+                // sampleinfo should contain information relative to these new extra samples
+                new_sampleinfo = (uint16*) _TIFFcalloc(tif->tif_dir.td_extrasamples, sizeof(uint16));
+                if (!new_sampleinfo) {
+                    TIFFErrorExt(tif->tif_clientdata, module, "Failed to allocate memory for "
+                                "temporary new sampleinfo array (%d 16 bit elements)",
+                                tif->tif_dir.td_extrasamples);
+                    goto bad;
+                }
+
+                memcpy(new_sampleinfo, tif->tif_dir.td_sampleinfo, old_extrasamples * sizeof(uint16));
+                _TIFFsetShortArray(&tif->tif_dir.td_sampleinfo, new_sampleinfo, tif->tif_dir.td_extrasamples);
+                _TIFFfree(new_sampleinfo);
+        }
+
        /*
         * Verify Palette image has a Colormap.
         */
        /*
         * Verify Palette image has a Colormap.
         */
@@ -4881,17 +4941,18 @@ TIFFFetchNormalTag(TIFF* tif, TIFFDirEntry* dp, int recover)
                                err=TIFFReadDirEntryByteArray(tif,dp,&data);
                                if (err==TIFFReadDirEntryErrOk)
                                {
                                err=TIFFReadDirEntryByteArray(tif,dp,&data);
                                if (err==TIFFReadDirEntryErrOk)
                                {
-                                       uint8* ma;
-                                       uint32 mb;
+                                       uint32 mb = 0;
                                        int n;
                                        int n;
-                                       ma=data;
-                                       mb=0;
-                                       while (mb<(uint32)dp->tdir_count)
+                                       if (data != NULL)
                                        {
                                        {
-                                               if (*ma==0)
-                                                       break;
-                                               ma++;
-                                               mb++;
+                                           uint8* ma = data;
+                                           while (mb<(uint32)dp->tdir_count)
+                                           {
+                                                   if (*ma==0)
+                                                           break;
+                                                   ma++;
+                                                   mb++;
+                                           }
                                        }
                                        if (mb+1<(uint32)dp->tdir_count)
                                                TIFFWarningExt(tif->tif_clientdata,module,"ASCII value for tag \"%s\" contains null byte in value; value incorrectly truncated during reading due to implementation limitations",fip->field_name);
                                        }
                                        if (mb+1<(uint32)dp->tdir_count)
                                                TIFFWarningExt(tif->tif_clientdata,module,"ASCII value for tag \"%s\" contains null byte in value; value incorrectly truncated during reading due to implementation limitations",fip->field_name);
@@ -5141,11 +5202,11 @@ TIFFFetchNormalTag(TIFF* tif, TIFFDirEntry* dp, int recover)
                                        if (err==TIFFReadDirEntryErrOk)
                                        {
                                                int m;
                                        if (err==TIFFReadDirEntryErrOk)
                                        {
                                                int m;
-                        if( dp->tdir_count > 0 && data[dp->tdir_count-1] != '\0' )
-                        {
-                            TIFFWarningExt(tif->tif_clientdata,module,"ASCII value for tag \"%s\" does not end in null byte. Forcing it to be null",fip->field_name);
-                            data[dp->tdir_count-1] = '\0';
-                        }
+                                               if( data != 0 && dp->tdir_count > 0 && data[dp->tdir_count-1] != '\0' )
+                                               {
+                                                   TIFFWarningExt(tif->tif_clientdata,module,"ASCII value for tag \"%s\" does not end in null byte. Forcing it to be null",fip->field_name);
+                                                   data[dp->tdir_count-1] = '\0';
+                                               }
                                                m=TIFFSetField(tif,dp->tdir_tag,(uint16)(dp->tdir_count),data);
                                                if (data!=0)
                                                        _TIFFfree(data);
                                                m=TIFFSetField(tif,dp->tdir_tag,(uint16)(dp->tdir_count),data);
                                                if (data!=0)
                                                        _TIFFfree(data);
@@ -5318,11 +5379,11 @@ TIFFFetchNormalTag(TIFF* tif, TIFFDirEntry* dp, int recover)
                                if (err==TIFFReadDirEntryErrOk)
                                {
                                        int m;
                                if (err==TIFFReadDirEntryErrOk)
                                {
                                        int m;
-                    if( dp->tdir_count > 0 && data[dp->tdir_count-1] != '\0' )
-                    {
-                        TIFFWarningExt(tif->tif_clientdata,module,"ASCII value for tag \"%s\" does not end in null byte. Forcing it to be null",fip->field_name);
-                        data[dp->tdir_count-1] = '\0';
-                    }
+                                       if( data != 0 && dp->tdir_count > 0 && data[dp->tdir_count-1] != '\0' )
+                                       {
+                                           TIFFWarningExt(tif->tif_clientdata,module,"ASCII value for tag \"%s\" does not end in null byte. Forcing it to be null",fip->field_name);
+                                            data[dp->tdir_count-1] = '\0';
+                                       }
                                        m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data);
                                        if (data!=0)
                                                _TIFFfree(data);
                                        m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data);
                                        if (data!=0)
                                                _TIFFfree(data);
@@ -5698,6 +5759,16 @@ ChopUpSingleUncompressedStrip(TIFF* tif)
         if( nstrips == 0 )
             return;
 
         if( nstrips == 0 )
             return;
 
+        /* If we are going to allocate a lot of memory, make sure that the */
+        /* file is as big as needed */
+        if( tif->tif_mode == O_RDONLY &&
+            nstrips > 1000000 &&
+            (offset >= TIFFGetFileSize(tif) ||
+             stripbytes > (TIFFGetFileSize(tif) - offset) / (nstrips - 1)) )
+        {
+            return;
+        }
+
        newcounts = (uint64*) _TIFFCheckMalloc(tif, nstrips, sizeof (uint64),
                                "for chopped \"StripByteCounts\" array");
        newoffsets = (uint64*) _TIFFCheckMalloc(tif, nstrips, sizeof (uint64),
        newcounts = (uint64*) _TIFFCheckMalloc(tif, nstrips, sizeof (uint64),
                                "for chopped \"StripByteCounts\" array");
        newoffsets = (uint64*) _TIFFCheckMalloc(tif, nstrips, sizeof (uint64),
index 21f57a1..acc41c8 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id: tif_dirwrite.c,v 1.89 2017-08-23 13:33:42 erouault Exp $ */
-
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
@@ -697,8 +695,11 @@ TIFFWriteDirectorySec(TIFF* tif, int isimage, int imagedone, uint64* pdiroff)
                                                                }
                                                                break;
                                                        default:
                                                                }
                                                                break;
                                                        default:
-                                                               assert(0);   /* we should never get here */
-                                                               break;
+                                                               TIFFErrorExt(tif->tif_clientdata,module,
+                                                                           "Cannot write tag %d (%s)",
+                                                                           TIFFFieldTag(o),
+                                                                            o->field_name ? o->field_name : "unknown");
+                                                               goto bad;
                                                }
                                        }
                                }
                                                }
                                        }
                                }
index 1e1425a..910e616 100644 (file)
@@ -1,5 +1,3 @@
-/* $Header: /cvs/maptools/cvsroot/libtiff/libtiff/tif_dumpmode.c,v 1.15 2015-12-12 18:04:26 erouault Exp $ */
-
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
index a8f1af8..7269563 100644 (file)
@@ -1,5 +1,3 @@
-/* $Header: /cvs/maptools/cvsroot/libtiff/libtiff/tif_error.c,v 1.6 2017-07-04 12:54:42 erouault Exp $ */
-
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
index c10fa34..18407b0 100644 (file)
@@ -1,5 +1,3 @@
-/* $Header: /cvs/maptools/cvsroot/libtiff/libtiff/tif_extension.c,v 1.8 2015-12-06 11:13:43 erouault Exp $ */
-
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
index 2047bc6..447a576 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id: tif_fax3.c,v 1.81 2017-06-18 10:31:50 erouault Exp $ */
-
 /*
  * Copyright (c) 1990-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
 /*
  * Copyright (c) 1990-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
index 94f97c5..d76738a 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id: tif_flush.c,v 1.9 2010-03-31 06:40:10 fwarmerdam Exp $ */
-
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
index d0f4af4..7fc00d6 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id: tif_getimage.c,v 1.114 2017-11-17 20:21:00 erouault Exp $ */
-
 /*
  * Copyright (c) 1991-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
 /*
  * Copyright (c) 1991-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
index 707fa9c..7ffe885 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id: tif_jbig.c,v 1.16 2017-06-26 15:20:00 erouault Exp $ */
-
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
@@ -32,7 +30,7 @@
  *
  */
 
  *
  */
 
-#include <precomp.h>
+#include "tiffiop.h"
 
 #ifdef JBIG_SUPPORT
 #include "jbig.h"
 
 #ifdef JBIG_SUPPORT
 #include "jbig.h"
@@ -53,17 +51,18 @@ static int JBIGDecode(TIFF* tif, uint8* buffer, tmsize_t size, uint16 s)
        struct jbg_dec_state decoder;
        int decodeStatus = 0;
        unsigned char* pImage = NULL;
        struct jbg_dec_state decoder;
        int decodeStatus = 0;
        unsigned char* pImage = NULL;
-       (void) size, (void) s;
+       unsigned long decodedSize;
+       (void) s;
 
        if (isFillOrder(tif, tif->tif_dir.td_fillorder))
        {
 
        if (isFillOrder(tif, tif->tif_dir.td_fillorder))
        {
-               TIFFReverseBits(tif->tif_rawdata, tif->tif_rawdatasize);
+               TIFFReverseBits(tif->tif_rawcp, tif->tif_rawcc);
        }
 
        jbg_dec_init(&decoder);
 
 #if defined(HAVE_JBG_NEWLEN)
        }
 
        jbg_dec_init(&decoder);
 
 #if defined(HAVE_JBG_NEWLEN)
-       jbg_newlen(tif->tif_rawdata, (size_t)tif->tif_rawdatasize);
+       jbg_newlen(tif->tif_rawcp, (size_t)tif->tif_rawcc);
        /*
         * I do not check the return status of jbg_newlen because even if this
         * function fails it does not necessarily mean that decoding the image
        /*
         * I do not check the return status of jbg_newlen because even if this
         * function fails it does not necessarily mean that decoding the image
@@ -76,8 +75,8 @@ static int JBIGDecode(TIFF* tif, uint8* buffer, tmsize_t size, uint16 s)
         */
 #endif /* HAVE_JBG_NEWLEN */
 
         */
 #endif /* HAVE_JBG_NEWLEN */
 
-       decodeStatus = jbg_dec_in(&decoder, (unsigned char*)tif->tif_rawdata,
-                                 (size_t)tif->tif_rawdatasize, NULL);
+       decodeStatus = jbg_dec_in(&decoder, (unsigned char*)tif->tif_rawcp,
+                                 (size_t)tif->tif_rawcc, NULL);
        if (JBG_EOK != decodeStatus)
        {
                /*
        if (JBG_EOK != decodeStatus)
        {
                /*
@@ -98,9 +97,28 @@ static int JBIGDecode(TIFF* tif, uint8* buffer, tmsize_t size, uint16 s)
                return 0;
        }
 
                return 0;
        }
 
+       decodedSize = jbg_dec_getsize(&decoder);
+       if( (tmsize_t)decodedSize < size )
+       {
+           TIFFWarningExt(tif->tif_clientdata, "JBIG",
+                          "Only decoded %lu bytes, whereas %lu requested",
+                          decodedSize, (unsigned long)size);
+       }
+       else if( (tmsize_t)decodedSize > size )
+       {
+           TIFFErrorExt(tif->tif_clientdata, "JBIG",
+                        "Decoded %lu bytes, whereas %lu were requested",
+                        decodedSize, (unsigned long)size);
+           jbg_dec_free(&decoder);
+           return 0;
+       }
        pImage = jbg_dec_getimage(&decoder, 0);
        pImage = jbg_dec_getimage(&decoder, 0);
-       _TIFFmemcpy(buffer, pImage, jbg_dec_getsize(&decoder));
+       _TIFFmemcpy(buffer, pImage, decodedSize);
        jbg_dec_free(&decoder);
        jbg_dec_free(&decoder);
+
+        tif->tif_rawcp += tif->tif_rawcc;
+        tif->tif_rawcc = 0;
+
        return 1;
 }
 
        return 1;
 }
 
index 9d4f3dd..f2ddc33 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id: tif_jpeg.c,v 1.134 2017-10-17 19:04:47 erouault Exp $ */
-
 /*
  * Copyright (c) 1994-1997 Sam Leffler
  * Copyright (c) 1994-1997 Silicon Graphics, Inc.
 /*
  * Copyright (c) 1994-1997 Sam Leffler
  * Copyright (c) 1994-1997 Silicon Graphics, Inc.
@@ -27,7 +25,8 @@
 #define WIN32_LEAN_AND_MEAN
 #define VC_EXTRALEAN
 
 #define WIN32_LEAN_AND_MEAN
 #define VC_EXTRALEAN
 
-#include <precomp.h>
+#include "tiffiop.h"
+#include <stdlib.h>
 
 #ifdef JPEG_SUPPORT
 
 
 #ifdef JPEG_SUPPORT
 
@@ -75,7 +74,7 @@ int TIFFJPEGIsFullStripRequired_12(TIFF* tif);
    "JPEGLib: JPEG parameter struct mismatch: library thinks size is 432,
    caller expects 464"
 
    "JPEGLib: JPEG parameter struct mismatch: library thinks size is 432,
    caller expects 464"
 
-   For such users we wil fix the problem here. See install.doc file from
+   For such users we will fix the problem here. See install.doc file from
    the JPEG library distribution for details.
 */
 
    the JPEG library distribution for details.
 */
 
index e6be21e..3b9e633 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id: tif_luv.c,v 1.49 2017-07-24 12:47:30 erouault Exp $ */
-
 /*
  * Copyright (c) 1997 Greg Ward Larson
  * Copyright (c) 1997 Silicon Graphics, Inc.
 /*
  * Copyright (c) 1997 Greg Ward Larson
  * Copyright (c) 1997 Silicon Graphics, Inc.
@@ -215,7 +213,7 @@ LogL16Decode(TIFF* tif, uint8* op, tmsize_t occ, uint16 s)
        bp = (unsigned char*) tif->tif_rawcp;
        cc = tif->tif_rawcc;
        /* get each byte string */
        bp = (unsigned char*) tif->tif_rawcp;
        cc = tif->tif_rawcc;
        /* get each byte string */
-       for (shft = 2*8; (shft -= 8) >= 0; ) {
+       for (shft = 8; shft >= 0; shft -=8) {
                for (i = 0; i < npixels && cc > 0; ) {
                        if (*bp >= 128) {               /* run */
                                if( cc < 2 )
                for (i = 0; i < npixels && cc > 0; ) {
                        if (*bp >= 128) {               /* run */
                                if( cc < 2 )
@@ -349,7 +347,7 @@ LogLuvDecode32(TIFF* tif, uint8* op, tmsize_t occ, uint16 s)
        bp = (unsigned char*) tif->tif_rawcp;
        cc = tif->tif_rawcc;
        /* get each byte string */
        bp = (unsigned char*) tif->tif_rawcp;
        cc = tif->tif_rawcc;
        /* get each byte string */
-       for (shft = 4*8; (shft -= 8) >= 0; ) {
+       for (shft = 24; shft >= 0; shft -=8) {
                for (i = 0; i < npixels && cc > 0; ) {
                        if (*bp >= 128) {               /* run */
                                if( cc < 2 )
                for (i = 0; i < npixels && cc > 0; ) {
                        if (*bp >= 128) {               /* run */
                                if( cc < 2 )
@@ -467,7 +465,7 @@ LogL16Encode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
        /* compress each byte string */
        op = tif->tif_rawcp;
        occ = tif->tif_rawdatasize - tif->tif_rawcc;
        /* compress each byte string */
        op = tif->tif_rawcp;
        occ = tif->tif_rawdatasize - tif->tif_rawcc;
-       for (shft = 2*8; (shft -= 8) >= 0; )
+       for (shft = 8; shft >= 0; shft -=8) {
                for (i = 0; i < npixels; i += rc) {
                        if (occ < 4) {
                                tif->tif_rawcp = op;
                for (i = 0; i < npixels; i += rc) {
                        if (occ < 4) {
                                tif->tif_rawcp = op;
@@ -522,6 +520,7 @@ LogL16Encode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
                        } else
                                rc = 0;
                }
                        } else
                                rc = 0;
                }
+       }
        tif->tif_rawcp = op;
        tif->tif_rawcc = tif->tif_rawdatasize - occ;
 
        tif->tif_rawcp = op;
        tif->tif_rawcc = tif->tif_rawdatasize - occ;
 
@@ -618,7 +617,7 @@ LogLuvEncode32(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
        /* compress each byte string */
        op = tif->tif_rawcp;
        occ = tif->tif_rawdatasize - tif->tif_rawcc;
        /* compress each byte string */
        op = tif->tif_rawcp;
        occ = tif->tif_rawdatasize - tif->tif_rawcc;
-       for (shft = 4*8; (shft -= 8) >= 0; )
+       for (shft = 24; shft >= 0; shft -=8) {
                for (i = 0; i < npixels; i += rc) {
                        if (occ < 4) {
                                tif->tif_rawcp = op;
                for (i = 0; i < npixels; i += rc) {
                        if (occ < 4) {
                                tif->tif_rawcp = op;
@@ -673,6 +672,7 @@ LogLuvEncode32(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
                        } else
                                rc = 0;
                }
                        } else
                                rc = 0;
                }
+       }
        tif->tif_rawcp = op;
        tif->tif_rawcc = tif->tif_rawdatasize - occ;
 
        tif->tif_rawcp = op;
        tif->tif_rawcc = tif->tif_rawdatasize - occ;
 
index b95fe46..19f960f 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id: tif_lzma.c,v 1.6 2016-09-17 09:18:59 erouault Exp $ */
-
 /*
  * Copyright (c) 2010, Andrey Kiselev <dron@ak4719.spb.edu>
  *
 /*
  * Copyright (c) 2010, Andrey Kiselev <dron@ak4719.spb.edu>
  *
@@ -250,6 +248,7 @@ LZMAPreEncode(TIFF* tif, uint16 s)
 {
        static const char module[] = "LZMAPreEncode";
        LZMAState *sp = EncoderState(tif);
 {
        static const char module[] = "LZMAPreEncode";
        LZMAState *sp = EncoderState(tif);
+       lzma_ret ret;
 
        (void) s;
        assert(sp != NULL);
 
        (void) s;
        assert(sp != NULL);
@@ -263,7 +262,13 @@ LZMAPreEncode(TIFF* tif, uint16 s)
                             "Liblzma cannot deal with buffers this size");
                return 0;
        }
                             "Liblzma cannot deal with buffers this size");
                return 0;
        }
-       return (lzma_stream_encoder(&sp->stream, sp->filters, sp->check) == LZMA_OK);
+       ret = lzma_stream_encoder(&sp->stream, sp->filters, sp->check);
+       if (ret != LZMA_OK) {
+               TIFFErrorExt(tif->tif_clientdata, module,
+                       "Error in lzma_stream_encoder(): %s", LZMAStrerror(ret));
+               return 0;
+       }
+       return 1;
 }
 
 /*
 }
 
 /*
index c6ab1be..4726053 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id: tif_lzw.c,v 1.57 2017-07-11 10:54:29 erouault Exp $ */
-
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
@@ -135,6 +133,7 @@ typedef struct {
        long    dec_restart;            /* restart count */
 #ifdef LZW_CHECKEOS
        uint64  dec_bitsleft;           /* available bits in raw data */
        long    dec_restart;            /* restart count */
 #ifdef LZW_CHECKEOS
        uint64  dec_bitsleft;           /* available bits in raw data */
+       tmsize_t old_tif_rawcc;         /* value of tif_rawcc at the end of the previous TIFLZWDecode() call */
 #endif
        decodeFunc dec_decode;          /* regular or backwards compatible */
        code_t* dec_codep;              /* current recognized code */
 #endif
        decodeFunc dec_decode;          /* regular or backwards compatible */
        code_t* dec_codep;              /* current recognized code */
@@ -320,6 +319,7 @@ LZWPreDecode(TIFF* tif, uint16 s)
        sp->dec_nbitsmask = MAXCODE(BITS_MIN);
 #ifdef LZW_CHECKEOS
        sp->dec_bitsleft = 0;
        sp->dec_nbitsmask = MAXCODE(BITS_MIN);
 #ifdef LZW_CHECKEOS
        sp->dec_bitsleft = 0;
+        sp->old_tif_rawcc = 0;
 #endif
        sp->dec_free_entp = sp->dec_codetab + CODE_FIRST;
        /*
 #endif
        sp->dec_free_entp = sp->dec_codetab + CODE_FIRST;
        /*
@@ -427,7 +427,7 @@ LZWDecode(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s)
 
        bp = (unsigned char *)tif->tif_rawcp;
 #ifdef LZW_CHECKEOS
 
        bp = (unsigned char *)tif->tif_rawcp;
 #ifdef LZW_CHECKEOS
-       sp->dec_bitsleft = (((uint64)tif->tif_rawcc) << 3);
+       sp->dec_bitsleft += (((uint64)tif->tif_rawcc - sp->old_tif_rawcc) << 3);
 #endif
        nbits = sp->lzw_nbits;
        nextdata = sp->lzw_nextdata;
 #endif
        nbits = sp->lzw_nbits;
        nextdata = sp->lzw_nextdata;
@@ -555,6 +555,9 @@ LZWDecode(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s)
 
        tif->tif_rawcc -= (tmsize_t)( (uint8*) bp - tif->tif_rawcp );
        tif->tif_rawcp = (uint8*) bp;
 
        tif->tif_rawcc -= (tmsize_t)( (uint8*) bp - tif->tif_rawcp );
        tif->tif_rawcp = (uint8*) bp;
+#ifdef LZW_CHECKEOS
+       sp->old_tif_rawcc = tif->tif_rawcc;
+#endif
        sp->lzw_nbits = (unsigned short) nbits;
        sp->lzw_nextdata = nextdata;
        sp->lzw_nextbits = nextbits;
        sp->lzw_nbits = (unsigned short) nbits;
        sp->lzw_nextdata = nextdata;
        sp->lzw_nextbits = nextbits;
@@ -604,6 +607,7 @@ LZWDecodeCompat(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s)
        char *tp;
        unsigned char *bp;
        int code, nbits;
        char *tp;
        unsigned char *bp;
        int code, nbits;
+       int len;
        long nextbits, nextdata, nbitsmask;
        code_t *codep, *free_entp, *maxcodep, *oldcodep;
 
        long nextbits, nextdata, nbitsmask;
        code_t *codep, *free_entp, *maxcodep, *oldcodep;
 
@@ -657,7 +661,7 @@ LZWDecodeCompat(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s)
 
        bp = (unsigned char *)tif->tif_rawcp;
 #ifdef LZW_CHECKEOS
 
        bp = (unsigned char *)tif->tif_rawcp;
 #ifdef LZW_CHECKEOS
-       sp->dec_bitsleft = (((uint64)tif->tif_rawcc) << 3);
+       sp->dec_bitsleft += (((uint64)tif->tif_rawcc - sp->old_tif_rawcc) << 3);
 #endif
        nbits = sp->lzw_nbits;
        nextdata = sp->lzw_nextdata;
 #endif
        nbits = sp->lzw_nbits;
        nextdata = sp->lzw_nextdata;
@@ -755,13 +759,18 @@ LZWDecodeCompat(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s)
                                }  while (--occ);
                                break;
                        }
                                }  while (--occ);
                                break;
                        }
-                       assert(occ >= codep->length);
-                       op += codep->length;
-                       occ -= codep->length;
-                       tp = op;
+                       len = codep->length;
+                       tp = op + len;
                        do {
                        do {
-                               *--tp = codep->value;
-                       } while( (codep = codep->next) != NULL );
+                               int t;
+                               --tp;
+                               t = codep->value;
+                               codep = codep->next;
+                               *tp = (char)t;
+                       } while (codep && tp > op);
+                       assert(occ >= len);
+                       op += len;
+                       occ -= len;
                } else {
                        *op++ = (char)code;
                        occ--;
                } else {
                        *op++ = (char)code;
                        occ--;
@@ -770,6 +779,9 @@ LZWDecodeCompat(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s)
 
        tif->tif_rawcc -= (tmsize_t)( (uint8*) bp - tif->tif_rawcp );
        tif->tif_rawcp = (uint8*) bp;
 
        tif->tif_rawcc -= (tmsize_t)( (uint8*) bp - tif->tif_rawcp );
        tif->tif_rawcp = (uint8*) bp;
+#ifdef LZW_CHECKEOS
+       sp->old_tif_rawcc = tif->tif_rawcc;
+#endif
        sp->lzw_nbits = (unsigned short)nbits;
        sp->lzw_nextdata = nextdata;
        sp->lzw_nextbits = nextbits;
        sp->lzw_nbits = (unsigned short)nbits;
        sp->lzw_nextdata = nextdata;
        sp->lzw_nextbits = nextbits;
index c75f7f1..69e8fc6 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id: tif_next.c,v 1.19 2016-09-04 21:32:56 erouault Exp $ */
-
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
index 4da4577..27385d8 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id: tif_ojpeg.c,v 1.69 2017-04-27 17:29:26 erouault Exp $ */
-
 /* WARNING: The type of JPEG encapsulation defined by the TIFF Version 6.0
    specification is now totally obsolete and deprecated for new applications and
    images. This file was was created solely in order to read unconverted images
 /* WARNING: The type of JPEG encapsulation defined by the TIFF Version 6.0
    specification is now totally obsolete and deprecated for new applications and
    images. This file was was created solely in order to read unconverted images
 #define WIN32_LEAN_AND_MEAN
 #define VC_EXTRALEAN
 
 #define WIN32_LEAN_AND_MEAN
 #define VC_EXTRALEAN
 
-#include <precomp.h>
-
+#include "tiffiop.h"
 #ifdef OJPEG_SUPPORT
 
 /* Configuration defines here are:
 #ifdef OJPEG_SUPPORT
 
 /* Configuration defines here are:
index 58fbb0a..7a9f074 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id: tif_open.c,v 1.48 2016-11-20 22:29:47 erouault Exp $ */
-
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
index e813312..f464e17 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id: tif_packbits.c,v 1.26 2017-05-14 02:26:07 erouault Exp $ */
-
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
index 53bdd4d..655a12b 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id: tif_pixarlog.c,v 1.54 2017-07-10 10:40:28 erouault Exp $ */
-
 /*
  * Copyright (c) 1996-1997 Sam Leffler
  * Copyright (c) 1996 Pixar
 /*
  * Copyright (c) 1996-1997 Sam Leffler
  * Copyright (c) 1996 Pixar
index f83b19f..ebdf6c8 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id: tif_predict.c,v 1.44 2017-06-18 10:31:50 erouault Exp $ */
-
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
index 37a2111..b5a3e8c 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id: tif_print.c,v 1.65 2016-11-20 22:31:22 erouault Exp $ */
-
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
@@ -547,7 +545,7 @@ TIFFPrintDirectory(TIFF* tif, FILE* fd, long flags)
                                uint16 i;
                                fprintf(fd, "    %2ld: %5u",
                                    l, td->td_transferfunction[0][l]);
                                uint16 i;
                                fprintf(fd, "    %2ld: %5u",
                                    l, td->td_transferfunction[0][l]);
-                               for (i = 1; i < td->td_samplesperpixel; i++)
+                               for (i = 1; i < td->td_samplesperpixel - td->td_extrasamples && i < 3; i++)
                                        fprintf(fd, " %5u",
                                            td->td_transferfunction[i][l]);
                                fputc('\n', fd);
                                        fprintf(fd, " %5u",
                                            td->td_transferfunction[i][l]);
                                fputc('\n', fd);
@@ -668,13 +666,13 @@ TIFFPrintDirectory(TIFF* tif, FILE* fd, long flags)
 #if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
                        fprintf(fd, "    %3lu: [%8I64u, %8I64u]\n",
                            (unsigned long) s,
 #if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
                        fprintf(fd, "    %3lu: [%8I64u, %8I64u]\n",
                            (unsigned long) s,
-                           (unsigned __int64) td->td_stripoffset[s],
-                           (unsigned __int64) td->td_stripbytecount[s]);
+                           td->td_stripoffset ? (unsigned __int64) td->td_stripoffset[s] : 0,
+                           td->td_stripbytecount ? (unsigned __int64) td->td_stripbytecount[s] : 0);
 #else
                        fprintf(fd, "    %3lu: [%8llu, %8llu]\n",
                            (unsigned long) s,
 #else
                        fprintf(fd, "    %3lu: [%8llu, %8llu]\n",
                            (unsigned long) s,
-                           (unsigned long long) td->td_stripoffset[s],
-                           (unsigned long long) td->td_stripbytecount[s]);
+                           td->td_stripoffset ? (unsigned long long) td->td_stripoffset[s] : 0,
+                           td->td_stripbytecount ? (unsigned long long) td->td_stripbytecount[s] : 0);
 #endif
        }
 }
 #endif
        }
 }
index 2d0e0f7..78c23aa 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id: tif_read.c,v 1.66 2017-11-17 20:21:00 erouault Exp $ */
-
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
@@ -58,7 +56,7 @@ static int TIFFReadAndRealloc( TIFF* tif, tmsize_t size,
                                int is_strip, uint32 strip_or_tile,
                                const char* module )
 {
                                int is_strip, uint32 strip_or_tile,
                                const char* module )
 {
-#if SIZEOF_VOIDP == 8 || SIZEOF_SIZE_T == 8
+#if SIZEOF_SIZE_T == 8
         tmsize_t threshold = INITIAL_THRESHOLD;
 #endif
         tmsize_t already_read = 0;
         tmsize_t threshold = INITIAL_THRESHOLD;
 #endif
         tmsize_t already_read = 0;
@@ -73,7 +71,7 @@ static int TIFFReadAndRealloc( TIFF* tif, tmsize_t size,
         {
             tmsize_t bytes_read;
             tmsize_t to_read = size - already_read;
         {
             tmsize_t bytes_read;
             tmsize_t to_read = size - already_read;
-#if SIZEOF_VOIDP == 8 || SIZEOF_SIZE_T == 8
+#if SIZEOF_SIZE_T == 8
             if( to_read >= threshold && threshold < MAX_THRESHOLD &&
                 already_read + to_read + rawdata_offset > tif->tif_rawdatasize )
             {
             if( to_read >= threshold && threshold < MAX_THRESHOLD &&
                 already_read + to_read + rawdata_offset > tif->tif_rawdatasize )
             {
@@ -348,6 +346,13 @@ TIFFSeek(TIFF* tif, uint32 row, uint16 sample )
             return 0;
         whole_strip = tif->tif_dir.td_stripbytecount[strip] < 10
                 || isMapped(tif);
             return 0;
         whole_strip = tif->tif_dir.td_stripbytecount[strip] < 10
                 || isMapped(tif);
+        if( td->td_compression == COMPRESSION_LERC ||
+            td->td_compression == COMPRESSION_JBIG )
+        {
+            /* Ideally plugins should have a way to declare they don't support
+             * chunk strip */
+            whole_strip = 1;
+        }
 #else
         whole_strip = 1;
 #endif
 #else
         whole_strip = 1;
 #endif
index ecca1fd..7f640a9 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id: tif_stream.cxx,v 1.13 2015-05-28 01:50:22 bfriesen Exp $ */
-
 /*
  * Copyright (c) 1988-1996 Sam Leffler
  * Copyright (c) 1991-1996 Silicon Graphics, Inc.
 /*
  * Copyright (c) 1988-1996 Sam Leffler
  * Copyright (c) 1991-1996 Silicon Graphics, Inc.
@@ -375,6 +373,9 @@ _tiffStreamOpen(const char* name, const char* mode, void *fd)
                                _tiffosSizeProc,
                                _tiffDummyMapProc,
                                 _tiffDummyUnmapProc);
                                _tiffosSizeProc,
                                _tiffDummyMapProc,
                                 _tiffDummyUnmapProc);
+               if (!tif) {
+                       delete data;
+               }
        } else {
                tiffis_data     *data = new tiffis_data;
                data->stream = reinterpret_cast<istream *>(fd);
        } else {
                tiffis_data     *data = new tiffis_data;
                data->stream = reinterpret_cast<istream *>(fd);
@@ -389,6 +390,9 @@ _tiffStreamOpen(const char* name, const char* mode, void *fd)
                                _tiffisSizeProc,
                                _tiffDummyMapProc,
                                 _tiffDummyUnmapProc);
                                _tiffisSizeProc,
                                _tiffDummyMapProc,
                                 _tiffDummyUnmapProc);
+               if (!tif) {
+                       delete data;
+               }
        }
 
        return (tif);
        }
 
        return (tif);
index 9beaa3b..d468714 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id: tif_strip.c,v 1.38 2016-12-03 11:02:15 erouault Exp $ */
-
 /*
  * Copyright (c) 1991-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
 /*
  * Copyright (c) 1991-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
index c16c6fa..30bf160 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id: tif_swab.c,v 1.15 2017-06-08 16:39:50 erouault Exp $ */
-
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
index 523fd17..cec8770 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id: tif_thunder.c,v 1.13 2016-09-04 21:32:56 erouault Exp $ */
-
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
index b416823..36a0000 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id: tif_tile.c,v 1.24 2015-06-07 22:35:40 bfriesen Exp $ */
-
 /*
  * Copyright (c) 1991-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
 /*
  * Copyright (c) 1991-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
index 80c437c..874f1fe 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id: tif_unix.c,v 1.28 2017-01-11 19:02:49 erouault Exp $ */
-
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
index 37e6c30..0139cdb 100644 (file)
@@ -1,4 +1,3 @@
-/* $Header: /cvs/maptools/cvsroot/libtiff/libtiff/tif_version.c,v 1.3 2010-03-10 18:56:49 bfriesen Exp $ */
 /*
  * Copyright (c) 1992-1997 Sam Leffler
  * Copyright (c) 1992-1997 Silicon Graphics, Inc.
 /*
  * Copyright (c) 1992-1997 Sam Leffler
  * Copyright (c) 1992-1997 Silicon Graphics, Inc.
index 51ce200..49f4d58 100644 (file)
@@ -1,5 +1,3 @@
-/* $Header: /cvs/maptools/cvsroot/libtiff/libtiff/tif_warning.c,v 1.4 2017-07-04 12:54:42 erouault Exp $ */
-
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
diff --git a/dll/3rdparty/libtiff/tif_webp.c b/dll/3rdparty/libtiff/tif_webp.c
new file mode 100644 (file)
index 0000000..a002f48
--- /dev/null
@@ -0,0 +1,684 @@
+/*
+* Copyright (c) 2018, Mapbox
+* Author: <norman.barker at mapbox.com>
+*
+* Permission to use, copy, modify, distribute, and sell this software and
+* its documentation for any purpose is hereby granted without fee, provided
+* that (i) the above copyright notices and this permission notice appear in
+* all copies of the software and related documentation, and (ii) the names of
+* Sam Leffler and Silicon Graphics may not be used in any advertising or
+* publicity relating to the software without the specific, prior written
+* permission of Sam Leffler and Silicon Graphics.
+*
+* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
+* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
+* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
+*
+* IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
+* ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
+* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
+* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+* OF THIS SOFTWARE.
+*/
+
+#include "tiffiop.h"
+#ifdef WEBP_SUPPORT
+/*
+ * TIFF Library.
+ *
+ * WEBP Compression Support
+ *
+ */
+
+#include "webp/decode.h"
+#include "webp/encode.h"
+
+#include <stdio.h>
+
+#define LSTATE_INIT_DECODE 0x01
+#define LSTATE_INIT_ENCODE 0x02
+/*
+ * State block for each open TIFF
+ * file using WEBP compression/decompression.
+ */
+typedef struct {
+  uint16           nSamples;               /* number of samples per pixel */
+  
+  int              lossless;               /* lossy/lossless compression */
+  int              quality_level;          /* compression level */
+  WebPPicture      sPicture;               /* WebP Picture */
+  WebPConfig       sEncoderConfig;         /* WebP encoder config */
+  uint8*           pBuffer;                /* buffer to hold raw data on encoding */
+  unsigned int     buffer_offset;          /* current offset into the buffer */
+  unsigned int     buffer_size;
+  
+  WebPIDecoder*    psDecoder;              /* WebPIDecoder */
+  WebPDecBuffer    sDecBuffer;             /* Decoder buffer */
+  int              last_y;                 /* Last row decoded */
+  
+  int              state;                  /* state flags */
+  
+       TIFFVGetMethod   vgetparent;             /* super-class method */
+       TIFFVSetMethod   vsetparent;             /* super-class method */
+} WebPState;
+
+#define LState(tif)            ((WebPState*) (tif)->tif_data)
+#define DecoderState(tif)       LState(tif)
+#define EncoderState(tif)       LState(tif)
+
+static int TWebPEncode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s);
+static int TWebPDecode(TIFF* tif, uint8* op, tmsize_t occ, uint16 s);
+
+static
+int TWebPDatasetWriter(const uint8_t* data, size_t data_size,
+                      const WebPPicture* const picture)
+{
+  static const char module[] = "TWebPDatasetWriter";
+  TIFF* tif = (TIFF*)(picture->custom_ptr);
+  
+  if ( (tif->tif_rawcc + (tmsize_t)data_size) > tif->tif_rawdatasize ) {
+    TIFFErrorExt(tif->tif_clientdata, module,
+                 "Buffer too small by " TIFF_SIZE_FORMAT " bytes.",
+                 (size_t) (tif->tif_rawcc + data_size - tif->tif_rawdatasize));
+    return 0;
+  } else {
+    _TIFFmemcpy(tif->tif_rawcp, data, data_size);
+    tif->tif_rawcc += data_size;
+    tif->tif_rawcp += data_size;
+    return 1;    
+  }
+}
+
+/*
+ * Encode a chunk of pixels.
+ */
+static int
+TWebPEncode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
+{
+  static const char module[] = "TWebPEncode";
+  WebPState *sp = EncoderState(tif);
+  (void) s;
+
+  assert(sp != NULL);
+  assert(sp->state == LSTATE_INIT_ENCODE);
+    
+  if( (uint64)sp->buffer_offset +
+                            (uint64)cc > sp->buffer_size )
+  {
+      TIFFErrorExt(tif->tif_clientdata, module,
+                   "Too many bytes to be written");
+      return 0;
+  }
+
+  memcpy(sp->pBuffer + sp->buffer_offset,
+         bp, cc);
+  sp->buffer_offset += (unsigned)cc;
+
+  return 1;
+  
+}
+
+static int
+TWebPDecode(TIFF* tif, uint8* op, tmsize_t occ, uint16 s)
+{
+  static const char module[] = "WebPDecode";
+  VP8StatusCode status = VP8_STATUS_OK;
+  WebPState *sp = DecoderState(tif);
+  (void) s;  
+
+  assert(sp != NULL);
+  assert(sp->state == LSTATE_INIT_DECODE);
+  
+  if (occ % sp->sDecBuffer.u.RGBA.stride)
+  {
+    TIFFErrorExt(tif->tif_clientdata, module,
+                 "Fractional scanlines cannot be read");
+    return 0;
+  }
+
+  status = WebPIAppend(sp->psDecoder, tif->tif_rawcp, tif->tif_rawcc);
+
+  if (status != VP8_STATUS_OK && status != VP8_STATUS_SUSPENDED) {
+    if (status == VP8_STATUS_INVALID_PARAM) {
+       TIFFErrorExt(tif->tif_clientdata, module,
+         "Invalid parameter used.");      
+    } else if (status == VP8_STATUS_OUT_OF_MEMORY) {
+      TIFFErrorExt(tif->tif_clientdata, module,
+        "Out of memory.");         
+    } else {
+      TIFFErrorExt(tif->tif_clientdata, module,
+        "Unrecognized error.");   
+    }
+    return 0;
+  } else {
+    int current_y, stride;
+    uint8_t* buf;
+
+    /* Returns the RGB/A image decoded so far */
+    buf = WebPIDecGetRGB(sp->psDecoder, &current_y, NULL, NULL, &stride);
+    
+    if ((buf != NULL) &&
+        (occ <= stride * (current_y - sp->last_y))) {
+      memcpy(op,   
+         buf + (sp->last_y * stride),
+         occ);
+
+      tif->tif_rawcp += tif->tif_rawcc;
+      tif->tif_rawcc = 0;
+      sp->last_y += occ / sp->sDecBuffer.u.RGBA.stride;
+      return 1;
+    } else {
+      TIFFErrorExt(tif->tif_clientdata, module, "Unable to decode WebP data."); 
+      return 0;
+    }
+  }
+}
+
+static int
+TWebPFixupTags(TIFF* tif)
+{
+  (void) tif;
+  if (tif->tif_dir.td_planarconfig != PLANARCONFIG_CONTIG) {
+    static const char module[] = "TWebPFixupTags";
+    TIFFErrorExt(tif->tif_clientdata, module,
+      "TIFF WEBP requires data to be stored contiguously in RGB e.g. RGBRGBRGB "
+#if WEBP_ENCODER_ABI_VERSION >= 0x0100
+      "or RGBARGBARGBA"
+#endif
+    );
+    return 0;
+  }
+  return 1;
+}
+
+static int
+TWebPSetupDecode(TIFF* tif)
+{
+  static const char module[] = "WebPSetupDecode";
+  uint16 nBitsPerSample = tif->tif_dir.td_bitspersample;
+  uint16 sampleFormat = tif->tif_dir.td_sampleformat;
+
+  WebPState* sp = DecoderState(tif);
+  assert(sp != NULL);
+
+  sp->nSamples = tif->tif_dir.td_samplesperpixel;
+
+  /* check band count */
+  if ( sp->nSamples != 3
+#if WEBP_ENCODER_ABI_VERSION >= 0x0100
+    && sp->nSamples != 4
+#endif
+  )
+  {
+    TIFFErrorExt(tif->tif_clientdata, module,
+      "WEBP driver doesn't support %d bands. Must be 3 (RGB) "
+  #if WEBP_ENCODER_ABI_VERSION >= 0x0100
+      "or 4 (RGBA) "
+  #endif
+    "bands.",
+    sp->nSamples );
+    return 0;
+  }
+
+  /* check bits per sample and data type */
+  if ((nBitsPerSample != 8) && (sampleFormat != 1)) {
+    TIFFErrorExt(tif->tif_clientdata, module,
+                "WEBP driver requires 8 bit unsigned data");
+    return 0;
+  }
+  
+  /* if we were last encoding, terminate this mode */
+  if (sp->state & LSTATE_INIT_ENCODE) {
+      WebPPictureFree(&sp->sPicture);
+      if (sp->pBuffer != NULL) {
+        _TIFFfree(sp->pBuffer);
+        sp->pBuffer = NULL;
+      }
+      sp->buffer_offset = 0;
+      sp->state = 0;
+  }
+
+  sp->state |= LSTATE_INIT_DECODE;
+
+  return 1;
+}
+
+/*
+* Setup state for decoding a strip.
+*/
+static int
+TWebPPreDecode(TIFF* tif, uint16 s)
+{
+  static const char module[] = "TWebPPreDecode";
+  uint32 segment_width, segment_height;
+  WebPState* sp = DecoderState(tif);
+  TIFFDirectory* td = &tif->tif_dir;
+  (void) s;
+  assert(sp != NULL);
+  
+  if (isTiled(tif)) {
+    segment_width = td->td_tilewidth;
+    segment_height = td->td_tilelength;
+  } else {
+    segment_width = td->td_imagewidth;
+    segment_height = td->td_imagelength - tif->tif_row;
+    if (segment_height > td->td_rowsperstrip)
+      segment_height = td->td_rowsperstrip;
+  }
+
+  if( (sp->state & LSTATE_INIT_DECODE) == 0 )
+      tif->tif_setupdecode(tif);
+      
+  if (sp->psDecoder != NULL) {
+    WebPIDelete(sp->psDecoder);
+    WebPFreeDecBuffer(&sp->sDecBuffer);
+    sp->psDecoder = NULL;
+  }
+
+  sp->last_y = 0;
+  
+  WebPInitDecBuffer(&sp->sDecBuffer);
+  
+  sp->sDecBuffer.is_external_memory = 0;
+  sp->sDecBuffer.width = segment_width;
+  sp->sDecBuffer.height = segment_height;
+  sp->sDecBuffer.u.RGBA.stride = segment_width * sp->nSamples;
+  sp->sDecBuffer.u.RGBA.size = segment_width * sp->nSamples * segment_height;
+  
+  if (sp->nSamples > 3) {
+    sp->sDecBuffer.colorspace = MODE_RGBA;
+  } else {
+    sp->sDecBuffer.colorspace = MODE_RGB;
+  }
+  
+  sp->psDecoder = WebPINewDecoder(&sp->sDecBuffer);
+  
+  if (sp->psDecoder == NULL) {
+    TIFFErrorExt(tif->tif_clientdata, module,
+                "Unable to allocate WebP decoder.");
+    return 0;
+  }
+  
+  return 1;
+}
+
+static int
+TWebPSetupEncode(TIFF* tif)
+{
+  static const char module[] = "WebPSetupEncode";
+  uint16 nBitsPerSample = tif->tif_dir.td_bitspersample;
+  uint16 sampleFormat = tif->tif_dir.td_sampleformat;
+  
+  WebPState* sp = EncoderState(tif);
+  assert(sp != NULL);
+
+  sp->nSamples = tif->tif_dir.td_samplesperpixel;
+
+  /* check band count */
+  if ( sp->nSamples != 3
+#if WEBP_ENCODER_ABI_VERSION >= 0x0100
+    && sp->nSamples != 4
+#endif
+  )
+  {
+    TIFFErrorExt(tif->tif_clientdata, module,
+      "WEBP driver doesn't support %d bands. Must be 3 (RGB) "
+#if WEBP_ENCODER_ABI_VERSION >= 0x0100
+      "or 4 (RGBA) "
+#endif
+    "bands.",
+    sp->nSamples );
+    return 0;
+  }
+  
+  /* check bits per sample and data type */
+  if ((nBitsPerSample != 8) && (sampleFormat != 1)) {
+    TIFFErrorExt(tif->tif_clientdata, module,
+                "WEBP driver requires 8 bit unsigned data");
+    return 0;
+  }
+  
+  if (sp->state & LSTATE_INIT_DECODE) {
+    WebPIDelete(sp->psDecoder);
+    WebPFreeDecBuffer(&sp->sDecBuffer);
+    sp->psDecoder = NULL;
+    sp->last_y = 0;
+    sp->state = 0;
+  }
+
+  sp->state |= LSTATE_INIT_ENCODE;
+
+  if (!WebPConfigInitInternal(&sp->sEncoderConfig, WEBP_PRESET_DEFAULT,
+                              sp->quality_level,
+                              WEBP_ENCODER_ABI_VERSION)) {
+    TIFFErrorExt(tif->tif_clientdata, module,
+      "Error creating WebP encoder configuration.");
+    return 0;
+  }
+
+#if WEBP_ENCODER_ABI_VERSION >= 0x0100
+  sp->sEncoderConfig.lossless = sp->lossless;
+#endif
+
+  if (!WebPValidateConfig(&sp->sEncoderConfig)) {
+    TIFFErrorExt(tif->tif_clientdata, module,
+      "Error with WebP encoder configuration.");
+    return 0;
+  }
+
+  if (!WebPPictureInit(&sp->sPicture)) {
+    TIFFErrorExt(tif->tif_clientdata, module,
+        "Error initializing WebP picture.");
+    return 0;
+  }
+
+  return 1;
+}
+
+/*
+* Reset encoding state at the start of a strip.
+*/
+static int
+TWebPPreEncode(TIFF* tif, uint16 s)
+{
+  static const char module[] = "TWebPPreEncode";
+  uint32 segment_width, segment_height;
+  WebPState *sp = EncoderState(tif);
+  TIFFDirectory* td = &tif->tif_dir;
+
+  (void) s;
+
+  assert(sp != NULL);
+  if( sp->state != LSTATE_INIT_ENCODE )
+    tif->tif_setupencode(tif);
+
+  /*
+   * Set encoding parameters for this strip/tile.
+   */
+  if (isTiled(tif)) {
+    segment_width = td->td_tilewidth;
+    segment_height = td->td_tilelength;
+  } else {
+    segment_width = td->td_imagewidth;
+    segment_height = td->td_imagelength - tif->tif_row;
+    if (segment_height > td->td_rowsperstrip)
+      segment_height = td->td_rowsperstrip;
+  }
+
+  if( segment_width > 16383 || segment_height > 16383 ) {
+      TIFFErrorExt(tif->tif_clientdata, module, 
+                   "WEBP maximum image dimensions are 16383 x 16383.");
+      return 0;
+  }
+
+  /* set up buffer for raw data */
+  /* given above check and that nSamples <= 4, buffer_size is <= 1 GB */
+  sp->buffer_size = segment_width * segment_height * sp->nSamples;
+  sp->pBuffer = _TIFFmalloc(sp->buffer_size);
+  if( !sp->pBuffer) {
+      TIFFErrorExt(tif->tif_clientdata, module, "Cannot allocate buffer");
+      return 0;
+  }
+  sp->buffer_offset = 0;
+
+  sp->sPicture.width = segment_width;
+  sp->sPicture.height = segment_height;
+  sp->sPicture.writer = TWebPDatasetWriter;
+  sp->sPicture.custom_ptr = tif;
+
+  return 1;
+}
+
+/*
+* Finish off an encoded strip by flushing it.
+*/
+static int
+TWebPPostEncode(TIFF* tif)
+{
+  static const char module[] = "WebPPostEncode";
+  int64_t stride;
+  WebPState *sp = EncoderState(tif);
+  assert(sp != NULL);
+
+  assert(sp->state == LSTATE_INIT_ENCODE);
+
+  stride = (int64_t)sp->sPicture.width * sp->nSamples;
+
+#if WEBP_ENCODER_ABI_VERSION >= 0x0100
+  if (sp->nSamples == 4) {
+      if (!WebPPictureImportRGBA(&sp->sPicture, sp->pBuffer, (int)stride)) {
+          TIFFErrorExt(tif->tif_clientdata, module,
+                    "WebPPictureImportRGBA() failed" );
+          return 0;
+      }
+  }
+  else
+#endif
+  if (!WebPPictureImportRGB(&sp->sPicture, sp->pBuffer, (int)stride)) {
+      TIFFErrorExt(tif->tif_clientdata, module,
+                    "WebPPictureImportRGB() failed");
+      return 0;
+  }
+
+  if (!WebPEncode(&sp->sEncoderConfig, &sp->sPicture)) {
+
+#if WEBP_ENCODER_ABI_VERSION >= 0x0100
+    const char* pszErrorMsg = NULL;
+    switch(sp->sPicture.error_code) {
+    case VP8_ENC_ERROR_OUT_OF_MEMORY:
+        pszErrorMsg = "Out of memory"; break;
+    case VP8_ENC_ERROR_BITSTREAM_OUT_OF_MEMORY:
+        pszErrorMsg = "Out of memory while flushing bits"; break;
+    case VP8_ENC_ERROR_NULL_PARAMETER:
+        pszErrorMsg = "A pointer parameter is NULL"; break;
+    case VP8_ENC_ERROR_INVALID_CONFIGURATION:
+        pszErrorMsg = "Configuration is invalid"; break;
+    case VP8_ENC_ERROR_BAD_DIMENSION:
+        pszErrorMsg = "Picture has invalid width/height"; break;
+    case VP8_ENC_ERROR_PARTITION0_OVERFLOW:
+        pszErrorMsg = "Partition is bigger than 512k. Try using less "
+            "SEGMENTS, or increase PARTITION_LIMIT value";
+        break;
+    case VP8_ENC_ERROR_PARTITION_OVERFLOW:
+        pszErrorMsg = "Partition is bigger than 16M";
+        break;
+    case VP8_ENC_ERROR_BAD_WRITE:
+        pszErrorMsg = "Error while fludshing bytes"; break;
+    case VP8_ENC_ERROR_FILE_TOO_BIG:
+        pszErrorMsg = "File is bigger than 4G"; break;
+    case VP8_ENC_ERROR_USER_ABORT:
+        pszErrorMsg = "User interrupted";
+        break;
+    default:
+        TIFFErrorExt(tif->tif_clientdata, module,
+                "WebPEncode returned an unknown error code: %d",
+                sp->sPicture.error_code);
+        pszErrorMsg = "Unknown WebP error type.";
+        break;
+    }
+    TIFFErrorExt(tif->tif_clientdata, module,
+             "WebPEncode() failed : %s", pszErrorMsg);
+#else
+    TIFFErrorExt(tif->tif_clientdata, module,
+             "Error in WebPEncode()");
+#endif
+    return 0;
+  }
+
+  sp->sPicture.custom_ptr = NULL;
+
+  if (!TIFFFlushData1(tif))
+  {
+    TIFFErrorExt(tif->tif_clientdata, module,
+      "Error flushing TIFF WebP encoder.");
+    return 0;
+  }
+
+  return 1;
+}
+
+static void
+TWebPCleanup(TIFF* tif)
+{
+  WebPState* sp = LState(tif);
+
+  assert(sp != 0);
+
+  tif->tif_tagmethods.vgetfield = sp->vgetparent;
+  tif->tif_tagmethods.vsetfield = sp->vsetparent;
+
+  if (sp->state & LSTATE_INIT_ENCODE) {
+    WebPPictureFree(&sp->sPicture);
+  }
+
+  if (sp->psDecoder != NULL) {
+    WebPIDelete(sp->psDecoder);
+    WebPFreeDecBuffer(&sp->sDecBuffer);
+    sp->psDecoder = NULL;
+    sp->last_y = 0;
+  }
+  
+  if (sp->pBuffer != NULL) {
+    _TIFFfree(sp->pBuffer);
+    sp->pBuffer = NULL;
+  }
+
+  if (tif->tif_data) {
+    _TIFFfree(tif->tif_data);
+    tif->tif_data = NULL;
+  }
+  
+  _TIFFSetDefaultCompressionState(tif);
+}
+
+static int
+TWebPVSetField(TIFF* tif, uint32 tag, va_list ap)
+{
+       static const char module[] = "WebPVSetField";
+  WebPState* sp = LState(tif);
+
+  switch (tag) {
+  case TIFFTAG_WEBP_LEVEL:
+    sp->quality_level = (int) va_arg(ap, int);
+    if( sp->quality_level <= 0 ||
+        sp->quality_level > 100.0f ) {
+      TIFFWarningExt(tif->tif_clientdata, module,
+                     "WEBP_LEVEL should be between 1 and 100");
+    }
+    return 1;
+  case TIFFTAG_WEBP_LOSSLESS:
+    #if WEBP_ENCODER_ABI_VERSION >= 0x0100
+    sp->lossless = va_arg(ap, int);
+    return 1;
+    #else
+      TIFFErrorExt(tif->tif_clientdata, module,
+                  "Need to upgrade WEBP driver, this version doesn't support "
+                  "lossless compression.");
+      return 0;
+    #endif 
+  default:
+    return (*sp->vsetparent)(tif, tag, ap);
+  }
+  /*NOTREACHED*/
+}
+
+static int
+TWebPVGetField(TIFF* tif, uint32 tag, va_list ap)
+{
+  WebPState* sp = LState(tif);
+
+  switch (tag) {
+  case TIFFTAG_WEBP_LEVEL:
+    *va_arg(ap, int*) = sp->quality_level;
+    break;
+  case TIFFTAG_WEBP_LOSSLESS:
+    *va_arg(ap, int*) = sp->lossless;
+    break;
+  default:
+    return (*sp->vgetparent)(tif, tag, ap);
+  }
+  return 1;
+}
+
+static const TIFFField TWebPFields[] = {
+  { TIFFTAG_WEBP_LEVEL, 0, 0, TIFF_ANY, 0, TIFF_SETGET_INT,
+    TIFF_SETGET_UNDEFINED,
+    FIELD_PSEUDO, TRUE, FALSE, "WEBP quality", NULL },
+  { TIFFTAG_WEBP_LOSSLESS, 0, 0, TIFF_ANY, 0, TIFF_SETGET_INT,
+    TIFF_SETGET_UNDEFINED,
+    FIELD_PSEUDO, TRUE, FALSE, "WEBP lossless/lossy", NULL
+  },
+};
+
+int
+TIFFInitWebP(TIFF* tif, int scheme)
+{
+  static const char module[] = "TIFFInitWebP";
+  WebPState* sp;
+
+  assert( scheme == COMPRESSION_WEBP );
+
+  /*
+  * Merge codec-specific tag information.
+  */
+  if ( !_TIFFMergeFields(tif, TWebPFields, TIFFArrayCount(TWebPFields)) ) {
+    TIFFErrorExt(tif->tif_clientdata, module,
+                "Merging WebP codec-specific tags failed");
+    return 0;
+  }
+
+  /*
+  * Allocate state block so tag methods have storage to record values.
+  */
+  tif->tif_data = (uint8*) _TIFFmalloc(sizeof(WebPState));
+  if (tif->tif_data == NULL)
+    goto bad;
+  sp = LState(tif);
+
+  /*
+  * Override parent get/set field methods.
+  */
+  sp->vgetparent = tif->tif_tagmethods.vgetfield;
+  tif->tif_tagmethods.vgetfield = TWebPVGetField;      /* hook for codec tags */
+  sp->vsetparent = tif->tif_tagmethods.vsetfield;
+  tif->tif_tagmethods.vsetfield = TWebPVSetField;      /* hook for codec tags */
+
+  /* Default values for codec-specific fields */
+  sp->quality_level = 75.0f;           /* default comp. level */
+  sp->lossless = 0; /* default to false */
+  sp->state = 0;
+  sp->nSamples = 0;
+  sp->psDecoder = NULL;
+  sp->last_y = 0;
+  
+  sp->buffer_offset = 0;
+  sp->pBuffer = NULL;
+
+  /*
+  * Install codec methods.
+  * Notes:
+  * encoderow is not supported
+  */
+  tif->tif_fixuptags = TWebPFixupTags;
+  tif->tif_setupdecode = TWebPSetupDecode;
+  tif->tif_predecode = TWebPPreDecode;
+  tif->tif_decoderow = TWebPDecode;
+  tif->tif_decodestrip = TWebPDecode;
+  tif->tif_decodetile = TWebPDecode;
+  tif->tif_setupencode = TWebPSetupEncode;
+  tif->tif_preencode = TWebPPreEncode;
+  tif->tif_postencode = TWebPPostEncode;
+  tif->tif_encoderow = TWebPEncode;
+  tif->tif_encodestrip = TWebPEncode;
+  tif->tif_encodetile = TWebPEncode;
+  tif->tif_cleanup = TWebPCleanup;
+
+  return 1;
+bad:
+  TIFFErrorExt(tif->tif_clientdata, module,
+            "No space for WebP state block");
+  return 0;
+}
+
+#endif /* WEBP_SUPPORT */
index a3ada36..d2dd822 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id: tif_win32.c,v 1.42 2017-01-11 19:02:49 erouault Exp $ */
-
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
@@ -411,60 +409,21 @@ _TIFFmemcmp(const void* p1, const void* p2, tmsize_t c)
 static void
 Win32WarningHandler(const char* module, const char* fmt, va_list ap)
 {
 static void
 Win32WarningHandler(const char* module, const char* fmt, va_list ap)
 {
-#ifndef TIF_PLATFORM_CONSOLE
-       LPTSTR szTitle;
-       LPTSTR szTmp;
-       LPCTSTR szTitleText = "%s Warning";
-       LPCTSTR szDefaultModule = "LIBTIFF";
-       LPCTSTR szTmpModule = (module == NULL) ? szDefaultModule : module;
-        SIZE_T nBufSize = (strlen(szTmpModule) +
-                        strlen(szTitleText) + strlen(fmt) + 256)*sizeof(char);
-
-       if ((szTitle = (LPTSTR)LocalAlloc(LMEM_FIXED, nBufSize)) == NULL)
-               return;
-       sprintf(szTitle, szTitleText, szTmpModule);
-       szTmp = szTitle + (strlen(szTitle)+2)*sizeof(char);
-       vsnprintf(szTmp, nBufSize-(strlen(szTitle)+2)*sizeof(char), fmt, ap);
-       MessageBoxA(GetFocus(), szTmp, szTitle, MB_OK | MB_ICONINFORMATION);
-       LocalFree(szTitle);
-
-       return;
-#else
        if (module != NULL)
                fprintf(stderr, "%s: ", module);
        fprintf(stderr, "Warning, ");
        vfprintf(stderr, fmt, ap);
        fprintf(stderr, ".\n");
        if (module != NULL)
                fprintf(stderr, "%s: ", module);
        fprintf(stderr, "Warning, ");
        vfprintf(stderr, fmt, ap);
        fprintf(stderr, ".\n");
-#endif        
 }
 TIFFErrorHandler _TIFFwarningHandler = Win32WarningHandler;
 
 static void
 Win32ErrorHandler(const char* module, const char* fmt, va_list ap)
 {
 }
 TIFFErrorHandler _TIFFwarningHandler = Win32WarningHandler;
 
 static void
 Win32ErrorHandler(const char* module, const char* fmt, va_list ap)
 {
-#ifndef TIF_PLATFORM_CONSOLE
-       LPTSTR szTitle;
-       LPTSTR szTmp;
-       LPCTSTR szTitleText = "%s Error";
-       LPCTSTR szDefaultModule = "LIBTIFF";
-       LPCTSTR szTmpModule = (module == NULL) ? szDefaultModule : module;
-        SIZE_T nBufSize = (strlen(szTmpModule) +
-                        strlen(szTitleText) + strlen(fmt) + 256)*sizeof(char);
-
-       if ((szTitle = (LPTSTR)LocalAlloc(LMEM_FIXED, nBufSize)) == NULL)
-               return;
-       sprintf(szTitle, szTitleText, szTmpModule);
-       szTmp = szTitle + (strlen(szTitle)+2)*sizeof(char);
-       vsnprintf(szTmp, nBufSize-(strlen(szTitle)+2)*sizeof(char), fmt, ap);
-       MessageBoxA(GetFocus(), szTmp, szTitle, MB_OK | MB_ICONEXCLAMATION);
-       LocalFree(szTitle);
-       return;
-#else
        if (module != NULL)
                fprintf(stderr, "%s: ", module);
        vfprintf(stderr, fmt, ap);
        fprintf(stderr, ".\n");
        if (module != NULL)
                fprintf(stderr, "%s: ", module);
        vfprintf(stderr, fmt, ap);
        fprintf(stderr, ".\n");
-#endif        
 }
 TIFFErrorHandler _TIFFerrorHandler = Win32ErrorHandler;
 
 }
 TIFFErrorHandler _TIFFerrorHandler = Win32ErrorHandler;
 
index d0071e2..32603fe 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id: tif_write.c,v 1.46 2016-12-03 21:57:44 erouault Exp $ */
-
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
@@ -541,9 +539,11 @@ TIFFSetupStrips(TIFF* tif)
        if (td->td_planarconfig == PLANARCONFIG_SEPARATE)
                td->td_stripsperimage /= td->td_samplesperpixel;
        td->td_stripoffset = (uint64 *)
        if (td->td_planarconfig == PLANARCONFIG_SEPARATE)
                td->td_stripsperimage /= td->td_samplesperpixel;
        td->td_stripoffset = (uint64 *)
-           _TIFFmalloc(td->td_nstrips * sizeof (uint64));
+            _TIFFCheckMalloc(tif, td->td_nstrips, sizeof (uint64),
+                             "for \"StripOffsets\" array");
        td->td_stripbytecount = (uint64 *)
        td->td_stripbytecount = (uint64 *)
-           _TIFFmalloc(td->td_nstrips * sizeof (uint64));
+            _TIFFCheckMalloc(tif, td->td_nstrips, sizeof (uint64),
+                             "for \"StripByteCounts\" array");
        if (td->td_stripoffset == NULL || td->td_stripbytecount == NULL)
                return (0);
        /*
        if (td->td_stripoffset == NULL || td->td_stripbytecount == NULL)
                return (0);
        /*
index 7ab0212..6dc64b2 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id: tif_zip.c,v 1.37 2017-05-10 15:21:16 erouault Exp $ */
-
 /*
  * Copyright (c) 1995-1997 Sam Leffler
  * Copyright (c) 1995-1997 Silicon Graphics, Inc.
 /*
  * Copyright (c) 1995-1997 Sam Leffler
  * Copyright (c) 1995-1997 Silicon Graphics, Inc.
diff --git a/dll/3rdparty/libtiff/tif_zstd.c b/dll/3rdparty/libtiff/tif_zstd.c
new file mode 100644 (file)
index 0000000..21c935e
--- /dev/null
@@ -0,0 +1,440 @@
+/*
+* Copyright (c) 2017, Planet Labs
+* Author: <even.rouault at spatialys.com>
+*
+* Permission to use, copy, modify, distribute, and sell this software and
+* its documentation for any purpose is hereby granted without fee, provided
+* that (i) the above copyright notices and this permission notice appear in
+* all copies of the software and related documentation, and (ii) the names of
+* Sam Leffler and Silicon Graphics may not be used in any advertising or
+* publicity relating to the software without the specific, prior written
+* permission of Sam Leffler and Silicon Graphics.
+*
+* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
+* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
+* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
+*
+* IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
+* ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
+* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
+* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+* OF THIS SOFTWARE.
+*/
+
+#include "tiffiop.h"
+#ifdef ZSTD_SUPPORT
+/*
+* TIFF Library.
+*
+* ZSTD Compression Support
+*
+*/
+
+#include "tif_predict.h"
+#include "zstd.h"
+
+#include <stdio.h>
+
+/*
+* State block for each open TIFF file using ZSTD compression/decompression.
+*/
+typedef struct {
+        TIFFPredictorState predict;
+        ZSTD_DStream*   dstream;
+        ZSTD_CStream*   cstream;
+        int             compression_level;      /* compression level */
+        ZSTD_outBuffer  out_buffer;
+        int             state;                  /* state flags */
+#define LSTATE_INIT_DECODE 0x01
+#define LSTATE_INIT_ENCODE 0x02
+
+        TIFFVGetMethod  vgetparent;            /* super-class method */
+        TIFFVSetMethod  vsetparent;            /* super-class method */
+} ZSTDState;
+
+#define LState(tif)             ((ZSTDState*) (tif)->tif_data)
+#define DecoderState(tif)       LState(tif)
+#define EncoderState(tif)       LState(tif)
+
+static int ZSTDEncode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s);
+static int ZSTDDecode(TIFF* tif, uint8* op, tmsize_t occ, uint16 s);
+
+static int
+ZSTDFixupTags(TIFF* tif)
+{
+        (void) tif;
+        return 1;
+}
+
+static int
+ZSTDSetupDecode(TIFF* tif)
+{
+        ZSTDState* sp = DecoderState(tif);
+
+        assert(sp != NULL);
+
+        /* if we were last encoding, terminate this mode */
+        if (sp->state & LSTATE_INIT_ENCODE) {
+            ZSTD_freeCStream(sp->cstream);
+            sp->cstream = NULL;
+            sp->state = 0;
+        }
+
+        sp->state |= LSTATE_INIT_DECODE;
+        return 1;
+}
+
+/*
+* Setup state for decoding a strip.
+*/
+static int
+ZSTDPreDecode(TIFF* tif, uint16 s)
+{
+        static const char module[] = "ZSTDPreDecode";
+        ZSTDState* sp = DecoderState(tif);
+        size_t zstd_ret;
+
+        (void) s;
+        assert(sp != NULL);
+
+        if( (sp->state & LSTATE_INIT_DECODE) == 0 )
+            tif->tif_setupdecode(tif);
+
+        if( sp->dstream )
+        {
+            ZSTD_freeDStream(sp->dstream);
+            sp->dstream = NULL;
+        }
+
+        sp->dstream = ZSTD_createDStream();
+        if( sp->dstream == NULL ) {
+            TIFFErrorExt(tif->tif_clientdata, module,
+                         "Cannot allocate decompression stream");
+            return 0;
+        }
+        zstd_ret = ZSTD_initDStream(sp->dstream);
+        if( ZSTD_isError(zstd_ret) ) {
+            TIFFErrorExt(tif->tif_clientdata, module,
+                         "Error in ZSTD_initDStream(): %s",
+                         ZSTD_getErrorName(zstd_ret));
+            return 0;
+        }
+
+        return 1;
+}
+
+static int
+ZSTDDecode(TIFF* tif, uint8* op, tmsize_t occ, uint16 s)
+{
+        static const char module[] = "ZSTDDecode";
+        ZSTDState* sp = DecoderState(tif);
+        ZSTD_inBuffer   in_buffer;
+        ZSTD_outBuffer  out_buffer;
+        size_t          zstd_ret;
+
+        (void) s;
+        assert(sp != NULL);
+        assert(sp->state == LSTATE_INIT_DECODE);
+
+        in_buffer.src = tif->tif_rawcp;
+        in_buffer.size = (size_t) tif->tif_rawcc;
+        in_buffer.pos = 0;
+
+        out_buffer.dst = op;
+        out_buffer.size = (size_t) occ;
+        out_buffer.pos = 0;
+
+        do {
+                zstd_ret = ZSTD_decompressStream(sp->dstream, &out_buffer,
+                                                 &in_buffer);
+                if( ZSTD_isError(zstd_ret) ) {
+                    TIFFErrorExt(tif->tif_clientdata, module,
+                                "Error in ZSTD_decompressStream(): %s",
+                                ZSTD_getErrorName(zstd_ret));
+                    return 0;
+                }
+        } while( zstd_ret != 0 &&
+                 in_buffer.pos < in_buffer.size &&
+                 out_buffer.pos < out_buffer.size );
+
+        if (out_buffer.pos < (size_t)occ) {
+                TIFFErrorExt(tif->tif_clientdata, module,
+                    "Not enough data at scanline %lu (short %lu bytes)",
+                    (unsigned long) tif->tif_row,
+                    (unsigned long) (size_t)occ - out_buffer.pos);
+                return 0;
+        }
+
+        tif->tif_rawcp += in_buffer.pos;
+        tif->tif_rawcc -= in_buffer.pos;
+
+        return 1;
+}
+
+static int
+ZSTDSetupEncode(TIFF* tif)
+{
+        ZSTDState* sp = EncoderState(tif);
+
+        assert(sp != NULL);
+        if (sp->state & LSTATE_INIT_DECODE) {
+                ZSTD_freeDStream(sp->dstream);
+                sp->dstream = NULL;
+                sp->state = 0;
+        }
+
+        sp->state |= LSTATE_INIT_ENCODE;
+        return 1;
+}
+
+/*
+* Reset encoding state at the start of a strip.
+*/
+static int
+ZSTDPreEncode(TIFF* tif, uint16 s)
+{
+        static const char module[] = "ZSTDPreEncode";
+        ZSTDState *sp = EncoderState(tif);
+        size_t zstd_ret;
+
+        (void) s;
+        assert(sp != NULL);
+        if( sp->state != LSTATE_INIT_ENCODE )
+            tif->tif_setupencode(tif);
+
+        if (sp->cstream) {
+            ZSTD_freeCStream(sp->cstream);
+            sp->cstream = NULL;
+        }
+        sp->cstream = ZSTD_createCStream();
+        if( sp->cstream == NULL ) {
+            TIFFErrorExt(tif->tif_clientdata, module,
+                         "Cannot allocate compression stream");
+            return 0;
+        }
+
+        zstd_ret = ZSTD_initCStream(sp->cstream, sp->compression_level);
+        if( ZSTD_isError(zstd_ret) ) {
+            TIFFErrorExt(tif->tif_clientdata, module,
+                         "Error in ZSTD_initCStream(): %s",
+                         ZSTD_getErrorName(zstd_ret));
+            return 0;
+        }
+
+        sp->out_buffer.dst = tif->tif_rawdata;
+        sp->out_buffer.size = (size_t)tif->tif_rawdatasize;
+        sp->out_buffer.pos = 0;
+
+        return 1;
+}
+
+/*
+* Encode a chunk of pixels.
+*/
+static int
+ZSTDEncode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
+{
+        static const char module[] = "ZSTDEncode";
+        ZSTDState *sp = EncoderState(tif);
+        ZSTD_inBuffer   in_buffer;
+        size_t          zstd_ret;
+
+        assert(sp != NULL);
+        assert(sp->state == LSTATE_INIT_ENCODE);
+
+        (void) s;
+
+        in_buffer.src = bp;
+        in_buffer.size = (size_t)cc;
+        in_buffer.pos = 0;
+
+        do {
+                zstd_ret = ZSTD_compressStream(sp->cstream, &sp->out_buffer,
+                                               &in_buffer);
+                if( ZSTD_isError(zstd_ret) ) {
+                    TIFFErrorExt(tif->tif_clientdata, module,
+                                "Error in ZSTD_compressStream(): %s",
+                                ZSTD_getErrorName(zstd_ret));
+                    return 0;
+                }
+                if( sp->out_buffer.pos == sp->out_buffer.size ) {
+                        tif->tif_rawcc = tif->tif_rawdatasize;
+                        TIFFFlushData1(tif);
+                        sp->out_buffer.dst = tif->tif_rawcp;
+                        sp->out_buffer.pos = 0;
+                }
+        } while( in_buffer.pos < in_buffer.size );
+
+        return 1;
+}
+
+/*
+* Finish off an encoded strip by flushing it.
+*/
+static int
+ZSTDPostEncode(TIFF* tif)
+{
+        static const char module[] = "ZSTDPostEncode";
+        ZSTDState *sp = EncoderState(tif);
+        size_t          zstd_ret;
+
+        do {
+                zstd_ret = ZSTD_endStream(sp->cstream, &sp->out_buffer);
+                if( ZSTD_isError(zstd_ret) ) {
+                    TIFFErrorExt(tif->tif_clientdata, module,
+                                "Error in ZSTD_endStream(): %s",
+                                ZSTD_getErrorName(zstd_ret));
+                    return 0;
+                }
+                if( sp->out_buffer.pos > 0 ) {
+                        tif->tif_rawcc = sp->out_buffer.pos;
+                        TIFFFlushData1(tif);
+                        sp->out_buffer.dst = tif->tif_rawcp;
+                        sp->out_buffer.pos = 0;
+                }
+        } while (zstd_ret != 0);
+        return 1;
+}
+
+static void
+ZSTDCleanup(TIFF* tif)
+{
+        ZSTDState* sp = LState(tif);
+
+        assert(sp != 0);
+
+        (void)TIFFPredictorCleanup(tif);
+
+        tif->tif_tagmethods.vgetfield = sp->vgetparent;
+        tif->tif_tagmethods.vsetfield = sp->vsetparent;
+
+        if (sp->dstream) {
+            ZSTD_freeDStream(sp->dstream);
+            sp->dstream = NULL;
+        }
+        if (sp->cstream) {
+            ZSTD_freeCStream(sp->cstream);
+            sp->cstream = NULL;
+        }
+        _TIFFfree(sp);
+        tif->tif_data = NULL;
+
+        _TIFFSetDefaultCompressionState(tif);
+}
+
+static int
+ZSTDVSetField(TIFF* tif, uint32 tag, va_list ap)
+{
+       static const char module[] = "ZSTDVSetField";
+        ZSTDState* sp = LState(tif);
+
+        switch (tag) {
+        case TIFFTAG_ZSTD_LEVEL:
+                sp->compression_level = (int) va_arg(ap, int);
+                if( sp->compression_level <= 0 ||
+                    sp->compression_level > ZSTD_maxCLevel() )
+                {
+                    TIFFWarningExt(tif->tif_clientdata, module,
+                                   "ZSTD_LEVEL should be between 1 and %d",
+                                   ZSTD_maxCLevel());
+                }
+                return 1;
+        default:
+                return (*sp->vsetparent)(tif, tag, ap);
+        }
+        /*NOTREACHED*/
+}
+
+static int
+ZSTDVGetField(TIFF* tif, uint32 tag, va_list ap)
+{
+        ZSTDState* sp = LState(tif);
+
+        switch (tag) {
+        case TIFFTAG_ZSTD_LEVEL:
+                *va_arg(ap, int*) = sp->compression_level;
+                break;
+        default:
+                return (*sp->vgetparent)(tif, tag, ap);
+        }
+        return 1;
+}
+
+static const TIFFField ZSTDFields[] = {
+        { TIFFTAG_ZSTD_LEVEL, 0, 0, TIFF_ANY, 0, TIFF_SETGET_INT,
+          TIFF_SETGET_UNDEFINED,
+          FIELD_PSEUDO, TRUE, FALSE, "ZSTD compression_level", NULL },
+};
+
+int
+TIFFInitZSTD(TIFF* tif, int scheme)
+{
+        static const char module[] = "TIFFInitZSTD";
+        ZSTDState* sp;
+
+        assert( scheme == COMPRESSION_ZSTD );
+
+        /*
+        * Merge codec-specific tag information.
+        */
+        if (!_TIFFMergeFields(tif, ZSTDFields, TIFFArrayCount(ZSTDFields))) {
+                TIFFErrorExt(tif->tif_clientdata, module,
+                            "Merging ZSTD codec-specific tags failed");
+                return 0;
+        }
+
+        /*
+        * Allocate state block so tag methods have storage to record values.
+        */
+        tif->tif_data = (uint8*) _TIFFmalloc(sizeof(ZSTDState));
+        if (tif->tif_data == NULL)
+                goto bad;
+        sp = LState(tif);
+
+        /*
+        * Override parent get/set field methods.
+        */
+        sp->vgetparent = tif->tif_tagmethods.vgetfield;
+        tif->tif_tagmethods.vgetfield = ZSTDVGetField; /* hook for codec tags */
+        sp->vsetparent = tif->tif_tagmethods.vsetfield;
+        tif->tif_tagmethods.vsetfield = ZSTDVSetField; /* hook for codec tags */
+
+        /* Default values for codec-specific fields */
+        sp->compression_level = 9;             /* default comp. level */
+        sp->state = 0;
+        sp->dstream = 0;
+        sp->cstream = 0;
+        sp->out_buffer.dst = NULL;
+        sp->out_buffer.size = 0;
+        sp->out_buffer.pos = 0;
+
+        /*
+        * Install codec methods.
+        */
+        tif->tif_fixuptags = ZSTDFixupTags;
+        tif->tif_setupdecode = ZSTDSetupDecode;
+        tif->tif_predecode = ZSTDPreDecode;
+        tif->tif_decoderow = ZSTDDecode;
+        tif->tif_decodestrip = ZSTDDecode;
+        tif->tif_decodetile = ZSTDDecode;
+        tif->tif_setupencode = ZSTDSetupEncode;
+        tif->tif_preencode = ZSTDPreEncode;
+        tif->tif_postencode = ZSTDPostEncode;
+        tif->tif_encoderow = ZSTDEncode;
+        tif->tif_encodestrip = ZSTDEncode;
+        tif->tif_encodetile = ZSTDEncode;
+        tif->tif_cleanup = ZSTDCleanup;
+        /*
+        * Setup predictor setup.
+        */
+        (void) TIFFPredictorInit(tif);
+        return 1;
+bad:
+        TIFFErrorExt(tif->tif_clientdata, module,
+                    "No space for ZSTD state block");
+        return 0;
+}
+#endif /* ZSTD_SUPPORT */
+
+/* vim: set ts=8 sts=8 sw=8 noet: */
index 8561d82..037b981 100644 (file)
@@ -83,7 +83,7 @@ Used Version: 9c
 Website: http://www.ijg.org/
 
 Title: libtiff
 Website: http://www.ijg.org/
 
 Title: libtiff
-Used Version: 4.0.9
+Used Version: 4.0.10
 Website: http://www.simplesystems.org/libtiff/
 
 Title: mbed TLS
 Website: http://www.simplesystems.org/libtiff/
 
 Title: mbed TLS
index b908f54..fb0951a 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id: t4.h,v 1.3 2010-03-10 18:56:48 bfriesen Exp $ */
-
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
index 94e92bb..e85e2e6 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id: tif_config.wince.h,v 1.3 2010-03-10 18:56:48 bfriesen Exp $ */
-
 /*
  * TIFF library configuration header for Windows CE platform.
  */
 /*
  * TIFF library configuration header for Windows CE platform.
  */
index 5a38076..b2f5e69 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id: tif_dir.h,v 1.55 2017-06-01 12:44:04 erouault Exp $ */
-
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
 
 #ifndef _TIFFDIR_
 #define        _TIFFDIR_
 
 #ifndef _TIFFDIR_
 #define        _TIFFDIR_
+
+#include "tiff.h"
+#include "tiffio.h"
+
 /*
  * ``Library-private'' Directory-related Definitions.
  */
 /*
  * ``Library-private'' Directory-related Definitions.
  */
index 8a43505..abadcd9 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id: tif_fax3.h,v 1.13 2016-12-14 18:36:27 faxguy Exp $ */
-
 /*
  * Copyright (c) 1990-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
 /*
  * Copyright (c) 1990-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
index 6c68e21..a326b9b 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id: tif_predict.h,v 1.9 2016-10-31 17:24:26 erouault Exp $ */
-
 /*
  * Copyright (c) 1995-1997 Sam Leffler
  * Copyright (c) 1995-1997 Silicon Graphics, Inc.
 /*
  * Copyright (c) 1995-1997 Sam Leffler
  * Copyright (c) 1995-1997 Silicon Graphics, Inc.
 
 #ifndef _TIFFPREDICT_
 #define        _TIFFPREDICT_
 
 #ifndef _TIFFPREDICT_
 #define        _TIFFPREDICT_
+
+#include "tiffio.h"
+#include "tiffiop.h"
+
 /*
  * ``Library-private'' Support for the Predictor Tag
  */
 /*
  * ``Library-private'' Support for the Predictor Tag
  */
index fb39634..5b0a0c9 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id: tiff.h,v 1.70 2016-01-23 21:20:34 erouault Exp $ */
-
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
@@ -189,7 +187,11 @@ typedef enum {
 #define     COMPRESSION_SGILOG         34676   /* SGI Log Luminance RLE */
 #define     COMPRESSION_SGILOG24       34677   /* SGI Log 24-bit packed */
 #define     COMPRESSION_JP2000          34712   /* Leadtools JPEG2000 */
 #define     COMPRESSION_SGILOG         34676   /* SGI Log Luminance RLE */
 #define     COMPRESSION_SGILOG24       34677   /* SGI Log 24-bit packed */
 #define     COMPRESSION_JP2000          34712   /* Leadtools JPEG2000 */
+#define     COMPRESSION_LERC            34887   /* ESRI Lerc codec: https://github.com/Esri/lerc */
+/* compression codes 34887-34889 are reserved for ESRI */
 #define            COMPRESSION_LZMA            34925   /* LZMA2 */
 #define            COMPRESSION_LZMA            34925   /* LZMA2 */
+#define            COMPRESSION_ZSTD            50000   /* ZSTD: WARNING not registered in Adobe-maintained registry */
+#define            COMPRESSION_WEBP            50001   /* WEBP: WARNING not registered in Adobe-maintained registry */
 #define        TIFFTAG_PHOTOMETRIC             262     /* photometric interpretation */
 #define            PHOTOMETRIC_MINISWHITE      0       /* min value is white */
 #define            PHOTOMETRIC_MINISBLACK      1       /* min value is black */
 #define        TIFFTAG_PHOTOMETRIC             262     /* photometric interpretation */
 #define            PHOTOMETRIC_MINISWHITE      0       /* min value is white */
 #define            PHOTOMETRIC_MINISBLACK      1       /* min value is black */
@@ -450,6 +452,8 @@ typedef enum {
 /* tag 34929 is a private tag registered to FedEx */
 #define        TIFFTAG_FEDEX_EDR               34929   /* unknown use */
 #define TIFFTAG_INTEROPERABILITYIFD    40965   /* Pointer to Interoperability private directory */
 /* tag 34929 is a private tag registered to FedEx */
 #define        TIFFTAG_FEDEX_EDR               34929   /* unknown use */
 #define TIFFTAG_INTEROPERABILITYIFD    40965   /* Pointer to Interoperability private directory */
+/* tags 50674 to 50677 are reserved for ESRI */
+#define TIFFTAG_LERC_PARAMETERS         50674   /* Stores LERC version and additional compression method */
 /* Adobe Digital Negative (DNG) format tags */
 #define TIFFTAG_DNGVERSION             50706   /* &DNG version number */
 #define TIFFTAG_DNGBACKWARDVERSION     50707   /* &DNG compatibility version */
 /* Adobe Digital Negative (DNG) format tags */
 #define TIFFTAG_DNGVERSION             50706   /* &DNG version number */
 #define TIFFTAG_DNGBACKWARDVERSION     50707   /* &DNG compatibility version */
@@ -603,6 +607,16 @@ typedef enum {
 #define TIFFTAG_PERSAMPLE       65563  /* interface for per sample tags */
 #define     PERSAMPLE_MERGED        0  /* present as a single value */
 #define     PERSAMPLE_MULTI         1  /* present as multiple values */
 #define TIFFTAG_PERSAMPLE       65563  /* interface for per sample tags */
 #define     PERSAMPLE_MERGED        0  /* present as a single value */
 #define     PERSAMPLE_MULTI         1  /* present as multiple values */
+#define TIFFTAG_ZSTD_LEVEL      65564    /* ZSTD compression level */
+#define TIFFTAG_LERC_VERSION            65565 /* LERC version */
+#define     LERC_VERSION_2_4            4
+#define TIFFTAG_LERC_ADD_COMPRESSION    65566 /* LERC additional compression */
+#define     LERC_ADD_COMPRESSION_NONE    0
+#define     LERC_ADD_COMPRESSION_DEFLATE 1
+#define     LERC_ADD_COMPRESSION_ZSTD    2
+#define TIFFTAG_LERC_MAXZERROR          65567    /* LERC maximum error */
+#define TIFFTAG_WEBP_LEVEL               65568 /* WebP compression level: WARNING not registered in Adobe-maintained registry */
+#define TIFFTAG_WEBP_LOSSLESS          65569   /* WebP lossless/lossy : WARNING not registered in Adobe-maintained registry */
 
 /*
  * EXIF tags
 
 /*
  * EXIF tags
index 799a47a..ce08d8a 100644 (file)
@@ -7,15 +7,6 @@
 #ifndef _TIFFCONF_
 #define _TIFFCONF_
 
 #ifndef _TIFFCONF_
 #define _TIFFCONF_
 
-/* Define to 1 if the system has the type `int16'. */
-/* #undef HAVE_INT16 */
-
-/* Define to 1 if the system has the type `int32'. */
-/* #undef HAVE_INT32 */
-
-/* Define to 1 if the system has the type `int8'. */
-/* #undef HAVE_INT8 */
-
 /* The size of a `int', as computed by sizeof. */
 #define SIZEOF_INT 4
 
 /* The size of a `int', as computed by sizeof. */
 #define SIZEOF_INT 4
 
index c8c6c65..fb37a75 100644 (file)
@@ -7,15 +7,6 @@
 #ifndef _TIFFCONF_
 #define _TIFFCONF_
 
 #ifndef _TIFFCONF_
 #define _TIFFCONF_
 
-/* Define to 1 if the system has the type `int16'. */
-/* #undef HAVE_INT16 */
-
-/* Define to 1 if the system has the type `int32'. */
-/* #undef HAVE_INT32 */
-
-/* Define to 1 if the system has the type `int8'. */
-/* #undef HAVE_INT8 */
-
 /* The size of a `int', as computed by sizeof. */
 #define SIZEOF_INT 4
 
 /* The size of a `int', as computed by sizeof. */
 #define SIZEOF_INT 4
 
index 2ef3958..013b096 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id: tiffconf.wince.h,v 1.3 2010-03-10 18:56:49 bfriesen Exp $ */
-
 /*
  * Windows CE platform tiffconf.wince.h
  * Created by Mateusz Loskot (mateusz@loskot.net)
 /*
  * Windows CE platform tiffconf.wince.h
  * Created by Mateusz Loskot (mateusz@loskot.net)
 #ifndef _TIFFCONF_
 #define _TIFFCONF_
 
 #ifndef _TIFFCONF_
 #define _TIFFCONF_
 
-/* Define to 1 if the system has the type `int16'. */
-/* #undef HAVE_INT16 */
-
-/* Define to 1 if the system has the type `int32'. */
-/* #undef HAVE_INT32 */
-
-/* Define to 1 if the system has the type `int8'. */
-/* #undef HAVE_INT8 */
-
 /* The size of a `int', as computed by sizeof. */
 #define SIZEOF_INT 4
 
 /* The size of a `int', as computed by sizeof. */
 #define SIZEOF_INT 4
 
index c7eff6d..e806549 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id: tiffio.h,v 1.94 2017-01-11 19:02:49 erouault Exp $ */
-
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
@@ -52,7 +50,7 @@ typedef struct tiff TIFF;
  *     promoted type (i.e. one of int, unsigned int, pointer,
  *     or double) and because we defined pseudo-tags that are
  *     outside the range of legal Aldus-assigned tags.
  *     promoted type (i.e. one of int, unsigned int, pointer,
  *     or double) and because we defined pseudo-tags that are
  *     outside the range of legal Aldus-assigned tags.
- * NB: tsize_t is int32 and not uint32 because some functions
+ * NB: tsize_t is signed and not unsigned because some functions
  *     return -1.
  * NB: toff_t is not off_t for many reasons; TIFFs max out at
  *     32-bit file offsets, and BigTIFF maxes out at 64-bit
  *     return -1.
  * NB: toff_t is not off_t for many reasons; TIFFs max out at
  *     32-bit file offsets, and BigTIFF maxes out at 64-bit
index ed994f1..df2cbbc 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id: tiffio.hxx,v 1.3 2010-06-08 18:55:15 bfriesen Exp $ */
-
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
@@ -33,6 +31,7 @@
 
 #include <iostream>
 #include "tiff.h"
 
 #include <iostream>
 #include "tiff.h"
+#include "tiffio.h"
 
 extern TIFF* TIFFStreamOpen(const char*, std::ostream *);
 extern TIFF* TIFFStreamOpen(const char*, std::istream *);
 
 extern TIFF* TIFFStreamOpen(const char*, std::ostream *);
 extern TIFF* TIFFStreamOpen(const char*, std::istream *);
index daa291c..186c291 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id: tiffiop.h,v 1.95 2017-09-07 14:02:52 erouault Exp $ */
-
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
 /*
  * Copyright (c) 1988-1997 Sam Leffler
  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
@@ -72,6 +70,7 @@ extern int snprintf(char* str, size_t size, const char* format, ...);
 #endif
 
 #define    streq(a,b)      (strcmp(a,b) == 0)
 #endif
 
 #define    streq(a,b)      (strcmp(a,b) == 0)
+#define    strneq(a,b,n)   (strncmp(a,b,n) == 0)
 
 #ifndef TRUE
 #define        TRUE    1
 
 #ifndef TRUE
 #define        TRUE    1
@@ -314,11 +313,15 @@ typedef size_t TIFFIOSize_t;
 #define _TIFF_off_t off_t
 #endif
 
 #define _TIFF_off_t off_t
 #endif
 
-#if __clang_major__ >= 4 || (__clang_major__ == 3 && __clang_minor__ >= 8)
+#if defined(__has_attribute) && defined(__clang__)
+#if __has_attribute(no_sanitize)
 #define TIFF_NOSANITIZE_UNSIGNED_INT_OVERFLOW __attribute__((no_sanitize("unsigned-integer-overflow")))
 #else
 #define TIFF_NOSANITIZE_UNSIGNED_INT_OVERFLOW
 #endif
 #define TIFF_NOSANITIZE_UNSIGNED_INT_OVERFLOW __attribute__((no_sanitize("unsigned-integer-overflow")))
 #else
 #define TIFF_NOSANITIZE_UNSIGNED_INT_OVERFLOW
 #endif
+#else
+#define TIFF_NOSANITIZE_UNSIGNED_INT_OVERFLOW
+#endif
 
 
 #if defined(__cplusplus)
 
 
 #if defined(__cplusplus)
@@ -424,6 +427,12 @@ extern int TIFFInitSGILog(TIFF*, int);
 #ifdef LZMA_SUPPORT
 extern int TIFFInitLZMA(TIFF*, int);
 #endif
 #ifdef LZMA_SUPPORT
 extern int TIFFInitLZMA(TIFF*, int);
 #endif
+#ifdef ZSTD_SUPPORT
+extern int TIFFInitZSTD(TIFF*, int);
+#endif
+#ifdef WEBP_SUPPORT
+extern int TIFFInitWebP(TIFF*, int);
+#endif
 #ifdef VMS
 extern const TIFFCodec _TIFFBuiltinCODECS[];
 #else
 #ifdef VMS
 extern const TIFFCodec _TIFFBuiltinCODECS[];
 #else
index 7c41574..403d61b 100644 (file)
@@ -1,4 +1,4 @@
-#define TIFFLIB_VERSION_STR "LIBTIFF, Version 4.0.9\nCopyright (c) 1988-1996 Sam Leffler\nCopyright (c) 1991-1996 Silicon Graphics, Inc."
+#define TIFFLIB_VERSION_STR "LIBTIFF, Version 4.0.10\nCopyright (c) 1988-1996 Sam Leffler\nCopyright (c) 1991-1996 Silicon Graphics, Inc."
 /*
  * This define can be used in code that requires
  * compilation-related definitions specific to a
 /*
  * This define can be used in code that requires
  * compilation-related definitions specific to a
@@ -6,4 +6,4 @@
  * version checking should be done based on the
  * string returned by TIFFGetVersion.
  */
  * version checking should be done based on the
  * string returned by TIFFGetVersion.
  */
-#define TIFFLIB_VERSION 20171118
+#define TIFFLIB_VERSION 20181110