summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTarja Sundqvist <tarja.sundqvist@qt.io>2022-04-07 15:22:06 +0300
committerTarja Sundqvist <tarja.sundqvist@qt.io>2022-04-07 15:22:06 +0300
commit8c5bcabbf6a2e27539c2ad689fd69f2406d5cf5c (patch)
treec94914f103305661850b45164cda5d7313c301e5
parent90038c936763645610fe1e5f05cfc025e4d98631 (diff)
parent40da7331d6d818ec96604feaf978c8e6e828da7f (diff)
Merge remote-tracking branch 'origin/tqtc/lts-5.15.4' into tqtc/lts-5.15-opensourcev5.15.4-lts-lgpl
-rw-r--r--.qmake.conf2
-rw-r--r--src/3rdparty/libtiff/ChangeLog1442
-rw-r--r--src/3rdparty/libtiff/RELEASE-DATE2
-rw-r--r--src/3rdparty/libtiff/VERSION2
-rw-r--r--src/3rdparty/libtiff/libtiff/libtiff.def8
-rw-r--r--src/3rdparty/libtiff/libtiff/tif_aux.c24
-rw-r--r--src/3rdparty/libtiff/libtiff/tif_compress.c2
-rw-r--r--src/3rdparty/libtiff/libtiff/tif_config.h3
-rw-r--r--src/3rdparty/libtiff/libtiff/tif_config.h.in3
-rw-r--r--src/3rdparty/libtiff/libtiff/tif_config.vc.h21
-rw-r--r--src/3rdparty/libtiff/libtiff/tif_dir.c94
-rw-r--r--src/3rdparty/libtiff/libtiff/tif_dir.h2
-rw-r--r--src/3rdparty/libtiff/libtiff/tif_dirinfo.c244
-rw-r--r--src/3rdparty/libtiff/libtiff/tif_dirread.c120
-rw-r--r--src/3rdparty/libtiff/libtiff/tif_dirwrite.c512
-rw-r--r--src/3rdparty/libtiff/libtiff/tif_fax3.c114
-rw-r--r--src/3rdparty/libtiff/libtiff/tif_fax3.h39
-rw-r--r--src/3rdparty/libtiff/libtiff/tif_fax3sm.c1
-rw-r--r--src/3rdparty/libtiff/libtiff/tif_getimage.c33
-rw-r--r--src/3rdparty/libtiff/libtiff/tif_jbig.c1
-rw-r--r--src/3rdparty/libtiff/libtiff/tif_jpeg.c65
-rw-r--r--src/3rdparty/libtiff/libtiff/tif_luv.c28
-rw-r--r--src/3rdparty/libtiff/libtiff/tif_lzma.c7
-rw-r--r--src/3rdparty/libtiff/libtiff/tif_lzw.c12
-rw-r--r--src/3rdparty/libtiff/libtiff/tif_ojpeg.c63
-rw-r--r--src/3rdparty/libtiff/libtiff/tif_open.c5
-rw-r--r--src/3rdparty/libtiff/libtiff/tif_pixarlog.c7
-rw-r--r--src/3rdparty/libtiff/libtiff/tif_predict.c6
-rw-r--r--src/3rdparty/libtiff/libtiff/tif_read.c18
-rw-r--r--src/3rdparty/libtiff/libtiff/tif_unix.c2
-rw-r--r--src/3rdparty/libtiff/libtiff/tif_win32.c60
-rw-r--r--src/3rdparty/libtiff/libtiff/tif_write.c11
-rw-r--r--src/3rdparty/libtiff/libtiff/tif_zip.c280
-rw-r--r--src/3rdparty/libtiff/libtiff/tiff.h117
-rw-r--r--src/3rdparty/libtiff/libtiff/tiffconf.h3
-rw-r--r--src/3rdparty/libtiff/libtiff/tiffconf.h.in3
-rw-r--r--src/3rdparty/libtiff/libtiff/tiffio.h16
-rw-r--r--src/3rdparty/libtiff/libtiff/tiffiop.h3
-rw-r--r--src/3rdparty/libtiff/libtiff/tiffvers.h4
-rw-r--r--src/3rdparty/libtiff/port/libport.h12
-rw-r--r--src/3rdparty/libtiff/qt_attribution.json2
-rw-r--r--src/3rdparty/libwebp/AUTHORS2
-rw-r--r--src/3rdparty/libwebp/ChangeLog78
-rw-r--r--src/3rdparty/libwebp/NEWS12
-rw-r--r--src/3rdparty/libwebp/README14
-rw-r--r--src/3rdparty/libwebp/qt_attribution.json2
-rw-r--r--src/3rdparty/libwebp/src/dec/io_dec.c53
-rw-r--r--src/3rdparty/libwebp/src/dec/vp8_dec.c12
-rw-r--r--src/3rdparty/libwebp/src/dec/vp8i_dec.h2
-rw-r--r--src/3rdparty/libwebp/src/dec/vp8l_dec.c1
-rw-r--r--src/3rdparty/libwebp/src/demux/anim_decode.c11
-rw-r--r--src/3rdparty/libwebp/src/demux/demux.c7
-rw-r--r--src/3rdparty/libwebp/src/dsp/alpha_processing.c8
-rw-r--r--src/3rdparty/libwebp/src/dsp/alpha_processing_sse2.c22
-rw-r--r--src/3rdparty/libwebp/src/dsp/cpu.c38
-rw-r--r--src/3rdparty/libwebp/src/dsp/dec_neon.c68
-rw-r--r--src/3rdparty/libwebp/src/dsp/dsp.h18
-rw-r--r--src/3rdparty/libwebp/src/dsp/lossless.c56
-rw-r--r--src/3rdparty/libwebp/src/dsp/lossless.h17
-rw-r--r--src/3rdparty/libwebp/src/dsp/lossless_common.h13
-rw-r--r--src/3rdparty/libwebp/src/dsp/lossless_enc.c173
-rw-r--r--src/3rdparty/libwebp/src/dsp/lossless_enc_sse2.c38
-rw-r--r--src/3rdparty/libwebp/src/enc/analysis_enc.c60
-rw-r--r--src/3rdparty/libwebp/src/enc/backward_references_enc.c201
-rw-r--r--src/3rdparty/libwebp/src/enc/backward_references_enc.h20
-rw-r--r--src/3rdparty/libwebp/src/enc/config_enc.c5
-rw-r--r--src/3rdparty/libwebp/src/enc/frame_enc.c20
-rw-r--r--src/3rdparty/libwebp/src/enc/histogram_enc.c1
-rw-r--r--src/3rdparty/libwebp/src/enc/picture_csp_enc.c14
-rw-r--r--src/3rdparty/libwebp/src/enc/picture_tools_enc.c31
-rw-r--r--src/3rdparty/libwebp/src/enc/vp8i_enc.h8
-rw-r--r--src/3rdparty/libwebp/src/enc/vp8l_enc.c327
-rw-r--r--src/3rdparty/libwebp/src/enc/vp8li_enc.h2
-rw-r--r--src/3rdparty/libwebp/src/enc/webp_enc.c2
-rw-r--r--src/3rdparty/libwebp/src/mux/muxi.h2
-rw-r--r--src/3rdparty/libwebp/src/mux/muxread.c2
-rw-r--r--src/3rdparty/libwebp/src/utils/utils.c2
-rw-r--r--src/3rdparty/libwebp/src/webp/config.h6
-rw-r--r--src/3rdparty/libwebp/src/webp/decode.h2
-rw-r--r--src/3rdparty/libwebp/src/webp/encode.h8
-rw-r--r--src/plugins/imageformats/tiff/qtiffhandler.cpp4
81 files changed, 3829 insertions, 926 deletions
diff --git a/.qmake.conf b/.qmake.conf
index 5fb75cf..163ffef 100644
--- a/.qmake.conf
+++ b/.qmake.conf
@@ -2,4 +2,4 @@ load(qt_build_config)
DEFINES += QT_NO_FOREACH QT_NO_JAVA_STYLE_ITERATORS QT_NO_LINKED_LIST
-MODULE_VERSION = 5.15.3
+MODULE_VERSION = 5.15.4
diff --git a/src/3rdparty/libtiff/ChangeLog b/src/3rdparty/libtiff/ChangeLog
index 01e2182..452dcb3 100644
--- a/src/3rdparty/libtiff/ChangeLog
+++ b/src/3rdparty/libtiff/ChangeLog
@@ -1,3 +1,1445 @@
+2020-12-19 Bob Friesenhahn <bfriesen@simple.dallas.tx.us>
+
+ * libtiff 4.2.0 released.
+
+ * configure.ac: Pass tar-ustar option to AM_INIT_AUTOMAKE rather
+ than tar-pax since ustar POSIX 1003.1-1988 format is more portable
+ than PAX POSIX 1003.1-2001 format.
+
+2020-12-12 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'w_adjust-deflate_names' into 'master'
+ Set 'deflate' to DEFLATE_NAMES, instead of 'libdeflate'
+
+ See merge request libtiff/libtiff!174
+
+2020-12-12 Lemures Lemniscati <lemures.lemniscati@gmail.com>
+
+ Set 'deflate' to DEFLATE_NAMES, instead of 'libdeflate'
+ 'lib' will be automatically added as a prefix while doing find_library()
+
+2020-12-12 Even Rouault <even.rouault@spatialys.com>
+
+ DoubleToRational(): avoid casting NaN to uint32 (fixes #227)
+
+2020-12-12 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'fix_221' into 'master'
+ tiffio.h: do not define __attribute__ but defines TIFF_ATTRIBUTE instead (fixes #221)
+
+ Closes #221
+
+ See merge request libtiff/libtiff!173
+
+2020-12-12 Even Rouault <even.rouault@spatialys.com>
+
+ tiffio.h: do not define __attribute__ but defines TIFF_ATTRIBUTE instead (fixes #221)
+
+2020-12-08 Even Rouault <even.rouault@spatialys.com>
+
+ TIFFReadDirEntryArrayWithLimit(): properly read from offline tag value when we clamp the number of strips to 1.
+ Fixes regression of commit 7057734d986001b7fd6d2afde9667da7754ff2cc on reading
+ a file with StripByteCounts with 1 element (broken) and StripOffsets with
+ 896 elements, and where StripOffsets[0] is correct
+
+ $ tiffdump foo.tif
+ Magic: 0x4949 <little-endian> Version: 0x2a <ClassicTIFF>
+ Directory 0: offset 25725448 (0x1888a08) next 0 (0)
+ SubFileType (254) LONG (4) 1<0>
+ ImageWidth (256) LONG (4) 1<640>
+ ImageLength (257) LONG (4) 1<20098>
+ BitsPerSample (258) SHORT (3) 1<16>
+ Photometric (262) SHORT (3) 1<1>
+ SamplesPerPixel (277) SHORT (3) 1<1>
+ ResolutionUnit (296) SHORT (3) 1<2>
+ StripByteCounts (279) LONG (4) 1<1806>
+ StripOffsets (273) LONG (4) 896<8 648 1288 1928 2568 3208 3848 4488 5128 5768 6408 7048 7688 8328 8968 9608 10248 10888 11528 12168 12808 13448 14088 14728 ...>
+
+2020-12-02 Even Rouault <even.rouault@spatialys.com>
+
+ tif_jpeg.c: avoid potential harmless unsigned integer overflow on data->fileoffset in JPEGFixupTagsSubsamplingSkip() by validating earlier. Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=28200
+
+2020-11-27 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'Jamaika1-master-patch-47839' into 'master'
+ Change ULARGE_INTEGER to LARGE_INTEGER
+
+ See merge request libtiff/libtiff!170
+
+2020-11-27 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'Jamaika1-master-patch-46397' into 'master'
+ Added stdint.h
+
+ See merge request libtiff/libtiff!171
+
+2020-11-27 Jamaika <lukaszcz18@wp.pl>
+
+ Added stdint.h.
+
+ ``` tif_win32.c: In function '_tiffSizeProc': tif_win32.c:159:23: warning: passing argument 2 of 'GetFileSizeEx' from incompatible pointer type [-Wincompatible-pointer-types] 159 | if (GetFileSizeEx(fd,&m)) | ^~ | | | ULARGE_INTEGER * In file included from c:\msys1021\x86_64-w64-mingw32\include\winbase.h:18, from c:\msys1021\x86_64-w64-mingw32\include\windows.h:70, from tif_win32.c:32: c:\msys1021\x86_64-w64-mingw32\include\fileapi.h:78:73: note: expected 'PLARGE_INTEGER' {aka 'LARGE_INTEGER *'} but argument is of type 'ULARGE_INTEGER *' 78 | WINBASEAPI WINBOOL WINAPI GetFileSizeEx (HANDLE hFile, PLARGE_INTEGER lpFileSize); | ~~~~~~~~~~~~~~~^~~~~~~~~~ ```
+
+2020-11-21 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-113' into 'master'
+ tiffcrop: fix buffer overrun in extractContigSamples24bits()
+
+ Closes #113
+
+ See merge request libtiff/libtiff!169
+
+2020-11-21 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-156' into 'master'
+ tiff2pdf: Check output size before writing
+
+ Closes #156
+
+ See merge request libtiff/libtiff!168
+
+2020-11-21 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-201' into 'master'
+ tiff2pdf: enforce memory limit for tiled pictures too
+
+ Closes #201
+
+ See merge request libtiff/libtiff!167
+
+2020-11-20 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-207' into 'master'
+ enforce (configurable) memory limit in tiff2rgba
+
+ Closes #209 et #207
+
+ See merge request libtiff/libtiff!165
+
+2020-11-20 Even Rouault <even.rouault@spatialys.com>
+
+ tif_lzw.c: avoid false positive -Wnull-dereference of mingw32 gcc 7.3.
+
+2020-11-17 Thomas Bernard <miniupnp@free.fr>
+
+ tiffcrop: fix buffer overrun in extractContigSamples24bits()
+ fixes #113
+
+ tiff2pdf: Check output size before writing.
+ fixes #156
+
+ tiff2pdf: enforce memory limit for tiled pictures too.
+ fixes #201
+
+2020-11-15 Thomas Bernard <miniupnp@free.fr>
+
+ tiff2rgba.1: -M option.
+
+ enforce (configurable) memory limit in tiff2rgba.
+ fixes #207
+ fixes #209
+
+2020-11-14 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-220' into 'master'
+ tiff2pdf.c: properly calculate datasize when saving to JPEG YCbCr
+
+ Closes #220
+
+ See merge request libtiff/libtiff!159
+
+2020-11-14 Thomas Bernard <miniupnp@free.fr>
+
+ tiff2pdf.c: properly calculate datasize when saving to JPEG YCbCr.
+ fixes #220
+
+2020-11-14 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-204' into 'master'
+ avoid buffer overflow while writing jpeg end of file marker
+
+ Closes #204
+
+ See merge request libtiff/libtiff!161
+
+2020-11-14 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-193' into 'master'
+ fix buffer overflow in tiff2ps.c
+
+ Closes #193
+
+ See merge request libtiff/libtiff!162
+
+2020-11-14 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'skal65535-master-patch-91082' into 'master'
+ More overflow fixes for large widths
+
+ See merge request libtiff/libtiff!164
+
+2020-11-14 skal <pascal.massimino@gmail.com>
+
+ More overflow fixes for large width.
+ Also: use INT_MAX instead of hard-coded constants.
+
+2020-11-12 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'skal65535-master-patch-56655' into 'master'
+ Fix potential overflow in gtStripContig()
+
+ See merge request libtiff/libtiff!163
+
+2020-11-12 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-211' into 'master'
+ check for tile width overflow
+
+ Closes #211
+
+ See merge request libtiff/libtiff!160
+
+2020-11-12 skal <pascal.massimino@gmail.com>
+
+ Fix potential overflow in gtStripContig()
+ (w + w) might not fit in int32 if too large.
+
+2020-11-09 Thomas Bernard <miniupnp@free.fr>
+
+ tiff2ps.c: fix buffer overread.
+ fixes #193
+
+ fix undefined behaviour (int shifted too much to the left)
+
+ avoid buffer overflow while writing jpeg end of file marker.
+ fixes #204
+
+ gtTileContig(): check Tile width for overflow.
+ fixes #211
+
+ fix warning messages (v32 is unsigned)
+
+2020-10-26 Even Rouault <even.rouault@spatialys.com>
+
+ TIFFStartStrip(): avoid potential crash in WebP codec when using scanline access on corrupted files. Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=26650
+
+2020-10-20 Even Rouault <even.rouault@spatialys.com>
+
+ tif_webp.c: validate tile/strip dimension to avoid unsigned integer overflow in RGBA.size computation
+
+2020-10-19 Even Rouault <even.rouault@spatialys.com>
+
+ tif_zip.c: fix typo in comment.
+
+2020-10-16 Even Rouault <even.rouault@spatialys.com>
+
+ tiff.h: remove irrelevant warning about webp related pseudo-tags not being registered: they are purely internal libtiff concepts
+
+2020-10-16 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'libdeflate' into 'master'
+ Add support for building against libdeflate for faster Zip/Deflate compression/decompression
+
+ See merge request libtiff/libtiff!158
+
+2020-10-16 Even Rouault <even.rouault@spatialys.com>
+
+ test: add testdeflatelaststripextradata.sh.
+
+2020-10-16 Even Rouault <even.rouault@spatialys.com>
+
+ Add support for optional building against libdeflate for faster Zip/Deflate compression/decompression.
+ So we can have 2 kind of builds with the Zip/Deflate codec:
+ - zlib only
+ - zlib + libdeflate
+
+ Speed improvements in the 35%-50% range can be expected when libdeflate is used.
+ Compression level up to 12 is now supported (capped to 9 when zlib is used).
+ Still requires zlib for situations where libdeflate cannot be used (that
+ is for scanline access, since libdeflate has no streaming mode)
+
+ Pseudo-tag TIFFTAG_DEFLATE_SUBCODEC=DEFLATE_SUBCODEC_ZLIB/DEFLATE_SUBCODEC_LIBDEFLATE
+ is added to control which subcodec (zlib or libdeflate) should be used (it defaults
+ of course to libdeflate, when it is available).
+ This is mostly aimed at being used on the writing side, to be able to reproduce
+ output of previous libtiff versions at a binary level, in situations where this would
+ be really needed. Or as a safety belt in case there would be unforeseen issues
+ with using libdeflate.
+ It can be used to know when libdeflate is available at runtime (DEFLATE_SUBCODEC_LIBDEFLATE
+ will be the default value in that situation).
+
+ Of course, deflate codestreams produced by libdeflate can be read by zlib, and vice-versa.
+
+2020-10-14 Even Rouault <even.rouault@spatialys.com>
+
+ tif_webp.c: fix compiler warnings with MSVC.
+
+2020-10-12 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'various_fixes' into 'master'
+ Fix compiler warnings about unused variables when assert() expands to nothing
+
+ See merge request libtiff/libtiff!157
+
+2020-10-12 Even Rouault <even.rouault@spatialys.com>
+
+ .gitignore: add entries for new files in test/
+
+ Fix compiler warnings about unused variables when assert() expands to nothing
+
+2020-10-09 Roger Leigh <rleigh@codelibre.net>
+
+ Merge branch '215-cygwin-appveyor-fail' into 'master'
+ Update Appveyor CI build to build with VS2019 image
+
+ Closes #215
+
+ See merge request libtiff/libtiff!154
+
+2020-10-09 Roger Leigh <rleigh@codelibre.net>
+
+ wip.
+
+ wip.
+
+ wip.
+
+ wip.
+
+ wip.
+
+ wip.
+
+2020-10-09 Roger Leigh <rleigh@codelibre.net>
+
+ Merge branch 'TIFF-217_m_lib_path' into 'master'
+ cmake: Do not use absolute libm path
+
+ Closes #217
+
+ See merge request libtiff/libtiff!156
+
+2020-10-09 Roger Leigh <rleigh@codelibre.net>
+
+ cmake: Do not use absolute libm path.
+
+2020-10-08 Even Rouault <even.rouault@spatialys.com>
+
+ tif_fax3.h: restore systematic calls to CLEANUP_RUNS()
+ now that SETVALUE() no longer cause overflows.
+ Those were removed per b351db8be1b4d3f712bdb9424a79d3174cc03202 and
+ 3440ac216463fcad170bbb391491e69730a59ffa.
+
+ As SETVALUE() now returns an error, this allow the decoder to exit.
+
+ Otherwise, the assert(x == lastx) in _TIFFFax3fillruns() can trigger.
+
+ Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=26201
+
+2020-10-06 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'check_TIFFFlushData1' into 'master'
+ FAX/JPEG/LZMA/PixarLog/ZIP/ZSTD codecs: make sure to check TIFFFlushData1() return value
+
+ See merge request libtiff/libtiff!155
+
+2020-10-04 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'shared-memory' into 'master'
+ Set the --shared-memory linker flag for Emscripten builds
+
+ See merge request libtiff/libtiff!153
+
+2020-10-03 Even Rouault <even.rouault@spatialys.com>
+
+ tiff2rgba.c: fix -Wold-style-declaration warning.
+
+ FAX/JPEG/LZMA/PixarLog/ZIP/ZSTD codecs: make sure to check TIFFFlushData1() return value
+
+2020-09-26 Even Rouault <even.rouault@spatialys.com>
+
+ tif_fax3.h: extra buffer overflow checks. Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=25934
+
+2020-09-25 Roger Leigh <rleigh@codelibre.net>
+
+ wip.
+
+ wip.
+
+ wip.
+
+ wip.
+
+ wip.
+
+ wip.
+
+ Update AppVeyor image.
+
+ test-appveyor.
+
+2020-09-24 Attila Oláh <atl@google.com>
+
+ Also pass --shared-memory to raw_decode.
+ This is needed when building for Emscripten with *both* WEBP and JPEG
+ support.
+
+ Set the --shared-memory linker flag for Emscripten builds.
+ This is only needed when building with WEBP support, which uses atomics,
+ therefore the linker needs the --shared-memory flag. The flag cannot be
+ added globally because not all executables link against libwebp.
+
+2020-09-22 Even Rouault <even.rouault@spatialys.com>
+
+ tif_fax3.h: return error when a buffer overflow occurs. Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=25552 and https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=25849
+
+2020-09-11 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'fix-float-compare' into 'master'
+ Fix comparison for max negative float value.
+
+ See merge request libtiff/libtiff!152
+
+2020-09-11 Dirk Lemstra <dirk@lemstra.org>
+
+ Fix comparison for max negative float value.
+
+2020-09-07 Even Rouault <even.rouault@spatialys.com>
+
+ Fax3PreDecode(): reset curruns and refruns state variables.
+ to avoid out-of-bounds write triggered by GDAL when repeatedly
+ reading a corrupt strip.
+
+ Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=25493
+
+2020-06-06 Thomas Bernard <miniupnp@free.fr>
+
+ Merge branch 'issue-17' into 'master'
+ normalize tools behaviour regarding -h
+
+ Closes #17
+
+ See merge request libtiff/libtiff!115
+
+2020-05-31 Even Rouault <even.rouault@spatialys.com>
+
+ TWebPSetupEncode(): fix logic problem (and instead of or) in test that checks input is 8bit unsigned data
+
+2020-05-12 Even Rouault <even.rouault@spatialys.com>
+
+ TIFFGetConfiguredCODECs(): fix to avoid wrong structure to be returned for registered (ie non built-in) codecs
+
+2020-05-09 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'zstd-webp-update' into 'master'
+ gitlab-ci: use latest zstd and webp versions
+
+ See merge request libtiff/libtiff!148
+
+2020-05-09 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'deprecated' into 'master'
+ ojpeg: s/Depreciated/Deprecated/
+
+ See merge request libtiff/libtiff!149
+
+2020-05-09 Aaron Boxer <boxerab@gmail.com>
+
+ ojpeg: s/Depreciated/Deprecated/
+
+2020-04-27 Even Rouault <even.rouault@spatialys.com>
+
+ Fix typos.
+
+ tif_jpeg.c: avoid potential division in previous fix (master only)
+
+2020-04-26 Thomas Bernard <miniupnp@free.fr>
+
+ gitlab-ci: use latest zstd and webp versions.
+
+2020-04-26 Even Rouault <even.rouault@spatialys.com>
+
+ tiff.h: fixes to use ASCII only characters (master only)
+
+2020-04-26 Thomas Bernard <miniupnp@free.fr>
+
+ tiffsplit: use EXIT_SUCCESS / EXIT_FAILURE.
+
+ tiffset: print usage on stdout when -h is used.
+ also use EXIT_FAILURE / EXIT_SUCCESS
+ see #17
+
+ tiffmedian: shopw usage on stdout when -h is used.
+ aslo use EXIT_SUCCESS/EXIT_FAILURE
+ see #17
+
+ tiffinfo: print usage on stdout when -h is used.
+ also use EXIT_FAILURE / EXIT_SUCCESS
+ see #17
+
+ raw2tiff: print usage to stdout when -h is used.
+ see #17
+
+ tiff2pdf: print usage on stdout when -h is used.
+ see #17
+
+ tiffgt: output usage on stdout with -h.
+ also use EXIT_SUCCESS / EXIT_FAILURE
+
+ tiffdump: use EXIT_FAILURE / EXIT_SUCCESS.
+ see #17
+
+ tiffdither: print usage on stdout when -h is used.
+ see #17
+
+2020-04-26 Thomas Bernard <miniupnp@free.fr>
+
+ tiffcrop: -h / -v prints usage/version to stdout.
+ also uses the standard C EXIT_SUCCESS / EXIT_FAILURE
+ macros
+
+ see #17
+
+2020-04-26 Thomas Bernard <miniupnp@free.fr>
+
+ tiffcp: output usage to stdout when using -h.
+ also use EXIT_FAILURE / EXIT_SUCCESS
+ see #17
+
+ tiffcmp: match exit status for posix cmp and diff tools.
+
+ tiff2rgba: output usage to stdout when using -h.
+ also uses std C EXIT_FAILURE / EXIT_SUCCESS
+ see #17
+
+ tiff2ps: sue EXIT_FAILURE / EXIT_SUCCESS.
+ see #17
+
+ tiff2bw: output usage on stdout when using -h.
+ also uses EXIT_SUCCESS / EXIT_FAILURE
+ see #17
+
+ thumbnail: use EXIT_FAILURE / EXIT_SUCCESS.
+ the -h option was already used so it cannot be used for help/usage
+ see #17
+
+ rgb2ycbcr: use EXIT_FAILURE / EXIT_SUCCESS.
+ the -h option was already used so it cannot be used for help/usage
+ see #17
+
+ ppm2tiff: output usage to stdout when using -h option.
+ also uses std C EXIT_SUCCESS / EXIT_FAILURE
+ see #17
+
+ pal2rgb: output usage to stdout when -h is used.
+ see #17
+
+ fax2tiff.c: print usage on stdout when using -h option.
+ see #17
+
+ fax2ps: output usage to stdout when using -h option.
+ also use EXIT_SUCCESS, EXIT_FAILURE from C standard
+
+2020-04-25 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'jpeg_multiscan_dos_logic' into 'master'
+ tif_jpeg.c: revise logic to detect potential excessive memory usage when...
+
+ See merge request libtiff/libtiff!147
+
+2020-04-24 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-176' into 'master'
+ tiff2pdf: get rid of uninitialized memory content
+
+ Closes #176
+
+ See merge request libtiff/libtiff!143
+
+2020-04-24 Even Rouault <even.rouault@spatialys.com>
+
+ tif_jpeg.c: revise logic to detect potential excessive memory usage when decoding multiscan JPEG compressed images
+
+2020-04-19 Thomas Bernard <miniupnp@free.fr>
+
+ tiff2pdf: test the return code of TIFFReadRawStrip() and TIFFReadRawTile()
+
+ tiff2pdf.c: fix some whitespace problems in source.
+
+ tiff2pdf: get rid of uninitialized memory content.
+ fixes #176
+
+2020-04-19 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-18' into 'master'
+ tiffset: pass size for TIFFTAG_INKNAMES
+
+ Closes #18
+
+ See merge request libtiff/libtiff!146
+
+2020-04-18 Olivier Paquet <olivier.paquet@gmail.com>
+
+ Merge branch 'issue-80' into 'master'
+ tiffinfo: fix dump of Tiled images
+
+ Closes #80
+
+ See merge request libtiff/libtiff!144
+
+2020-04-15 Even Rouault <even.rouault@spatialys.com>
+
+ Fix wrong file size checks for memory-mapped BigTIFF files that could lead to image rejection
+
+2020-04-05 Thomas Bernard <miniupnp@free.fr>
+
+ tiffset: pass size for TIFFTAG_INKNAMES.
+ Uses TIFFFieldPassCount() to know which arguments need to be
+ passed to TiffSetField()
+
+ fixes #18
+ see http://bugzilla.maptools.org/show_bug.cgi?id=2202
+
+2020-04-04 Thomas Bernard <miniupnp@free.fr>
+
+ tiffinfo: showdata for tiled images.
+
+ tiffinfo: fix dump of Tiled images.
+ fixes #80
+
+2020-04-03 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-117' into 'master'
+ tiffcrop: enforce memory allocation limit
+
+ Closes #117
+
+ See merge request libtiff/libtiff!140
+
+2020-04-03 Thomas Bernard <miniupnp@free.fr>
+
+ tiffcrop: enforce memory allocation limit.
+ uses -k option to change limit (default to 256MiB)
+ fixes #117 / http://bugzilla.maptools.org/show_bug.cgi?id=2757
+
+2020-04-02 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-45' into 'master'
+ tiffcp: disable strip chopping when trying to convert to JBIG compression
+
+ Closes #45
+
+ See merge request libtiff/libtiff!138
+
+2020-04-02 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-124' into 'master'
+ TIFFGetFields(3tiff): TIFFTAG_*BYTECOUNTS TIFFTAG_*OFFSETS are uint64
+
+ Closes #124
+
+ See merge request libtiff/libtiff!137
+
+2020-04-02 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'aix_itrunc' into 'master'
+ Rename itrunc to fix name clash with a different itrunc in math.h on AIX. Fixes issue #189
+
+ Closes #189
+
+ See merge request libtiff/libtiff!139
+
+2020-04-01 Rob Boehne <robb@datalogics.com>
+
+ Rename itrunc to fix name clash with a different itrunc in math.h on AIX. Fixes issue #189
+
+2020-04-01 Thomas Bernard <miniupnp@free.fr>
+
+ tiffcp: disable strip chopping when trying to convert to JBIG compression
+ fixes #45
+
+2020-03-29 Thomas Bernard <miniupnp@free.fr>
+
+ TIFFGetFields(3tiff): TIFFTAG_*BYTECOUNTS TIFFTAG_*OFFSETS are uint64.
+ fixes #124 / http://bugzilla.maptools.org/show_bug.cgi?id=2774
+
+2020-03-29 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-48' into 'master'
+ tiff2pdf: fix "raw" copy of Deflate streams
+
+ Closes #48
+
+ See merge request libtiff/libtiff!136
+
+2020-03-27 Thomas Bernard <miniupnp@free.fr>
+
+ tiff2pdf: fix "raw" copy of Deflate streams.
+ The Predictor parametter was not copied from the source tiff to the PDF.
+ fixes #48 / http://bugzilla.maptools.org/show_bug.cgi?id=2442
+
+2020-03-26 Thomas Bernard <miniupnp@free.fr>
+
+ tif_fax3: quit Fax3Decode2D() when a buffer overflow occurs.
+ fixes #186
+
+2020-03-24 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-143-144' into 'master'
+ tiffdump: avoid unaligned memory access
+
+ Closes #144 et #143
+
+ See merge request libtiff/libtiff!133
+
+2020-03-24 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-133' into 'master'
+ tiff2pdf: avoid divide by 0
+
+ Closes #133
+
+ See merge request libtiff/libtiff!126
+
+2020-03-24 Thomas Bernard <miniupnp@free.fr>
+
+ tiff2pdf: normalizePoint() macro to normalize the white point.
+
+2020-03-23 Thomas Bernard <miniupnp@free.fr>
+
+ tiffdump: avoid unaligned memory access.
+ fixes #143
+ fixes #144
+
+2020-03-23 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'out-of-memory' into 'master'
+ tiffcp/tiff2pdf/tiff2ps: enforce maximum malloc size
+
+ Closes #153, #84, #116 et #115
+
+ See merge request libtiff/libtiff!130
+
+2020-03-23 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-157' into 'master'
+ tiffset: check memory allocation
+
+ Closes #157
+
+ See merge request libtiff/libtiff!132
+
+2020-03-23 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-185' into 'master'
+ tif_fax3: more buffer overflow checks in Fax3Decode2D()
+
+ Closes #185
+
+ See merge request libtiff/libtiff!131
+
+2020-03-23 Thomas Bernard <miniupnp@free.fr>
+
+ tiffset: check memory allocation.
+ fixes #157 / http://bugzilla.maptools.org/show_bug.cgi?id=2850
+
+ tif_fax3: more buffer overflow checks in Fax3Decode2D()
+ fixes #185
+
+2020-03-21 Thomas Bernard <miniupnp@free.fr>
+
+ tiff2ps: enforce memory allocation limit.
+ fixes #153 / http://bugzilla.maptools.org/show_bug.cgi?id=2845
+
+ tiff2pdf: enforce maximum data size.
+ fixes #116 / http://bugzilla.maptools.org/show_bug.cgi?id=2756
+ fixes #84 / http://bugzilla.maptools.org/show_bug.cgi?id=2683
+
+ update man page for tiffcp regarding the -m option.
+
+ tiffcp.c: _TIFFmalloc() => limitMalloc()
+
+2020-03-21 Thomas Bernard <miniupnp@free.fr>
+
+ tiffcp: enforce maximum malloc size.
+ default is 256MB. use -m option to change
+
+ fixes #115 / http://bugzilla.maptools.org/show_bug.cgi?id=2755
+
+2020-03-21 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-184' into 'master'
+ CmakeLists.txt: define WORDS_BIGENDIAN when the CPU is big endian
+
+ Closes #184
+
+ See merge request libtiff/libtiff!127
+
+2020-03-21 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-44' into 'master'
+ tiff2pdf: "" causes the relevant argument not to be written
+
+ Closes #44
+
+ See merge request libtiff/libtiff!128
+
+2020-03-21 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-56' into 'master'
+ fix man for TIFFReadEncodedStrip(), TIFFStripSize, TIFFVStripSize, TIFFRawStripSize
+
+ Closes #56
+
+ See merge request libtiff/libtiff!129
+
+2020-03-20 Thomas Bernard <miniupnp@free.fr>
+
+ fix man for TIFFReadEncodedStrip(), TIFFStripSize, TIFFVStripSize, TIFFRawStripSize
+ fixes #56
+ http://bugzilla.maptools.org/show_bug.cgi?id=2507
+
+ tiff2pdf: "" causes the relevant argument not to be written.
+ fixes #44
+
+ CmakeLists.txt: define WORDS_BIGENDIAN when the CPU is big endian.
+ fixes #184
+
+2020-03-17 Thomas Bernard <miniupnp@free.fr>
+
+ tiff2pdf: avoid divide by 0.
+ fixes #133 http://bugzilla.maptools.org/show_bug.cgi?id=2796
+
+2020-03-17 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-22' into 'master'
+ do not _tiffMapProc 0 size files
+
+ Closes #22
+
+ See merge request libtiff/libtiff!125
+
+2020-03-13 Thomas Bernard <miniupnp@free.fr>
+
+ tif_win32.c: do not _tiffMapProc() 0 sized files.
+ see #22
+
+ tif_unix.c: do not _tiffMapProc 0 size files.
+ fixes #22
+ http://bugzilla.maptools.org/show_bug.cgi?id=2249
+
+2020-03-12 Even Rouault <even.rouault@spatialys.com>
+
+ tif_fax3.c: fix warning C4018: '<': signed/unsigned mismatch introduced in past commits
+
+2020-03-11 Even Rouault <even.rouault@spatialys.com>
+
+ tiff.h: mention TIFFTAG_RPCCOEFFICIENT, TIFFTAG_TIFF_RSID, TIFFTAG_GEO_METADATA
+
+2020-03-11 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-60' into 'master'
+ added support for more private tags
+
+ Closes #60
+
+ See merge request libtiff/libtiff!124
+
+2020-03-11 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-160' into 'master'
+ Fax3SetupState(): check consistency of rowbytes and rowpixels
+
+ Closes #160
+
+ See merge request libtiff/libtiff!123
+
+2020-03-11 Thomas Bernard <miniupnp@free.fr>
+
+ added support for more private tags.
+ see https://gitlab.com/libtiff/libtiff/-/issues/60
+ bugzilla.maptools.org/show_bug.cgi?id=2525
+
+ closes #60
+
+ original author : art1@andreas-romeyke.de
+
+2020-03-11 Thomas Bernard <miniupnp@free.fr>
+
+ Fax3SetupState(): check consistency of rowbytes and rowpixels.
+ also add some parameter documentation to Fax3Decode1D()
+
+ fixes #160
+ http://bugzilla.maptools.org/show_bug.cgi?id=2854
+
+2020-03-10 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-11-const-pointers' into 'master'
+ Make pointers returned via TIFFGetField const
+
+ Closes #11
+
+ See merge request libtiff/libtiff!118
+
+2020-03-10 Even Rouault <even.rouault@spatialys.com>
+
+ tif_ojpeg.c: relax again too strict sanity checks to allow reading of valid images such as https://gitlab.com/libtiff/libtiff/-/issues/181#note_302535232. Fixes #181
+
+2020-03-09 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-52' into 'master'
+ contrib/win_dib/tiff2dib: fix Uninitialized variable: lpBits
+
+ Closes #52
+
+ See merge request libtiff/libtiff!121
+
+2020-03-09 Thomas Bernard <miniupnp@free.fr>
+
+ contrib/win_dib/tiff2dib: fix Uninitialized variable: lpBits.
+ fixes #52
+ http://bugzilla.maptools.org/show_bug.cgi?id=2469
+
+2020-03-08 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-58' into 'master'
+ Make TIFFTAG_CFAPATTERN variable count
+
+ Closes #58
+
+ See merge request libtiff/libtiff!120
+
+2020-03-08 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-158-no-predictor-in-webp' into 'master'
+ TIFFTAG_PREDICTOR is not supported for WebP
+
+ Closes #158
+
+ See merge request libtiff/libtiff!119
+
+2020-03-08 Sam Hasinoff <hasinoff@google.com>
+
+ Make TIFFTAG_CFAPATTERN variable count.
+ The TIFFTAG_CFAPATTERN tag (33422) from TIFF/EP, recently introduced in libtiff
+ 3363eda09d082e3e1dfffa6281f53085cac51ad3 / http://bugzilla.maptools.org/show_bug.cgi?id=2457
+ is described as having a fixed count of 4.
+ But the TIFF/EP spec says this should support a variable count (= CFARepeatRows * CFARepeatCols):
+
+ TIFF/EP, ISO 12234-2:2001
+ http://www.barrypearson.co.uk/top2009/downloads/TAG2000-22_DIS12234-2.pdf
+ page 18 and 26
+
+2020-03-08 Thomas Bernard <miniupnp@free.fr>
+
+ TIFFTAG_PREDICTOR is not supported for WebP.
+ fixes #158
+ https://gitlab.com/libtiff/libtiff/-/issues/158
+
+ this bug was introduced by 9eacd59fecc4ef593ac17689bc530ab451c8ec14
+ merge request !32
+
+2020-03-07 Adam Goode <adam@spicenitz.org>
+
+ Make the default whitepoint and ycbcrcoeffs arrays const.
+ Now that we are returning const pointers in TIFFGetFieldDefaulted,
+ we can now make these static default arrays const.
+
+ see #11
+
+2020-03-07 Adam Goode <adam@spicenitz.org>
+
+ Make pointers returned via TIFFGetField const.
+ According to http://bugzilla.maptools.org/show_bug.cgi?id=2125#c6
+ callers are not allowed to modify pointer or array values returned from
+ TIFFGetField or the like. So, make this explicit in the documentation
+ by specifying these things as const. Note that this is not an ABI
+ change, since C does not encode const in libraries. Also, this is
+ not really an API change, since the varargs call strips away all
+ the types anyway. So it really is more of a documentation change.
+
+ fixes #11
+
+2020-03-07 Even Rouault <even.rouault@spatialys.com>
+
+ CMake: Skip custom_dir_EXIF_231 test on shared builds to avoid issues on Windows
+
+2020-03-07 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'EXIF231_GPS_upgrade' into 'master'
+ EXIF 2.32 and GPS TIFF-tags and functionality upgraded.
+
+ See merge request libtiff/libtiff!91
+
+2020-03-07 Su_Laus <sulau@freenet.de>
+
+ EXIF 2.32 and GPS tags and functionality upgraded.
+ - Existing EXIF field definition of tags is upgraded to EXIF version 2.3.2
+ - EXIF-GPS structure, tags and access functions are added as special CustomDirectory (like it was done for EXIF).
+ - Test program custom_dir_EXIF_231.c added to test writing/reading of EXID IFD and GPS IFD tags
+ and to highlight some quirks of IFD-handling and peculiarities of reading/writing the different data types.
+ - Reading error for FileSource and SceneType tags corrected.
+
+ - EXIF_GPS_upgrade rebased onto c8c5309b765ef4ff097d2aaffbdb8f403db8967d (Merge branch 'Rational2DoublePrecision_correction' into 'master')
+ and adapted:
+ - tif_dirinfo.c: All rational tags set to TIFF_SETGET_FLOAT but only the GPSTAG_ tags set to TIFF_SETGET_DOUBLE.
+ - custom_dir_EXIF_231.c: Editorials amended and gcc warnigs fixed.
+ - CMakeLists.txt: add_test(NAME "custom_dir_EXIF_231" COMMAND "custom_dir_EXIF_231") added.
+
+2020-03-07 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-55' into 'master'
+ ppm2tiff: support any bps value from 1 to 16
+
+ Closes #55
+
+ See merge request libtiff/libtiff!106
+
+2020-03-07 Thomas Bernard <miniupnp@free.fr>
+
+ ppm2tiff: Add test for 16bpc PPM.
+
+ ppm2tiff: remove unused argument warning.
+
+2020-03-07 Ludolf Holzheid <ludolf.holzheid@gmx.de>
+
+ ppm2tiff: support any bps value from 1 to 16.
+ fix #55
+ http://bugzilla.maptools.org/show_bug.cgi?id=2505
+
+ Patch originally submited by Ludolf Holzheid <ludolf.holzheid@gmx.de>
+
+2020-03-06 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'fax-test' into 'master'
+ add test for fax4 decoding
+
+ See merge request libtiff/libtiff!114
+
+2020-03-05 Thomas Bernard <miniupnp@free.fr>
+
+ add test for fax4 decoding.
+ This will check for regression on #46
+ https://gitlab.com/libtiff/libtiff/issues/46
+ http://bugzilla.maptools.org/show_bug.cgi?id=2434
+
+2020-03-05 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'freebsd-tests' into 'master'
+ make tests pass under FreeBSD.
+
+ See merge request libtiff/libtiff!113
+
+2020-03-05 Thomas Bernard <miniupnp@free.fr>
+
+ make tests pass under FreeBSD.
+ the -I option for the GNU diff and the FreeBSD diff
+ behaves differently regarding escaping the ( ) and |
+
+ By using two -I option, we avoid using such charracters.
+
+2020-03-05 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-31' into 'master'
+ HTML
+
+ Closes #31
+
+ See merge request libtiff/libtiff!111
+
+2020-03-05 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-179' into 'master'
+ tif_fax3.h: check for buffer overflow in EXPAND2D before "calling" CLEANUP_RUNS()
+
+ Closes #179
+
+ See merge request libtiff/libtiff!112
+
+2020-03-05 Thomas Bernard <miniupnp@free.fr>
+
+ v4.1.0.html: fix for validation.
+ long <!----------------> comments were replaced
+ because they confused some parsers
+
+ add DOCTYPE on v*.html.
+
+ fix HTML files so they are valid according to https://validator.w3.org.
+
+2020-03-05 Thomas Bernard <miniupnp@free.fr>
+
+ tif_fax3.h: check for buffer overflow in EXPAND2D before "calling" CLEANUP_RUNS()
+ fixes #179
+
+ this fixes the regression introduced in 02bb0175 / 72c4acef
+ ( merge request !110 )
+
+ It may be a better fix to do the overflow check in SETVALUE() but the
+ macro do { } while(0) construct makes it difficult to quit the loop
+ properly.
+
+2020-03-01 Thomas Bernard <miniupnp@free.fr>
+
+ index.html: fix unclosed <tt> tag.
+
+2020-03-01 Thomas Bernard <miniupnp@free.fr>
+
+ html: do not force colors (which are default anyway)
+ If needed, style should be set using CSS.
+
+ fixes #31
+ https://gitlab.com/libtiff/libtiff/issues/31
+ http://bugzilla.maptools.org/show_bug.cgi?id=2326
+
+2020-03-01 Even Rouault <even.rouault@spatialys.com>
+
+ TIFFReadCustomDirectory(): fix potential heap buffer overflow when reading a custom directory, after a regular directory where a codec was active. Fixes https://gitlab.com/libtiff/libtiff/issues/178
+
+2020-03-01 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-46' into 'master'
+ fix decoding of fax4 images
+
+ Closes #46
+
+ See merge request libtiff/libtiff!110
+
+2020-02-29 Thomas Bernard <miniupnp@free.fr>
+
+ tif_fax3: better fix for CVE-2011-0192.
+ There are some legitimate case which were forbidden by the previous fix
+
+ tif_fax3.h: allow 0 length run in DECODE2D.
+ fixes #46
+ https://gitlab.com/libtiff/libtiff/issues/46
+ http://bugzilla.maptools.org/show_bug.cgi?id=2434
+
+2020-02-29 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'mingwlibm' into 'master'
+ Don't use libm with libtiff due to conflict with libmsvcrt
+
+ See merge request libtiff/libtiff!73
+
+2020-02-29 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'Rational2DoublePrecision_correction' into 'master'
+ tif_dirwrite.c: bugfix DoubleToSrational() for plain signed integers
+
+ See merge request libtiff/libtiff!109
+
+2020-02-29 Su_Laus <sulau@freenet.de>
+
+ tif_dirwrite.c: bugfix DoubleToSrational(), which returns plain signed interger values always as unsigned rationals. Add a test into rational_precision2double.c for "-1.0" and some editorials in tif_dirwrite.c. (code is related to 6df997c786928757caea0dd68d26ea5f098f49df changes).
+
+2020-02-29 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'issue-174' into 'master'
+ tif_fax3.c: check buffer overflow in Fax4Decode()
+
+ Closes #174
+
+ See merge request libtiff/libtiff!108
+
+2020-02-29 Thomas Bernard <miniupnp@free.fr>
+
+ Fax4Decode(): log error message in case of buffer overrun.
+
+ tif_fax3.c: check buffer overflow in Fax4Decode()
+ fixes #174
+
+2020-02-28 Even Rouault <even.rouault@spatialys.com>
+
+ typo fixes in code comments.
+
+ ToRationalEuclideanGCD: remove useless test that confuses Coverity Scan about a potential later modulo by zero
+
+2020-02-27 Even Rouault <even.rouault@spatialys.com>
+
+ tif_dirwrite.c: fix other warnings related to 6df997c786928757caea0dd68d26ea5f098f49df changes
+
+ rational_precision2double.c: fix many warnings, and do not build it on CMake on shared lib builds
+
+ tif_dirwrite.c: fix various warnings found when building GDAL with internal libtiff after 6df997c786928757caea0dd68d26ea5f098f49df changes
+
+ tif_dirwrite.c: qualify ToRationalEuclideanGCD() with static.
+
+2020-02-27 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'Rational2DoublePrecision' into 'master'
+ Rational with Double Precision Upgrade
+
+ See merge request libtiff/libtiff!100
+
+2020-02-27 Su_Laus <sulau@freenet.de>
+
+ Rational with Double Precision Upgrade.
+ Unfortunately, custom rational tags (TIFF_RATIONAL with field_bit=FIELD_CUSTOM) are defined as TIFF_SETGET_DOUBLE
+ but for the reading interface and LibTiff internally they are stored ALLWAYS as floating point SINGLE precision.
+ Double precision custom rational tags are not supported by LibTiff.
+
+ For the GPS tags in WGS84 a higher accuracy / precision is needed.
+ Therefore, this upgrade is made, keeping the old interface for the already defined tags and allowing a double precision definition,
+ as well as calculating rationals with higher accuracy / precision.
+ This higher accuracy can be used for newly defined tags like that in EXIF/GPS.
+
+ Refer also to the very old Bugzilla issue 2542 (#69)
+
+ A test file rational_precision2double.c is added, which shows prevention of the old interface to the already defined custom rational tags
+ with the standard library as well as with the upgraded library.
+
+ Also TIFFTAG_XRESOLUTION, TIFFTAG_YRESOLUTION, TIFFTAG_XPOSITION, TIFFTAG_YPOSITION amended from TIFF_SETGET_DOUBLE to TIFF_SETGET_FLOAT and testcase inserted in rational_precision2double.c
+
+2020-02-26 Chris Degawa <ccom@randomderp.com>
+
+ mingw-w64 cmake: Don't find libm.
+ mingw-w64 will provide libm symbols by default without -lm and mingw-64's
+ libm is just a stub.
+
+ This is just to make sure that on systems with msys2 and also cygwin, cmake
+ doesn't find a libm that actually contains math functions.
+
+2020-02-26 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'division-by-zero' into 'master'
+ tools/tiffcp.c: fix potential division by zero
+
+ See merge request libtiff/libtiff!83
+
+2020-02-26 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'fix-unused-warning' into 'master'
+ warnings: mark conditionally used parameters
+
+ See merge request libtiff/libtiff!49
+
+2020-02-26 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'master' into 'master'
+ fix issue #78 warnings regarding RichTIFFIPTC data type
+
+ Closes #78
+
+ See merge request libtiff/libtiff!99
+
+2020-02-26 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'win64-handle-casts-warn-fix' into 'master'
+ Avoid warnings about casts between HANDLE and int in Win64 builds
+
+ Closes #2
+
+ See merge request libtiff/libtiff!93
+
+2020-02-26 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'bug2839' into 'master'
+ raw2tiff: avoid divide by 0
+
+ Closes #151
+
+ See merge request libtiff/libtiff!103
+
+2020-02-26 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'bug2669' into 'master'
+ tiff2pdf: palette bound check in t2p_sample_realize_palette()
+
+ Closes #82
+
+ See merge request libtiff/libtiff!104
+
+2020-02-26 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'int-shift' into 'master'
+ tiffcrop: fix asan runtime error caused by integer promotion
+
+ See merge request libtiff/libtiff!105
+
+2020-02-26 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'bug-2538' into 'master'
+ libtiff.html: fix function casing
+
+ Closes #68
+
+ See merge request libtiff/libtiff!107
+
+2020-02-16 Thomas Bernard <miniupnp@free.fr>
+
+ raw2tiff: avoid divide by 0.
+ fixes #151 / http://bugzilla.maptools.org/show_bug.cgi?id=2839
+
+ first memcmp() lines before computing corellation
+ and always avoid divide by 0 anyway
+
+2020-02-09 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'bug2855' into 'master'
+ tiff2ps: fix heap buffer read overflow in PSDataColorContig()
+
+ Closes #161
+
+ See merge request libtiff/libtiff!102
+
+2020-02-08 Thomas Bernard <miniupnp@free.fr>
+
+ libtiff.html: fix function casing.
+
+ libtiff.html: fix function casing.
+ fixes #68 / http://bugzilla.maptools.org/show_bug.cgi?id=2538
+
+2020-02-08 Thomas Bernard <miniupnp@free.fr>
+
+ tiffcrop: fix asan runtime error caused by integer promotion.
+ tiffcrop.c:4027:20: runtime error: left shift of 190 by 24 places cannot be represented in type 'int'
+
+ C treats (byte << 24) as an int expression.
+ casting explicitely to unsigned type uint32 avoids the problem.
+
+ the same issue has been fixed elsewhere with a24213691616e7cd35aa3e2805493de80c7e4fcf
+
+ I detected the bug with the test file of #86
+
+2020-02-08 Thomas Bernard <miniupnp@free.fr>
+
+ tiff2pdf: palette bound check in t2p_sample_realize_palette()
+ fixes #82
+
+2020-02-08 Thomas Bernard <miniupnp@free.fr>
+
+ tiff2ps: fix heap buffer read overflow in PSDataColorContig()
+ fixes #161 / http://bugzilla.maptools.org/show_bug.cgi?id=2855
+
+ in 05029fb7f1ecf771abaf90b5705b6cab9eb522a7 I missed that 1 extra byte is read
+ in this loop.
+
+2020-02-05 Even Rouault <even.rouault@spatialys.com>
+
+ tif_dirread.c: suppress CLang static Analyzer 9.0 false positive.
+
+2020-02-01 Even Rouault <even.rouault@spatialys.com>
+
+ TIFFSetupStrips: enforce 2GB limitation of Strip/Tile Offsets/ByteCounts arrays
+ TIFFWriteDirectoryTagData() has an assertion that checks that the
+ arrays are not larger than 2GB. So error out earlier if in that situation.
+
+2020-01-29 Bob Friesenhahn <bfriesen@simple.dallas.tx.us>
+
+ Simplify nmake configuration for building port directory. Now there is only one boolean setting to enable building strtoll() and strtoull() port functions. The boolean setting enables the necessary port files to be built, but the remainder of the logic is via pre-processor code in the common tif_config.h, which was prepared before entering the port directory to do a build.
+
+2020-01-28 Bob Friesenhahn <bfriesen@simple.dallas.tx.us>
+
+ Make sure that tif_config.h is produced prior to entering the port directory and add an include path so that the port files can include tif_config.h. Do not actually include tif_config.h at this time since CMake and Autotools builds are not prepared for that. This issue could be handled by updating the CMake and Autotools builds or by adding a define which directs libport.h to include tif_config.h.
+
+2020-01-26 Bob Friesenhahn <bfriesen@simple.dallas.tx.us>
+
+ Fix nmake build mistakes in my last commit:
+ tif_config.vc.h:
+
+ Always define HAVE_STRTOL/HAVE_STRTOUL.
+ Define HAVE_STRTOLL/HAVE_STRTOULL if _MSC_VER >= 1900.
+
+ nmake.opt:
+
+ Provide defaults suitable for MSVC prior to 14.0.
+
+ libport.h:
+
+ The sense of the pre-processor logic was inverted from what it
+ should be. The intention is to only provide the prototype if the
+ function is missing.
+
+2020-01-25 Bob Friesenhahn <bfriesen@simple.dallas.tx.us>
+
+ Add nmake build support for manually configuring the 'port' files to be built based on MSVC features. Include tif_config.h in tools/tiffset.c.
+
+2020-01-23 Even Rouault <even.rouault@spatialys.com>
+
+ Adjust previous fix to avoid undue warning in some situations triggered by GDAL
+
+2020-01-12 Even Rouault <even.rouault@spatialys.com>
+
+ _TIFFPartialReadStripArray: bring back support for non-conformant SLONG8 data type
+ Such as in https://github.com/OSGeo/gdal/issues/2165
+
+2020-01-07 Even Rouault <even.rouault@spatialys.com>
+
+ test: add test for single-strip OJPEG file without RowsPerStrip tag (like in CR2 files)
+
+ OJPEGReadHeaderInfo: if rowsperstrip not defined, then assume one-single-strip. Complementary fix to 0356ea76bac908c61160d735f078437ace953bd3
+
+2019-12-16 Angel Sánchez <angelsanchez@inedit.com>
+
+ fix issue #78 warnings regarding RichTIFFIPTC data type.
+
+2019-12-14 Even Rouault <even.rouault@spatialys.com>
+
+ contrib/oss-fuzz/build.sh: fix broken if construct.
+
+2019-11-28 Even Rouault <even.rouault@spatialys.com>
+
+ contrib/oss-fuzz/build.sh: other attempt at fixing build failure.
+
+2019-11-20 Even Rouault <even.rouault@spatialys.com>
+
+ contrib/oss-fuzz/build.sh: install liblzma-dev for x86_64 builds.
+
+2019-11-17 Even Rouault <even.rouault@spatialys.com>
+
+ contrib/oss-fuzz/build.sh: install liblzma-dev:i386 on i386 builds.
+
+2019-11-15 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'cmake-parse' into 'master'
+ CMake: simplify parsing variables from configure
+
+ See merge request libtiff/libtiff!98
+
+2019-11-15 Rolf Eike Beer <eb@emlix.com>
+
+ CMake: simplify parsing variables from configure.
+
+2019-11-14 Even Rouault <even.rouault@spatialys.com>
+
+ contrib/oss-fuzz/build.sh: fix ossfuzz build by statically linking to lzma
+
+2019-11-12 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'fix_ojpeg_172' into 'master'
+ OJPEG: fix broken sanity check added in 4.1.0 (#fixes 172)
+
+ See merge request libtiff/libtiff!97
+
+2019-11-11 Even Rouault <even.rouault@spatialys.com>
+
+ OJPEG: fix broken sanity check added in 4.1.0, and add two OJPEG test files
+
+ test/: add missing generated .sh files.
+
+2019-11-04 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'fix-missing-checks-TIFFGetField-tiffcrop' into 'master'
+ adds missing checks on TIFFGetField in tiffcrop tool
+
+ Closes #170
+
+ See merge request libtiff/libtiff!96
+
+2019-11-04 Bug Checkers <coolbugcheckers@gmail.com>
+
+ adds missing checks on TIFFGetField in tiffcrop tool (fixes #170)
+
+2019-11-04 Even Rouault <even.rouault@spatialys.com>
+
+ Merge branch 'adds-missing-TIFFClose-rgb2ycbcr' into 'master'
+ adds a missing TIFFClose in rgb2ycbcr tool
+
+ See merge request libtiff/libtiff!95
+
+2019-11-04 Mansour Ahmadi <mansourweb@gmail.com>
+
+ adds a missing TIFFClose in rgb2ycbcr tool.
+
2019-11-03 Bob Friesenhahn <bfriesen@simple.dallas.tx.us>
libtiff 4.1.0 released.
diff --git a/src/3rdparty/libtiff/RELEASE-DATE b/src/3rdparty/libtiff/RELEASE-DATE
index ad4fa62..1137155 100644
--- a/src/3rdparty/libtiff/RELEASE-DATE
+++ b/src/3rdparty/libtiff/RELEASE-DATE
@@ -1 +1 @@
-20191103
+20201219
diff --git a/src/3rdparty/libtiff/VERSION b/src/3rdparty/libtiff/VERSION
index ee74734..6aba2b2 100644
--- a/src/3rdparty/libtiff/VERSION
+++ b/src/3rdparty/libtiff/VERSION
@@ -1 +1 @@
-4.1.0
+4.2.0
diff --git a/src/3rdparty/libtiff/libtiff/libtiff.def b/src/3rdparty/libtiff/libtiff/libtiff.def
index e34fac5..b2d03fe 100644
--- a/src/3rdparty/libtiff/libtiff/libtiff.def
+++ b/src/3rdparty/libtiff/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/src/3rdparty/libtiff/libtiff/tif_aux.c b/src/3rdparty/libtiff/libtiff/tif_aux.c
index 8188db5..c9f1905 100644
--- a/src/3rdparty/libtiff/libtiff/tif_aux.c
+++ b/src/3rdparty/libtiff/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/src/3rdparty/libtiff/libtiff/tif_compress.c b/src/3rdparty/libtiff/libtiff/tif_compress.c
index 8130ef0..915478f 100644
--- a/src/3rdparty/libtiff/libtiff/tif_compress.c
+++ b/src/3rdparty/libtiff/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/src/3rdparty/libtiff/libtiff/tif_config.h b/src/3rdparty/libtiff/libtiff/tif_config.h
index 73c602f..d780d9b 100644
--- a/src/3rdparty/libtiff/libtiff/tif_config.h
+++ b/src/3rdparty/libtiff/libtiff/tif_config.h
@@ -223,6 +223,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/src/3rdparty/libtiff/libtiff/tif_config.h.in b/src/3rdparty/libtiff/libtiff/tif_config.h.in
index 523da3e..30afd7a 100644
--- a/src/3rdparty/libtiff/libtiff/tif_config.h.in
+++ b/src/3rdparty/libtiff/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/src/3rdparty/libtiff/libtiff/tif_config.vc.h b/src/3rdparty/libtiff/libtiff/tif_config.vc.h
index 5cebfa0..939594f 100644
--- a/src/3rdparty/libtiff/libtiff/tif_config.vc.h
+++ b/src/3rdparty/libtiff/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/src/3rdparty/libtiff/libtiff/tif_dir.c b/src/3rdparty/libtiff/libtiff/tif_dir.c
index 1e0a76c..347b711 100644
--- a/src/3rdparty/libtiff/libtiff/tif_dir.c
+++ b/src/3rdparty/libtiff/libtiff/tif_dir.c
@@ -29,6 +29,7 @@
* (and also some miscellaneous stuff)
*/
#include "tiffiop.h"
+#include <float.h> /*--: for Rational2Double */
/*
* These are used in the backwards compatibility code...
@@ -123,7 +124,7 @@ setExtraSamples(TIFF* tif, va_list ap, uint32* v)
{
TIFFWarningExt(tif->tif_clientdata,module,
"ExtraSamples tag value is changing, "
- "but TransferFunction was read with a different value. Cancelling it");
+ "but TransferFunction was read with a different value. Canceling it");
TIFFClrFieldBit(tif,FIELD_TRANSFERFUNCTION);
_TIFFfree(td->td_transferfunction[0]);
td->td_transferfunction[0] = NULL;
@@ -205,7 +206,7 @@ _TIFFVSetField(TIFF* tif, uint32 tag, va_list ap)
/*
* If the data require post-decoding processing to byte-swap
* samples, set it up here. Note that since tags are required
- * to be ordered, compression code can override this behaviour
+ * to be ordered, compression code can override this behavior
* in the setup method if it wants to roll the post decoding
* work in with its normal work.
*/
@@ -275,7 +276,7 @@ _TIFFVSetField(TIFF* tif, uint32 tag, va_list ap)
{
TIFFWarningExt(tif->tif_clientdata,module,
"SamplesPerPixel tag value is changing, "
- "but SMinSampleValue tag was read with a different value. Cancelling it");
+ "but SMinSampleValue tag was read with a different value. Canceling it");
TIFFClrFieldBit(tif,FIELD_SMINSAMPLEVALUE);
_TIFFfree(td->td_sminsamplevalue);
td->td_sminsamplevalue = NULL;
@@ -284,7 +285,7 @@ _TIFFVSetField(TIFF* tif, uint32 tag, va_list ap)
{
TIFFWarningExt(tif->tif_clientdata,module,
"SamplesPerPixel tag value is changing, "
- "but SMaxSampleValue tag was read with a different value. Cancelling it");
+ "but SMaxSampleValue tag was read with a different value. Canceling it");
TIFFClrFieldBit(tif,FIELD_SMAXSAMPLEVALUE);
_TIFFfree(td->td_smaxsamplevalue);
td->td_smaxsamplevalue = NULL;
@@ -296,7 +297,7 @@ _TIFFVSetField(TIFF* tif, uint32 tag, va_list ap)
{
TIFFWarningExt(tif->tif_clientdata,module,
"SamplesPerPixel tag value is changing, "
- "but TransferFunction was read with a different value. Cancelling it");
+ "but TransferFunction was read with a different value. Canceling it");
TIFFClrFieldBit(tif,FIELD_TRANSFERFUNCTION);
_TIFFfree(td->td_transferfunction[0]);
td->td_transferfunction[0] = NULL;
@@ -393,7 +394,7 @@ _TIFFVSetField(TIFF* tif, uint32 tag, va_list ap)
if (tif->tif_mode != O_RDONLY)
goto badvalue32;
TIFFWarningExt(tif->tif_clientdata, tif->tif_name,
- "Nonstandard tile width %d, convert file", v32);
+ "Nonstandard tile width %u, convert file", v32);
}
td->td_tilewidth = v32;
tif->tif_flags |= TIFF_ISTILED;
@@ -404,7 +405,7 @@ _TIFFVSetField(TIFF* tif, uint32 tag, va_list ap)
if (tif->tif_mode != O_RDONLY)
goto badvalue32;
TIFFWarningExt(tif->tif_clientdata, tif->tif_name,
- "Nonstandard tile length %d, convert file", v32);
+ "Nonstandard tile length %u, convert file", v32);
}
td->td_tilelength = v32;
tif->tif_flags |= TIFF_ISTILED;
@@ -559,6 +560,10 @@ _TIFFVSetField(TIFF* tif, uint32 tag, va_list ap)
* Set custom value ... save a copy of the custom tag value.
*/
tv_size = _TIFFDataSize(fip->field_type);
+ /*--: Rational2Double: For Rationals evaluate "set_field_type" to determine internal storage size. */
+ if (fip->field_type == TIFF_RATIONAL || fip->field_type == TIFF_SRATIONAL) {
+ tv_size = _TIFFSetGetFieldSize(fip->set_field_type);
+ }
if (tv_size == 0) {
status = 0;
TIFFErrorExt(tif->tif_clientdata, module,
@@ -638,6 +643,7 @@ _TIFFVSetField(TIFF* tif, uint32 tag, va_list ap)
|| fip->field_writecount == TIFF_VARIABLE2
|| fip->field_writecount == TIFF_SPP
|| tv->count > 1) {
+ /*--: Rational2Double: For Rationals tv_size is set above to 4 or 8 according to fip->set_field_type! */
_TIFFmemcpy(tv->value, va_arg(ap, void *),
tv->count * tv_size);
} else {
@@ -698,6 +704,22 @@ _TIFFVSetField(TIFF* tif, uint32 tag, va_list ap)
break;
case TIFF_RATIONAL:
case TIFF_SRATIONAL:
+ /*-- Rational2Double: For Rationals tv_size is set above to 4 or 8 according to fip->set_field_type! */
+ {
+ if (tv_size == 8) {
+ double v2 = va_arg(ap, double);
+ _TIFFmemcpy(val, &v2, tv_size);
+ } else {
+ /*-- default should be tv_size == 4 */
+ float v3 = (float)va_arg(ap, double);
+ _TIFFmemcpy(val, &v3, tv_size);
+ /*-- ToDo: After Testing, this should be removed and tv_size==4 should be set as default. */
+ if (tv_size != 4) {
+ TIFFErrorExt(0,"TIFFLib: _TIFFVSetField()", "Rational2Double: .set_field_type in not 4 but %d", tv_size);
+ }
+ }
+ }
+ break;
case TIFF_FLOAT:
{
float v2 = _TIFFClampDoubleToFloat(va_arg(ap, double));
@@ -1011,19 +1033,19 @@ _TIFFVGetField(TIFF* tif, uint32 tag, va_list ap)
*va_arg(ap, uint16*) = td->td_halftonehints[1];
break;
case TIFFTAG_COLORMAP:
- *va_arg(ap, uint16**) = td->td_colormap[0];
- *va_arg(ap, uint16**) = td->td_colormap[1];
- *va_arg(ap, uint16**) = td->td_colormap[2];
+ *va_arg(ap, const uint16**) = td->td_colormap[0];
+ *va_arg(ap, const uint16**) = td->td_colormap[1];
+ *va_arg(ap, const uint16**) = td->td_colormap[2];
break;
case TIFFTAG_STRIPOFFSETS:
case TIFFTAG_TILEOFFSETS:
_TIFFFillStriles( tif );
- *va_arg(ap, uint64**) = td->td_stripoffset_p;
+ *va_arg(ap, const uint64**) = td->td_stripoffset_p;
break;
case TIFFTAG_STRIPBYTECOUNTS:
case TIFFTAG_TILEBYTECOUNTS:
_TIFFFillStriles( tif );
- *va_arg(ap, uint64**) = td->td_stripbytecount_p;
+ *va_arg(ap, const uint64**) = td->td_stripbytecount_p;
break;
case TIFFTAG_MATTEING:
*va_arg(ap, uint16*) =
@@ -1032,7 +1054,7 @@ _TIFFVGetField(TIFF* tif, uint32 tag, va_list ap)
break;
case TIFFTAG_EXTRASAMPLES:
*va_arg(ap, uint16*) = td->td_extrasamples;
- *va_arg(ap, uint16**) = td->td_sampleinfo;
+ *va_arg(ap, const uint16**) = td->td_sampleinfo;
break;
case TIFFTAG_TILEWIDTH:
*va_arg(ap, uint32*) = td->td_tilewidth;
@@ -1067,7 +1089,7 @@ _TIFFVGetField(TIFF* tif, uint32 tag, va_list ap)
break;
case TIFFTAG_SUBIFD:
*va_arg(ap, uint16*) = td->td_nsubifd;
- *va_arg(ap, uint64**) = td->td_subifd;
+ *va_arg(ap, const uint64**) = td->td_subifd;
break;
case TIFFTAG_YCBCRPOSITIONING:
*va_arg(ap, uint16*) = td->td_ycbcrpositioning;
@@ -1077,20 +1099,20 @@ _TIFFVGetField(TIFF* tif, uint32 tag, va_list ap)
*va_arg(ap, uint16*) = td->td_ycbcrsubsampling[1];
break;
case TIFFTAG_TRANSFERFUNCTION:
- *va_arg(ap, uint16**) = td->td_transferfunction[0];
+ *va_arg(ap, const uint16**) = td->td_transferfunction[0];
if (td->td_samplesperpixel - td->td_extrasamples > 1) {
- *va_arg(ap, uint16**) = td->td_transferfunction[1];
- *va_arg(ap, uint16**) = td->td_transferfunction[2];
+ *va_arg(ap, const uint16**) = td->td_transferfunction[1];
+ *va_arg(ap, const uint16**) = td->td_transferfunction[2];
} else {
- *va_arg(ap, uint16**) = NULL;
- *va_arg(ap, uint16**) = NULL;
+ *va_arg(ap, const uint16**) = NULL;
+ *va_arg(ap, const uint16**) = NULL;
}
break;
case TIFFTAG_REFERENCEBLACKWHITE:
- *va_arg(ap, float**) = td->td_refblackwhite;
+ *va_arg(ap, const float**) = td->td_refblackwhite;
break;
case TIFFTAG_INKNAMES:
- *va_arg(ap, char**) = td->td_inknames;
+ *va_arg(ap, const char**) = td->td_inknames;
break;
default:
{
@@ -1132,7 +1154,7 @@ _TIFFVGetField(TIFF* tif, uint32 tag, va_list ap)
*va_arg(ap, uint32*) = (uint32)tv->count;
else /* Assume TIFF_VARIABLE */
*va_arg(ap, uint16*) = (uint16)tv->count;
- *va_arg(ap, void **) = tv->value;
+ *va_arg(ap, const void **) = tv->value;
ret_val = 1;
} else if (fip->field_tag == TIFFTAG_DOTRANGE
&& strcmp(fip->field_name,"DotRange") == 0) {
@@ -1200,6 +1222,23 @@ _TIFFVGetField(TIFF* tif, uint32 tag, va_list ap)
break;
case TIFF_RATIONAL:
case TIFF_SRATIONAL:
+ {
+ /*-- Rational2Double: For Rationals evaluate "set_field_type" to determine internal storage size and return value size. */
+ int tv_size = _TIFFSetGetFieldSize(fip->set_field_type);
+ if (tv_size == 8) {
+ *va_arg(ap, double*) = *(double *)val;
+ ret_val = 1;
+ } else {
+ /*-- default should be tv_size == 4 */
+ *va_arg(ap, float*) = *(float *)val;
+ ret_val = 1;
+ /*-- ToDo: After Testing, this should be removed and tv_size==4 should be set as default. */
+ if (tv_size != 4) {
+ TIFFErrorExt(0,"TIFFLib: _TIFFVGetField()", "Rational2Double: .set_field_type in not 4 but %d", tv_size);
+ }
+ }
+ }
+ break;
case TIFF_FLOAT:
*va_arg(ap, float*) =
*(float *)val;
@@ -1365,6 +1404,17 @@ TIFFCreateEXIFDirectory(TIFF* tif)
}
/*
+ * Creates the EXIF GPS custom directory
+ */
+int
+TIFFCreateGPSDirectory(TIFF* tif)
+{
+ const TIFFFieldArray* gpsFieldArray;
+ gpsFieldArray = _TIFFGetGpsFields();
+ return TIFFCreateCustomDirectory(tif, gpsFieldArray);
+}
+
+/*
* Setup a default directory structure.
*/
int
diff --git a/src/3rdparty/libtiff/libtiff/tif_dir.h b/src/3rdparty/libtiff/libtiff/tif_dir.h
index e7f0667..f608dd7 100644
--- a/src/3rdparty/libtiff/libtiff/tif_dir.h
+++ b/src/3rdparty/libtiff/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/src/3rdparty/libtiff/libtiff/tif_dirinfo.c b/src/3rdparty/libtiff/libtiff/tif_dirinfo.c
index e1f6b23..7217042 100644
--- a/src/3rdparty/libtiff/libtiff/tif_dirinfo.c
+++ b/src/3rdparty/libtiff/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/src/3rdparty/libtiff/libtiff/tif_dirread.c b/src/3rdparty/libtiff/libtiff/tif_dirread.c
index 6f90941..ba127ca 100644
--- a/src/3rdparty/libtiff/libtiff/tif_dirread.c
+++ b/src/3rdparty/libtiff/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/src/3rdparty/libtiff/libtiff/tif_dirwrite.c b/src/3rdparty/libtiff/libtiff/tif_dirwrite.c
index 9e4d306..f481250 100644
--- a/src/3rdparty/libtiff/libtiff/tif_dirwrite.c
+++ b/src/3rdparty/libtiff/libtiff/tif_dirwrite.c
@@ -28,6 +28,8 @@
* Directory Write Support Routines.
*/
#include "tiffiop.h"
+#include <float.h> /*--: for Rational2Double */
+#include <math.h> /*--: for Rational2Double */
#ifdef HAVE_IEEEFP
#define TIFFCvtNativeToIEEEFloat(tif, n, fp)
@@ -154,6 +156,19 @@ static int TIFFWriteDirectoryTagCheckedSlong8Array(TIFF* tif, uint32* ndir, TIFF
static int TIFFWriteDirectoryTagCheckedRational(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, double value);
static int TIFFWriteDirectoryTagCheckedRationalArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, float* value);
static int TIFFWriteDirectoryTagCheckedSrationalArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, float* value);
+
+/*--: Rational2Double: New functions to support true double-precision for custom rational tag types. */
+static int TIFFWriteDirectoryTagRationalDoubleArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, double* value);
+static int TIFFWriteDirectoryTagSrationalDoubleArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, double* value);
+static int TIFFWriteDirectoryTagCheckedRationalDoubleArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, double* value);
+static int TIFFWriteDirectoryTagCheckedSrationalDoubleArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, double* value);
+static void DoubleToRational(double value, uint32 *num, uint32 *denom);
+static void DoubleToSrational(double value, int32 *num, int32 *denom);
+#if 0
+static void DoubleToRational_direct(double value, unsigned long *num, unsigned long *denom);
+static void DoubleToSrational_direct(double value, long *num, long *denom);
+#endif
+
#ifdef notdef
static int TIFFWriteDirectoryTagCheckedFloat(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, float value);
#endif
@@ -796,12 +811,42 @@ TIFFWriteDirectorySec(TIFF* tif, int isimage, int imagedone, uint64* pdiroff)
goto bad;
break;
case TIFF_RATIONAL:
- if (!TIFFWriteDirectoryTagRationalArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))
- goto bad;
+ {
+ /*-- Rational2Double: For Rationals evaluate "set_field_type" to determine internal storage size. */
+ int tv_size;
+ tv_size = _TIFFSetGetFieldSize(tif->tif_dir.td_customValues[m].info->set_field_type);
+ if (tv_size == 8) {
+ if (!TIFFWriteDirectoryTagRationalDoubleArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))
+ goto bad;
+ } else {
+ /*-- default should be tv_size == 4 */
+ if (!TIFFWriteDirectoryTagRationalArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))
+ goto bad;
+ /*-- ToDo: After Testing, this should be removed and tv_size==4 should be set as default. */
+ if (tv_size != 4) {
+ TIFFErrorExt(0,"TIFFLib: _TIFFWriteDirectorySec()", "Rational2Double: .set_field_type in not 4 but %d", tv_size);
+ }
+ }
+ }
break;
case TIFF_SRATIONAL:
- if (!TIFFWriteDirectoryTagSrationalArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))
- goto bad;
+ {
+ /*-- Rational2Double: For Rationals evaluate "set_field_type" to determine internal storage size. */
+ int tv_size;
+ tv_size = _TIFFSetGetFieldSize(tif->tif_dir.td_customValues[m].info->set_field_type);
+ if (tv_size == 8) {
+ if (!TIFFWriteDirectoryTagSrationalDoubleArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))
+ goto bad;
+ } else {
+ /*-- default should be tv_size == 4 */
+ if (!TIFFWriteDirectoryTagSrationalArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))
+ goto bad;
+ /*-- ToDo: After Testing, this should be removed and tv_size==4 should be set as default. */
+ if (tv_size != 4) {
+ TIFFErrorExt(0,"TIFFLib: _TIFFWriteDirectorySec()", "Rational2Double: .set_field_type in not 4 but %d", tv_size);
+ }
+ }
+ }
break;
case TIFF_FLOAT:
if (!TIFFWriteDirectoryTagFloatArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))
@@ -1560,6 +1605,29 @@ TIFFWriteDirectoryTagSrationalArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir,
return(TIFFWriteDirectoryTagCheckedSrationalArray(tif,ndir,dir,tag,count,value));
}
+/*-- Rational2Double: additional write functions */
+static int
+TIFFWriteDirectoryTagRationalDoubleArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, double* value)
+{
+ if (dir==NULL)
+ {
+ (*ndir)++;
+ return(1);
+ }
+ return(TIFFWriteDirectoryTagCheckedRationalDoubleArray(tif,ndir,dir,tag,count,value));
+}
+
+static int
+TIFFWriteDirectoryTagSrationalDoubleArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, double* value)
+{
+ if (dir==NULL)
+ {
+ (*ndir)++;
+ return(1);
+ }
+ return(TIFFWriteDirectoryTagCheckedSrationalDoubleArray(tif,ndir,dir,tag,count,value));
+}
+
#ifdef notdef
static int TIFFWriteDirectoryTagFloat(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, float value)
{
@@ -2318,19 +2386,20 @@ TIFFWriteDirectoryTagCheckedSlong8Array(TIFF* tif, uint32* ndir, TIFFDirEntry* d
static int
TIFFWriteDirectoryTagCheckedRational(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, double value)
{
- static const char module[] = "TIFFWriteDirectoryTagCheckedRational";
+ static const char module[] = "TIFFWriteDirectoryTagCheckedRational";
uint32 m[2];
assert(sizeof(uint32)==4);
- if( value < 0 )
- {
- TIFFErrorExt(tif->tif_clientdata,module,"Negative value is illegal");
- return 0;
- }
- else if( value != value )
- {
- TIFFErrorExt(tif->tif_clientdata,module,"Not-a-number value is illegal");
- return 0;
- }
+ if (value < 0)
+ {
+ TIFFErrorExt(tif->tif_clientdata, module, "Negative value is illegal");
+ return 0;
+ }
+ else if (value != value)
+ {
+ TIFFErrorExt(tif->tif_clientdata, module, "Not-a-number value is illegal");
+ return 0;
+ }
+#ifdef not_def
else if (value==0.0)
{
m[0]=0;
@@ -2351,6 +2420,15 @@ TIFFWriteDirectoryTagCheckedRational(TIFF* tif, uint32* ndir, TIFFDirEntry* dir,
m[0]=0xFFFFFFFF;
m[1]=(uint32)(0xFFFFFFFF/value);
}
+#else
+ /*--Rational2Double: New function also used for non-custom rational tags.
+ * However, could be omitted here, because TIFFWriteDirectoryTagCheckedRational() is not used by code for custom tags,
+ * only by code for named-tiff-tags like FIELD_RESOLUTION and FIELD_POSITION */
+ else {
+ DoubleToRational(value, &m[0], &m[1]);
+ }
+#endif
+
if (tif->tif_flags&TIFF_SWAB)
{
TIFFSwabLong(&m[0]);
@@ -2377,6 +2455,7 @@ TIFFWriteDirectoryTagCheckedRationalArray(TIFF* tif, uint32* ndir, TIFFDirEntry*
}
for (na=value, nb=m, nc=0; nc<count; na++, nb+=2, nc++)
{
+#ifdef not_def
if (*na<=0.0 || *na != *na)
{
nb[0]=0;
@@ -2398,6 +2477,10 @@ TIFFWriteDirectoryTagCheckedRationalArray(TIFF* tif, uint32* ndir, TIFFDirEntry*
nb[0]=0xFFFFFFFF;
nb[1]=(uint32)((double)0xFFFFFFFF/(*na));
}
+#else
+ /*-- Rational2Double: Also for float precision accuracy is sometimes enhanced --*/
+ DoubleToRational(*na, &nb[0], &nb[1]);
+#endif
}
if (tif->tif_flags&TIFF_SWAB)
TIFFSwabArrayOfLong(m,count*2);
@@ -2424,6 +2507,7 @@ TIFFWriteDirectoryTagCheckedSrationalArray(TIFF* tif, uint32* ndir, TIFFDirEntry
}
for (na=value, nb=m, nc=0; nc<count; na++, nb+=2, nc++)
{
+#ifdef not_def
if (*na<0.0)
{
if (*na==(int32)(*na))
@@ -2460,6 +2544,10 @@ TIFFWriteDirectoryTagCheckedSrationalArray(TIFF* tif, uint32* ndir, TIFFDirEntry
nb[1]=(int32)((double)0x7FFFFFFF/(*na));
}
}
+#else
+ /*-- Rational2Double: Also for float precision accuracy is sometimes enhanced --*/
+ DoubleToSrational(*na, &nb[0], &nb[1]);
+#endif
}
if (tif->tif_flags&TIFF_SWAB)
TIFFSwabArrayOfLong((uint32*)m,count*2);
@@ -2468,6 +2556,400 @@ TIFFWriteDirectoryTagCheckedSrationalArray(TIFF* tif, uint32* ndir, TIFFDirEntry
return(o);
}
+/*-- Rational2Double: additional write functions for double arrays */
+static int
+TIFFWriteDirectoryTagCheckedRationalDoubleArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, double* value)
+{
+ static const char module[] = "TIFFWriteDirectoryTagCheckedRationalDoubleArray";
+ uint32* m;
+ double* na;
+ uint32* nb;
+ uint32 nc;
+ int o;
+ assert(sizeof(uint32)==4);
+ m=_TIFFmalloc(count*2*sizeof(uint32));
+ if (m==NULL)
+ {
+ TIFFErrorExt(tif->tif_clientdata,module,"Out of memory");
+ return(0);
+ }
+ for (na=value, nb=m, nc=0; nc<count; na++, nb+=2, nc++)
+ {
+ DoubleToRational(*na, &nb[0], &nb[1]);
+ }
+ if (tif->tif_flags&TIFF_SWAB)
+ TIFFSwabArrayOfLong(m,count*2);
+ o=TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_RATIONAL,count,count*8,&m[0]);
+ _TIFFfree(m);
+ return(o);
+} /*-- TIFFWriteDirectoryTagCheckedRationalDoubleArray() ------- */
+
+static int
+TIFFWriteDirectoryTagCheckedSrationalDoubleArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, double* value)
+{
+ static const char module[] = "TIFFWriteDirectoryTagCheckedSrationalDoubleArray";
+ int32* m;
+ double* na;
+ int32* nb;
+ uint32 nc;
+ int o;
+ assert(sizeof(int32)==4);
+ m=_TIFFmalloc(count*2*sizeof(int32));
+ if (m==NULL)
+ {
+ TIFFErrorExt(tif->tif_clientdata,module,"Out of memory");
+ return(0);
+ }
+ for (na=value, nb=m, nc=0; nc<count; na++, nb+=2, nc++)
+ {
+ DoubleToSrational(*na, &nb[0], &nb[1]);
+ }
+ if (tif->tif_flags&TIFF_SWAB)
+ TIFFSwabArrayOfLong((uint32*)m,count*2);
+ o=TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_SRATIONAL,count,count*8,&m[0]);
+ _TIFFfree(m);
+ return(o);
+} /*--- TIFFWriteDirectoryTagCheckedSrationalDoubleArray() -------- */
+
+#if 0
+static
+void DoubleToRational_direct(double value, unsigned long *num, unsigned long *denom)
+{
+ /*--- OLD Code for debugging and comparison ---- */
+ /* code merged from TIFFWriteDirectoryTagCheckedRationalArray() and TIFFWriteDirectoryTagCheckedRational() */
+
+ /* First check for zero and also check for negative numbers (which are illegal for RATIONAL)
+ * and also check for "not-a-number". In each case just set this to zero to support also rational-arrays.
+ */
+ if (value<=0.0 || value != value)
+ {
+ *num=0;
+ *denom=1;
+ }
+ else if (value <= 0xFFFFFFFFU && (value==(double)(uint32)(value))) /* check for integer values */
+ {
+ *num=(uint32)(value);
+ *denom=1;
+ }
+ else if (value<1.0)
+ {
+ *num = (uint32)((value) * (double)0xFFFFFFFFU);
+ *denom=0xFFFFFFFFU;
+ }
+ else
+ {
+ *num=0xFFFFFFFFU;
+ *denom=(uint32)((double)0xFFFFFFFFU/(value));
+ }
+} /*-- DoubleToRational_direct() -------------- */
+#endif
+
+#if 0
+static
+void DoubleToSrational_direct(double value, long *num, long *denom)
+{
+ /*--- OLD Code for debugging and comparison -- SIGNED-version ----*/
+ /* code was amended from original TIFFWriteDirectoryTagCheckedSrationalArray() */
+
+ /* First check for zero and also check for negative numbers (which are illegal for RATIONAL)
+ * and also check for "not-a-number". In each case just set this to zero to support also rational-arrays.
+ */
+ if (value<0.0)
+ {
+ if (value==(int32)(value))
+ {
+ *num=(int32)(value);
+ *denom=1;
+ }
+ else if (value>-1.0)
+ {
+ *num=-(int32)((-value) * (double)0x7FFFFFFF);
+ *denom=0x7FFFFFFF;
+ }
+ else
+ {
+ *num=-0x7FFFFFFF;
+ *denom=(int32)((double)0x7FFFFFFF / (-value));
+ }
+ }
+ else
+ {
+ if (value==(int32)(value))
+ {
+ *num=(int32)(value);
+ *denom=1;
+ }
+ else if (value<1.0)
+ {
+ *num=(int32)((value) *(double)0x7FFFFFFF);
+ *denom=0x7FFFFFFF;
+ }
+ else
+ {
+ *num=0x7FFFFFFF;
+ *denom=(int32)((double)0x7FFFFFFF / (value));
+ }
+ }
+} /*-- DoubleToSrational_direct() --------------*/
+#endif
+
+//#define DOUBLE2RAT_DEBUGOUTPUT
+/** ----- Rational2Double: Double To Rational Conversion ----------------------------------------------------------
+* There is a mathematical theorem to convert real numbers into a rational (integer fraction) number.
+* This is called "continuous fraction" which uses the Euclidean algorithm to find the greatest common divisor (GCD).
+* (ref. e.g. https://de.wikipedia.org/wiki/Kettenbruch or https://en.wikipedia.org/wiki/Continued_fraction
+* https://en.wikipedia.org/wiki/Euclidean_algorithm)
+* The following functions implement the
+* - ToRationalEuclideanGCD() auxiliary function which mainly implements euclidean GCD
+* - DoubleToRational() conversion function for un-signed rationals
+* - DoubleToSrational() conversion function for signed rationals
+------------------------------------------------------------------------------------------------------------------*/
+
+/**---- ToRationalEuclideanGCD() -----------------------------------------
+* Calculates the rational fractional of a double input value
+* using the Euclidean algorithm to find the greatest common divisor (GCD)
+------------------------------------------------------------------------*/
+static
+void ToRationalEuclideanGCD(double value, int blnUseSignedRange, int blnUseSmallRange, unsigned long long *ullNum, unsigned long long *ullDenom)
+{
+ /* Internally, the integer variables can be bigger than the external ones,
+ * as long as the result will fit into the external variable size.
+ */
+ unsigned long long val, numSum[3] = { 0, 1, 0 }, denomSum[3] = { 1, 0, 0 };
+ unsigned long long aux, bigNum, bigDenom;
+ unsigned long long returnLimit;
+ int i;
+ unsigned long long nMax;
+ double fMax;
+ unsigned long maxDenom;
+ /*-- nMax and fMax defines the initial accuracy of the starting fractional,
+ * or better, the highest used integer numbers used within the starting fractional (bigNum/bigDenom).
+ * There are two approaches, which can accidentally lead to different accuracies just depending on the value.
+ * Therefore, blnUseSmallRange steers this behavior.
+ * For long long nMax = ((9223372036854775807-1)/2); for long nMax = ((2147483647-1)/2);
+ */
+ if (blnUseSmallRange) {
+ nMax = (unsigned long long)((2147483647 - 1) / 2); /* for ULONG range */
+ }
+ else {
+ nMax = ((9223372036854775807 - 1) / 2); /* for ULLONG range */
+ }
+ fMax = (double)nMax;
+
+ /*-- For the Euclidean GCD define the denominator range, so that it stays within size of unsigned long variables.
+ * maxDenom should be LONG_MAX for negative values and ULONG_MAX for positive ones.
+ * Also the final returned value of ullNum and ullDenom is limited according to signed- or unsigned-range.
+ */
+ if (blnUseSignedRange) {
+ maxDenom = 2147483647UL; /*LONG_MAX = 0x7FFFFFFFUL*/
+ returnLimit = maxDenom;
+ }
+ else {
+ maxDenom = 0xFFFFFFFFUL; /*ULONG_MAX = 0xFFFFFFFFUL*/
+ returnLimit = maxDenom;
+ }
+
+ /*-- First generate a rational fraction (bigNum/bigDenom) which represents the value
+ * as a rational number with the highest accuracy. Therefore, unsigned long long (uint64) is needed.
+ * This rational fraction is then reduced using the Euclidean algorithm to find the greatest common divisor (GCD).
+ * bigNum = big numinator of value without fraction (or cut residual fraction)
+ * bigDenom = big denominator of value
+ *-- Break-criteria so that uint64 cast to "bigNum" introduces no error and bigDenom has no overflow,
+ * and stop with enlargement of fraction when the double-value of it reaches an integer number without fractional part.
+ */
+ bigDenom = 1;
+ while ((value != floor(value)) && (value < fMax) && (bigDenom < nMax)) {
+ bigDenom <<= 1;
+ value *= 2;
+ }
+ bigNum = (unsigned long long)value;
+
+ /*-- Start Euclidean algorithm to find the greatest common divisor (GCD) -- */
+#define MAX_ITERATIONS 64
+ for (i = 0; i < MAX_ITERATIONS; i++) {
+ /* if bigDenom is not zero, calculate integer part of fraction. */
+ if (bigDenom == 0) {
+ val = 0;
+ break;
+ }
+ else {
+ val = bigNum / bigDenom;
+ }
+
+ /* Set bigDenom to reminder of bigNum/bigDenom and bigNum to previous denominator bigDenom. */
+ aux = bigNum;
+ bigNum = bigDenom;
+ bigDenom = aux % bigDenom;
+
+ /* calculate next denominator and check for its given maximum */
+ aux = val;
+ if (denomSum[1] * val + denomSum[0] >= maxDenom) {
+ aux = (maxDenom - denomSum[0]) / denomSum[1];
+ if (aux * 2 >= val || denomSum[1] >= maxDenom)
+ i = (MAX_ITERATIONS + 1); /* exit but execute rest of for-loop */
+ else
+ break;
+ }
+ /* calculate next numerator to numSum2 and save previous one to numSum0; numSum1 just copy of numSum2. */
+ numSum[2] = aux * numSum[1] + numSum[0];
+ numSum[0] = numSum[1];
+ numSum[1] = numSum[2];
+ /* calculate next denominator to denomSum2 and save previous one to denomSum0; denomSum1 just copy of denomSum2. */
+ denomSum[2] = aux * denomSum[1] + denomSum[0];
+ denomSum[0] = denomSum[1];
+ denomSum[1] = denomSum[2];
+ }
+
+ /*-- Check and adapt for final variable size and return values; reduces internal accuracy; denominator is kept in ULONG-range with maxDenom -- */
+ while (numSum[1] > returnLimit || denomSum[1] > returnLimit) {
+ numSum[1] = numSum[1] / 2;
+ denomSum[1] = denomSum[1] / 2;
+ }
+
+ /* return values */
+ *ullNum = numSum[1];
+ *ullDenom = denomSum[1];
+
+} /*-- ToRationalEuclideanGCD() -------------- */
+
+
+/**---- DoubleToRational() -----------------------------------------------
+* Calculates the rational fractional of a double input value
+* for UN-SIGNED rationals,
+* using the Euclidean algorithm to find the greatest common divisor (GCD)
+------------------------------------------------------------------------*/
+static
+void DoubleToRational(double value, uint32 *num, uint32 *denom)
+{
+ /*---- UN-SIGNED RATIONAL ---- */
+ double dblDiff, dblDiff2;
+ unsigned long long ullNum, ullDenom, ullNum2, ullDenom2;
+
+ /*-- Check for negative values. If so it is an error. */
+ /* Test written that way to catch NaN */
+ if (!(value >= 0)) {
+ *num = *denom = 0;
+ TIFFErrorExt(0, "TIFFLib: DoubleToRational()", " Negative Value for Unsigned Rational given.");
+ return;
+ }
+
+ /*-- Check for too big numbers (> ULONG_MAX) -- */
+ if (value > 0xFFFFFFFFUL) {
+ *num = 0xFFFFFFFFU;
+ *denom = 0;
+ return;
+ }
+ /*-- Check for easy integer numbers -- */
+ if (value == (uint32)(value)) {
+ *num = (uint32)value;
+ *denom = 1;
+ return;
+ }
+ /*-- Check for too small numbers for "unsigned long" type rationals -- */
+ if (value < 1.0 / (double)0xFFFFFFFFUL) {
+ *num = 0;
+ *denom = 0xFFFFFFFFU;
+ return;
+ }
+
+ /*-- There are two approaches using the Euclidean algorithm,
+ * which can accidentally lead to different accuracies just depending on the value.
+ * Try both and define which one was better.
+ */
+ ToRationalEuclideanGCD(value, FALSE, FALSE, &ullNum, &ullDenom);
+ ToRationalEuclideanGCD(value, FALSE, TRUE, &ullNum2, &ullDenom2);
+ /*-- Double-Check, that returned values fit into ULONG :*/
+ if (ullNum > 0xFFFFFFFFUL || ullDenom > 0xFFFFFFFFUL || ullNum2 > 0xFFFFFFFFUL || ullDenom2 > 0xFFFFFFFFUL) {
+#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
+ TIFFErrorExt(0, "TIFFLib: DoubleToRational()", " Num or Denom exceeds ULONG: val=%14.6f, num=%I64u, denom=%I64u | num2=%I64u, denom2=%I64u", value, ullNum, ullDenom, ullNum2, ullDenom2);
+#else
+ TIFFErrorExt(0, "TIFFLib: DoubleToRational()", " Num or Denom exceeds ULONG: val=%14.6f, num=%12llu, denom=%12llu | num2=%12llu, denom2=%12llu", value, ullNum, ullDenom, ullNum2, ullDenom2);
+#endif
+ assert(0);
+ }
+
+ /* Check, which one has higher accuracy and take that. */
+ dblDiff = fabs(value - ((double)ullNum / (double)ullDenom));
+ dblDiff2 = fabs(value - ((double)ullNum2 / (double)ullDenom2));
+ if (dblDiff < dblDiff2) {
+ *num = (uint32)ullNum;
+ *denom = (uint32)ullDenom;
+ }
+ else {
+ *num = (uint32)ullNum2;
+ *denom = (uint32)ullDenom2;
+ }
+} /*-- DoubleToRational() -------------- */
+
+/**---- DoubleToSrational() -----------------------------------------------
+* Calculates the rational fractional of a double input value
+* for SIGNED rationals,
+* using the Euclidean algorithm to find the greatest common divisor (GCD)
+------------------------------------------------------------------------*/
+static
+void DoubleToSrational(double value, int32 *num, int32 *denom)
+{
+ /*---- SIGNED RATIONAL ----*/
+ int neg = 1;
+ double dblDiff, dblDiff2;
+ unsigned long long ullNum, ullDenom, ullNum2, ullDenom2;
+
+ /*-- Check for negative values and use then the positive one for internal calculations, but take the sign into account before returning. */
+ if (value < 0) { neg = -1; value = -value; }
+
+ /*-- Check for too big numbers (> LONG_MAX) -- */
+ if (value > 0x7FFFFFFFL) {
+ *num = 0x7FFFFFFFL;
+ *denom = 0;
+ return;
+ }
+ /*-- Check for easy numbers -- */
+ if (value == (int32)(value)) {
+ *num = (int32)(neg * value);
+ *denom = 1;
+ return;
+ }
+ /*-- Check for too small numbers for "long" type rationals -- */
+ if (value < 1.0 / (double)0x7FFFFFFFL) {
+ *num = 0;
+ *denom = 0x7FFFFFFFL;
+ return;
+ }
+
+ /*-- There are two approaches using the Euclidean algorithm,
+ * which can accidentally lead to different accuracies just depending on the value.
+ * Try both and define which one was better.
+ * Furthermore, set behavior of ToRationalEuclideanGCD() to the range of signed-long.
+ */
+ ToRationalEuclideanGCD(value, TRUE, FALSE, &ullNum, &ullDenom);
+ ToRationalEuclideanGCD(value, TRUE, TRUE, &ullNum2, &ullDenom2);
+ /*-- Double-Check, that returned values fit into LONG :*/
+ if (ullNum > 0x7FFFFFFFL || ullDenom > 0x7FFFFFFFL || ullNum2 > 0x7FFFFFFFL || ullDenom2 > 0x7FFFFFFFL) {
+#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
+ TIFFErrorExt(0, "TIFFLib: DoubleToSrational()", " Num or Denom exceeds LONG: val=%14.6f, num=%I64u, denom=%I64u | num2=%I64u, denom2=%I64u", neg*value, ullNum, ullDenom, ullNum2, ullDenom2);
+#else
+ TIFFErrorExt(0, "TIFFLib: DoubleToSrational()", " Num or Denom exceeds LONG: val=%14.6f, num=%12llu, denom=%12llu | num2=%12llu, denom2=%12llu", neg*value, ullNum, ullDenom, ullNum2, ullDenom2);
+#endif
+ assert(0);
+ }
+
+ /* Check, which one has higher accuracy and take that. */
+ dblDiff = fabs(value - ((double)ullNum / (double)ullDenom));
+ dblDiff2 = fabs(value - ((double)ullNum2 / (double)ullDenom2));
+ if (dblDiff < dblDiff2) {
+ *num = (int32)(neg * (long)ullNum);
+ *denom = (int32)ullDenom;
+ }
+ else {
+ *num = (int32)(neg * (long)ullNum2);
+ *denom = (int32)ullDenom2;
+ }
+} /*-- DoubleToSrational() --------------*/
+
+
+
+
+
#ifdef notdef
static int
TIFFWriteDirectoryTagCheckedFloat(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, float value)
diff --git a/src/3rdparty/libtiff/libtiff/tif_fax3.c b/src/3rdparty/libtiff/libtiff/tif_fax3.c
index d11c968..9ab5b26 100644
--- a/src/3rdparty/libtiff/libtiff/tif_fax3.c
+++ b/src/3rdparty/libtiff/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/src/3rdparty/libtiff/libtiff/tif_fax3.h b/src/3rdparty/libtiff/libtiff/tif_fax3.h
index abadcd9..701716c 100644
--- a/src/3rdparty/libtiff/libtiff/tif_fax3.h
+++ b/src/3rdparty/libtiff/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/src/3rdparty/libtiff/libtiff/tif_fax3sm.c b/src/3rdparty/libtiff/libtiff/tif_fax3sm.c
index 822191e..ba2fc53 100644
--- a/src/3rdparty/libtiff/libtiff/tif_fax3sm.c
+++ b/src/3rdparty/libtiff/libtiff/tif_fax3sm.c
@@ -1,5 +1,6 @@
/* WARNING, this file was automatically generated by the
mkg3states program */
+#include <stdint.h>
#include "tiff.h"
#include "tif_fax3.h"
const TIFFFaxTabEnt TIFFFaxMainTable[128] = {
diff --git a/src/3rdparty/libtiff/libtiff/tif_getimage.c b/src/3rdparty/libtiff/libtiff/tif_getimage.c
index 4da785d..3460af7 100644
--- a/src/3rdparty/libtiff/libtiff/tif_getimage.c
+++ b/src/3rdparty/libtiff/libtiff/tif_getimage.c
@@ -29,6 +29,7 @@
*/
#include "tiffiop.h"
#include <stdio.h>
+#include <limits.h>
static int gtTileContig(TIFFRGBAImage*, uint32*, uint32, uint32);
static int gtTileSeparate(TIFFRGBAImage*, uint32*, uint32, uint32);
@@ -645,12 +646,20 @@ gtTileContig(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h)
flip = setorientation(img);
if (flip & FLIP_VERTICALLY) {
- y = h - 1;
- toskew = -(int32)(tw + w);
+ if ((tw + w) > INT_MAX) {
+ TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "%s", "unsupported tile size (too wide)");
+ return (0);
+ }
+ y = h - 1;
+ toskew = -(int32)(tw + w);
}
else {
- y = 0;
- toskew = -(int32)(tw - w);
+ if (tw > (INT_MAX + w)) {
+ TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "%s", "unsupported tile size (too wide)");
+ return (0);
+ }
+ y = 0;
+ toskew = -(int32)(tw - w);
}
/*
@@ -765,10 +774,18 @@ gtTileSeparate(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h)
flip = setorientation(img);
if (flip & FLIP_VERTICALLY) {
+ if ((tw + w) > INT_MAX) {
+ TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "%s", "unsupported tile size (too wide)");
+ return (0);
+ }
y = h - 1;
toskew = -(int32)(tw + w);
}
else {
+ if (tw > (INT_MAX + w)) {
+ TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "%s", "unsupported tile size (too wide)");
+ return (0);
+ }
y = 0;
toskew = -(int32)(tw - w);
}
@@ -936,6 +953,10 @@ gtStripContig(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h)
flip = setorientation(img);
if (flip & FLIP_VERTICALLY) {
+ if ( w > INT_MAX ) {
+ TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "Width overflow");
+ return (0);
+ }
y = h - 1;
toskew = -(int32)(w + w);
} else {
@@ -1032,6 +1053,10 @@ gtStripSeparate(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h)
flip = setorientation(img);
if (flip & FLIP_VERTICALLY) {
+ if ( w > INT_MAX ) {
+ TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "Width overflow");
+ return (0);
+ }
y = h - 1;
toskew = -(int32)(w + w);
}
diff --git a/src/3rdparty/libtiff/libtiff/tif_jbig.c b/src/3rdparty/libtiff/libtiff/tif_jbig.c
index 7ffe885..a3500e0 100644
--- a/src/3rdparty/libtiff/libtiff/tif_jbig.c
+++ b/src/3rdparty/libtiff/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/src/3rdparty/libtiff/libtiff/tif_jpeg.c b/src/3rdparty/libtiff/libtiff/tif_jpeg.c
index 93ae2ea..6711137 100644
--- a/src/3rdparty/libtiff/libtiff/tif_jpeg.c
+++ b/src/3rdparty/libtiff/libtiff/tif_jpeg.c
@@ -466,7 +466,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;
@@ -937,7 +938,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;
@@ -1206,35 +1210,37 @@ JPEGPreDecode(TIFF* tif, uint16 s)
/* store for all coefficients */
/* See call to jinit_d_coef_controller() from master_selection() */
/* in libjpeg */
- toff_t nRequiredMemory = (toff_t)sp->cinfo.d.image_width *
- sp->cinfo.d.image_height *
- sp->cinfo.d.num_components *
- ((td->td_bitspersample+7)/8);
- /* BLOCK_SMOOTHING_SUPPORTED is generally defined, so we need */
- /* to replicate the logic of jinit_d_coef_controller() */
- if( sp->cinfo.d.progressive_mode )
- nRequiredMemory *= 3;
-
-#ifndef TIFF_LIBJPEG_LARGEST_MEM_ALLOC
-#define TIFF_LIBJPEG_LARGEST_MEM_ALLOC (100 * 1024 * 1024)
-#endif
- if( nRequiredMemory > TIFF_LIBJPEG_LARGEST_MEM_ALLOC &&
+ /* 1 MB for regular libjpeg usage */
+ toff_t nRequiredMemory = 1024 * 1024;
+
+ for (ci = 0; ci < sp->cinfo.d.num_components; ci++) {
+ const jpeg_component_info *compptr = &(sp->cinfo.d.comp_info[ci]);
+ if( compptr->h_samp_factor > 0 && compptr->v_samp_factor > 0 )
+ {
+ nRequiredMemory += (toff_t)(
+ ((compptr->width_in_blocks + compptr->h_samp_factor - 1) / compptr->h_samp_factor)) *
+ ((compptr->height_in_blocks + compptr->v_samp_factor - 1) / compptr->v_samp_factor) *
+ sizeof(JBLOCK);
+ }
+ }
+
+ if( sp->cinfo.d.mem->max_memory_to_use > 0 &&
+ nRequiredMemory > (toff_t)(sp->cinfo.d.mem->max_memory_to_use) &&
getenv("LIBTIFF_ALLOW_LARGE_LIBJPEG_MEM_ALLOC") == NULL )
{
- TIFFErrorExt(tif->tif_clientdata, module,
- "Reading this strip would require libjpeg to allocate "
- "at least %u bytes. "
- "This is disabled since above the %u threshold. "
- "You may override this restriction by defining the "
- "LIBTIFF_ALLOW_LARGE_LIBJPEG_MEM_ALLOC environment variable, "
- "or recompile libtiff by defining the "
- "TIFF_LIBJPEG_LARGEST_MEM_ALLOC macro to a value greater "
- "than %u",
- (unsigned)nRequiredMemory,
- (unsigned)TIFF_LIBJPEG_LARGEST_MEM_ALLOC,
- (unsigned)TIFF_LIBJPEG_LARGEST_MEM_ALLOC);
- return (0);
+ TIFFErrorExt(tif->tif_clientdata, module,
+ "Reading this image would require libjpeg to allocate "
+ "at least %u bytes. "
+ "This is disabled since above the %u threshold. "
+ "You may override this restriction by defining the "
+ "LIBTIFF_ALLOW_LARGE_LIBJPEG_MEM_ALLOC environment variable, "
+ "or setting the JPEGMEM environment variable to a value greater "
+ "or equal to '%uM'",
+ (unsigned)(nRequiredMemory),
+ (unsigned)(sp->cinfo.d.mem->max_memory_to_use),
+ (unsigned)((nRequiredMemory + 1000000 - 1) / 1000000));
+ return 0;
}
}
@@ -2344,7 +2350,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;
@@ -2479,6 +2485,7 @@ TIFFInitJPEG(TIFF* tif, int scheme)
{
JPEGState* sp;
+ (void)scheme;
assert(scheme == COMPRESSION_JPEG);
/*
diff --git a/src/3rdparty/libtiff/libtiff/tif_luv.c b/src/3rdparty/libtiff/libtiff/tif_luv.c
index 6fe4858..3bd02e8 100644
--- a/src/3rdparty/libtiff/libtiff/tif_luv.c
+++ b/src/3rdparty/libtiff/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/src/3rdparty/libtiff/libtiff/tif_lzma.c b/src/3rdparty/libtiff/libtiff/tif_lzma.c
index 3f6096b..e150bd6 100644
--- a/src/3rdparty/libtiff/libtiff/tif_lzma.c
+++ b/src/3rdparty/libtiff/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/src/3rdparty/libtiff/libtiff/tif_lzw.c b/src/3rdparty/libtiff/libtiff/tif_lzw.c
index 21064f2..d92d0fd 100644
--- a/src/3rdparty/libtiff/libtiff/tif_lzw.c
+++ b/src/3rdparty/libtiff/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/src/3rdparty/libtiff/libtiff/tif_ojpeg.c b/src/3rdparty/libtiff/libtiff/tif_ojpeg.c
index bf0d1a2..133d1f1 100644
--- a/src/3rdparty/libtiff/libtiff/tif_ojpeg.c
+++ b/src/3rdparty/libtiff/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/src/3rdparty/libtiff/libtiff/tif_open.c b/src/3rdparty/libtiff/libtiff/tif_open.c
index 3cb53d4..a0e3158 100644
--- a/src/3rdparty/libtiff/libtiff/tif_open.c
+++ b/src/3rdparty/libtiff/libtiff/tif_open.c
@@ -104,6 +104,7 @@ TIFFClientOpen(
} n;
n.a8[0]=1;
n.a8[1]=0;
+ (void)n;
#ifdef WORDS_BIGENDIAN
assert(n.a16==256);
#else
@@ -165,7 +166,7 @@ TIFFClientOpen(
/*
* Process library-specific flags in the open mode string.
* The following flags may be used to control intrinsic library
- * behaviour that may or may not be desirable (usually for
+ * behavior that may or may not be desirable (usually for
* compatibility with some application that claims to support
* TIFF but only supports some brain dead idea of what the
* vendor thinks TIFF is):
@@ -206,7 +207,7 @@ TIFFClientOpen(
* not do right now.
*
* The 'M' and 'm' flags are provided because some virtual memory
- * systems exhibit poor behaviour when large images are mapped.
+ * systems exhibit poor behavior when large images are mapped.
* These options permit clients to control the use of memory-mapped
* files on a per-file basis.
*
diff --git a/src/3rdparty/libtiff/libtiff/tif_pixarlog.c b/src/3rdparty/libtiff/libtiff/tif_pixarlog.c
index 6264090..f291201 100644
--- a/src/3rdparty/libtiff/libtiff/tif_pixarlog.c
+++ b/src/3rdparty/libtiff/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/src/3rdparty/libtiff/libtiff/tif_predict.c b/src/3rdparty/libtiff/libtiff/tif_predict.c
index b775663..c023397 100644
--- a/src/3rdparty/libtiff/libtiff/tif_predict.c
+++ b/src/3rdparty/libtiff/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/src/3rdparty/libtiff/libtiff/tif_read.c b/src/3rdparty/libtiff/libtiff/tif_read.c
index 527fadd..c4c868b 100644
--- a/src/3rdparty/libtiff/libtiff/tif_read.c
+++ b/src/3rdparty/libtiff/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/src/3rdparty/libtiff/libtiff/tif_unix.c b/src/3rdparty/libtiff/libtiff/tif_unix.c
index 874f1fe..bea1ef7 100644
--- a/src/3rdparty/libtiff/libtiff/tif_unix.c
+++ b/src/3rdparty/libtiff/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/src/3rdparty/libtiff/libtiff/tif_win32.c b/src/3rdparty/libtiff/libtiff/tif_win32.c
index 088880e..8964569 100644
--- a/src/3rdparty/libtiff/libtiff/tif_win32.c
+++ b/src/3rdparty/libtiff/libtiff/tif_win32.c
@@ -27,33 +27,37 @@
* Scott Wagner (wagner@itek.com), Itek Graphix, Rochester, NY USA
*/
-/*
- CreateFileA/CreateFileW return type 'HANDLE'.
-
- thandle_t is declared like
-
- DECLARE_HANDLE(thandle_t);
+#include "tiffiop.h"
- in tiffio.h.
+#include <windows.h>
- Windows (from winnt.h) DECLARE_HANDLE logic looks like
+/*
+ CreateFileA/CreateFileW return type 'HANDLE' while TIFFFdOpen() takes 'int',
+ which is formally incompatible and can even seemingly be of different size:
+ HANDLE is 64 bit under Win64, while int is still 32 bits there.
- #ifdef STRICT
- typedef void *HANDLE;
- #define DECLARE_HANDLE(name) struct name##__ { int unused; }; typedef struct name##__ *name
- #else
- typedef PVOID HANDLE;
- #define DECLARE_HANDLE(name) typedef HANDLE name
- #endif
+ However, only the lower 32 bits of a HANDLE are significant under Win64 as,
+ for interoperability reasons, they must have the same values in 32- and
+ 64-bit programs running on the same system, see
- See http://bugzilla.maptools.org/show_bug.cgi?id=1941 for problems in WIN64
- builds resulting from this. Unfortunately, the proposed patch was lost.
+ https://docs.microsoft.com/en-us/windows/win32/winprog64/interprocess-communication
+ Because of this, it is safe to define the following trivial functions for
+ casting between ints and HANDLEs, which are only really needed to avoid
+ compiler warnings (and, perhaps, to make the code slightly more clear).
+ Note that using the intermediate cast to "intptr_t" is crucial for warning
+ avoidance, as this integer type has the same size as HANDLE in all builds.
*/
-
-#include "tiffiop.h"
-#include <windows.h>
+static inline thandle_t thandle_from_int(int ifd)
+{
+ return (thandle_t)(intptr_t)ifd;
+}
+
+static inline int thandle_to_int(thandle_t fd)
+{
+ return (int)(intptr_t)fd;
+}
static tmsize_t
_tiffReadProc(thandle_t fd, void* buf, tmsize_t size)
@@ -151,9 +155,11 @@ _tiffCloseProc(thandle_t fd)
static uint64
_tiffSizeProc(thandle_t fd)
{
- ULARGE_INTEGER m;
- m.LowPart=GetFileSize(fd,&m.HighPart);
- return(m.QuadPart);
+ LARGE_INTEGER m;
+ if (GetFileSizeEx(fd,&m))
+ return(m.QuadPart);
+ else
+ return(0);
}
static int
@@ -185,7 +191,7 @@ _tiffMapProc(thandle_t fd, void** pbase, toff_t* psize)
size = _tiffSizeProc(fd);
sizem = (tmsize_t)size;
- if ((uint64)sizem!=size)
+ if (!size || (uint64)sizem!=size)
return (0);
/* By passing in 0 for the maximum file size, it specifies that we
@@ -237,7 +243,7 @@ TIFFFdOpen(int ifd, const char* name, const char* mode)
break;
}
}
- tif = TIFFClientOpen(name, mode, (thandle_t)ifd, /* FIXME: WIN64 cast to pointer warning */
+ tif = TIFFClientOpen(name, mode, thandle_from_int(ifd),
_tiffReadProc, _tiffWriteProc,
_tiffSeekProc, _tiffCloseProc, _tiffSizeProc,
fSuppressMap ? _tiffDummyMapProc : _tiffMapProc,
@@ -282,7 +288,7 @@ TIFFOpen(const char* name, const char* mode)
return ((TIFF *)0);
}
- tif = TIFFFdOpen((int)fd, name, mode); /* FIXME: WIN64 cast from pointer to int warning */
+ tif = TIFFFdOpen(thandle_to_int(fd), name, mode);
if(!tif)
CloseHandle(fd);
return tif;
@@ -337,7 +343,7 @@ TIFFOpenW(const wchar_t* name, const char* mode)
NULL, NULL);
}
- tif = TIFFFdOpen((int)fd, /* FIXME: WIN64 cast from pointer to int warning */
+ tif = TIFFFdOpen(thandle_to_int(fd),
(mbname != NULL) ? mbname : "<unknown>", mode);
if(!tif)
CloseHandle(fd);
diff --git a/src/3rdparty/libtiff/libtiff/tif_write.c b/src/3rdparty/libtiff/libtiff/tif_write.c
index 33e803c..3af69ab 100644
--- a/src/3rdparty/libtiff/libtiff/tif_write.c
+++ b/src/3rdparty/libtiff/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/src/3rdparty/libtiff/libtiff/tif_zip.c b/src/3rdparty/libtiff/libtiff/tif_zip.c
index c750773..e71c312 100644
--- a/src/3rdparty/libtiff/libtiff/tif_zip.c
+++ b/src/3rdparty/libtiff/libtiff/tif_zip.c
@@ -29,24 +29,22 @@
*
* ZIP (aka Deflate) Compression Support
*
- * This file is simply an interface to the zlib library written by
+ * This file is an interface to the zlib library written by
* Jean-loup Gailly and Mark Adler. You must use version 1.0 or later
- * of the library: this code assumes the 1.0 API and also depends on
- * the ability to write the zlib header multiple times (one per strip)
- * which was not possible with versions prior to 0.95. Note also that
- * older versions of this codec avoided this bug by suppressing the header
- * entirely. This means that files written with the old library cannot
- * be read; they should be converted to a different compression scheme
- * and then reconverted.
+ * of the library.
*
- * The data format used by the zlib library is described in the files
- * zlib-3.1.doc, deflate-1.1.doc and gzip-4.1.doc, available in the
- * directory ftp://ftp.uu.net/pub/archiving/zip/doc. The library was
- * last found at ftp://ftp.uu.net/pub/archiving/zip/zlib/zlib-0.99.tar.gz.
+ * Optionally, libdeflate (https://github.com/ebiggers/libdeflate) may be used
+ * to do the compression and decompression, but only for whole strips and tiles.
+ * For scanline access, zlib will be sued as a fallback.
*/
#include "tif_predict.h"
#include "zlib.h"
+#if LIBDEFLATE_SUPPORT
+#include "libdeflate.h"
+#endif
+#define LIBDEFLATE_MAX_COMPRESSION_LEVEL 12
+
#include <stdio.h>
/*
@@ -70,6 +68,12 @@ typedef struct {
z_stream stream;
int zipquality; /* compression level */
int state; /* state flags */
+ int subcodec; /* DEFLATE_SUBCODEC_ZLIB or DEFLATE_SUBCODEC_LIBDEFLATE */
+#if LIBDEFLATE_SUPPORT
+ int libdeflate_state; /* -1 = until first time ZIPEncode() / ZIPDecode() is called, 0 = use zlib, 1 = use libdeflate */
+ struct libdeflate_decompressor* libdeflate_dec;
+ struct libdeflate_compressor* libdeflate_enc;
+#endif
#define ZSTATE_INIT_DECODE 0x01
#define ZSTATE_INIT_ENCODE 0x02
@@ -132,6 +136,9 @@ ZIPPreDecode(TIFF* tif, uint16 s)
if( (sp->state & ZSTATE_INIT_DECODE) == 0 )
tif->tif_setupdecode( tif );
+#if LIBDEFLATE_SUPPORT
+ sp->libdeflate_state = -1;
+#endif
sp->stream.next_in = tif->tif_rawdata;
assert(sizeof(sp->stream.avail_in)==4); /* if this assert gets raised,
we need to simplify this code to reflect a ZLib that is likely updated
@@ -151,6 +158,77 @@ ZIPDecode(TIFF* tif, uint8* op, tmsize_t occ, uint16 s)
assert(sp != NULL);
assert(sp->state == ZSTATE_INIT_DECODE);
+#if LIBDEFLATE_SUPPORT
+ if( sp->libdeflate_state == 1 )
+ return 0;
+
+ /* If we have libdeflate support and we are asked to read a whole */
+ /* strip/tile, then go for using it */
+ do {
+ TIFFDirectory *td = &tif->tif_dir;
+
+ if( sp->libdeflate_state == 0 )
+ break;
+ if( sp->subcodec == DEFLATE_SUBCODEC_ZLIB )
+ break;
+
+ /* Check if we are in the situation where we can use libdeflate */
+ if (isTiled(tif)) {
+ if( TIFFTileSize64(tif) != (uint64)occ )
+ break;
+ } else {
+ uint32 strip_height = td->td_imagelength - tif->tif_row;
+ if (strip_height > td->td_rowsperstrip)
+ strip_height = td->td_rowsperstrip;
+ if( TIFFVStripSize64(tif, strip_height) != (uint64)occ )
+ break;
+ }
+
+ /* Check for overflow */
+ if( (size_t)tif->tif_rawcc != (uint64)tif->tif_rawcc )
+ break;
+ if( (size_t)occ != (uint64)occ )
+ break;
+
+ /* Go for decompression using libdeflate */
+ {
+ enum libdeflate_result res;
+ if( sp->libdeflate_dec == NULL )
+ {
+ sp->libdeflate_dec = libdeflate_alloc_decompressor();
+ if( sp->libdeflate_dec == NULL )
+ {
+ break;
+ }
+ }
+
+ sp->libdeflate_state = 1;
+
+ res = libdeflate_zlib_decompress(
+ sp->libdeflate_dec, tif->tif_rawcp, (size_t)tif->tif_rawcc, op, (size_t)occ, NULL);
+
+ tif->tif_rawcp += tif->tif_rawcc;
+ tif->tif_rawcc = 0;
+
+ /* We accept LIBDEFLATE_INSUFFICIENT_SPACE has a return */
+ /* There are odd files in the wild where the last strip, when */
+ /* it is smaller in height than td_rowsperstrip, actually contains */
+ /* data for td_rowsperstrip lines. Just ignore that silently. */
+ if( res != LIBDEFLATE_SUCCESS &&
+ res != LIBDEFLATE_INSUFFICIENT_SPACE )
+ {
+ TIFFErrorExt(tif->tif_clientdata, module,
+ "Decoding error at scanline %lu",
+ (unsigned long) tif->tif_row);
+ return 0;
+ }
+
+ return 1;
+ }
+ } while(0);
+ sp->libdeflate_state = 0;
+#endif /* LIBDEFLATE_SUPPORT */
+
sp->stream.next_in = tif->tif_rawcp;
sp->stream.next_out = op;
@@ -198,6 +276,7 @@ ZIPSetupEncode(TIFF* tif)
{
static const char module[] = "ZIPSetupEncode";
ZIPState* sp = EncoderState(tif);
+ int cappedQuality;
assert(sp != NULL);
if (sp->state & ZSTATE_INIT_DECODE) {
@@ -205,7 +284,11 @@ ZIPSetupEncode(TIFF* tif)
sp->state = 0;
}
- if (deflateInit(&sp->stream, sp->zipquality) != Z_OK) {
+ cappedQuality = sp->zipquality;
+ if( cappedQuality > Z_BEST_COMPRESSION )
+ cappedQuality = Z_BEST_COMPRESSION;
+
+ if (deflateInit(&sp->stream, cappedQuality) != Z_OK) {
TIFFErrorExt(tif->tif_clientdata, module, "%s", SAFE_MSG(sp));
return (0);
} else {
@@ -227,6 +310,9 @@ ZIPPreEncode(TIFF* tif, uint16 s)
if( sp->state != ZSTATE_INIT_ENCODE )
tif->tif_setupencode( tif );
+#if LIBDEFLATE_SUPPORT
+ sp->libdeflate_state = -1;
+#endif
sp->stream.next_out = tif->tif_rawdata;
assert(sizeof(sp->stream.avail_out)==4); /* if this assert gets raised,
we need to simplify this code to reflect a ZLib that is likely updated
@@ -249,6 +335,95 @@ ZIPEncode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
assert(sp->state == ZSTATE_INIT_ENCODE);
(void) s;
+
+#if LIBDEFLATE_SUPPORT
+ if( sp->libdeflate_state == 1 )
+ return 0;
+
+ /* If we have libdeflate support and we are asked to write a whole */
+ /* strip/tile, then go for using it */
+ do {
+ TIFFDirectory *td = &tif->tif_dir;
+
+ if( sp->libdeflate_state == 0 )
+ break;
+ if( sp->subcodec == DEFLATE_SUBCODEC_ZLIB )
+ break;
+
+ /* Libdeflate does not support the 0-compression level */
+ if( sp->zipquality == Z_NO_COMPRESSION )
+ break;
+
+ /* Check if we are in the situation where we can use libdeflate */
+ if (isTiled(tif)) {
+ if( TIFFTileSize64(tif) != (uint64)cc )
+ break;
+ } else {
+ uint32 strip_height = td->td_imagelength - tif->tif_row;
+ if (strip_height > td->td_rowsperstrip)
+ strip_height = td->td_rowsperstrip;
+ if( TIFFVStripSize64(tif, strip_height) != (uint64)cc )
+ break;
+ }
+
+ /* Check for overflow */
+ if( (size_t)tif->tif_rawdatasize != (uint64)tif->tif_rawdatasize )
+ break;
+ if( (size_t)cc != (uint64)cc )
+ break;
+
+ /* Go for compression using libdeflate */
+ {
+ size_t nCompressedBytes;
+ if( sp->libdeflate_enc == NULL )
+ {
+ /* To get results as good as zlib, we asked for an extra */
+ /* level of compression */
+ sp->libdeflate_enc = libdeflate_alloc_compressor(
+ sp->zipquality == Z_DEFAULT_COMPRESSION ? 7 :
+ sp->zipquality >= 6 && sp->zipquality <= 9 ? sp->zipquality + 1 :
+ sp->zipquality);
+ if( sp->libdeflate_enc == NULL )
+ {
+ TIFFErrorExt(tif->tif_clientdata, module,
+ "Cannot allocate compressor");
+ break;
+ }
+ }
+
+ /* Make sure the output buffer is large enough for the worse case. */
+ /* In TIFFWriteBufferSetup(), when libtiff allocates the buffer */
+ /* we've taken a 10% margin over the uncompressed size, which should */
+ /* be large enough even for the the worse case scenario. */
+ if( libdeflate_zlib_compress_bound(sp->libdeflate_enc, (size_t)cc) >
+ (size_t)tif->tif_rawdatasize)
+ {
+ break;
+ }
+
+ sp->libdeflate_state = 1;
+ nCompressedBytes = libdeflate_zlib_compress(
+ sp->libdeflate_enc, bp, (size_t)cc, tif->tif_rawdata, (size_t)tif->tif_rawdatasize);
+
+ if( nCompressedBytes == 0 )
+ {
+ TIFFErrorExt(tif->tif_clientdata, module,
+ "Encoder error at scanline %lu",
+ (unsigned long) tif->tif_row);
+ return 0;
+ }
+
+ tif->tif_rawcc = nCompressedBytes;
+
+ if( !TIFFFlushData1(tif) )
+ return 0;
+
+ return 1;
+ }
+ } while(0);
+ sp->libdeflate_state = 0;
+#endif /* LIBDEFLATE_SUPPORT */
+
sp->stream.next_in = bp;
assert(sizeof(sp->stream.avail_in)==4); /* if this assert gets raised,
we need to simplify this code to reflect a ZLib that is likely updated
@@ -265,7 +440,8 @@ ZIPEncode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
}
if (sp->stream.avail_out == 0) {
tif->tif_rawcc = tif->tif_rawdatasize;
- TIFFFlushData1(tif);
+ if (!TIFFFlushData1(tif))
+ return 0;
sp->stream.next_out = tif->tif_rawdata;
sp->stream.avail_out = (uint64)tif->tif_rawdatasize <= 0xFFFFFFFFU ? (uInt)tif->tif_rawdatasize : 0xFFFFFFFFU;
}
@@ -285,6 +461,11 @@ ZIPPostEncode(TIFF* tif)
ZIPState *sp = EncoderState(tif);
int state;
+#if LIBDEFLATE_SUPPORT
+ if( sp->libdeflate_state == 1 )
+ return 1;
+#endif
+
sp->stream.avail_in = 0;
do {
state = deflate(&sp->stream, Z_FINISH);
@@ -294,7 +475,8 @@ ZIPPostEncode(TIFF* tif)
if ((tmsize_t)sp->stream.avail_out != tif->tif_rawdatasize)
{
tif->tif_rawcc = tif->tif_rawdatasize - sp->stream.avail_out;
- TIFFFlushData1(tif);
+ if (!TIFFFlushData1(tif))
+ return 0;
sp->stream.next_out = tif->tif_rawdata;
sp->stream.avail_out = (uint64)tif->tif_rawdatasize <= 0xFFFFFFFFU ? (uInt)tif->tif_rawdatasize : 0xFFFFFFFFU;
}
@@ -327,6 +509,14 @@ ZIPCleanup(TIFF* tif)
inflateEnd(&sp->stream);
sp->state = 0;
}
+
+#if LIBDEFLATE_SUPPORT
+ if( sp->libdeflate_dec )
+ libdeflate_free_decompressor(sp->libdeflate_dec);
+ if( sp->libdeflate_enc )
+ libdeflate_free_compressor(sp->libdeflate_enc);
+#endif
+
_TIFFfree(sp);
tif->tif_data = NULL;
@@ -342,15 +532,55 @@ ZIPVSetField(TIFF* tif, uint32 tag, va_list ap)
switch (tag) {
case TIFFTAG_ZIPQUALITY:
sp->zipquality = (int) va_arg(ap, int);
- if ( sp->state&ZSTATE_INIT_ENCODE ) {
+ if( sp->zipquality < Z_DEFAULT_COMPRESSION ||
+ sp->zipquality > LIBDEFLATE_MAX_COMPRESSION_LEVEL ) {
+ TIFFErrorExt(tif->tif_clientdata, module,
+ "Invalid ZipQuality value. Should be in [-1,%d] range",
+ LIBDEFLATE_MAX_COMPRESSION_LEVEL);
+ return 0;
+ }
+
+ if ( sp->state&ZSTATE_INIT_ENCODE ) {
+ int cappedQuality = sp->zipquality;
+ if( cappedQuality > Z_BEST_COMPRESSION )
+ cappedQuality = Z_BEST_COMPRESSION;
if (deflateParams(&sp->stream,
- sp->zipquality, Z_DEFAULT_STRATEGY) != Z_OK) {
+ cappedQuality, Z_DEFAULT_STRATEGY) != Z_OK) {
TIFFErrorExt(tif->tif_clientdata, module, "ZLib error: %s",
SAFE_MSG(sp));
return (0);
}
}
+
+#if LIBDEFLATE_SUPPORT
+ if( sp->libdeflate_enc )
+ {
+ libdeflate_free_compressor(sp->libdeflate_enc);
+ sp->libdeflate_enc = NULL;
+ }
+#endif
+
return (1);
+
+ case TIFFTAG_DEFLATE_SUBCODEC:
+ sp->subcodec = (int) va_arg(ap, int);
+ if( sp->subcodec != DEFLATE_SUBCODEC_ZLIB &&
+ sp->subcodec != DEFLATE_SUBCODEC_LIBDEFLATE )
+ {
+ TIFFErrorExt(tif->tif_clientdata, module,
+ "Invalid DeflateCodec value.");
+ return 0;
+ }
+#if !LIBDEFLATE_SUPPORT
+ if( sp->subcodec == DEFLATE_SUBCODEC_LIBDEFLATE )
+ {
+ TIFFErrorExt(tif->tif_clientdata, module,
+ "DeflateCodec = DEFLATE_SUBCODEC_LIBDEFLATE unsupported in this build");
+ return 0;
+ }
+#endif
+ return 1;
+
default:
return (*sp->vsetparent)(tif, tag, ap);
}
@@ -366,6 +596,11 @@ ZIPVGetField(TIFF* tif, uint32 tag, va_list ap)
case TIFFTAG_ZIPQUALITY:
*va_arg(ap, int*) = sp->zipquality;
break;
+
+ case TIFFTAG_DEFLATE_SUBCODEC:
+ *va_arg(ap, int*) = sp->subcodec;
+ break;
+
default:
return (*sp->vgetparent)(tif, tag, ap);
}
@@ -374,6 +609,7 @@ ZIPVGetField(TIFF* tif, uint32 tag, va_list ap)
static const TIFFField zipFields[] = {
{ TIFFTAG_ZIPQUALITY, 0, 0, TIFF_ANY, 0, TIFF_SETGET_INT, TIFF_SETGET_UNDEFINED, FIELD_PSEUDO, TRUE, FALSE, "", NULL },
+ { TIFFTAG_DEFLATE_SUBCODEC, 0, 0, TIFF_ANY, 0, TIFF_SETGET_INT, TIFF_SETGET_UNDEFINED, FIELD_PSEUDO, TRUE, FALSE, "", NULL },
};
int
@@ -384,6 +620,9 @@ TIFFInitZIP(TIFF* tif, int scheme)
assert( (scheme == COMPRESSION_DEFLATE)
|| (scheme == COMPRESSION_ADOBE_DEFLATE));
+#ifdef NDEBUG
+ (void)scheme;
+#endif
/*
* Merge codec-specific tag information.
@@ -397,7 +636,7 @@ TIFFInitZIP(TIFF* tif, int scheme)
/*
* Allocate state block so tag methods have storage to record values.
*/
- tif->tif_data = (uint8*) _TIFFmalloc(sizeof (ZIPState));
+ tif->tif_data = (uint8*) _TIFFcalloc(sizeof (ZIPState), 1);
if (tif->tif_data == NULL)
goto bad;
sp = ZState(tif);
@@ -417,6 +656,11 @@ TIFFInitZIP(TIFF* tif, int scheme)
/* Default values for codec-specific fields */
sp->zipquality = Z_DEFAULT_COMPRESSION; /* default comp. level */
sp->state = 0;
+#if LIBDEFLATE_SUPPORT
+ sp->subcodec = DEFLATE_SUBCODEC_LIBDEFLATE;
+#else
+ sp->subcodec = DEFLATE_SUBCODEC_ZLIB;
+#endif
/*
* Install codec methods.
diff --git a/src/3rdparty/libtiff/libtiff/tiff.h b/src/3rdparty/libtiff/libtiff/tiff.h
index 5b0a0c9..2d4a476 100644
--- a/src/3rdparty/libtiff/libtiff/tiff.h
+++ b/src/3rdparty/libtiff/libtiff/tiff.h
@@ -119,6 +119,11 @@ typedef struct {
* Tag data type information.
*
* Note: RATIONALs are the ratio of two 32-bit integer values.
+ *--:
+ * Note2: TIFF_IFD8 data type is used in tiffFields[]-tag definition in order to distinguish the write-handling
+ of those tags between ClassicTIFF and BigTiff:
+ For ClassicTIFF libtiff writes a 32-bit value and the TIFF_IFD type-id into the file
+ For BigTIFF libtiff writes a 64-bit value and the TIFF_IFD8 type-id into the file
*/
typedef enum {
TIFF_NOTYPE = 0, /* placeholder */
@@ -375,6 +380,7 @@ typedef enum {
January 2004 */
#define TIFFTAG_OPIIMAGEID 32781 /* %OPI ImageID
[Adobe TIFF technote] */
+#define TIFFTAG_TIFFANNOTATIONDATA 32932 /* http://web.archive.org/web/20050309141348/http://www.kofile.com/support%20pro/faqs/annospec.htm */
/* tags 32952-32956 are private tags registered to Island Graphics */
#define TIFFTAG_REFPTS 32953 /* image reference points */
#define TIFFTAG_REGIONTACKPOINT 32954 /* region-xform tack point */
@@ -409,8 +415,23 @@ typedef enum {
#define TIFFTAG_CFAPATTERN 33422 /* color filter array pattern */
/* tag 33432 is listed in the 6.0 spec w/ unknown ownership */
#define TIFFTAG_COPYRIGHT 33432 /* copyright string */
+/* Tags 33445-33452 are used for GEL fileformat, see
+ * http://research.stowers-institute.org/mcm/efg/ScientificSoftware/Utility/TiffTags/GEL-FileFormat.pdf
+ */
+#define TIFFTAG_MD_FILETAG 33445 /* http://research.stowers-institute.org/mcm/efg/ScientificSoftware/Utility/TiffTags/GEL-FileFormat.pdf */
+#define TIFFTAG_MD_SCALEPIXEL 33446 /* http://research.stowers-institute.org/mcm/efg/ScientificSoftware/Utility/TiffTags/GEL-FileFormat.pdf */
+#define TIFFTAG_MD_COLORTABLE 33447 /* http://research.stowers-institute.org/mcm/efg/ScientificSoftware/Utility/TiffTags/GEL-FileFormat.pdf */
+#define TIFFTAG_MD_LABNAME 33448 /* http://research.stowers-institute.org/mcm/efg/ScientificSoftware/Utility/TiffTags/GEL-FileFormat.pdf */
+#define TIFFTAG_MD_SAMPLEINFO 33449 /* http://research.stowers-institute.org/mcm/efg/ScientificSoftware/Utility/TiffTags/GEL-FileFormat.pdf */
+#define TIFFTAG_MD_PREPDATE 33450 /* http://research.stowers-institute.org/mcm/efg/ScientificSoftware/Utility/TiffTags/GEL-FileFormat.pdf */
+#define TIFFTAG_MD_PREPTIME 33451 /* http://research.stowers-institute.org/mcm/efg/ScientificSoftware/Utility/TiffTags/GEL-FileFormat.pdf */
+#define TIFFTAG_MD_FILEUNITS 33452 /* http://research.stowers-institute.org/mcm/efg/ScientificSoftware/Utility/TiffTags/GEL-FileFormat.pdf */
/* IPTC TAG from RichTIFF specifications */
#define TIFFTAG_RICHTIFFIPTC 33723
+#define TIFFTAG_INGR_PACKET_DATA_TAG 33918 /* Intergraph Application specific storage. */
+#define TIFFTAG_INGR_FLAG_REGISTERS 33919 /* Intergraph Application specific flags. */
+#define TIFFTAG_IRASB_TRANSORMATION_MATRIX 33920 /* Originally part of Intergraph's GeoTIFF tags, but likely understood by IrasB only. */
+#define TIFFTAG_MODELTIEPOINTTAG 33922 /* GeoTIFF */
/* 34016-34029 are reserved for ANSI IT8 TIFF/IT <dkelly@apago.com) */
#define TIFFTAG_IT8SITE 34016 /* site name */
#define TIFFTAG_IT8COLORSEQUENCE 34017 /* color seq. [RGB,CMYK,etc] */
@@ -432,6 +453,7 @@ typedef enum {
#define TIFFTAG_IT8CMYKEQUIVALENT 34032 /* CMYK color equivalents */
/* tags 34232-34236 are private tags registered to Texas Instruments */
#define TIFFTAG_FRAMECOUNT 34232 /* Sequence Frame Count */
+#define TIFFTAG_MODELTRANSFORMATIONTAG 34264 /* Used in interchangeable GeoTIFF files */
/* tag 34377 is private tag registered to Adobe for PhotoShop */
#define TIFFTAG_PHOTOSHOP 34377
/* tags 34665, 34853 and 40965 are documented in EXIF specification */
@@ -451,7 +473,15 @@ typedef enum {
#define TIFFTAG_STONITS 37439 /* Sample value to Nits */
/* tag 34929 is a private tag registered to FedEx */
#define TIFFTAG_FEDEX_EDR 34929 /* unknown use */
+#define TIFFTAG_IMAGESOURCEDATA 37724 /* http://justsolve.archiveteam.org/wiki/PSD, http://www.adobe.com/devnet-apps/photoshop/fileformatashtml/ */
#define TIFFTAG_INTEROPERABILITYIFD 40965 /* Pointer to Interoperability private directory */
+#define TIFFTAG_GDAL_METADATA 42112 /* Used by the GDAL library */
+#define TIFFTAG_GDAL_NODATA 42113 /* Used by the GDAL library */
+#define TIFFTAG_OCE_SCANJOB_DESCRIPTION 50215 /* Used in the Oce scanning process */
+#define TIFFTAG_OCE_APPLICATION_SELECTOR 50216 /* Used in the Oce scanning process. */
+#define TIFFTAG_OCE_IDENTIFICATION_NUMBER 50217
+#define TIFFTAG_OCE_IMAGELOGIC_CHARACTERISTICS 50218
+
/* tags 50674 to 50677 are reserved for ESRI */
#define TIFFTAG_LERC_PARAMETERS 50674 /* Stores LERC version and additional compression method */
/* Adobe Digital Negative (DNG) format tags */
@@ -535,6 +565,17 @@ typedef enum {
into ICC profile space */
#define TIFFTAG_CURRENTICCPROFILE 50833 /* & */
#define TIFFTAG_CURRENTPREPROFILEMATRIX 50834 /* & */
+
+#define TIFFTAG_RPCCOEFFICIENT 50844 /* Define by GDAL for geospatial georeferencing through RPC: http://geotiff.maptools.org/rpc_prop.html */
+
+#define TIFFTAG_ALIAS_LAYER_METADATA 50784 /* Alias Sketchbook Pro layer usage description. */
+
+/* GeoTIFF DGIWG */
+#define TIFFTAG_TIFF_RSID 50908 /* https://www.awaresystems.be/imaging/tiff/tifftags/tiff_rsid.html */
+#define TIFFTAG_GEO_METADATA 50909 /* https://www.awaresystems.be/imaging/tiff/tifftags/geo_metadata.html */
+
+#define TIFFTAG_EXTRACAMERAPROFILES 50933 /* http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/products/photoshop/pdfs/dng_spec_1.4.0.0.pdf */
+
/* tag 65535 is an undefined tag used by Eastman Kodak */
#define TIFFTAG_DCSHUESHIFTVALUES 65535 /* hue shift correction data */
@@ -615,8 +656,11 @@ typedef enum {
#define LERC_ADD_COMPRESSION_DEFLATE 1
#define LERC_ADD_COMPRESSION_ZSTD 2
#define TIFFTAG_LERC_MAXZERROR 65567 /* LERC maximum error */
-#define TIFFTAG_WEBP_LEVEL 65568 /* WebP compression level: WARNING not registered in Adobe-maintained registry */
-#define TIFFTAG_WEBP_LOSSLESS 65569 /* WebP lossless/lossy : WARNING not registered in Adobe-maintained registry */
+#define TIFFTAG_WEBP_LEVEL 65568 /* WebP compression level */
+#define TIFFTAG_WEBP_LOSSLESS 65569 /* WebP lossless/lossy */
+#define TIFFTAG_DEFLATE_SUBCODEC 65570 /* ZIP codec: to get/set the sub-codec to use. Will default to libdeflate when available */
+#define DEFLATE_SUBCODEC_ZLIB 0
+#define DEFLATE_SUBCODEC_LIBDEFLATE 1
/*
* EXIF tags
@@ -626,8 +670,8 @@ typedef enum {
#define EXIFTAG_EXPOSUREPROGRAM 34850 /* Exposure program */
#define EXIFTAG_SPECTRALSENSITIVITY 34852 /* Spectral sensitivity */
#define EXIFTAG_ISOSPEEDRATINGS 34855 /* ISO speed rating */
-#define EXIFTAG_OECF 34856 /* Optoelectric conversion
- factor */
+#define EXIFTAG_PHOTOGRAPHICSENSITIVITY 34855 /* Photographic Sensitivity (new name for tag 34855) */
+#define EXIFTAG_OECF 34856 /* Optoelectric conversion factor */
#define EXIFTAG_EXIFVERSION 36864 /* Exif version */
#define EXIFTAG_DATETIMEORIGINAL 36867 /* Date and time of original
data generation */
@@ -679,10 +723,71 @@ typedef enum {
#define EXIFTAG_SHARPNESS 41994 /* Sharpness */
#define EXIFTAG_DEVICESETTINGDESCRIPTION 41995 /* Device settings description */
#define EXIFTAG_SUBJECTDISTANCERANGE 41996 /* Subject distance range */
-#define EXIFTAG_GAINCONTROL 41991 /* Gain control */
-#define EXIFTAG_GAINCONTROL 41991 /* Gain control */
#define EXIFTAG_IMAGEUNIQUEID 42016 /* Unique image ID */
+/*--: New for EXIF-Version 2.32, May 2019 ... */
+#define EXIFTAG_SENSITIVITYTYPE 34864 /* The SensitivityType tag indicates which one of the parameters of ISO12232 is the PhotographicSensitivity tag. */
+#define EXIFTAG_STANDARDOUTPUTSENSITIVITY 34865 /* This tag indicates the standard output sensitivity value of a camera or input device defined in ISO 12232. */
+#define EXIFTAG_RECOMMENDEDEXPOSUREINDEX 34866 /* recommended exposure index */
+#define EXIFTAG_ISOSPEED 34867 /* ISO speed value */
+#define EXIFTAG_ISOSPEEDLATITUDEYYY 34868 /* ISO speed latitude yyy */
+#define EXIFTAG_ISOSPEEDLATITUDEZZZ 34869 /* ISO speed latitude zzz */
+#define EXIFTAG_OFFSETTIME 36880 /* offset from UTC of the time of DateTime tag. */
+#define EXIFTAG_OFFSETTIMEORIGINAL 36881 /* offset from UTC of the time of DateTimeOriginal tag. */
+#define EXIFTAG_OFFSETTIMEDIGITIZED 36882 /* offset from UTC of the time of DateTimeDigitized tag. */
+#define EXIFTAG_TEMPERATURE 37888 /* Temperature as the ambient situation at the shot in dergee Celsius */
+#define EXIFTAG_HUMIDITY 37889 /* Humidity as the ambient situation at the shot in percent */
+#define EXIFTAG_PRESSURE 37890 /* Pressure as the ambient situation at the shot hecto-Pascal (hPa) */
+#define EXIFTAG_WATERDEPTH 37891 /* WaterDepth as the ambient situation at the shot in meter (m) */
+#define EXIFTAG_ACCELERATION 37892 /* Acceleration (a scalar regardless of direction) as the ambient situation at the shot in units of mGal (10-5 m/s^2) */
+#define EXIFTAG_CAMERAELEVATIONANGLE 37893 /* Elevation/depression. angle of the orientation of the camera(imaging optical axis) as the ambient situation at the shot in degree from -180deg to +180deg. */
+#define EXIFTAG_CAMERAOWNERNAME 42032 /* owner of a camera */
+#define EXIFTAG_BODYSERIALNUMBER 42033 /* serial number of the body of the camera */
+#define EXIFTAG_LENSSPECIFICATION 42034 /* minimum focal length (in mm), maximum focal length (in mm), minimum F number in the minimum focal length, and minimum F number in the maximum focal length, */
+#define EXIFTAG_LENSMAKE 42035 /* the lens manufacturer */
+#define EXIFTAG_LENSMODEL 42036 /* the lens model name and model number */
+#define EXIFTAG_LENSSERIALNUMBER 42037 /* the serial number of the interchangeable lens */
+#define EXIFTAG_GAMMA 42240 /* value of coefficient gamma */
+#define EXIFTAG_COMPOSITEIMAGE 42080 /* composite image */
+#define EXIFTAG_SOURCEIMAGENUMBEROFCOMPOSITEIMAGE 42081 /* source image number of composite image */
+#define EXIFTAG_SOURCEEXPOSURETIMESOFCOMPOSITEIMAGE 42082 /* source exposure times of composite image */
+
+/*
+ * EXIF-GPS tags (Version 2.31, July 2016)
+ */
+#define GPSTAG_VERSIONID 0 /* Indicates the version of GPSInfoIFD. */
+#define GPSTAG_LATITUDEREF 1 /* Indicates whether the latitude is north or south latitude. */
+#define GPSTAG_LATITUDE 2 /* Indicates the latitude. */
+#define GPSTAG_LONGITUDEREF 3 /* Indicates whether the longitude is east or west longitude. */
+#define GPSTAG_LONGITUDE 4 /* Indicates the longitude. */
+#define GPSTAG_ALTITUDEREF 5 /* Indicates the altitude used as the reference altitude. */
+#define GPSTAG_ALTITUDE 6 /* Indicates the altitude based on the reference in GPSAltitudeRef. */
+#define GPSTAG_TIMESTAMP 7 /* Indicates the time as UTC (Coordinated Universal Time). */
+#define GPSTAG_SATELLITES 8 /* Indicates the GPS satellites used for measurements. */
+#define GPSTAG_STATUS 9 /* Indicates the status of the GPS receiver when the image is recorded. */
+#define GPSTAG_MEASUREMODE 10 /* Indicates the GPS measurement mode. */
+#define GPSTAG_DOP 11 /* Indicates the GPS DOP (data degree of precision). */
+#define GPSTAG_SPEEDREF 12 /* Indicates the unit used to express the GPS receiver speed of movement. */
+#define GPSTAG_SPEED 13 /* Indicates the speed of GPS receiver movement. */
+#define GPSTAG_TRACKREF 14 /* Indicates the reference for giving the direction of GPS receiver movement. */
+#define GPSTAG_TRACK 15 /* Indicates the direction of GPS receiver movement. */
+#define GPSTAG_IMGDIRECTIONREF 16 /* Indicates the reference for giving the direction of the image when it is captured. */
+#define GPSTAG_IMGDIRECTION 17 /* Indicates the direction of the image when it was captured. */
+#define GPSTAG_MAPDATUM 18 /* Indicates the geodetic survey data used by the GPS receiver. (e.g. WGS-84) */
+#define GPSTAG_DESTLATITUDEREF 19 /* Indicates whether the latitude of the destination point is north or south latitude. */
+#define GPSTAG_DESTLATITUDE 20 /* Indicates the latitude of the destination point. */
+#define GPSTAG_DESTLONGITUDEREF 21 /* Indicates whether the longitude of the destination point is east or west longitude. */
+#define GPSTAG_DESTLONGITUDE 22 /* Indicates the longitude of the destination point. */
+#define GPSTAG_DESTBEARINGREF 23 /* Indicates the reference used for giving the bearing to the destination point. */
+#define GPSTAG_DESTBEARING 24 /* Indicates the bearing to the destination point. */
+#define GPSTAG_DESTDISTANCEREF 25 /* Indicates the unit used to express the distance to the destination point. */
+#define GPSTAG_DESTDISTANCE 26 /* Indicates the distance to the destination point. */
+#define GPSTAG_PROCESSINGMETHOD 27 /* A character string recording the name of the method used for location finding. */
+#define GPSTAG_AREAINFORMATION 28 /* A character string recording the name of the GPS area. */
+#define GPSTAG_DATESTAMP 29 /* A character string recording date and time information relative to UTC (Coordinated Universal Time). */
+#define GPSTAG_DIFFERENTIAL 30 /* Indicates whether differential correction is applied to the GPS receiver. */
+#define GPSTAG_GPSHPOSITIONINGERROR 31 /* Indicates horizontal positioning errors in meters. */
+
#endif /* _TIFF_ */
/* vim: set ts=8 sts=8 sw=8 noet: */
diff --git a/src/3rdparty/libtiff/libtiff/tiffconf.h b/src/3rdparty/libtiff/libtiff/tiffconf.h
index f37b0b5..b6e1d99 100644
--- a/src/3rdparty/libtiff/libtiff/tiffconf.h
+++ b/src/3rdparty/libtiff/libtiff/tiffconf.h
@@ -100,6 +100,9 @@
/* Support Deflate compression */
#define ZIP_SUPPORT 1
+/* Support libdeflate enhanced compression */
+/* #undef LIBDEFLATE_SUPPORT */
+
/* Support strip chopping (whether or not to convert single-strip uncompressed
images to mutiple strips of ~8Kb to reduce memory usage) */
#define STRIPCHOP_DEFAULT TIFF_STRIPCHOP
diff --git a/src/3rdparty/libtiff/libtiff/tiffconf.h.in b/src/3rdparty/libtiff/libtiff/tiffconf.h.in
index 5de30c9..9bd6a2d 100644
--- a/src/3rdparty/libtiff/libtiff/tiffconf.h.in
+++ b/src/3rdparty/libtiff/libtiff/tiffconf.h.in
@@ -84,6 +84,9 @@
/* Support Deflate compression */
#undef ZIP_SUPPORT
+/* Support libdeflate enhanced compression */
+#undef LIBDEFLATE_SUPPORT
+
/* Support strip chopping (whether or not to convert single-strip uncompressed
images to mutiple strips of ~8Kb to reduce memory usage) */
#undef STRIPCHOP_DEFAULT
diff --git a/src/3rdparty/libtiff/libtiff/tiffio.h b/src/3rdparty/libtiff/libtiff/tiffio.h
index 198481d..6274f09 100644
--- a/src/3rdparty/libtiff/libtiff/tiffio.h
+++ b/src/3rdparty/libtiff/libtiff/tiffio.h
@@ -261,8 +261,10 @@ typedef struct {
#define LOGLUV_PUBLIC 1
#endif
-#if !defined(__GNUC__) && !defined(__attribute__)
-# define __attribute__(x) /*nothing*/
+#if defined(__GNUC__) || defined(__attribute__)
+# define TIFF_ATTRIBUTE(x) __attribute__(x)
+#else
+# define TIFF_ATTRIBUTE(x) /*nothing*/
#endif
#if defined(c_plusplus) || defined(__cplusplus)
@@ -350,6 +352,7 @@ extern int TIFFVGetFieldDefaulted(TIFF* tif, uint32 tag, va_list ap);
extern int TIFFReadDirectory(TIFF* tif);
extern int TIFFReadCustomDirectory(TIFF* tif, toff_t diroff, const TIFFFieldArray* infoarray);
extern int TIFFReadEXIFDirectory(TIFF* tif, toff_t diroff);
+extern int TIFFReadGPSDirectory(TIFF* tif, toff_t diroff);
extern uint64 TIFFScanlineSize64(TIFF* tif);
extern tmsize_t TIFFScanlineSize(TIFF* tif);
extern uint64 TIFFRasterScanlineSize64(TIFF* tif);
@@ -400,6 +403,7 @@ extern void TIFFFreeDirectory(TIFF*);
extern int TIFFCreateDirectory(TIFF*);
extern int TIFFCreateCustomDirectory(TIFF*,const TIFFFieldArray*);
extern int TIFFCreateEXIFDirectory(TIFF*);
+extern int TIFFCreateGPSDirectory(TIFF*);
extern int TIFFLastDirectory(TIFF*);
extern int TIFFSetDirectory(TIFF*, uint16);
extern int TIFFSetSubDirectory(TIFF*, uint64);
@@ -450,10 +454,10 @@ extern TIFF* TIFFClientOpen(const char*, const char*,
TIFFMapFileProc, TIFFUnmapFileProc);
extern const char* TIFFFileName(TIFF*);
extern const char* TIFFSetFileName(TIFF*, const char *);
-extern void TIFFError(const char*, const char*, ...) __attribute__((__format__ (__printf__,2,3)));
-extern void TIFFErrorExt(thandle_t, const char*, const char*, ...) __attribute__((__format__ (__printf__,3,4)));
-extern void TIFFWarning(const char*, const char*, ...) __attribute__((__format__ (__printf__,2,3)));
-extern void TIFFWarningExt(thandle_t, const char*, const char*, ...) __attribute__((__format__ (__printf__,3,4)));
+extern void TIFFError(const char*, const char*, ...) TIFF_ATTRIBUTE((__format__ (__printf__,2,3)));
+extern void TIFFErrorExt(thandle_t, const char*, const char*, ...) TIFF_ATTRIBUTE((__format__ (__printf__,3,4)));
+extern void TIFFWarning(const char*, const char*, ...) TIFF_ATTRIBUTE((__format__ (__printf__,2,3)));
+extern void TIFFWarningExt(thandle_t, const char*, const char*, ...) TIFF_ATTRIBUTE((__format__ (__printf__,3,4)));
extern TIFFErrorHandler TIFFSetErrorHandler(TIFFErrorHandler);
extern TIFFErrorHandlerExt TIFFSetErrorHandlerExt(TIFFErrorHandlerExt);
extern TIFFErrorHandler TIFFSetWarningHandler(TIFFErrorHandler);
diff --git a/src/3rdparty/libtiff/libtiff/tiffiop.h b/src/3rdparty/libtiff/libtiff/tiffiop.h
index 45a7932..39b54c8 100644
--- a/src/3rdparty/libtiff/libtiff/tiffiop.h
+++ b/src/3rdparty/libtiff/libtiff/tiffiop.h
@@ -367,6 +367,9 @@ extern uint32 _TIFFDefaultStripSize(TIFF* tif, uint32 s);
extern void _TIFFDefaultTileSize(TIFF* tif, uint32* tw, uint32* th);
extern int _TIFFDataSize(TIFFDataType type);
+/*--: Rational2Double: Return size of TIFFSetGetFieldType in bytes. */
+extern int _TIFFSetGetFieldSize(TIFFSetGetFieldType setgettype);
+
extern void _TIFFsetByteArray(void**, void*, uint32);
extern void _TIFFsetString(char**, char*);
extern void _TIFFsetShortArray(uint16**, uint16*, uint32);
diff --git a/src/3rdparty/libtiff/libtiff/tiffvers.h b/src/3rdparty/libtiff/libtiff/tiffvers.h
index aa3f613..0cce798 100644
--- a/src/3rdparty/libtiff/libtiff/tiffvers.h
+++ b/src/3rdparty/libtiff/libtiff/tiffvers.h
@@ -1,4 +1,4 @@
-#define TIFFLIB_VERSION_STR "LIBTIFF, Version 4.1.0\nCopyright (c) 1988-1996 Sam Leffler\nCopyright (c) 1991-1996 Silicon Graphics, Inc."
+#define TIFFLIB_VERSION_STR "LIBTIFF, Version 4.2.0\nCopyright (c) 1988-1996 Sam Leffler\nCopyright (c) 1991-1996 Silicon Graphics, Inc."
/*
* This define can be used in code that requires
* compilation-related definitions specific to a
@@ -6,4 +6,4 @@
* version checking should be done based on the
* string returned by TIFFGetVersion.
*/
-#define TIFFLIB_VERSION 20191103
+#define TIFFLIB_VERSION 20201219
diff --git a/src/3rdparty/libtiff/port/libport.h b/src/3rdparty/libtiff/port/libport.h
index ff26263..9f2dace 100644
--- a/src/3rdparty/libtiff/port/libport.h
+++ b/src/3rdparty/libtiff/port/libport.h
@@ -24,6 +24,10 @@
#ifndef _LIBPORT_
#define _LIBPORT_
+#if defined(HAVE_CONFIG_H)
+# include <tif_config.h>
+#endif
+
int getopt(int argc, char * const argv[], const char *optstring);
extern char *optarg;
extern int opterr;
@@ -36,16 +40,16 @@ int strcasecmp(const char *s1, const char *s2);
# define HAVE_GETOPT 1
#endif
-#if HAVE_STRTOL
+#if !defined(HAVE_STRTOL)
long strtol(const char *nptr, char **endptr, int base);
#endif
-#if HAVE_STRTOLL
+#if !defined(HAVE_STRTOLL)
long long strtoll(const char *nptr, char **endptr, int base);
#endif
-#if HAVE_STRTOUL
+#if !defined(HAVE_STRTOUL)
unsigned long strtoul(const char *nptr, char **endptr, int base);
#endif
-#if HAVE_STRTOULL
+#if !defined(HAVE_STRTOULL)
unsigned long long strtoull(const char *nptr, char **endptr, int base);
#endif
diff --git a/src/3rdparty/libtiff/qt_attribution.json b/src/3rdparty/libtiff/qt_attribution.json
index 283f5e6..30d106d 100644
--- a/src/3rdparty/libtiff/qt_attribution.json
+++ b/src/3rdparty/libtiff/qt_attribution.json
@@ -6,7 +6,7 @@
"Description": "",
"Homepage": "http://www.simplesystems.org/libtiff/",
- "Version": "4.1.0",
+ "Version": "4.2.0",
"License": "libtiff License",
"LicenseId": "libtiff",
"LicenseFile": "COPYRIGHT",
diff --git a/src/3rdparty/libwebp/AUTHORS b/src/3rdparty/libwebp/AUTHORS
index 32ff2fb..8a6e262 100644
--- a/src/3rdparty/libwebp/AUTHORS
+++ b/src/3rdparty/libwebp/AUTHORS
@@ -6,6 +6,7 @@ Contributors:
- Christian Duvivier (cduvivier at google dot com)
- Djordje Pesut (djordje dot pesut at imgtec dot com)
- Hui Su (huisu at google dot com)
+- Ingvar Stepanyan (rreverser at google dot com)
- James Zern (jzern at google dot com)
- Jan Engelhardt (jengelh at medozas dot de)
- Jehan (jehan at girinstud dot io)
@@ -41,5 +42,6 @@ Contributors:
- Vikas Arora (vikasa at google dot com)
- Vincent Rabaud (vrabaud at google dot com)
- Vlad Tsyrklevich (vtsyrklevich at chromium dot org)
+- Wan-Teh Chang (wtc at google dot com)
- Yang Zhang (yang dot zhang at arm dot com)
- Yannis Guyon (yguyon at google dot com)
diff --git a/src/3rdparty/libwebp/ChangeLog b/src/3rdparty/libwebp/ChangeLog
index 0a286fc..895ae99 100644
--- a/src/3rdparty/libwebp/ChangeLog
+++ b/src/3rdparty/libwebp/ChangeLog
@@ -1,4 +1,82 @@
+170a8712 Fix check_c_source_compiles with pthread.
+85995719 disable CombinedShannonEntropy_SSE2 on x86
+8af7436f Merge "{ios,xcframework}build.sh: make min version(s) more visible" into 1.2.0
+e56c3c5b pngdec: raise memory limit if needed
+13b8e9fe {ios,xcframework}build.sh: make min version(s) more visible
+a9225410 animdecoder_fuzzer: fix memory leak
+d6c2285d update gradle to 6.1.1
+52ce6333 update NEWS
+28c49820 bump version to 1.2.0
+7363dff2 webp/encode.h: restore WEBP_ENCODER_ABI_VERSION to v1.1.0
+826aafa5 update AUTHORS
+63258823 animdecoder_fuzzer: validate canvas size
+9eb26381 CMake: remove duplicate "include(GNUInstallDirs)"
+2e7bed79 WebPPicture: clarify the ownership of user-owned data.
+cccf5e33 webpmux: add an '-set loop <value>' option
+c9a3f6a1 Merge changes Ie29f9867,I289c54c4
+319f56f1 iosbuild.sh: sync some aspects of xcframeworkbuild.sh
+e8e8db98 add xcframeworkbuild.sh
+ae545534 dsp.h: allow config.h to override MSVC SIMD autodetection
+fef789f3 Merge "cmake: fix per-file assembly flags"
+fc14fc03 Have C encoding predictors use decoding predictors.
+7656f0b3 README,cosmetics: fix a couple typos
+d2e245ea cmake: disable webp.js if WEBP_ENABLE_SIMD=1
+96099a79 cmake: fix per-file assembly flags
+5abb5582 Merge "cmake: fix compilation w/Xcode generator"
+8484a120 cmake: fix compilation w/Xcode generator
+d7bf01c9 Merge changes Ifcae0f38,Iee2d7401
+36c81ff6 WASM-SIMD: port 2 patches from rreverser@'s tree
+988b02ab Merge "Couple of fixes to allow SIMD on Emscripten"
+26faf770 wicdec: fail with animated images
+ab2d08a8 [cd]webp: document lack of animated webp support
+52273943 Couple of fixes to allow SIMD on Emscripten
+8870ba7f Fix skia bug #10952
+4b3c6953 Detect if StoreFrame read more than anmf_payload_size bytes
+17fd4ba8 webp/decode.h,cosmetics: normalize 'flip' comment
+411d3677 remove some unreachable break statements
+3700ffd7 WebPPictureHasTransparency: remove unreachable return
+83604bf3 {animencoder,enc_dec}_fuzzer: convert some abort()s to returns
+eb44119c Merge changes I8ae09473,I678c8b1e
+9f6055fc fuzz_utils.h: rename max() to Max()
+695788e7 fuzz_utils.h: make functions WEBP_INLINE
+906c1fcd make ImgIoUtilReadFile use WebPMalloc instead of malloc
+8cb7e536 rename demux_api_fuzzer.c -> mux_demux_api_fuzzer.c
+443db47d add animdecoder_fuzzer.cc
+36a6eea3 Merge "import fuzzers from oss-fuzz/chromium"
+ec5f12c1 Makefile.vc: remove deprecated /Gm option
+64425a08 picture_tools_enc: fix windows build warning
+bd94090a import fuzzers from oss-fuzz/chromium
+cf847cba use WEBP_DSP_INIT_FUNC for Init{GammaTables*,GetCoeffs}
+55a080e5 Add WebPReplaceTransparentPixels() in dsp
+84739717 GetBackgroundColorGIF: promote to uint32_t before << 24
+def64e92 cwebp: Fix -print_psnr for near_lossless
+cf2f88b3 Add palette and spatial for q >= 75 and -m 5
+f0110bae Add no-color cache configuration to the cruncher
+749a8b99 Better estimate of the cache cost.
+4f9f00cc Use spatial predictors on top of palette no matter what.
+7658c686 Add spatial prediction on top of palette in cruncher.
+133ff0e3 webp_js: force WASM=0 option explicitly
+e3c259a2 Fix integer overflow in EmitFancyRGB.
+b3ff0bde man/{gif2,img2}webp,webpmux: normalize some wording
+f9b30586 fix ABI breakage introduced by 6a0ff358
+1d58dcfc README.webp_js: update note about emscripten version
+44070266 README.webp_js: s/fastcomp/upstream/
+2565fa8f README.webp_js: update cmake command
+47309ef5 webp: WEBP_OFFSET_PTR()
+687ab00e DC{4,8,16}_NEON: replace vmovl w/vaddl
+1b92fe75 DC16_NEON,aarch64: use vaddlv
+53f3d8cf dec_neon,DC8_NEON: use vaddlv instead of movl+vaddv
+27d08240 Fix integer overflow in WebPAnimDecoderGetNext()
+69776e38 Merge "remove call to MBAnalyzeBestIntra4Mode for method >= 5"
+a99078c1 remove call to MBAnalyzeBestIntra4Mode for method >= 5
+22e404cc CMakeLists.txt: fix set(CACHE) argument order
+71690b52 fix MSVC warning
+6a0ff358 Enc: add a qmin / qmax range for quality factor
+0fa56f30 Merge tag 'v1.1.0'
+6cf504d0 PNM decoding: handle max_value != 255
+d7844e97 update ChangeLog (tag: v1.1.0-rc2, tag: v1.1.0, origin/1.1.0)
7f006436 Makefile.vc: fix webp_quality.exe link
+cf047e83 Makefile.vc: fix webp_quality.exe link
c074c653 update NEWS
30f09551 bump version to 1.1.0
a76694a1 update AUTHORS
diff --git a/src/3rdparty/libwebp/NEWS b/src/3rdparty/libwebp/NEWS
index 46daa09..5b87b3a 100644
--- a/src/3rdparty/libwebp/NEWS
+++ b/src/3rdparty/libwebp/NEWS
@@ -1,3 +1,15 @@
+- 12/23/2020: version 1.2.0
+ * API changes:
+ - libwebp:
+ encode.h: add a qmin / qmax range for quality factor (cwebp adds -qrange)
+ * lossless encoder improvements
+ * SIMD support for Wasm builds
+ * add xcframeworkbuild.sh, supports Mac Catalyst builds
+ * import fuzzers from oss-fuzz & chromium (#409)
+ * webpmux: add an '-set loop <value>' option (#494)
+ * toolchain updates and bug fixes (#449, #463, #470, #475, #477, #478, #479,
+ #488, #491)
+
- 12/18/2019: version 1.1.0
* API changes:
- libwebp:
diff --git a/src/3rdparty/libwebp/README b/src/3rdparty/libwebp/README
index 0592727..bbe2c81 100644
--- a/src/3rdparty/libwebp/README
+++ b/src/3rdparty/libwebp/README
@@ -4,7 +4,7 @@
\__\__/\____/\_____/__/ ____ ___
/ _/ / \ \ / _ \/ _/
/ \_/ / / \ \ __/ \__
- \____/____/\_____/_____/____/v1.1.0
+ \____/____/\_____/_____/____/v1.2.0
Description:
============
@@ -113,7 +113,7 @@ make install
CMake:
------
-With CMake, you can compile libwebp, cwebp, dwebp, gif2web, img2webp, webpinfo
+With CMake, you can compile libwebp, cwebp, dwebp, gif2webp, img2webp, webpinfo
and the JS bindings.
Prerequisites:
@@ -225,6 +225,7 @@ Usage:
If input size (-s) for an image is not specified, it is
assumed to be a PNG, JPEG, TIFF or WebP file.
+Note: Animated PNG and WebP files are not supported.
Options:
-h / -help ............. short help
@@ -254,6 +255,8 @@ Options:
-partition_limit <int> . limit quality to fit the 512k limit on
the first partition (0=no degradation ... 100=full)
-pass <int> ............ analysis pass number (1..10)
+ -qrange <min> <max> .... specifies the permissible quality range
+ (default: 0 100)
-crop <x> <y> <w> <h> .. crop picture with the given rectangle
-resize <w> <h> ........ resize picture (after any cropping)
-mt .................... use multi-threading if available
@@ -294,6 +297,7 @@ Experimental Options:
-af .................... auto-adjust filter strength
-pre <int> ............. pre-processing filter
+
The main options you might want to try in order to further tune the
visual quality are:
-preset
@@ -341,7 +345,9 @@ The full list of options is available using -h:
> dwebp -h
Usage: dwebp in_file [options] [-o out_file]
-Decodes the WebP image file to PNG format [Default]
+Decodes the WebP image file to PNG format [Default].
+Note: Animated WebP files are not supported.
+
Use following options to convert into alternate image formats:
-pam ......... save the raw RGBA samples as a color PAM
-ppm ......... save the raw RGB samples as a color PPM
@@ -423,7 +429,7 @@ Prerequisites:
1) OpenGL & OpenGL Utility Toolkit (GLUT)
Linux:
$ sudo apt-get install freeglut3-dev mesa-common-dev
- Mac + XCode:
+ Mac + Xcode:
- These libraries should be available in the OpenGL / GLUT frameworks.
Windows:
http://freeglut.sourceforge.net/index.php#download
diff --git a/src/3rdparty/libwebp/qt_attribution.json b/src/3rdparty/libwebp/qt_attribution.json
index 618c31c..bb7577e 100644
--- a/src/3rdparty/libwebp/qt_attribution.json
+++ b/src/3rdparty/libwebp/qt_attribution.json
@@ -6,7 +6,7 @@
"Description": "WebP is a new image format that provides lossless and lossy compression for images on the web.",
"Homepage": "https://developers.google.com/speed/webp/",
- "Version": "1.1.0",
+ "Version": "1.2.0",
"License": "BSD 3-clause \"New\" or \"Revised\" License",
"LicenseId": "BSD-3-Clause",
"LicenseFile": "COPYING",
diff --git a/src/3rdparty/libwebp/src/dec/io_dec.c b/src/3rdparty/libwebp/src/dec/io_dec.c
index e603f19..29dc634 100644
--- a/src/3rdparty/libwebp/src/dec/io_dec.c
+++ b/src/3rdparty/libwebp/src/dec/io_dec.c
@@ -25,21 +25,16 @@
static int EmitYUV(const VP8Io* const io, WebPDecParams* const p) {
WebPDecBuffer* output = p->output;
const WebPYUVABuffer* const buf = &output->u.YUVA;
- uint8_t* const y_dst = buf->y + io->mb_y * buf->y_stride;
- uint8_t* const u_dst = buf->u + (io->mb_y >> 1) * buf->u_stride;
- uint8_t* const v_dst = buf->v + (io->mb_y >> 1) * buf->v_stride;
+ uint8_t* const y_dst = buf->y + (size_t)io->mb_y * buf->y_stride;
+ uint8_t* const u_dst = buf->u + (size_t)(io->mb_y >> 1) * buf->u_stride;
+ uint8_t* const v_dst = buf->v + (size_t)(io->mb_y >> 1) * buf->v_stride;
const int mb_w = io->mb_w;
const int mb_h = io->mb_h;
const int uv_w = (mb_w + 1) / 2;
const int uv_h = (mb_h + 1) / 2;
- int j;
- for (j = 0; j < mb_h; ++j) {
- memcpy(y_dst + j * buf->y_stride, io->y + j * io->y_stride, mb_w);
- }
- for (j = 0; j < uv_h; ++j) {
- memcpy(u_dst + j * buf->u_stride, io->u + j * io->uv_stride, uv_w);
- memcpy(v_dst + j * buf->v_stride, io->v + j * io->uv_stride, uv_w);
- }
+ WebPCopyPlane(io->y, io->y_stride, y_dst, buf->y_stride, mb_w, mb_h);
+ WebPCopyPlane(io->u, io->uv_stride, u_dst, buf->u_stride, uv_w, uv_h);
+ WebPCopyPlane(io->v, io->uv_stride, v_dst, buf->v_stride, uv_w, uv_h);
return io->mb_h;
}
@@ -47,7 +42,7 @@ static int EmitYUV(const VP8Io* const io, WebPDecParams* const p) {
static int EmitSampledRGB(const VP8Io* const io, WebPDecParams* const p) {
WebPDecBuffer* const output = p->output;
WebPRGBABuffer* const buf = &output->u.RGBA;
- uint8_t* const dst = buf->rgba + io->mb_y * buf->stride;
+ uint8_t* const dst = buf->rgba + (size_t)io->mb_y * buf->stride;
WebPSamplerProcessPlane(io->y, io->y_stride,
io->u, io->v, io->uv_stride,
dst, buf->stride, io->mb_w, io->mb_h,
@@ -62,7 +57,7 @@ static int EmitSampledRGB(const VP8Io* const io, WebPDecParams* const p) {
static int EmitFancyRGB(const VP8Io* const io, WebPDecParams* const p) {
int num_lines_out = io->mb_h; // a priori guess
const WebPRGBABuffer* const buf = &p->output->u.RGBA;
- uint8_t* dst = buf->rgba + io->mb_y * buf->stride;
+ uint8_t* dst = buf->rgba + (size_t)io->mb_y * buf->stride;
WebPUpsampleLinePairFunc upsample = WebPUpsamplers[p->output->colorspace];
const uint8_t* cur_y = io->y;
const uint8_t* cur_u = io->u;
@@ -133,7 +128,7 @@ static int EmitAlphaYUV(const VP8Io* const io, WebPDecParams* const p,
const WebPYUVABuffer* const buf = &p->output->u.YUVA;
const int mb_w = io->mb_w;
const int mb_h = io->mb_h;
- uint8_t* dst = buf->a + io->mb_y * buf->a_stride;
+ uint8_t* dst = buf->a + (size_t)io->mb_y * buf->a_stride;
int j;
(void)expected_num_lines_out;
assert(expected_num_lines_out == mb_h);
@@ -186,7 +181,7 @@ static int EmitAlphaRGB(const VP8Io* const io, WebPDecParams* const p,
(colorspace == MODE_ARGB || colorspace == MODE_Argb);
const WebPRGBABuffer* const buf = &p->output->u.RGBA;
int num_rows;
- const int start_y = GetAlphaSourceRow(io, &alpha, &num_rows);
+ const size_t start_y = GetAlphaSourceRow(io, &alpha, &num_rows);
uint8_t* const base_rgba = buf->rgba + start_y * buf->stride;
uint8_t* const dst = base_rgba + (alpha_first ? 0 : 3);
const int has_alpha = WebPDispatchAlpha(alpha, io->width, mb_w,
@@ -210,7 +205,7 @@ static int EmitAlphaRGBA4444(const VP8Io* const io, WebPDecParams* const p,
const WEBP_CSP_MODE colorspace = p->output->colorspace;
const WebPRGBABuffer* const buf = &p->output->u.RGBA;
int num_rows;
- const int start_y = GetAlphaSourceRow(io, &alpha, &num_rows);
+ const size_t start_y = GetAlphaSourceRow(io, &alpha, &num_rows);
uint8_t* const base_rgba = buf->rgba + start_y * buf->stride;
#if (WEBP_SWAP_16BIT_CSP == 1)
uint8_t* alpha_dst = base_rgba;
@@ -276,9 +271,9 @@ static int EmitRescaledYUV(const VP8Io* const io, WebPDecParams* const p) {
static int EmitRescaledAlphaYUV(const VP8Io* const io, WebPDecParams* const p,
int expected_num_lines_out) {
const WebPYUVABuffer* const buf = &p->output->u.YUVA;
- uint8_t* const dst_a = buf->a + p->last_y * buf->a_stride;
+ uint8_t* const dst_a = buf->a + (size_t)p->last_y * buf->a_stride;
if (io->a != NULL) {
- uint8_t* const dst_y = buf->y + p->last_y * buf->y_stride;
+ uint8_t* const dst_y = buf->y + (size_t)p->last_y * buf->y_stride;
const int num_lines_out = Rescale(io->a, io->width, io->mb_h, p->scaler_a);
assert(expected_num_lines_out == num_lines_out);
if (num_lines_out > 0) { // unmultiply the Y
@@ -356,7 +351,7 @@ static int ExportRGB(WebPDecParams* const p, int y_pos) {
const WebPYUV444Converter convert =
WebPYUV444Converters[p->output->colorspace];
const WebPRGBABuffer* const buf = &p->output->u.RGBA;
- uint8_t* dst = buf->rgba + y_pos * buf->stride;
+ uint8_t* dst = buf->rgba + (size_t)y_pos * buf->stride;
int num_lines_out = 0;
// For RGB rescaling, because of the YUV420, current scan position
// U/V can be +1/-1 line from the Y one. Hence the double test.
@@ -383,15 +378,15 @@ static int EmitRescaledRGB(const VP8Io* const io, WebPDecParams* const p) {
while (j < mb_h) {
const int y_lines_in =
WebPRescalerImport(p->scaler_y, mb_h - j,
- io->y + j * io->y_stride, io->y_stride);
+ io->y + (size_t)j * io->y_stride, io->y_stride);
j += y_lines_in;
if (WebPRescaleNeededLines(p->scaler_u, uv_mb_h - uv_j)) {
- const int u_lines_in =
- WebPRescalerImport(p->scaler_u, uv_mb_h - uv_j,
- io->u + uv_j * io->uv_stride, io->uv_stride);
- const int v_lines_in =
- WebPRescalerImport(p->scaler_v, uv_mb_h - uv_j,
- io->v + uv_j * io->uv_stride, io->uv_stride);
+ const int u_lines_in = WebPRescalerImport(
+ p->scaler_u, uv_mb_h - uv_j, io->u + (size_t)uv_j * io->uv_stride,
+ io->uv_stride);
+ const int v_lines_in = WebPRescalerImport(
+ p->scaler_v, uv_mb_h - uv_j, io->v + (size_t)uv_j * io->uv_stride,
+ io->uv_stride);
(void)v_lines_in; // remove a gcc warning
assert(u_lines_in == v_lines_in);
uv_j += u_lines_in;
@@ -403,7 +398,7 @@ static int EmitRescaledRGB(const VP8Io* const io, WebPDecParams* const p) {
static int ExportAlpha(WebPDecParams* const p, int y_pos, int max_lines_out) {
const WebPRGBABuffer* const buf = &p->output->u.RGBA;
- uint8_t* const base_rgba = buf->rgba + y_pos * buf->stride;
+ uint8_t* const base_rgba = buf->rgba + (size_t)y_pos * buf->stride;
const WEBP_CSP_MODE colorspace = p->output->colorspace;
const int alpha_first =
(colorspace == MODE_ARGB || colorspace == MODE_Argb);
@@ -431,7 +426,7 @@ static int ExportAlpha(WebPDecParams* const p, int y_pos, int max_lines_out) {
static int ExportAlphaRGBA4444(WebPDecParams* const p, int y_pos,
int max_lines_out) {
const WebPRGBABuffer* const buf = &p->output->u.RGBA;
- uint8_t* const base_rgba = buf->rgba + y_pos * buf->stride;
+ uint8_t* const base_rgba = buf->rgba + (size_t)y_pos * buf->stride;
#if (WEBP_SWAP_16BIT_CSP == 1)
uint8_t* alpha_dst = base_rgba;
#else
@@ -470,7 +465,7 @@ static int EmitRescaledAlphaRGB(const VP8Io* const io, WebPDecParams* const p,
int lines_left = expected_num_out_lines;
const int y_end = p->last_y + lines_left;
while (lines_left > 0) {
- const int row_offset = scaler->src_y - io->mb_y;
+ const int64_t row_offset = (int64_t)scaler->src_y - io->mb_y;
WebPRescalerImport(scaler, io->mb_h + io->mb_y - scaler->src_y,
io->a + row_offset * io->width, io->width);
lines_left -= p->emit_alpha_row(p, y_end - lines_left, lines_left);
diff --git a/src/3rdparty/libwebp/src/dec/vp8_dec.c b/src/3rdparty/libwebp/src/dec/vp8_dec.c
index 57efb69..8f73697 100644
--- a/src/3rdparty/libwebp/src/dec/vp8_dec.c
+++ b/src/3rdparty/libwebp/src/dec/vp8_dec.c
@@ -494,13 +494,11 @@ static int GetCoeffsAlt(VP8BitReader* const br,
return 16;
}
-static WEBP_TSAN_IGNORE_FUNCTION void InitGetCoeffs(void) {
- if (GetCoeffs == NULL) {
- if (VP8GetCPUInfo != NULL && VP8GetCPUInfo(kSlowSSSE3)) {
- GetCoeffs = GetCoeffsAlt;
- } else {
- GetCoeffs = GetCoeffsFast;
- }
+WEBP_DSP_INIT_FUNC(InitGetCoeffs) {
+ if (VP8GetCPUInfo != NULL && VP8GetCPUInfo(kSlowSSSE3)) {
+ GetCoeffs = GetCoeffsAlt;
+ } else {
+ GetCoeffs = GetCoeffsFast;
}
}
diff --git a/src/3rdparty/libwebp/src/dec/vp8i_dec.h b/src/3rdparty/libwebp/src/dec/vp8i_dec.h
index 600a684..a0c0af1 100644
--- a/src/3rdparty/libwebp/src/dec/vp8i_dec.h
+++ b/src/3rdparty/libwebp/src/dec/vp8i_dec.h
@@ -31,7 +31,7 @@ extern "C" {
// version numbers
#define DEC_MAJ_VERSION 1
-#define DEC_MIN_VERSION 1
+#define DEC_MIN_VERSION 2
#define DEC_REV_VERSION 0
// YUV-cache parameters. Cache is 32-bytes wide (= one cacheline).
diff --git a/src/3rdparty/libwebp/src/dec/vp8l_dec.c b/src/3rdparty/libwebp/src/dec/vp8l_dec.c
index 93615d4..2d603b4 100644
--- a/src/3rdparty/libwebp/src/dec/vp8l_dec.c
+++ b/src/3rdparty/libwebp/src/dec/vp8l_dec.c
@@ -947,7 +947,6 @@ static WEBP_INLINE void CopyBlock8b(uint8_t* const dst, int dist, int length) {
break;
default:
goto Copy;
- break;
}
CopySmallPattern8b(src, dst, length, pattern);
return;
diff --git a/src/3rdparty/libwebp/src/demux/anim_decode.c b/src/3rdparty/libwebp/src/demux/anim_decode.c
index 05dd707..3dcacc3 100644
--- a/src/3rdparty/libwebp/src/demux/anim_decode.c
+++ b/src/3rdparty/libwebp/src/demux/anim_decode.c
@@ -346,12 +346,15 @@ int WebPAnimDecoderGetNext(WebPAnimDecoder* dec,
{
const uint8_t* in = iter.fragment.bytes;
const size_t in_size = iter.fragment.size;
- const size_t out_offset =
- (iter.y_offset * width + iter.x_offset) * NUM_CHANNELS;
+ const uint32_t stride = width * NUM_CHANNELS; // at most 25 + 2 bits
+ const uint64_t out_offset = (uint64_t)iter.y_offset * stride +
+ (uint64_t)iter.x_offset * NUM_CHANNELS; // 53b
+ const uint64_t size = (uint64_t)iter.height * stride; // at most 25 + 27b
WebPDecoderConfig* const config = &dec->config_;
WebPRGBABuffer* const buf = &config->output.u.RGBA;
- buf->stride = NUM_CHANNELS * width;
- buf->size = buf->stride * iter.height;
+ if ((size_t)size != size) goto Error;
+ buf->stride = (int)stride;
+ buf->size = (size_t)size;
buf->rgba = dec->curr_frame_ + out_offset;
if (WebPDecode(in, in_size, config) != VP8_STATUS_OK) {
diff --git a/src/3rdparty/libwebp/src/demux/demux.c b/src/3rdparty/libwebp/src/demux/demux.c
index 1b3cc2e..860e2ce 100644
--- a/src/3rdparty/libwebp/src/demux/demux.c
+++ b/src/3rdparty/libwebp/src/demux/demux.c
@@ -24,7 +24,7 @@
#include "src/webp/format_constants.h"
#define DMUX_MAJ_VERSION 1
-#define DMUX_MIN_VERSION 1
+#define DMUX_MIN_VERSION 2
#define DMUX_REV_VERSION 0
typedef struct {
@@ -312,6 +312,7 @@ static ParseStatus ParseAnimationFrame(
int bits;
MemBuffer* const mem = &dmux->mem_;
Frame* frame;
+ size_t start_offset;
ParseStatus status =
NewFrame(mem, ANMF_CHUNK_SIZE, frame_chunk_size, &frame);
if (status != PARSE_OK) return status;
@@ -332,7 +333,11 @@ static ParseStatus ParseAnimationFrame(
// Store a frame only if the animation flag is set there is some data for
// this frame is available.
+ start_offset = mem->start_;
status = StoreFrame(dmux->num_frames_ + 1, anmf_payload_size, mem, frame);
+ if (status != PARSE_ERROR && mem->start_ - start_offset > anmf_payload_size) {
+ status = PARSE_ERROR;
+ }
if (status != PARSE_ERROR && is_animation && frame->frame_num_ > 0) {
added_frame = AddFrame(dmux, frame);
if (added_frame) {
diff --git a/src/3rdparty/libwebp/src/dsp/alpha_processing.c b/src/3rdparty/libwebp/src/dsp/alpha_processing.c
index 819d139..3a27990 100644
--- a/src/3rdparty/libwebp/src/dsp/alpha_processing.c
+++ b/src/3rdparty/libwebp/src/dsp/alpha_processing.c
@@ -359,6 +359,11 @@ static int HasAlpha32b_C(const uint8_t* src, int length) {
return 0;
}
+static void AlphaReplace_C(uint32_t* src, int length, uint32_t color) {
+ int x;
+ for (x = 0; x < length; ++x) if ((src[x] >> 24) == 0) src[x] = color;
+}
+
//------------------------------------------------------------------------------
// Simple channel manipulations.
@@ -400,6 +405,7 @@ void (*WebPPackRGB)(const uint8_t* r, const uint8_t* g, const uint8_t* b,
int (*WebPHasAlpha8b)(const uint8_t* src, int length);
int (*WebPHasAlpha32b)(const uint8_t* src, int length);
+void (*WebPAlphaReplace)(uint32_t* src, int length, uint32_t color);
//------------------------------------------------------------------------------
// Init function
@@ -428,6 +434,7 @@ WEBP_DSP_INIT_FUNC(WebPInitAlphaProcessing) {
WebPHasAlpha8b = HasAlpha8b_C;
WebPHasAlpha32b = HasAlpha32b_C;
+ WebPAlphaReplace = AlphaReplace_C;
// If defined, use CPUInfo() to overwrite some pointers with faster versions.
if (VP8GetCPUInfo != NULL) {
@@ -469,4 +476,5 @@ WEBP_DSP_INIT_FUNC(WebPInitAlphaProcessing) {
assert(WebPPackRGB != NULL);
assert(WebPHasAlpha8b != NULL);
assert(WebPHasAlpha32b != NULL);
+ assert(WebPAlphaReplace != NULL);
}
diff --git a/src/3rdparty/libwebp/src/dsp/alpha_processing_sse2.c b/src/3rdparty/libwebp/src/dsp/alpha_processing_sse2.c
index 2871c56..f6c6e0f 100644
--- a/src/3rdparty/libwebp/src/dsp/alpha_processing_sse2.c
+++ b/src/3rdparty/libwebp/src/dsp/alpha_processing_sse2.c
@@ -265,6 +265,27 @@ static int HasAlpha32b_SSE2(const uint8_t* src, int length) {
return 0;
}
+static void AlphaReplace_SSE2(uint32_t* src, int length, uint32_t color) {
+ const __m128i m_color = _mm_set1_epi32(color);
+ const __m128i zero = _mm_setzero_si128();
+ int i = 0;
+ for (; i + 8 <= length; i += 8) {
+ const __m128i a0 = _mm_loadu_si128((const __m128i*)(src + i + 0));
+ const __m128i a1 = _mm_loadu_si128((const __m128i*)(src + i + 4));
+ const __m128i b0 = _mm_srai_epi32(a0, 24);
+ const __m128i b1 = _mm_srai_epi32(a1, 24);
+ const __m128i c0 = _mm_cmpeq_epi32(b0, zero);
+ const __m128i c1 = _mm_cmpeq_epi32(b1, zero);
+ const __m128i d0 = _mm_and_si128(c0, m_color);
+ const __m128i d1 = _mm_and_si128(c1, m_color);
+ const __m128i e0 = _mm_andnot_si128(c0, a0);
+ const __m128i e1 = _mm_andnot_si128(c1, a1);
+ _mm_storeu_si128((__m128i*)(src + i + 0), _mm_or_si128(d0, e0));
+ _mm_storeu_si128((__m128i*)(src + i + 4), _mm_or_si128(d1, e1));
+ }
+ for (; i < length; ++i) if ((src[i] >> 24) == 0) src[i] = color;
+}
+
// -----------------------------------------------------------------------------
// Apply alpha value to rows
@@ -334,6 +355,7 @@ WEBP_TSAN_IGNORE_FUNCTION void WebPInitAlphaProcessingSSE2(void) {
WebPHasAlpha8b = HasAlpha8b_SSE2;
WebPHasAlpha32b = HasAlpha32b_SSE2;
+ WebPAlphaReplace = AlphaReplace_SSE2;
}
#else // !WEBP_USE_SSE2
diff --git a/src/3rdparty/libwebp/src/dsp/cpu.c b/src/3rdparty/libwebp/src/dsp/cpu.c
index 0fa5b6a..4ca90d8 100644
--- a/src/3rdparty/libwebp/src/dsp/cpu.c
+++ b/src/3rdparty/libwebp/src/dsp/cpu.c
@@ -55,12 +55,18 @@ static WEBP_INLINE void GetCPUInfo(int cpu_info[4], int info_type) {
: "=a"(cpu_info[0]), "=b"(cpu_info[1]), "=c"(cpu_info[2]), "=d"(cpu_info[3])
: "a"(info_type), "c"(0));
}
-#elif (defined(_M_X64) || defined(_M_IX86)) && \
- defined(_MSC_FULL_VER) && _MSC_FULL_VER >= 150030729 // >= VS2008 SP1
+#elif defined(_MSC_VER) && (defined(_M_X64) || defined(_M_IX86))
+
+#if defined(_MSC_FULL_VER) && _MSC_FULL_VER >= 150030729 // >= VS2008 SP1
#include <intrin.h>
#define GetCPUInfo(info, type) __cpuidex(info, type, 0) // set ecx=0
-#elif defined(WEBP_MSC_SSE2)
+#define WEBP_HAVE_MSC_CPUID
+#elif _MSC_VER > 1310
+#include <intrin.h>
#define GetCPUInfo __cpuid
+#define WEBP_HAVE_MSC_CPUID
+#endif
+
#endif
// NaCl has no support for xgetbv or the raw opcode.
@@ -94,7 +100,7 @@ static WEBP_INLINE uint64_t xgetbv(void) {
#define xgetbv() 0U // no AVX for older x64 or unrecognized toolchains.
#endif
-#if defined(__i386__) || defined(__x86_64__) || defined(WEBP_MSC_SSE2)
+#if defined(__i386__) || defined(__x86_64__) || defined(WEBP_HAVE_MSC_CPUID)
// helper function for run-time detection of slow SSSE3 platforms
static int CheckSlowModel(int info) {
@@ -179,6 +185,30 @@ static int AndroidCPUInfo(CPUFeature feature) {
return 0;
}
VP8CPUInfo VP8GetCPUInfo = AndroidCPUInfo;
+#elif defined(EMSCRIPTEN) // also needs to be before generic NEON test
+// Use compile flags as an indicator of SIMD support instead of a runtime check.
+static int wasmCPUInfo(CPUFeature feature) {
+ switch (feature) {
+#ifdef WEBP_USE_SSE2
+ case kSSE2:
+ return 1;
+#endif
+#ifdef WEBP_USE_SSE41
+ case kSSE3:
+ case kSlowSSSE3:
+ case kSSE4_1:
+ return 1;
+#endif
+#ifdef WEBP_USE_NEON
+ case kNEON:
+ return 1;
+#endif
+ default:
+ break;
+ }
+ return 0;
+}
+VP8CPUInfo VP8GetCPUInfo = wasmCPUInfo;
#elif defined(WEBP_USE_NEON)
// define a dummy function to enable turning off NEON at runtime by setting
// VP8DecGetCPUInfo = NULL
diff --git a/src/3rdparty/libwebp/src/dsp/dec_neon.c b/src/3rdparty/libwebp/src/dsp/dec_neon.c
index 239ec41..fa85170 100644
--- a/src/3rdparty/libwebp/src/dsp/dec_neon.c
+++ b/src/3rdparty/libwebp/src/dsp/dec_neon.c
@@ -1283,12 +1283,12 @@ static void DC4_NEON(uint8_t* dst) { // DC
const uint8x8_t A = vld1_u8(dst - BPS); // top row
const uint16x4_t p0 = vpaddl_u8(A); // cascading summation of the top
const uint16x4_t p1 = vpadd_u16(p0, p0);
- const uint16x8_t L0 = vmovl_u8(vld1_u8(dst + 0 * BPS - 1));
- const uint16x8_t L1 = vmovl_u8(vld1_u8(dst + 1 * BPS - 1));
- const uint16x8_t L2 = vmovl_u8(vld1_u8(dst + 2 * BPS - 1));
- const uint16x8_t L3 = vmovl_u8(vld1_u8(dst + 3 * BPS - 1));
- const uint16x8_t s0 = vaddq_u16(L0, L1);
- const uint16x8_t s1 = vaddq_u16(L2, L3);
+ const uint8x8_t L0 = vld1_u8(dst + 0 * BPS - 1);
+ const uint8x8_t L1 = vld1_u8(dst + 1 * BPS - 1);
+ const uint8x8_t L2 = vld1_u8(dst + 2 * BPS - 1);
+ const uint8x8_t L3 = vld1_u8(dst + 3 * BPS - 1);
+ const uint16x8_t s0 = vaddl_u8(L0, L1);
+ const uint16x8_t s1 = vaddl_u8(L2, L3);
const uint16x8_t s01 = vaddq_u16(s0, s1);
const uint16x8_t sum = vaddq_u16(s01, vcombine_u16(p1, p1));
const uint8x8_t dc0 = vrshrn_n_u16(sum, 3); // (sum + 4) >> 3
@@ -1429,8 +1429,7 @@ static WEBP_INLINE void DC8_NEON(uint8_t* dst, int do_top, int do_left) {
if (do_top) {
const uint8x8_t A = vld1_u8(dst - BPS); // top row
#if defined(__aarch64__)
- const uint16x8_t B = vmovl_u8(A);
- const uint16_t p2 = vaddvq_u16(B);
+ const uint16_t p2 = vaddlv_u8(A);
sum_top = vdupq_n_u16(p2);
#else
const uint16x4_t p0 = vpaddl_u8(A); // cascading summation of the top
@@ -1441,18 +1440,18 @@ static WEBP_INLINE void DC8_NEON(uint8_t* dst, int do_top, int do_left) {
}
if (do_left) {
- const uint16x8_t L0 = vmovl_u8(vld1_u8(dst + 0 * BPS - 1));
- const uint16x8_t L1 = vmovl_u8(vld1_u8(dst + 1 * BPS - 1));
- const uint16x8_t L2 = vmovl_u8(vld1_u8(dst + 2 * BPS - 1));
- const uint16x8_t L3 = vmovl_u8(vld1_u8(dst + 3 * BPS - 1));
- const uint16x8_t L4 = vmovl_u8(vld1_u8(dst + 4 * BPS - 1));
- const uint16x8_t L5 = vmovl_u8(vld1_u8(dst + 5 * BPS - 1));
- const uint16x8_t L6 = vmovl_u8(vld1_u8(dst + 6 * BPS - 1));
- const uint16x8_t L7 = vmovl_u8(vld1_u8(dst + 7 * BPS - 1));
- const uint16x8_t s0 = vaddq_u16(L0, L1);
- const uint16x8_t s1 = vaddq_u16(L2, L3);
- const uint16x8_t s2 = vaddq_u16(L4, L5);
- const uint16x8_t s3 = vaddq_u16(L6, L7);
+ const uint8x8_t L0 = vld1_u8(dst + 0 * BPS - 1);
+ const uint8x8_t L1 = vld1_u8(dst + 1 * BPS - 1);
+ const uint8x8_t L2 = vld1_u8(dst + 2 * BPS - 1);
+ const uint8x8_t L3 = vld1_u8(dst + 3 * BPS - 1);
+ const uint8x8_t L4 = vld1_u8(dst + 4 * BPS - 1);
+ const uint8x8_t L5 = vld1_u8(dst + 5 * BPS - 1);
+ const uint8x8_t L6 = vld1_u8(dst + 6 * BPS - 1);
+ const uint8x8_t L7 = vld1_u8(dst + 7 * BPS - 1);
+ const uint16x8_t s0 = vaddl_u8(L0, L1);
+ const uint16x8_t s1 = vaddl_u8(L2, L3);
+ const uint16x8_t s2 = vaddl_u8(L4, L5);
+ const uint16x8_t s3 = vaddl_u8(L6, L7);
const uint16x8_t s01 = vaddq_u16(s0, s1);
const uint16x8_t s23 = vaddq_u16(s2, s3);
sum_left = vaddq_u16(s01, s23);
@@ -1512,29 +1511,34 @@ static WEBP_INLINE void DC16_NEON(uint8_t* dst, int do_top, int do_left) {
if (do_top) {
const uint8x16_t A = vld1q_u8(dst - BPS); // top row
+#if defined(__aarch64__)
+ const uint16_t p3 = vaddlvq_u8(A);
+ sum_top = vdupq_n_u16(p3);
+#else
const uint16x8_t p0 = vpaddlq_u8(A); // cascading summation of the top
const uint16x4_t p1 = vadd_u16(vget_low_u16(p0), vget_high_u16(p0));
const uint16x4_t p2 = vpadd_u16(p1, p1);
const uint16x4_t p3 = vpadd_u16(p2, p2);
sum_top = vcombine_u16(p3, p3);
+#endif
}
if (do_left) {
int i;
sum_left = vdupq_n_u16(0);
for (i = 0; i < 16; i += 8) {
- const uint16x8_t L0 = vmovl_u8(vld1_u8(dst + (i + 0) * BPS - 1));
- const uint16x8_t L1 = vmovl_u8(vld1_u8(dst + (i + 1) * BPS - 1));
- const uint16x8_t L2 = vmovl_u8(vld1_u8(dst + (i + 2) * BPS - 1));
- const uint16x8_t L3 = vmovl_u8(vld1_u8(dst + (i + 3) * BPS - 1));
- const uint16x8_t L4 = vmovl_u8(vld1_u8(dst + (i + 4) * BPS - 1));
- const uint16x8_t L5 = vmovl_u8(vld1_u8(dst + (i + 5) * BPS - 1));
- const uint16x8_t L6 = vmovl_u8(vld1_u8(dst + (i + 6) * BPS - 1));
- const uint16x8_t L7 = vmovl_u8(vld1_u8(dst + (i + 7) * BPS - 1));
- const uint16x8_t s0 = vaddq_u16(L0, L1);
- const uint16x8_t s1 = vaddq_u16(L2, L3);
- const uint16x8_t s2 = vaddq_u16(L4, L5);
- const uint16x8_t s3 = vaddq_u16(L6, L7);
+ const uint8x8_t L0 = vld1_u8(dst + (i + 0) * BPS - 1);
+ const uint8x8_t L1 = vld1_u8(dst + (i + 1) * BPS - 1);
+ const uint8x8_t L2 = vld1_u8(dst + (i + 2) * BPS - 1);
+ const uint8x8_t L3 = vld1_u8(dst + (i + 3) * BPS - 1);
+ const uint8x8_t L4 = vld1_u8(dst + (i + 4) * BPS - 1);
+ const uint8x8_t L5 = vld1_u8(dst + (i + 5) * BPS - 1);
+ const uint8x8_t L6 = vld1_u8(dst + (i + 6) * BPS - 1);
+ const uint8x8_t L7 = vld1_u8(dst + (i + 7) * BPS - 1);
+ const uint16x8_t s0 = vaddl_u8(L0, L1);
+ const uint16x8_t s1 = vaddl_u8(L2, L3);
+ const uint16x8_t s2 = vaddl_u8(L4, L5);
+ const uint16x8_t s3 = vaddl_u8(L6, L7);
const uint16x8_t s01 = vaddq_u16(s0, s1);
const uint16x8_t s23 = vaddq_u16(s2, s3);
const uint16x8_t sum = vaddq_u16(s01, s23);
diff --git a/src/3rdparty/libwebp/src/dsp/dsp.h b/src/3rdparty/libwebp/src/dsp/dsp.h
index 7c75b26..6df48cf 100644
--- a/src/3rdparty/libwebp/src/dsp/dsp.h
+++ b/src/3rdparty/libwebp/src/dsp/dsp.h
@@ -51,9 +51,7 @@ extern "C" {
# define __has_builtin(x) 0
#endif
-// for now, none of the optimizations below are available in emscripten
-#if !defined(EMSCRIPTEN)
-
+#if !defined(HAVE_CONFIG_H)
#if defined(_MSC_VER) && _MSC_VER > 1310 && \
(defined(_M_X64) || defined(_M_IX86)) && !defined(__clang__)
#define WEBP_MSC_SSE2 // Visual C++ SSE2 targets
@@ -63,6 +61,7 @@ extern "C" {
(defined(_M_X64) || defined(_M_IX86)) && !defined(__clang__)
#define WEBP_MSC_SSE41 // Visual C++ SSE4.1 targets
#endif
+#endif
// WEBP_HAVE_* are used to indicate the presence of the instruction set in dsp
// files without intrinsics, allowing the corresponding Init() to be called.
@@ -76,6 +75,9 @@ extern "C" {
#define WEBP_USE_SSE41
#endif
+#undef WEBP_MSC_SSE41
+#undef WEBP_MSC_SSE2
+
// The intrinsics currently cause compiler errors with arm-nacl-gcc and the
// inline assembly would need to be modified for use with Native Client.
#if (defined(__ARM_NEON__) || \
@@ -110,8 +112,6 @@ extern "C" {
#define WEBP_USE_MSA
#endif
-#endif /* EMSCRIPTEN */
-
#ifndef WEBP_DSP_OMIT_C_CODE
#define WEBP_DSP_OMIT_C_CODE 1
#endif
@@ -193,6 +193,12 @@ extern "C" {
#endif
#endif
+// If 'ptr' is NULL, returns NULL. Otherwise returns 'ptr + off'.
+// Prevents undefined behavior sanitizer nullptr-with-nonzero-offset warning.
+#if !defined(WEBP_OFFSET_PTR)
+#define WEBP_OFFSET_PTR(ptr, off) (((ptr) == NULL) ? NULL : ((ptr) + (off)))
+#endif
+
// Regularize the definition of WEBP_SWAP_16BIT_CSP (backward compatibility)
#if !defined(WEBP_SWAP_16BIT_CSP)
#define WEBP_SWAP_16BIT_CSP 0
@@ -632,6 +638,8 @@ extern void (*WebPPackRGB)(const uint8_t* r, const uint8_t* g, const uint8_t* b,
extern int (*WebPHasAlpha8b)(const uint8_t* src, int length);
// This function returns true if src[4*i] contains a value different from 0xff.
extern int (*WebPHasAlpha32b)(const uint8_t* src, int length);
+// replaces transparent values in src[] by 'color'.
+extern void (*WebPAlphaReplace)(uint32_t* src, int length, uint32_t color);
// To be called first before using the above.
void WebPInitAlphaProcessing(void);
diff --git a/src/3rdparty/libwebp/src/dsp/lossless.c b/src/3rdparty/libwebp/src/dsp/lossless.c
index aad5f43..46b220e 100644
--- a/src/3rdparty/libwebp/src/dsp/lossless.c
+++ b/src/3rdparty/libwebp/src/dsp/lossless.c
@@ -107,62 +107,62 @@ static WEBP_INLINE uint32_t Select(uint32_t a, uint32_t b, uint32_t c) {
//------------------------------------------------------------------------------
// Predictors
-static uint32_t Predictor0_C(uint32_t left, const uint32_t* const top) {
+uint32_t VP8LPredictor0_C(uint32_t left, const uint32_t* const top) {
(void)top;
(void)left;
return ARGB_BLACK;
}
-static uint32_t Predictor1_C(uint32_t left, const uint32_t* const top) {
+uint32_t VP8LPredictor1_C(uint32_t left, const uint32_t* const top) {
(void)top;
return left;
}
-static uint32_t Predictor2_C(uint32_t left, const uint32_t* const top) {
+uint32_t VP8LPredictor2_C(uint32_t left, const uint32_t* const top) {
(void)left;
return top[0];
}
-static uint32_t Predictor3_C(uint32_t left, const uint32_t* const top) {
+uint32_t VP8LPredictor3_C(uint32_t left, const uint32_t* const top) {
(void)left;
return top[1];
}
-static uint32_t Predictor4_C(uint32_t left, const uint32_t* const top) {
+uint32_t VP8LPredictor4_C(uint32_t left, const uint32_t* const top) {
(void)left;
return top[-1];
}
-static uint32_t Predictor5_C(uint32_t left, const uint32_t* const top) {
+uint32_t VP8LPredictor5_C(uint32_t left, const uint32_t* const top) {
const uint32_t pred = Average3(left, top[0], top[1]);
return pred;
}
-static uint32_t Predictor6_C(uint32_t left, const uint32_t* const top) {
+uint32_t VP8LPredictor6_C(uint32_t left, const uint32_t* const top) {
const uint32_t pred = Average2(left, top[-1]);
return pred;
}
-static uint32_t Predictor7_C(uint32_t left, const uint32_t* const top) {
+uint32_t VP8LPredictor7_C(uint32_t left, const uint32_t* const top) {
const uint32_t pred = Average2(left, top[0]);
return pred;
}
-static uint32_t Predictor8_C(uint32_t left, const uint32_t* const top) {
+uint32_t VP8LPredictor8_C(uint32_t left, const uint32_t* const top) {
const uint32_t pred = Average2(top[-1], top[0]);
(void)left;
return pred;
}
-static uint32_t Predictor9_C(uint32_t left, const uint32_t* const top) {
+uint32_t VP8LPredictor9_C(uint32_t left, const uint32_t* const top) {
const uint32_t pred = Average2(top[0], top[1]);
(void)left;
return pred;
}
-static uint32_t Predictor10_C(uint32_t left, const uint32_t* const top) {
+uint32_t VP8LPredictor10_C(uint32_t left, const uint32_t* const top) {
const uint32_t pred = Average4(left, top[-1], top[0], top[1]);
return pred;
}
-static uint32_t Predictor11_C(uint32_t left, const uint32_t* const top) {
+uint32_t VP8LPredictor11_C(uint32_t left, const uint32_t* const top) {
const uint32_t pred = Select(top[0], left, top[-1]);
return pred;
}
-static uint32_t Predictor12_C(uint32_t left, const uint32_t* const top) {
+uint32_t VP8LPredictor12_C(uint32_t left, const uint32_t* const top) {
const uint32_t pred = ClampedAddSubtractFull(left, top[0], top[-1]);
return pred;
}
-static uint32_t Predictor13_C(uint32_t left, const uint32_t* const top) {
+uint32_t VP8LPredictor13_C(uint32_t left, const uint32_t* const top) {
const uint32_t pred = ClampedAddSubtractHalf(left, top[0], top[-1]);
return pred;
}
@@ -182,18 +182,18 @@ static void PredictorAdd1_C(const uint32_t* in, const uint32_t* upper,
out[i] = left = VP8LAddPixels(in[i], left);
}
}
-GENERATE_PREDICTOR_ADD(Predictor2_C, PredictorAdd2_C)
-GENERATE_PREDICTOR_ADD(Predictor3_C, PredictorAdd3_C)
-GENERATE_PREDICTOR_ADD(Predictor4_C, PredictorAdd4_C)
-GENERATE_PREDICTOR_ADD(Predictor5_C, PredictorAdd5_C)
-GENERATE_PREDICTOR_ADD(Predictor6_C, PredictorAdd6_C)
-GENERATE_PREDICTOR_ADD(Predictor7_C, PredictorAdd7_C)
-GENERATE_PREDICTOR_ADD(Predictor8_C, PredictorAdd8_C)
-GENERATE_PREDICTOR_ADD(Predictor9_C, PredictorAdd9_C)
-GENERATE_PREDICTOR_ADD(Predictor10_C, PredictorAdd10_C)
-GENERATE_PREDICTOR_ADD(Predictor11_C, PredictorAdd11_C)
-GENERATE_PREDICTOR_ADD(Predictor12_C, PredictorAdd12_C)
-GENERATE_PREDICTOR_ADD(Predictor13_C, PredictorAdd13_C)
+GENERATE_PREDICTOR_ADD(VP8LPredictor2_C, PredictorAdd2_C)
+GENERATE_PREDICTOR_ADD(VP8LPredictor3_C, PredictorAdd3_C)
+GENERATE_PREDICTOR_ADD(VP8LPredictor4_C, PredictorAdd4_C)
+GENERATE_PREDICTOR_ADD(VP8LPredictor5_C, PredictorAdd5_C)
+GENERATE_PREDICTOR_ADD(VP8LPredictor6_C, PredictorAdd6_C)
+GENERATE_PREDICTOR_ADD(VP8LPredictor7_C, PredictorAdd7_C)
+GENERATE_PREDICTOR_ADD(VP8LPredictor8_C, PredictorAdd8_C)
+GENERATE_PREDICTOR_ADD(VP8LPredictor9_C, PredictorAdd9_C)
+GENERATE_PREDICTOR_ADD(VP8LPredictor10_C, PredictorAdd10_C)
+GENERATE_PREDICTOR_ADD(VP8LPredictor11_C, PredictorAdd11_C)
+GENERATE_PREDICTOR_ADD(VP8LPredictor12_C, PredictorAdd12_C)
+GENERATE_PREDICTOR_ADD(VP8LPredictor13_C, PredictorAdd13_C)
//------------------------------------------------------------------------------
@@ -562,7 +562,6 @@ VP8LPredictorFunc VP8LPredictors[16];
// exposed plain-C implementations
VP8LPredictorAddSubFunc VP8LPredictorsAdd_C[16];
-VP8LPredictorFunc VP8LPredictors_C[16];
VP8LTransformColorInverseFunc VP8LTransformColorInverse;
@@ -600,8 +599,7 @@ extern void VP8LDspInitMSA(void);
} while (0);
WEBP_DSP_INIT_FUNC(VP8LDspInit) {
- COPY_PREDICTOR_ARRAY(Predictor, VP8LPredictors)
- COPY_PREDICTOR_ARRAY(Predictor, VP8LPredictors_C)
+ COPY_PREDICTOR_ARRAY(VP8LPredictor, VP8LPredictors)
COPY_PREDICTOR_ARRAY(PredictorAdd, VP8LPredictorsAdd)
COPY_PREDICTOR_ARRAY(PredictorAdd, VP8LPredictorsAdd_C)
diff --git a/src/3rdparty/libwebp/src/dsp/lossless.h b/src/3rdparty/libwebp/src/dsp/lossless.h
index f709cc8..ebd316d 100644
--- a/src/3rdparty/libwebp/src/dsp/lossless.h
+++ b/src/3rdparty/libwebp/src/dsp/lossless.h
@@ -30,7 +30,22 @@ extern "C" {
typedef uint32_t (*VP8LPredictorFunc)(uint32_t left, const uint32_t* const top);
extern VP8LPredictorFunc VP8LPredictors[16];
-extern VP8LPredictorFunc VP8LPredictors_C[16];
+
+uint32_t VP8LPredictor0_C(uint32_t left, const uint32_t* const top);
+uint32_t VP8LPredictor1_C(uint32_t left, const uint32_t* const top);
+uint32_t VP8LPredictor2_C(uint32_t left, const uint32_t* const top);
+uint32_t VP8LPredictor3_C(uint32_t left, const uint32_t* const top);
+uint32_t VP8LPredictor4_C(uint32_t left, const uint32_t* const top);
+uint32_t VP8LPredictor5_C(uint32_t left, const uint32_t* const top);
+uint32_t VP8LPredictor6_C(uint32_t left, const uint32_t* const top);
+uint32_t VP8LPredictor7_C(uint32_t left, const uint32_t* const top);
+uint32_t VP8LPredictor8_C(uint32_t left, const uint32_t* const top);
+uint32_t VP8LPredictor9_C(uint32_t left, const uint32_t* const top);
+uint32_t VP8LPredictor10_C(uint32_t left, const uint32_t* const top);
+uint32_t VP8LPredictor11_C(uint32_t left, const uint32_t* const top);
+uint32_t VP8LPredictor12_C(uint32_t left, const uint32_t* const top);
+uint32_t VP8LPredictor13_C(uint32_t left, const uint32_t* const top);
+
// These Add/Sub function expects upper[-1] and out[-1] to be readable.
typedef void (*VP8LPredictorAddSubFunc)(const uint32_t* in,
const uint32_t* upper, int num_pixels,
diff --git a/src/3rdparty/libwebp/src/dsp/lossless_common.h b/src/3rdparty/libwebp/src/dsp/lossless_common.h
index 9c2ebe6..96a106f 100644
--- a/src/3rdparty/libwebp/src/dsp/lossless_common.h
+++ b/src/3rdparty/libwebp/src/dsp/lossless_common.h
@@ -184,19 +184,6 @@ static void PREDICTOR_ADD(const uint32_t* in, const uint32_t* upper, \
} \
}
-// It subtracts the prediction from the input pixel and stores the residual
-// in the output pixel.
-#define GENERATE_PREDICTOR_SUB(PREDICTOR, PREDICTOR_SUB) \
-static void PREDICTOR_SUB(const uint32_t* in, const uint32_t* upper, \
- int num_pixels, uint32_t* out) { \
- int x; \
- assert(upper != NULL); \
- for (x = 0; x < num_pixels; ++x) { \
- const uint32_t pred = (PREDICTOR)(in[x - 1], upper + x); \
- out[x] = VP8LSubPixels(in[x], pred); \
- } \
-}
-
#ifdef __cplusplus
} // extern "C"
#endif
diff --git a/src/3rdparty/libwebp/src/dsp/lossless_enc.c b/src/3rdparty/libwebp/src/dsp/lossless_enc.c
index 9c36055..a0c7ab9 100644
--- a/src/3rdparty/libwebp/src/dsp/lossless_enc.c
+++ b/src/3rdparty/libwebp/src/dsp/lossless_enc.c
@@ -702,140 +702,6 @@ void VP8LHistogramAdd(const VP8LHistogram* const a,
//------------------------------------------------------------------------------
// Image transforms.
-static WEBP_INLINE uint32_t Average2(uint32_t a0, uint32_t a1) {
- return (((a0 ^ a1) & 0xfefefefeu) >> 1) + (a0 & a1);
-}
-
-static WEBP_INLINE uint32_t Average3(uint32_t a0, uint32_t a1, uint32_t a2) {
- return Average2(Average2(a0, a2), a1);
-}
-
-static WEBP_INLINE uint32_t Average4(uint32_t a0, uint32_t a1,
- uint32_t a2, uint32_t a3) {
- return Average2(Average2(a0, a1), Average2(a2, a3));
-}
-
-static WEBP_INLINE uint32_t Clip255(uint32_t a) {
- if (a < 256) {
- return a;
- }
- // return 0, when a is a negative integer.
- // return 255, when a is positive.
- return ~a >> 24;
-}
-
-static WEBP_INLINE int AddSubtractComponentFull(int a, int b, int c) {
- return Clip255(a + b - c);
-}
-
-static WEBP_INLINE uint32_t ClampedAddSubtractFull(uint32_t c0, uint32_t c1,
- uint32_t c2) {
- const int a = AddSubtractComponentFull(c0 >> 24, c1 >> 24, c2 >> 24);
- const int r = AddSubtractComponentFull((c0 >> 16) & 0xff,
- (c1 >> 16) & 0xff,
- (c2 >> 16) & 0xff);
- const int g = AddSubtractComponentFull((c0 >> 8) & 0xff,
- (c1 >> 8) & 0xff,
- (c2 >> 8) & 0xff);
- const int b = AddSubtractComponentFull(c0 & 0xff, c1 & 0xff, c2 & 0xff);
- return ((uint32_t)a << 24) | (r << 16) | (g << 8) | b;
-}
-
-static WEBP_INLINE int AddSubtractComponentHalf(int a, int b) {
- return Clip255(a + (a - b) / 2);
-}
-
-static WEBP_INLINE uint32_t ClampedAddSubtractHalf(uint32_t c0, uint32_t c1,
- uint32_t c2) {
- const uint32_t ave = Average2(c0, c1);
- const int a = AddSubtractComponentHalf(ave >> 24, c2 >> 24);
- const int r = AddSubtractComponentHalf((ave >> 16) & 0xff, (c2 >> 16) & 0xff);
- const int g = AddSubtractComponentHalf((ave >> 8) & 0xff, (c2 >> 8) & 0xff);
- const int b = AddSubtractComponentHalf((ave >> 0) & 0xff, (c2 >> 0) & 0xff);
- return ((uint32_t)a << 24) | (r << 16) | (g << 8) | b;
-}
-
-// gcc-4.9 on ARM generates incorrect code in Select() when Sub3() is inlined.
-#if defined(__arm__) && \
- (LOCAL_GCC_VERSION == 0x409 || LOCAL_GCC_VERSION == 0x408)
-# define LOCAL_INLINE __attribute__ ((noinline))
-#else
-# define LOCAL_INLINE WEBP_INLINE
-#endif
-
-static LOCAL_INLINE int Sub3(int a, int b, int c) {
- const int pb = b - c;
- const int pa = a - c;
- return abs(pb) - abs(pa);
-}
-
-#undef LOCAL_INLINE
-
-static WEBP_INLINE uint32_t Select(uint32_t a, uint32_t b, uint32_t c) {
- const int pa_minus_pb =
- Sub3((a >> 24) , (b >> 24) , (c >> 24) ) +
- Sub3((a >> 16) & 0xff, (b >> 16) & 0xff, (c >> 16) & 0xff) +
- Sub3((a >> 8) & 0xff, (b >> 8) & 0xff, (c >> 8) & 0xff) +
- Sub3((a ) & 0xff, (b ) & 0xff, (c ) & 0xff);
- return (pa_minus_pb <= 0) ? a : b;
-}
-
-//------------------------------------------------------------------------------
-// Predictors
-
-static uint32_t Predictor2(uint32_t left, const uint32_t* const top) {
- (void)left;
- return top[0];
-}
-static uint32_t Predictor3(uint32_t left, const uint32_t* const top) {
- (void)left;
- return top[1];
-}
-static uint32_t Predictor4(uint32_t left, const uint32_t* const top) {
- (void)left;
- return top[-1];
-}
-static uint32_t Predictor5(uint32_t left, const uint32_t* const top) {
- const uint32_t pred = Average3(left, top[0], top[1]);
- return pred;
-}
-static uint32_t Predictor6(uint32_t left, const uint32_t* const top) {
- const uint32_t pred = Average2(left, top[-1]);
- return pred;
-}
-static uint32_t Predictor7(uint32_t left, const uint32_t* const top) {
- const uint32_t pred = Average2(left, top[0]);
- return pred;
-}
-static uint32_t Predictor8(uint32_t left, const uint32_t* const top) {
- const uint32_t pred = Average2(top[-1], top[0]);
- (void)left;
- return pred;
-}
-static uint32_t Predictor9(uint32_t left, const uint32_t* const top) {
- const uint32_t pred = Average2(top[0], top[1]);
- (void)left;
- return pred;
-}
-static uint32_t Predictor10(uint32_t left, const uint32_t* const top) {
- const uint32_t pred = Average4(left, top[-1], top[0], top[1]);
- return pred;
-}
-static uint32_t Predictor11(uint32_t left, const uint32_t* const top) {
- const uint32_t pred = Select(top[0], left, top[-1]);
- return pred;
-}
-static uint32_t Predictor12(uint32_t left, const uint32_t* const top) {
- const uint32_t pred = ClampedAddSubtractFull(left, top[0], top[-1]);
- return pred;
-}
-static uint32_t Predictor13(uint32_t left, const uint32_t* const top) {
- const uint32_t pred = ClampedAddSubtractHalf(left, top[0], top[-1]);
- return pred;
-}
-
-//------------------------------------------------------------------------------
-
static void PredictorSub0_C(const uint32_t* in, const uint32_t* upper,
int num_pixels, uint32_t* out) {
int i;
@@ -850,18 +716,33 @@ static void PredictorSub1_C(const uint32_t* in, const uint32_t* upper,
(void)upper;
}
-GENERATE_PREDICTOR_SUB(Predictor2, PredictorSub2_C)
-GENERATE_PREDICTOR_SUB(Predictor3, PredictorSub3_C)
-GENERATE_PREDICTOR_SUB(Predictor4, PredictorSub4_C)
-GENERATE_PREDICTOR_SUB(Predictor5, PredictorSub5_C)
-GENERATE_PREDICTOR_SUB(Predictor6, PredictorSub6_C)
-GENERATE_PREDICTOR_SUB(Predictor7, PredictorSub7_C)
-GENERATE_PREDICTOR_SUB(Predictor8, PredictorSub8_C)
-GENERATE_PREDICTOR_SUB(Predictor9, PredictorSub9_C)
-GENERATE_PREDICTOR_SUB(Predictor10, PredictorSub10_C)
-GENERATE_PREDICTOR_SUB(Predictor11, PredictorSub11_C)
-GENERATE_PREDICTOR_SUB(Predictor12, PredictorSub12_C)
-GENERATE_PREDICTOR_SUB(Predictor13, PredictorSub13_C)
+// It subtracts the prediction from the input pixel and stores the residual
+// in the output pixel.
+#define GENERATE_PREDICTOR_SUB(PREDICTOR_I) \
+static void PredictorSub##PREDICTOR_I##_C(const uint32_t* in, \
+ const uint32_t* upper, \
+ int num_pixels, uint32_t* out) { \
+ int x; \
+ assert(upper != NULL); \
+ for (x = 0; x < num_pixels; ++x) { \
+ const uint32_t pred = \
+ VP8LPredictor##PREDICTOR_I##_C(in[x - 1], upper + x); \
+ out[x] = VP8LSubPixels(in[x], pred); \
+ } \
+}
+
+GENERATE_PREDICTOR_SUB(2)
+GENERATE_PREDICTOR_SUB(3)
+GENERATE_PREDICTOR_SUB(4)
+GENERATE_PREDICTOR_SUB(5)
+GENERATE_PREDICTOR_SUB(6)
+GENERATE_PREDICTOR_SUB(7)
+GENERATE_PREDICTOR_SUB(8)
+GENERATE_PREDICTOR_SUB(9)
+GENERATE_PREDICTOR_SUB(10)
+GENERATE_PREDICTOR_SUB(11)
+GENERATE_PREDICTOR_SUB(12)
+GENERATE_PREDICTOR_SUB(13)
//------------------------------------------------------------------------------
diff --git a/src/3rdparty/libwebp/src/dsp/lossless_enc_sse2.c b/src/3rdparty/libwebp/src/dsp/lossless_enc_sse2.c
index e676f6f..90c2637 100644
--- a/src/3rdparty/libwebp/src/dsp/lossless_enc_sse2.c
+++ b/src/3rdparty/libwebp/src/dsp/lossless_enc_sse2.c
@@ -249,6 +249,7 @@ static void AddVectorEq_SSE2(const uint32_t* a, uint32_t* out, int size) {
} \
} while (0)
+#if !(defined(__i386__) || defined(_M_IX86))
static float CombinedShannonEntropy_SSE2(const int X[256], const int Y[256]) {
int i;
double retval = 0.;
@@ -300,6 +301,8 @@ static float CombinedShannonEntropy_SSE2(const int X[256], const int Y[256]) {
retval += VP8LFastSLog2(sumX) + VP8LFastSLog2(sumXY);
return (float)retval;
}
+#endif // !(defined(__i386__) || defined(_M_IX86))
+
#undef ANALYZE_X_OR_Y
#undef ANALYZE_XY
@@ -460,20 +463,22 @@ static void PredictorSub0_SSE2(const uint32_t* in, const uint32_t* upper,
(void)upper;
}
-#define GENERATE_PREDICTOR_1(X, IN) \
-static void PredictorSub##X##_SSE2(const uint32_t* in, const uint32_t* upper, \
- int num_pixels, uint32_t* out) { \
- int i; \
- for (i = 0; i + 4 <= num_pixels; i += 4) { \
- const __m128i src = _mm_loadu_si128((const __m128i*)&in[i]); \
- const __m128i pred = _mm_loadu_si128((const __m128i*)&(IN)); \
- const __m128i res = _mm_sub_epi8(src, pred); \
- _mm_storeu_si128((__m128i*)&out[i], res); \
- } \
- if (i != num_pixels) { \
- VP8LPredictorsSub_C[(X)](in + i, upper + i, num_pixels - i, out + i); \
- } \
-}
+#define GENERATE_PREDICTOR_1(X, IN) \
+ static void PredictorSub##X##_SSE2(const uint32_t* const in, \
+ const uint32_t* const upper, \
+ int num_pixels, uint32_t* const out) { \
+ int i; \
+ for (i = 0; i + 4 <= num_pixels; i += 4) { \
+ const __m128i src = _mm_loadu_si128((const __m128i*)&in[i]); \
+ const __m128i pred = _mm_loadu_si128((const __m128i*)&(IN)); \
+ const __m128i res = _mm_sub_epi8(src, pred); \
+ _mm_storeu_si128((__m128i*)&out[i], res); \
+ } \
+ if (i != num_pixels) { \
+ VP8LPredictorsSub_C[(X)](in + i, WEBP_OFFSET_PTR(upper, i), \
+ num_pixels - i, out + i); \
+ } \
+ }
GENERATE_PREDICTOR_1(1, in[i - 1]) // Predictor1: L
GENERATE_PREDICTOR_1(2, upper[i]) // Predictor2: T
@@ -657,7 +662,12 @@ WEBP_TSAN_IGNORE_FUNCTION void VP8LEncDspInitSSE2(void) {
VP8LCollectColorRedTransforms = CollectColorRedTransforms_SSE2;
VP8LAddVector = AddVector_SSE2;
VP8LAddVectorEq = AddVectorEq_SSE2;
+ // TODO(https://crbug.com/webp/499): this function produces different results
+ // from the C code due to use of double/float resulting in output differences
+ // when compared to -noasm.
+#if !(defined(__i386__) || defined(_M_IX86))
VP8LCombinedShannonEntropy = CombinedShannonEntropy_SSE2;
+#endif
VP8LVectorMismatch = VectorMismatch_SSE2;
VP8LBundleColorMap = BundleColorMap_SSE2;
diff --git a/src/3rdparty/libwebp/src/enc/analysis_enc.c b/src/3rdparty/libwebp/src/enc/analysis_enc.c
index 687757a..ebb7842 100644
--- a/src/3rdparty/libwebp/src/enc/analysis_enc.c
+++ b/src/3rdparty/libwebp/src/enc/analysis_enc.c
@@ -126,16 +126,6 @@ static void InitHistogram(VP8Histogram* const histo) {
histo->last_non_zero = 1;
}
-static void MergeHistograms(const VP8Histogram* const in,
- VP8Histogram* const out) {
- if (in->max_value > out->max_value) {
- out->max_value = in->max_value;
- }
- if (in->last_non_zero > out->last_non_zero) {
- out->last_non_zero = in->last_non_zero;
- }
-}
-
//------------------------------------------------------------------------------
// Simplified k-Means, to assign Nb segments based on alpha-histogram
@@ -285,49 +275,6 @@ static int FastMBAnalyze(VP8EncIterator* const it) {
return 0;
}
-static int MBAnalyzeBestIntra4Mode(VP8EncIterator* const it,
- int best_alpha) {
- uint8_t modes[16];
- const int max_mode = MAX_INTRA4_MODE;
- int i4_alpha;
- VP8Histogram total_histo;
- int cur_histo = 0;
- InitHistogram(&total_histo);
-
- VP8IteratorStartI4(it);
- do {
- int mode;
- int best_mode_alpha = DEFAULT_ALPHA;
- VP8Histogram histos[2];
- const uint8_t* const src = it->yuv_in_ + Y_OFF_ENC + VP8Scan[it->i4_];
-
- VP8MakeIntra4Preds(it);
- for (mode = 0; mode < max_mode; ++mode) {
- int alpha;
-
- InitHistogram(&histos[cur_histo]);
- VP8CollectHistogram(src, it->yuv_p_ + VP8I4ModeOffsets[mode],
- 0, 1, &histos[cur_histo]);
- alpha = GetAlpha(&histos[cur_histo]);
- if (IS_BETTER_ALPHA(alpha, best_mode_alpha)) {
- best_mode_alpha = alpha;
- modes[it->i4_] = mode;
- cur_histo ^= 1; // keep track of best histo so far.
- }
- }
- // accumulate best histogram
- MergeHistograms(&histos[cur_histo ^ 1], &total_histo);
- // Note: we reuse the original samples for predictors
- } while (VP8IteratorRotateI4(it, it->yuv_in_ + Y_OFF_ENC));
-
- i4_alpha = GetAlpha(&total_histo);
- if (IS_BETTER_ALPHA(i4_alpha, best_alpha)) {
- VP8SetIntra4Mode(it, modes);
- best_alpha = i4_alpha;
- }
- return best_alpha;
-}
-
static int MBAnalyzeBestUVMode(VP8EncIterator* const it) {
int best_alpha = DEFAULT_ALPHA;
int smallest_alpha = 0;
@@ -371,13 +318,6 @@ static void MBAnalyze(VP8EncIterator* const it,
best_alpha = FastMBAnalyze(it);
} else {
best_alpha = MBAnalyzeBestIntra16Mode(it);
- if (enc->method_ >= 5) {
- // We go and make a fast decision for intra4/intra16.
- // It's usually not a good and definitive pick, but helps seeding the
- // stats about level bit-cost.
- // TODO(skal): improve criterion.
- best_alpha = MBAnalyzeBestIntra4Mode(it, best_alpha);
- }
}
best_uv_alpha = MBAnalyzeBestUVMode(it);
diff --git a/src/3rdparty/libwebp/src/enc/backward_references_enc.c b/src/3rdparty/libwebp/src/enc/backward_references_enc.c
index d445b40..519b36a 100644
--- a/src/3rdparty/libwebp/src/enc/backward_references_enc.c
+++ b/src/3rdparty/libwebp/src/enc/backward_references_enc.c
@@ -11,13 +11,14 @@
//
#include <assert.h>
+#include <float.h>
#include <math.h>
-#include "src/enc/backward_references_enc.h"
-#include "src/enc/histogram_enc.h"
+#include "src/dsp/dsp.h"
#include "src/dsp/lossless.h"
#include "src/dsp/lossless_common.h"
-#include "src/dsp/dsp.h"
+#include "src/enc/backward_references_enc.h"
+#include "src/enc/histogram_enc.h"
#include "src/utils/color_cache_utils.h"
#include "src/utils/utils.h"
@@ -103,6 +104,20 @@ void VP8LBackwardRefsClear(VP8LBackwardRefs* const refs) {
}
}
+// Swaps the content of two VP8LBackwardRefs.
+static void BackwardRefsSwap(VP8LBackwardRefs* const refs1,
+ VP8LBackwardRefs* const refs2) {
+ const int point_to_refs1 =
+ (refs1->tail_ != NULL && refs1->tail_ == &refs1->refs_);
+ const int point_to_refs2 =
+ (refs2->tail_ != NULL && refs2->tail_ == &refs2->refs_);
+ const VP8LBackwardRefs tmp = *refs1;
+ *refs1 = *refs2;
+ *refs2 = tmp;
+ if (point_to_refs2) refs1->tail_ = &refs1->refs_;
+ if (point_to_refs1) refs2->tail_ = &refs2->refs_;
+}
+
void VP8LBackwardRefsInit(VP8LBackwardRefs* const refs, int block_size) {
assert(refs != NULL);
memset(refs, 0, sizeof(*refs));
@@ -154,6 +169,22 @@ static PixOrCopyBlock* BackwardRefsNewBlock(VP8LBackwardRefs* const refs) {
return b;
}
+// Return 1 on success, 0 on error.
+static int BackwardRefsClone(const VP8LBackwardRefs* const from,
+ VP8LBackwardRefs* const to) {
+ const PixOrCopyBlock* block_from = from->refs_;
+ VP8LClearBackwardRefs(to);
+ while (block_from != NULL) {
+ PixOrCopyBlock* const block_to = BackwardRefsNewBlock(to);
+ if (block_to == NULL) return 0;
+ memcpy(block_to->start_, block_from->start_,
+ block_from->size_ * sizeof(PixOrCopy));
+ block_to->size_ = block_from->size_;
+ block_from = block_from->next_;
+ }
+ return 1;
+}
+
extern void VP8LBackwardRefsCursorAdd(VP8LBackwardRefs* const refs,
const PixOrCopy v);
void VP8LBackwardRefsCursorAdd(VP8LBackwardRefs* const refs,
@@ -753,12 +784,18 @@ static int CalculateBestCacheSize(const uint32_t* argb, int quality,
}
}
} else {
+ int code, extra_bits, extra_bits_value;
// We should compute the contribution of the (distance,length)
// histograms but those are the same independently from the cache size.
// As those constant contributions are in the end added to the other
- // histogram contributions, we can safely ignore them.
+ // histogram contributions, we can ignore them, except for the length
+ // prefix that is part of the literal_ histogram.
int len = PixOrCopyLength(v);
uint32_t argb_prev = *argb ^ 0xffffffffu;
+ VP8LPrefixEncode(len, &code, &extra_bits, &extra_bits_value);
+ for (i = 0; i <= cache_bits_max; ++i) {
+ ++histos[i]->literal_[NUM_LITERAL_CODES + code];
+ }
// Update the color caches.
do {
if (*argb != argb_prev) {
@@ -842,16 +879,21 @@ extern int VP8LBackwardReferencesTraceBackwards(
int xsize, int ysize, const uint32_t* const argb, int cache_bits,
const VP8LHashChain* const hash_chain,
const VP8LBackwardRefs* const refs_src, VP8LBackwardRefs* const refs_dst);
-static VP8LBackwardRefs* GetBackwardReferences(
- int width, int height, const uint32_t* const argb, int quality,
- int lz77_types_to_try, int* const cache_bits,
- const VP8LHashChain* const hash_chain, VP8LBackwardRefs* best,
- VP8LBackwardRefs* worst) {
- const int cache_bits_initial = *cache_bits;
- double bit_cost_best = -1;
+static int GetBackwardReferences(int width, int height,
+ const uint32_t* const argb, int quality,
+ int lz77_types_to_try, int cache_bits_max,
+ int do_no_cache,
+ const VP8LHashChain* const hash_chain,
+ VP8LBackwardRefs* const refs,
+ int* const cache_bits_best) {
VP8LHistogram* histo = NULL;
- int lz77_type, lz77_type_best = 0;
+ int i, lz77_type;
+ // Index 0 is for a color cache, index 1 for no cache (if needed).
+ int lz77_types_best[2] = {0, 0};
+ double bit_costs_best[2] = {DBL_MAX, DBL_MAX};
VP8LHashChain hash_chain_box;
+ VP8LBackwardRefs* const refs_tmp = &refs[do_no_cache ? 2 : 1];
+ int status = 0;
memset(&hash_chain_box, 0, sizeof(hash_chain_box));
histo = VP8LAllocateHistogram(MAX_COLOR_CACHE_BITS);
@@ -860,86 +902,129 @@ static VP8LBackwardRefs* GetBackwardReferences(
for (lz77_type = 1; lz77_types_to_try;
lz77_types_to_try &= ~lz77_type, lz77_type <<= 1) {
int res = 0;
- double bit_cost;
- int cache_bits_tmp = cache_bits_initial;
+ double bit_cost = 0.;
if ((lz77_types_to_try & lz77_type) == 0) continue;
switch (lz77_type) {
case kLZ77RLE:
- res = BackwardReferencesRle(width, height, argb, 0, worst);
+ res = BackwardReferencesRle(width, height, argb, 0, refs_tmp);
break;
case kLZ77Standard:
// Compute LZ77 with no cache (0 bits), as the ideal LZ77 with a color
// cache is not that different in practice.
- res = BackwardReferencesLz77(width, height, argb, 0, hash_chain, worst);
+ res = BackwardReferencesLz77(width, height, argb, 0, hash_chain,
+ refs_tmp);
break;
case kLZ77Box:
if (!VP8LHashChainInit(&hash_chain_box, width * height)) goto Error;
res = BackwardReferencesLz77Box(width, height, argb, 0, hash_chain,
- &hash_chain_box, worst);
+ &hash_chain_box, refs_tmp);
break;
default:
assert(0);
}
if (!res) goto Error;
- // Next, try with a color cache and update the references.
- if (!CalculateBestCacheSize(argb, quality, worst, &cache_bits_tmp)) {
- goto Error;
- }
- if (cache_bits_tmp > 0) {
- if (!BackwardRefsWithLocalCache(argb, cache_bits_tmp, worst)) {
- goto Error;
+ // Start with the no color cache case.
+ for (i = 1; i >= 0; --i) {
+ int cache_bits = (i == 1) ? 0 : cache_bits_max;
+
+ if (i == 1 && !do_no_cache) continue;
+
+ if (i == 0) {
+ // Try with a color cache.
+ if (!CalculateBestCacheSize(argb, quality, refs_tmp, &cache_bits)) {
+ goto Error;
+ }
+ if (cache_bits > 0) {
+ if (!BackwardRefsWithLocalCache(argb, cache_bits, refs_tmp)) {
+ goto Error;
+ }
+ }
}
- }
- // Keep the best backward references.
- VP8LHistogramCreate(histo, worst, cache_bits_tmp);
- bit_cost = VP8LHistogramEstimateBits(histo);
- if (lz77_type_best == 0 || bit_cost < bit_cost_best) {
- VP8LBackwardRefs* const tmp = worst;
- worst = best;
- best = tmp;
- bit_cost_best = bit_cost;
- *cache_bits = cache_bits_tmp;
- lz77_type_best = lz77_type;
+ if (i == 0 && do_no_cache && cache_bits == 0) {
+ // No need to re-compute bit_cost as it was computed at i == 1.
+ } else {
+ VP8LHistogramCreate(histo, refs_tmp, cache_bits);
+ bit_cost = VP8LHistogramEstimateBits(histo);
+ }
+
+ if (bit_cost < bit_costs_best[i]) {
+ if (i == 1) {
+ // Do not swap as the full cache analysis would have the wrong
+ // VP8LBackwardRefs to start with.
+ if (!BackwardRefsClone(refs_tmp, &refs[1])) goto Error;
+ } else {
+ BackwardRefsSwap(refs_tmp, &refs[0]);
+ }
+ bit_costs_best[i] = bit_cost;
+ lz77_types_best[i] = lz77_type;
+ if (i == 0) *cache_bits_best = cache_bits;
+ }
}
}
- assert(lz77_type_best > 0);
+ assert(lz77_types_best[0] > 0);
+ assert(!do_no_cache || lz77_types_best[1] > 0);
// Improve on simple LZ77 but only for high quality (TraceBackwards is
// costly).
- if ((lz77_type_best == kLZ77Standard || lz77_type_best == kLZ77Box) &&
- quality >= 25) {
- const VP8LHashChain* const hash_chain_tmp =
- (lz77_type_best == kLZ77Standard) ? hash_chain : &hash_chain_box;
- if (VP8LBackwardReferencesTraceBackwards(width, height, argb, *cache_bits,
- hash_chain_tmp, best, worst)) {
- double bit_cost_trace;
- VP8LHistogramCreate(histo, worst, *cache_bits);
- bit_cost_trace = VP8LHistogramEstimateBits(histo);
- if (bit_cost_trace < bit_cost_best) best = worst;
+ for (i = 1; i >= 0; --i) {
+ if (i == 1 && !do_no_cache) continue;
+ if ((lz77_types_best[i] == kLZ77Standard ||
+ lz77_types_best[i] == kLZ77Box) &&
+ quality >= 25) {
+ const VP8LHashChain* const hash_chain_tmp =
+ (lz77_types_best[i] == kLZ77Standard) ? hash_chain : &hash_chain_box;
+ const int cache_bits = (i == 1) ? 0 : *cache_bits_best;
+ if (VP8LBackwardReferencesTraceBackwards(width, height, argb, cache_bits,
+ hash_chain_tmp, &refs[i],
+ refs_tmp)) {
+ double bit_cost_trace;
+ VP8LHistogramCreate(histo, refs_tmp, cache_bits);
+ bit_cost_trace = VP8LHistogramEstimateBits(histo);
+ if (bit_cost_trace < bit_costs_best[i]) {
+ BackwardRefsSwap(refs_tmp, &refs[i]);
+ }
+ }
}
- }
- BackwardReferences2DLocality(width, best);
+ BackwardReferences2DLocality(width, &refs[i]);
+
+ if (i == 1 && lz77_types_best[0] == lz77_types_best[1] &&
+ *cache_bits_best == 0) {
+ // If the best cache size is 0 and we have the same best LZ77, just copy
+ // the data over and stop here.
+ if (!BackwardRefsClone(&refs[1], &refs[0])) goto Error;
+ break;
+ }
+ }
+ status = 1;
Error:
VP8LHashChainClear(&hash_chain_box);
VP8LFreeHistogram(histo);
- return best;
+ return status;
}
-VP8LBackwardRefs* VP8LGetBackwardReferences(
+WebPEncodingError VP8LGetBackwardReferences(
int width, int height, const uint32_t* const argb, int quality,
- int low_effort, int lz77_types_to_try, int* const cache_bits,
- const VP8LHashChain* const hash_chain, VP8LBackwardRefs* const refs_tmp1,
- VP8LBackwardRefs* const refs_tmp2) {
+ int low_effort, int lz77_types_to_try, int cache_bits_max, int do_no_cache,
+ const VP8LHashChain* const hash_chain, VP8LBackwardRefs* const refs,
+ int* const cache_bits_best) {
if (low_effort) {
- return GetBackwardReferencesLowEffort(width, height, argb, cache_bits,
- hash_chain, refs_tmp1);
+ VP8LBackwardRefs* refs_best;
+ *cache_bits_best = cache_bits_max;
+ refs_best = GetBackwardReferencesLowEffort(
+ width, height, argb, cache_bits_best, hash_chain, refs);
+ if (refs_best == NULL) return VP8_ENC_ERROR_OUT_OF_MEMORY;
+ // Set it in first position.
+ BackwardRefsSwap(refs_best, &refs[0]);
} else {
- return GetBackwardReferences(width, height, argb, quality,
- lz77_types_to_try, cache_bits, hash_chain,
- refs_tmp1, refs_tmp2);
+ if (!GetBackwardReferences(width, height, argb, quality, lz77_types_to_try,
+ cache_bits_max, do_no_cache, hash_chain, refs,
+ cache_bits_best)) {
+ return VP8_ENC_ERROR_OUT_OF_MEMORY;
+ }
}
+ return VP8_ENC_OK;
}
diff --git a/src/3rdparty/libwebp/src/enc/backward_references_enc.h b/src/3rdparty/libwebp/src/enc/backward_references_enc.h
index 103ddfd..4c0267b 100644
--- a/src/3rdparty/libwebp/src/enc/backward_references_enc.h
+++ b/src/3rdparty/libwebp/src/enc/backward_references_enc.h
@@ -16,6 +16,7 @@
#include <assert.h>
#include <stdlib.h>
#include "src/webp/types.h"
+#include "src/webp/encode.h"
#include "src/webp/format_constants.h"
#ifdef __cplusplus
@@ -218,14 +219,19 @@ enum VP8LLZ77Type {
// Evaluates best possible backward references for specified quality.
// The input cache_bits to 'VP8LGetBackwardReferences' sets the maximum cache
// bits to use (passing 0 implies disabling the local color cache).
-// The optimal cache bits is evaluated and set for the *cache_bits parameter.
-// The return value is the pointer to the best of the two backward refs viz,
-// refs[0] or refs[1].
-VP8LBackwardRefs* VP8LGetBackwardReferences(
+// The optimal cache bits is evaluated and set for the *cache_bits_best
+// parameter with the matching refs_best.
+// If do_no_cache == 0, refs is an array of 2 values and the best
+// VP8LBackwardRefs is put in the first element.
+// If do_no_cache != 0, refs is an array of 3 values and the best
+// VP8LBackwardRefs is put in the first element, the best value with no-cache in
+// the second element.
+// In both cases, the last element is used as temporary internally.
+WebPEncodingError VP8LGetBackwardReferences(
int width, int height, const uint32_t* const argb, int quality,
- int low_effort, int lz77_types_to_try, int* const cache_bits,
- const VP8LHashChain* const hash_chain, VP8LBackwardRefs* const refs_tmp1,
- VP8LBackwardRefs* const refs_tmp2);
+ int low_effort, int lz77_types_to_try, int cache_bits_max, int do_no_cache,
+ const VP8LHashChain* const hash_chain, VP8LBackwardRefs* const refs,
+ int* const cache_bits_best);
#ifdef __cplusplus
}
diff --git a/src/3rdparty/libwebp/src/enc/config_enc.c b/src/3rdparty/libwebp/src/enc/config_enc.c
index 9d48289..3518b41 100644
--- a/src/3rdparty/libwebp/src/enc/config_enc.c
+++ b/src/3rdparty/libwebp/src/enc/config_enc.c
@@ -39,6 +39,8 @@ int WebPConfigInitInternal(WebPConfig* config,
config->partitions = 0;
config->segments = 4;
config->pass = 1;
+ config->qmin = 0;
+ config->qmax = 100;
config->show_compressed = 0;
config->preprocessing = 0;
config->autofilter = 0;
@@ -106,6 +108,9 @@ int WebPValidateConfig(const WebPConfig* config) {
if (config->filter_type < 0 || config->filter_type > 1) return 0;
if (config->autofilter < 0 || config->autofilter > 1) return 0;
if (config->pass < 1 || config->pass > 10) return 0;
+ if (config->qmin < 0 || config->qmax > 100 || config->qmin > config->qmax) {
+ return 0;
+ }
if (config->show_compressed < 0 || config->show_compressed > 1) return 0;
if (config->preprocessing < 0 || config->preprocessing > 7) return 0;
if (config->partitions < 0 || config->partitions > 3) return 0;
diff --git a/src/3rdparty/libwebp/src/enc/frame_enc.c b/src/3rdparty/libwebp/src/enc/frame_enc.c
index 1aec376..af538d8 100644
--- a/src/3rdparty/libwebp/src/enc/frame_enc.c
+++ b/src/3rdparty/libwebp/src/enc/frame_enc.c
@@ -31,10 +31,15 @@
// we allow 2k of extra head-room in PARTITION0 limit.
#define PARTITION0_SIZE_LIMIT ((VP8_MAX_PARTITION0_SIZE - 2048ULL) << 11)
+static float Clamp(float v, float min, float max) {
+ return (v < min) ? min : (v > max) ? max : v;
+}
+
typedef struct { // struct for organizing convergence in either size or PSNR
int is_first;
float dq;
float q, last_q;
+ float qmin, qmax;
double value, last_value; // PSNR or size
double target;
int do_size_search;
@@ -47,7 +52,9 @@ static int InitPassStats(const VP8Encoder* const enc, PassStats* const s) {
s->is_first = 1;
s->dq = 10.f;
- s->q = s->last_q = enc->config_->quality;
+ s->qmin = 1.f * enc->config_->qmin;
+ s->qmax = 1.f * enc->config_->qmax;
+ s->q = s->last_q = Clamp(enc->config_->quality, s->qmin, s->qmax);
s->target = do_size_search ? (double)target_size
: (target_PSNR > 0.) ? target_PSNR
: 40.; // default, just in case
@@ -56,10 +63,6 @@ static int InitPassStats(const VP8Encoder* const enc, PassStats* const s) {
return do_size_search;
}
-static float Clamp(float v, float min, float max) {
- return (v < min) ? min : (v > max) ? max : v;
-}
-
static float ComputeNextQ(PassStats* const s) {
float dq;
if (s->is_first) {
@@ -75,7 +78,7 @@ static float ComputeNextQ(PassStats* const s) {
s->dq = Clamp(dq, -30.f, 30.f);
s->last_q = s->q;
s->last_value = s->value;
- s->q = Clamp(s->q + s->dq, 0.f, 100.f);
+ s->q = Clamp(s->q + s->dq, s->qmin, s->qmax);
return s->q;
}
@@ -848,9 +851,10 @@ int VP8EncTokenLoop(VP8Encoder* const enc) {
}
#if (DEBUG_SEARCH > 0)
- printf("#%2d metric:%.1lf -> %.1lf last_q=%.2lf q=%.2lf dq=%.2lf\n",
+ printf("#%2d metric:%.1lf -> %.1lf last_q=%.2lf q=%.2lf dq=%.2lf "
+ " range:[%.1f, %.1f]\n",
num_pass_left, stats.last_value, stats.value,
- stats.last_q, stats.q, stats.dq);
+ stats.last_q, stats.q, stats.dq, stats.qmin, stats.qmax);
#endif
if (enc->max_i4_header_bits_ > 0 && size_p0 > PARTITION0_SIZE_LIMIT) {
++num_pass_left;
diff --git a/src/3rdparty/libwebp/src/enc/histogram_enc.c b/src/3rdparty/libwebp/src/enc/histogram_enc.c
index a4e6bf3..edc6e4f 100644
--- a/src/3rdparty/libwebp/src/enc/histogram_enc.c
+++ b/src/3rdparty/libwebp/src/enc/histogram_enc.c
@@ -208,6 +208,7 @@ void VP8LHistogramAddSinglePixOrCopy(VP8LHistogram* const histo,
} else if (PixOrCopyIsCacheIdx(v)) {
const int literal_ix =
NUM_LITERAL_CODES + NUM_LENGTH_CODES + PixOrCopyCacheIdx(v);
+ assert(histo->palette_code_bits_ != 0);
++histo->literal_[literal_ix];
} else {
int code, extra_bits;
diff --git a/src/3rdparty/libwebp/src/enc/picture_csp_enc.c b/src/3rdparty/libwebp/src/enc/picture_csp_enc.c
index 718e014..35eede9 100644
--- a/src/3rdparty/libwebp/src/enc/picture_csp_enc.c
+++ b/src/3rdparty/libwebp/src/enc/picture_csp_enc.c
@@ -61,16 +61,14 @@ static int CheckNonOpaque(const uint8_t* alpha, int width, int height,
// Checking for the presence of non-opaque alpha.
int WebPPictureHasTransparency(const WebPPicture* picture) {
if (picture == NULL) return 0;
- if (!picture->use_argb) {
- return CheckNonOpaque(picture->a, picture->width, picture->height,
- 1, picture->a_stride);
- } else {
+ if (picture->use_argb) {
const int alpha_offset = ALPHA_OFFSET;
return CheckNonOpaque((const uint8_t*)picture->argb + alpha_offset,
picture->width, picture->height,
4, picture->argb_stride * sizeof(*picture->argb));
}
- return 0;
+ return CheckNonOpaque(picture->a, picture->width, picture->height,
+ 1, picture->a_stride);
}
//------------------------------------------------------------------------------
@@ -90,8 +88,9 @@ int WebPPictureHasTransparency(const WebPPicture* picture) {
static int kLinearToGammaTab[kGammaTabSize + 1];
static uint16_t kGammaToLinearTab[256];
static volatile int kGammaTablesOk = 0;
+static void InitGammaTables(void);
-static WEBP_TSAN_IGNORE_FUNCTION void InitGammaTables(void) {
+WEBP_DSP_INIT_FUNC(InitGammaTables) {
if (!kGammaTablesOk) {
int v;
const double scale = (double)(1 << kGammaTabFix) / kGammaScale;
@@ -181,8 +180,9 @@ static uint32_t kLinearToGammaTabS[kGammaTabSize + 2];
#define GAMMA_TO_LINEAR_BITS 14
static uint32_t kGammaToLinearTabS[MAX_Y_T + 1]; // size scales with Y_FIX
static volatile int kGammaTablesSOk = 0;
+static void InitGammaTablesS(void);
-static WEBP_TSAN_IGNORE_FUNCTION void InitGammaTablesS(void) {
+WEBP_DSP_INIT_FUNC(InitGammaTablesS) {
assert(2 * GAMMA_TO_LINEAR_BITS < 32); // we use uint32_t intermediate values
if (!kGammaTablesSOk) {
int v;
diff --git a/src/3rdparty/libwebp/src/enc/picture_tools_enc.c b/src/3rdparty/libwebp/src/enc/picture_tools_enc.c
index d0e8a49..38cb015 100644
--- a/src/3rdparty/libwebp/src/enc/picture_tools_enc.c
+++ b/src/3rdparty/libwebp/src/enc/picture_tools_enc.c
@@ -83,6 +83,19 @@ static int SmoothenBlock(const uint8_t* a_ptr, int a_stride, uint8_t* y_ptr,
return (count == 0);
}
+void WebPReplaceTransparentPixels(WebPPicture* const pic, uint32_t color) {
+ if (pic != NULL && pic->use_argb) {
+ int y = pic->height;
+ uint32_t* argb = pic->argb;
+ color &= 0xffffffu; // force alpha=0
+ WebPInitAlphaProcessing();
+ while (y-- > 0) {
+ WebPAlphaReplace(argb, pic->width, color);
+ argb += pic->argb_stride;
+ }
+ }
+}
+
void WebPCleanupTransparentArea(WebPPicture* pic) {
int x, y, w, h;
if (pic == NULL) return;
@@ -165,24 +178,6 @@ void WebPCleanupTransparentArea(WebPPicture* pic) {
#undef SIZE
#undef SIZE2
-void WebPCleanupTransparentAreaLossless(WebPPicture* const pic) {
- int x, y, w, h;
- uint32_t* argb;
- assert(pic != NULL && pic->use_argb);
- w = pic->width;
- h = pic->height;
- argb = pic->argb;
-
- for (y = 0; y < h; ++y) {
- for (x = 0; x < w; ++x) {
- if ((argb[x] & 0xff000000) == 0) {
- argb[x] = 0x00000000;
- }
- }
- argb += pic->argb_stride;
- }
-}
-
//------------------------------------------------------------------------------
// Blend color and remove transparency info
diff --git a/src/3rdparty/libwebp/src/enc/vp8i_enc.h b/src/3rdparty/libwebp/src/enc/vp8i_enc.h
index fedcaee..0e35562 100644
--- a/src/3rdparty/libwebp/src/enc/vp8i_enc.h
+++ b/src/3rdparty/libwebp/src/enc/vp8i_enc.h
@@ -31,7 +31,7 @@ extern "C" {
// version numbers
#define ENC_MAJ_VERSION 1
-#define ENC_MIN_VERSION 1
+#define ENC_MIN_VERSION 2
#define ENC_REV_VERSION 0
enum { MAX_LF_LEVELS = 64, // Maximum loop filter level
@@ -505,9 +505,9 @@ int WebPPictureAllocARGB(WebPPicture* const picture, int width, int height);
// Returns false in case of error (invalid param, out-of-memory).
int WebPPictureAllocYUVA(WebPPicture* const picture, int width, int height);
-// Clean-up the RGB samples under fully transparent area, to help lossless
-// compressibility (no guarantee, though). Assumes that pic->use_argb is true.
-void WebPCleanupTransparentAreaLossless(WebPPicture* const pic);
+// Replace samples that are fully transparent by 'color' to help compressibility
+// (no guarantee, though). Assumes pic->use_argb is true.
+void WebPReplaceTransparentPixels(WebPPicture* const pic, uint32_t color);
//------------------------------------------------------------------------------
diff --git a/src/3rdparty/libwebp/src/enc/vp8l_enc.c b/src/3rdparty/libwebp/src/enc/vp8l_enc.c
index 2efd403..0b44ebe 100644
--- a/src/3rdparty/libwebp/src/enc/vp8l_enc.c
+++ b/src/3rdparty/libwebp/src/enc/vp8l_enc.c
@@ -144,7 +144,8 @@ typedef enum {
kSubGreen = 2,
kSpatialSubGreen = 3,
kPalette = 4,
- kNumEntropyIx = 5
+ kPaletteAndSpatial = 5,
+ kNumEntropyIx = 6
} EntropyIx;
typedef enum {
@@ -354,11 +355,15 @@ static int GetTransformBits(int method, int histo_bits) {
}
// Set of parameters to be used in each iteration of the cruncher.
-#define CRUNCH_CONFIGS_LZ77_MAX 2
+#define CRUNCH_SUBCONFIGS_MAX 2
+typedef struct {
+ int lz77_;
+ int do_no_cache_;
+} CrunchSubConfig;
typedef struct {
int entropy_idx_;
- int lz77s_types_to_try_[CRUNCH_CONFIGS_LZ77_MAX];
- int lz77s_types_to_try_size_;
+ CrunchSubConfig sub_configs_[CRUNCH_SUBCONFIGS_MAX];
+ int sub_configs_size_;
} CrunchConfig;
#define CRUNCH_CONFIGS_MAX kNumEntropyIx
@@ -376,6 +381,9 @@ static int EncoderAnalyze(VP8LEncoder* const enc,
int i;
int use_palette;
int n_lz77s;
+ // If set to 0, analyze the cache with the computed cache value. If 1, also
+ // analyze with no-cache.
+ int do_no_cache = 0;
assert(pic != NULL && pic->argb != NULL);
use_palette =
@@ -402,10 +410,13 @@ static int EncoderAnalyze(VP8LEncoder* const enc,
return 0;
}
if (method == 6 && config->quality == 100) {
+ do_no_cache = 1;
// Go brute force on all transforms.
*crunch_configs_size = 0;
for (i = 0; i < kNumEntropyIx; ++i) {
- if (i != kPalette || use_palette) {
+ // We can only apply kPalette or kPaletteAndSpatial if we can indeed use
+ // a palette.
+ if ((i != kPalette && i != kPaletteAndSpatial) || use_palette) {
assert(*crunch_configs_size < CRUNCH_CONFIGS_MAX);
crunch_configs[(*crunch_configs_size)++].entropy_idx_ = i;
}
@@ -414,17 +425,28 @@ static int EncoderAnalyze(VP8LEncoder* const enc,
// Only choose the guessed best transform.
*crunch_configs_size = 1;
crunch_configs[0].entropy_idx_ = min_entropy_ix;
+ if (config->quality >= 75 && method == 5) {
+ // Test with and without color cache.
+ do_no_cache = 1;
+ // If we have a palette, also check in combination with spatial.
+ if (min_entropy_ix == kPalette) {
+ *crunch_configs_size = 2;
+ crunch_configs[1].entropy_idx_ = kPaletteAndSpatial;
+ }
+ }
}
}
// Fill in the different LZ77s.
- assert(n_lz77s <= CRUNCH_CONFIGS_LZ77_MAX);
+ assert(n_lz77s <= CRUNCH_SUBCONFIGS_MAX);
for (i = 0; i < *crunch_configs_size; ++i) {
int j;
for (j = 0; j < n_lz77s; ++j) {
- crunch_configs[i].lz77s_types_to_try_[j] =
+ assert(j < CRUNCH_SUBCONFIGS_MAX);
+ crunch_configs[i].sub_configs_[j].lz77_ =
(j == 0) ? kLZ77Standard | kLZ77RLE : kLZ77Box;
+ crunch_configs[i].sub_configs_[j].do_no_cache_ = do_no_cache;
}
- crunch_configs[i].lz77s_types_to_try_size_ = n_lz77s;
+ crunch_configs[i].sub_configs_size_ = n_lz77s;
}
return 1;
}
@@ -440,7 +462,7 @@ static int EncoderInit(VP8LEncoder* const enc) {
int i;
if (!VP8LHashChainInit(&enc->hash_chain_, pix_cnt)) return 0;
- for (i = 0; i < 3; ++i) VP8LBackwardRefsInit(&enc->refs_[i], refs_block_size);
+ for (i = 0; i < 4; ++i) VP8LBackwardRefsInit(&enc->refs_[i], refs_block_size);
return 1;
}
@@ -769,13 +791,10 @@ static WebPEncodingError StoreImageToBitMask(
}
// Special case of EncodeImageInternal() for cache-bits=0, histo_bits=31
-static WebPEncodingError EncodeImageNoHuffman(VP8LBitWriter* const bw,
- const uint32_t* const argb,
- VP8LHashChain* const hash_chain,
- VP8LBackwardRefs* const refs_tmp1,
- VP8LBackwardRefs* const refs_tmp2,
- int width, int height,
- int quality, int low_effort) {
+static WebPEncodingError EncodeImageNoHuffman(
+ VP8LBitWriter* const bw, const uint32_t* const argb,
+ VP8LHashChain* const hash_chain, VP8LBackwardRefs* const refs_array,
+ int width, int height, int quality, int low_effort) {
int i;
int max_tokens = 0;
WebPEncodingError err = VP8_ENC_OK;
@@ -798,13 +817,11 @@ static WebPEncodingError EncodeImageNoHuffman(VP8LBitWriter* const bw,
err = VP8_ENC_ERROR_OUT_OF_MEMORY;
goto Error;
}
- refs = VP8LGetBackwardReferences(width, height, argb, quality, 0,
- kLZ77Standard | kLZ77RLE, &cache_bits,
- hash_chain, refs_tmp1, refs_tmp2);
- if (refs == NULL) {
- err = VP8_ENC_ERROR_OUT_OF_MEMORY;
- goto Error;
- }
+ err = VP8LGetBackwardReferences(
+ width, height, argb, quality, /*low_effort=*/0, kLZ77Standard | kLZ77RLE,
+ cache_bits, /*do_no_cache=*/0, hash_chain, refs_array, &cache_bits);
+ if (err != VP8_ENC_OK) goto Error;
+ refs = &refs_array[0];
histogram_image = VP8LAllocateHistogramSet(1, cache_bits);
if (histogram_image == NULL) {
err = VP8_ENC_ERROR_OUT_OF_MEMORY;
@@ -860,11 +877,11 @@ static WebPEncodingError EncodeImageNoHuffman(VP8LBitWriter* const bw,
static WebPEncodingError EncodeImageInternal(
VP8LBitWriter* const bw, const uint32_t* const argb,
- VP8LHashChain* const hash_chain, VP8LBackwardRefs refs_array[3], int width,
+ VP8LHashChain* const hash_chain, VP8LBackwardRefs refs_array[4], int width,
int height, int quality, int low_effort, int use_cache,
const CrunchConfig* const config, int* cache_bits, int histogram_bits,
size_t init_byte_position, int* const hdr_size, int* const data_size) {
- WebPEncodingError err = VP8_ENC_OK;
+ WebPEncodingError err = VP8_ENC_ERROR_OUT_OF_MEMORY;
const uint32_t histogram_image_xysize =
VP8LSubSampleSize(width, histogram_bits) *
VP8LSubSampleSize(height, histogram_bits);
@@ -876,103 +893,103 @@ static WebPEncodingError EncodeImageInternal(
3ULL * CODE_LENGTH_CODES, sizeof(*huff_tree));
HuffmanTreeToken* tokens = NULL;
HuffmanTreeCode* huffman_codes = NULL;
- VP8LBackwardRefs* refs_best;
- VP8LBackwardRefs* refs_tmp;
uint16_t* const histogram_symbols =
(uint16_t*)WebPSafeMalloc(histogram_image_xysize,
sizeof(*histogram_symbols));
- int lz77s_idx;
+ int sub_configs_idx;
+ int cache_bits_init, write_histogram_image;
VP8LBitWriter bw_init = *bw, bw_best;
int hdr_size_tmp;
+ VP8LHashChain hash_chain_histogram; // histogram image hash chain
+ size_t bw_size_best = ~(size_t)0;
assert(histogram_bits >= MIN_HUFFMAN_BITS);
assert(histogram_bits <= MAX_HUFFMAN_BITS);
assert(hdr_size != NULL);
assert(data_size != NULL);
- if (histogram_symbols == NULL) {
- err = VP8_ENC_ERROR_OUT_OF_MEMORY;
+ // Make sure we can allocate the different objects.
+ memset(&hash_chain_histogram, 0, sizeof(hash_chain_histogram));
+ if (huff_tree == NULL || histogram_symbols == NULL ||
+ !VP8LHashChainInit(&hash_chain_histogram, histogram_image_xysize) ||
+ !VP8LHashChainFill(hash_chain, quality, argb, width, height,
+ low_effort)) {
goto Error;
}
-
if (use_cache) {
// If the value is different from zero, it has been set during the
// palette analysis.
- if (*cache_bits == 0) *cache_bits = MAX_COLOR_CACHE_BITS;
+ cache_bits_init = (*cache_bits == 0) ? MAX_COLOR_CACHE_BITS : *cache_bits;
} else {
- *cache_bits = 0;
+ cache_bits_init = 0;
}
- // 'best_refs' is the reference to the best backward refs and points to one
- // of refs_array[0] or refs_array[1].
- // Calculate backward references from ARGB image.
- if (huff_tree == NULL ||
- !VP8LHashChainFill(hash_chain, quality, argb, width, height,
- low_effort) ||
- !VP8LBitWriterInit(&bw_best, 0) ||
- (config->lz77s_types_to_try_size_ > 1 &&
+ // If several iterations will happen, clone into bw_best.
+ if (!VP8LBitWriterInit(&bw_best, 0) ||
+ ((config->sub_configs_size_ > 1 ||
+ config->sub_configs_[0].do_no_cache_) &&
!VP8LBitWriterClone(bw, &bw_best))) {
- err = VP8_ENC_ERROR_OUT_OF_MEMORY;
goto Error;
}
- for (lz77s_idx = 0; lz77s_idx < config->lz77s_types_to_try_size_;
- ++lz77s_idx) {
- refs_best = VP8LGetBackwardReferences(
- width, height, argb, quality, low_effort,
- config->lz77s_types_to_try_[lz77s_idx], cache_bits, hash_chain,
- &refs_array[0], &refs_array[1]);
- if (refs_best == NULL) {
- err = VP8_ENC_ERROR_OUT_OF_MEMORY;
- goto Error;
- }
- // Keep the best references aside and use the other element from the first
- // two as a temporary for later usage.
- refs_tmp = &refs_array[refs_best == &refs_array[0] ? 1 : 0];
-
- histogram_image =
- VP8LAllocateHistogramSet(histogram_image_xysize, *cache_bits);
- tmp_histo = VP8LAllocateHistogram(*cache_bits);
- if (histogram_image == NULL || tmp_histo == NULL) {
- err = VP8_ENC_ERROR_OUT_OF_MEMORY;
- goto Error;
- }
-
- // Build histogram image and symbols from backward references.
- if (!VP8LGetHistoImageSymbols(width, height, refs_best, quality, low_effort,
- histogram_bits, *cache_bits, histogram_image,
- tmp_histo, histogram_symbols)) {
- err = VP8_ENC_ERROR_OUT_OF_MEMORY;
- goto Error;
- }
- // Create Huffman bit lengths and codes for each histogram image.
- histogram_image_size = histogram_image->size;
- bit_array_size = 5 * histogram_image_size;
- huffman_codes = (HuffmanTreeCode*)WebPSafeCalloc(bit_array_size,
- sizeof(*huffman_codes));
- // Note: some histogram_image entries may point to tmp_histos[], so the
- // latter need to outlive the following call to GetHuffBitLengthsAndCodes().
- if (huffman_codes == NULL ||
- !GetHuffBitLengthsAndCodes(histogram_image, huffman_codes)) {
- err = VP8_ENC_ERROR_OUT_OF_MEMORY;
- goto Error;
- }
- // Free combined histograms.
- VP8LFreeHistogramSet(histogram_image);
- histogram_image = NULL;
-
- // Free scratch histograms.
- VP8LFreeHistogram(tmp_histo);
- tmp_histo = NULL;
+ for (sub_configs_idx = 0; sub_configs_idx < config->sub_configs_size_;
+ ++sub_configs_idx) {
+ const CrunchSubConfig* const sub_config =
+ &config->sub_configs_[sub_configs_idx];
+ int cache_bits_best, i_cache;
+ err = VP8LGetBackwardReferences(width, height, argb, quality, low_effort,
+ sub_config->lz77_, cache_bits_init,
+ sub_config->do_no_cache_, hash_chain,
+ &refs_array[0], &cache_bits_best);
+ if (err != VP8_ENC_OK) goto Error;
- // Color Cache parameters.
- if (*cache_bits > 0) {
- VP8LPutBits(bw, 1, 1);
- VP8LPutBits(bw, *cache_bits, 4);
- } else {
- VP8LPutBits(bw, 0, 1);
- }
+ for (i_cache = 0; i_cache < (sub_config->do_no_cache_ ? 2 : 1); ++i_cache) {
+ const int cache_bits_tmp = (i_cache == 0) ? cache_bits_best : 0;
+ // Speed-up: no need to study the no-cache case if it was already studied
+ // in i_cache == 0.
+ if (i_cache == 1 && cache_bits_best == 0) break;
+
+ // Reset the bit writer for this iteration.
+ VP8LBitWriterReset(&bw_init, bw);
+
+ // Build histogram image and symbols from backward references.
+ histogram_image =
+ VP8LAllocateHistogramSet(histogram_image_xysize, cache_bits_tmp);
+ tmp_histo = VP8LAllocateHistogram(cache_bits_tmp);
+ if (histogram_image == NULL || tmp_histo == NULL ||
+ !VP8LGetHistoImageSymbols(width, height, &refs_array[i_cache],
+ quality, low_effort, histogram_bits,
+ cache_bits_tmp, histogram_image, tmp_histo,
+ histogram_symbols)) {
+ goto Error;
+ }
+ // Create Huffman bit lengths and codes for each histogram image.
+ histogram_image_size = histogram_image->size;
+ bit_array_size = 5 * histogram_image_size;
+ huffman_codes = (HuffmanTreeCode*)WebPSafeCalloc(bit_array_size,
+ sizeof(*huffman_codes));
+ // Note: some histogram_image entries may point to tmp_histos[], so the
+ // latter need to outlive the following call to
+ // GetHuffBitLengthsAndCodes().
+ if (huffman_codes == NULL ||
+ !GetHuffBitLengthsAndCodes(histogram_image, huffman_codes)) {
+ goto Error;
+ }
+ // Free combined histograms.
+ VP8LFreeHistogramSet(histogram_image);
+ histogram_image = NULL;
+
+ // Free scratch histograms.
+ VP8LFreeHistogram(tmp_histo);
+ tmp_histo = NULL;
+
+ // Color Cache parameters.
+ if (cache_bits_tmp > 0) {
+ VP8LPutBits(bw, 1, 1);
+ VP8LPutBits(bw, cache_bits_tmp, 4);
+ } else {
+ VP8LPutBits(bw, 0, 1);
+ }
- // Huffman image + meta huffman.
- {
- const int write_histogram_image = (histogram_image_size > 1);
+ // Huffman image + meta huffman.
+ write_histogram_image = (histogram_image_size > 1);
VP8LPutBits(bw, write_histogram_image, 1);
if (write_histogram_image) {
uint32_t* const histogram_argb =
@@ -980,10 +997,7 @@ static WebPEncodingError EncodeImageInternal(
sizeof(*histogram_argb));
int max_index = 0;
uint32_t i;
- if (histogram_argb == NULL) {
- err = VP8_ENC_ERROR_OUT_OF_MEMORY;
- goto Error;
- }
+ if (histogram_argb == NULL) goto Error;
for (i = 0; i < histogram_image_xysize; ++i) {
const int symbol_index = histogram_symbols[i] & 0xffff;
histogram_argb[i] = (symbol_index << 8);
@@ -995,65 +1009,64 @@ static WebPEncodingError EncodeImageInternal(
VP8LPutBits(bw, histogram_bits - 2, 3);
err = EncodeImageNoHuffman(
- bw, histogram_argb, hash_chain, refs_tmp, &refs_array[2],
+ bw, histogram_argb, &hash_chain_histogram, &refs_array[2],
VP8LSubSampleSize(width, histogram_bits),
VP8LSubSampleSize(height, histogram_bits), quality, low_effort);
WebPSafeFree(histogram_argb);
if (err != VP8_ENC_OK) goto Error;
}
- }
- // Store Huffman codes.
- {
- int i;
- int max_tokens = 0;
- // Find maximum number of symbols for the huffman tree-set.
- for (i = 0; i < 5 * histogram_image_size; ++i) {
- HuffmanTreeCode* const codes = &huffman_codes[i];
- if (max_tokens < codes->num_symbols) {
- max_tokens = codes->num_symbols;
+ // Store Huffman codes.
+ {
+ int i;
+ int max_tokens = 0;
+ // Find maximum number of symbols for the huffman tree-set.
+ for (i = 0; i < 5 * histogram_image_size; ++i) {
+ HuffmanTreeCode* const codes = &huffman_codes[i];
+ if (max_tokens < codes->num_symbols) {
+ max_tokens = codes->num_symbols;
+ }
+ }
+ tokens = (HuffmanTreeToken*)WebPSafeMalloc(max_tokens, sizeof(*tokens));
+ if (tokens == NULL) goto Error;
+ for (i = 0; i < 5 * histogram_image_size; ++i) {
+ HuffmanTreeCode* const codes = &huffman_codes[i];
+ StoreHuffmanCode(bw, huff_tree, tokens, codes);
+ ClearHuffmanTreeIfOnlyOneSymbol(codes);
}
}
- tokens = (HuffmanTreeToken*)WebPSafeMalloc(max_tokens, sizeof(*tokens));
- if (tokens == NULL) {
- err = VP8_ENC_ERROR_OUT_OF_MEMORY;
- goto Error;
+ // Store actual literals.
+ hdr_size_tmp = (int)(VP8LBitWriterNumBytes(bw) - init_byte_position);
+ err = StoreImageToBitMask(bw, width, histogram_bits, &refs_array[i_cache],
+ histogram_symbols, huffman_codes);
+ if (err != VP8_ENC_OK) goto Error;
+ // Keep track of the smallest image so far.
+ if (VP8LBitWriterNumBytes(bw) < bw_size_best) {
+ bw_size_best = VP8LBitWriterNumBytes(bw);
+ *cache_bits = cache_bits_tmp;
+ *hdr_size = hdr_size_tmp;
+ *data_size =
+ (int)(VP8LBitWriterNumBytes(bw) - init_byte_position - *hdr_size);
+ VP8LBitWriterSwap(bw, &bw_best);
}
- for (i = 0; i < 5 * histogram_image_size; ++i) {
- HuffmanTreeCode* const codes = &huffman_codes[i];
- StoreHuffmanCode(bw, huff_tree, tokens, codes);
- ClearHuffmanTreeIfOnlyOneSymbol(codes);
+ WebPSafeFree(tokens);
+ tokens = NULL;
+ if (huffman_codes != NULL) {
+ WebPSafeFree(huffman_codes->codes);
+ WebPSafeFree(huffman_codes);
+ huffman_codes = NULL;
}
}
- // Store actual literals.
- hdr_size_tmp = (int)(VP8LBitWriterNumBytes(bw) - init_byte_position);
- err = StoreImageToBitMask(bw, width, histogram_bits, refs_best,
- histogram_symbols, huffman_codes);
- // Keep track of the smallest image so far.
- if (lz77s_idx == 0 ||
- VP8LBitWriterNumBytes(bw) < VP8LBitWriterNumBytes(&bw_best)) {
- *hdr_size = hdr_size_tmp;
- *data_size =
- (int)(VP8LBitWriterNumBytes(bw) - init_byte_position - *hdr_size);
- VP8LBitWriterSwap(bw, &bw_best);
- }
- // Reset the bit writer for the following iteration if any.
- if (config->lz77s_types_to_try_size_ > 1) VP8LBitWriterReset(&bw_init, bw);
- WebPSafeFree(tokens);
- tokens = NULL;
- if (huffman_codes != NULL) {
- WebPSafeFree(huffman_codes->codes);
- WebPSafeFree(huffman_codes);
- huffman_codes = NULL;
- }
}
VP8LBitWriterSwap(bw, &bw_best);
+ err = VP8_ENC_OK;
Error:
WebPSafeFree(tokens);
WebPSafeFree(huff_tree);
VP8LFreeHistogramSet(histogram_image);
VP8LFreeHistogram(tmp_histo);
+ VP8LHashChainClear(&hash_chain_histogram);
if (huffman_codes != NULL) {
WebPSafeFree(huffman_codes->codes);
WebPSafeFree(huffman_codes);
@@ -1095,8 +1108,7 @@ static WebPEncodingError ApplyPredictFilter(const VP8LEncoder* const enc,
VP8LPutBits(bw, pred_bits - 2, 3);
return EncodeImageNoHuffman(
bw, enc->transform_data_, (VP8LHashChain*)&enc->hash_chain_,
- (VP8LBackwardRefs*)&enc->refs_[0], // cast const away
- (VP8LBackwardRefs*)&enc->refs_[1], transform_width, transform_height,
+ (VP8LBackwardRefs*)&enc->refs_[0], transform_width, transform_height,
quality, low_effort);
}
@@ -1116,8 +1128,7 @@ static WebPEncodingError ApplyCrossColorFilter(const VP8LEncoder* const enc,
VP8LPutBits(bw, ccolor_transform_bits - 2, 3);
return EncodeImageNoHuffman(
bw, enc->transform_data_, (VP8LHashChain*)&enc->hash_chain_,
- (VP8LBackwardRefs*)&enc->refs_[0], // cast const away
- (VP8LBackwardRefs*)&enc->refs_[1], transform_width, transform_height,
+ (VP8LBackwardRefs*)&enc->refs_[0], transform_width, transform_height,
quality, low_effort);
}
@@ -1464,8 +1475,8 @@ static WebPEncodingError EncodePalette(VP8LBitWriter* const bw, int low_effort,
}
tmp_palette[0] = palette[0];
return EncodeImageNoHuffman(bw, tmp_palette, &enc->hash_chain_,
- &enc->refs_[0], &enc->refs_[1], palette_size, 1,
- 20 /* quality */, low_effort);
+ &enc->refs_[0], palette_size, 1, /*quality=*/20,
+ low_effort);
}
// -----------------------------------------------------------------------------
@@ -1491,7 +1502,7 @@ static void VP8LEncoderDelete(VP8LEncoder* enc) {
if (enc != NULL) {
int i;
VP8LHashChainClear(&enc->hash_chain_);
- for (i = 0; i < 3; ++i) VP8LBackwardRefsClear(&enc->refs_[i]);
+ for (i = 0; i < 4; ++i) VP8LBackwardRefsClear(&enc->refs_[i]);
ClearTransformBuffer(enc);
WebPSafeFree(enc);
}
@@ -1541,7 +1552,7 @@ static int EncodeStreamHook(void* input, void* data2) {
int data_size = 0;
int use_delta_palette = 0;
int idx;
- size_t best_size = 0;
+ size_t best_size = ~(size_t)0;
VP8LBitWriter bw_init = *bw, bw_best;
(void)data2;
@@ -1553,11 +1564,13 @@ static int EncodeStreamHook(void* input, void* data2) {
for (idx = 0; idx < num_crunch_configs; ++idx) {
const int entropy_idx = crunch_configs[idx].entropy_idx_;
- enc->use_palette_ = (entropy_idx == kPalette);
+ enc->use_palette_ =
+ (entropy_idx == kPalette) || (entropy_idx == kPaletteAndSpatial);
enc->use_subtract_green_ =
(entropy_idx == kSubGreen) || (entropy_idx == kSpatialSubGreen);
- enc->use_predict_ =
- (entropy_idx == kSpatial) || (entropy_idx == kSpatialSubGreen);
+ enc->use_predict_ = (entropy_idx == kSpatial) ||
+ (entropy_idx == kSpatialSubGreen) ||
+ (entropy_idx == kPaletteAndSpatial);
if (low_effort) {
enc->use_cross_color_ = 0;
} else {
@@ -1640,7 +1653,7 @@ static int EncodeStreamHook(void* input, void* data2) {
if (err != VP8_ENC_OK) goto Error;
// If we are better than what we already have.
- if (idx == 0 || VP8LBitWriterNumBytes(bw) < best_size) {
+ if (VP8LBitWriterNumBytes(bw) < best_size) {
best_size = VP8LBitWriterNumBytes(bw);
// Store the BitWriter.
VP8LBitWriterSwap(bw, &bw_best);
@@ -1816,7 +1829,7 @@ Error:
}
#undef CRUNCH_CONFIGS_MAX
-#undef CRUNCH_CONFIGS_LZ77_MAX
+#undef CRUNCH_SUBCONFIGS_MAX
int VP8LEncodeImage(const WebPConfig* const config,
const WebPPicture* const picture) {
diff --git a/src/3rdparty/libwebp/src/enc/vp8li_enc.h b/src/3rdparty/libwebp/src/enc/vp8li_enc.h
index d2d0fc5..94210ce 100644
--- a/src/3rdparty/libwebp/src/enc/vp8li_enc.h
+++ b/src/3rdparty/libwebp/src/enc/vp8li_enc.h
@@ -71,7 +71,7 @@ typedef struct {
uint32_t palette_[MAX_PALETTE_SIZE];
// Some 'scratch' (potentially large) objects.
- struct VP8LBackwardRefs refs_[3]; // Backward Refs array for temporaries.
+ struct VP8LBackwardRefs refs_[4]; // Backward Refs array for temporaries.
VP8LHashChain hash_chain_; // HashChain data for constructing
// backward references.
} VP8LEncoder;
diff --git a/src/3rdparty/libwebp/src/enc/webp_enc.c b/src/3rdparty/libwebp/src/enc/webp_enc.c
index 9f4b10c..ce2db2e 100644
--- a/src/3rdparty/libwebp/src/enc/webp_enc.c
+++ b/src/3rdparty/libwebp/src/enc/webp_enc.c
@@ -400,7 +400,7 @@ int WebPEncode(const WebPConfig* config, WebPPicture* pic) {
}
if (!config->exact) {
- WebPCleanupTransparentAreaLossless(pic);
+ WebPReplaceTransparentPixels(pic, 0x000000);
}
ok = VP8LEncodeImage(config, pic); // Sets pic->error in case of problem.
diff --git a/src/3rdparty/libwebp/src/mux/muxi.h b/src/3rdparty/libwebp/src/mux/muxi.h
index ad3e1bd..2289822 100644
--- a/src/3rdparty/libwebp/src/mux/muxi.h
+++ b/src/3rdparty/libwebp/src/mux/muxi.h
@@ -28,7 +28,7 @@ extern "C" {
// Defines and constants.
#define MUX_MAJ_VERSION 1
-#define MUX_MIN_VERSION 1
+#define MUX_MIN_VERSION 2
#define MUX_REV_VERSION 0
// Chunk object.
diff --git a/src/3rdparty/libwebp/src/mux/muxread.c b/src/3rdparty/libwebp/src/mux/muxread.c
index ae3b876..0101fde 100644
--- a/src/3rdparty/libwebp/src/mux/muxread.c
+++ b/src/3rdparty/libwebp/src/mux/muxread.c
@@ -155,7 +155,6 @@ static int MuxImageParse(const WebPChunk* const chunk, int copy_data,
break;
default:
goto Fail;
- break;
}
subchunk_size = ChunkDiskSize(&subchunk);
bytes += subchunk_size;
@@ -264,7 +263,6 @@ WebPMux* WebPMuxCreateInternal(const WebPData* bitstream, int copy_data,
if (!MuxImageParse(&chunk, copy_data, wpi)) goto Err;
ChunkRelease(&chunk);
goto PushImage;
- break;
default: // A non-image chunk.
if (wpi->is_partial_) goto Err; // Encountered a non-image chunk before
// getting all chunks of an image.
diff --git a/src/3rdparty/libwebp/src/utils/utils.c b/src/3rdparty/libwebp/src/utils/utils.c
index 764f752..6080e19 100644
--- a/src/3rdparty/libwebp/src/utils/utils.c
+++ b/src/3rdparty/libwebp/src/utils/utils.c
@@ -231,7 +231,7 @@ void WebPFree(void* ptr) {
void WebPCopyPlane(const uint8_t* src, int src_stride,
uint8_t* dst, int dst_stride, int width, int height) {
assert(src != NULL && dst != NULL);
- assert(src_stride >= width && dst_stride >= width);
+ assert(abs(src_stride) >= width && abs(dst_stride) >= width);
while (height-- > 0) {
memcpy(dst, src, width);
src += src_stride;
diff --git a/src/3rdparty/libwebp/src/webp/config.h b/src/3rdparty/libwebp/src/webp/config.h
index 6f5d153..29cf0e6 100644
--- a/src/3rdparty/libwebp/src/webp/config.h
+++ b/src/3rdparty/libwebp/src/webp/config.h
@@ -81,7 +81,7 @@
#define PACKAGE_NAME "libwebp"
/* Define to the full name and version of this package. */
-#define PACKAGE_STRING "libwebp 1.1.0"
+#define PACKAGE_STRING "libwebp 1.2.0"
/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "libwebp"
@@ -90,7 +90,7 @@
#define PACKAGE_URL "http://developers.google.com/speed/webp"
/* Define to the version of this package. */
-#define PACKAGE_VERSION "1.1.0"
+#define PACKAGE_VERSION "1.2.0"
/* Define to necessary symbol if this constant uses a non-standard name on
your system. */
@@ -100,7 +100,7 @@
/* #undef STDC_HEADERS */
/* Version number of package */
-#define VERSION "1.1.0"
+#define VERSION "1.2.0"
/* Enable experimental code */
/* #undef WEBP_EXPERIMENTAL_FEATURES */
diff --git a/src/3rdparty/libwebp/src/webp/decode.h b/src/3rdparty/libwebp/src/webp/decode.h
index 80dd0ef..44fcd64 100644
--- a/src/3rdparty/libwebp/src/webp/decode.h
+++ b/src/3rdparty/libwebp/src/webp/decode.h
@@ -453,7 +453,7 @@ struct WebPDecoderOptions {
int scaled_width, scaled_height; // final resolution
int use_threads; // if true, use multi-threaded decoding
int dithering_strength; // dithering strength (0=Off, 100=full)
- int flip; // flip output vertically
+ int flip; // if true, flip output vertically
int alpha_dithering_strength; // alpha dithering strength in [0..100]
uint32_t pad[5]; // padding for later use
diff --git a/src/3rdparty/libwebp/src/webp/encode.h b/src/3rdparty/libwebp/src/webp/encode.h
index 655166e..b4c599d 100644
--- a/src/3rdparty/libwebp/src/webp/encode.h
+++ b/src/3rdparty/libwebp/src/webp/encode.h
@@ -148,7 +148,8 @@ struct WebPConfig {
int use_delta_palette; // reserved for future lossless feature
int use_sharp_yuv; // if needed, use sharp (and slow) RGB->YUV conversion
- uint32_t pad[2]; // padding for later use
+ int qmin; // minimum permissible quality factor
+ int qmax; // maximum permissible quality factor
};
// Enumerate some predefined settings for WebPConfig, depending on the type
@@ -291,6 +292,11 @@ typedef enum WebPEncodingError {
#define WEBP_MAX_DIMENSION 16383
// Main exchange structure (input samples, output bytes, statistics)
+//
+// Once WebPPictureInit() has been called, it's ok to make all the INPUT fields
+// (use_argb, y/u/v, argb, ...) point to user-owned data, even if
+// WebPPictureAlloc() has been called. Depending on the value use_argb,
+// it's guaranteed that either *argb or *y/*u/*v content will be kept untouched.
struct WebPPicture {
// INPUT
//////////////
diff --git a/src/plugins/imageformats/tiff/qtiffhandler.cpp b/src/plugins/imageformats/tiff/qtiffhandler.cpp
index a41bb36..55eb216 100644
--- a/src/plugins/imageformats/tiff/qtiffhandler.cpp
+++ b/src/plugins/imageformats/tiff/qtiffhandler.cpp
@@ -453,6 +453,10 @@ bool QTiffHandler::read(QImage *image)
}
_TIFFfree(buf);
} else {
+ if (image->bytesPerLine() < TIFFScanlineSize(tiff)) {
+ d->close();
+ return false;
+ }
for (uint32 y=0; y<height; ++y) {
if (TIFFReadScanline(tiff, image->scanLine(y), y, 0) < 0) {
d->close();