summaryrefslogtreecommitdiff
path: root/tiff
diff options
context:
space:
mode:
authorThomas Deutschmann <whissi@gentoo.org>2021-03-30 10:59:39 +0200
committerThomas Deutschmann <whissi@gentoo.org>2021-04-01 00:04:14 +0200
commit5ff1d6955496b3cf9a35042c9ac35db43bc336b1 (patch)
tree6d470f7eb448f59f53e8df1010aec9dad8ce1f72 /tiff
parentImport Ghostscript 9.53.1 (diff)
downloadghostscript-gpl-patches-5ff1d6955496b3cf9a35042c9ac35db43bc336b1.tar.gz
ghostscript-gpl-patches-5ff1d6955496b3cf9a35042c9ac35db43bc336b1.tar.bz2
ghostscript-gpl-patches-5ff1d6955496b3cf9a35042c9ac35db43bc336b1.zip
Import Ghostscript 9.54ghostscript-9.54
Signed-off-by: Thomas Deutschmann <whissi@gentoo.org>
Diffstat (limited to 'tiff')
-rw-r--r--tiff/CMakeLists.txt57
-rw-r--r--tiff/ChangeLog1442
-rw-r--r--tiff/Makefile.in36
-rw-r--r--tiff/Makefile.vc3
-rw-r--r--tiff/RELEASE-DATE2
-rw-r--r--tiff/VERSION2
-rw-r--r--tiff/aclocal.m450
-rw-r--r--tiff/build/Makefile.in4
-rwxr-xr-xtiff/configure221
-rw-r--r--tiff/configure.ac68
-rw-r--r--tiff/contrib/Makefile.in4
-rw-r--r--tiff/contrib/addtiffo/CMakeLists.txt6
-rw-r--r--tiff/contrib/addtiffo/Makefile.in4
-rw-r--r--tiff/contrib/addtiffo/tif_ovrcache.c1
-rw-r--r--tiff/contrib/dbs/CMakeLists.txt11
-rw-r--r--tiff/contrib/dbs/Makefile.in4
-rw-r--r--tiff/contrib/dbs/xtiff/Makefile.in4
-rw-r--r--tiff/contrib/iptcutil/Makefile.in4
-rw-r--r--tiff/contrib/mfs/Makefile.in4
-rw-r--r--tiff/contrib/pds/Makefile.in4
-rw-r--r--tiff/contrib/ras/Makefile.in4
-rw-r--r--tiff/contrib/stream/Makefile.in4
-rw-r--r--tiff/contrib/tags/Makefile.in4
-rw-r--r--tiff/contrib/win_dib/Makefile.in4
-rw-r--r--tiff/contrib/win_dib/tiff2dib.c2
-rw-r--r--tiff/html/Makefile.am3
-rw-r--r--tiff/html/Makefile.in7
-rw-r--r--tiff/html/addingtags.html17
-rw-r--r--tiff/html/bugs.html13
-rw-r--r--tiff/html/build.html16
-rw-r--r--tiff/html/contrib.html17
-rw-r--r--tiff/html/document.html11
-rw-r--r--tiff/html/images.html11
-rw-r--r--tiff/html/images/Makefile.in4
-rw-r--r--tiff/html/index.html6
-rw-r--r--tiff/html/internals.html75
-rw-r--r--tiff/html/intro.html13
-rw-r--r--tiff/html/libtiff.html30
-rw-r--r--tiff/html/man/Makefile.in4
-rw-r--r--tiff/html/misc.html16
-rw-r--r--tiff/html/support.html2
-rw-r--r--tiff/html/tools.html19
-rw-r--r--tiff/html/v3.4beta007.html1
-rw-r--r--tiff/html/v3.4beta016.html1
-rw-r--r--tiff/html/v3.4beta018.html1
-rw-r--r--tiff/html/v3.4beta024.html1
-rw-r--r--tiff/html/v3.4beta028.html1
-rw-r--r--tiff/html/v3.4beta029.html1
-rw-r--r--tiff/html/v3.4beta031.html1
-rw-r--r--tiff/html/v3.4beta032.html1
-rw-r--r--tiff/html/v3.4beta033.html1
-rw-r--r--tiff/html/v3.4beta034.html1
-rw-r--r--tiff/html/v3.4beta035.html1
-rw-r--r--tiff/html/v3.4beta036.html1
-rw-r--r--tiff/html/v3.5.1.html1
-rw-r--r--tiff/html/v3.5.2.html1
-rw-r--r--tiff/html/v3.5.3.html1
-rw-r--r--tiff/html/v3.5.4.html1
-rw-r--r--tiff/html/v3.5.5.html1
-rw-r--r--tiff/html/v3.5.6-beta.html1
-rw-r--r--tiff/html/v3.5.7.html1
-rw-r--r--tiff/html/v3.6.0.html1
-rw-r--r--tiff/html/v3.6.1.html1
-rw-r--r--tiff/html/v3.7.0.html1
-rw-r--r--tiff/html/v3.7.0alpha.html1
-rw-r--r--tiff/html/v3.7.0beta.html1
-rw-r--r--tiff/html/v3.7.0beta2.html1
-rw-r--r--tiff/html/v3.7.1.html1
-rw-r--r--tiff/html/v3.7.2.html1
-rw-r--r--tiff/html/v3.7.3.html1
-rw-r--r--tiff/html/v3.7.4.html1
-rw-r--r--tiff/html/v3.8.0.html1
-rw-r--r--tiff/html/v3.8.1.html1
-rw-r--r--tiff/html/v3.8.2.html1
-rw-r--r--tiff/html/v3.9.0beta.html1
-rw-r--r--tiff/html/v3.9.1.html1
-rw-r--r--tiff/html/v3.9.2.html1
-rw-r--r--tiff/html/v4.0.0.html1
-rw-r--r--tiff/html/v4.0.1.html1
-rw-r--r--tiff/html/v4.0.10.html1
-rw-r--r--tiff/html/v4.0.2.html1
-rw-r--r--tiff/html/v4.0.3.html1
-rw-r--r--tiff/html/v4.0.4.html1
-rw-r--r--tiff/html/v4.0.4beta.html1
-rw-r--r--tiff/html/v4.0.5.html1
-rw-r--r--tiff/html/v4.0.6.html1
-rw-r--r--tiff/html/v4.0.7.html1
-rw-r--r--tiff/html/v4.0.8.html1
-rw-r--r--tiff/html/v4.0.9.html1
-rw-r--r--tiff/html/v4.1.0.html53
-rw-r--r--tiff/html/v4.2.0.html205
-rw-r--r--tiff/libtiff/Makefile.in8
-rw-r--r--tiff/libtiff/libtiff.def8
-rw-r--r--tiff/libtiff/tif_aux.c24
-rw-r--r--tiff/libtiff/tif_compress.c2
-rw-r--r--tiff/libtiff/tif_config.h.in3
-rw-r--r--tiff/libtiff/tif_config.vc.h21
-rw-r--r--tiff/libtiff/tif_dir.c94
-rw-r--r--tiff/libtiff/tif_dir.h2
-rw-r--r--tiff/libtiff/tif_dirinfo.c244
-rw-r--r--tiff/libtiff/tif_dirread.c120
-rw-r--r--tiff/libtiff/tif_dirwrite.c512
-rw-r--r--tiff/libtiff/tif_fax3.c114
-rw-r--r--tiff/libtiff/tif_fax3.h39
-rw-r--r--tiff/libtiff/tif_getimage.c33
-rw-r--r--tiff/libtiff/tif_jbig.c1
-rw-r--r--tiff/libtiff/tif_jpeg.c65
-rw-r--r--tiff/libtiff/tif_luv.c28
-rw-r--r--tiff/libtiff/tif_lzma.c7
-rw-r--r--tiff/libtiff/tif_lzw.c12
-rw-r--r--tiff/libtiff/tif_ojpeg.c63
-rw-r--r--tiff/libtiff/tif_open.c5
-rw-r--r--tiff/libtiff/tif_pixarlog.c31
-rw-r--r--tiff/libtiff/tif_predict.c6
-rw-r--r--tiff/libtiff/tif_read.c18
-rw-r--r--tiff/libtiff/tif_thunder.c8
-rw-r--r--tiff/libtiff/tif_unix.c2
-rw-r--r--tiff/libtiff/tif_webp.c15
-rw-r--r--tiff/libtiff/tif_win32.c60
-rw-r--r--tiff/libtiff/tif_write.c11
-rw-r--r--tiff/libtiff/tif_zip.c280
-rw-r--r--tiff/libtiff/tif_zstd.c6
-rw-r--r--tiff/libtiff/tiff.h117
-rw-r--r--tiff/libtiff/tiffconf.h.cmake.in3
-rw-r--r--tiff/libtiff/tiffconf.h.in3
-rw-r--r--tiff/libtiff/tiffio.h16
-rw-r--r--tiff/libtiff/tiffiop.h21
-rw-r--r--tiff/libtiff/tiffvers.h4
-rw-r--r--tiff/man/Makefile.in4
-rw-r--r--tiff/man/TIFFGetField.3tiff62
-rw-r--r--tiff/man/TIFFReadEncodedStrip.3tiff2
-rw-r--r--tiff/man/TIFFstrip.3tiff6
-rw-r--r--tiff/man/tiff2pdf.13
-rw-r--r--tiff/man/tiff2ps.14
-rw-r--r--tiff/man/tiff2rgba.14
-rw-r--r--tiff/man/tiffcp.115
-rw-r--r--tiff/man/tiffcrop.14
-rw-r--r--tiff/nmake.opt10
-rw-r--r--tiff/port/Makefile.in4
-rw-r--r--tiff/port/Makefile.vc44
-rw-r--r--tiff/port/libport.h12
-rw-r--r--tiff/test/CMakeLists.txt47
-rw-r--r--tiff/test/Makefile.am28
-rw-r--r--tiff/test/Makefile.in129
-rw-r--r--tiff/test/common.sh3
-rw-r--r--tiff/test/custom_dir_EXIF_231.c1398
-rw-r--r--tiff/test/defer_strile_loading.c13
-rw-r--r--tiff/test/images/README.txt3
-rw-r--r--tiff/test/images/deflate-last-strip-extra-data.tiffbin0 -> 12789 bytes
-rw-r--r--tiff/test/images/ojpeg_chewey_subsamp21_multi_strip.tiffbin0 -> 39752 bytes
-rw-r--r--tiff/test/images/ojpeg_single_strip_no_rowsperstrip.tiffbin0 -> 8258 bytes
-rw-r--r--tiff/test/images/ojpeg_zackthecat_subsamp22_single_strip.tiffbin0 -> 8258 bytes
-rw-r--r--tiff/test/images/rgb-3c-16b.ppmbin0 -> 142305 bytes
-rw-r--r--tiff/test/images/testfax4.tiffbin0 -> 39637 bytes
-rwxr-xr-xtiff/test/ppm2tiff_pbm.sh1
-rwxr-xr-xtiff/test/ppm2tiff_pgm.sh1
-rwxr-xr-xtiff/test/ppm2tiff_ppm.sh7
-rw-r--r--tiff/test/rational_precision2double.c972
-rw-r--r--tiff/test/refs/o-deflate-last-strip-extra-data.tiffbin0 -> 12560 bytes
-rw-r--r--tiff/test/refs/o-testfax4.tiffbin0 -> 106326 bytes
-rwxr-xr-xtiff/test/testdeflatelaststripextradata.sh43
-rwxr-xr-xtiff/test/testfax4.sh24
-rwxr-xr-xtiff/test/tiff2ps-EPS1.sh2
-rwxr-xr-xtiff/test/tiff2ps-PS1.sh3
-rwxr-xr-xtiff/test/tiff2ps-PS2.sh2
-rwxr-xr-xtiff/test/tiff2ps-PS3.sh2
-rwxr-xr-xtiff/test/tiff2rgba-ojpeg_chewey_subsamp21_multi_strip.sh7
-rwxr-xr-xtiff/test/tiff2rgba-ojpeg_single_strip_no_rowsperstrip.sh7
-rwxr-xr-xtiff/test/tiff2rgba-ojpeg_zackthecat_subsamp22_single_strip.sh7
-rw-r--r--tiff/tools/CMakeLists.txt27
-rw-r--r--tiff/tools/Makefile.in4
-rw-r--r--tiff/tools/fax2ps.c30
-rw-r--r--tiff/tools/fax2tiff.c23
-rw-r--r--tiff/tools/pal2rgb.c50
-rw-r--r--tiff/tools/ppm2tiff.c230
-rw-r--r--tiff/tools/raw2tiff.c63
-rw-r--r--tiff/tools/rgb2ycbcr.c32
-rw-r--r--tiff/tools/thumbnail.c32
-rw-r--r--tiff/tools/tiff2bw.c40
-rw-r--r--tiff/tools/tiff2pdf.c409
-rw-r--r--tiff/tools/tiff2ps.c122
-rw-r--r--tiff/tools/tiff2rgba.c62
-rw-r--r--tiff/tools/tiffcmp.c42
-rw-r--r--tiff/tools/tiffcp.c149
-rw-r--r--tiff/tools/tiffcrop.c235
-rw-r--r--tiff/tools/tiffdither.c46
-rw-r--r--tiff/tools/tiffdump.c17
-rw-r--r--tiff/tools/tiffgt.c51
-rw-r--r--tiff/tools/tiffinfo.c103
-rw-r--r--tiff/tools/tiffmedian.c49
-rw-r--r--tiff/tools/tiffset.c61
-rw-r--r--tiff/tools/tiffsplit.c17
192 files changed, 8001 insertions, 1290 deletions
diff --git a/tiff/CMakeLists.txt b/tiff/CMakeLists.txt
index 35b48770..efe857df 100644
--- a/tiff/CMakeLists.txt
+++ b/tiff/CMakeLists.txt
@@ -43,17 +43,13 @@ if (POLICY CMP0054)
endif(POLICY CMP0054)
# Read version information from configure.ac.
-FILE(READ "${CMAKE_CURRENT_SOURCE_DIR}/configure.ac" configure)
-STRING(REGEX REPLACE ";" "\\\\;" configure "${configure}")
-STRING(REGEX REPLACE "\n" ";" configure "${configure}")
+FILE(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/configure.ac" configure REGEX "^LIBTIFF_.*=")
foreach(line ${configure})
foreach(var LIBTIFF_MAJOR_VERSION LIBTIFF_MINOR_VERSION LIBTIFF_MICRO_VERSION LIBTIFF_ALPHA_VERSION
LIBTIFF_CURRENT LIBTIFF_REVISION LIBTIFF_AGE)
- if(NOT ${var})
- string(REGEX MATCH "^${var}=(.*)" ${var}_MATCH "${line}")
- if(${var}_MATCH)
- string(REGEX REPLACE "^${var}=(.*)" "\\1" ${var} "${line}")
- endif()
+ if(NOT ${var} AND line MATCHES "^${var}=(.*)")
+ set(${var} "${CMAKE_MATCH_1}")
+ break()
endif()
endforeach()
endforeach()
@@ -207,7 +203,9 @@ else()
endif()
# Find libm, if available
-find_library(M_LIBRARY m)
+if(NOT MINGW)
+ find_library(M_LIBRARY m)
+endif()
check_include_file(assert.h HAVE_ASSERT_H)
check_include_file(dlfcn.h HAVE_DLFCN_H)
@@ -404,6 +402,9 @@ endif()
# CPU endianness
include(TestBigEndian)
test_big_endian(HOST_BIG_ENDIAN)
+if(HOST_BIG_ENDIAN)
+ add_definitions(-DWORDS_BIGENDIAN)
+endif()
# IEEE floating point
set(HAVE_IEEEFP 1)
@@ -456,6 +457,33 @@ if(ZLIB_FOUND)
set(ZLIB_SUPPORT 1)
endif()
set(ZIP_SUPPORT ${ZLIB_SUPPORT})
+
+
+# libdeflate
+option(libdeflate "use libdeflate (optional for faster Deflate support, still requires zlib)" ON)
+if (libdeflate)
+ set(DEFLATE_FOUND 0)
+ find_path(DEFLATE_INCLUDE_DIR libdeflate.h)
+ set(DEFLATE_NAMES ${DEFLATE_NAMES} deflate)
+ find_library(DEFLATE_LIBRARY NAMES ${DEFLATE_NAMES})
+ if (DEFLATE_INCLUDE_DIR AND DEFLATE_LIBRARY)
+ set(DEFLATE_FOUND 1)
+ set(DEFLATE_LIBRARIES ${DEFLATE_LIBRARY})
+ endif()
+endif()
+set(LIBDEFLATE_SUPPORT FALSE)
+if(DEFLATE_FOUND)
+ set(LIBDEFLATE_SUPPORT TRUE)
+endif()
+
+if(LIBDEFLATE_SUPPORT AND NOT ZIP_SUPPORT)
+ message(WARNING "libdeflate available but zlib is not. libdeflate cannot be used")
+ set(LIBDEFLATE_SUPPORT FALSE)
+endif()
+
+set(LIBDEFLATE_SUPPORT ${LIBDEFLATE_SUPPORT})
+
+
# Option for Pixar log-format algorithm
# Pixar log format
@@ -654,6 +682,9 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libtiff-4.pc
if(ZLIB_INCLUDE_DIRS)
list(APPEND TIFF_INCLUDES ${ZLIB_INCLUDE_DIRS})
endif()
+if(DEFLATE_INCLUDE_DIR)
+ list(APPEND TIFF_INCLUDES ${DEFLATE_INCLUDE_DIR})
+endif()
if(JPEG_INCLUDE_DIR)
list(APPEND TIFF_INCLUDES ${JPEG_INCLUDE_DIR})
endif()
@@ -675,12 +706,15 @@ endif()
# Libraries required by libtiff
set(TIFF_LIBRARY_DEPS)
-if(M_LIBRARY)
- list(APPEND TIFF_LIBRARY_DEPS ${M_LIBRARY})
+if(NOT MINGW AND M_LIBRARY)
+ list(APPEND TIFF_LIBRARY_DEPS "m")
endif()
if(ZLIB_LIBRARIES)
list(APPEND TIFF_LIBRARY_DEPS ${ZLIB_LIBRARIES})
endif()
+if(DEFLATE_LIBRARIES)
+ list(APPEND TIFF_LIBRARY_DEPS ${DEFLATE_LIBRARIES})
+endif()
if(JPEG_LIBRARIES)
list(APPEND TIFF_LIBRARY_DEPS ${JPEG_LIBRARIES})
endif()
@@ -736,6 +770,7 @@ message(STATUS " LogLuv high dynamic range encoding: ${logluv}")
message(STATUS "")
message(STATUS " Support for external codecs:")
message(STATUS " ZLIB support: ${zlib} (requested) ${ZLIB_FOUND} (availability)")
+message(STATUS " libdeflate support: ${libdeflate} (requested) ${LIBDEFLATE_SUPPORT} (availability)")
message(STATUS " Pixar log-format algorithm: ${pixarlog} (requested) ${PIXARLOG_SUPPORT} (availability)")
message(STATUS " JPEG support: ${jpeg} (requested) ${JPEG_FOUND} (availability)")
message(STATUS " Old JPEG support: ${old-jpeg} (requested) ${JPEG_FOUND} (availability)")
diff --git a/tiff/ChangeLog b/tiff/ChangeLog
index 01e2182c..452dcb3a 100644
--- a/tiff/ChangeLog
+++ b/tiff/ChangeLog
@@ -1,3 +1,1445 @@
+2020-12-19 Bob Friesenhahn <bfriesen@simple.dallas.tx.us>
+
+ * libtiff 4.2.0 released.
+
+ * configure.ac: Pass tar-ustar option to AM_INIT_AUTOMAKE rather
+ than tar-pax since ustar POSIX 1003.1-1988 format is more portable
+ than PAX POSIX 1003.1-2001 format.
+
+2020-12-12 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'w_adjust-deflate_names' into 'master'
+ Set 'deflate' to DEFLATE_NAMES, instead of 'libdeflate'
+
+ See merge request libtiff/libtiff!174
+
+2020-12-12 Lemures Lemniscati <lemures.lemniscati@gmail.com>
+
+ Set 'deflate' to DEFLATE_NAMES, instead of 'libdeflate'
+ 'lib' will be automatically added as a prefix while doing find_library()
+
+2020-12-12 Even Rouault <even.rouault@spatialys.com>
+
+ DoubleToRational(): avoid casting NaN to uint32 (fixes #227)
+
+2020-12-12 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'fix_221' into 'master'
+ tiffio.h: do not define __attribute__ but defines TIFF_ATTRIBUTE instead (fixes #221)
+
+ Closes #221
+
+ See merge request libtiff/libtiff!173
+
+2020-12-12 Even Rouault <even.rouault@spatialys.com>
+
+ tiffio.h: do not define __attribute__ but defines TIFF_ATTRIBUTE instead (fixes #221)
+
+2020-12-08 Even Rouault <even.rouault@spatialys.com>
+
+ TIFFReadDirEntryArrayWithLimit(): properly read from offline tag value when we clamp the number of strips to 1.
+ Fixes regression of commit 7057734d986001b7fd6d2afde9667da7754ff2cc on reading
+ a file with StripByteCounts with 1 element (broken) and StripOffsets with
+ 896 elements, and where StripOffsets[0] is correct
+
+ $ tiffdump foo.tif
+ Magic: 0x4949 <little-endian> Version: 0x2a <ClassicTIFF>
+ Directory 0: offset 25725448 (0x1888a08) next 0 (0)
+ SubFileType (254) LONG (4) 1<0>
+ ImageWidth (256) LONG (4) 1<640>
+ ImageLength (257) LONG (4) 1<20098>
+ BitsPerSample (258) SHORT (3) 1<16>
+ Photometric (262) SHORT (3) 1<1>
+ SamplesPerPixel (277) SHORT (3) 1<1>
+ ResolutionUnit (296) SHORT (3) 1<2>
+ StripByteCounts (279) LONG (4) 1<1806>
+ StripOffsets (273) LONG (4) 896<8 648 1288 1928 2568 3208 3848 4488 5128 5768 6408 7048 7688 8328 8968 9608 10248 10888 11528 12168 12808 13448 14088 14728 ...>
+
+2020-12-02 Even Rouault <even.rouault@spatialys.com>
+
+ tif_jpeg.c: avoid potential harmless unsigned integer overflow on data->fileoffset in JPEGFixupTagsSubsamplingSkip() by validating earlier. Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=28200
+
+2020-11-27 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'Jamaika1-master-patch-47839' into 'master'
+ Change ULARGE_INTEGER to LARGE_INTEGER
+
+ See merge request libtiff/libtiff!170
+
+2020-11-27 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'Jamaika1-master-patch-46397' into 'master'
+ Added stdint.h
+
+ See merge request libtiff/libtiff!171
+
+2020-11-27 Jamaika <lukaszcz18@wp.pl>
+
+ Added stdint.h.
+
+ ``` tif_win32.c: In function '_tiffSizeProc': tif_win32.c:159:23: warning: passing argument 2 of 'GetFileSizeEx' from incompatible pointer type [-Wincompatible-pointer-types] 159 | if (GetFileSizeEx(fd,&m)) | ^~ | | | ULARGE_INTEGER * In file included from c:\msys1021\x86_64-w64-mingw32\include\winbase.h:18, from c:\msys1021\x86_64-w64-mingw32\include\windows.h:70, from tif_win32.c:32: c:\msys1021\x86_64-w64-mingw32\include\fileapi.h:78:73: note: expected 'PLARGE_INTEGER' {aka 'LARGE_INTEGER *'} but argument is of type 'ULARGE_INTEGER *' 78 | WINBASEAPI WINBOOL WINAPI GetFileSizeEx (HANDLE hFile, PLARGE_INTEGER lpFileSize); | ~~~~~~~~~~~~~~~^~~~~~~~~~ ```
+
+2020-11-21 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-113' into 'master'
+ tiffcrop: fix buffer overrun in extractContigSamples24bits()
+
+ Closes #113
+
+ See merge request libtiff/libtiff!169
+
+2020-11-21 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-156' into 'master'
+ tiff2pdf: Check output size before writing
+
+ Closes #156
+
+ See merge request libtiff/libtiff!168
+
+2020-11-21 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-201' into 'master'
+ tiff2pdf: enforce memory limit for tiled pictures too
+
+ Closes #201
+
+ See merge request libtiff/libtiff!167
+
+2020-11-20 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-207' into 'master'
+ enforce (configurable) memory limit in tiff2rgba
+
+ Closes #209 et #207
+
+ See merge request libtiff/libtiff!165
+
+2020-11-20 Even Rouault <even.rouault@spatialys.com>
+
+ tif_lzw.c: avoid false positive -Wnull-dereference of mingw32 gcc 7.3.
+
+2020-11-17 Thomas Bernard <miniupnp@free.fr>
+
+ tiffcrop: fix buffer overrun in extractContigSamples24bits()
+ fixes #113
+
+ tiff2pdf: Check output size before writing.
+ fixes #156
+
+ tiff2pdf: enforce memory limit for tiled pictures too.
+ fixes #201
+
+2020-11-15 Thomas Bernard <miniupnp@free.fr>
+
+ tiff2rgba.1: -M option.
+
+ enforce (configurable) memory limit in tiff2rgba.
+ fixes #207
+ fixes #209
+
+2020-11-14 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-220' into 'master'
+ tiff2pdf.c: properly calculate datasize when saving to JPEG YCbCr
+
+ Closes #220
+
+ See merge request libtiff/libtiff!159
+
+2020-11-14 Thomas Bernard <miniupnp@free.fr>
+
+ tiff2pdf.c: properly calculate datasize when saving to JPEG YCbCr.
+ fixes #220
+
+2020-11-14 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-204' into 'master'
+ avoid buffer overflow while writing jpeg end of file marker
+
+ Closes #204
+
+ See merge request libtiff/libtiff!161
+
+2020-11-14 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-193' into 'master'
+ fix buffer overflow in tiff2ps.c
+
+ Closes #193
+
+ See merge request libtiff/libtiff!162
+
+2020-11-14 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'skal65535-master-patch-91082' into 'master'
+ More overflow fixes for large widths
+
+ See merge request libtiff/libtiff!164
+
+2020-11-14 skal <pascal.massimino@gmail.com>
+
+ More overflow fixes for large width.
+ Also: use INT_MAX instead of hard-coded constants.
+
+2020-11-12 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'skal65535-master-patch-56655' into 'master'
+ Fix potential overflow in gtStripContig()
+
+ See merge request libtiff/libtiff!163
+
+2020-11-12 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-211' into 'master'
+ check for tile width overflow
+
+ Closes #211
+
+ See merge request libtiff/libtiff!160
+
+2020-11-12 skal <pascal.massimino@gmail.com>
+
+ Fix potential overflow in gtStripContig()
+ (w + w) might not fit in int32 if too large.
+
+2020-11-09 Thomas Bernard <miniupnp@free.fr>
+
+ tiff2ps.c: fix buffer overread.
+ fixes #193
+
+ fix undefined behaviour (int shifted too much to the left)
+
+ avoid buffer overflow while writing jpeg end of file marker.
+ fixes #204
+
+ gtTileContig(): check Tile width for overflow.
+ fixes #211
+
+ fix warning messages (v32 is unsigned)
+
+2020-10-26 Even Rouault <even.rouault@spatialys.com>
+
+ TIFFStartStrip(): avoid potential crash in WebP codec when using scanline access on corrupted files. Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=26650
+
+2020-10-20 Even Rouault <even.rouault@spatialys.com>
+
+ tif_webp.c: validate tile/strip dimension to avoid unsigned integer overflow in RGBA.size computation
+
+2020-10-19 Even Rouault <even.rouault@spatialys.com>
+
+ tif_zip.c: fix typo in comment.
+
+2020-10-16 Even Rouault <even.rouault@spatialys.com>
+
+ tiff.h: remove irrelevant warning about webp related pseudo-tags not being registered: they are purely internal libtiff concepts
+
+2020-10-16 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'libdeflate' into 'master'
+ Add support for building against libdeflate for faster Zip/Deflate compression/decompression
+
+ See merge request libtiff/libtiff!158
+
+2020-10-16 Even Rouault <even.rouault@spatialys.com>
+
+ test: add testdeflatelaststripextradata.sh.
+
+2020-10-16 Even Rouault <even.rouault@spatialys.com>
+
+ Add support for optional building against libdeflate for faster Zip/Deflate compression/decompression.
+ So we can have 2 kind of builds with the Zip/Deflate codec:
+ - zlib only
+ - zlib + libdeflate
+
+ Speed improvements in the 35%-50% range can be expected when libdeflate is used.
+ Compression level up to 12 is now supported (capped to 9 when zlib is used).
+ Still requires zlib for situations where libdeflate cannot be used (that
+ is for scanline access, since libdeflate has no streaming mode)
+
+ Pseudo-tag TIFFTAG_DEFLATE_SUBCODEC=DEFLATE_SUBCODEC_ZLIB/DEFLATE_SUBCODEC_LIBDEFLATE
+ is added to control which subcodec (zlib or libdeflate) should be used (it defaults
+ of course to libdeflate, when it is available).
+ This is mostly aimed at being used on the writing side, to be able to reproduce
+ output of previous libtiff versions at a binary level, in situations where this would
+ be really needed. Or as a safety belt in case there would be unforeseen issues
+ with using libdeflate.
+ It can be used to know when libdeflate is available at runtime (DEFLATE_SUBCODEC_LIBDEFLATE
+ will be the default value in that situation).
+
+ Of course, deflate codestreams produced by libdeflate can be read by zlib, and vice-versa.
+
+2020-10-14 Even Rouault <even.rouault@spatialys.com>
+
+ tif_webp.c: fix compiler warnings with MSVC.
+
+2020-10-12 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'various_fixes' into 'master'
+ Fix compiler warnings about unused variables when assert() expands to nothing
+
+ See merge request libtiff/libtiff!157
+
+2020-10-12 Even Rouault <even.rouault@spatialys.com>
+
+ .gitignore: add entries for new files in test/
+
+ Fix compiler warnings about unused variables when assert() expands to nothing
+
+2020-10-09 Roger Leigh <rleigh@codelibre.net>
+
+ Merge branch '215-cygwin-appveyor-fail' into 'master'
+ Update Appveyor CI build to build with VS2019 image
+
+ Closes #215
+
+ See merge request libtiff/libtiff!154
+
+2020-10-09 Roger Leigh <rleigh@codelibre.net>
+
+ wip.
+
+ wip.
+
+ wip.
+
+ wip.
+
+ wip.
+
+ wip.
+
+2020-10-09 Roger Leigh <rleigh@codelibre.net>
+
+ Merge branch 'TIFF-217_m_lib_path' into 'master'
+ cmake: Do not use absolute libm path
+
+ Closes #217
+
+ See merge request libtiff/libtiff!156
+
+2020-10-09 Roger Leigh <rleigh@codelibre.net>
+
+ cmake: Do not use absolute libm path.
+
+2020-10-08 Even Rouault <even.rouault@spatialys.com>
+
+ tif_fax3.h: restore systematic calls to CLEANUP_RUNS()
+ now that SETVALUE() no longer cause overflows.
+ Those were removed per b351db8be1b4d3f712bdb9424a79d3174cc03202 and
+ 3440ac216463fcad170bbb391491e69730a59ffa.
+
+ As SETVALUE() now returns an error, this allow the decoder to exit.
+
+ Otherwise, the assert(x == lastx) in _TIFFFax3fillruns() can trigger.
+
+ Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=26201
+
+2020-10-06 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'check_TIFFFlushData1' into 'master'
+ FAX/JPEG/LZMA/PixarLog/ZIP/ZSTD codecs: make sure to check TIFFFlushData1() return value
+
+ See merge request libtiff/libtiff!155
+
+2020-10-04 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'shared-memory' into 'master'
+ Set the --shared-memory linker flag for Emscripten builds
+
+ See merge request libtiff/libtiff!153
+
+2020-10-03 Even Rouault <even.rouault@spatialys.com>
+
+ tiff2rgba.c: fix -Wold-style-declaration warning.
+
+ FAX/JPEG/LZMA/PixarLog/ZIP/ZSTD codecs: make sure to check TIFFFlushData1() return value
+
+2020-09-26 Even Rouault <even.rouault@spatialys.com>
+
+ tif_fax3.h: extra buffer overflow checks. Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=25934
+
+2020-09-25 Roger Leigh <rleigh@codelibre.net>
+
+ wip.
+
+ wip.
+
+ wip.
+
+ wip.
+
+ wip.
+
+ wip.
+
+ Update AppVeyor image.
+
+ test-appveyor.
+
+2020-09-24 Attila Oláh <atl@google.com>
+
+ Also pass --shared-memory to raw_decode.
+ This is needed when building for Emscripten with *both* WEBP and JPEG
+ support.
+
+ Set the --shared-memory linker flag for Emscripten builds.
+ This is only needed when building with WEBP support, which uses atomics,
+ therefore the linker needs the --shared-memory flag. The flag cannot be
+ added globally because not all executables link against libwebp.
+
+2020-09-22 Even Rouault <even.rouault@spatialys.com>
+
+ tif_fax3.h: return error when a buffer overflow occurs. Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=25552 and https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=25849
+
+2020-09-11 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'fix-float-compare' into 'master'
+ Fix comparison for max negative float value.
+
+ See merge request libtiff/libtiff!152
+
+2020-09-11 Dirk Lemstra <dirk@lemstra.org>
+
+ Fix comparison for max negative float value.
+
+2020-09-07 Even Rouault <even.rouault@spatialys.com>
+
+ Fax3PreDecode(): reset curruns and refruns state variables.
+ to avoid out-of-bounds write triggered by GDAL when repeatedly
+ reading a corrupt strip.
+
+ Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=25493
+
+2020-06-06 Thomas Bernard <miniupnp@free.fr>
+
+ Merge branch 'issue-17' into 'master'
+ normalize tools behaviour regarding -h
+
+ Closes #17
+
+ See merge request libtiff/libtiff!115
+
+2020-05-31 Even Rouault <even.rouault@spatialys.com>
+
+ TWebPSetupEncode(): fix logic problem (and instead of or) in test that checks input is 8bit unsigned data
+
+2020-05-12 Even Rouault <even.rouault@spatialys.com>
+
+ TIFFGetConfiguredCODECs(): fix to avoid wrong structure to be returned for registered (ie non built-in) codecs
+
+2020-05-09 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'zstd-webp-update' into 'master'
+ gitlab-ci: use latest zstd and webp versions
+
+ See merge request libtiff/libtiff!148
+
+2020-05-09 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'deprecated' into 'master'
+ ojpeg: s/Depreciated/Deprecated/
+
+ See merge request libtiff/libtiff!149
+
+2020-05-09 Aaron Boxer <boxerab@gmail.com>
+
+ ojpeg: s/Depreciated/Deprecated/
+
+2020-04-27 Even Rouault <even.rouault@spatialys.com>
+
+ Fix typos.
+
+ tif_jpeg.c: avoid potential division in previous fix (master only)
+
+2020-04-26 Thomas Bernard <miniupnp@free.fr>
+
+ gitlab-ci: use latest zstd and webp versions.
+
+2020-04-26 Even Rouault <even.rouault@spatialys.com>
+
+ tiff.h: fixes to use ASCII only characters (master only)
+
+2020-04-26 Thomas Bernard <miniupnp@free.fr>
+
+ tiffsplit: use EXIT_SUCCESS / EXIT_FAILURE.
+
+ tiffset: print usage on stdout when -h is used.
+ also use EXIT_FAILURE / EXIT_SUCCESS
+ see #17
+
+ tiffmedian: shopw usage on stdout when -h is used.
+ aslo use EXIT_SUCCESS/EXIT_FAILURE
+ see #17
+
+ tiffinfo: print usage on stdout when -h is used.
+ also use EXIT_FAILURE / EXIT_SUCCESS
+ see #17
+
+ raw2tiff: print usage to stdout when -h is used.
+ see #17
+
+ tiff2pdf: print usage on stdout when -h is used.
+ see #17
+
+ tiffgt: output usage on stdout with -h.
+ also use EXIT_SUCCESS / EXIT_FAILURE
+
+ tiffdump: use EXIT_FAILURE / EXIT_SUCCESS.
+ see #17
+
+ tiffdither: print usage on stdout when -h is used.
+ see #17
+
+2020-04-26 Thomas Bernard <miniupnp@free.fr>
+
+ tiffcrop: -h / -v prints usage/version to stdout.
+ also uses the standard C EXIT_SUCCESS / EXIT_FAILURE
+ macros
+
+ see #17
+
+2020-04-26 Thomas Bernard <miniupnp@free.fr>
+
+ tiffcp: output usage to stdout when using -h.
+ also use EXIT_FAILURE / EXIT_SUCCESS
+ see #17
+
+ tiffcmp: match exit status for posix cmp and diff tools.
+
+ tiff2rgba: output usage to stdout when using -h.
+ also uses std C EXIT_FAILURE / EXIT_SUCCESS
+ see #17
+
+ tiff2ps: sue EXIT_FAILURE / EXIT_SUCCESS.
+ see #17
+
+ tiff2bw: output usage on stdout when using -h.
+ also uses EXIT_SUCCESS / EXIT_FAILURE
+ see #17
+
+ thumbnail: use EXIT_FAILURE / EXIT_SUCCESS.
+ the -h option was already used so it cannot be used for help/usage
+ see #17
+
+ rgb2ycbcr: use EXIT_FAILURE / EXIT_SUCCESS.
+ the -h option was already used so it cannot be used for help/usage
+ see #17
+
+ ppm2tiff: output usage to stdout when using -h option.
+ also uses std C EXIT_SUCCESS / EXIT_FAILURE
+ see #17
+
+ pal2rgb: output usage to stdout when -h is used.
+ see #17
+
+ fax2tiff.c: print usage on stdout when using -h option.
+ see #17
+
+ fax2ps: output usage to stdout when using -h option.
+ also use EXIT_SUCCESS, EXIT_FAILURE from C standard
+
+2020-04-25 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'jpeg_multiscan_dos_logic' into 'master'
+ tif_jpeg.c: revise logic to detect potential excessive memory usage when...
+
+ See merge request libtiff/libtiff!147
+
+2020-04-24 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-176' into 'master'
+ tiff2pdf: get rid of uninitialized memory content
+
+ Closes #176
+
+ See merge request libtiff/libtiff!143
+
+2020-04-24 Even Rouault <even.rouault@spatialys.com>
+
+ tif_jpeg.c: revise logic to detect potential excessive memory usage when decoding multiscan JPEG compressed images
+
+2020-04-19 Thomas Bernard <miniupnp@free.fr>
+
+ tiff2pdf: test the return code of TIFFReadRawStrip() and TIFFReadRawTile()
+
+ tiff2pdf.c: fix some whitespace problems in source.
+
+ tiff2pdf: get rid of uninitialized memory content.
+ fixes #176
+
+2020-04-19 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-18' into 'master'
+ tiffset: pass size for TIFFTAG_INKNAMES
+
+ Closes #18
+
+ See merge request libtiff/libtiff!146
+
+2020-04-18 Olivier Paquet <olivier.paquet@gmail.com>
+
+ Merge branch 'issue-80' into 'master'
+ tiffinfo: fix dump of Tiled images
+
+ Closes #80
+
+ See merge request libtiff/libtiff!144
+
+2020-04-15 Even Rouault <even.rouault@spatialys.com>
+
+ Fix wrong file size checks for memory-mapped BigTIFF files that could lead to image rejection
+
+2020-04-05 Thomas Bernard <miniupnp@free.fr>
+
+ tiffset: pass size for TIFFTAG_INKNAMES.
+ Uses TIFFFieldPassCount() to know which arguments need to be
+ passed to TiffSetField()
+
+ fixes #18
+ see http://bugzilla.maptools.org/show_bug.cgi?id=2202
+
+2020-04-04 Thomas Bernard <miniupnp@free.fr>
+
+ tiffinfo: showdata for tiled images.
+
+ tiffinfo: fix dump of Tiled images.
+ fixes #80
+
+2020-04-03 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-117' into 'master'
+ tiffcrop: enforce memory allocation limit
+
+ Closes #117
+
+ See merge request libtiff/libtiff!140
+
+2020-04-03 Thomas Bernard <miniupnp@free.fr>
+
+ tiffcrop: enforce memory allocation limit.
+ uses -k option to change limit (default to 256MiB)
+ fixes #117 / http://bugzilla.maptools.org/show_bug.cgi?id=2757
+
+2020-04-02 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-45' into 'master'
+ tiffcp: disable strip chopping when trying to convert to JBIG compression
+
+ Closes #45
+
+ See merge request libtiff/libtiff!138
+
+2020-04-02 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-124' into 'master'
+ TIFFGetFields(3tiff): TIFFTAG_*BYTECOUNTS TIFFTAG_*OFFSETS are uint64
+
+ Closes #124
+
+ See merge request libtiff/libtiff!137
+
+2020-04-02 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'aix_itrunc' into 'master'
+ Rename itrunc to fix name clash with a different itrunc in math.h on AIX. Fixes issue #189
+
+ Closes #189
+
+ See merge request libtiff/libtiff!139
+
+2020-04-01 Rob Boehne <robb@datalogics.com>
+
+ Rename itrunc to fix name clash with a different itrunc in math.h on AIX. Fixes issue #189
+
+2020-04-01 Thomas Bernard <miniupnp@free.fr>
+
+ tiffcp: disable strip chopping when trying to convert to JBIG compression
+ fixes #45
+
+2020-03-29 Thomas Bernard <miniupnp@free.fr>
+
+ TIFFGetFields(3tiff): TIFFTAG_*BYTECOUNTS TIFFTAG_*OFFSETS are uint64.
+ fixes #124 / http://bugzilla.maptools.org/show_bug.cgi?id=2774
+
+2020-03-29 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-48' into 'master'
+ tiff2pdf: fix "raw" copy of Deflate streams
+
+ Closes #48
+
+ See merge request libtiff/libtiff!136
+
+2020-03-27 Thomas Bernard <miniupnp@free.fr>
+
+ tiff2pdf: fix "raw" copy of Deflate streams.
+ The Predictor parametter was not copied from the source tiff to the PDF.
+ fixes #48 / http://bugzilla.maptools.org/show_bug.cgi?id=2442
+
+2020-03-26 Thomas Bernard <miniupnp@free.fr>
+
+ tif_fax3: quit Fax3Decode2D() when a buffer overflow occurs.
+ fixes #186
+
+2020-03-24 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-143-144' into 'master'
+ tiffdump: avoid unaligned memory access
+
+ Closes #144 et #143
+
+ See merge request libtiff/libtiff!133
+
+2020-03-24 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-133' into 'master'
+ tiff2pdf: avoid divide by 0
+
+ Closes #133
+
+ See merge request libtiff/libtiff!126
+
+2020-03-24 Thomas Bernard <miniupnp@free.fr>
+
+ tiff2pdf: normalizePoint() macro to normalize the white point.
+
+2020-03-23 Thomas Bernard <miniupnp@free.fr>
+
+ tiffdump: avoid unaligned memory access.
+ fixes #143
+ fixes #144
+
+2020-03-23 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'out-of-memory' into 'master'
+ tiffcp/tiff2pdf/tiff2ps: enforce maximum malloc size
+
+ Closes #153, #84, #116 et #115
+
+ See merge request libtiff/libtiff!130
+
+2020-03-23 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-157' into 'master'
+ tiffset: check memory allocation
+
+ Closes #157
+
+ See merge request libtiff/libtiff!132
+
+2020-03-23 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-185' into 'master'
+ tif_fax3: more buffer overflow checks in Fax3Decode2D()
+
+ Closes #185
+
+ See merge request libtiff/libtiff!131
+
+2020-03-23 Thomas Bernard <miniupnp@free.fr>
+
+ tiffset: check memory allocation.
+ fixes #157 / http://bugzilla.maptools.org/show_bug.cgi?id=2850
+
+ tif_fax3: more buffer overflow checks in Fax3Decode2D()
+ fixes #185
+
+2020-03-21 Thomas Bernard <miniupnp@free.fr>
+
+ tiff2ps: enforce memory allocation limit.
+ fixes #153 / http://bugzilla.maptools.org/show_bug.cgi?id=2845
+
+ tiff2pdf: enforce maximum data size.
+ fixes #116 / http://bugzilla.maptools.org/show_bug.cgi?id=2756
+ fixes #84 / http://bugzilla.maptools.org/show_bug.cgi?id=2683
+
+ update man page for tiffcp regarding the -m option.
+
+ tiffcp.c: _TIFFmalloc() => limitMalloc()
+
+2020-03-21 Thomas Bernard <miniupnp@free.fr>
+
+ tiffcp: enforce maximum malloc size.
+ default is 256MB. use -m option to change
+
+ fixes #115 / http://bugzilla.maptools.org/show_bug.cgi?id=2755
+
+2020-03-21 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-184' into 'master'
+ CmakeLists.txt: define WORDS_BIGENDIAN when the CPU is big endian
+
+ Closes #184
+
+ See merge request libtiff/libtiff!127
+
+2020-03-21 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-44' into 'master'
+ tiff2pdf: "" causes the relevant argument not to be written
+
+ Closes #44
+
+ See merge request libtiff/libtiff!128
+
+2020-03-21 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-56' into 'master'
+ fix man for TIFFReadEncodedStrip(), TIFFStripSize, TIFFVStripSize, TIFFRawStripSize
+
+ Closes #56
+
+ See merge request libtiff/libtiff!129
+
+2020-03-20 Thomas Bernard <miniupnp@free.fr>
+
+ fix man for TIFFReadEncodedStrip(), TIFFStripSize, TIFFVStripSize, TIFFRawStripSize
+ fixes #56
+ http://bugzilla.maptools.org/show_bug.cgi?id=2507
+
+ tiff2pdf: "" causes the relevant argument not to be written.
+ fixes #44
+
+ CmakeLists.txt: define WORDS_BIGENDIAN when the CPU is big endian.
+ fixes #184
+
+2020-03-17 Thomas Bernard <miniupnp@free.fr>
+
+ tiff2pdf: avoid divide by 0.
+ fixes #133 http://bugzilla.maptools.org/show_bug.cgi?id=2796
+
+2020-03-17 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-22' into 'master'
+ do not _tiffMapProc 0 size files
+
+ Closes #22
+
+ See merge request libtiff/libtiff!125
+
+2020-03-13 Thomas Bernard <miniupnp@free.fr>
+
+ tif_win32.c: do not _tiffMapProc() 0 sized files.
+ see #22
+
+ tif_unix.c: do not _tiffMapProc 0 size files.
+ fixes #22
+ http://bugzilla.maptools.org/show_bug.cgi?id=2249
+
+2020-03-12 Even Rouault <even.rouault@spatialys.com>
+
+ tif_fax3.c: fix warning C4018: '<': signed/unsigned mismatch introduced in past commits
+
+2020-03-11 Even Rouault <even.rouault@spatialys.com>
+
+ tiff.h: mention TIFFTAG_RPCCOEFFICIENT, TIFFTAG_TIFF_RSID, TIFFTAG_GEO_METADATA
+
+2020-03-11 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-60' into 'master'
+ added support for more private tags
+
+ Closes #60
+
+ See merge request libtiff/libtiff!124
+
+2020-03-11 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-160' into 'master'
+ Fax3SetupState(): check consistency of rowbytes and rowpixels
+
+ Closes #160
+
+ See merge request libtiff/libtiff!123
+
+2020-03-11 Thomas Bernard <miniupnp@free.fr>
+
+ added support for more private tags.
+ see https://gitlab.com/libtiff/libtiff/-/issues/60
+ bugzilla.maptools.org/show_bug.cgi?id=2525
+
+ closes #60
+
+ original author : art1@andreas-romeyke.de
+
+2020-03-11 Thomas Bernard <miniupnp@free.fr>
+
+ Fax3SetupState(): check consistency of rowbytes and rowpixels.
+ also add some parameter documentation to Fax3Decode1D()
+
+ fixes #160
+ http://bugzilla.maptools.org/show_bug.cgi?id=2854
+
+2020-03-10 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-11-const-pointers' into 'master'
+ Make pointers returned via TIFFGetField const
+
+ Closes #11
+
+ See merge request libtiff/libtiff!118
+
+2020-03-10 Even Rouault <even.rouault@spatialys.com>
+
+ tif_ojpeg.c: relax again too strict sanity checks to allow reading of valid images such as https://gitlab.com/libtiff/libtiff/-/issues/181#note_302535232. Fixes #181
+
+2020-03-09 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-52' into 'master'
+ contrib/win_dib/tiff2dib: fix Uninitialized variable: lpBits
+
+ Closes #52
+
+ See merge request libtiff/libtiff!121
+
+2020-03-09 Thomas Bernard <miniupnp@free.fr>
+
+ contrib/win_dib/tiff2dib: fix Uninitialized variable: lpBits.
+ fixes #52
+ http://bugzilla.maptools.org/show_bug.cgi?id=2469
+
+2020-03-08 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-58' into 'master'
+ Make TIFFTAG_CFAPATTERN variable count
+
+ Closes #58
+
+ See merge request libtiff/libtiff!120
+
+2020-03-08 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-158-no-predictor-in-webp' into 'master'
+ TIFFTAG_PREDICTOR is not supported for WebP
+
+ Closes #158
+
+ See merge request libtiff/libtiff!119
+
+2020-03-08 Sam Hasinoff <hasinoff@google.com>
+
+ Make TIFFTAG_CFAPATTERN variable count.
+ The TIFFTAG_CFAPATTERN tag (33422) from TIFF/EP, recently introduced in libtiff
+ 3363eda09d082e3e1dfffa6281f53085cac51ad3 / http://bugzilla.maptools.org/show_bug.cgi?id=2457
+ is described as having a fixed count of 4.
+ But the TIFF/EP spec says this should support a variable count (= CFARepeatRows * CFARepeatCols):
+
+ TIFF/EP, ISO 12234-2:2001
+ http://www.barrypearson.co.uk/top2009/downloads/TAG2000-22_DIS12234-2.pdf
+ page 18 and 26
+
+2020-03-08 Thomas Bernard <miniupnp@free.fr>
+
+ TIFFTAG_PREDICTOR is not supported for WebP.
+ fixes #158
+ https://gitlab.com/libtiff/libtiff/-/issues/158
+
+ this bug was introduced by 9eacd59fecc4ef593ac17689bc530ab451c8ec14
+ merge request !32
+
+2020-03-07 Adam Goode <adam@spicenitz.org>
+
+ Make the default whitepoint and ycbcrcoeffs arrays const.
+ Now that we are returning const pointers in TIFFGetFieldDefaulted,
+ we can now make these static default arrays const.
+
+ see #11
+
+2020-03-07 Adam Goode <adam@spicenitz.org>
+
+ Make pointers returned via TIFFGetField const.
+ According to http://bugzilla.maptools.org/show_bug.cgi?id=2125#c6
+ callers are not allowed to modify pointer or array values returned from
+ TIFFGetField or the like. So, make this explicit in the documentation
+ by specifying these things as const. Note that this is not an ABI
+ change, since C does not encode const in libraries. Also, this is
+ not really an API change, since the varargs call strips away all
+ the types anyway. So it really is more of a documentation change.
+
+ fixes #11
+
+2020-03-07 Even Rouault <even.rouault@spatialys.com>
+
+ CMake: Skip custom_dir_EXIF_231 test on shared builds to avoid issues on Windows
+
+2020-03-07 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'EXIF231_GPS_upgrade' into 'master'
+ EXIF 2.32 and GPS TIFF-tags and functionality upgraded.
+
+ See merge request libtiff/libtiff!91
+
+2020-03-07 Su_Laus <sulau@freenet.de>
+
+ EXIF 2.32 and GPS tags and functionality upgraded.
+ - Existing EXIF field definition of tags is upgraded to EXIF version 2.3.2
+ - EXIF-GPS structure, tags and access functions are added as special CustomDirectory (like it was done for EXIF).
+ - Test program custom_dir_EXIF_231.c added to test writing/reading of EXID IFD and GPS IFD tags
+ and to highlight some quirks of IFD-handling and peculiarities of reading/writing the different data types.
+ - Reading error for FileSource and SceneType tags corrected.
+
+ - EXIF_GPS_upgrade rebased onto c8c5309b765ef4ff097d2aaffbdb8f403db8967d (Merge branch 'Rational2DoublePrecision_correction' into 'master')
+ and adapted:
+ - tif_dirinfo.c: All rational tags set to TIFF_SETGET_FLOAT but only the GPSTAG_ tags set to TIFF_SETGET_DOUBLE.
+ - custom_dir_EXIF_231.c: Editorials amended and gcc warnigs fixed.
+ - CMakeLists.txt: add_test(NAME "custom_dir_EXIF_231" COMMAND "custom_dir_EXIF_231") added.
+
+2020-03-07 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-55' into 'master'
+ ppm2tiff: support any bps value from 1 to 16
+
+ Closes #55
+
+ See merge request libtiff/libtiff!106
+
+2020-03-07 Thomas Bernard <miniupnp@free.fr>
+
+ ppm2tiff: Add test for 16bpc PPM.
+
+ ppm2tiff: remove unused argument warning.
+
+2020-03-07 Ludolf Holzheid <ludolf.holzheid@gmx.de>
+
+ ppm2tiff: support any bps value from 1 to 16.
+ fix #55
+ http://bugzilla.maptools.org/show_bug.cgi?id=2505
+
+ Patch originally submited by Ludolf Holzheid <ludolf.holzheid@gmx.de>
+
+2020-03-06 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'fax-test' into 'master'
+ add test for fax4 decoding
+
+ See merge request libtiff/libtiff!114
+
+2020-03-05 Thomas Bernard <miniupnp@free.fr>
+
+ add test for fax4 decoding.
+ This will check for regression on #46
+ https://gitlab.com/libtiff/libtiff/issues/46
+ http://bugzilla.maptools.org/show_bug.cgi?id=2434
+
+2020-03-05 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'freebsd-tests' into 'master'
+ make tests pass under FreeBSD.
+
+ See merge request libtiff/libtiff!113
+
+2020-03-05 Thomas Bernard <miniupnp@free.fr>
+
+ make tests pass under FreeBSD.
+ the -I option for the GNU diff and the FreeBSD diff
+ behaves differently regarding escaping the ( ) and |
+
+ By using two -I option, we avoid using such charracters.
+
+2020-03-05 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-31' into 'master'
+ HTML
+
+ Closes #31
+
+ See merge request libtiff/libtiff!111
+
+2020-03-05 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-179' into 'master'
+ tif_fax3.h: check for buffer overflow in EXPAND2D before "calling" CLEANUP_RUNS()
+
+ Closes #179
+
+ See merge request libtiff/libtiff!112
+
+2020-03-05 Thomas Bernard <miniupnp@free.fr>
+
+ v4.1.0.html: fix for validation.
+ long <!----------------> comments were replaced
+ because they confused some parsers
+
+ add DOCTYPE on v*.html.
+
+ fix HTML files so they are valid according to https://validator.w3.org.
+
+2020-03-05 Thomas Bernard <miniupnp@free.fr>
+
+ tif_fax3.h: check for buffer overflow in EXPAND2D before "calling" CLEANUP_RUNS()
+ fixes #179
+
+ this fixes the regression introduced in 02bb0175 / 72c4acef
+ ( merge request !110 )
+
+ It may be a better fix to do the overflow check in SETVALUE() but the
+ macro do { } while(0) construct makes it difficult to quit the loop
+ properly.
+
+2020-03-01 Thomas Bernard <miniupnp@free.fr>
+
+ index.html: fix unclosed <tt> tag.
+
+2020-03-01 Thomas Bernard <miniupnp@free.fr>
+
+ html: do not force colors (which are default anyway)
+ If needed, style should be set using CSS.
+
+ fixes #31
+ https://gitlab.com/libtiff/libtiff/issues/31
+ http://bugzilla.maptools.org/show_bug.cgi?id=2326
+
+2020-03-01 Even Rouault <even.rouault@spatialys.com>
+
+ TIFFReadCustomDirectory(): fix potential heap buffer overflow when reading a custom directory, after a regular directory where a codec was active. Fixes https://gitlab.com/libtiff/libtiff/issues/178
+
+2020-03-01 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-46' into 'master'
+ fix decoding of fax4 images
+
+ Closes #46
+
+ See merge request libtiff/libtiff!110
+
+2020-02-29 Thomas Bernard <miniupnp@free.fr>
+
+ tif_fax3: better fix for CVE-2011-0192.
+ There are some legitimate case which were forbidden by the previous fix
+
+ tif_fax3.h: allow 0 length run in DECODE2D.
+ fixes #46
+ https://gitlab.com/libtiff/libtiff/issues/46
+ http://bugzilla.maptools.org/show_bug.cgi?id=2434
+
+2020-02-29 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'mingwlibm' into 'master'
+ Don't use libm with libtiff due to conflict with libmsvcrt
+
+ See merge request libtiff/libtiff!73
+
+2020-02-29 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'Rational2DoublePrecision_correction' into 'master'
+ tif_dirwrite.c: bugfix DoubleToSrational() for plain signed integers
+
+ See merge request libtiff/libtiff!109
+
+2020-02-29 Su_Laus <sulau@freenet.de>
+
+ tif_dirwrite.c: bugfix DoubleToSrational(), which returns plain signed interger values always as unsigned rationals. Add a test into rational_precision2double.c for "-1.0" and some editorials in tif_dirwrite.c. (code is related to 6df997c786928757caea0dd68d26ea5f098f49df changes).
+
+2020-02-29 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-174' into 'master'
+ tif_fax3.c: check buffer overflow in Fax4Decode()
+
+ Closes #174
+
+ See merge request libtiff/libtiff!108
+
+2020-02-29 Thomas Bernard <miniupnp@free.fr>
+
+ Fax4Decode(): log error message in case of buffer overrun.
+
+ tif_fax3.c: check buffer overflow in Fax4Decode()
+ fixes #174
+
+2020-02-28 Even Rouault <even.rouault@spatialys.com>
+
+ typo fixes in code comments.
+
+ ToRationalEuclideanGCD: remove useless test that confuses Coverity Scan about a potential later modulo by zero
+
+2020-02-27 Even Rouault <even.rouault@spatialys.com>
+
+ tif_dirwrite.c: fix other warnings related to 6df997c786928757caea0dd68d26ea5f098f49df changes
+
+ rational_precision2double.c: fix many warnings, and do not build it on CMake on shared lib builds
+
+ tif_dirwrite.c: fix various warnings found when building GDAL with internal libtiff after 6df997c786928757caea0dd68d26ea5f098f49df changes
+
+ tif_dirwrite.c: qualify ToRationalEuclideanGCD() with static.
+
+2020-02-27 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'Rational2DoublePrecision' into 'master'
+ Rational with Double Precision Upgrade
+
+ See merge request libtiff/libtiff!100
+
+2020-02-27 Su_Laus <sulau@freenet.de>
+
+ Rational with Double Precision Upgrade.
+ Unfortunately, custom rational tags (TIFF_RATIONAL with field_bit=FIELD_CUSTOM) are defined as TIFF_SETGET_DOUBLE
+ but for the reading interface and LibTiff internally they are stored ALLWAYS as floating point SINGLE precision.
+ Double precision custom rational tags are not supported by LibTiff.
+
+ For the GPS tags in WGS84 a higher accuracy / precision is needed.
+ Therefore, this upgrade is made, keeping the old interface for the already defined tags and allowing a double precision definition,
+ as well as calculating rationals with higher accuracy / precision.
+ This higher accuracy can be used for newly defined tags like that in EXIF/GPS.
+
+ Refer also to the very old Bugzilla issue 2542 (#69)
+
+ A test file rational_precision2double.c is added, which shows prevention of the old interface to the already defined custom rational tags
+ with the standard library as well as with the upgraded library.
+
+ Also TIFFTAG_XRESOLUTION, TIFFTAG_YRESOLUTION, TIFFTAG_XPOSITION, TIFFTAG_YPOSITION amended from TIFF_SETGET_DOUBLE to TIFF_SETGET_FLOAT and testcase inserted in rational_precision2double.c
+
+2020-02-26 Chris Degawa <ccom@randomderp.com>
+
+ mingw-w64 cmake: Don't find libm.
+ mingw-w64 will provide libm symbols by default without -lm and mingw-64's
+ libm is just a stub.
+
+ This is just to make sure that on systems with msys2 and also cygwin, cmake
+ doesn't find a libm that actually contains math functions.
+
+2020-02-26 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'division-by-zero' into 'master'
+ tools/tiffcp.c: fix potential division by zero
+
+ See merge request libtiff/libtiff!83
+
+2020-02-26 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'fix-unused-warning' into 'master'
+ warnings: mark conditionally used parameters
+
+ See merge request libtiff/libtiff!49
+
+2020-02-26 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'master' into 'master'
+ fix issue #78 warnings regarding RichTIFFIPTC data type
+
+ Closes #78
+
+ See merge request libtiff/libtiff!99
+
+2020-02-26 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'win64-handle-casts-warn-fix' into 'master'
+ Avoid warnings about casts between HANDLE and int in Win64 builds
+
+ Closes #2
+
+ See merge request libtiff/libtiff!93
+
+2020-02-26 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'bug2839' into 'master'
+ raw2tiff: avoid divide by 0
+
+ Closes #151
+
+ See merge request libtiff/libtiff!103
+
+2020-02-26 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'bug2669' into 'master'
+ tiff2pdf: palette bound check in t2p_sample_realize_palette()
+
+ Closes #82
+
+ See merge request libtiff/libtiff!104
+
+2020-02-26 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'int-shift' into 'master'
+ tiffcrop: fix asan runtime error caused by integer promotion
+
+ See merge request libtiff/libtiff!105
+
+2020-02-26 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'bug-2538' into 'master'
+ libtiff.html: fix function casing
+
+ Closes #68
+
+ See merge request libtiff/libtiff!107
+
+2020-02-16 Thomas Bernard <miniupnp@free.fr>
+
+ raw2tiff: avoid divide by 0.
+ fixes #151 / http://bugzilla.maptools.org/show_bug.cgi?id=2839
+
+ first memcmp() lines before computing corellation
+ and always avoid divide by 0 anyway
+
+2020-02-09 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'bug2855' into 'master'
+ tiff2ps: fix heap buffer read overflow in PSDataColorContig()
+
+ Closes #161
+
+ See merge request libtiff/libtiff!102
+
+2020-02-08 Thomas Bernard <miniupnp@free.fr>
+
+ libtiff.html: fix function casing.
+
+ libtiff.html: fix function casing.
+ fixes #68 / http://bugzilla.maptools.org/show_bug.cgi?id=2538
+
+2020-02-08 Thomas Bernard <miniupnp@free.fr>
+
+ tiffcrop: fix asan runtime error caused by integer promotion.
+ tiffcrop.c:4027:20: runtime error: left shift of 190 by 24 places cannot be represented in type 'int'
+
+ C treats (byte << 24) as an int expression.
+ casting explicitely to unsigned type uint32 avoids the problem.
+
+ the same issue has been fixed elsewhere with a24213691616e7cd35aa3e2805493de80c7e4fcf
+
+ I detected the bug with the test file of #86
+
+2020-02-08 Thomas Bernard <miniupnp@free.fr>
+
+ tiff2pdf: palette bound check in t2p_sample_realize_palette()
+ fixes #82
+
+2020-02-08 Thomas Bernard <miniupnp@free.fr>
+
+ tiff2ps: fix heap buffer read overflow in PSDataColorContig()
+ fixes #161 / http://bugzilla.maptools.org/show_bug.cgi?id=2855
+
+ in 05029fb7f1ecf771abaf90b5705b6cab9eb522a7 I missed that 1 extra byte is read
+ in this loop.
+
+2020-02-05 Even Rouault <even.rouault@spatialys.com>
+
+ tif_dirread.c: suppress CLang static Analyzer 9.0 false positive.
+
+2020-02-01 Even Rouault <even.rouault@spatialys.com>
+
+ TIFFSetupStrips: enforce 2GB limitation of Strip/Tile Offsets/ByteCounts arrays
+ TIFFWriteDirectoryTagData() has an assertion that checks that the
+ arrays are not larger than 2GB. So error out earlier if in that situation.
+
+2020-01-29 Bob Friesenhahn <bfriesen@simple.dallas.tx.us>
+
+ Simplify nmake configuration for building port directory. Now there is only one boolean setting to enable building strtoll() and strtoull() port functions. The boolean setting enables the necessary port files to be built, but the remainder of the logic is via pre-processor code in the common tif_config.h, which was prepared before entering the port directory to do a build.
+
+2020-01-28 Bob Friesenhahn <bfriesen@simple.dallas.tx.us>
+
+ Make sure that tif_config.h is produced prior to entering the port directory and add an include path so that the port files can include tif_config.h. Do not actually include tif_config.h at this time since CMake and Autotools builds are not prepared for that. This issue could be handled by updating the CMake and Autotools builds or by adding a define which directs libport.h to include tif_config.h.
+
+2020-01-26 Bob Friesenhahn <bfriesen@simple.dallas.tx.us>
+
+ Fix nmake build mistakes in my last commit:
+ tif_config.vc.h:
+
+ Always define HAVE_STRTOL/HAVE_STRTOUL.
+ Define HAVE_STRTOLL/HAVE_STRTOULL if _MSC_VER >= 1900.
+
+ nmake.opt:
+
+ Provide defaults suitable for MSVC prior to 14.0.
+
+ libport.h:
+
+ The sense of the pre-processor logic was inverted from what it
+ should be. The intention is to only provide the prototype if the
+ function is missing.
+
+2020-01-25 Bob Friesenhahn <bfriesen@simple.dallas.tx.us>
+
+ Add nmake build support for manually configuring the 'port' files to be built based on MSVC features. Include tif_config.h in tools/tiffset.c.
+
+2020-01-23 Even Rouault <even.rouault@spatialys.com>
+
+ Adjust previous fix to avoid undue warning in some situations triggered by GDAL
+
+2020-01-12 Even Rouault <even.rouault@spatialys.com>
+
+ _TIFFPartialReadStripArray: bring back support for non-conformant SLONG8 data type
+ Such as in https://github.com/OSGeo/gdal/issues/2165
+
+2020-01-07 Even Rouault <even.rouault@spatialys.com>
+
+ test: add test for single-strip OJPEG file without RowsPerStrip tag (like in CR2 files)
+
+ OJPEGReadHeaderInfo: if rowsperstrip not defined, then assume one-single-strip. Complementary fix to 0356ea76bac908c61160d735f078437ace953bd3
+
+2019-12-16 Angel Sánchez <angelsanchez@inedit.com>
+
+ fix issue #78 warnings regarding RichTIFFIPTC data type.
+
+2019-12-14 Even Rouault <even.rouault@spatialys.com>
+
+ contrib/oss-fuzz/build.sh: fix broken if construct.
+
+2019-11-28 Even Rouault <even.rouault@spatialys.com>
+
+ contrib/oss-fuzz/build.sh: other attempt at fixing build failure.
+
+2019-11-20 Even Rouault <even.rouault@spatialys.com>
+
+ contrib/oss-fuzz/build.sh: install liblzma-dev for x86_64 builds.
+
+2019-11-17 Even Rouault <even.rouault@spatialys.com>
+
+ contrib/oss-fuzz/build.sh: install liblzma-dev:i386 on i386 builds.
+
+2019-11-15 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'cmake-parse' into 'master'
+ CMake: simplify parsing variables from configure
+
+ See merge request libtiff/libtiff!98
+
+2019-11-15 Rolf Eike Beer <eb@emlix.com>
+
+ CMake: simplify parsing variables from configure.
+
+2019-11-14 Even Rouault <even.rouault@spatialys.com>
+
+ contrib/oss-fuzz/build.sh: fix ossfuzz build by statically linking to lzma
+
+2019-11-12 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'fix_ojpeg_172' into 'master'
+ OJPEG: fix broken sanity check added in 4.1.0 (#fixes 172)
+
+ See merge request libtiff/libtiff!97
+
+2019-11-11 Even Rouault <even.rouault@spatialys.com>
+
+ OJPEG: fix broken sanity check added in 4.1.0, and add two OJPEG test files
+
+ test/: add missing generated .sh files.
+
+2019-11-04 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'fix-missing-checks-TIFFGetField-tiffcrop' into 'master'
+ adds missing checks on TIFFGetField in tiffcrop tool
+
+ Closes #170
+
+ See merge request libtiff/libtiff!96
+
+2019-11-04 Bug Checkers <coolbugcheckers@gmail.com>
+
+ adds missing checks on TIFFGetField in tiffcrop tool (fixes #170)
+
+2019-11-04 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'adds-missing-TIFFClose-rgb2ycbcr' into 'master'
+ adds a missing TIFFClose in rgb2ycbcr tool
+
+ See merge request libtiff/libtiff!95
+
+2019-11-04 Mansour Ahmadi <mansourweb@gmail.com>
+
+ adds a missing TIFFClose in rgb2ycbcr tool.
+
2019-11-03 Bob Friesenhahn <bfriesen@simple.dallas.tx.us>
libtiff 4.1.0 released.
diff --git a/tiff/Makefile.in b/tiff/Makefile.in
index 625934a3..a4a7b80c 100644
--- a/tiff/Makefile.in
+++ b/tiff/Makefile.in
@@ -1,7 +1,7 @@
-# Makefile.in generated by automake 1.16.1 from Makefile.am.
+# Makefile.in generated by automake 1.16.2 from Makefile.am.
# @configure_input@
-# Copyright (C) 1994-2018 Free Software Foundation, Inc.
+# Copyright (C) 1994-2020 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -722,6 +722,10 @@ dist-xz: distdir
tardir=$(distdir) && $(am__tar) | XZ_OPT=$${XZ_OPT--e} xz -c >$(distdir).tar.xz
$(am__post_remove_distdir)
+dist-zstd: distdir
+ tardir=$(distdir) && $(am__tar) | zstd -c $${ZSTD_CLEVEL-$${ZSTD_OPT--19}} >$(distdir).tar.zst
+ $(am__post_remove_distdir)
+
dist-tarZ: distdir
@echo WARNING: "Support for distribution archives compressed with" \
"legacy program 'compress' is deprecated." >&2
@@ -763,6 +767,8 @@ distcheck: dist
eval GZIP= gzip $(GZIP_ENV) -dc $(distdir).shar.gz | unshar ;;\
*.zip*) \
unzip $(distdir).zip ;;\
+ *.tar.zst*) \
+ zstd -dc $(distdir).tar.zst | $(am__untar) ;;\
esac
chmod -R a-w $(distdir)
chmod u+w $(distdir)
@@ -944,19 +950,19 @@ uninstall-am: uninstall-dist_docDATA uninstall-pkgconfigDATA
am--refresh check check-am clean clean-cscope clean-generic \
clean-libtool cscope cscopelist-am ctags ctags-am dist \
dist-all dist-bzip2 dist-gzip dist-lzip dist-shar dist-tarZ \
- dist-xz dist-zip distcheck distclean distclean-generic \
- distclean-libtool distclean-tags distcleancheck distdir \
- distuninstallcheck dvi dvi-am html html-am info info-am \
- install install-am install-data install-data-am \
- install-dist_docDATA install-dvi install-dvi-am install-exec \
- install-exec-am install-html install-html-am install-info \
- install-info-am install-man install-pdf install-pdf-am \
- install-pkgconfigDATA install-ps install-ps-am install-strip \
- installcheck installcheck-am installdirs installdirs-am \
- maintainer-clean maintainer-clean-generic mostlyclean \
- mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
- tags tags-am uninstall uninstall-am uninstall-dist_docDATA \
- uninstall-pkgconfigDATA
+ dist-xz dist-zip dist-zstd distcheck distclean \
+ distclean-generic distclean-libtool distclean-tags \
+ distcleancheck distdir distuninstallcheck dvi dvi-am html \
+ html-am info info-am install install-am install-data \
+ install-data-am install-dist_docDATA install-dvi \
+ install-dvi-am install-exec install-exec-am install-html \
+ install-html-am install-info install-info-am install-man \
+ install-pdf install-pdf-am install-pkgconfigDATA install-ps \
+ install-ps-am install-strip installcheck installcheck-am \
+ installdirs installdirs-am maintainer-clean \
+ maintainer-clean-generic mostlyclean mostlyclean-generic \
+ mostlyclean-libtool pdf pdf-am ps ps-am tags tags-am uninstall \
+ uninstall-am uninstall-dist_docDATA uninstall-pkgconfigDATA
.PRECIOUS: Makefile
diff --git a/tiff/Makefile.vc b/tiff/Makefile.vc
index 6e66c730..eeb5d04d 100644
--- a/tiff/Makefile.vc
+++ b/tiff/Makefile.vc
@@ -31,6 +31,9 @@
all: port lib tools
port::
+ cd libtiff
+ $(MAKE) /f Makefile.vc tif_config.h
+ cd..
cd port
$(MAKE) /f Makefile.vc
cd..
diff --git a/tiff/RELEASE-DATE b/tiff/RELEASE-DATE
index ad4fa62a..1137155e 100644
--- a/tiff/RELEASE-DATE
+++ b/tiff/RELEASE-DATE
@@ -1 +1 @@
-20191103
+20201219
diff --git a/tiff/VERSION b/tiff/VERSION
index ee74734a..6aba2b24 100644
--- a/tiff/VERSION
+++ b/tiff/VERSION
@@ -1 +1 @@
-4.1.0
+4.2.0
diff --git a/tiff/aclocal.m4 b/tiff/aclocal.m4
index 9299d04d..3ba29cd2 100644
--- a/tiff/aclocal.m4
+++ b/tiff/aclocal.m4
@@ -1,6 +1,6 @@
-# generated automatically by aclocal 1.16.1 -*- Autoconf -*-
+# generated automatically by aclocal 1.16.2 -*- Autoconf -*-
-# Copyright (C) 1996-2018 Free Software Foundation, Inc.
+# Copyright (C) 1996-2020 Free Software Foundation, Inc.
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -20,7 +20,7 @@ You have another version of autoconf. It may work, but is not guaranteed to.
If you have problems, you may need to regenerate the build system entirely.
To do so, use the procedure documented by the package, typically 'autoreconf'.])])
-# Copyright (C) 2002-2018 Free Software Foundation, Inc.
+# Copyright (C) 2002-2020 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -35,7 +35,7 @@ AC_DEFUN([AM_AUTOMAKE_VERSION],
[am__api_version='1.16'
dnl Some users find AM_AUTOMAKE_VERSION and mistake it for a way to
dnl require some minimum version. Point them to the right macro.
-m4_if([$1], [1.16.1], [],
+m4_if([$1], [1.16.2], [],
[AC_FATAL([Do not call $0, use AM_INIT_AUTOMAKE([$1]).])])dnl
])
@@ -51,14 +51,14 @@ m4_define([_AM_AUTOCONF_VERSION], [])
# Call AM_AUTOMAKE_VERSION and AM_AUTOMAKE_VERSION so they can be traced.
# This function is AC_REQUIREd by AM_INIT_AUTOMAKE.
AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION],
-[AM_AUTOMAKE_VERSION([1.16.1])dnl
+[AM_AUTOMAKE_VERSION([1.16.2])dnl
m4_ifndef([AC_AUTOCONF_VERSION],
[m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl
_AM_AUTOCONF_VERSION(m4_defn([AC_AUTOCONF_VERSION]))])
# AM_AUX_DIR_EXPAND -*- Autoconf -*-
-# Copyright (C) 2001-2018 Free Software Foundation, Inc.
+# Copyright (C) 2001-2020 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -110,7 +110,7 @@ am_aux_dir=`cd "$ac_aux_dir" && pwd`
# AM_CONDITIONAL -*- Autoconf -*-
-# Copyright (C) 1997-2018 Free Software Foundation, Inc.
+# Copyright (C) 1997-2020 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -141,7 +141,7 @@ AC_CONFIG_COMMANDS_PRE(
Usually this means the macro was only invoked conditionally.]])
fi])])
-# Copyright (C) 1999-2018 Free Software Foundation, Inc.
+# Copyright (C) 1999-2020 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -332,7 +332,7 @@ _AM_SUBST_NOTMAKE([am__nodep])dnl
# Generate code to set up dependency tracking. -*- Autoconf -*-
-# Copyright (C) 1999-2018 Free Software Foundation, Inc.
+# Copyright (C) 1999-2020 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -371,7 +371,9 @@ AC_DEFUN([_AM_OUTPUT_DEPENDENCY_COMMANDS],
done
if test $am_rc -ne 0; then
AC_MSG_FAILURE([Something went wrong bootstrapping makefile fragments
- for automatic dependency tracking. Try re-running configure with the
+ for automatic dependency tracking. If GNU make was not used, consider
+ re-running the configure script with MAKE="gmake" (or whatever is
+ necessary). You can also try re-running configure with the
'--disable-dependency-tracking' option to at least be able to build
the package (albeit without support for automatic dependency tracking).])
fi
@@ -398,7 +400,7 @@ AC_DEFUN([AM_OUTPUT_DEPENDENCY_COMMANDS],
# Do all the work for Automake. -*- Autoconf -*-
-# Copyright (C) 1996-2018 Free Software Foundation, Inc.
+# Copyright (C) 1996-2020 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -595,7 +597,7 @@ for _am_header in $config_headers :; do
done
echo "timestamp for $_am_arg" >`AS_DIRNAME(["$_am_arg"])`/stamp-h[]$_am_stamp_count])
-# Copyright (C) 2001-2018 Free Software Foundation, Inc.
+# Copyright (C) 2001-2020 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -616,7 +618,7 @@ if test x"${install_sh+set}" != xset; then
fi
AC_SUBST([install_sh])])
-# Copyright (C) 2003-2018 Free Software Foundation, Inc.
+# Copyright (C) 2003-2020 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -638,7 +640,7 @@ AC_SUBST([am__leading_dot])])
# Add --enable-maintainer-mode option to configure. -*- Autoconf -*-
# From Jim Meyering
-# Copyright (C) 1996-2018 Free Software Foundation, Inc.
+# Copyright (C) 1996-2020 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -673,7 +675,7 @@ AC_MSG_CHECKING([whether to enable maintainer-specific portions of Makefiles])
# Check to see how 'make' treats includes. -*- Autoconf -*-
-# Copyright (C) 2001-2018 Free Software Foundation, Inc.
+# Copyright (C) 2001-2020 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -716,7 +718,7 @@ AC_SUBST([am__quote])])
# Fake the existence of programs that GNU maintainers use. -*- Autoconf -*-
-# Copyright (C) 1997-2018 Free Software Foundation, Inc.
+# Copyright (C) 1997-2020 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -755,7 +757,7 @@ fi
# Helper functions for option handling. -*- Autoconf -*-
-# Copyright (C) 2001-2018 Free Software Foundation, Inc.
+# Copyright (C) 2001-2020 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -784,7 +786,7 @@ AC_DEFUN([_AM_SET_OPTIONS],
AC_DEFUN([_AM_IF_OPTION],
[m4_ifset(_AM_MANGLE_OPTION([$1]), [$2], [$3])])
-# Copyright (C) 1999-2018 Free Software Foundation, Inc.
+# Copyright (C) 1999-2020 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -831,7 +833,7 @@ AC_LANG_POP([C])])
# For backward compatibility.
AC_DEFUN_ONCE([AM_PROG_CC_C_O], [AC_REQUIRE([AC_PROG_CC])])
-# Copyright (C) 2001-2018 Free Software Foundation, Inc.
+# Copyright (C) 2001-2020 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -850,7 +852,7 @@ AC_DEFUN([AM_RUN_LOG],
# Check to make sure that the build environment is sane. -*- Autoconf -*-
-# Copyright (C) 1996-2018 Free Software Foundation, Inc.
+# Copyright (C) 1996-2020 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -931,7 +933,7 @@ AC_CONFIG_COMMANDS_PRE(
rm -f conftest.file
])
-# Copyright (C) 2009-2018 Free Software Foundation, Inc.
+# Copyright (C) 2009-2020 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -991,7 +993,7 @@ AC_SUBST([AM_BACKSLASH])dnl
_AM_SUBST_NOTMAKE([AM_BACKSLASH])dnl
])
-# Copyright (C) 2001-2018 Free Software Foundation, Inc.
+# Copyright (C) 2001-2020 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -1019,7 +1021,7 @@ fi
INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s"
AC_SUBST([INSTALL_STRIP_PROGRAM])])
-# Copyright (C) 2006-2018 Free Software Foundation, Inc.
+# Copyright (C) 2006-2020 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -1038,7 +1040,7 @@ AC_DEFUN([AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE($@)])
# Check how to create a tarball. -*- Autoconf -*-
-# Copyright (C) 2004-2018 Free Software Foundation, Inc.
+# Copyright (C) 2004-2020 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
diff --git a/tiff/build/Makefile.in b/tiff/build/Makefile.in
index 92906d4d..d0893046 100644
--- a/tiff/build/Makefile.in
+++ b/tiff/build/Makefile.in
@@ -1,7 +1,7 @@
-# Makefile.in generated by automake 1.16.1 from Makefile.am.
+# Makefile.in generated by automake 1.16.2 from Makefile.am.
# @configure_input@
-# Copyright (C) 1994-2018 Free Software Foundation, Inc.
+# Copyright (C) 1994-2020 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
diff --git a/tiff/configure b/tiff/configure
index 17597b79..96362dad 100755
--- a/tiff/configure
+++ b/tiff/configure
@@ -1,6 +1,6 @@
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.69 for LibTIFF Software 4.1.0.
+# Generated by GNU Autoconf 2.69 for LibTIFF Software 4.2.0.
#
# Report bugs to <tiff@lists.maptools.org>.
#
@@ -590,8 +590,8 @@ MAKEFLAGS=
# Identity of this package.
PACKAGE_NAME='LibTIFF Software'
PACKAGE_TARNAME='tiff'
-PACKAGE_VERSION='4.1.0'
-PACKAGE_STRING='LibTIFF Software 4.1.0'
+PACKAGE_VERSION='4.2.0'
+PACKAGE_STRING='LibTIFF Software 4.2.0'
PACKAGE_BUGREPORT='tiff@lists.maptools.org'
PACKAGE_URL=''
@@ -833,6 +833,9 @@ enable_mdi
enable_zlib
with_zlib_include_dir
with_zlib_lib_dir
+enable_libdeflate
+with_libdeflate_include_dir
+with_libdeflate_lib_dir
enable_pixarlog
enable_jpeg
with_jpeg_include_dir
@@ -1418,7 +1421,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
-\`configure' configures LibTIFF Software 4.1.0 to adapt to many kinds of systems.
+\`configure' configures LibTIFF Software 4.2.0 to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]...
@@ -1492,7 +1495,7 @@ fi
if test -n "$ac_init_help"; then
case $ac_init_help in
- short | recursive ) echo "Configuration of LibTIFF Software 4.1.0:";;
+ short | recursive ) echo "Configuration of LibTIFF Software 4.2.0:";;
esac
cat <<\_ACEOF
@@ -1528,6 +1531,9 @@ Optional Features:
--disable-mdi disable support for Microsoft Document Imaging
--disable-zlib disable Zlib usage (required for Deflate
compression, enabled by default)
+ --disable-libdeflate disable libdeflate usage (optional for faster
+ Deflate support (still requires zlib), enabled by
+ default)
--disable-pixarlog disable support for Pixar log-format algorithm
(requires Zlib)
--disable-jpeg disable IJG JPEG library usage (required for JPEG
@@ -1582,6 +1588,10 @@ Optional Packages:
--with-zlib-include-dir=DIR
location of Zlib headers
--with-zlib-lib-dir=DIR location of Zlib library binary
+ --with-libdeflate-include-dir=DIR
+ location of libdeflate headers
+ --with-libdeflate-lib-dir=DIR
+ location of libdeflate library binary
--with-jpeg-include-dir=DIR
location of IJG JPEG library headers
--with-jpeg-lib-dir=DIR location of IJG JPEG library binary
@@ -1688,7 +1698,7 @@ fi
test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
cat <<\_ACEOF
-LibTIFF Software configure 4.1.0
+LibTIFF Software configure 4.2.0
generated by GNU Autoconf 2.69
Copyright (C) 2012 Free Software Foundation, Inc.
@@ -2461,7 +2471,7 @@ cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
-It was created by LibTIFF Software $as_me 4.1.0, which was
+It was created by LibTIFF Software $as_me 4.2.0, which was
generated by GNU Autoconf 2.69. Invocation command line was
$ $0 $@
@@ -3404,7 +3414,7 @@ fi
# Define the identity of the package.
PACKAGE='tiff'
- VERSION='4.1.0'
+ VERSION='4.2.0'
cat >>confdefs.h <<_ACEOF
@@ -3446,16 +3456,47 @@ AMTAR='$${TAR-tar}'
# We'll loop over all known methods to create a tar archive until one works.
-_am_tools='gnutar pax cpio none'
-
-
+_am_tools='gnutar plaintar pax cpio none'
+
+# The POSIX 1988 'ustar' format is defined with fixed-size fields.
+ # There is notably a 21 bits limit for the UID and the GID. In fact,
+ # the 'pax' utility can hang on bigger UID/GID (see automake bug#8343
+ # and bug#13588).
+ am_max_uid=2097151 # 2^21 - 1
+ am_max_gid=$am_max_uid
+ # The $UID and $GID variables are not portable, so we need to resort
+ # to the POSIX-mandated id(1) utility. Errors in the 'id' calls
+ # below are definitely unexpected, so allow the users to see them
+ # (that is, avoid stderr redirection).
+ am_uid=`id -u || echo unknown`
+ am_gid=`id -g || echo unknown`
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether UID '$am_uid' is supported by ustar format" >&5
+$as_echo_n "checking whether UID '$am_uid' is supported by ustar format... " >&6; }
+ if test $am_uid -le $am_max_uid; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+ else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+ _am_tools=none
+ fi
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether GID '$am_gid' is supported by ustar format" >&5
+$as_echo_n "checking whether GID '$am_gid' is supported by ustar format... " >&6; }
+ if test $am_gid -le $am_max_gid; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+ else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+ _am_tools=none
+ fi
- { $as_echo "$as_me:${as_lineno-$LINENO}: checking how to create a pax tar archive" >&5
-$as_echo_n "checking how to create a pax tar archive... " >&6; }
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking how to create a ustar tar archive" >&5
+$as_echo_n "checking how to create a ustar tar archive... " >&6; }
# Go ahead even if we have the value already cached. We do so because we
# need to set the values for the 'am__tar' and 'am__untar' variables.
- _am_tools=${am_cv_prog_tar_pax-$_am_tools}
+ _am_tools=${am_cv_prog_tar_ustar-$_am_tools}
for _am_tool in $_am_tools; do
case $_am_tool in
@@ -3467,8 +3508,8 @@ $as_echo_n "checking how to create a pax tar archive... " >&6; }
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } && break
done
- am__tar="$_am_tar --format=posix -chf - "'"$$tardir"'
- am__tar_="$_am_tar --format=posix -chf - "'"$tardir"'
+ am__tar="$_am_tar --format=ustar -chf - "'"$$tardir"'
+ am__tar_="$_am_tar --format=ustar -chf - "'"$tardir"'
am__untar="$_am_tar -xf -"
;;
plaintar)
@@ -3480,14 +3521,14 @@ $as_echo_n "checking how to create a pax tar archive... " >&6; }
am__untar='tar xf -'
;;
pax)
- am__tar='pax -L -x pax -w "$$tardir"'
- am__tar_='pax -L -x pax -w "$tardir"'
+ am__tar='pax -L -x ustar -w "$$tardir"'
+ am__tar_='pax -L -x ustar -w "$tardir"'
am__untar='pax -r'
;;
cpio)
- am__tar='find "$$tardir" -print | cpio -o -H pax -L'
- am__tar_='find "$tardir" -print | cpio -o -H pax -L'
- am__untar='cpio -i -H pax -d'
+ am__tar='find "$$tardir" -print | cpio -o -H ustar -L'
+ am__tar_='find "$tardir" -print | cpio -o -H ustar -L'
+ am__untar='cpio -i -H ustar -d'
;;
none)
am__tar=false
@@ -3498,7 +3539,7 @@ $as_echo_n "checking how to create a pax tar archive... " >&6; }
# If the value was cached, stop now. We just wanted to have am__tar
# and am__untar set.
- test -n "${am_cv_prog_tar_pax}" && break
+ test -n "${am_cv_prog_tar_ustar}" && break
# tar/untar a dummy directory, and stop if the command works.
rm -rf conftest.dir
@@ -3526,14 +3567,14 @@ $as_echo_n "checking how to create a pax tar archive... " >&6; }
done
rm -rf conftest.dir
- if ${am_cv_prog_tar_pax+:} false; then :
+ if ${am_cv_prog_tar_ustar+:} false; then :
$as_echo_n "(cached) " >&6
else
- am_cv_prog_tar_pax=$_am_tool
+ am_cv_prog_tar_ustar=$_am_tool
fi
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_prog_tar_pax" >&5
-$as_echo "$am_cv_prog_tar_pax" >&6; }
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_prog_tar_ustar" >&5
+$as_echo "$am_cv_prog_tar_ustar" >&6; }
@@ -3607,15 +3648,15 @@ fi
LIBTIFF_MAJOR_VERSION=4
-LIBTIFF_MINOR_VERSION=1
+LIBTIFF_MINOR_VERSION=2
LIBTIFF_MICRO_VERSION=0
LIBTIFF_ALPHA_VERSION=
LIBTIFF_VERSION=$LIBTIFF_MAJOR_VERSION.$LIBTIFF_MINOR_VERSION.$LIBTIFF_MICRO_VERSION$LIBTIFF_ALPHA_VERSION
LIBTIFF_RELEASE_DATE=`date +"%Y%m%d"`
-LIBTIFF_CURRENT=10
+LIBTIFF_CURRENT=11
LIBTIFF_REVISION=0
-LIBTIFF_AGE=5
+LIBTIFF_AGE=6
LIBTIFF_VERSION_INFO=$LIBTIFF_CURRENT:$LIBTIFF_REVISION:$LIBTIFF_AGE
# This is a special hack for OpenBSD and MirOS systems. The dynamic linker
@@ -18688,6 +18729,119 @@ $as_echo "#define ZIP_SUPPORT 1" >>confdefs.h
fi
+HAVE_LIBDEFLATE=no
+
+# Check whether --enable-libdeflate was given.
+if test "${enable_libdeflate+set}" = set; then :
+ enableval=$enable_libdeflate;
+fi
+
+
+# Check whether --with-libdeflate-include-dir was given.
+if test "${with_libdeflate_include_dir+set}" = set; then :
+ withval=$with_libdeflate_include_dir;
+fi
+
+
+# Check whether --with-libdeflate-lib-dir was given.
+if test "${with_libdeflate_lib_dir+set}" = set; then :
+ withval=$with_libdeflate_lib_dir;
+fi
+
+
+if test "x$enable_libdeflate" != "xno" ; then
+
+ if test "x$with_libdeflate_lib_dir" != "x" ; then
+ LDFLAGS="-L$with_libdeflate_lib_dir $LDFLAGS"
+ fi
+
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for libdeflate_zlib_decompress in -ldeflate" >&5
+$as_echo_n "checking for libdeflate_zlib_decompress in -ldeflate... " >&6; }
+if ${ac_cv_lib_deflate_libdeflate_zlib_decompress+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ ac_check_lib_save_LIBS=$LIBS
+LIBS="-ldeflate $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+/* Override any GCC internal prototype to avoid an error.
+ Use char because int might match the return type of a GCC
+ builtin and then its argument prototype would still apply. */
+#ifdef __cplusplus
+extern "C"
+#endif
+char libdeflate_zlib_decompress ();
+int
+main ()
+{
+return libdeflate_zlib_decompress ();
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+ ac_cv_lib_deflate_libdeflate_zlib_decompress=yes
+else
+ ac_cv_lib_deflate_libdeflate_zlib_decompress=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_deflate_libdeflate_zlib_decompress" >&5
+$as_echo "$ac_cv_lib_deflate_libdeflate_zlib_decompress" >&6; }
+if test "x$ac_cv_lib_deflate_libdeflate_zlib_decompress" = xyes; then :
+ libdeflate_lib=yes
+else
+ libdeflate_lib=no
+fi
+
+ if test "$libdeflate_lib" = "no" -a "x$with_libdeflate_lib_dir" != "x"; then
+ as_fn_error $? "libdeflate library not found at $with_libdeflate_lib_dir" "$LINENO" 5
+ fi
+
+ if test "x$with_libdeflate_include_dir" != "x" ; then
+ CPPFLAGS="-I$with_libdeflate_include_dir $CPPFLAGS"
+ fi
+ ac_fn_c_check_header_mongrel "$LINENO" "libdeflate.h" "ac_cv_header_libdeflate_h" "$ac_includes_default"
+if test "x$ac_cv_header_libdeflate_h" = xyes; then :
+ libdeflate_h=yes
+else
+ libdeflate_h=no
+fi
+
+
+ if test "$libdeflate_h" = "no" -a "x$with_libdeflate_include_dir" != "x" ; then
+ as_fn_error $? "libdeflate headers not found at $with_libdeflate_include_dir" "$LINENO" 5
+ fi
+
+ if test "$libdeflate_lib" = "yes" -a "$libdeflate_h" = "yes" ; then
+ HAVE_LIBDEFLATE=yes
+ fi
+
+fi
+
+if test "$HAVE_LIBDEFLATE" = "yes" -a "$HAVE_ZLIB" = "no" ; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: libdeflate available but zlib is not. libdeflate cannot be used" >&5
+$as_echo "$as_me: WARNING: libdeflate available but zlib is not. libdeflate cannot be used" >&2;}
+ HAVE_LIBDEFLATE=no
+fi
+
+if test "$HAVE_LIBDEFLATE" = "yes" ; then
+
+$as_echo "#define LIBDEFLATE_SUPPORT 1" >>confdefs.h
+
+ LIBS="-ldeflate $LIBS"
+ tiff_libs_private="-ldeflate ${tiff_libs_private}"
+
+ if test "$HAVE_RPATH" = "yes" -a "x$with_libdeflate_lib_dir" != "x" ; then
+ LIBDIR="-R $with_libdeflate_lib_dir $LIBDIR"
+ fi
+
+fi
+
+
# Check whether --enable-pixarlog was given.
if test "${enable_pixarlog+set}" = set; then :
enableval=$enable_pixarlog; HAVE_PIXARLOG=$enableval
@@ -21673,7 +21827,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
-This file was extended by LibTIFF Software $as_me 4.1.0, which was
+This file was extended by LibTIFF Software $as_me 4.2.0, which was
generated by GNU Autoconf 2.69. Invocation command line was
CONFIG_FILES = $CONFIG_FILES
@@ -21739,7 +21893,7 @@ _ACEOF
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
ac_cs_version="\\
-LibTIFF Software config.status 4.1.0
+LibTIFF Software config.status 4.2.0
configured by $0, generated by GNU Autoconf 2.69,
with options \\"\$ac_cs_config\\"
@@ -22954,7 +23108,9 @@ $as_echo X/"$am_mf" |
{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
as_fn_error $? "Something went wrong bootstrapping makefile fragments
- for automatic dependency tracking. Try re-running configure with the
+ for automatic dependency tracking. If GNU make was not used, consider
+ re-running the configure script with MAKE=\"gmake\" (or whatever is
+ necessary). You can also try re-running configure with the
'--disable-dependency-tracking' option to at least be able to build
the package (albeit without support for automatic dependency tracking).
See \`config.log' for more details" "$LINENO" 5; }
@@ -23741,6 +23897,7 @@ echo " LogLuv high dynamic range encoding: ${HAVE_LOGLUV}"
echo ""
echo " Support for external codecs:"
echo " ZLIB support: ${HAVE_ZLIB}"
+echo " libdeflate support: ${HAVE_LIBDEFLATE}"
echo " Pixar log-format algorithm: ${HAVE_PIXARLOG}"
echo " JPEG support: ${HAVE_JPEG}"
echo " Old JPEG support: ${HAVE_OJPEG}"
diff --git a/tiff/configure.ac b/tiff/configure.ac
index eecb8e99..a2242330 100644
--- a/tiff/configure.ac
+++ b/tiff/configure.ac
@@ -25,7 +25,7 @@ dnl OF THIS SOFTWARE.
dnl Process this file with autoconf to produce a configure script.
AC_PREREQ(2.64)
-AC_INIT([LibTIFF Software],[4.1.0],[tiff@lists.maptools.org],[tiff])
+AC_INIT([LibTIFF Software],[4.2.0],[tiff@lists.maptools.org],[tiff])
AC_CONFIG_AUX_DIR(config)
AC_CONFIG_MACRO_DIR(m4)
AC_LANG(C)
@@ -33,14 +33,14 @@ AC_LANG(C)
dnl Compute the canonical host (run-time) system type variable
AC_CANONICAL_HOST
-AM_INIT_AUTOMAKE(tar-pax)
+AM_INIT_AUTOMAKE(tar-ustar)
dnl Do not rebuild generated files every time
AM_MAINTAINER_MODE
dnl Versioning.
dnl Don't fill the ALPHA_VERSION field, if not applicable.
LIBTIFF_MAJOR_VERSION=4
-LIBTIFF_MINOR_VERSION=1
+LIBTIFF_MINOR_VERSION=2
LIBTIFF_MICRO_VERSION=0
LIBTIFF_ALPHA_VERSION=
LIBTIFF_VERSION=$LIBTIFF_MAJOR_VERSION.$LIBTIFF_MINOR_VERSION.$LIBTIFF_MICRO_VERSION$LIBTIFF_ALPHA_VERSION
@@ -76,9 +76,9 @@ dnl 5. If any interfaces have been added since the last public release, then
dnl increment age.
dnl 6. If any interfaces have been removed since the last public release,
dnl then set age to 0.
-LIBTIFF_CURRENT=10
+LIBTIFF_CURRENT=11
LIBTIFF_REVISION=0
-LIBTIFF_AGE=5
+LIBTIFF_AGE=6
LIBTIFF_VERSION_INFO=$LIBTIFF_CURRENT:$LIBTIFF_REVISION:$LIBTIFF_AGE
# This is a special hack for OpenBSD and MirOS systems. The dynamic linker
@@ -615,6 +615,63 @@ if test "$HAVE_ZLIB" = "yes" ; then
fi
dnl ---------------------------------------------------------------------------
+dnl Check for libdeflate.
+dnl ---------------------------------------------------------------------------
+
+HAVE_LIBDEFLATE=no
+
+AC_ARG_ENABLE(libdeflate,
+ AS_HELP_STRING([--disable-libdeflate],
+ [disable libdeflate usage (optional for faster Deflate support (still requires zlib), enabled by default)]),,)
+AC_ARG_WITH(libdeflate-include-dir,
+ AS_HELP_STRING([--with-libdeflate-include-dir=DIR],
+ [location of libdeflate headers]),,)
+AC_ARG_WITH(libdeflate-lib-dir,
+ AS_HELP_STRING([--with-libdeflate-lib-dir=DIR],
+ [location of libdeflate library binary]),,)
+
+if test "x$enable_libdeflate" != "xno" ; then
+
+ if test "x$with_libdeflate_lib_dir" != "x" ; then
+ LDFLAGS="-L$with_libdeflate_lib_dir $LDFLAGS"
+ fi
+
+ AC_CHECK_LIB(deflate, libdeflate_zlib_decompress, [libdeflate_lib=yes], [libdeflate_lib=no],)
+ if test "$libdeflate_lib" = "no" -a "x$with_libdeflate_lib_dir" != "x"; then
+ AC_MSG_ERROR([libdeflate library not found at $with_libdeflate_lib_dir])
+ fi
+
+ if test "x$with_libdeflate_include_dir" != "x" ; then
+ CPPFLAGS="-I$with_libdeflate_include_dir $CPPFLAGS"
+ fi
+ AC_CHECK_HEADER(libdeflate.h, [libdeflate_h=yes], [libdeflate_h=no])
+ if test "$libdeflate_h" = "no" -a "x$with_libdeflate_include_dir" != "x" ; then
+ AC_MSG_ERROR([libdeflate headers not found at $with_libdeflate_include_dir])
+ fi
+
+ if test "$libdeflate_lib" = "yes" -a "$libdeflate_h" = "yes" ; then
+ HAVE_LIBDEFLATE=yes
+ fi
+
+fi
+
+if test "$HAVE_LIBDEFLATE" = "yes" -a "$HAVE_ZLIB" = "no" ; then
+ AC_MSG_WARN([libdeflate available but zlib is not. libdeflate cannot be used])
+ HAVE_LIBDEFLATE=no
+fi
+
+if test "$HAVE_LIBDEFLATE" = "yes" ; then
+ AC_DEFINE(LIBDEFLATE_SUPPORT,1,[Support libdeflate enhanced compression])
+ LIBS="-ldeflate $LIBS"
+ tiff_libs_private="-ldeflate ${tiff_libs_private}"
+
+ if test "$HAVE_RPATH" = "yes" -a "x$with_libdeflate_lib_dir" != "x" ; then
+ LIBDIR="-R $with_libdeflate_lib_dir $LIBDIR"
+ fi
+
+fi
+
+dnl ---------------------------------------------------------------------------
dnl Check for Pixar log-format algorithm.
dnl ---------------------------------------------------------------------------
@@ -1191,6 +1248,7 @@ LOC_MSG([ LogLuv high dynamic range encoding: ${HAVE_LOGLUV}])
LOC_MSG()
LOC_MSG([ Support for external codecs:])
LOC_MSG([ ZLIB support: ${HAVE_ZLIB}])
+LOC_MSG([ libdeflate support: ${HAVE_LIBDEFLATE}])
LOC_MSG([ Pixar log-format algorithm: ${HAVE_PIXARLOG}])
LOC_MSG([ JPEG support: ${HAVE_JPEG}])
LOC_MSG([ Old JPEG support: ${HAVE_OJPEG}])
diff --git a/tiff/contrib/Makefile.in b/tiff/contrib/Makefile.in
index c4d5cd6e..c0f998b3 100644
--- a/tiff/contrib/Makefile.in
+++ b/tiff/contrib/Makefile.in
@@ -1,7 +1,7 @@
-# Makefile.in generated by automake 1.16.1 from Makefile.am.
+# Makefile.in generated by automake 1.16.2 from Makefile.am.
# @configure_input@
-# Copyright (C) 1994-2018 Free Software Foundation, Inc.
+# Copyright (C) 1994-2020 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
diff --git a/tiff/contrib/addtiffo/CMakeLists.txt b/tiff/contrib/addtiffo/CMakeLists.txt
index b7482635..45e733cd 100644
--- a/tiff/contrib/addtiffo/CMakeLists.txt
+++ b/tiff/contrib/addtiffo/CMakeLists.txt
@@ -32,3 +32,9 @@ include_directories(${PROJECT_SOURCE_DIR}/libtiff
add_executable(addtiffo addtiffo.c tif_overview.c tif_ovrcache.c tif_ovrcache.h)
target_link_libraries(addtiffo tiff port)
+
+if(WEBP_SUPPORT AND EMSCRIPTEN)
+ # Emscripten is pretty finnicky about linker flags.
+ # It needs --shared-memory if and only if atomics or bulk-memory is used.
+ target_link_options(addtiffo PUBLIC "-Wl,--shared-memory")
+endif()
diff --git a/tiff/contrib/addtiffo/Makefile.in b/tiff/contrib/addtiffo/Makefile.in
index abe4c027..31dc815c 100644
--- a/tiff/contrib/addtiffo/Makefile.in
+++ b/tiff/contrib/addtiffo/Makefile.in
@@ -1,7 +1,7 @@
-# Makefile.in generated by automake 1.16.1 from Makefile.am.
+# Makefile.in generated by automake 1.16.2 from Makefile.am.
# @configure_input@
-# Copyright (C) 1994-2018 Free Software Foundation, Inc.
+# Copyright (C) 1994-2020 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
diff --git a/tiff/contrib/addtiffo/tif_ovrcache.c b/tiff/contrib/addtiffo/tif_ovrcache.c
index 67a88120..ac500ab4 100644
--- a/tiff/contrib/addtiffo/tif_ovrcache.c
+++ b/tiff/contrib/addtiffo/tif_ovrcache.c
@@ -166,6 +166,7 @@ static void TIFFWriteOvrRow( TIFFOvrCache * psCache )
/* -------------------------------------------------------------------- */
nBaseDirOffset = TIFFCurrentDirOffset( psCache->hTIFF );
nRet = TIFFSetSubDirectory( psCache->hTIFF, psCache->nDirOffset );
+ (void) nRet;
assert( nRet == 1 );
/* -------------------------------------------------------------------- */
diff --git a/tiff/contrib/dbs/CMakeLists.txt b/tiff/contrib/dbs/CMakeLists.txt
index b2e809b2..ff3ce20c 100644
--- a/tiff/contrib/dbs/CMakeLists.txt
+++ b/tiff/contrib/dbs/CMakeLists.txt
@@ -41,3 +41,14 @@ target_link_libraries(tiff-rgb tiff port)
add_subdirectory(xtiff)
extra_dist(README)
+
+if(WEBP_SUPPORT AND EMSCRIPTEN)
+ # Emscripten is pretty finnicky about linker flags.
+ # It needs --shared-memory if and only if atomics or bulk-memory is used.
+ foreach(target tiff-bi
+ tiff-grayscale
+ tiff-palette
+ tiff-rgb)
+ target_link_options(${target} PUBLIC "-Wl,--shared-memory")
+ endforeach()
+endif()
diff --git a/tiff/contrib/dbs/Makefile.in b/tiff/contrib/dbs/Makefile.in
index 38a13830..0f44fdd1 100644
--- a/tiff/contrib/dbs/Makefile.in
+++ b/tiff/contrib/dbs/Makefile.in
@@ -1,7 +1,7 @@
-# Makefile.in generated by automake 1.16.1 from Makefile.am.
+# Makefile.in generated by automake 1.16.2 from Makefile.am.
# @configure_input@
-# Copyright (C) 1994-2018 Free Software Foundation, Inc.
+# Copyright (C) 1994-2020 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
diff --git a/tiff/contrib/dbs/xtiff/Makefile.in b/tiff/contrib/dbs/xtiff/Makefile.in
index 61594863..4be51fd8 100644
--- a/tiff/contrib/dbs/xtiff/Makefile.in
+++ b/tiff/contrib/dbs/xtiff/Makefile.in
@@ -1,7 +1,7 @@
-# Makefile.in generated by automake 1.16.1 from Makefile.am.
+# Makefile.in generated by automake 1.16.2 from Makefile.am.
# @configure_input@
-# Copyright (C) 1994-2018 Free Software Foundation, Inc.
+# Copyright (C) 1994-2020 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
diff --git a/tiff/contrib/iptcutil/Makefile.in b/tiff/contrib/iptcutil/Makefile.in
index 790bb6c0..c0cc3959 100644
--- a/tiff/contrib/iptcutil/Makefile.in
+++ b/tiff/contrib/iptcutil/Makefile.in
@@ -1,7 +1,7 @@
-# Makefile.in generated by automake 1.16.1 from Makefile.am.
+# Makefile.in generated by automake 1.16.2 from Makefile.am.
# @configure_input@
-# Copyright (C) 1994-2018 Free Software Foundation, Inc.
+# Copyright (C) 1994-2020 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
diff --git a/tiff/contrib/mfs/Makefile.in b/tiff/contrib/mfs/Makefile.in
index 201e700b..0ed2019c 100644
--- a/tiff/contrib/mfs/Makefile.in
+++ b/tiff/contrib/mfs/Makefile.in
@@ -1,7 +1,7 @@
-# Makefile.in generated by automake 1.16.1 from Makefile.am.
+# Makefile.in generated by automake 1.16.2 from Makefile.am.
# @configure_input@
-# Copyright (C) 1994-2018 Free Software Foundation, Inc.
+# Copyright (C) 1994-2020 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
diff --git a/tiff/contrib/pds/Makefile.in b/tiff/contrib/pds/Makefile.in
index e4c4651d..77b02179 100644
--- a/tiff/contrib/pds/Makefile.in
+++ b/tiff/contrib/pds/Makefile.in
@@ -1,7 +1,7 @@
-# Makefile.in generated by automake 1.16.1 from Makefile.am.
+# Makefile.in generated by automake 1.16.2 from Makefile.am.
# @configure_input@
-# Copyright (C) 1994-2018 Free Software Foundation, Inc.
+# Copyright (C) 1994-2020 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
diff --git a/tiff/contrib/ras/Makefile.in b/tiff/contrib/ras/Makefile.in
index 0028f091..dac37b63 100644
--- a/tiff/contrib/ras/Makefile.in
+++ b/tiff/contrib/ras/Makefile.in
@@ -1,7 +1,7 @@
-# Makefile.in generated by automake 1.16.1 from Makefile.am.
+# Makefile.in generated by automake 1.16.2 from Makefile.am.
# @configure_input@
-# Copyright (C) 1994-2018 Free Software Foundation, Inc.
+# Copyright (C) 1994-2020 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
diff --git a/tiff/contrib/stream/Makefile.in b/tiff/contrib/stream/Makefile.in
index 481faa82..5f7f1eba 100644
--- a/tiff/contrib/stream/Makefile.in
+++ b/tiff/contrib/stream/Makefile.in
@@ -1,7 +1,7 @@
-# Makefile.in generated by automake 1.16.1 from Makefile.am.
+# Makefile.in generated by automake 1.16.2 from Makefile.am.
# @configure_input@
-# Copyright (C) 1994-2018 Free Software Foundation, Inc.
+# Copyright (C) 1994-2020 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
diff --git a/tiff/contrib/tags/Makefile.in b/tiff/contrib/tags/Makefile.in
index 0b53ed76..502d8f05 100644
--- a/tiff/contrib/tags/Makefile.in
+++ b/tiff/contrib/tags/Makefile.in
@@ -1,7 +1,7 @@
-# Makefile.in generated by automake 1.16.1 from Makefile.am.
+# Makefile.in generated by automake 1.16.2 from Makefile.am.
# @configure_input@
-# Copyright (C) 1994-2018 Free Software Foundation, Inc.
+# Copyright (C) 1994-2020 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
diff --git a/tiff/contrib/win_dib/Makefile.in b/tiff/contrib/win_dib/Makefile.in
index 7663106d..fa3b2237 100644
--- a/tiff/contrib/win_dib/Makefile.in
+++ b/tiff/contrib/win_dib/Makefile.in
@@ -1,7 +1,7 @@
-# Makefile.in generated by automake 1.16.1 from Makefile.am.
+# Makefile.in generated by automake 1.16.2 from Makefile.am.
# @configure_input@
-# Copyright (C) 1994-2018 Free Software Foundation, Inc.
+# Copyright (C) 1994-2020 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
diff --git a/tiff/contrib/win_dib/tiff2dib.c b/tiff/contrib/win_dib/tiff2dib.c
index 475ef304..2fa2de69 100644
--- a/tiff/contrib/win_dib/tiff2dib.c
+++ b/tiff/contrib/win_dib/tiff2dib.c
@@ -106,6 +106,8 @@ HDIB LoadTIFFinDIB(LPSTR lpFileName)
if (lpDIB)
lpBits = FindDIBBits((LPSTR) lpDIB);
+ else
+ lpBits = NULL;
//In the tiff file the lines are save from up to down
//In a DIB the lines must be save from down to up
diff --git a/tiff/html/Makefile.am b/tiff/html/Makefile.am
index 10b419b2..2929b8ed 100644
--- a/tiff/html/Makefile.am
+++ b/tiff/html/Makefile.am
@@ -88,7 +88,8 @@ docfiles = \
v4.0.8.html \
v4.0.9.html \
v4.0.10.html \
- v4.1.0.html
+ v4.1.0.html \
+ v4.2.0.html
dist_doc_DATA = $(docfiles)
diff --git a/tiff/html/Makefile.in b/tiff/html/Makefile.in
index 30932e63..b60e5cfa 100644
--- a/tiff/html/Makefile.in
+++ b/tiff/html/Makefile.in
@@ -1,7 +1,7 @@
-# Makefile.in generated by automake 1.16.1 from Makefile.am.
+# Makefile.in generated by automake 1.16.2 from Makefile.am.
# @configure_input@
-# Copyright (C) 1994-2018 Free Software Foundation, Inc.
+# Copyright (C) 1994-2020 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -450,7 +450,8 @@ docfiles = \
v4.0.8.html \
v4.0.9.html \
v4.0.10.html \
- v4.1.0.html
+ v4.1.0.html \
+ v4.2.0.html
dist_doc_DATA = $(docfiles)
SUBDIRS = images man
diff --git a/tiff/html/addingtags.html b/tiff/html/addingtags.html
index c61a2623..bd4b972a 100644
--- a/tiff/html/addingtags.html
+++ b/tiff/html/addingtags.html
@@ -1,11 +1,16 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>
Modifying The TIFF Library
</TITLE>
+<style type="text/css">
+body {
+font-family: Arial, Helvetica, Sans;
+}
+</style>
</HEAD>
-<BODY BGCOLOR=white>
-<FONT FACE="Arial, Helvetica, Sans">
+<BODY>
<H1>
Defining New TIFF Tags
@@ -198,8 +203,8 @@ If tag definitions are only required for writing custom tags, you can just
call TIFFMergeFieldInfo() before setting new tags. The whole extender
architecture can then be avoided.<p>
-<A NAME=AddingTags><P><H2>Adding New Builtin Tags</H2></A>
-
+<H2 id="AddingTags">Adding New Builtin Tags</H2>
+<P>
A similar approach is taken to the above. However, the TIFFFieldInfo
should be added to the tiffFieldInfo[] list in tif_dirinfo.c. Ensure that
new tags are added in sorted order by the tag number.<p>
@@ -238,8 +243,8 @@ about data types. Use the typedefs (<TT>uint16</TT>, etc. when dealing with
data on disk and <TT>t*_t</TT> when stuff is in memory) and be careful about
passing items through printf or similar vararg interfaces.
-<A NAME=AddingCODECTags><P><H2>Adding New Codec-private Tags</H2></A>
-
+<H2 id="AddingCODECTags">Adding New Codec-private Tags</H2>
+<P>
To add tags that are meaningful <EM>only when a particular compression
algorithm is used</EM> follow these steps:
diff --git a/tiff/html/bugs.html b/tiff/html/bugs.html
index bc27955e..a05a4659 100644
--- a/tiff/html/bugs.html
+++ b/tiff/html/bugs.html
@@ -1,11 +1,16 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Bugs and the TIFF Mailing List</TITLE>
+<style type="text/css">
+body {
+font-family: Arial, Helvetica, Sans;
+}
+</style>
</HEAD>
-<BODY BGCOLOR=white>
-<FONT FACE="Arial, Helvetica, Sans">
+<BODY>
<H1>
-<IMG SRC=images/cover.jpg WIDTH=110 HEIGHT=110 ALIGN=left BORDER=1 HSPACE=6>
+<IMG SRC="images/cover.jpg" WIDTH=110 HEIGHT=110 ALIGN=left BORDER=1 HSPACE=6 ALT="cover">
Bugs, Bugzilla, and the TIFF Mailing List
</H1>
@@ -27,7 +32,7 @@ the problem is still reproducible with the current development software
from CVS.
<P>
If you'd like to enter a new bug, you can do so at
-<A HREF=https://gitlab.com/libtiff/libtiff/issues/new>https://gitlab.com/libtiff/libtiff/issues/new</A>.
+<A HREF="https://gitlab.com/libtiff/libtiff/issues/new">https://gitlab.com/libtiff/libtiff/issues/new</A>.
<P>
If you'd like to inform us about some kind of security issue that should not
be disclosed for a period of time, then you can contact maintainers directly.
diff --git a/tiff/html/build.html b/tiff/html/build.html
index 77fbc40b..4186645b 100644
--- a/tiff/html/build.html
+++ b/tiff/html/build.html
@@ -1,14 +1,16 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
-<meta name="generator" content=
-"HTML Tidy for Linux (vers 25 March 2009), see www.w3.org">
<title>Building the TIFF Software Distribution</title>
+<style type="text/css">
+body {
+font-family: Arial, Helvetica, Sans;
+}
+</style>
</head>
-<body bgcolor="white">
-<h1><font face="Arial, Helvetica, Sans"><img src=
-"images/cramps.gif" width="159" height="203" align="left" border=
-"1" hspace="6"> Building the Software Distribution</font></h1>
+<body>
+<h1><img src="images/cramps.gif" width="159" height="203" align="left" border="1" hspace="6" alt="cramps">
+Building the Software Distribution</h1>
<ul>
<li><a href="#CMAKE">Building on all systems with CMake</a>.</li>
<li><a href="#UNIX">Building on a UNIX system with Autoconf</a>.</li>
@@ -229,7 +231,6 @@ available <tt>zlib</tt> distribution written by Jean-loup Gailly and
Mark Adler; this software is available at <a href=
"http://www.zlib.org/">http://www.zlib.org/</a>.</dd>
</dl>
-<a name="Sample" id="Sample"></a>
<hr width="65%" align="right">
<a name="UNIX" id="UNIX"></a>
<h2>Building on a UNIX System with Autoconf</h2>
@@ -421,7 +422,6 @@ enabled the <tt>DIRS_LIBINC</tt> and <tt>DIR_GZLIB</tt> parameters
should also be set (see below). By default this package is not
configured.</dd>
</dl>
-<a name="Sample" id="Sample"></a>
<hr width="65%" align="right">
<a name="PC" id="PC"></a>
<h2>Building the Software under Windows 2000/XP/7/8/10 with nmake</h2>
diff --git a/tiff/html/contrib.html b/tiff/html/contrib.html
index f20a1cb3..9a670658 100644
--- a/tiff/html/contrib.html
+++ b/tiff/html/contrib.html
@@ -1,14 +1,18 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>
Contributed TIFF Software
</TITLE>
+<style type="text/css">
+body {
+font-family: Arial, Helvetica, Sans;
+}
+</style>
</HEAD>
-
-<BODY BGCOLOR=white>
-<FONT FACE="Arial, Helvetica, Sans">
+<BODY>
<H1>
-<IMG SRC=images/smallliz.jpg WIDTH=144 HEIGHT=108 ALIGN=left BORDER=1 HSPACE=6>
+<IMG SRC="images/smallliz.jpg" WIDTH=144 HEIGHT=108 ALIGN=left BORDER=1 HSPACE=6 ALT="smallliz">
Contributed TIFF Software
</H1>
@@ -155,11 +159,10 @@ various routines from Conrad Poelman; a TIFF image iterator and
<TD>
-A utility by <A HREF=mailto:billr@corbis.com>Bill Radcliffe</a> to
+A utility by <A HREF="mailto:billr@corbis.com">Bill Radcliffe</a> to
convert an extracted IPTC Newsphoto caption from a binary blob to
ASCII text, and vice versa. IPTC binary blobs can be extracted from
-images via the <A
-HREF=http://www.ImageMagick.org/>ImageMagick</a> convert(1)
+images via the <A HREF="http://www.ImageMagick.org/">ImageMagick</a> convert(1)
utility.
diff --git a/tiff/html/document.html b/tiff/html/document.html
index 71d04126..a9750933 100644
--- a/tiff/html/document.html
+++ b/tiff/html/document.html
@@ -1,13 +1,18 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>
TIFF Documentation
</TITLE>
+<style type="text/css">
+body {
+font-family: Arial, Helvetica, Sans;
+}
+</style>
</HEAD>
-<BODY BGCOLOR=white>
-<FONT FACE="Arial, Helvetica, Sans">
+<BODY>
<H1>
-<IMG SRC=images/jim.gif WIDTH=139 HEIGHT=170 ALIGN=left BORDER=1 HSPACE=6>
+<IMG SRC="images/jim.gif" WIDTH=139 HEIGHT=170 ALIGN=left BORDER=1 HSPACE=6 ALT="jim">
TIFF Documentation
</H1>
diff --git a/tiff/html/images.html b/tiff/html/images.html
index 6e2e29be..c93f38bf 100644
--- a/tiff/html/images.html
+++ b/tiff/html/images.html
@@ -1,13 +1,18 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>
TIFF Test Images
</TITLE>
+<style type="text/css">
+body {
+font-family: Arial, Helvetica, Sans;
+}
+</style>
</HEAD>
-<BODY BGCOLOR=white>
-<FONT FACE="Arial, Helvetica, Sans">
+<BODY>
<H1>
-<IMG SRC=images/bali.jpg WIDTH=158 HEIGHT=107 ALIGN=left BORDER=1 HSPACE=6>
+<IMG SRC="images/bali.jpg" WIDTH=158 HEIGHT=107 ALIGN=left BORDER=1 HSPACE=6 ALT="bali">
TIFF Test Images
</H1>
diff --git a/tiff/html/images/Makefile.in b/tiff/html/images/Makefile.in
index 234a29a5..64f473d1 100644
--- a/tiff/html/images/Makefile.in
+++ b/tiff/html/images/Makefile.in
@@ -1,7 +1,7 @@
-# Makefile.in generated by automake 1.16.1 from Makefile.am.
+# Makefile.in generated by automake 1.16.2 from Makefile.am.
# @configure_input@
-# Copyright (C) 1994-2018 Free Software Foundation, Inc.
+# Copyright (C) 1994-2020 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
diff --git a/tiff/html/index.html b/tiff/html/index.html
index dca511e7..fd7b5f77 100644
--- a/tiff/html/index.html
+++ b/tiff/html/index.html
@@ -10,7 +10,7 @@
-->
</style>
</head>
-<body lang="en" text="#000000" bgcolor="#ffffff" link="#0000ff" alink="#0000ff" vlink="#0000ff">
+<body lang="en">
<h1>LibTIFF - TIFF Library and Utilities</h1>
<hr>
<table cellspacing="0" cellpadding="0" border="0">
@@ -28,7 +28,7 @@
</tr>
<tr>
<th>Latest Stable Release</th>
- <td><a href="v4.1.0.html">v4.1.0</a></td>
+ <td><a href="v4.2.0.html">v4.2.0</a></td>
</tr>
<tr>
<th>Master Download Site</th>
@@ -44,7 +44,7 @@
</tr>
<tr>
<th>git repository</th>
- <td><tt><a href="https://gitlab.com/libtiff/libtiff">https://gitlab.com/libtiff/libtiff</a></td>
+ <td><tt><a href="https://gitlab.com/libtiff/libtiff">https://gitlab.com/libtiff/libtiff</a></tt></td>
</tr>
</table>
<hr>
diff --git a/tiff/html/internals.html b/tiff/html/internals.html
index 8d94e5ce..20061ef0 100644
--- a/tiff/html/internals.html
+++ b/tiff/html/internals.html
@@ -1,13 +1,18 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>
Modifying The TIFF Library
</TITLE>
+<style type="text/css">
+body {
+font-family: Arial, Helvetica, Sans;
+}
+</style>
</HEAD>
-<BODY BGCOLOR=white>
-<FONT FACE="Arial, Helvetica, Sans">
+<BODY>
<H1>
-<IMG SRC=images/dave.gif WIDTH=107 HEIGHT=148 BORDER=2 ALIGN=left HSPACE=6>
+<IMG SRC="images/dave.gif" WIDTH=107 HEIGHT=148 BORDER=2 ALIGN=left HSPACE=6 ALT="dave">
Modifying The TIFF Library
</H1>
@@ -19,18 +24,19 @@ how to add new support to the library.
The following sections are found in this chapter:
<UL>
-<LI><A HREF=#Config>Library Configuration</A>
-<LI><A HREF=#Portability>General Portability Comments</A>
+<LI><A HREF="#Config">Library Configuration</A>
+<LI><A HREF="#Portability">General Portability Comments</A>
<LI><A HREF="#Types">Types and Portability</A>
<LI><A HREF="addingtags.html">Adding New Tags</A>
-<LI><A HREF=#AddingCODECS>Adding New Builtin Codecs</A>
+<LI><A HREF="#AddingCODECS">Adding New Builtin Codecs</A>
<LI><A HREF="addingtags.html#AddingCODECTags">Adding New Codec-private Tags</A>
-<LI><A HREF=#Other>Other Comments</A>
+<LI><A HREF="#Other">Other Comments</A>
</UL>
-<A NAME="Config"><P><HR WIDTH=65% ALIGN=right><H3>Library Configuration</H3></A>
-
+<HR WIDTH="65%" ALIGN=right>
+<H3 id="Config">Library Configuration</H3>
+<P>
Information on compiling the library is given
<A HREF=build.html>elsewhere in this documentation</A>.
This section describes the low-level mechanisms used to control
@@ -71,11 +77,11 @@ To override the default compression behaviour define
to enable configuration of the appropriate codecs (see the table
below); e.g.
-<UL><PRE>
+<PRE style="margin-left: 3em;">
#define COMPRESSION_SUPPORT
#define CCITT_SUPPORT
#define PACKBITS_SUPPORT
-</PRE></UL>
+</PRE>
Several other compression schemes are configured separately from
the default set because they depend on ancillary software
@@ -87,7 +93,7 @@ The JPEG codec that comes with <TT>libtiff</TT> is designed for
use with release 5 or later of the Independent JPEG Group's freely
available software distribution.
This software can be retrieved from the directory
-<A HREF=ftp://ftp.uu.net/graphics/jpeg>ftp.uu.net:/graphics/jpeg/</A>.
+<A HREF="ftp://ftp.uu.net/graphics/jpeg">ftp.uu.net:/graphics/jpeg/</A>.
<P>
@@ -103,14 +109,14 @@ for use with version 0.99 or later of the freely available
<TT>libz</TT> library written by Jean-loup Gailly and Mark Adler.
The data format used by this library is described
in the files
-<A HREF=ftp://ftp.uu.net/pub/archiving/zip/doc/zlib-3.1.doc>zlib-3.1.doc</A>,
+<A HREF="ftp://ftp.uu.net/pub/archiving/zip/doc/zlib-3.1.doc">zlib-3.1.doc</A>,
and
-<A HREF=ftp://ftp.uu.net/pub/archiving/zip/doc/deflate-1.1.doc>deflate-1.1.doc</A>,
+<A HREF="ftp://ftp.uu.net/pub/archiving/zip/doc/deflate-1.1.doc">deflate-1.1.doc</A>,
available in the directory
-<A HREF=ftp://ftp.uu.net/pub/archiving/zip/doc>ftp.uu.net:/pub/archiving/zip/doc</A>.</EM>
+<A HREF="ftp://ftp.uu.net/pub/archiving/zip/doc">ftp.uu.net:/pub/archiving/zip/doc</A>.
The library can be retried from the directory
-<A HREF=ftp://ftp.uu.net/pub/archiving/zip/zlib/>ftp.uu.net:/pub/archiving/zip/zlib/</A>
-(or try <A HREF=ftp://quest.jpl.nasa.gov/beta/zlib/>quest.jpl.nasa.gov:/beta/zlib/</A>).
+<A HREF="ftp://ftp.uu.net/pub/archiving/zip/zlib/">ftp.uu.net:/pub/archiving/zip/zlib/</A>
+(or try <A HREF="ftp://quest.jpl.nasa.gov/beta/zlib/">quest.jpl.nasa.gov:/beta/zlib/</A>).
<P>
<IMG SRC="images/warning.gif" ALT="NOTE: " ALIGN=left HSPACE=8 VSPACE=6>
@@ -205,15 +211,15 @@ run-length encoding scheme from ThunderScan (compression 32809)</TD>
<I>The ICC Profile Format Specification</I>,
Annex B.3 "Embedding ICC Profiles in TIFF Files";
available at
-<A HREF=http://www.color.org>http://www.color.org</A>
+<A HREF="http://www.color.org">http://www.color.org</A>
</TD>
</TR>
</TABLE>
-
-<A NAME="Portability"><P><HR WIDTH=65% ALIGN=right><H3>General Portability Comments</H3></A>
-
+<HR WIDTH="65%" ALIGN=right>
+<H3 id="Portability">General Portability Comments</H3>
+<P>
This software is developed on Silicon Graphics UNIX
systems (big-endian, MIPS CPU, 32-bit ints,
IEEE floating point).
@@ -271,7 +277,7 @@ codecs for optimization purposes.
The following defines control general portability:
<P>
-<TABLE BORDER CELLPADDING=3 WIDTH=100%>
+<TABLE BORDER CELLPADDING=3 WIDTH="100%">
<TR>
<TD VALIGN=top><TT>BSDTYPES</TT></TD>
@@ -317,8 +323,9 @@ Note that <B>tiffcomp.h</B> defines <TT>HAVE_IEEEFP</TT> to be
1 (<TT>BSDTYPES</TT> is not defined).
-<A NAME="Types"><P><HR WIDTH=65% ALIGN=right><H3>Types and Portability</H3></A>
-
+<HR WIDTH="65%" ALIGN=right>
+<H3 id="Types">Types and Portability</H3>
+<P>
The software makes extensive use of C typedefs to promote portability.
Two sets of typedefs are used, one for communication with clients
of the library and one for internal data structures and parsing of the
@@ -328,7 +335,7 @@ purely by fiddling with the following machine-dependent typedefs:
<P>
-<TABLE BORDER CELLPADDING=3 WIDTH=100%>
+<TABLE BORDER CELLPADDING=3 WIDTH="100%">
<TR>
<TD>uint8</TD>
@@ -385,10 +392,10 @@ structure:
<P>
-<TABLE BORDER CELLPADDING=3 WIDTH=100%>
+<TABLE BORDER CELLPADDING=3 WIDTH="100%">
<TR>
-<TD WIDTH=25%>typedef unsigned int ttag_t;</TD> <TD>directory tag</TD>
+<TD WIDTH="25%">typedef unsigned int ttag_t;</TD> <TD>directory tag</TD>
</TR>
<TR>
@@ -451,8 +458,9 @@ passed as opaque handles and only cast at the lowest layers where
their type is presumed.
-<P><HR WIDTH=65% ALIGN=right><H3>General Comments</H3></A>
-
+<HR WIDTH="65%" ALIGN=right>
+<H3>General Comments</H3>
+<P>
The library is designed to hide as much of the details of TIFF from
applications as
possible. In particular, TIFF directories are read in their entirety
@@ -460,7 +468,9 @@ into an internal format. Only the tags known by the library are
available to a user and certain tag data may be maintained that a user
does not care about (e.g. transfer function tables).
-<A NAME=AddingCODECS><P><HR WIDTH=65% ALIGN=right><H3>Adding New Builtin Codecs</H3></A>
+<HR WIDTH="65%" ALIGN=right>
+<H3 id="AddingCODECS">Adding New Builtin Codecs</H3>
+<P>
To add builtin support for a new compression algorithm, you can either
use the "tag-extension" trick to override the handling of the
@@ -514,8 +524,9 @@ encoded or decoded if the image is organized with <TT>PlanarConfig</TT>=2
(separate planes). This is important for algorithms such as JPEG.
If <TT>PlanarConfig</TT>=1 (interleaved), then sample will always be 0.
-<A NAME=Other><P><HR WIDTH=65% ALIGN=right><H3>Other Comments</H3></A>
-
+<HR WIDTH="65%" ALIGN=right>
+<H3 id="Other">Other Comments</H3>
+<P>
The library handles most I/O buffering. There are two data buffers
when decoding data: a raw data buffer that holds all the data in a
strip, and a user-supplied scanline buffer that compression schemes
diff --git a/tiff/html/intro.html b/tiff/html/intro.html
index 83902f61..ad3b2d91 100644
--- a/tiff/html/intro.html
+++ b/tiff/html/intro.html
@@ -1,13 +1,18 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>
Introduction to the TIFF Documentation
</TITLE>
+<style type="text/css">
+body {
+font-family: Arial, Helvetica, Sans;
+}
+</style>
</HEAD>
-<BODY BGCOLOR=white>
-<FONT FACE="Arial, Helvetica, Sans">
+<BODY>
<H1>
-<IMG SRC=images/strike.gif WIDTH=128 HEIGHT=100 ALIGN=left HSPACE=6>
+<IMG SRC="images/strike.gif" WIDTH=128 HEIGHT=100 ALIGN=left HSPACE=6 ALT="strike">
Introduction to the TIFF Documentation
</H1>
@@ -37,7 +42,7 @@ They are consistent with the terminology used in the TIFF 6.0 specification.
<DT><I>Codec</I>
<DD>Software that implements the decoding and encoding algorithms
of a compression scheme.
-</UL>
+</DL>
<P>
In order to better understand how TIFF works (and consequently this
diff --git a/tiff/html/libtiff.html b/tiff/html/libtiff.html
index 56535d97..cda66b5a 100644
--- a/tiff/html/libtiff.html
+++ b/tiff/html/libtiff.html
@@ -10,7 +10,7 @@
-->
</style>
</head>
-<body lang="en" text="#000000" bgcolor="#ffffff" link="#0000ff" alink="#0000ff" vlink="#0000ff">
+<body lang="en">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td style="padding-left: 1em; padding-right: 1em"><img src="images/cat.gif" width="113" height="146" alt=""></td>
@@ -518,9 +518,9 @@
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &amp;imagelength);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;buf = _TIFFmalloc(TIFFScanlineSize(tif));<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (row = 0; row &lt; imagelength; row++)<br>
- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tiffreadscanline(tif, buf, row);<br>
- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_tifffree(buf);<br>
- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tiffclose(tif);<br>
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TIFFReadScanline(tif, buf, row, 0);<br>
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_TIFFfree(buf);<br>
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TIFFClose(tif);<br>
&nbsp;&nbsp;&nbsp;&nbsp;}<br>
}</tt>
</p>
@@ -547,17 +547,17 @@
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;buf = _TIFFmalloc(TIFFScanlineSize(tif));<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (config == PLANARCONFIG_CONTIG) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (row = 0; row &lt; imagelength; row++)<br>
- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tiffreadscanline(tif, buf, row);<br>
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TIFFReadScanline(tif, buf, row, 0);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} else if (config == planarconfig_separate) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;uint16 s, nsamples;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tiffgetfield(tif, tifftag_samplesperpixel, &amp;nsamples);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (s = 0; s &lt; nsamples; s++)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (row = 0; row &lt; imagelength; row++)<br>
- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tiffreadscanline(tif, buf, row, s);<br>
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TIFFReadScanline(tif, buf, row, s);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>
- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_tifffree(buf);<br>
- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tiffclose(tif);<br>
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_TIFFfree(buf);<br>
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TIFFClose(tif);<br>
&nbsp;&nbsp;&nbsp;&nbsp;}<br>
}</tt>
</p>
@@ -568,7 +568,7 @@
<p style="margin-left: 40px">
<tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (row = 0; row &lt; imagelength; row++)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (s = 0; s &lt; nsamples; s++)<br>
- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tiffreadscanline(tif, buf, row, s);</tt>
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TIFFReadScanline(tif, buf, row, s);</tt>
</p>
<p>
...then problems would arise if <tt>RowsPerStrip</tt> was not one
@@ -601,8 +601,8 @@
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;buf = _TIFFmalloc(TIFFStripSize(tif));<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (strip = 0; strip &lt; tiffnumberofstrips(tif); strip++)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tiffreadencodedstrip(tif, strip, buf, (tsize_t) -1);<br>
- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_tifffree(buf);<br>
- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tiffclose(tif);<br>
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_TIFFfree(buf);<br>
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TIFFClose(tif);<br>
&nbsp;&nbsp;&nbsp;&nbsp;}<br>
}</tt>
</p>
@@ -702,8 +702,8 @@
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (y = 0; y &lt; imagelength; y += tilelength)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (x = 0; x &lt; imagewidth; x += tilewidth)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tiffreadtile(tif, buf, x, y, 0);<br>
- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_tifffree(buf);<br>
- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tiffclose(tif);<br>
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_TIFFfree(buf);<br>
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TIFFClose(tif);<br>
&nbsp;&nbsp;&nbsp;&nbsp;}<br>
}</tt>
</p>
@@ -729,8 +729,8 @@
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;buf = _TIFFmalloc(TIFFTileSize(tif));<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (tile = 0; tile &lt; tiffnumberoftiles(tif); tile++)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tiffreadencodedtile(tif, tile, buf, (tsize_t) -1);<br>
- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_tifffree(buf);<br>
- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tiffclose(tif);<br>
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_TIFFfree(buf);<br>
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TIFFClose(tif);<br>
&nbsp;&nbsp;&nbsp;&nbsp;}<br>
}</tt>
</p>
diff --git a/tiff/html/man/Makefile.in b/tiff/html/man/Makefile.in
index c435bad5..f6d6cef2 100644
--- a/tiff/html/man/Makefile.in
+++ b/tiff/html/man/Makefile.in
@@ -1,7 +1,7 @@
-# Makefile.in generated by automake 1.16.1 from Makefile.am.
+# Makefile.in generated by automake 1.16.2 from Makefile.am.
# @configure_input@
-# Copyright (C) 1994-2018 Free Software Foundation, Inc.
+# Copyright (C) 1994-2020 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
diff --git a/tiff/html/misc.html b/tiff/html/misc.html
index b30eb676..69d3ba18 100644
--- a/tiff/html/misc.html
+++ b/tiff/html/misc.html
@@ -1,13 +1,18 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>
Acknowledgments and Other Issues
</TITLE>
+<style type="text/css">
+body {
+font-family: Arial, Helvetica, Sans;
+}
+</style>
</HEAD>
-<BODY BGCOLOR=white>
-<FONT FACE="Arial, Helvetica, Sans">
+<BODY>
<H1>
-<IMG SRC=images/ring.gif WIDTH=124 HEIGHT=124 ALIGN=left BORDER=1 HSPACE=6>
+<IMG SRC="images/ring.gif" WIDTH=124 HEIGHT=124 ALIGN=left BORDER=1 HSPACE=6 ALT="ring">
Acknowledgments and Other Issues
</H1>
@@ -84,7 +89,7 @@ the more persistent contributors have been:
<H2>Use and Copyright</H2>
-<P><H5><PRE>
+<PRE><B>
Copyright (c) 1988-1997 Sam Leffler
Copyright (c) 1991-1997 Silicon Graphics, Inc.
@@ -106,9 +111,8 @@ 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.
-</PRE></H5>
+</B></PRE>
-<P>
<HR>
diff --git a/tiff/html/support.html b/tiff/html/support.html
index 2330d40a..e29d2d0d 100644
--- a/tiff/html/support.html
+++ b/tiff/html/support.html
@@ -10,7 +10,7 @@
-->
</style>
</head>
-<body lang="en" text="#000000" bgcolor="#ffffff" link="#0000ff" alink="#0000ff" vlink="#0000ff">
+<body lang="en">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td style="padding-left: 1em; padding-right: 1em"><img src="images/strike.gif" width="128" height="100" alt=""></td>
diff --git a/tiff/html/tools.html b/tiff/html/tools.html
index 7b99d71d..d567ad8a 100644
--- a/tiff/html/tools.html
+++ b/tiff/html/tools.html
@@ -1,14 +1,16 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
-<meta name="generator" content=
-"HTML Tidy for Solaris (vers 12 April 2005), see www.w3.org">
<title>TIFF Tools Overview</title>
+<style type="text/css">
+body {
+font-family: Arial, Helvetica, Sans;
+}
+</style>
</head>
-<body bgcolor="white">
-<h1><font face="Arial, Helvetica, Sans"><img src="images/quad.jpg"
-width="144" height="108" align="left" border="1" hspace="6"> TIFF
-Tools Overview</font></h1>
+<body>
+<h1><img src="images/quad.jpg" width="144" height="108" align="left" border="1" hspace="6" alt="quad">
+TIFF Tools Overview</h1>
<p>This software distribution comes with a small collection of
programs for converting non-TIFF format images to TIFF and for
manipulating and interrogating the contents of TIFF images. Several
@@ -30,6 +32,7 @@ facilities described elsewhere.</td>
<h3>Device-independent Programs</h3>
The remaining programs should be device-independent:
<table border cellpadding="3">
+<tr>
<td valign="top" width="10%"><tt><a href="man/fax2ps.1.html">fax2ps</a></tt></td>
<td>Convert a Group 3- or Group 4- compressed TIFF to PostScript
that is significantly more compressed than is generated by
@@ -39,6 +42,7 @@ that is significantly more compressed than is generated by
<td valign="top" width="10%"><tt><a href="man/fax2tiff.1.html">fax2tiff</a></tt></td>
<td>Convert raw Group 3 or Group 4 facsimile data to TIFF</td>
</tr>
+<tr>
<td valign="top" width="10%"><tt><a href="man/pal2rgb.1.html">pal2rgb</a></tt></td>
<td>Convert a Palette-style image to a full color RGB image by
applying the colormap</td>
@@ -47,6 +51,7 @@ applying the colormap</td>
<td valign="top" width="10%"><tt><a href="man/ppm2tiff.1.html">ppm2tiff</a></tt></td>
<td>A quick hack that converts 8-bit PPM format images to TIFF</td>
</tr>
+<tr>
<td valign="top" width="10%"><tt><a href="man/raw2tiff.1.html">raw2tiff</a></tt></td>
<td>Create a TIFF file from raw data</td>
</tr>
@@ -56,7 +61,7 @@ applying the colormap</td>
TIFF image; it's mainly provided for testing</td>
</tr>
<tr>
-<td valign="top" width="10%"><tt><a href="man/thumbnail.1.html">thumbnail</a></tt></tt></td>
+<td valign="top" width="10%"><tt><a href="man/thumbnail.1.html">thumbnail</a></tt></td>
<td>Copy a bilevel TIFF to one that includes 8-bit greyscale
"thumbnail images" for each page; it is provided as an example of
how one might use the <tt>SubIFD</tt> tag (and the library support
diff --git a/tiff/html/v3.4beta007.html b/tiff/html/v3.4beta007.html
index 10307205..c2b51f0a 100644
--- a/tiff/html/v3.4beta007.html
+++ b/tiff/html/v3.4beta007.html
@@ -1,3 +1,4 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>
diff --git a/tiff/html/v3.4beta016.html b/tiff/html/v3.4beta016.html
index 170f3384..11035384 100644
--- a/tiff/html/v3.4beta016.html
+++ b/tiff/html/v3.4beta016.html
@@ -1,3 +1,4 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>
diff --git a/tiff/html/v3.4beta018.html b/tiff/html/v3.4beta018.html
index 4843c95d..63ffb497 100644
--- a/tiff/html/v3.4beta018.html
+++ b/tiff/html/v3.4beta018.html
@@ -1,3 +1,4 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>
diff --git a/tiff/html/v3.4beta024.html b/tiff/html/v3.4beta024.html
index ee2b243b..ec82840c 100644
--- a/tiff/html/v3.4beta024.html
+++ b/tiff/html/v3.4beta024.html
@@ -1,3 +1,4 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>
diff --git a/tiff/html/v3.4beta028.html b/tiff/html/v3.4beta028.html
index 5ac9d75f..5ae0e490 100644
--- a/tiff/html/v3.4beta028.html
+++ b/tiff/html/v3.4beta028.html
@@ -1,3 +1,4 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>
diff --git a/tiff/html/v3.4beta029.html b/tiff/html/v3.4beta029.html
index f7e863d0..580cfc49 100644
--- a/tiff/html/v3.4beta029.html
+++ b/tiff/html/v3.4beta029.html
@@ -1,3 +1,4 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>
diff --git a/tiff/html/v3.4beta031.html b/tiff/html/v3.4beta031.html
index 137368da..2dff6349 100644
--- a/tiff/html/v3.4beta031.html
+++ b/tiff/html/v3.4beta031.html
@@ -1,3 +1,4 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>
diff --git a/tiff/html/v3.4beta032.html b/tiff/html/v3.4beta032.html
index 4651539e..8ac2cc2d 100644
--- a/tiff/html/v3.4beta032.html
+++ b/tiff/html/v3.4beta032.html
@@ -1,3 +1,4 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>
diff --git a/tiff/html/v3.4beta033.html b/tiff/html/v3.4beta033.html
index f311e6a3..256b3f8e 100644
--- a/tiff/html/v3.4beta033.html
+++ b/tiff/html/v3.4beta033.html
@@ -1,3 +1,4 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>
diff --git a/tiff/html/v3.4beta034.html b/tiff/html/v3.4beta034.html
index a2735de2..33ca2f19 100644
--- a/tiff/html/v3.4beta034.html
+++ b/tiff/html/v3.4beta034.html
@@ -1,3 +1,4 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>
diff --git a/tiff/html/v3.4beta035.html b/tiff/html/v3.4beta035.html
index 5b0901d3..51e4116c 100644
--- a/tiff/html/v3.4beta035.html
+++ b/tiff/html/v3.4beta035.html
@@ -1,3 +1,4 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>
diff --git a/tiff/html/v3.4beta036.html b/tiff/html/v3.4beta036.html
index a853113d..91c2721f 100644
--- a/tiff/html/v3.4beta036.html
+++ b/tiff/html/v3.4beta036.html
@@ -1,3 +1,4 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>
diff --git a/tiff/html/v3.5.1.html b/tiff/html/v3.5.1.html
index e3ee7077..559f5496 100644
--- a/tiff/html/v3.5.1.html
+++ b/tiff/html/v3.5.1.html
@@ -1,3 +1,4 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>
diff --git a/tiff/html/v3.5.2.html b/tiff/html/v3.5.2.html
index daad4c55..2c4cbf51 100644
--- a/tiff/html/v3.5.2.html
+++ b/tiff/html/v3.5.2.html
@@ -1,3 +1,4 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>
diff --git a/tiff/html/v3.5.3.html b/tiff/html/v3.5.3.html
index 9ea78562..0aabcaa8 100644
--- a/tiff/html/v3.5.3.html
+++ b/tiff/html/v3.5.3.html
@@ -1,3 +1,4 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>
diff --git a/tiff/html/v3.5.4.html b/tiff/html/v3.5.4.html
index 7e3eb841..c9fdcf65 100644
--- a/tiff/html/v3.5.4.html
+++ b/tiff/html/v3.5.4.html
@@ -1,3 +1,4 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>
diff --git a/tiff/html/v3.5.5.html b/tiff/html/v3.5.5.html
index 779e3772..aa606fd1 100644
--- a/tiff/html/v3.5.5.html
+++ b/tiff/html/v3.5.5.html
@@ -1,3 +1,4 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>
diff --git a/tiff/html/v3.5.6-beta.html b/tiff/html/v3.5.6-beta.html
index 498cc439..81f11a36 100644
--- a/tiff/html/v3.5.6-beta.html
+++ b/tiff/html/v3.5.6-beta.html
@@ -1,3 +1,4 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>
diff --git a/tiff/html/v3.5.7.html b/tiff/html/v3.5.7.html
index b68e29ee..a58b7e5a 100644
--- a/tiff/html/v3.5.7.html
+++ b/tiff/html/v3.5.7.html
@@ -1,3 +1,4 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>
diff --git a/tiff/html/v3.6.0.html b/tiff/html/v3.6.0.html
index 11b10af0..1a3ba4a9 100644
--- a/tiff/html/v3.6.0.html
+++ b/tiff/html/v3.6.0.html
@@ -1,3 +1,4 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>
diff --git a/tiff/html/v3.6.1.html b/tiff/html/v3.6.1.html
index 3f0e93c3..6a357f4c 100644
--- a/tiff/html/v3.6.1.html
+++ b/tiff/html/v3.6.1.html
@@ -1,3 +1,4 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>
diff --git a/tiff/html/v3.7.0.html b/tiff/html/v3.7.0.html
index c70e8e72..9c0819a4 100644
--- a/tiff/html/v3.7.0.html
+++ b/tiff/html/v3.7.0.html
@@ -1,3 +1,4 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>
diff --git a/tiff/html/v3.7.0alpha.html b/tiff/html/v3.7.0alpha.html
index 5ce60069..39b63238 100644
--- a/tiff/html/v3.7.0alpha.html
+++ b/tiff/html/v3.7.0alpha.html
@@ -1,3 +1,4 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>
diff --git a/tiff/html/v3.7.0beta.html b/tiff/html/v3.7.0beta.html
index a29e521f..f646480f 100644
--- a/tiff/html/v3.7.0beta.html
+++ b/tiff/html/v3.7.0beta.html
@@ -1,3 +1,4 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>
diff --git a/tiff/html/v3.7.0beta2.html b/tiff/html/v3.7.0beta2.html
index 9a313aca..41ba6c3a 100644
--- a/tiff/html/v3.7.0beta2.html
+++ b/tiff/html/v3.7.0beta2.html
@@ -1,3 +1,4 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>
diff --git a/tiff/html/v3.7.1.html b/tiff/html/v3.7.1.html
index 3e332b14..164b4059 100644
--- a/tiff/html/v3.7.1.html
+++ b/tiff/html/v3.7.1.html
@@ -1,3 +1,4 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>
diff --git a/tiff/html/v3.7.2.html b/tiff/html/v3.7.2.html
index 2be1edef..d396021e 100644
--- a/tiff/html/v3.7.2.html
+++ b/tiff/html/v3.7.2.html
@@ -1,3 +1,4 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>
diff --git a/tiff/html/v3.7.3.html b/tiff/html/v3.7.3.html
index c3aafff4..54978c8f 100644
--- a/tiff/html/v3.7.3.html
+++ b/tiff/html/v3.7.3.html
@@ -1,3 +1,4 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>
diff --git a/tiff/html/v3.7.4.html b/tiff/html/v3.7.4.html
index 465af218..eeb0f3ca 100644
--- a/tiff/html/v3.7.4.html
+++ b/tiff/html/v3.7.4.html
@@ -1,3 +1,4 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>
diff --git a/tiff/html/v3.8.0.html b/tiff/html/v3.8.0.html
index 8ac23f38..81a8b0c6 100644
--- a/tiff/html/v3.8.0.html
+++ b/tiff/html/v3.8.0.html
@@ -1,3 +1,4 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>
diff --git a/tiff/html/v3.8.1.html b/tiff/html/v3.8.1.html
index 6b069e32..0fe7d9c0 100644
--- a/tiff/html/v3.8.1.html
+++ b/tiff/html/v3.8.1.html
@@ -1,3 +1,4 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>
diff --git a/tiff/html/v3.8.2.html b/tiff/html/v3.8.2.html
index 10fa57d2..41bb2e55 100644
--- a/tiff/html/v3.8.2.html
+++ b/tiff/html/v3.8.2.html
@@ -1,3 +1,4 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>
diff --git a/tiff/html/v3.9.0beta.html b/tiff/html/v3.9.0beta.html
index e973ca8b..56f32ed3 100644
--- a/tiff/html/v3.9.0beta.html
+++ b/tiff/html/v3.9.0beta.html
@@ -1,3 +1,4 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>
diff --git a/tiff/html/v3.9.1.html b/tiff/html/v3.9.1.html
index fc6bca19..1f369a83 100644
--- a/tiff/html/v3.9.1.html
+++ b/tiff/html/v3.9.1.html
@@ -1,3 +1,4 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>
diff --git a/tiff/html/v3.9.2.html b/tiff/html/v3.9.2.html
index 34a117a4..a190a301 100644
--- a/tiff/html/v3.9.2.html
+++ b/tiff/html/v3.9.2.html
@@ -1,3 +1,4 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>
diff --git a/tiff/html/v4.0.0.html b/tiff/html/v4.0.0.html
index f64208ac..a7e9bb63 100644
--- a/tiff/html/v4.0.0.html
+++ b/tiff/html/v4.0.0.html
@@ -1,3 +1,4 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>
diff --git a/tiff/html/v4.0.1.html b/tiff/html/v4.0.1.html
index b4a8bc2f..5e927173 100644
--- a/tiff/html/v4.0.1.html
+++ b/tiff/html/v4.0.1.html
@@ -1,3 +1,4 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>
diff --git a/tiff/html/v4.0.10.html b/tiff/html/v4.0.10.html
index b7d87361..578404e1 100644
--- a/tiff/html/v4.0.10.html
+++ b/tiff/html/v4.0.10.html
@@ -1,3 +1,4 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>
diff --git a/tiff/html/v4.0.2.html b/tiff/html/v4.0.2.html
index 91f20dde..cbed8b89 100644
--- a/tiff/html/v4.0.2.html
+++ b/tiff/html/v4.0.2.html
@@ -1,3 +1,4 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>
diff --git a/tiff/html/v4.0.3.html b/tiff/html/v4.0.3.html
index 14ccfb39..e034c3f0 100644
--- a/tiff/html/v4.0.3.html
+++ b/tiff/html/v4.0.3.html
@@ -1,3 +1,4 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>
diff --git a/tiff/html/v4.0.4.html b/tiff/html/v4.0.4.html
index a5691140..61c31101 100644
--- a/tiff/html/v4.0.4.html
+++ b/tiff/html/v4.0.4.html
@@ -1,3 +1,4 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>
diff --git a/tiff/html/v4.0.4beta.html b/tiff/html/v4.0.4beta.html
index e06a2c22..e9e70a55 100644
--- a/tiff/html/v4.0.4beta.html
+++ b/tiff/html/v4.0.4beta.html
@@ -1,3 +1,4 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>
diff --git a/tiff/html/v4.0.5.html b/tiff/html/v4.0.5.html
index c638638a..a3354704 100644
--- a/tiff/html/v4.0.5.html
+++ b/tiff/html/v4.0.5.html
@@ -1,3 +1,4 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>
diff --git a/tiff/html/v4.0.6.html b/tiff/html/v4.0.6.html
index 8fc63b5c..dbca5c86 100644
--- a/tiff/html/v4.0.6.html
+++ b/tiff/html/v4.0.6.html
@@ -1,3 +1,4 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>
diff --git a/tiff/html/v4.0.7.html b/tiff/html/v4.0.7.html
index e1b5dec9..4f92c129 100644
--- a/tiff/html/v4.0.7.html
+++ b/tiff/html/v4.0.7.html
@@ -1,3 +1,4 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>
diff --git a/tiff/html/v4.0.8.html b/tiff/html/v4.0.8.html
index 86db3bbf..bd3f751c 100644
--- a/tiff/html/v4.0.8.html
+++ b/tiff/html/v4.0.8.html
@@ -1,3 +1,4 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>
diff --git a/tiff/html/v4.0.9.html b/tiff/html/v4.0.9.html
index 4efe987f..19b370a4 100644
--- a/tiff/html/v4.0.9.html
+++ b/tiff/html/v4.0.9.html
@@ -1,3 +1,4 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>
diff --git a/tiff/html/v4.1.0.html b/tiff/html/v4.1.0.html
index 7c61fac7..80dac5bf 100644
--- a/tiff/html/v4.1.0.html
+++ b/tiff/html/v4.1.0.html
@@ -1,9 +1,13 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>
Changes in TIFF v4.1.0
</TITLE>
-<STYLE>
+<STYLE TYPE="text/css">
+body {
+ font-family: Helvetica, Arial, Sans;
+}
table, th, td {
border: 1px solid black;
border-collapse: collapse;
@@ -39,28 +43,31 @@ ol.d {
list-style-type: lower-alpha;
}
+hr {
+ width: 65%;
+}
+
</STYLE>
</HEAD>
<BODY BGCOLOR=white>
-<FONT FACE="Helvetica, Arial, Sans">
<BASEFONT SIZE=4>
-<B><FONT SIZE=+3>T</FONT>IFF <FONT SIZE=+2>C</FONT>HANGE <FONT SIZE=+2>I</FONT>NFORMATION</B>
+<B><FONT SIZE="+3">T</FONT>IFF <FONT SIZE="+2">C</FONT>HANGE <FONT SIZE="+2">I</FONT>NFORMATION</B>
<BASEFONT SIZE=3>
-<UL>
-<HR SIZE=4 WIDTH=65% ALIGN=left>
+<div style="margin-left: 3em">
+<HR SIZE=4 ALIGN=left>
<B>Current Version</B>: v4.1.0<BR>
<B>Previous Version</B>: <A HREF=v4.0.10.html>v4.0.10</a><BR>
<B>Master Download Site</B>: <A HREF="https://download.osgeo.org/libtiff">
-download.osgeo.org</a>, directory pub/libtiff</A><BR>
+download.osgeo.org</a>, directory pub/libtiff<<BR>
<B>Master HTTP Site #1</B>: <A HREF="http://www.simplesystems.org/libtiff/">
http://www.simplesystems.org/libtiff/</a><BR>
<B>Master HTTP Site #2</B>: <A HREF="http://libtiff.maptools.org/">
http://libtiff.maptools.org/</a>
-<HR SIZE=4 WIDTH=65% ALIGN=left>
-</UL>
+<HR SIZE=4 ALIGN=left>
+</div>
<P>
This document describes the changes made to the software between the
@@ -78,11 +85,11 @@ history:
<LI><A HREF="#contrib">Changes in the contrib area</A>
</UL>
<p>
-<P><HR WIDTH=65% ALIGN=left>
+<P><HR ALIGN=left>
-<!--------------------------------------------------------------------------->
+<!-- ============================================================= -->
-<A NAME="highlights"><B><FONT SIZE=+3>M</FONT>AJOR CHANGES:</B></A>
+<A NAME="highlights"><B><FONT SIZE="+3">M</FONT>AJOR CHANGES:</B></A>
<UL>
@@ -117,10 +124,10 @@ history:
</UL>
-<P><HR WIDTH=65% ALIGN=left>
-<!--------------------------------------------------------------------------->
+<P><HR ALIGN=left>
+<!-- ============================================================= -->
-<A NAME="configure"><B><FONT SIZE=+3>C</FONT>HANGES IN THE SOFTWARE CONFIGURATION:</B></A>
+<A NAME="configure"><B><FONT SIZE="+3">C</FONT>HANGES IN THE SOFTWARE CONFIGURATION:</B></A>
<UL>
@@ -131,11 +138,11 @@ history:
</UL>
-<P><HR WIDTH=65% ALIGN=left>
+<P><HR ALIGN=left>
-<!--------------------------------------------------------------------------->
+<!-- ============================================================= -->
-<A NAME="libtiff"><B><FONT SIZE=+3>C</FONT>HANGES IN LIBTIFF:</B></A>
+<A NAME="libtiff"><B><FONT SIZE="+3">C</FONT>HANGES IN LIBTIFF:</B></A>
<UL>
@@ -166,11 +173,11 @@ history:
</UL>
-<P><HR WIDTH=65% ALIGN=left>
+<P><HR ALIGN=left>
-<!-------------------------------------------------------------------------->
+<!-- ============================================================= -->
-<A NAME="tools"><B><FONT SIZE=+3>C</FONT>HANGES IN THE TOOLS:</B></A>
+<A NAME="tools"><B><FONT SIZE="+3">C</FONT>HANGES IN THE TOOLS:</B></A>
<UL>
@@ -180,11 +187,11 @@ history:
</UL>
-<P><HR WIDTH=65% ALIGN=left>
+<P><HR ALIGN=left>
-<!--------------------------------------------------------------------------->
+<!-- ============================================================= -->
-<A NAME="contrib"><B><FONT SIZE=+3>C</FONT>HANGES IN THE CONTRIB AREA:</B></A>
+<A NAME="contrib"><B><FONT SIZE="+3">C</FONT>HANGES IN THE CONTRIB AREA:</B></A>
<UL>
diff --git a/tiff/html/v4.2.0.html b/tiff/html/v4.2.0.html
new file mode 100644
index 00000000..c81ecdd2
--- /dev/null
+++ b/tiff/html/v4.2.0.html
@@ -0,0 +1,205 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<HTML>
+<HEAD>
+<TITLE>
+ Changes in TIFF v4.2.0
+</TITLE>
+<STYLE TYPE="text/css">
+body {
+ font-family: Helvetica, Arial, Sans;
+}
+table, th, td {
+ border: 1px solid black;
+ border-collapse: collapse;
+}
+th, td {
+ padding: 8pt;
+ text-align: center;
+}
+th {
+ text-align: center;
+}
+td {
+ text-align: center;
+}
+
+ul li {
+ padding: 3pt;
+}
+
+ul.a {
+ list-style-type: circle;
+}
+
+ul.b {
+ list-style-type: square;
+}
+
+ol.c {
+ list-style-type: upper-roman;
+}
+
+ol.d {
+ list-style-type: lower-alpha;
+}
+
+hr {
+ width: 65%;
+}
+
+</STYLE>
+</HEAD>
+
+<BODY BGCOLOR=white>
+
+<BASEFONT SIZE=4>
+<B><FONT SIZE="+3">T</FONT>IFF <FONT SIZE="+2">C</FONT>HANGE <FONT SIZE="+2">I</FONT>NFORMATION</B>
+<BASEFONT SIZE=3>
+
+<div style="margin-left: 3em">
+<HR SIZE=4 ALIGN=left>
+<B>Current Version</B>: v4.2.0<BR>
+<B>Previous Version</B>: <A HREF=v4.1.0.html>v4.1.0</a><BR>
+<B>Master Download Site</B>: <A HREF="https://download.osgeo.org/libtiff">
+download.osgeo.org</a>, directory pub/libtiff<<BR>
+<B>Master HTTP Site #1</B>: <A HREF="http://www.simplesystems.org/libtiff/">
+http://www.simplesystems.org/libtiff/</a><BR>
+<B>Master HTTP Site #2</B>: <A HREF="http://libtiff.maptools.org/">
+http://libtiff.maptools.org/</a>
+<HR SIZE=4 ALIGN=left>
+</div>
+
+<P>
+This document provides a summary of significant changes made to the
+software between the <I>previous</I> and <I>current</I> versions (see
+above). A fully-detailed change summary is provided by the ChangeLog file
+included in the release package and by the Git commit history:
+<UL>
+<LI><A HREF="#highlights">Major Changes</A>
+<LI><A HREF="#configure">Changes in the software configuration</A>
+<LI><A HREF="#libtiff">Changes in libtiff</A>
+<LI><A HREF="#tools">Changes in the tools</A>
+<LI><A HREF="#contrib">Changes in the contrib area</A>
+</UL>
+<p>
+<P><HR ALIGN=left>
+
+<!-- ============================================================= -->
+
+<A NAME="highlights"><B><FONT SIZE="+3">M</FONT>AJOR CHANGES:</B></A>
+
+<UL>
+
+ <LI>Optional support for using libdeflate is added.</LI>
+
+ <LI>Many of the tools now support a memory usage limit.</LI>
+
+</UL>
+
+
+<P><HR ALIGN=left>
+<!-- ============================================================= -->
+
+<A NAME="configure"><B><FONT SIZE="+3">C</FONT>HANGES IN THE SOFTWARE CONFIGURATION:</B></A>
+
+<UL>
+
+ <LI>The Microsoft Windows 'nmake' build is resuscitated and provides
+ a default HAVE_STRTOLL setting in 'nmake.opt' which is suitable for
+ MSVC++ 14.0 ("Visual Studio 2015") and later but may be disabled in
+ order to compile with earlier compiler versions.</LI>
+
+ <LI>mingw-w64 cmake build fixes to not add libm</LI>
+
+</UL>
+
+<P><HR ALIGN=left>
+
+<!-- ============================================================= -->
+
+<A NAME="libtiff"><B><FONT SIZE="+3">C</FONT>HANGES IN LIBTIFF:</B></A>
+
+<UL>
+
+ <LI>A great many issues discovered by fuzzers (via oss-fuzz and other reports) have been addressed.</LI>
+
+ <LI>EXIF 2.32 and GPS tags and functionality have been upgraded:
+ <UL>
+ <LI>Existing EXIF field definition of tags are upgraded to EXIF version 2.3.2</LI>
+ <LI>EXIF-GPS structure, tags and access functions are added as special CustomDirectory (like it was done for EXIF).</LI>
+ <LI>Reading error for FileSource and SceneType tags corrected.</LI>
+ </UL>
+
+ <LI>Make TIFFTAG_CFAPATTERN variable count.</LI>
+
+ <LI>Cmake configuration fixes for big-endian targets.</LI>
+
+ <LI><P>Added support for optional building against libdeflate for
+ faster Zip/Deflate compression/decompression.</P>
+
+ <P>We now have 2 kinds of builds with the Zip/Deflate codec:</P>
+ <UL>
+ <LI>zlib only</LI>
+ <LI>zlib + libdeflate</LI>
+ </UL>
+
+ <P>Speed improvements in the 35%-50% range can be expected when libdeflate is used.
+ Compression level up to 12 is now supported (capped to 9 when zlib is used).
+ Still requires zlib for situations where libdeflate cannot be used (that
+ is for scanline access, since libdeflate has no streaming mode)</P>
+
+ <P>Pseudo-tag TIFFTAG_DEFLATE_SUBCODEC=DEFLATE_SUBCODEC_ZLIB/DEFLATE_SUBCODEC_LIBDEFLATE
+ is added to control which subcodec (zlib or libdeflate) should be used (it defaults
+ of course to libdeflate, when it is available).
+ This is mostly aimed at being used on the writing side, to be able to reproduce
+ output of previous libtiff versions at a binary level, in situations where this would
+ be really needed. Or as a safety belt in case there would be unforeseen issues
+ with using libdeflate.
+ It can be used to know when libdeflate is available at runtime (DEFLATE_SUBCODEC_LIBDEFLATE
+ will be the default value in that situation).</P>
+ <P>Of course, deflate codestreams produced by libdeflate can be read by zlib, and vice-versa.</P>
+
+ </LI>
+
+</UL>
+
+<P><HR ALIGN=left>
+
+<!-- ============================================================= -->
+
+<A NAME="tools"><B><FONT SIZE="+3">C</FONT>HANGES IN THE TOOLS:</B></A>
+
+<UL>
+
+ <LI>A great many issues discovered by fuzzers (via oss-fuzz and other reports) have been addressed.</LI>
+
+ <LI>ppm2tiff: support any bps value from 1 to 16.</LI>
+
+ <LI>tiff2ps, tiff2rgba: A default memory limit is now enforced (256MiB) and a '-M' option is added to allow the user to adjust the limit.</LI>
+
+ <LI>tiff2pdf, tiffcp: A default memory limit is now enforced (256MiB) and a '-m' option is added to allow the user to adjust the limit.</LI>
+
+ <LI>tiffcrop: A default memory limit is now enforced (256MiB) and a '-k' option is added to allow the user to adjust the limit.</LI>
+
+ <LI>tiff2pdf: fix "raw" copy of Deflate streams.</LI>
+
+ <LI>tiff2pdf.c: properly calculate datasize when saving to JPEG YCbCr</LI>
+
+ <LI>tiffcp: disable strip chopping when trying to convert to JBIG compression</LI>
+
+</UL>
+
+<P><HR ALIGN=left>
+
+<!-- ============================================================= -->
+
+<A NAME="contrib"><B><FONT SIZE="+3">C</FONT>HANGES IN THE CONTRIB AREA:</B></A>
+
+<UL>
+
+ <LI>None</LI>
+
+</UL>
+
+</BODY>
+</HTML>
diff --git a/tiff/libtiff/Makefile.in b/tiff/libtiff/Makefile.in
index a593fc22..2f853ea5 100644
--- a/tiff/libtiff/Makefile.in
+++ b/tiff/libtiff/Makefile.in
@@ -1,7 +1,7 @@
-# Makefile.in generated by automake 1.16.1 from Makefile.am.
+# Makefile.in generated by automake 1.16.2 from Makefile.am.
# @configure_input@
-# Copyright (C) 1994-2018 Free Software Foundation, Inc.
+# Copyright (C) 1994-2020 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -301,8 +301,8 @@ am__libtiffinclude_HEADERS_DIST = tiff.h tiffio.h tiffvers.h \
tiffio.hxx
HEADERS = $(libtiffinclude_HEADERS) $(nodist_libtiffinclude_HEADERS) \
$(noinst_HEADERS)
-am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) \
- $(LISP)tif_config.h.in tiffconf.h.in
+am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) \
+ tif_config.h.in tiffconf.h.in
# Read a list of newline-separated strings from the standard input,
# and print each of them once, without duplicates. Input order is
# *not* preserved.
diff --git a/tiff/libtiff/libtiff.def b/tiff/libtiff/libtiff.def
index e34fac58..b2d03fe7 100644
--- a/tiff/libtiff/libtiff.def
+++ b/tiff/libtiff/libtiff.def
@@ -12,6 +12,7 @@ EXPORTS TIFFAccessTagMethods
TIFFCreateCustomDirectory
TIFFCreateDirectory
TIFFCreateEXIFDirectory
+ TIFFCreateGPSDirectory
TIFFCurrentDirOffset
TIFFCurrentDirectory
TIFFCurrentRow
@@ -86,6 +87,7 @@ EXPORTS TIFFAccessTagMethods
TIFFReadCustomDirectory
TIFFReadDirectory
TIFFReadEXIFDirectory
+ TIFFReadGPSDirectory
TIFFReadEncodedStrip
TIFFReadEncodedTile
TIFFReadFromUserBuffer
@@ -171,5 +173,7 @@ EXPORTS TIFFAccessTagMethods
_TIFFmemcpy
_TIFFmemset
_TIFFrealloc
- _TIFFMultiply32
- _TIFFMultiply64
+ _TIFFMultiply32
+ _TIFFMultiply64
+ _TIFFGetExifFields
+ _TIFFGetGpsFields
diff --git a/tiff/libtiff/tif_aux.c b/tiff/libtiff/tif_aux.c
index 8188db53..c9f19054 100644
--- a/tiff/libtiff/tif_aux.c
+++ b/tiff/libtiff/tif_aux.c
@@ -270,7 +270,7 @@ TIFFVGetFieldDefaulted(TIFF* tif, uint32 tag, va_list ap)
return (1);
case TIFFTAG_EXTRASAMPLES:
*va_arg(ap, uint16 *) = td->td_extrasamples;
- *va_arg(ap, uint16 **) = td->td_sampleinfo;
+ *va_arg(ap, const uint16 **) = td->td_sampleinfo;
return (1);
case TIFFTAG_MATTEING:
*va_arg(ap, uint16 *) =
@@ -292,8 +292,8 @@ TIFFVGetFieldDefaulted(TIFF* tif, uint32 tag, va_list ap)
case TIFFTAG_YCBCRCOEFFICIENTS:
{
/* defaults are from CCIR Recommendation 601-1 */
- static float ycbcrcoeffs[] = { 0.299f, 0.587f, 0.114f };
- *va_arg(ap, float **) = ycbcrcoeffs;
+ static const float ycbcrcoeffs[] = { 0.299f, 0.587f, 0.114f };
+ *va_arg(ap, const float **) = ycbcrcoeffs;
return 1;
}
case TIFFTAG_YCBCRSUBSAMPLING:
@@ -305,14 +305,14 @@ TIFFVGetFieldDefaulted(TIFF* tif, uint32 tag, va_list ap)
return (1);
case TIFFTAG_WHITEPOINT:
{
- static float whitepoint[2];
-
/* TIFF 6.0 specification tells that it is no default
value for the WhitePoint, but AdobePhotoshop TIFF
Technical Note tells that it should be CIE D50. */
- whitepoint[0] = D50_X0 / (D50_X0 + D50_Y0 + D50_Z0);
- whitepoint[1] = D50_Y0 / (D50_X0 + D50_Y0 + D50_Z0);
- *va_arg(ap, float **) = whitepoint;
+ static const float whitepoint[] = {
+ D50_X0 / (D50_X0 + D50_Y0 + D50_Z0),
+ D50_Y0 / (D50_X0 + D50_Y0 + D50_Z0)
+ };
+ *va_arg(ap, const float **) = whitepoint;
return 1;
}
case TIFFTAG_TRANSFERFUNCTION:
@@ -321,16 +321,16 @@ TIFFVGetFieldDefaulted(TIFF* tif, uint32 tag, va_list ap)
TIFFErrorExt(tif->tif_clientdata, tif->tif_name, "No space for \"TransferFunction\" tag");
return (0);
}
- *va_arg(ap, uint16 **) = td->td_transferfunction[0];
+ *va_arg(ap, const uint16 **) = td->td_transferfunction[0];
if (td->td_samplesperpixel - td->td_extrasamples > 1) {
- *va_arg(ap, uint16 **) = td->td_transferfunction[1];
- *va_arg(ap, uint16 **) = td->td_transferfunction[2];
+ *va_arg(ap, const uint16 **) = td->td_transferfunction[1];
+ *va_arg(ap, const uint16 **) = td->td_transferfunction[2];
}
return (1);
case TIFFTAG_REFERENCEBLACKWHITE:
if (!td->td_refblackwhite && !TIFFDefaultRefBlackWhite(td))
return (0);
- *va_arg(ap, float **) = td->td_refblackwhite;
+ *va_arg(ap, const float **) = td->td_refblackwhite;
return (1);
}
return 0;
diff --git a/tiff/libtiff/tif_compress.c b/tiff/libtiff/tif_compress.c
index 8130ef08..915478f5 100644
--- a/tiff/libtiff/tif_compress.c
+++ b/tiff/libtiff/tif_compress.c
@@ -264,7 +264,7 @@ TIFFGetConfiguredCODECs()
return NULL;
}
codecs = new_codecs;
- _TIFFmemcpy(codecs + i - 1, cd, sizeof(TIFFCodec));
+ _TIFFmemcpy(codecs + i - 1, cd->info, sizeof(TIFFCodec));
i++;
}
for (c = _TIFFBuiltinCODECS; c->name; c++) {
diff --git a/tiff/libtiff/tif_config.h.in b/tiff/libtiff/tif_config.h.in
index 523da3e3..30afd7a1 100644
--- a/tiff/libtiff/tif_config.h.in
+++ b/tiff/libtiff/tif_config.h.in
@@ -153,6 +153,9 @@
/* Support JPEG compression (requires IJG JPEG library) */
#undef JPEG_SUPPORT
+/* Support libdeflate enhanced compression */
+#undef LIBDEFLATE_SUPPORT
+
/* 12bit libjpeg primary include file with path */
#undef LIBJPEG_12_PATH
diff --git a/tiff/libtiff/tif_config.vc.h b/tiff/libtiff/tif_config.vc.h
index 5cebfa02..939594f8 100644
--- a/tiff/libtiff/tif_config.vc.h
+++ b/tiff/libtiff/tif_config.vc.h
@@ -104,11 +104,24 @@
/* Set the native cpu bit order */
#define HOST_FILLORDER FILLORDER_LSB2MSB
+/*
+ Please see associated settings in "nmake.opt" which configure porting
+ settings. It should not be necessary to edit the following pre-processor
+ logic.
+*/
+#if defined(_MSC_VER)
/* Visual Studio 2015 / VC 14 / MSVC 19.00 finally has snprintf() */
-#if defined(_MSC_VER) && _MSC_VER < 1900
-#define snprintf _snprintf
-#else
-#define HAVE_SNPRINTF 1
+# if _MSC_VER < 1900 /* Visual C++ 2015 */
+# define snprintf _snprintf
+# else
+# define HAVE_SNPRINTF 1
+# endif
+# define HAVE_STRTOL 1
+# define HAVE_STRTOUL 1
+# if _MSC_VER >= 1900 /* Visual Studio 2015 added strtoll/strtoull */
+# define HAVE_STRTOLL 1
+# define HAVE_STRTOULL 1
+# endif
#endif
/* Define to 1 if your processor stores words with the most significant byte
diff --git a/tiff/libtiff/tif_dir.c b/tiff/libtiff/tif_dir.c
index 1e0a76c3..347b7115 100644
--- a/tiff/libtiff/tif_dir.c
+++ b/tiff/libtiff/tif_dir.c
@@ -29,6 +29,7 @@
* (and also some miscellaneous stuff)
*/
#include "tiffiop.h"
+#include <float.h> /*--: for Rational2Double */
/*
* These are used in the backwards compatibility code...
@@ -123,7 +124,7 @@ setExtraSamples(TIFF* tif, va_list ap, uint32* v)
{
TIFFWarningExt(tif->tif_clientdata,module,
"ExtraSamples tag value is changing, "
- "but TransferFunction was read with a different value. Cancelling it");
+ "but TransferFunction was read with a different value. Canceling it");
TIFFClrFieldBit(tif,FIELD_TRANSFERFUNCTION);
_TIFFfree(td->td_transferfunction[0]);
td->td_transferfunction[0] = NULL;
@@ -205,7 +206,7 @@ _TIFFVSetField(TIFF* tif, uint32 tag, va_list ap)
/*
* If the data require post-decoding processing to byte-swap
* samples, set it up here. Note that since tags are required
- * to be ordered, compression code can override this behaviour
+ * to be ordered, compression code can override this behavior
* in the setup method if it wants to roll the post decoding
* work in with its normal work.
*/
@@ -275,7 +276,7 @@ _TIFFVSetField(TIFF* tif, uint32 tag, va_list ap)
{
TIFFWarningExt(tif->tif_clientdata,module,
"SamplesPerPixel tag value is changing, "
- "but SMinSampleValue tag was read with a different value. Cancelling it");
+ "but SMinSampleValue tag was read with a different value. Canceling it");
TIFFClrFieldBit(tif,FIELD_SMINSAMPLEVALUE);
_TIFFfree(td->td_sminsamplevalue);
td->td_sminsamplevalue = NULL;
@@ -284,7 +285,7 @@ _TIFFVSetField(TIFF* tif, uint32 tag, va_list ap)
{
TIFFWarningExt(tif->tif_clientdata,module,
"SamplesPerPixel tag value is changing, "
- "but SMaxSampleValue tag was read with a different value. Cancelling it");
+ "but SMaxSampleValue tag was read with a different value. Canceling it");
TIFFClrFieldBit(tif,FIELD_SMAXSAMPLEVALUE);
_TIFFfree(td->td_smaxsamplevalue);
td->td_smaxsamplevalue = NULL;
@@ -296,7 +297,7 @@ _TIFFVSetField(TIFF* tif, uint32 tag, va_list ap)
{
TIFFWarningExt(tif->tif_clientdata,module,
"SamplesPerPixel tag value is changing, "
- "but TransferFunction was read with a different value. Cancelling it");
+ "but TransferFunction was read with a different value. Canceling it");
TIFFClrFieldBit(tif,FIELD_TRANSFERFUNCTION);
_TIFFfree(td->td_transferfunction[0]);
td->td_transferfunction[0] = NULL;
@@ -393,7 +394,7 @@ _TIFFVSetField(TIFF* tif, uint32 tag, va_list ap)
if (tif->tif_mode != O_RDONLY)
goto badvalue32;
TIFFWarningExt(tif->tif_clientdata, tif->tif_name,
- "Nonstandard tile width %d, convert file", v32);
+ "Nonstandard tile width %u, convert file", v32);
}
td->td_tilewidth = v32;
tif->tif_flags |= TIFF_ISTILED;
@@ -404,7 +405,7 @@ _TIFFVSetField(TIFF* tif, uint32 tag, va_list ap)
if (tif->tif_mode != O_RDONLY)
goto badvalue32;
TIFFWarningExt(tif->tif_clientdata, tif->tif_name,
- "Nonstandard tile length %d, convert file", v32);
+ "Nonstandard tile length %u, convert file", v32);
}
td->td_tilelength = v32;
tif->tif_flags |= TIFF_ISTILED;
@@ -559,6 +560,10 @@ _TIFFVSetField(TIFF* tif, uint32 tag, va_list ap)
* Set custom value ... save a copy of the custom tag value.
*/
tv_size = _TIFFDataSize(fip->field_type);
+ /*--: Rational2Double: For Rationals evaluate "set_field_type" to determine internal storage size. */
+ if (fip->field_type == TIFF_RATIONAL || fip->field_type == TIFF_SRATIONAL) {
+ tv_size = _TIFFSetGetFieldSize(fip->set_field_type);
+ }
if (tv_size == 0) {
status = 0;
TIFFErrorExt(tif->tif_clientdata, module,
@@ -638,6 +643,7 @@ _TIFFVSetField(TIFF* tif, uint32 tag, va_list ap)
|| fip->field_writecount == TIFF_VARIABLE2
|| fip->field_writecount == TIFF_SPP
|| tv->count > 1) {
+ /*--: Rational2Double: For Rationals tv_size is set above to 4 or 8 according to fip->set_field_type! */
_TIFFmemcpy(tv->value, va_arg(ap, void *),
tv->count * tv_size);
} else {
@@ -698,6 +704,22 @@ _TIFFVSetField(TIFF* tif, uint32 tag, va_list ap)
break;
case TIFF_RATIONAL:
case TIFF_SRATIONAL:
+ /*-- Rational2Double: For Rationals tv_size is set above to 4 or 8 according to fip->set_field_type! */
+ {
+ if (tv_size == 8) {
+ double v2 = va_arg(ap, double);
+ _TIFFmemcpy(val, &v2, tv_size);
+ } else {
+ /*-- default should be tv_size == 4 */
+ float v3 = (float)va_arg(ap, double);
+ _TIFFmemcpy(val, &v3, tv_size);
+ /*-- ToDo: After Testing, this should be removed and tv_size==4 should be set as default. */
+ if (tv_size != 4) {
+ TIFFErrorExt(0,"TIFFLib: _TIFFVSetField()", "Rational2Double: .set_field_type in not 4 but %d", tv_size);
+ }
+ }
+ }
+ break;
case TIFF_FLOAT:
{
float v2 = _TIFFClampDoubleToFloat(va_arg(ap, double));
@@ -1011,19 +1033,19 @@ _TIFFVGetField(TIFF* tif, uint32 tag, va_list ap)
*va_arg(ap, uint16*) = td->td_halftonehints[1];
break;
case TIFFTAG_COLORMAP:
- *va_arg(ap, uint16**) = td->td_colormap[0];
- *va_arg(ap, uint16**) = td->td_colormap[1];
- *va_arg(ap, uint16**) = td->td_colormap[2];
+ *va_arg(ap, const uint16**) = td->td_colormap[0];
+ *va_arg(ap, const uint16**) = td->td_colormap[1];
+ *va_arg(ap, const uint16**) = td->td_colormap[2];
break;
case TIFFTAG_STRIPOFFSETS:
case TIFFTAG_TILEOFFSETS:
_TIFFFillStriles( tif );
- *va_arg(ap, uint64**) = td->td_stripoffset_p;
+ *va_arg(ap, const uint64**) = td->td_stripoffset_p;
break;
case TIFFTAG_STRIPBYTECOUNTS:
case TIFFTAG_TILEBYTECOUNTS:
_TIFFFillStriles( tif );
- *va_arg(ap, uint64**) = td->td_stripbytecount_p;
+ *va_arg(ap, const uint64**) = td->td_stripbytecount_p;
break;
case TIFFTAG_MATTEING:
*va_arg(ap, uint16*) =
@@ -1032,7 +1054,7 @@ _TIFFVGetField(TIFF* tif, uint32 tag, va_list ap)
break;
case TIFFTAG_EXTRASAMPLES:
*va_arg(ap, uint16*) = td->td_extrasamples;
- *va_arg(ap, uint16**) = td->td_sampleinfo;
+ *va_arg(ap, const uint16**) = td->td_sampleinfo;
break;
case TIFFTAG_TILEWIDTH:
*va_arg(ap, uint32*) = td->td_tilewidth;
@@ -1067,7 +1089,7 @@ _TIFFVGetField(TIFF* tif, uint32 tag, va_list ap)
break;
case TIFFTAG_SUBIFD:
*va_arg(ap, uint16*) = td->td_nsubifd;
- *va_arg(ap, uint64**) = td->td_subifd;
+ *va_arg(ap, const uint64**) = td->td_subifd;
break;
case TIFFTAG_YCBCRPOSITIONING:
*va_arg(ap, uint16*) = td->td_ycbcrpositioning;
@@ -1077,20 +1099,20 @@ _TIFFVGetField(TIFF* tif, uint32 tag, va_list ap)
*va_arg(ap, uint16*) = td->td_ycbcrsubsampling[1];
break;
case TIFFTAG_TRANSFERFUNCTION:
- *va_arg(ap, uint16**) = td->td_transferfunction[0];
+ *va_arg(ap, const uint16**) = td->td_transferfunction[0];
if (td->td_samplesperpixel - td->td_extrasamples > 1) {
- *va_arg(ap, uint16**) = td->td_transferfunction[1];
- *va_arg(ap, uint16**) = td->td_transferfunction[2];
+ *va_arg(ap, const uint16**) = td->td_transferfunction[1];
+ *va_arg(ap, const uint16**) = td->td_transferfunction[2];
} else {
- *va_arg(ap, uint16**) = NULL;
- *va_arg(ap, uint16**) = NULL;
+ *va_arg(ap, const uint16**) = NULL;
+ *va_arg(ap, const uint16**) = NULL;
}
break;
case TIFFTAG_REFERENCEBLACKWHITE:
- *va_arg(ap, float**) = td->td_refblackwhite;
+ *va_arg(ap, const float**) = td->td_refblackwhite;
break;
case TIFFTAG_INKNAMES:
- *va_arg(ap, char**) = td->td_inknames;
+ *va_arg(ap, const char**) = td->td_inknames;
break;
default:
{
@@ -1132,7 +1154,7 @@ _TIFFVGetField(TIFF* tif, uint32 tag, va_list ap)
*va_arg(ap, uint32*) = (uint32)tv->count;
else /* Assume TIFF_VARIABLE */
*va_arg(ap, uint16*) = (uint16)tv->count;
- *va_arg(ap, void **) = tv->value;
+ *va_arg(ap, const void **) = tv->value;
ret_val = 1;
} else if (fip->field_tag == TIFFTAG_DOTRANGE
&& strcmp(fip->field_name,"DotRange") == 0) {
@@ -1200,6 +1222,23 @@ _TIFFVGetField(TIFF* tif, uint32 tag, va_list ap)
break;
case TIFF_RATIONAL:
case TIFF_SRATIONAL:
+ {
+ /*-- Rational2Double: For Rationals evaluate "set_field_type" to determine internal storage size and return value size. */
+ int tv_size = _TIFFSetGetFieldSize(fip->set_field_type);
+ if (tv_size == 8) {
+ *va_arg(ap, double*) = *(double *)val;
+ ret_val = 1;
+ } else {
+ /*-- default should be tv_size == 4 */
+ *va_arg(ap, float*) = *(float *)val;
+ ret_val = 1;
+ /*-- ToDo: After Testing, this should be removed and tv_size==4 should be set as default. */
+ if (tv_size != 4) {
+ TIFFErrorExt(0,"TIFFLib: _TIFFVGetField()", "Rational2Double: .set_field_type in not 4 but %d", tv_size);
+ }
+ }
+ }
+ break;
case TIFF_FLOAT:
*va_arg(ap, float*) =
*(float *)val;
@@ -1365,6 +1404,17 @@ TIFFCreateEXIFDirectory(TIFF* tif)
}
/*
+ * Creates the EXIF GPS custom directory
+ */
+int
+TIFFCreateGPSDirectory(TIFF* tif)
+{
+ const TIFFFieldArray* gpsFieldArray;
+ gpsFieldArray = _TIFFGetGpsFields();
+ return TIFFCreateCustomDirectory(tif, gpsFieldArray);
+}
+
+/*
* Setup a default directory structure.
*/
int
diff --git a/tiff/libtiff/tif_dir.h b/tiff/libtiff/tif_dir.h
index e7f06673..f608dd71 100644
--- a/tiff/libtiff/tif_dir.h
+++ b/tiff/libtiff/tif_dir.h
@@ -261,6 +261,7 @@ extern "C" {
extern const TIFFFieldArray* _TIFFGetFields(void);
extern const TIFFFieldArray* _TIFFGetExifFields(void);
+extern const TIFFFieldArray* _TIFFGetGpsFields(void);
extern void _TIFFSetupFields(TIFF* tif, const TIFFFieldArray* infoarray);
extern void _TIFFPrintFieldInfo(TIFF*, FILE*);
@@ -269,6 +270,7 @@ extern int _TIFFFillStriles(TIFF*);
typedef enum {
tfiatImage,
tfiatExif,
+ tfiatGps, /* EXIF-GPS fields array type */
tfiatOther
} TIFFFieldArrayType;
diff --git a/tiff/libtiff/tif_dirinfo.c b/tiff/libtiff/tif_dirinfo.c
index e1f6b23e..7217042c 100644
--- a/tiff/libtiff/tif_dirinfo.c
+++ b/tiff/libtiff/tif_dirinfo.c
@@ -47,9 +47,19 @@
#endif
static const TIFFFieldArray tiffFieldArray;
static const TIFFFieldArray exifFieldArray;
+static const TIFFFieldArray gpsFieldArray;
#ifdef _MSC_VER
#pragma warning( pop )
#endif
+/*--: Rational2Double: --
+ * The Rational2Double upgraded libtiff functionality allows the definition and achievement of true double-precision accuracy
+ * for TIFF tags of RATIONAL type and field_bit=FIELD_CUSTOM using the set_field_type = TIFF_SETGET_DOUBLE.
+ * Unfortunately, that changes the old implemented interface for TIFFGetField().
+ * In order to keep the old TIFFGetField() interface behavior those tags have to be redefined with set_field_type = TIFF_SETGET_FLOAT!
+ *
+ * Rational custom arrays are already defined as _Cxx_FLOAT, thus can stay.
+ *
+ */
static const TIFFField
tiffFields[] = {
@@ -75,12 +85,12 @@ tiffFields[] = {
{ TIFFTAG_STRIPBYTECOUNTS, -1, -1, TIFF_LONG8, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_STRIPBYTECOUNTS, 0, 0, "StripByteCounts", NULL },
{ TIFFTAG_MINSAMPLEVALUE, -2, -1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_MINSAMPLEVALUE, 1, 0, "MinSampleValue", NULL },
{ TIFFTAG_MAXSAMPLEVALUE, -2, -1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_MAXSAMPLEVALUE, 1, 0, "MaxSampleValue", NULL },
- { TIFFTAG_XRESOLUTION, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_RESOLUTION, 1, 0, "XResolution", NULL },
- { TIFFTAG_YRESOLUTION, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_RESOLUTION, 1, 0, "YResolution", NULL },
+ { TIFFTAG_XRESOLUTION, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_RESOLUTION, 1, 0, "XResolution", NULL },
+ { TIFFTAG_YRESOLUTION, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_RESOLUTION, 1, 0, "YResolution", NULL },
{ TIFFTAG_PLANARCONFIG, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_PLANARCONFIG, 0, 0, "PlanarConfiguration", NULL },
{ TIFFTAG_PAGENAME, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "PageName", NULL },
- { TIFFTAG_XPOSITION, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_POSITION, 1, 0, "XPosition", NULL },
- { TIFFTAG_YPOSITION, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_POSITION, 1, 0, "YPosition", NULL },
+ { TIFFTAG_XPOSITION, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_POSITION, 1, 0, "XPosition", NULL },
+ { TIFFTAG_YPOSITION, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_POSITION, 1, 0, "YPosition", NULL },
{ TIFFTAG_FREEOFFSETS, -1, -1, TIFF_LONG8, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_IGNORE, 0, 0, "FreeOffsets", NULL },
{ TIFFTAG_FREEBYTECOUNTS, -1, -1, TIFF_LONG8, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_IGNORE, 0, 0, "FreeByteCounts", NULL },
{ TIFFTAG_GRAYRESPONSEUNIT, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_IGNORE, 1, 0, "GrayResponseUnit", NULL },
@@ -135,14 +145,18 @@ tiffFields[] = {
{ TIFFTAG_PIXAR_MATRIX_WORLDTOSCREEN, 16, 16, TIFF_FLOAT, 0, TIFF_SETGET_C0_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "MatrixWorldToScreen", NULL },
{ TIFFTAG_PIXAR_MATRIX_WORLDTOCAMERA, 16, 16, TIFF_FLOAT, 0, TIFF_SETGET_C0_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "MatrixWorldToCamera", NULL },
{ TIFFTAG_CFAREPEATPATTERNDIM, 2, 2, TIFF_SHORT, 0, TIFF_SETGET_C0_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "CFARepeatPatternDim", NULL },
- { TIFFTAG_CFAPATTERN, 4, 4, TIFF_BYTE, 0, TIFF_SETGET_C0_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "CFAPattern" , NULL},
+ { TIFFTAG_CFAPATTERN, -1, -1, TIFF_BYTE, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "CFAPattern" , NULL},
{ TIFFTAG_COPYRIGHT, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Copyright", NULL },
/* end Pixar tags */
- { TIFFTAG_RICHTIFFIPTC, -3, -3, TIFF_LONG, 0, TIFF_SETGET_C32_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "RichTIFFIPTC", NULL },
+ { TIFFTAG_RICHTIFFIPTC, -3, -3, TIFF_UNDEFINED, 0, TIFF_SETGET_C32_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "RichTIFFIPTC", NULL },
{ TIFFTAG_PHOTOSHOP, -3, -3, TIFF_BYTE, 0, TIFF_SETGET_C32_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "Photoshop", NULL },
- { TIFFTAG_EXIFIFD, 1, 1, TIFF_IFD8, 0, TIFF_SETGET_IFD8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "EXIFIFDOffset", (TIFFFieldArray*) &exifFieldArray },
+ /*--: EXIFIFD and GPSIFD specified as TIFF_LONG by Aware-Systems and not TIFF_IFD8 as in original LibTiff.
+ * However, for IFD-like tags, libtiff uses the data type TIFF_IFD8 in tiffFields[]-tag definition combined with
+ * a special handling procedure in order to write either a 32-bit value and the TIFF_IFD type-id into ClassicTIFF files
+ * or a 64-bit value and the TIFF_IFD8 type-id into BigTIFF files. */
+ { TIFFTAG_EXIFIFD, 1, 1, TIFF_IFD8, 0, TIFF_SETGET_IFD8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "EXIFIFDOffset", (TIFFFieldArray*) &exifFieldArray },
{ TIFFTAG_ICCPROFILE, -3, -3, TIFF_UNDEFINED, 0, TIFF_SETGET_C32_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "ICC Profile", NULL },
- { TIFFTAG_GPSIFD, 1, 1, TIFF_IFD8, 0, TIFF_SETGET_IFD8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "GPSIFDOffset", NULL },
+ { TIFFTAG_GPSIFD, 1, 1, TIFF_IFD8, 0, TIFF_SETGET_IFD8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "GPSIFDOffset", (TIFFFieldArray*) &gpsFieldArray },
{ TIFFTAG_FAXRECVPARAMS, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UINT32, FIELD_CUSTOM, TRUE, FALSE, "FaxRecvParams", NULL },
{ TIFFTAG_FAXSUBADDRESS, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_ASCII, FIELD_CUSTOM, TRUE, FALSE, "FaxSubAddress", NULL },
{ TIFFTAG_FAXRECVTIME, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UINT32, FIELD_CUSTOM, TRUE, FALSE, "FaxRecvTime", NULL },
@@ -163,7 +177,7 @@ tiffFields[] = {
{ TIFFTAG_BLACKLEVELDELTAV, -1, -1, TIFF_SRATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "BlackLevelDeltaV", NULL },
{ TIFFTAG_WHITELEVEL, -1, -1, TIFF_LONG, 0, TIFF_SETGET_C16_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "WhiteLevel", NULL },
{ TIFFTAG_DEFAULTSCALE, 2, 2, TIFF_RATIONAL, 0, TIFF_SETGET_C0_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "DefaultScale", NULL },
- { TIFFTAG_BESTQUALITYSCALE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "BestQualityScale", NULL },
+ { TIFFTAG_BESTQUALITYSCALE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "BestQualityScale", NULL },
{ TIFFTAG_DEFAULTCROPORIGIN, 2, 2, TIFF_RATIONAL, 0, TIFF_SETGET_C0_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "DefaultCropOrigin", NULL },
{ TIFFTAG_DEFAULTCROPSIZE, 2, 2, TIFF_RATIONAL, 0, TIFF_SETGET_C0_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "DefaultCropSize", NULL },
{ TIFFTAG_COLORMATRIX1, -1, -1, TIFF_SRATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "ColorMatrix1", NULL },
@@ -175,16 +189,16 @@ tiffFields[] = {
{ TIFFTAG_ANALOGBALANCE, -1, -1, TIFF_RATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "AnalogBalance", NULL },
{ TIFFTAG_ASSHOTNEUTRAL, -1, -1, TIFF_RATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "AsShotNeutral", NULL },
{ TIFFTAG_ASSHOTWHITEXY, 2, 2, TIFF_RATIONAL, 0, TIFF_SETGET_C0_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "AsShotWhiteXY", NULL },
- { TIFFTAG_BASELINEEXPOSURE, 1, 1, TIFF_SRATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "BaselineExposure", NULL },
- { TIFFTAG_BASELINENOISE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "BaselineNoise", NULL },
- { TIFFTAG_BASELINESHARPNESS, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "BaselineSharpness", NULL },
+ { TIFFTAG_BASELINEEXPOSURE, 1, 1, TIFF_SRATIONAL, 0, TIFF_SETGET_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "BaselineExposure", NULL },
+ { TIFFTAG_BASELINENOISE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "BaselineNoise", NULL },
+ { TIFFTAG_BASELINESHARPNESS, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "BaselineSharpness", NULL },
{ TIFFTAG_BAYERGREENSPLIT, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "BayerGreenSplit", NULL },
- { TIFFTAG_LINEARRESPONSELIMIT, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "LinearResponseLimit", NULL },
+ { TIFFTAG_LINEARRESPONSELIMIT, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "LinearResponseLimit", NULL },
{ TIFFTAG_CAMERASERIALNUMBER, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "CameraSerialNumber", NULL },
{ TIFFTAG_LENSINFO, 4, 4, TIFF_RATIONAL, 0, TIFF_SETGET_C0_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "LensInfo", NULL },
- { TIFFTAG_CHROMABLURRADIUS, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "ChromaBlurRadius", NULL },
- { TIFFTAG_ANTIALIASSTRENGTH, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "AntiAliasStrength", NULL },
- { TIFFTAG_SHADOWSCALE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "ShadowScale", NULL },
+ { TIFFTAG_CHROMABLURRADIUS, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "ChromaBlurRadius", NULL },
+ { TIFFTAG_ANTIALIASSTRENGTH, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "AntiAliasStrength", NULL },
+ { TIFFTAG_SHADOWSCALE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "ShadowScale", NULL },
{ TIFFTAG_DNGPRIVATEDATA, -1, -1, TIFF_BYTE, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "DNGPrivateData", NULL },
{ TIFFTAG_MAKERNOTESAFETY, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "MakerNoteSafety", NULL },
{ TIFFTAG_CALIBRATIONILLUMINANT1, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "CalibrationIlluminant1", NULL },
@@ -217,47 +231,68 @@ tiffFields[] = {
/* begin pseudo tags */
};
+/*
+ * EXIF tags (Version 2.31, July 2016 plus version 2.32 May 2019)
+ */
static const TIFFField
exifFields[] = {
- { EXIFTAG_EXPOSURETIME, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ExposureTime", NULL },
- { EXIFTAG_FNUMBER, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FNumber", NULL },
+ { EXIFTAG_EXPOSURETIME, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ExposureTime", NULL },
+ { EXIFTAG_FNUMBER, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FNumber", NULL },
{ EXIFTAG_EXPOSUREPROGRAM, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ExposureProgram", NULL },
{ EXIFTAG_SPECTRALSENSITIVITY, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SpectralSensitivity", NULL },
{ EXIFTAG_ISOSPEEDRATINGS, -1, -1, TIFF_SHORT, 0, TIFF_SETGET_C16_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "ISOSpeedRatings", NULL },
{ EXIFTAG_OECF, -1, -1, TIFF_UNDEFINED, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "OptoelectricConversionFactor", NULL },
+ { EXIFTAG_SENSITIVITYTYPE, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SensitivityType", NULL },
+ { EXIFTAG_STANDARDOUTPUTSENSITIVITY, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "StandardOutputSensitivity", NULL },
+ { EXIFTAG_RECOMMENDEDEXPOSUREINDEX, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "RecommendedExposureIndex", NULL },
+ { EXIFTAG_ISOSPEED, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ISOSpeed", NULL },
+ { EXIFTAG_ISOSPEEDLATITUDEYYY, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ISOSpeedLatitudeyyy", NULL },
+ { EXIFTAG_ISOSPEEDLATITUDEZZZ, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ISOSpeedLatitudezzz", NULL },
{ EXIFTAG_EXIFVERSION, 4, 4, TIFF_UNDEFINED, 0, TIFF_SETGET_C0_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ExifVersion", NULL },
{ EXIFTAG_DATETIMEORIGINAL, 20, 20, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "DateTimeOriginal", NULL },
{ EXIFTAG_DATETIMEDIGITIZED, 20, 20, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "DateTimeDigitized", NULL },
+ { EXIFTAG_OFFSETTIME, 7, 7, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "OffsetTime", NULL },
+ { EXIFTAG_OFFSETTIMEORIGINAL, 7, 7, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "OffsetTimeOriginal", NULL },
+ { EXIFTAG_OFFSETTIMEDIGITIZED, 7, 7, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "OffsetTimeDigitized", NULL },
{ EXIFTAG_COMPONENTSCONFIGURATION, 4, 4, TIFF_UNDEFINED, 0, TIFF_SETGET_C0_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ComponentsConfiguration", NULL },
- { EXIFTAG_COMPRESSEDBITSPERPIXEL, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "CompressedBitsPerPixel", NULL },
- { EXIFTAG_SHUTTERSPEEDVALUE, 1, 1, TIFF_SRATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ShutterSpeedValue", NULL },
- { EXIFTAG_APERTUREVALUE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ApertureValue", NULL },
- { EXIFTAG_BRIGHTNESSVALUE, 1, 1, TIFF_SRATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "BrightnessValue", NULL },
- { EXIFTAG_EXPOSUREBIASVALUE, 1, 1, TIFF_SRATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ExposureBiasValue", NULL },
- { EXIFTAG_MAXAPERTUREVALUE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "MaxApertureValue", NULL },
- { EXIFTAG_SUBJECTDISTANCE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SubjectDistance", NULL },
+ { EXIFTAG_COMPRESSEDBITSPERPIXEL, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "CompressedBitsPerPixel", NULL },
+ { EXIFTAG_SHUTTERSPEEDVALUE, 1, 1, TIFF_SRATIONAL, 0, TIFF_SETGET_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ShutterSpeedValue", NULL },
+ { EXIFTAG_APERTUREVALUE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ApertureValue", NULL },
+ { EXIFTAG_BRIGHTNESSVALUE, 1, 1, TIFF_SRATIONAL, 0, TIFF_SETGET_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "BrightnessValue", NULL },
+ { EXIFTAG_EXPOSUREBIASVALUE, 1, 1, TIFF_SRATIONAL, 0, TIFF_SETGET_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ExposureBiasValue", NULL },
+ { EXIFTAG_MAXAPERTUREVALUE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "MaxApertureValue", NULL },
+ /*--: EXIFTAG_SUBJECTDISTANCE: LibTiff returns value of "-1" if numerator equals 4294967295 (0xFFFFFFFF) to indicate infinite distance!
+ * However, there are two other EXIF tags where numerator indicates a special value and six other cases where the denominator indicates special values,
+ * which are not treated within LibTiff!! */
+ { EXIFTAG_SUBJECTDISTANCE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SubjectDistance", NULL },
{ EXIFTAG_METERINGMODE, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "MeteringMode", NULL },
{ EXIFTAG_LIGHTSOURCE, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "LightSource", NULL },
{ EXIFTAG_FLASH, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Flash", NULL },
- { EXIFTAG_FOCALLENGTH, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FocalLength", NULL },
+ { EXIFTAG_FOCALLENGTH, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FocalLength", NULL },
{ EXIFTAG_SUBJECTAREA, -1, -1, TIFF_SHORT, 0, TIFF_SETGET_C16_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "SubjectArea", NULL },
{ EXIFTAG_MAKERNOTE, -1, -1, TIFF_UNDEFINED, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "MakerNote", NULL },
{ EXIFTAG_USERCOMMENT, -1, -1, TIFF_UNDEFINED, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "UserComment", NULL },
{ EXIFTAG_SUBSECTIME, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SubSecTime", NULL },
{ EXIFTAG_SUBSECTIMEORIGINAL, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SubSecTimeOriginal", NULL },
{ EXIFTAG_SUBSECTIMEDIGITIZED, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SubSecTimeDigitized", NULL },
+ { EXIFTAG_TEMPERATURE, 1, 1, TIFF_SRATIONAL, 0, TIFF_SETGET_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Temperature", NULL },
+ { EXIFTAG_HUMIDITY, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Humidity", NULL },
+ { EXIFTAG_PRESSURE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Pressure", NULL },
+ { EXIFTAG_WATERDEPTH, 1, 1, TIFF_SRATIONAL, 0, TIFF_SETGET_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "WaterDepth", NULL },
+ { EXIFTAG_ACCELERATION, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Acceleration", NULL },
+ { EXIFTAG_CAMERAELEVATIONANGLE, 1, 1, TIFF_SRATIONAL, 0, TIFF_SETGET_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "CameraElevationAngle", NULL },
{ EXIFTAG_FLASHPIXVERSION, 4, 4, TIFF_UNDEFINED, 0, TIFF_SETGET_C0_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FlashpixVersion", NULL },
{ EXIFTAG_COLORSPACE, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ColorSpace", NULL },
{ EXIFTAG_PIXELXDIMENSION, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "PixelXDimension", NULL },
{ EXIFTAG_PIXELYDIMENSION, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "PixelYDimension", NULL },
{ EXIFTAG_RELATEDSOUNDFILE, 13, 13, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "RelatedSoundFile", NULL },
- { EXIFTAG_FLASHENERGY, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FlashEnergy", NULL },
+ { EXIFTAG_FLASHENERGY, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FlashEnergy", NULL },
{ EXIFTAG_SPATIALFREQUENCYRESPONSE, -1, -1, TIFF_UNDEFINED, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "SpatialFrequencyResponse", NULL },
- { EXIFTAG_FOCALPLANEXRESOLUTION, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FocalPlaneXResolution", NULL },
- { EXIFTAG_FOCALPLANEYRESOLUTION, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FocalPlaneYResolution", NULL },
+ { EXIFTAG_FOCALPLANEXRESOLUTION, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FocalPlaneXResolution", NULL },
+ { EXIFTAG_FOCALPLANEYRESOLUTION, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FocalPlaneYResolution", NULL },
{ EXIFTAG_FOCALPLANERESOLUTIONUNIT, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FocalPlaneResolutionUnit", NULL },
{ EXIFTAG_SUBJECTLOCATION, 2, 2, TIFF_SHORT, 0, TIFF_SETGET_C0_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SubjectLocation", NULL },
- { EXIFTAG_EXPOSUREINDEX, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ExposureIndex", NULL },
+ { EXIFTAG_EXPOSUREINDEX, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ExposureIndex", NULL },
{ EXIFTAG_SENSINGMETHOD, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SensingMethod", NULL },
{ EXIFTAG_FILESOURCE, 1, 1, TIFF_UNDEFINED, 0, TIFF_SETGET_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FileSource", NULL },
{ EXIFTAG_SCENETYPE, 1, 1, TIFF_UNDEFINED, 0, TIFF_SETGET_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SceneType", NULL },
@@ -265,22 +300,79 @@ exifFields[] = {
{ EXIFTAG_CUSTOMRENDERED, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "CustomRendered", NULL },
{ EXIFTAG_EXPOSUREMODE, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ExposureMode", NULL },
{ EXIFTAG_WHITEBALANCE, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "WhiteBalance", NULL },
- { EXIFTAG_DIGITALZOOMRATIO, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "DigitalZoomRatio", NULL },
+ { EXIFTAG_DIGITALZOOMRATIO, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "DigitalZoomRatio", NULL },
{ EXIFTAG_FOCALLENGTHIN35MMFILM, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FocalLengthIn35mmFilm", NULL },
{ EXIFTAG_SCENECAPTURETYPE, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SceneCaptureType", NULL },
- { EXIFTAG_GAINCONTROL, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "GainControl", NULL },
+ { EXIFTAG_GAINCONTROL, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "GainControl", NULL },
{ EXIFTAG_CONTRAST, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Contrast", NULL },
{ EXIFTAG_SATURATION, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Saturation", NULL },
{ EXIFTAG_SHARPNESS, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Sharpness", NULL },
{ EXIFTAG_DEVICESETTINGDESCRIPTION, -1, -1, TIFF_UNDEFINED, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "DeviceSettingDescription", NULL },
{ EXIFTAG_SUBJECTDISTANCERANGE, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SubjectDistanceRange", NULL },
- { EXIFTAG_IMAGEUNIQUEID, 33, 33, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ImageUniqueID", NULL }
+ { EXIFTAG_IMAGEUNIQUEID, 33, 33, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ImageUniqueID", NULL },
+ { EXIFTAG_CAMERAOWNERNAME, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "CameraOwnerName", NULL },
+ { EXIFTAG_BODYSERIALNUMBER, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "BodySerialNumber", NULL },
+ { EXIFTAG_LENSSPECIFICATION, 4, 4, TIFF_RATIONAL, 0, TIFF_SETGET_C0_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "LensSpecification", NULL },
+ { EXIFTAG_LENSMAKE, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "LensMake", NULL },
+ { EXIFTAG_LENSMODEL, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "LensModel", NULL },
+ { EXIFTAG_LENSSERIALNUMBER, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "LensSerialNumber", NULL },
+ { EXIFTAG_GAMMA, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Gamma", NULL },
+ { EXIFTAG_COMPOSITEIMAGE, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "CompositeImage", NULL },
+ { EXIFTAG_SOURCEIMAGENUMBEROFCOMPOSITEIMAGE, 2, 2, TIFF_SHORT, 0, TIFF_SETGET_C0_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SourceImageNumberOfCompositeImage", NULL },
+ { EXIFTAG_SOURCEEXPOSURETIMESOFCOMPOSITEIMAGE, -1, -1, TIFF_UNDEFINED, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "SourceExposureTimesOfCompositeImage", NULL }
+};
+/*
+ * EXIF-GPS tags (Version 2.31, July 2016; nothing changed for version 2.32 May 2019)
+ */
+
+static TIFFField
+gpsFields[] = {
+ /* For the GPS tag definitions in gpsFields[] the standard definition for Rationals is TIFF_SETGET_DOUBLE and TIFF_SETGET_C0_FLOAT.
+ *-- ATTENTION: After the upgrade with Rational2Double, the GPSTAG values can now be written and also read in double precision!
+ * In order to achieve double precision for GPS tags:
+ * Standard definitions for GPSTAG is kept to TIFF_SETGET_DOUBLE
+ * and TIFF_SETGET_C0_FLOAT is changed to TIFF_SETGET_C0_DOUBLE.
+ */
+ { GPSTAG_VERSIONID , 4, 4, TIFF_BYTE , 0, TIFF_SETGET_C0_UINT8 , TIFF_SETGET_UINT8 , FIELD_CUSTOM , 1, 0, "VersionID", NULL },
+ { GPSTAG_LATITUDEREF , 2, 2, TIFF_ASCII , 0, TIFF_SETGET_ASCII , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 0, "LatitudeRef", NULL },
+ { GPSTAG_LATITUDE , 3, 3, TIFF_RATIONAL , 0, TIFF_SETGET_C0_DOUBLE , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 0, "Latitude", NULL },
+ { GPSTAG_LONGITUDEREF , 2, 2, TIFF_ASCII , 0, TIFF_SETGET_ASCII , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 0, "LongitudeRef", NULL },
+ { GPSTAG_LONGITUDE , 3, 3, TIFF_RATIONAL , 0, TIFF_SETGET_C0_DOUBLE , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 0, "Longitude", NULL },
+ { GPSTAG_ALTITUDEREF , 1, 1, TIFF_BYTE , 0, TIFF_SETGET_UINT8 , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 0, "AltitudeRef", NULL },
+ { GPSTAG_ALTITUDE , 1, 1, TIFF_RATIONAL , 0, TIFF_SETGET_DOUBLE , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 0, "Altitude", NULL },
+ { GPSTAG_TIMESTAMP , 3, 3, TIFF_RATIONAL , 0, TIFF_SETGET_C0_DOUBLE , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 0, "TimeStamp", NULL },
+ { GPSTAG_SATELLITES , -1, -1, TIFF_ASCII , 0, TIFF_SETGET_ASCII , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 0, "Satellites", NULL },
+ { GPSTAG_STATUS , 2, 2, TIFF_ASCII , 0, TIFF_SETGET_ASCII , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 0, "Status", NULL },
+ { GPSTAG_MEASUREMODE , 2, 2, TIFF_ASCII , 0, TIFF_SETGET_ASCII , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 0, "MeasureMode", NULL },
+ { GPSTAG_DOP , 1, 1, TIFF_RATIONAL , 0, TIFF_SETGET_DOUBLE , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 0, "DOP", NULL },
+ { GPSTAG_SPEEDREF , 2, 2, TIFF_ASCII , 0, TIFF_SETGET_ASCII , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 0, "SpeedRef", NULL },
+ { GPSTAG_SPEED , 1, 1, TIFF_RATIONAL , 0, TIFF_SETGET_DOUBLE , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 0, "Speed", NULL },
+ { GPSTAG_TRACKREF , 2, 2, TIFF_ASCII , 0, TIFF_SETGET_ASCII , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 0, "TrackRef", NULL },
+ { GPSTAG_TRACK , 1, 1, TIFF_RATIONAL , 0, TIFF_SETGET_DOUBLE , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 0, "Track", NULL },
+ { GPSTAG_IMGDIRECTIONREF , 2, 2, TIFF_ASCII , 0, TIFF_SETGET_ASCII , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 0, "ImgDirectionRef", NULL },
+ { GPSTAG_IMGDIRECTION , 1, 1, TIFF_RATIONAL , 0, TIFF_SETGET_DOUBLE , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 0, "ImgDirection", NULL },
+ { GPSTAG_MAPDATUM , -1, -1, TIFF_ASCII , 0, TIFF_SETGET_ASCII , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 0, "MapDatum", NULL },
+ { GPSTAG_DESTLATITUDEREF , 2, 2, TIFF_ASCII , 0, TIFF_SETGET_ASCII , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 0, "DestLatitudeRef", NULL },
+ { GPSTAG_DESTLATITUDE , 3, 3, TIFF_RATIONAL , 0, TIFF_SETGET_C0_DOUBLE , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 0, "DestLatitude", NULL },
+ { GPSTAG_DESTLONGITUDEREF , 2, 2, TIFF_ASCII , 0, TIFF_SETGET_ASCII , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 0, "DestLongitudeRef", NULL },
+ { GPSTAG_DESTLONGITUDE , 3, 3, TIFF_RATIONAL , 0, TIFF_SETGET_C0_DOUBLE , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 0, "DestLongitude", NULL },
+ { GPSTAG_DESTBEARINGREF , 2, 2, TIFF_ASCII , 0, TIFF_SETGET_ASCII , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 0, "DestBearingRef", NULL },
+ { GPSTAG_DESTBEARING , 1, 1, TIFF_RATIONAL , 0, TIFF_SETGET_DOUBLE , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 0, "DestBearing", NULL },
+ { GPSTAG_DESTDISTANCEREF , 2, 2, TIFF_ASCII , 0, TIFF_SETGET_ASCII , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 0, "DestDistanceRef", NULL },
+ { GPSTAG_DESTDISTANCE , 1, 1, TIFF_RATIONAL , 0, TIFF_SETGET_DOUBLE , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 0, "DestDistance", NULL },
+ { GPSTAG_PROCESSINGMETHOD , -1, -1, TIFF_UNDEFINED , 0, TIFF_SETGET_C16_UINT8 , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 1, "ProcessingMethod", NULL },
+ { GPSTAG_AREAINFORMATION , -1, -1, TIFF_UNDEFINED , 0, TIFF_SETGET_C16_UINT8 , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 1, "AreaInformation", NULL },
+ { GPSTAG_DATESTAMP , 11, 11, TIFF_ASCII , 0, TIFF_SETGET_ASCII , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 0, "DateStamp", NULL },
+ { GPSTAG_DIFFERENTIAL , 1, 1, TIFF_SHORT , 0, TIFF_SETGET_UINT16 , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 0, "Differential", NULL },
+ { GPSTAG_GPSHPOSITIONINGERROR , 1, 1, TIFF_RATIONAL , 0, TIFF_SETGET_DOUBLE , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 0, "HorizontalPositioningError", NULL }
};
static const TIFFFieldArray
tiffFieldArray = { tfiatImage, 0, TIFFArrayCount(tiffFields), (TIFFField*) tiffFields };
static const TIFFFieldArray
exifFieldArray = { tfiatExif, 0, TIFFArrayCount(exifFields), (TIFFField*) exifFields };
+static const TIFFFieldArray
+gpsFieldArray = { tfiatGps, 0, TIFFArrayCount(gpsFields), (TIFFField*) gpsFields };
/*
* We have our own local lfind() equivalent to avoid subtle differences
@@ -313,6 +405,12 @@ _TIFFGetExifFields(void)
return(&exifFieldArray);
}
+const TIFFFieldArray*
+_TIFFGetGpsFields(void)
+{
+ return(&gpsFieldArray);
+}
+
void
_TIFFSetupFields(TIFF* tif, const TIFFFieldArray* fieldarray)
{
@@ -502,6 +600,82 @@ _TIFFDataSize(TIFFDataType type)
}
}
+/*
+ * Rational2Double:
+ * Return size of TIFFSetGetFieldType in bytes.
+ *
+ * XXX: TIFF_RATIONAL values for FIELD_CUSTOM are stored internally as 4-byte float.
+ * However, some of them should be stored internally as 8-byte double.
+ * This is now managed by the SetGetField of the tag-definition!
+ */
+int
+_TIFFSetGetFieldSize(TIFFSetGetFieldType setgettype)
+{
+ switch (setgettype)
+ {
+ case TIFF_SETGET_UNDEFINED:
+ case TIFF_SETGET_ASCII:
+ case TIFF_SETGET_C0_ASCII:
+ case TIFF_SETGET_C16_ASCII:
+ case TIFF_SETGET_C32_ASCII:
+ case TIFF_SETGET_OTHER:
+ return 0;
+ case TIFF_SETGET_UINT8:
+ case TIFF_SETGET_SINT8:
+ case TIFF_SETGET_C0_UINT8:
+ case TIFF_SETGET_C0_SINT8:
+ case TIFF_SETGET_C16_UINT8:
+ case TIFF_SETGET_C16_SINT8:
+ case TIFF_SETGET_C32_UINT8:
+ case TIFF_SETGET_C32_SINT8:
+ return 1;
+ case TIFF_SETGET_UINT16:
+ case TIFF_SETGET_SINT16:
+ case TIFF_SETGET_C0_UINT16:
+ case TIFF_SETGET_C0_SINT16:
+ case TIFF_SETGET_C16_UINT16:
+ case TIFF_SETGET_C16_SINT16:
+ case TIFF_SETGET_C32_UINT16:
+ case TIFF_SETGET_C32_SINT16:
+ return 2;
+ case TIFF_SETGET_INT:
+ case TIFF_SETGET_UINT32:
+ case TIFF_SETGET_SINT32:
+ case TIFF_SETGET_FLOAT:
+ case TIFF_SETGET_UINT16_PAIR:
+ case TIFF_SETGET_C0_UINT32:
+ case TIFF_SETGET_C0_SINT32:
+ case TIFF_SETGET_C0_FLOAT:
+ case TIFF_SETGET_C16_UINT32:
+ case TIFF_SETGET_C16_SINT32:
+ case TIFF_SETGET_C16_FLOAT:
+ case TIFF_SETGET_C32_UINT32:
+ case TIFF_SETGET_C32_SINT32:
+ case TIFF_SETGET_C32_FLOAT:
+ return 4;
+ case TIFF_SETGET_UINT64:
+ case TIFF_SETGET_SINT64:
+ case TIFF_SETGET_DOUBLE:
+ case TIFF_SETGET_IFD8:
+ case TIFF_SETGET_C0_UINT64:
+ case TIFF_SETGET_C0_SINT64:
+ case TIFF_SETGET_C0_DOUBLE:
+ case TIFF_SETGET_C0_IFD8:
+ case TIFF_SETGET_C16_UINT64:
+ case TIFF_SETGET_C16_SINT64:
+ case TIFF_SETGET_C16_DOUBLE:
+ case TIFF_SETGET_C16_IFD8:
+ case TIFF_SETGET_C32_UINT64:
+ case TIFF_SETGET_C32_SINT64:
+ case TIFF_SETGET_C32_DOUBLE:
+ case TIFF_SETGET_C32_IFD8:
+ return 8;
+ default:
+ return 0;
+ }
+} /*-- _TIFFSetGetFieldSize --- */
+
+
const TIFFField*
TIFFFindField(TIFF* tif, uint32 tag, TIFFDataType dt)
{
@@ -1062,10 +1236,6 @@ _TIFFCheckFieldIsValidForCodec(TIFF *tif, ttag_t tag)
if (tag == TIFFTAG_LERC_PARAMETERS)
return 1;
break;
- case COMPRESSION_WEBP:
- if (tag == TIFFTAG_PREDICTOR)
- return 1;
- break;
}
return 0;
}
diff --git a/tiff/libtiff/tif_dirread.c b/tiff/libtiff/tif_dirread.c
index 6f909413..ba127ca9 100644
--- a/tiff/libtiff/tif_dirread.c
+++ b/tiff/libtiff/tif_dirread.c
@@ -639,7 +639,7 @@ static enum TIFFReadDirEntryErr TIFFReadDirEntryFloat(TIFF* tif, TIFFDirEntry* d
err=TIFFReadDirEntryCheckedDouble(tif,direntry,&m);
if (err!=TIFFReadDirEntryErrOk)
return(err);
- if ((m > FLT_MAX) || (m < FLT_MIN))
+ if ((m > FLT_MAX) || (m < -FLT_MAX))
return(TIFFReadDirEntryErrRange);
*value=(float)m;
return(TIFFReadDirEntryErrOk);
@@ -838,6 +838,7 @@ static enum TIFFReadDirEntryErr TIFFReadDirEntryArrayWithLimit(
uint32 datasize;
void* data;
uint64 target_count64;
+ int original_datasize_clamped;
typesize=TIFFDataWidth(direntry->tdir_type);
target_count64 = (direntry->tdir_count > maxcount) ?
@@ -850,6 +851,12 @@ static enum TIFFReadDirEntryErr TIFFReadDirEntryArrayWithLimit(
}
(void) desttypesize;
+ /* We just want to know if the original tag size is more than 4 bytes
+ * (classic TIFF) or 8 bytes (BigTIFF)
+ */
+ original_datasize_clamped =
+ ((direntry->tdir_count > 10) ? 10 : (int)direntry->tdir_count) * typesize;
+
/*
* As a sanity check, make sure we have no more than a 2GB tag array
* in either the current data type or the dest data type. This also
@@ -864,7 +871,7 @@ static enum TIFFReadDirEntryErr TIFFReadDirEntryArrayWithLimit(
datasize=(*count)*typesize;
assert((tmsize_t)datasize>0);
- if( isMapped(tif) && datasize > (uint32)tif->tif_size )
+ if( isMapped(tif) && datasize > (uint64)tif->tif_size )
return TIFFReadDirEntryErrIo;
if( !isMapped(tif) &&
@@ -881,7 +888,7 @@ static enum TIFFReadDirEntryErr TIFFReadDirEntryArrayWithLimit(
}
if (!(tif->tif_flags&TIFF_BIGTIFF))
{
- if (datasize<=4)
+ if (original_datasize_clamped<=4)
_TIFFmemcpy(data,&direntry->tdir_offset,datasize);
else
{
@@ -902,7 +909,7 @@ static enum TIFFReadDirEntryErr TIFFReadDirEntryArrayWithLimit(
}
else
{
- if (datasize<=8)
+ if (original_datasize_clamped<=8)
_TIFFmemcpy(data,&direntry->tdir_offset,datasize);
else
{
@@ -3400,7 +3407,7 @@ TIFFReadDirEntryData(TIFF* tif, uint64 offset, tmsize_t size, void* dest)
return TIFFReadDirEntryErrIo;
}
mb=ma+size;
- if (mb > (size_t)tif->tif_size)
+ if (mb > (uint64)tif->tif_size)
return(TIFFReadDirEntryErrIo);
_TIFFmemcpy(dest,tif->tif_base+ma,size);
}
@@ -3902,11 +3909,51 @@ TIFFReadDirectory(TIFF* tif)
break;
case TIFFTAG_STRIPOFFSETS:
case TIFFTAG_TILEOFFSETS:
+ switch( dp->tdir_type )
+ {
+ case TIFF_SHORT:
+ case TIFF_LONG:
+ case TIFF_LONG8:
+ break;
+ default:
+ /* Warn except if directory typically created with TIFFDeferStrileArrayWriting() */
+ if( !(tif->tif_mode == O_RDWR &&
+ dp->tdir_count == 0 &&
+ dp->tdir_type == 0 &&
+ dp->tdir_offset.toff_long8 == 0) )
+ {
+ fip = TIFFFieldWithTag(tif,dp->tdir_tag);
+ TIFFWarningExt(tif->tif_clientdata,module,
+ "Invalid data type for tag %s",
+ fip ? fip->field_name : "unknown tagname");
+ }
+ break;
+ }
_TIFFmemcpy( &(tif->tif_dir.td_stripoffset_entry),
dp, sizeof(TIFFDirEntry) );
break;
case TIFFTAG_STRIPBYTECOUNTS:
case TIFFTAG_TILEBYTECOUNTS:
+ switch( dp->tdir_type )
+ {
+ case TIFF_SHORT:
+ case TIFF_LONG:
+ case TIFF_LONG8:
+ break;
+ default:
+ /* Warn except if directory typically created with TIFFDeferStrileArrayWriting() */
+ if( !(tif->tif_mode == O_RDWR &&
+ dp->tdir_count == 0 &&
+ dp->tdir_type == 0 &&
+ dp->tdir_offset.toff_long8 == 0) )
+ {
+ fip = TIFFFieldWithTag(tif,dp->tdir_tag);
+ TIFFWarningExt(tif->tif_clientdata,module,
+ "Invalid data type for tag %s",
+ fip ? fip->field_name : "unknown tagname");
+ }
+ break;
+ }
_TIFFmemcpy( &(tif->tif_dir.td_stripbytecount_entry),
dp, sizeof(TIFFDirEntry) );
break;
@@ -4401,6 +4448,7 @@ TIFFReadCustomDirectory(TIFF* tif, toff_t diroff,
uint16 di;
const TIFFField* fip;
uint32 fii;
+ (*tif->tif_cleanup)(tif); /* cleanup any previous compression state */
_TIFFSetupFields(tif, infoarray);
dircount=TIFFFetchDirectory(tif,diroff,&dir,NULL);
if (!dircount)
@@ -4505,6 +4553,17 @@ TIFFReadEXIFDirectory(TIFF* tif, toff_t diroff)
return TIFFReadCustomDirectory(tif, diroff, exifFieldArray);
}
+/*
+ *--: EXIF-GPS custom directory reading as another special case of custom IFD.
+ */
+int
+TIFFReadGPSDirectory(TIFF* tif, toff_t diroff)
+{
+ const TIFFFieldArray* gpsFieldArray;
+ gpsFieldArray = _TIFFGetGpsFields();
+ return TIFFReadCustomDirectory(tif, diroff, gpsFieldArray);
+}
+
static int
EstimateStripByteCounts(TIFF* tif, TIFFDirEntry* dir, uint16 dircount)
{
@@ -5140,6 +5199,7 @@ TIFFFetchNormalTag(TIFF* tif, TIFFDirEntry* dp, int recover)
if (err==TIFFReadDirEntryErrOk)
{
int m;
+ assert(data); /* avoid CLang static Analyzer false positive */
m=TIFFSetField(tif,dp->tdir_tag,data[0],data[1]);
_TIFFfree(data);
if (!m)
@@ -5223,7 +5283,7 @@ TIFFFetchNormalTag(TIFF* tif, TIFFDirEntry* dp, int recover)
assert(fip->field_readcount>=1);
assert(fip->field_passcount==0);
if (dp->tdir_count!=(uint64)fip->field_readcount)
- /* corrupt file */;
+ /* corrupt file */;
else
{
err=TIFFReadDirEntryFloatArray(tif,dp,&data);
@@ -5239,6 +5299,29 @@ TIFFFetchNormalTag(TIFF* tif, TIFFDirEntry* dp, int recover)
}
}
break;
+ /*--: Rational2Double: Extend for Double Arrays and Rational-Arrays read into Double-Arrays. */
+ case TIFF_SETGET_C0_DOUBLE:
+ {
+ double* data;
+ assert(fip->field_readcount>=1);
+ assert(fip->field_passcount==0);
+ if (dp->tdir_count!=(uint64)fip->field_readcount)
+ /* corrupt file */;
+ else
+ {
+ err=TIFFReadDirEntryDoubleArray(tif,dp,&data);
+ if (err==TIFFReadDirEntryErrOk)
+ {
+ int m;
+ m=TIFFSetField(tif,dp->tdir_tag,data);
+ if (data!=0)
+ _TIFFfree(data);
+ if (!m)
+ return(0);
+ }
+ }
+ }
+ break;
case TIFF_SETGET_C16_ASCII:
{
uint8* data;
@@ -6034,6 +6117,12 @@ int _TIFFPartialReadStripArray( TIFF* tif, TIFFDirEntry* dirent,
{
sizeofval = sizeof(uint64);
}
+ else if( dirent->tdir_type == TIFF_SLONG8 )
+ {
+ /* Non conformant but used by some images as in */
+ /* https://github.com/OSGeo/gdal/issues/2165 */
+ sizeofval = sizeof(int64);
+ }
else
{
TIFFErrorExt(tif->tif_clientdata, module,
@@ -6106,7 +6195,7 @@ int _TIFFPartialReadStripArray( TIFF* tif, TIFFDirEntry* dirent,
_TIFFUnsanitizedAddUInt64AndInt(nOffset, (i + 1) * sizeofvalint) <= nOffsetEndPage;
++i )
{
- if( sizeofval == sizeof(uint16) )
+ if( dirent->tdir_type == TIFF_SHORT )
{
uint16 val;
memcpy(&val,
@@ -6116,7 +6205,7 @@ int _TIFFPartialReadStripArray( TIFF* tif, TIFFDirEntry* dirent,
TIFFSwabShort(&val);
panVals[strile + i] = val;
}
- else if( sizeofval == sizeof(uint32) )
+ else if( dirent->tdir_type == TIFF_LONG )
{
uint32 val;
memcpy(&val,
@@ -6126,7 +6215,7 @@ int _TIFFPartialReadStripArray( TIFF* tif, TIFFDirEntry* dirent,
TIFFSwabLong(&val);
panVals[strile + i] = val;
}
- else
+ else if( dirent->tdir_type == TIFF_LONG8 )
{
uint64 val;
memcpy(&val,
@@ -6136,6 +6225,17 @@ int _TIFFPartialReadStripArray( TIFF* tif, TIFFDirEntry* dirent,
TIFFSwabLong8(&val);
panVals[strile + i] = val;
}
+ else /* if( dirent->tdir_type == TIFF_SLONG8 ) */
+ {
+ /* Non conformant data type */
+ int64 val;
+ memcpy(&val,
+ buffer + (nOffset - nOffsetStartPage) + i * sizeofvalint,
+ sizeof(val));
+ if( bSwab )
+ TIFFSwabLong8((uint64*) &val);
+ panVals[strile + i] = (uint64) val;
+ }
}
return 1;
}
@@ -6346,7 +6446,7 @@ static int _TIFFFillStrilesInternal( TIFF *tif, int loadStripByteCount )
if( td->td_stripoffset_p != NULL )
return 1;
- /* If tdir_count was cancelled, then we already got there, but in error */
+ /* If tdir_count was canceled, then we already got there, but in error */
if( td->td_stripoffset_entry.tdir_count == 0 )
return 0;
diff --git a/tiff/libtiff/tif_dirwrite.c b/tiff/libtiff/tif_dirwrite.c
index 9e4d3060..f481250e 100644
--- a/tiff/libtiff/tif_dirwrite.c
+++ b/tiff/libtiff/tif_dirwrite.c
@@ -28,6 +28,8 @@
* Directory Write Support Routines.
*/
#include "tiffiop.h"
+#include <float.h> /*--: for Rational2Double */
+#include <math.h> /*--: for Rational2Double */
#ifdef HAVE_IEEEFP
#define TIFFCvtNativeToIEEEFloat(tif, n, fp)
@@ -154,6 +156,19 @@ static int TIFFWriteDirectoryTagCheckedSlong8Array(TIFF* tif, uint32* ndir, TIFF
static int TIFFWriteDirectoryTagCheckedRational(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, double value);
static int TIFFWriteDirectoryTagCheckedRationalArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, float* value);
static int TIFFWriteDirectoryTagCheckedSrationalArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, float* value);
+
+/*--: Rational2Double: New functions to support true double-precision for custom rational tag types. */
+static int TIFFWriteDirectoryTagRationalDoubleArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, double* value);
+static int TIFFWriteDirectoryTagSrationalDoubleArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, double* value);
+static int TIFFWriteDirectoryTagCheckedRationalDoubleArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, double* value);
+static int TIFFWriteDirectoryTagCheckedSrationalDoubleArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, double* value);
+static void DoubleToRational(double value, uint32 *num, uint32 *denom);
+static void DoubleToSrational(double value, int32 *num, int32 *denom);
+#if 0
+static void DoubleToRational_direct(double value, unsigned long *num, unsigned long *denom);
+static void DoubleToSrational_direct(double value, long *num, long *denom);
+#endif
+
#ifdef notdef
static int TIFFWriteDirectoryTagCheckedFloat(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, float value);
#endif
@@ -796,12 +811,42 @@ TIFFWriteDirectorySec(TIFF* tif, int isimage, int imagedone, uint64* pdiroff)
goto bad;
break;
case TIFF_RATIONAL:
- if (!TIFFWriteDirectoryTagRationalArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))
- goto bad;
+ {
+ /*-- Rational2Double: For Rationals evaluate "set_field_type" to determine internal storage size. */
+ int tv_size;
+ tv_size = _TIFFSetGetFieldSize(tif->tif_dir.td_customValues[m].info->set_field_type);
+ if (tv_size == 8) {
+ if (!TIFFWriteDirectoryTagRationalDoubleArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))
+ goto bad;
+ } else {
+ /*-- default should be tv_size == 4 */
+ if (!TIFFWriteDirectoryTagRationalArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))
+ goto bad;
+ /*-- ToDo: After Testing, this should be removed and tv_size==4 should be set as default. */
+ if (tv_size != 4) {
+ TIFFErrorExt(0,"TIFFLib: _TIFFWriteDirectorySec()", "Rational2Double: .set_field_type in not 4 but %d", tv_size);
+ }
+ }
+ }
break;
case TIFF_SRATIONAL:
- if (!TIFFWriteDirectoryTagSrationalArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))
- goto bad;
+ {
+ /*-- Rational2Double: For Rationals evaluate "set_field_type" to determine internal storage size. */
+ int tv_size;
+ tv_size = _TIFFSetGetFieldSize(tif->tif_dir.td_customValues[m].info->set_field_type);
+ if (tv_size == 8) {
+ if (!TIFFWriteDirectoryTagSrationalDoubleArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))
+ goto bad;
+ } else {
+ /*-- default should be tv_size == 4 */
+ if (!TIFFWriteDirectoryTagSrationalArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))
+ goto bad;
+ /*-- ToDo: After Testing, this should be removed and tv_size==4 should be set as default. */
+ if (tv_size != 4) {
+ TIFFErrorExt(0,"TIFFLib: _TIFFWriteDirectorySec()", "Rational2Double: .set_field_type in not 4 but %d", tv_size);
+ }
+ }
+ }
break;
case TIFF_FLOAT:
if (!TIFFWriteDirectoryTagFloatArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))
@@ -1560,6 +1605,29 @@ TIFFWriteDirectoryTagSrationalArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir,
return(TIFFWriteDirectoryTagCheckedSrationalArray(tif,ndir,dir,tag,count,value));
}
+/*-- Rational2Double: additional write functions */
+static int
+TIFFWriteDirectoryTagRationalDoubleArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, double* value)
+{
+ if (dir==NULL)
+ {
+ (*ndir)++;
+ return(1);
+ }
+ return(TIFFWriteDirectoryTagCheckedRationalDoubleArray(tif,ndir,dir,tag,count,value));
+}
+
+static int
+TIFFWriteDirectoryTagSrationalDoubleArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, double* value)
+{
+ if (dir==NULL)
+ {
+ (*ndir)++;
+ return(1);
+ }
+ return(TIFFWriteDirectoryTagCheckedSrationalDoubleArray(tif,ndir,dir,tag,count,value));
+}
+
#ifdef notdef
static int TIFFWriteDirectoryTagFloat(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, float value)
{
@@ -2318,19 +2386,20 @@ TIFFWriteDirectoryTagCheckedSlong8Array(TIFF* tif, uint32* ndir, TIFFDirEntry* d
static int
TIFFWriteDirectoryTagCheckedRational(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, double value)
{
- static const char module[] = "TIFFWriteDirectoryTagCheckedRational";
+ static const char module[] = "TIFFWriteDirectoryTagCheckedRational";
uint32 m[2];
assert(sizeof(uint32)==4);
- if( value < 0 )
- {
- TIFFErrorExt(tif->tif_clientdata,module,"Negative value is illegal");
- return 0;
- }
- else if( value != value )
- {
- TIFFErrorExt(tif->tif_clientdata,module,"Not-a-number value is illegal");
- return 0;
- }
+ if (value < 0)
+ {
+ TIFFErrorExt(tif->tif_clientdata, module, "Negative value is illegal");
+ return 0;
+ }
+ else if (value != value)
+ {
+ TIFFErrorExt(tif->tif_clientdata, module, "Not-a-number value is illegal");
+ return 0;
+ }
+#ifdef not_def
else if (value==0.0)
{
m[0]=0;
@@ -2351,6 +2420,15 @@ TIFFWriteDirectoryTagCheckedRational(TIFF* tif, uint32* ndir, TIFFDirEntry* dir,
m[0]=0xFFFFFFFF;
m[1]=(uint32)(0xFFFFFFFF/value);
}
+#else
+ /*--Rational2Double: New function also used for non-custom rational tags.
+ * However, could be omitted here, because TIFFWriteDirectoryTagCheckedRational() is not used by code for custom tags,
+ * only by code for named-tiff-tags like FIELD_RESOLUTION and FIELD_POSITION */
+ else {
+ DoubleToRational(value, &m[0], &m[1]);
+ }
+#endif
+
if (tif->tif_flags&TIFF_SWAB)
{
TIFFSwabLong(&m[0]);
@@ -2377,6 +2455,7 @@ TIFFWriteDirectoryTagCheckedRationalArray(TIFF* tif, uint32* ndir, TIFFDirEntry*
}
for (na=value, nb=m, nc=0; nc<count; na++, nb+=2, nc++)
{
+#ifdef not_def
if (*na<=0.0 || *na != *na)
{
nb[0]=0;
@@ -2398,6 +2477,10 @@ TIFFWriteDirectoryTagCheckedRationalArray(TIFF* tif, uint32* ndir, TIFFDirEntry*
nb[0]=0xFFFFFFFF;
nb[1]=(uint32)((double)0xFFFFFFFF/(*na));
}
+#else
+ /*-- Rational2Double: Also for float precision accuracy is sometimes enhanced --*/
+ DoubleToRational(*na, &nb[0], &nb[1]);
+#endif
}
if (tif->tif_flags&TIFF_SWAB)
TIFFSwabArrayOfLong(m,count*2);
@@ -2424,6 +2507,7 @@ TIFFWriteDirectoryTagCheckedSrationalArray(TIFF* tif, uint32* ndir, TIFFDirEntry
}
for (na=value, nb=m, nc=0; nc<count; na++, nb+=2, nc++)
{
+#ifdef not_def
if (*na<0.0)
{
if (*na==(int32)(*na))
@@ -2460,6 +2544,10 @@ TIFFWriteDirectoryTagCheckedSrationalArray(TIFF* tif, uint32* ndir, TIFFDirEntry
nb[1]=(int32)((double)0x7FFFFFFF/(*na));
}
}
+#else
+ /*-- Rational2Double: Also for float precision accuracy is sometimes enhanced --*/
+ DoubleToSrational(*na, &nb[0], &nb[1]);
+#endif
}
if (tif->tif_flags&TIFF_SWAB)
TIFFSwabArrayOfLong((uint32*)m,count*2);
@@ -2468,6 +2556,400 @@ TIFFWriteDirectoryTagCheckedSrationalArray(TIFF* tif, uint32* ndir, TIFFDirEntry
return(o);
}
+/*-- Rational2Double: additional write functions for double arrays */
+static int
+TIFFWriteDirectoryTagCheckedRationalDoubleArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, double* value)
+{
+ static const char module[] = "TIFFWriteDirectoryTagCheckedRationalDoubleArray";
+ uint32* m;
+ double* na;
+ uint32* nb;
+ uint32 nc;
+ int o;
+ assert(sizeof(uint32)==4);
+ m=_TIFFmalloc(count*2*sizeof(uint32));
+ if (m==NULL)
+ {
+ TIFFErrorExt(tif->tif_clientdata,module,"Out of memory");
+ return(0);
+ }
+ for (na=value, nb=m, nc=0; nc<count; na++, nb+=2, nc++)
+ {
+ DoubleToRational(*na, &nb[0], &nb[1]);
+ }
+ if (tif->tif_flags&TIFF_SWAB)
+ TIFFSwabArrayOfLong(m,count*2);
+ o=TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_RATIONAL,count,count*8,&m[0]);
+ _TIFFfree(m);
+ return(o);
+} /*-- TIFFWriteDirectoryTagCheckedRationalDoubleArray() ------- */
+
+static int
+TIFFWriteDirectoryTagCheckedSrationalDoubleArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, double* value)
+{
+ static const char module[] = "TIFFWriteDirectoryTagCheckedSrationalDoubleArray";
+ int32* m;
+ double* na;
+ int32* nb;
+ uint32 nc;
+ int o;
+ assert(sizeof(int32)==4);
+ m=_TIFFmalloc(count*2*sizeof(int32));
+ if (m==NULL)
+ {
+ TIFFErrorExt(tif->tif_clientdata,module,"Out of memory");
+ return(0);
+ }
+ for (na=value, nb=m, nc=0; nc<count; na++, nb+=2, nc++)
+ {
+ DoubleToSrational(*na, &nb[0], &nb[1]);
+ }
+ if (tif->tif_flags&TIFF_SWAB)
+ TIFFSwabArrayOfLong((uint32*)m,count*2);
+ o=TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_SRATIONAL,count,count*8,&m[0]);
+ _TIFFfree(m);
+ return(o);
+} /*--- TIFFWriteDirectoryTagCheckedSrationalDoubleArray() -------- */
+
+#if 0
+static
+void DoubleToRational_direct(double value, unsigned long *num, unsigned long *denom)
+{
+ /*--- OLD Code for debugging and comparison ---- */
+ /* code merged from TIFFWriteDirectoryTagCheckedRationalArray() and TIFFWriteDirectoryTagCheckedRational() */
+
+ /* First check for zero and also check for negative numbers (which are illegal for RATIONAL)
+ * and also check for "not-a-number". In each case just set this to zero to support also rational-arrays.
+ */
+ if (value<=0.0 || value != value)
+ {
+ *num=0;
+ *denom=1;
+ }
+ else if (value <= 0xFFFFFFFFU && (value==(double)(uint32)(value))) /* check for integer values */
+ {
+ *num=(uint32)(value);
+ *denom=1;
+ }
+ else if (value<1.0)
+ {
+ *num = (uint32)((value) * (double)0xFFFFFFFFU);
+ *denom=0xFFFFFFFFU;
+ }
+ else
+ {
+ *num=0xFFFFFFFFU;
+ *denom=(uint32)((double)0xFFFFFFFFU/(value));
+ }
+} /*-- DoubleToRational_direct() -------------- */
+#endif
+
+#if 0
+static
+void DoubleToSrational_direct(double value, long *num, long *denom)
+{
+ /*--- OLD Code for debugging and comparison -- SIGNED-version ----*/
+ /* code was amended from original TIFFWriteDirectoryTagCheckedSrationalArray() */
+
+ /* First check for zero and also check for negative numbers (which are illegal for RATIONAL)
+ * and also check for "not-a-number". In each case just set this to zero to support also rational-arrays.
+ */
+ if (value<0.0)
+ {
+ if (value==(int32)(value))
+ {
+ *num=(int32)(value);
+ *denom=1;
+ }
+ else if (value>-1.0)
+ {
+ *num=-(int32)((-value) * (double)0x7FFFFFFF);
+ *denom=0x7FFFFFFF;
+ }
+ else
+ {
+ *num=-0x7FFFFFFF;
+ *denom=(int32)((double)0x7FFFFFFF / (-value));
+ }
+ }
+ else
+ {
+ if (value==(int32)(value))
+ {
+ *num=(int32)(value);
+ *denom=1;
+ }
+ else if (value<1.0)
+ {
+ *num=(int32)((value) *(double)0x7FFFFFFF);
+ *denom=0x7FFFFFFF;
+ }
+ else
+ {
+ *num=0x7FFFFFFF;
+ *denom=(int32)((double)0x7FFFFFFF / (value));
+ }
+ }
+} /*-- DoubleToSrational_direct() --------------*/
+#endif
+
+//#define DOUBLE2RAT_DEBUGOUTPUT
+/** ----- Rational2Double: Double To Rational Conversion ----------------------------------------------------------
+* There is a mathematical theorem to convert real numbers into a rational (integer fraction) number.
+* This is called "continuous fraction" which uses the Euclidean algorithm to find the greatest common divisor (GCD).
+* (ref. e.g. https://de.wikipedia.org/wiki/Kettenbruch or https://en.wikipedia.org/wiki/Continued_fraction
+* https://en.wikipedia.org/wiki/Euclidean_algorithm)
+* The following functions implement the
+* - ToRationalEuclideanGCD() auxiliary function which mainly implements euclidean GCD
+* - DoubleToRational() conversion function for un-signed rationals
+* - DoubleToSrational() conversion function for signed rationals
+------------------------------------------------------------------------------------------------------------------*/
+
+/**---- ToRationalEuclideanGCD() -----------------------------------------
+* Calculates the rational fractional of a double input value
+* using the Euclidean algorithm to find the greatest common divisor (GCD)
+------------------------------------------------------------------------*/
+static
+void ToRationalEuclideanGCD(double value, int blnUseSignedRange, int blnUseSmallRange, unsigned long long *ullNum, unsigned long long *ullDenom)
+{
+ /* Internally, the integer variables can be bigger than the external ones,
+ * as long as the result will fit into the external variable size.
+ */
+ unsigned long long val, numSum[3] = { 0, 1, 0 }, denomSum[3] = { 1, 0, 0 };
+ unsigned long long aux, bigNum, bigDenom;
+ unsigned long long returnLimit;
+ int i;
+ unsigned long long nMax;
+ double fMax;
+ unsigned long maxDenom;
+ /*-- nMax and fMax defines the initial accuracy of the starting fractional,
+ * or better, the highest used integer numbers used within the starting fractional (bigNum/bigDenom).
+ * There are two approaches, which can accidentally lead to different accuracies just depending on the value.
+ * Therefore, blnUseSmallRange steers this behavior.
+ * For long long nMax = ((9223372036854775807-1)/2); for long nMax = ((2147483647-1)/2);
+ */
+ if (blnUseSmallRange) {
+ nMax = (unsigned long long)((2147483647 - 1) / 2); /* for ULONG range */
+ }
+ else {
+ nMax = ((9223372036854775807 - 1) / 2); /* for ULLONG range */
+ }
+ fMax = (double)nMax;
+
+ /*-- For the Euclidean GCD define the denominator range, so that it stays within size of unsigned long variables.
+ * maxDenom should be LONG_MAX for negative values and ULONG_MAX for positive ones.
+ * Also the final returned value of ullNum and ullDenom is limited according to signed- or unsigned-range.
+ */
+ if (blnUseSignedRange) {
+ maxDenom = 2147483647UL; /*LONG_MAX = 0x7FFFFFFFUL*/
+ returnLimit = maxDenom;
+ }
+ else {
+ maxDenom = 0xFFFFFFFFUL; /*ULONG_MAX = 0xFFFFFFFFUL*/
+ returnLimit = maxDenom;
+ }
+
+ /*-- First generate a rational fraction (bigNum/bigDenom) which represents the value
+ * as a rational number with the highest accuracy. Therefore, unsigned long long (uint64) is needed.
+ * This rational fraction is then reduced using the Euclidean algorithm to find the greatest common divisor (GCD).
+ * bigNum = big numinator of value without fraction (or cut residual fraction)
+ * bigDenom = big denominator of value
+ *-- Break-criteria so that uint64 cast to "bigNum" introduces no error and bigDenom has no overflow,
+ * and stop with enlargement of fraction when the double-value of it reaches an integer number without fractional part.
+ */
+ bigDenom = 1;
+ while ((value != floor(value)) && (value < fMax) && (bigDenom < nMax)) {
+ bigDenom <<= 1;
+ value *= 2;
+ }
+ bigNum = (unsigned long long)value;
+
+ /*-- Start Euclidean algorithm to find the greatest common divisor (GCD) -- */
+#define MAX_ITERATIONS 64
+ for (i = 0; i < MAX_ITERATIONS; i++) {
+ /* if bigDenom is not zero, calculate integer part of fraction. */
+ if (bigDenom == 0) {
+ val = 0;
+ break;
+ }
+ else {
+ val = bigNum / bigDenom;
+ }
+
+ /* Set bigDenom to reminder of bigNum/bigDenom and bigNum to previous denominator bigDenom. */
+ aux = bigNum;
+ bigNum = bigDenom;
+ bigDenom = aux % bigDenom;
+
+ /* calculate next denominator and check for its given maximum */
+ aux = val;
+ if (denomSum[1] * val + denomSum[0] >= maxDenom) {
+ aux = (maxDenom - denomSum[0]) / denomSum[1];
+ if (aux * 2 >= val || denomSum[1] >= maxDenom)
+ i = (MAX_ITERATIONS + 1); /* exit but execute rest of for-loop */
+ else
+ break;
+ }
+ /* calculate next numerator to numSum2 and save previous one to numSum0; numSum1 just copy of numSum2. */
+ numSum[2] = aux * numSum[1] + numSum[0];
+ numSum[0] = numSum[1];
+ numSum[1] = numSum[2];
+ /* calculate next denominator to denomSum2 and save previous one to denomSum0; denomSum1 just copy of denomSum2. */
+ denomSum[2] = aux * denomSum[1] + denomSum[0];
+ denomSum[0] = denomSum[1];
+ denomSum[1] = denomSum[2];
+ }
+
+ /*-- Check and adapt for final variable size and return values; reduces internal accuracy; denominator is kept in ULONG-range with maxDenom -- */
+ while (numSum[1] > returnLimit || denomSum[1] > returnLimit) {
+ numSum[1] = numSum[1] / 2;
+ denomSum[1] = denomSum[1] / 2;
+ }
+
+ /* return values */
+ *ullNum = numSum[1];
+ *ullDenom = denomSum[1];
+
+} /*-- ToRationalEuclideanGCD() -------------- */
+
+
+/**---- DoubleToRational() -----------------------------------------------
+* Calculates the rational fractional of a double input value
+* for UN-SIGNED rationals,
+* using the Euclidean algorithm to find the greatest common divisor (GCD)
+------------------------------------------------------------------------*/
+static
+void DoubleToRational(double value, uint32 *num, uint32 *denom)
+{
+ /*---- UN-SIGNED RATIONAL ---- */
+ double dblDiff, dblDiff2;
+ unsigned long long ullNum, ullDenom, ullNum2, ullDenom2;
+
+ /*-- Check for negative values. If so it is an error. */
+ /* Test written that way to catch NaN */
+ if (!(value >= 0)) {
+ *num = *denom = 0;
+ TIFFErrorExt(0, "TIFFLib: DoubleToRational()", " Negative Value for Unsigned Rational given.");
+ return;
+ }
+
+ /*-- Check for too big numbers (> ULONG_MAX) -- */
+ if (value > 0xFFFFFFFFUL) {
+ *num = 0xFFFFFFFFU;
+ *denom = 0;
+ return;
+ }
+ /*-- Check for easy integer numbers -- */
+ if (value == (uint32)(value)) {
+ *num = (uint32)value;
+ *denom = 1;
+ return;
+ }
+ /*-- Check for too small numbers for "unsigned long" type rationals -- */
+ if (value < 1.0 / (double)0xFFFFFFFFUL) {
+ *num = 0;
+ *denom = 0xFFFFFFFFU;
+ return;
+ }
+
+ /*-- There are two approaches using the Euclidean algorithm,
+ * which can accidentally lead to different accuracies just depending on the value.
+ * Try both and define which one was better.
+ */
+ ToRationalEuclideanGCD(value, FALSE, FALSE, &ullNum, &ullDenom);
+ ToRationalEuclideanGCD(value, FALSE, TRUE, &ullNum2, &ullDenom2);
+ /*-- Double-Check, that returned values fit into ULONG :*/
+ if (ullNum > 0xFFFFFFFFUL || ullDenom > 0xFFFFFFFFUL || ullNum2 > 0xFFFFFFFFUL || ullDenom2 > 0xFFFFFFFFUL) {
+#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
+ TIFFErrorExt(0, "TIFFLib: DoubleToRational()", " Num or Denom exceeds ULONG: val=%14.6f, num=%I64u, denom=%I64u | num2=%I64u, denom2=%I64u", value, ullNum, ullDenom, ullNum2, ullDenom2);
+#else
+ TIFFErrorExt(0, "TIFFLib: DoubleToRational()", " Num or Denom exceeds ULONG: val=%14.6f, num=%12llu, denom=%12llu | num2=%12llu, denom2=%12llu", value, ullNum, ullDenom, ullNum2, ullDenom2);
+#endif
+ assert(0);
+ }
+
+ /* Check, which one has higher accuracy and take that. */
+ dblDiff = fabs(value - ((double)ullNum / (double)ullDenom));
+ dblDiff2 = fabs(value - ((double)ullNum2 / (double)ullDenom2));
+ if (dblDiff < dblDiff2) {
+ *num = (uint32)ullNum;
+ *denom = (uint32)ullDenom;
+ }
+ else {
+ *num = (uint32)ullNum2;
+ *denom = (uint32)ullDenom2;
+ }
+} /*-- DoubleToRational() -------------- */
+
+/**---- DoubleToSrational() -----------------------------------------------
+* Calculates the rational fractional of a double input value
+* for SIGNED rationals,
+* using the Euclidean algorithm to find the greatest common divisor (GCD)
+------------------------------------------------------------------------*/
+static
+void DoubleToSrational(double value, int32 *num, int32 *denom)
+{
+ /*---- SIGNED RATIONAL ----*/
+ int neg = 1;
+ double dblDiff, dblDiff2;
+ unsigned long long ullNum, ullDenom, ullNum2, ullDenom2;
+
+ /*-- Check for negative values and use then the positive one for internal calculations, but take the sign into account before returning. */
+ if (value < 0) { neg = -1; value = -value; }
+
+ /*-- Check for too big numbers (> LONG_MAX) -- */
+ if (value > 0x7FFFFFFFL) {
+ *num = 0x7FFFFFFFL;
+ *denom = 0;
+ return;
+ }
+ /*-- Check for easy numbers -- */
+ if (value == (int32)(value)) {
+ *num = (int32)(neg * value);
+ *denom = 1;
+ return;
+ }
+ /*-- Check for too small numbers for "long" type rationals -- */
+ if (value < 1.0 / (double)0x7FFFFFFFL) {
+ *num = 0;
+ *denom = 0x7FFFFFFFL;
+ return;
+ }
+
+ /*-- There are two approaches using the Euclidean algorithm,
+ * which can accidentally lead to different accuracies just depending on the value.
+ * Try both and define which one was better.
+ * Furthermore, set behavior of ToRationalEuclideanGCD() to the range of signed-long.
+ */
+ ToRationalEuclideanGCD(value, TRUE, FALSE, &ullNum, &ullDenom);
+ ToRationalEuclideanGCD(value, TRUE, TRUE, &ullNum2, &ullDenom2);
+ /*-- Double-Check, that returned values fit into LONG :*/
+ if (ullNum > 0x7FFFFFFFL || ullDenom > 0x7FFFFFFFL || ullNum2 > 0x7FFFFFFFL || ullDenom2 > 0x7FFFFFFFL) {
+#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
+ TIFFErrorExt(0, "TIFFLib: DoubleToSrational()", " Num or Denom exceeds LONG: val=%14.6f, num=%I64u, denom=%I64u | num2=%I64u, denom2=%I64u", neg*value, ullNum, ullDenom, ullNum2, ullDenom2);
+#else
+ TIFFErrorExt(0, "TIFFLib: DoubleToSrational()", " Num or Denom exceeds LONG: val=%14.6f, num=%12llu, denom=%12llu | num2=%12llu, denom2=%12llu", neg*value, ullNum, ullDenom, ullNum2, ullDenom2);
+#endif
+ assert(0);
+ }
+
+ /* Check, which one has higher accuracy and take that. */
+ dblDiff = fabs(value - ((double)ullNum / (double)ullDenom));
+ dblDiff2 = fabs(value - ((double)ullNum2 / (double)ullDenom2));
+ if (dblDiff < dblDiff2) {
+ *num = (int32)(neg * (long)ullNum);
+ *denom = (int32)ullDenom;
+ }
+ else {
+ *num = (int32)(neg * (long)ullNum2);
+ *denom = (int32)ullDenom2;
+ }
+} /*-- DoubleToSrational() --------------*/
+
+
+
+
+
#ifdef notdef
static int
TIFFWriteDirectoryTagCheckedFloat(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, float value)
diff --git a/tiff/libtiff/tif_fax3.c b/tiff/libtiff/tif_fax3.c
index d11c9684..9ab5b26a 100644
--- a/tiff/libtiff/tif_fax3.c
+++ b/tiff/libtiff/tif_fax3.c
@@ -73,6 +73,7 @@ typedef struct {
int EOLcnt; /* count of EOL codes recognized */
TIFFFaxFillFunc fill; /* fill routine */
uint32* runs; /* b&w runs for current/previous row */
+ uint32 nruns; /* size of the refruns / curruns arrays */
uint32* refruns; /* runs for reference line */
uint32* curruns; /* runs for current line */
@@ -160,7 +161,9 @@ Fax3PreDecode(TIFF* tif, uint16 s)
*/
sp->bitmap =
TIFFGetBitRevTable(tif->tif_dir.td_fillorder != FILLORDER_LSB2MSB);
+ sp->curruns = sp->runs;
if (sp->refruns) { /* init reference line to white */
+ sp->refruns = sp->runs + sp->nruns;
sp->refruns[0] = (uint32) sp->b.rowpixels;
sp->refruns[1] = 0;
}
@@ -218,8 +221,12 @@ Fax3PrematureEOF(const char* module, TIFF* tif, uint32 line, uint32 a0)
#define Nop
-/*
+/**
* Decode the requested amount of G3 1D-encoded data.
+ * @param buf destination buffer
+ * @param occ available bytes in destination buffer
+ * @param s number of planes (ignored)
+ * @returns 1 for success, -1 in case of error
*/
static int
Fax3Decode1D(TIFF* tif, uint8* buf, tmsize_t occ, uint16 s)
@@ -300,7 +307,9 @@ Fax3Decode2D(TIFF* tif, uint8* buf, tmsize_t occ, uint16 s)
else
EXPAND2D(EOF2Da);
(*sp->fill)(buf, thisrun, pa, lastx);
- SETVALUE(0); /* imaginary change for reference */
+ if (pa < thisrun + sp->nruns) {
+ SETVALUE(0); /* imaginary change for reference */
+ }
SWAP(uint32*, sp->curruns, sp->refruns);
buf += sp->b.rowbytes;
occ -= sp->b.rowbytes;
@@ -506,7 +515,7 @@ Fax3SetupState(TIFF* tif)
int needsRefLine;
Fax3CodecState* dsp = (Fax3CodecState*) Fax3State(tif);
tmsize_t rowbytes;
- uint32 rowpixels, nruns;
+ uint32 rowpixels;
if (td->td_bitspersample != 1) {
TIFFErrorExt(tif->tif_clientdata, module,
@@ -523,6 +532,13 @@ Fax3SetupState(TIFF* tif)
rowbytes = TIFFScanlineSize(tif);
rowpixels = td->td_imagewidth;
}
+ if ((uint64)rowbytes < ((uint64)rowpixels + 7) / 8)
+ {
+ TIFFErrorExt(tif->tif_clientdata, module,
+ "Inconsistent number of bytes per row : rowbytes=%lu rowpixels=%lu",
+ (unsigned long)(rowbytes), (unsigned long)(rowpixels));
+ return (0);
+ }
sp->rowbytes = rowbytes;
sp->rowpixels = rowpixels;
/*
@@ -539,26 +555,26 @@ Fax3SetupState(TIFF* tif)
TIFFroundup and TIFFSafeMultiply return zero on integer overflow
*/
dsp->runs=(uint32*) NULL;
- nruns = TIFFroundup_32(rowpixels,32);
+ dsp->nruns = TIFFroundup_32(rowpixels,32);
if (needsRefLine) {
- nruns = TIFFSafeMultiply(uint32,nruns,2);
+ dsp->nruns = TIFFSafeMultiply(uint32,dsp->nruns,2);
}
- if ((nruns == 0) || (TIFFSafeMultiply(uint32,nruns,2) == 0)) {
+ if ((dsp->nruns == 0) || (TIFFSafeMultiply(uint32,dsp->nruns,2) == 0)) {
TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
"Row pixels integer overflow (rowpixels %u)",
rowpixels);
return (0);
}
dsp->runs = (uint32*) _TIFFCheckMalloc(tif,
- TIFFSafeMultiply(uint32,nruns,2),
+ TIFFSafeMultiply(uint32,dsp->nruns,2),
sizeof (uint32),
"for Group 3/4 run arrays");
if (dsp->runs == NULL)
return (0);
- memset( dsp->runs, 0, TIFFSafeMultiply(uint32,nruns,2)*sizeof(uint32));
+ memset( dsp->runs, 0, TIFFSafeMultiply(uint32,dsp->nruns,2)*sizeof(uint32));
dsp->curruns = dsp->runs;
if (needsRefLine)
- dsp->refruns = dsp->runs + nruns;
+ dsp->refruns = dsp->runs + dsp->nruns;
else
dsp->refruns = NULL;
if (td->td_compression == COMPRESSION_CCITTFAX3
@@ -594,15 +610,19 @@ Fax3SetupState(TIFF* tif)
*/
#define Fax3FlushBits(tif, sp) { \
- if ((tif)->tif_rawcc >= (tif)->tif_rawdatasize) \
- (void) TIFFFlushData1(tif); \
+ if ((tif)->tif_rawcc >= (tif)->tif_rawdatasize) { \
+ if( !TIFFFlushData1(tif) ) \
+ return 0; \
+ } \
*(tif)->tif_rawcp++ = (uint8) (sp)->data; \
(tif)->tif_rawcc++; \
(sp)->data = 0, (sp)->bit = 8; \
}
#define _FlushBits(tif) { \
- if ((tif)->tif_rawcc >= (tif)->tif_rawdatasize) \
- (void) TIFFFlushData1(tif); \
+ if ((tif)->tif_rawcc >= (tif)->tif_rawdatasize) { \
+ if( !TIFFFlushData1(tif) ) \
+ return 0; \
+ } \
*(tif)->tif_rawcp++ = (uint8) data; \
(tif)->tif_rawcc++; \
data = 0, bit = 8; \
@@ -627,7 +647,7 @@ static const int _msbmask[9] =
* the output stream. Values are
* assumed to be at most 16 bits.
*/
-static void
+static int
Fax3PutBits(TIFF* tif, unsigned int bits, unsigned int length)
{
Fax3CodecState* sp = EncoderState(tif);
@@ -638,6 +658,7 @@ Fax3PutBits(TIFF* tif, unsigned int bits, unsigned int length)
sp->data = data;
sp->bit = bit;
+ return 1;
}
/*
@@ -662,7 +683,7 @@ Fax3PutBits(TIFF* tif, unsigned int bits, unsigned int length)
* appropriate table that holds the make-up and
* terminating codes is supplied.
*/
-static void
+static int
putspan(TIFF* tif, int32 span, const tableentry* tab)
{
Fax3CodecState* sp = EncoderState(tif);
@@ -700,6 +721,8 @@ putspan(TIFF* tif, int32 span, const tableentry* tab)
sp->data = data;
sp->bit = bit;
+
+ return 1;
}
/*
@@ -708,7 +731,7 @@ putspan(TIFF* tif, int32 span, const tableentry* tab)
* here. We also handle writing the tag bit for the next
* scanline when doing 2d encoding.
*/
-static void
+static int
Fax3PutEOL(TIFF* tif)
{
Fax3CodecState* sp = EncoderState(tif);
@@ -742,6 +765,8 @@ Fax3PutEOL(TIFF* tif)
sp->data = data;
sp->bit = bit;
+
+ return 1;
}
/*
@@ -991,12 +1016,14 @@ Fax3Encode1DRow(TIFF* tif, unsigned char* bp, uint32 bits)
for (;;) {
span = find0span(bp, bs, bits); /* white span */
- putspan(tif, span, TIFFFaxWhiteCodes);
+ if( !putspan(tif, span, TIFFFaxWhiteCodes) )
+ return 0;
bs += span;
if (bs >= bits)
break;
span = find1span(bp, bs, bits); /* black span */
- putspan(tif, span, TIFFFaxBlackCodes);
+ if( !putspan(tif, span, TIFFFaxBlackCodes) )
+ return 0;
bs += span;
if (bs >= bits)
break;
@@ -1048,21 +1075,28 @@ Fax3Encode2DRow(TIFF* tif, unsigned char* bp, unsigned char* rp, uint32 bits)
(b1 < a1 && a1 - b1 <= 3U) ? -(int32)(a1 - b1) : 0x7FFFFFFF;
if (!(-3 <= d && d <= 3)) { /* horizontal mode */
a2 = finddiff2(bp, a1, bits, PIXEL(bp,a1));
- putcode(tif, &horizcode);
+ if( !putcode(tif, &horizcode) )
+ return 0;
if (a0+a1 == 0 || PIXEL(bp, a0) == 0) {
- putspan(tif, a1-a0, TIFFFaxWhiteCodes);
- putspan(tif, a2-a1, TIFFFaxBlackCodes);
+ if( !putspan(tif, a1-a0, TIFFFaxWhiteCodes) )
+ return 0;
+ if( !putspan(tif, a2-a1, TIFFFaxBlackCodes) )
+ return 0;
} else {
- putspan(tif, a1-a0, TIFFFaxBlackCodes);
- putspan(tif, a2-a1, TIFFFaxWhiteCodes);
+ if( !putspan(tif, a1-a0, TIFFFaxBlackCodes) )
+ return 0;
+ if( !putspan(tif, a2-a1, TIFFFaxWhiteCodes) )
+ return 0;
}
a0 = a2;
} else { /* vertical mode */
- putcode(tif, &vcodes[d+3]);
+ if( !putcode(tif, &vcodes[d+3]) )
+ return 0;
a0 = a1;
}
} else { /* pass mode */
- putcode(tif, &passcode);
+ if( !putcode(tif, &passcode) )
+ return 0;
a0 = b2;
}
if (a0 >= bits)
@@ -1091,7 +1125,10 @@ Fax3Encode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
}
while (cc > 0) {
if ((sp->b.mode & FAXMODE_NOEOL) == 0)
- Fax3PutEOL(tif);
+ {
+ if( !Fax3PutEOL(tif) )
+ return 0;
+ }
if (is2DEncoding(sp)) {
if (sp->tag == G3_1D) {
if (!Fax3Encode1DRow(tif, bp, sp->b.rowpixels))
@@ -1128,8 +1165,8 @@ Fax3PostEncode(TIFF* tif)
return (1);
}
-static void
-Fax3Close(TIFF* tif)
+static int
+_Fax3Close(TIFF* tif)
{
if ((Fax3State(tif)->mode & FAXMODE_NORTC) == 0 && tif->tif_rawcp) {
Fax3CodecState* sp = EncoderState(tif);
@@ -1145,6 +1182,13 @@ Fax3Close(TIFF* tif)
Fax3PutBits(tif, code, length);
Fax3FlushBits(tif, sp);
}
+ return 1;
+}
+
+static void
+Fax3Close(TIFF* tif)
+{
+ _Fax3Close(tif);
}
static void
@@ -1453,6 +1497,13 @@ Fax4Decode(TIFF* tif, uint8* buf, tmsize_t occ, uint16 s)
EXPAND2D(EOFG4);
if (EOLcnt)
goto EOFG4;
+ if (((lastx + 7) >> 3) > (int)occ) /* check for buffer overrun */
+ {
+ TIFFErrorExt(tif->tif_clientdata, module,
+ "Buffer overrun detected : %d bytes available, %d bits needed",
+ (int)occ, lastx);
+ return -1;
+ }
(*sp->fill)(buf, thisrun, pa, lastx);
SETVALUE(0); /* imaginary change for reference */
SWAP(uint32*, sp->curruns, sp->refruns);
@@ -1468,6 +1519,13 @@ Fax4Decode(TIFF* tif, uint8* buf, tmsize_t occ, uint16 s)
fputs( "Bad EOFB\n", stderr );
#endif
ClrBits( 13 );
+ if (((lastx + 7) >> 3) > (int)occ) /* check for buffer overrun */
+ {
+ TIFFErrorExt(tif->tif_clientdata, module,
+ "Buffer overrun detected : %d bytes available, %d bits needed",
+ (int)occ, lastx);
+ return -1;
+ }
(*sp->fill)(buf, thisrun, pa, lastx);
UNCACHE_STATE(tif, sp);
return ( sp->line ? 1 : -1); /* don't error on badly-terminated strips */
diff --git a/tiff/libtiff/tif_fax3.h b/tiff/libtiff/tif_fax3.h
index abadcd97..701716cc 100644
--- a/tiff/libtiff/tif_fax3.h
+++ b/tiff/libtiff/tif_fax3.h
@@ -240,6 +240,11 @@ static const char* StateNames[] = {
* current row and reset decoding state.
*/
#define SETVALUE(x) do { \
+ if (pa >= thisrun + sp->nruns) { \
+ TIFFErrorExt(tif->tif_clientdata, module, "Buffer overflow at line %u of %s %u", \
+ sp->line, isTiled(tif) ? "tile" : "strip", isTiled(tif) ? tif->tif_curtile : tif->tif_curstrip); \
+ return (-1); \
+ } \
*pa++ = RunLength + (x); \
a0 += (x); \
RunLength = 0; \
@@ -377,6 +382,11 @@ done1d: \
*/
#define CHECK_b1 do { \
if (pa != thisrun) while (b1 <= a0 && b1 < lastx) { \
+ if( pb + 1 >= sp->refruns + sp->nruns) { \
+ TIFFErrorExt(tif->tif_clientdata, module, "Buffer overflow at line %u of %s %u", \
+ sp->line, isTiled(tif) ? "tile" : "strip", isTiled(tif) ? tif->tif_curtile : tif->tif_curstrip); \
+ return (-1); \
+ } \
b1 += pb[0] + pb[1]; \
pb += 2; \
} \
@@ -387,10 +397,20 @@ done1d: \
*/
#define EXPAND2D(eoflab) do { \
while (a0 < lastx) { \
+ if (pa >= thisrun + sp->nruns) { \
+ TIFFErrorExt(tif->tif_clientdata, module, "Buffer overflow at line %u of %s %u", \
+ sp->line, isTiled(tif) ? "tile" : "strip", isTiled(tif) ? tif->tif_curtile : tif->tif_curstrip); \
+ return (-1); \
+ } \
LOOKUP8(7, TIFFFaxMainTable, eof2d); \
switch (TabEnt->State) { \
case S_Pass: \
CHECK_b1; \
+ if( pb + 1 >= sp->refruns + sp->nruns) { \
+ TIFFErrorExt(tif->tif_clientdata, module, "Buffer overflow at line %u of %s %u", \
+ sp->line, isTiled(tif) ? "tile" : "strip", isTiled(tif) ? tif->tif_curtile : tif->tif_curstrip); \
+ return (-1); \
+ } \
b1 += *pb++; \
RunLength += b1 - a0; \
a0 = b1; \
@@ -469,20 +489,28 @@ done1d: \
case S_V0: \
CHECK_b1; \
SETVALUE(b1 - a0); \
+ if( pb >= sp->refruns + sp->nruns) { \
+ TIFFErrorExt(tif->tif_clientdata, module, "Buffer overflow at line %u of %s %u", \
+ sp->line, isTiled(tif) ? "tile" : "strip", isTiled(tif) ? tif->tif_curtile : tif->tif_curstrip); \
+ return (-1); \
+ } \
b1 += *pb++; \
break; \
case S_VR: \
CHECK_b1; \
SETVALUE(b1 - a0 + TabEnt->Param); \
+ if( pb >= sp->refruns + sp->nruns) { \
+ TIFFErrorExt(tif->tif_clientdata, module, "Buffer overflow at line %u of %s %u", \
+ sp->line, isTiled(tif) ? "tile" : "strip", isTiled(tif) ? tif->tif_curtile : tif->tif_curstrip); \
+ return (-1); \
+ } \
b1 += *pb++; \
break; \
case S_VL: \
CHECK_b1; \
- if (b1 <= (int) (a0 + TabEnt->Param)) { \
- if (b1 < (int) (a0 + TabEnt->Param) || pa != thisrun) { \
- unexpected("VL", a0); \
- goto eol2d; \
- } \
+ if (b1 < (int) (a0 + TabEnt->Param)) { \
+ unexpected("VL", a0); \
+ goto eol2d; \
} \
SETVALUE(b1 - a0 - TabEnt->Param); \
b1 -= *--pb; \
@@ -529,6 +557,7 @@ eol2d: \
CLEANUP_RUNS(); \
} while (0)
#endif /* _FAX3_ */
+/* vim: set ts=8 sts=4 sw=4 noet: */
/*
* Local Variables:
* mode: c
diff --git a/tiff/libtiff/tif_getimage.c b/tiff/libtiff/tif_getimage.c
index 4da785d3..3460af74 100644
--- a/tiff/libtiff/tif_getimage.c
+++ b/tiff/libtiff/tif_getimage.c
@@ -29,6 +29,7 @@
*/
#include "tiffiop.h"
#include <stdio.h>
+#include <limits.h>
static int gtTileContig(TIFFRGBAImage*, uint32*, uint32, uint32);
static int gtTileSeparate(TIFFRGBAImage*, uint32*, uint32, uint32);
@@ -645,12 +646,20 @@ gtTileContig(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h)
flip = setorientation(img);
if (flip & FLIP_VERTICALLY) {
- y = h - 1;
- toskew = -(int32)(tw + w);
+ if ((tw + w) > INT_MAX) {
+ TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "%s", "unsupported tile size (too wide)");
+ return (0);
+ }
+ y = h - 1;
+ toskew = -(int32)(tw + w);
}
else {
- y = 0;
- toskew = -(int32)(tw - w);
+ if (tw > (INT_MAX + w)) {
+ TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "%s", "unsupported tile size (too wide)");
+ return (0);
+ }
+ y = 0;
+ toskew = -(int32)(tw - w);
}
/*
@@ -765,10 +774,18 @@ gtTileSeparate(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h)
flip = setorientation(img);
if (flip & FLIP_VERTICALLY) {
+ if ((tw + w) > INT_MAX) {
+ TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "%s", "unsupported tile size (too wide)");
+ return (0);
+ }
y = h - 1;
toskew = -(int32)(tw + w);
}
else {
+ if (tw > (INT_MAX + w)) {
+ TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "%s", "unsupported tile size (too wide)");
+ return (0);
+ }
y = 0;
toskew = -(int32)(tw - w);
}
@@ -936,6 +953,10 @@ gtStripContig(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h)
flip = setorientation(img);
if (flip & FLIP_VERTICALLY) {
+ if ( w > INT_MAX ) {
+ TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "Width overflow");
+ return (0);
+ }
y = h - 1;
toskew = -(int32)(w + w);
} else {
@@ -1032,6 +1053,10 @@ gtStripSeparate(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h)
flip = setorientation(img);
if (flip & FLIP_VERTICALLY) {
+ if ( w > INT_MAX ) {
+ TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "Width overflow");
+ return (0);
+ }
y = h - 1;
toskew = -(int32)(w + w);
}
diff --git a/tiff/libtiff/tif_jbig.c b/tiff/libtiff/tif_jbig.c
index 7ffe8851..a3500e0b 100644
--- a/tiff/libtiff/tif_jbig.c
+++ b/tiff/libtiff/tif_jbig.c
@@ -199,6 +199,7 @@ static int JBIGEncode(TIFF* tif, uint8* buffer, tmsize_t size, uint16 s)
int TIFFInitJBIG(TIFF* tif, int scheme)
{
+ (void)scheme;
assert(scheme == COMPRESSION_JBIG);
/*
diff --git a/tiff/libtiff/tif_jpeg.c b/tiff/libtiff/tif_jpeg.c
index d49b9040..d051471e 100644
--- a/tiff/libtiff/tif_jpeg.c
+++ b/tiff/libtiff/tif_jpeg.c
@@ -475,7 +475,8 @@ std_empty_output_buffer(j_compress_ptr cinfo)
}
#endif
- TIFFFlushData1(tif);
+ if( !TIFFFlushData1(tif) )
+ return FALSE;
sp->dest.next_output_byte = (JOCTET*) tif->tif_rawdata;
sp->dest.free_in_buffer = (size_t) tif->tif_rawdatasize;
@@ -946,7 +947,10 @@ JPEGFixupTagsSubsamplingReadByte(struct JPEGFixupTagsSubsamplingData* data, uint
return(0);
if (!data->filepositioned)
{
- TIFFSeekFile(data->tif,data->fileoffset,SEEK_SET);
+ if (TIFFSeekFile(data->tif,data->fileoffset,SEEK_SET) == (toff_t)-1)
+ {
+ return 0;
+ }
data->filepositioned=1;
}
m=data->buffersize;
@@ -1215,35 +1219,37 @@ JPEGPreDecode(TIFF* tif, uint16 s)
/* store for all coefficients */
/* See call to jinit_d_coef_controller() from master_selection() */
/* in libjpeg */
- toff_t nRequiredMemory = (toff_t)sp->cinfo.d.image_width *
- sp->cinfo.d.image_height *
- sp->cinfo.d.num_components *
- ((td->td_bitspersample+7)/8);
- /* BLOCK_SMOOTHING_SUPPORTED is generally defined, so we need */
- /* to replicate the logic of jinit_d_coef_controller() */
- if( sp->cinfo.d.progressive_mode )
- nRequiredMemory *= 3;
-
-#ifndef TIFF_LIBJPEG_LARGEST_MEM_ALLOC
-#define TIFF_LIBJPEG_LARGEST_MEM_ALLOC (100 * 1024 * 1024)
-#endif
- if( nRequiredMemory > TIFF_LIBJPEG_LARGEST_MEM_ALLOC &&
+ /* 1 MB for regular libjpeg usage */
+ toff_t nRequiredMemory = 1024 * 1024;
+
+ for (ci = 0; ci < sp->cinfo.d.num_components; ci++) {
+ const jpeg_component_info *compptr = &(sp->cinfo.d.comp_info[ci]);
+ if( compptr->h_samp_factor > 0 && compptr->v_samp_factor > 0 )
+ {
+ nRequiredMemory += (toff_t)(
+ ((compptr->width_in_blocks + compptr->h_samp_factor - 1) / compptr->h_samp_factor)) *
+ ((compptr->height_in_blocks + compptr->v_samp_factor - 1) / compptr->v_samp_factor) *
+ sizeof(JBLOCK);
+ }
+ }
+
+ if( sp->cinfo.d.mem->max_memory_to_use > 0 &&
+ nRequiredMemory > (toff_t)(sp->cinfo.d.mem->max_memory_to_use) &&
getenv("LIBTIFF_ALLOW_LARGE_LIBJPEG_MEM_ALLOC") == NULL )
{
- TIFFErrorExt(tif->tif_clientdata, module,
- "Reading this strip would require libjpeg to allocate "
- "at least %u bytes. "
- "This is disabled since above the %u threshold. "
- "You may override this restriction by defining the "
- "LIBTIFF_ALLOW_LARGE_LIBJPEG_MEM_ALLOC environment variable, "
- "or recompile libtiff by defining the "
- "TIFF_LIBJPEG_LARGEST_MEM_ALLOC macro to a value greater "
- "than %u",
- (unsigned)nRequiredMemory,
- (unsigned)TIFF_LIBJPEG_LARGEST_MEM_ALLOC,
- (unsigned)TIFF_LIBJPEG_LARGEST_MEM_ALLOC);
- return (0);
+ TIFFErrorExt(tif->tif_clientdata, module,
+ "Reading this image would require libjpeg to allocate "
+ "at least %u bytes. "
+ "This is disabled since above the %u threshold. "
+ "You may override this restriction by defining the "
+ "LIBTIFF_ALLOW_LARGE_LIBJPEG_MEM_ALLOC environment variable, "
+ "or setting the JPEGMEM environment variable to a value greater "
+ "or equal to '%uM'",
+ (unsigned)(nRequiredMemory),
+ (unsigned)(sp->cinfo.d.mem->max_memory_to_use),
+ (unsigned)((nRequiredMemory + 1000000 - 1) / 1000000));
+ return 0;
}
}
@@ -2353,7 +2359,7 @@ JPEGVGetField(TIFF* tif, uint32 tag, va_list ap)
switch (tag) {
case TIFFTAG_JPEGTABLES:
*va_arg(ap, uint32*) = sp->jpegtables_length;
- *va_arg(ap, void**) = sp->jpegtables;
+ *va_arg(ap, const void**) = sp->jpegtables;
break;
case TIFFTAG_JPEGQUALITY:
*va_arg(ap, int*) = sp->jpegquality;
@@ -2488,6 +2494,7 @@ TIFFInitJPEG(TIFF* tif, int scheme)
{
JPEGState* sp;
+ (void)scheme;
assert(scheme == COMPRESSION_JPEG);
/*
diff --git a/tiff/libtiff/tif_luv.c b/tiff/libtiff/tif_luv.c
index 6fe48588..3bd02e88 100644
--- a/tiff/libtiff/tif_luv.c
+++ b/tiff/libtiff/tif_luv.c
@@ -193,6 +193,7 @@ LogL16Decode(TIFF* tif, uint8* op, tmsize_t occ, uint16 s)
tmsize_t cc;
int rc;
+ (void)s;
assert(s == 0);
assert(sp != NULL);
@@ -266,6 +267,7 @@ LogLuvDecode24(TIFF* tif, uint8* op, tmsize_t occ, uint16 s)
unsigned char* bp;
uint32* tp;
+ (void)s;
assert(s == 0);
assert(sp != NULL);
@@ -326,6 +328,7 @@ LogLuvDecode32(TIFF* tif, uint8* op, tmsize_t occ, uint16 s)
tmsize_t cc;
int rc;
+ (void)s;
assert(s == 0);
sp = DecoderState(tif);
assert(sp != NULL);
@@ -447,6 +450,7 @@ LogL16Encode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
int rc=0, mask;
tmsize_t beg;
+ (void)s;
assert(s == 0);
assert(sp != NULL);
npixels = cc / sp->pixel_size;
@@ -541,6 +545,7 @@ LogLuvEncode24(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
uint8* op;
uint32* tp;
+ (void)s;
assert(s == 0);
assert(sp != NULL);
npixels = cc / sp->pixel_size;
@@ -598,6 +603,7 @@ LogLuvEncode32(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
int rc=0, mask;
tmsize_t beg;
+ (void)s;
assert(s == 0);
assert(sp != NULL);
@@ -742,7 +748,7 @@ LogLuvEncodeTile(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
#undef exp2 /* Conflict with C'99 function */
#define exp2(x) exp(M_LN2*(x))
-static int itrunc(double x, int m)
+static int tiff_itrunc(double x, int m)
{
if( m == SGILOGENCODE_NODITHER )
return (int)x;
@@ -777,9 +783,9 @@ LogL16fromY(double Y, int em) /* get 16-bit LogL from Y */
if (Y <= -1.8371976e19)
return (0xffff);
if (Y > 5.4136769e-20)
- return itrunc(256.*(log2(Y) + 64.), em);
+ return tiff_itrunc(256.*(log2(Y) + 64.), em);
if (Y < -5.4136769e-20)
- return (~0x7fff | itrunc(256.*(log2(-Y) + 64.), em));
+ return (~0x7fff | tiff_itrunc(256.*(log2(-Y) + 64.), em));
return (0);
}
@@ -855,7 +861,7 @@ LogL10fromY(double Y, int em) /* get 10-bit LogL from Y */
else if (Y <= .00024283)
return (0);
else
- return itrunc(64.*(log2(Y) + 12.), em);
+ return tiff_itrunc(64.*(log2(Y) + 12.), em);
}
#define NANGLES 100
@@ -925,12 +931,12 @@ uv_encode(double u, double v, int em) /* encode (u',v') coordinates */
if (v < UV_VSTART)
return oog_encode(u, v);
- vi = itrunc((v - UV_VSTART)*(1./UV_SQSIZ), em);
+ vi = tiff_itrunc((v - UV_VSTART)*(1./UV_SQSIZ), em);
if (vi >= UV_NVS)
return oog_encode(u, v);
if (u < uv_row[vi].ustart)
return oog_encode(u, v);
- ui = itrunc((u - uv_row[vi].ustart)*(1./UV_SQSIZ), em);
+ ui = tiff_itrunc((u - uv_row[vi].ustart)*(1./UV_SQSIZ), em);
if (ui >= uv_row[vi].nus)
return oog_encode(u, v);
@@ -1099,7 +1105,7 @@ Luv24fromLuv48(LogLuvState* sp, uint8* op, tmsize_t n)
else if (sp->encode_meth == SGILOGENCODE_NODITHER)
Le = (luv3[0]-3314) >> 2;
else
- Le = itrunc(.25*(luv3[0]-3314.), sp->encode_meth);
+ Le = tiff_itrunc(.25*(luv3[0]-3314.), sp->encode_meth);
Ce = uv_encode((luv3[1]+.5)/(1<<15), (luv3[2]+.5)/(1<<15),
sp->encode_meth);
@@ -1155,10 +1161,10 @@ LogLuv32fromXYZ(float XYZ[3], int em)
v = 9.*XYZ[1] / s;
}
if (u <= 0.) ue = 0;
- else ue = itrunc(UVSCALE*u, em);
+ else ue = tiff_itrunc(UVSCALE*u, em);
if (ue > 255) ue = 255;
if (v <= 0.) ve = 0;
- else ve = itrunc(UVSCALE*v, em);
+ else ve = tiff_itrunc(UVSCALE*v, em);
if (ve > 255) ve = 255;
/* combine encodings */
return (Le << 16 | ue << 8 | ve);
@@ -1238,8 +1244,8 @@ Luv32fromLuv48(LogLuvState* sp, uint8* op, tmsize_t n)
}
while (n-- > 0) {
*luv++ = (uint32)luv3[0] << 16 |
- (itrunc(luv3[1]*(UVSCALE/(1<<15)), sp->encode_meth) << 8 & 0xff00) |
- (itrunc(luv3[2]*(UVSCALE/(1<<15)), sp->encode_meth) & 0xff);
+ (tiff_itrunc(luv3[1]*(UVSCALE/(1<<15)), sp->encode_meth) << 8 & 0xff00) |
+ (tiff_itrunc(luv3[2]*(UVSCALE/(1<<15)), sp->encode_meth) & 0xff);
luv3 += 3;
}
}
diff --git a/tiff/libtiff/tif_lzma.c b/tiff/libtiff/tif_lzma.c
index 3f6096b6..e150bd63 100644
--- a/tiff/libtiff/tif_lzma.c
+++ b/tiff/libtiff/tif_lzma.c
@@ -300,7 +300,8 @@ LZMAEncode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
}
if (sp->stream.avail_out == 0) {
tif->tif_rawcc = tif->tif_rawdatasize;
- TIFFFlushData1(tif);
+ if (!TIFFFlushData1(tif))
+ return 0;
sp->stream.next_out = tif->tif_rawdata;
sp->stream.avail_out = (size_t)tif->tif_rawdatasize; /* this is a safe typecast, as check is made already in LZMAPreEncode */
}
@@ -328,7 +329,8 @@ LZMAPostEncode(TIFF* tif)
if ((tmsize_t)sp->stream.avail_out != tif->tif_rawdatasize) {
tif->tif_rawcc =
tif->tif_rawdatasize - sp->stream.avail_out;
- TIFFFlushData1(tif);
+ if (!TIFFFlushData1(tif))
+ return 0;
sp->stream.next_out = tif->tif_rawdata;
sp->stream.avail_out = (size_t)tif->tif_rawdatasize; /* this is a safe typecast, as check is made already in ZIPPreEncode */
}
@@ -418,6 +420,7 @@ TIFFInitLZMA(TIFF* tif, int scheme)
LZMAState* sp;
lzma_stream tmp_stream = LZMA_STREAM_INIT;
+ (void)scheme;
assert( scheme == COMPRESSION_LZMA );
/*
diff --git a/tiff/libtiff/tif_lzw.c b/tiff/libtiff/tif_lzw.c
index 21064f29..d92d0fd3 100644
--- a/tiff/libtiff/tif_lzw.c
+++ b/tiff/libtiff/tif_lzw.c
@@ -214,19 +214,16 @@ LZWSetupDecode(TIFF* tif)
return (0);
}
- DecoderState(tif)->dec_codetab = NULL;
- DecoderState(tif)->dec_decode = NULL;
+ sp = DecoderState(tif);
+ sp->dec_codetab = NULL;
+ sp->dec_decode = NULL;
/*
* Setup predictor setup.
*/
(void) TIFFPredictorInit(tif);
-
- sp = DecoderState(tif);
}
- assert(sp != NULL);
-
if (sp->dec_codetab == NULL) {
sp->dec_codetab = (code_t*)_TIFFmalloc(CSIZE*sizeof (code_t));
if (sp->dec_codetab == NULL) {
@@ -1161,6 +1158,7 @@ int
TIFFInitLZW(TIFF* tif, int scheme)
{
static const char module[] = "TIFFInitLZW";
+ (void)scheme;
assert(scheme == COMPRESSION_LZW);
/*
* Allocate state block so tag methods have storage to record values.
@@ -1218,7 +1216,7 @@ bad:
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#endif /* LZW_SUPPORT */
diff --git a/tiff/libtiff/tif_ojpeg.c b/tiff/libtiff/tif_ojpeg.c
index a3d4513a..d9000764 100644
--- a/tiff/libtiff/tif_ojpeg.c
+++ b/tiff/libtiff/tif_ojpeg.c
@@ -74,7 +74,7 @@
or errors, up to the point where either these values are read, or it's clear they
aren't there. This means that some of the data is read twice, but we feel speed
in correcting these values is important enough to warrant this sacrifice. Although
- there is currently no define or other configuration mechanism to disable this behaviour,
+ there is currently no define or other configuration mechanism to disable this behavior,
the actual header scanning is build to robustly respond with error report if it
should encounter an uncorrected mismatch of subsampling values. See
OJPEGReadHeaderInfoSecStreamSof.
@@ -433,6 +433,7 @@ TIFFInitOJPEG(TIFF* tif, int scheme)
static const char module[]="TIFFInitOJPEG";
OJPEGState* sp;
+ (void)scheme;
assert(scheme==COMPRESSION_OJPEG);
/*
@@ -510,15 +511,15 @@ OJPEGVGetField(TIFF* tif, uint32 tag, va_list ap)
break;
case TIFFTAG_JPEGQTABLES:
*va_arg(ap,uint32*)=(uint32)sp->qtable_offset_count;
- *va_arg(ap,void**)=(void*)sp->qtable_offset;
+ *va_arg(ap,const void**)=(const void*)sp->qtable_offset;
break;
case TIFFTAG_JPEGDCTABLES:
*va_arg(ap,uint32*)=(uint32)sp->dctable_offset_count;
- *va_arg(ap,void**)=(void*)sp->dctable_offset;
+ *va_arg(ap,const void**)=(const void*)sp->dctable_offset;
break;
case TIFFTAG_JPEGACTABLES:
*va_arg(ap,uint32*)=(uint32)sp->actable_offset_count;
- *va_arg(ap,void**)=(void*)sp->actable_offset;
+ *va_arg(ap,const void**)=(const void*)sp->actable_offset;
break;
case TIFFTAG_JPEGPROC:
*va_arg(ap,uint16*)=(uint16)sp->jpeg_proc;
@@ -670,7 +671,7 @@ static int
OJPEGSetupDecode(TIFF* tif)
{
static const char module[]="OJPEGSetupDecode";
- TIFFWarningExt(tif->tif_clientdata,module,"Depreciated and troublesome old-style JPEG compression mode, please convert to new-style JPEG compression and notify vendor of writing software");
+ TIFFWarningExt(tif->tif_clientdata,module,"Deprecated and troublesome old-style JPEG compression mode, please convert to new-style JPEG compression and notify vendor of writing software");
return(1);
}
@@ -849,36 +850,6 @@ OJPEGDecodeRaw(TIFF* tif, uint8* buf, tmsize_t cc)
{
if (sp->subsampling_convert_state==0)
{
- const jpeg_decompress_struct* cinfo = &sp->libjpeg_jpeg_decompress_struct;
- int width = 0;
- int last_col_width = 0;
- int jpeg_bytes;
- int expected_bytes;
- int i;
- if (cinfo->MCUs_per_row == 0)
- {
- sp->error_in_raw_data_decoding = 1;
- return 0;
- }
- for (i = 0; i < cinfo->comps_in_scan; ++i)
- {
- const jpeg_component_info* info = cinfo->cur_comp_info[i];
-#if JPEG_LIB_VERSION >= 70
- width += info->MCU_width * info->DCT_h_scaled_size;
- last_col_width += info->last_col_width * info->DCT_h_scaled_size;
-#else
- width += info->MCU_width * info->DCT_scaled_size;
- last_col_width += info->last_col_width * info->DCT_scaled_size;
-#endif
- }
- jpeg_bytes = (cinfo->MCUs_per_row - 1) * width + last_col_width;
- expected_bytes = sp->subsampling_convert_clinelenout * sp->subsampling_ver * sp->subsampling_hor;
- if (jpeg_bytes != expected_bytes)
- {
- TIFFErrorExt(tif->tif_clientdata,module,"Inconsistent number of MCU in codestream");
- sp->error_in_raw_data_decoding = 1;
- return(0);
- }
if (jpeg_read_raw_data_encap(sp,&(sp->libjpeg_jpeg_decompress_struct),sp->subsampling_convert_ycbcrimage,sp->subsampling_ver*8)==0)
{
sp->error_in_raw_data_decoding = 1;
@@ -1106,6 +1077,8 @@ OJPEGReadHeaderInfo(TIFF* tif)
{
sp->strile_width=sp->image_width;
sp->strile_length=tif->tif_dir.td_rowsperstrip;
+ if( sp->strile_length == (uint32)-1 )
+ sp->strile_length = sp->image_length;
sp->strile_length_total=sp->image_length;
}
if (tif->tif_dir.td_samplesperpixel==1)
@@ -1398,6 +1371,26 @@ OJPEGWriteHeaderInfo(TIFF* tif)
}
if (jpeg_start_decompress_encap(sp,&(sp->libjpeg_jpeg_decompress_struct))==0)
return(0);
+ if(sp->libjpeg_jpeg_decompress_struct.image_width != sp->strile_width ) {
+ TIFFErrorExt(tif->tif_clientdata,module,
+ "jpeg_start_decompress() returned image_width = %d, "
+ "expected %d",
+ sp->libjpeg_jpeg_decompress_struct.image_width,
+ sp->strile_width);
+ return 0;
+ }
+ if(sp->libjpeg_jpeg_decompress_struct.max_h_samp_factor != sp->subsampling_hor ||
+ sp->libjpeg_jpeg_decompress_struct.max_v_samp_factor != sp->subsampling_ver) {
+ TIFFErrorExt(tif->tif_clientdata,module,
+ "jpeg_start_decompress() returned max_h_samp_factor = %d "
+ "and max_v_samp_factor = %d, expected %d and %d",
+ sp->libjpeg_jpeg_decompress_struct.max_h_samp_factor,
+ sp->libjpeg_jpeg_decompress_struct.max_v_samp_factor,
+ sp->subsampling_hor,
+ sp->subsampling_ver);
+ return 0;
+ }
+
sp->writeheader_done=1;
return(1);
}
diff --git a/tiff/libtiff/tif_open.c b/tiff/libtiff/tif_open.c
index ffe7835f..0534773a 100644
--- a/tiff/libtiff/tif_open.c
+++ b/tiff/libtiff/tif_open.c
@@ -104,6 +104,7 @@ TIFFClientOpen(
} n;
n.a8[0]=1;
n.a8[1]=0;
+ (void)n;
#ifdef WORDS_BIGENDIAN
assert(n.a16==256);
#else
@@ -165,7 +166,7 @@ TIFFClientOpen(
/*
* Process library-specific flags in the open mode string.
* The following flags may be used to control intrinsic library
- * behaviour that may or may not be desirable (usually for
+ * behavior that may or may not be desirable (usually for
* compatibility with some application that claims to support
* TIFF but only supports some brain dead idea of what the
* vendor thinks TIFF is):
@@ -206,7 +207,7 @@ TIFFClientOpen(
* not do right now.
*
* The 'M' and 'm' flags are provided because some virtual memory
- * systems exhibit poor behaviour when large images are mapped.
+ * systems exhibit poor behavior when large images are mapped.
* These options permit clients to control the use of memory-mapped
* files on a per-file basis.
*
diff --git a/tiff/libtiff/tif_pixarlog.c b/tiff/libtiff/tif_pixarlog.c
index 0ed9f010..f2912015 100644
--- a/tiff/libtiff/tif_pixarlog.c
+++ b/tiff/libtiff/tif_pixarlog.c
@@ -103,6 +103,9 @@
#define CODE_MASK 0x7ff /* 11 bits. */
+static float Fltsize;
+static float LogK1, LogK2;
+
#define REPEAT(n, op) { int i; i=n; do { i--; op; } while (i>0); }
static void
@@ -471,9 +474,6 @@ typedef struct {
uint16 *FromLT2;
uint16 *From14; /* Really for 16-bit data, but we shift down 2 */
uint16 *From8;
-
- float Fltsize;
- float LogK1, LogK2;
} PixarLogState;
@@ -508,8 +508,8 @@ PixarLogMakeTables(PixarLogState *sp)
b = exp(-c*ONE); /* multiplicative scale factor [b*exp(c*ONE) = 1] */
linstep = b*c*exp(1.);
- sp->LogK1 = (float)(1./c); /* if (v >= 2) token = k1*log(v*k2) */
- sp->LogK2 = (float)(1./b);
+ LogK1 = (float)(1./c); /* if (v >= 2) token = k1*log(v*k2) */
+ LogK2 = (float)(1./b);
lt2size = (int)(2./linstep) + 1;
FromLT2 = (uint16 *)_TIFFmalloc(lt2size*sizeof(uint16));
From14 = (uint16 *)_TIFFmalloc(16384*sizeof(uint16));
@@ -579,7 +579,7 @@ PixarLogMakeTables(PixarLogState *sp)
From8[i] = (uint16)j;
}
- sp->Fltsize = (float)(lt2size/2);
+ Fltsize = (float)(lt2size/2);
sp->ToLinearF = ToLinearF;
sp->ToLinear16 = ToLinear16;
@@ -956,15 +956,15 @@ PixarLogPreEncode(TIFF* tif, uint16 s)
}
static void
-horizontalDifferenceF(PixarLogState *sp, float *ip, int n, int stride, uint16 *wp, uint16 *FromLT2)
+horizontalDifferenceF(float *ip, int n, int stride, uint16 *wp, uint16 *FromLT2)
{
int32 r1, g1, b1, a1, r2, g2, b2, a2, mask;
- float fltsize = sp->Fltsize;
+ float fltsize = Fltsize;
#define CLAMP(v) ( (v<(float)0.) ? 0 \
: (v<(float)2.) ? FromLT2[(int)(v*fltsize)] \
: (v>(float)24.2) ? 2047 \
- : sp->LogK1*log(v*sp->LogK2) + 0.5 )
+ : LogK1*log(v*LogK2) + 0.5 )
mask = CODE_MASK;
if (n >= stride) {
@@ -981,7 +981,7 @@ horizontalDifferenceF(PixarLogState *sp, float *ip, int n, int stride, uint16 *w
g1 = (int32) CLAMP(ip[1]); wp[1] = (uint16)((g1-g2) & mask); g2 = g1;
b1 = (int32) CLAMP(ip[2]); wp[2] = (uint16)((b1-b2) & mask); b2 = b1;
}
- } else if (sp->stride == 4) {
+ } else if (stride == 4) {
r2 = wp[0] = (uint16) CLAMP(ip[0]);
g2 = wp[1] = (uint16) CLAMP(ip[1]);
b2 = wp[2] = (uint16) CLAMP(ip[2]);
@@ -1157,8 +1157,8 @@ PixarLogEncode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
for (i = 0, up = sp->tbuf; i < n; i += llen, up += llen) {
switch (sp->user_datafmt) {
case PIXARLOGDATAFMT_FLOAT:
- horizontalDifferenceF(sp, (float *)bp, llen,
- sp->stride, up, sp->FromLT2);
+ horizontalDifferenceF((float *)bp, llen,
+ sp->stride, up, sp->FromLT2);
bp += llen * sizeof(float);
break;
case PIXARLOGDATAFMT_16BIT:
@@ -1200,7 +1200,8 @@ PixarLogEncode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
}
if (sp->stream.avail_out == 0) {
tif->tif_rawcc = tif->tif_rawdatasize;
- TIFFFlushData1(tif);
+ if (!TIFFFlushData1(tif))
+ return 0;
sp->stream.next_out = tif->tif_rawdata;
sp->stream.avail_out = (uInt) tif->tif_rawdatasize; /* this is a safe typecast, as check is made already in PixarLogPreEncode */
}
@@ -1230,7 +1231,8 @@ PixarLogPostEncode(TIFF* tif)
if ((tmsize_t)sp->stream.avail_out != tif->tif_rawdatasize) {
tif->tif_rawcc =
tif->tif_rawdatasize - sp->stream.avail_out;
- TIFFFlushData1(tif);
+ if (!TIFFFlushData1(tif))
+ return 0;
sp->stream.next_out = tif->tif_rawdata;
sp->stream.avail_out = (uInt) tif->tif_rawdatasize; /* this is a safe typecast, as check is made already in PixarLogPreEncode */
}
@@ -1398,6 +1400,7 @@ TIFFInitPixarLog(TIFF* tif, int scheme)
PixarLogState* sp;
+ (void)scheme;
assert(scheme == COMPRESSION_PIXARLOG);
/*
diff --git a/tiff/libtiff/tif_predict.c b/tiff/libtiff/tif_predict.c
index b775663a..c0233974 100644
--- a/tiff/libtiff/tif_predict.c
+++ b/tiff/libtiff/tif_predict.c
@@ -116,7 +116,7 @@ PredictorSetupDecode(TIFF* tif)
TIFFDirectory* td = &tif->tif_dir;
/* Note: when PredictorSetup() fails, the effets of setupdecode() */
- /* will not be "cancelled" so setupdecode() might be robust to */
+ /* will not be "canceled" so setupdecode() might be robust to */
/* be called several times. */
if (!(*sp->setupdecode)(tif) || !PredictorSetup(tif))
return 0;
@@ -270,8 +270,8 @@ PredictorSetupEncode(TIFF* tif)
}
/* Remarks related to C standard compliance in all below functions : */
-/* - to avoid any undefined behaviour, we only operate on unsigned types */
-/* since the behaviour of "overflows" is defined (wrap over) */
+/* - to avoid any undefined behavior, we only operate on unsigned types */
+/* since the behavior of "overflows" is defined (wrap over) */
/* - when storing into the byte stream, we explicitly mask with 0xff so */
/* as to make icc -check=conversions happy (not necessary by the standard) */
diff --git a/tiff/libtiff/tif_read.c b/tiff/libtiff/tif_read.c
index 527fadd6..c4c868b1 100644
--- a/tiff/libtiff/tif_read.c
+++ b/tiff/libtiff/tif_read.c
@@ -753,7 +753,7 @@ TIFFReadRawStrip(TIFF* tif, uint32 strip, void* buf, tmsize_t size)
}
TIFF_NOSANITIZE_UNSIGNED_INT_OVERFLOW
-static uint64 NoSantizeSubUInt64(uint64 a, uint64 b)
+static uint64 NoSanitizeSubUInt64(uint64 a, uint64 b)
{
return a - b;
}
@@ -841,7 +841,7 @@ TIFFFillStrip(TIFF* tif, uint32 strip)
"Read error on strip %lu; "
"got %I64u bytes, expected %I64u",
(unsigned long) strip,
- (unsigned __int64) NoSantizeSubUInt64(tif->tif_size, TIFFGetStrileOffset(tif, strip)),
+ (unsigned __int64) NoSanitizeSubUInt64(tif->tif_size, TIFFGetStrileOffset(tif, strip)),
(unsigned __int64) bytecount);
#else
TIFFErrorExt(tif->tif_clientdata, module,
@@ -849,7 +849,7 @@ TIFFFillStrip(TIFF* tif, uint32 strip)
"Read error on strip %lu; "
"got %llu bytes, expected %llu",
(unsigned long) strip,
- (unsigned long long) NoSantizeSubUInt64(tif->tif_size, TIFFGetStrileOffset(tif, strip)),
+ (unsigned long long) NoSanitizeSubUInt64(tif->tif_size, TIFFGetStrileOffset(tif, strip)),
(unsigned long long) bytecount);
#endif
tif->tif_curstrip = NOSTRIP;
@@ -1445,8 +1445,16 @@ TIFFStartStrip(TIFF* tif, uint32 strip)
else
tif->tif_rawcc = (tmsize_t)TIFFGetStrileByteCount(tif, strip);
}
- return ((*tif->tif_predecode)(tif,
- (uint16)(strip / td->td_stripsperimage)));
+ if ((*tif->tif_predecode)(tif,
+ (uint16)(strip / td->td_stripsperimage)) == 0 ) {
+ /* Needed for example for scanline access, if tif_predecode */
+ /* fails, and we try to read the same strip again. Without invalidating */
+ /* tif_curstrip, we'd call tif_decoderow() on a possibly invalid */
+ /* codec state. */
+ tif->tif_curstrip = NOSTRIP;
+ return 0;
+ }
+ return 1;
}
/*
diff --git a/tiff/libtiff/tif_thunder.c b/tiff/libtiff/tif_thunder.c
index db6383a8..b56e3c35 100644
--- a/tiff/libtiff/tif_thunder.c
+++ b/tiff/libtiff/tif_thunder.c
@@ -112,10 +112,10 @@ ThunderDecode(TIFF* tif, uint8* op, tmsize_t maxpixels)
} else
lastpixel |= lastpixel << 4;
npixels += n;
- if (npixels < maxpixels) {
- for (; n > 0; n -= 2)
- *op++ = (uint8) lastpixel;
- }
+ if (npixels > maxpixels)
+ n -= npixels - maxpixels;
+ for (; n > 0; n -= 2)
+ *op++ = (uint8) lastpixel;
if (n == -1)
*--op &= 0xf0;
lastpixel &= 0xf;
diff --git a/tiff/libtiff/tif_unix.c b/tiff/libtiff/tif_unix.c
index 874f1feb..bea1ef78 100644
--- a/tiff/libtiff/tif_unix.c
+++ b/tiff/libtiff/tif_unix.c
@@ -162,7 +162,7 @@ _tiffMapProc(thandle_t fd, void** pbase, toff_t* psize)
{
uint64 size64 = _tiffSizeProc(fd);
tmsize_t sizem = (tmsize_t)size64;
- if ((uint64)sizem==size64) {
+ if (size64 && (uint64)sizem==size64) {
fd_as_handle_union_t fdh;
fdh.h = fd;
*pbase = (void*)
diff --git a/tiff/libtiff/tif_webp.c b/tiff/libtiff/tif_webp.c
index 22665f2d..a00478f6 100644
--- a/tiff/libtiff/tif_webp.c
+++ b/tiff/libtiff/tif_webp.c
@@ -267,6 +267,12 @@ TWebPPreDecode(TIFF* tif, uint16 s)
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;
+ }
+
if( (sp->state & LSTATE_INIT_DECODE) == 0 )
tif->tif_setupdecode(tif);
@@ -333,7 +339,7 @@ TWebPSetupEncode(TIFF* tif)
}
/* check bits per sample and data type */
- if ((nBitsPerSample != 8) && (sampleFormat != 1)) {
+ if ((nBitsPerSample != 8) || (sampleFormat != SAMPLEFORMAT_UINT)) {
TIFFErrorExt(tif->tif_clientdata, module,
"WEBP driver requires 8 bit unsigned data");
return 0;
@@ -356,7 +362,7 @@ TWebPSetupEncode(TIFF* tif)
}
if (!WebPConfigInitInternal(&sp->sEncoderConfig, WEBP_PRESET_DEFAULT,
- sp->quality_level,
+ (float)sp->quality_level,
WEBP_ENCODER_ABI_VERSION)) {
TIFFErrorExt(tif->tif_clientdata, module,
"Error creating WebP encoder configuration.");
@@ -579,7 +585,7 @@ TWebPVSetField(TIFF* tif, uint32 tag, va_list ap)
#if WEBP_ENCODER_ABI_VERSION >= 0x0100
sp->lossless = va_arg(ap, int);
if (sp->lossless){
- sp->quality_level = 100.0f;
+ sp->quality_level = 100;
}
return 1;
#else
@@ -628,6 +634,7 @@ TIFFInitWebP(TIFF* tif, int scheme)
static const char module[] = "TIFFInitWebP";
WebPState* sp;
+ (void)scheme;
assert( scheme == COMPRESSION_WEBP );
/*
@@ -656,7 +663,7 @@ TIFFInitWebP(TIFF* tif, int scheme)
tif->tif_tagmethods.vsetfield = TWebPVSetField; /* hook for codec tags */
/* Default values for codec-specific fields */
- sp->quality_level = 75.0f; /* default comp. level */
+ sp->quality_level = 75; /* default comp. level */
sp->lossless = 0; /* default to false */
sp->state = 0;
sp->nSamples = 0;
diff --git a/tiff/libtiff/tif_win32.c b/tiff/libtiff/tif_win32.c
index 088880e7..89645693 100644
--- a/tiff/libtiff/tif_win32.c
+++ b/tiff/libtiff/tif_win32.c
@@ -27,33 +27,37 @@
* Scott Wagner (wagner@itek.com), Itek Graphix, Rochester, NY USA
*/
-/*
- CreateFileA/CreateFileW return type 'HANDLE'.
-
- thandle_t is declared like
-
- DECLARE_HANDLE(thandle_t);
+#include "tiffiop.h"
- in tiffio.h.
+#include <windows.h>
- Windows (from winnt.h) DECLARE_HANDLE logic looks like
+/*
+ CreateFileA/CreateFileW return type 'HANDLE' while TIFFFdOpen() takes 'int',
+ which is formally incompatible and can even seemingly be of different size:
+ HANDLE is 64 bit under Win64, while int is still 32 bits there.
- #ifdef STRICT
- typedef void *HANDLE;
- #define DECLARE_HANDLE(name) struct name##__ { int unused; }; typedef struct name##__ *name
- #else
- typedef PVOID HANDLE;
- #define DECLARE_HANDLE(name) typedef HANDLE name
- #endif
+ However, only the lower 32 bits of a HANDLE are significant under Win64 as,
+ for interoperability reasons, they must have the same values in 32- and
+ 64-bit programs running on the same system, see
- See http://bugzilla.maptools.org/show_bug.cgi?id=1941 for problems in WIN64
- builds resulting from this. Unfortunately, the proposed patch was lost.
+ https://docs.microsoft.com/en-us/windows/win32/winprog64/interprocess-communication
+ Because of this, it is safe to define the following trivial functions for
+ casting between ints and HANDLEs, which are only really needed to avoid
+ compiler warnings (and, perhaps, to make the code slightly more clear).
+ Note that using the intermediate cast to "intptr_t" is crucial for warning
+ avoidance, as this integer type has the same size as HANDLE in all builds.
*/
-
-#include "tiffiop.h"
-#include <windows.h>
+static inline thandle_t thandle_from_int(int ifd)
+{
+ return (thandle_t)(intptr_t)ifd;
+}
+
+static inline int thandle_to_int(thandle_t fd)
+{
+ return (int)(intptr_t)fd;
+}
static tmsize_t
_tiffReadProc(thandle_t fd, void* buf, tmsize_t size)
@@ -151,9 +155,11 @@ _tiffCloseProc(thandle_t fd)
static uint64
_tiffSizeProc(thandle_t fd)
{
- ULARGE_INTEGER m;
- m.LowPart=GetFileSize(fd,&m.HighPart);
- return(m.QuadPart);
+ LARGE_INTEGER m;
+ if (GetFileSizeEx(fd,&m))
+ return(m.QuadPart);
+ else
+ return(0);
}
static int
@@ -185,7 +191,7 @@ _tiffMapProc(thandle_t fd, void** pbase, toff_t* psize)
size = _tiffSizeProc(fd);
sizem = (tmsize_t)size;
- if ((uint64)sizem!=size)
+ if (!size || (uint64)sizem!=size)
return (0);
/* By passing in 0 for the maximum file size, it specifies that we
@@ -237,7 +243,7 @@ TIFFFdOpen(int ifd, const char* name, const char* mode)
break;
}
}
- tif = TIFFClientOpen(name, mode, (thandle_t)ifd, /* FIXME: WIN64 cast to pointer warning */
+ tif = TIFFClientOpen(name, mode, thandle_from_int(ifd),
_tiffReadProc, _tiffWriteProc,
_tiffSeekProc, _tiffCloseProc, _tiffSizeProc,
fSuppressMap ? _tiffDummyMapProc : _tiffMapProc,
@@ -282,7 +288,7 @@ TIFFOpen(const char* name, const char* mode)
return ((TIFF *)0);
}
- tif = TIFFFdOpen((int)fd, name, mode); /* FIXME: WIN64 cast from pointer to int warning */
+ tif = TIFFFdOpen(thandle_to_int(fd), name, mode);
if(!tif)
CloseHandle(fd);
return tif;
@@ -337,7 +343,7 @@ TIFFOpenW(const wchar_t* name, const char* mode)
NULL, NULL);
}
- tif = TIFFFdOpen((int)fd, /* FIXME: WIN64 cast from pointer to int warning */
+ tif = TIFFFdOpen(thandle_to_int(fd),
(mbname != NULL) ? mbname : "<unknown>", mode);
if(!tif)
CloseHandle(fd);
diff --git a/tiff/libtiff/tif_write.c b/tiff/libtiff/tif_write.c
index 33e803c1..3af69ab4 100644
--- a/tiff/libtiff/tif_write.c
+++ b/tiff/libtiff/tif_write.c
@@ -533,6 +533,13 @@ TIFFSetupStrips(TIFF* tif)
isUnspecified(tif, FIELD_ROWSPERSTRIP) ?
td->td_samplesperpixel : TIFFNumberOfStrips(tif);
td->td_nstrips = td->td_stripsperimage;
+ /* TIFFWriteDirectoryTagData has a limitation to 0x80000000U bytes */
+ if( td->td_nstrips >= 0x80000000U / ((tif->tif_flags&TIFF_BIGTIFF)?0x8U:0x4U) )
+ {
+ TIFFErrorExt(tif->tif_clientdata, "TIFFSetupStrips",
+ "Too large Strip/Tile Offsets/ByteCounts arrays");
+ return 0;
+ }
if (td->td_planarconfig == PLANARCONFIG_SEPARATE)
td->td_stripsperimage /= td->td_samplesperpixel;
td->td_stripoffset_p = (uint64 *)
@@ -661,6 +668,10 @@ TIFFWriteBufferSetup(TIFF* tif, void* bp, tmsize_t size)
if (size == (tmsize_t)(-1)) {
size = (isTiled(tif) ?
tif->tif_tilesize : TIFFStripSize(tif));
+
+ /* Adds 10% margin for cases where compression would expand a bit */
+ if( size < TIFF_TMSIZE_T_MAX - size / 10 )
+ size += size / 10;
/*
* Make raw data buffer at least 8K
*/
diff --git a/tiff/libtiff/tif_zip.c b/tiff/libtiff/tif_zip.c
index c7507734..e71c312c 100644
--- a/tiff/libtiff/tif_zip.c
+++ b/tiff/libtiff/tif_zip.c
@@ -29,24 +29,22 @@
*
* ZIP (aka Deflate) Compression Support
*
- * This file is simply an interface to the zlib library written by
+ * This file is an interface to the zlib library written by
* Jean-loup Gailly and Mark Adler. You must use version 1.0 or later
- * of the library: this code assumes the 1.0 API and also depends on
- * the ability to write the zlib header multiple times (one per strip)
- * which was not possible with versions prior to 0.95. Note also that
- * older versions of this codec avoided this bug by suppressing the header
- * entirely. This means that files written with the old library cannot
- * be read; they should be converted to a different compression scheme
- * and then reconverted.
+ * of the library.
*
- * The data format used by the zlib library is described in the files
- * zlib-3.1.doc, deflate-1.1.doc and gzip-4.1.doc, available in the
- * directory ftp://ftp.uu.net/pub/archiving/zip/doc. The library was
- * last found at ftp://ftp.uu.net/pub/archiving/zip/zlib/zlib-0.99.tar.gz.
+ * Optionally, libdeflate (https://github.com/ebiggers/libdeflate) may be used
+ * to do the compression and decompression, but only for whole strips and tiles.
+ * For scanline access, zlib will be sued as a fallback.
*/
#include "tif_predict.h"
#include "zlib.h"
+#if LIBDEFLATE_SUPPORT
+#include "libdeflate.h"
+#endif
+#define LIBDEFLATE_MAX_COMPRESSION_LEVEL 12
+
#include <stdio.h>
/*
@@ -70,6 +68,12 @@ typedef struct {
z_stream stream;
int zipquality; /* compression level */
int state; /* state flags */
+ int subcodec; /* DEFLATE_SUBCODEC_ZLIB or DEFLATE_SUBCODEC_LIBDEFLATE */
+#if LIBDEFLATE_SUPPORT
+ int libdeflate_state; /* -1 = until first time ZIPEncode() / ZIPDecode() is called, 0 = use zlib, 1 = use libdeflate */
+ struct libdeflate_decompressor* libdeflate_dec;
+ struct libdeflate_compressor* libdeflate_enc;
+#endif
#define ZSTATE_INIT_DECODE 0x01
#define ZSTATE_INIT_ENCODE 0x02
@@ -132,6 +136,9 @@ ZIPPreDecode(TIFF* tif, uint16 s)
if( (sp->state & ZSTATE_INIT_DECODE) == 0 )
tif->tif_setupdecode( tif );
+#if LIBDEFLATE_SUPPORT
+ sp->libdeflate_state = -1;
+#endif
sp->stream.next_in = tif->tif_rawdata;
assert(sizeof(sp->stream.avail_in)==4); /* if this assert gets raised,
we need to simplify this code to reflect a ZLib that is likely updated
@@ -151,6 +158,77 @@ ZIPDecode(TIFF* tif, uint8* op, tmsize_t occ, uint16 s)
assert(sp != NULL);
assert(sp->state == ZSTATE_INIT_DECODE);
+#if LIBDEFLATE_SUPPORT
+ if( sp->libdeflate_state == 1 )
+ return 0;
+
+ /* If we have libdeflate support and we are asked to read a whole */
+ /* strip/tile, then go for using it */
+ do {
+ TIFFDirectory *td = &tif->tif_dir;
+
+ if( sp->libdeflate_state == 0 )
+ break;
+ if( sp->subcodec == DEFLATE_SUBCODEC_ZLIB )
+ break;
+
+ /* Check if we are in the situation where we can use libdeflate */
+ if (isTiled(tif)) {
+ if( TIFFTileSize64(tif) != (uint64)occ )
+ break;
+ } else {
+ uint32 strip_height = td->td_imagelength - tif->tif_row;
+ if (strip_height > td->td_rowsperstrip)
+ strip_height = td->td_rowsperstrip;
+ if( TIFFVStripSize64(tif, strip_height) != (uint64)occ )
+ break;
+ }
+
+ /* Check for overflow */
+ if( (size_t)tif->tif_rawcc != (uint64)tif->tif_rawcc )
+ break;
+ if( (size_t)occ != (uint64)occ )
+ break;
+
+ /* Go for decompression using libdeflate */
+ {
+ enum libdeflate_result res;
+ if( sp->libdeflate_dec == NULL )
+ {
+ sp->libdeflate_dec = libdeflate_alloc_decompressor();
+ if( sp->libdeflate_dec == NULL )
+ {
+ break;
+ }
+ }
+
+ sp->libdeflate_state = 1;
+
+ res = libdeflate_zlib_decompress(
+ sp->libdeflate_dec, tif->tif_rawcp, (size_t)tif->tif_rawcc, op, (size_t)occ, NULL);
+
+ tif->tif_rawcp += tif->tif_rawcc;
+ tif->tif_rawcc = 0;
+
+ /* We accept LIBDEFLATE_INSUFFICIENT_SPACE has a return */
+ /* There are odd files in the wild where the last strip, when */
+ /* it is smaller in height than td_rowsperstrip, actually contains */
+ /* data for td_rowsperstrip lines. Just ignore that silently. */
+ if( res != LIBDEFLATE_SUCCESS &&
+ res != LIBDEFLATE_INSUFFICIENT_SPACE )
+ {
+ TIFFErrorExt(tif->tif_clientdata, module,
+ "Decoding error at scanline %lu",
+ (unsigned long) tif->tif_row);
+ return 0;
+ }
+
+ return 1;
+ }
+ } while(0);
+ sp->libdeflate_state = 0;
+#endif /* LIBDEFLATE_SUPPORT */
+
sp->stream.next_in = tif->tif_rawcp;
sp->stream.next_out = op;
@@ -198,6 +276,7 @@ ZIPSetupEncode(TIFF* tif)
{
static const char module[] = "ZIPSetupEncode";
ZIPState* sp = EncoderState(tif);
+ int cappedQuality;
assert(sp != NULL);
if (sp->state & ZSTATE_INIT_DECODE) {
@@ -205,7 +284,11 @@ ZIPSetupEncode(TIFF* tif)
sp->state = 0;
}
- if (deflateInit(&sp->stream, sp->zipquality) != Z_OK) {
+ cappedQuality = sp->zipquality;
+ if( cappedQuality > Z_BEST_COMPRESSION )
+ cappedQuality = Z_BEST_COMPRESSION;
+
+ if (deflateInit(&sp->stream, cappedQuality) != Z_OK) {
TIFFErrorExt(tif->tif_clientdata, module, "%s", SAFE_MSG(sp));
return (0);
} else {
@@ -227,6 +310,9 @@ ZIPPreEncode(TIFF* tif, uint16 s)
if( sp->state != ZSTATE_INIT_ENCODE )
tif->tif_setupencode( tif );
+#if LIBDEFLATE_SUPPORT
+ sp->libdeflate_state = -1;
+#endif
sp->stream.next_out = tif->tif_rawdata;
assert(sizeof(sp->stream.avail_out)==4); /* if this assert gets raised,
we need to simplify this code to reflect a ZLib that is likely updated
@@ -249,6 +335,95 @@ ZIPEncode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
assert(sp->state == ZSTATE_INIT_ENCODE);
(void) s;
+
+#if LIBDEFLATE_SUPPORT
+ if( sp->libdeflate_state == 1 )
+ return 0;
+
+ /* If we have libdeflate support and we are asked to write a whole */
+ /* strip/tile, then go for using it */
+ do {
+ TIFFDirectory *td = &tif->tif_dir;
+
+ if( sp->libdeflate_state == 0 )
+ break;
+ if( sp->subcodec == DEFLATE_SUBCODEC_ZLIB )
+ break;
+
+ /* Libdeflate does not support the 0-compression level */
+ if( sp->zipquality == Z_NO_COMPRESSION )
+ break;
+
+ /* Check if we are in the situation where we can use libdeflate */
+ if (isTiled(tif)) {
+ if( TIFFTileSize64(tif) != (uint64)cc )
+ break;
+ } else {
+ uint32 strip_height = td->td_imagelength - tif->tif_row;
+ if (strip_height > td->td_rowsperstrip)
+ strip_height = td->td_rowsperstrip;
+ if( TIFFVStripSize64(tif, strip_height) != (uint64)cc )
+ break;
+ }
+
+ /* Check for overflow */
+ if( (size_t)tif->tif_rawdatasize != (uint64)tif->tif_rawdatasize )
+ break;
+ if( (size_t)cc != (uint64)cc )
+ break;
+
+ /* Go for compression using libdeflate */
+ {
+ size_t nCompressedBytes;
+ if( sp->libdeflate_enc == NULL )
+ {
+ /* To get results as good as zlib, we asked for an extra */
+ /* level of compression */
+ sp->libdeflate_enc = libdeflate_alloc_compressor(
+ sp->zipquality == Z_DEFAULT_COMPRESSION ? 7 :
+ sp->zipquality >= 6 && sp->zipquality <= 9 ? sp->zipquality + 1 :
+ sp->zipquality);
+ if( sp->libdeflate_enc == NULL )
+ {
+ TIFFErrorExt(tif->tif_clientdata, module,
+ "Cannot allocate compressor");
+ break;
+ }
+ }
+
+ /* Make sure the output buffer is large enough for the worse case. */
+ /* In TIFFWriteBufferSetup(), when libtiff allocates the buffer */
+ /* we've taken a 10% margin over the uncompressed size, which should */
+ /* be large enough even for the the worse case scenario. */
+ if( libdeflate_zlib_compress_bound(sp->libdeflate_enc, (size_t)cc) >
+ (size_t)tif->tif_rawdatasize)
+ {
+ break;
+ }
+
+ sp->libdeflate_state = 1;
+ nCompressedBytes = libdeflate_zlib_compress(
+ sp->libdeflate_enc, bp, (size_t)cc, tif->tif_rawdata, (size_t)tif->tif_rawdatasize);
+
+ if( nCompressedBytes == 0 )
+ {
+ TIFFErrorExt(tif->tif_clientdata, module,
+ "Encoder error at scanline %lu",
+ (unsigned long) tif->tif_row);
+ return 0;
+ }
+
+ tif->tif_rawcc = nCompressedBytes;
+
+ if( !TIFFFlushData1(tif) )
+ return 0;
+
+ return 1;
+ }
+ } while(0);
+ sp->libdeflate_state = 0;
+#endif /* LIBDEFLATE_SUPPORT */
+
sp->stream.next_in = bp;
assert(sizeof(sp->stream.avail_in)==4); /* if this assert gets raised,
we need to simplify this code to reflect a ZLib that is likely updated
@@ -265,7 +440,8 @@ ZIPEncode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
}
if (sp->stream.avail_out == 0) {
tif->tif_rawcc = tif->tif_rawdatasize;
- TIFFFlushData1(tif);
+ if (!TIFFFlushData1(tif))
+ return 0;
sp->stream.next_out = tif->tif_rawdata;
sp->stream.avail_out = (uint64)tif->tif_rawdatasize <= 0xFFFFFFFFU ? (uInt)tif->tif_rawdatasize : 0xFFFFFFFFU;
}
@@ -285,6 +461,11 @@ ZIPPostEncode(TIFF* tif)
ZIPState *sp = EncoderState(tif);
int state;
+#if LIBDEFLATE_SUPPORT
+ if( sp->libdeflate_state == 1 )
+ return 1;
+#endif
+
sp->stream.avail_in = 0;
do {
state = deflate(&sp->stream, Z_FINISH);
@@ -294,7 +475,8 @@ ZIPPostEncode(TIFF* tif)
if ((tmsize_t)sp->stream.avail_out != tif->tif_rawdatasize)
{
tif->tif_rawcc = tif->tif_rawdatasize - sp->stream.avail_out;
- TIFFFlushData1(tif);
+ if (!TIFFFlushData1(tif))
+ return 0;
sp->stream.next_out = tif->tif_rawdata;
sp->stream.avail_out = (uint64)tif->tif_rawdatasize <= 0xFFFFFFFFU ? (uInt)tif->tif_rawdatasize : 0xFFFFFFFFU;
}
@@ -327,6 +509,14 @@ ZIPCleanup(TIFF* tif)
inflateEnd(&sp->stream);
sp->state = 0;
}
+
+#if LIBDEFLATE_SUPPORT
+ if( sp->libdeflate_dec )
+ libdeflate_free_decompressor(sp->libdeflate_dec);
+ if( sp->libdeflate_enc )
+ libdeflate_free_compressor(sp->libdeflate_enc);
+#endif
+
_TIFFfree(sp);
tif->tif_data = NULL;
@@ -342,15 +532,55 @@ ZIPVSetField(TIFF* tif, uint32 tag, va_list ap)
switch (tag) {
case TIFFTAG_ZIPQUALITY:
sp->zipquality = (int) va_arg(ap, int);
- if ( sp->state&ZSTATE_INIT_ENCODE ) {
+ if( sp->zipquality < Z_DEFAULT_COMPRESSION ||
+ sp->zipquality > LIBDEFLATE_MAX_COMPRESSION_LEVEL ) {
+ TIFFErrorExt(tif->tif_clientdata, module,
+ "Invalid ZipQuality value. Should be in [-1,%d] range",
+ LIBDEFLATE_MAX_COMPRESSION_LEVEL);
+ return 0;
+ }
+
+ if ( sp->state&ZSTATE_INIT_ENCODE ) {
+ int cappedQuality = sp->zipquality;
+ if( cappedQuality > Z_BEST_COMPRESSION )
+ cappedQuality = Z_BEST_COMPRESSION;
if (deflateParams(&sp->stream,
- sp->zipquality, Z_DEFAULT_STRATEGY) != Z_OK) {
+ cappedQuality, Z_DEFAULT_STRATEGY) != Z_OK) {
TIFFErrorExt(tif->tif_clientdata, module, "ZLib error: %s",
SAFE_MSG(sp));
return (0);
}
}
+
+#if LIBDEFLATE_SUPPORT
+ if( sp->libdeflate_enc )
+ {
+ libdeflate_free_compressor(sp->libdeflate_enc);
+ sp->libdeflate_enc = NULL;
+ }
+#endif
+
return (1);
+
+ case TIFFTAG_DEFLATE_SUBCODEC:
+ sp->subcodec = (int) va_arg(ap, int);
+ if( sp->subcodec != DEFLATE_SUBCODEC_ZLIB &&
+ sp->subcodec != DEFLATE_SUBCODEC_LIBDEFLATE )
+ {
+ TIFFErrorExt(tif->tif_clientdata, module,
+ "Invalid DeflateCodec value.");
+ return 0;
+ }
+#if !LIBDEFLATE_SUPPORT
+ if( sp->subcodec == DEFLATE_SUBCODEC_LIBDEFLATE )
+ {
+ TIFFErrorExt(tif->tif_clientdata, module,
+ "DeflateCodec = DEFLATE_SUBCODEC_LIBDEFLATE unsupported in this build");
+ return 0;
+ }
+#endif
+ return 1;
+
default:
return (*sp->vsetparent)(tif, tag, ap);
}
@@ -366,6 +596,11 @@ ZIPVGetField(TIFF* tif, uint32 tag, va_list ap)
case TIFFTAG_ZIPQUALITY:
*va_arg(ap, int*) = sp->zipquality;
break;
+
+ case TIFFTAG_DEFLATE_SUBCODEC:
+ *va_arg(ap, int*) = sp->subcodec;
+ break;
+
default:
return (*sp->vgetparent)(tif, tag, ap);
}
@@ -374,6 +609,7 @@ ZIPVGetField(TIFF* tif, uint32 tag, va_list ap)
static const TIFFField zipFields[] = {
{ TIFFTAG_ZIPQUALITY, 0, 0, TIFF_ANY, 0, TIFF_SETGET_INT, TIFF_SETGET_UNDEFINED, FIELD_PSEUDO, TRUE, FALSE, "", NULL },
+ { TIFFTAG_DEFLATE_SUBCODEC, 0, 0, TIFF_ANY, 0, TIFF_SETGET_INT, TIFF_SETGET_UNDEFINED, FIELD_PSEUDO, TRUE, FALSE, "", NULL },
};
int
@@ -384,6 +620,9 @@ TIFFInitZIP(TIFF* tif, int scheme)
assert( (scheme == COMPRESSION_DEFLATE)
|| (scheme == COMPRESSION_ADOBE_DEFLATE));
+#ifdef NDEBUG
+ (void)scheme;
+#endif
/*
* Merge codec-specific tag information.
@@ -397,7 +636,7 @@ TIFFInitZIP(TIFF* tif, int scheme)
/*
* Allocate state block so tag methods have storage to record values.
*/
- tif->tif_data = (uint8*) _TIFFmalloc(sizeof (ZIPState));
+ tif->tif_data = (uint8*) _TIFFcalloc(sizeof (ZIPState), 1);
if (tif->tif_data == NULL)
goto bad;
sp = ZState(tif);
@@ -417,6 +656,11 @@ TIFFInitZIP(TIFF* tif, int scheme)
/* Default values for codec-specific fields */
sp->zipquality = Z_DEFAULT_COMPRESSION; /* default comp. level */
sp->state = 0;
+#if LIBDEFLATE_SUPPORT
+ sp->subcodec = DEFLATE_SUBCODEC_LIBDEFLATE;
+#else
+ sp->subcodec = DEFLATE_SUBCODEC_ZLIB;
+#endif
/*
* Install codec methods.
diff --git a/tiff/libtiff/tif_zstd.c b/tiff/libtiff/tif_zstd.c
index 21c935e2..66135e03 100644
--- a/tiff/libtiff/tif_zstd.c
+++ b/tiff/libtiff/tif_zstd.c
@@ -260,7 +260,8 @@ ZSTDEncode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
}
if( sp->out_buffer.pos == sp->out_buffer.size ) {
tif->tif_rawcc = tif->tif_rawdatasize;
- TIFFFlushData1(tif);
+ if (!TIFFFlushData1(tif))
+ return 0;
sp->out_buffer.dst = tif->tif_rawcp;
sp->out_buffer.pos = 0;
}
@@ -289,7 +290,8 @@ ZSTDPostEncode(TIFF* tif)
}
if( sp->out_buffer.pos > 0 ) {
tif->tif_rawcc = sp->out_buffer.pos;
- TIFFFlushData1(tif);
+ if (!TIFFFlushData1(tif))
+ return 0;
sp->out_buffer.dst = tif->tif_rawcp;
sp->out_buffer.pos = 0;
}
diff --git a/tiff/libtiff/tiff.h b/tiff/libtiff/tiff.h
index 5b0a0c90..2d4a4767 100644
--- a/tiff/libtiff/tiff.h
+++ b/tiff/libtiff/tiff.h
@@ -119,6 +119,11 @@ typedef struct {
* Tag data type information.
*
* Note: RATIONALs are the ratio of two 32-bit integer values.
+ *--:
+ * Note2: TIFF_IFD8 data type is used in tiffFields[]-tag definition in order to distinguish the write-handling
+ of those tags between ClassicTIFF and BigTiff:
+ For ClassicTIFF libtiff writes a 32-bit value and the TIFF_IFD type-id into the file
+ For BigTIFF libtiff writes a 64-bit value and the TIFF_IFD8 type-id into the file
*/
typedef enum {
TIFF_NOTYPE = 0, /* placeholder */
@@ -375,6 +380,7 @@ typedef enum {
January 2004 */
#define TIFFTAG_OPIIMAGEID 32781 /* %OPI ImageID
[Adobe TIFF technote] */
+#define TIFFTAG_TIFFANNOTATIONDATA 32932 /* http://web.archive.org/web/20050309141348/http://www.kofile.com/support%20pro/faqs/annospec.htm */
/* tags 32952-32956 are private tags registered to Island Graphics */
#define TIFFTAG_REFPTS 32953 /* image reference points */
#define TIFFTAG_REGIONTACKPOINT 32954 /* region-xform tack point */
@@ -409,8 +415,23 @@ typedef enum {
#define TIFFTAG_CFAPATTERN 33422 /* color filter array pattern */
/* tag 33432 is listed in the 6.0 spec w/ unknown ownership */
#define TIFFTAG_COPYRIGHT 33432 /* copyright string */
+/* Tags 33445-33452 are used for GEL fileformat, see
+ * http://research.stowers-institute.org/mcm/efg/ScientificSoftware/Utility/TiffTags/GEL-FileFormat.pdf
+ */
+#define TIFFTAG_MD_FILETAG 33445 /* http://research.stowers-institute.org/mcm/efg/ScientificSoftware/Utility/TiffTags/GEL-FileFormat.pdf */
+#define TIFFTAG_MD_SCALEPIXEL 33446 /* http://research.stowers-institute.org/mcm/efg/ScientificSoftware/Utility/TiffTags/GEL-FileFormat.pdf */
+#define TIFFTAG_MD_COLORTABLE 33447 /* http://research.stowers-institute.org/mcm/efg/ScientificSoftware/Utility/TiffTags/GEL-FileFormat.pdf */
+#define TIFFTAG_MD_LABNAME 33448 /* http://research.stowers-institute.org/mcm/efg/ScientificSoftware/Utility/TiffTags/GEL-FileFormat.pdf */
+#define TIFFTAG_MD_SAMPLEINFO 33449 /* http://research.stowers-institute.org/mcm/efg/ScientificSoftware/Utility/TiffTags/GEL-FileFormat.pdf */
+#define TIFFTAG_MD_PREPDATE 33450 /* http://research.stowers-institute.org/mcm/efg/ScientificSoftware/Utility/TiffTags/GEL-FileFormat.pdf */
+#define TIFFTAG_MD_PREPTIME 33451 /* http://research.stowers-institute.org/mcm/efg/ScientificSoftware/Utility/TiffTags/GEL-FileFormat.pdf */
+#define TIFFTAG_MD_FILEUNITS 33452 /* http://research.stowers-institute.org/mcm/efg/ScientificSoftware/Utility/TiffTags/GEL-FileFormat.pdf */
/* IPTC TAG from RichTIFF specifications */
#define TIFFTAG_RICHTIFFIPTC 33723
+#define TIFFTAG_INGR_PACKET_DATA_TAG 33918 /* Intergraph Application specific storage. */
+#define TIFFTAG_INGR_FLAG_REGISTERS 33919 /* Intergraph Application specific flags. */
+#define TIFFTAG_IRASB_TRANSORMATION_MATRIX 33920 /* Originally part of Intergraph's GeoTIFF tags, but likely understood by IrasB only. */
+#define TIFFTAG_MODELTIEPOINTTAG 33922 /* GeoTIFF */
/* 34016-34029 are reserved for ANSI IT8 TIFF/IT <dkelly@apago.com) */
#define TIFFTAG_IT8SITE 34016 /* site name */
#define TIFFTAG_IT8COLORSEQUENCE 34017 /* color seq. [RGB,CMYK,etc] */
@@ -432,6 +453,7 @@ typedef enum {
#define TIFFTAG_IT8CMYKEQUIVALENT 34032 /* CMYK color equivalents */
/* tags 34232-34236 are private tags registered to Texas Instruments */
#define TIFFTAG_FRAMECOUNT 34232 /* Sequence Frame Count */
+#define TIFFTAG_MODELTRANSFORMATIONTAG 34264 /* Used in interchangeable GeoTIFF files */
/* tag 34377 is private tag registered to Adobe for PhotoShop */
#define TIFFTAG_PHOTOSHOP 34377
/* tags 34665, 34853 and 40965 are documented in EXIF specification */
@@ -451,7 +473,15 @@ typedef enum {
#define TIFFTAG_STONITS 37439 /* Sample value to Nits */
/* tag 34929 is a private tag registered to FedEx */
#define TIFFTAG_FEDEX_EDR 34929 /* unknown use */
+#define TIFFTAG_IMAGESOURCEDATA 37724 /* http://justsolve.archiveteam.org/wiki/PSD, http://www.adobe.com/devnet-apps/photoshop/fileformatashtml/ */
#define TIFFTAG_INTEROPERABILITYIFD 40965 /* Pointer to Interoperability private directory */
+#define TIFFTAG_GDAL_METADATA 42112 /* Used by the GDAL library */
+#define TIFFTAG_GDAL_NODATA 42113 /* Used by the GDAL library */
+#define TIFFTAG_OCE_SCANJOB_DESCRIPTION 50215 /* Used in the Oce scanning process */
+#define TIFFTAG_OCE_APPLICATION_SELECTOR 50216 /* Used in the Oce scanning process. */
+#define TIFFTAG_OCE_IDENTIFICATION_NUMBER 50217
+#define TIFFTAG_OCE_IMAGELOGIC_CHARACTERISTICS 50218
+
/* 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 */
@@ -535,6 +565,17 @@ typedef enum {
into ICC profile space */
#define TIFFTAG_CURRENTICCPROFILE 50833 /* & */
#define TIFFTAG_CURRENTPREPROFILEMATRIX 50834 /* & */
+
+#define TIFFTAG_RPCCOEFFICIENT 50844 /* Define by GDAL for geospatial georeferencing through RPC: http://geotiff.maptools.org/rpc_prop.html */
+
+#define TIFFTAG_ALIAS_LAYER_METADATA 50784 /* Alias Sketchbook Pro layer usage description. */
+
+/* GeoTIFF DGIWG */
+#define TIFFTAG_TIFF_RSID 50908 /* https://www.awaresystems.be/imaging/tiff/tifftags/tiff_rsid.html */
+#define TIFFTAG_GEO_METADATA 50909 /* https://www.awaresystems.be/imaging/tiff/tifftags/geo_metadata.html */
+
+#define TIFFTAG_EXTRACAMERAPROFILES 50933 /* http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/products/photoshop/pdfs/dng_spec_1.4.0.0.pdf */
+
/* tag 65535 is an undefined tag used by Eastman Kodak */
#define TIFFTAG_DCSHUESHIFTVALUES 65535 /* hue shift correction data */
@@ -615,8 +656,11 @@ typedef enum {
#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 */
+#define TIFFTAG_WEBP_LEVEL 65568 /* WebP compression level */
+#define TIFFTAG_WEBP_LOSSLESS 65569 /* WebP lossless/lossy */
+#define TIFFTAG_DEFLATE_SUBCODEC 65570 /* ZIP codec: to get/set the sub-codec to use. Will default to libdeflate when available */
+#define DEFLATE_SUBCODEC_ZLIB 0
+#define DEFLATE_SUBCODEC_LIBDEFLATE 1
/*
* EXIF tags
@@ -626,8 +670,8 @@ typedef enum {
#define EXIFTAG_EXPOSUREPROGRAM 34850 /* Exposure program */
#define EXIFTAG_SPECTRALSENSITIVITY 34852 /* Spectral sensitivity */
#define EXIFTAG_ISOSPEEDRATINGS 34855 /* ISO speed rating */
-#define EXIFTAG_OECF 34856 /* Optoelectric conversion
- factor */
+#define EXIFTAG_PHOTOGRAPHICSENSITIVITY 34855 /* Photographic Sensitivity (new name for tag 34855) */
+#define EXIFTAG_OECF 34856 /* Optoelectric conversion factor */
#define EXIFTAG_EXIFVERSION 36864 /* Exif version */
#define EXIFTAG_DATETIMEORIGINAL 36867 /* Date and time of original
data generation */
@@ -679,10 +723,71 @@ typedef enum {
#define EXIFTAG_SHARPNESS 41994 /* Sharpness */
#define EXIFTAG_DEVICESETTINGDESCRIPTION 41995 /* Device settings description */
#define EXIFTAG_SUBJECTDISTANCERANGE 41996 /* Subject distance range */
-#define EXIFTAG_GAINCONTROL 41991 /* Gain control */
-#define EXIFTAG_GAINCONTROL 41991 /* Gain control */
#define EXIFTAG_IMAGEUNIQUEID 42016 /* Unique image ID */
+/*--: New for EXIF-Version 2.32, May 2019 ... */
+#define EXIFTAG_SENSITIVITYTYPE 34864 /* The SensitivityType tag indicates which one of the parameters of ISO12232 is the PhotographicSensitivity tag. */
+#define EXIFTAG_STANDARDOUTPUTSENSITIVITY 34865 /* This tag indicates the standard output sensitivity value of a camera or input device defined in ISO 12232. */
+#define EXIFTAG_RECOMMENDEDEXPOSUREINDEX 34866 /* recommended exposure index */
+#define EXIFTAG_ISOSPEED 34867 /* ISO speed value */
+#define EXIFTAG_ISOSPEEDLATITUDEYYY 34868 /* ISO speed latitude yyy */
+#define EXIFTAG_ISOSPEEDLATITUDEZZZ 34869 /* ISO speed latitude zzz */
+#define EXIFTAG_OFFSETTIME 36880 /* offset from UTC of the time of DateTime tag. */
+#define EXIFTAG_OFFSETTIMEORIGINAL 36881 /* offset from UTC of the time of DateTimeOriginal tag. */
+#define EXIFTAG_OFFSETTIMEDIGITIZED 36882 /* offset from UTC of the time of DateTimeDigitized tag. */
+#define EXIFTAG_TEMPERATURE 37888 /* Temperature as the ambient situation at the shot in dergee Celsius */
+#define EXIFTAG_HUMIDITY 37889 /* Humidity as the ambient situation at the shot in percent */
+#define EXIFTAG_PRESSURE 37890 /* Pressure as the ambient situation at the shot hecto-Pascal (hPa) */
+#define EXIFTAG_WATERDEPTH 37891 /* WaterDepth as the ambient situation at the shot in meter (m) */
+#define EXIFTAG_ACCELERATION 37892 /* Acceleration (a scalar regardless of direction) as the ambient situation at the shot in units of mGal (10-5 m/s^2) */
+#define EXIFTAG_CAMERAELEVATIONANGLE 37893 /* Elevation/depression. angle of the orientation of the camera(imaging optical axis) as the ambient situation at the shot in degree from -180deg to +180deg. */
+#define EXIFTAG_CAMERAOWNERNAME 42032 /* owner of a camera */
+#define EXIFTAG_BODYSERIALNUMBER 42033 /* serial number of the body of the camera */
+#define EXIFTAG_LENSSPECIFICATION 42034 /* minimum focal length (in mm), maximum focal length (in mm), minimum F number in the minimum focal length, and minimum F number in the maximum focal length, */
+#define EXIFTAG_LENSMAKE 42035 /* the lens manufacturer */
+#define EXIFTAG_LENSMODEL 42036 /* the lens model name and model number */
+#define EXIFTAG_LENSSERIALNUMBER 42037 /* the serial number of the interchangeable lens */
+#define EXIFTAG_GAMMA 42240 /* value of coefficient gamma */
+#define EXIFTAG_COMPOSITEIMAGE 42080 /* composite image */
+#define EXIFTAG_SOURCEIMAGENUMBEROFCOMPOSITEIMAGE 42081 /* source image number of composite image */
+#define EXIFTAG_SOURCEEXPOSURETIMESOFCOMPOSITEIMAGE 42082 /* source exposure times of composite image */
+
+/*
+ * EXIF-GPS tags (Version 2.31, July 2016)
+ */
+#define GPSTAG_VERSIONID 0 /* Indicates the version of GPSInfoIFD. */
+#define GPSTAG_LATITUDEREF 1 /* Indicates whether the latitude is north or south latitude. */
+#define GPSTAG_LATITUDE 2 /* Indicates the latitude. */
+#define GPSTAG_LONGITUDEREF 3 /* Indicates whether the longitude is east or west longitude. */
+#define GPSTAG_LONGITUDE 4 /* Indicates the longitude. */
+#define GPSTAG_ALTITUDEREF 5 /* Indicates the altitude used as the reference altitude. */
+#define GPSTAG_ALTITUDE 6 /* Indicates the altitude based on the reference in GPSAltitudeRef. */
+#define GPSTAG_TIMESTAMP 7 /* Indicates the time as UTC (Coordinated Universal Time). */
+#define GPSTAG_SATELLITES 8 /* Indicates the GPS satellites used for measurements. */
+#define GPSTAG_STATUS 9 /* Indicates the status of the GPS receiver when the image is recorded. */
+#define GPSTAG_MEASUREMODE 10 /* Indicates the GPS measurement mode. */
+#define GPSTAG_DOP 11 /* Indicates the GPS DOP (data degree of precision). */
+#define GPSTAG_SPEEDREF 12 /* Indicates the unit used to express the GPS receiver speed of movement. */
+#define GPSTAG_SPEED 13 /* Indicates the speed of GPS receiver movement. */
+#define GPSTAG_TRACKREF 14 /* Indicates the reference for giving the direction of GPS receiver movement. */
+#define GPSTAG_TRACK 15 /* Indicates the direction of GPS receiver movement. */
+#define GPSTAG_IMGDIRECTIONREF 16 /* Indicates the reference for giving the direction of the image when it is captured. */
+#define GPSTAG_IMGDIRECTION 17 /* Indicates the direction of the image when it was captured. */
+#define GPSTAG_MAPDATUM 18 /* Indicates the geodetic survey data used by the GPS receiver. (e.g. WGS-84) */
+#define GPSTAG_DESTLATITUDEREF 19 /* Indicates whether the latitude of the destination point is north or south latitude. */
+#define GPSTAG_DESTLATITUDE 20 /* Indicates the latitude of the destination point. */
+#define GPSTAG_DESTLONGITUDEREF 21 /* Indicates whether the longitude of the destination point is east or west longitude. */
+#define GPSTAG_DESTLONGITUDE 22 /* Indicates the longitude of the destination point. */
+#define GPSTAG_DESTBEARINGREF 23 /* Indicates the reference used for giving the bearing to the destination point. */
+#define GPSTAG_DESTBEARING 24 /* Indicates the bearing to the destination point. */
+#define GPSTAG_DESTDISTANCEREF 25 /* Indicates the unit used to express the distance to the destination point. */
+#define GPSTAG_DESTDISTANCE 26 /* Indicates the distance to the destination point. */
+#define GPSTAG_PROCESSINGMETHOD 27 /* A character string recording the name of the method used for location finding. */
+#define GPSTAG_AREAINFORMATION 28 /* A character string recording the name of the GPS area. */
+#define GPSTAG_DATESTAMP 29 /* A character string recording date and time information relative to UTC (Coordinated Universal Time). */
+#define GPSTAG_DIFFERENTIAL 30 /* Indicates whether differential correction is applied to the GPS receiver. */
+#define GPSTAG_GPSHPOSITIONINGERROR 31 /* Indicates horizontal positioning errors in meters. */
+
#endif /* _TIFF_ */
/* vim: set ts=8 sts=8 sw=8 noet: */
diff --git a/tiff/libtiff/tiffconf.h.cmake.in b/tiff/libtiff/tiffconf.h.cmake.in
index 59542f1e..9b4b0328 100644
--- a/tiff/libtiff/tiffconf.h.cmake.in
+++ b/tiff/libtiff/tiffconf.h.cmake.in
@@ -87,6 +87,9 @@
/* Support Deflate compression */
#cmakedefine ZIP_SUPPORT 1
+/* Support libdeflate enhanced compression */
+#cmakedefine LIBDEFLATE_SUPPORT 1
+
/* Support strip chopping (whether or not to convert single-strip uncompressed
images to mutiple strips of ~8Kb to reduce memory usage) */
#cmakedefine STRIPCHOP_DEFAULT 1
diff --git a/tiff/libtiff/tiffconf.h.in b/tiff/libtiff/tiffconf.h.in
index 5de30c9b..9bd6a2de 100644
--- a/tiff/libtiff/tiffconf.h.in
+++ b/tiff/libtiff/tiffconf.h.in
@@ -84,6 +84,9 @@
/* Support Deflate compression */
#undef ZIP_SUPPORT
+/* Support libdeflate enhanced compression */
+#undef LIBDEFLATE_SUPPORT
+
/* Support strip chopping (whether or not to convert single-strip uncompressed
images to mutiple strips of ~8Kb to reduce memory usage) */
#undef STRIPCHOP_DEFAULT
diff --git a/tiff/libtiff/tiffio.h b/tiff/libtiff/tiffio.h
index a626a764..a4512434 100644
--- a/tiff/libtiff/tiffio.h
+++ b/tiff/libtiff/tiffio.h
@@ -261,8 +261,10 @@ typedef struct {
#define LOGLUV_PUBLIC 1
#endif
-#if !defined(__GNUC__) && !defined(__attribute__)
-# define __attribute__(x) /*nothing*/
+#if defined(__GNUC__) || defined(__attribute__)
+# define TIFF_ATTRIBUTE(x) __attribute__(x)
+#else
+# define TIFF_ATTRIBUTE(x) /*nothing*/
#endif
#if defined(c_plusplus) || defined(__cplusplus)
@@ -350,6 +352,7 @@ extern int TIFFVGetFieldDefaulted(TIFF* tif, uint32 tag, va_list ap);
extern int TIFFReadDirectory(TIFF* tif);
extern int TIFFReadCustomDirectory(TIFF* tif, toff_t diroff, const TIFFFieldArray* infoarray);
extern int TIFFReadEXIFDirectory(TIFF* tif, toff_t diroff);
+extern int TIFFReadGPSDirectory(TIFF* tif, toff_t diroff);
extern uint64 TIFFScanlineSize64(TIFF* tif);
extern tmsize_t TIFFScanlineSize(TIFF* tif);
extern uint64 TIFFRasterScanlineSize64(TIFF* tif);
@@ -400,6 +403,7 @@ extern void TIFFFreeDirectory(TIFF*);
extern int TIFFCreateDirectory(TIFF*);
extern int TIFFCreateCustomDirectory(TIFF*,const TIFFFieldArray*);
extern int TIFFCreateEXIFDirectory(TIFF*);
+extern int TIFFCreateGPSDirectory(TIFF*);
extern int TIFFLastDirectory(TIFF*);
extern int TIFFSetDirectory(TIFF*, uint16);
extern int TIFFSetSubDirectory(TIFF*, uint64);
@@ -453,10 +457,10 @@ extern TIFF* TIFFClientOpen(const char*, const char*,
TIFFMapFileProc, TIFFUnmapFileProc);
extern const char* TIFFFileName(TIFF*);
extern const char* TIFFSetFileName(TIFF*, const char *);
-extern void TIFFError(const char*, const char*, ...) __attribute__((__format__ (__printf__,2,3)));
-extern void TIFFErrorExt(thandle_t, const char*, const char*, ...) __attribute__((__format__ (__printf__,3,4)));
-extern void TIFFWarning(const char*, const char*, ...) __attribute__((__format__ (__printf__,2,3)));
-extern void TIFFWarningExt(thandle_t, const char*, const char*, ...) __attribute__((__format__ (__printf__,3,4)));
+extern void TIFFError(const char*, const char*, ...) TIFF_ATTRIBUTE((__format__ (__printf__,2,3)));
+extern void TIFFErrorExt(thandle_t, const char*, const char*, ...) TIFF_ATTRIBUTE((__format__ (__printf__,3,4)));
+extern void TIFFWarning(const char*, const char*, ...) TIFF_ATTRIBUTE((__format__ (__printf__,2,3)));
+extern void TIFFWarningExt(thandle_t, const char*, const char*, ...) TIFF_ATTRIBUTE((__format__ (__printf__,3,4)));
extern TIFFErrorHandler TIFFSetErrorHandler(TIFFErrorHandler);
extern TIFFErrorHandlerExt TIFFSetErrorHandlerExt(TIFFErrorHandlerExt);
extern TIFFErrorHandler TIFFSetWarningHandler(TIFFErrorHandler);
diff --git a/tiff/libtiff/tiffiop.h b/tiff/libtiff/tiffiop.h
index 900f4786..b22acb3c 100644
--- a/tiff/libtiff/tiffiop.h
+++ b/tiff/libtiff/tiffiop.h
@@ -34,22 +34,6 @@
# include <fcntl.h>
#endif
-#ifndef O_RDONLY
-#define O_RDONLY _O_RDONLY
-#endif
-#ifndef O_WRONLY
-#define O_WRONLY _O_WRONLY
-#endif
-#ifndef O_RDWR
-#define O_RDWR _O_RDWR
-#endif
-#ifndef O_CREAT
-#define O_CREAT _O_CREAT
-#endif
-#ifndef O_TRUNC
-#define O_TRUNC _O_TRUNC
-#endif
-
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
@@ -71,13 +55,11 @@ extern void *lfind(const void *, const void *, size_t *, size_t,
int (*)(const void *, const void *));
#endif
-#if !defined(__WIN32__)
#if !defined(HAVE_SNPRINTF) && !defined(HAVE__SNPRINTF)
#undef snprintf
#define snprintf _TIFF_snprintf_f
extern int snprintf(char* str, size_t size, const char* format, ...);
#endif
-#endif
#include "tiffio.h"
@@ -386,6 +368,9 @@ extern uint32 _TIFFDefaultStripSize(TIFF* tif, uint32 s);
extern void _TIFFDefaultTileSize(TIFF* tif, uint32* tw, uint32* th);
extern int _TIFFDataSize(TIFFDataType type);
+/*--: Rational2Double: Return size of TIFFSetGetFieldType in bytes. */
+extern int _TIFFSetGetFieldSize(TIFFSetGetFieldType setgettype);
+
extern void _TIFFsetByteArray(void**, void*, uint32);
extern void _TIFFsetString(char**, char*);
extern void _TIFFsetShortArray(uint16**, uint16*, uint32);
diff --git a/tiff/libtiff/tiffvers.h b/tiff/libtiff/tiffvers.h
index aa3f613e..0cce798b 100644
--- a/tiff/libtiff/tiffvers.h
+++ b/tiff/libtiff/tiffvers.h
@@ -1,4 +1,4 @@
-#define TIFFLIB_VERSION_STR "LIBTIFF, Version 4.1.0\nCopyright (c) 1988-1996 Sam Leffler\nCopyright (c) 1991-1996 Silicon Graphics, Inc."
+#define TIFFLIB_VERSION_STR "LIBTIFF, Version 4.2.0\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
@@ -6,4 +6,4 @@
* version checking should be done based on the
* string returned by TIFFGetVersion.
*/
-#define TIFFLIB_VERSION 20191103
+#define TIFFLIB_VERSION 20201219
diff --git a/tiff/man/Makefile.in b/tiff/man/Makefile.in
index f5c9bf0c..4568bfe7 100644
--- a/tiff/man/Makefile.in
+++ b/tiff/man/Makefile.in
@@ -1,7 +1,7 @@
-# Makefile.in generated by automake 1.16.1 from Makefile.am.
+# Makefile.in generated by automake 1.16.2 from Makefile.am.
# @configure_input@
-# Copyright (C) 1994-2018 Free Software Foundation, Inc.
+# Copyright (C) 1994-2020 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
diff --git a/tiff/man/TIFFGetField.3tiff b/tiff/man/TIFFGetField.3tiff
index c2fd025f..431f4ae9 100644
--- a/tiff/man/TIFFGetField.3tiff
+++ b/tiff/man/TIFFGetField.3tiff
@@ -22,7 +22,7 @@
.\" OF THIS SOFTWARE.
.\"
.if n .po 0
-.TH TIFFGetField 3TIFF "March 18, 2005" "libtiff"
+.TH TIFFGetField 3TIFF "March 29, 2020" "libtiff"
.SH NAME
TIFFGetField, TIFFVGetField \- get the value(s) of a tag in an open
.SM TIFF
@@ -102,77 +102,77 @@ meaning of each tag and their possible values.
.ta \w'TIFFTAG_CONSECUTIVEBADFAXLINES'u+2n +\w'Count'u+2n +\w'TIFFFaxFillFunc*'u+2n
\fITag Name\fP \fICount\fP \fITypes\fP \fINotes\fP
.sp 5p
-TIFFTAG_ARTIST 1 char**
+TIFFTAG_ARTIST 1 const char**
TIFFTAG_BADFAXLINES 1 uint32*
TIFFTAG_BITSPERSAMPLE 1 uint16*
TIFFTAG_CLEANFAXDATA 1 uint16*
-TIFFTAG_COLORMAP 3 uint16** 1<<BitsPerSample arrays
+TIFFTAG_COLORMAP 3 const uint16** 1<<BitsPerSample arrays
TIFFTAG_COMPRESSION 1 uint16*
TIFFTAG_CONSECUTIVEBADFAXLINES 1 uint32*
-TIFFTAG_COPYRIGHT 1 char**
+TIFFTAG_COPYRIGHT 1 const char**
TIFFTAG_DATATYPE 1 uint16*
-TIFFTAG_DATETIME 1 char**
-TIFFTAG_DOCUMENTNAME 1 char**
+TIFFTAG_DATETIME 1 const char**
+TIFFTAG_DOCUMENTNAME 1 const char**
TIFFTAG_DOTRANGE 2 uint16*
-TIFFTAG_EXTRASAMPLES 2 uint16*,uint16** count & types array
+TIFFTAG_EXTRASAMPLES 2 uint16*,const uint16** count & types array
TIFFTAG_FAXFILLFUNC 1 TIFFFaxFillFunc* G3/G4 compression pseudo-tag
TIFFTAG_FAXMODE 1 int* G3/G4 compression pseudo-tag
TIFFTAG_FILLORDER 1 uint16*
TIFFTAG_GROUP3OPTIONS 1 uint32*
TIFFTAG_GROUP4OPTIONS 1 uint32*
TIFFTAG_HALFTONEHINTS 2 uint16*
-TIFFTAG_HOSTCOMPUTER 1 char**
-TIFFTAG_ICCPROFILE 2 uint32*,void** count, profile data
+TIFFTAG_HOSTCOMPUTER 1 const char**
+TIFFTAG_ICCPROFILE 2 const uint32*,const void** count, profile data
TIFFTAG_IMAGEDEPTH 1 uint32*
-TIFFTAG_IMAGEDESCRIPTION 1 char**
+TIFFTAG_IMAGEDESCRIPTION 1 const char**
TIFFTAG_IMAGELENGTH 1 uint32*
TIFFTAG_IMAGEWIDTH 1 uint32*
-TIFFTAG_INKNAMES 1 char**
+TIFFTAG_INKNAMES 1 const char**
TIFFTAG_INKSET 1 uint16*
TIFFTAG_JPEGCOLORMODE 1 int* JPEG pseudo-tag
TIFFTAG_JPEGQUALITY 1 int* JPEG pseudo-tag
-TIFFTAG_JPEGTABLES 2 uint32*,void** count & tables
+TIFFTAG_JPEGTABLES 2 uint32*,const void** count & tables
TIFFTAG_JPEGTABLESMODE 1 int* JPEG pseudo-tag
-TIFFTAG_MAKE 1 char**
+TIFFTAG_MAKE 1 const char**
TIFFTAG_MATTEING 1 uint16*
TIFFTAG_MAXSAMPLEVALUE 1 uint16*
TIFFTAG_MINSAMPLEVALUE 1 uint16*
-TIFFTAG_MODEL 1 char**
+TIFFTAG_MODEL 1 const char**
TIFFTAG_ORIENTATION 1 uint16*
-TIFFTAG_PAGENAME 1 char**
+TIFFTAG_PAGENAME 1 const char**
TIFFTAG_PAGENUMBER 2 uint16*
TIFFTAG_PHOTOMETRIC 1 uint16*
-TIFFTAG_PHOTOSHOP 2 uint32*,void** count, data
+TIFFTAG_PHOTOSHOP 2 uint32*,const void** count, data
TIFFTAG_PLANARCONFIG 1 uint16*
TIFFTAG_PREDICTOR 1 uint16*
-TIFFTAG_PRIMARYCHROMATICITIES 1 float** 6-entry array
-TIFFTAG_REFERENCEBLACKWHITE 1 float** 6-entry array
+TIFFTAG_PRIMARYCHROMATICITIES 1 const float** 6-entry array
+TIFFTAG_REFERENCEBLACKWHITE 1 const float** 6-entry array
TIFFTAG_RESOLUTIONUNIT 1 uint16*
-TIFFTAG_RICHTIFFIPTC 2 uint32*,void** count, data
+TIFFTAG_RICHTIFFIPTC 2 uint32*,const void** count, data
TIFFTAG_ROWSPERSTRIP 1 uint32*
TIFFTAG_SAMPLEFORMAT 1 uint16*
TIFFTAG_SAMPLESPERPIXEL 1 uint16*
TIFFTAG_SMAXSAMPLEVALUE 1 double*
TIFFTAG_SMINSAMPLEVALUE 1 double*
-TIFFTAG_SOFTWARE 1 char**
-TIFFTAG_STONITS 1 double**
-TIFFTAG_STRIPBYTECOUNTS 1 uint32**
-TIFFTAG_STRIPOFFSETS 1 uint32**
+TIFFTAG_SOFTWARE 1 const char**
+TIFFTAG_STONITS 1 const double**
+TIFFTAG_STRIPBYTECOUNTS 1 const uint64**
+TIFFTAG_STRIPOFFSETS 1 const uint64**
TIFFTAG_SUBFILETYPE 1 uint32*
-TIFFTAG_SUBIFD 2 uint16*,uint64** count & offsets array
-TIFFTAG_TARGETPRINTER 1 char**
+TIFFTAG_SUBIFD 2 uint16*,const uint64** count & offsets array
+TIFFTAG_TARGETPRINTER 1 const char**
TIFFTAG_THRESHHOLDING 1 uint16*
-TIFFTAG_TILEBYTECOUNTS 1 uint32**
+TIFFTAG_TILEBYTECOUNTS 1 const uint64**
TIFFTAG_TILEDEPTH 1 uint32*
TIFFTAG_TILELENGTH 1 uint32*
-TIFFTAG_TILEOFFSETS 1 uint32**
+TIFFTAG_TILEOFFSETS 1 const uint64**
TIFFTAG_TILEWIDTH 1 uint32*
-TIFFTAG_TRANSFERFUNCTION 1 or 3\(dg uint16**1<<BitsPerSample entry arrays
-TIFFTAG_WHITEPOINT 1 float** 2-entry array
-TIFFTAG_XMLPACKET 2 uint32*,void** count, data
+TIFFTAG_TRANSFERFUNCTION 1 or 3\(dg const uint16**1<<BitsPerSample entry arrays
+TIFFTAG_WHITEPOINT 1 const float** 2-entry array
+TIFFTAG_XMLPACKET 2 uint32*,const void** count, data
TIFFTAG_XPOSITION 1 float*
TIFFTAG_XRESOLUTION 1 float*
-TIFFTAG_YCBCRCOEFFICIENTS 1 float** 3-entry array
+TIFFTAG_YCBCRCOEFFICIENTS 1 const float** 3-entry array
TIFFTAG_YCBCRPOSITIONING 1 uint16*
TIFFTAG_YCBCRSUBSAMPLING 2 uint16*
TIFFTAG_YPOSITION 1 float*
diff --git a/tiff/man/TIFFReadEncodedStrip.3tiff b/tiff/man/TIFFReadEncodedStrip.3tiff
index 7122946a..05ddefb9 100644
--- a/tiff/man/TIFFReadEncodedStrip.3tiff
+++ b/tiff/man/TIFFReadEncodedStrip.3tiff
@@ -30,7 +30,7 @@ file
.SH SYNOPSIS
.B "#include <tiffio.h>"
.sp
-.BI "tsize_t TIFFReadEncodedStrip(TIFF *" tif ", tstrip_t " strip ", tdata_t " buf ", tsize_t " size ")"
+.BI "tmsize_t TIFFReadEncodedStrip(TIFF *" tif ", uint32 " strip ", void *" buf ", tmsize_t " size ")"
.SH DESCRIPTION
Read the specified strip of data and place up to
.I size
diff --git a/tiff/man/TIFFstrip.3tiff b/tiff/man/TIFFstrip.3tiff
index eb38318f..ce3f718c 100644
--- a/tiff/man/TIFFstrip.3tiff
+++ b/tiff/man/TIFFstrip.3tiff
@@ -31,11 +31,11 @@ TIFFComputeStrip, TIFFNumberOfStrips \- strip-related utility routines
.sp
.BI "uint32 TIFFDefaultStripSize(TIFF *" tif ", uint32 " estimate ")"
.br
-.BI "tsize_t TIFFStripSize(TIFF *" tif ")"
+.BI "tmsize_t TIFFStripSize(TIFF *" tif ")"
.br
-.BI "tsize_t TIFFVStripSize(TIFF *" tif ", uint32 " nrows ")"
+.BI "tmsize_t TIFFVStripSize(TIFF *" tif ", uint32 " nrows ")"
.br
-.BI "tsize_t TIFFRawStripSize(TIFF *" tif ", tstrip_t " strip ")"
+.BI "tmsize_t TIFFRawStripSize(TIFF *" tif ", uint32 " strip ")"
.br
.BI "tstrip_t TIFFComputeStrip(TIFF *" tif ", uint32 " row ", tsample_t " sample ")"
.br
diff --git a/tiff/man/tiff2pdf.1 b/tiff/man/tiff2pdf.1
index 93011332..6b3b4abf 100644
--- a/tiff/man/tiff2pdf.1
+++ b/tiff/man/tiff2pdf.1
@@ -212,6 +212,9 @@ Set document information subject, overrides image image description default.
.BI \-k " keywords"
Set document information keywords.
.TP
+.BI \-m " size"
+Set memory allocation limit (in MiB). Default is 256MiB. Set to 0 to disable the limit.
+.TP
.B \-h
List usage reminder to stderr and exit.
.SH EXAMPLES
diff --git a/tiff/man/tiff2ps.1 b/tiff/man/tiff2ps.1
index 5e2b9a85..ce323eee 100644
--- a/tiff/man/tiff2ps.1
+++ b/tiff/man/tiff2ps.1
@@ -160,6 +160,10 @@ options.
Specify the left margin for the output (in inches). This does not affect
the width of the printed image.
.TP
+.BI \-M " size"
+Set maximum memory allocation size (in MiB). The default is 256MiB.
+Set to 0 to disable the limit.
+.TP
.B \-m
Where possible render using the
.I imagemask
diff --git a/tiff/man/tiff2rgba.1 b/tiff/man/tiff2rgba.1
index d9c9baae..fe9ebb2c 100644
--- a/tiff/man/tiff2rgba.1
+++ b/tiff/man/tiff2rgba.1
@@ -87,6 +87,10 @@ Drop the alpha component from the output file, producing a pure RGB file.
Currently this does not work if the
.B \-b
flag is also in effect.
+.TP
+.BI \-M " size"
+Set maximum memory allocation size (in MiB). The default is 256MiB.
+Set to 0 to disable the limit.
.SH "SEE ALSO"
.BR tiff2bw (1),
.BR TIFFReadRGBAImage (3t),
diff --git a/tiff/man/tiffcp.1 b/tiff/man/tiffcp.1
index 0545686c..6bfee348 100644
--- a/tiff/man/tiffcp.1
+++ b/tiff/man/tiffcp.1
@@ -151,6 +151,17 @@ e.g.
for
.SM Deflate
encoding with maximum compression level and floating point predictor.
+.IP
+For the
+.SM Deflate
+codec, and in a libtiff build with libdeflate enabled, ``p12`` is
+actually the maximum level.
+.IP
+For the
+.SM Deflate
+codec, and in a libtiff build with libdeflate enabled, ``s0`` can be used to
+require zlib to be used, and ``s1`` for libdeflate (defaults to libdeflate when
+it is available).
.TP
.B \-f
Specify the bit fill order to use in writing output data.
@@ -247,6 +258,10 @@ Note that
.B \-,=
with whitespace immediately following will disable
the special meaning of the `,' entirely. See examples.
+.TP
+.BI \-m " size"
+Set maximum memory allocation size (in MiB). The default is 256MiB.
+Set to 0 to disable the limit.
.SH EXAMPLES
The following concatenates two files and writes the result using
.SM LZW
diff --git a/tiff/man/tiffcrop.1 b/tiff/man/tiffcrop.1
index 5bd00976..d7a4c4d7 100644
--- a/tiff/man/tiffcrop.1
+++ b/tiff/man/tiffcrop.1
@@ -350,6 +350,10 @@ will force data to be written with the FillOrder tag set to
.TP
.B \-i
Ignore non\-fatal read errors and continue processing of the input file.
+.TP
+.B "\-k size"
+Set maximum memory allocation size (in MiB). The default is 256MiB.
+Set to 0 to disable the limit.
.TP
.B \-l
Specify the length of a tile (in pixels).
diff --git a/tiff/nmake.opt b/tiff/nmake.opt
index ae544670..d9bf15f1 100644
--- a/tiff/nmake.opt
+++ b/tiff/nmake.opt
@@ -29,6 +29,7 @@
# Usage examples (see details below):
# nmake -f makefile.vc
# nmake -f makefile.vc DEBUG=1
+# nmake -f makefile.vc clean
#
#
###### Edit the following lines to choose a feature set you need. #######
@@ -108,6 +109,11 @@ CHECK_JPEG_YCBCR_SUBSAMPLING = 1
####################### Compiler related options. #######################
#
+
+# Indicate if the compiler provides strtoll/strtoull (default 1)
+# Users of MSVC++ 14.0 ("Visual Studio 2015") and later should set this to 1
+HAVE_STRTOLL = 1
+
#
# Pick debug or optimized build flags. We default to an optimized build
# with no debugging information.
@@ -118,7 +124,7 @@ OPTFLAGS = /MDd /EHsc /W3 /D_CRT_SECURE_NO_DEPRECATE
!ELSE
OPTFLAGS = /Ox /MD /EHsc /W3 /D_CRT_SECURE_NO_DEPRECATE
!ENDIF
-#OPTFLAGS = /Zi
+#OPTFLAGS = /Zi
#
# Uncomment following line to enable using Windows Common RunTime Library
@@ -139,7 +145,7 @@ LD = link /nologo
CFLAGS = $(OPTFLAGS) $(INCL) $(EXTRAFLAGS)
CXXFLAGS = $(OPTFLAGS) $(INCL) $(EXTRAFLAGS)
-EXTRAFLAGS =
+EXTRAFLAGS = -DHAVE_CONFIG_H
LIBS =
# Name of the output shared library
diff --git a/tiff/port/Makefile.in b/tiff/port/Makefile.in
index 72e192b0..ba9d98f8 100644
--- a/tiff/port/Makefile.in
+++ b/tiff/port/Makefile.in
@@ -1,7 +1,7 @@
-# Makefile.in generated by automake 1.16.1 from Makefile.am.
+# Makefile.in generated by automake 1.16.2 from Makefile.am.
# @configure_input@
-# Copyright (C) 1994-2018 Free Software Foundation, Inc.
+# Copyright (C) 1994-2020 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
diff --git a/tiff/port/Makefile.vc b/tiff/port/Makefile.vc
index 992d2696..e4471af5 100644
--- a/tiff/port/Makefile.vc
+++ b/tiff/port/Makefile.vc
@@ -23,13 +23,53 @@
# Makefile for MS Visual C and Watcom C compilers.
#
# To build:
-# C:\libtiff\port> nmake /f makefile.vc
+# C:\libtiff\port> nmake /f makefile.vc
!INCLUDE ..\nmake.opt
+HAVE_STRTOL = 1
+HAVE_STRTOUL = 1
+
+# strtoul()/strtoull() are provided together
+!IF $(HAVE_STRTOLL)
+HAVE_STRTOULL = 1
+!ELSE
+HAVE_STRTOULL = 0
+!endif
+
+!IF $(HAVE_STRTOL)
+STRTOL_OBJ =
+!ELSE
+STRTOL_OBJ = strtol.obj
+!ENDIF
+
+!IF $(HAVE_STRTOUL)
+STRTOUL_OBJ =
+!ELSE
+STRTOUL_OBJ = strtoul.obj
+!ENDIF
+
+!IF $(HAVE_STRTOLL)
+STRTOLL_OBJ =
+!ELSE
+STRTOLL_OBJ = strtoll.obj
+!ENDIF
+
+!IF $(HAVE_STRTOULL)
+STRTOULL_OBJ =
+!ELSE
+STRTOULL_OBJ = strtoull.obj
+!ENDIF
+
+INCL = -I..\libtiff
+
OBJ = \
- snprintf.obj \
+ snprintf.obj \
strcasecmp.obj \
+ $(STRTOL_OBJ) \
+ $(STRTOUL_OBJ) \
+ $(STRTOLL_OBJ) \
+ $(STRTOULL_OBJ) \
getopt.obj
all: libport.lib
diff --git a/tiff/port/libport.h b/tiff/port/libport.h
index ff262638..9f2dace1 100644
--- a/tiff/port/libport.h
+++ b/tiff/port/libport.h
@@ -24,6 +24,10 @@
#ifndef _LIBPORT_
#define _LIBPORT_
+#if defined(HAVE_CONFIG_H)
+# include <tif_config.h>
+#endif
+
int getopt(int argc, char * const argv[], const char *optstring);
extern char *optarg;
extern int opterr;
@@ -36,16 +40,16 @@ int strcasecmp(const char *s1, const char *s2);
# define HAVE_GETOPT 1
#endif
-#if HAVE_STRTOL
+#if !defined(HAVE_STRTOL)
long strtol(const char *nptr, char **endptr, int base);
#endif
-#if HAVE_STRTOLL
+#if !defined(HAVE_STRTOLL)
long long strtoll(const char *nptr, char **endptr, int base);
#endif
-#if HAVE_STRTOUL
+#if !defined(HAVE_STRTOUL)
unsigned long strtoul(const char *nptr, char **endptr, int base);
#endif
-#if HAVE_STRTOULL
+#if !defined(HAVE_STRTOULL)
unsigned long long strtoull(const char *nptr, char **endptr, int base);
#endif
diff --git a/tiff/test/CMakeLists.txt b/tiff/test/CMakeLists.txt
index a4216d56..bffb8bf7 100644
--- a/tiff/test/CMakeLists.txt
+++ b/tiff/test/CMakeLists.txt
@@ -105,7 +105,12 @@ set(TESTSCRIPTS
tiff2rgba-palette-1c-8b.sh
tiff2rgba-rgb-3c-16b.sh
tiff2rgba-rgb-3c-8b.sh
- tiff2rgba-quad-tile.jpg.sh)
+ tiff2rgba-quad-tile.jpg.sh
+ tiff2rgba-ojpeg_zackthecat_subsamp22_single_strip.sh
+ tiff2rgba-ojpeg_chewey_subsamp21_multi_strip.sh
+ tiff2rgba-ojpeg_single_strip_no_rowsperstrip.sh
+ testfax4.sh
+ testdeflatelaststripextradata.sh)
# This list should contain all of the TIFF files in the 'images'
# subdirectory which are intended to be used as input images for
@@ -123,7 +128,11 @@ set(TIFFIMAGES
images/rgb-3c-8b.tiff
images/quad-tile.jpg.tiff
images/quad-lzw-compat.tiff
- images/lzw-single-strip.tiff)
+ images/lzw-single-strip.tiff
+ images/ojpeg_zackthecat_subsamp22_single_strip.tiff
+ images/ojpeg_chewey_subsamp21_multi_strip.tiff
+ images/ojpeg_single_strip_no_rowsperstrip.tiff
+ images/testfax4.tiff)
set(BMPIMAGES
images/palette-1c-8b.bmp
@@ -135,6 +144,7 @@ set(GIFIMAGES
set(PNMIMAGES
images/minisblack-1c-8b.pgm
images/miniswhite-1c-1b.pbm
+ images/rgb-3c-16b.ppm
images/rgb-3c-8b.ppm)
# All uncompressed image files
@@ -188,6 +198,20 @@ endif()
add_executable(custom_dir custom_dir.c)
target_link_libraries(custom_dir tiff port)
+if(NOT BUILD_SHARED_LIBS)
+add_executable(rational_precision2double rational_precision2double.c)
+target_link_libraries(rational_precision2double tiff port)
+add_test(NAME "rational_precision2double"
+ COMMAND "rational_precision2double")
+endif()
+
+if(NOT BUILD_SHARED_LIBS)
+add_executable(custom_dir_EXIF_231 custom_dir_EXIF_231.c)
+target_link_libraries(custom_dir_EXIF_231 tiff port)
+add_test(NAME "custom_dir_EXIF_231"
+ COMMAND "custom_dir_EXIF_231")
+endif()
+
add_executable(defer_strile_loading defer_strile_loading.c)
target_link_libraries(defer_strile_loading tiff port)
@@ -197,6 +221,24 @@ target_link_libraries(defer_strile_writing tiff port)
add_executable(testtypes testtypes.c)
target_link_libraries(testtypes tiff port)
+if(WEBP_SUPPORT AND EMSCRIPTEN)
+ # Emscripten is pretty finnicky about linker flags.
+ # It needs --shared-memory if and only if atomics or bulk-memory is used.
+ foreach(target ascii_tag
+ custom_dir
+ defer_strile_loading
+ defer_strile_writing
+ long_tag
+ rewrite
+ short_tag
+ strip_rw)
+ target_link_options(${target} PUBLIC "-Wl,--shared-memory")
+ endforeach()
+ if(JPEG_SUPPORT)
+ target_link_options(raw_decode PUBLIC "-Wl,--shared-memory")
+ endif()
+endif()
+
set(TEST_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/output")
file(MAKE_DIRECTORY "${TEST_OUTPUT}")
@@ -338,6 +380,7 @@ add_convert_test(gif2tiff palette "" "images/palette-1c-8b.gif" TRUE)
# PPM
add_convert_test(ppm2tiff miniswhite "" "images/miniswhite-1c-1b.pbm" TRUE)
add_convert_test(ppm2tiff minisblack "" "images/minisblack-1c-8b.pgm" TRUE)
+add_convert_test(ppm2tiff rgb "" "images/rgb-3c-16b.ppm" TRUE)
add_convert_test(ppm2tiff rgb "" "images/rgb-3c-8b.ppm" TRUE)
# tiffcp
diff --git a/tiff/test/Makefile.am b/tiff/test/Makefile.am
index 90c2f3d1..4973b614 100644
--- a/tiff/test/Makefile.am
+++ b/tiff/test/Makefile.am
@@ -55,7 +55,11 @@ CLEANFILES = test_packbits.tif o-*
if HAVE_JPEG
JPEG_DEPENDENT_CHECK_PROG=raw_decode
JPEG_DEPENDENT_TESTSCRIPTS=\
- tiff2rgba-quad-tile.jpg.sh
+ tiff2rgba-quad-tile.jpg.sh \
+ tiff2rgba-ojpeg_zackthecat_subsamp22_single_strip.sh \
+ tiff2rgba-ojpeg_chewey_subsamp21_multi_strip.sh \
+ tiff2rgba-ojpeg_single_strip_no_rowsperstrip.sh
+
else
JPEG_DEPENDENT_CHECK_PROG=
JPEG_DEPENDENT_TESTSCRIPTS=
@@ -63,8 +67,8 @@ endif
# Executable programs which need to be built in order to support tests
check_PROGRAMS = \
- ascii_tag long_tag short_tag strip_rw rewrite custom_dir \
- defer_strile_loading defer_strile_writing testtypes \
+ ascii_tag long_tag short_tag strip_rw rewrite custom_dir custom_dir_EXIF_231 \
+ rational_precision2double defer_strile_loading defer_strile_writing testtypes \
$(JPEG_DEPENDENT_CHECK_PROG)
# Test scripts to execute
@@ -145,6 +149,8 @@ TESTSCRIPTS = \
tiff2rgba-palette-1c-8b.sh \
tiff2rgba-rgb-3c-16b.sh \
tiff2rgba-rgb-3c-8b.sh \
+ testfax4.sh \
+ testdeflatelaststripextradata.sh \
$(JPEG_DEPENDENT_TESTSCRIPTS)
# This list should contain the references files
@@ -153,7 +159,9 @@ REFFILES = \
refs/o-tiff2ps-EPS1.ps \
refs/o-tiff2ps-PS1.ps \
refs/o-tiff2ps-PS2.ps \
- refs/o-tiff2ps-PS3.ps
+ refs/o-tiff2ps-PS3.ps \
+ refs/o-testfax4.tiff \
+ refs/o-deflate-last-strip-extra-data.tiff
# This list should contain all of the TIFF files in the 'images'
# subdirectory which are intended to be used as input images for
@@ -171,11 +179,17 @@ TIFFIMAGES = \
images/rgb-3c-8b.tiff \
images/quad-tile.jpg.tiff \
images/quad-lzw-compat.tiff \
- images/lzw-single-strip.tiff
+ images/lzw-single-strip.tiff \
+ images/ojpeg_zackthecat_subsamp22_single_strip.tiff \
+ images/ojpeg_chewey_subsamp21_multi_strip.tiff \
+ images/ojpeg_single_strip_no_rowsperstrip.tiff \
+ images/testfax4.tiff \
+ images/deflate-last-strip-extra-data.tiff
PNMIMAGES = \
images/minisblack-1c-8b.pgm \
images/miniswhite-1c-1b.pbm \
+ images/rgb-3c-16b.ppm \
images/rgb-3c-8b.ppm
# This list should include all of the files in the 'images'
@@ -203,6 +217,10 @@ raw_decode_SOURCES = raw_decode.c
raw_decode_LDADD = $(LIBTIFF)
custom_dir_SOURCES = custom_dir.c
custom_dir_LDADD = $(LIBTIFF)
+rational_precision2double_SOURCES = rational_precision2double.c
+rational_precision2double_LDADD = $(LIBTIFF)
+custom_dir_EXIF_231_SOURCES = custom_dir_EXIF_231.c
+custom_dir_EXIF_231_LDADD = $(LIBTIFF)
defer_strile_loading_SOURCES = defer_strile_loading.c
defer_strile_loading_LDADD = $(LIBTIFF)
defer_strile_writing_SOURCES = defer_strile_writing.c
diff --git a/tiff/test/Makefile.in b/tiff/test/Makefile.in
index 5a2f0607..15b7b826 100644
--- a/tiff/test/Makefile.in
+++ b/tiff/test/Makefile.in
@@ -1,7 +1,7 @@
-# Makefile.in generated by automake 1.16.1 from Makefile.am.
+# Makefile.in generated by automake 1.16.2 from Makefile.am.
# @configure_input@
-# Copyright (C) 1994-2018 Free Software Foundation, Inc.
+# Copyright (C) 1994-2020 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -117,9 +117,10 @@ TESTS = $(check_PROGRAMS) $(am__EXEEXT_3)
XFAIL_TESTS =
check_PROGRAMS = ascii_tag$(EXEEXT) long_tag$(EXEEXT) \
short_tag$(EXEEXT) strip_rw$(EXEEXT) rewrite$(EXEEXT) \
- custom_dir$(EXEEXT) defer_strile_loading$(EXEEXT) \
- defer_strile_writing$(EXEEXT) testtypes$(EXEEXT) \
- $(am__EXEEXT_1)
+ custom_dir$(EXEEXT) custom_dir_EXIF_231$(EXEEXT) \
+ rational_precision2double$(EXEEXT) \
+ defer_strile_loading$(EXEEXT) defer_strile_writing$(EXEEXT) \
+ testtypes$(EXEEXT) $(am__EXEEXT_1)
subdir = test
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/acinclude.m4 \
@@ -146,6 +147,9 @@ am__v_lt_1 =
am_custom_dir_OBJECTS = custom_dir.$(OBJEXT)
custom_dir_OBJECTS = $(am_custom_dir_OBJECTS)
custom_dir_DEPENDENCIES = $(LIBTIFF)
+am_custom_dir_EXIF_231_OBJECTS = custom_dir_EXIF_231.$(OBJEXT)
+custom_dir_EXIF_231_OBJECTS = $(am_custom_dir_EXIF_231_OBJECTS)
+custom_dir_EXIF_231_DEPENDENCIES = $(LIBTIFF)
am_defer_strile_loading_OBJECTS = defer_strile_loading.$(OBJEXT)
defer_strile_loading_OBJECTS = $(am_defer_strile_loading_OBJECTS)
defer_strile_loading_DEPENDENCIES = $(LIBTIFF)
@@ -155,6 +159,11 @@ defer_strile_writing_DEPENDENCIES = $(LIBTIFF)
am_long_tag_OBJECTS = long_tag.$(OBJEXT) check_tag.$(OBJEXT)
long_tag_OBJECTS = $(am_long_tag_OBJECTS)
long_tag_DEPENDENCIES = $(LIBTIFF)
+am_rational_precision2double_OBJECTS = \
+ rational_precision2double.$(OBJEXT)
+rational_precision2double_OBJECTS = \
+ $(am_rational_precision2double_OBJECTS)
+rational_precision2double_DEPENDENCIES = $(LIBTIFF)
am_raw_decode_OBJECTS = raw_decode.$(OBJEXT)
raw_decode_OBJECTS = $(am_raw_decode_OBJECTS)
raw_decode_DEPENDENCIES = $(LIBTIFF)
@@ -188,8 +197,10 @@ depcomp = $(SHELL) $(top_srcdir)/config/depcomp
am__maybe_remake_depfiles = depfiles
am__depfiles_remade = ./$(DEPDIR)/ascii_tag.Po \
./$(DEPDIR)/check_tag.Po ./$(DEPDIR)/custom_dir.Po \
+ ./$(DEPDIR)/custom_dir_EXIF_231.Po \
./$(DEPDIR)/defer_strile_loading.Po \
./$(DEPDIR)/defer_strile_writing.Po ./$(DEPDIR)/long_tag.Po \
+ ./$(DEPDIR)/rational_precision2double.Po \
./$(DEPDIR)/raw_decode.Po ./$(DEPDIR)/rewrite_tag.Po \
./$(DEPDIR)/short_tag.Po ./$(DEPDIR)/strip.Po \
./$(DEPDIR)/strip_rw.Po ./$(DEPDIR)/test_arrays.Po \
@@ -214,15 +225,17 @@ am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
am__v_CCLD_0 = @echo " CCLD " $@;
am__v_CCLD_1 =
SOURCES = $(ascii_tag_SOURCES) $(custom_dir_SOURCES) \
- $(defer_strile_loading_SOURCES) \
+ $(custom_dir_EXIF_231_SOURCES) $(defer_strile_loading_SOURCES) \
$(defer_strile_writing_SOURCES) $(long_tag_SOURCES) \
- $(raw_decode_SOURCES) $(rewrite_SOURCES) $(short_tag_SOURCES) \
- $(strip_rw_SOURCES) testtypes.c
+ $(rational_precision2double_SOURCES) $(raw_decode_SOURCES) \
+ $(rewrite_SOURCES) $(short_tag_SOURCES) $(strip_rw_SOURCES) \
+ testtypes.c
DIST_SOURCES = $(ascii_tag_SOURCES) $(custom_dir_SOURCES) \
- $(defer_strile_loading_SOURCES) \
+ $(custom_dir_EXIF_231_SOURCES) $(defer_strile_loading_SOURCES) \
$(defer_strile_writing_SOURCES) $(long_tag_SOURCES) \
- $(raw_decode_SOURCES) $(rewrite_SOURCES) $(short_tag_SOURCES) \
- $(strip_rw_SOURCES) testtypes.c
+ $(rational_precision2double_SOURCES) $(raw_decode_SOURCES) \
+ $(rewrite_SOURCES) $(short_tag_SOURCES) $(strip_rw_SOURCES) \
+ testtypes.c
am__can_run_installinfo = \
case $$AM_UPDATE_INFO_DIR in \
n|no|NO) false;; \
@@ -432,7 +445,10 @@ am__set_TESTS_bases = \
bases=`echo $$bases`
RECHECK_LOGS = $(TEST_LOGS)
AM_RECURSIVE_TARGETS = check recheck
-@HAVE_JPEG_TRUE@am__EXEEXT_2 = tiff2rgba-quad-tile.jpg.sh
+@HAVE_JPEG_TRUE@am__EXEEXT_2 = tiff2rgba-quad-tile.jpg.sh \
+@HAVE_JPEG_TRUE@ tiff2rgba-ojpeg_zackthecat_subsamp22_single_strip.sh \
+@HAVE_JPEG_TRUE@ tiff2rgba-ojpeg_chewey_subsamp21_multi_strip.sh \
+@HAVE_JPEG_TRUE@ tiff2rgba-ojpeg_single_strip_no_rowsperstrip.sh
am__EXEEXT_3 = ppm2tiff_pbm.sh ppm2tiff_pgm.sh ppm2tiff_ppm.sh \
fax2tiff.sh tiffcp-g3.sh tiffcp-g3-1d.sh tiffcp-g3-1d-fill.sh \
tiffcp-g3-2d.sh tiffcp-g3-2d-fill.sh tiffcp-g4.sh \
@@ -481,7 +497,8 @@ am__EXEEXT_3 = ppm2tiff_pbm.sh ppm2tiff_pgm.sh ppm2tiff_ppm.sh \
tiff2rgba-minisblack-2c-8b-alpha.sh \
tiff2rgba-miniswhite-1c-1b.sh tiff2rgba-palette-1c-1b.sh \
tiff2rgba-palette-1c-4b.sh tiff2rgba-palette-1c-8b.sh \
- tiff2rgba-rgb-3c-16b.sh tiff2rgba-rgb-3c-8b.sh $(am__EXEEXT_2)
+ tiff2rgba-rgb-3c-16b.sh tiff2rgba-rgb-3c-8b.sh testfax4.sh \
+ testdeflatelaststripextradata.sh $(am__EXEEXT_2)
TEST_SUITE_LOG = test-suite.log
TEST_EXTENSIONS = @EXEEXT@ .test
LOG_DRIVER = $(SHELL) $(top_srcdir)/config/test-driver
@@ -679,7 +696,10 @@ CLEANFILES = test_packbits.tif o-*
@HAVE_JPEG_TRUE@JPEG_DEPENDENT_CHECK_PROG = raw_decode
@HAVE_JPEG_FALSE@JPEG_DEPENDENT_TESTSCRIPTS =
@HAVE_JPEG_TRUE@JPEG_DEPENDENT_TESTSCRIPTS = \
-@HAVE_JPEG_TRUE@ tiff2rgba-quad-tile.jpg.sh
+@HAVE_JPEG_TRUE@ tiff2rgba-quad-tile.jpg.sh \
+@HAVE_JPEG_TRUE@ tiff2rgba-ojpeg_zackthecat_subsamp22_single_strip.sh \
+@HAVE_JPEG_TRUE@ tiff2rgba-ojpeg_chewey_subsamp21_multi_strip.sh \
+@HAVE_JPEG_TRUE@ tiff2rgba-ojpeg_single_strip_no_rowsperstrip.sh
# Test scripts to execute
@@ -760,6 +780,8 @@ TESTSCRIPTS = \
tiff2rgba-palette-1c-8b.sh \
tiff2rgba-rgb-3c-16b.sh \
tiff2rgba-rgb-3c-8b.sh \
+ testfax4.sh \
+ testdeflatelaststripextradata.sh \
$(JPEG_DEPENDENT_TESTSCRIPTS)
@@ -769,7 +791,9 @@ REFFILES = \
refs/o-tiff2ps-EPS1.ps \
refs/o-tiff2ps-PS1.ps \
refs/o-tiff2ps-PS2.ps \
- refs/o-tiff2ps-PS3.ps
+ refs/o-tiff2ps-PS3.ps \
+ refs/o-testfax4.tiff \
+ refs/o-deflate-last-strip-extra-data.tiff
# This list should contain all of the TIFF files in the 'images'
@@ -788,11 +812,17 @@ TIFFIMAGES = \
images/rgb-3c-8b.tiff \
images/quad-tile.jpg.tiff \
images/quad-lzw-compat.tiff \
- images/lzw-single-strip.tiff
+ images/lzw-single-strip.tiff \
+ images/ojpeg_zackthecat_subsamp22_single_strip.tiff \
+ images/ojpeg_chewey_subsamp21_multi_strip.tiff \
+ images/ojpeg_single_strip_no_rowsperstrip.tiff \
+ images/testfax4.tiff \
+ images/deflate-last-strip-extra-data.tiff
PNMIMAGES = \
images/minisblack-1c-8b.pgm \
images/miniswhite-1c-1b.pbm \
+ images/rgb-3c-16b.ppm \
images/rgb-3c-8b.ppm
@@ -820,6 +850,10 @@ raw_decode_SOURCES = raw_decode.c
raw_decode_LDADD = $(LIBTIFF)
custom_dir_SOURCES = custom_dir.c
custom_dir_LDADD = $(LIBTIFF)
+rational_precision2double_SOURCES = rational_precision2double.c
+rational_precision2double_LDADD = $(LIBTIFF)
+custom_dir_EXIF_231_SOURCES = custom_dir_EXIF_231.c
+custom_dir_EXIF_231_LDADD = $(LIBTIFF)
defer_strile_loading_SOURCES = defer_strile_loading.c
defer_strile_loading_LDADD = $(LIBTIFF)
defer_strile_writing_SOURCES = defer_strile_writing.c
@@ -876,6 +910,10 @@ custom_dir$(EXEEXT): $(custom_dir_OBJECTS) $(custom_dir_DEPENDENCIES) $(EXTRA_cu
@rm -f custom_dir$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(custom_dir_OBJECTS) $(custom_dir_LDADD) $(LIBS)
+custom_dir_EXIF_231$(EXEEXT): $(custom_dir_EXIF_231_OBJECTS) $(custom_dir_EXIF_231_DEPENDENCIES) $(EXTRA_custom_dir_EXIF_231_DEPENDENCIES)
+ @rm -f custom_dir_EXIF_231$(EXEEXT)
+ $(AM_V_CCLD)$(LINK) $(custom_dir_EXIF_231_OBJECTS) $(custom_dir_EXIF_231_LDADD) $(LIBS)
+
defer_strile_loading$(EXEEXT): $(defer_strile_loading_OBJECTS) $(defer_strile_loading_DEPENDENCIES) $(EXTRA_defer_strile_loading_DEPENDENCIES)
@rm -f defer_strile_loading$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(defer_strile_loading_OBJECTS) $(defer_strile_loading_LDADD) $(LIBS)
@@ -888,6 +926,10 @@ long_tag$(EXEEXT): $(long_tag_OBJECTS) $(long_tag_DEPENDENCIES) $(EXTRA_long_tag
@rm -f long_tag$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(long_tag_OBJECTS) $(long_tag_LDADD) $(LIBS)
+rational_precision2double$(EXEEXT): $(rational_precision2double_OBJECTS) $(rational_precision2double_DEPENDENCIES) $(EXTRA_rational_precision2double_DEPENDENCIES)
+ @rm -f rational_precision2double$(EXEEXT)
+ $(AM_V_CCLD)$(LINK) $(rational_precision2double_OBJECTS) $(rational_precision2double_LDADD) $(LIBS)
+
raw_decode$(EXEEXT): $(raw_decode_OBJECTS) $(raw_decode_DEPENDENCIES) $(EXTRA_raw_decode_DEPENDENCIES)
@rm -f raw_decode$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(raw_decode_OBJECTS) $(raw_decode_LDADD) $(LIBS)
@@ -917,9 +959,11 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ascii_tag.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/check_tag.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/custom_dir.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/custom_dir_EXIF_231.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/defer_strile_loading.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/defer_strile_writing.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/long_tag.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rational_precision2double.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/raw_decode.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rewrite_tag.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/short_tag.Po@am__quote@ # am--include-marker
@@ -1196,6 +1240,20 @@ custom_dir.log: custom_dir$(EXEEXT)
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
+custom_dir_EXIF_231.log: custom_dir_EXIF_231$(EXEEXT)
+ @p='custom_dir_EXIF_231$(EXEEXT)'; \
+ b='custom_dir_EXIF_231'; \
+ $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
+ --log-file $$b.log --trs-file $$b.trs \
+ $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
+ "$$tst" $(AM_TESTS_FD_REDIRECT)
+rational_precision2double.log: rational_precision2double$(EXEEXT)
+ @p='rational_precision2double$(EXEEXT)'; \
+ b='rational_precision2double'; \
+ $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
+ --log-file $$b.log --trs-file $$b.trs \
+ $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
+ "$$tst" $(AM_TESTS_FD_REDIRECT)
defer_strile_loading.log: defer_strile_loading$(EXEEXT)
@p='defer_strile_loading$(EXEEXT)'; \
b='defer_strile_loading'; \
@@ -1756,6 +1814,20 @@ tiff2rgba-rgb-3c-8b.sh.log: tiff2rgba-rgb-3c-8b.sh
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
+testfax4.sh.log: testfax4.sh
+ @p='testfax4.sh'; \
+ b='testfax4.sh'; \
+ $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
+ --log-file $$b.log --trs-file $$b.trs \
+ $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
+ "$$tst" $(AM_TESTS_FD_REDIRECT)
+testdeflatelaststripextradata.sh.log: testdeflatelaststripextradata.sh
+ @p='testdeflatelaststripextradata.sh'; \
+ b='testdeflatelaststripextradata.sh'; \
+ $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
+ --log-file $$b.log --trs-file $$b.trs \
+ $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
+ "$$tst" $(AM_TESTS_FD_REDIRECT)
tiff2rgba-quad-tile.jpg.sh.log: tiff2rgba-quad-tile.jpg.sh
@p='tiff2rgba-quad-tile.jpg.sh'; \
b='tiff2rgba-quad-tile.jpg.sh'; \
@@ -1763,6 +1835,27 @@ tiff2rgba-quad-tile.jpg.sh.log: tiff2rgba-quad-tile.jpg.sh
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
+tiff2rgba-ojpeg_zackthecat_subsamp22_single_strip.sh.log: tiff2rgba-ojpeg_zackthecat_subsamp22_single_strip.sh
+ @p='tiff2rgba-ojpeg_zackthecat_subsamp22_single_strip.sh'; \
+ b='tiff2rgba-ojpeg_zackthecat_subsamp22_single_strip.sh'; \
+ $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
+ --log-file $$b.log --trs-file $$b.trs \
+ $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
+ "$$tst" $(AM_TESTS_FD_REDIRECT)
+tiff2rgba-ojpeg_chewey_subsamp21_multi_strip.sh.log: tiff2rgba-ojpeg_chewey_subsamp21_multi_strip.sh
+ @p='tiff2rgba-ojpeg_chewey_subsamp21_multi_strip.sh'; \
+ b='tiff2rgba-ojpeg_chewey_subsamp21_multi_strip.sh'; \
+ $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
+ --log-file $$b.log --trs-file $$b.trs \
+ $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
+ "$$tst" $(AM_TESTS_FD_REDIRECT)
+tiff2rgba-ojpeg_single_strip_no_rowsperstrip.sh.log: tiff2rgba-ojpeg_single_strip_no_rowsperstrip.sh
+ @p='tiff2rgba-ojpeg_single_strip_no_rowsperstrip.sh'; \
+ b='tiff2rgba-ojpeg_single_strip_no_rowsperstrip.sh'; \
+ $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
+ --log-file $$b.log --trs-file $$b.trs \
+ $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
+ "$$tst" $(AM_TESTS_FD_REDIRECT)
.test.log:
@p='$<'; \
$(am__set_b); \
@@ -1860,9 +1953,11 @@ distclean: distclean-am
-rm -f ./$(DEPDIR)/ascii_tag.Po
-rm -f ./$(DEPDIR)/check_tag.Po
-rm -f ./$(DEPDIR)/custom_dir.Po
+ -rm -f ./$(DEPDIR)/custom_dir_EXIF_231.Po
-rm -f ./$(DEPDIR)/defer_strile_loading.Po
-rm -f ./$(DEPDIR)/defer_strile_writing.Po
-rm -f ./$(DEPDIR)/long_tag.Po
+ -rm -f ./$(DEPDIR)/rational_precision2double.Po
-rm -f ./$(DEPDIR)/raw_decode.Po
-rm -f ./$(DEPDIR)/rewrite_tag.Po
-rm -f ./$(DEPDIR)/short_tag.Po
@@ -1918,9 +2013,11 @@ maintainer-clean: maintainer-clean-am
-rm -f ./$(DEPDIR)/ascii_tag.Po
-rm -f ./$(DEPDIR)/check_tag.Po
-rm -f ./$(DEPDIR)/custom_dir.Po
+ -rm -f ./$(DEPDIR)/custom_dir_EXIF_231.Po
-rm -f ./$(DEPDIR)/defer_strile_loading.Po
-rm -f ./$(DEPDIR)/defer_strile_writing.Po
-rm -f ./$(DEPDIR)/long_tag.Po
+ -rm -f ./$(DEPDIR)/rational_precision2double.Po
-rm -f ./$(DEPDIR)/raw_decode.Po
-rm -f ./$(DEPDIR)/rewrite_tag.Po
-rm -f ./$(DEPDIR)/short_tag.Po
diff --git a/tiff/test/common.sh b/tiff/test/common.sh
index 5bebcd37..0219ab3a 100644
--- a/tiff/test/common.sh
+++ b/tiff/test/common.sh
@@ -46,10 +46,11 @@ IMG_LZW_SINGLE_STROP=${IMAGES}/lzw-single-strip.tiff
IMG_MINISWHITE_1C_1B_PBM=${IMAGES}/miniswhite-1c-1b.pbm
IMG_MINISBLACK_1C_8B_PGM=${IMAGES}/minisblack-1c-8b.pgm
+IMG_RGB_3C_16B_PPM=${IMAGES}/rgb-3c-16b.ppm
IMG_RGB_3C_8B_PPM=${IMAGES}/rgb-3c-8b.ppm
# All uncompressed image files
-IMG_UNCOMPRESSED="${IMG_MINISBLACK_1C_16B} ${IMG_MINISBLACK_1C_8B} ${IMG_MINISWHITE_1C_1B} ${IMG_PALETTE_1C_1B} ${IMG_PALETTE_1C_4B} ${IMG_PALETTE_1C_4B} ${IMG_PALETTE_1C_8B} ${IMG_RGB_3C_8B}"
+IMG_UNCOMPRESSED="${IMG_MINISBLACK_1C_16B} ${IMG_MINISBLACK_1C_8B} ${IMG_MINISWHITE_1C_1B} ${IMG_PALETTE_1C_1B} ${IMG_PALETTE_1C_4B} ${IMG_PALETTE_1C_4B} ${IMG_PALETTE_1C_8B} ${IMG_RGB_3C_8B} ${IMG_RGB_3C_16B}"
#
# Test a simple convert-like command.
diff --git a/tiff/test/custom_dir_EXIF_231.c b/tiff/test/custom_dir_EXIF_231.c
new file mode 100644
index 00000000..4c70e48f
--- /dev/null
+++ b/tiff/test/custom_dir_EXIF_231.c
@@ -0,0 +1,1398 @@
+
+/*
+ * Copyright (c) 2012, Frank Warmerdam <warmerdam@pobox.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.
+ */
+
+/*
+ * TIFF Library
+ *
+ * -- Module copied from custom_dir.c --
+ *=========== Purpose ===================================================================================
+ * Extended and amended version for testing of EXIF 2.32, GPS and handling of custom fields.
+ * EXIF 2.32 and GPS are defined in amended files tif_dirinfo.c, tif_dirread.c, tiff.h, tiffio.h, tif_dir.h, tif_dir.c
+ *
+ *-- ATTENTION: After the upgrade with Rational2Double, the GPSTAG values are defined as double precision
+ * and need to be written and also read in double precision!
+ * In order to maintain this code for both cases, it is checked above if the TiffLibrary is
+ * compiled with the new interface with Rational2Double or still uses the old definitions,
+ * by setting blnIsRational2Double above.
+ *
+ */
+
+
+/*------------
+ * This version writes the GPS and EXIF tags correctly, without additonal main-IFD and parameters!
+ * In contrary, custom_dir.c does write additional main-IFD and parameters to file.
+ -------------*/
+
+
+#define FOR_AUTO_TESTING
+#ifdef FOR_AUTO_TESTING
+/* Only for automake and CMake infrastructure the test should:
+ a.) delete any written testfiles when test passed (otherwise autotest will fail)
+ b.) goto failure, if any failure is detected, which is not necessary when test is initiated manually for debugging
+*/
+#define GOTOFAILURE goto failure;
+#define GOTOFAILURE_GPS goto failure;
+#define GOTOFAILURE_ALL_EXIF goto failure;
+#else
+#define GOTOFAILURE
+#define GOTOFAILURE_GPS
+#define GOTOFAILURE_ALL_EXIF
+#endif
+
+
+#ifdef _MSC_VER
+#pragma warning( disable : 4101)
+#endif
+
+#include "tif_config.h"
+#include <stdio.h>
+#include <string.h>
+#include <math.h>
+#include <errno.h>
+
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+
+#include "tiffio.h"
+#include "tiffiop.h"
+#include "tif_dir.h"
+#include "tifftest.h"
+
+
+
+int write_test_tiff(TIFF *tif, const char *filenameRead);
+
+static const char filename[] = "custom_dir_EXIF_231.tif";
+static const char filenameBigTiff[] = "custom_dir_EXIF_231_Big.tif";
+
+#define SPP 3 /* Samples per pixel */
+const uint16 width = 1;
+const uint16 length = 1;
+const uint16 bps = 8;
+const uint16 photometric = PHOTOMETRIC_RGB;
+const uint16 rows_per_strip = 1;
+const uint16 planarconfig = PLANARCONFIG_CONTIG;
+
+
+int
+main()
+{
+ TIFF *tif;
+ int ret, ret1, ret2;
+
+ fprintf(stderr, "==== Test automatically if all EXIF and GPS tags are written/read correctly. ====\n");
+ /* --- Test with Classic-TIFF ---*/
+ /* delete file, if exists */
+ ret = unlink(filename);
+ if (ret != 0 && errno != ENOENT) {
+ fprintf(stderr, "Can't delete test TIFF file %s.\n", filename);
+ }
+
+ /* We write the main directory as a simple image. */
+ tif = TIFFOpen(filename, "w+");
+ if (!tif) {
+ fprintf(stderr, "Can't create test TIFF file %s.\n", filename);
+ return 1;
+ }
+ fprintf(stderr, "-------- Test with ClassicTIFF started ----------\n");
+ ret1 = write_test_tiff(tif, filename);
+
+ if (ret1 > 0) return(ret1);
+
+ /*--- Test with BIG-TIFF ---*/
+ /* delete file, if exists */
+ ret = unlink(filenameBigTiff);
+ if (ret != 0 && errno != ENOENT) {
+ fprintf(stderr, "Can't delete test TIFF file %s.\n", filenameBigTiff);
+ }
+
+ tif = TIFFOpen(filenameBigTiff, "w8");
+ if (!tif) {
+ fprintf(stderr, "Can't create test TIFF file %s.\n", filenameBigTiff);
+ return 1;
+ }
+ fprintf(stderr, "\n\n-------- Test with BigTIFF started ----------\n");
+ ret2 = write_test_tiff(tif, filenameBigTiff);
+
+ if (ret2 > 0) return(ret2 + 10); else return(ret2);
+
+} /* main() */
+
+
+
+
+
+
+
+int
+write_test_tiff(TIFF *tif, const char *filenameRead)
+{
+ unsigned char buf[SPP] = { 0, 127, 255 };
+ uint64 dir_offset = 0;
+ uint64 dir_offset_GPS = 0, dir_offset_EXIF = 0;
+ uint64 read_dir_offset = 0;
+ /*-- Additional variables --*/
+ int retCode, retCode2;
+ unsigned char exifVersion[4] = {'0','2','3','1'}; /* EXIF 2.31 version is 4 characters of a string! */
+ unsigned char gpsVersion[4] = {2,2,0,1}; /* GPS Version is 4 numbers! */
+ unsigned char *pGpsVersion;
+ float auxFloat = 0.0f;
+ double auxDouble = 0.0;
+ char auxChar = 0;
+ uint32 auxUint32 = 0;
+ short auxShort=0;
+ long auxLong = 0;
+ void *pVoid;
+ int blnIsRational2Double;
+
+ int i, j;
+ long nTags;
+
+ const TIFFFieldArray* tFieldArray;
+ unsigned long tTag;
+ TIFFDataType tType;
+ short tWriteCount;
+ TIFFSetGetFieldType tSetFieldType;
+ char *tFieldName;
+ const TIFFField *fip;
+
+ char blnFillGPSManually = 1;
+
+#define STRSIZE 1000
+#define N_SIZE 120
+#define VARIABLE_ARRAY_SIZE 6
+
+ /* -- Test data for writing -- */
+ char auxCharArrayW[N_SIZE];
+ short auxShortArrayW[N_SIZE];
+ long auxLongArrayW[N_SIZE];
+ float auxFloatArrayW[N_SIZE];
+ double auxDoubleArrayW[N_SIZE];
+ char auxTextArrayW[N_SIZE][STRSIZE];
+ double auxDoubleArrayGPS1[3] = {1.0/7.0, 61.23456789012345, 62.0};
+ double auxDoubleArrayGPS2[3] = {1.0/19.0, 88.34434, 15.12345678901234567890};
+ double auxDoubleArrayGPSTime[3] = {22.0, 17.0, 15.3456789};
+ double auxDoubleGPSAltitude = 3456.0;
+ double auxDoubleGPSDirection = 63.7;
+ float auxFloatArrayN1[3] = { 1.0f / 7.0f, 61.23456789012345f, 62.3f };
+ float auxFloatArrayN2[3] = { -1.0f / 7.0f, -61.23456789012345f, -62.3f };
+
+ /* -- Variables for reading -- */
+ uint16 count16 = 0;
+ union {
+ long Long;
+ short Short1;
+ short Short2[2];
+ char Char[4];
+ } unionLong;
+ union {
+ double dbl;
+ float flt1;
+ float flt2;
+ } auxDblUnion;
+ void *pVoidArray;
+ char *pAscii;
+ char auxCharArray[2*STRSIZE];
+ short auxShortArray[2*N_SIZE];
+ long auxLongArray[2*N_SIZE];
+ float auxFloatArray[2*N_SIZE];
+ double auxDoubleArray[2*N_SIZE];
+ double dblDiff, dblDiffLimit;
+#define RATIONAL_EPS (1.0/30000.0) /* reduced difference of rational values, approx 3.3e-5 */
+
+ /*-- Fill test data arrays for writing ----------- */
+ for (i=0; i<N_SIZE; i++) {
+ sprintf(auxTextArrayW[i],"N%d-String-%d_tttttttttttttttttttttttttttttx", i, i);
+ }
+ for (i=0; i<N_SIZE; i++) {
+ auxCharArrayW[i] = (char)(i+1);
+ }
+ for (i=0; i<N_SIZE; i++) {
+ auxShortArrayW[i] = (short)(i+1)*7;
+ }
+ for (i=0; i<N_SIZE; i++) {
+ auxLongArrayW[i] = (i+1)*133;
+ }
+ for (i=0; i<N_SIZE; i++) {
+ auxFloatArrayW[i] = (float)((i+1)*133)/3.3f;
+ }
+ for (i=0; i<N_SIZE; i++) {
+ auxDoubleArrayW[i] = (double)((i+1)*3689)/4.5697;
+ }
+
+ /*-- Setup standard tags of a simple tiff file --*/
+ if (!TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, width)) {
+ fprintf (stderr, "Can't set ImageWidth tag.\n");
+ goto failure;
+ }
+ if (!TIFFSetField(tif, TIFFTAG_IMAGELENGTH, length)) {
+ fprintf (stderr, "Can't set ImageLength tag.\n");
+ goto failure;
+ }
+ if (!TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, bps)) {
+ fprintf (stderr, "Can't set BitsPerSample tag.\n");
+ goto failure;
+ }
+ if (!TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, SPP)) {
+ fprintf (stderr, "Can't set SamplesPerPixel tag.\n");
+ goto failure;
+ }
+ if (!TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, rows_per_strip)) {
+ fprintf (stderr, "Can't set SamplesPerPixel tag.\n");
+ goto failure;
+ }
+ if (!TIFFSetField(tif, TIFFTAG_PLANARCONFIG, planarconfig)) {
+ fprintf (stderr, "Can't set PlanarConfiguration tag.\n");
+ goto failure;
+ }
+ if (!TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, photometric)) {
+ fprintf (stderr, "Can't set PhotometricInterpretation tag.\n");
+ goto failure;
+ }
+
+#define ADDITIONAL_TAGS
+#ifdef ADDITIONAL_TAGS
+ /*-- Additional tags to check Rational standard tags, which are also defined as FIELD_CUSTOM */
+
+ /*- TIFFTAG_INKSET is a SHORT parameter (TIFF_SHORT, TIFF_SETGET_UINT16) with field_bit=FIELD_CUSTOM !! -*/
+ if (!TIFFSetField(tif, TIFFTAG_INKSET, 34)) {
+ fprintf(stderr, "Can't set TIFFTAG_INKSET tag.\n");
+ goto failure;
+ }
+
+ /*- TIFFTAG_PIXAR_FOVCOT is a FLOAT parameter ( TIFF_FLOAT, TIFF_SETGET_FLOAT) with field_bit=FIELD_CUSTOM !! -*/
+ /* - can be written with Double but has to be read with float parameter */
+#define PIXAR_FOVCOT_VAL 5.123456789123456789
+ auxFloat = (float)PIXAR_FOVCOT_VAL;
+ auxDouble = (double)PIXAR_FOVCOT_VAL;
+ if (!TIFFSetField(tif, TIFFTAG_PIXAR_FOVCOT, auxDouble)) {
+ fprintf(stderr, "Can't set TIFFTAG_PIXAR_FOVCOT tag.\n");
+ goto failure;
+ }
+ /*- TIFFTAG_STONITS is a DOUBLE parameter (TIFF_DOUBLE, TIFF_SETGET_DOUBLE) with field_bit=FIELD_CUSTOM!
+ * Only TIFFTAG_STONITS is a TIFF_DOUBLE, which has to be read as DOUBLE!!
+ */
+#define STONITS_VAL 6.123456789123456789
+ auxDouble = STONITS_VAL;
+ auxFloat = (float)auxDouble;
+ if (!TIFFSetField(tif, TIFFTAG_STONITS, auxDouble)) {
+ fprintf(stderr, "Can't set TIFFTAG_STONITS tag.\n");
+ goto failure;
+ }
+
+ /*- TIFFTAG_YCBCRPOSITIONING is a SHORT parameter */
+ auxLong = auxShort = 5;
+ if (!TIFFSetField(tif, TIFFTAG_YCBCRPOSITIONING, auxLong )) {
+ fprintf (stderr, "Can't set TIFFTAG_YCBCRPOSITIONING tag.\n");
+ goto failure;
+ }
+
+ /* - TIFFTAG_BESTQUALITYSCALE is a Rational parameter, FIELD_CUSTOM and TIFF_SETGET_DOUBLE */
+ /* With Rational2Double upgrade tag is redefined to TIFF_SETGET_FLOAT, but can be still written with double. */
+#define BESTQUALITYSCALE_VAL 15.3
+ auxDouble = BESTQUALITYSCALE_VAL;
+ if (!TIFFSetField(tif, TIFFTAG_BESTQUALITYSCALE, auxDouble )) {
+ fprintf (stderr, "Can't set TIFFTAG_BESTQUALITYSCALE tag.\n");
+ goto failure;
+ }
+
+ /* - TIFFTAG_BASELINENOISE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT */
+ if (!TIFFSetField(tif, TIFFTAG_BASELINENOISE, auxDouble)) {
+ fprintf(stderr, "Can't set TIFFTAG_BASELINENOISE tag.\n");
+ goto failure;
+ }
+
+
+ /*--- For static or variable ARRAYs the case is different ---*/
+/*- Variable Array: TIFFTAG_DECODE is a SRATIONAL parameter TIFF_SETGET_C16_FLOAT type FIELD_CUSTOM with passcount=1 and variable length of array. */
+ if (!TIFFSetField(tif, TIFFTAG_DECODE, 3, auxFloatArrayN2)) {
+ fprintf(stderr, "Can't set TIFFTAG_DECODE tag.\n");
+ goto failure;
+ }
+
+ /*- Varable Array: TIFF_RATIONAL, 0, TIFF_SETGET_C16_FLOAT */
+ if (!TIFFSetField(tif, TIFFTAG_BLACKLEVEL, 3, auxFloatArrayN1)) {
+ fprintf(stderr, "Can't set TIFFTAG_BLACKLEVEL tag.\n");
+ goto failure;
+ }
+
+ /*- Fixed Array: TIFFTAG_DEFAULTCROPSIZE, 2, 2, TIFF_RATIONAL, 0, TIFF_SETGET_C0_FLOAT */
+ if (!TIFFSetField(tif, TIFFTAG_DEFAULTCROPSIZE, &auxFloatArrayW[0])) {
+ fprintf(stderr, "Can't set TIFFTAG_DEFAULTCROPSIZE tag.\n");
+ goto failure;
+ }
+#endif /* -- ADDITIONAL_TAGS -- */
+
+/*================== Rational2Double Interface Check =====================*/
+ /*-- Check, if the TiffLibrary is compiled with the new interface with Rational2Double or still uses the old definitions.
+ For that, TIFF_RATIONAL tags with FIELD_CUSTOM are changed from TIFF_SETGET_DOUBLE to TIFF_SETGET_FLOAT for the
+ new interface in order to prevent the old reading behaviour.
+ Tags to check: TIFFTAG_BESTQUALITYSCALE, TIFFTAG_BASELINENOISE, TIFFTAG_BASELINESHARPNESS
+ */
+ fip = TIFFFindField(tif, TIFFTAG_BESTQUALITYSCALE, TIFF_ANY);
+ tSetFieldType = fip->set_field_type;
+ if (tSetFieldType == TIFF_SETGET_DOUBLE) {
+ blnIsRational2Double = FALSE;
+ } else {
+ blnIsRational2Double = TRUE;
+ fprintf(stderr, "-- Rational2Double from TIFF tag detected --\n");
+ }
+
+/*================== Write GPS and EXIF tags =====================*/
+
+ /*-- Set dummy EXIF/GPS tag in original tiff-structure in order to reserve space for final dir_offset value, */
+ /* which is properly written at the end. */
+ dir_offset = 0; /* Zero, in case no Custom-IFD is written */
+
+#define WRITE_GPS_TAGS
+#ifdef WRITE_GPS_TAGS
+ if (!TIFFSetField(tif, TIFFTAG_GPSIFD, dir_offset )) {
+ fprintf (stderr, "Can't write TIFFTAG_GPSIFD\n" );
+ }
+#endif
+
+ /*------- And also do the same for the EXIF IFD tag here, because we have to save the main directory next ------*/
+ /*-- Set dummy EXIF/GPS tag in original tiff-structure in order to reserve space for final dir_offset value,
+ * which is properly written at the end.
+ */
+#define WRITE_EXIF_TAGS
+#ifdef WRITE_EXIF_TAGS
+ if (!TIFFSetField(tif, TIFFTAG_EXIFIFD, dir_offset )) {
+ fprintf (stderr, "Can't write TIFFTAG_EXIFIFD\n" );
+ }
+#endif
+
+#ifndef WRITEPIXELLAST
+ /*-- Write dummy pixel data. --*/
+ if (TIFFWriteScanline(tif, buf, 0, 0) < 0) {
+ fprintf (stderr, "Can't write image data.\n");
+ goto failure;
+ }
+#endif
+
+
+#ifdef WRITE_GPS_TAGS
+#define READ_GPS_TAGS
+ /*================== Write GPS tags =====================*/
+
+ /*-- Save current tiff-directory to file before directory is changed. Otherwise it will be lost! */
+ /* The tif-structure is overwritten/ freshly initialized by any "CreateDirectory" */
+ /*retCode = TIFFCheckpointDirectory(tif);*/ /* does not cleanup Tiff-Structure */
+ retCode = TIFFWriteDirectory(tif); /* cleanup Tiff-structure */
+
+ /*-- Now create a GPS directory. */
+ if (TIFFCreateGPSDirectory(tif) != 0) {
+ fprintf (stderr, "TIFFCreateGPSDirectory() failed.\n" );
+ goto failure;
+ }
+
+ if (!TIFFSetField( tif, GPSTAG_VERSIONID, gpsVersion)) {
+ fprintf (stderr, "Can't write GPSTAG_VERSIONID\n" );
+ goto failure;
+ }
+
+ if (blnFillGPSManually) {
+ /*================= Write manually valid data to the GPS fields ==============*/
+ if (!TIFFSetField( tif, GPSTAG_LATITUDEREF, "N\0")) {
+ fprintf (stderr, "Can't write GPSTAG_LATITUDEREF\n" );
+ goto failure;
+ }
+ /*-- Unfortunately, Rational values are defined as SETGET_DOUBLE but are internally always stored as float.
+ * Single Rational values do not matter for writing, because TIFFSetField() uses va_arg() which performs "variables promotion" from type float to type double!
+ * However, for reading of Rational values ONLY float-variables are allowed - in contrary to the SETGET_DOUBLE specification at tiffFields[] in tif_dirinfo.c.
+ */
+ /*-- ATTENTION: After the upgrade with Rational2Double, the GPSTAG values are defined as double precision
+ * and need to be written and also read in double precision!
+ * In order to maintain this code for both cases, it is checked above if the TiffLibrary is
+ * compiled with the new interface with Rational2Double or still uses the old definitions,
+ * by setting blnIsRational2Double above.
+ */
+ if (blnIsRational2Double) {
+ fprintf(stderr, "-- GPS tags are written using Rational2Double --\n");
+ } else {
+ fprintf(stderr, "-- GPS tags are written using standard --\n");
+ }
+ if (!blnIsRational2Double) {
+ for (j = 0; j < 3; j++) auxFloatArray[j] = (float)auxDoubleArrayGPS1[j];
+ if (!TIFFSetField(tif, GPSTAG_LATITUDE, auxFloatArray)) {
+ fprintf(stderr, "Can't write GPSTAG_LATITUDE\n");
+ goto failure;
+ }
+ } else {
+ /* Rational2Double interface for GPSTAG */
+ if (!TIFFSetField(tif, GPSTAG_LATITUDE, auxDoubleArrayGPS1)) {
+ fprintf(stderr, "Can't write GPSTAG_LATITUDE\n");
+ goto failure;
+ }
+ }
+ if (!TIFFSetField( tif, GPSTAG_LONGITUDEREF, "W\0")) {
+ fprintf (stderr, "Can't write GPSTAG_LONGITUDEREF\n" );
+ goto failure;
+ }
+ if (!blnIsRational2Double) {
+ for (j=0; j<3; j++) auxFloatArray[j] = (float)auxDoubleArrayGPS2[j];
+ if (!TIFFSetField( tif, GPSTAG_LONGITUDE, auxFloatArray)) {
+ fprintf (stderr, "Can't write GPSTAG_LONGITUDE\n" );
+ goto failure;
+ }
+ } else {
+ /* Rational2Double interface for GPSTAG */
+ if (!TIFFSetField(tif, GPSTAG_LONGITUDE, auxDoubleArrayGPS2)) {
+ fprintf(stderr, "Can't write GPSTAG_LATITUDE\n");
+ goto failure;
+ }
+ }
+ /*-- AltitudeRef: default is above sea level!! */
+ if (!TIFFSetField( tif, GPSTAG_ALTITUDEREF, 0)) {
+ fprintf (stderr, "Can't write GPSTAG_ALTITUDEREF\n" );
+ goto failure;
+ }
+ if (!TIFFSetField( tif, GPSTAG_ALTITUDE, auxDoubleGPSAltitude)) {
+ fprintf (stderr, "Can't write GPSTAG_ALTITUDE\n" );
+ goto failure;
+ }
+ /*-- TimeStamp is only hh:mm:ss. See also DateTime string */
+ if (!TIFFSetField( tif, GPSTAG_TIMESTAMP, auxDoubleArrayGPSTime)) {
+ fprintf (stderr, "Can't write GPSTAG_TIMESTAMP\n" );
+ goto failure;
+ }
+ if (!TIFFSetField( tif, GPSTAG_DATESTAMP, "2012:11:04")) {
+ fprintf (stderr, "Can't write GPSTAG_DATESTAMP\n" );
+ goto failure;
+ }
+
+ if (!TIFFSetField( tif, GPSTAG_IMGDIRECTIONREF, "T\0")) {
+ fprintf (stderr, "Can't write GPSTAG_IMGDIRECTIONREF\n" );
+ goto failure;
+ }
+ if (!TIFFSetField( tif, GPSTAG_IMGDIRECTION, auxDoubleGPSDirection)) {
+ fprintf (stderr, "Can't write GPSTAG_IMGDIRECTION\n" );
+ goto failure;
+ }
+
+ /*-- Type TIFF_UNDEFINED */
+ if (!TIFFSetField( tif, GPSTAG_PROCESSINGMETHOD, 3, &auxCharArrayW[10])) {
+ fprintf (stderr, "Can't write GPSTAG_PROCESSINGMETHOD\n" );
+ goto failure;
+ }
+ if (!TIFFSetField( tif, GPSTAG_AREAINFORMATION, 4, &auxCharArrayW[20])) {
+ fprintf (stderr, "Can't write GPSTAG_AREAINFORMATION\n" );
+ goto failure;
+ }
+
+ /*-- PSTAG_DIFFERENTIAL , 1, 1, TIFF_SHORT , 0, TIFF_SETGET_UINT16 */
+ if (!TIFFSetField( tif, GPSTAG_DIFFERENTIAL, auxShortArrayW[5])) {
+ fprintf (stderr, "Can't write GPSTAG_DIFFERENTIAL\n" );
+ goto failure;
+ }
+
+ /* GPSTAG_GPSHPOSITIONINGERROR , 1, 1, TIFF_RATIONAL , 0, TIFF_SETGET_DOUBLE but here written in float-precision */
+#define GPSHPOSITIONINGERROR_VAL 0.369
+ auxFloat = (float)GPSHPOSITIONINGERROR_VAL;
+ if (!TIFFSetField( tif, GPSTAG_GPSHPOSITIONINGERROR, auxFloat)) {
+ fprintf (stderr, "Can't write GPSTAG_GPSHPOSITIONINGERROR\n" );
+ goto failure;
+ }
+
+ } else {
+ /*================= Write arbitrary data to the GPS fields ==============*/
+
+ /*-- Get array, where GPS tag fields are defined --*/
+ tFieldArray = _TIFFGetGpsFields();
+ nTags = tFieldArray->count;
+
+ /*-- TODO: fill in the for / switch part of EXIF writing, when finished and tested!! */
+
+ } /*-- if (blnFillGPSManually) --*/
+
+
+
+
+ /*-- GPS - write custom directory GPS into file...---*/
+ /* (Get back the offset of GPS directory) */
+ if (!TIFFWriteCustomDirectory( tif, &dir_offset_GPS )) {
+ fprintf (stderr, "TIFFWriteCustomDirectory() with GPS failed.\n");
+ goto failure;
+ }
+
+ /*--- CheckpointDirectory at this place generates a second Main-IFD!!! */
+ /* retCode = TIFFCheckpointDirectory(tif); */
+
+ /*-- Set / reload previously saved main directory from file ---*/
+ if (!TIFFSetDirectory(tif, 0)) {
+ fprintf (stderr, "TIFFSetDirectory() within GPS failed.\n");
+ goto failure;
+ }
+
+ /*-- Write GPS tag reference / offset into GPSIFD tag in main directory --*/
+ if (!TIFFSetField(tif, TIFFTAG_GPSIFD, dir_offset_GPS )) {
+ fprintf (stderr, "Can't write TIFFTAG_GPSIFD\n");
+ goto failure;
+ }
+
+ /*=============== END writing GPS tags ==========================*/
+#endif /*-- WRITE_GPS_TAGS --*/
+
+
+/*================== Write EXIF 2.31 tags =====================*/
+
+ /*-- Set dummy EXIF/GPS tag in original tiff-structure in order to reserve space for final dir_offset value, */
+ /* which is properly written at the end.*/
+ /*- We did this already above together with the GPS IFD-tag. Otherwise we would do this here !! --------*/
+ /* if (!TIFFSetField(tif, TIFFTAG_EXIFIFD, dir_offset )) {
+ fprintf (stderr, "Can't write TIFFTAG_EXIFIFD\n" );
+ }
+ */
+
+#ifdef WRITE_EXIF_TAGS
+#define READ_EXIF_TAGS
+ /*-- Save current tiff-directory to file before directory is changed. Otherwise it will be lost!
+ * The tif-structure is overwritten/ freshly initialized by any "CreateDirectory"
+ */
+
+ /*----- What is needed here ??? ----
+ * In custom_dir.c only TIFFFreeDirectory( tif ); is used to set fields of another Sub-Directory
+ * TIFFFreeDirectory(tif); *-- Release storage associated with a directory, especially custom-fields.
+ *-- Using only TIFFFreeDirectory() here leads to an error!!
+ *-- Using here TIFFCheckpointDirectory() leads to an additional Main-IFD ??
+ */
+ /*retCode = TIFFCheckpointDirectory(tif);*/ /* does not cleanup Tiff-Structure */
+ retCode = TIFFWriteDirectory(tif); /* cleanup Tiff-structure */
+
+ /*-- Now create an EXIF directory. */
+ if (TIFFCreateEXIFDirectory(tif) != 0) {
+ fprintf (stderr, "TIFFCreateEXIFDirectory() failed.\n" );
+ goto failure;
+ }
+
+#define WRITE_ALL_EXIF_TAGS
+#ifdef WRITE_ALL_EXIF_TAGS
+#define READ_ALL_EXIF_TAGS
+ /*================= EXIF: Write arbitrary data to the EXIF fields ==============*/
+ /*-- Get array, where EXIF tag fields are defined
+ * EXIF tags are written automatically with the defined precision according to its tSetFieldType using the code below --*/
+ tFieldArray = _TIFFGetExifFields();
+ nTags = tFieldArray->count;
+
+ for (i=0; i<nTags; i++) {
+ tTag = tFieldArray->fields[i].field_tag;
+ tType = tFieldArray->fields[i].field_type; /* e.g. TIFF_RATIONAL */
+ tWriteCount = tFieldArray->fields[i].field_writecount;
+ tSetFieldType = tFieldArray->fields[i].set_field_type; /* e.g. TIFF_SETGET_C0_FLOAT */
+ tFieldName = tFieldArray->fields[i].field_name;
+ pVoid = NULL;
+
+ /*-- dependent on set_field_type write value --*/
+ switch (tSetFieldType)
+ {
+ case TIFF_SETGET_ASCII:
+ /* Either the stringlength is defined as a fixed length in .field_writecount or a NULL-terminated string is used. */
+ /* Shorter strings than in auxTextArraxW need a NULL-termination. Therefore copy the string. */
+ if (tWriteCount > 0) auxLong = tWriteCount-1; else auxLong = (long)strlen(auxTextArrayW[i])-1;
+ strncpy(auxCharArray, auxTextArrayW[i], auxLong);
+ auxCharArray[auxLong] = 0;
+ if (!TIFFSetField( tif, tTag, auxCharArray)) {
+ fprintf (stderr, "Can't write %s\n", tFieldArray->fields[i].field_name);
+ goto failure;
+ }
+ break;
+ case TIFF_SETGET_UINT8:
+ case TIFF_SETGET_UINT16:
+ case TIFF_SETGET_UINT32:
+ case TIFF_SETGET_IFD8:
+ case TIFF_SETGET_INT:
+ /*-- All those can be written with char, short or long parameter. Only value range should be in line. */
+ if (!TIFFSetField( tif, tTag, auxLongArrayW[i])) {
+ fprintf (stderr, "Can't write %s\n", tFieldArray->fields[i].field_name);
+ goto failure;
+ }
+ break;
+ case TIFF_SETGET_SINT8:
+ case TIFF_SETGET_SINT16:
+ case TIFF_SETGET_SINT32:
+ /*-- All those can be written with char, short or long parameter. Only value range should be in line. */
+ if (!TIFFSetField( tif, tTag, -1.0*auxLongArrayW[i])) {
+ fprintf (stderr, "Can't write %s\n", tFieldArray->fields[i].field_name);
+ goto failure;
+ }
+ break;
+ case TIFF_SETGET_FLOAT:
+ case TIFF_SETGET_DOUBLE:
+ if (tWriteCount == 1) {
+ /*-- All single values can be written with float or double parameter. Only value range should be in line. */
+ if (!TIFFSetField( tif, tTag, auxDoubleArrayW[i])) {
+ fprintf (stderr, "Can't write %s\n", tFieldArray->fields[i].field_name);
+ goto failure;
+ }
+ } else {
+ fprintf (stderr, "WriteCount for .set_field_type %d should be 1! %s\n", tSetFieldType, tFieldArray->fields[i].field_name);
+ }
+ break;
+ case TIFF_SETGET_C0_FLOAT:
+ case TIFF_SETGET_C0_DOUBLE:
+ case TIFF_SETGET_C16_FLOAT:
+ case TIFF_SETGET_C16_DOUBLE:
+ case TIFF_SETGET_C32_FLOAT:
+ case TIFF_SETGET_C32_DOUBLE:
+ /* _Cxx_ just defines the size of the count parameter for the array as C0=char, C16=short or C32=long */
+ /*-- Check, if it is a single parameter, a fixed array or a variable array */
+ if (tWriteCount == 1) {
+ fprintf (stderr, "WriteCount for .set_field_type %d should be -1 or greather than 1! %s\n", tSetFieldType, tFieldArray->fields[i].field_name);
+ } else {
+ /*-- Either fix or variable array --*/
+ /* For arrays, distinguishing between float or double is essential, even for writing */
+ if (tSetFieldType == TIFF_SETGET_C0_FLOAT || tSetFieldType == TIFF_SETGET_C16_FLOAT || tSetFieldType == TIFF_SETGET_C32_FLOAT)
+ pVoid = &auxFloatArrayW[i]; else pVoid = &auxDoubleArrayW[i];
+ /* Now decide between fixed or variable array */
+ if (tWriteCount > 1) {
+ /* fixed array with needed arraysize defined in .field_writecount */
+ if (!TIFFSetField( tif, tTag, pVoid)) {
+ fprintf (stderr, "Can't write %s\n", tFieldArray->fields[i].field_name);
+ goto failure;
+ }
+ } else {
+ /* special treatment of variable array */
+ /* for test, use always arraysize of VARIABLE_ARRAY_SIZE */
+ if (!TIFFSetField( tif, tTag, VARIABLE_ARRAY_SIZE, pVoid)) {
+ fprintf (stderr, "Can't write %s\n", tFieldArray->fields[i].field_name);
+ goto failure;
+ }
+ }
+ }
+ break;
+ case TIFF_SETGET_C0_UINT8:
+ case TIFF_SETGET_C0_SINT8:
+ case TIFF_SETGET_C16_UINT8:
+ case TIFF_SETGET_C16_SINT8:
+ case TIFF_SETGET_C32_UINT8:
+ case TIFF_SETGET_C32_SINT8:
+ /* For arrays, distinguishing between float or double is essential, even for writing */
+ pVoid = &auxCharArrayW[i];
+ case TIFF_SETGET_C0_UINT16:
+ case TIFF_SETGET_C0_SINT16:
+ case TIFF_SETGET_C16_UINT16:
+ case TIFF_SETGET_C16_SINT16:
+ case TIFF_SETGET_C32_UINT16:
+ case TIFF_SETGET_C32_SINT16:
+ if (pVoid == NULL) pVoid = &auxShortArrayW[i];
+ case TIFF_SETGET_C0_UINT32:
+ case TIFF_SETGET_C0_SINT32:
+ case TIFF_SETGET_C16_UINT32:
+ case TIFF_SETGET_C16_SINT32:
+ case TIFF_SETGET_C32_UINT32:
+ case TIFF_SETGET_C32_SINT32:
+ if (pVoid == NULL) pVoid = &auxLongArrayW[i];
+ /* _Cxx_ just defines the size of the count parameter for the array as C0=char, C16=short or C32=long */
+ /*-- Check, if it is a single parameter, a fixed array or a variable array */
+ if (tWriteCount == 1) {
+ fprintf (stderr, "WriteCount for .set_field_type %d should be -1 or greather than 1! %s\n", tSetFieldType, tFieldArray->fields[i].field_name);
+ } else {
+ /*-- Either fix or variable array --*/
+ /* Now decide between fixed or variable array */
+ if (tWriteCount > 1) {
+ /* fixed array with needed arraysize defined in .field_writecount */
+ if (!TIFFSetField( tif, tTag, pVoid)) {
+ fprintf (stderr, "Can't write %s\n", tFieldArray->fields[i].field_name);
+ goto failure;
+ }
+ } else {
+ /* special treatment of variable array */
+ /* for test, use always arraysize of VARIABLE_ARRAY_SIZE */
+ if (!TIFFSetField( tif, tTag, VARIABLE_ARRAY_SIZE, pVoid)) {
+ fprintf (stderr, "Can't write %s\n", tFieldArray->fields[i].field_name);
+ goto failure;
+ }
+ }
+ }
+ break;
+ default:
+ fprintf (stderr, "SetFieldType %d not defined within writing switch for %s.\n", tSetFieldType, tFieldName);
+ }; /*-- switch() --*/
+ } /*-- for() --*/
+ /*================= EXIF: END Writing arbitrary data to the EXIF fields END END END ==============*/
+#endif /*-- WRITE_ALL_EXIF_TAGS --*/
+
+ /*--- Set valid EXIF version, which is a 4 byte string --*/
+ if (!TIFFSetField( tif, EXIFTAG_EXIFVERSION, exifVersion)) {
+ fprintf (stderr, "Can't write EXIFTAG_EXIFVERSION\n" );
+ goto failure;
+ }
+
+
+ /*-- EXIF - write custom directory EXIF into file...---*/
+ /* (Get back the offset of EXIF directory) */
+ if (!TIFFWriteCustomDirectory( tif, &dir_offset_EXIF )) {
+ fprintf (stderr, "TIFFWriteCustomDirectory() with EXIF failed.\n");
+ goto failure;
+ }
+
+ /*-- Go back to the first (main) directory, and set correct value of the EXIFIFD pointer. */
+ /* (directory is reloaded from file!) */
+ TIFFSetDirectory(tif, 0);
+ TIFFSetField(tif, TIFFTAG_EXIFIFD, dir_offset_EXIF );
+#endif /*-- WRITE_EXIF_TAGS --*/
+
+#ifdef WRITEPIXELLAST
+ /*-- Write dummy pixel data. --*/
+ if (TIFFWriteScanline(tif, buf, 0, 0) < 0) {
+ fprintf (stderr, "Can't write image data.\n");
+ goto failure;
+ }
+#endif
+ /*-- Write directory to file --*/
+ /* Always WriteDirectory before using/creating another directory. */
+ /* Not necessary before TIFFClose(), however, TIFFClose() uses TIFFReWriteDirectory(), which forces directory to be written at another location. */
+ retCode = TIFFWriteDirectory(tif);
+
+ /*-- Write File to disk and close file --*/
+ /* TIFFClose() uses TIFFReWriteDirectory(), which forces directory to be written at another location. */
+ /* Therefore, better use TIFFWriteDirectory() before. */
+ TIFFClose(tif);
+
+ fprintf (stderr, "-------- Continue Test ---------- reading ...\n");
+
+/*========================= READING ============= READING ========================================*/
+ /* Ok, now test whether we can read written values correctly. */
+ tif = TIFFOpen(filenameRead, "r");
+
+
+ /*-- Read some parameters out of the main directory --*/
+
+ /*-- IMAGEWIDTH and -LENGTH are defined as TIFF_SETGET_UINT32 */
+ retCode = TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &auxUint32 );
+ if (!retCode) { fprintf(stderr, "Can't read %s\n", "TIFFTAG_IMAGEWIDTH"); }
+ if (auxUint32 != width) {
+ fprintf (stderr, "Read value of IMAGEWIDTH %d differs from set value %d\n", auxUint32, width);
+ }
+ retCode = TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &auxUint32 );
+ if (!retCode) { fprintf(stderr, "Can't read %s\n", "TIFFTAG_IMAGELENGTH"); }
+ if (auxUint32 != width) {
+ fprintf (stderr, "Read value of TIFFTAG_IMAGELENGTH %d differs from set value %d\n", auxUint32, length);
+ }
+
+#ifdef ADDITIONAL_TAGS
+ /*- TIFFTAG_PIXAR_FOVCOT is a FLOAT parameter of type FIELD_CUSTOM !! */
+ retCode = TIFFGetField(tif, TIFFTAG_PIXAR_FOVCOT, &auxFloat );
+ if (!retCode) { fprintf(stderr, "Can't read %s\n", "TIFFTAG_PIXAR_FOVCOT"); }
+ if (auxFloat != (float)PIXAR_FOVCOT_VAL) {
+ fprintf (stderr, "Read value of TIFFTAG_PIXAR_FOVCOT %f differs from set value %f\n", auxFloat, PIXAR_FOVCOT_VAL);
+ }
+
+ /* - TIFFTAG_BESTQUALITYSCALE is a Rational parameter, FIELD_CUSTOM and TIFF_SETGET_FLOAT */
+ retCode = TIFFGetField(tif, TIFFTAG_BESTQUALITYSCALE, &auxFloat );
+ if (!retCode) { fprintf(stderr, "Can't read %s\n", "TIFFTAG_BESTQUALITYSCALE"); }
+ if (auxFloat != (float)BESTQUALITYSCALE_VAL) {
+ fprintf (stderr, "Read value of TIFFTAG_BESTQUALITYSCALE %f differs from set value %f\n", auxFloat, BESTQUALITYSCALE_VAL);
+ }
+
+ /* - TIFFTAG_BASELINENOISE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT */
+ retCode = TIFFGetField(tif, TIFFTAG_BASELINENOISE, &auxDblUnion.dbl);
+ if (!retCode) { fprintf(stderr, "Can't read %s\n", "TIFFTAG_BASELINENOISE"); }
+ if (auxDblUnion.flt1 != (float)BESTQUALITYSCALE_VAL) {
+ fprintf(stderr, "Read float value of TIFFTAG_BASELINENOISE %f differs from set value %f\n", auxDblUnion.flt1, BESTQUALITYSCALE_VAL);
+ }
+
+
+ /*- Variable Array: TIFFTAG_DECODE is a SRATIONAL parameter TIFF_SETGET_C16_FLOAT type FIELD_CUSTOM with passcount=1 and variable length of array. */
+ retCode = TIFFGetField(tif, TIFFTAG_DECODE, &count16, &pVoidArray );
+ if (!retCode) { fprintf(stderr, "Can't read %s\n", "TIFFTAG_DECODE"); }
+ /*- pVoidArray points to a Tiff-internal temporary memorypart. Thus, contents needs to be saved. */
+ memcpy(&auxFloatArray, pVoidArray,(count16 * sizeof(auxFloatArray[0])));
+ for (i=0; i<count16; i++) {
+ dblDiffLimit = RATIONAL_EPS*auxFloatArrayN2[i];
+ dblDiff = auxFloatArray[i] - auxFloatArrayN2[i];
+ if (fabs(dblDiff) > fabs(dblDiffLimit)) {
+ fprintf (stderr, "Read value %d of TIFFTAG_DECODE Array %f differs from set value %f\n", i, auxFloatArray[i], auxFloatArrayN2[i]);
+ }
+ }
+
+ retCode = TIFFGetField(tif, TIFFTAG_BLACKLEVEL, &count16, &pVoidArray);
+ if (!retCode) { fprintf(stderr, "Can't read %s\n", "TIFFTAG_BLACKLEVEL"); }
+ /*- pVoidArray points to a Tiff-internal temporary memorypart. Thus, contents needs to be saved. */
+ memcpy(&auxFloatArray, pVoidArray, (count16 * sizeof(auxFloatArray[0])));
+ for (i = 0; i<count16; i++) {
+ dblDiffLimit = RATIONAL_EPS*auxFloatArrayN1[i];
+ dblDiff = auxFloatArray[i] - auxFloatArrayN1[i];
+ if (fabs(dblDiff) > fabs(dblDiffLimit)) {
+ fprintf(stderr, "Read value %d of TIFFTAG_BLACKLEVEL Array %f differs from set value %f\n", i, auxFloatArray[i], auxFloatArrayN1[i]);
+ }
+ }
+
+ /*- Fixed Array: TIFFTAG_DEFAULTCROPSIZE, 2, 2, TIFF_RATIONAL, 0, TIFF_SETGET_C0_FLOAT */
+ retCode = TIFFGetField(tif, TIFFTAG_DEFAULTCROPSIZE, &pVoidArray);
+ if (!retCode) { fprintf(stderr, "Can't read %s\n", "TIFFTAG_DEFAULTCROPSIZE"); }
+ /*- pVoidArray points to a Tiff-internal temporary memorypart. Thus, contents needs to be saved. */
+ memcpy(&auxFloatArray, pVoidArray, (2 * sizeof(auxFloatArray[0])));
+ for (i = 0; i < 2; i++) {
+ dblDiffLimit = RATIONAL_EPS * auxFloatArrayW[i];
+ dblDiff = auxFloatArray[i] - auxFloatArrayW[i];
+ if (fabs(dblDiff) > fabs(dblDiffLimit)) {
+ fprintf(stderr, "Read value %d of TIFFTAG_DEFAULTCROPSIZE Array %f differs from set value %f\n", i, auxFloatArray[i], auxFloatArrayW[i]);
+ }
+ }
+
+#endif /*-- ADDITIONAL_TAGS --*/
+
+
+#ifdef READ_GPS_TAGS
+/*================== Reading GPS tags =====================*/
+ /*-- First get offset to GPS-directory and set it active (this will destroy previously main directory fields in memory!) */
+ retCode = TIFFGetField(tif, TIFFTAG_GPSIFD, &read_dir_offset );
+ if (!retCode) {fprintf(stderr, "Can't read %s\n", "TIFFTAG_GPSIFD"); }
+ retCode = TIFFReadGPSDirectory(tif, read_dir_offset);
+ if (!retCode) { fprintf(stderr, "Can't read %s\n", "TIFFReadGPSDirectory()"); }
+
+ /*-- Now read some parameters from GPS-directory --*/
+
+ /*-- Fixed Array: GPS-Version is a fixed array (of 4 characters) */
+ retCode = TIFFGetField(tif, GPSTAG_VERSIONID, &pGpsVersion);
+ if (!retCode) { fprintf(stderr, "Can't read %s\n", "GPSTAG_VERSIONID"); }
+ else {
+ memcpy(auxCharArray, pGpsVersion, sizeof(gpsVersion));
+ for (i = 0; i < 4; i++) {
+ if (auxCharArray[i] != pGpsVersion[i]) {
+ fprintf(stderr, "Read value %d of GPSTAG_VERSIONID %d differs from set value %d\n", i, auxCharArray[i], pGpsVersion[i]);
+ }
+ }
+ }
+ /*-- LATITUDEREF is a fixed String of one character plus ending zero. */
+ retCode = TIFFGetField(tif, GPSTAG_LATITUDEREF, &pAscii);
+ if (!retCode) { fprintf(stderr, "Can't read %s\n", "GPSTAG_LATITUDEREF"); }
+ retCode2 = strncmp("N", pAscii, 1);
+ if (retCode2 != 0) {
+ fprintf (stderr, "Read value %d of GPSTAG_LATITUDEREF %s differs from set value %s\n", i, "N", pAscii);
+ }
+
+ /*-- Fixed Array: Latitude is an array of 3 Rational-values. TIFFGetField() returns a pointer to a temporary float-/double-array. */
+ /*-- ATTENTION: After the upgrade with Rational2Double, the GPSTAG values are defined as double precision
+ * and need to be written and also read in double precision!
+ * In order to maintain this code for both cases, it is checked above if the TiffLibrary is
+ * compiled with the new interface with Rational2Double or still uses the old definitions,
+ * by setting blnIsRational2Double above.
+ */
+ if (blnIsRational2Double) {
+ fprintf(stderr, "-- GPS tags are read using Rational2Double --\n");
+ } else {
+ fprintf(stderr, "-- GPS tags are read using standard --\n");
+ }
+ retCode = TIFFGetField(tif, GPSTAG_LATITUDE, &pVoidArray);
+ if (!retCode) { fprintf(stderr, "Can't read %s\n", "GPSTAG_LATITUDE"); }
+ if (!blnIsRational2Double) {
+ /* Reset arrays for debugging purpose first */
+ memset(auxFloatArray, 0, sizeof(auxFloatArray));
+ memcpy(auxFloatArray, pVoidArray, 3*sizeof(float));
+ /* for comparison copy to doubleArray */
+ for (i=0; i<3; i++) auxDoubleArray[i] = (double)auxFloatArray[i];
+ } else {
+ /* Rational2Double interface for GPSTAG reads double array */
+ memset(auxDoubleArray, 0, sizeof(auxDoubleArray));
+ memcpy(auxDoubleArray, pVoidArray, 3 * sizeof(double));
+ }
+ for (i=0; i<3; i++) {
+ dblDiffLimit = RATIONAL_EPS*auxDoubleArrayGPS1[i];
+ dblDiff = auxDoubleArray[i] - auxDoubleArrayGPS1[i];
+ if (fabs(dblDiff) > fabs(dblDiffLimit)) {
+ fprintf (stderr, "Read value %d of GPSTAG_LATITUDE %f differs from set value %f\n", i, auxDoubleArray[i], auxDoubleArrayGPS1[i]);
+ }
+ }
+
+ /*-- LONGITUDEREF is a fixed String of one character plus ending zero. */
+ retCode = TIFFGetField(tif, GPSTAG_LONGITUDEREF, &pAscii);
+ if (!retCode) { fprintf(stderr, "Can't read %s\n", "GPSTAG_LONGITUDEREF"); }
+ retCode2 = strncmp("W", pAscii, 1);
+ if (retCode2 != 0) {
+ fprintf(stderr, "Read value %d of GPSTAG_LONGITUDEREF %s differs from set value %s\n", i, "W", pAscii);
+ }
+
+ retCode = TIFFGetField(tif, GPSTAG_LONGITUDE, &pVoidArray);
+ if (!retCode) { fprintf(stderr, "Can't read %s\n", "GPSTAG_LONGITUDE"); }
+ if (!blnIsRational2Double) {
+ /* Reset arrays for debugging purpose first */
+ memset(auxFloatArray, 0, sizeof(auxFloatArray));
+ memcpy(auxFloatArray, pVoidArray, 3 * sizeof(float));
+ /* for comparison copy to doubleArray */
+ for (i = 0; i < 3; i++) auxDoubleArray[i] = (double)auxFloatArray[i];
+ } else {
+ /* Rational2Double interface for GPSTAG reads double array */
+ memset(auxDoubleArray, 0, sizeof(auxDoubleArray));
+ memcpy(auxDoubleArray, pVoidArray, 3 * sizeof(double));
+ }
+ for (i = 0; i < 3; i++) {
+ dblDiffLimit = RATIONAL_EPS * auxDoubleArrayGPS2[i];
+ dblDiff = auxDoubleArray[i] - auxDoubleArrayGPS2[i];
+ if (fabs(dblDiff) > fabs(dblDiffLimit)) {
+ fprintf(stderr, "Read value %d of GPSTAG_LONGITUDE %f differs from set value %f\n", i, auxDoubleArray[i], auxDoubleArrayGPS2[i]);
+ }
+ }
+
+ /* TIFF_RATIONAL, TIFF_SETGET_DOUBLE */
+ if (!TIFFGetField(tif, GPSTAG_ALTITUDE, &auxDblUnion.dbl)) {
+ fprintf(stderr, "Can't read GPSTAG_ALTITUDE\n");
+ GOTOFAILURE_GPS
+ }
+ if (blnIsRational2Double) {
+ /* New interface allows also double precision for TIFF_RATIONAL */
+ auxDouble = auxDblUnion.dbl;
+ } else {
+ /* Old interface reads TIFF_RATIONAL defined as TIFF_SETGET_DOUBLE alwasy as FLOAT */
+ auxDouble = (double)auxDblUnion.flt1;
+ }
+ /* compare read values with written ones */
+ dblDiffLimit = RATIONAL_EPS * auxDoubleGPSAltitude;
+ dblDiff = auxDouble - auxDoubleGPSAltitude;
+ if (fabs(dblDiff) > fabs(dblDiffLimit)) {
+ fprintf(stderr, "Read value of GPSTAG_ALTITUDE %f differs from set value %f\n", auxDouble, auxDoubleGPSAltitude);
+ GOTOFAILURE_GPS
+ }
+
+ /*-- TimeStamp is only hh:mm:ss. See also DateTime string 3, TIFF_RATIONAL, TIFF_SETGET_C0_DOUBLE */
+ retCode = TIFFGetField(tif, GPSTAG_TIMESTAMP, &pVoidArray);
+ if (!retCode) { fprintf(stderr, "Can't read %s\n", "GPSTAG_TIMESTAMP"); }
+ if (!blnIsRational2Double) {
+ /* Reset arrays for debugging purpose first */
+ memset(auxFloatArray, 0, sizeof(auxFloatArray));
+ memcpy(auxFloatArray, pVoidArray, 3 * sizeof(float));
+ /* for comparison copy to doubleArray */
+ for (i = 0; i < 3; i++) auxDoubleArray[i] = (double)auxFloatArray[i];
+ } else {
+ /* Rational2Double interface for GPSTAG reads double array */
+ memset(auxDoubleArray, 0, sizeof(auxDoubleArray));
+ memcpy(auxDoubleArray, pVoidArray, 3 * sizeof(double));
+ }
+ for (i = 0; i < 3; i++) {
+ dblDiffLimit = RATIONAL_EPS * auxDoubleArrayGPSTime[i];
+ dblDiff = auxDoubleArray[i] - auxDoubleArrayGPSTime[i];
+ if (fabs(dblDiff) > fabs(dblDiffLimit)) {
+ fprintf(stderr, "Read value %d of GPSTAG_TIMESTAMP %f differs from set value %f\n", i, auxDoubleArray[i], auxDoubleArrayGPS2[i]);
+ GOTOFAILURE_GPS
+ }
+ }
+
+ /* GPSTAG_IMGDIRECTION --- TIFF_RATIONAL, TIFF_SETGET_DOUBLE */
+ if (!TIFFGetField(tif, GPSTAG_IMGDIRECTION, &auxDblUnion.dbl)) {
+ fprintf(stderr, "Can't read GPSTAG_IMGDIRECTION\n");
+ GOTOFAILURE_GPS
+ }
+ if (blnIsRational2Double) {
+ /* New interface allows also double precision for TIFF_RATIONAL */
+ auxDouble = auxDblUnion.dbl;
+ } else {
+ /* Old interface reads TIFF_RATIONAL defined as TIFF_SETGET_DOUBLE alwasy as FLOAT */
+ auxDouble = (double)auxDblUnion.flt1;
+ }
+ /* compare read values with written ones */
+ dblDiffLimit = RATIONAL_EPS * auxDoubleGPSDirection;
+ dblDiff = auxDouble - auxDoubleGPSDirection;
+ if (fabs(dblDiff) > fabs(dblDiffLimit)) {
+ fprintf(stderr, "Read value of GPSTAG_IMGDIRECTION %f differs from set value %f\n", auxDouble, auxDoubleGPSDirection);
+ GOTOFAILURE_GPS
+ }
+
+ /*-- GPSTAG_DIFFERENTIAL , 1, 1, TIFF_SHORT , 0, TIFF_SETGET_UINT16 */
+ retCode = TIFFGetField(tif, GPSTAG_DIFFERENTIAL, &auxShort);
+ if (!retCode) { fprintf(stderr, "Can't read %s\n", "GPSTAG_DIFFERENTIAL"); }
+ if (auxShort != auxShortArrayW[5]) {
+ fprintf(stderr, "Read value of GPSTAG_DIFFERENTIAL %d differs from set value %d\n", auxShort, auxShortArrayW[5]);
+ GOTOFAILURE_GPS
+ }
+
+ /*-- GPSHPOSITIONINGERROR - new tag for EXIF 2.31 --*/
+ if (!TIFFGetField(tif, GPSTAG_GPSHPOSITIONINGERROR, &auxDblUnion.dbl)) {
+ fprintf(stderr, "Can't read GPSTAG_GPSHPOSITIONINGERROR\n");
+ GOTOFAILURE_GPS
+ }
+ if (blnIsRational2Double) {
+ /* New interface allows also double precision for TIFF_RATIONAL */
+ auxDouble = auxDblUnion.dbl;
+ } else {
+ /* Old interface reads TIFF_RATIONAL defined as TIFF_SETGET_DOUBLE alwasy as FLOAT */
+ auxDouble = (double)auxDblUnion.flt1;
+ }
+ /* compare read values with written ones */
+ auxFloat = (float)GPSHPOSITIONINGERROR_VAL;
+ dblDiffLimit = RATIONAL_EPS * auxFloat;
+ dblDiff = auxDouble - auxFloat;
+ if (fabs(dblDiff) > fabs(dblDiffLimit)) {
+ fprintf(stderr, "Read value of GPSTAG_GPSHPOSITIONINGERROR %f differs from set value %f\n", auxDouble, auxFloat);
+ GOTOFAILURE_GPS
+ }
+
+ /*=============== END reading GPS tags ==========================*/
+#endif /*-- READ_GPS_TAGS --*/
+
+
+
+/*================== Reading EXIF 2.31 tags =====================*/
+
+ /*--- Firstly, get EXIF directory offset from main directory. */
+
+ /*-- Go back to the first (main) directory, and get value of the EXIFIFD directory- offset. */
+ /* (directory is reloaded from file!) */
+ TIFFSetDirectory(tif, 0);
+ retCode = TIFFGetField(tif, TIFFTAG_EXIFIFD, &read_dir_offset );
+
+#ifdef READ_EXIF_TAGS
+ /*-- Now read EXIF directory from file into memory --*/
+ retCode = TIFFReadEXIFDirectory(tif, read_dir_offset);
+
+ /*-- Now get some parameters from EXIF-directory (already read into memory) --*/
+ retCode = TIFFGetField(tif, EXIFTAG_EXIFVERSION, &pAscii);
+
+
+#ifdef READ_ALL_EXIF_TAGS
+ /*-- Get array, where EXIF tag fields are defined --*/
+ tFieldArray = _TIFFGetExifFields();
+ nTags = tFieldArray->count;
+ /*-- Check, if the TiffLibrary is compiled with the new interface with Rational2Double or still uses the old definitions. */
+ /* tif points to EXIF tags, so TIFFFindField() can only access the EXIF tag fields */
+ fip = TIFFFindField(tif, EXIFTAG_EXPOSURETIME, TIFF_ANY);
+ tSetFieldType = fip->set_field_type;
+ if (tSetFieldType == TIFF_SETGET_DOUBLE) {
+ blnIsRational2Double = FALSE;
+ fprintf(stderr, "-- EXIF tags read with standard --\n");
+ } else {
+ blnIsRational2Double = TRUE;
+ fprintf(stderr, "-- Rational2Double for reading EXIF tags detected --\n");
+ }
+
+ for (i=0; i<nTags; i++) {
+ tTag = tFieldArray->fields[i].field_tag;
+ tType = tFieldArray->fields[i].field_type; /* e.g. TIFF_RATIONAL */
+ tWriteCount = tFieldArray->fields[i].field_writecount;
+ tSetFieldType = tFieldArray->fields[i].set_field_type; /* e.g. TIFF_SETGET_C0_FLOAT */
+ tFieldName = tFieldArray->fields[i].field_name;
+ pVoid = NULL;
+
+ /*-- dependent on set_field_type read value --*/
+ switch (tSetFieldType)
+ {
+ case TIFF_SETGET_ASCII:
+ /* Either the stringlength is defined as a fixed length in .field_writecount or a NULL-terminated string is used. */
+ if (!TIFFGetField( tif, tTag, &pAscii)) {
+ fprintf (stderr, "Can't read %s\n", tFieldArray->fields[i].field_name);
+ GOTOFAILURE_ALL_EXIF
+ break;
+ }
+ /* Save string from temporary buffer and compare with written string. */
+ strncpy(auxCharArray, pAscii, sizeof(auxCharArray));
+ if (tWriteCount > 0) auxLong = tWriteCount-1; else auxLong = (long)strlen(auxCharArray);
+ retCode2 = strncmp(auxCharArray, auxTextArrayW[i], auxLong);
+ if (retCode2 != 0) {
+ fprintf (stderr, "%d:Read value of %s %s differs from set value %s\n", i, tFieldName, auxCharArray, auxTextArrayW[i]);
+ GOTOFAILURE_ALL_EXIF
+ }
+ break;
+ /*-- For reading, the parameter size is to be observed !! */
+ case TIFF_SETGET_UINT8:
+ case TIFF_SETGET_SINT8:
+ if (!TIFFGetField( tif, tTag, &auxChar)) {
+ fprintf (stderr, "Can't read %s\n", tFieldArray->fields[i].field_name);
+ GOTOFAILURE_ALL_EXIF
+ break;
+ }
+ /* compare read values with written ones */
+ auxLong = auxChar;
+ if (auxLong != (char)auxLongArrayW[i]) {
+ fprintf (stderr, "%d:Read value of %s %ld differs from set value %ld\n", i, tFieldName, auxLong, auxLongArrayW[i]);
+ }
+ break;
+ case TIFF_SETGET_UINT16:
+ case TIFF_SETGET_SINT16:
+ if (!TIFFGetField( tif, tTag, &auxShort)) {
+ fprintf (stderr, "Can't read %s\n", tFieldArray->fields[i].field_name);
+ GOTOFAILURE_ALL_EXIF
+ break;
+ }
+ /* compare read values with written ones */
+ auxLong = auxShort;
+ if (auxLong != (short)auxLongArrayW[i]) {
+ fprintf (stderr, "%d:Read value of %s %ld differs from set value %ld\n", i, tFieldName, auxLong, auxLongArrayW[i]);
+ }
+ break;
+ case TIFF_SETGET_UINT32:
+ case TIFF_SETGET_SINT32:
+ case TIFF_SETGET_IFD8:
+ case TIFF_SETGET_INT:
+ if (!TIFFGetField( tif, tTag, &auxUint32)) {
+ fprintf (stderr, "Can't read %s\n", tFieldArray->fields[i].field_name);
+ GOTOFAILURE_ALL_EXIF
+ break;
+ }
+ /* compare read values with written ones */
+ auxLong = auxUint32;
+ if (auxLong != auxLongArrayW[i]) {
+ fprintf (stderr, "%d:Read value of %s %ld differs from set value %ld\n", i, tFieldName, auxLong, auxLongArrayW[i]);
+ }
+ break;
+ case TIFF_SETGET_FLOAT:
+ if (!TIFFGetField( tif, tTag, &auxFloat)) {
+ fprintf (stderr, "Can't read %s\n", tFieldArray->fields[i].field_name);
+ GOTOFAILURE_ALL_EXIF
+ break;
+ }
+ /* compare read values with written ones */
+ if (tType == TIFF_RATIONAL || tType == TIFF_SRATIONAL) dblDiffLimit = RATIONAL_EPS*auxDoubleArrayW[i]; else dblDiffLimit = 1e-6;
+ dblDiff = auxFloat - auxDoubleArrayW[i];
+ if (fabs(dblDiff) > fabs(dblDiffLimit)) {
+ /*--: EXIFTAG_SUBJECTDISTANCE: LibTiff returns value of "-1.0" if numerator equals 4294967295 (0xFFFFFFFF) to indicate infinite distance!
+ * However, there are two other EXIF tags where numerator indicates a special value and six other cases where the denominator indicates special values,
+ * which are not treated within LibTiff!!
+ */
+ if (!(tTag == EXIFTAG_SUBJECTDISTANCE && auxFloat == -1.0)) {
+ fprintf (stderr, "%d:Read value of %s %f differs from set value %f\n", i, tFieldName, auxFloat, auxDoubleArrayW[i]);
+ GOTOFAILURE_ALL_EXIF
+ }
+ }
+ break;
+ case TIFF_SETGET_DOUBLE:
+ /*-- Unfortunately, TIFF_SETGET_DOUBLE is used for TIFF_RATIONAL but those have to be read with FLOAT !!! */
+ /* Only TIFFTAG_STONITS is a TIFF_DOUBLE, which has to be read as DOUBLE!! */
+ /*-- ATTENTION: ----
+ * Only after update with Rational2Double feature, also TIFF_RATIONAL can be read in double precision!!!
+ * Therefore, use a union to avoid overflow in TIFFGetField() return value
+ * and depending on version check for the right interface here:
+ * - old interface: correct value should be here a float
+ * - new interface: correct value should be here a double
+ * Interface version (old/new) is determined above.
+ -------------------*/
+ if (!TIFFGetField(tif, tTag, &auxDblUnion.dbl)) {
+ fprintf(stderr, "Can't read %s\n", tFieldArray->fields[i].field_name);
+ GOTOFAILURE_ALL_EXIF
+ break;
+ }
+ if (tType == TIFF_RATIONAL || tType == TIFF_SRATIONAL) {
+ if (blnIsRational2Double) {
+ /* New interface allows also double precision for TIFF_RATIONAL */
+ auxDouble = auxDblUnion.dbl;
+ }
+ else {
+ /* Old interface reads TIFF_RATIONAL defined as TIFF_SETGET_DOUBLE alwasy as FLOAT */
+ auxDouble = (double)auxDblUnion.flt1;
+ }
+ }
+ else {
+ auxDouble = auxDblUnion.dbl;
+ }
+ /* compare read values with written ones */
+ if (tType == TIFF_RATIONAL || tType == TIFF_SRATIONAL) dblDiffLimit = RATIONAL_EPS*auxDoubleArrayW[i]; else dblDiffLimit = 1e-6;
+ dblDiff = auxDouble - auxDoubleArrayW[i];
+ if (fabs(dblDiff) > fabs(dblDiffLimit)) {
+ /*--: EXIFTAG_SUBJECTDISTANCE: LibTiff returns value of "-1.0" if numerator equals 4294967295 (0xFFFFFFFF) to indicate infinite distance! */
+ if (!(tTag == EXIFTAG_SUBJECTDISTANCE && auxDouble == -1.0)) {
+ fprintf (stderr, "%d:Read value of %s %f differs from set value %f\n", i, tFieldName, auxDouble, auxDoubleArrayW[i]);
+ GOTOFAILURE_ALL_EXIF
+ }
+ }
+ break;
+
+ case TIFF_SETGET_C0_FLOAT:
+ case TIFF_SETGET_C0_DOUBLE:
+ case TIFF_SETGET_C16_FLOAT:
+ case TIFF_SETGET_C16_DOUBLE:
+ case TIFF_SETGET_C32_FLOAT:
+ case TIFF_SETGET_C32_DOUBLE:
+ /* _Cxx_ just defines the size of the count parameter for the array as C0=char, C16=short or C32=long */
+ /*-- Check, if it is a single parameter, a fixed array or a variable array */
+ if (tWriteCount == 1) {
+ fprintf (stderr, "Reading: WriteCount for .set_field_type %d should be -1 or greather than 1! %s\n", tSetFieldType, tFieldArray->fields[i].field_name);
+ } else {
+ /*-- Either fix or variable array --*/
+ /* For arrays, distinguishing between float or double is essential. */
+ /* Now decide between fixed or variable array */
+ if (tWriteCount > 1) {
+ /* fixed array with needed arraysize defined in .field_writecount */
+ if (!TIFFGetField( tif, tTag, &pVoidArray)) {
+ fprintf (stderr, "Can't read %s\n", tFieldArray->fields[i].field_name);
+ GOTOFAILURE_ALL_EXIF
+ break;
+ }
+ /* set tWriteCount to number of read samples for next steps */
+ auxLong = tWriteCount;
+ } else {
+ /* Special treatment of variable array. */
+ /* Dependent on Cxx, the count parameter is char, short or long. Therefore use unionLong! */
+ if (!TIFFGetField( tif, tTag, &unionLong, &pVoidArray)) {
+ fprintf (stderr, "Can't read %s\n", tFieldArray->fields[i].field_name);
+ GOTOFAILURE_ALL_EXIF
+ break;
+ }
+ /* set tWriteCount to number of read samples for next steps */
+ auxLong = unionLong.Short1;
+ }
+ /* Save values from temporary array */
+ if (tSetFieldType == TIFF_SETGET_C0_FLOAT || tSetFieldType == TIFF_SETGET_C16_FLOAT || tSetFieldType == TIFF_SETGET_C32_FLOAT) {
+ memcpy(&auxFloatArray, pVoidArray,(auxLong * sizeof(auxFloatArray[0])));
+ /* compare read values with written ones */
+ if (tType == TIFF_RATIONAL || tType == TIFF_SRATIONAL) dblDiffLimit = RATIONAL_EPS*auxDoubleArrayW[i]; else dblDiffLimit = 1e-6;
+ for (j=0; j<auxLong; j++) {
+ dblDiff = auxFloatArray[j] - auxFloatArrayW[i+j];
+ if (fabs(dblDiff) > fabs(dblDiffLimit)) {
+ /*if (auxFloatArray[j] != (float)auxFloatArrayW[i+j]) { */
+ fprintf (stderr, "Read value %d of %s #%d %f differs from set value %f\n", i, tFieldName, j, auxFloatArray[j], auxFloatArrayW[i+j]);
+ GOTOFAILURE_ALL_EXIF
+ }
+ }
+ } else {
+ memcpy(&auxDoubleArray, pVoidArray,(auxLong * sizeof(auxDoubleArray[0])));
+ /* compare read values with written ones */
+ if (tType == TIFF_RATIONAL || tType == TIFF_SRATIONAL) dblDiffLimit = RATIONAL_EPS*auxDoubleArrayW[i]; else dblDiffLimit = 1e-6;
+ for (j=0; j<auxLong; j++) {
+ dblDiff = auxDoubleArray[j] - auxDoubleArrayW[i+j];
+ if (fabs(dblDiff) > fabs(dblDiffLimit)) {
+ /*if (auxDoubleArray[j] != auxDoubleArrayW[i+j]) { */
+ fprintf (stderr, "Read value %d of %s #%d %f differs from set value %f\n", i, tFieldName, j, auxDoubleArray[j], auxDoubleArrayW[i+j]);
+ GOTOFAILURE_ALL_EXIF
+ }
+ }
+ }
+ }
+ break;
+ case TIFF_SETGET_C0_UINT8:
+ case TIFF_SETGET_C0_SINT8:
+ case TIFF_SETGET_C16_UINT8:
+ case TIFF_SETGET_C16_SINT8:
+ case TIFF_SETGET_C32_UINT8:
+ case TIFF_SETGET_C32_SINT8:
+ /* For arrays, distinguishing between float or double is essential, even for writing */
+ pVoid = &auxCharArrayW[i];
+ case TIFF_SETGET_C0_UINT16:
+ case TIFF_SETGET_C0_SINT16:
+ case TIFF_SETGET_C16_UINT16:
+ case TIFF_SETGET_C16_SINT16:
+ case TIFF_SETGET_C32_UINT16:
+ case TIFF_SETGET_C32_SINT16:
+ if (pVoid == NULL) pVoid = &auxShortArrayW[i];
+ case TIFF_SETGET_C0_UINT32:
+ case TIFF_SETGET_C0_SINT32:
+ case TIFF_SETGET_C16_UINT32:
+ case TIFF_SETGET_C16_SINT32:
+ case TIFF_SETGET_C32_UINT32:
+ case TIFF_SETGET_C32_SINT32:
+ if (pVoid == NULL) pVoid = &auxLongArrayW[i];
+ /* _Cxx_ just defines the size of the count parameter for the array as C0=char, C16=short or C32=long */
+ /*-- Check, if it is a single parameter, a fixed array or a variable array */
+ if (tWriteCount == 1) {
+ fprintf (stderr, "WriteCount for .set_field_type %d should be -1 or greather than 1! %s\n", tSetFieldType, tFieldArray->fields[i].field_name);
+ } else {
+ /*-- Either fix or variable array --*/
+ /* Now decide between fixed or variable array */
+ if (tWriteCount > 1) {
+ /* fixed array with needed arraysize defined in .field_writecount */
+ if (!TIFFGetField( tif, tTag, &pVoidArray)) {
+ fprintf (stderr, "Can't read %s\n", tFieldArray->fields[i].field_name);
+ GOTOFAILURE_ALL_EXIF
+ break;
+ }
+ /* set tWriteCount to number of read samples for next steps */
+ auxLong = tWriteCount;
+ } else {
+ /* special treatment of variable array */
+ /* for test, use always arraysize of VARIABLE_ARRAY_SIZE */
+ if (!TIFFGetField( tif, tTag, &unionLong, &pVoidArray)) {
+ fprintf (stderr, "Can't read %s\n", tFieldArray->fields[i].field_name);
+ GOTOFAILURE_ALL_EXIF
+ break;
+ }
+ /* set tWriteCount to number of read samples for next steps */
+ auxLong = unionLong.Short1;
+ }
+ /* Save values from temporary array */
+ if (tSetFieldType == TIFF_SETGET_C0_UINT8 || tSetFieldType == TIFF_SETGET_C0_SINT8 ||
+ tSetFieldType == TIFF_SETGET_C16_UINT8 || tSetFieldType == TIFF_SETGET_C16_SINT8 ||
+ tSetFieldType == TIFF_SETGET_C32_UINT8 || tSetFieldType == TIFF_SETGET_C32_SINT8 ) {
+ memcpy(&auxCharArray, pVoidArray,(auxLong * sizeof(auxCharArray[0])));
+ /* Compare and check values */
+ for (j=0; j<auxLong; j++) {
+ if (tTag == EXIFTAG_EXIFVERSION) {
+ /*-- Use exifVersion[] instead of auxCharArrayW[] for differently set EXIFVERSION tag */
+ if (auxCharArray[j] != exifVersion[j]) {
+ fprintf(stderr, "Read value %d of %s #%d %d differs from set value %d\n", i, tFieldName, j, auxCharArray[j], auxCharArrayW[i + j]);
+ GOTOFAILURE_ALL_EXIF
+ }
+ } else {
+ if (auxCharArray[j] != auxCharArrayW[i + j]) {
+ fprintf(stderr, "Read value %d of %s #%d %d differs from set value %d\n", i, tFieldName, j, auxCharArray[j], auxCharArrayW[i + j]);
+ GOTOFAILURE_ALL_EXIF
+ }
+ }
+ }
+ } else if (tSetFieldType == TIFF_SETGET_C0_UINT16 || tSetFieldType == TIFF_SETGET_C0_SINT16 ||
+ tSetFieldType == TIFF_SETGET_C16_UINT16 || tSetFieldType == TIFF_SETGET_C16_SINT16 ||
+ tSetFieldType == TIFF_SETGET_C32_UINT16 || tSetFieldType == TIFF_SETGET_C32_SINT16 ) {
+ memcpy(&auxShortArray, pVoidArray,(auxLong * sizeof(auxShortArray[0])));
+ /* Compare and check values */
+ for (j=0; j<auxLong; j++) {
+ if (auxShortArray[j] != auxShortArrayW[i+j]) {
+ fprintf (stderr, "Read value %d of %s #%d %d differs from set value %d\n", i, tFieldName, j, auxShortArray[j], auxShortArrayW[i+j]);
+ GOTOFAILURE_ALL_EXIF
+ }
+ }
+ } else if (tSetFieldType == TIFF_SETGET_C0_UINT32 || tSetFieldType == TIFF_SETGET_C0_SINT32 ||
+ tSetFieldType == TIFF_SETGET_C16_UINT32 || tSetFieldType == TIFF_SETGET_C16_SINT32 ||
+ tSetFieldType == TIFF_SETGET_C32_UINT32 || tSetFieldType == TIFF_SETGET_C32_SINT32 ) {
+ memcpy(&auxLongArray, pVoidArray,(auxLong * sizeof(auxLongArray[0])));
+ /* Compare and check values */
+ for (j=0; j<auxLong; j++) {
+ if (auxLongArray[j] != auxLongArrayW[i+j]) {
+ fprintf (stderr, "Read value %d of %s #%d %ld differs from set value %ld\n", i, tFieldName, j, auxLongArray[j], auxLongArrayW[i+j]);
+ GOTOFAILURE_ALL_EXIF
+ }
+ }
+ } else {
+ fprintf (stderr, "SetFieldType %d not defined within switch case reading for UINT for %s.\n", tSetFieldType, tFieldName);
+ GOTOFAILURE
+ }
+ }
+ break;
+ default:
+ fprintf (stderr, "SetFieldType %d not defined within writing switch for %s.\n", tSetFieldType, tFieldName);
+ GOTOFAILURE
+ }; /*-- switch() --*/
+ } /*-- for() --*/
+ /*================= EXIF: END Reading arbitrary data to the EXIF fields END END END ==============*/
+#endif /*-- READ_ALL_EXIF_TAGS --*/
+#endif /*-- READ_EXIF_TAGS --*/
+
+
+
+
+ TIFFClose(tif);
+
+ /* All tests passed; delete file and exit with success status. */
+#ifdef FOR_AUTO_TESTING
+ unlink(filenameRead);
+#endif
+ fprintf(stderr, "-------- Test finished OK ----------\n");
+ return 0;
+
+failure:
+ /*
+ * Something goes wrong; close file and return unsuccessful status.
+ * Do not remove the file for further manual investigation.
+ */
+ TIFFClose(tif);
+ fprintf(stderr, "-------- Test finished with FAILURE --------\n");
+ return 1;
+}
diff --git a/tiff/test/defer_strile_loading.c b/tiff/test/defer_strile_loading.c
index b444c01f..b2280324 100644
--- a/tiff/test/defer_strile_loading.c
+++ b/tiff/test/defer_strile_loading.c
@@ -148,11 +148,15 @@ int test(int classictif, int height, int tiled)
assert(err == 0);
size = TIFFGetStrileByteCountWithErr(tif, j, &err);
+ (void)size;
assert(size == 256);
assert(err == 0);
fseek(f, offset, SEEK_SET);
- fread(inputbuffer, 256, 1, f);
+ {
+ size_t nread = fread(inputbuffer, 256, 1, f);
+ (void)nread;
+ }
memset(tilebuffer,0, 256);
ret = TIFFReadFromUserBuffer(tif, j,
@@ -204,12 +208,15 @@ int test(int classictif, int height, int tiled)
assert(err == 0);
size = TIFFGetStrileByteCountWithErr(tif, j, &err);
+ (void)size;
assert(size == 1);
assert(err == 0);
fseek(f, offset, SEEK_SET);
- fread(inputbuffer, 1, 1, f);
-
+ {
+ size_t nread = fread(inputbuffer, 1, 1, f);
+ (void)nread;
+ }
memset(tilebuffer,0, 1);
ret = TIFFReadFromUserBuffer(tif, j,
inputbuffer, 1,
diff --git a/tiff/test/images/README.txt b/tiff/test/images/README.txt
index b6447d8e..4a7ad829 100644
--- a/tiff/test/images/README.txt
+++ b/tiff/test/images/README.txt
@@ -30,3 +30,6 @@ PNM files:
G3 Fax files :
miniswhite-1c-1b.g3
+
+deflate-last-strip-extra-data.tiff is
+https://github.com/OSGeo/gdal/blob/master/autotest/alg/data/utmsmall_near.tiff
diff --git a/tiff/test/images/deflate-last-strip-extra-data.tiff b/tiff/test/images/deflate-last-strip-extra-data.tiff
new file mode 100644
index 00000000..e3ee9dcc
--- /dev/null
+++ b/tiff/test/images/deflate-last-strip-extra-data.tiff
Binary files differ
diff --git a/tiff/test/images/ojpeg_chewey_subsamp21_multi_strip.tiff b/tiff/test/images/ojpeg_chewey_subsamp21_multi_strip.tiff
new file mode 100644
index 00000000..8b04d473
--- /dev/null
+++ b/tiff/test/images/ojpeg_chewey_subsamp21_multi_strip.tiff
Binary files differ
diff --git a/tiff/test/images/ojpeg_single_strip_no_rowsperstrip.tiff b/tiff/test/images/ojpeg_single_strip_no_rowsperstrip.tiff
new file mode 100644
index 00000000..61611b9d
--- /dev/null
+++ b/tiff/test/images/ojpeg_single_strip_no_rowsperstrip.tiff
Binary files differ
diff --git a/tiff/test/images/ojpeg_zackthecat_subsamp22_single_strip.tiff b/tiff/test/images/ojpeg_zackthecat_subsamp22_single_strip.tiff
new file mode 100644
index 00000000..15185b68
--- /dev/null
+++ b/tiff/test/images/ojpeg_zackthecat_subsamp22_single_strip.tiff
Binary files differ
diff --git a/tiff/test/images/rgb-3c-16b.ppm b/tiff/test/images/rgb-3c-16b.ppm
new file mode 100644
index 00000000..c1cd4b64
--- /dev/null
+++ b/tiff/test/images/rgb-3c-16b.ppm
Binary files differ
diff --git a/tiff/test/images/testfax4.tiff b/tiff/test/images/testfax4.tiff
new file mode 100644
index 00000000..f7f2629c
--- /dev/null
+++ b/tiff/test/images/testfax4.tiff
Binary files differ
diff --git a/tiff/test/ppm2tiff_pbm.sh b/tiff/test/ppm2tiff_pbm.sh
index 68d9e459..fb6c3cf7 100755
--- a/tiff/test/ppm2tiff_pbm.sh
+++ b/tiff/test/ppm2tiff_pbm.sh
@@ -1,5 +1,4 @@
#!/bin/sh
-# Generated file, master is Makefile.am
. ${srcdir:-.}/common.sh
infile="$IMG_MINISWHITE_1C_1B_PBM"
outfile="o-ppm2tiff_pbm.tiff"
diff --git a/tiff/test/ppm2tiff_pgm.sh b/tiff/test/ppm2tiff_pgm.sh
index 001ec706..60352348 100755
--- a/tiff/test/ppm2tiff_pgm.sh
+++ b/tiff/test/ppm2tiff_pgm.sh
@@ -1,5 +1,4 @@
#!/bin/sh
-# Generated file, master is Makefile.am
. ${srcdir:-.}/common.sh
infile="$IMG_MINISBLACK_1C_8B_PGM"
outfile="o-ppm2tiff_pgm.tiff"
diff --git a/tiff/test/ppm2tiff_ppm.sh b/tiff/test/ppm2tiff_ppm.sh
index 8a81527b..576ab3e0 100755
--- a/tiff/test/ppm2tiff_ppm.sh
+++ b/tiff/test/ppm2tiff_ppm.sh
@@ -1,7 +1,10 @@
#!/bin/sh
-# Generated file, master is Makefile.am
. ${srcdir:-.}/common.sh
infile="$IMG_RGB_3C_8B_PPM"
-outfile="o-ppm2tiff_ppm.tiff"
+outfile="o-ppm2tiff_8b_ppm.tiff"
+f_test_convert "$PPM2TIFF" $infile $outfile
+f_tiffinfo_validate $outfile
+infile="$IMG_RGB_3C_16B_PPM"
+outfile="o-ppm2tiff_16b_ppm.tiff"
f_test_convert "$PPM2TIFF" $infile $outfile
f_tiffinfo_validate $outfile
diff --git a/tiff/test/rational_precision2double.c b/tiff/test/rational_precision2double.c
new file mode 100644
index 00000000..e33cc97d
--- /dev/null
+++ b/tiff/test/rational_precision2double.c
@@ -0,0 +1,972 @@
+
+/*
+ * Copyright (c) 2012, Frank Warmerdam <warmerdam@pobox.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.
+ */
+
+/*
+ * TIFF Library
+ *
+ * -- Module copied from custom_dir.c --
+ *=========== Purpose ===================================================================================
+ * Extended and amended version for testing the TIFFSetField() / and TIFFGetField()- interface
+ * for custom fields of type RATIONAL when the TIFFLib internal precision is updated from FLOAT to DOUBLE!
+ * The external interface of already defined tags schould be kept.
+ * This is verified for some of those tags with this test.
+ *
+ */
+
+
+#define FOR_AUTO_TESTING
+#ifdef FOR_AUTO_TESTING
+/* Only for automake and CMake infrastructure the test should:
+ a.) delete any written testfiles when test passed (otherwise autotest will fail)
+ b.) goto failure, if any failure is detected, which is not necessary when test is initiated manually for debugging
+*/
+#define GOTOFAILURE goto failure;
+#else
+#define GOTOFAILURE
+#endif
+
+#ifdef _MSC_VER
+#pragma warning( disable : 4101)
+#endif
+
+#include "tif_config.h"
+#include <stdio.h>
+#include <string.h>
+#include <math.h>
+#include <errno.h>
+
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+
+#include "tiffio.h"
+#include "tiffiop.h"
+#include "tif_dir.h"
+#include "tifftest.h"
+
+
+#include "tif_dirwrite.c"
+
+
+int write_test_tiff(TIFF *tif, const char *filenameRead, int blnAllCustomTags);
+
+#define SPP 3 /* Samples per pixel */
+const uint16 width = 1;
+const uint16 length = 1;
+const uint16 bps = 8;
+const uint16 photometric = PHOTOMETRIC_RGB;
+const uint16 rows_per_strip = 1;
+const uint16 planarconfig = PLANARCONFIG_CONTIG;
+
+/*-- Additional custom TIFF tags for testing of Rational2Double precision --*/
+#define TIFFTAG_RATIONAL_DOUBLE 60000
+#define TIFFTAG_SRATIONAL_DOUBLE 60001
+#define TIFFTAG_RATIONAL_C0_DOUBLE 60002
+#define TIFFTAG_SRATIONAL_C16_DOUBLE 60003
+
+
+/*--- TIFFField Definition ---
+ field_tag: the tag number. For instance 277 for the SamplesPerPixel tag. Builtin tags will generally have a #define in tiff.h for each known tag.
+ field_readcount: The number of values which should be read. The special value TIFF_VARIABLE (-1) indicates that a variable number of values may be read. The special value TIFFTAG_SPP (-2) indicates that there should be one value for each sample as defined by TIFFTAG_SAMPLESPERPIXEL. The special value TIFF_VARIABLE2 (-3) is presumably similar to TIFF_VARIABLE though I am not sure what the distinction in behaviour is. This field is TIFF_VARIABLE for variable length ascii fields.
+ field_writecount: The number of values which should be written. Generally the same as field_readcount. A few built-in exceptions exist, but I haven't analysed why they differ.
+ field_type: Type of the field. One of TIFF_BYTE, TIFF_ASCII, TIFF_SHORT, TIFF_LONG, TIFF_RATIONAL, TIFF_SBYTE, TIFF_UNDEFINED, TIFF_SSHORT, TIFF_SLONG, TIFF_SRATIONAL, TIFF_FLOAT, TIFF_DOUBLE or TIFF_IFD. Note that some fields can support more than one type (for instance short and long). These fields should have multiple TIFFFieldInfos.
+ reserved:
+ set_field_type: TIFF_SETGET_DOUBLE
+ get_field_type: - not used -
+ field_bit: Built-in tags stored in special fields in the TIFF structure have assigned field numbers to distinguish them (ie. FIELD_SAMPLESPERPIXEL). New tags should generally just use FIELD_CUSTOM indicating they are stored in the generic tag list.
+ field_oktochange: TRUE if it is OK to change this tag value while an image is being written. FALSE for stuff that must be set once and then left unchanged (like ImageWidth, or PhotometricInterpretation for instance).
+ field_passcount: If TRUE, then the count value must be passed in TIFFSetField(), and TIFFGetField(), otherwise the count is not required. This should generally be TRUE for non-ascii variable count tags unless the count is implicit (such as with the colormap).
+ field_name: A name for the tag. Normally mixed case (studly caps) like "StripByteCounts" and relatively short.
+*/
+
+static const TIFFField
+tifFieldInfo[] = {
+ { TIFFTAG_RATIONAL_DOUBLE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "Rational2Double_U_Double", NULL },
+ { TIFFTAG_SRATIONAL_DOUBLE, 1, 1, TIFF_SRATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "Rational2Double_S_Double", NULL },
+ { TIFFTAG_RATIONAL_C0_DOUBLE, 3, 3, TIFF_RATIONAL, 0, TIFF_SETGET_C0_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "Rational2Double_C0", NULL },
+ { TIFFTAG_SRATIONAL_C16_DOUBLE, -1, -1, TIFF_SRATIONAL, 0, TIFF_SETGET_C16_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "Rational2Double_S_C16", NULL },
+};
+
+#define N(a) (sizeof (a) / sizeof (a[0]))
+
+/*--- Add aditional Rational-Double Tags to TIFF
+ ref: html\addingtags.html but with new function _TIFFMergeFields().
+---*/
+
+/* In libtiff 3.6.0 a new mechanism was introduced allowing libtiff to read unrecognised tags automatically.
+ When an unknown tags is encountered, it is automatically internally defined with a default name and a type derived from the tag value in the file.
+ Applications only need to predefine application specific tags if they need to be able to set them in a file, or if particular calling conventions
+ are desired for TIFFSetField() and TIFFGetField().
+ When tags are autodefined like this the field_readcount and field_writecount values are always TIFF_VARIABLE.
+ The field_passcount is always TRUE, and the field_bit is FIELD_CUSTOM. The field name will be "Tag %d" where the %d is the tag number.
+*/
+
+/*The tags need to be defined for each TIFF file opened - and when reading they should be defined before the tags of the file are read,
+ yet a valid TIFF * is needed to merge the tags against. In order to get them registered at the appropriate part of the setup process,
+ it is necessary to register our merge function as an extender callback with libtiff. This is done with TIFFSetTagExtender().
+ We also keep track of the previous tag extender (if any) so that we can call it from our extender allowing a chain of customizations to take effect.
+*/
+static TIFFExtendProc _ParentExtender = NULL;
+static void _XTIFFDefaultDirectory(TIFF *tif);
+
+static
+void _XTIFFInitialize(void)
+{
+ static int first_time=1;
+
+ if (! first_time) return; /* Been there. Done that. */
+first_time = 0;
+
+/* Grab the inherited method and install */
+_ParentExtender = TIFFSetTagExtender(_XTIFFDefaultDirectory);
+}
+
+/* The extender callback is looks like this.
+It merges in our new fields and then calls the next extender if there is one in effect.
+*/
+static void
+_XTIFFDefaultDirectory(TIFF *tif)
+{
+ uint32 n, nadded;
+
+ /* Install the extended Tag field info */
+ n = N(tifFieldInfo);
+ //_TIFFMergeFields(tif, const TIFFField info[], uint32 n);
+ nadded = _TIFFMergeFields(tif, tifFieldInfo, n);
+ (void)nadded;
+
+ /* Since an XTIFF client module may have overridden
+ * the default directory method, we call it now to
+ * allow it to set up the rest of its own methods.
+ */
+
+ if (_ParentExtender)
+ (*_ParentExtender)(tif);
+}
+
+
+int
+main()
+{
+ static const char filenameClassicTiff[] = "rationalPrecision2Double.tif";
+ static const char filenameBigTiff[] = "rationalPrecision2Double_Big.tif";
+
+ TIFF *tif;
+ int ret;
+ int errorNo;
+
+ /*-- Initialize TIFF-Extender to add additonal TIFF-Tags --*/
+ _XTIFFInitialize();
+
+ fprintf(stderr, "==== Test if Set()/Get() interface for some custom rational tags behave as before change. ====\n");
+ /* --- Test with Classic-TIFF ---*/
+ /* delete file, if exists */
+ ret = unlink(filenameClassicTiff);
+ errorNo = errno;
+ if (ret != 0 && errorNo != ENOENT) {
+ fprintf(stderr, "Can't delete test TIFF file %s.\n", filenameClassicTiff);
+ }
+
+ /* We write the main directory as a simple image. */
+ tif = TIFFOpen(filenameClassicTiff, "w+");
+ if (!tif) {
+ fprintf(stderr, "Can't create test TIFF file %s.\n", filenameClassicTiff);
+ return 1;
+ }
+ fprintf(stderr, "-------- Test with ClassicTIFF started ----------\n");
+ ret = write_test_tiff(tif, filenameClassicTiff, FALSE);
+ if (ret > 0) return(ret);
+
+ /*--- Test with BIG-TIFF ---*/
+ /* delete file, if exists */
+ ret = unlink(filenameBigTiff);
+ if (ret != 0 && errorNo != ENOENT) {
+ fprintf(stderr, "Can't delete test TIFF file %s.\n", filenameBigTiff);
+ }
+
+ tif = TIFFOpen(filenameBigTiff, "w8");
+ if (!tif) {
+ fprintf(stderr, "Can't create test TIFF file %s.\n", filenameBigTiff);
+ return 1;
+ }
+ fprintf(stderr, "\n-------- Test with BigTIFF started ----------\n");
+ ret = write_test_tiff(tif, filenameBigTiff, FALSE);
+ if (ret > 0) return(ret);
+
+
+ fprintf(stderr, "\n\n==== Test automatically, if all custom rational tags are written/read correctly. ====\n");
+ /* --- Test with Classic-TIFF ---*/
+ /* delete file, if exists */
+ ret = unlink(filenameClassicTiff);
+ errorNo = errno;
+ if (ret != 0 && errorNo != ENOENT) {
+ fprintf(stderr, "Can't delete test TIFF file %s.\n", filenameClassicTiff);
+ }
+
+ /* We write the main directory as a simple image. */
+ tif = TIFFOpen(filenameClassicTiff, "w+");
+ if (!tif) {
+ fprintf(stderr, "Can't create test TIFF file %s.\n", filenameClassicTiff);
+ return 1;
+ }
+ fprintf(stderr, "-------- Test with ClassicTIFF started ----------\n");
+ ret = write_test_tiff(tif, filenameClassicTiff, TRUE);
+ if (ret > 0) return(ret);
+
+ /*--- Test with BIG-TIFF ---*/
+ /* delete file, if exists */
+ ret = unlink(filenameBigTiff);
+ if (ret != 0 && errno != ENOENT) {
+ fprintf(stderr, "Can't delete test TIFF file %s.\n", filenameBigTiff);
+ }
+
+ tif = TIFFOpen(filenameBigTiff, "w8");
+ if (!tif) {
+ fprintf(stderr, "Can't create test TIFF file %s.\n", filenameBigTiff);
+ return 1;
+ }
+ fprintf(stderr, "\n-------- Test with BigTIFF started ----------\n");
+ ret = write_test_tiff(tif, filenameBigTiff, TRUE);
+ return(ret);
+} /* main() */
+
+
+
+
+int
+write_test_tiff(TIFF* tif, const char* filenameRead, int blnAllCustomTags) {
+ unsigned char buf[SPP] = {0, 127, 255};
+ /*-- Additional variables --*/
+ int retCode;
+ float auxFloat = 0.0f;
+ double auxDouble = 0.0;
+ uint16 auxUint16 = 0;
+ uint32 auxUint32 = 0;
+ long auxLong = 0;
+ void* pVoid;
+ int blnIsRational2Double;
+
+ int i, j;
+ long nTags;
+
+ const TIFFFieldArray* tFieldArray;
+ unsigned long tTag;
+ TIFFDataType tType;
+ short tWriteCount;
+ TIFFSetGetFieldType tSetFieldType;
+ unsigned short tFieldBit;
+ const TIFFField *fip;
+ char* tFieldName;
+
+
+#define STRSIZE 1000
+#define N_SIZE 200
+#define VARIABLE_ARRAY_SIZE 6
+
+ /* -- Test data for writing -- */
+ float auxFloatArrayW[N_SIZE];
+ double auxDoubleArrayW[N_SIZE];
+ char auxTextArrayW[N_SIZE][STRSIZE];
+ float auxFloatArrayN1[3] = {1.0f / 7.0f, 61.23456789012345f, 62.3f};
+ float auxFloatArrayResolutions[4] = {5.456789f, 6.666666f, 0.0033f, 5.0f / 213.0f};
+
+ /* -- Variables for reading -- */
+ uint16 count16 = 0;
+ union {
+ long Long;
+ short Short1;
+ short Short2[2];
+ char Char[4];
+ } auxLongUnion;
+ union {
+ double dbl;
+ float flt1;
+ float flt2;
+ } auxDblUnion;
+
+ void* pVoidArray;
+ float* pFloatArray;
+ float auxFloatArray[2 * N_SIZE];
+ double auxDoubleArray[2 * N_SIZE];
+ double dblDiff, dblDiffLimit;
+ float fltDiff;
+#define RATIONAL_EPS (1.0/30000.0) /* reduced difference of rational values, approx 3.3e-5 */
+
+
+ /*-- Fill test data arrays for writing ----------- */
+ for (i = 0; i < N_SIZE; i++) {
+ sprintf(auxTextArrayW[i], "N%d-String-%d_tttttttttttttttttttttttttttttx", i, i);
+ }
+ for (i = 0; i < N_SIZE; i++) {
+ auxFloatArrayW[i] = (float)((i + 1) * 133) / 3.3f;
+ }
+ for (i = 0; i < N_SIZE; i++) {
+ auxDoubleArrayW[i] = (double)((i + 1) * 3689) / 4.5697;
+ }
+
+ /*-- Setup standard tags of a simple tiff file --*/
+ if (!TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, width)) {
+ fprintf(stderr, "Can't set ImageWidth tag.\n");
+ goto failure;
+ }
+ if (!TIFFSetField(tif, TIFFTAG_IMAGELENGTH, length)) {
+ fprintf(stderr, "Can't set ImageLength tag.\n");
+ goto failure;
+ }
+ if (!TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, bps)) {
+ fprintf(stderr, "Can't set BitsPerSample tag.\n");
+ goto failure;
+ }
+ if (!TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, SPP)) {
+ fprintf(stderr, "Can't set SamplesPerPixel tag.\n");
+ goto failure;
+ }
+ if (!TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, rows_per_strip)) {
+ fprintf(stderr, "Can't set SamplesPerPixel tag.\n");
+ goto failure;
+ }
+ if (!TIFFSetField(tif, TIFFTAG_PLANARCONFIG, planarconfig)) {
+ fprintf(stderr, "Can't set PlanarConfiguration tag.\n");
+ goto failure;
+ }
+ if (!TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, photometric)) {
+ fprintf(stderr, "Can't set PhotometricInterpretation tag.\n");
+ goto failure;
+ }
+
+ /*--- Standard tags with TIFF_RATIONAL and TIFF_SETGET_DOUBLE to TIFF_SETGET_FLOAT change. ---
+ * They can be written either using float or double but have to be read using float.
+ -------------------------------------------------------------------------------------------- */
+ if (!TIFFSetField(tif, TIFFTAG_XRESOLUTION, auxFloatArrayResolutions[0])) {
+ fprintf(stderr, "Can't set TIFFTAG_XRESOLUTION tag.\n");
+ goto failure;
+ }
+ /* Test here the double input possibility */
+ if (!TIFFSetField(tif, TIFFTAG_YRESOLUTION, (double)auxFloatArrayResolutions[1])) {
+ fprintf(stderr, "Can't set TIFFTAG_YRESOLUTION tag.\n");
+ goto failure;
+ }
+ if (!TIFFSetField(tif, TIFFTAG_XPOSITION, auxFloatArrayResolutions[2])) {
+ fprintf(stderr, "Can't set TIFFTAG_XPOSITION tag.\n");
+ goto failure;
+ }
+ if (!TIFFSetField(tif, TIFFTAG_YPOSITION, auxFloatArrayResolutions[3])) {
+ fprintf(stderr, "Can't set TIFFTAG_YPOSITION tag.\n");
+ goto failure;
+ }
+
+ /*--- Some additional FIELD_CUSTOM tags to check standard interface ---*/
+
+ /*- TIFFTAG_INKSET is a SHORT parameter (TIFF_SHORT, TIFF_SETGET_UINT16) with field_bit=FIELD_CUSTOM !! -*/
+ if (!TIFFSetField(tif, TIFFTAG_INKSET, 34)) {
+ fprintf(stderr, "Can't set TIFFTAG_INKSET tag.\n");
+ goto failure;
+ }
+
+ /*- TIFFTAG_PIXAR_FOVCOT is a FLOAT parameter ( TIFF_FLOAT, TIFF_SETGET_FLOAT) with field_bit=FIELD_CUSTOM !! -*/
+ /* - can be written with Double but has to be read with float parameter */
+#define PIXAR_FOVCOT_VAL 5.123456789123456789
+ auxFloat = (float)PIXAR_FOVCOT_VAL;
+ /* if (!TIFFSetField(tif, TIFFTAG_PIXAR_FOVCOT, auxFloat )) {
+ fprintf (stderr, "Can't set TIFFTAG_PIXAR_FOVCOT tag.\n");
+ goto failure;
+ }
+ */
+ auxDouble = (double)PIXAR_FOVCOT_VAL;
+ if (!TIFFSetField(tif, TIFFTAG_PIXAR_FOVCOT, auxDouble)) {
+ fprintf(stderr, "Can't set TIFFTAG_PIXAR_FOVCOT tag.\n");
+ goto failure;
+ }
+ /*- TIFFTAG_STONITS is a DOUBLE parameter (TIFF_DOUBLE, TIFF_SETGET_DOUBLE) with field_bit=FIELD_CUSTOM!
+ *-- Unfortunately, TIFF_SETGET_DOUBLE is used for TIFF_RATIONAL but those have to be read with FLOAT !!!
+ * Only TIFFTAG_STONITS is a TIFF_DOUBLE, which has to be read as DOUBLE!!
+ */
+#define STONITS_VAL 6.123456789123456789
+ auxDouble = STONITS_VAL;
+ auxFloat = (float)auxDouble;
+ if (!TIFFSetField(tif, TIFFTAG_STONITS, auxDouble)) {
+ fprintf(stderr, "Can't set TIFFTAG_STONITS tag.\n");
+ goto failure;
+ }
+
+
+ /*-- Additional tags to check Rational standard tags, which are also defined with field_bit=FIELD_CUSTOM */
+ /*
+ The following standard tags have field_type = TIFF_RATIONAL with field_bit=FIELD_CUSTOM:
+ TIFFTAG_BASELINENOISE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE
+ TIFFTAG_BASELINESHARPNESS, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE
+ TIFFTAG_LINEARRESPONSELIMIT, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE
+ TIFFTAG_CHROMABLURRADIUS, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE
+ TIFFTAG_ANTIALIASSTRENGTH, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE
+ TIFFTAG_SHADOWSCALE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE
+ TIFFTAG_BESTQUALITYSCALE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE
+ and with Signed Rational:
+ TIFFTAG_BASELINEEXPOSURE, 1, 1, TIFF_SRATIONAL, 0, TIFF_SETGET_DOUBLE
+ Due to the fact that TIFFSetField() and TIFFGetField() interface is using va_args, variable promotion is applied,
+ which means:
+ If the actual argument is of type float, it is promoted to type double when function is to be made.
+ - Any signed or unsigned char, short, enumerated type, or bit field is converted to either a signed or an unsigned int
+ using integral promotion.
+ - Any argument of class type is passed by value as a data structure; the copy is created by binary copying instead
+ of by invoking the class’s copy constructor (if one exists).
+ So, if your argument types are of float type, you should expect the argument retrieved to be of type double
+ and it is char or short, you should expect it to be signed or unsigned int. Otherwise, the code will give you wrong results.
+ */
+
+ if (!blnAllCustomTags) {
+ /*--- TEST: First tag is written with FLOAT and second tag is written with DOUBLE parameter ---*/
+ /*- TIFFTAG_SHADOWSCALE is a Rational parameter (TIFF_RATIONAL, TIFF_SETGET_DOUBLE) with field_bit=FIELD_CUSTOM! -*/
+ #define SHADOWSCALE_VAL 15.123456789123456789
+ auxFloat = (float)SHADOWSCALE_VAL;
+ if (!TIFFSetField(tif, TIFFTAG_SHADOWSCALE, auxFloat)) {
+ fprintf(stderr, "Can't set TIFFTAG_SHADOWSCALE tag.\n");
+ goto failure;
+ }
+
+ /*- TIFFTAG_BESTQUALITYSCALE is a Rational parameter (TIFF_RATIONAL, TIFF_SETGET_DOUBLE) with field_bit=FIELD_CUSTOM! -*/
+ #define BESTQUALITYSCALE_VAL 17.123456789123456789
+ auxDouble = BESTQUALITYSCALE_VAL;
+ if (!TIFFSetField(tif, TIFFTAG_BESTQUALITYSCALE, auxDouble)) {
+ fprintf(stderr, "Can't set TIFFTAG_BESTQUALITYSCALE tag.\n");
+ goto failure;
+ }
+
+
+ /*- TIFFTAG_BASELINEEXPOSURE is a Rational parameter (TIFF_SRATIONAL, TIFF_SETGET_DOUBLE) with field_bit=FIELD_CUSTOM! -*/
+ #define BASELINEEXPOSURE_VAL (-3.14159265358979323846)
+ /*
+ fprintf(stderr, "(-3.14159265358979323846) as float= %.18f, double=%.18f\n", (float)BASELINEEXPOSURE_VAL, (double)BASELINEEXPOSURE_VAL, BASELINEEXPOSURE_VAL);
+ fprintf(stderr, "(-3.141592742098056) as float= %.18f, double=%.18f\n", (float)(-3.141592742098056), (double)(-3.141592742098056));
+ */
+ auxDouble = BASELINEEXPOSURE_VAL;
+ if (!TIFFSetField(tif, TIFFTAG_BASELINEEXPOSURE, auxDouble)) {
+ fprintf(stderr, "Can't set TIFFTAG_BASELINEEXPOSURE tag.\n");
+ goto failure;
+ }
+
+
+ /*--- For static or variable ARRAYs the case is different ---*/
+
+ /*- Variable Array: TIFFTAG_DECODE is a SRATIONAL parameter TIFF_SETGET_C16_FLOAT type FIELD_CUSTOM with passcount=1 and variable length of array. */
+ if (!TIFFSetField(tif, TIFFTAG_DECODE, 3, auxFloatArrayN1)) { /* for TIFF_SETGET_C16_DOUBLE */
+ fprintf(stderr, "Can't set TIFFTAG_DECODE tag.\n");
+ goto failure;
+ }
+
+ /*- Varable Array: TIFF_RATIONAL, 0, TIFF_SETGET_C16_FLOAT */
+ if (!TIFFSetField(tif, TIFFTAG_BLACKLEVEL, 3, auxFloatArrayN1)) { /* for TIFF_SETGET_C16_FLOAT */
+ fprintf(stderr, "Can't set TIFFTAG_BLACKLEVEL tag.\n");
+ goto failure;
+ }
+
+ /*-- Check, if the TiffLibrary is compiled with the new interface with Rational2Double or still uses the old definitions. */
+ /* tags to check: TIFFTAG_BESTQUALITYSCALE, TIFFTAG_BASELINENOISE, TIFFTAG_BASELINESHARPNESS, */
+ fip = TIFFFindField(tif, TIFFTAG_BESTQUALITYSCALE, TIFF_ANY);
+ tSetFieldType = fip->set_field_type;
+ if (tSetFieldType == TIFF_SETGET_DOUBLE)
+ blnIsRational2Double = FALSE;
+ else
+ blnIsRational2Double = TRUE;
+
+ /*--- Write now additional Rational2Double test tags ---*/
+ /*--- However, this additional tags are only written as Double correctly,
+ if blnIsRational2Double is defined!
+ ------------------------------------------------------*/
+ if (blnIsRational2Double) {
+ if (!TIFFSetField(tif, TIFFTAG_RATIONAL_DOUBLE, auxDoubleArrayW[100])) {
+ fprintf(stderr, "Can't set TIFFTAG_RATIONAL_DOUBLE tag.\n");
+ goto failure;
+ }
+ /* test for plain integers */
+ if (!TIFFSetField(tif, TIFFTAG_SRATIONAL_DOUBLE, (-1.0 ))) {
+ fprintf(stderr, "Can't set TIFFTAG_SRATIONAL_DOUBLE tag.\n");
+ goto failure;
+ }
+ if (!TIFFSetField(tif, TIFFTAG_RATIONAL_C0_DOUBLE, &auxDoubleArrayW[110])) {
+ fprintf(stderr, "Can't set TIFFTAG_RATIONAL_C0_DOUBLE tag.\n");
+ goto failure;
+ }
+ if (!TIFFSetField(tif, TIFFTAG_SRATIONAL_C16_DOUBLE, 2, &auxDoubleArrayW[120])) {
+ fprintf(stderr, "Can't set TIFFTAG_SRATIONAL_C16_DOUBLE tag.\n");
+ goto failure;
+ }
+ }
+
+ } else { /* blnAllCustomTags */
+ /*==== Automatically check all custom rational tags == WRITING ===*/
+ /*-- Get array, where TIFF tag fields are defined --*/
+ tFieldArray = _TIFFGetFields();
+ nTags = tFieldArray->count;
+
+ for (i = 0; i < nTags; i++) {
+ tTag = tFieldArray->fields[i].field_tag;
+ tType = tFieldArray->fields[i].field_type; /* e.g. TIFF_RATIONAL */
+ tWriteCount = tFieldArray->fields[i].field_writecount;
+ tSetFieldType = tFieldArray->fields[i].set_field_type; /* e.g. TIFF_SETGET_C0_FLOAT */
+ tFieldBit = tFieldArray->fields[i].field_bit;
+ tFieldName = tFieldArray->fields[i].field_name;
+ pVoid = NULL;
+
+ if (tType == TIFF_RATIONAL && tFieldBit == FIELD_CUSTOM) {
+ /*-- dependent on set_field_type write value --*/
+ switch (tSetFieldType) {
+ case TIFF_SETGET_FLOAT:
+ case TIFF_SETGET_DOUBLE:
+ if (tWriteCount == 1) {
+ /*-- All single values can be written with float or double parameter. Only value range should be in line. */
+ if (!TIFFSetField(tif, tTag, auxDoubleArrayW[i])) {
+ fprintf(stderr, "Can't write %s\n", tFieldArray->fields[i].field_name);
+ goto failure;
+ }
+ } else {
+ fprintf(stderr, "WriteCount for .set_field_type %d should be 1! %s\n", tSetFieldType, tFieldArray->fields[i].field_name);
+ }
+ break;
+ case TIFF_SETGET_C0_FLOAT:
+ case TIFF_SETGET_C0_DOUBLE:
+ case TIFF_SETGET_C16_FLOAT:
+ case TIFF_SETGET_C16_DOUBLE:
+ case TIFF_SETGET_C32_FLOAT:
+ case TIFF_SETGET_C32_DOUBLE:
+ /* _Cxx_ just defines the size of the count parameter for the array as C0=char, C16=short or C32=long */
+ /*-- Check, if it is a single parameter, a fixed array or a variable array */
+ if (tWriteCount == 1) {
+ fprintf(stderr, "WriteCount for .set_field_type %d should be -1 or greather than 1! %s\n", tSetFieldType, tFieldArray->fields[i].field_name);
+ } else {
+ /*-- Either fix or variable array --*/
+ /* For arrays, distinguishing between float or double is essential, even for writing */
+ if (tSetFieldType == TIFF_SETGET_C0_FLOAT || tSetFieldType == TIFF_SETGET_C16_FLOAT || tSetFieldType == TIFF_SETGET_C32_FLOAT)
+ pVoid = &auxFloatArrayW[i]; else pVoid = &auxDoubleArrayW[i];
+ /* Now decide between fixed or variable array */
+ if (tWriteCount > 1) {
+ /* fixed array with needed arraysize defined in .field_writecount */
+ if (!TIFFSetField(tif, tTag, pVoid)) {
+ fprintf(stderr, "Can't write %s\n", tFieldArray->fields[i].field_name);
+ goto failure;
+ }
+ } else {
+ /* special treatment of variable array */
+ /* for test, use always arraysize of VARIABLE_ARRAY_SIZE */
+ if (!TIFFSetField(tif, tTag, VARIABLE_ARRAY_SIZE, pVoid)) {
+ fprintf(stderr, "Can't write %s\n", tFieldArray->fields[i].field_name);
+ goto failure;
+ }
+ }
+ }
+ break;
+ default:
+ fprintf(stderr, "SetFieldType %d not defined within writing switch for %s.\n", tSetFieldType, tFieldName);
+ }; /*-- switch() --*/
+ } /* if () */
+ } /*-- for() --*/
+ } /* blnAllCustomTags */ /*==== END END - Automatically check all custom rational tags == WRITING END ===*/
+
+ /*-- Write dummy pixel data. --*/
+ if (TIFFWriteScanline(tif, buf, 0, 0) < 0) {
+ fprintf (stderr, "Can't write image data.\n");
+ goto failure;
+ }
+
+ /*-- Write directory to file --*/
+ /* Always WriteDirectory before using/creating another directory. */
+ /* Not necessary before TIFFClose(), however, TIFFClose() uses TIFFReWriteDirectory(), which forces directory to be written at another location. */
+ retCode = TIFFWriteDirectory(tif);
+
+ /*-- Write File to disk and close file --*/
+ /* TIFFClose() uses TIFFReWriteDirectory(), which forces directory to be written at another location. */
+ /* Therefore, better use TIFFWriteDirectory() before. */
+ TIFFClose(tif);
+
+ fprintf (stderr, "-------- Continue Test ---------- reading ...\n");
+
+/*========================= READING ============= READING ========================================*/
+ /* Ok, now test whether we can read written values in the EXIF directory. */
+ tif = TIFFOpen(filenameRead, "r");
+
+
+ /*-- Read some parameters out of the main directory --*/
+
+ /*-- IMAGEWIDTH and -LENGTH are defined as TIFF_SETGET_UINT32 */
+ retCode = TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &auxUint32 );
+ if (auxUint32 != width) {
+ fprintf (stderr, "Read value of IMAGEWIDTH %d differs from set value %d\n", auxUint32, width);
+ GOTOFAILURE
+ }
+ retCode = TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &auxUint32 );
+ if (auxUint32 != width) {
+ fprintf (stderr, "Read value of TIFFTAG_IMAGELENGTH %d differs from set value %d\n", auxUint32, length);
+ GOTOFAILURE
+ }
+
+ /*--- Standard tags with TIFF_RATIONAL and TIFF_SETGET_DOUBLE to TIFF_SETGET_FLOAT change. ---
+ * They can be written either using float or double but have to be read using float.
+ -------------------------------------------------------------------------------------------- */
+ dblDiffLimit = RATIONAL_EPS;
+ retCode = TIFFGetField(tif, TIFFTAG_XRESOLUTION, &auxFloat);
+ dblDiff = auxFloat - auxFloatArrayResolutions[0];
+ if (fabs(dblDiff) > fabs(dblDiffLimit)) {
+ fprintf(stderr, "Read value of TIFFTAG_XRESOLUTION %f differs from set value %f\n", auxFloat, auxFloatArrayResolutions[0]);
+ GOTOFAILURE
+ }
+ retCode = TIFFGetField(tif, TIFFTAG_YRESOLUTION, &auxFloat);
+ dblDiff = auxFloat - auxFloatArrayResolutions[1];
+ if (fabs(dblDiff) > fabs(dblDiffLimit)) {
+ fprintf(stderr, "Read value of TIFFTAG_YRESOLUTION %f differs from set value %f\n", auxFloat, auxFloatArrayResolutions[1]);
+ GOTOFAILURE
+ }
+ retCode = TIFFGetField(tif, TIFFTAG_XPOSITION, &auxFloat);
+ dblDiff = auxFloat - auxFloatArrayResolutions[2];
+ if (fabs(dblDiff) > fabs(dblDiffLimit)) {
+ fprintf(stderr, "Read value of TIFFTAG_XPOSITION %f differs from set value %f\n", auxFloat, auxFloatArrayResolutions[2]);
+ GOTOFAILURE
+ }
+ retCode = TIFFGetField(tif, TIFFTAG_YPOSITION, &auxFloat);
+ dblDiff = auxFloat - auxFloatArrayResolutions[3];
+ if (fabs(dblDiff) > fabs(dblDiffLimit)) {
+ fprintf(stderr, "Read value of TIFFTAG_YPOSITION %f differs from set value %f\n", auxFloat, auxFloatArrayResolutions[3]);
+ GOTOFAILURE
+ }
+
+
+ /*- TIFFTAG_INKSET is a SHORT parameter (TIFF_SHORT, TIFF_SETGET_UINT16) with field_bit=FIELD_CUSTOM !! -*/
+ retCode = TIFFGetField(tif, TIFFTAG_INKSET, &auxUint16);
+ if (auxUint16 != 34) {
+ fprintf(stderr, "Read value of TIFFTAG_PIXAR_FOVCOT %d differs from set value %d\n", auxUint16, TIFFTAG_INKSET);
+ GOTOFAILURE
+ }
+
+ /*- TIFFTAG_PIXAR_FOVCOT is a FLOAT parameter ( TIFF_FLOAT, TIFF_SETGET_FLOAT) with field_bit=FIELD_CUSTOM !! -*/
+ /* - was written with Double but has to be read with Float */
+ retCode = TIFFGetField(tif, TIFFTAG_PIXAR_FOVCOT, &auxFloat );
+ if (auxFloat != (float)PIXAR_FOVCOT_VAL) {
+ fprintf (stderr, "Read value of TIFFTAG_PIXAR_FOVCOT %f differs from set value %f\n", auxFloat, PIXAR_FOVCOT_VAL);
+ GOTOFAILURE
+ }
+
+ /*- TIFFTAG_STONITS is a DOUBLE parameter (TIFF_DOUBLE, TIFF_SETGET_DOUBLE) with field_bit=FIELD_CUSTOM!! -*/
+ retCode = TIFFGetField(tif, TIFFTAG_STONITS, &auxDouble);
+ if (auxDouble != (double)STONITS_VAL) {
+ fprintf(stderr, "Read value of TIFFTAG_STONITS %f differs from set value %f\n", auxDouble, STONITS_VAL);
+ GOTOFAILURE
+ }
+
+
+
+
+ /*-- Check, if the TiffLibrary is compiled with the new interface with Rational2Double or still uses the old definitions. */
+ /* tags to check: TIFFTAG_BESTQUALITYSCALE, TIFFTAG_BASELINENOISE, TIFFTAG_BASELINESHARPNESS, */
+ fip = TIFFFindField(tif, TIFFTAG_BESTQUALITYSCALE, TIFF_ANY);
+ tSetFieldType = fip->set_field_type;
+ if (tSetFieldType == TIFF_SETGET_DOUBLE)
+ blnIsRational2Double = FALSE;
+ else
+ blnIsRational2Double = TRUE;
+
+
+ if (!blnAllCustomTags) {
+
+ /*- TIFFTAG_BESTQUALITYSCALE is a Rational parameter (TIFF_RATIONAL, TIFF_SETGET_DOUBLE) with field_bit=FIELD_CUSTOM!
+ and written with double parameter -*/
+ /*- Read into a union to test the correct precision (float or double) returned.
+ * Float-parameter should be correct, but double-parameter should give a wrong value
+ */
+ auxDblUnion.dbl = 0;
+ retCode = TIFFGetField(tif, TIFFTAG_BESTQUALITYSCALE, &auxDblUnion.dbl);
+ dblDiffLimit = RATIONAL_EPS * (double)BESTQUALITYSCALE_VAL;
+ dblDiff = auxDblUnion.dbl - (double)BESTQUALITYSCALE_VAL;
+ fltDiff = auxDblUnion.flt1 - (float)BESTQUALITYSCALE_VAL;
+ if (!((fabs(dblDiff) > fabs(dblDiffLimit)) && !(fabs(fltDiff) > fabs(dblDiffLimit)))) {
+ fprintf(stderr, "Float-Read value of TIFFTAG_BESTQUALITYSCALE %.12f differs from set value %.12f too much,\n", auxDblUnion.flt1, BESTQUALITYSCALE_VAL);
+ fprintf(stderr, "whereas Double-Read value of TIFFTAG_BESTQUALITYSCALE %.12f is nearly equal to set value %.12f\n", auxDblUnion.dbl, BESTQUALITYSCALE_VAL);
+ GOTOFAILURE
+ }
+
+ /*--- Now the same for a Signed Rational ---*/
+ /*- TIFFTAG_BASELINEEXPOSURE is a Rational parameter (TIFF_SRATIONAL, TIFF_SETGET_DOUBLE) with field_bit=FIELD_CUSTOM! -
+ and written with double parameter - */
+ /*- Read into a union to test the correct precision (float or double) returned.
+ * Float-parameter should be correct, but double-parameter should give a wrong value
+ */
+ auxDblUnion.dbl = 0;
+ retCode = TIFFGetField(tif, TIFFTAG_BASELINEEXPOSURE, &auxDblUnion.dbl);
+ dblDiffLimit = RATIONAL_EPS * (double)BASELINEEXPOSURE_VAL;
+ dblDiff = auxDblUnion.dbl - (double)BASELINEEXPOSURE_VAL;
+ fltDiff = auxDblUnion.flt1 - (float)BASELINEEXPOSURE_VAL;
+ if (!((fabs(dblDiff) > fabs(dblDiffLimit)) && !(fabs(fltDiff) > fabs(dblDiffLimit)))) {
+ fprintf(stderr, "Float-Read value of TIFFTAG_BASELINEEXPOSURE %.12f differs from set value %.12f too much,\n", auxDblUnion.flt1, BASELINEEXPOSURE_VAL);
+ fprintf(stderr, "whereas Double-Read value of TIFFTAG_BESTQUALITYSCALE %.12f is nearly equal to set value %.12f\n", auxDblUnion.dbl, BASELINEEXPOSURE_VAL);
+ GOTOFAILURE
+ }
+
+ /*- Variable Array: TIFFTAG_DECODE is a SRATIONAL parameter TIFF_SETGET_C16_FLOAT type FIELD_CUSTOM with passcount=1 and variable length of array. */
+ retCode = TIFFGetField(tif, TIFFTAG_DECODE, &count16, &pVoidArray);
+ retCode = TIFFGetField(tif, TIFFTAG_DECODE, &count16, &pFloatArray);
+ /*- pVoidArray points to a Tiff-internal temporary memorypart. Thus, contents needs to be saved. */
+ memcpy(&auxFloatArray, pVoidArray, (count16 * sizeof(auxFloatArray[0])));
+ for (i = 0; i < count16; i++) {
+ dblDiffLimit = RATIONAL_EPS * auxFloatArrayN1[i];
+ dblDiff = auxFloatArray[i] - auxFloatArrayN1[i];
+ if (fabs(dblDiff) > fabs(dblDiffLimit)) {
+ fprintf(stderr, "Read value %d of TIFFTAG_DECODE Array %f differs from set value %f\n", i, auxFloatArray[i], auxFloatArrayN1[i]);
+ GOTOFAILURE
+ }
+ }
+
+ retCode = TIFFGetField(tif, TIFFTAG_BLACKLEVEL, &count16, &pVoidArray);
+ /*- pVoidArray points to a Tiff-internal temporary memorypart. Thus, contents needs to be saved. */
+ memcpy(&auxFloatArray, pVoidArray, (count16 * sizeof(auxFloatArray[0])));
+ for (i = 0; i < count16; i++) {
+ dblDiffLimit = RATIONAL_EPS * auxFloatArrayN1[i];
+ dblDiff = auxFloatArray[i] - auxFloatArrayN1[i];
+ if (fabs(dblDiff) > fabs(dblDiffLimit)) {
+ fprintf(stderr, "Read value %d of TIFFTAG_BLACKLEVEL Array %f differs from set value %f\n", i, auxFloatArray[i], auxFloatArrayN1[i]);
+ GOTOFAILURE
+ }
+ }
+
+
+ /*--- Read now additional Rational2Double test tags ---
+ This should be now with nearly double precision
+ However, this additional tags are only read as Double,
+ if blnIsRational2Double is defined!
+ ------------------------------------------------------*/
+ if (blnIsRational2Double) {
+ auxDblUnion.dbl = 0;
+ retCode = TIFFGetField(tif, TIFFTAG_RATIONAL_DOUBLE, &auxDblUnion.dbl);
+ if (!retCode) { fprintf(stderr, "Can't read %s\n", "TIFFTAG_RATIONAL_DOUBLE"); GOTOFAILURE }
+ dblDiffLimit = RATIONAL_EPS * auxDoubleArrayW[100];
+ dblDiff = auxDblUnion.dbl - auxDoubleArrayW[100];
+ if (fabs(dblDiff) > fabs(dblDiffLimit)) {
+ fprintf(stderr, "Read value of TIFFTAG_RATIONAL_DOUBLE %f differs from set value %f\n", auxDblUnion.dbl, auxDoubleArrayW[100]);
+ GOTOFAILURE
+ }
+
+ auxDblUnion.dbl = 0;
+ retCode = TIFFGetField(tif, TIFFTAG_SRATIONAL_DOUBLE, &auxDblUnion.dbl);
+ if (!retCode) { fprintf(stderr, "Can't read %s\n", "TIFFTAG_SRATIONAL_DOUBLE"); GOTOFAILURE }
+ auxDouble = -1.0;
+ dblDiffLimit = RATIONAL_EPS * auxDouble;
+ dblDiff = auxDblUnion.dbl - auxDouble;
+ if (fabs(dblDiff) > fabs(dblDiffLimit)) {
+ fprintf(stderr, "Read value of TIFFTAG_SRATIONAL_DOUBLE %f differs from set value %f\n", auxDblUnion.dbl, auxDouble);
+ GOTOFAILURE
+ }
+
+ /*- Fixed Array: TIFFTAG_RATIONAL_C0_DOUBLE, 3, 3, TIFF_RATIONAL, 0, TIFF_SETGET_C0_DOUBLE */
+ count16 = 3; /* set fixed array length for checking */
+ retCode = TIFFGetField(tif, TIFFTAG_RATIONAL_C0_DOUBLE, &pVoidArray);
+ /*- pVoidArray points to a Tiff-internal temporary memorypart. Thus, contents needs to be saved. */
+ memcpy(&auxDoubleArray, pVoidArray, (count16 * sizeof(auxDoubleArray[0])));
+ for (i = 0; i < count16; i++) {
+ dblDiffLimit = RATIONAL_EPS * auxDoubleArrayW[110 + i];
+ dblDiff = auxDoubleArray[i] - auxDoubleArrayW[110 + i];
+ if (fabs(dblDiff) > fabs(dblDiffLimit)) {
+ fprintf(stderr, "Read value %d of TIFFTAG_RATIONAL_C0_DOUBLE Array %f differs from set value %f\n", i, auxDoubleArray[i], auxDoubleArrayW[110 + i]);
+ GOTOFAILURE
+ }
+ }
+
+ /*- Variable Array: TIFFTAG_SRATIONAL_C16_DOUBLE, -1, -1, TIFF_SRATIONAL, 0, TIFF_SETGET_C16_DOUBLE */
+ retCode = TIFFGetField(tif, TIFFTAG_SRATIONAL_C16_DOUBLE, &count16, &pVoidArray);
+ /*- pVoidArray points to a Tiff-internal temporary memorypart. Thus, contents needs to be saved. */
+ memcpy(&auxDoubleArray, pVoidArray, (count16 * sizeof(auxDoubleArray[0])));
+ for (i = 0; i < count16; i++) {
+ dblDiffLimit = RATIONAL_EPS * auxDoubleArrayW[120 + i];
+ dblDiff = auxDoubleArray[i] - auxDoubleArrayW[120 + i];
+ if (fabs(dblDiff) > fabs(dblDiffLimit)) {
+ fprintf(stderr, "Read value %d of TIFFTAG_SRATIONAL_C16_DOUBLE Array %f differs from set value %f\n", i, auxDoubleArray[i], auxDoubleArrayW[120 + i]);
+ GOTOFAILURE
+ }
+ }
+ }
+
+ } else { /* blnAllCustomTags */
+ /*==== Automatically check all custom rational tags == READING ===*/
+
+ /*-- Get array, where standard TIFF tag fields are defined --*/
+ tFieldArray = _TIFFGetFields();
+ nTags = tFieldArray->count;
+
+ for (i = 0; i < nTags; i++) {
+ tTag = tFieldArray->fields[i].field_tag;
+ tType = tFieldArray->fields[i].field_type; /* e.g. TIFF_RATIONAL */
+ tWriteCount = tFieldArray->fields[i].field_writecount;
+ tSetFieldType = tFieldArray->fields[i].set_field_type; /* e.g. TIFF_SETGET_C0_FLOAT */
+ tFieldBit = tFieldArray->fields[i].field_bit;
+ tFieldName = tFieldArray->fields[i].field_name;
+ pVoid = NULL;
+ auxDblUnion.dbl = 0;
+
+ if (tType == TIFF_RATIONAL && tFieldBit == FIELD_CUSTOM) {
+ /*-- dependent on set_field_type read value --*/
+ switch (tSetFieldType) {
+ case TIFF_SETGET_FLOAT:
+ if (!TIFFGetField(tif, tTag, &auxFloat)) {
+ fprintf(stderr, "Can't read %s\n", tFieldArray->fields[i].field_name);
+ GOTOFAILURE
+ break;
+ }
+ /* compare read values with written ones */
+ if (tType == TIFF_RATIONAL || tType == TIFF_SRATIONAL) dblDiffLimit = RATIONAL_EPS * auxDoubleArrayW[i]; else dblDiffLimit = 1e-6;
+ dblDiff = auxFloat - auxDoubleArrayW[i];
+ if (fabs(dblDiff) > fabs(dblDiffLimit)) {
+ /*--: EXIFTAG_SUBJECTDISTANCE: LibTiff returns value of "-1.0" if numerator equals 4294967295 (0xFFFFFFFF) to indicate infinite distance!
+ * However, there are two other EXIF tags where numerator indicates a special value and six other cases where the denominator indicates special values,
+ * which are not treated within LibTiff!!
+ */
+ if (!(tTag == EXIFTAG_SUBJECTDISTANCE && auxFloat == -1.0)) {
+ fprintf(stderr, "%d:Read value of %s %f differs from set value %f\n", i, tFieldName, auxFloat, auxDoubleArrayW[i]);
+ GOTOFAILURE
+ }
+ }
+ break;
+ case TIFF_SETGET_DOUBLE:
+ /*-- Unfortunately, TIFF_SETGET_DOUBLE is used for TIFF_RATIONAL but those have to be read with FLOAT !!! */
+ /* Only after update with Rational2Double feature, also TIFF_RATIONAL can be read in double precision!!! */
+ /* Therefore, use a union to avoid overflow in TIFFGetField() return value
+ * and depending on version check for the right interface here:
+ * - old interface: correct value should be here a float
+ * - new interface: correct value should be here a double
+ * Interface version (old/new) is determined above.
+ */
+ if (!TIFFGetField(tif, tTag, &auxDblUnion.dbl)) {
+ fprintf(stderr, "Can't read %s\n", tFieldArray->fields[i].field_name);
+ GOTOFAILURE
+ break;
+ }
+ if (tType == TIFF_RATIONAL || tType == TIFF_SRATIONAL) {
+ if (blnIsRational2Double) {
+ /* New interface allows also double precision for TIFF_RATIONAL */
+ auxDouble = auxDblUnion.dbl;
+ }
+ else {
+ /* Old interface reads TIFF_RATIONAL defined as TIFF_SETGET_DOUBLE alwasy as FLOAT */
+ auxDouble = (double)auxDblUnion.flt1;
+ }
+ } else {
+ auxDouble = auxDblUnion.dbl;
+ }
+ /* compare read values with written ones */
+ if (tType == TIFF_RATIONAL || tType == TIFF_SRATIONAL) dblDiffLimit = RATIONAL_EPS * auxDoubleArrayW[i]; else dblDiffLimit = 1e-6;
+ dblDiff = auxDouble - auxDoubleArrayW[i];
+ if (fabs(dblDiff) > fabs(dblDiffLimit)) {
+ /*--: EXIFTAG_SUBJECTDISTANCE: LibTiff returns value of "-1.0" if numerator equals 4294967295 (0xFFFFFFFF) to indicate infinite distance! */
+ if (!(tTag == EXIFTAG_SUBJECTDISTANCE && auxDouble == -1.0))
+ fprintf(stderr, "%d:Read value of %s %f differs from set value %f\n", i, tFieldName, auxDouble, auxDoubleArrayW[i]);
+ GOTOFAILURE
+ }
+ break;
+
+ case TIFF_SETGET_C0_FLOAT:
+ case TIFF_SETGET_C0_DOUBLE:
+ case TIFF_SETGET_C16_FLOAT:
+ case TIFF_SETGET_C16_DOUBLE:
+ case TIFF_SETGET_C32_FLOAT:
+ case TIFF_SETGET_C32_DOUBLE:
+ /* _Cxx_ just defines the size of the count parameter for the array as C0=char, C16=short or C32=long */
+ /*-- Check, if it is a single parameter, a fixed array or a variable array */
+ if (tWriteCount == 1) {
+ fprintf(stderr, "Reading: WriteCount for .set_field_type %d should be -1 or greather than 1! %s\n", tSetFieldType, tFieldArray->fields[i].field_name);
+ GOTOFAILURE
+ } else {
+ /*-- Either fix or variable array --*/
+ /* For arrays, distinguishing between float or double is essential. */
+ /* Now decide between fixed or variable array */
+ if (tWriteCount > 1) {
+ /* fixed array with needed arraysize defined in .field_writecount */
+ if (!TIFFGetField(tif, tTag, &pVoidArray)) {
+ fprintf(stderr, "Can't read %s\n", tFieldArray->fields[i].field_name);
+ GOTOFAILURE
+ break;
+ }
+ /* set tWriteCount to number of read samples for next steps */
+ auxLong = tWriteCount;
+ } else {
+ /* Special treatment of variable array. */
+ /* Dependent on Cxx, the count parameter is char, short or long. Therefore use unionLong! */
+ if (!TIFFGetField(tif, tTag, &auxLongUnion, &pVoidArray)) {
+ fprintf(stderr, "Can't read %s\n", tFieldArray->fields[i].field_name);
+ GOTOFAILURE
+ break;
+ }
+ /* set tWriteCount to number of read samples for next steps */
+ auxLong = auxLongUnion.Short1;
+ }
+ /* Save values from temporary array */
+ if (tSetFieldType == TIFF_SETGET_C0_FLOAT || tSetFieldType == TIFF_SETGET_C16_FLOAT || tSetFieldType == TIFF_SETGET_C32_FLOAT) {
+ memcpy(&auxFloatArray, pVoidArray, (auxLong * sizeof(auxFloatArray[0])));
+ /* compare read values with written ones */
+ if (tType == TIFF_RATIONAL || tType == TIFF_SRATIONAL) dblDiffLimit = RATIONAL_EPS * auxDoubleArrayW[i]; else dblDiffLimit = 1e-6;
+ for (j = 0; j < auxLong; j++) {
+ dblDiff = auxFloatArray[j] - auxFloatArrayW[i + j];
+ if (fabs(dblDiff) > fabs(dblDiffLimit)) {
+ /*if (auxFloatArray[j] != (float)auxFloatArrayW[i+j]) { */
+ fprintf(stderr, "Read value %d of %s #%d %f differs from set value %f\n", i, tFieldName, j, auxFloatArray[j], auxFloatArrayW[i + j]);
+ GOTOFAILURE
+ }
+ }
+ } else {
+ memcpy(&auxDoubleArray, pVoidArray, (auxLong * sizeof(auxDoubleArray[0])));
+ /* compare read values with written ones */
+ if (tType == TIFF_RATIONAL || tType == TIFF_SRATIONAL) dblDiffLimit = RATIONAL_EPS * auxDoubleArrayW[i]; else dblDiffLimit = 1e-6;
+ for (j = 0; j < auxLong; j++) {
+ dblDiff = auxDoubleArray[j] - auxDoubleArrayW[i + j];
+ if (fabs(dblDiff) > fabs(dblDiffLimit)) {
+ /*if (auxDoubleArray[j] != auxDoubleArrayW[i+j]) { */
+ fprintf(stderr, "Read value %d of %s #%d %f differs from set value %f\n", i, tFieldName, j, auxDoubleArray[j], auxDoubleArrayW[i + j]);
+ GOTOFAILURE
+ }
+ }
+ }
+ }
+ break;
+ default:
+ fprintf(stderr, "SetFieldType %d not defined within reading switch for %s.\n", tSetFieldType, tFieldName);
+ }; /*-- switch() --*/
+ } /* if () */
+ } /*-- for() --*/
+
+
+ } /* blnAllCustomTags */ /*==== END END - Automatically check all custom rational tags == READING END ===*/
+
+
+
+ TIFFClose(tif);
+
+ /* All tests passed; delete file and exit with success status. */
+#ifdef FOR_AUTO_TESTING
+ unlink(filenameRead);
+#endif
+ fprintf(stderr, "-------- Test finished OK ----------\n");
+ return 0;
+
+failure:
+ /*
+ * Something goes wrong; close file and return unsuccessful status.
+ * Do not remove the file for further manual investigation.
+ */
+ TIFFClose(tif);
+ fprintf(stderr, "-------- Test finished with FAILURE --------\n");
+ return 1;
+}
diff --git a/tiff/test/refs/o-deflate-last-strip-extra-data.tiff b/tiff/test/refs/o-deflate-last-strip-extra-data.tiff
new file mode 100644
index 00000000..5d56fe54
--- /dev/null
+++ b/tiff/test/refs/o-deflate-last-strip-extra-data.tiff
Binary files differ
diff --git a/tiff/test/refs/o-testfax4.tiff b/tiff/test/refs/o-testfax4.tiff
new file mode 100644
index 00000000..cad45045
--- /dev/null
+++ b/tiff/test/refs/o-testfax4.tiff
Binary files differ
diff --git a/tiff/test/testdeflatelaststripextradata.sh b/tiff/test/testdeflatelaststripextradata.sh
new file mode 100755
index 00000000..115eb226
--- /dev/null
+++ b/tiff/test/testdeflatelaststripextradata.sh
@@ -0,0 +1,43 @@
+#!/bin/sh
+#
+# check decoding of a deflate compressed file whose last strip which should
+# contain data for only 4 lines has more in it.
+. ${srcdir:-.}/common.sh
+infile="${IMAGES}/deflate-last-strip-extra-data.tiff"
+outfile="o-deflate-last-strip-extra-data.tiff"
+rm -f $outfile
+echo "$MEMCHECK ${TIFFCP} -c zip $infile $outfile"
+eval "$MEMCHECK ${TIFFCP} -c zip $infile $outfile"
+status=$?
+if [ $status != 0 ] ; then
+ echo "Returned failed status $status!"
+ echo "Output (if any) is in \"${outfile}\"."
+ exit $status
+fi
+echo "$MEMCHECK ${TIFFCMP} $outfile ${REFS}/$outfile"
+eval "$MEMCHECK ${TIFFCMP} $outfile ${REFS}/$outfile"
+status=$?
+if [ $status != 0 ] ; then
+ echo "Returned failed status $status!"
+ echo "\"${outfile}\" differs from reference file."
+ exit $status
+fi
+
+outfile="o-deflate-last-strip-extra-data-tiled.tiff"
+rm -f $outfile
+echo "$MEMCHECK ${TIFFCP} -c zip -t -w 256 -l 256 $infile $outfile"
+eval "$MEMCHECK ${TIFFCP} -c zip -t -w 256 -l 256 $infile $outfile"
+status=$?
+if [ $status != 0 ] ; then
+ echo "Returned failed status $status!"
+ echo "Output (if any) is in \"${outfile}\"."
+ exit $status
+fi
+echo "$MEMCHECK ${TIFFCMP} $outfile ${REFS}/o-deflate-last-strip-extra-data.tiff"
+eval "$MEMCHECK ${TIFFCMP} $outfile ${REFS}/o-deflate-last-strip-extra-data.tiff"
+status=$?
+if [ $status != 0 ] ; then
+ echo "Returned failed status $status!"
+ echo "\"${outfile}\" differs from reference file."
+ exit $status
+fi
diff --git a/tiff/test/testfax4.sh b/tiff/test/testfax4.sh
new file mode 100755
index 00000000..6f465e8f
--- /dev/null
+++ b/tiff/test/testfax4.sh
@@ -0,0 +1,24 @@
+#!/bin/sh
+#
+# check decoding of a CCITT Group 4 encoded TIFF
+# with 0 length runs
+. ${srcdir:-.}/common.sh
+infile="${IMAGES}/testfax4.tiff"
+outfile="o-testfax4.tiff"
+rm -f $outfile
+echo "$MEMCHECK ${TIFFCP} -c lzw $infile $outfile"
+eval "$MEMCHECK ${TIFFCP} -c lzw $infile $outfile"
+status=$?
+if [ $status != 0 ] ; then
+ echo "Returned failed status $status!"
+ echo "Output (if any) is in \"${outfile}\"."
+ exit $status
+fi
+echo "$MEMCHECK ${TIFFCMP} $outfile ${REFS}/$outfile"
+eval "$MEMCHECK ${TIFFCMP} $outfile ${REFS}/$outfile"
+status=$?
+if [ $status != 0 ] ; then
+ echo "Returned failed status $status!"
+ echo "\"${outfile}\" differs from reference file."
+ exit $status
+fi
diff --git a/tiff/test/tiff2ps-EPS1.sh b/tiff/test/tiff2ps-EPS1.sh
index b1dc82e7..150039ef 100755
--- a/tiff/test/tiff2ps-EPS1.sh
+++ b/tiff/test/tiff2ps-EPS1.sh
@@ -5,4 +5,4 @@
PSFILE=o-tiff2ps-EPS1.ps
. ${srcdir:-.}/common.sh
f_test_stdout "${TIFF2PS} -e -1" "${IMG_MINISWHITE_1C_1B}" "${PSFILE}"
-diff -I '%%\(CreationDate\|Title\):*' -u "${REFS}/${PSFILE}" "${PSFILE}" || exit 1
+diff -I '%%CreationDate:.*' -I '%%Title:.*' -u "${REFS}/${PSFILE}" "${PSFILE}" || exit 1
diff --git a/tiff/test/tiff2ps-PS1.sh b/tiff/test/tiff2ps-PS1.sh
index 73171b98..ef08b13b 100755
--- a/tiff/test/tiff2ps-PS1.sh
+++ b/tiff/test/tiff2ps-PS1.sh
@@ -5,4 +5,5 @@
PSFILE="o-tiff2ps-PS1.ps"
. ${srcdir:-.}/common.sh
f_test_stdout "${TIFF2PS} -a -p -1" "${IMG_MINISWHITE_1C_1B}" "${PSFILE}"
-diff -I '%%\(CreationDate\|Title\):*' -u "${REFS}/${PSFILE}" "${PSFILE}" || exit 1
+#diff -I '%%(CreationDate|Title):.*' -u "${REFS}/${PSFILE}" "${PSFILE}" || exit 1
+diff -I '%%CreationDate:.*' -I '%%Title:.*' -u "${REFS}/${PSFILE}" "${PSFILE}" || exit 1
diff --git a/tiff/test/tiff2ps-PS2.sh b/tiff/test/tiff2ps-PS2.sh
index 9d3a521d..b130b08c 100755
--- a/tiff/test/tiff2ps-PS2.sh
+++ b/tiff/test/tiff2ps-PS2.sh
@@ -5,4 +5,4 @@
PSFILE=o-tiff2ps-PS2.ps
. ${srcdir:-.}/common.sh
f_test_stdout "${TIFF2PS} -a -p -2" "${IMG_MINISWHITE_1C_1B}" "${PSFILE}"
-diff -I '%%\(CreationDate\|Title\):*' -u "${REFS}/${PSFILE}" "${PSFILE}" || exit 1
+diff -I '%%CreationDate:.*' -I '%%Title:.*' -u "${REFS}/${PSFILE}" "${PSFILE}" || exit 1
diff --git a/tiff/test/tiff2ps-PS3.sh b/tiff/test/tiff2ps-PS3.sh
index eb55b9a0..d22be09a 100755
--- a/tiff/test/tiff2ps-PS3.sh
+++ b/tiff/test/tiff2ps-PS3.sh
@@ -5,4 +5,4 @@
PSFILE=o-tiff2ps-PS3.ps
. ${srcdir:-.}/common.sh
f_test_stdout "${TIFF2PS} -a -p -3" "${IMG_MINISWHITE_1C_1B}" "${PSFILE}"
-diff -I '%%\(CreationDate\|Title\):*' -u "${REFS}/${PSFILE}" "${PSFILE}" || exit 1
+diff -I '%%CreationDate:.*' -I '%%Title:.*' -u "${REFS}/${PSFILE}" "${PSFILE}" || exit 1
diff --git a/tiff/test/tiff2rgba-ojpeg_chewey_subsamp21_multi_strip.sh b/tiff/test/tiff2rgba-ojpeg_chewey_subsamp21_multi_strip.sh
new file mode 100755
index 00000000..d1225c94
--- /dev/null
+++ b/tiff/test/tiff2rgba-ojpeg_chewey_subsamp21_multi_strip.sh
@@ -0,0 +1,7 @@
+#!/bin/sh
+# Generated file, master is Makefile.am
+. ${srcdir:-.}/common.sh
+infile="$srcdir/images/ojpeg_chewey_subsamp21_multi_strip.tiff"
+outfile="o-tiff2rgba-ojpeg_chewey_subsamp21_multi_strip.tiff"
+f_test_convert "$TIFF2RGBA" $infile $outfile
+f_tiffinfo_validate $outfile
diff --git a/tiff/test/tiff2rgba-ojpeg_single_strip_no_rowsperstrip.sh b/tiff/test/tiff2rgba-ojpeg_single_strip_no_rowsperstrip.sh
new file mode 100755
index 00000000..d69c99dc
--- /dev/null
+++ b/tiff/test/tiff2rgba-ojpeg_single_strip_no_rowsperstrip.sh
@@ -0,0 +1,7 @@
+#!/bin/sh
+# Generated file, master is Makefile.am
+. ${srcdir:-.}/common.sh
+infile="$srcdir/images/ojpeg_single_strip_no_rowsperstrip.tiff"
+outfile="o-tiff2rgba-ojpeg_single_strip_no_rowsperstrip.tiff"
+f_test_convert "$TIFF2RGBA" $infile $outfile
+f_tiffinfo_validate $outfile
diff --git a/tiff/test/tiff2rgba-ojpeg_zackthecat_subsamp22_single_strip.sh b/tiff/test/tiff2rgba-ojpeg_zackthecat_subsamp22_single_strip.sh
new file mode 100755
index 00000000..ca23a12d
--- /dev/null
+++ b/tiff/test/tiff2rgba-ojpeg_zackthecat_subsamp22_single_strip.sh
@@ -0,0 +1,7 @@
+#!/bin/sh
+# Generated file, master is Makefile.am
+. ${srcdir:-.}/common.sh
+infile="$srcdir/images/ojpeg_zackthecat_subsamp22_single_strip.tiff"
+outfile="o-tiff2rgba-ojpeg_zackthecat_subsamp22_single_strip.tiff"
+f_test_convert "$TIFF2RGBA" $infile $outfile
+f_tiffinfo_validate $outfile
diff --git a/tiff/tools/CMakeLists.txt b/tiff/tools/CMakeLists.txt
index 886d4549..ff2a1ddc 100644
--- a/tiff/tools/CMakeLists.txt
+++ b/tiff/tools/CMakeLists.txt
@@ -123,3 +123,30 @@ if(HAVE_OPENGL)
install(TARGETS tiffgt
RUNTIME DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}")
endif()
+
+if(WEBP_SUPPORT AND EMSCRIPTEN)
+ # Emscripten is pretty finnicky about linker flags.
+ # It needs --shared-memory if and only if atomics or bulk-memory is used.
+ foreach(target fax2ps
+ fax2tiff
+ pal2rgb
+ ppm2tiff
+ raw2tiff
+ rgb2ycbcr
+ thumbnail
+ tiff2bw
+ tiff2pdf
+ tiff2ps
+ tiff2rgba
+ tiffcmp
+ tiffcp
+ tiffcrop
+ tiffdither
+ tiffdump
+ tiffinfo
+ tiffmedian
+ tiffset
+ tiffsplit)
+ target_link_options(${target} PUBLIC "-Wl,--shared-memory")
+ endforeach()
+endif()
diff --git a/tiff/tools/Makefile.in b/tiff/tools/Makefile.in
index 7ec4ed62..8b1a2460 100644
--- a/tiff/tools/Makefile.in
+++ b/tiff/tools/Makefile.in
@@ -1,7 +1,7 @@
-# Makefile.in generated by automake 1.16.1 from Makefile.am.
+# Makefile.in generated by automake 1.16.2 from Makefile.am.
# @configure_input@
-# Copyright (C) 1994-2018 Free Software Foundation, Inc.
+# Copyright (C) 1994-2020 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
diff --git a/tiff/tools/fax2ps.c b/tiff/tools/fax2ps.c
index 274b29e4..f59f4921 100644
--- a/tiff/tools/fax2ps.c
+++ b/tiff/tools/fax2ps.c
@@ -48,6 +48,13 @@
#include "tiffiop.h"
#include "tiffio.h"
+#ifndef EXIT_SUCCESS
+#define EXIT_SUCCESS 0
+#endif
+#ifndef EXIT_FAILURE
+#define EXIT_FAILURE 1
+#endif
+
float defxres = 204.; /* default x resolution (pixels/inch) */
float defyres = 98.; /* default y resolution (lines/inch) */
const float half = 0.5;
@@ -330,7 +337,7 @@ main(int argc, char** argv)
int c, dowarnings = 0; /* if 1, enable library warnings */
TIFF* tif;
- while ((c = getopt(argc, argv, "l:p:x:y:W:H:wS")) != -1)
+ while ((c = getopt(argc, argv, "l:p:x:y:W:H:wSh")) != -1)
switch (c) {
case 'H': /* page height */
pageHeight = (float)atof(optarg);
@@ -350,7 +357,7 @@ main(int argc, char** argv)
if( pages == NULL )
{
fprintf(stderr, "Out of memory\n");
- exit(-1);
+ exit(EXIT_FAILURE);
}
pages[npages++] = pageNumber;
break;
@@ -366,8 +373,10 @@ main(int argc, char** argv)
case 'l':
maxline = atoi(optarg);
break;
+ case 'h':
+ usage(EXIT_SUCCESS);
case '?':
- usage(-1);
+ usage(EXIT_FAILURE);
}
if (npages > 0)
qsort(pages, npages, sizeof(uint16), pcompar);
@@ -391,7 +400,7 @@ main(int argc, char** argv)
fd = tmpfile();
if (fd == NULL) {
fprintf(stderr, "Could not obtain temporary file.\n");
- exit(-2);
+ exit(EXIT_FAILURE);
}
#if defined(HAVE_SETMODE) && defined(O_BINARY)
setmode(fileno(stdin), O_BINARY);
@@ -401,7 +410,7 @@ main(int argc, char** argv)
fclose(fd);
fprintf(stderr,
"Could not copy stdin to temporary file.\n");
- exit(-2);
+ exit(EXIT_FAILURE);
}
}
_TIFF_lseek_f(fileno(fd), 0, SEEK_SET);
@@ -421,10 +430,10 @@ main(int argc, char** argv)
printf("%%%%Pages: %u\n", totalPages);
printf("%%%%EOF\n");
- return (0);
+ return (EXIT_SUCCESS);
}
-char* stuff[] = {
+const char* stuff[] = {
"usage: fax2ps [options] [input.tif ...]",
"where options are:",
" -w suppress warning messages",
@@ -441,13 +450,12 @@ NULL
static void
usage(int code)
{
- char buf[BUFSIZ];
int i;
+ FILE * out = (code == EXIT_SUCCESS) ? stdout : stderr;
- setbuf(stderr, buf);
- fprintf(stderr, "%s\n\n", TIFFGetVersion());
+ fprintf(out, "%s\n\n", TIFFGetVersion());
for (i = 0; stuff[i] != NULL; i++)
- fprintf(stderr, "%s\n", stuff[i]);
+ fprintf(out, "%s\n", stuff[i]);
exit(code);
}
diff --git a/tiff/tools/fax2tiff.c b/tiff/tools/fax2tiff.c
index 21223131..eecb41e3 100644
--- a/tiff/tools/fax2tiff.c
+++ b/tiff/tools/fax2tiff.c
@@ -68,7 +68,7 @@ uint16 badfaxrun;
uint32 badfaxlines;
int copyFaxFile(TIFF* tifin, TIFF* tifout);
-static void usage(void);
+static void usage(int code);
/*
Struct to carry client data. Note that it does not appear that the client
@@ -110,7 +110,7 @@ main(int argc, char* argv[])
extern char* optarg;
#endif
- while ((c = getopt(argc, argv, "R:X:o:r:1234ABLMPUW5678abcflmprsuvwz?")) != -1)
+ while ((c = getopt(argc, argv, "R:X:o:r:1234ABLMPUW5678abcflmprsuvwzh")) != -1)
switch (c) {
/* input-related options */
case '3': /* input is g3-encoded */
@@ -216,13 +216,15 @@ main(int argc, char* argv[])
case 'v': /* -v for info */
verbose++;
break;
+ case 'h':
+ usage(EXIT_SUCCESS);
case '?':
- usage();
+ usage(EXIT_FAILURE);
/*NOTREACHED*/
}
npages = argc - optind;
if (npages < 1)
- usage();
+ usage(EXIT_FAILURE);
rowbuf = _TIFFmalloc(TIFFhowmany8(xsize));
refbuf = _TIFFmalloc(TIFFhowmany8(xsize));
@@ -426,7 +428,7 @@ copyFaxFile(TIFF* tifin, TIFF* tifout)
return (row);
}
-char* stuff[] = {
+const char* stuff[] = {
"usage: fax2tiff [options] input.raw...",
"where options are:",
" -3 input data is G3-encoded [default]",
@@ -463,16 +465,15 @@ NULL
};
static void
-usage(void)
+usage(int code)
{
- char buf[BUFSIZ];
int i;
+ FILE * out = (code == EXIT_SUCCESS) ? stdout : stderr;
- setbuf(stderr, buf);
- fprintf(stderr, "%s\n\n", TIFFGetVersion());
+ fprintf(out, "%s\n\n", TIFFGetVersion());
for (i = 0; stuff[i] != NULL; i++)
- fprintf(stderr, "%s\n", stuff[i]);
- exit(EXIT_FAILURE);
+ fprintf(out, "%s\n", stuff[i]);
+ exit(code);
}
/* vim: set ts=8 sts=8 sw=8 noet: */
diff --git a/tiff/tools/pal2rgb.c b/tiff/tools/pal2rgb.c
index 9492f1cf..bf95cb37 100644
--- a/tiff/tools/pal2rgb.c
+++ b/tiff/tools/pal2rgb.c
@@ -39,10 +39,17 @@
#include "tiffio.h"
+#ifndef EXIT_SUCCESS
+#define EXIT_SUCCESS 0
+#endif
+#ifndef EXIT_FAILURE
+#define EXIT_FAILURE 1
+#endif
+
#define streq(a,b) (strcmp(a,b) == 0)
#define strneq(a,b,n) (strncmp(a,b,n) == 0)
-static void usage(void);
+static void usage(int code);
static void cpTags(TIFF* in, TIFF* out);
static int
@@ -85,14 +92,14 @@ main(int argc, char* argv[])
extern char* optarg;
#endif
- while ((c = getopt(argc, argv, "C:c:p:r:")) != -1)
+ while ((c = getopt(argc, argv, "C:c:p:r:h")) != -1)
switch (c) {
case 'C': /* force colormap interpretation */
cmap = atoi(optarg);
break;
case 'c': /* compression scheme */
if (!processCompressOptions(optarg))
- usage();
+ usage(EXIT_FAILURE);
break;
case 'p': /* planar configuration */
if (streq(optarg, "separate"))
@@ -100,33 +107,35 @@ main(int argc, char* argv[])
else if (streq(optarg, "contig"))
config = PLANARCONFIG_CONTIG;
else
- usage();
+ usage(EXIT_FAILURE);
break;
case 'r': /* rows/strip */
rowsperstrip = atoi(optarg);
break;
+ case 'h':
+ usage(EXIT_SUCCESS);
case '?':
- usage();
+ usage(EXIT_FAILURE);
/*NOTREACHED*/
}
if (argc - optind != 2)
- usage();
+ usage(EXIT_FAILURE);
in = TIFFOpen(argv[optind], "r");
if (in == NULL)
- return (-1);
+ return (EXIT_FAILURE);
if (!TIFFGetField(in, TIFFTAG_PHOTOMETRIC, &shortv) ||
shortv != PHOTOMETRIC_PALETTE) {
fprintf(stderr, "%s: Expecting a palette image.\n",
argv[optind]);
(void) TIFFClose(in);
- return (-1);
+ return (EXIT_FAILURE);
}
if (!TIFFGetField(in, TIFFTAG_COLORMAP, &rmap, &gmap, &bmap)) {
fprintf(stderr,
"%s: No colormap (not a valid palette image).\n",
argv[optind]);
(void) TIFFClose(in);
- return (-1);
+ return (EXIT_FAILURE);
}
bitspersample = 0;
TIFFGetField(in, TIFFTAG_BITSPERSAMPLE, &bitspersample);
@@ -134,12 +143,12 @@ main(int argc, char* argv[])
fprintf(stderr, "%s: Sorry, can only handle 8-bit images.\n",
argv[optind]);
(void) TIFFClose(in);
- return (-1);
+ return (EXIT_FAILURE);
}
out = TIFFOpen(argv[optind+1], "w");
if (out == NULL) {
(void) TIFFClose(in);
- return (-2);
+ return (EXIT_FAILURE);
}
cpTags(in, out);
TIFFGetField(in, TIFFTAG_IMAGEWIDTH, &imagewidth);
@@ -198,7 +207,7 @@ main(int argc, char* argv[])
* buffer overflow. Go ahead and fail now to prevent that.
*/
fprintf(stderr, "Could not determine correct image size for output. Exiting.\n");
- return -1;
+ return EXIT_FAILURE;
}
ibuf = (unsigned char*)_TIFFmalloc(tss_in);
obuf = (unsigned char*)_TIFFmalloc(tss_out);
@@ -242,7 +251,7 @@ main(int argc, char* argv[])
done:
(void) TIFFClose(in);
(void) TIFFClose(out);
- return (0);
+ return (EXIT_SUCCESS);
}
static int
@@ -263,7 +272,7 @@ processCompressOptions(char* opt)
else if (cp[1] == 'r' )
jpegcolormode = JPEGCOLORMODE_RAW;
else
- usage();
+ usage(EXIT_FAILURE);
cp = strchr(cp+1,':');
}
@@ -427,7 +436,7 @@ cpTags(TIFF* in, TIFF* out)
}
#undef NTAGS
-char* stuff[] = {
+const char* stuff[] = {
"usage: pal2rgb [options] input.tif output.tif",
"where options are:",
" -p contig pack samples contiguously (e.g. RGBRGB...)",
@@ -448,16 +457,15 @@ NULL
};
static void
-usage(void)
+usage(int code)
{
- char buf[BUFSIZ];
int i;
+ FILE * out = (code == EXIT_SUCCESS) ? stdout : stderr;
- setbuf(stderr, buf);
- fprintf(stderr, "%s\n\n", TIFFGetVersion());
+ fprintf(out, "%s\n\n", TIFFGetVersion());
for (i = 0; stuff[i] != NULL; i++)
- fprintf(stderr, "%s\n", stuff[i]);
- exit(-1);
+ fprintf(out, "%s\n", stuff[i]);
+ exit(code);
}
/* vim: set ts=8 sts=8 sw=8 noet: */
diff --git a/tiff/tools/ppm2tiff.c b/tiff/tools/ppm2tiff.c
index 2b275618..c6332439 100644
--- a/tiff/tools/ppm2tiff.c
+++ b/tiff/tools/ppm2tiff.c
@@ -51,6 +51,13 @@
extern int getopt(int argc, char * const argv[], const char *optstring);
#endif
+#ifndef EXIT_SUCCESS
+#define EXIT_SUCCESS 0
+#endif
+#ifndef EXIT_FAILURE
+#define EXIT_FAILURE 1
+#endif
+
#define streq(a,b) (strcmp(a,b) == 0)
#define strneq(a,b,n) (strncmp(a,b,n) == 0)
@@ -60,14 +67,109 @@ static int quality = 75; /* JPEG quality */
static int jpegcolormode = JPEGCOLORMODE_RGB;
static uint32 g3opts;
-static void usage(void);
+static void usage(int code);
static int processCompressOptions(char*);
static void
+pack_none (unsigned char *buf, unsigned int smpls, uint16 bps)
+{
+ (void)buf;
+ (void)smpls;
+ (void)bps;
+ return;
+}
+
+static void
+pack_swab (unsigned char *buf, unsigned int smpls, uint16 bps)
+{
+ unsigned int s;
+ unsigned char h;
+ unsigned char l;
+ (void)bps;
+
+ for (s = 0; smpls > s; s++) {
+
+ h = buf [s * 2 + 0];
+ l = buf [s * 2 + 1];
+
+ buf [s * 2 + 0] = l;
+ buf [s * 2 + 1] = h;
+ }
+ return;
+}
+
+static void
+pack_bytes (unsigned char *buf, unsigned int smpls, uint16 bps)
+{
+ unsigned int s;
+ unsigned int in;
+ unsigned int out;
+ int bits;
+ uint16 t;
+
+ in = 0;
+ out = 0;
+ bits = 0;
+ t = 0;
+
+ for (s = 0; smpls > s; s++) {
+
+ t <<= bps;
+ t |= (uint16) buf [in++];
+
+ bits += bps;
+
+ if (8 <= bits) {
+ bits -= 8;
+ buf [out++] = (t >> bits) & 0xFF;
+ }
+ }
+ if (0 != bits)
+ buf [out] = (t << (8 - bits)) & 0xFF;
+}
+
+static void
+pack_words (unsigned char *buf, unsigned int smpls, uint16 bps)
+{
+ unsigned int s;
+ unsigned int in;
+ unsigned int out;
+ int bits;
+ uint32 t;
+
+ in = 0;
+ out = 0;
+ bits = 0;
+ t = 0;
+
+ for (s = 0; smpls > s; s++) {
+
+ t <<= bps;
+ t |= (uint32) buf [in++] << 8;
+ t |= (uint32) buf [in++] << 0;
+
+ bits += bps;
+
+ if (16 <= bits) {
+
+ bits -= 16;
+ buf [out++] = (t >> (bits + 8));
+ buf [out++] = (t >> (bits + 0));
+ }
+ }
+ if (0 != bits) {
+ t <<= 16 - bits;
+
+ buf [out++] = (t >> (16 + 8));
+ buf [out++] = (t >> (16 + 0));
+ }
+}
+
+static void
BadPPM(char* file)
{
fprintf(stderr, "%s: Not a PPM file.\n", file);
- exit(-2);
+ exit(EXIT_FAILURE);
}
@@ -90,8 +192,10 @@ main(int argc, char* argv[])
double resolution = -1;
unsigned char *buf = NULL;
tmsize_t linebytes = 0;
+ int pbm;
uint16 spp = 1;
uint16 bpp = 8;
+ void (*pack_func) (unsigned char *buf, unsigned int smpls, uint16 bps);
TIFF *out;
FILE *in;
unsigned int w, h, prec, row;
@@ -105,13 +209,13 @@ main(int argc, char* argv[])
if (argc < 2) {
fprintf(stderr, "%s: Too few arguments\n", argv[0]);
- usage();
+ usage(EXIT_FAILURE);
}
- while ((c = getopt(argc, argv, "c:r:R:")) != -1)
+ while ((c = getopt(argc, argv, "c:r:R:h")) != -1)
switch (c) {
case 'c': /* compression scheme */
if (!processCompressOptions(optarg))
- usage();
+ usage(EXIT_FAILURE);
break;
case 'r': /* rows/strip */
rowsperstrip = atoi(optarg);
@@ -119,14 +223,16 @@ main(int argc, char* argv[])
case 'R': /* resolution */
resolution = atof(optarg);
break;
+ case 'h':
+ usage(EXIT_SUCCESS);
case '?':
- usage();
+ usage(EXIT_FAILURE);
/*NOTREACHED*/
}
if (optind + 2 < argc) {
fprintf(stderr, "%s: Too many arguments\n", argv[0]);
- usage();
+ usage(EXIT_FAILURE);
}
/*
@@ -138,7 +244,7 @@ main(int argc, char* argv[])
in = fopen(infile, "rb");
if (in == NULL) {
fprintf(stderr, "%s: Can not open.\n", infile);
- return (-1);
+ return (EXIT_FAILURE);
}
} else {
infile = "<stdin>";
@@ -152,17 +258,17 @@ main(int argc, char* argv[])
BadPPM(infile);
switch (fgetc(in)) {
case '4': /* it's a PBM file */
- bpp = 1;
+ pbm = !0;
spp = 1;
photometric = PHOTOMETRIC_MINISWHITE;
break;
case '5': /* it's a PGM file */
- bpp = 8;
+ pbm = 0;
spp = 1;
photometric = PHOTOMETRIC_MINISBLACK;
break;
case '6': /* it's a PPM file */
- bpp = 8;
+ pbm = 0;
spp = 3;
photometric = PHOTOMETRIC_RGB;
if (compression == COMPRESSION_JPEG &&
@@ -193,23 +299,56 @@ main(int argc, char* argv[])
ungetc(c, in);
break;
}
- switch (bpp) {
- case 1:
+ if (pbm) {
if (fscanf(in, " %u %u", &w, &h) != 2)
BadPPM(infile);
if (fgetc(in) != '\n')
BadPPM(infile);
- break;
- case 8:
+ bpp = 1;
+ pack_func = pack_none;
+ } else {
if (fscanf(in, " %u %u %u", &w, &h, &prec) != 3)
BadPPM(infile);
- if (fgetc(in) != '\n' || prec != 255)
+ if (fgetc(in) != '\n' || 0 == prec || 65535 < prec)
BadPPM(infile);
- break;
+
+ if (0 != (prec & (prec + 1))) {
+ fprintf(stderr, "%s: unsupported maxval %u.\n",
+ infile, prec);
+ exit(EXIT_FAILURE);
+ }
+ bpp = 0;
+ if ((prec + 1) & 0xAAAAAAAA) bpp |= 1;
+ if ((prec + 1) & 0xCCCCCCCC) bpp |= 2;
+ if ((prec + 1) & 0xF0F0F0F0) bpp |= 4;
+ if ((prec + 1) & 0xFF00FF00) bpp |= 8;
+ if ((prec + 1) & 0xFFFF0000) bpp |= 16;
+
+ switch (bpp) {
+ case 8:
+ pack_func = pack_none;
+ break;
+ case 16:
+ {
+ const unsigned short i = 0x0100;
+
+ if (0 == *(unsigned char*) &i)
+ pack_func = pack_swab;
+ else
+ pack_func = pack_none;
+ }
+ break;
+ default:
+ if (8 >= bpp)
+ pack_func = pack_bytes;
+ else
+ pack_func = pack_words;
+ break;
+ }
}
out = TIFFOpen(argv[optind], "w");
if (out == NULL)
- return (-4);
+ return (EXIT_FAILURE);
TIFFSetField(out, TIFFTAG_IMAGEWIDTH, (uint32) w);
TIFFSetField(out, TIFFTAG_IMAGELENGTH, (uint32) h);
TIFFSetField(out, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
@@ -232,33 +371,30 @@ main(int argc, char* argv[])
TIFFSetField(out, TIFFTAG_GROUP3OPTIONS, g3opts);
break;
}
- switch (bpp) {
- case 1:
- /* if round-up overflows, result will be zero, OK */
- linebytes = (multiply_ms(spp, w) + (8 - 1)) / 8;
- if (rowsperstrip == (uint32) -1) {
- TIFFSetField(out, TIFFTAG_ROWSPERSTRIP, h);
- } else {
- TIFFSetField(out, TIFFTAG_ROWSPERSTRIP,
- TIFFDefaultStripSize(out, rowsperstrip));
- }
- break;
- case 8:
- linebytes = multiply_ms(spp, w);
- TIFFSetField(out, TIFFTAG_ROWSPERSTRIP,
- TIFFDefaultStripSize(out, rowsperstrip));
- break;
+ if (pbm) {
+ /* if round-up overflows, result will be zero, OK */
+ linebytes = (multiply_ms(spp, w) + (8 - 1)) / 8;
+ } else if (bpp <= 8) {
+ linebytes = multiply_ms(spp, w);
+ } else {
+ linebytes = multiply_ms(2 * spp, w);
+ }
+ if (rowsperstrip == (uint32) -1) {
+ TIFFSetField(out, TIFFTAG_ROWSPERSTRIP, h);
+ } else {
+ TIFFSetField(out, TIFFTAG_ROWSPERSTRIP,
+ TIFFDefaultStripSize(out, rowsperstrip));
}
if (linebytes == 0) {
fprintf(stderr, "%s: scanline size overflow\n", infile);
(void) TIFFClose(out);
- exit(-2);
+ exit(EXIT_FAILURE);
}
scanline_size = TIFFScanlineSize(out);
if (scanline_size == 0) {
/* overflow - TIFFScanlineSize already printed a message */
(void) TIFFClose(out);
- exit(-2);
+ exit(EXIT_FAILURE);
}
if (scanline_size < linebytes)
buf = (unsigned char *)_TIFFmalloc(linebytes);
@@ -267,7 +403,7 @@ main(int argc, char* argv[])
if (buf == NULL) {
fprintf(stderr, "%s: Not enough memory\n", infile);
(void) TIFFClose(out);
- exit(-2);
+ exit(EXIT_FAILURE);
}
if (resolution > 0) {
TIFFSetField(out, TIFFTAG_XRESOLUTION, resolution);
@@ -280,6 +416,7 @@ main(int argc, char* argv[])
infile, (unsigned long) row);
break;
}
+ pack_func (buf, w * spp, bpp);
if (TIFFWriteScanline(out, buf, row, 0) < 0)
break;
}
@@ -288,7 +425,7 @@ main(int argc, char* argv[])
(void) TIFFClose(out);
if (buf)
_TIFFfree(buf);
- return (0);
+ return (EXIT_SUCCESS);
}
static void
@@ -305,7 +442,7 @@ processG3Options(char* cp)
else if (strneq(cp, "fill", 4))
g3opts |= GROUP3OPT_FILLBITS;
else
- usage();
+ usage(EXIT_FAILURE);
} while( (cp = strchr(cp, ':')) );
}
}
@@ -328,7 +465,7 @@ processCompressOptions(char* opt)
else if (cp[1] == 'r' )
jpegcolormode = JPEGCOLORMODE_RAW;
else
- usage();
+ usage(EXIT_FAILURE);
cp = strchr(cp+1,':');
}
@@ -352,7 +489,7 @@ processCompressOptions(char* opt)
return (1);
}
-char* stuff[] = {
+const char* stuff[] = {
"usage: ppm2tiff [options] input.ppm output.tif",
"where options are:",
" -r # make each strip have no more than # rows",
@@ -376,16 +513,15 @@ NULL
};
static void
-usage(void)
+usage(int code)
{
- char buf[BUFSIZ];
int i;
+ FILE * out = (code == EXIT_SUCCESS) ? stdout : stderr;
- setbuf(stderr, buf);
- fprintf(stderr, "%s\n\n", TIFFGetVersion());
+ fprintf(out, "%s\n\n", TIFFGetVersion());
for (i = 0; stuff[i] != NULL; i++)
- fprintf(stderr, "%s\n", stuff[i]);
- exit(-1);
+ fprintf(out, "%s\n", stuff[i]);
+ exit(code);
}
/* vim: set ts=8 sts=8 sw=8 noet: */
diff --git a/tiff/tools/raw2tiff.c b/tiff/tools/raw2tiff.c
index ab36ff4e..8bbdc045 100644
--- a/tiff/tools/raw2tiff.c
+++ b/tiff/tools/raw2tiff.c
@@ -59,6 +59,13 @@
#include "tiffiop.h"
#include "tiffio.h"
+#ifndef EXIT_SUCCESS
+#define EXIT_SUCCESS 0
+#endif
+#ifndef EXIT_FAILURE
+#define EXIT_FAILURE 1
+#endif
+
#ifndef HAVE_GETOPT
extern int getopt(int argc, char * const argv[], const char *optstring);
#endif
@@ -81,7 +88,7 @@ static void swapBytesInScanline(void *, uint32, TIFFDataType);
static int guessSize(int, TIFFDataType, _TIFF_off_t, uint32, int,
uint32 *, uint32 *);
static double correlation(void *, void *, uint32, TIFFDataType);
-static void usage(void);
+static void usage(int);
static int processCompressOptions(char*);
int
@@ -114,7 +121,7 @@ main(int argc, char* argv[])
switch (c) {
case 'c': /* compression scheme */
if (!processCompressOptions(optarg))
- usage();
+ usage(EXIT_FAILURE);
break;
case 'r': /* rows/strip */
rowsperstrip = atoi(optarg);
@@ -193,24 +200,24 @@ main(int argc, char* argv[])
outfilename = optarg;
break;
case 'h':
- usage();
+ usage(EXIT_SUCCESS);
default:
break;
}
}
if (argc - optind < 2)
- usage();
+ usage(EXIT_FAILURE);
fd = open(argv[optind], O_RDONLY|O_BINARY, 0);
if (fd < 0) {
fprintf(stderr, "%s: %s: Cannot open input file.\n",
argv[0], argv[optind]);
- return (-1);
+ return (EXIT_FAILURE);
}
if (guessSize(fd, dtype, hdr_size, nbands, swab, &width, &length) < 0)
- return 1;
+ return EXIT_FAILURE;
if (outfilename == NULL)
outfilename = argv[optind+1];
@@ -218,7 +225,7 @@ main(int argc, char* argv[])
if (out == NULL) {
fprintf(stderr, "%s: %s: Cannot open file for output.\n",
argv[0], outfilename);
- return (-1);
+ return (EXIT_FAILURE);
}
TIFFSetField(out, TIFFTAG_IMAGEWIDTH, width);
TIFFSetField(out, TIFFTAG_IMAGELENGTH, length);
@@ -336,7 +343,7 @@ main(int argc, char* argv[])
if (buf1)
_TIFFfree(buf1);
TIFFClose(out);
- return (0);
+ return (EXIT_SUCCESS);
}
static void
@@ -372,7 +379,7 @@ guessSize(int fd, TIFFDataType dtype, _TIFF_off_t hdr_size, uint32 nbands,
_TIFF_stat_s filestat;
uint32 w, h, scanlinesize, imagesize;
uint32 depth = TIFFDataWidth(dtype);
- float cor_coef = 0, tmp;
+ double cor_coef = 0, tmp;
if (_TIFF_fstat_f(fd, &filestat) == -1) {
fprintf(stderr, "Failed to obtain file size.\n");
@@ -419,22 +426,28 @@ guessSize(int fd, TIFFDataType dtype, _TIFF_off_t hdr_size, uint32 nbands,
w++) {
if (imagesize % w == 0) {
scanlinesize = w * depth;
+ h = imagesize / w;
+ if (h < 2)
+ continue;
+ /* reads 2 lines at the middle of the image and calculate their correlation.
+ * it works for h >= 2. (in this case it will compare line 0 and line 1 */
buf1 = _TIFFmalloc(scanlinesize);
buf2 = _TIFFmalloc(scanlinesize);
- h = imagesize / w;
do {
- if (_TIFF_lseek_f(fd, hdr_size + (int)(h/2)*scanlinesize,
+ if (_TIFF_lseek_f(fd, hdr_size + (int)((h - 1)/2)*scanlinesize,
SEEK_SET) == (_TIFF_off_t)-1) {
fprintf(stderr, "seek error.\n");
fail=1;
break;
}
+ /* read line (h-1)/2 */
if (read(fd, buf1, scanlinesize) !=
(long) scanlinesize) {
fprintf(stderr, "read error.\n");
fail=1;
break;
}
+ /* read line ((h-1)/2)+1 */
if (read(fd, buf2, scanlinesize) !=
(long) scanlinesize) {
fprintf(stderr, "read error.\n");
@@ -445,11 +458,15 @@ guessSize(int fd, TIFFDataType dtype, _TIFF_off_t hdr_size, uint32 nbands,
swapBytesInScanline(buf1, w, dtype);
swapBytesInScanline(buf2, w, dtype);
}
- tmp = (float) fabs(correlation(buf1, buf2,
- w, dtype));
- if (tmp > cor_coef) {
- cor_coef = tmp;
+ if (0 == memcmp(buf1, buf2, scanlinesize)) {
*width = w, *length = h;
+ } else {
+ tmp = fabs(correlation(buf1, buf2,
+ w, dtype));
+ if (tmp > cor_coef) {
+ cor_coef = tmp;
+ *width = w, *length = h;
+ }
}
} while (0);
@@ -564,6 +581,7 @@ correlation(void *buf1, void *buf2, uint32 n_elem, TIFFDataType dtype)
M2 /= n_elem;
D1 -= M1 * M1 * n_elem;
D2 -= M2 * M2 * n_elem;
+ if (D1 * D2 == 0.0) return 0.0; /* avoid divide by zero */
K = (K - M1 * M2 * n_elem) / sqrt(D1 * D2);
return K;
@@ -587,7 +605,7 @@ processCompressOptions(char* opt)
else if (cp[1] == 'r' )
jpegcolormode = JPEGCOLORMODE_RAW;
else
- usage();
+ usage(EXIT_FAILURE);
cp = strchr(cp+1,':');
}
@@ -606,7 +624,7 @@ processCompressOptions(char* opt)
return (1);
}
-static char* stuff[] = {
+static const char* stuff[] = {
"raw2tiff --- tool for converting raw byte sequences in TIFF images",
"usage: raw2tiff [options] input.raw output.tif",
"where options are:",
@@ -667,16 +685,15 @@ NULL
};
static void
-usage(void)
+usage(int code)
{
- char buf[BUFSIZ];
int i;
+ FILE * out = (code == EXIT_SUCCESS) ? stdout : stderr;
- setbuf(stderr, buf);
- fprintf(stderr, "%s\n\n", TIFFGetVersion());
+ fprintf(out, "%s\n\n", TIFFGetVersion());
for (i = 0; stuff[i] != NULL; i++)
- fprintf(stderr, "%s\n", stuff[i]);
- exit(-1);
+ fprintf(out, "%s\n", stuff[i]);
+ exit(code);
}
/* vim: set ts=8 sts=8 sw=8 noet: */
diff --git a/tiff/tools/rgb2ycbcr.c b/tiff/tools/rgb2ycbcr.c
index cf5f956f..482cc5b4 100644
--- a/tiff/tools/rgb2ycbcr.c
+++ b/tiff/tools/rgb2ycbcr.c
@@ -39,6 +39,13 @@
#include "tiffiop.h"
#include "tiffio.h"
+#ifndef EXIT_SUCCESS
+#define EXIT_SUCCESS 0
+#endif
+#ifndef EXIT_FAILURE
+#define EXIT_FAILURE 1
+#endif
+
#define streq(a,b) (strcmp(a,b) == 0)
#define CopyField(tag, v) \
if (TIFFGetField(in, tag, &v)) TIFFSetField(out, tag, v)
@@ -89,17 +96,17 @@ main(int argc, char* argv[])
else if (streq(optarg, "zip"))
compression = COMPRESSION_ADOBE_DEFLATE;
else
- usage(-1);
+ usage(EXIT_FAILURE);
break;
case 'h':
horizSubSampling = atoi(optarg);
if( horizSubSampling != 1 && horizSubSampling != 2 && horizSubSampling != 4 )
- usage(-1);
+ usage(EXIT_FAILURE);
break;
case 'v':
vertSubSampling = atoi(optarg);
if( vertSubSampling != 1 && vertSubSampling != 2 && vertSubSampling != 4 )
- usage(-1);
+ usage(EXIT_FAILURE);
break;
case 'r':
rowsperstrip = atoi(optarg);
@@ -113,14 +120,14 @@ main(int argc, char* argv[])
refBlackWhite[5] = 240.;
break;
case '?':
- usage(0);
+ usage(EXIT_FAILURE);
/*NOTREACHED*/
}
if (argc - optind < 2)
- usage(-1);
+ usage(EXIT_FAILURE);
out = TIFFOpen(argv[argc-1], "w");
if (out == NULL)
- return (-2);
+ return (EXIT_FAILURE);
setupLumaTables();
for (; optind < argc-1; optind++) {
in = TIFFOpen(argv[optind], "r");
@@ -129,6 +136,7 @@ main(int argc, char* argv[])
if (!tiffcvt(in, out) ||
!TIFFWriteDirectory(out)) {
(void) TIFFClose(out);
+ (void) TIFFClose(in);
return (1);
}
} while (TIFFReadDirectory(in));
@@ -136,7 +144,7 @@ main(int argc, char* argv[])
}
}
(void) TIFFClose(out);
- return (0);
+ return (EXIT_SUCCESS);
}
float *lumaRed;
@@ -356,7 +364,7 @@ tiffcvt(TIFF* in, TIFF* out)
return result;
}
-char* stuff[] = {
+const char* stuff[] = {
"usage: rgb2ycbcr [-c comp] [-r rows] [-h N] [-v N] input... output\n",
"where comp is one of the following compression algorithms:\n",
" jpeg\t\tJPEG encoding\n",
@@ -374,14 +382,12 @@ char* stuff[] = {
static void
usage(int code)
{
- char buf[BUFSIZ];
int i;
+ FILE * out = (code == EXIT_SUCCESS) ? stdout : stderr;
- setbuf(stderr, buf);
-
- fprintf(stderr, "%s\n\n", TIFFGetVersion());
+ fprintf(out, "%s\n\n", TIFFGetVersion());
for (i = 0; stuff[i] != NULL; i++)
- fprintf(stderr, "%s\n", stuff[i]);
+ fprintf(out, "%s\n", stuff[i]);
exit(code);
}
diff --git a/tiff/tools/thumbnail.c b/tiff/tools/thumbnail.c
index 169a6369..edb69983 100644
--- a/tiff/tools/thumbnail.c
+++ b/tiff/tools/thumbnail.c
@@ -39,6 +39,13 @@
#include "tiffio.h"
+#ifndef EXIT_SUCCESS
+#define EXIT_SUCCESS 0
+#endif
+#ifndef EXIT_FAILURE
+#define EXIT_FAILURE 1
+#endif
+
#ifndef HAVE_GETOPT
extern int getopt(int argc, char * const argv[], const char *optstring);
#endif
@@ -67,7 +74,7 @@ static uint8* thumbnail;
static int cpIFD(TIFF*, TIFF*);
static int generateThumbnail(TIFF*, TIFF*);
static void initScale();
-static void usage(void);
+static void usage(int code);
#if !HAVE_DECL_OPTARG
extern char* optarg;
@@ -94,11 +101,11 @@ main(int argc, char* argv[])
streq(optarg, "linear")? LINEAR :
EXP;
break;
- default: usage();
+ default: usage(EXIT_FAILURE);
}
}
if (argc-optind != 2)
- usage();
+ usage(EXIT_FAILURE);
out = TIFFOpen(argv[optind+1], "w");
if (out == NULL)
@@ -111,7 +118,7 @@ main(int argc, char* argv[])
if (!thumbnail) {
TIFFError(TIFFFileName(in),
"Can't allocate space for thumbnail buffer.");
- return 1;
+ return EXIT_FAILURE;
}
if (in != NULL) {
@@ -125,10 +132,10 @@ main(int argc, char* argv[])
(void) TIFFClose(in);
}
(void) TIFFClose(out);
- return 0;
+ return EXIT_SUCCESS;
bad:
(void) TIFFClose(out);
- return 1;
+ return EXIT_FAILURE;
}
#define CopyField(tag, v) \
@@ -650,7 +657,7 @@ generateThumbnail(TIFF* in, TIFF* out)
TIFFWriteDirectory(out) != -1);
}
-char* stuff[] = {
+const char* stuff[] = {
"usage: thumbnail [options] input.tif output.tif",
"where options are:",
" -h # specify thumbnail image height (default is 274)",
@@ -667,16 +674,15 @@ NULL
};
static void
-usage(void)
+usage(int code)
{
- char buf[BUFSIZ];
int i;
+ FILE * out = (code == EXIT_SUCCESS) ? stdout : stderr;
- setbuf(stderr, buf);
- fprintf(stderr, "%s\n\n", TIFFGetVersion());
+ fprintf(out, "%s\n\n", TIFFGetVersion());
for (i = 0; stuff[i] != NULL; i++)
- fprintf(stderr, "%s\n", stuff[i]);
- exit(-1);
+ fprintf(out, "%s\n", stuff[i]);
+ exit(code);
}
/* vim: set ts=8 sts=8 sw=8 noet: */
diff --git a/tiff/tools/tiff2bw.c b/tiff/tools/tiff2bw.c
index dbc697b0..654bd324 100644
--- a/tiff/tools/tiff2bw.c
+++ b/tiff/tools/tiff2bw.c
@@ -40,13 +40,20 @@
#include "tiffio.h"
#include "tiffiop.h"
+#ifndef EXIT_SUCCESS
+#define EXIT_SUCCESS 0
+#endif
+#ifndef EXIT_FAILURE
+#define EXIT_FAILURE 1
+#endif
+
/* x% weighting -> fraction of full color */
#define PCT(x) (((x)*256+50)/100)
int RED = PCT(30); /* 30% */
int GREEN = PCT(59); /* 59% */
int BLUE = PCT(11); /* 11% */
-static void usage(void);
+static void usage(int code);
static int processCompressOptions(char*);
static void
@@ -133,11 +140,11 @@ main(int argc, char* argv[])
inbuf = (unsigned char *) NULL;
outbuf = (unsigned char *) NULL;
- while ((c = getopt(argc, argv, "c:r:R:G:B:")) != -1)
+ while ((c = getopt(argc, argv, "c:r:R:G:B:h")) != -1)
switch (c) {
case 'c': /* compression scheme */
if (!processCompressOptions(optarg))
- usage();
+ usage(EXIT_FAILURE);
break;
case 'r': /* rows/strip */
rowsperstrip = atoi(optarg);
@@ -151,15 +158,17 @@ main(int argc, char* argv[])
case 'B':
BLUE = PCT(atoi(optarg));
break;
+ case 'h':
+ usage(EXIT_SUCCESS);
case '?':
- usage();
+ usage(EXIT_FAILURE);
/*NOTREACHED*/
}
if (argc - optind < 2)
- usage();
+ usage(EXIT_FAILURE);
in = TIFFOpen(argv[optind], "r");
if (in == NULL)
- return (-1);
+ return (EXIT_FAILURE);
photometric = 0;
TIFFGetField(in, TIFFTAG_PHOTOMETRIC, &photometric);
if (photometric != PHOTOMETRIC_RGB && photometric != PHOTOMETRIC_PALETTE ) {
@@ -306,7 +315,7 @@ main(int argc, char* argv[])
_TIFFfree(outbuf);
TIFFClose(in);
TIFFClose(out);
- return (0);
+ return (EXIT_SUCCESS);
tiff2bw_error:
if (inbuf)
@@ -317,7 +326,7 @@ main(int argc, char* argv[])
TIFFClose(out);
if (in)
TIFFClose(in);
- return (-1);
+ return (EXIT_FAILURE);
}
static int
@@ -338,7 +347,7 @@ processCompressOptions(char* opt)
else if (cp[1] == 'r' )
jpegcolormode = JPEGCOLORMODE_RAW;
else
- usage();
+ usage(EXIT_FAILURE);
cp = strchr(cp+1,':');
}
@@ -492,7 +501,7 @@ cpTags(TIFF* in, TIFF* out)
}
#undef NTAGS
-char* stuff[] = {
+const char* stuff[] = {
"usage: tiff2bw [options] input.tif output.tif",
"where options are:",
" -R % use #% from red channel",
@@ -515,16 +524,15 @@ NULL
};
static void
-usage(void)
+usage(int code)
{
- char buf[BUFSIZ];
int i;
+ FILE * out = (code == EXIT_SUCCESS) ? stdout : stderr;
- setbuf(stderr, buf);
- fprintf(stderr, "%s\n\n", TIFFGetVersion());
+ fprintf(out, "%s\n\n", TIFFGetVersion());
for (i = 0; stuff[i] != NULL; i++)
- fprintf(stderr, "%s\n", stuff[i]);
- exit(-1);
+ fprintf(out, "%s\n", stuff[i]);
+ exit(code);
}
/* vim: set ts=8 sts=8 sw=8 noet: */
diff --git a/tiff/tools/tiff2pdf.c b/tiff/tools/tiff2pdf.c
index 779c1662..acaef0d6 100644
--- a/tiff/tools/tiff2pdf.c
+++ b/tiff/tools/tiff2pdf.c
@@ -70,6 +70,8 @@ extern int getopt(int argc, char * const argv[], const char *optstring);
#define TIFF_DIR_MAX 65534
+#define DEFAULT_MAX_MALLOC (256 * 1024 * 1024)
+
/* This type is of PDF color spaces. */
typedef enum {
T2P_CS_BILEVEL = 0x01, /* Bilevel, black and white */
@@ -176,6 +178,7 @@ typedef struct {
uint16 tiff_orientation;
toff_t tiff_dataoffset;
tsize_t tiff_datasize;
+ tsize_t tiff_maxdatasize;
uint16 tiff_resunit;
uint16 pdf_centimeters;
uint16 pdf_overrideres;
@@ -207,14 +210,19 @@ typedef struct {
char pdf_datetime[TIFF2PDF_DATETIME_SIZE];
#define TIFF2PDF_CREATOR_SIZE 512
char pdf_creator[TIFF2PDF_CREATOR_SIZE];
+ int pdf_creator_set;
#define TIFF2PDF_AUTHOR_SIZE 512
char pdf_author[TIFF2PDF_AUTHOR_SIZE];
+ int pdf_author_set;
#define TIFF2PDF_TITLE_SIZE 512
char pdf_title[TIFF2PDF_TITLE_SIZE];
+ int pdf_title_set;
#define TIFF2PDF_SUBJECT_SIZE 512
char pdf_subject[TIFF2PDF_SUBJECT_SIZE];
+ int pdf_subject_set;
#define TIFF2PDF_KEYWORDS_SIZE 512
char pdf_keywords[TIFF2PDF_KEYWORDS_SIZE];
+ int pdf_keywords_set;
t2p_cs_t pdf_colorspace;
uint16 pdf_colorspace_invert;
uint16 pdf_switchdecode;
@@ -224,7 +232,7 @@ typedef struct {
t2p_compress_t pdf_defaultcompression;
uint16 pdf_defaultcompressionquality;
t2p_compress_t pdf_compression;
- uint16 pdf_compressionquality;
+ uint16 pdf_compressionquality; /* for deflate : 100 * zipquality + predictor */
uint16 pdf_nopassthrough;
t2p_transcode_t pdf_transcode;
t2p_sample_t pdf_sample;
@@ -255,7 +263,7 @@ typedef struct {
/* These functions are called by main. */
-void tiff2pdf_usage(void);
+static void tiff2pdf_usage(int);
int tiff2pdf_match_paper_size(float*, float*, char*);
/* These functions are used to generate a PDF from a TIFF. */
@@ -301,8 +309,8 @@ tsize_t t2p_sample_lab_signed_to_unsigned(tdata_t, uint32);
tsize_t t2p_write_pdf_header(T2P*, TIFF*);
tsize_t t2p_write_pdf_obj_start(uint32, TIFF*);
tsize_t t2p_write_pdf_obj_end(TIFF*);
-tsize_t t2p_write_pdf_name(unsigned char*, TIFF*);
-tsize_t t2p_write_pdf_string(char*, TIFF*);
+tsize_t t2p_write_pdf_name(const unsigned char*, TIFF*);
+tsize_t t2p_write_pdf_string(const char*, TIFF*);
tsize_t t2p_write_pdf_stream(tdata_t, tsize_t, TIFF*);
tsize_t t2p_write_pdf_stream_start(TIFF*);
tsize_t t2p_write_pdf_stream_end(TIFF*);
@@ -617,8 +625,11 @@ int main(int argc, char** argv){
while (argv &&
(c = getopt(argc, argv,
- "o:q:u:x:y:w:l:r:p:e:c:a:t:s:k:jzndifbhF")) != -1){
+ "m:o:q:u:x:y:w:l:r:p:e:c:a:t:s:k:jzndifbhF")) != -1){
switch (c) {
+ case 'm':
+ t2p->tiff_maxdatasize = (tsize_t)strtoul(optarg, NULL, 0) << 20;
+ break;
case 'o':
outfilename = optarg;
break;
@@ -718,31 +729,37 @@ int main(int argc, char** argv){
case 'c':
strncpy(t2p->pdf_creator, optarg, sizeof(t2p->pdf_creator) - 1);
t2p->pdf_creator[sizeof(t2p->pdf_creator) - 1] = '\0';
+ t2p->pdf_creator_set = 1;
break;
case 'a':
strncpy(t2p->pdf_author, optarg, sizeof(t2p->pdf_author) - 1);
t2p->pdf_author[sizeof(t2p->pdf_author) - 1] = '\0';
+ t2p->pdf_author_set = 1;
break;
case 't':
strncpy(t2p->pdf_title, optarg, sizeof(t2p->pdf_title) - 1);
t2p->pdf_title[sizeof(t2p->pdf_title) - 1] = '\0';
+ t2p->pdf_title_set = 1;
break;
case 's':
strncpy(t2p->pdf_subject, optarg, sizeof(t2p->pdf_subject) - 1);
t2p->pdf_subject[sizeof(t2p->pdf_subject) - 1] = '\0';
+ t2p->pdf_subject_set = 1;
break;
case 'k':
strncpy(t2p->pdf_keywords, optarg, sizeof(t2p->pdf_keywords) - 1);
t2p->pdf_keywords[sizeof(t2p->pdf_keywords) - 1] = '\0';
+ t2p->pdf_keywords_set = 1;
break;
case 'b':
t2p->pdf_image_interpolate = 1;
break;
- case 'h':
- case '?':
- tiff2pdf_usage();
+ case 'h':
+ tiff2pdf_usage(EXIT_SUCCESS);
goto success;
- break;
+ case '?':
+ tiff2pdf_usage(EXIT_FAILURE);
+ goto fail;
}
}
@@ -759,14 +776,14 @@ int main(int argc, char** argv){
}
} else {
TIFFError(TIFF2PDF_MODULE, "No input file specified");
- tiff2pdf_usage();
+ tiff2pdf_usage(EXIT_FAILURE);
goto fail;
}
if(argc > optind) {
TIFFError(TIFF2PDF_MODULE,
"No support for multiple input files");
- tiff2pdf_usage();
+ tiff2pdf_usage(EXIT_FAILURE);
goto fail;
}
@@ -828,8 +845,8 @@ success:
}
-void tiff2pdf_usage(){
- char* lines[]={
+static void tiff2pdf_usage(int code) {
+ static const char* lines[]={
"usage: tiff2pdf [options] input.tiff",
"options:",
" -o: output to file name",
@@ -850,7 +867,7 @@ void tiff2pdf_usage(){
" -l: length in units",
" -r: 'd' for resolution default, 'o' for resolution override",
" -p: paper size, eg \"letter\", \"legal\", \"A4\"",
- " -F: make the tiff fill the PDF page",
+ " -F: make the tiff fill the PDF page",
" -f: set PDF \"Fit Window\" user preference",
" -e: date, overrides image or current date/time default, YYYYMMDDHHMMSS",
" -c: sets document creator, overrides image software default",
@@ -859,14 +876,16 @@ void tiff2pdf_usage(){
" -s: sets document subject, overrides image image description default",
" -k: sets document keywords",
" -b: set PDF \"Interpolate\" user preference",
+ " -m: set memory allocation limit (in MiB). set to 0 to disable limit",
" -h: usage",
NULL
};
int i=0;
+ FILE * out = (code == EXIT_SUCCESS) ? stdout : stderr;
- fprintf(stderr, "%s\n\n", TIFFGetVersion());
+ fprintf(out, "%s\n\n", TIFFGetVersion());
for (i=0;lines[i]!=NULL;i++){
- fprintf(stderr, "%s\n", lines[i]);
+ fprintf(out, "%s\n", lines[i]);
}
return;
@@ -954,6 +973,7 @@ T2P* t2p_init()
t2p->pdf_defaultpagewidth=612.0;
t2p->pdf_defaultpagelength=792.0;
t2p->pdf_xrefcount=3; /* Catalog, Info, Pages */
+ t2p->tiff_maxdatasize = DEFAULT_MAX_MALLOC;
return(t2p);
}
@@ -1012,14 +1032,14 @@ void t2p_validate(T2P* t2p){
#endif
#ifdef ZIP_SUPPORT
if(t2p->pdf_defaultcompression==T2P_COMPRESS_ZIP){
- uint16 m=t2p->pdf_defaultcompressionquality%100;
- if(t2p->pdf_defaultcompressionquality/100 > 9 ||
- (m>1 && m<10) || m>15){
- t2p->pdf_defaultcompressionquality=0;
+ uint16 m=t2p->pdf_defaultcompressionquality%100;
+ if(t2p->pdf_defaultcompressionquality/100 > 9 ||
+ (m>1 && m<10) || m>15){
+ t2p->pdf_defaultcompressionquality=0;
}
if(t2p->pdf_defaultcompressionquality%100 !=0){
- t2p->pdf_defaultcompressionquality/=100;
- t2p->pdf_defaultcompressionquality*=100;
+ t2p->pdf_defaultcompressionquality/=100;
+ t2p->pdf_defaultcompressionquality*=100;
TIFFError(
TIFF2PDF_MODULE,
"PNG Group predictor differencing not implemented, assuming compression quality %u",
@@ -1804,8 +1824,12 @@ void t2p_read_tiff_data(T2P* t2p, TIFF* input){
if(t2p->tiff_compression== COMPRESSION_ADOBE_DEFLATE
|| t2p->tiff_compression==COMPRESSION_DEFLATE){
if(TIFFIsTiled(input) || (TIFFNumberOfStrips(input)==1) ){
+ uint16 predictor;
t2p->pdf_transcode = T2P_TRANSCODE_RAW;
t2p->pdf_compression=T2P_COMPRESS_ZIP;
+ TIFFGetField(input, TIFFTAG_PREDICTOR, &predictor);
+ t2p->pdf_compressionquality = predictor;
+ /* TIFFTAG_ZIPQUALITY is always Z_DEFAULT_COMPRESSION on reading */
}
}
#endif
@@ -2063,9 +2087,17 @@ void t2p_read_tiff_size(T2P* t2p, TIFF* input){
#endif
(void) 0;
}
- k = checkMultiply64(TIFFScanlineSize(input), t2p->tiff_length, t2p);
- if(t2p->tiff_planar==PLANARCONFIG_SEPARATE){
- k = checkMultiply64(k, t2p->tiff_samplesperpixel, t2p);
+#ifdef JPEG_SUPPORT
+ if(t2p->pdf_compression == T2P_COMPRESS_JPEG
+ && t2p->tiff_photometric == PHOTOMETRIC_YCBCR) {
+ k = checkMultiply64(TIFFNumberOfStrips(input), TIFFStripSize(input), t2p);
+ } else
+#endif
+ {
+ k = checkMultiply64(TIFFScanlineSize(input), t2p->tiff_length, t2p);
+ if(t2p->tiff_planar==PLANARCONFIG_SEPARATE){
+ k = checkMultiply64(k, t2p->tiff_samplesperpixel, t2p);
+ }
}
if (k == 0) {
/* Assume we had overflow inside TIFFScanlineSize */
@@ -2115,7 +2147,7 @@ void t2p_read_tiff_size_tile(T2P* t2p, TIFF* input, ttile_t tile){
k=tbc[tile];
#ifdef OJPEG_SUPPORT
if(t2p->tiff_compression==COMPRESSION_OJPEG){
- k = checkAdd64(k, 2048, t2p);
+ k = checkAdd64(k, 2048, t2p);
}
#endif
#ifdef JPEG_SUPPORT
@@ -2205,6 +2237,9 @@ int t2p_tile_is_corner_edge(T2P_TILES tiles, ttile_t tile){
return(t2p_tile_is_right_edge(tiles, tile) & t2p_tile_is_bottom_edge(tiles, tile) );
}
+#if defined(JPEG_SUPPORT) || defined(OJPEG_SUPPORT)
+static const unsigned char jpeg_eof_marker[] = { 0xff, 0xd9 };
+#endif
/*
This function reads the raster image data from the input TIFF for an image and writes
@@ -2252,16 +2287,22 @@ tsize_t t2p_readwrite_pdf_image(T2P* t2p, TIFF* input, TIFF* output){
buffer = (unsigned char*)
_TIFFmalloc(t2p->tiff_datasize);
if (buffer == NULL) {
- TIFFError(TIFF2PDF_MODULE,
- "Can't allocate %lu bytes of memory for "
- "t2p_readwrite_pdf_image, %s",
- (unsigned long) t2p->tiff_datasize,
+ TIFFError(TIFF2PDF_MODULE,
+ "Can't allocate %lu bytes of memory for "
+ "t2p_readwrite_pdf_image, %s",
+ (unsigned long) t2p->tiff_datasize,
TIFFFileName(input));
t2p->t2p_error = T2P_ERR_ERROR;
return(0);
}
- TIFFReadRawStrip(input, 0, (tdata_t) buffer,
- t2p->tiff_datasize);
+ memset(buffer, 0, t2p->tiff_datasize);
+ if (TIFFReadRawStrip(input, 0, (tdata_t) buffer,
+ t2p->tiff_datasize) < 0) {
+ TIFFError(TIFF2PDF_MODULE,
+ "TIFFReadRawStrip() failed");
+ _TIFFfree(buffer);
+ return(0);
+ }
if (t2p->tiff_fillorder==FILLORDER_LSB2MSB){
/*
* make sure is lsb-to-msb
@@ -2281,16 +2322,21 @@ tsize_t t2p_readwrite_pdf_image(T2P* t2p, TIFF* input, TIFF* output){
buffer = (unsigned char*)
_TIFFmalloc(t2p->tiff_datasize);
if(buffer == NULL){
- TIFFError(TIFF2PDF_MODULE,
- "Can't allocate %lu bytes of memory for t2p_readwrite_pdf_image, %s",
- (unsigned long) t2p->tiff_datasize,
+ TIFFError(TIFF2PDF_MODULE,
+ "Can't allocate %lu bytes of memory for t2p_readwrite_pdf_image, %s",
+ (unsigned long) t2p->tiff_datasize,
TIFFFileName(input));
t2p->t2p_error = T2P_ERR_ERROR;
return(0);
}
- memset(buffer, 0, t2p->tiff_datasize);
- TIFFReadRawStrip(input, 0, (tdata_t) buffer,
- t2p->tiff_datasize);
+ memset(buffer, 0, t2p->tiff_datasize);
+ if (TIFFReadRawStrip(input, 0, (tdata_t) buffer,
+ t2p->tiff_datasize) < 0) {
+ TIFFError(TIFF2PDF_MODULE,
+ "TIFFReadRawStrip() failed");
+ _TIFFfree(buffer);
+ return(0);
+ }
if (t2p->tiff_fillorder==FILLORDER_LSB2MSB) {
TIFFReverseBits(buffer,
t2p->tiff_datasize);
@@ -2308,14 +2354,14 @@ tsize_t t2p_readwrite_pdf_image(T2P* t2p, TIFF* input, TIFF* output){
buffer = (unsigned char*)
_TIFFmalloc(t2p->tiff_datasize);
if(buffer == NULL) {
- TIFFError(TIFF2PDF_MODULE,
- "Can't allocate %lu bytes of memory for t2p_readwrite_pdf_image, %s",
- (unsigned long) t2p->tiff_datasize,
+ TIFFError(TIFF2PDF_MODULE,
+ "Can't allocate %lu bytes of memory for t2p_readwrite_pdf_image, %s",
+ (unsigned long) t2p->tiff_datasize,
TIFFFileName(input));
t2p->t2p_error = T2P_ERR_ERROR;
return(0);
}
- memset(buffer, 0, t2p->tiff_datasize);
+ memset(buffer, 0, t2p->tiff_datasize);
if(t2p->pdf_ojpegiflength==0){
inputoffset=t2pSeekFile(input, 0,
SEEK_CUR);
@@ -2375,8 +2421,8 @@ tsize_t t2p_readwrite_pdf_image(T2P* t2p, TIFF* input, TIFF* output){
}
} else {
if(! t2p->pdf_ojpegdata){
- TIFFError(TIFF2PDF_MODULE,
- "No support for OJPEG image %s with bad tables",
+ TIFFError(TIFF2PDF_MODULE,
+ "No support for OJPEG image %s with bad tables",
TIFFFileName(input));
t2p->t2p_error = T2P_ERR_ERROR;
return(0);
@@ -2384,32 +2430,39 @@ tsize_t t2p_readwrite_pdf_image(T2P* t2p, TIFF* input, TIFF* output){
buffer = (unsigned char*)
_TIFFmalloc(t2p->tiff_datasize);
if(buffer==NULL){
- TIFFError(TIFF2PDF_MODULE,
- "Can't allocate %lu bytes of memory for t2p_readwrite_pdf_image, %s",
- (unsigned long) t2p->tiff_datasize,
+ TIFFError(TIFF2PDF_MODULE,
+ "Can't allocate %lu bytes of memory for t2p_readwrite_pdf_image, %s",
+ (unsigned long) t2p->tiff_datasize,
TIFFFileName(input));
t2p->t2p_error = T2P_ERR_ERROR;
return(0);
}
- memset(buffer, 0, t2p->tiff_datasize);
+ memset(buffer, 0, t2p->tiff_datasize);
_TIFFmemcpy(buffer, t2p->pdf_ojpegdata, t2p->pdf_ojpegdatalength);
bufferoffset=t2p->pdf_ojpegdatalength;
stripcount=TIFFNumberOfStrips(input);
for(i=0;i<stripcount;i++){
+ tsize_t retTIFFReadRawStrip;
if(i != 0){
buffer[bufferoffset++]=0xff;
buffer[bufferoffset++]=(0xd0 | ((i-1)%8));
}
- bufferoffset+=TIFFReadRawStrip(input,
+ retTIFFReadRawStrip = TIFFReadRawStrip(input,
i,
(tdata_t) &(((unsigned char*)buffer)[bufferoffset]),
-1);
+ if (retTIFFReadRawStrip < 0) {
+ TIFFError(TIFF2PDF_MODULE, "TIFFReadRawStrip()");
+ _TIFFfree(buffer);
+ t2p->t2p_error = T2P_ERR_ERROR;
+ return(0);
+ }
+ bufferoffset += retTIFFReadRawStrip;
}
+ t2pWriteFile(output, (tdata_t) buffer, bufferoffset);
if( ! ( (buffer[bufferoffset-1]==0xd9) && (buffer[bufferoffset-2]==0xff) ) ){
- buffer[bufferoffset++]=0xff;
- buffer[bufferoffset++]=0xd9;
+ t2pWriteFile(output, (tdata_t) jpeg_eof_marker, sizeof(jpeg_eof_marker));
}
- t2pWriteFile(output, (tdata_t) buffer, bufferoffset);
_TIFFfree(buffer);
return(bufferoffset);
#if 0
@@ -2433,14 +2486,14 @@ tsize_t t2p_readwrite_pdf_image(T2P* t2p, TIFF* input, TIFF* output){
buffer = (unsigned char*)
_TIFFmalloc(t2p->tiff_datasize);
if(buffer==NULL){
- TIFFError(TIFF2PDF_MODULE,
- "Can't allocate %lu bytes of memory for t2p_readwrite_pdf_image, %s",
- (unsigned long) t2p->tiff_datasize,
+ TIFFError(TIFF2PDF_MODULE,
+ "Can't allocate %lu bytes of memory for t2p_readwrite_pdf_image, %s",
+ (unsigned long) t2p->tiff_datasize,
TIFFFileName(input));
t2p->t2p_error = T2P_ERR_ERROR;
return(0);
}
- memset(buffer, 0, t2p->tiff_datasize);
+ memset(buffer, 0, t2p->tiff_datasize);
if (TIFFGetField(input, TIFFTAG_JPEGTABLES, &count, &jpt) != 0) {
if(count > 4) {
_TIFFmemcpy(buffer, jpt, count);
@@ -2455,16 +2508,24 @@ tsize_t t2p_readwrite_pdf_image(T2P* t2p, TIFF* input, TIFF* output){
stripbuffer = (unsigned char*)
_TIFFmalloc(max_striplength);
if(stripbuffer==NULL){
- TIFFError(TIFF2PDF_MODULE,
- "Can't allocate %u bytes of memory for t2p_readwrite_pdf_image, %s",
- max_striplength,
+ TIFFError(TIFF2PDF_MODULE,
+ "Can't allocate %u bytes of memory for t2p_readwrite_pdf_image, %s",
+ max_striplength,
TIFFFileName(input));
_TIFFfree(buffer);
t2p->t2p_error = T2P_ERR_ERROR;
return(0);
}
+ memset(stripbuffer, 0, max_striplength);
for(i=0;i<stripcount;i++){
striplength=TIFFReadRawStrip(input, i, (tdata_t) stripbuffer, -1);
+ if (striplength < 0) {
+ TIFFError(TIFF2PDF_MODULE, "TIFFReadRawStrip() failed");
+ _TIFFfree(samplebuffer);
+ _TIFFfree(buffer);
+ t2p->t2p_error = T2P_ERR_ERROR;
+ return(0);
+ }
if(!t2p_process_jpeg_strip(
stripbuffer,
&striplength,
@@ -2482,9 +2543,8 @@ tsize_t t2p_readwrite_pdf_image(T2P* t2p, TIFF* input, TIFF* output){
return(0);
}
}
- buffer[bufferoffset++]=0xff;
- buffer[bufferoffset++]=0xd9;
t2pWriteFile(output, (tdata_t) buffer, bufferoffset);
+ t2pWriteFile(output, (tdata_t) jpeg_eof_marker, sizeof(jpeg_eof_marker));
_TIFFfree(stripbuffer);
_TIFFfree(buffer);
return(bufferoffset);
@@ -2496,14 +2556,14 @@ tsize_t t2p_readwrite_pdf_image(T2P* t2p, TIFF* input, TIFF* output){
if(t2p->pdf_sample==T2P_SAMPLE_NOTHING){
buffer = (unsigned char*) _TIFFmalloc(t2p->tiff_datasize);
if(buffer==NULL){
- TIFFError(TIFF2PDF_MODULE,
- "Can't allocate %lu bytes of memory for t2p_readwrite_pdf_image, %s",
- (unsigned long) t2p->tiff_datasize,
+ TIFFError(TIFF2PDF_MODULE,
+ "Can't allocate %lu bytes of memory for t2p_readwrite_pdf_image, %s",
+ (unsigned long) t2p->tiff_datasize,
TIFFFileName(input));
t2p->t2p_error = T2P_ERR_ERROR;
return(0);
}
- memset(buffer, 0, t2p->tiff_datasize);
+ memset(buffer, 0, t2p->tiff_datasize);
stripsize=TIFFStripSize(input);
stripcount=TIFFNumberOfStrips(input);
for(i=0;i<stripcount;i++){
@@ -2534,19 +2594,19 @@ tsize_t t2p_readwrite_pdf_image(T2P* t2p, TIFF* input, TIFF* output){
buffer = (unsigned char*) _TIFFmalloc(t2p->tiff_datasize);
if(buffer==NULL){
- TIFFError(TIFF2PDF_MODULE,
- "Can't allocate %lu bytes of memory for t2p_readwrite_pdf_image, %s",
- (unsigned long) t2p->tiff_datasize,
+ TIFFError(TIFF2PDF_MODULE,
+ "Can't allocate %lu bytes of memory for t2p_readwrite_pdf_image, %s",
+ (unsigned long) t2p->tiff_datasize,
TIFFFileName(input));
t2p->t2p_error = T2P_ERR_ERROR;
return(0);
}
- memset(buffer, 0, t2p->tiff_datasize);
+ memset(buffer, 0, t2p->tiff_datasize);
samplebuffer = (unsigned char*) _TIFFmalloc(stripsize);
if(samplebuffer==NULL){
- TIFFError(TIFF2PDF_MODULE,
- "Can't allocate %lu bytes of memory for t2p_readwrite_pdf_image, %s",
- (unsigned long) t2p->tiff_datasize,
+ TIFFError(TIFF2PDF_MODULE,
+ "Can't allocate %lu bytes of memory for t2p_readwrite_pdf_image, %s",
+ (unsigned long) t2p->tiff_datasize,
TIFFFileName(input));
t2p->t2p_error = T2P_ERR_ERROR;
_TIFFfree(buffer);
@@ -2561,9 +2621,9 @@ tsize_t t2p_readwrite_pdf_image(T2P* t2p, TIFF* input, TIFF* output){
(tdata_t) &(samplebuffer[samplebufferoffset]),
TIFFmin(sepstripsize, stripsize - samplebufferoffset));
if(read==-1){
- TIFFError(TIFF2PDF_MODULE,
- "Error on decoding strip %u of %s",
- i + j*stripcount,
+ TIFFError(TIFF2PDF_MODULE,
+ "Error on decoding strip %u of %s",
+ i + j*stripcount,
TIFFFileName(input));
_TIFFfree(buffer);
t2p->t2p_error=T2P_ERR_ERROR;
@@ -2584,14 +2644,14 @@ tsize_t t2p_readwrite_pdf_image(T2P* t2p, TIFF* input, TIFF* output){
buffer = (unsigned char*) _TIFFmalloc(t2p->tiff_datasize);
if(buffer==NULL){
- TIFFError(TIFF2PDF_MODULE,
- "Can't allocate %lu bytes of memory for t2p_readwrite_pdf_image, %s",
- (unsigned long) t2p->tiff_datasize,
+ TIFFError(TIFF2PDF_MODULE,
+ "Can't allocate %lu bytes of memory for t2p_readwrite_pdf_image, %s",
+ (unsigned long) t2p->tiff_datasize,
TIFFFileName(input));
t2p->t2p_error = T2P_ERR_ERROR;
return(0);
}
- memset(buffer, 0, t2p->tiff_datasize);
+ memset(buffer, 0, t2p->tiff_datasize);
stripsize=TIFFStripSize(input);
stripcount=TIFFNumberOfStrips(input);
for(i=0;i<stripcount;i++){
@@ -2855,7 +2915,14 @@ tsize_t t2p_readwrite_pdf_image_tile(T2P* t2p, TIFF* input, TIFF* output, ttile_
t2p->t2p_error = T2P_ERR_ERROR;
return(0);
}
- TIFFReadRawTile(input, tile, (tdata_t) buffer, t2p->tiff_datasize);
+ memset(buffer, 0, t2p->tiff_datasize);
+ if (TIFFReadRawTile(input, tile, (tdata_t) buffer, t2p->tiff_datasize) < 0) {
+ TIFFError(TIFF2PDF_MODULE,
+ "TIFFReadRawTile() failed");
+ _TIFFfree(buffer);
+ t2p->t2p_error = T2P_ERR_ERROR;
+ return(0);
+ }
if (t2p->tiff_fillorder==FILLORDER_LSB2MSB){
TIFFReverseBits(buffer, t2p->tiff_datasize);
}
@@ -2876,7 +2943,14 @@ tsize_t t2p_readwrite_pdf_image_tile(T2P* t2p, TIFF* input, TIFF* output, ttile_
t2p->t2p_error = T2P_ERR_ERROR;
return(0);
}
- TIFFReadRawTile(input, tile, (tdata_t) buffer, t2p->tiff_datasize);
+ memset(buffer, 0, t2p->tiff_datasize);
+ if (TIFFReadRawTile(input, tile, (tdata_t) buffer, t2p->tiff_datasize) < 0) {
+ TIFFError(TIFF2PDF_MODULE,
+ "TIFFReadRawTile() failed");
+ _TIFFfree(buffer);
+ t2p->t2p_error = T2P_ERR_ERROR;
+ return(0);
+ }
if (t2p->tiff_fillorder==FILLORDER_LSB2MSB){
TIFFReverseBits(buffer, t2p->tiff_datasize);
}
@@ -2887,6 +2961,7 @@ tsize_t t2p_readwrite_pdf_image_tile(T2P* t2p, TIFF* input, TIFF* output, ttile_
#endif
#ifdef OJPEG_SUPPORT
if(t2p->tiff_compression == COMPRESSION_OJPEG){
+ tsize_t retTIFFReadRawTile;
if(! t2p->pdf_ojpegdata){
TIFFError(TIFF2PDF_MODULE,
"No support for OJPEG image %s with "
@@ -2905,6 +2980,7 @@ tsize_t t2p_readwrite_pdf_image_tile(T2P* t2p, TIFF* input, TIFF* output, ttile_
t2p->t2p_error = T2P_ERR_ERROR;
return(0);
}
+ memset(buffer, 0, t2p->tiff_datasize);
_TIFFmemcpy(buffer, t2p->pdf_ojpegdata, t2p->pdf_ojpegdatalength);
if(edge!=0){
if(t2p_tile_is_bottom_edge(t2p->tiff_tiles[t2p->pdf_page], tile)){
@@ -2920,14 +2996,20 @@ tsize_t t2p_readwrite_pdf_image_tile(T2P* t2p, TIFF* input, TIFF* output, ttile_
(t2p->tiff_tiles[t2p->pdf_page].tiles_edgetilewidth ) & 0xff;
}
}
- bufferoffset=t2p->pdf_ojpegdatalength;
- bufferoffset+=TIFFReadRawTile(input,
+ bufferoffset = t2p->pdf_ojpegdatalength;
+ retTIFFReadRawTile = TIFFReadRawTile(input,
tile,
(tdata_t) &(((unsigned char*)buffer)[bufferoffset]),
-1);
- ((unsigned char*)buffer)[bufferoffset++]=0xff;
- ((unsigned char*)buffer)[bufferoffset++]=0xd9;
+ if (retTIFFReadRawTile < 0) {
+ TIFFError(TIFF2PDF_MODULE, "TIFFReadRawTile() failed");
+ _TIFFfree(buffer);
+ t2p->t2p_error = T2P_ERR_ERROR;
+ return(0);
+ }
+ bufferoffset += retTIFFReadRawTile;
t2pWriteFile(output, (tdata_t) buffer, bufferoffset);
+ t2pWriteFile(output, (tdata_t) jpeg_eof_marker, sizeof(jpeg_eof_marker));
_TIFFfree(buffer);
return(bufferoffset);
}
@@ -2946,9 +3028,10 @@ tsize_t t2p_readwrite_pdf_image_tile(T2P* t2p, TIFF* input, TIFF* output, ttile_
t2p->t2p_error = T2P_ERR_ERROR;
return(0);
}
+ memset(buffer, 0, t2p->tiff_datasize);
if(TIFFGetField(input, TIFFTAG_JPEGTABLES, &count, &jpt) != 0) {
if (count > 4) {
- int retTIFFReadRawTile;
+ tsize_t retTIFFReadRawTile;
/* Ignore EOI marker of JpegTables */
_TIFFmemcpy(buffer, jpt, count - 2);
bufferoffset += count - 2;
@@ -2957,7 +3040,7 @@ tsize_t t2p_readwrite_pdf_image_tile(T2P* t2p, TIFF* input, TIFF* output, ttile_
table_end[1] = buffer[bufferoffset-1];
xuint32 = bufferoffset;
bufferoffset -= 2;
- retTIFFReadRawTile= TIFFReadRawTile(
+ retTIFFReadRawTile = TIFFReadRawTile(
input,
tile,
(tdata_t) &(((unsigned char*)buffer)[bufferoffset]),
@@ -2994,6 +3077,7 @@ tsize_t t2p_readwrite_pdf_image_tile(T2P* t2p, TIFF* input, TIFF* output, ttile_
t2p->t2p_error = T2P_ERR_ERROR;
return(0);
}
+ memset(buffer, 0, t2p->tiff_datasize);
read = TIFFReadEncodedTile(
input,
@@ -3019,25 +3103,27 @@ tsize_t t2p_readwrite_pdf_image_tile(T2P* t2p, TIFF* input, TIFF* output, ttile_
tilecount=septilecount/t2p->tiff_samplesperpixel;
buffer = (unsigned char*) _TIFFmalloc(t2p->tiff_datasize);
if(buffer==NULL){
- TIFFError(TIFF2PDF_MODULE,
+ TIFFError(TIFF2PDF_MODULE,
"Can't allocate %lu bytes of memory "
- "for t2p_readwrite_pdf_image_tile, %s",
- (unsigned long) t2p->tiff_datasize,
+ "for t2p_readwrite_pdf_image_tile, %s",
+ (unsigned long) t2p->tiff_datasize,
TIFFFileName(input));
t2p->t2p_error = T2P_ERR_ERROR;
return(0);
}
+ memset(buffer, 0, t2p->tiff_datasize);
samplebuffer = (unsigned char*) _TIFFmalloc(t2p->tiff_datasize);
if(samplebuffer==NULL){
- TIFFError(TIFF2PDF_MODULE,
+ TIFFError(TIFF2PDF_MODULE,
"Can't allocate %lu bytes of memory "
- "for t2p_readwrite_pdf_image_tile, %s",
- (unsigned long) t2p->tiff_datasize,
+ "for t2p_readwrite_pdf_image_tile, %s",
+ (unsigned long) t2p->tiff_datasize,
TIFFFileName(input));
_TIFFfree(buffer);
t2p->t2p_error = T2P_ERR_ERROR;
return(0);
}
+ memset(samplebuffer, 0, t2p->tiff_datasize);
samplebufferoffset=0;
for(i=0;i<t2p->tiff_samplesperpixel;i++){
read =
@@ -3069,23 +3155,24 @@ tsize_t t2p_readwrite_pdf_image_tile(T2P* t2p, TIFF* input, TIFF* output, ttile_
if(buffer==NULL){
buffer = (unsigned char*) _TIFFmalloc(t2p->tiff_datasize);
if(buffer==NULL){
- TIFFError(TIFF2PDF_MODULE,
+ TIFFError(TIFF2PDF_MODULE,
"Can't allocate %lu bytes of memory "
- "for t2p_readwrite_pdf_image_tile, %s",
- (unsigned long) t2p->tiff_datasize,
+ "for t2p_readwrite_pdf_image_tile, %s",
+ (unsigned long) t2p->tiff_datasize,
TIFFFileName(input));
t2p->t2p_error = T2P_ERR_ERROR;
return(0);
}
+ memset(buffer, 0, t2p->tiff_datasize);
read = TIFFReadEncodedTile(
input,
tile,
(tdata_t) &buffer[bufferoffset],
t2p->tiff_datasize);
if(read==-1){
- TIFFError(TIFF2PDF_MODULE,
- "Error on decoding tile %u of %s",
- tile,
+ TIFFError(TIFF2PDF_MODULE,
+ "Error on decoding tile %u of %s",
+ tile,
TIFFFileName(input));
_TIFFfree(buffer);
t2p->t2p_error=T2P_ERR_ERROR;
@@ -3108,8 +3195,8 @@ tsize_t t2p_readwrite_pdf_image_tile(T2P* t2p, TIFF* input, TIFF* output, ttile_
}
if(t2p->pdf_sample & T2P_SAMPLE_YCBCR_TO_RGB){
- TIFFError(TIFF2PDF_MODULE,
- "No support for YCbCr to RGB in tile for %s",
+ TIFFError(TIFF2PDF_MODULE,
+ "No support for YCbCr to RGB in tile for %s",
TIFFFileName(input));
_TIFFfree(buffer);
t2p->t2p_error = T2P_ERR_ERROR;
@@ -3242,18 +3329,26 @@ tsize_t t2p_readwrite_pdf_image_tile(T2P* t2p, TIFF* input, TIFF* output, ttile_
break;
}
+ if (TIFFStripSize(output) > t2p->tiff_datasize) {
+ TIFFError(TIFF2PDF_MODULE,
+ "Size mismatch input %ld, output %ld",
+ t2p->tiff_datasize, TIFFStripSize(output));
+ _TIFFfree(buffer);
+ t2p->t2p_error = T2P_ERR_ERROR;
+ return(0);
+ }
t2p_enable(output);
t2p->outputwritten = 0;
bufferoffset = TIFFWriteEncodedStrip(output, (tstrip_t) 0, buffer,
- TIFFStripSize(output));
+ TIFFStripSize(output));
if (buffer != NULL) {
_TIFFfree(buffer);
buffer = NULL;
}
if (bufferoffset == -1) {
- TIFFError(TIFF2PDF_MODULE,
- "Error writing encoded tile to output PDF %s",
- TIFFFileName(output));
+ TIFFError(TIFF2PDF_MODULE,
+ "Error writing encoded tile to output PDF %s",
+ TIFFFileName(output));
t2p->t2p_error = T2P_ERR_ERROR;
return(0);
}
@@ -3731,6 +3826,11 @@ tsize_t t2p_sample_realize_palette(T2P* t2p, unsigned char* buffer){
for(i=sample_count;i>0;i--){
palette_offset=buffer[i-1] * component_count;
sample_offset= (i-1) * component_count;
+ if(palette_offset + component_count > t2p->pdf_palettesize){
+ TIFFError(TIFF2PDF_MODULE,
+ "Error: palette_offset + component_count > t2p->pdf_palettesize");
+ return 1;
+ }
for(j=0;j<component_count;j++){
buffer[sample_offset+j]=t2p->pdf_palette[palette_offset+j];
}
@@ -3886,7 +3986,7 @@ tsize_t t2p_write_pdf_obj_end(TIFF* output){
This function writes a PDF name object to output.
*/
-tsize_t t2p_write_pdf_name(unsigned char* name, TIFF* output){
+tsize_t t2p_write_pdf_name(const unsigned char* name, TIFF* output){
tsize_t written=0;
uint32 i=0;
@@ -3984,7 +4084,7 @@ tsize_t t2p_write_pdf_name(unsigned char* name, TIFF* output){
* This function writes a PDF string object to output.
*/
-tsize_t t2p_write_pdf_string(char* pdfstr, TIFF* output)
+tsize_t t2p_write_pdf_string(const char* pdfstr, TIFF* output)
{
tsize_t written = 0;
uint32 i = 0;
@@ -4175,7 +4275,7 @@ tsize_t t2p_write_pdf_catalog(T2P* t2p, TIFF* output)
tsize_t t2p_write_pdf_info(T2P* t2p, TIFF* input, TIFF* output)
{
tsize_t written = 0;
- char* info;
+ const char* info;
char buffer[512];
if(t2p->pdf_datetime[0] == '\0')
@@ -4190,60 +4290,51 @@ tsize_t t2p_write_pdf_info(T2P* t2p, TIFF* input, TIFF* output)
snprintf(buffer, sizeof(buffer), "libtiff / tiff2pdf - %d", TIFFLIB_VERSION);
written += t2p_write_pdf_string(buffer, output);
written += t2pWriteFile(output, (tdata_t) "\n", 1);
+ if (!t2p->pdf_creator_set) {
+ if (TIFFGetField(input, TIFFTAG_SOFTWARE, &info) != 0 && info) {
+ strncpy(t2p->pdf_creator, info, sizeof(t2p->pdf_creator) - 1);
+ t2p->pdf_creator[sizeof(t2p->pdf_creator) - 1] = '\0';
+ }
+ }
if (t2p->pdf_creator[0] != '\0') {
written += t2pWriteFile(output, (tdata_t) "/Creator ", 9);
written += t2p_write_pdf_string(t2p->pdf_creator, output);
written += t2pWriteFile(output, (tdata_t) "\n", 1);
- } else {
- if (TIFFGetField(input, TIFFTAG_SOFTWARE, &info) != 0 && info) {
- if(strlen(info) >= sizeof(t2p->pdf_creator))
- info[sizeof(t2p->pdf_creator) - 1] = '\0';
- written += t2pWriteFile(output, (tdata_t) "/Creator ", 9);
- written += t2p_write_pdf_string(info, output);
- written += t2pWriteFile(output, (tdata_t) "\n", 1);
+ }
+ if (!t2p->pdf_author_set) {
+ if ((TIFFGetField(input, TIFFTAG_ARTIST, &info) != 0
+ || TIFFGetField(input, TIFFTAG_COPYRIGHT, &info) != 0)
+ && info) {
+ strncpy(t2p->pdf_author, info, sizeof(t2p->pdf_author) - 1);
+ t2p->pdf_author[sizeof(t2p->pdf_author) - 1] = '\0';
}
}
if (t2p->pdf_author[0] != '\0') {
written += t2pWriteFile(output, (tdata_t) "/Author ", 8);
written += t2p_write_pdf_string(t2p->pdf_author, output);
written += t2pWriteFile(output, (tdata_t) "\n", 1);
- } else {
- if ((TIFFGetField(input, TIFFTAG_ARTIST, &info) != 0
- || TIFFGetField(input, TIFFTAG_COPYRIGHT, &info) != 0)
- && info) {
- if (strlen(info) >= sizeof(t2p->pdf_author))
- info[sizeof(t2p->pdf_author) - 1] = '\0';
- written += t2pWriteFile(output, (tdata_t) "/Author ", 8);
- written += t2p_write_pdf_string(info, output);
- written += t2pWriteFile(output, (tdata_t) "\n", 1);
+ }
+ if (!t2p->pdf_title_set) {
+ if (TIFFGetField(input, TIFFTAG_DOCUMENTNAME, &info) != 0 && info) {
+ strncpy(t2p->pdf_title, info, sizeof(t2p->pdf_title) - 1);
+ t2p->pdf_title[sizeof(t2p->pdf_title) - 1] = '\0';
}
}
if (t2p->pdf_title[0] != '\0') {
written += t2pWriteFile(output, (tdata_t) "/Title ", 7);
written += t2p_write_pdf_string(t2p->pdf_title, output);
written += t2pWriteFile(output, (tdata_t) "\n", 1);
- } else {
- if (TIFFGetField(input, TIFFTAG_DOCUMENTNAME, &info) != 0){
- if(strlen(info) > 511) {
- info[512] = '\0';
- }
- written += t2pWriteFile(output, (tdata_t) "/Title ", 7);
- written += t2p_write_pdf_string(info, output);
- written += t2pWriteFile(output, (tdata_t) "\n", 1);
+ }
+ if (!t2p->pdf_subject_set) {
+ if (TIFFGetField(input, TIFFTAG_IMAGEDESCRIPTION, &info) != 0 && info) {
+ strncpy(t2p->pdf_subject, info, sizeof(t2p->pdf_subject) - 1);
+ t2p->pdf_subject[sizeof(t2p->pdf_subject) - 1] = '\0';
}
}
if (t2p->pdf_subject[0] != '\0') {
written += t2pWriteFile(output, (tdata_t) "/Subject ", 9);
written += t2p_write_pdf_string(t2p->pdf_subject, output);
written += t2pWriteFile(output, (tdata_t) "\n", 1);
- } else {
- if (TIFFGetField(input, TIFFTAG_IMAGEDESCRIPTION, &info) != 0 && info) {
- if (strlen(info) >= sizeof(t2p->pdf_subject))
- info[sizeof(t2p->pdf_subject) - 1] = '\0';
- written += t2pWriteFile(output, (tdata_t) "/Subject ", 9);
- written += t2p_write_pdf_string(info, output);
- written += t2pWriteFile(output, (tdata_t) "\n", 1);
- }
}
if (t2p->pdf_keywords[0] != '\0') {
written += t2pWriteFile(output, (tdata_t) "/Keywords ", 10);
@@ -4928,8 +5019,18 @@ tsize_t t2p_write_pdf_xobject_stream_dict(ttile_t tile,
return(written);
}
+
+/* used to normalize the White Point */
+#define normalizePoint(x,y,z) do { \
+ if (y != 0.0F) { \
+ x /= y; \
+ z /= y; \
+ y = 1.0F; \
+ } \
+} while(0)
+
/*
- * This function writes a PDF Image XObject Colorspace name to output.
+ * This function writes a PDF Image XObject Colorspace name to output.
*/
@@ -4988,9 +5089,7 @@ tsize_t t2p_write_pdf_xobject_cs(T2P* t2p, TIFF* output){
X_W = t2p->tiff_whitechromaticities[0];
Y_W = t2p->tiff_whitechromaticities[1];
Z_W = 1.0F - (X_W + Y_W);
- X_W /= Y_W;
- Z_W /= Y_W;
- Y_W = 1.0F;
+ normalizePoint(X_W, Y_W, Z_W);
buflen=snprintf(buffer, sizeof(buffer), "[%.4f %.4f %.4f] \n", X_W, Y_W, Z_W);
check_snprintf_ret(t2p, buflen, buffer);
written += t2pWriteFile(output, (tdata_t) buffer, buflen);
@@ -5119,9 +5218,7 @@ tsize_t t2p_write_pdf_xobject_calcs(T2P* t2p, TIFF* output){
X_W = t2p->tiff_whitechromaticities[0];
Y_W = t2p->tiff_whitechromaticities[1];
Z_W = 1.0F - (X_W + Y_W);
- X_W /= Y_W;
- Z_W /= Y_W;
- Y_W = 1.0F;
+ normalizePoint(X_W, Y_W, Z_W);
}
if(t2p->pdf_colorspace & T2P_CS_CALRGB){
written += t2pWriteFile(output, (tdata_t) "/CalRGB ", 8);
@@ -5146,9 +5243,7 @@ tsize_t t2p_write_pdf_xobject_calcs(T2P* t2p, TIFF* output){
X_W = (X_R * R) + (X_G * G) + (X_B * B);
Y_W = (Y_R * R) + (Y_G * G) + (Y_B * B);
Z_W = (Z_R * R) + (Z_G * G) + (Z_B * B);
- X_W /= Y_W;
- Z_W /= Y_W;
- Y_W = 1.0;
+ normalizePoint(X_W, Y_W, Z_W);
}
written += t2pWriteFile(output, (tdata_t) "<< \n", 4);
if(t2p->pdf_colorspace & T2P_CS_CALGRAY){
@@ -5597,6 +5692,13 @@ tsize_t t2p_write_pdf(T2P* t2p, TIFF* input, TIFF* output){
written += t2p_write_pdf_stream_start(output);
streamlen=written;
t2p_read_tiff_size_tile(t2p, input, i2);
+ if (t2p->tiff_maxdatasize && (t2p->tiff_datasize > t2p->tiff_maxdatasize)) {
+ TIFFError(TIFF2PDF_MODULE,
+ "Allocation of " TIFF_UINT64_FORMAT " bytes is forbidden. Limit is " TIFF_UINT64_FORMAT ". Use -m option to change limit",
+ (uint64)t2p->tiff_datasize, (uint64)t2p->tiff_maxdatasize);
+ t2p->t2p_error = T2P_ERR_ERROR;
+ return (0);
+ }
written += t2p_readwrite_pdf_image_tile(t2p, input, output, i2);
t2p_write_advance_directory(t2p, output);
if(t2p->t2p_error!=T2P_ERR_OK){return(0);}
@@ -5620,6 +5722,13 @@ tsize_t t2p_write_pdf(T2P* t2p, TIFF* input, TIFF* output){
written += t2p_write_pdf_stream_start(output);
streamlen=written;
t2p_read_tiff_size(t2p, input);
+ if (t2p->tiff_maxdatasize && (t2p->tiff_datasize > t2p->tiff_maxdatasize)) {
+ TIFFError(TIFF2PDF_MODULE,
+ "Allocation of " TIFF_UINT64_FORMAT " bytes is forbidden. Limit is " TIFF_UINT64_FORMAT ". Use -m option to change limit",
+ (uint64)t2p->tiff_datasize, (uint64)t2p->tiff_maxdatasize);
+ t2p->t2p_error = T2P_ERR_ERROR;
+ return (0);
+ }
written += t2p_readwrite_pdf_image(t2p, input, output);
t2p_write_advance_directory(t2p, output);
if(t2p->t2p_error!=T2P_ERR_OK){return(0);}
diff --git a/tiff/tools/tiff2ps.c b/tiff/tools/tiff2ps.c
index 5874aba6..4ed5eba2 100644
--- a/tiff/tools/tiff2ps.c
+++ b/tiff/tools/tiff2ps.c
@@ -40,6 +40,13 @@
#include "tiffio.h"
+#ifndef EXIT_SUCCESS
+#define EXIT_SUCCESS 0
+#endif
+#ifndef EXIT_FAILURE
+#define EXIT_FAILURE 1
+#endif
+
/*
* Revision history
* 2013-Jan-21
@@ -174,6 +181,12 @@
#define FALSE 0
#endif
+#define DEFAULT_MAX_MALLOC (256 * 1024 * 1024)
+
+/* malloc size limit (in bytes)
+ * disabled when set to 0 */
+static tmsize_t maxMalloc = DEFAULT_MAX_MALLOC;
+
int ascii85 = FALSE; /* use ASCII85 encoding */
int interpolate = TRUE; /* interpolate level2 image */
int level2 = FALSE; /* generate PostScript level 2 */
@@ -234,6 +247,20 @@ tsize_t Ascii85EncodeBlock( uint8 * ascii85_p, unsigned f_eod, const uint8 * raw
static void usage(int);
+/**
+ * This custom malloc function enforce a maximum allocation size
+ */
+static void* limitMalloc(tmsize_t s)
+{
+ if (maxMalloc && (s > maxMalloc)) {
+ fprintf(stderr, "MemoryLimitError: allocation of " TIFF_UINT64_FORMAT " bytes is forbidden. Limit is " TIFF_UINT64_FORMAT ".\n",
+ (uint64)s, (uint64)maxMalloc);
+ fprintf(stderr, " use -M option to change limit.\n");
+ return NULL;
+ }
+ return _TIFFmalloc(s);
+}
+
int
main(int argc, char* argv[])
{
@@ -252,8 +279,11 @@ main(int argc, char* argv[])
pageOrientation[0] = '\0';
- while ((c = getopt(argc, argv, "b:d:h:H:W:L:i:w:l:o:O:P:C:r:t:acemxyzps1238DT")) != -1)
+ while ((c = getopt(argc, argv, "b:d:h:H:W:L:M:i:w:l:o:O:P:C:r:t:acemxyzps1238DT")) != -1)
switch (c) {
+ case 'M':
+ maxMalloc = (tmsize_t)strtoul(optarg, NULL, 0) << 20;
+ break;
case 'b':
bottommargin = atof(optarg);
break;
@@ -309,7 +339,7 @@ main(int argc, char* argv[])
case '9': diroff = (uint32) strtoul(optarg, NULL, 0);
break;
default: TIFFError ("-o", "Offset must be a numeric value.");
- exit (1);
+ exit (EXIT_FAILURE);
}
break;
case 'O': /* XXX too bad -o is already taken */
@@ -318,21 +348,21 @@ main(int argc, char* argv[])
fprintf(stderr,
"%s: %s: Cannot open output file.\n",
argv[0], optarg);
- exit(-2);
+ exit (EXIT_FAILURE);
}
break;
case 'P':
- switch (optarg[0])
- {
- case 'l':
- case 'L': strcpy (pageOrientation, "Landscape");
- break;
- case 'p':
- case 'P': strcpy (pageOrientation, "Portrait");
- break;
- default: TIFFError ("-P", "Page orientation must be Landscape or Portrait");
- exit (-1);
- }
+ switch (optarg[0])
+ {
+ case 'l':
+ case 'L': strcpy (pageOrientation, "Landscape");
+ break;
+ case 'p':
+ case 'P': strcpy (pageOrientation, "Portrait");
+ break;
+ default: TIFFError ("-P", "Page orientation must be Landscape or Portrait");
+ exit (EXIT_FAILURE);
+ }
break;
case 'l':
leftmargin = atof(optarg);
@@ -363,7 +393,7 @@ main(int argc, char* argv[])
break;
default:
fprintf (stderr, "Rotation angle must be 90, 180, 270 (degrees ccw) or auto\n");
- exit (-1);
+ exit (EXIT_FAILURE);
}
break;
case 's':
@@ -401,7 +431,7 @@ main(int argc, char* argv[])
res_unit = RESUNIT_INCH;
break;
case '?':
- usage(-1);
+ usage(EXIT_FAILURE);
}
if (useImagemask == TRUE)
@@ -409,14 +439,14 @@ main(int argc, char* argv[])
if ((level2 == FALSE) && (level3 == FALSE))
{
TIFFError ("-m "," imagemask operator requres Postscript Level2 or Level3");
- exit (1);
+ exit (EXIT_FAILURE);
}
}
if (pageWidth && (maxPageWidth > pageWidth))
{
TIFFError ("-W", "Max viewport width cannot exceed page width");
- exit (1);
+ exit (EXIT_FAILURE);
}
/* auto rotate requires a specified page width and height */
@@ -429,13 +459,13 @@ main(int argc, char* argv[])
if ((maxPageWidth > 0) || (maxPageHeight > 0))
{
TIFFError ("-r auto", " is incompatible with maximum page width/height specified by -H or -W");
- exit (1);
+ exit (EXIT_FAILURE);
}
}
if ((maxPageWidth > 0) && (maxPageHeight > 0))
{
TIFFError ("-H and -W", " Use only one of -H or -W to define a viewport");
- exit (1);
+ exit (EXIT_FAILURE);
}
if ((generateEPSF == TRUE) && (printAll == TRUE))
@@ -466,13 +496,13 @@ main(int argc, char* argv[])
&& !TIFFSetDirectory(tif, (tdir_t)dirnum))
{
TIFFClose(tif);
- return (-1);
+ return (EXIT_FAILURE);
}
else if (diroff != 0 &&
!TIFFSetSubDirectory(tif, diroff))
{
TIFFClose(tif);
- return (-1);
+ return (EXIT_FAILURE);
}
np = TIFF2PS(output, tif, pageWidth, pageHeight,
leftmargin, bottommargin, centered);
@@ -486,10 +516,10 @@ main(int argc, char* argv[])
if (np)
PSTail(output, np);
else
- usage(-1);
+ usage(EXIT_FAILURE);
if (output != stdout)
fclose(output);
- return (0);
+ return (EXIT_SUCCESS);
}
static uint16 samplesperpixel;
@@ -2187,7 +2217,7 @@ PS_Lvl2page(FILE* fd, TIFF* tif, uint32 w, uint32 h)
else
chunk_size = TIFFStripSize(tif);
}
- buf_data = (unsigned char *)_TIFFmalloc(chunk_size);
+ buf_data = (unsigned char *)limitMalloc(chunk_size);
if (!buf_data) {
TIFFError(filename, "Can't alloc %lu bytes for %s.",
(unsigned long) chunk_size, tiled_image ? "tiles" : "strips");
@@ -2205,7 +2235,7 @@ PS_Lvl2page(FILE* fd, TIFF* tif, uint32 w, uint32 h)
* 5*chunk_size/4.
*/
- ascii85_p = _TIFFmalloc( (chunk_size+(chunk_size/2)) + 8 );
+ ascii85_p = limitMalloc( (chunk_size+(chunk_size/2)) + 8 );
if ( !ascii85_p ) {
_TIFFfree( buf_data );
@@ -2449,7 +2479,7 @@ PSDataColorContig(FILE* fd, TIFF* tif, uint32 w, uint32 h, int nc)
TIFFError(filename, "Inconsistent value of es: %d (samplesperpixel=%u, nc=%d)", es, samplesperpixel, nc);
return;
}
- tf_buf = (unsigned char *) _TIFFmalloc(tf_bytesperrow);
+ tf_buf = (unsigned char *) limitMalloc(tf_bytesperrow);
if (tf_buf == NULL) {
TIFFError(filename, "No space for scanline buffer");
return;
@@ -2467,8 +2497,10 @@ PSDataColorContig(FILE* fd, TIFF* tif, uint32 w, uint32 h, int nc)
}
if (alpha) {
int adjust;
- cc = 0;
- for (; (cc + nc) <= tf_bytesperrow; cc += samplesperpixel) {
+ /*
+ * the code inside this loop reads nc bytes + 1 extra byte (for adjust)
+ */
+ for (cc = 0; (cc + nc) < tf_bytesperrow; cc += samplesperpixel) {
DOBREAK(breaklen, nc, fd);
/*
* For images with alpha, matte against
@@ -2486,8 +2518,10 @@ PSDataColorContig(FILE* fd, TIFF* tif, uint32 w, uint32 h, int nc)
cp += es;
}
} else {
- cc = 0;
- for (; (cc + nc) <= tf_bytesperrow; cc += samplesperpixel) {
+ /*
+ * the code inside this loop reads nc bytes per iteration
+ */
+ for (cc = 0; (cc + nc) <= tf_bytesperrow; cc += samplesperpixel) {
DOBREAK(breaklen, nc, fd);
switch (nc) {
case 4: c = *cp++; PUTHEX(c,fd);
@@ -2513,7 +2547,7 @@ PSDataColorSeparate(FILE* fd, TIFF* tif, uint32 w, uint32 h, int nc)
unsigned char *cp, c;
(void) w;
- tf_buf = (unsigned char *) _TIFFmalloc(tf_bytesperrow);
+ tf_buf = (unsigned char *) limitMalloc(tf_bytesperrow);
if (tf_buf == NULL) {
TIFFError(filename, "No space for scanline buffer");
return;
@@ -2559,7 +2593,7 @@ PSDataPalette(FILE* fd, TIFF* tif, uint32 w, uint32 h)
return;
}
nc = 3 * (8 / bitspersample);
- tf_buf = (unsigned char *) _TIFFmalloc(tf_bytesperrow);
+ tf_buf = (unsigned char *) limitMalloc(tf_bytesperrow);
if (tf_buf == NULL) {
TIFFError(filename, "No space for scanline buffer");
return;
@@ -2624,7 +2658,7 @@ PSDataBW(FILE* fd, TIFF* tif, uint32 w, uint32 h)
#endif
(void) w; (void) h;
- tf_buf = (unsigned char *) _TIFFmalloc(stripsize);
+ tf_buf = (unsigned char *) limitMalloc(stripsize);
if (tf_buf == NULL) {
TIFFError(filename, "No space for scanline buffer");
return;
@@ -2644,7 +2678,7 @@ PSDataBW(FILE* fd, TIFF* tif, uint32 w, uint32 h)
* 5*stripsize/4.
*/
- ascii85_p = _TIFFmalloc( (stripsize+(stripsize/2)) + 8 );
+ ascii85_p = limitMalloc( (stripsize+(stripsize/2)) + 8 );
if ( !ascii85_p ) {
_TIFFfree( tf_buf );
@@ -2681,7 +2715,7 @@ PSDataBW(FILE* fd, TIFF* tif, uint32 w, uint32 h)
#if defined( EXP_ASCII85ENCODER )
if (alpha) {
int adjust, i;
- for (i = 0; i < cc; i+=2) {
+ for (i = 0; i < (cc - 1); i+=2) {
adjust = 255 - cp[i + 1];
cp[i / 2] = cp[i] + adjust;
}
@@ -2771,7 +2805,7 @@ PSRawDataBW(FILE* fd, TIFF* tif, uint32 w, uint32 h)
bufsize = (uint32) bc[s];
}
- tf_buf = (unsigned char*) _TIFFmalloc(bufsize);
+ tf_buf = (unsigned char*) limitMalloc(bufsize);
if (tf_buf == NULL) {
TIFFError(filename, "No space for strip buffer");
return;
@@ -2788,7 +2822,7 @@ PSRawDataBW(FILE* fd, TIFF* tif, uint32 w, uint32 h)
* 5*bufsize/4.
*/
- ascii85_p = _TIFFmalloc( (bufsize+(bufsize/2)) + 8 );
+ ascii85_p = limitMalloc( (bufsize+(bufsize/2)) + 8 );
if ( !ascii85_p ) {
_TIFFfree( tf_buf );
@@ -3014,7 +3048,7 @@ tsize_t Ascii85EncodeBlock( uint8 * ascii85_p, unsigned f_eod, const uint8 * raw
tsize_t len; /* Output this many bytes */
len = raw_l + 1;
- val32 = *++raw_p << 24; /* Prime the pump */
+ val32 = (uint32)*++raw_p << 24; /* Prime the pump */
if ( --raw_l > 0 ) val32 += *(++raw_p) << 16;
if ( --raw_l > 0 ) val32 += *(++raw_p) << 8;
@@ -3053,7 +3087,7 @@ tsize_t Ascii85EncodeBlock( uint8 * ascii85_p, unsigned f_eod, const uint8 * raw
#endif /* EXP_ASCII85ENCODER */
-char* stuff[] = {
+const char* stuff[] = {
"usage: tiff2ps [options] input.tif ...",
"where options are:",
" -1 generate PostScript Level 1 (default)",
@@ -3075,6 +3109,7 @@ char* stuff[] = {
" -i # enable/disable (Nz/0) pixel interpolation (default: enable)",
" -l # set the left margin to # inches",
" -m use \"imagemask\" operator instead of \"image\"",
+" -M size set the memory allocation limit in MiB. 0 to disable limit",
" -o # convert directory at file offset # bytes",
" -O file write PostScript to file instead of standard output",
" -p generate regular (non-encapsulated) PostScript",
@@ -3092,13 +3127,12 @@ NULL
static void
usage(int code)
{
- char buf[BUFSIZ];
int i;
+ FILE * out = (code == EXIT_SUCCESS) ? stdout : stderr;
- setbuf(stderr, buf);
- fprintf(stderr, "%s\n\n", TIFFGetVersion());
+ fprintf(out, "%s\n\n", TIFFGetVersion());
for (i = 0; stuff[i] != NULL; i++)
- fprintf(stderr, "%s\n", stuff[i]);
+ fprintf(out, "%s\n", stuff[i]);
exit(code);
}
diff --git a/tiff/tools/tiff2rgba.c b/tiff/tools/tiff2rgba.c
index 2eb6f6c4..764395f6 100644
--- a/tiff/tools/tiff2rgba.c
+++ b/tiff/tools/tiff2rgba.c
@@ -39,6 +39,13 @@
#include "tiffiop.h"
#include "tiffio.h"
+#ifndef EXIT_SUCCESS
+#define EXIT_SUCCESS 0
+#endif
+#ifndef EXIT_FAILURE
+#define EXIT_FAILURE 1
+#endif
+
#define streq(a,b) (strcmp(a,b) == 0)
#define CopyField(tag, v) \
if (TIFFGetField(in, tag, &v)) TIFFSetField(out, tag, v)
@@ -53,6 +60,10 @@ uint32 rowsperstrip = (uint32) -1;
int process_by_block = 0; /* default is whole image at once */
int no_alpha = 0;
int bigtiff_output = 0;
+#define DEFAULT_MAX_MALLOC (256 * 1024 * 1024)
+/* malloc size limit (in bytes)
+ * disabled when set to 0 */
+static tmsize_t maxMalloc = DEFAULT_MAX_MALLOC;
static int tiffcvt(TIFF* in, TIFF* out);
@@ -68,8 +79,11 @@ main(int argc, char* argv[])
extern char *optarg;
#endif
- while ((c = getopt(argc, argv, "c:r:t:bn8")) != -1)
+ while ((c = getopt(argc, argv, "c:r:t:bn8hM:")) != -1)
switch (c) {
+ case 'M':
+ maxMalloc = (tmsize_t)strtoul(optarg, NULL, 0) << 20;
+ break;
case 'b':
process_by_block = 1;
break;
@@ -86,7 +100,7 @@ main(int argc, char* argv[])
else if (streq(optarg, "zip"))
compression = COMPRESSION_DEFLATE;
else
- usage(-1);
+ usage(EXIT_FAILURE);
break;
case 'r':
@@ -105,17 +119,20 @@ main(int argc, char* argv[])
bigtiff_output = 1;
break;
+ case 'h':
+ usage(EXIT_SUCCESS);
+ /*NOTREACHED*/
case '?':
- usage(0);
+ usage(EXIT_FAILURE);
/*NOTREACHED*/
}
if (argc - optind < 2)
- usage(-1);
+ usage(EXIT_FAILURE);
out = TIFFOpen(argv[argc-1], bigtiff_output?"w8":"w");
if (out == NULL)
- return (-2);
+ return (EXIT_FAILURE);
for (; optind < argc-1; optind++) {
in = TIFFOpen(argv[optind], "r");
@@ -132,7 +149,7 @@ main(int argc, char* argv[])
}
}
(void) TIFFClose(out);
- return (0);
+ return (EXIT_SUCCESS);
}
static int
@@ -166,7 +183,7 @@ cvt_by_tile( TIFF *in, TIFF *out )
if (tile_width != (rastersize / tile_height) / sizeof( uint32))
{
TIFFError(TIFFFileName(in), "Integer overflow when calculating raster buffer");
- exit(-1);
+ exit(EXIT_FAILURE);
}
raster = (uint32*)_TIFFmalloc(rastersize);
if (raster == 0) {
@@ -182,7 +199,7 @@ cvt_by_tile( TIFF *in, TIFF *out )
if (tile_width != wrk_linesize / sizeof (uint32))
{
TIFFError(TIFFFileName(in), "Integer overflow when calculating wrk_line buffer");
- exit(-1);
+ exit(EXIT_FAILURE);
}
wrk_line = (uint32*)_TIFFmalloc(wrk_linesize);
if (!wrk_line) {
@@ -279,7 +296,7 @@ cvt_by_strip( TIFF *in, TIFF *out )
if (width != (rastersize / rowsperstrip) / sizeof( uint32))
{
TIFFError(TIFFFileName(in), "Integer overflow when calculating raster buffer");
- exit(-1);
+ exit(EXIT_FAILURE);
}
raster = (uint32*)_TIFFmalloc(rastersize);
if (raster == 0) {
@@ -295,7 +312,7 @@ cvt_by_strip( TIFF *in, TIFF *out )
if (width != wrk_linesize / sizeof (uint32))
{
TIFFError(TIFFFileName(in), "Integer overflow when calculating wrk_line buffer");
- exit(-1);
+ exit(EXIT_FAILURE);
}
wrk_line = (uint32*)_TIFFmalloc(wrk_linesize);
if (!wrk_line) {
@@ -395,6 +412,12 @@ cvt_whole_image( TIFF *in, TIFF *out )
(unsigned long)width, (unsigned long)height);
return 0;
}
+ if (maxMalloc != 0 && (tmsize_t)pixel_count * (tmsize_t)sizeof(uint32) > maxMalloc) {
+ TIFFError(TIFFFileName(in),
+ "Raster size " TIFF_UINT64_FORMAT " over memory limit (" TIFF_UINT64_FORMAT "), try -b option.",
+ (uint64)pixel_count * sizeof(uint32), (uint64)maxMalloc);
+ return 0;
+ }
rowsperstrip = TIFFDefaultStripSize(out, rowsperstrip);
TIFFSetField(out, TIFFTAG_ROWSPERSTRIP, rowsperstrip);
@@ -520,6 +543,13 @@ tiffcvt(TIFF* in, TIFF* out)
TIFFSetField(out, TIFFTAG_SOFTWARE, TIFFGetVersion());
CopyField(TIFFTAG_DOCUMENTNAME, stringv);
+ if (maxMalloc != 0 && TIFFStripSize(in) > maxMalloc)
+ {
+ TIFFError(TIFFFileName(in),
+ "Strip Size " TIFF_UINT64_FORMAT " over memory limit (" TIFF_UINT64_FORMAT ")",
+ (uint64)TIFFStripSize(in), (uint64)maxMalloc);
+ return 0;
+ }
if( process_by_block && TIFFIsTiled( in ) )
return( cvt_by_tile( in, out ) );
else if( process_by_block )
@@ -528,8 +558,8 @@ tiffcvt(TIFF* in, TIFF* out)
return( cvt_whole_image( in, out ) );
}
-static char* stuff[] = {
- "usage: tiff2rgba [-c comp] [-r rows] [-b] [-n] [-8] input... output",
+static const char* stuff[] = {
+ "usage: tiff2rgba [-c comp] [-r rows] [-b] [-n] [-8] [-M size] input... output",
"where comp is one of the following compression algorithms:",
" jpeg\t\tJPEG encoding",
" zip\t\tZip/Deflate encoding",
@@ -541,19 +571,19 @@ static char* stuff[] = {
" -b (progress by block rather than as a whole image)",
" -n don't emit alpha component.",
" -8 write BigTIFF file instead of ClassicTIFF",
+ " -M set the memory allocation limit in MiB. 0 to disable limit",
NULL
};
static void
usage(int code)
{
- char buf[BUFSIZ];
int i;
+ FILE * out = (code == EXIT_SUCCESS) ? stdout : stderr;
- setbuf(stderr, buf);
- fprintf(stderr, "%s\n\n", TIFFGetVersion());
+ fprintf(out, "%s\n\n", TIFFGetVersion());
for (i = 0; stuff[i] != NULL; i++)
- fprintf(stderr, "%s\n", stuff[i]);
+ fprintf(out, "%s\n", stuff[i]);
exit(code);
}
diff --git a/tiff/tools/tiffcmp.c b/tiff/tools/tiffcmp.c
index 7b764883..041d6a2d 100644
--- a/tiff/tools/tiffcmp.c
+++ b/tiff/tools/tiffcmp.c
@@ -39,6 +39,13 @@
#include "tiffio.h"
+#ifndef EXIT_SUCCESS
+#define EXIT_SUCCESS 0
+#endif
+#ifndef EXIT_FAILURE
+#define EXIT_FAILURE 1
+#endif
+
#ifndef HAVE_GETOPT
extern int getopt(int argc, char * const argv[], const char *optstring);
#endif
@@ -51,7 +58,7 @@ static uint16 sampleformat = SAMPLEFORMAT_UINT;
static uint32 imagewidth;
static uint32 imagelength;
-static void usage(void);
+static void usage(int code);
static int tiffcmp(TIFF*, TIFF*);
static int cmptags(TIFF*, TIFF*);
static int ContigCompare(int, uint32, unsigned char*, unsigned char*, tsize_t);
@@ -61,6 +68,12 @@ static void PrintFloatDiff(uint32, int, uint32, double, double);
static void leof(const char*, uint32, int);
+/*
+ * exit with status :
+ * 0 No differences were found.
+ * 1 Differences were found.
+ * >1 An error occurred.
+ */
int
main(int argc, char* argv[])
{
@@ -71,7 +84,7 @@ main(int argc, char* argv[])
extern char* optarg;
#endif
- while ((c = getopt(argc, argv, "ltz:")) != -1)
+ while ((c = getopt(argc, argv, "ltz:h")) != -1)
switch (c) {
case 'l':
stopondiff = 0;
@@ -82,18 +95,20 @@ main(int argc, char* argv[])
case 't':
stoponfirsttag = 0;
break;
+ case 'h':
+ usage(EXIT_SUCCESS);
case '?':
- usage();
+ usage(2);
/*NOTREACHED*/
}
if (argc - optind < 2)
- usage();
+ usage(2);
tif1 = TIFFOpen(argv[optind], "r");
if (tif1 == NULL)
- return (-1);
+ return (2);
tif2 = TIFFOpen(argv[optind+1], "r");
if (tif2 == NULL)
- return (-2);
+ return (2);
dirnum = 0;
while (tiffcmp(tif1, tif2)) {
if (!TIFFReadDirectory(tif1)) {
@@ -115,7 +130,7 @@ main(int argc, char* argv[])
return (0);
}
-char* stuff[] = {
+static const char* stuff[] = {
"usage: tiffcmp [options] file1 file2",
"where options are:",
" -l list each byte of image data that differs between the files",
@@ -125,16 +140,15 @@ NULL
};
static void
-usage(void)
+usage(int code)
{
- char buf[BUFSIZ];
int i;
+ FILE * out = (code == EXIT_SUCCESS) ? stdout : stderr;
- setbuf(stderr, buf);
- fprintf(stderr, "%s\n\n", TIFFGetVersion());
+ fprintf(out, "%s\n\n", TIFFGetVersion());
for (i = 0; stuff[i] != NULL; i++)
- fprintf(stderr, "%s\n", stuff[i]);
- exit(-1);
+ fprintf(out, "%s\n", stuff[i]);
+ exit(code);
}
#define checkEOF(tif, row, sample) { \
@@ -177,7 +191,7 @@ tiffcmp(TIFF* tif1, TIFF* tif2)
buf2 = (unsigned char *)_TIFFmalloc(TIFFScanlineSize(tif2));
if (buf1 == NULL || buf2 == NULL) {
fprintf(stderr, "No space for scanline buffers\n");
- exit(-1);
+ exit(2);
}
if (config1 != config2 && bitspersample != 8 && samplesperpixel > 1) {
fprintf(stderr,
diff --git a/tiff/tools/tiffcp.c b/tiff/tools/tiffcp.c
index 84d81488..e56b1c10 100644
--- a/tiff/tools/tiffcp.c
+++ b/tiff/tools/tiffcp.c
@@ -51,6 +51,13 @@
#include "tiffio.h"
+#ifndef EXIT_SUCCESS
+#define EXIT_SUCCESS 0
+#endif
+#ifndef EXIT_FAILURE
+#define EXIT_FAILURE 1
+#endif
+
#ifndef HAVE_GETOPT
extern int getopt(int argc, char * const argv[], const char *optstring);
#endif
@@ -65,6 +72,12 @@ extern int getopt(int argc, char * const argv[], const char *optstring);
#define TRUE 1
#define FALSE 0
+#define DEFAULT_MAX_MALLOC (256 * 1024 * 1024)
+
+/* malloc size limit (in bytes)
+ * disabled when set to 0 */
+static tmsize_t maxMalloc = DEFAULT_MAX_MALLOC;
+
static int outtiled = -1;
static uint32 tilewidth;
static uint32 tilelength;
@@ -84,16 +97,31 @@ static int jpegcolormode = JPEGCOLORMODE_RGB;
static uint16 defcompression = (uint16) -1;
static uint16 defpredictor = (uint16) -1;
static int defpreset = -1;
+static int subcodec = -1;
static int tiffcp(TIFF*, TIFF*);
static int processCompressOptions(char*);
-static void usage(void);
+static void usage(int code);
static char comma = ','; /* (default) comma separator character */
static TIFF* bias = NULL;
static int pageNum = 0;
static int pageInSeq = 0;
+/**
+ * This custom malloc function enforce a maximum allocation size
+ */
+static void* limitMalloc(tmsize_t s)
+{
+ if (maxMalloc && (s > maxMalloc)) {
+ fprintf(stderr, "MemoryLimitError: allocation of " TIFF_UINT64_FORMAT " bytes is forbidden. Limit is " TIFF_UINT64_FORMAT ".\n",
+ (uint64)s, (uint64)maxMalloc);
+ fprintf(stderr, " use -m option to change limit.\n");
+ return NULL;
+ }
+ return _TIFFmalloc(s);
+}
+
static int nextSrcImage (TIFF *tif, char **imageSpec)
/*
seek to the next image specified in *imageSpec
@@ -114,7 +142,7 @@ static int nextSrcImage (TIFF *tif, char **imageSpec)
fprintf (stderr,
"Expected a %c separated image # list after %s\n",
comma, TIFFFileName (tif));
- exit (-4); /* syntax error */
+ exit (EXIT_FAILURE); /* syntax error */
}
}
if (TIFFSetDirectory (tif, nextImage)) return 1;
@@ -132,12 +160,14 @@ static TIFF* openSrcImage (char **imageSpec)
no images specified, or a pointer to the next image number text
*/
{
+ /* disable strip shopping when using jbig compression */
+ const char *mode = (defcompression == COMPRESSION_JBIG) ? "rc" : "r";
TIFF *tif;
char *fn = *imageSpec;
*imageSpec = strchr (fn, comma);
if (*imageSpec) { /* there is at least one image number specifier */
**imageSpec = '\0';
- tif = TIFFOpen (fn, "r");
+ tif = TIFFOpen (fn, mode);
/* but, ignore any single trailing comma */
if (!(*imageSpec)[1]) {*imageSpec = NULL; return tif;}
if (tif) {
@@ -148,7 +178,7 @@ static TIFF* openSrcImage (char **imageSpec)
}
}
}else
- tif = TIFFOpen (fn, "r");
+ tif = TIFFOpen (fn, mode);
return tif;
}
@@ -173,30 +203,33 @@ main(int argc, char* argv[])
*mp++ = 'w';
*mp = '\0';
- while ((c = getopt(argc, argv, ",:b:c:f:l:o:p:r:w:aistBLMC8x")) != -1)
+ while ((c = getopt(argc, argv, "m:,:b:c:f:l:o:p:r:w:aistBLMC8xh")) != -1)
switch (c) {
+ case 'm':
+ maxMalloc = (tmsize_t)strtoul(optarg, NULL, 0) << 20;
+ break;
case ',':
- if (optarg[0] != '=') usage();
+ if (optarg[0] != '=') usage(EXIT_FAILURE);
comma = optarg[1];
break;
case 'b': /* this file is bias image subtracted from others */
if (bias) {
fputs ("Only 1 bias image may be specified\n", stderr);
- exit (-2);
+ exit (EXIT_FAILURE);
}
{
uint16 samples = (uint16) -1;
char **biasFn = &optarg;
bias = openSrcImage (biasFn);
- if (!bias) exit (-5);
+ if (!bias) exit (EXIT_FAILURE);
if (TIFFIsTiled (bias)) {
fputs ("Bias image must be organized in strips\n", stderr);
- exit (-7);
+ exit (EXIT_FAILURE);
}
TIFFGetField(bias, TIFFTAG_SAMPLESPERPIXEL, &samples);
if (samples != 1) {
fputs ("Bias image must be monochrome\n", stderr);
- exit (-7);
+ exit (EXIT_FAILURE);
}
}
break;
@@ -205,7 +238,7 @@ main(int argc, char* argv[])
break;
case 'c': /* compression scheme */
if (!processCompressOptions(optarg))
- usage();
+ usage(EXIT_FAILURE);
break;
case 'f': /* fill order */
if (streq(optarg, "lsb2msb"))
@@ -213,7 +246,7 @@ main(int argc, char* argv[])
else if (streq(optarg, "msb2lsb"))
deffillorder = FILLORDER_MSB2LSB;
else
- usage();
+ usage(EXIT_FAILURE);
break;
case 'i': /* ignore errors */
ignore = TRUE;
@@ -231,7 +264,7 @@ main(int argc, char* argv[])
else if (streq(optarg, "contig"))
defconfig = PLANARCONFIG_CONTIG;
else
- usage();
+ usage(EXIT_FAILURE);
break;
case 'r': /* rows/strip */
defrowsperstrip = atol(optarg);
@@ -264,15 +297,18 @@ main(int argc, char* argv[])
case 'x':
pageInSeq = 1;
break;
+ case 'h':
+ usage(EXIT_SUCCESS);
+ /*NOTREACHED*/
case '?':
- usage();
+ usage(EXIT_FAILURE);
/*NOTREACHED*/
}
if (argc - optind < 2)
- usage();
+ usage(EXIT_FAILURE);
out = TIFFOpen(argv[argc-1], mode);
if (out == NULL)
- return (-2);
+ return (EXIT_FAILURE);
if ((argc - optind) == 2)
pageNum = -1;
for (; optind < argc-1 ; optind++) {
@@ -280,14 +316,14 @@ main(int argc, char* argv[])
in = openSrcImage (&imageCursor);
if (in == NULL) {
(void) TIFFClose(out);
- return (-3);
+ return (EXIT_FAILURE);
}
if (diroff != 0 && !TIFFSetSubDirectory(in, diroff)) {
TIFFError(TIFFFileName(in),
"Error, setting subdirectory at " TIFF_UINT64_FORMAT, diroff);
(void) TIFFClose(in);
(void) TIFFClose(out);
- return (1);
+ return (EXIT_FAILURE);
}
for (;;) {
config = defconfig;
@@ -302,7 +338,7 @@ main(int argc, char* argv[])
if (!tiffcp(in, out) || !TIFFWriteDirectory(out)) {
(void) TIFFClose(in);
(void) TIFFClose(out);
- return (1);
+ return (EXIT_FAILURE);
}
if (imageCursor) { /* seek next image directory */
if (!nextSrcImage(in, &imageCursor)) break;
@@ -313,7 +349,7 @@ main(int argc, char* argv[])
}
(void) TIFFClose(out);
- return (0);
+ return (EXIT_SUCCESS);
}
static void
@@ -326,8 +362,10 @@ processZIPOptions(char* cp)
defpredictor = atoi(cp);
else if (*cp == 'p')
defpreset = atoi(++cp);
+ else if (*cp == 's')
+ subcodec = atoi(++cp);
else
- usage();
+ usage(EXIT_FAILURE);
} while( (cp = strchr(cp, ':')) );
}
}
@@ -347,7 +385,7 @@ processG3Options(char* cp)
else if (strneq(cp, "fill", 4))
defg3opts |= GROUP3OPT_FILLBITS;
else
- usage();
+ usage(EXIT_FAILURE);
} while( (cp = strchr(cp, ':')) );
}
}
@@ -370,7 +408,7 @@ processCompressOptions(char* opt)
else if (cp[1] == 'r' )
jpegcolormode = JPEGCOLORMODE_RAW;
else
- usage();
+ usage(EXIT_FAILURE);
cp = strchr(cp+1,':');
}
@@ -405,7 +443,7 @@ processCompressOptions(char* opt)
return (1);
}
-char* stuff[] = {
+static const char* stuff[] = {
"usage: tiffcp [options] input... output",
"where options are:",
" -a append to output instead of overwriting",
@@ -423,6 +461,7 @@ char* stuff[] = {
" -i ignore read errors",
" -b file[,#] bias (dark) monochrome image to be subtracted from all others",
" -,=% use % rather than , to separate image #'s (per Note below)",
+" -m size set maximum memory allocation size (MiB). 0 to disable limit.",
"",
" -r # make each strip have no more than # rows",
" -w # set output tile width (pixels)",
@@ -458,6 +497,9 @@ char* stuff[] = {
"LZW, Deflate (ZIP), LZMA2, ZSTD and WEBP options:",
" # set predictor value",
" p# set compression level (preset)",
+#if LIBDEFLATE_SUPPORT
+" s# set subcodec (0=zlib, 1=libdeflate) (only for Deflate/ZIP)",
+#endif
"For example, -c lzw:2 to get LZW-encoded data with horizontal differencing,",
"-c zip:3:p9 for Deflate encoding with maximum compression level and floating",
"point predictor.",
@@ -470,16 +512,15 @@ NULL
};
static void
-usage(void)
+usage(int code)
{
- char buf[BUFSIZ];
int i;
+ FILE * out = (code == EXIT_SUCCESS) ? stdout : stderr;
- setbuf(stderr, buf);
- fprintf(stderr, "%s\n\n", TIFFGetVersion());
+ fprintf(out, "%s\n\n", TIFFGetVersion());
for (i = 0; stuff[i] != NULL; i++)
- fprintf(stderr, "%s\n", stuff[i]);
- exit(-1);
+ fprintf(out, "%s\n", stuff[i]);
+ exit(code);
}
#define CopyField(tag, v) \
@@ -741,11 +782,23 @@ tiffcp(TIFF* in, TIFF* out)
case COMPRESSION_DEFLATE:
case COMPRESSION_LZMA:
case COMPRESSION_ZSTD:
- case COMPRESSION_WEBP:
if (predictor != (uint16)-1)
TIFFSetField(out, TIFFTAG_PREDICTOR, predictor);
else
CopyField(TIFFTAG_PREDICTOR, predictor);
+ if( compression == COMPRESSION_ADOBE_DEFLATE ||
+ compression == COMPRESSION_DEFLATE )
+ {
+ if( subcodec != -1 )
+ {
+ if( TIFFSetField(out, TIFFTAG_DEFLATE_SUBCODEC, subcodec) != 1 )
+ {
+ return FALSE;
+ }
+ }
+ }
+ /*fallthrough*/
+ case COMPRESSION_WEBP:
if (preset != -1) {
if (compression == COMPRESSION_ADOBE_DEFLATE
|| compression == COMPRESSION_DEFLATE)
@@ -858,7 +911,7 @@ DECLAREcpFunc(cpContig2ContigByRow)
tdata_t buf;
uint32 row;
- buf = _TIFFmalloc(scanlinesize);
+ buf = limitMalloc(scanlinesize);
if (!buf)
return 0;
_TIFFmemset(buf, 0, scanlinesize);
@@ -932,8 +985,8 @@ DECLAREcpFunc(cpBiasedContig2Contig)
subtractLine = lineSubtractFn (sampleBits);
if (subtractLine) {
uint32 row;
- buf = _TIFFmalloc(bufSize);
- biasBuf = _TIFFmalloc(bufSize);
+ buf = limitMalloc(bufSize);
+ biasBuf = limitMalloc(bufSize);
for (row = 0; row < imagelength; row++) {
if (TIFFReadScanline(in, buf, row, 0) < 0
&& !ignore) {
@@ -995,7 +1048,7 @@ bad:
DECLAREcpFunc(cpDecodedStrips)
{
tsize_t stripsize = TIFFStripSize(in);
- tdata_t buf = _TIFFmalloc(stripsize);
+ tdata_t buf = limitMalloc(stripsize);
(void) imagewidth; (void) spp;
if (buf) {
@@ -1045,7 +1098,7 @@ DECLAREcpFunc(cpSeparate2SeparateByRow)
tsample_t s;
(void) imagewidth;
- buf = _TIFFmalloc(scanlinesize);
+ buf = limitMalloc(scanlinesize);
if (!buf)
return 0;
_TIFFmemset(buf, 0, scanlinesize);
@@ -1096,8 +1149,8 @@ DECLAREcpFunc(cpContig2SeparateByRow)
return 0;
}
- inbuf = _TIFFmalloc(scanlinesizein);
- outbuf = _TIFFmalloc(scanlinesizeout);
+ inbuf = limitMalloc(scanlinesizein);
+ outbuf = limitMalloc(scanlinesizeout);
if (!inbuf || !outbuf)
goto bad;
_TIFFmemset(inbuf, 0, scanlinesizein);
@@ -1159,8 +1212,8 @@ DECLAREcpFunc(cpSeparate2ContigByRow)
return 0;
}
- inbuf = _TIFFmalloc(scanlinesizein);
- outbuf = _TIFFmalloc(scanlinesizeout);
+ inbuf = limitMalloc(scanlinesizein);
+ outbuf = limitMalloc(scanlinesizeout);
if (!inbuf || !outbuf)
goto bad;
_TIFFmemset(inbuf, 0, scanlinesizein);
@@ -1266,7 +1319,7 @@ cpImage(TIFF* in, TIFF* out, readFunc fin, writeFunc fout,
if (scanlinesize
&& imagelength
&& bytes / (tsize_t)imagelength == scanlinesize) {
- buf = _TIFFmalloc(bytes);
+ buf = limitMalloc(bytes);
if (buf) {
if ((*fin)(in, (uint8*)buf, imagelength,
imagewidth, spp)) {
@@ -1314,7 +1367,7 @@ DECLAREreadFunc(readSeparateStripsIntoBuffer)
if (!scanlinesize)
return 0;
- scanline = _TIFFmalloc(scanlinesize);
+ scanline = limitMalloc(scanlinesize);
if (!scanline)
return 0;
_TIFFmemset(scanline, 0, scanlinesize);
@@ -1363,7 +1416,7 @@ DECLAREreadFunc(readContigTilesIntoBuffer)
uint32 row;
(void) spp;
- tilebuf = _TIFFmalloc(tilesize);
+ tilebuf = limitMalloc(tilesize);
if (tilebuf == 0)
return 0;
_TIFFmemset(tilebuf, 0, tilesize);
@@ -1417,13 +1470,13 @@ DECLAREreadFunc(readSeparateTilesIntoBuffer)
uint32 row;
uint16 bps = 0, bytes_per_sample;
- if (spp > (INT_MAX / tilew))
+ if (tilew && spp > (INT_MAX / tilew))
{
TIFFError(TIFFFileName(in), "Error, cannot handle that much samples per tile row (Tile Width * Samples/Pixel)");
return 0;
}
iskew = imagew - tilew*spp;
- tilebuf = _TIFFmalloc(tilesize);
+ tilebuf = limitMalloc(tilesize);
if (tilebuf == 0)
return 0;
_TIFFmemset(tilebuf, 0, tilesize);
@@ -1524,7 +1577,7 @@ DECLAREwriteFunc(writeBufferToSeparateStrips)
tstrip_t strip = 0;
tsample_t s;
- obuf = _TIFFmalloc(stripsize);
+ obuf = limitMalloc(stripsize);
if (obuf == NULL)
return (0);
_TIFFmemset(obuf, 0, stripsize);
@@ -1566,7 +1619,7 @@ DECLAREwriteFunc(writeBufferToContigTiles)
(void) spp;
- obuf = _TIFFmalloc(TIFFTileSize(out));
+ obuf = limitMalloc(TIFFTileSize(out));
if (obuf == NULL)
return 0;
_TIFFmemset(obuf, 0, tilesize);
@@ -1619,7 +1672,7 @@ DECLAREwriteFunc(writeBufferToSeparateTiles)
uint32 row;
uint16 bps = 0, bytes_per_sample;
- obuf = _TIFFmalloc(TIFFTileSize(out));
+ obuf = limitMalloc(TIFFTileSize(out));
if (obuf == NULL)
return 0;
_TIFFmemset(obuf, 0, tilesize);
diff --git a/tiff/tools/tiffcrop.c b/tiff/tools/tiffcrop.c
index 7b3c9e78..d20b585a 100644
--- a/tiff/tools/tiffcrop.c
+++ b/tiff/tools/tiffcrop.c
@@ -128,6 +128,13 @@ static char tiffcrop_rev_date[] = "12-13-2010";
# include <stdint.h>
#endif
+#ifndef EXIT_SUCCESS
+#define EXIT_SUCCESS 0
+#endif
+#ifndef EXIT_FAILURE
+#define EXIT_FAILURE 1
+#endif
+
#ifndef HAVE_GETOPT
extern int getopt(int argc, char * const argv[], const char *optstring);
#endif
@@ -333,7 +340,7 @@ struct paperdef {
/* European page sizes corrected from update sent by
* thomas . jarosch @ intra2net . com on 5/7/2010
* Paper Size Width Length Aspect Ratio */
-struct paperdef PaperTable[MAX_PAPERNAMES] = {
+const struct paperdef PaperTable[MAX_PAPERNAMES] = {
{"default", 8.500, 14.000, 0.607},
{"pa4", 8.264, 11.000, 0.751},
{"letter", 8.500, 11.000, 0.773},
@@ -461,7 +468,7 @@ static int writeBufferToSeparateTiles (TIFF*, uint8*, uint32, uint32, tsample
static int extractContigSamplesToBuffer (uint8 *, uint8 *, uint32, uint32, tsample_t,
uint16, uint16, struct dump_opts *);
static int processCompressOptions(char*);
-static void usage(void);
+static void usage(int code);
/* All other functions by Richard Nolde, not found in tiffcp */
static void initImageData (struct image_data *);
@@ -617,7 +624,28 @@ static int dump_buffer (FILE *, int, uint32, uint32, uint32, unsigned char *);
/* Functions derived in whole or in part from tiffcp */
/* The following functions are taken largely intact from tiffcp */
-static char* usage_info[] = {
+#define DEFAULT_MAX_MALLOC (256 * 1024 * 1024)
+
+/* malloc size limit (in bytes)
+ * disabled when set to 0 */
+static tmsize_t maxMalloc = DEFAULT_MAX_MALLOC;
+
+/**
+ * This custom malloc function enforce a maximum allocation size
+ */
+static void* limitMalloc(tmsize_t s)
+{
+ if (maxMalloc && (s > maxMalloc)) {
+ fprintf(stderr, "MemoryLimitError: allocation of " TIFF_UINT64_FORMAT " bytes is forbidden. Limit is " TIFF_UINT64_FORMAT ".\n",
+ (uint64)s, (uint64)maxMalloc);
+ fprintf(stderr, " use -k option to change limit.\n"); return NULL;
+ }
+ return _TIFFmalloc(s);
+}
+
+
+
+static const char* usage_info[] = {
"usage: tiffcrop [options] source1 ... sourceN destination",
"where options are:",
" -h Print this syntax listing",
@@ -630,6 +658,7 @@ static char* usage_info[] = {
" -s Write output in strips",
" -t Write output in tiles",
" -i Ignore read errors",
+" -k size set the memory allocation limit in MiB. 0 to disable limit",
" ",
" -r # Make each strip have no more than # rows",
" -w # Set output tile width (pixels)",
@@ -798,7 +827,7 @@ static int readContigTilesIntoBuffer (TIFF* in, uint8* buf,
if (tilesize == 0 || tile_rowsize == 0)
{
TIFFError("readContigTilesIntoBuffer", "Tile size or tile rowsize is zero");
- exit(-1);
+ exit(EXIT_FAILURE);
}
if (tilesize < (tsize_t)(tl * tile_rowsize))
@@ -812,7 +841,7 @@ static int readContigTilesIntoBuffer (TIFF* in, uint8* buf,
if (tl != (tile_buffsize / tile_rowsize))
{
TIFFError("readContigTilesIntoBuffer", "Integer overflow when calculating buffer size.");
- exit(-1);
+ exit(EXIT_FAILURE);
}
}
@@ -820,9 +849,9 @@ static int readContigTilesIntoBuffer (TIFF* in, uint8* buf,
if( (size_t) tile_buffsize > 0xFFFFFFFFU - 3U )
{
TIFFError("readContigTilesIntoBuffer", "Integer overflow when calculating buffer size.");
- exit(-1);
+ exit(EXIT_FAILURE);
}
- tilebuf = _TIFFmalloc(tile_buffsize + 3);
+ tilebuf = limitMalloc(tile_buffsize + 3);
if (tilebuf == 0)
return 0;
tilebuf[tile_buffsize] = 0;
@@ -986,7 +1015,7 @@ static int readSeparateTilesIntoBuffer (TIFF* in, uint8 *obuf,
for (sample = 0; (sample < spp) && (sample < MAX_SAMPLES); sample++)
{
srcbuffs[sample] = NULL;
- tbuff = (unsigned char *)_TIFFmalloc(tilesize + 8);
+ tbuff = (unsigned char *)limitMalloc(tilesize + 8);
if (!tbuff)
{
TIFFError ("readSeparateTilesIntoBuffer",
@@ -1181,7 +1210,7 @@ writeBufferToSeparateStrips (TIFF* out, uint8* buf,
}
rowstripsize = rowsperstrip * bytes_per_sample * (width + 1);
- obuf = _TIFFmalloc (rowstripsize);
+ obuf = limitMalloc (rowstripsize);
if (obuf == NULL)
return 1;
@@ -1246,7 +1275,7 @@ static int writeBufferToContigTiles (TIFF* out, uint8* buf, uint32 imagelength,
if (tilesize == 0 || tile_rowsize == 0 || tl == 0 || tw == 0)
{
TIFFError("writeBufferToContigTiles", "Tile size, tile row size, tile width, or tile length is zero");
- exit(-1);
+ exit(EXIT_FAILURE);
}
tile_buffsize = tilesize;
@@ -1261,7 +1290,7 @@ static int writeBufferToContigTiles (TIFF* out, uint8* buf, uint32 imagelength,
if (tl != tile_buffsize / tile_rowsize)
{
TIFFError("writeBufferToContigTiles", "Integer overflow when calculating buffer size");
- exit(-1);
+ exit(EXIT_FAILURE);
}
}
@@ -1275,7 +1304,7 @@ static int writeBufferToContigTiles (TIFF* out, uint8* buf, uint32 imagelength,
}
src_rowsize = ((imagewidth * spp * bps) + 7U) / 8;
- tilebuf = _TIFFmalloc(tile_buffsize);
+ tilebuf = limitMalloc(tile_buffsize);
if (tilebuf == 0)
return 1;
for (row = 0; row < imagelength; row += tl)
@@ -1323,7 +1352,7 @@ static int writeBufferToSeparateTiles (TIFF* out, uint8* buf, uint32 imagelength
uint32 imagewidth, tsample_t spp,
struct dump_opts * dump)
{
- tdata_t obuf = _TIFFmalloc(TIFFTileSize(out));
+ tdata_t obuf = limitMalloc(TIFFTileSize(out));
uint32 tl, tw;
uint32 row, col, nrow, ncol;
uint32 src_rowsize, col_offset;
@@ -1334,9 +1363,10 @@ static int writeBufferToSeparateTiles (TIFF* out, uint8* buf, uint32 imagelength
if (obuf == NULL)
return 1;
- TIFFGetField(out, TIFFTAG_TILELENGTH, &tl);
- TIFFGetField(out, TIFFTAG_TILEWIDTH, &tw);
- TIFFGetField(out, TIFFTAG_BITSPERSAMPLE, &bps);
+ if( !TIFFGetField(out, TIFFTAG_TILELENGTH, &tl) ||
+ !TIFFGetField(out, TIFFTAG_TILEWIDTH, &tw) ||
+ !TIFFGetField(out, TIFFTAG_BITSPERSAMPLE, &bps) )
+ return 1;
if( imagewidth == 0 ||
(uint32)bps * (uint32)spp > TIFF_UINT32_MAX / imagewidth ||
@@ -1407,7 +1437,7 @@ processG3Options(char* cp)
else if (strneq(cp, "fill", 4))
defg3opts |= GROUP3OPT_FILLBITS;
else
- usage();
+ usage(EXIT_FAILURE);
} while( (cp = strchr(cp, ':')) );
}
}
@@ -1439,7 +1469,7 @@ processCompressOptions(char* opt)
else if (strneq(cp + 1, "rgb", 3 ))
jpegcolormode = JPEGCOLORMODE_RGB;
else
- usage();
+ usage(EXIT_FAILURE);
cp = strchr(cp + 1, ':');
}
}
@@ -1473,14 +1503,15 @@ processCompressOptions(char* opt)
}
static void
-usage(void)
+usage(int code)
{
int i;
+ FILE * out = (code == EXIT_SUCCESS) ? stdout : stderr;
- fprintf(stderr, "\n%s\n", TIFFGetVersion());
+ fprintf(out, "\n%s\n", TIFFGetVersion());
for (i = 0; usage_info[i] != NULL; i++)
- fprintf(stderr, "%s\n", usage_info[i]);
- exit(-1);
+ fprintf(out, "%s\n", usage_info[i]);
+ exit(code);
}
#define CopyField(tag, v) \
@@ -1611,7 +1642,7 @@ void process_command_opts (int argc, char *argv[], char *mp, char *mode, uint32
*mp++ = 'w';
*mp = '\0';
while ((c = getopt(argc, argv,
- "ac:d:e:f:hil:m:p:r:stvw:z:BCD:E:F:H:I:J:K:LMN:O:P:R:S:U:V:X:Y:Z:")) != -1)
+ "ac:d:e:f:hik:l:m:p:r:stvw:z:BCD:E:F:H:I:J:K:LMN:O:P:R:S:U:V:X:Y:Z:")) != -1)
{
good_args++;
switch (c) {
@@ -1621,7 +1652,7 @@ void process_command_opts (int argc, char *argv[], char *mp, char *mode, uint32
{
TIFFError ("Unknown compression option", "%s", optarg);
TIFFError ("For valid options type", "tiffcrop -h");
- exit (-1);
+ exit (EXIT_FAILURE);
}
break;
case 'd': start = strtoul(optarg, NULL, 0); /* initial IFD offset */
@@ -1629,7 +1660,7 @@ void process_command_opts (int argc, char *argv[], char *mp, char *mode, uint32
{
TIFFError ("","Directory offset must be greater than zero");
TIFFError ("For valid options type", "tiffcrop -h");
- exit (-1);
+ exit (EXIT_FAILURE);
}
*dirnum = start - 1;
break;
@@ -1652,7 +1683,7 @@ void process_command_opts (int argc, char *argv[], char *mp, char *mode, uint32
break; /* Sections */
default: TIFFError ("Unknown export mode","%s", optarg);
TIFFError ("For valid options type", "tiffcrop -h");
- exit (-1);
+ exit (EXIT_FAILURE);
}
break;
case 'f': if (streq(optarg, "lsb2msb")) /* fill order */
@@ -1663,13 +1694,15 @@ void process_command_opts (int argc, char *argv[], char *mp, char *mode, uint32
{
TIFFError ("Unknown fill order", "%s", optarg);
TIFFError ("For valid options type", "tiffcrop -h");
- exit (-1);
+ exit (EXIT_FAILURE);
}
break;
- case 'h': usage();
+ case 'h': usage(EXIT_SUCCESS);
break;
case 'i': ignore = TRUE; /* ignore errors */
break;
+ case 'k': maxMalloc = (tmsize_t)strtoul(optarg, NULL, 0) << 20;
+ break;
case 'l': outtiled = TRUE; /* tile length */
*deftilelength = atoi(optarg);
break;
@@ -1682,7 +1715,7 @@ void process_command_opts (int argc, char *argv[], char *mp, char *mode, uint32
{
TIFFError ("Unknown planar configuration", "%s", optarg);
TIFFError ("For valid options type", "tiffcrop -h");
- exit (-1);
+ exit (EXIT_FAILURE);
}
break;
case 'r': /* rows/strip */
@@ -1694,13 +1727,13 @@ void process_command_opts (int argc, char *argv[], char *mp, char *mode, uint32
case 't': /* generate tiled output */
outtiled = TRUE;
break;
- case 'v': TIFFError("Library Release", "%s", TIFFGetVersion());
- TIFFError ("Tiffcrop version", "%s, last updated: %s",
+ case 'v': printf("Library Release: %s\n", TIFFGetVersion());
+ printf("Tiffcrop version: %s, last updated: %s\n",
tiffcrop_version_id, tiffcrop_rev_date);
- TIFFError ("Tiffcp code", "Copyright (c) 1988-1997 Sam Leffler");
- TIFFError (" ", "Copyright (c) 1991-1997 Silicon Graphics, Inc");
- TIFFError ("Tiffcrop additions", "Copyright (c) 2007-2010 Richard Nolde");
- exit (0);
+ printf("Tiffcp code: Copyright (c) 1988-1997 Sam Leffler\n");
+ printf(" : Copyright (c) 1991-1997 Silicon Graphics, Inc\n");
+ printf("Tiffcrop additions: Copyright (c) 2007-2010 Richard Nolde\n");
+ exit (EXIT_SUCCESS);
break;
case 'w': /* tile width */
outtiled = TRUE;
@@ -1719,7 +1752,7 @@ void process_command_opts (int argc, char *argv[], char *mp, char *mode, uint32
{
TIFFError ("Unable to parse coordinates for region", "%d %s", i, optarg);
TIFFError ("For valid options type", "tiffcrop -h");
- exit (-1);
+ exit (EXIT_FAILURE);
}
}
/* check for remaining elements over MAX_REGIONS */
@@ -1727,7 +1760,7 @@ void process_command_opts (int argc, char *argv[], char *mp, char *mode, uint32
{
TIFFError ("Region list exceeds limit of", "%d regions %s", MAX_REGIONS, optarg);
TIFFError ("For valid options type", "tiffcrop -h");
- exit (-1);;
+ exit (EXIT_FAILURE);;
}
break;
/* options for file open modes */
@@ -1749,7 +1782,7 @@ void process_command_opts (int argc, char *argv[], char *mp, char *mode, uint32
{
TIFFError("Invalid dump option", "%s", optarg);
TIFFError ("For valid options type", "tiffcrop -h");
- exit (-1);
+ exit (EXIT_FAILURE);
}
*opt_offset = '\0';
@@ -1781,7 +1814,7 @@ void process_command_opts (int argc, char *argv[], char *mp, char *mode, uint32
{
TIFFError("parse_command_opts", "Unknown dump format %s", opt_offset + 1);
TIFFError ("For valid options type", "tiffcrop -h");
- exit (-1);
+ exit (EXIT_FAILURE);
}
}
}
@@ -1813,7 +1846,7 @@ void process_command_opts (int argc, char *argv[], char *mp, char *mode, uint32
{
TIFFError("", "You must specify a dump format for dump files");
TIFFError ("For valid options type", "tiffcrop -h");
- exit (-1);
+ exit (EXIT_FAILURE);
}
}
break;
@@ -1842,7 +1875,7 @@ void process_command_opts (int argc, char *argv[], char *mp, char *mode, uint32
break;
default: TIFFError ("Edge reference must be top, bottom, left, or right", "%s", optarg);
TIFFError ("For valid options type", "tiffcrop -h");
- exit (-1);
+ exit (EXIT_FAILURE);
}
break;
case 'F': /* flip eg mirror image or cropped segment, M was already used */
@@ -1857,7 +1890,7 @@ void process_command_opts (int argc, char *argv[], char *mp, char *mode, uint32
break;
default: TIFFError ("Flip mode must be horiz, vert, or both", "%s", optarg);
TIFFError ("For valid options type", "tiffcrop -h");
- exit (-1);
+ exit (EXIT_FAILURE);
}
break;
case 'H': /* set horizontal resolution to new value */
@@ -1890,7 +1923,7 @@ void process_command_opts (int argc, char *argv[], char *mp, char *mode, uint32
TIFFError("Missing or unknown option for inverting PHOTOMETRIC_INTERPRETATION", "%s", optarg);
TIFFError ("For valid options type", "tiffcrop -h");
- exit (-1);
+ exit (EXIT_FAILURE);
break;
case 'J': /* horizontal margin for sectioned ouput pages */
page->hmargin = atof(optarg);
@@ -1963,7 +1996,7 @@ void process_command_opts (int argc, char *argv[], char *mp, char *mode, uint32
break;
default: TIFFError ("Orientation must be portrait, landscape, or auto.", "%s", optarg);
TIFFError ("For valid options type", "tiffcrop -h");
- exit (-1);
+ exit (EXIT_FAILURE);
}
break;
case 'P': /* page size selection */
@@ -1982,7 +2015,7 @@ void process_command_opts (int argc, char *argv[], char *mp, char *mode, uint32
TIFFError ("", "%-15.15s %5.2f %5.2f",
PaperTable[i].name, PaperTable[i].width,
PaperTable[i].length);
- exit (-1);
+ exit (EXIT_FAILURE);
}
TIFFError ("Invalid paper size", "%s", optarg);
@@ -1992,7 +2025,7 @@ void process_command_opts (int argc, char *argv[], char *mp, char *mode, uint32
TIFFError ("", "%-15.15s %5.2f %5.2f",
PaperTable[i].name, PaperTable[i].width,
PaperTable[i].length);
- exit (-1);
+ exit (EXIT_FAILURE);
}
else
{
@@ -2011,7 +2044,7 @@ void process_command_opts (int argc, char *argv[], char *mp, char *mode, uint32
break;
default: TIFFError ("Rotation must be 90, 180, or 270 degrees clockwise", "%s", optarg);
TIFFError ("For valid options type", "tiffcrop -h");
- exit (-1);
+ exit (EXIT_FAILURE);
}
break;
case 'S': /* subdivide into Cols:Rows sections, eg 3:2 would be 3 across and 2 down */
@@ -2030,7 +2063,7 @@ void process_command_opts (int argc, char *argv[], char *mp, char *mode, uint32
if ((page->cols * page->rows) > MAX_SECTIONS)
{
TIFFError ("Limit for subdivisions, ie rows x columns, exceeded", "%d", MAX_SECTIONS);
- exit (-1);
+ exit (EXIT_FAILURE);
}
page->mode |= PAGE_MODE_ROWSCOLS;
break;
@@ -2054,7 +2087,7 @@ void process_command_opts (int argc, char *argv[], char *mp, char *mode, uint32
{
TIFFError ("Illegal unit of measure","%s", optarg);
TIFFError ("For valid options type", "tiffcrop -h");
- exit (-1);
+ exit (EXIT_FAILURE);
}
break;
case 'V': /* set vertical resolution to new value */
@@ -2079,7 +2112,7 @@ void process_command_opts (int argc, char *argv[], char *mp, char *mode, uint32
opt_offset = strchr(opt_ptr, ':');
if (!opt_offset) {
TIFFError("Wrong parameter syntax for -Z", "tiffcrop -h");
- exit(-1);
+ exit(EXIT_FAILURE);
}
*opt_offset = '\0';
crop_data->zonelist[i].position = atoi(opt_ptr);
@@ -2089,11 +2122,11 @@ void process_command_opts (int argc, char *argv[], char *mp, char *mode, uint32
if ((opt_ptr != NULL) && (i >= MAX_REGIONS))
{
TIFFError("Zone list exceeds region limit", "%d", MAX_REGIONS);
- exit (-1);
+ exit (EXIT_FAILURE);
}
break;
case '?': TIFFError ("For valid options type", "tiffcrop -h");
- exit (-1);
+ exit (EXIT_FAILURE);
/*NOTREACHED*/
}
}
@@ -2225,7 +2258,7 @@ main(int argc, char* argv[])
&crop, &page, &dump, imagelist, &image_count);
if (argc - optind < 2)
- usage();
+ usage(EXIT_FAILURE);
if ((argc - optind) == 2)
pageNum = -1;
@@ -2318,7 +2351,7 @@ main(int argc, char* argv[])
if ((dump.infile = fopen(temp_filename, dump.mode)) == NULL)
{
TIFFError ("Unable to open dump file for writing", "%s", temp_filename);
- exit (-1);
+ exit (EXIT_FAILURE);
}
dump_info(dump.infile, dump.format, "Reading image","%d from %s",
dump_images, TIFFFileName(in));
@@ -2337,7 +2370,7 @@ main(int argc, char* argv[])
if ((dump.outfile = fopen(temp_filename, dump.mode)) == NULL)
{
TIFFError ("Unable to open dump file for writing", "%s", temp_filename);
- exit (-1);
+ exit (EXIT_FAILURE);
}
dump_info(dump.outfile, dump.format, "Writing image","%d from %s",
dump_images, TIFFFileName(in));
@@ -2350,7 +2383,7 @@ main(int argc, char* argv[])
if (loadImage(in, &image, &dump, &read_buff))
{
TIFFError("main", "Unable to load source image");
- exit (-1);
+ exit (EXIT_FAILURE);
}
/* Correct the image orientation if it was not ORIENTATION_TOPLEFT.
@@ -2364,7 +2397,7 @@ main(int argc, char* argv[])
if (getCropOffsets(&image, &crop, &dump))
{
TIFFError("main", "Unable to define crop regions");
- exit (-1);
+ exit (EXIT_FAILURE);
}
if (crop.selections > 0)
@@ -2372,7 +2405,7 @@ main(int argc, char* argv[])
if (processCropSelections(&image, &crop, &read_buff, seg_buffs))
{
TIFFError("main", "Unable to process image selections");
- exit (-1);
+ exit (EXIT_FAILURE);
}
}
else /* Single image segment without zones or regions */
@@ -2380,7 +2413,7 @@ main(int argc, char* argv[])
if (createCroppedImage(&image, &crop, &read_buff, &crop_buff))
{
TIFFError("main", "Unable to create output image");
- exit (-1);
+ exit (EXIT_FAILURE);
}
}
if (page.mode == PAGE_MODE_NONE)
@@ -2394,12 +2427,12 @@ main(int argc, char* argv[])
{
if (update_output_file (&out, mp, crop.exp_mode, argv[argc - 1],
&next_page))
- exit (1);
+ exit (EXIT_FAILURE);
if (writeCroppedImage(in, out, &image, &dump,crop.combined_width,
crop.combined_length, crop_buff, next_page, total_pages))
{
TIFFError("main", "Unable to write new image");
- exit (-1);
+ exit (EXIT_FAILURE);
}
}
}
@@ -2416,18 +2449,18 @@ main(int argc, char* argv[])
if (computeOutputPixelOffsets(&crop, &image, &page, sections, &dump))
{
TIFFError("main", "Unable to compute output section data");
- exit (-1);
+ exit (EXIT_FAILURE);
}
/* If there are multiple files on the command line, the final one is assumed
* to be the output filename into which the images are written.
*/
if (update_output_file (&out, mp, crop.exp_mode, argv[argc - 1], &next_page))
- exit (1);
+ exit (EXIT_FAILURE);
if (writeImageSections(in, out, &image, &page, sections, &dump, sect_src, &sect_buff))
{
TIFFError("main", "Unable to write image sections");
- exit (-1);
+ exit (EXIT_FAILURE);
}
}
@@ -3002,9 +3035,25 @@ extractContigSamples24bits (uint8 *in, uint8 *out, uint32 cols,
src = in + src_byte;
matchbits = maskbits << (32 - src_bit - bps);
if (little_endian)
- buff1 = (src[0] << 24) | (src[1] << 16) | (src[2] << 8) | src[3];
+ {
+ buff1 = (src[0] << 24);
+ if (matchbits & 0x00ff0000)
+ buff1 |= (src[1] << 16);
+ if (matchbits & 0x0000ff00)
+ buff1 |= (src[2] << 8);
+ if (matchbits & 0x000000ff)
+ buff1 |= src[3];
+ }
else
- buff1 = (src[3] << 24) | (src[2] << 16) | (src[1] << 8) | src[0];
+ {
+ buff1 = src[0];
+ if (matchbits & 0x0000ff00)
+ buff1 |= (src[1] << 8);
+ if (matchbits & 0x00ff0000)
+ buff1 |= (src[2] << 16);
+ if (matchbits & 0xff000000)
+ buff1 |= (src[3] << 24);
+ }
buff1 = (buff1 & matchbits) << (src_bit);
if (ready_bits < 16) /* add another bps bits to the buffer */
@@ -4023,9 +4072,9 @@ combineSeparateSamples24bits (uint8 *in[], uint8 *out, uint32 cols,
{
src = in[s] + src_offset + src_byte;
if (little_endian)
- buff1 = (src[0] << 24) | (src[1] << 16) | (src[2] << 8) | src[3];
+ buff1 = ((uint32)src[0] << 24) | ((uint32)src[1] << 16) | ((uint32)src[2] << 8) | (uint32)src[3];
else
- buff1 = (src[3] << 24) | (src[2] << 16) | (src[1] << 8) | src[0];
+ buff1 = ((uint32)src[3] << 24) | ((uint32)src[2] << 16) | ((uint32)src[1] << 8) | (uint32)src[0];
buff1 = (buff1 & matchbits) << (src_bit);
/* If we have a full buffer's worth, write it out */
@@ -4824,13 +4873,13 @@ static int readSeparateStripsIntoBuffer (TIFF *in, uint8 *obuf, uint32 length,
if( (size_t) stripsize > 0xFFFFFFFFU - 3U )
{
TIFFError("readSeparateStripsIntoBuffer", "Integer overflow when calculating buffer size.");
- exit(-1);
+ exit(EXIT_FAILURE);
}
for (s = 0; (s < spp) && (s < MAX_SAMPLES); s++)
{
srcbuffs[s] = NULL;
- buff = _TIFFmalloc(stripsize + 3);
+ buff = limitMalloc(stripsize + 3);
if (!buff)
{
TIFFError ("readSeparateStripsIntoBuffer",
@@ -6034,13 +6083,13 @@ loadImage(TIFF* in, struct image_data *image, struct dump_opts *dump, unsigned c
if (ntiles == 0 || tlsize == 0 || tile_rowsize == 0)
{
TIFFError("loadImage", "File appears to be tiled, but the number of tiles, tile size, or tile rowsize is zero.");
- exit(-1);
+ exit(EXIT_FAILURE);
}
buffsize = tlsize * ntiles;
if (tlsize != (buffsize / ntiles))
{
TIFFError("loadImage", "Integer overflow when calculating buffer size");
- exit(-1);
+ exit(EXIT_FAILURE);
}
if (buffsize < (uint32)(ntiles * tl * tile_rowsize))
@@ -6049,7 +6098,7 @@ loadImage(TIFF* in, struct image_data *image, struct dump_opts *dump, unsigned c
if (ntiles != (buffsize / tl / tile_rowsize))
{
TIFFError("loadImage", "Integer overflow when calculating buffer size");
- exit(-1);
+ exit(EXIT_FAILURE);
}
#ifdef DEBUG2
@@ -6074,20 +6123,20 @@ loadImage(TIFF* in, struct image_data *image, struct dump_opts *dump, unsigned c
if (nstrips == 0 || stsize == 0)
{
TIFFError("loadImage", "File appears to be striped, but the number of stipes or stripe size is zero.");
- exit(-1);
+ exit(EXIT_FAILURE);
}
buffsize = stsize * nstrips;
if (stsize != (buffsize / nstrips))
{
TIFFError("loadImage", "Integer overflow when calculating buffer size");
- exit(-1);
+ exit(EXIT_FAILURE);
}
buffsize_check = ((length * width * spp * bps) + 7);
if (length != ((buffsize_check - 7) / width / spp / bps))
{
TIFFError("loadImage", "Integer overflow detected.");
- exit(-1);
+ exit(EXIT_FAILURE);
}
if (buffsize < (uint32) (((length * width * spp * bps) + 7) / 8))
{
@@ -6137,7 +6186,7 @@ loadImage(TIFF* in, struct image_data *image, struct dump_opts *dump, unsigned c
TIFFError("loadImage", "Unable to allocate/reallocate read buffer");
return (-1);
}
- read_buff = (unsigned char *)_TIFFmalloc(buffsize+3);
+ read_buff = (unsigned char *)limitMalloc(buffsize+3);
}
else
{
@@ -6152,7 +6201,7 @@ loadImage(TIFF* in, struct image_data *image, struct dump_opts *dump, unsigned c
if (!new_buff)
{
free (read_buff);
- read_buff = (unsigned char *)_TIFFmalloc(buffsize+3);
+ read_buff = (unsigned char *)limitMalloc(buffsize+3);
}
else
read_buff = new_buff;
@@ -7026,21 +7075,21 @@ writeImageSections(TIFF *in, TIFF *out, struct image_data *image,
if (createImageSection(sectsize, sect_buff_ptr))
{
TIFFError("writeImageSections", "Unable to allocate section buffer");
- exit (-1);
+ exit(EXIT_FAILURE);
}
sect_buff = *sect_buff_ptr;
if (extractImageSection (image, &sections[i], src_buff, sect_buff))
{
TIFFError("writeImageSections", "Unable to extract image sections");
- exit (-1);
+ exit(EXIT_FAILURE);
}
/* call the write routine here instead of outside the loop */
if (writeSingleSection(in, out, image, dump, width, length, hres, vres, sect_buff))
{
TIFFError("writeImageSections", "Unable to write image section");
- exit (-1);
+ exit(EXIT_FAILURE);
}
}
@@ -7335,7 +7384,7 @@ createImageSection(uint32 sectsize, unsigned char **sect_buff_ptr)
if (!sect_buff)
{
- sect_buff = (unsigned char *)_TIFFmalloc(sectsize);
+ sect_buff = (unsigned char *)limitMalloc(sectsize);
*sect_buff_ptr = sect_buff;
_TIFFmemset(sect_buff, 0, sectsize);
}
@@ -7346,8 +7395,8 @@ createImageSection(uint32 sectsize, unsigned char **sect_buff_ptr)
new_buff = _TIFFrealloc(sect_buff, sectsize);
if (!new_buff)
{
- free (sect_buff);
- sect_buff = (unsigned char *)_TIFFmalloc(sectsize);
+ _TIFFfree (sect_buff);
+ sect_buff = (unsigned char *)limitMalloc(sectsize);
}
else
sect_buff = new_buff;
@@ -7388,7 +7437,7 @@ processCropSelections(struct image_data *image, struct crop_mask *crop,
cropsize = crop->bufftotal;
crop_buff = seg_buffs[0].buffer;
if (!crop_buff)
- crop_buff = (unsigned char *)_TIFFmalloc(cropsize);
+ crop_buff = (unsigned char *)limitMalloc(cropsize);
else
{
prev_cropsize = seg_buffs[0].size;
@@ -7398,7 +7447,7 @@ processCropSelections(struct image_data *image, struct crop_mask *crop,
if (! next_buff)
{
_TIFFfree (crop_buff);
- crop_buff = (unsigned char *)_TIFFmalloc(cropsize);
+ crop_buff = (unsigned char *)limitMalloc(cropsize);
}
else
crop_buff = next_buff;
@@ -7490,7 +7539,7 @@ processCropSelections(struct image_data *image, struct crop_mask *crop,
cropsize = crop->bufftotal;
crop_buff = seg_buffs[i].buffer;
if (!crop_buff)
- crop_buff = (unsigned char *)_TIFFmalloc(cropsize);
+ crop_buff = (unsigned char *)limitMalloc(cropsize);
else
{
prev_cropsize = seg_buffs[0].size;
@@ -7500,7 +7549,7 @@ processCropSelections(struct image_data *image, struct crop_mask *crop,
if (! next_buff)
{
_TIFFfree (crop_buff);
- crop_buff = (unsigned char *)_TIFFmalloc(cropsize);
+ crop_buff = (unsigned char *)limitMalloc(cropsize);
}
else
crop_buff = next_buff;
@@ -7626,7 +7675,7 @@ createCroppedImage(struct image_data *image, struct crop_mask *crop,
crop_buff = *crop_buff_ptr;
if (!crop_buff)
{
- crop_buff = (unsigned char *)_TIFFmalloc(cropsize);
+ crop_buff = (unsigned char *)limitMalloc(cropsize);
*crop_buff_ptr = crop_buff;
_TIFFmemset(crop_buff, 0, cropsize);
prev_cropsize = cropsize;
@@ -7639,7 +7688,7 @@ createCroppedImage(struct image_data *image, struct crop_mask *crop,
if (!new_buff)
{
free (crop_buff);
- crop_buff = (unsigned char *)_TIFFmalloc(cropsize);
+ crop_buff = (unsigned char *)limitMalloc(cropsize);
}
else
crop_buff = new_buff;
@@ -8412,7 +8461,7 @@ rotateImage(uint16 rotation, struct image_data *image, uint32 *img_width,
return (-1);
}
- if (!(rbuff = (unsigned char *)_TIFFmalloc(buffsize)))
+ if (!(rbuff = (unsigned char *)limitMalloc(buffsize)))
{
TIFFError("rotateImage", "Unable to allocate rotation buffer of %1u bytes", buffsize);
return (-1);
@@ -9042,7 +9091,7 @@ mirrorImage(uint16 spp, uint16 bps, uint16 mirror, uint32 width, uint32 length,
{
case MIRROR_BOTH:
case MIRROR_VERT:
- line_buff = (unsigned char *)_TIFFmalloc(rowsize);
+ line_buff = (unsigned char *)limitMalloc(rowsize);
if (line_buff == NULL)
{
TIFFError ("mirrorImage", "Unable to allocate mirror line buffer of %1u bytes", rowsize);
@@ -9079,7 +9128,7 @@ mirrorImage(uint16 spp, uint16 bps, uint16 mirror, uint32 width, uint32 length,
}
else
{ /* non 8 bit per sample data */
- if (!(line_buff = (unsigned char *)_TIFFmalloc(rowsize + 1)))
+ if (!(line_buff = (unsigned char *)limitMalloc(rowsize + 1)))
{
TIFFError("mirrorImage", "Unable to allocate mirror line buffer");
return (-1);
diff --git a/tiff/tools/tiffdither.c b/tiff/tools/tiffdither.c
index 3fd7f81a..a9d1b7c5 100644
--- a/tiff/tools/tiffdither.c
+++ b/tiff/tools/tiffdither.c
@@ -39,6 +39,13 @@
#include "tiffio.h"
#include "tiffiop.h"
+#ifndef EXIT_SUCCESS
+#define EXIT_SUCCESS 0
+#endif
+#ifndef EXIT_FAILURE
+#define EXIT_FAILURE 1
+#endif
+
#define streq(a,b) (strcmp(a,b) == 0)
#define strneq(a,b,n) (strncmp(a,b,n) == 0)
@@ -49,7 +56,7 @@ uint32 imagewidth;
uint32 imagelength;
int threshold = 128;
-static void usage(void);
+static void usage(int code);
/*
* Floyd-Steinberg error propragation with threshold.
@@ -166,7 +173,7 @@ processG3Options(char* cp)
else if (strneq(cp, "fill", 4))
group3options |= GROUP3OPT_FILLBITS;
else
- usage();
+ usage(EXIT_FAILURE);
} while ((cp = strchr(cp, ':')));
}
}
@@ -213,11 +220,11 @@ main(int argc, char* argv[])
extern char *optarg;
#endif
- while ((c = getopt(argc, argv, "c:f:r:t:")) != -1)
+ while ((c = getopt(argc, argv, "c:f:r:t:h")) != -1)
switch (c) {
case 'c': /* compression scheme */
if (!processCompressOptions(optarg))
- usage();
+ usage(EXIT_FAILURE);
break;
case 'f': /* fill order */
if (streq(optarg, "lsb2msb"))
@@ -225,7 +232,7 @@ main(int argc, char* argv[])
else if (streq(optarg, "msb2lsb"))
fillorder = FILLORDER_MSB2LSB;
else
- usage();
+ usage(EXIT_FAILURE);
break;
case 'r': /* rows/strip */
rowsperstrip = atoi(optarg);
@@ -237,29 +244,31 @@ main(int argc, char* argv[])
else if (threshold > 255)
threshold = 255;
break;
+ case 'h':
+ usage(EXIT_SUCCESS);
case '?':
- usage();
+ usage(EXIT_FAILURE);
/*NOTREACHED*/
}
if (argc - optind < 2)
- usage();
+ usage(EXIT_FAILURE);
in = TIFFOpen(argv[optind], "r");
if (in == NULL)
- return (-1);
+ return (EXIT_FAILURE);
TIFFGetField(in, TIFFTAG_SAMPLESPERPIXEL, &samplesperpixel);
if (samplesperpixel != 1) {
fprintf(stderr, "%s: Not a b&w image.\n", argv[0]);
- return (-1);
+ return (EXIT_FAILURE);
}
TIFFGetField(in, TIFFTAG_BITSPERSAMPLE, &bitspersample);
if (bitspersample != 8) {
fprintf(stderr,
" %s: Sorry, only handle 8-bit samples.\n", argv[0]);
- return (-1);
+ return (EXIT_FAILURE);
}
out = TIFFOpen(argv[optind+1], "w");
if (out == NULL)
- return (-1);
+ return (EXIT_FAILURE);
CopyField(TIFFTAG_IMAGEWIDTH, imagewidth);
TIFFGetField(in, TIFFTAG_IMAGELENGTH, &imagelength);
TIFFSetField(out, TIFFTAG_IMAGELENGTH, imagelength-1);
@@ -293,10 +302,10 @@ main(int argc, char* argv[])
fsdither(in, out);
TIFFClose(in);
TIFFClose(out);
- return (0);
+ return (EXIT_SUCCESS);
}
-char* stuff[] = {
+static const char* stuff[] = {
"usage: tiffdither [options] input.tif output.tif",
"where options are:",
" -r # make each strip have no more than # rows",
@@ -323,16 +332,15 @@ NULL
};
static void
-usage(void)
+usage(int code)
{
- char buf[BUFSIZ];
int i;
+ FILE * out = (code == EXIT_SUCCESS) ? stdout : stderr;
- setbuf(stderr, buf);
- fprintf(stderr, "%s\n\n", TIFFGetVersion());
+ fprintf(out, "%s\n\n", TIFFGetVersion());
for (i = 0; stuff[i] != NULL; i++)
- fprintf(stderr, "%s\n", stuff[i]);
- exit(-1);
+ fprintf(out, "%s\n", stuff[i]);
+ exit(code);
}
/* vim: set ts=8 sts=8 sw=8 noet: */
diff --git a/tiff/tools/tiffdump.c b/tiff/tools/tiffdump.c
index 4cdcda0c..00be9dd4 100644
--- a/tiff/tools/tiffdump.c
+++ b/tiff/tools/tiffdump.c
@@ -56,6 +56,13 @@ extern int getopt(int argc, char * const argv[], const char *optstring);
#include "tiffio.h"
+#ifndef EXIT_SUCCESS
+#define EXIT_SUCCESS 0
+#endif
+#ifndef EXIT_FAILURE
+#define EXIT_FAILURE 1
+#endif
+
#ifndef O_BINARY
# define O_BINARY 0
#endif
@@ -105,7 +112,7 @@ void
usage()
{
fprintf(stderr, "usage: %s [-h] [-o offset] [-m maxitems] file.tif ...\n", appname);
- exit(-1);
+ exit(EXIT_FAILURE);
}
int
@@ -142,7 +149,7 @@ main(int argc, char* argv[])
fd = open(argv[optind], O_RDONLY|O_BINARY, 0);
if (fd < 0) {
perror(argv[0]);
- return (-1);
+ return (EXIT_FAILURE);
}
if (multiplefiles)
printf("%s:\n", argv[optind]);
@@ -152,7 +159,7 @@ main(int argc, char* argv[])
dump(fd, diroff);
close(fd);
}
- return (0);
+ return (EXIT_SUCCESS);
}
#define ord(e) ((int)e)
@@ -451,7 +458,7 @@ ReadDirectory(int fd, unsigned int ix, uint64 off)
{
datafits = 0;
datamem = NULL;
- dataoffset = *(uint64*)dp;
+ memcpy(&dataoffset, dp, sizeof(uint64));
if (swabflag)
TIFFSwabLong8(&dataoffset);
}
@@ -874,7 +881,7 @@ Fatal(const char* fmt, ...)
va_start(ap, fmt);
vError(stderr, fmt, ap);
va_end(ap);
- exit(-1);
+ exit(EXIT_FAILURE);
}
/* vim: set ts=8 sts=8 sw=8 noet: */
diff --git a/tiff/tools/tiffgt.c b/tiff/tools/tiffgt.c
index 2f11b0ca..f3cca8c9 100644
--- a/tiff/tools/tiffgt.c
+++ b/tiff/tools/tiffgt.c
@@ -48,6 +48,13 @@
#include "tiffio.h"
#include "tiffiop.h"
+#ifndef EXIT_SUCCESS
+#define EXIT_SUCCESS 0
+#endif
+#ifndef EXIT_FAILURE
+#define EXIT_FAILURE 1
+#endif
+
#ifndef HAVE_GETOPT
extern int getopt(int argc, char * const argv[], const char *optstring);
#endif
@@ -68,12 +75,12 @@ static int filenum;
static TIFFErrorHandler oerror;
static TIFFErrorHandler owarning;
-static void cleanup_and_exit(void);
+static void cleanup_and_exit(int);
static int initImage(void);
static int prevImage(void);
static int nextImage(void);
static void setWindowSize(void);
-static void usage(void);
+static void usage(int);
static uint16 photoArg(const char*);
static void raster_draw(void);
static void raster_reshape(int, int);
@@ -102,7 +109,7 @@ main(int argc, char* argv[])
oerror = TIFFSetErrorHandler(NULL);
owarning = TIFFSetWarningHandler(NULL);
- while ((c = getopt(argc, argv, "d:o:p:eflmsvw?")) != -1)
+ while ((c = getopt(argc, argv, "d:o:p:eflmsvwh")) != -1)
switch (c) {
case 'd':
dirnum = atoi(optarg);
@@ -131,13 +138,16 @@ main(int argc, char* argv[])
case 'v':
verbose = 1;
break;
+ case 'h':
+ usage(EXIT_SUCCESS);
+ /*NOTREACHED*/
case '?':
- usage();
+ usage(EXIT_FAILURE);
/*NOTREACHED*/
}
filenum = argc - optind;
if ( filenum < 1)
- usage();
+ usage(EXIT_FAILURE);
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
@@ -157,13 +167,13 @@ main(int argc, char* argv[])
filelist = (char **) _TIFFmalloc(filenum * sizeof(char*));
if (!filelist) {
TIFFError(argv[0], "Can not allocate space for the file list.");
- return 1;
+ return EXIT_FAILURE;
}
_TIFFmemcpy(filelist, argv + optind, filenum * sizeof(char*));
fileindex = -1;
if (nextImage() < 0) {
_TIFFfree(filelist);
- return 2;
+ return EXIT_FAILURE;
}
/*
* Set initial directory if user-specified
@@ -177,7 +187,7 @@ main(int argc, char* argv[])
photo = photo0;
if (initImage() < 0){
_TIFFfree(filelist);
- return 3;
+ return EXIT_FAILURE;
}
/*
* Create a new window or reconfigure an existing
@@ -193,12 +203,12 @@ main(int argc, char* argv[])
glutSpecialFunc(raster_special);
glutMainLoop();
- cleanup_and_exit();
- return 0;
+ cleanup_and_exit(EXIT_SUCCESS);
+ return EXIT_SUCCESS;
}
static void
-cleanup_and_exit(void)
+cleanup_and_exit(int code)
{
TIFFRGBAImageEnd(&img);
if (filelist != NULL)
@@ -207,7 +217,7 @@ cleanup_and_exit(void)
_TIFFfree(raster);
if (tif != NULL)
TIFFClose(tif);
- exit(0);
+ exit(code);
}
static int
@@ -250,7 +260,7 @@ initImage(void)
if (raster == NULL) {
width = height = 0;
TIFFError(filelist[fileindex], "No space for raster buffer");
- cleanup_and_exit();
+ cleanup_and_exit(EXIT_FAILURE);
}
width = w;
height = h;
@@ -361,7 +371,7 @@ raster_keys(unsigned char key, int x, int y)
break;
case 'q': /* exit */
case '\033':
- cleanup_and_exit();
+ cleanup_and_exit(EXIT_SUCCESS);
}
glutPostRedisplay();
}
@@ -422,7 +432,7 @@ raster_special(int key, int x, int y)
# pragma GCC diagnostic pop
# endif
-char* stuff[] = {
+static const char* stuff[] = {
"usage: tiffgt [options] file.tif",
"where options are:",
" -c use colormap visual",
@@ -440,16 +450,15 @@ NULL
};
static void
-usage(void)
+usage(int code)
{
- char buf[BUFSIZ];
int i;
+ FILE * out = (code == EXIT_SUCCESS) ? stdout : stderr;
- setbuf(stderr, buf);
- fprintf(stderr, "%s\n\n", TIFFGetVersion());
+ fprintf(out, "%s\n\n", TIFFGetVersion());
for (i = 0; stuff[i] != NULL; i++)
- fprintf(stderr, "%s\n", stuff[i]);
- exit(-1);
+ fprintf(out, "%s\n", stuff[i]);
+ exit(code);
}
static uint16
diff --git a/tiff/tools/tiffinfo.c b/tiff/tools/tiffinfo.c
index 049e3a34..2271c9d1 100644
--- a/tiff/tools/tiffinfo.c
+++ b/tiff/tools/tiffinfo.c
@@ -42,15 +42,22 @@
#include "tiffiop.h"
+#ifndef EXIT_SUCCESS
+#define EXIT_SUCCESS 0
+#endif
+#ifndef EXIT_FAILURE
+#define EXIT_FAILURE 1
+#endif
+
static TIFFErrorHandler old_error_handler = 0;
-static int status = 0; /* exit status */
+static int status = EXIT_SUCCESS; /* exit status */
static int showdata = 0; /* show data */
static int rawdata = 0; /* show raw/decoded data */
static int showwords = 0; /* show data as bytes/words */
static int readdata = 0; /* read data in file */
static int stoponerr = 1; /* stop on first read error */
-static void usage(void);
+static void usage(int);
static void tiffinfo(TIFF*, uint16, long, int);
static void
@@ -58,7 +65,7 @@ PrivateErrorHandler(const char* module, const char* fmt, va_list ap)
{
if (old_error_handler)
(*old_error_handler)(module,fmt,ap);
- status = 1;
+ status = EXIT_FAILURE;
}
int
@@ -75,7 +82,7 @@ main(int argc, char* argv[])
uint64 diroff = 0;
int chopstrips = 0; /* disable strip chopping */
- while ((c = getopt(argc, argv, "f:o:cdDSjilmrsvwz0123456789")) != -1)
+ while ((c = getopt(argc, argv, "f:o:cdDSjilmrsvwz0123456789h")) != -1)
switch (c) {
case '0': case '1': case '2': case '3':
case '4': case '5': case '6': case '7':
@@ -97,7 +104,7 @@ main(int argc, char* argv[])
else if (streq(optarg, "msb2lsb"))
order = FILLORDER_MSB2LSB;
else
- usage();
+ usage(EXIT_FAILURE);
break;
case 'i':
stoponerr = 0;
@@ -122,12 +129,15 @@ main(int argc, char* argv[])
case 'z':
chopstrips = 1;
break;
+ case 'h':
+ usage(EXIT_SUCCESS);
+ /*NOTREACHED*/
case '?':
- usage();
+ usage(EXIT_FAILURE);
/*NOTREACHED*/
}
if (optind >= argc)
- usage();
+ usage(EXIT_FAILURE);
old_error_handler = TIFFSetErrorHandler(PrivateErrorHandler);
@@ -162,7 +172,7 @@ main(int argc, char* argv[])
return (status);
}
-char* stuff[] = {
+static const char* stuff[] = {
"usage: tiffinfo [options] input...",
"where options are:",
" -D read data",
@@ -182,16 +192,15 @@ NULL
};
static void
-usage(void)
+usage(int code)
{
- char buf[BUFSIZ];
int i;
+ FILE * out = (code == EXIT_SUCCESS) ? stdout : stderr;
- setbuf(stderr, buf);
- fprintf(stderr, "%s\n\n", TIFFGetVersion());
+ fprintf(out, "%s\n\n", TIFFGetVersion());
for (i = 0; stuff[i] != NULL; i++)
- fprintf(stderr, "%s\n", stuff[i]);
- exit(-1);
+ fprintf(out, "%s\n", stuff[i]);
+ exit(code);
}
static void
@@ -407,11 +416,11 @@ ShowRawWords(uint16* pp, uint32 n)
putchar('\n');
}
-void
-TIFFReadRawData(TIFF* tif, int bitrev)
+static void
+TIFFReadRawDataStriped(TIFF* tif, int bitrev)
{
tstrip_t nstrips = TIFFNumberOfStrips(tif);
- const char* what = TIFFIsTiled(tif) ? "Tile" : "Strip";
+ const char* what = "Strip";
uint64* stripbc=NULL;
TIFFGetField(tif, TIFFTAG_STRIPBYTECOUNTS, &stripbc);
@@ -456,6 +465,66 @@ TIFFReadRawData(TIFF* tif, int bitrev)
}
static void
+TIFFReadRawDataTiled(TIFF* tif, int bitrev)
+{
+ const char* what = "Tile";
+ uint32 ntiles = TIFFNumberOfTiles(tif);
+ uint64 *tilebc;
+
+ TIFFGetField(tif, TIFFTAG_TILEBYTECOUNTS, &tilebc);
+ if (tilebc != NULL && ntiles > 0) {
+ uint64 bufsize = 0;
+ tdata_t buf = NULL;
+ uint32 t;
+
+ for (t = 0; t < ntiles; t++) {
+ if (buf == NULL || tilebc[t] > bufsize) {
+ buf = _TIFFrealloc(buf, (tmsize_t)tilebc[t]);
+ bufsize = tilebc[t];
+ }
+ if (buf == NULL) {
+ fprintf(stderr,
+ "Cannot allocate buffer to read tile %lu\n",
+ (unsigned long) t);
+ break;
+ }
+ if (TIFFReadRawTile(tif, t, buf, (tmsize_t)tilebc[t]) < 0) {
+ fprintf(stderr, "Error reading tile %lu\n",
+ (unsigned long) t);
+ if (stoponerr)
+ break;
+ } else if (showdata) {
+ if (bitrev) {
+ TIFFReverseBits(buf, (tmsize_t)tilebc[t]);
+ printf("%s %lu: (bit reversed)\n ",
+ what, (unsigned long) t);
+ } else {
+ printf("%s %lu:\n ", what,
+ (unsigned long) t);
+ }
+ if (showwords) {
+ ShowRawWords((uint16*) buf, (uint32)(tilebc[t]>>1));
+ } else {
+ ShowRawBytes((unsigned char*) buf, (uint32) tilebc[t]);
+ }
+ }
+ }
+ if (buf != NULL)
+ _TIFFfree(buf);
+ }
+}
+
+void
+TIFFReadRawData(TIFF* tif, int bitrev)
+{
+ if (TIFFIsTiled(tif)) {
+ TIFFReadRawDataTiled(tif, bitrev);
+ } else {
+ TIFFReadRawDataStriped(tif, bitrev);
+ }
+}
+
+static void
tiffinfo(TIFF* tif, uint16 order, long flags, int is_image)
{
TIFFPrintDirectory(tif, stdout, flags);
diff --git a/tiff/tools/tiffmedian.c b/tiff/tools/tiffmedian.c
index bd0d1561..6654cd6f 100644
--- a/tiff/tools/tiffmedian.c
+++ b/tiff/tools/tiffmedian.c
@@ -54,6 +54,13 @@
#include "tiffio.h"
+#ifndef EXIT_SUCCESS
+#define EXIT_SUCCESS 0
+#endif
+#ifndef EXIT_FAILURE
+#define EXIT_FAILURE 1
+#endif
+
#define MAX_CMAP_SIZE 256
#define streq(a,b) (strcmp(a,b) == 0)
@@ -106,7 +113,7 @@ static void quant(TIFF*, TIFF*);
static void quant_fsdither(TIFF*, TIFF*);
static Colorbox* largest_box(void);
-static void usage(void);
+static void usage(int);
static int processCompressOptions(char*);
#define CopyField(tag, v) \
@@ -127,11 +134,11 @@ main(int argc, char* argv[])
#endif
num_colors = MAX_CMAP_SIZE;
- while ((c = getopt(argc, argv, "c:C:r:f")) != -1)
+ while ((c = getopt(argc, argv, "c:C:r:fh")) != -1)
switch (c) {
case 'c': /* compression scheme */
if (!processCompressOptions(optarg))
- usage();
+ usage(EXIT_FAILURE);
break;
case 'C': /* set colormap size */
num_colors = atoi(optarg);
@@ -139,7 +146,7 @@ main(int argc, char* argv[])
fprintf(stderr,
"-c: colormap too big, max %d\n",
MAX_CMAP_SIZE);
- usage();
+ usage(EXIT_FAILURE);
}
break;
case 'f': /* dither */
@@ -148,15 +155,18 @@ main(int argc, char* argv[])
case 'r': /* rows/strip */
rowsperstrip = atoi(optarg);
break;
+ case 'h':
+ usage(EXIT_SUCCESS);
+ /*NOTREACHED*/
case '?':
- usage();
+ usage(EXIT_FAILURE);
/*NOTREACHED*/
}
if (argc - optind != 2)
- usage();
+ usage(EXIT_FAILURE);
in = TIFFOpen(argv[optind], "r");
if (in == NULL)
- return (-1);
+ return (EXIT_FAILURE);
TIFFGetField(in, TIFFTAG_IMAGEWIDTH, &imagewidth);
TIFFGetField(in, TIFFTAG_IMAGELENGTH, &imagelength);
TIFFGetField(in, TIFFTAG_BITSPERSAMPLE, &bitspersample);
@@ -164,18 +174,18 @@ main(int argc, char* argv[])
if (bitspersample != 8 && bitspersample != 16) {
fprintf(stderr, "%s: Image must have at least 8-bits/sample\n",
argv[optind]);
- return (-3);
+ return (EXIT_FAILURE);
}
if (!TIFFGetField(in, TIFFTAG_PHOTOMETRIC, &photometric) ||
photometric != PHOTOMETRIC_RGB || samplesperpixel < 3) {
fprintf(stderr, "%s: Image must have RGB data\n", argv[optind]);
- return (-4);
+ return (EXIT_FAILURE);
}
TIFFGetField(in, TIFFTAG_PLANARCONFIG, &config);
if (config != PLANARCONFIG_CONTIG) {
fprintf(stderr, "%s: Can only handle contiguous data packing\n",
argv[optind]);
- return (-5);
+ return (EXIT_FAILURE);
}
/*
@@ -245,7 +255,7 @@ main(int argc, char* argv[])
*/
out = TIFFOpen(argv[optind+1], "w");
if (out == NULL)
- return (-2);
+ return (EXIT_FAILURE);
CopyField(TIFFTAG_SUBFILETYPE, longv);
CopyField(TIFFTAG_IMAGEWIDTH, longv);
@@ -290,7 +300,7 @@ main(int argc, char* argv[])
}
TIFFSetField(out, TIFFTAG_COLORMAP, rm, gm, bm);
(void) TIFFClose(out);
- return (0);
+ return (EXIT_SUCCESS);
}
static int
@@ -333,16 +343,15 @@ NULL
};
static void
-usage(void)
+usage(int code)
{
- char buf[BUFSIZ];
int i;
+ FILE * out = (code == EXIT_SUCCESS) ? stdout : stderr;
- setbuf(stderr, buf);
- fprintf(stderr, "%s\n\n", TIFFGetVersion());
+ fprintf(out, "%s\n\n", TIFFGetVersion());
for (i = 0; stuff[i] != NULL; i++)
- fprintf(stderr, "%s\n", stuff[i]);
- exit(-1);
+ fprintf(out, "%s\n", stuff[i]);
+ exit(code);
}
static void
@@ -356,7 +365,7 @@ get_histogram(TIFF* in, Colorbox* box)
inputline = (unsigned char *)_TIFFmalloc(TIFFScanlineSize(in));
if (inputline == NULL) {
fprintf(stderr, "No space for scanline buffer\n");
- exit(-1);
+ exit(EXIT_FAILURE);
}
box->rmin = box->gmin = box->bmin = 999;
box->rmax = box->gmax = box->bmax = -1;
@@ -378,7 +387,7 @@ get_histogram(TIFF* in, Colorbox* box)
fprintf(stderr,
"Logic error. "
"Histogram array overflow!\n");
- exit(-6);
+ exit(EXIT_FAILURE);
}
if (red < box->rmin)
box->rmin = red;
diff --git a/tiff/tools/tiffset.c b/tiff/tools/tiffset.c
index 7ecc401b..75cf45c0 100644
--- a/tiff/tools/tiffset.c
+++ b/tiff/tools/tiffset.c
@@ -35,7 +35,18 @@
#include "tiffio.h"
-static char* usageMsg[] = {
+#ifdef NEED_LIBPORT
+# include "libport.h"
+#endif
+
+#ifndef EXIT_SUCCESS
+#define EXIT_SUCCESS 0
+#endif
+#ifndef EXIT_FAILURE
+#define EXIT_FAILURE 1
+#endif
+
+static const char* usageMsg[] = {
"usage: tiffset [options] filename",
"where options are:",
" -s <tagname> [count] <value>... set the tag value",
@@ -43,16 +54,20 @@ static char* usageMsg[] = {
" -d <dirno> set the directory",
" -sd <diroff> set the subdirectory",
" -sf <tagname> <filename> read the tag value from file (for ASCII tags only)",
+" -h this help screen",
NULL
};
static void
-usage(void)
+usage(int code)
{
int i;
+ FILE * out = (code == EXIT_SUCCESS) ? stdout : stderr;
+
+ fprintf(out, "%s\n\n", TIFFGetVersion());
for (i = 0; usageMsg[i]; i++)
- fprintf(stderr, "%s\n", usageMsg[i]);
- exit(-1);
+ fprintf(out, "%s\n", usageMsg[i]);
+ exit(code);
}
static const TIFFField *
@@ -80,11 +95,11 @@ main(int argc, char* argv[])
int arg_index;
if (argc < 2)
- usage();
+ usage(EXIT_FAILURE);
tiff = TIFFOpen(argv[argc-1], "r+");
if (tiff == NULL)
- return 2;
+ return EXIT_FAILURE;
for( arg_index = 1; arg_index < argc-1; arg_index++ ) {
if (strcmp(argv[arg_index],"-d") == 0 && arg_index < argc-2) {
@@ -92,7 +107,7 @@ main(int argc, char* argv[])
if( TIFFSetDirectory(tiff, atoi(argv[arg_index]) ) != 1 )
{
fprintf( stderr, "Failed to set directory=%s\n", argv[arg_index] );
- return 6;
+ return EXIT_FAILURE;
}
arg_index++;
}
@@ -101,7 +116,7 @@ main(int argc, char* argv[])
if( TIFFSetSubDirectory(tiff, atoi(argv[arg_index]) ) != 1 )
{
fprintf( stderr, "Failed to set sub directory=%s\n", argv[arg_index] );
- return 7;
+ return EXIT_FAILURE;
}
arg_index++;
}
@@ -113,7 +128,7 @@ main(int argc, char* argv[])
tagname = argv[arg_index];
fip = GetField(tiff, tagname);
if (!fip)
- return 3;
+ return EXIT_FAILURE;
if (TIFFUnsetField(tiff, TIFFFieldTag(fip)) != 1)
{
@@ -151,7 +166,7 @@ main(int argc, char* argv[])
"Number of tag values is not enough. "
"Expected %d values for %s tag, got %d\n",
wc, TIFFFieldName(fip), argc - arg_index);
- return 4;
+ return EXIT_FAILURE;
}
if (wc > 1 || TIFFFieldWriteCount(fip) == TIFF_VARIABLE) {
@@ -200,7 +215,7 @@ main(int argc, char* argv[])
if (!array) {
fprintf(stderr, "No space for %s tag\n",
tagname);
- return 4;
+ return EXIT_FAILURE;
}
switch (TIFFFieldDataType(fip)) {
@@ -317,18 +332,19 @@ main(int argc, char* argv[])
const TIFFField *fip;
char *text;
size_t len;
+ int ret;
arg_index++;
fip = GetField(tiff, argv[arg_index]);
if (!fip)
- return 3;
+ return EXIT_FAILURE;
if (TIFFFieldDataType(fip) != TIFF_ASCII) {
fprintf( stderr,
"Only ASCII tags can be set from file. "
"%s is not ASCII tag.\n", TIFFFieldName(fip) );
- return 5;
+ return EXIT_FAILURE;
}
arg_index++;
@@ -339,28 +355,41 @@ main(int argc, char* argv[])
}
text = (char *) malloc(1000000);
+ if(text == NULL) {
+ fprintf( stderr,
+ "Memory allocation error\n");
+ fclose( fp );
+ continue;
+ }
len = fread( text, 1, 999999, fp );
text[len] = '\0';
fclose( fp );
- if(TIFFSetField( tiff, TIFFFieldTag(fip), text ) != 1) {
+ if(TIFFFieldPassCount( fip )) {
+ ret = TIFFSetField( tiff, TIFFFieldTag(fip), (uint16)len, text );
+ } else {
+ ret = TIFFSetField( tiff, TIFFFieldTag(fip), text );
+ }
+ if(!ret) {
fprintf(stderr, "Failed to set %s from file %s\n",
TIFFFieldName(fip), argv[arg_index]);
}
_TIFFfree( text );
arg_index++;
+ } else if (strcmp(argv[arg_index],"-h") == 0 || strcmp(argv[arg_index],"--help") == 0) {
+ usage(EXIT_SUCCESS);
} else {
fprintf(stderr, "Unrecognised option: %s\n",
argv[arg_index]);
- usage();
+ usage(EXIT_FAILURE);
}
}
TIFFRewriteDirectory(tiff);
TIFFClose(tiff);
- return 0;
+ return EXIT_SUCCESS;
}
/* vim: set ts=8 sts=8 sw=8 noet: */
diff --git a/tiff/tools/tiffsplit.c b/tiff/tools/tiffsplit.c
index c8b7f2dd..43b6fdc1 100644
--- a/tiff/tools/tiffsplit.c
+++ b/tiff/tools/tiffsplit.c
@@ -30,6 +30,13 @@
#include "tiffio.h"
+#ifndef EXIT_SUCCESS
+#define EXIT_SUCCESS 0
+#endif
+#ifndef EXIT_FAILURE
+#define EXIT_FAILURE 1
+#endif
+
#ifndef HAVE_GETOPT
extern int getopt(int argc, char * const argv[], const char *optstring);
#endif
@@ -60,7 +67,7 @@ main(int argc, char* argv[])
if (argc < 2) {
fprintf(stderr, "%s\n\n", TIFFGetVersion());
fprintf(stderr, "usage: tiffsplit input.tif [prefix]\n");
- return (-3);
+ return (EXIT_FAILURE);
}
if (argc > 2) {
strncpy(fname, argv[2], sizeof(fname));
@@ -83,14 +90,14 @@ main(int argc, char* argv[])
_TIFFfree(path);
if (out == NULL)
- return (-2);
+ return (EXIT_FAILURE);
if (!tiffcp(in, out))
- return (-1);
+ return (EXIT_FAILURE);
TIFFClose(out);
} while (TIFFReadDirectory(in));
(void) TIFFClose(in);
}
- return (0);
+ return (EXIT_SUCCESS);
}
static void
@@ -117,7 +124,7 @@ newfilename(void)
if (fnum == MAXFILES) {
if (!defname || fname[0] == 'z') {
fprintf(stderr, "tiffsplit: too many files.\n");
- exit(1);
+ exit(EXIT_FAILURE);
}
fname[0]++;
fnum = 0;