diff --git a/.appveyor.yml b/.appveyor.yml index bcc0d1a0..04369ec6 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -14,34 +14,31 @@ environment: configuration: Debug generator: Unix Makefiles shared: OFF - - compiler: mingw64-cmake + - compiler: mingw-cmake configuration: Release - generator: Unix Makefiles + generator: MinGW Makefiles shared: ON - - compiler: mingw64-cmake + - compiler: mingw-cmake configuration: Debug - generator: Unix Makefiles + generator: MinGW Makefiles shared: OFF - compiler: vc14-cmake configuration: Release - generator: Visual Studio 14 2015 Win64 + generator: Visual Studio 16 2019 shared: ON - compiler: vc14-cmake configuration: Debug - generator: Visual Studio 14 2015 Win64 + generator: Visual Studio 16 2019 shared: OFF - compiler: vc14-nmake configuration: Release - - compiler: vc9-cmake - configuration: Debug - generator: Visual Studio 9 2008 - shared: ON + cache: - - 'c:\projects\download -> appveyor.yml' + #- 'c:\projects\download -> appveyor.yml' # Operating system (build VM template) -os: 'Visual Studio 2015' +os: 'Visual Studio 2019' # clone directory clone_folder: 'c:\projects\libtiff' @@ -53,32 +50,37 @@ init: - git config --global core.autocrlf input before_build: - - 'FOR /F "tokens=* USEBACKQ" %%F IN (`C:\cygwin64\bin\cygpath -u %AV_TIFF_SOURCE%`) DO SET AV_TIFF_CYG_SOURCE=%%F' - - 'FOR /F "tokens=* USEBACKQ" %%F IN (`C:\cygwin64\bin\cygpath -u %AV_TIFF_INSTALL%`) DO SET AV_TIFF_CYG_INSTALL=%%F' + - 'FOR /F "tokens=* USEBACKQ" %%F IN (`C:\Cygwin64\bin\cygpath -u %AV_TIFF_SOURCE%`) DO SET AV_TIFF_CYG_SOURCE=%%F' + - 'FOR /F "tokens=* USEBACKQ" %%F IN (`C:\Cygwin64\bin\cygpath -u %AV_TIFF_INSTALL%`) DO SET AV_TIFF_CYG_INSTALL=%%F' - 'if %compiler%==cygwin-cmake C:\Cygwin64\setup-x86_64 -q -R C:\Cygwin64 -s http://cygwin.mirror.constant.com -l %AV_TIFF_DOWNLOAD%\cygwin -P cmake,libjpeg-devel,zlib-devel' - 'if %compiler%==cygwin-cmake set "PATH=C:\Cygwin64\bin;%PATH%"' - - 'if %compiler%==mingw64-cmake set "PATH=C:\mingw-w64\x86_64-6.3.0-posix-seh-rt_v5-rev1\mingw64\bin;%PATH%"' + - set + - 'if %compiler%==cygwin-cmake dir C:\Cygwin64\bin' + - 'if %compiler%==cygwin-cmake dir C:\Cygwin64\bin\cmake.exe' + - 'if %compiler%==cygwin-cmake C:\Cygwin64\bin\cmake.exe --version || echo CMake not found' + - 'if %compiler%==cygwin-cmake C:\Cygwin64\bin\cmake --version || echo CMake not found' + - 'if %compiler%==cygwin-cmake cygpath --version || echo cygpath not found' + - 'if %compiler%==cygwin-cmake cmake --version || echo CMake not found' + - set "AV_CMAKE_ARGS=-DBUILD_SHARED_LIBS:BOOL=%shared%" - set "AV_CMAKE_ARGS=-DBUILD_SHARED_LIBS:BOOL=%shared%" - - 'if %compiler%==mingw64-cmake set "PATH=C:\mingw-w64\x86_64-6.3.0-posix-seh-rt_v5-rev1\mingw64\bin;%PATH%"' - - 'if %compiler%==mingw64-cmake set "AV_CMAKE_ARGS=%AV_CMAKE_ARGS% -DCMAKE_MAKE_PROGRAM=C:\mingw-w64\x86_64-6.3.0-posix-seh-rt_v5-rev1\mingw64\bin\mingw32-make"' - set "AV_TIFF_CMAKE_SOURCE=%AV_TIFF_SOURCE%" - set "AV_TIFF_CMAKE_INSTALL=%AV_TIFF_INSTALL%" - 'if %compiler%==cygwin-cmake set "AV_TIFF_CMAKE_SOURCE=%AV_TIFF_CYG_SOURCE%' - 'if %compiler%==cygwin-cmake set "AV_TIFF_CMAKE_INSTALL=%AV_TIFF_CYG_INSTALL%' + - 'if %compiler%==mingw-cmake set "PATH=C:\MinGW\bin;%PATH%"' - 'if %compiler%==vc14-nmake call "%VS140COMNTOOLS%..\..\VC\vcvarsall.bat" %platform%' - mkdir %AV_TIFF_BUILD% - cd %AV_TIFF_BUILD% - if NOT %compiler%==vc14-nmake echo Running cmake -G "%generator%" -DCMAKE_INSTALL_PREFIX=%AV_TIFF_CMAKE_INSTALL% -DCMAKE_BUILD_TYPE=%configuration% %AV_TIFF_CMAKE_SOURCE% - 'if %compiler%==cygwin-cmake bash -c "cmake -G \"%generator%\" -DCMAKE_INSTALL_PREFIX:PATH=%AV_TIFF_CMAKE_INSTALL% -DCMAKE_BUILD_TYPE=%configuration% %AV_CMAKE_ARGS% %AV_TIFF_CMAKE_SOURCE%"' - - 'if %compiler%==mingw64-cmake cmake -G "%generator%" -DCMAKE_INSTALL_PREFIX:PATH=%AV_TIFF_CMAKE_INSTALL% -DCMAKE_BUILD_TYPE=%configuration% %AV_CMAKE_ARGS% %AV_TIFF_CMAKE_SOURCE%' - - 'if %compiler%==vc14-cmake cmake -G "%generator%" -DCMAKE_INSTALL_PREFIX:PATH=%AV_TIFF_CMAKE_INSTALL% -DCMAKE_BUILD_TYPE=%configuration% %AV_CMAKE_ARGS% %AV_TIFF_CMAKE_SOURCE%' - - 'if %compiler%==vc9-cmake cmake -G "%generator%" -DCMAKE_INSTALL_PREFIX:PATH=%AV_TIFF_CMAKE_INSTALL% -DCMAKE_BUILD_TYPE=%configuration% %AV_CMAKE_ARGS% %AV_TIFF_CMAKE_SOURCE%' + - 'if %compiler%==mingw-cmake cmake -G "%generator%" -DCMAKE_INSTALL_PREFIX:PATH=%AV_TIFF_CMAKE_INSTALL% -DCMAKE_BUILD_TYPE=%configuration% %AV_CMAKE_ARGS% %AV_TIFF_CMAKE_SOURCE%' + - 'if %compiler%==vc14-cmake cmake -G "%generator%" -A x64 -DCMAKE_INSTALL_PREFIX:PATH=%AV_TIFF_CMAKE_INSTALL% -DCMAKE_BUILD_TYPE=%configuration% %AV_CMAKE_ARGS% %AV_TIFF_CMAKE_SOURCE%' build_script: - if NOT %compiler%==vc14-nmake cd %AV_TIFF_BUILD% - if %compiler%==vc14-nmake cd %AV_TIFF_SOURCE% - 'if %compiler%==cygwin-cmake bash -c "cmake --build . --config %configuration% --target install"' - - 'if %compiler%==mingw64-cmake cmake --build . --config %configuration% --target install' + - 'if %compiler%==mingw-cmake cmake --build . --config %configuration% --target install' - 'if %compiler%==vc14-cmake cmake --build . --config %configuration% --target install' - 'if %compiler%==vc9-cmake cmake --build . --config %configuration% --target install' - 'if %compiler%==vc14-nmake nmake /f Makefile.vc EXTRAFLAGS=/DHAVE_SNPRINTF=1' @@ -104,7 +106,7 @@ after_build: before_test: - cd %AV_TIFF_BUILD% - 'if %compiler%==cygwin-cmake bash -c "ctest -V -C %configuration%"' - - 'if %compiler%==mingw64-cmake ctest -V -C %configuration%' + - 'if %compiler%==mingw-cmake ctest -V -C %configuration%' - 'if %compiler%==vc14-cmake ctest -V -C %configuration%' - 'if %compiler%==vc9-cmake ctest -V -C %configuration%' # vc14-nmake does not support unit tests diff --git a/.gitignore b/.gitignore index 59e2622f..d02f6367 100644 --- a/.gitignore +++ b/.gitignore @@ -58,6 +58,8 @@ test/strip_rw test/defer_strile_loading test/defer_strile_writing test/testtypes +test/custom_dir_EXIF_231 +test/rational_precision2double test/*.log test/*.trs test/o-* diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c8a89403..7efe145b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,6 +1,7 @@ -image: ubuntu:16.04 +image: ubuntu:20.04 + before_script: - - apt-get update -qq && apt-get install -y -qq autoconf automake build-essential cmake libtool libjpeg8-dev libjbig-dev liblzma-dev ninja-build zlib1g-dev zip wget + - apt-get update -qq && DEBIAN_FRONTEND=noninteractive apt-get install -y -qq autoconf automake build-essential cmake libtool libjpeg8-dev libjbig-dev liblzma-dev ninja-build zlib1g-dev libdeflate-dev zip wget stages: - build diff --git a/CMakeLists.txt b/CMakeLists.txt index 35b48770..efe857df 100644 --- a/CMakeLists.txt +++ b/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/ChangeLog b/ChangeLog index 01e2182c..452dcb3a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,1445 @@ +2020-12-19 Bob Friesenhahn + + * 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 + + 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 + + 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 + + DoubleToRational(): avoid casting NaN to uint32 (fixes #227) + +2020-12-12 Even Rouault + + 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 + + tiffio.h: do not define __attribute__ but defines TIFF_ATTRIBUTE instead (fixes #221) + +2020-12-08 Even Rouault + + 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 Version: 0x2a + 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 + + 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 + + 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 + + Merge branch 'Jamaika1-master-patch-46397' into 'master' + Added stdint.h + + See merge request libtiff/libtiff!171 + +2020-11-27 Jamaika + + 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 + + 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 + + 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 + + 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 + + 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 + + tif_lzw.c: avoid false positive -Wnull-dereference of mingw32 gcc 7.3. + +2020-11-17 Thomas Bernard + + 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 + + tiff2rgba.1: -M option. + + enforce (configurable) memory limit in tiff2rgba. + fixes #207 + fixes #209 + +2020-11-14 Even Rouault + + 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 + + tiff2pdf.c: properly calculate datasize when saving to JPEG YCbCr. + fixes #220 + +2020-11-14 Even Rouault + + 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 + + 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 + + Merge branch 'skal65535-master-patch-91082' into 'master' + More overflow fixes for large widths + + See merge request libtiff/libtiff!164 + +2020-11-14 skal + + More overflow fixes for large width. + Also: use INT_MAX instead of hard-coded constants. + +2020-11-12 Even Rouault + + Merge branch 'skal65535-master-patch-56655' into 'master' + Fix potential overflow in gtStripContig() + + See merge request libtiff/libtiff!163 + +2020-11-12 Even Rouault + + Merge branch 'issue-211' into 'master' + check for tile width overflow + + Closes #211 + + See merge request libtiff/libtiff!160 + +2020-11-12 skal + + Fix potential overflow in gtStripContig() + (w + w) might not fit in int32 if too large. + +2020-11-09 Thomas Bernard + + 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 + + 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 + + tif_webp.c: validate tile/strip dimension to avoid unsigned integer overflow in RGBA.size computation + +2020-10-19 Even Rouault + + tif_zip.c: fix typo in comment. + +2020-10-16 Even Rouault + + tiff.h: remove irrelevant warning about webp related pseudo-tags not being registered: they are purely internal libtiff concepts + +2020-10-16 Even Rouault + + 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 + + test: add testdeflatelaststripextradata.sh. + +2020-10-16 Even Rouault + + 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 + + tif_webp.c: fix compiler warnings with MSVC. + +2020-10-12 Even Rouault + + 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 + + .gitignore: add entries for new files in test/ + + Fix compiler warnings about unused variables when assert() expands to nothing + +2020-10-09 Roger Leigh + + 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 + + wip. + + wip. + + wip. + + wip. + + wip. + + wip. + +2020-10-09 Roger Leigh + + 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 + + cmake: Do not use absolute libm path. + +2020-10-08 Even Rouault + + 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 + + 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 + + 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 + + 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 + + tif_fax3.h: extra buffer overflow checks. Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=25934 + +2020-09-25 Roger Leigh + + wip. + + wip. + + wip. + + wip. + + wip. + + wip. + + Update AppVeyor image. + + test-appveyor. + +2020-09-24 Attila Oláh + + 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 + + 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 + + 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 + + Fix comparison for max negative float value. + +2020-09-07 Even Rouault + + 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 + + Merge branch 'issue-17' into 'master' + normalize tools behaviour regarding -h + + Closes #17 + + See merge request libtiff/libtiff!115 + +2020-05-31 Even Rouault + + TWebPSetupEncode(): fix logic problem (and instead of or) in test that checks input is 8bit unsigned data + +2020-05-12 Even Rouault + + TIFFGetConfiguredCODECs(): fix to avoid wrong structure to be returned for registered (ie non built-in) codecs + +2020-05-09 Even Rouault + + 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 + + Merge branch 'deprecated' into 'master' + ojpeg: s/Depreciated/Deprecated/ + + See merge request libtiff/libtiff!149 + +2020-05-09 Aaron Boxer + + ojpeg: s/Depreciated/Deprecated/ + +2020-04-27 Even Rouault + + Fix typos. + + tif_jpeg.c: avoid potential division in previous fix (master only) + +2020-04-26 Thomas Bernard + + gitlab-ci: use latest zstd and webp versions. + +2020-04-26 Even Rouault + + tiff.h: fixes to use ASCII only characters (master only) + +2020-04-26 Thomas Bernard + + 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 + + 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 + + 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 + + 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 + + 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 + + tif_jpeg.c: revise logic to detect potential excessive memory usage when decoding multiscan JPEG compressed images + +2020-04-19 Thomas Bernard + + 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 + + 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 + + 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 + + Fix wrong file size checks for memory-mapped BigTIFF files that could lead to image rejection + +2020-04-05 Thomas Bernard + + 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 + + tiffinfo: showdata for tiled images. + + tiffinfo: fix dump of Tiled images. + fixes #80 + +2020-04-03 Even Rouault + + Merge branch 'issue-117' into 'master' + tiffcrop: enforce memory allocation limit + + Closes #117 + + See merge request libtiff/libtiff!140 + +2020-04-03 Thomas Bernard + + 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 + + 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 + + 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 + + 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 + + Rename itrunc to fix name clash with a different itrunc in math.h on AIX. Fixes issue #189 + +2020-04-01 Thomas Bernard + + tiffcp: disable strip chopping when trying to convert to JBIG compression + fixes #45 + +2020-03-29 Thomas Bernard + + TIFFGetFields(3tiff): TIFFTAG_*BYTECOUNTS TIFFTAG_*OFFSETS are uint64. + fixes #124 / http://bugzilla.maptools.org/show_bug.cgi?id=2774 + +2020-03-29 Even Rouault + + 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 + + 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 + + tif_fax3: quit Fax3Decode2D() when a buffer overflow occurs. + fixes #186 + +2020-03-24 Even Rouault + + 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 + + Merge branch 'issue-133' into 'master' + tiff2pdf: avoid divide by 0 + + Closes #133 + + See merge request libtiff/libtiff!126 + +2020-03-24 Thomas Bernard + + tiff2pdf: normalizePoint() macro to normalize the white point. + +2020-03-23 Thomas Bernard + + tiffdump: avoid unaligned memory access. + fixes #143 + fixes #144 + +2020-03-23 Even Rouault + + 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 + + Merge branch 'issue-157' into 'master' + tiffset: check memory allocation + + Closes #157 + + See merge request libtiff/libtiff!132 + +2020-03-23 Even Rouault + + 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 + + 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 + + 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 + + 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 + + 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 + + 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 + + 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 + + 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 + + tiff2pdf: avoid divide by 0. + fixes #133 http://bugzilla.maptools.org/show_bug.cgi?id=2796 + +2020-03-17 Even Rouault + + 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 + + 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 + + tif_fax3.c: fix warning C4018: '<': signed/unsigned mismatch introduced in past commits + +2020-03-11 Even Rouault + + tiff.h: mention TIFFTAG_RPCCOEFFICIENT, TIFFTAG_TIFF_RSID, TIFFTAG_GEO_METADATA + +2020-03-11 Even Rouault + + 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 + + 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 + + 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 + + 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 + + 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 + + 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 + + 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 + + contrib/win_dib/tiff2dib: fix Uninitialized variable: lpBits. + fixes #52 + http://bugzilla.maptools.org/show_bug.cgi?id=2469 + +2020-03-08 Even Rouault + + Merge branch 'issue-58' into 'master' + Make TIFFTAG_CFAPATTERN variable count + + Closes #58 + + See merge request libtiff/libtiff!120 + +2020-03-08 Even Rouault + + 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 + + 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 + + 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 + + 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 + + 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 + + CMake: Skip custom_dir_EXIF_231 test on shared builds to avoid issues on Windows + +2020-03-07 Even Rouault + + 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 + + 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 + + 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 + + ppm2tiff: Add test for 16bpc PPM. + + ppm2tiff: remove unused argument warning. + +2020-03-07 Ludolf Holzheid + + 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 + +2020-03-06 Even Rouault + + Merge branch 'fax-test' into 'master' + add test for fax4 decoding + + See merge request libtiff/libtiff!114 + +2020-03-05 Thomas Bernard + + 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 + + Merge branch 'freebsd-tests' into 'master' + make tests pass under FreeBSD. + + See merge request libtiff/libtiff!113 + +2020-03-05 Thomas Bernard + + 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 + + Merge branch 'issue-31' into 'master' + HTML + + Closes #31 + + See merge request libtiff/libtiff!111 + +2020-03-05 Even Rouault + + 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 + + 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 + + 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 + + index.html: fix unclosed tag. + +2020-03-01 Thomas Bernard + + 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 + + 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 + + Merge branch 'issue-46' into 'master' + fix decoding of fax4 images + + Closes #46 + + See merge request libtiff/libtiff!110 + +2020-02-29 Thomas Bernard + + 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 + + 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 + + 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 + + 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 + + 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 + + Fax4Decode(): log error message in case of buffer overrun. + + tif_fax3.c: check buffer overflow in Fax4Decode() + fixes #174 + +2020-02-28 Even Rouault + + 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 + + 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 + + Merge branch 'Rational2DoublePrecision' into 'master' + Rational with Double Precision Upgrade + + See merge request libtiff/libtiff!100 + +2020-02-27 Su_Laus + + 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 + + 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 + + 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 + + Merge branch 'fix-unused-warning' into 'master' + warnings: mark conditionally used parameters + + See merge request libtiff/libtiff!49 + +2020-02-26 Even Rouault + + 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 + + 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 + + Merge branch 'bug2839' into 'master' + raw2tiff: avoid divide by 0 + + Closes #151 + + See merge request libtiff/libtiff!103 + +2020-02-26 Even Rouault + + 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 + + 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 + + Merge branch 'bug-2538' into 'master' + libtiff.html: fix function casing + + Closes #68 + + See merge request libtiff/libtiff!107 + +2020-02-16 Thomas Bernard + + 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 + + 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 + + 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 + + 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 + + tiff2pdf: palette bound check in t2p_sample_realize_palette() + fixes #82 + +2020-02-08 Thomas Bernard + + 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 + + tif_dirread.c: suppress CLang static Analyzer 9.0 false positive. + +2020-02-01 Even Rouault + + 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 + + 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 + + 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 + + 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 + + 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 + + Adjust previous fix to avoid undue warning in some situations triggered by GDAL + +2020-01-12 Even Rouault + + _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 + + 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 + + fix issue #78 warnings regarding RichTIFFIPTC data type. + +2019-12-14 Even Rouault + + contrib/oss-fuzz/build.sh: fix broken if construct. + +2019-11-28 Even Rouault + + contrib/oss-fuzz/build.sh: other attempt at fixing build failure. + +2019-11-20 Even Rouault + + contrib/oss-fuzz/build.sh: install liblzma-dev for x86_64 builds. + +2019-11-17 Even Rouault + + contrib/oss-fuzz/build.sh: install liblzma-dev:i386 on i386 builds. + +2019-11-15 Even Rouault + + Merge branch 'cmake-parse' into 'master' + CMake: simplify parsing variables from configure + + See merge request libtiff/libtiff!98 + +2019-11-15 Rolf Eike Beer + + CMake: simplify parsing variables from configure. + +2019-11-14 Even Rouault + + contrib/oss-fuzz/build.sh: fix ossfuzz build by statically linking to lzma + +2019-11-12 Even Rouault + + 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 + + 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 + + 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 + + adds missing checks on TIFFGetField in tiffcrop tool (fixes #170) + +2019-11-04 Even Rouault + + 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 + + adds a missing TIFFClose in rgb2ycbcr tool. + 2019-11-03 Bob Friesenhahn libtiff 4.1.0 released. diff --git a/HOWTO-RELEASE b/HOWTO-RELEASE index abcdc9ba..0896ef99 100644 --- a/HOWTO-RELEASE +++ b/HOWTO-RELEASE @@ -140,7 +140,7 @@ Notes on releasing. 17. Copy release packages from the build tree to the ftp.remotesensing.org ftp site. - scp tiff-*.tar.gz tiff-*.zip \ + scp tiff-*.tar.gz tiff-*.tar.gz.sig tiff-*.zip tiff-*.zip.sig \ bfriesen@upload.osgeo.org:/osgeo/download/libtiff 18. Announce to list, tiff@lists.maptools.org diff --git a/Makefile.in b/Makefile.in index 6f4a3101..26f52eda 100644 --- a/Makefile.in +++ b/Makefile.in @@ -403,6 +403,7 @@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ +runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ diff --git a/Makefile.vc b/Makefile.vc index 6e66c730..eeb5d04d 100644 --- a/Makefile.vc +++ b/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/RELEASE-DATE b/RELEASE-DATE index ad4fa62a..1137155e 100644 --- a/RELEASE-DATE +++ b/RELEASE-DATE @@ -1 +1 @@ -20191103 +20201219 diff --git a/VERSION b/VERSION index ee74734a..6aba2b24 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.1.0 +4.2.0 diff --git a/build/Makefile.in b/build/Makefile.in index 92906d4d..510cabfd 100644 --- a/build/Makefile.in +++ b/build/Makefile.in @@ -348,6 +348,7 @@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ +runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ diff --git a/build/gitlab-ci b/build/gitlab-ci index e7306268..213431bf 100644 --- a/build/gitlab-ci +++ b/build/gitlab-ci @@ -2,6 +2,10 @@ # This script is used for testing the build, primarily for use # with travis, but may be used by hand as well. +# Library versions to use +ZSTD_VER=1.4.4 +WEBP_VER=1.1.0 + set -e set -x @@ -40,23 +44,23 @@ build=$1 shift # Build zstd -wget https://github.com/facebook/zstd/archive/v1.3.3.tar.gz -tar xvzf v1.3.3.tar.gz -cd zstd-1.3.3/lib +wget https://github.com/facebook/zstd/archive/v${ZSTD_VER}.tar.gz +tar xvzf v${ZSTD_VER}.tar.gz +cd zstd-${ZSTD_VER}/lib # Faster build make -j3 PREFIX=/tmp ZSTD_LEGACY_SUPPORT=0 CFLAGS=-O1 make install PREFIX=/tmp ZSTD_LEGACY_SUPPORT=0 CFLAGS=-O1 cd ../.. -rm -rf zstd-1.3.3 +rm -rf zstd-${ZSTD_VER} # Build webp -wget https://storage.googleapis.com/downloads.webmproject.org/releases/webp/libwebp-1.0.0.tar.gz -tar xvzf libwebp-1.0.0.tar.gz -cd libwebp-1.0.0 +wget https://storage.googleapis.com/downloads.webmproject.org/releases/webp/libwebp-${WEBP_VER}.tar.gz +tar xvzf libwebp-${WEBP_VER}.tar.gz +cd libwebp-${WEBP_VER} ./configure --prefix=/tmp make && make install cd .. -rm -rf libwebp-1.0.0 +rm -rf libwebp-${WEBP_VER} export LD_LIBRARY_PATH=/tmp/lib diff --git a/config/compile b/config/compile index 7a83ae68..99e50524 100755 --- a/config/compile +++ b/config/compile @@ -53,7 +53,7 @@ func_file_conv () MINGW*) file_conv=mingw ;; - CYGWIN*|MSYS*) + CYGWIN*) file_conv=cygwin ;; *) @@ -67,7 +67,7 @@ func_file_conv () mingw/*) file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` ;; - cygwin/*|msys/*) + cygwin/*) file=`cygpath -m "$file" || echo "$file"` ;; wine/*) diff --git a/config/ltmain.sh b/config/ltmain.sh index 9a833f36..d4831800 100644 --- a/config/ltmain.sh +++ b/config/ltmain.sh @@ -31,7 +31,7 @@ PROGRAM=libtool PACKAGE=libtool -VERSION=2.4.6 +VERSION="2.4.6 Debian-2.4.6-9" package_revision=2.4.6 @@ -1370,7 +1370,7 @@ func_lt_ver () #! /bin/sh # Set a version string for this script. -scriptversion=2014-01-07.03; # UTC +scriptversion=2015-10-07.11; # UTC # A portable, pluggable option parser for Bourne shell. # Written by Gary V. Vaughan, 2010 @@ -1530,6 +1530,8 @@ func_run_hooks () { $debug_cmd + _G_rc_run_hooks=false + case " $hookable_fns " in *" $1 "*) ;; *) func_fatal_error "'$1' does not support hook funcions.n" ;; @@ -1538,16 +1540,16 @@ func_run_hooks () eval _G_hook_fns=\$$1_hooks; shift for _G_hook in $_G_hook_fns; do - eval $_G_hook '"$@"' - - # store returned options list back into positional - # parameters for next 'cmd' execution. - eval _G_hook_result=\$${_G_hook}_result - eval set dummy "$_G_hook_result"; shift + if eval $_G_hook '"$@"'; then + # store returned options list back into positional + # parameters for next 'cmd' execution. + eval _G_hook_result=\$${_G_hook}_result + eval set dummy "$_G_hook_result"; shift + _G_rc_run_hooks=: + fi done - func_quote_for_eval ${1+"$@"} - func_run_hooks_result=$func_quote_for_eval_result + $_G_rc_run_hooks && func_run_hooks_result=$_G_hook_result } @@ -1557,10 +1559,16 @@ func_run_hooks () ## --------------- ## # In order to add your own option parsing hooks, you must accept the -# full positional parameter list in your hook function, remove any -# options that you action, and then pass back the remaining unprocessed +# full positional parameter list in your hook function, you may remove/edit +# any options that you action, and then pass back the remaining unprocessed # options in '_result', escaped suitably for -# 'eval'. Like this: +# 'eval'. In this case you also must return $EXIT_SUCCESS to let the +# hook's caller know that it should pay attention to +# '_result'. Returning $EXIT_FAILURE signalizes that +# arguments are left untouched by the hook and therefore caller will ignore the +# result variable. +# +# Like this: # # my_options_prep () # { @@ -1570,9 +1578,11 @@ func_run_hooks () # usage_message=$usage_message' # -s, --silent don'\''t print informational messages # ' -# -# func_quote_for_eval ${1+"$@"} -# my_options_prep_result=$func_quote_for_eval_result +# # No change in '$@' (ignored completely by this hook). There is +# # no need to do the equivalent (but slower) action: +# # func_quote_for_eval ${1+"$@"} +# # my_options_prep_result=$func_quote_for_eval_result +# false # } # func_add_hook func_options_prep my_options_prep # @@ -1581,25 +1591,37 @@ func_run_hooks () # { # $debug_cmd # +# args_changed=false +# # # Note that for efficiency, we parse as many options as we can # # recognise in a loop before passing the remainder back to the # # caller on the first unrecognised argument we encounter. # while test $# -gt 0; do # opt=$1; shift # case $opt in -# --silent|-s) opt_silent=: ;; +# --silent|-s) opt_silent=: +# args_changed=: +# ;; # # Separate non-argument short options: # -s*) func_split_short_opt "$_G_opt" # set dummy "$func_split_short_opt_name" \ # "-$func_split_short_opt_arg" ${1+"$@"} # shift +# args_changed=: # ;; -# *) set dummy "$_G_opt" "$*"; shift; break ;; +# *) # Make sure the first unrecognised option "$_G_opt" +# # is added back to "$@", we could need that later +# # if $args_changed is true. +# set dummy "$_G_opt" ${1+"$@"}; shift; break ;; # esac # done # -# func_quote_for_eval ${1+"$@"} -# my_silent_option_result=$func_quote_for_eval_result +# if $args_changed; then +# func_quote_for_eval ${1+"$@"} +# my_silent_option_result=$func_quote_for_eval_result +# fi +# +# $args_changed # } # func_add_hook func_parse_options my_silent_option # @@ -1611,16 +1633,32 @@ func_run_hooks () # $opt_silent && $opt_verbose && func_fatal_help "\ # '--silent' and '--verbose' options are mutually exclusive." # -# func_quote_for_eval ${1+"$@"} -# my_option_validation_result=$func_quote_for_eval_result +# false # } # func_add_hook func_validate_options my_option_validation # -# You'll alse need to manually amend $usage_message to reflect the extra +# You'll also need to manually amend $usage_message to reflect the extra # options you parse. It's preferable to append if you can, so that # multiple option parsing hooks can be added safely. +# func_options_finish [ARG]... +# ---------------------------- +# Finishing the option parse loop (call 'func_options' hooks ATM). +func_options_finish () +{ + $debug_cmd + + _G_func_options_finish_exit=false + if func_run_hooks func_options ${1+"$@"}; then + func_options_finish_result=$func_run_hooks_result + _G_func_options_finish_exit=: + fi + + $_G_func_options_finish_exit +} + + # func_options [ARG]... # --------------------- # All the functions called inside func_options are hookable. See the @@ -1630,17 +1668,28 @@ func_options () { $debug_cmd - func_options_prep ${1+"$@"} - eval func_parse_options \ - ${func_options_prep_result+"$func_options_prep_result"} - eval func_validate_options \ - ${func_parse_options_result+"$func_parse_options_result"} + _G_rc_options=false - eval func_run_hooks func_options \ - ${func_validate_options_result+"$func_validate_options_result"} + for my_func in options_prep parse_options validate_options options_finish + do + if eval func_$my_func '${1+"$@"}'; then + eval _G_res_var='$'"func_${my_func}_result" + eval set dummy "$_G_res_var" ; shift + _G_rc_options=: + fi + done - # save modified positional parameters for caller - func_options_result=$func_run_hooks_result + # Save modified positional parameters for caller. As a top-level + # options-parser function we always need to set the 'func_options_result' + # variable (regardless the $_G_rc_options value). + if $_G_rc_options; then + func_options_result=$_G_res_var + else + func_quote_for_eval ${1+"$@"} + func_options_result=$func_quote_for_eval_result + fi + + $_G_rc_options } @@ -1649,9 +1698,9 @@ func_options () # All initialisations required before starting the option parse loop. # Note that when calling hook functions, we pass through the list of # positional parameters. If a hook function modifies that list, and -# needs to propogate that back to rest of this script, then the complete +# needs to propagate that back to rest of this script, then the complete # modified list must be put in 'func_run_hooks_result' before -# returning. +# returning $EXIT_SUCCESS (otherwise $EXIT_FAILURE is returned). func_hookable func_options_prep func_options_prep () { @@ -1661,10 +1710,14 @@ func_options_prep () opt_verbose=false opt_warning_types= - func_run_hooks func_options_prep ${1+"$@"} + _G_rc_options_prep=false + if func_run_hooks func_options_prep ${1+"$@"}; then + _G_rc_options_prep=: + # save modified positional parameters for caller + func_options_prep_result=$func_run_hooks_result + fi - # save modified positional parameters for caller - func_options_prep_result=$func_run_hooks_result + $_G_rc_options_prep } @@ -1678,18 +1731,20 @@ func_parse_options () func_parse_options_result= + _G_rc_parse_options=false # this just eases exit handling while test $# -gt 0; do # Defer to hook functions for initial option parsing, so they # get priority in the event of reusing an option name. - func_run_hooks func_parse_options ${1+"$@"} - - # Adjust func_parse_options positional parameters to match - eval set dummy "$func_run_hooks_result"; shift + if func_run_hooks func_parse_options ${1+"$@"}; then + eval set dummy "$func_run_hooks_result"; shift + _G_rc_parse_options=: + fi # Break out of the loop if we already parsed every option. test $# -gt 0 || break + _G_match_parse_options=: _G_opt=$1 shift case $_G_opt in @@ -1704,7 +1759,10 @@ func_parse_options () ;; --warnings|--warning|-W) - test $# = 0 && func_missing_arg $_G_opt && break + if test $# = 0 && func_missing_arg $_G_opt; then + _G_rc_parse_options=: + break + fi case " $warning_categories $1" in *" $1 "*) # trailing space prevents matching last $1 above @@ -1757,15 +1815,25 @@ func_parse_options () shift ;; - --) break ;; + --) _G_rc_parse_options=: ; break ;; -*) func_fatal_help "unrecognised option: '$_G_opt'" ;; - *) set dummy "$_G_opt" ${1+"$@"}; shift; break ;; + *) set dummy "$_G_opt" ${1+"$@"}; shift + _G_match_parse_options=false + break + ;; esac + + $_G_match_parse_options && _G_rc_parse_options=: done - # save modified positional parameters for caller - func_quote_for_eval ${1+"$@"} - func_parse_options_result=$func_quote_for_eval_result + + if $_G_rc_parse_options; then + # save modified positional parameters for caller + func_quote_for_eval ${1+"$@"} + func_parse_options_result=$func_quote_for_eval_result + fi + + $_G_rc_parse_options } @@ -1778,16 +1846,21 @@ func_validate_options () { $debug_cmd + _G_rc_validate_options=false + # Display all warnings if -W was not given. test -n "$opt_warning_types" || opt_warning_types=" $warning_categories" - func_run_hooks func_validate_options ${1+"$@"} + if func_run_hooks func_validate_options ${1+"$@"}; then + # save modified positional parameters for caller + func_validate_options_result=$func_run_hooks_result + _G_rc_validate_options=: + fi # Bail if the options were screwed! $exit_cmd $EXIT_FAILURE - # save modified positional parameters for caller - func_validate_options_result=$func_run_hooks_result + $_G_rc_validate_options } @@ -2068,12 +2141,12 @@ include the following information: compiler: $LTCC compiler flags: $LTCFLAGS linker: $LD (gnu? $with_gnu_ld) - version: $progname (GNU libtool) 2.4.6 + version: $progname $scriptversion Debian-2.4.6-9 automake: `($AUTOMAKE --version) 2>/dev/null |$SED 1q` autoconf: `($AUTOCONF --version) 2>/dev/null |$SED 1q` Report bugs to . -GNU libtool home page: . +GNU libtool home page: . General help using GNU software: ." exit 0 } @@ -2270,6 +2343,8 @@ libtool_options_prep () nonopt= preserve_args= + _G_rc_lt_options_prep=: + # Shorthand for --mode=foo, only valid as the first argument case $1 in clean|clea|cle|cl) @@ -2293,11 +2368,18 @@ libtool_options_prep () uninstall|uninstal|uninsta|uninst|unins|unin|uni|un|u) shift; set dummy --mode uninstall ${1+"$@"}; shift ;; + *) + _G_rc_lt_options_prep=false + ;; esac - # Pass back the list of options. - func_quote_for_eval ${1+"$@"} - libtool_options_prep_result=$func_quote_for_eval_result + if $_G_rc_lt_options_prep; then + # Pass back the list of options. + func_quote_for_eval ${1+"$@"} + libtool_options_prep_result=$func_quote_for_eval_result + fi + + $_G_rc_lt_options_prep } func_add_hook func_options_prep libtool_options_prep @@ -2309,9 +2391,12 @@ libtool_parse_options () { $debug_cmd + _G_rc_lt_parse_options=false + # Perform our own loop to consume as many options as possible in # each iteration. while test $# -gt 0; do + _G_match_lt_parse_options=: _G_opt=$1 shift case $_G_opt in @@ -2386,15 +2471,22 @@ libtool_parse_options () func_append preserve_args " $_G_opt" ;; - # An option not handled by this hook function: - *) set dummy "$_G_opt" ${1+"$@"}; shift; break ;; + # An option not handled by this hook function: + *) set dummy "$_G_opt" ${1+"$@"} ; shift + _G_match_lt_parse_options=false + break + ;; esac + $_G_match_lt_parse_options && _G_rc_lt_parse_options=: done + if $_G_rc_lt_parse_options; then + # save modified positional parameters for caller + func_quote_for_eval ${1+"$@"} + libtool_parse_options_result=$func_quote_for_eval_result + fi - # save modified positional parameters for caller - func_quote_for_eval ${1+"$@"} - libtool_parse_options_result=$func_quote_for_eval_result + $_G_rc_lt_parse_options } func_add_hook func_parse_options libtool_parse_options @@ -2418,7 +2510,7 @@ libtool_validate_options () case $host in # Solaris2 added to fix http://debbugs.gnu.org/cgi/bugreport.cgi?bug=16452 # see also: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59788 - *cygwin* | *msys* | *mingw* | *pw32* | *cegcc* | *solaris2* | *os2*) + *cygwin* | *mingw* | *pw32* | *cegcc* | *solaris2* | *os2*) # don't eliminate duplications in $postdeps and $predeps opt_duplicate_compiler_generated_deps=: ;; @@ -3439,7 +3531,7 @@ func_mode_compile () # On Cygwin there's no "real" PIC flag so we must build both object types case $host_os in - cygwin* | msys* | mingw* | pw32* | os2* | cegcc*) + cygwin* | mingw* | pw32* | os2* | cegcc*) pic_mode=default ;; esac @@ -4313,7 +4405,7 @@ func_mode_install () 'exit $?' tstripme=$stripme case $host_os in - cygwin* | msys* | mingw* | pw32* | cegcc*) + cygwin* | mingw* | pw32* | cegcc*) case $realname in *.dll.a) tstripme= @@ -4426,7 +4518,7 @@ func_mode_install () # Do a test to see if this is really a libtool program. case $host in - *cygwin* | *msys* | *mingw*) + *cygwin* | *mingw*) if func_ltwrapper_executable_p "$file"; then func_ltwrapper_scriptname "$file" wrapper=$func_ltwrapper_scriptname_result @@ -4501,7 +4593,7 @@ func_mode_install () # remove .exe since cygwin /usr/bin/install will append another # one anyway case $install_prog,$host in - */usr/bin/install*,*cygwin*|*/usr/bin/install*,*msys*) + */usr/bin/install*,*cygwin*) case $file:$destfile in *.exe:*.exe) # this is ok @@ -4654,7 +4746,7 @@ extern \"C\" { $RM $export_symbols eval "$SED -n -e '/^: @PROGRAM@ $/d' -e 's/^.* \(.*\)$/\1/p' "'< "$nlist" > "$export_symbols"' case $host in - *cygwin* | *msys* | *mingw* | *cegcc* ) + *cygwin* | *mingw* | *cegcc* ) eval "echo EXPORTS "'> "$output_objdir/$outputname.def"' eval 'cat "$export_symbols" >> "$output_objdir/$outputname.def"' ;; @@ -4666,7 +4758,7 @@ extern \"C\" { eval '$GREP -f "$output_objdir/$outputname.exp" < "$nlist" > "$nlist"T' eval '$MV "$nlist"T "$nlist"' case $host in - *cygwin* | *msys* | *mingw* | *cegcc* ) + *cygwin* | *mingw* | *cegcc* ) eval "echo EXPORTS "'> "$output_objdir/$outputname.def"' eval 'cat "$nlist" >> "$output_objdir/$outputname.def"' ;; @@ -4680,7 +4772,7 @@ extern \"C\" { func_basename "$dlprefile" name=$func_basename_result case $host in - *cygwin* | *msys* | *mingw* | *cegcc* ) + *cygwin* | *mingw* | *cegcc* ) # if an import library, we need to obtain dlname if func_win32_import_lib_p "$dlprefile"; then func_tr_sh "$dlprefile" @@ -4855,7 +4947,7 @@ static const void *lt_preloaded_setup() { # Transform the symbol file into the correct name. symfileobj=$output_objdir/${my_outputname}S.$objext case $host in - *cygwin* | *msys* | *mingw* | *cegcc* ) + *cygwin* | *mingw* | *cegcc* ) if test -f "$output_objdir/$my_outputname.def"; then compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"` finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"` @@ -5538,7 +5630,6 @@ EOF # include # include # ifdef __CYGWIN__ -# include # include # endif #endif @@ -5555,8 +5646,8 @@ EOF /* declarations of non-ANSI functions */ #if defined __MINGW32__ -# if defined(__STRICT_ANSI__) && !defined(__MINGW64_VERSION_MAJOR) || defined(_POSIX_) -int _putenv (const char *); +# ifdef __STRICT_ANSI__ +_CRTIMP int _putenv (const char *); # endif #elif defined __CYGWIN__ # ifdef __STRICT_ANSI__ @@ -5754,7 +5845,7 @@ main (int argc, char *argv[]) { EOF case $host in - *mingw* | *cygwin* | *msys* ) + *mingw* | *cygwin* ) # make stdout use "unix" line endings echo " setmode(1,_O_BINARY);" ;; @@ -6457,41 +6548,6 @@ EOF } # end: func_emit_cwrapperexe_src -# func_emit_exe_manifest -# emit a Win32 UAC manifest for executable on stdout -# Must ONLY be called from within func_mode_link because -# it depends on a number of variable set therein. -func_emit_exe_manifest () -{ - cat < - - - - - - - - - - - - -EOF -} - # func_win32_import_lib_p ARG # True if ARG is an import lib, as indicated by $file_magic_cmd func_win32_import_lib_p () @@ -6528,7 +6584,7 @@ func_mode_link () $debug_cmd case $host in - *-*-cygwin* | *-*-msys* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*) + *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*) # It is impossible to link a dll without this setting, and # we shouldn't force the makefile maintainer to figure out # what system we are compiling for in order to pass an extra @@ -7027,7 +7083,7 @@ func_mode_link () ;; esac case $host in - *-*-cygwin* | *-*-msys* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*) + *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*) testbindir=`$ECHO "$dir" | $SED 's*/lib$*/bin*'` case :$dllsearchpath: in *":$dir:"*) ;; @@ -7047,7 +7103,7 @@ func_mode_link () -l*) if test X-lc = "X$arg" || test X-lm = "X$arg"; then case $host in - *-*-cygwin* | *-*-msys* | *-*-mingw* | *-*-pw32* | *-*-beos* | *-cegcc* | *-*-haiku*) + *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-beos* | *-cegcc* | *-*-haiku*) # These systems don't actually have a C or math library (as such) continue ;; @@ -7130,7 +7186,7 @@ func_mode_link () -no-install) case $host in - *-*-cygwin* | *-*-msys* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin* | *-cegcc*) + *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin* | *-cegcc*) # The PATH hackery in wrapper scripts is required on Windows # and Darwin in order for the loader to find any dlls it needs. func_warning "'-no-install' is ignored for $host" @@ -7308,15 +7364,14 @@ func_mode_link () # -tp=* Portland pgcc target processor selection # --sysroot=* for sysroot support # -O*, -g*, -flto*, -fwhopr*, -fuse-linker-plugin GCC link-time optimization + # -specs=* GCC specs files # -stdlib=* select c++ std lib with clang - # -{shared,static}-libgcc, -static-{libgfortran|libstdc++} - # link against specified runtime library + # -fsanitize=* Clang/GCC memory and address sanitizer + # -fuse-ld=* Linker select flags for GCC -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \ -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \ -O*|-g*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*|-stdlib=*| \ - -ftree-parallelize-loops=*|-fcilkplus|-fgnu-tm|-ffast-math| \ - -funsafe-math-optimizations|-fvtable-verify*| \ - -shared-libgcc|-static-libgcc|-static-libgfortran|-static-libstdc++) + -specs=*|-fsanitize=*|-fuse-ld=*) func_quote_for_eval "$arg" arg=$func_quote_for_eval_result func_append compile_command " $arg" @@ -7609,7 +7664,10 @@ func_mode_link () case $pass in dlopen) libs=$dlfiles ;; dlpreopen) libs=$dlprefiles ;; - link) libs="$deplibs %DEPLIBS% $dependency_libs" ;; + link) + libs="$deplibs %DEPLIBS%" + test "X$link_all_deplibs" != Xno && libs="$libs $dependency_libs" + ;; esac fi if test lib,dlpreopen = "$linkmode,$pass"; then @@ -7803,15 +7861,8 @@ func_mode_link () fi case $linkmode in lib) - # Linking convenience modules and compiler provided static libraries - # into shared libraries is allowed, but linking other static - # libraries is non-portable. - case $deplib in - */libgcc*.$libext | */libclang_rt*.$libext) - deplibs="$deplib $deplibs" - continue - ;; - esac + # Linking convenience modules into shared libraries is allowed, + # but linking other static libraries is non-portable. case " $dlpreconveniencelibs " in *" $deplib "*) ;; *) @@ -7935,19 +7986,19 @@ func_mode_link () # It is a libtool convenience library, so add in its objects. func_append convenience " $ladir/$objdir/$old_library" func_append old_convenience " $ladir/$objdir/$old_library" + tmp_libs= + for deplib in $dependency_libs; do + deplibs="$deplib $deplibs" + if $opt_preserve_dup_deps; then + case "$tmp_libs " in + *" $deplib "*) func_append specialdeplibs " $deplib" ;; + esac + fi + func_append tmp_libs " $deplib" + done elif test prog != "$linkmode" && test lib != "$linkmode"; then func_fatal_error "'$lib' is not a convenience library" fi - tmp_libs= - for deplib in $dependency_libs; do - deplibs="$deplib $deplibs" - if $opt_preserve_dup_deps; then - case "$tmp_libs " in - *" $deplib "*) func_append specialdeplibs " $deplib" ;; - esac - fi - func_append tmp_libs " $deplib" - done continue fi # $pass = conv @@ -8036,7 +8087,7 @@ func_mode_link () fi case $host in # special handling for platforms with PE-DLLs. - *cygwin* | *msys* | *mingw* | *cegcc* ) + *cygwin* | *mingw* | *cegcc* ) # Linker will automatically link against shared library if both # static and shared are present. Therefore, ensure we extract # symbols from the import library if a shared library is present @@ -8180,7 +8231,7 @@ func_mode_link () if test -n "$library_names" && { test no = "$use_static_libs" || test -z "$old_library"; }; then case $host in - *cygwin* | *msys* | *mingw* | *cegcc* | *os2*) + *cygwin* | *mingw* | *cegcc* | *os2*) # No point in relinking DLLs because paths are not encoded func_append notinst_deplibs " $lib" need_relink=no @@ -8250,7 +8301,7 @@ func_mode_link () elif test -n "$soname_spec"; then # bleh windows case $host in - *cygwin* | *msys* | mingw* | *cegcc* | *os2*) + *cygwin* | mingw* | *cegcc* | *os2*) func_arith $current - $age major=$func_arith_result versuffix=-$major @@ -8571,9 +8622,7 @@ func_mode_link () eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $deplib` test -z "$libdir" && \ func_fatal_error "'$deplib' is not a valid libtool archive" - abs_inode=`ls -i "$deplib" | awk '{print $1}'` - lib_inode=`ls -i "$libdir/$(basename $deplib)" | awk '{print $1}'` - test "$abs_inode" != "$lib_inode" && \ + test "$absdir" != "$libdir" && \ func_warning "'$deplib' seems to be moved" path=-L$absdir @@ -8873,6 +8922,9 @@ func_mode_link () revision=$number_minor lt_irix_increment=no ;; + *) + func_fatal_configuration "$modename: unknown library version type '$version_type'" + ;; esac ;; no) @@ -9162,7 +9214,7 @@ func_mode_link () if test yes = "$build_libtool_libs"; then if test -n "$rpath"; then case $host in - *-*-cygwin* | *-*-msys* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-beos* | *-cegcc* | *-*-haiku*) + *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-beos* | *-cegcc* | *-*-haiku*) # these systems don't actually have a c library (as such)! ;; *-*-rhapsody* | *-*-darwin1.[012]) @@ -9676,7 +9728,7 @@ EOF orig_export_symbols= case $host_os in - cygwin* | msys* | mingw* | cegcc*) + cygwin* | mingw* | cegcc*) if test -n "$export_symbols" && test -z "$export_symbols_regex"; then # exporting using user supplied symfile func_dll_def_p "$export_symbols" || { @@ -9874,7 +9926,20 @@ EOF last_robj= k=1 - if test -n "$save_libobjs" && test : != "$skipped_export" && test -n "$file_list_spec"; then + if test -n "$save_libobjs" && test : != "$skipped_export" && test yes = "$with_gnu_ld"; then + output=$output_objdir/$output_la.lnkscript + func_verbose "creating GNU ld script: $output" + echo 'INPUT (' > $output + for obj in $save_libobjs + do + func_to_tool_file "$obj" + $ECHO "$func_to_tool_file_result" >> $output + done + echo ')' >> $output + func_append delfiles " $output" + func_to_tool_file "$output" + output=$func_to_tool_file_result + elif test -n "$save_libobjs" && test : != "$skipped_export" && test -n "$file_list_spec"; then output=$output_objdir/$output_la.lnk func_verbose "creating linker input file list: $output" : > $output @@ -9893,19 +9958,6 @@ EOF func_append delfiles " $output" func_to_tool_file "$output" output=$firstobj\"$file_list_spec$func_to_tool_file_result\" - elif test -n "$save_libobjs" && test : != "$skipped_export" && test yes = "$with_gnu_ld"; then - output=$output_objdir/$output_la.lnkscript - func_verbose "creating GNU ld script: $output" - echo 'INPUT (' > $output - for obj in $save_libobjs - do - func_to_tool_file "$obj" - $ECHO "$func_to_tool_file_result" >> $output - done - echo ')' >> $output - func_append delfiles " $output" - func_to_tool_file "$output" - output=$func_to_tool_file_result else if test -n "$save_libobjs"; then func_verbose "creating reloadable object files..." @@ -10235,7 +10287,7 @@ EOF prog) case $host in - *cygwin* | *msys*) func_stripname '' '.exe' "$output" + *cygwin*) func_stripname '' '.exe' "$output" output=$func_stripname_result.exe;; esac test -n "$vinfo" && \ @@ -10346,7 +10398,7 @@ EOF esac fi case $host in - *-*-cygwin* | *-*-msys* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*) + *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*) testbindir=`$ECHO "$libdir" | $SED -e 's*/lib$*/bin*'` case :$dllsearchpath: in *":$libdir:"*) ;; @@ -10424,7 +10476,7 @@ EOF # Disable wrappers for cegcc and mingw32ce hosts, we are cross compiling anyway. wrappers_required=false ;; - *cygwin* | *msys* | *mingw* ) + *cygwin* | *mingw* ) test yes = "$build_libtool_libs" || wrappers_required=false ;; *) @@ -10570,21 +10622,21 @@ EOF esac # test for cygwin because mv fails w/o .exe extensions case $host in - *cygwin* | *msys*) + *cygwin*) exeext=.exe func_stripname '' '.exe' "$outputname" outputname=$func_stripname_result ;; *) exeext= ;; esac case $host in - *cygwin* | *msys* | *mingw* ) + *cygwin* | *mingw* ) func_dirname_and_basename "$output" "" "." output_name=$func_basename_result output_path=$func_dirname_result cwrappersource=$output_path/$objdir/lt-$output_name.c cwrapper=$output_path/$output_name.exe $RM $cwrappersource $cwrapper - trap "$RM $cwrappersource $cwrapper $cwrapper.manifest; exit $EXIT_FAILURE" 1 2 15 + trap "$RM $cwrappersource $cwrapper; exit $EXIT_FAILURE" 1 2 15 func_emit_cwrapperexe_src > $cwrappersource @@ -10604,16 +10656,6 @@ EOF $opt_dry_run || { # note: this script will not be executed, so do not chmod. if test "x$build" = "x$host"; then - # Create the UAC manifests first if necessary (but the - # manifest files must have executable permission regardless). - case $output_name in - *instal*|*patch*|*setup*|*update*) - func_emit_exe_manifest > $cwrapper.manifest - func_emit_exe_manifest > $output_path/$objdir/$output_name.exe.manifest - chmod +x $cwrapper.manifest - chmod +x $output_path/$objdir/$output_name.exe.manifest - ;; - esac $cwrapper --lt-dump-script > $func_ltwrapper_scriptname_result else func_emit_wrapper no > $func_ltwrapper_scriptname_result @@ -10919,7 +10961,7 @@ EOF # tests/bindir.at for full details. tdlname=$dlname case $host,$output,$installed,$module,$dlname in - *cygwin*,*lai,yes,no,*.dll | *msys*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll | *cegcc*,*lai,yes,no,*.dll) + *cygwin*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll | *cegcc*,*lai,yes,no,*.dll) # If a -bindir argument was supplied, place the dll there. if test -n "$bindir"; then func_relative_path "$install_libdir" "$bindir" @@ -11138,9 +11180,8 @@ func_mode_uninstall () # note $name still contains .exe if it was in $file originally # as does the version of $file that was added into $rmfiles func_append rmfiles " $odir/$name $odir/${name}S.$objext" - func_append rmfiles " ${name}.manifest $objdir/${name}.manifest" if test yes = "$fast_install" && test -n "$relink_command"; then - func_append rmfiles " $odir/lt-$name $objdir/lt-${name}.manifest" + func_append rmfiles " $odir/lt-$name" fi if test "X$noexename" != "X$name"; then func_append rmfiles " $odir/lt-$noexename.c" diff --git a/configure b/configure index 95c5d2b5..12a63232 100755 --- a/configure +++ b/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 . # @@ -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='' @@ -785,6 +785,7 @@ infodir docdir oldincludedir includedir +runstatedir localstatedir sharedstatedir sysconfdir @@ -833,6 +834,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 @@ -916,6 +920,7 @@ datadir='${datarootdir}' sysconfdir='${prefix}/etc' sharedstatedir='${prefix}/com' localstatedir='${prefix}/var' +runstatedir='${localstatedir}/run' includedir='${prefix}/include' oldincludedir='/usr/include' docdir='${datarootdir}/doc/${PACKAGE_TARNAME}' @@ -1168,6 +1173,15 @@ do | -silent | --silent | --silen | --sile | --sil) silent=yes ;; + -runstatedir | --runstatedir | --runstatedi | --runstated \ + | --runstate | --runstat | --runsta | --runst | --runs \ + | --run | --ru | --r) + ac_prev=runstatedir ;; + -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \ + | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \ + | --run=* | --ru=* | --r=*) + runstatedir=$ac_optarg ;; + -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) ac_prev=sbindir ;; -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ @@ -1305,7 +1319,7 @@ fi for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ datadir sysconfdir sharedstatedir localstatedir includedir \ oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ - libdir localedir mandir + libdir localedir mandir runstatedir do eval ac_val=\$$ac_var # Remove trailing slashes. @@ -1418,7 +1432,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]... @@ -1458,6 +1472,7 @@ Fine tuning of the installation directories: --sysconfdir=DIR read-only single-machine data [PREFIX/etc] --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] --localstatedir=DIR modifiable single-machine data [PREFIX/var] + --runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run] --libdir=DIR object code libraries [EPREFIX/lib] --includedir=DIR C header files [PREFIX/include] --oldincludedir=DIR C header files for non-gcc [/usr/include] @@ -1492,7 +1507,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 +1543,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 +1600,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 +1710,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 +2483,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 +3426,7 @@ fi # Define the identity of the package. PACKAGE='tiff' - VERSION='4.1.0' + VERSION='4.2.0' cat >>confdefs.h <<_ACEOF @@ -3446,16 +3468,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 +3520,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 +3533,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 +3551,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 +3579,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 +3660,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 @@ -5636,7 +5689,7 @@ else lt_cv_sys_max_cmd_len=-1; ;; - cygwin* | msys* | mingw* | cegcc*) + cygwin* | mingw* | cegcc*) # On Win9x/ME, this test blows up -- it succeeds, but takes # about 5 minutes as the teststring grows exponentially. # Worse, since 9x/ME are not pre-emptively multitasking, @@ -5802,7 +5855,7 @@ else *-*-mingw* ) # actually msys lt_cv_to_host_file_cmd=func_convert_file_msys_to_w32 ;; - *-*-cygwin* | *-*-msys* ) + *-*-cygwin* ) lt_cv_to_host_file_cmd=func_convert_file_cygwin_to_w32 ;; * ) # otherwise, assume *nix @@ -5810,12 +5863,12 @@ else ;; esac ;; - *-*-cygwin* | *-*-msys* ) + *-*-cygwin* ) case $build in *-*-mingw* ) # actually msys lt_cv_to_host_file_cmd=func_convert_file_msys_to_cygwin ;; - *-*-cygwin* | *-*-msys* ) + *-*-cygwin* ) lt_cv_to_host_file_cmd=func_convert_file_noop ;; * ) # otherwise, assume *nix @@ -5881,7 +5934,7 @@ case $reload_flag in esac reload_cmds='$LD$reload_flag -o $output$reload_objs' case $host_os in - cygwin* | msys* | mingw* | pw32* | cegcc*) + cygwin* | mingw* | pw32* | cegcc*) if test yes != "$GCC"; then reload_cmds=false fi @@ -6036,7 +6089,7 @@ bsdi[45]*) lt_cv_file_magic_test_file=/shlib/libc.so ;; -cygwin* | msys*) +cygwin*) # func_win32_libid is a shell function defined in ltmain.sh lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL' lt_cv_file_magic_cmd='func_win32_libid' @@ -6124,7 +6177,7 @@ linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*) lt_cv_deplibs_check_method=pass_all ;; -netbsd*) +netbsd* | netbsdelf*-gnu) if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so\.[0-9]+\.[0-9]+|_pic\.a)$' else @@ -6352,7 +6405,7 @@ else lt_cv_sharedlib_from_linklib_cmd='unknown' case $host_os in -cygwin* | msys* | mingw* | pw32* | cegcc*) +cygwin* | mingw* | pw32* | cegcc*) # two different shell functions defined in ltmain.sh; # decide which one to use based on capabilities of $DLLTOOL case `$DLLTOOL --help 2>&1` in @@ -6844,7 +6897,7 @@ case $host_os in aix*) symcode='[BCDT]' ;; -cygwin* | msys* | mingw* | pw32* | cegcc*) +cygwin* | mingw* | pw32* | cegcc*) symcode='[ABCDGISTW]' ;; hpux*) @@ -6984,11 +7037,8 @@ _LT_EOF test $ac_status = 0; }; then # Now try to grab the symbols. nlist=conftest.nm - if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$NM conftest.$ac_objext \| "$lt_cv_sys_global_symbol_pipe" \> $nlist\""; } >&5 - (eval $NM conftest.$ac_objext \| "$lt_cv_sys_global_symbol_pipe" \> $nlist) 2>&5 - ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 - test $ac_status = 0; } && test -s "$nlist"; then + $ECHO "$as_me:$LINENO: $NM conftest.$ac_objext | $lt_cv_sys_global_symbol_pipe > $nlist" >&5 + if eval "$NM" conftest.$ac_objext \| "$lt_cv_sys_global_symbol_pipe" \> $nlist 2>&5 && test -s "$nlist"; then # Try sorting and uniquifying the output. if sort "$nlist" | uniq > "$nlist"T; then mv -f "$nlist"T "$nlist" @@ -8588,7 +8638,7 @@ done enable_win32_dll=yes case $host in -*-*-cygwin* | *-*-msys* | *-*-mingw* | *-*-pw32* | *-*-cegcc*) +*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-cegcc*) if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}as", so it can be a program name with args. set dummy ${ac_tool_prefix}as; ac_word=$2 @@ -9491,7 +9541,7 @@ lt_prog_compiler_static= # PIC is the default for these OSes. ;; - mingw* | cygwin* | msys* | pw32* | os2* | cegcc*) + mingw* | cygwin* | pw32* | os2* | cegcc*) # This hack is so that the source file can tell whether it is being # built for inclusion in a dll (and should export symbols for example). # Although the cygwin gcc ignores -fPIC, still need this for old-style @@ -9594,7 +9644,7 @@ lt_prog_compiler_static= esac ;; - mingw* | cygwin* | msys* | pw32* | os2* | cegcc*) + mingw* | cygwin* | pw32* | os2* | cegcc*) # This hack is so that the source file can tell whether it is being # built for inclusion in a dll (and should export symbols for example). lt_prog_compiler_pic='-DDLL_EXPORT' @@ -10096,7 +10146,7 @@ $as_echo_n "checking whether the $compiler linker ($LD) supports shared librarie extract_expsyms_cmds= case $host_os in - cygwin* | msys* | mingw* | pw32* | cegcc*) + cygwin* | mingw* | pw32* | cegcc*) # FIXME: the MSVC++ port hasn't been tested in a loooong time # When not using gcc, we currently assume that we are using # Microsoft Visual C++. @@ -10111,6 +10161,9 @@ $as_echo_n "checking whether the $compiler linker ($LD) supports shared librarie openbsd* | bitrig*) with_gnu_ld=no ;; + linux* | k*bsd*-gnu | gnu*) + link_all_deplibs=no + ;; esac ld_shlibs=yes @@ -10211,7 +10264,7 @@ _LT_EOF fi ;; - cygwin* | msys* | mingw* | pw32* | cegcc*) + cygwin* | mingw* | pw32* | cegcc*) # _LT_TAGVAR(hardcode_libdir_flag_spec, ) is actually meaningless, # as there is no search path for DLLs. hardcode_libdir_flag_spec='-L$libdir' @@ -10221,7 +10274,6 @@ _LT_EOF enable_shared_with_static_runtimes=yes export_symbols_cmds='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[BCDGRS][ ]/s/.*[ ]\([^ ]*\)/\1 DATA/;s/^.*[ ]__nm__\([^ ]*\)[ ][^ ]*/\1 DATA/;/^I[ ]/d;/^[AITW][ ]/s/.* //'\'' | sort | uniq > $export_symbols' exclude_expsyms='[_]+GLOBAL_OFFSET_TABLE_|[_]+GLOBAL__[FID]_.*|[_]+head_[A-Za-z0-9_]+_dll|[A-Za-z0-9_]+_dll_iname' - file_list_spec='@' if $LD --help 2>&1 | $GREP 'auto-import' > /dev/null; then archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags -o $output_objdir/$soname $wl--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' @@ -10366,7 +10418,7 @@ _LT_EOF fi ;; - netbsd*) + netbsd* | netbsdelf*-gnu) if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then archive_cmds='$LD -Bshareable $libobjs $deplibs $linker_flags -o $lib' wlarc= @@ -10752,7 +10804,7 @@ fi export_dynamic_flag_spec=-rdynamic ;; - cygwin* | msys* | mingw* | pw32* | cegcc*) + cygwin* | mingw* | pw32* | cegcc*) # When not using gcc, we currently assume that we are using # Microsoft Visual C++. # hardcode_libdir_flag_spec is actually meaningless, as there is @@ -11036,6 +11088,7 @@ $as_echo "$lt_cv_irix_exported_symbol" >&6; } if test yes = "$lt_cv_irix_exported_symbol"; then archive_expsym_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations $wl-exports_file $wl$export_symbols -o $lib' fi + link_all_deplibs=no else archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib' archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -exports_file $export_symbols -o $lib' @@ -11057,7 +11110,7 @@ $as_echo "$lt_cv_irix_exported_symbol" >&6; } esac ;; - netbsd*) + netbsd* | netbsdelf*-gnu) if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' # a.out else @@ -11787,7 +11840,7 @@ bsdi[45]*) # libtool to hard-code these into programs ;; -cygwin* | msys* | mingw* | pw32* | cegcc*) +cygwin* | mingw* | pw32* | cegcc*) version_type=windows shrext_cmds=.dll need_version=no @@ -11817,12 +11870,6 @@ cygwin* | msys* | mingw* | pw32* | cegcc*) # Cygwin DLLs use 'cyg' prefix rather than 'lib' soname_spec='`echo $libname | sed -e 's/^lib/cyg/'``echo $release | $SED -e 's/[.]/-/g'`$versuffix$shared_ext' - sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/lib/w32api" - ;; - msys*) - # MSYS DLLs use 'msys-' prefix rather than 'lib' - soname_spec='`echo $libname | sed -e 's/^lib/msys-/'``echo $release | $SED -e 's/[.]/-/g'`$versuffix$shared_ext' - sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/lib/w32api" ;; mingw* | cegcc*) @@ -11859,7 +11906,7 @@ cygwin* | msys* | mingw* | pw32* | cegcc*) # Convert to MSYS style. sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | sed -e 's|\\\\|/|g' -e 's| \\([a-zA-Z]\\):| /\\1|g' -e 's|^ ||'` ;; - cygwin* | msys*) + cygwin*) # Convert to unix form, then to dos form, then back to unix form # but this time dos style (no spaces!) so that the unix form looks # like /cygdrive/c/PROGRA~1:/cygdr... @@ -12178,6 +12225,18 @@ fi dynamic_linker='GNU/Linux ld.so' ;; +netbsdelf*-gnu) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + dynamic_linker='NetBSD ld.elf_so' + ;; + netbsd*) version_type=sunos need_lib_prefix=no @@ -12561,7 +12620,7 @@ else lt_cv_dlopen_libs= ;; - cygwin* | msys*) + cygwin*) lt_cv_dlopen=dlopen lt_cv_dlopen_libs= ;; @@ -13986,7 +14045,7 @@ with_gnu_ld=$lt_cv_prog_gnu_ld # Commands to make compiler produce verbose output that lists # what "hidden" libraries, object files and flags are used when # linking a shared library. - output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"' + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP " \-L"' else GXX=no @@ -14280,7 +14339,7 @@ fi esac ;; - cygwin* | msys* | mingw* | pw32* | cegcc*) + cygwin* | mingw* | pw32* | cegcc*) case $GXX,$cc_basename in ,cl* | no,cl*) # Native MSVC @@ -14333,7 +14392,6 @@ fi allow_undefined_flag_CXX=unsupported always_export_symbols_CXX=no enable_shared_with_static_runtimes_CXX=yes - file_list_spec_CXX='@' if $LD --help 2>&1 | $GREP 'auto-import' > /dev/null; then archive_cmds_CXX='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $output_objdir/$soname $wl--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' @@ -14479,7 +14537,7 @@ fi # explicitly linking system object files so we need to strip them # from the output so that they don't get included in the library # dependencies. - output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $EGREP "\-L"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' + output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $EGREP " \-L"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' ;; *) if test yes = "$GXX"; then @@ -14544,7 +14602,7 @@ fi # explicitly linking system object files so we need to strip them # from the output so that they don't get included in the library # dependencies. - output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $GREP "\-L"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' + output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $GREP " \-L"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' ;; *) if test yes = "$GXX"; then @@ -14883,7 +14941,7 @@ fi # Commands to make compiler produce verbose output that lists # what "hidden" libraries, object files and flags are used when # linking a shared library. - output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"' + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP " \-L"' else # FIXME: insert proper C++ library support @@ -14967,7 +15025,7 @@ fi # Commands to make compiler produce verbose output that lists # what "hidden" libraries, object files and flags are used when # linking a shared library. - output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"' + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP " \-L"' else # g++ 2.7 appears to require '-G' NOT '-shared' on this # platform. @@ -14978,7 +15036,7 @@ fi # Commands to make compiler produce verbose output that lists # what "hidden" libraries, object files and flags are used when # linking a shared library. - output_verbose_link_cmd='$CC -G $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"' + output_verbose_link_cmd='$CC -G $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP " \-L"' fi hardcode_libdir_flag_spec_CXX='$wl-R $wl$libdir' @@ -15120,7 +15178,7 @@ if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 for p in `eval "$output_verbose_link_cmd"`; do case $prev$p in - -L* | -R* | -l* | */libclang_rt.*.a) + -L* | -R* | -l*) # Some compilers place space between "-{L,R}" and the path. # Remove the space. if test x-L = "$p" || @@ -15291,7 +15349,7 @@ lt_prog_compiler_static_CXX= beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*) # PIC is the default for these OSes. ;; - mingw* | cygwin* | msys* | os2* | pw32* | cegcc*) + mingw* | cygwin* | os2* | pw32* | cegcc*) # This hack is so that the source file can tell whether it is being # built for inclusion in a dll (and should export symbols for example). # Although the cygwin gcc ignores -fPIC, still need this for old-style @@ -15366,7 +15424,7 @@ lt_prog_compiler_static_CXX= ;; esac ;; - mingw* | cygwin* | msys* | os2* | pw32* | cegcc*) + mingw* | cygwin* | os2* | pw32* | cegcc*) # This hack is so that the source file can tell whether it is being # built for inclusion in a dll (and should export symbols for example). lt_prog_compiler_pic_CXX='-DDLL_EXPORT' @@ -15491,7 +15549,7 @@ lt_prog_compiler_static_CXX= ;; esac ;; - netbsd*) + netbsd* | netbsdelf*-gnu) ;; *qnx* | *nto*) # QNX uses GNU C++, but need to define -shared option too, otherwise @@ -15855,7 +15913,7 @@ $as_echo_n "checking whether the $compiler linker ($LD) supports shared librarie pw32*) export_symbols_cmds_CXX=$ltdll_cmds ;; - cygwin* | msys* | mingw* | cegcc*) + cygwin* | mingw* | cegcc*) case $cc_basename in cl*) exclude_expsyms_CXX='_NULL_IMPORT_DESCRIPTOR|_IMPORT_DESCRIPTOR_.*' @@ -15866,6 +15924,9 @@ $as_echo_n "checking whether the $compiler linker ($LD) supports shared librarie ;; esac ;; + linux* | k*bsd*-gnu | gnu*) + link_all_deplibs_CXX=no + ;; *) export_symbols_cmds_CXX='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' ;; @@ -16176,7 +16237,7 @@ bsdi[45]*) # libtool to hard-code these into programs ;; -cygwin* | msys* | mingw* | pw32* | cegcc*) +cygwin* | mingw* | pw32* | cegcc*) version_type=windows shrext_cmds=.dll need_version=no @@ -16206,11 +16267,6 @@ cygwin* | msys* | mingw* | pw32* | cegcc*) # Cygwin DLLs use 'cyg' prefix rather than 'lib' soname_spec='`echo $libname | sed -e 's/^lib/cyg/'``echo $release | $SED -e 's/[.]/-/g'`$versuffix$shared_ext' - ;; - msys*) - # MSYS DLLs use 'msys-' prefix rather than 'lib' - soname_spec='`echo $libname | sed -e 's/^lib/msys-/'``echo $release | $SED -e 's/[.]/-/g'`$versuffix$shared_ext' - ;; mingw* | cegcc*) # MinGW DLLs use traditional 'lib' prefix @@ -16246,7 +16302,7 @@ cygwin* | msys* | mingw* | pw32* | cegcc*) # Convert to MSYS style. sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | sed -e 's|\\\\|/|g' -e 's| \\([a-zA-Z]\\):| /\\1|g' -e 's|^ ||'` ;; - cygwin* | msys*) + cygwin*) # Convert to unix form, then to dos form, then back to unix form # but this time dos style (no spaces!) so that the unix form looks # like /cygdrive/c/PROGRA~1:/cygdr... @@ -16564,6 +16620,18 @@ fi dynamic_linker='GNU/Linux ld.so' ;; +netbsdelf*-gnu) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + dynamic_linker='NetBSD ld.elf_so' + ;; + netbsd*) version_type=sunos need_lib_prefix=no @@ -18300,7 +18368,7 @@ else We can't simply define LARGE_OFF_T to be 9223372036854775807, since some C++ compilers masquerading as C compilers incorrectly reject 9223372036854775807. */ -#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) +#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31)) int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? 1 : -1]; @@ -18346,7 +18414,7 @@ else We can't simply define LARGE_OFF_T to be 9223372036854775807, since some C++ compilers masquerading as C compilers incorrectly reject 9223372036854775807. */ -#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) +#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31)) int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? 1 : -1]; @@ -18370,7 +18438,7 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext We can't simply define LARGE_OFF_T to be 9223372036854775807, since some C++ compilers masquerading as C compilers incorrectly reject 9223372036854775807. */ -#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) +#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31)) int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? 1 : -1]; @@ -18415,7 +18483,7 @@ else We can't simply define LARGE_OFF_T to be 9223372036854775807, since some C++ compilers masquerading as C compilers incorrectly reject 9223372036854775807. */ -#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) +#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31)) int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? 1 : -1]; @@ -18439,7 +18507,7 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext We can't simply define LARGE_OFF_T to be 9223372036854775807, since some C++ compilers masquerading as C compilers incorrectly reject 9223372036854775807. */ -#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) +#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31)) int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? 1 : -1]; @@ -18701,6 +18769,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 @@ -21686,7 +21867,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 @@ -21752,7 +21933,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\\" @@ -22994,7 +23175,6 @@ See \`config.log' for more details" "$LINENO" 5; } cat <<_LT_EOF >> "$cfgfile" #! $SHELL # Generated automatically by $as_me ($PACKAGE) $VERSION -# Libtool was configured on host `(hostname || uname -n) 2>/dev/null | sed 1q`: # NOTE: Changes made to this file will be lost: look at ltmain.sh. # Provide generalized library-building support services. @@ -23754,6 +23934,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/configure.ac b/configure.ac index eecb8e99..a2242330 100644 --- a/configure.ac +++ b/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 @@ -614,6 +614,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/contrib/Makefile.in b/contrib/Makefile.in index c4d5cd6e..68020e24 100644 --- a/contrib/Makefile.in +++ b/contrib/Makefile.in @@ -347,6 +347,7 @@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ +runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ diff --git a/contrib/addtiffo/CMakeLists.txt b/contrib/addtiffo/CMakeLists.txt index b7482635..45e733cd 100644 --- a/contrib/addtiffo/CMakeLists.txt +++ b/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/contrib/addtiffo/Makefile.in b/contrib/addtiffo/Makefile.in index abe4c027..6281eff4 100644 --- a/contrib/addtiffo/Makefile.in +++ b/contrib/addtiffo/Makefile.in @@ -341,6 +341,7 @@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ +runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ diff --git a/contrib/addtiffo/tif_ovrcache.c b/contrib/addtiffo/tif_ovrcache.c index 67a88120..ac500ab4 100644 --- a/contrib/addtiffo/tif_ovrcache.c +++ b/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/contrib/dbs/CMakeLists.txt b/contrib/dbs/CMakeLists.txt index b2e809b2..ff3ce20c 100644 --- a/contrib/dbs/CMakeLists.txt +++ b/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/contrib/dbs/Makefile.in b/contrib/dbs/Makefile.in index 38a13830..b6d0a3d3 100644 --- a/contrib/dbs/Makefile.in +++ b/contrib/dbs/Makefile.in @@ -395,6 +395,7 @@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ +runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ diff --git a/contrib/dbs/xtiff/Makefile.in b/contrib/dbs/xtiff/Makefile.in index 61594863..f99b4a98 100644 --- a/contrib/dbs/xtiff/Makefile.in +++ b/contrib/dbs/xtiff/Makefile.in @@ -290,6 +290,7 @@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ +runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ diff --git a/contrib/iptcutil/Makefile.in b/contrib/iptcutil/Makefile.in index 790bb6c0..22650889 100644 --- a/contrib/iptcutil/Makefile.in +++ b/contrib/iptcutil/Makefile.in @@ -339,6 +339,7 @@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ +runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ diff --git a/contrib/mfs/Makefile.in b/contrib/mfs/Makefile.in index 201e700b..48db2dfa 100644 --- a/contrib/mfs/Makefile.in +++ b/contrib/mfs/Makefile.in @@ -287,6 +287,7 @@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ +runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ diff --git a/contrib/oss-fuzz/build.sh b/contrib/oss-fuzz/build.sh index fe6bd340..ab824398 100755 --- a/contrib/oss-fuzz/build.sh +++ b/contrib/oss-fuzz/build.sh @@ -45,18 +45,30 @@ if [ "$ARCHITECTURE" = "i386" ]; then else make lib fi + mv "$SRC"/jbigkit/libjbig/*.a "$WORK/lib/" mv "$SRC"/jbigkit/libjbig/*.h "$WORK/include/" popd +if [ "$ARCHITECTURE" != "i386" ]; then + apt-get install -y liblzma-dev +fi + cmake . -DCMAKE_INSTALL_PREFIX=$WORK -DBUILD_SHARED_LIBS=off make -j$(nproc) make install -$CXX $CXXFLAGS -std=c++11 -I$WORK/include \ - $SRC/libtiff/contrib/oss-fuzz/tiff_read_rgba_fuzzer.cc -o $OUT/tiff_read_rgba_fuzzer \ - $LIB_FUZZING_ENGINE $WORK/lib/libtiffxx.a $WORK/lib/libtiff.a $WORK/lib/libz.a $WORK/lib/libjpeg.a \ - $WORK/lib/libjbig.a $WORK/lib/libjbig85.a +if [ "$ARCHITECTURE" = "i386" ]; then + $CXX $CXXFLAGS -std=c++11 -I$WORK/include \ + $SRC/libtiff/contrib/oss-fuzz/tiff_read_rgba_fuzzer.cc -o $OUT/tiff_read_rgba_fuzzer \ + $LIB_FUZZING_ENGINE $WORK/lib/libtiffxx.a $WORK/lib/libtiff.a $WORK/lib/libz.a $WORK/lib/libjpeg.a \ + $WORK/lib/libjbig.a $WORK/lib/libjbig85.a +else + $CXX $CXXFLAGS -std=c++11 -I$WORK/include \ + $SRC/libtiff/contrib/oss-fuzz/tiff_read_rgba_fuzzer.cc -o $OUT/tiff_read_rgba_fuzzer \ + $LIB_FUZZING_ENGINE $WORK/lib/libtiffxx.a $WORK/lib/libtiff.a $WORK/lib/libz.a $WORK/lib/libjpeg.a \ + $WORK/lib/libjbig.a $WORK/lib/libjbig85.a -Wl,-Bstatic -llzma -Wl,-Bdynamic +fi mkdir afl_testcases (cd afl_testcases; tar xf "$SRC/afl_testcases.tgz") diff --git a/contrib/pds/Makefile.in b/contrib/pds/Makefile.in index e4c4651d..5b85c821 100644 --- a/contrib/pds/Makefile.in +++ b/contrib/pds/Makefile.in @@ -287,6 +287,7 @@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ +runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ diff --git a/contrib/ras/Makefile.in b/contrib/ras/Makefile.in index 0028f091..7b1a409d 100644 --- a/contrib/ras/Makefile.in +++ b/contrib/ras/Makefile.in @@ -287,6 +287,7 @@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ +runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ diff --git a/contrib/stream/Makefile.in b/contrib/stream/Makefile.in index 481faa82..4e953897 100644 --- a/contrib/stream/Makefile.in +++ b/contrib/stream/Makefile.in @@ -287,6 +287,7 @@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ +runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ diff --git a/contrib/tags/Makefile.in b/contrib/tags/Makefile.in index 0b53ed76..a90307bc 100644 --- a/contrib/tags/Makefile.in +++ b/contrib/tags/Makefile.in @@ -287,6 +287,7 @@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ +runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ diff --git a/contrib/win_dib/Makefile.in b/contrib/win_dib/Makefile.in index 7663106d..5cde9594 100644 --- a/contrib/win_dib/Makefile.in +++ b/contrib/win_dib/Makefile.in @@ -287,6 +287,7 @@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ +runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ diff --git a/contrib/win_dib/tiff2dib.c b/contrib/win_dib/tiff2dib.c index 475ef304..2fa2de69 100644 --- a/contrib/win_dib/tiff2dib.c +++ b/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/html/Makefile.am b/html/Makefile.am index 10b419b2..2929b8ed 100644 --- a/html/Makefile.am +++ b/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/html/Makefile.in b/html/Makefile.in index 30932e63..8293f486 100644 --- a/html/Makefile.in +++ b/html/Makefile.in @@ -379,6 +379,7 @@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ +runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ @@ -450,7 +451,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/html/addingtags.html b/html/addingtags.html index c61a2623..bd4b972a 100644 --- a/html/addingtags.html +++ b/html/addingtags.html @@ -1,11 +1,16 @@ + Modifying The TIFF Library + - - +

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.

-

Adding New Builtin Tags

- +

Adding New Builtin Tags

+

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.

@@ -238,8 +243,8 @@ about data types. Use the typedefs (uint16, etc. when dealing with data on disk and t*_t when stuff is in memory) and be careful about passing items through printf or similar vararg interfaces. -

Adding New Codec-private Tags

- +

Adding New Codec-private Tags

+

To add tags that are meaningful only when a particular compression algorithm is used follow these steps: diff --git a/html/bigtiffdesign.html b/html/bigtiffdesign.html index 407173ff..814c28af 100644 --- a/html/bigtiffdesign.html +++ b/html/bigtiffdesign.html @@ -1,4 +1,5 @@ - + + BigTIFF Design @@ -33,7 +34,7 @@ other parties.

  • Header bytes 8-15 contain the 8-byte offset to the first IFD.
  • Value/Offset fields are 8 bytes long, and take up bytes 8-15 in an IFD entry.
      -
    • If the value is <= 8 bytes, it must be stored in the field.
    • +
    • If the value is <= 8 bytes, it must be stored in the field.
    • All values must begin at an 8-byte-aligned address.
  • 8-byte offset to the Next_IFD, at the end of an IFD.
  • To keep IFD entries 8-byte-aligned, we begin with an 8-byte (instead of 2-byte) count of the number of directory entries.
  • diff --git a/html/bigtiffpr.html b/html/bigtiffpr.html index b7a36c6b..578c46f2 100644 --- a/html/bigtiffpr.html +++ b/html/bigtiffpr.html @@ -5,7 +5,7 @@ - +

    Extending LibTiff library with support for the new BigTIFF format

    LibTiff maintainers have started work on LibTiff 4.0, diff --git a/html/bugs.html b/html/bugs.html index bc27955e..a05a4659 100644 --- a/html/bugs.html +++ b/html/bugs.html @@ -1,11 +1,16 @@ + Bugs and the TIFF Mailing List + - - +

    - +cover Bugs, Bugzilla, and the TIFF Mailing List

    @@ -27,7 +32,7 @@ the problem is still reproducible with the current development software from CVS.

    If you'd like to enter a new bug, you can do so at -https://gitlab.com/libtiff/libtiff/issues/new. +https://gitlab.com/libtiff/libtiff/issues/new.

    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/html/build.html b/html/build.html index 77fbc40b..4186645b 100644 --- a/html/build.html +++ b/html/build.html @@ -1,14 +1,16 @@ - Building the TIFF Software Distribution + - -

    Building the Software Distribution

    + +

    cramps +Building the Software Distribution

    • Building on all systems with CMake.
    • Building on a UNIX system with Autoconf.
    • @@ -229,7 +231,6 @@ available zlib distribution written by Jean-loup Gailly and Mark Adler; this software is available at http://www.zlib.org/. -

      Building on a UNIX System with Autoconf

      @@ -421,7 +422,6 @@ enabled the DIRS_LIBINC and DIR_GZLIB parameters should also be set (see below). By default this package is not configured. -

      Building the Software under Windows 2000/XP/7/8/10 with nmake

      diff --git a/html/contrib.html b/html/contrib.html index f20a1cb3..9a670658 100644 --- a/html/contrib.html +++ b/html/contrib.html @@ -1,14 +1,18 @@ + Contributed TIFF Software + - - - +

      - +smallliz Contributed TIFF Software

      @@ -155,11 +159,10 @@ various routines from Conrad Poelman; a TIFF image iterator and -A utility by Bill Radcliffe to +A utility by Bill Radcliffe 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 ImageMagick convert(1) +images via the ImageMagick convert(1) utility. diff --git a/html/document.html b/html/document.html index 71d04126..a9750933 100644 --- a/html/document.html +++ b/html/document.html @@ -1,13 +1,18 @@ + TIFF Documentation + - - +

      - +jim TIFF Documentation

      diff --git a/html/images.html b/html/images.html index 6e2e29be..c93f38bf 100644 --- a/html/images.html +++ b/html/images.html @@ -1,13 +1,18 @@ + TIFF Test Images + - - +

      - +bali TIFF Test Images

      diff --git a/html/images/Makefile.in b/html/images/Makefile.in index 234a29a5..caf00934 100644 --- a/html/images/Makefile.in +++ b/html/images/Makefile.in @@ -318,6 +318,7 @@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ +runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ diff --git a/html/index.html b/html/index.html index dca511e7..fd7b5f77 100644 --- a/html/index.html +++ b/html/index.html @@ -10,7 +10,7 @@ --> - +

      LibTIFF - TIFF Library and Utilities


      @@ -28,7 +28,7 @@ - + @@ -44,7 +44,7 @@ - +
      Latest Stable Releasev4.1.0v4.2.0
      Master Download Site
      git repositoryhttps://gitlab.com/libtiff/libtiffhttps://gitlab.com/libtiff/libtiff

      diff --git a/html/internals.html b/html/internals.html index 8d94e5ce..20061ef0 100644 --- a/html/internals.html +++ b/html/internals.html @@ -1,13 +1,18 @@ + Modifying The TIFF Library + - - +

      - +dave Modifying The TIFF Library

      @@ -19,18 +24,19 @@ how to add new support to the library. The following sections are found in this chapter: -


      Library Configuration

      - +
      +

      Library Configuration

      +

      Information on compiling the library is given elsewhere in this documentation. 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. -

        +
         #define	COMPRESSION_SUPPORT
         #define	CCITT_SUPPORT
         #define	PACKBITS_SUPPORT
        -
      + 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 libtiff 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 -ftp.uu.net:/graphics/jpeg/. +ftp.uu.net:/graphics/jpeg/.

      @@ -103,14 +109,14 @@ for use with version 0.99 or later of the freely available libz library written by Jean-loup Gailly and Mark Adler. The data format used by this library is described in the files -zlib-3.1.doc, +zlib-3.1.doc, and -deflate-1.1.doc, +deflate-1.1.doc, available in the directory -ftp.uu.net:/pub/archiving/zip/doc. +ftp.uu.net:/pub/archiving/zip/doc. The library can be retried from the directory -ftp.uu.net:/pub/archiving/zip/zlib/ -(or try quest.jpl.nasa.gov:/beta/zlib/). +ftp.uu.net:/pub/archiving/zip/zlib/ +(or try quest.jpl.nasa.gov:/beta/zlib/).

      NOTE: @@ -205,15 +211,15 @@ run-length encoding scheme from ThunderScan (compression 32809) The ICC Profile Format Specification, Annex B.3 "Embedding ICC Profiles in TIFF Files"; available at -http://www.color.org +http://www.color.org - -


      General Portability Comments

      - +
      +

      General Portability Comments

      +

      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:

      - +
      @@ -317,8 +323,9 @@ Note that tiffcomp.h defines HAVE_IEEEFP to be 1 (BSDTYPES is not defined). -


      Types and Portability

      - +
      +

      Types and Portability

      +

      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:

      -

      BSDTYPES
      +
      @@ -385,10 +392,10 @@ structure:

      -

      uint8
      +
      - + @@ -451,8 +458,9 @@ passed as opaque handles and only cast at the lowest layers where their type is presumed. -


      General Comments

      - +
      +

      General Comments

      +

      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). -


      Adding New Builtin Codecs

      +
      +

      Adding New Builtin Codecs

      +

      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 PlanarConfig=2 (separate planes). This is important for algorithms such as JPEG. If PlanarConfig=1 (interleaved), then sample will always be 0. -


      Other Comments

      - +
      +

      Other Comments

      +

      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/html/intro.html b/html/intro.html index 83902f61..ad3b2d91 100644 --- a/html/intro.html +++ b/html/intro.html @@ -1,13 +1,18 @@ + Introduction to the TIFF Documentation + - - +

      - +strike Introduction to the TIFF Documentation

      @@ -37,7 +42,7 @@ They are consistent with the terminology used in the TIFF 6.0 specification.
      Codec
      Software that implements the decoding and encoding algorithms of a compression scheme. - +

      In order to better understand how TIFF works (and consequently this diff --git a/html/libtiff.html b/html/libtiff.html index 56535d97..cda66b5a 100644 --- a/html/libtiff.html +++ b/html/libtiff.html @@ -10,7 +10,7 @@ --> - +

      typedef unsigned int ttag_t; directory tagtypedef unsigned int ttag_t; directory tag
      @@ -518,9 +518,9 @@         TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &imagelength);
              buf = _TIFFmalloc(TIFFScanlineSize(tif));
              for (row = 0; row < imagelength; row++)
      -             tiffreadscanline(tif, buf, row);
      -         _tifffree(buf);
      -         tiffclose(tif);
      +             TIFFReadScanline(tif, buf, row, 0);
      +         _TIFFfree(buf);
      +         TIFFClose(tif);
          }
      }

      @@ -547,17 +547,17 @@         buf = _TIFFmalloc(TIFFScanlineSize(tif));
              if (config == PLANARCONFIG_CONTIG) {
                  for (row = 0; row < imagelength; row++)
      -                 tiffreadscanline(tif, buf, row);
      +                 TIFFReadScanline(tif, buf, row, 0);
              } else if (config == planarconfig_separate) {
                  uint16 s, nsamples;
                  
                  tiffgetfield(tif, tifftag_samplesperpixel, &nsamples);
                  for (s = 0; s < nsamples; s++)
                      for (row = 0; row < imagelength; row++)
      -                     tiffreadscanline(tif, buf, row, s);
      +                     TIFFReadScanline(tif, buf, row, s);
              }
      -         _tifffree(buf);
      -         tiffclose(tif);
      +         _TIFFfree(buf);
      +         TIFFClose(tif);
          }
      }

      @@ -568,7 +568,7 @@

                  for (row = 0; row < imagelength; row++)
                      for (s = 0; s < nsamples; s++)
      -                     tiffreadscanline(tif, buf, row, s);
      +                     TIFFReadScanline(tif, buf, row, s);

      ...then problems would arise if RowsPerStrip was not one @@ -601,8 +601,8 @@         buf = _TIFFmalloc(TIFFStripSize(tif));
              for (strip = 0; strip < tiffnumberofstrips(tif); strip++)
                  tiffreadencodedstrip(tif, strip, buf, (tsize_t) -1);
      -         _tifffree(buf);
      -         tiffclose(tif);
      +         _TIFFfree(buf);
      +         TIFFClose(tif);
          }
      }

      @@ -702,8 +702,8 @@         for (y = 0; y < imagelength; y += tilelength)
                  for (x = 0; x < imagewidth; x += tilewidth)
                      tiffreadtile(tif, buf, x, y, 0);
      -         _tifffree(buf);
      -         tiffclose(tif);
      +         _TIFFfree(buf);
      +         TIFFClose(tif);
          }
      }

      @@ -729,8 +729,8 @@         buf = _TIFFmalloc(TIFFTileSize(tif));
              for (tile = 0; tile < tiffnumberoftiles(tif); tile++)
                  tiffreadencodedtile(tif, tile, buf, (tsize_t) -1);
      -         _tifffree(buf);
      -         tiffclose(tif);
      +         _TIFFfree(buf);
      +         TIFFClose(tif);
          }
      }

      diff --git a/html/man/Makefile.in b/html/man/Makefile.in index c435bad5..5e7065c1 100644 --- a/html/man/Makefile.in +++ b/html/man/Makefile.in @@ -318,6 +318,7 @@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ +runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ diff --git a/html/misc.html b/html/misc.html index b30eb676..69d3ba18 100644 --- a/html/misc.html +++ b/html/misc.html @@ -1,13 +1,18 @@ + Acknowledgments and Other Issues + - - +

      - +ring Acknowledgments and Other Issues

      @@ -84,7 +89,7 @@ the more persistent contributors have been:

      Use and Copyright

      -

      +
      
       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.
      -
      + -


      diff --git a/html/support.html b/html/support.html index 2330d40a..e29d2d0d 100644 --- a/html/support.html +++ b/html/support.html @@ -10,7 +10,7 @@ --> - +
      diff --git a/html/tools.html b/html/tools.html index 7b99d71d..d567ad8a 100644 --- a/html/tools.html +++ b/html/tools.html @@ -1,14 +1,16 @@ - TIFF Tools Overview + - -

      TIFF -Tools Overview

      + +

      quad +TIFF Tools Overview

      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.

      Device-independent Programs

      The remaining programs should be device-independent:
      + + @@ -47,6 +51,7 @@ applying the colormap + @@ -56,7 +61,7 @@ applying the colormap TIFF image; it's mainly provided for testing - +
      fax2ps 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 fax2tiff Convert raw Group 3 or Group 4 facsimile data to TIFF
      pal2rgb Convert a Palette-style image to a full color RGB image by applying the colormapppm2tiff A quick hack that converts 8-bit PPM format images to TIFF
      raw2tiff Create a TIFF file from raw data
      thumbnailthumbnail 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 SubIFD tag (and the library support diff --git a/html/v3.4beta007.html b/html/v3.4beta007.html index 10307205..c2b51f0a 100644 --- a/html/v3.4beta007.html +++ b/html/v3.4beta007.html @@ -1,3 +1,4 @@ + diff --git a/html/v3.4beta016.html b/html/v3.4beta016.html index 170f3384..11035384 100644 --- a/html/v3.4beta016.html +++ b/html/v3.4beta016.html @@ -1,3 +1,4 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML> <HEAD> <TITLE> diff --git a/html/v3.4beta018.html b/html/v3.4beta018.html index 4843c95d..63ffb497 100644 --- a/html/v3.4beta018.html +++ b/html/v3.4beta018.html @@ -1,3 +1,4 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML> <HEAD> <TITLE> diff --git a/html/v3.4beta024.html b/html/v3.4beta024.html index ee2b243b..ec82840c 100644 --- a/html/v3.4beta024.html +++ b/html/v3.4beta024.html @@ -1,3 +1,4 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML> <HEAD> <TITLE> diff --git a/html/v3.4beta028.html b/html/v3.4beta028.html index 5ac9d75f..5ae0e490 100644 --- a/html/v3.4beta028.html +++ b/html/v3.4beta028.html @@ -1,3 +1,4 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML> <HEAD> <TITLE> diff --git a/html/v3.4beta029.html b/html/v3.4beta029.html index f7e863d0..580cfc49 100644 --- a/html/v3.4beta029.html +++ b/html/v3.4beta029.html @@ -1,3 +1,4 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML> <HEAD> <TITLE> diff --git a/html/v3.4beta031.html b/html/v3.4beta031.html index 137368da..2dff6349 100644 --- a/html/v3.4beta031.html +++ b/html/v3.4beta031.html @@ -1,3 +1,4 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML> <HEAD> <TITLE> diff --git a/html/v3.4beta032.html b/html/v3.4beta032.html index 4651539e..8ac2cc2d 100644 --- a/html/v3.4beta032.html +++ b/html/v3.4beta032.html @@ -1,3 +1,4 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML> <HEAD> <TITLE> diff --git a/html/v3.4beta033.html b/html/v3.4beta033.html index f311e6a3..256b3f8e 100644 --- a/html/v3.4beta033.html +++ b/html/v3.4beta033.html @@ -1,3 +1,4 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML> <HEAD> <TITLE> diff --git a/html/v3.4beta034.html b/html/v3.4beta034.html index a2735de2..33ca2f19 100644 --- a/html/v3.4beta034.html +++ b/html/v3.4beta034.html @@ -1,3 +1,4 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML> <HEAD> <TITLE> diff --git a/html/v3.4beta035.html b/html/v3.4beta035.html index 5b0901d3..51e4116c 100644 --- a/html/v3.4beta035.html +++ b/html/v3.4beta035.html @@ -1,3 +1,4 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML> <HEAD> <TITLE> diff --git a/html/v3.4beta036.html b/html/v3.4beta036.html index a853113d..91c2721f 100644 --- a/html/v3.4beta036.html +++ b/html/v3.4beta036.html @@ -1,3 +1,4 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML> <HEAD> <TITLE> diff --git a/html/v3.5.1.html b/html/v3.5.1.html index e3ee7077..559f5496 100644 --- a/html/v3.5.1.html +++ b/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/html/v3.5.2.html b/html/v3.5.2.html index daad4c55..2c4cbf51 100644 --- a/html/v3.5.2.html +++ b/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/html/v3.5.3.html b/html/v3.5.3.html index 9ea78562..0aabcaa8 100644 --- a/html/v3.5.3.html +++ b/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/html/v3.5.4.html b/html/v3.5.4.html index 7e3eb841..c9fdcf65 100644 --- a/html/v3.5.4.html +++ b/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/html/v3.5.5.html b/html/v3.5.5.html index 779e3772..aa606fd1 100644 --- a/html/v3.5.5.html +++ b/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/html/v3.5.6-beta.html b/html/v3.5.6-beta.html index 498cc439..81f11a36 100644 --- a/html/v3.5.6-beta.html +++ b/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/html/v3.5.7.html b/html/v3.5.7.html index b68e29ee..a58b7e5a 100644 --- a/html/v3.5.7.html +++ b/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/html/v3.6.0.html b/html/v3.6.0.html index 11b10af0..1a3ba4a9 100644 --- a/html/v3.6.0.html +++ b/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/html/v3.6.1.html b/html/v3.6.1.html index 3f0e93c3..6a357f4c 100644 --- a/html/v3.6.1.html +++ b/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/html/v3.7.0.html b/html/v3.7.0.html index c70e8e72..9c0819a4 100644 --- a/html/v3.7.0.html +++ b/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/html/v3.7.0alpha.html b/html/v3.7.0alpha.html index 5ce60069..39b63238 100644 --- a/html/v3.7.0alpha.html +++ b/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/html/v3.7.0beta.html b/html/v3.7.0beta.html index a29e521f..f646480f 100644 --- a/html/v3.7.0beta.html +++ b/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/html/v3.7.0beta2.html b/html/v3.7.0beta2.html index 9a313aca..41ba6c3a 100644 --- a/html/v3.7.0beta2.html +++ b/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/html/v3.7.1.html b/html/v3.7.1.html index 3e332b14..164b4059 100644 --- a/html/v3.7.1.html +++ b/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/html/v3.7.2.html b/html/v3.7.2.html index 2be1edef..d396021e 100644 --- a/html/v3.7.2.html +++ b/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/html/v3.7.3.html b/html/v3.7.3.html index c3aafff4..54978c8f 100644 --- a/html/v3.7.3.html +++ b/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/html/v3.7.4.html b/html/v3.7.4.html index 465af218..eeb0f3ca 100644 --- a/html/v3.7.4.html +++ b/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/html/v3.8.0.html b/html/v3.8.0.html index 8ac23f38..81a8b0c6 100644 --- a/html/v3.8.0.html +++ b/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/html/v3.8.1.html b/html/v3.8.1.html index 6b069e32..0fe7d9c0 100644 --- a/html/v3.8.1.html +++ b/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/html/v3.8.2.html b/html/v3.8.2.html index 10fa57d2..41bb2e55 100644 --- a/html/v3.8.2.html +++ b/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/html/v3.9.0.html b/html/v3.9.0.html index e37ec84f..540e7cf2 100644 --- a/html/v3.9.0.html +++ b/html/v3.9.0.html @@ -1,3 +1,4 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML> <HEAD> <TITLE> diff --git a/html/v3.9.0beta.html b/html/v3.9.0beta.html index e973ca8b..56f32ed3 100644 --- a/html/v3.9.0beta.html +++ b/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/html/v3.9.1.html b/html/v3.9.1.html index fc6bca19..1f369a83 100644 --- a/html/v3.9.1.html +++ b/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/html/v3.9.2.html b/html/v3.9.2.html index 34a117a4..a190a301 100644 --- a/html/v3.9.2.html +++ b/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/html/v3.9.3.html b/html/v3.9.3.html index 0ceeb54c..52a9f087 100644 --- a/html/v3.9.3.html +++ b/html/v3.9.3.html @@ -1,3 +1,4 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML> <HEAD> <TITLE> diff --git a/html/v3.9.4.html b/html/v3.9.4.html index fc368a5c..3f5ef5c7 100644 --- a/html/v3.9.4.html +++ b/html/v3.9.4.html @@ -1,3 +1,4 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML> <HEAD> <TITLE> diff --git a/html/v3.9.5.html b/html/v3.9.5.html index fba38447..666220f3 100644 --- a/html/v3.9.5.html +++ b/html/v3.9.5.html @@ -1,3 +1,4 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML> <HEAD> <TITLE> diff --git a/html/v4.0.0.html b/html/v4.0.0.html index f64208ac..a7e9bb63 100644 --- a/html/v4.0.0.html +++ b/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/html/v4.0.1.html b/html/v4.0.1.html index b4a8bc2f..5e927173 100644 --- a/html/v4.0.1.html +++ b/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/html/v4.0.10.html b/html/v4.0.10.html index b7d87361..578404e1 100644 --- a/html/v4.0.10.html +++ b/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/html/v4.0.2.html b/html/v4.0.2.html index 91f20dde..cbed8b89 100644 --- a/html/v4.0.2.html +++ b/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/html/v4.0.3.html b/html/v4.0.3.html index 14ccfb39..e034c3f0 100644 --- a/html/v4.0.3.html +++ b/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/html/v4.0.4.html b/html/v4.0.4.html index a5691140..61c31101 100644 --- a/html/v4.0.4.html +++ b/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/html/v4.0.4beta.html b/html/v4.0.4beta.html index e06a2c22..e9e70a55 100644 --- a/html/v4.0.4beta.html +++ b/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/html/v4.0.5.html b/html/v4.0.5.html index c638638a..a3354704 100644 --- a/html/v4.0.5.html +++ b/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/html/v4.0.6.html b/html/v4.0.6.html index 8fc63b5c..dbca5c86 100644 --- a/html/v4.0.6.html +++ b/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/html/v4.0.7.html b/html/v4.0.7.html index e1b5dec9..4f92c129 100644 --- a/html/v4.0.7.html +++ b/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/html/v4.0.8.html b/html/v4.0.8.html index 86db3bbf..bd3f751c 100644 --- a/html/v4.0.8.html +++ b/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/html/v4.0.9.html b/html/v4.0.9.html index 4efe987f..19b370a4 100644 --- a/html/v4.0.9.html +++ b/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/html/v4.1.0.html b/html/v4.1.0.html index 7c61fac7..80dac5bf 100644 --- a/html/v4.1.0.html +++ b/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 - - -TIFF CHANGE INFORMATION +TIFF CHANGE INFORMATION - +
      +

      This document describes the changes made to the software between the @@ -78,11 +85,11 @@ history:

    • Changes in the contrib area

      -


      +


      - + -MAJOR CHANGES: +MAJOR CHANGES:
        @@ -117,10 +124,10 @@ history:
      -


      - +


      + -CHANGES IN THE SOFTWARE CONFIGURATION: +CHANGES IN THE SOFTWARE CONFIGURATION:
        @@ -131,11 +138,11 @@ history:
      -


      +


      - + -CHANGES IN LIBTIFF: +CHANGES IN LIBTIFF:
        @@ -166,11 +173,11 @@ history:
      -


      +


      - + -CHANGES IN THE TOOLS: +CHANGES IN THE TOOLS:
        @@ -180,11 +187,11 @@ history:
      -


      +


      - + -CHANGES IN THE CONTRIB AREA: +CHANGES IN THE CONTRIB AREA:
        diff --git a/html/v4.2.0.html b/html/v4.2.0.html new file mode 100644 index 00000000..c81ecdd2 --- /dev/null +++ b/html/v4.2.0.html @@ -0,0 +1,205 @@ + + + + + Changes in TIFF v4.2.0 + + + + + + + +TIFF CHANGE INFORMATION + + +
        +
        +Current Version: v4.2.0
        +Previous Version: v4.1.0
        +Master Download Site: +download.osgeo.org, directory pub/libtiff<
        +Master HTTP Site #1: +http://www.simplesystems.org/libtiff/
        +Master HTTP Site #2: +http://libtiff.maptools.org/ +
        +
        + +

        +This document provides a summary of significant changes made to the +software between the previous and current 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: +

        +

        +


        + + + +MAJOR CHANGES: + +
          + +
        • Optional support for using libdeflate is added.
        • + +
        • Many of the tools now support a memory usage limit.
        • + +
        + + +


        + + +CHANGES IN THE SOFTWARE CONFIGURATION: + +
          + +
        • 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.
        • + +
        • mingw-w64 cmake build fixes to not add libm
        • + +
        + +


        + + + +CHANGES IN LIBTIFF: + +
          + +
        • A great many issues discovered by fuzzers (via oss-fuzz and other reports) have been addressed.
        • + +
        • EXIF 2.32 and GPS tags and functionality have been upgraded: +
            +
          • Existing EXIF field definition of tags are 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).
          • +
          • Reading error for FileSource and SceneType tags corrected.
          • +
          + +
        • Make TIFFTAG_CFAPATTERN variable count.
        • + +
        • Cmake configuration fixes for big-endian targets.
        • + +
        • Added support for optional building against libdeflate for + faster Zip/Deflate compression/decompression.

          + +

          We now have 2 kinds 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.

          + +
        • + +
        + +


        + + + +CHANGES IN THE TOOLS: + +
          + +
        • A great many issues discovered by fuzzers (via oss-fuzz and other reports) have been addressed.
        • + +
        • ppm2tiff: support any bps value from 1 to 16.
        • + +
        • tiff2ps, tiff2rgba: A default memory limit is now enforced (256MiB) and a '-M' option is added to allow the user to adjust the limit.
        • + +
        • tiff2pdf, tiffcp: A default memory limit is now enforced (256MiB) and a '-m' option is added to allow the user to adjust the limit.
        • + +
        • tiffcrop: A default memory limit is now enforced (256MiB) and a '-k' option is added to allow the user to adjust the limit.
        • + +
        • tiff2pdf: fix "raw" copy of Deflate streams.
        • + +
        • tiff2pdf.c: properly calculate datasize when saving to JPEG YCbCr
        • + +
        • tiffcp: disable strip chopping when trying to convert to JBIG compression
        • + +
        + +


        + + + +CHANGES IN THE CONTRIB AREA: + +
          + +
        • None
        • + +
        + + + diff --git a/libtiff/Makefile.in b/libtiff/Makefile.in index a593fc22..ce42dd82 100644 --- a/libtiff/Makefile.in +++ b/libtiff/Makefile.in @@ -463,6 +463,7 @@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ +runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ diff --git a/libtiff/libtiff.def b/libtiff/libtiff.def index e34fac58..b2d03fe7 100644 --- a/libtiff/libtiff.def +++ b/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/libtiff/tif_aux.c b/libtiff/tif_aux.c index 8188db53..c9f19054 100644 --- a/libtiff/tif_aux.c +++ b/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/libtiff/tif_compress.c b/libtiff/tif_compress.c index 8130ef08..915478f5 100644 --- a/libtiff/tif_compress.c +++ b/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/libtiff/tif_config.h.in b/libtiff/tif_config.h.in index 523da3e3..30afd7a1 100644 --- a/libtiff/tif_config.h.in +++ b/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/libtiff/tif_config.vc.h b/libtiff/tif_config.vc.h index 5cebfa02..939594f8 100644 --- a/libtiff/tif_config.vc.h +++ b/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/libtiff/tif_dir.c b/libtiff/tif_dir.c index 1e0a76c3..347b7115 100644 --- a/libtiff/tif_dir.c +++ b/libtiff/tif_dir.c @@ -29,6 +29,7 @@ * (and also some miscellaneous stuff) */ #include "tiffiop.h" +#include /*--: 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; @@ -1364,6 +1403,17 @@ TIFFCreateEXIFDirectory(TIFF* tif) return TIFFCreateCustomDirectory(tif, exifFieldArray); } +/* + * Creates the EXIF GPS custom directory + */ +int +TIFFCreateGPSDirectory(TIFF* tif) +{ + const TIFFFieldArray* gpsFieldArray; + gpsFieldArray = _TIFFGetGpsFields(); + return TIFFCreateCustomDirectory(tif, gpsFieldArray); +} + /* * Setup a default directory structure. */ diff --git a/libtiff/tif_dir.h b/libtiff/tif_dir.h index e7f06673..f608dd71 100644 --- a/libtiff/tif_dir.h +++ b/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/libtiff/tif_dirinfo.c b/libtiff/tif_dirinfo.c index e1f6b23e..7217042c 100644 --- a/libtiff/tif_dirinfo.c +++ b/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/libtiff/tif_dirread.c b/libtiff/tif_dirread.c index 8d2a6d10..ced266a0 100644 --- a/libtiff/tif_dirread.c +++ b/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/libtiff/tif_dirwrite.c b/libtiff/tif_dirwrite.c index 9e4d3060..f481250e 100644 --- a/libtiff/tif_dirwrite.c +++ b/libtiff/tif_dirwrite.c @@ -28,6 +28,8 @@ * Directory Write Support Routines. */ #include "tiffiop.h" +#include /*--: for Rational2Double */ +#include /*--: 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; nctif_flags&TIFF_SWAB) TIFFSwabArrayOfLong(m,count*2); @@ -2424,6 +2507,7 @@ TIFFWriteDirectoryTagCheckedSrationalArray(TIFF* tif, uint32* ndir, TIFFDirEntry } for (na=value, nb=m, nc=0; nctif_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; nctif_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; nctif_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/libtiff/tif_fax3.c b/libtiff/tif_fax3.c index d11c9684..9ab5b26a 100644 --- a/libtiff/tif_fax3.c +++ b/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/libtiff/tif_fax3.h b/libtiff/tif_fax3.h index abadcd97..701716cc 100644 --- a/libtiff/tif_fax3.h +++ b/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/libtiff/tif_fax3sm.c b/libtiff/tif_fax3sm.c index 822191ec..ba2fc532 100644 --- a/libtiff/tif_fax3sm.c +++ b/libtiff/tif_fax3sm.c @@ -1,5 +1,6 @@ /* WARNING, this file was automatically generated by the mkg3states program */ +#include #include "tiff.h" #include "tif_fax3.h" const TIFFFaxTabEnt TIFFFaxMainTable[128] = { diff --git a/libtiff/tif_getimage.c b/libtiff/tif_getimage.c index 4da785d3..3460af74 100644 --- a/libtiff/tif_getimage.c +++ b/libtiff/tif_getimage.c @@ -29,6 +29,7 @@ */ #include "tiffiop.h" #include +#include 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/libtiff/tif_jbig.c b/libtiff/tif_jbig.c index 7ffe8851..a3500e0b 100644 --- a/libtiff/tif_jbig.c +++ b/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/libtiff/tif_jpeg.c b/libtiff/tif_jpeg.c index eea26730..80084f5e 100644 --- a/libtiff/tif_jpeg.c +++ b/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 + /* 1 MB for regular libjpeg usage */ + toff_t nRequiredMemory = 1024 * 1024; - if( nRequiredMemory > TIFF_LIBJPEG_LARGEST_MEM_ALLOC && + 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/libtiff/tif_luv.c b/libtiff/tif_luv.c index 6fe48588..3bd02e88 100644 --- a/libtiff/tif_luv.c +++ b/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/libtiff/tif_lzma.c b/libtiff/tif_lzma.c index 3f6096b6..e150bd63 100644 --- a/libtiff/tif_lzma.c +++ b/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/libtiff/tif_lzw.c b/libtiff/tif_lzw.c index 21064f29..d92d0fd3 100644 --- a/libtiff/tif_lzw.c +++ b/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/libtiff/tif_ojpeg.c b/libtiff/tif_ojpeg.c index bf0d1a2a..133d1f1c 100644 --- a/libtiff/tif_ojpeg.c +++ b/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. @@ -421,6 +421,7 @@ TIFFInitOJPEG(TIFF* tif, int scheme) static const char module[]="TIFFInitOJPEG"; OJPEGState* sp; + (void)scheme; assert(scheme==COMPRESSION_OJPEG); /* @@ -498,15 +499,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; @@ -658,7 +659,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); } @@ -837,36 +838,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; @@ -1094,6 +1065,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) @@ -1291,6 +1264,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/libtiff/tif_open.c b/libtiff/tif_open.c index 04f19746..912c8d20 100644 --- a/libtiff/tif_open.c +++ b/libtiff/tif_open.c @@ -105,6 +105,7 @@ TIFFClientOpen( } n; n.a8[0]=1; n.a8[1]=0; + (void)n; #ifdef WORDS_BIGENDIAN assert(n.a16==256); #else @@ -167,7 +168,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): @@ -208,7 +209,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/libtiff/tif_pixarlog.c b/libtiff/tif_pixarlog.c index 62640905..f2912015 100644 --- a/libtiff/tif_pixarlog.c +++ b/libtiff/tif_pixarlog.c @@ -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/libtiff/tif_predict.c b/libtiff/tif_predict.c index 76ac2032..776f48d8 100644 --- a/libtiff/tif_predict.c +++ b/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/libtiff/tif_read.c b/libtiff/tif_read.c index 527fadd6..c4c868b1 100644 --- a/libtiff/tif_read.c +++ b/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/libtiff/tif_unix.c b/libtiff/tif_unix.c index da0d9ebe..a54905a8 100644 --- a/libtiff/tif_unix.c +++ b/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/libtiff/tif_webp.c b/libtiff/tif_webp.c index 22665f2d..a00478f6 100644 --- a/libtiff/tif_webp.c +++ b/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/libtiff/tif_win32.c b/libtiff/tif_win32.c index 465a8d69..11d9b169 100644 --- a/libtiff/tif_win32.c +++ b/libtiff/tif_win32.c @@ -155,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 @@ -189,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 diff --git a/libtiff/tif_write.c b/libtiff/tif_write.c index 33e803c1..3af69ab4 100644 --- a/libtiff/tif_write.c +++ b/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/libtiff/tif_zip.c b/libtiff/tif_zip.c index c7507734..e71c312c 100644 --- a/libtiff/tif_zip.c +++ b/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 /* @@ -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/libtiff/tif_zstd.c b/libtiff/tif_zstd.c index 21c935e2..66135e03 100644 --- a/libtiff/tif_zstd.c +++ b/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/libtiff/tiff.h b/libtiff/tiff.h index b05f0e0a..b701692b 100644 --- a/libtiff/tiff.h +++ b/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 > "$cfgfile" #! $SHELL # Generated automatically by $as_me ($PACKAGE) $VERSION -# Libtool was configured on host `(hostname || uname -n) 2>/dev/null | sed 1q`: # NOTE: Changes made to this file will be lost: look at ltmain.sh. # Provide generalized library-building support services. @@ -1692,7 +1691,7 @@ AC_CACHE_VAL([lt_cv_sys_max_cmd_len], [dnl lt_cv_sys_max_cmd_len=-1; ;; - cygwin* | msys* | mingw* | cegcc*) + cygwin* | mingw* | cegcc*) # On Win9x/ME, this test blows up -- it succeeds, but takes # about 5 minutes as the teststring grows exponentially. # Worse, since 9x/ME are not pre-emptively multitasking, @@ -1940,7 +1939,7 @@ else lt_cv_dlopen_libs= ;; - cygwin* | msys*) + cygwin*) lt_cv_dlopen=dlopen lt_cv_dlopen_libs= ;; @@ -2521,7 +2520,7 @@ bsdi[[45]]*) # libtool to hard-code these into programs ;; -cygwin* | msys* | mingw* | pw32* | cegcc*) +cygwin* | mingw* | pw32* | cegcc*) version_type=windows shrext_cmds=.dll need_version=no @@ -2550,12 +2549,6 @@ cygwin* | msys* | mingw* | pw32* | cegcc*) cygwin*) # Cygwin DLLs use 'cyg' prefix rather than 'lib' soname_spec='`echo $libname | sed -e 's/^lib/cyg/'``echo $release | $SED -e 's/[[.]]/-/g'`$versuffix$shared_ext' -m4_if([$1], [],[ - sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/lib/w32api"]) - ;; - msys*) - # MSYS DLLs use 'msys-' prefix rather than 'lib' - soname_spec='`echo $libname | sed -e 's/^lib/msys-/'``echo $release | $SED -e 's/[[.]]/-/g'`$versuffix$shared_ext' m4_if([$1], [],[ sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/lib/w32api"]) ;; @@ -2593,7 +2586,7 @@ m4_if([$1], [],[ # Convert to MSYS style. sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | sed -e 's|\\\\|/|g' -e 's| \\([[a-zA-Z]]\\):| /\\1|g' -e 's|^ ||'` ;; - cygwin* | msys*) + cygwin*) # Convert to unix form, then to dos form, then back to unix form # but this time dos style (no spaces!) so that the unix form looks # like /cygdrive/c/PROGRA~1:/cygdr... @@ -2893,6 +2886,18 @@ linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*) dynamic_linker='GNU/Linux ld.so' ;; +netbsdelf*-gnu) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + dynamic_linker='NetBSD ld.elf_so' + ;; + netbsd*) version_type=sunos need_lib_prefix=no @@ -3371,7 +3376,7 @@ case $reload_flag in esac reload_cmds='$LD$reload_flag -o $output$reload_objs' case $host_os in - cygwin* | msys* | mingw* | pw32* | cegcc*) + cygwin* | mingw* | pw32* | cegcc*) if test yes != "$GCC"; then reload_cmds=false fi @@ -3464,7 +3469,7 @@ bsdi[[45]]*) lt_cv_file_magic_test_file=/shlib/libc.so ;; -cygwin* | msys*) +cygwin*) # func_win32_libid is a shell function defined in ltmain.sh lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL' lt_cv_file_magic_cmd='func_win32_libid' @@ -3552,7 +3557,7 @@ linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*) lt_cv_deplibs_check_method=pass_all ;; -netbsd*) +netbsd* | netbsdelf*-gnu) if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|_pic\.a)$' else @@ -3777,7 +3782,7 @@ lt_cv_sharedlib_from_linklib_cmd, [lt_cv_sharedlib_from_linklib_cmd='unknown' case $host_os in -cygwin* | msys* | mingw* | pw32* | cegcc*) +cygwin* | mingw* | pw32* | cegcc*) # two different shell functions defined in ltmain.sh; # decide which one to use based on capabilities of $DLLTOOL case `$DLLTOOL --help 2>&1` in @@ -3847,7 +3852,7 @@ AC_DEFUN([LT_LIB_M], [AC_REQUIRE([AC_CANONICAL_HOST])dnl LIBM= case $host in -*-*-beos* | *-*-cegcc* | *-*-cygwin* | *-*-msys* | *-*-haiku* | *-*-pw32* | *-*-darwin*) +*-*-beos* | *-*-cegcc* | *-*-cygwin* | *-*-haiku* | *-*-pw32* | *-*-darwin*) # These system don't have libm, or don't need it ;; *-ncr-sysv4.3*) @@ -3922,7 +3927,7 @@ case $host_os in aix*) symcode='[[BCDT]]' ;; -cygwin* | msys* | mingw* | pw32* | cegcc*) +cygwin* | mingw* | pw32* | cegcc*) symcode='[[ABCDGISTW]]' ;; hpux*) @@ -4058,7 +4063,8 @@ _LT_EOF if AC_TRY_EVAL(ac_compile); then # Now try to grab the symbols. nlist=conftest.nm - if AC_TRY_EVAL(NM conftest.$ac_objext \| "$lt_cv_sys_global_symbol_pipe" \> $nlist) && test -s "$nlist"; then + $ECHO "$as_me:$LINENO: $NM conftest.$ac_objext | $lt_cv_sys_global_symbol_pipe > $nlist" >&AS_MESSAGE_LOG_FD + if eval "$NM" conftest.$ac_objext \| "$lt_cv_sys_global_symbol_pipe" \> $nlist 2>&AS_MESSAGE_LOG_FD && test -s "$nlist"; then # Try sorting and uniquifying the output. if sort "$nlist" | uniq > "$nlist"T; then mv -f "$nlist"T "$nlist" @@ -4228,7 +4234,7 @@ m4_if([$1], [CXX], [ beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*) # PIC is the default for these OSes. ;; - mingw* | cygwin* | msys* | os2* | pw32* | cegcc*) + mingw* | cygwin* | os2* | pw32* | cegcc*) # This hack is so that the source file can tell whether it is being # built for inclusion in a dll (and should export symbols for example). # Although the cygwin gcc ignores -fPIC, still need this for old-style @@ -4304,7 +4310,7 @@ m4_if([$1], [CXX], [ ;; esac ;; - mingw* | cygwin* | msys* | os2* | pw32* | cegcc*) + mingw* | cygwin* | os2* | pw32* | cegcc*) # This hack is so that the source file can tell whether it is being # built for inclusion in a dll (and should export symbols for example). m4_if([$1], [GCJ], [], @@ -4430,7 +4436,7 @@ m4_if([$1], [CXX], [ ;; esac ;; - netbsd*) + netbsd* | netbsdelf*-gnu) ;; *qnx* | *nto*) # QNX uses GNU C++, but need to define -shared option too, otherwise @@ -4552,7 +4558,7 @@ m4_if([$1], [CXX], [ # PIC is the default for these OSes. ;; - mingw* | cygwin* | msys* | pw32* | os2* | cegcc*) + mingw* | cygwin* | pw32* | os2* | cegcc*) # This hack is so that the source file can tell whether it is being # built for inclusion in a dll (and should export symbols for example). # Although the cygwin gcc ignores -fPIC, still need this for old-style @@ -4656,7 +4662,7 @@ m4_if([$1], [CXX], [ esac ;; - mingw* | cygwin* | msys* | pw32* | os2* | cegcc*) + mingw* | cygwin* | pw32* | os2* | cegcc*) # This hack is so that the source file can tell whether it is being # built for inclusion in a dll (and should export symbols for example). m4_if([$1], [GCJ], [], @@ -4931,7 +4937,7 @@ m4_if([$1], [CXX], [ pw32*) _LT_TAGVAR(export_symbols_cmds, $1)=$ltdll_cmds ;; - cygwin* | msys* | mingw* | cegcc*) + cygwin* | mingw* | cegcc*) case $cc_basename in cl*) _LT_TAGVAR(exclude_expsyms, $1)='_NULL_IMPORT_DESCRIPTOR|_IMPORT_DESCRIPTOR_.*' @@ -4942,6 +4948,9 @@ m4_if([$1], [CXX], [ ;; esac ;; + linux* | k*bsd*-gnu | gnu*) + _LT_TAGVAR(link_all_deplibs, $1)=no + ;; *) _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' ;; @@ -4989,7 +4998,7 @@ dnl Note also adjust exclude_expsyms for C++ above. extract_expsyms_cmds= case $host_os in - cygwin* | msys* | mingw* | pw32* | cegcc*) + cygwin* | mingw* | pw32* | cegcc*) # FIXME: the MSVC++ port hasn't been tested in a loooong time # When not using gcc, we currently assume that we are using # Microsoft Visual C++. @@ -5004,6 +5013,9 @@ dnl Note also adjust exclude_expsyms for C++ above. openbsd* | bitrig*) with_gnu_ld=no ;; + linux* | k*bsd*-gnu | gnu*) + _LT_TAGVAR(link_all_deplibs, $1)=no + ;; esac _LT_TAGVAR(ld_shlibs, $1)=yes @@ -5104,7 +5116,7 @@ _LT_EOF fi ;; - cygwin* | msys* | mingw* | pw32* | cegcc*) + cygwin* | mingw* | pw32* | cegcc*) # _LT_TAGVAR(hardcode_libdir_flag_spec, $1) is actually meaningless, # as there is no search path for DLLs. _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' @@ -5114,7 +5126,6 @@ _LT_EOF _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[[BCDGRS]][[ ]]/s/.*[[ ]]\([[^ ]]*\)/\1 DATA/;s/^.*[[ ]]__nm__\([[^ ]]*\)[[ ]][[^ ]]*/\1 DATA/;/^I[[ ]]/d;/^[[AITW]][[ ]]/s/.* //'\'' | sort | uniq > $export_symbols' _LT_TAGVAR(exclude_expsyms, $1)=['[_]+GLOBAL_OFFSET_TABLE_|[_]+GLOBAL__[FID]_.*|[_]+head_[A-Za-z0-9_]+_dll|[A-Za-z0-9_]+_dll_iname'] - _LT_TAGVAR(file_list_spec, $1)='@' if $LD --help 2>&1 | $GREP 'auto-import' > /dev/null; then _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -o $output_objdir/$soname $wl--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' @@ -5259,7 +5270,7 @@ _LT_EOF fi ;; - netbsd*) + netbsd* | netbsdelf*-gnu) if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable $libobjs $deplibs $linker_flags -o $lib' wlarc= @@ -5561,7 +5572,7 @@ _LT_EOF _LT_TAGVAR(export_dynamic_flag_spec, $1)=-rdynamic ;; - cygwin* | msys* | mingw* | pw32* | cegcc*) + cygwin* | mingw* | pw32* | cegcc*) # When not using gcc, we currently assume that we are using # Microsoft Visual C++. # hardcode_libdir_flag_spec is actually meaningless, as there is @@ -5780,6 +5791,7 @@ _LT_EOF if test yes = "$lt_cv_irix_exported_symbol"; then _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations $wl-exports_file $wl$export_symbols -o $lib' fi + _LT_TAGVAR(link_all_deplibs, $1)=no else _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -exports_file $export_symbols -o $lib' @@ -5801,7 +5813,7 @@ _LT_EOF esac ;; - netbsd*) + netbsd* | netbsdelf*-gnu) if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' # a.out else @@ -6427,7 +6439,7 @@ if test yes != "$_lt_caught_CXX_error"; then # Commands to make compiler produce verbose output that lists # what "hidden" libraries, object files and flags are used when # linking a shared library. - output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"' + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP " \-L"' else GXX=no @@ -6636,7 +6648,7 @@ if test yes != "$_lt_caught_CXX_error"; then esac ;; - cygwin* | msys* | mingw* | pw32* | cegcc*) + cygwin* | mingw* | pw32* | cegcc*) case $GXX,$cc_basename in ,cl* | no,cl*) # Native MSVC @@ -6689,7 +6701,6 @@ if test yes != "$_lt_caught_CXX_error"; then _LT_TAGVAR(allow_undefined_flag, $1)=unsupported _LT_TAGVAR(always_export_symbols, $1)=no _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes - _LT_TAGVAR(file_list_spec, $1)='@' if $LD --help 2>&1 | $GREP 'auto-import' > /dev/null; then _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $output_objdir/$soname $wl--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' @@ -6803,7 +6814,7 @@ if test yes != "$_lt_caught_CXX_error"; then # explicitly linking system object files so we need to strip them # from the output so that they don't get included in the library # dependencies. - output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $EGREP "\-L"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' + output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $EGREP " \-L"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' ;; *) if test yes = "$GXX"; then @@ -6868,7 +6879,7 @@ if test yes != "$_lt_caught_CXX_error"; then # explicitly linking system object files so we need to strip them # from the output so that they don't get included in the library # dependencies. - output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $GREP "\-L"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' + output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $GREP " \-L"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' ;; *) if test yes = "$GXX"; then @@ -7207,7 +7218,7 @@ if test yes != "$_lt_caught_CXX_error"; then # Commands to make compiler produce verbose output that lists # what "hidden" libraries, object files and flags are used when # linking a shared library. - output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"' + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP " \-L"' else # FIXME: insert proper C++ library support @@ -7291,7 +7302,7 @@ if test yes != "$_lt_caught_CXX_error"; then # Commands to make compiler produce verbose output that lists # what "hidden" libraries, object files and flags are used when # linking a shared library. - output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"' + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP " \-L"' else # g++ 2.7 appears to require '-G' NOT '-shared' on this # platform. @@ -7302,7 +7313,7 @@ if test yes != "$_lt_caught_CXX_error"; then # Commands to make compiler produce verbose output that lists # what "hidden" libraries, object files and flags are used when # linking a shared library. - output_verbose_link_cmd='$CC -G $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"' + output_verbose_link_cmd='$CC -G $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP " \-L"' fi _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-R $wl$libdir' @@ -7539,7 +7550,7 @@ if AC_TRY_EVAL(ac_compile); then for p in `eval "$output_verbose_link_cmd"`; do case $prev$p in - -L* | -R* | -l* | */libclang_rt.*.a) + -L* | -R* | -l*) # Some compilers place space between "-{L,R}" and the path. # Remove the space. if test x-L = "$p" || @@ -8325,7 +8336,7 @@ AC_CACHE_VAL(lt_cv_to_host_file_cmd, *-*-mingw* ) # actually msys lt_cv_to_host_file_cmd=func_convert_file_msys_to_w32 ;; - *-*-cygwin* | *-*-msys* ) + *-*-cygwin* ) lt_cv_to_host_file_cmd=func_convert_file_cygwin_to_w32 ;; * ) # otherwise, assume *nix @@ -8333,12 +8344,12 @@ AC_CACHE_VAL(lt_cv_to_host_file_cmd, ;; esac ;; - *-*-cygwin* | *-*-msys* ) + *-*-cygwin* ) case $build in *-*-mingw* ) # actually msys lt_cv_to_host_file_cmd=func_convert_file_msys_to_cygwin ;; - *-*-cygwin* | *-*-msys* ) + *-*-cygwin* ) lt_cv_to_host_file_cmd=func_convert_file_noop ;; * ) # otherwise, assume *nix diff --git a/m4/ltoptions.m4 b/m4/ltoptions.m4 index b2bcc354..94b08297 100644 --- a/m4/ltoptions.m4 +++ b/m4/ltoptions.m4 @@ -128,7 +128,7 @@ LT_OPTION_DEFINE([LT_INIT], [win32-dll], [enable_win32_dll=yes case $host in -*-*-cygwin* | *-*-msys* | *-*-mingw* | *-*-pw32* | *-*-cegcc*) +*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-cegcc*) AC_CHECK_TOOL(AS, as, false) AC_CHECK_TOOL(DLLTOOL, dlltool, false) AC_CHECK_TOOL(OBJDUMP, objdump, false) diff --git a/man/Makefile.in b/man/Makefile.in index f5c9bf0c..b25c5efd 100644 --- a/man/Makefile.in +++ b/man/Makefile.in @@ -320,6 +320,7 @@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ +runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ diff --git a/man/TIFFGetField.3tiff b/man/TIFFGetField.3tiff index c2fd025f..431f4ae9 100644 --- a/man/TIFFGetField.3tiff +++ b/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<" .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/man/TIFFstrip.3tiff b/man/TIFFstrip.3tiff index eb38318f..ce3f718c 100644 --- a/man/TIFFstrip.3tiff +++ b/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/man/tiff2pdf.1 b/man/tiff2pdf.1 index 93011332..6b3b4abf 100644 --- a/man/tiff2pdf.1 +++ b/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/man/tiff2ps.1 b/man/tiff2ps.1 index 5e2b9a85..ce323eee 100644 --- a/man/tiff2ps.1 +++ b/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/man/tiff2rgba.1 b/man/tiff2rgba.1 index d9c9baae..fe9ebb2c 100644 --- a/man/tiff2rgba.1 +++ b/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/man/tiffcp.1 b/man/tiffcp.1 index 0545686c..6bfee348 100644 --- a/man/tiffcp.1 +++ b/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/man/tiffcrop.1 b/man/tiffcrop.1 index 5bd00976..d7a4c4d7 100644 --- a/man/tiffcrop.1 +++ b/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/nmake.opt b/nmake.opt index ae544670..d9bf15f1 100644 --- a/nmake.opt +++ b/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/port/Makefile.in b/port/Makefile.in index 72e192b0..83ce6f14 100644 --- a/port/Makefile.in +++ b/port/Makefile.in @@ -343,6 +343,7 @@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ +runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ diff --git a/port/Makefile.vc b/port/Makefile.vc index 992d2696..e4471af5 100644 --- a/port/Makefile.vc +++ b/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/port/libport.h b/port/libport.h index ff262638..9f2dace1 100644 --- a/port/libport.h +++ b/port/libport.h @@ -24,6 +24,10 @@ #ifndef _LIBPORT_ #define _LIBPORT_ +#if defined(HAVE_CONFIG_H) +# include +#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/test/CMakeLists.txt b/test/CMakeLists.txt index a4216d56..bffb8bf7 100644 --- a/test/CMakeLists.txt +++ b/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/test/Makefile.am b/test/Makefile.am index 90c2f3d1..4973b614 100644 --- a/test/Makefile.am +++ b/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/test/Makefile.in b/test/Makefile.in index 5a2f0607..fc7eea54 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -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 @@ -644,6 +661,7 @@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ +runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ @@ -679,7 +697,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 +781,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 +792,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 +813,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 +851,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 +911,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 +927,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 +960,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 +1241,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 +1815,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 +1836,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 +1954,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 +2014,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/test/common.sh b/test/common.sh index 5bebcd37..0219ab3a 100644 --- a/test/common.sh +++ b/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/test/custom_dir_EXIF_231.c b/test/custom_dir_EXIF_231.c new file mode 100644 index 00000000..854b19a9 --- /dev/null +++ b/test/custom_dir_EXIF_231.c @@ -0,0 +1,1398 @@ + +/* + * Copyright (c) 2012, Frank Warmerdam + * + * 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 +#include +#include +#include + +#ifdef HAVE_UNISTD_H +# include +#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; iset_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; ifields[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 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 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; ifields[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 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 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 + * + * 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 +#include +#include +#include + +#ifdef HAVE_UNISTD_H +# include +#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/test/refs/o-deflate-last-strip-extra-data.tiff b/test/refs/o-deflate-last-strip-extra-data.tiff new file mode 100644 index 00000000..5d56fe54 Binary files /dev/null and b/test/refs/o-deflate-last-strip-extra-data.tiff differ diff --git a/test/refs/o-testfax4.tiff b/test/refs/o-testfax4.tiff new file mode 100644 index 00000000..cad45045 Binary files /dev/null and b/test/refs/o-testfax4.tiff differ diff --git a/test/testdeflatelaststripextradata.sh b/test/testdeflatelaststripextradata.sh new file mode 100755 index 00000000..115eb226 --- /dev/null +++ b/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/test/testfax4.sh b/test/testfax4.sh new file mode 100755 index 00000000..6f465e8f --- /dev/null +++ b/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/test/tiff2bw-logluv-3c-16b.sh b/test/tiff2bw-logluv-3c-16b.sh new file mode 100755 index 00000000..9a64a1af --- /dev/null +++ b/test/tiff2bw-logluv-3c-16b.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/logluv-3c-16b.tiff" +outfile="o-tiff2bw-logluv-3c-16b.tiff" +f_test_convert "$TIFF2BW" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiff2bw-lzw-single-strip.sh b/test/tiff2bw-lzw-single-strip.sh new file mode 100755 index 00000000..def92097 --- /dev/null +++ b/test/tiff2bw-lzw-single-strip.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/lzw-single-strip.tiff" +outfile="o-tiff2bw-lzw-single-strip.tiff" +f_test_convert "$TIFF2BW" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiff2bw-minisblack-1c-16b.sh b/test/tiff2bw-minisblack-1c-16b.sh new file mode 100755 index 00000000..d0dee2c8 --- /dev/null +++ b/test/tiff2bw-minisblack-1c-16b.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/minisblack-1c-16b.tiff" +outfile="o-tiff2bw-minisblack-1c-16b.tiff" +f_test_convert "$TIFF2BW" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiff2bw-minisblack-1c-8b.sh b/test/tiff2bw-minisblack-1c-8b.sh new file mode 100755 index 00000000..c3437b95 --- /dev/null +++ b/test/tiff2bw-minisblack-1c-8b.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/minisblack-1c-8b.tiff" +outfile="o-tiff2bw-minisblack-1c-8b.tiff" +f_test_convert "$TIFF2BW" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiff2bw-minisblack-2c-8b-alpha.sh b/test/tiff2bw-minisblack-2c-8b-alpha.sh new file mode 100755 index 00000000..81f7b6d6 --- /dev/null +++ b/test/tiff2bw-minisblack-2c-8b-alpha.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/minisblack-2c-8b-alpha.tiff" +outfile="o-tiff2bw-minisblack-2c-8b-alpha.tiff" +f_test_convert "$TIFF2BW" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiff2bw-miniswhite-1c-1b.sh b/test/tiff2bw-miniswhite-1c-1b.sh new file mode 100755 index 00000000..e3043c1f --- /dev/null +++ b/test/tiff2bw-miniswhite-1c-1b.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/miniswhite-1c-1b.tiff" +outfile="o-tiff2bw-miniswhite-1c-1b.tiff" +f_test_convert "$TIFF2BW" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiff2bw-ojpeg_chewey_subsamp21_multi_strip.sh b/test/tiff2bw-ojpeg_chewey_subsamp21_multi_strip.sh new file mode 100755 index 00000000..61a2ccf5 --- /dev/null +++ b/test/tiff2bw-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-tiff2bw-ojpeg_chewey_subsamp21_multi_strip.tiff" +f_test_convert "$TIFF2BW" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiff2bw-ojpeg_zackthecat_subsamp22_single_strip.sh b/test/tiff2bw-ojpeg_zackthecat_subsamp22_single_strip.sh new file mode 100755 index 00000000..7b09ded9 --- /dev/null +++ b/test/tiff2bw-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-tiff2bw-ojpeg_zackthecat_subsamp22_single_strip.tiff" +f_test_convert "$TIFF2BW" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiff2bw-palette-1c-1b.sh b/test/tiff2bw-palette-1c-1b.sh new file mode 100755 index 00000000..3862614e --- /dev/null +++ b/test/tiff2bw-palette-1c-1b.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/palette-1c-1b.tiff" +outfile="o-tiff2bw-palette-1c-1b.tiff" +f_test_convert "$TIFF2BW" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiff2bw-palette-1c-4b.sh b/test/tiff2bw-palette-1c-4b.sh new file mode 100755 index 00000000..21d8e90d --- /dev/null +++ b/test/tiff2bw-palette-1c-4b.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/palette-1c-4b.tiff" +outfile="o-tiff2bw-palette-1c-4b.tiff" +f_test_convert "$TIFF2BW" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiff2bw-quad-tile.jpg.sh b/test/tiff2bw-quad-tile.jpg.sh new file mode 100755 index 00000000..29c2f40a --- /dev/null +++ b/test/tiff2bw-quad-tile.jpg.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/quad-tile.jpg.tiff" +outfile="o-tiff2bw-quad-tile.jpg.tiff" +f_test_convert "$TIFF2BW" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiff2bw-quad-tile.jpg.t1iff.sh b/test/tiff2bw-quad-tile.jpg.t1iff.sh new file mode 100755 index 00000000..1c507b37 --- /dev/null +++ b/test/tiff2bw-quad-tile.jpg.t1iff.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/quad-tile.jpg.t1iff" +outfile="o-tiff2bw-quad-tile.jpg.t1iff.tiff" +f_test_convert "$TIFF2BW" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiff2bw-rgb-3c-16b.sh b/test/tiff2bw-rgb-3c-16b.sh new file mode 100755 index 00000000..0ba9efb1 --- /dev/null +++ b/test/tiff2bw-rgb-3c-16b.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/rgb-3c-16b.tiff" +outfile="o-tiff2bw-rgb-3c-16b.tiff" +f_test_convert "$TIFF2BW" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiff2ps-EPS1.sh b/test/tiff2ps-EPS1.sh index b1dc82e7..150039ef 100755 --- a/test/tiff2ps-EPS1.sh +++ b/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/test/tiff2ps-PS1.sh b/test/tiff2ps-PS1.sh index 73171b98..ef08b13b 100755 --- a/test/tiff2ps-PS1.sh +++ b/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/test/tiff2ps-PS2.sh b/test/tiff2ps-PS2.sh index 9d3a521d..b130b08c 100755 --- a/test/tiff2ps-PS2.sh +++ b/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/test/tiff2ps-PS3.sh b/test/tiff2ps-PS3.sh index eb55b9a0..d22be09a 100755 --- a/test/tiff2ps-PS3.sh +++ b/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/test/tiff2rgba-lzw-single-strip.sh b/test/tiff2rgba-lzw-single-strip.sh new file mode 100755 index 00000000..184a28d5 --- /dev/null +++ b/test/tiff2rgba-lzw-single-strip.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/lzw-single-strip.tiff" +outfile="o-tiff2rgba-lzw-single-strip.tiff" +f_test_convert "$TIFF2RGBA" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiff2rgba-ojpeg_chewey_subsamp21_multi_strip.sh b/test/tiff2rgba-ojpeg_chewey_subsamp21_multi_strip.sh new file mode 100755 index 00000000..d1225c94 --- /dev/null +++ b/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/test/tiff2rgba-ojpeg_single_strip_no_rowsperstrip.sh b/test/tiff2rgba-ojpeg_single_strip_no_rowsperstrip.sh new file mode 100755 index 00000000..d69c99dc --- /dev/null +++ b/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/test/tiff2rgba-ojpeg_zackthecat_subsamp22_single_strip.sh b/test/tiff2rgba-ojpeg_zackthecat_subsamp22_single_strip.sh new file mode 100755 index 00000000..ca23a12d --- /dev/null +++ b/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/test/tiff2rgba-quad-lzw-compat.sh b/test/tiff2rgba-quad-lzw-compat.sh new file mode 100755 index 00000000..5ad808a5 --- /dev/null +++ b/test/tiff2rgba-quad-lzw-compat.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/quad-lzw-compat.tiff" +outfile="o-tiff2rgba-quad-lzw-compat.tiff" +f_test_convert "$TIFF2RGBA" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiff2rgba-quad-tile.jpg.t1iff.sh b/test/tiff2rgba-quad-tile.jpg.t1iff.sh new file mode 100755 index 00000000..9d553df6 --- /dev/null +++ b/test/tiff2rgba-quad-tile.jpg.t1iff.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/quad-tile.jpg.t1iff" +outfile="o-tiff2rgba-quad-tile.jpg.t1iff.tiff" +f_test_convert "$TIFF2RGBA" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiffcrop-R90-lzw-single-strip.sh b/test/tiffcrop-R90-lzw-single-strip.sh new file mode 100755 index 00000000..7b4fdbf9 --- /dev/null +++ b/test/tiffcrop-R90-lzw-single-strip.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/lzw-single-strip.tiff" +outfile="o-tiffcrop-R90-lzw-single-strip.tiff" +f_test_convert "$TIFFCROP -R90" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiffcrop-R90-ojpeg_chewey_subsamp21_multi_strip.sh b/test/tiffcrop-R90-ojpeg_chewey_subsamp21_multi_strip.sh new file mode 100755 index 00000000..41df587d --- /dev/null +++ b/test/tiffcrop-R90-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-tiffcrop-R90-ojpeg_chewey_subsamp21_multi_strip.tiff" +f_test_convert "$TIFFCROP -R90" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiffcrop-R90-ojpeg_zackthecat_subsamp22_single_strip.sh b/test/tiffcrop-R90-ojpeg_zackthecat_subsamp22_single_strip.sh new file mode 100755 index 00000000..61f8fc41 --- /dev/null +++ b/test/tiffcrop-R90-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-tiffcrop-R90-ojpeg_zackthecat_subsamp22_single_strip.tiff" +f_test_convert "$TIFFCROP -R90" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiffcrop-R90-quad-lzw-compat.sh b/test/tiffcrop-R90-quad-lzw-compat.sh new file mode 100755 index 00000000..1a40412e --- /dev/null +++ b/test/tiffcrop-R90-quad-lzw-compat.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/quad-lzw-compat.tiff" +outfile="o-tiffcrop-R90-quad-lzw-compat.tiff" +f_test_convert "$TIFFCROP -R90" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiffcrop-R90-quad-tile.jpg.t1iff.sh b/test/tiffcrop-R90-quad-tile.jpg.t1iff.sh new file mode 100755 index 00000000..0d2bf973 --- /dev/null +++ b/test/tiffcrop-R90-quad-tile.jpg.t1iff.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/quad-tile.jpg.t1iff" +outfile="o-tiffcrop-R90-quad-tile.jpg.t1iff.tiff" +f_test_convert "$TIFFCROP -R90" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiffcrop-doubleflip-lzw-single-strip.sh b/test/tiffcrop-doubleflip-lzw-single-strip.sh new file mode 100755 index 00000000..15351247 --- /dev/null +++ b/test/tiffcrop-doubleflip-lzw-single-strip.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/lzw-single-strip.tiff" +outfile="o-tiffcrop-doubleflip-lzw-single-strip.tiff" +f_test_convert "$TIFFCROP -F both" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiffcrop-doubleflip-ojpeg_chewey_subsamp21_multi_strip.sh b/test/tiffcrop-doubleflip-ojpeg_chewey_subsamp21_multi_strip.sh new file mode 100755 index 00000000..3196ae1d --- /dev/null +++ b/test/tiffcrop-doubleflip-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-tiffcrop-doubleflip-ojpeg_chewey_subsamp21_multi_strip.tiff" +f_test_convert "$TIFFCROP -F both" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiffcrop-doubleflip-ojpeg_zackthecat_subsamp22_single_strip.sh b/test/tiffcrop-doubleflip-ojpeg_zackthecat_subsamp22_single_strip.sh new file mode 100755 index 00000000..6ce71d4f --- /dev/null +++ b/test/tiffcrop-doubleflip-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-tiffcrop-doubleflip-ojpeg_zackthecat_subsamp22_single_strip.tiff" +f_test_convert "$TIFFCROP -F both" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiffcrop-doubleflip-quad-lzw-compat.sh b/test/tiffcrop-doubleflip-quad-lzw-compat.sh new file mode 100755 index 00000000..5c482a5d --- /dev/null +++ b/test/tiffcrop-doubleflip-quad-lzw-compat.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/quad-lzw-compat.tiff" +outfile="o-tiffcrop-doubleflip-quad-lzw-compat.tiff" +f_test_convert "$TIFFCROP -F both" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiffcrop-doubleflip-quad-tile.jpg.t1iff.sh b/test/tiffcrop-doubleflip-quad-tile.jpg.t1iff.sh new file mode 100755 index 00000000..2e097126 --- /dev/null +++ b/test/tiffcrop-doubleflip-quad-tile.jpg.t1iff.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/quad-tile.jpg.t1iff" +outfile="o-tiffcrop-doubleflip-quad-tile.jpg.t1iff.tiff" +f_test_convert "$TIFFCROP -F both" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiffcrop-extract-lzw-single-strip.sh b/test/tiffcrop-extract-lzw-single-strip.sh new file mode 100755 index 00000000..58041a23 --- /dev/null +++ b/test/tiffcrop-extract-lzw-single-strip.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/lzw-single-strip.tiff" +outfile="o-tiffcrop-extract-lzw-single-strip.tiff" +f_test_convert "$TIFFCROP -U px -E top -X 60 -Y 60" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiffcrop-extract-ojpeg_chewey_subsamp21_multi_strip.sh b/test/tiffcrop-extract-ojpeg_chewey_subsamp21_multi_strip.sh new file mode 100755 index 00000000..bb30f9bd --- /dev/null +++ b/test/tiffcrop-extract-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-tiffcrop-extract-ojpeg_chewey_subsamp21_multi_strip.tiff" +f_test_convert "$TIFFCROP -U px -E top -X 60 -Y 60" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiffcrop-extract-ojpeg_zackthecat_subsamp22_single_strip.sh b/test/tiffcrop-extract-ojpeg_zackthecat_subsamp22_single_strip.sh new file mode 100755 index 00000000..ce06a261 --- /dev/null +++ b/test/tiffcrop-extract-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-tiffcrop-extract-ojpeg_zackthecat_subsamp22_single_strip.tiff" +f_test_convert "$TIFFCROP -U px -E top -X 60 -Y 60" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiffcrop-extract-quad-lzw-compat.sh b/test/tiffcrop-extract-quad-lzw-compat.sh new file mode 100755 index 00000000..bade2456 --- /dev/null +++ b/test/tiffcrop-extract-quad-lzw-compat.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/quad-lzw-compat.tiff" +outfile="o-tiffcrop-extract-quad-lzw-compat.tiff" +f_test_convert "$TIFFCROP -U px -E top -X 60 -Y 60" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiffcrop-extract-quad-tile.jpg.t1iff.sh b/test/tiffcrop-extract-quad-tile.jpg.t1iff.sh new file mode 100755 index 00000000..11834416 --- /dev/null +++ b/test/tiffcrop-extract-quad-tile.jpg.t1iff.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/quad-tile.jpg.t1iff" +outfile="o-tiffcrop-extract-quad-tile.jpg.t1iff.tiff" +f_test_convert "$TIFFCROP -U px -E top -X 60 -Y 60" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiffcrop-extractz14-lzw-single-strip.sh b/test/tiffcrop-extractz14-lzw-single-strip.sh new file mode 100755 index 00000000..022ab76f --- /dev/null +++ b/test/tiffcrop-extractz14-lzw-single-strip.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/lzw-single-strip.tiff" +outfile="o-tiffcrop-extractz14-lzw-single-strip.tiff" +f_test_convert "$TIFFCROP -E left -Z1:4,2:4" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiffcrop-extractz14-ojpeg_chewey_subsamp21_multi_strip.sh b/test/tiffcrop-extractz14-ojpeg_chewey_subsamp21_multi_strip.sh new file mode 100755 index 00000000..81d66249 --- /dev/null +++ b/test/tiffcrop-extractz14-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-tiffcrop-extractz14-ojpeg_chewey_subsamp21_multi_strip.tiff" +f_test_convert "$TIFFCROP -E left -Z1:4,2:4" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiffcrop-extractz14-ojpeg_zackthecat_subsamp22_single_strip.sh b/test/tiffcrop-extractz14-ojpeg_zackthecat_subsamp22_single_strip.sh new file mode 100755 index 00000000..e6c3c5f3 --- /dev/null +++ b/test/tiffcrop-extractz14-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-tiffcrop-extractz14-ojpeg_zackthecat_subsamp22_single_strip.tiff" +f_test_convert "$TIFFCROP -E left -Z1:4,2:4" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiffcrop-extractz14-quad-lzw-compat.sh b/test/tiffcrop-extractz14-quad-lzw-compat.sh new file mode 100755 index 00000000..3fe169c3 --- /dev/null +++ b/test/tiffcrop-extractz14-quad-lzw-compat.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/quad-lzw-compat.tiff" +outfile="o-tiffcrop-extractz14-quad-lzw-compat.tiff" +f_test_convert "$TIFFCROP -E left -Z1:4,2:4" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiffcrop-extractz14-quad-tile.jpg.t1iff.sh b/test/tiffcrop-extractz14-quad-tile.jpg.t1iff.sh new file mode 100755 index 00000000..5d36e7da --- /dev/null +++ b/test/tiffcrop-extractz14-quad-tile.jpg.t1iff.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/quad-tile.jpg.t1iff" +outfile="o-tiffcrop-extractz14-quad-tile.jpg.t1iff.tiff" +f_test_convert "$TIFFCROP -E left -Z1:4,2:4" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 886d4549..ff2a1ddc 100644 --- a/tools/CMakeLists.txt +++ b/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/tools/Makefile.in b/tools/Makefile.in index 7ec4ed62..3c866668 100644 --- a/tools/Makefile.in +++ b/tools/Makefile.in @@ -437,6 +437,7 @@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ +runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ diff --git a/tools/fax2ps.c b/tools/fax2ps.c index 274b29e4..f59f4921 100644 --- a/tools/fax2ps.c +++ b/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/tools/fax2tiff.c b/tools/fax2tiff.c index 21223131..eecb41e3 100644 --- a/tools/fax2tiff.c +++ b/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/tools/pal2rgb.c b/tools/pal2rgb.c index 9492f1cf..bf95cb37 100644 --- a/tools/pal2rgb.c +++ b/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/tools/ppm2tiff.c b/tools/ppm2tiff.c index 2b275618..c6332439 100644 --- a/tools/ppm2tiff.c +++ b/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 = ""; @@ -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/tools/raw2tiff.c b/tools/raw2tiff.c index ab36ff4e..8bbdc045 100644 --- a/tools/raw2tiff.c +++ b/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/tools/rgb2ycbcr.c b/tools/rgb2ycbcr.c index cf5f956f..482cc5b4 100644 --- a/tools/rgb2ycbcr.c +++ b/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/tools/thumbnail.c b/tools/thumbnail.c index 169a6369..edb69983 100644 --- a/tools/thumbnail.c +++ b/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/tools/tiff2bw.c b/tools/tiff2bw.c index dbc697b0..654bd324 100644 --- a/tools/tiff2bw.c +++ b/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/tools/tiff2pdf.c b/tools/tiff2pdf.c index 779c1662..acaef0d6 100644 --- a/tools/tiff2pdf.c +++ b/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;it2p_error = T2P_ERR_ERROR; + return(0); + } + bufferoffset += retTIFFReadRawStrip; } t2pWriteFile(output, (tdata_t) buffer, bufferoffset); + if( ! ( (buffer[bufferoffset-1]==0xd9) && (buffer[bufferoffset-2]==0xff) ) ){ + t2pWriteFile(output, (tdata_t) jpeg_eof_marker, sizeof(jpeg_eof_marker)); + } _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;it2p_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;itiff_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;it2p_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;itiff_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;jpdf_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/tools/tiff2ps.c b/tools/tiff2ps.c index 5874aba6..4ed5eba2 100644 --- a/tools/tiff2ps.c +++ b/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/tools/tiff2rgba.c b/tools/tiff2rgba.c index 2eb6f6c4..764395f6 100644 --- a/tools/tiff2rgba.c +++ b/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/tools/tiffcmp.c b/tools/tiffcmp.c index 7b764883..041d6a2d 100644 --- a/tools/tiffcmp.c +++ b/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/tools/tiffcp.c b/tools/tiffcp.c index 84d81488..e56b1c10 100644 --- a/tools/tiffcp.c +++ b/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/tools/tiffcrop.c b/tools/tiffcrop.c index 7b3c9e78..d20b585a 100644 --- a/tools/tiffcrop.c +++ b/tools/tiffcrop.c @@ -128,6 +128,13 @@ static char tiffcrop_rev_date[] = "12-13-2010"; # include #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, §_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, §ions[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/tools/tiffdither.c b/tools/tiffdither.c index 3fd7f81a..a9d1b7c5 100644 --- a/tools/tiffdither.c +++ b/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/tools/tiffdump.c b/tools/tiffdump.c index 4cdcda0c..00be9dd4 100644 --- a/tools/tiffdump.c +++ b/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/tools/tiffgt.c b/tools/tiffgt.c index 2f11b0ca..f3cca8c9 100644 --- a/tools/tiffgt.c +++ b/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/tools/tiffinfo.c b/tools/tiffinfo.c index 049e3a34..2271c9d1 100644 --- a/tools/tiffinfo.c +++ b/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); @@ -455,6 +464,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) { diff --git a/tools/tiffmedian.c b/tools/tiffmedian.c index bd0d1561..6654cd6f 100644 --- a/tools/tiffmedian.c +++ b/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/tools/tiffset.c b/tools/tiffset.c index 7ecc401b..75cf45c0 100644 --- a/tools/tiffset.c +++ b/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 [count] ... set the tag value", @@ -43,16 +54,20 @@ static char* usageMsg[] = { " -d set the directory", " -sd set the subdirectory", " -sf 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/tools/tiffsplit.c b/tools/tiffsplit.c index c8b7f2dd..43b6fdc1 100644 --- a/tools/tiffsplit.c +++ b/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;