From a978e75e7c613e859863454e3f1eda4f49edd164 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Fri, 11 Jan 2019 10:50:12 -0500 Subject: [PATCH 001/180] warnings: mark conditionally used parameters --- libtiff/tif_zip.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libtiff/tif_zip.c b/libtiff/tif_zip.c index b71c44e8..80f0dfe9 100644 --- a/libtiff/tif_zip.c +++ b/libtiff/tif_zip.c @@ -402,6 +402,9 @@ TIFFInitZIP(TIFF* tif, int scheme) assert( (scheme == COMPRESSION_DEFLATE) || (scheme == COMPRESSION_ADOBE_DEFLATE)); +#ifdef NDEBUG + (void)scheme; +#endif /* * Merge codec-specific tag information. From e8974423448b2bf14102f0331d687d796ae12172 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Forr=C3=B3?= Date: Wed, 12 Jun 2019 12:23:33 +0200 Subject: [PATCH 002/180] tools/tiffcp.c: fix potential division by zero MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nikola Forró --- tools/tiffcp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/tiffcp.c b/tools/tiffcp.c index 8c81aa4f..e36311de 100644 --- a/tools/tiffcp.c +++ b/tools/tiffcp.c @@ -1417,7 +1417,7 @@ DECLAREreadFunc(readSeparateTilesIntoBuffer) uint32 row; uint16 bps = 0, bytes_per_sample; - if (spp > (INT_MAX / tilew)) + if (tilew && spp > (INT_MAX / tilew)) { TIFFError(TIFFFileName(in), "Error, cannot handle that much samples per tile row (Tile Width * Samples/Pixel)"); return 0; From cad76c5b089d44dd0a0e17cc67de9da93c5655af Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 6 Oct 2019 01:47:06 +0200 Subject: [PATCH 003/180] Avoid warnings about casts between HANDLE and int in Win64 builds Add helper thandle_{from,to}_int() functions performing the casts between (64-bit, under Win64) thandle_t and (32-bit, always) int in a way that doesn't trigger compiler warnings. Also explain why suppressing these warnings is the right thing to do. Closes https://gitlab.com/libtiff/libtiff/issues/2 --- libtiff/tif_win32.c | 58 ++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/libtiff/tif_win32.c b/libtiff/tif_win32.c index 088880e7..bf5fbfb3 100644 --- a/libtiff/tif_win32.c +++ b/libtiff/tif_win32.c @@ -27,34 +27,38 @@ * Scott Wagner (wagner@itek.com), Itek Graphix, Rochester, NY USA */ -/* - CreateFileA/CreateFileW return type 'HANDLE'. - - thandle_t is declared like - - DECLARE_HANDLE(thandle_t); - - in tiffio.h. - - Windows (from winnt.h) DECLARE_HANDLE logic looks like - - #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 - - See http://bugzilla.maptools.org/show_bug.cgi?id=1941 for problems in WIN64 - builds resulting from this. Unfortunately, the proposed patch was lost. - -*/ - #include "tiffiop.h" #include +/* + 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. + + 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 + + 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. +*/ + +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) { @@ -237,7 +241,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 +286,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 +341,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 : "", mode); if(!tif) CloseHandle(fd); From f2f1289601402a7424da000632443c7202129db9 Mon Sep 17 00:00:00 2001 From: Mansour Ahmadi Date: Mon, 4 Nov 2019 14:48:13 -0500 Subject: [PATCH 004/180] adds a missing TIFFClose in rgb2ycbcr tool --- tools/rgb2ycbcr.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/rgb2ycbcr.c b/tools/rgb2ycbcr.c index cf5f956f..cb94d458 100644 --- a/tools/rgb2ycbcr.c +++ b/tools/rgb2ycbcr.c @@ -129,6 +129,7 @@ main(int argc, char* argv[]) if (!tiffcvt(in, out) || !TIFFWriteDirectory(out)) { (void) TIFFClose(out); + (void) TIFFClose(in); return (1); } } while (TIFFReadDirectory(in)); From 47656ccb3f5847b5236c7fa236a0d8928fc50ce0 Mon Sep 17 00:00:00 2001 From: Bug Checkers Date: Mon, 4 Nov 2019 21:14:38 +0000 Subject: [PATCH 005/180] adds missing checks on TIFFGetField in tiffcrop tool (fixes #170) --- tools/tiffcrop.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/tiffcrop.c b/tools/tiffcrop.c index 7b3c9e78..29c19a2f 100644 --- a/tools/tiffcrop.c +++ b/tools/tiffcrop.c @@ -1334,9 +1334,10 @@ static int writeBufferToSeparateTiles (TIFF* out, uint8* buf, uint32 imagelength if (obuf == NULL) return 1; - TIFFGetField(out, TIFFTAG_TILELENGTH, &tl); - TIFFGetField(out, TIFFTAG_TILEWIDTH, &tw); - TIFFGetField(out, TIFFTAG_BITSPERSAMPLE, &bps); + if( !TIFFGetField(out, TIFFTAG_TILELENGTH, &tl) || + !TIFFGetField(out, TIFFTAG_TILEWIDTH, &tw) || + !TIFFGetField(out, TIFFTAG_BITSPERSAMPLE, &bps) ) + return 1; if( imagewidth == 0 || (uint32)bps * (uint32)spp > TIFF_UINT32_MAX / imagewidth || From f417f056c5274c96b4176d5fbeede2cf2e2f699e Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Mon, 11 Nov 2019 23:01:03 +0100 Subject: [PATCH 006/180] test/: add missing generated .sh files --- test/ppm2tiff_pbm.sh | 1 - test/ppm2tiff_pgm.sh | 1 - test/ppm2tiff_ppm.sh | 1 - test/tiff2bw-logluv-3c-16b.sh | 7 +++++++ test/tiff2bw-lzw-single-strip.sh | 7 +++++++ test/tiff2bw-minisblack-1c-16b.sh | 7 +++++++ test/tiff2bw-minisblack-1c-8b.sh | 7 +++++++ test/tiff2bw-minisblack-2c-8b-alpha.sh | 7 +++++++ test/tiff2bw-miniswhite-1c-1b.sh | 7 +++++++ test/tiff2bw-palette-1c-1b.sh | 7 +++++++ test/tiff2bw-palette-1c-4b.sh | 7 +++++++ test/tiff2bw-quad-tile.jpg.sh | 7 +++++++ test/tiff2bw-quad-tile.jpg.t1iff.sh | 7 +++++++ test/tiff2bw-rgb-3c-16b.sh | 7 +++++++ test/tiff2rgba-lzw-single-strip.sh | 7 +++++++ test/tiff2rgba-quad-lzw-compat.sh | 7 +++++++ test/tiff2rgba-quad-tile.jpg.t1iff.sh | 7 +++++++ test/tiffcrop-R90-lzw-single-strip.sh | 7 +++++++ test/tiffcrop-R90-quad-lzw-compat.sh | 7 +++++++ test/tiffcrop-R90-quad-tile.jpg.t1iff.sh | 7 +++++++ test/tiffcrop-doubleflip-lzw-single-strip.sh | 7 +++++++ test/tiffcrop-doubleflip-quad-lzw-compat.sh | 7 +++++++ test/tiffcrop-doubleflip-quad-tile.jpg.t1iff.sh | 7 +++++++ test/tiffcrop-extract-lzw-single-strip.sh | 7 +++++++ test/tiffcrop-extract-quad-lzw-compat.sh | 7 +++++++ test/tiffcrop-extract-quad-tile.jpg.t1iff.sh | 7 +++++++ test/tiffcrop-extractz14-lzw-single-strip.sh | 7 +++++++ test/tiffcrop-extractz14-quad-lzw-compat.sh | 7 +++++++ test/tiffcrop-extractz14-quad-tile.jpg.t1iff.sh | 7 +++++++ 29 files changed, 182 insertions(+), 3 deletions(-) create mode 100755 test/tiff2bw-logluv-3c-16b.sh create mode 100755 test/tiff2bw-lzw-single-strip.sh create mode 100755 test/tiff2bw-minisblack-1c-16b.sh create mode 100755 test/tiff2bw-minisblack-1c-8b.sh create mode 100755 test/tiff2bw-minisblack-2c-8b-alpha.sh create mode 100755 test/tiff2bw-miniswhite-1c-1b.sh create mode 100755 test/tiff2bw-palette-1c-1b.sh create mode 100755 test/tiff2bw-palette-1c-4b.sh create mode 100755 test/tiff2bw-quad-tile.jpg.sh create mode 100755 test/tiff2bw-quad-tile.jpg.t1iff.sh create mode 100755 test/tiff2bw-rgb-3c-16b.sh create mode 100755 test/tiff2rgba-lzw-single-strip.sh create mode 100755 test/tiff2rgba-quad-lzw-compat.sh create mode 100755 test/tiff2rgba-quad-tile.jpg.t1iff.sh create mode 100755 test/tiffcrop-R90-lzw-single-strip.sh create mode 100755 test/tiffcrop-R90-quad-lzw-compat.sh create mode 100755 test/tiffcrop-R90-quad-tile.jpg.t1iff.sh create mode 100755 test/tiffcrop-doubleflip-lzw-single-strip.sh create mode 100755 test/tiffcrop-doubleflip-quad-lzw-compat.sh create mode 100755 test/tiffcrop-doubleflip-quad-tile.jpg.t1iff.sh create mode 100755 test/tiffcrop-extract-lzw-single-strip.sh create mode 100755 test/tiffcrop-extract-quad-lzw-compat.sh create mode 100755 test/tiffcrop-extract-quad-tile.jpg.t1iff.sh create mode 100755 test/tiffcrop-extractz14-lzw-single-strip.sh create mode 100755 test/tiffcrop-extractz14-quad-lzw-compat.sh create mode 100755 test/tiffcrop-extractz14-quad-tile.jpg.t1iff.sh diff --git a/test/ppm2tiff_pbm.sh b/test/ppm2tiff_pbm.sh index 68d9e459..fb6c3cf7 100755 --- a/test/ppm2tiff_pbm.sh +++ b/test/ppm2tiff_pbm.sh @@ -1,5 +1,4 @@ #!/bin/sh -# Generated file, master is Makefile.am . ${srcdir:-.}/common.sh infile="$IMG_MINISWHITE_1C_1B_PBM" outfile="o-ppm2tiff_pbm.tiff" diff --git a/test/ppm2tiff_pgm.sh b/test/ppm2tiff_pgm.sh index 001ec706..60352348 100755 --- a/test/ppm2tiff_pgm.sh +++ b/test/ppm2tiff_pgm.sh @@ -1,5 +1,4 @@ #!/bin/sh -# Generated file, master is Makefile.am . ${srcdir:-.}/common.sh infile="$IMG_MINISBLACK_1C_8B_PGM" outfile="o-ppm2tiff_pgm.tiff" diff --git a/test/ppm2tiff_ppm.sh b/test/ppm2tiff_ppm.sh index 8a81527b..e213a71d 100755 --- a/test/ppm2tiff_ppm.sh +++ b/test/ppm2tiff_ppm.sh @@ -1,5 +1,4 @@ #!/bin/sh -# Generated file, master is Makefile.am . ${srcdir:-.}/common.sh infile="$IMG_RGB_3C_8B_PPM" outfile="o-ppm2tiff_ppm.tiff" diff --git a/test/tiff2bw-logluv-3c-16b.sh b/test/tiff2bw-logluv-3c-16b.sh new file mode 100755 index 00000000..9a64a1af --- /dev/null +++ b/test/tiff2bw-logluv-3c-16b.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/logluv-3c-16b.tiff" +outfile="o-tiff2bw-logluv-3c-16b.tiff" +f_test_convert "$TIFF2BW" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiff2bw-lzw-single-strip.sh b/test/tiff2bw-lzw-single-strip.sh new file mode 100755 index 00000000..def92097 --- /dev/null +++ b/test/tiff2bw-lzw-single-strip.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/lzw-single-strip.tiff" +outfile="o-tiff2bw-lzw-single-strip.tiff" +f_test_convert "$TIFF2BW" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiff2bw-minisblack-1c-16b.sh b/test/tiff2bw-minisblack-1c-16b.sh new file mode 100755 index 00000000..d0dee2c8 --- /dev/null +++ b/test/tiff2bw-minisblack-1c-16b.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/minisblack-1c-16b.tiff" +outfile="o-tiff2bw-minisblack-1c-16b.tiff" +f_test_convert "$TIFF2BW" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiff2bw-minisblack-1c-8b.sh b/test/tiff2bw-minisblack-1c-8b.sh new file mode 100755 index 00000000..c3437b95 --- /dev/null +++ b/test/tiff2bw-minisblack-1c-8b.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/minisblack-1c-8b.tiff" +outfile="o-tiff2bw-minisblack-1c-8b.tiff" +f_test_convert "$TIFF2BW" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiff2bw-minisblack-2c-8b-alpha.sh b/test/tiff2bw-minisblack-2c-8b-alpha.sh new file mode 100755 index 00000000..81f7b6d6 --- /dev/null +++ b/test/tiff2bw-minisblack-2c-8b-alpha.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/minisblack-2c-8b-alpha.tiff" +outfile="o-tiff2bw-minisblack-2c-8b-alpha.tiff" +f_test_convert "$TIFF2BW" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiff2bw-miniswhite-1c-1b.sh b/test/tiff2bw-miniswhite-1c-1b.sh new file mode 100755 index 00000000..e3043c1f --- /dev/null +++ b/test/tiff2bw-miniswhite-1c-1b.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/miniswhite-1c-1b.tiff" +outfile="o-tiff2bw-miniswhite-1c-1b.tiff" +f_test_convert "$TIFF2BW" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiff2bw-palette-1c-1b.sh b/test/tiff2bw-palette-1c-1b.sh new file mode 100755 index 00000000..3862614e --- /dev/null +++ b/test/tiff2bw-palette-1c-1b.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/palette-1c-1b.tiff" +outfile="o-tiff2bw-palette-1c-1b.tiff" +f_test_convert "$TIFF2BW" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiff2bw-palette-1c-4b.sh b/test/tiff2bw-palette-1c-4b.sh new file mode 100755 index 00000000..21d8e90d --- /dev/null +++ b/test/tiff2bw-palette-1c-4b.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/palette-1c-4b.tiff" +outfile="o-tiff2bw-palette-1c-4b.tiff" +f_test_convert "$TIFF2BW" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiff2bw-quad-tile.jpg.sh b/test/tiff2bw-quad-tile.jpg.sh new file mode 100755 index 00000000..29c2f40a --- /dev/null +++ b/test/tiff2bw-quad-tile.jpg.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/quad-tile.jpg.tiff" +outfile="o-tiff2bw-quad-tile.jpg.tiff" +f_test_convert "$TIFF2BW" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiff2bw-quad-tile.jpg.t1iff.sh b/test/tiff2bw-quad-tile.jpg.t1iff.sh new file mode 100755 index 00000000..1c507b37 --- /dev/null +++ b/test/tiff2bw-quad-tile.jpg.t1iff.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/quad-tile.jpg.t1iff" +outfile="o-tiff2bw-quad-tile.jpg.t1iff.tiff" +f_test_convert "$TIFF2BW" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiff2bw-rgb-3c-16b.sh b/test/tiff2bw-rgb-3c-16b.sh new file mode 100755 index 00000000..0ba9efb1 --- /dev/null +++ b/test/tiff2bw-rgb-3c-16b.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/rgb-3c-16b.tiff" +outfile="o-tiff2bw-rgb-3c-16b.tiff" +f_test_convert "$TIFF2BW" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiff2rgba-lzw-single-strip.sh b/test/tiff2rgba-lzw-single-strip.sh new file mode 100755 index 00000000..184a28d5 --- /dev/null +++ b/test/tiff2rgba-lzw-single-strip.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/lzw-single-strip.tiff" +outfile="o-tiff2rgba-lzw-single-strip.tiff" +f_test_convert "$TIFF2RGBA" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiff2rgba-quad-lzw-compat.sh b/test/tiff2rgba-quad-lzw-compat.sh new file mode 100755 index 00000000..5ad808a5 --- /dev/null +++ b/test/tiff2rgba-quad-lzw-compat.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/quad-lzw-compat.tiff" +outfile="o-tiff2rgba-quad-lzw-compat.tiff" +f_test_convert "$TIFF2RGBA" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiff2rgba-quad-tile.jpg.t1iff.sh b/test/tiff2rgba-quad-tile.jpg.t1iff.sh new file mode 100755 index 00000000..9d553df6 --- /dev/null +++ b/test/tiff2rgba-quad-tile.jpg.t1iff.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/quad-tile.jpg.t1iff" +outfile="o-tiff2rgba-quad-tile.jpg.t1iff.tiff" +f_test_convert "$TIFF2RGBA" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiffcrop-R90-lzw-single-strip.sh b/test/tiffcrop-R90-lzw-single-strip.sh new file mode 100755 index 00000000..7b4fdbf9 --- /dev/null +++ b/test/tiffcrop-R90-lzw-single-strip.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/lzw-single-strip.tiff" +outfile="o-tiffcrop-R90-lzw-single-strip.tiff" +f_test_convert "$TIFFCROP -R90" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiffcrop-R90-quad-lzw-compat.sh b/test/tiffcrop-R90-quad-lzw-compat.sh new file mode 100755 index 00000000..1a40412e --- /dev/null +++ b/test/tiffcrop-R90-quad-lzw-compat.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/quad-lzw-compat.tiff" +outfile="o-tiffcrop-R90-quad-lzw-compat.tiff" +f_test_convert "$TIFFCROP -R90" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiffcrop-R90-quad-tile.jpg.t1iff.sh b/test/tiffcrop-R90-quad-tile.jpg.t1iff.sh new file mode 100755 index 00000000..0d2bf973 --- /dev/null +++ b/test/tiffcrop-R90-quad-tile.jpg.t1iff.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/quad-tile.jpg.t1iff" +outfile="o-tiffcrop-R90-quad-tile.jpg.t1iff.tiff" +f_test_convert "$TIFFCROP -R90" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiffcrop-doubleflip-lzw-single-strip.sh b/test/tiffcrop-doubleflip-lzw-single-strip.sh new file mode 100755 index 00000000..15351247 --- /dev/null +++ b/test/tiffcrop-doubleflip-lzw-single-strip.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/lzw-single-strip.tiff" +outfile="o-tiffcrop-doubleflip-lzw-single-strip.tiff" +f_test_convert "$TIFFCROP -F both" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiffcrop-doubleflip-quad-lzw-compat.sh b/test/tiffcrop-doubleflip-quad-lzw-compat.sh new file mode 100755 index 00000000..5c482a5d --- /dev/null +++ b/test/tiffcrop-doubleflip-quad-lzw-compat.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/quad-lzw-compat.tiff" +outfile="o-tiffcrop-doubleflip-quad-lzw-compat.tiff" +f_test_convert "$TIFFCROP -F both" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiffcrop-doubleflip-quad-tile.jpg.t1iff.sh b/test/tiffcrop-doubleflip-quad-tile.jpg.t1iff.sh new file mode 100755 index 00000000..2e097126 --- /dev/null +++ b/test/tiffcrop-doubleflip-quad-tile.jpg.t1iff.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/quad-tile.jpg.t1iff" +outfile="o-tiffcrop-doubleflip-quad-tile.jpg.t1iff.tiff" +f_test_convert "$TIFFCROP -F both" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiffcrop-extract-lzw-single-strip.sh b/test/tiffcrop-extract-lzw-single-strip.sh new file mode 100755 index 00000000..58041a23 --- /dev/null +++ b/test/tiffcrop-extract-lzw-single-strip.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/lzw-single-strip.tiff" +outfile="o-tiffcrop-extract-lzw-single-strip.tiff" +f_test_convert "$TIFFCROP -U px -E top -X 60 -Y 60" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiffcrop-extract-quad-lzw-compat.sh b/test/tiffcrop-extract-quad-lzw-compat.sh new file mode 100755 index 00000000..bade2456 --- /dev/null +++ b/test/tiffcrop-extract-quad-lzw-compat.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/quad-lzw-compat.tiff" +outfile="o-tiffcrop-extract-quad-lzw-compat.tiff" +f_test_convert "$TIFFCROP -U px -E top -X 60 -Y 60" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiffcrop-extract-quad-tile.jpg.t1iff.sh b/test/tiffcrop-extract-quad-tile.jpg.t1iff.sh new file mode 100755 index 00000000..11834416 --- /dev/null +++ b/test/tiffcrop-extract-quad-tile.jpg.t1iff.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/quad-tile.jpg.t1iff" +outfile="o-tiffcrop-extract-quad-tile.jpg.t1iff.tiff" +f_test_convert "$TIFFCROP -U px -E top -X 60 -Y 60" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiffcrop-extractz14-lzw-single-strip.sh b/test/tiffcrop-extractz14-lzw-single-strip.sh new file mode 100755 index 00000000..022ab76f --- /dev/null +++ b/test/tiffcrop-extractz14-lzw-single-strip.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/lzw-single-strip.tiff" +outfile="o-tiffcrop-extractz14-lzw-single-strip.tiff" +f_test_convert "$TIFFCROP -E left -Z1:4,2:4" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiffcrop-extractz14-quad-lzw-compat.sh b/test/tiffcrop-extractz14-quad-lzw-compat.sh new file mode 100755 index 00000000..3fe169c3 --- /dev/null +++ b/test/tiffcrop-extractz14-quad-lzw-compat.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/quad-lzw-compat.tiff" +outfile="o-tiffcrop-extractz14-quad-lzw-compat.tiff" +f_test_convert "$TIFFCROP -E left -Z1:4,2:4" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiffcrop-extractz14-quad-tile.jpg.t1iff.sh b/test/tiffcrop-extractz14-quad-tile.jpg.t1iff.sh new file mode 100755 index 00000000..5d36e7da --- /dev/null +++ b/test/tiffcrop-extractz14-quad-tile.jpg.t1iff.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/quad-tile.jpg.t1iff" +outfile="o-tiffcrop-extractz14-quad-tile.jpg.t1iff.tiff" +f_test_convert "$TIFFCROP -E left -Z1:4,2:4" $infile $outfile +f_tiffinfo_validate $outfile From 0356ea76bac908c61160d735f078437ace953bd3 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Mon, 11 Nov 2019 23:02:08 +0100 Subject: [PATCH 007/180] OJPEG: fix broken sanity check added in 4.1.0, and add two OJPEG test files --- libtiff/tif_ojpeg.c | 53 ++++++++---------- test/CMakeLists.txt | 8 ++- test/Makefile.am | 9 ++- .../ojpeg_chewey_subsamp21_multi_strip.tiff | Bin 0 -> 39752 bytes ...peg_zackthecat_subsamp22_single_strip.tiff | Bin 0 -> 8258 bytes ...f2bw-ojpeg_chewey_subsamp21_multi_strip.sh | 7 +++ ...ojpeg_zackthecat_subsamp22_single_strip.sh | 7 +++ ...rgba-ojpeg_chewey_subsamp21_multi_strip.sh | 7 +++ ...ojpeg_zackthecat_subsamp22_single_strip.sh | 7 +++ ...-R90-ojpeg_chewey_subsamp21_multi_strip.sh | 7 +++ ...ojpeg_zackthecat_subsamp22_single_strip.sh | 7 +++ ...flip-ojpeg_chewey_subsamp21_multi_strip.sh | 7 +++ ...ojpeg_zackthecat_subsamp22_single_strip.sh | 7 +++ ...ract-ojpeg_chewey_subsamp21_multi_strip.sh | 7 +++ ...ojpeg_zackthecat_subsamp22_single_strip.sh | 7 +++ ...tz14-ojpeg_chewey_subsamp21_multi_strip.sh | 7 +++ ...ojpeg_zackthecat_subsamp22_single_strip.sh | 7 +++ 17 files changed, 120 insertions(+), 34 deletions(-) create mode 100644 test/images/ojpeg_chewey_subsamp21_multi_strip.tiff create mode 100644 test/images/ojpeg_zackthecat_subsamp22_single_strip.tiff create mode 100755 test/tiff2bw-ojpeg_chewey_subsamp21_multi_strip.sh create mode 100755 test/tiff2bw-ojpeg_zackthecat_subsamp22_single_strip.sh create mode 100755 test/tiff2rgba-ojpeg_chewey_subsamp21_multi_strip.sh create mode 100755 test/tiff2rgba-ojpeg_zackthecat_subsamp22_single_strip.sh create mode 100755 test/tiffcrop-R90-ojpeg_chewey_subsamp21_multi_strip.sh create mode 100755 test/tiffcrop-R90-ojpeg_zackthecat_subsamp22_single_strip.sh create mode 100755 test/tiffcrop-doubleflip-ojpeg_chewey_subsamp21_multi_strip.sh create mode 100755 test/tiffcrop-doubleflip-ojpeg_zackthecat_subsamp22_single_strip.sh create mode 100755 test/tiffcrop-extract-ojpeg_chewey_subsamp21_multi_strip.sh create mode 100755 test/tiffcrop-extract-ojpeg_zackthecat_subsamp22_single_strip.sh create mode 100755 test/tiffcrop-extractz14-ojpeg_chewey_subsamp21_multi_strip.sh create mode 100755 test/tiffcrop-extractz14-ojpeg_zackthecat_subsamp22_single_strip.sh diff --git a/libtiff/tif_ojpeg.c b/libtiff/tif_ojpeg.c index bf0d1a2a..d6f7d97e 100644 --- a/libtiff/tif_ojpeg.c +++ b/libtiff/tif_ojpeg.c @@ -837,36 +837,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; @@ -1291,6 +1261,29 @@ 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 || + sp->libjpeg_jpeg_decompress_struct.image_height < sp->strile_length) { + TIFFErrorExt(tif->tif_clientdata,module, + "jpeg_start_decompress() returned image_width = %d " + "and image_height = %d, expected %d and %d", + sp->libjpeg_jpeg_decompress_struct.image_width, + sp->libjpeg_jpeg_decompress_struct.image_height, + sp->strile_width, + sp->strile_length); + 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/test/CMakeLists.txt b/test/CMakeLists.txt index a4216d56..c89bb824 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -105,7 +105,9 @@ set(TESTSCRIPTS tiff2rgba-palette-1c-8b.sh tiff2rgba-rgb-3c-16b.sh tiff2rgba-rgb-3c-8b.sh - tiff2rgba-quad-tile.jpg.sh) + tiff2rgba-quad-tile.jpg.sh + tiff2rgba-ojpeg_zackthecat_subsamp22_single_strip.sh + tiff2rgba-ojpeg_chewey_subsamp21_multi_strip.sh) # This list should contain all of the TIFF files in the 'images' # subdirectory which are intended to be used as input images for @@ -123,7 +125,9 @@ set(TIFFIMAGES images/rgb-3c-8b.tiff images/quad-tile.jpg.tiff images/quad-lzw-compat.tiff - images/lzw-single-strip.tiff) + images/lzw-single-strip.tiff + images/ojpeg_zackthecat_subsamp22_single_strip.tiff + images/ojpeg_chewey_subsamp21_multi_strip.tiff) set(BMPIMAGES images/palette-1c-8b.bmp diff --git a/test/Makefile.am b/test/Makefile.am index 90c2f3d1..420d7523 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -55,7 +55,10 @@ CLEANFILES = test_packbits.tif o-* if HAVE_JPEG JPEG_DEPENDENT_CHECK_PROG=raw_decode JPEG_DEPENDENT_TESTSCRIPTS=\ - tiff2rgba-quad-tile.jpg.sh + tiff2rgba-quad-tile.jpg.sh \ + tiff2rgba-ojpeg_zackthecat_subsamp22_single_strip.sh \ + tiff2rgba-ojpeg_chewey_subsamp21_multi_strip.sh + else JPEG_DEPENDENT_CHECK_PROG= JPEG_DEPENDENT_TESTSCRIPTS= @@ -171,7 +174,9 @@ TIFFIMAGES = \ images/rgb-3c-8b.tiff \ images/quad-tile.jpg.tiff \ images/quad-lzw-compat.tiff \ - images/lzw-single-strip.tiff + images/lzw-single-strip.tiff \ + images/ojpeg_zackthecat_subsamp22_single_strip.tiff \ + images/ojpeg_chewey_subsamp21_multi_strip.tiff PNMIMAGES = \ images/minisblack-1c-8b.pgm \ diff --git a/test/images/ojpeg_chewey_subsamp21_multi_strip.tiff b/test/images/ojpeg_chewey_subsamp21_multi_strip.tiff new file mode 100644 index 0000000000000000000000000000000000000000..8b04d473dc590b36aad5be1b93e16a8c00170345 GIT binary patch literal 39752 zcmce-XIN89^f$Ug0tpDAYoZAT5;`i~geFBoLhmA?hbB!#LNB5TO~4S6Py~z-q=TR+ z2w0AwKmh3=BDQFvG*MB|W54nI&-*^_hx_5)`{B;>Oy)PU*IqL#d(X_8wbmw+bpRLu z07&2$00BTE^lt)z|HXNt2GD`Km3Q+*8lJyx^4f_=ZWaIgT((G!(~xlJO0BRBCPcvy$AvZAThv9RNnqm z5&NGp|LGSb_CK=xBWf4>4<8g^@P9NS5&$Y{|I@#>H~_%@!+|0!`5%rJVFeNWzpO;C;>Ke>m0VJyyFyZ;wcF~g#V;JG?3rFfBSlWPX3cg;{VfUKSU9z-nstoeSi2-?f-}0|GMW- z*)8JbC%T{WMFH5~^C@}T=z6l>p9`Xd^-fIuga3>JCVE5vyrX)5-p2oFe*-H{GqT@2-c@3emtV<-A-gdK1cJWapI-wJkKgmZ ze*v%qHm(j9V!xjNc7Tke)D|h2%oeFFaJY=DB1TzJK|xUyrLqmPTiZZ?xArbQBQr-U zBU9pDy3XTo?f1YR{lZ$?tzXTo^F4bfZ%YrqP(Jpva*Jo$u1MO|JUhvFCY&S z+Xu=6gH!=Ac@S70^t&I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literal 0 HcmV?d00001 diff --git a/test/tiff2bw-ojpeg_chewey_subsamp21_multi_strip.sh b/test/tiff2bw-ojpeg_chewey_subsamp21_multi_strip.sh new file mode 100755 index 00000000..61a2ccf5 --- /dev/null +++ b/test/tiff2bw-ojpeg_chewey_subsamp21_multi_strip.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/ojpeg_chewey_subsamp21_multi_strip.tiff" +outfile="o-tiff2bw-ojpeg_chewey_subsamp21_multi_strip.tiff" +f_test_convert "$TIFF2BW" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiff2bw-ojpeg_zackthecat_subsamp22_single_strip.sh b/test/tiff2bw-ojpeg_zackthecat_subsamp22_single_strip.sh new file mode 100755 index 00000000..7b09ded9 --- /dev/null +++ b/test/tiff2bw-ojpeg_zackthecat_subsamp22_single_strip.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/ojpeg_zackthecat_subsamp22_single_strip.tiff" +outfile="o-tiff2bw-ojpeg_zackthecat_subsamp22_single_strip.tiff" +f_test_convert "$TIFF2BW" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiff2rgba-ojpeg_chewey_subsamp21_multi_strip.sh b/test/tiff2rgba-ojpeg_chewey_subsamp21_multi_strip.sh new file mode 100755 index 00000000..d1225c94 --- /dev/null +++ b/test/tiff2rgba-ojpeg_chewey_subsamp21_multi_strip.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/ojpeg_chewey_subsamp21_multi_strip.tiff" +outfile="o-tiff2rgba-ojpeg_chewey_subsamp21_multi_strip.tiff" +f_test_convert "$TIFF2RGBA" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiff2rgba-ojpeg_zackthecat_subsamp22_single_strip.sh b/test/tiff2rgba-ojpeg_zackthecat_subsamp22_single_strip.sh new file mode 100755 index 00000000..ca23a12d --- /dev/null +++ b/test/tiff2rgba-ojpeg_zackthecat_subsamp22_single_strip.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/ojpeg_zackthecat_subsamp22_single_strip.tiff" +outfile="o-tiff2rgba-ojpeg_zackthecat_subsamp22_single_strip.tiff" +f_test_convert "$TIFF2RGBA" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiffcrop-R90-ojpeg_chewey_subsamp21_multi_strip.sh b/test/tiffcrop-R90-ojpeg_chewey_subsamp21_multi_strip.sh new file mode 100755 index 00000000..41df587d --- /dev/null +++ b/test/tiffcrop-R90-ojpeg_chewey_subsamp21_multi_strip.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/ojpeg_chewey_subsamp21_multi_strip.tiff" +outfile="o-tiffcrop-R90-ojpeg_chewey_subsamp21_multi_strip.tiff" +f_test_convert "$TIFFCROP -R90" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiffcrop-R90-ojpeg_zackthecat_subsamp22_single_strip.sh b/test/tiffcrop-R90-ojpeg_zackthecat_subsamp22_single_strip.sh new file mode 100755 index 00000000..61f8fc41 --- /dev/null +++ b/test/tiffcrop-R90-ojpeg_zackthecat_subsamp22_single_strip.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/ojpeg_zackthecat_subsamp22_single_strip.tiff" +outfile="o-tiffcrop-R90-ojpeg_zackthecat_subsamp22_single_strip.tiff" +f_test_convert "$TIFFCROP -R90" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiffcrop-doubleflip-ojpeg_chewey_subsamp21_multi_strip.sh b/test/tiffcrop-doubleflip-ojpeg_chewey_subsamp21_multi_strip.sh new file mode 100755 index 00000000..3196ae1d --- /dev/null +++ b/test/tiffcrop-doubleflip-ojpeg_chewey_subsamp21_multi_strip.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/ojpeg_chewey_subsamp21_multi_strip.tiff" +outfile="o-tiffcrop-doubleflip-ojpeg_chewey_subsamp21_multi_strip.tiff" +f_test_convert "$TIFFCROP -F both" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiffcrop-doubleflip-ojpeg_zackthecat_subsamp22_single_strip.sh b/test/tiffcrop-doubleflip-ojpeg_zackthecat_subsamp22_single_strip.sh new file mode 100755 index 00000000..6ce71d4f --- /dev/null +++ b/test/tiffcrop-doubleflip-ojpeg_zackthecat_subsamp22_single_strip.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/ojpeg_zackthecat_subsamp22_single_strip.tiff" +outfile="o-tiffcrop-doubleflip-ojpeg_zackthecat_subsamp22_single_strip.tiff" +f_test_convert "$TIFFCROP -F both" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiffcrop-extract-ojpeg_chewey_subsamp21_multi_strip.sh b/test/tiffcrop-extract-ojpeg_chewey_subsamp21_multi_strip.sh new file mode 100755 index 00000000..bb30f9bd --- /dev/null +++ b/test/tiffcrop-extract-ojpeg_chewey_subsamp21_multi_strip.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/ojpeg_chewey_subsamp21_multi_strip.tiff" +outfile="o-tiffcrop-extract-ojpeg_chewey_subsamp21_multi_strip.tiff" +f_test_convert "$TIFFCROP -U px -E top -X 60 -Y 60" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiffcrop-extract-ojpeg_zackthecat_subsamp22_single_strip.sh b/test/tiffcrop-extract-ojpeg_zackthecat_subsamp22_single_strip.sh new file mode 100755 index 00000000..ce06a261 --- /dev/null +++ b/test/tiffcrop-extract-ojpeg_zackthecat_subsamp22_single_strip.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/ojpeg_zackthecat_subsamp22_single_strip.tiff" +outfile="o-tiffcrop-extract-ojpeg_zackthecat_subsamp22_single_strip.tiff" +f_test_convert "$TIFFCROP -U px -E top -X 60 -Y 60" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiffcrop-extractz14-ojpeg_chewey_subsamp21_multi_strip.sh b/test/tiffcrop-extractz14-ojpeg_chewey_subsamp21_multi_strip.sh new file mode 100755 index 00000000..81d66249 --- /dev/null +++ b/test/tiffcrop-extractz14-ojpeg_chewey_subsamp21_multi_strip.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/ojpeg_chewey_subsamp21_multi_strip.tiff" +outfile="o-tiffcrop-extractz14-ojpeg_chewey_subsamp21_multi_strip.tiff" +f_test_convert "$TIFFCROP -E left -Z1:4,2:4" $infile $outfile +f_tiffinfo_validate $outfile diff --git a/test/tiffcrop-extractz14-ojpeg_zackthecat_subsamp22_single_strip.sh b/test/tiffcrop-extractz14-ojpeg_zackthecat_subsamp22_single_strip.sh new file mode 100755 index 00000000..e6c3c5f3 --- /dev/null +++ b/test/tiffcrop-extractz14-ojpeg_zackthecat_subsamp22_single_strip.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Generated file, master is Makefile.am +. ${srcdir:-.}/common.sh +infile="$srcdir/images/ojpeg_zackthecat_subsamp22_single_strip.tiff" +outfile="o-tiffcrop-extractz14-ojpeg_zackthecat_subsamp22_single_strip.tiff" +f_test_convert "$TIFFCROP -E left -Z1:4,2:4" $infile $outfile +f_tiffinfo_validate $outfile From 4159bda6db2f8cf8e848d8095b5d37d49ba67a10 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Thu, 14 Nov 2019 15:07:47 +0100 Subject: [PATCH 008/180] contrib/oss-fuzz/build.sh: fix ossfuzz build by statically linking to lzma --- contrib/oss-fuzz/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/oss-fuzz/build.sh b/contrib/oss-fuzz/build.sh index fe6bd340..b65c2c27 100755 --- a/contrib/oss-fuzz/build.sh +++ b/contrib/oss-fuzz/build.sh @@ -56,7 +56,7 @@ make install $CXX $CXXFLAGS -std=c++11 -I$WORK/include \ $SRC/libtiff/contrib/oss-fuzz/tiff_read_rgba_fuzzer.cc -o $OUT/tiff_read_rgba_fuzzer \ $LIB_FUZZING_ENGINE $WORK/lib/libtiffxx.a $WORK/lib/libtiff.a $WORK/lib/libz.a $WORK/lib/libjpeg.a \ - $WORK/lib/libjbig.a $WORK/lib/libjbig85.a + $WORK/lib/libjbig.a $WORK/lib/libjbig85.a -Wl,-Bstatic -llzma -Wl,-Bdynamic mkdir afl_testcases (cd afl_testcases; tar xf "$SRC/afl_testcases.tgz") From 47b1d516d30204069e18a5db2da1060092510711 Mon Sep 17 00:00:00 2001 From: Rolf Eike Beer Date: Fri, 15 Nov 2019 10:45:47 +0100 Subject: [PATCH 009/180] CMake: simplify parsing variables from configure --- CMakeLists.txt | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 35b48770..d0285be0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,17 +43,13 @@ if (POLICY CMP0054) endif(POLICY CMP0054) # Read version information from configure.ac. -FILE(READ "${CMAKE_CURRENT_SOURCE_DIR}/configure.ac" configure) -STRING(REGEX REPLACE ";" "\\\\;" configure "${configure}") -STRING(REGEX REPLACE "\n" ";" configure "${configure}") +FILE(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/configure.ac" configure REGEX "^LIBTIFF_.*=") foreach(line ${configure}) foreach(var LIBTIFF_MAJOR_VERSION LIBTIFF_MINOR_VERSION LIBTIFF_MICRO_VERSION LIBTIFF_ALPHA_VERSION LIBTIFF_CURRENT LIBTIFF_REVISION LIBTIFF_AGE) - if(NOT ${var}) - string(REGEX MATCH "^${var}=(.*)" ${var}_MATCH "${line}") - if(${var}_MATCH) - string(REGEX REPLACE "^${var}=(.*)" "\\1" ${var} "${line}") - endif() + if(NOT ${var} AND line MATCHES "^${var}=(.*)") + set(${var} "${CMAKE_MATCH_1}") + break() endif() endforeach() endforeach() From 6927706c57d9e1778aee81f3f341e733b8a98dc1 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sun, 17 Nov 2019 12:58:30 +0100 Subject: [PATCH 010/180] contrib/oss-fuzz/build.sh: install liblzma-dev:i386 on i386 builds --- contrib/oss-fuzz/build.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/contrib/oss-fuzz/build.sh b/contrib/oss-fuzz/build.sh index b65c2c27..b0982d30 100755 --- a/contrib/oss-fuzz/build.sh +++ b/contrib/oss-fuzz/build.sh @@ -45,10 +45,16 @@ if [ "$ARCHITECTURE" = "i386" ]; then else make lib fi + mv "$SRC"/jbigkit/libjbig/*.a "$WORK/lib/" mv "$SRC"/jbigkit/libjbig/*.h "$WORK/include/" popd +if [ "$ARCHITECTURE" = "i386" ]; then + dpkg --add-architecture i386 + apt-get install -y liblzma-dev:i386 +fi + cmake . -DCMAKE_INSTALL_PREFIX=$WORK -DBUILD_SHARED_LIBS=off make -j$(nproc) make install From ad25410d09f58e44a66b2dea6625def406aad609 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Wed, 20 Nov 2019 12:04:31 +0100 Subject: [PATCH 011/180] contrib/oss-fuzz/build.sh: install liblzma-dev for x86_64 builds --- contrib/oss-fuzz/build.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/contrib/oss-fuzz/build.sh b/contrib/oss-fuzz/build.sh index b0982d30..f97bb55b 100755 --- a/contrib/oss-fuzz/build.sh +++ b/contrib/oss-fuzz/build.sh @@ -53,6 +53,8 @@ popd if [ "$ARCHITECTURE" = "i386" ]; then dpkg --add-architecture i386 apt-get install -y liblzma-dev:i386 +else + apt-get install -y liblzma-dev fi cmake . -DCMAKE_INSTALL_PREFIX=$WORK -DBUILD_SHARED_LIBS=off From b52fb8a91d325c533c7dd29d48f7c11b7dea00ee Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Thu, 28 Nov 2019 14:18:38 +0100 Subject: [PATCH 012/180] contrib/oss-fuzz/build.sh: other attempt at fixing build failure --- contrib/oss-fuzz/build.sh | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/contrib/oss-fuzz/build.sh b/contrib/oss-fuzz/build.sh index f97bb55b..b56a2c82 100755 --- a/contrib/oss-fuzz/build.sh +++ b/contrib/oss-fuzz/build.sh @@ -51,8 +51,7 @@ mv "$SRC"/jbigkit/libjbig/*.h "$WORK/include/" popd if [ "$ARCHITECTURE" = "i386" ]; then - dpkg --add-architecture i386 - apt-get install -y liblzma-dev:i386 + # Nothing else apt-get install -y liblzma-dev fi @@ -61,10 +60,17 @@ cmake . -DCMAKE_INSTALL_PREFIX=$WORK -DBUILD_SHARED_LIBS=off make -j$(nproc) make install -$CXX $CXXFLAGS -std=c++11 -I$WORK/include \ - $SRC/libtiff/contrib/oss-fuzz/tiff_read_rgba_fuzzer.cc -o $OUT/tiff_read_rgba_fuzzer \ - $LIB_FUZZING_ENGINE $WORK/lib/libtiffxx.a $WORK/lib/libtiff.a $WORK/lib/libz.a $WORK/lib/libjpeg.a \ - $WORK/lib/libjbig.a $WORK/lib/libjbig85.a -Wl,-Bstatic -llzma -Wl,-Bdynamic +if [ "$ARCHITECTURE" = "i386" ]; then + $CXX $CXXFLAGS -std=c++11 -I$WORK/include \ + $SRC/libtiff/contrib/oss-fuzz/tiff_read_rgba_fuzzer.cc -o $OUT/tiff_read_rgba_fuzzer \ + $LIB_FUZZING_ENGINE $WORK/lib/libtiffxx.a $WORK/lib/libtiff.a $WORK/lib/libz.a $WORK/lib/libjpeg.a \ + $WORK/lib/libjbig.a $WORK/lib/libjbig85.a +else + $CXX $CXXFLAGS -std=c++11 -I$WORK/include \ + $SRC/libtiff/contrib/oss-fuzz/tiff_read_rgba_fuzzer.cc -o $OUT/tiff_read_rgba_fuzzer \ + $LIB_FUZZING_ENGINE $WORK/lib/libtiffxx.a $WORK/lib/libtiff.a $WORK/lib/libz.a $WORK/lib/libjpeg.a \ + $WORK/lib/libjbig.a $WORK/lib/libjbig85.a -Wl,-Bstatic -llzma -Wl,-Bdynamic +fi mkdir afl_testcases (cd afl_testcases; tar xf "$SRC/afl_testcases.tgz") From 4f6db6a12971cea851094dca560669c61044a999 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sat, 14 Dec 2019 12:03:43 +0100 Subject: [PATCH 013/180] contrib/oss-fuzz/build.sh: fix broken if construct --- contrib/oss-fuzz/build.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/contrib/oss-fuzz/build.sh b/contrib/oss-fuzz/build.sh index b56a2c82..ab824398 100755 --- a/contrib/oss-fuzz/build.sh +++ b/contrib/oss-fuzz/build.sh @@ -50,9 +50,7 @@ mv "$SRC"/jbigkit/libjbig/*.a "$WORK/lib/" mv "$SRC"/jbigkit/libjbig/*.h "$WORK/include/" popd -if [ "$ARCHITECTURE" = "i386" ]; then - # Nothing -else +if [ "$ARCHITECTURE" != "i386" ]; then apt-get install -y liblzma-dev fi From 1fc1faa5a91df37b9f70b71a448777f61af20b96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Angel=20S=C3=A1nchez?= Date: Mon, 16 Dec 2019 13:12:20 +0100 Subject: [PATCH 014/180] fix issue #78 warnings regarding RichTIFFIPTC data type --- libtiff/tif_dirinfo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libtiff/tif_dirinfo.c b/libtiff/tif_dirinfo.c index e1f6b23e..b508040c 100644 --- a/libtiff/tif_dirinfo.c +++ b/libtiff/tif_dirinfo.c @@ -138,7 +138,7 @@ tiffFields[] = { { TIFFTAG_CFAPATTERN, 4, 4, TIFF_BYTE, 0, TIFF_SETGET_C0_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "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 }, { TIFFTAG_ICCPROFILE, -3, -3, TIFF_UNDEFINED, 0, TIFF_SETGET_C32_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "ICC Profile", NULL }, From 0a8245b7b81e4b2cf9841b81c6fcc252b8fe6162 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Tue, 7 Jan 2020 23:13:11 +0100 Subject: [PATCH 015/180] OJPEGReadHeaderInfo: if rowsperstrip not defined, then assume one-single-strip. Complementary fix to 0356ea76bac908c61160d735f078437ace953bd3 --- libtiff/tif_ojpeg.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libtiff/tif_ojpeg.c b/libtiff/tif_ojpeg.c index d6f7d97e..aa5ff5e2 100644 --- a/libtiff/tif_ojpeg.c +++ b/libtiff/tif_ojpeg.c @@ -1064,6 +1064,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) From 8192df23fa04f5e380c602790f16f4b0bb9371f3 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Tue, 7 Jan 2020 23:41:26 +0100 Subject: [PATCH 016/180] test: add test for single-strip OJPEG file without RowsPerStrip tag (like in CR2 files) --- test/CMakeLists.txt | 6 ++++-- test/Makefile.am | 6 ++++-- .../ojpeg_single_strip_no_rowsperstrip.tiff | Bin 0 -> 8258 bytes ...ff2rgba-ojpeg_single_strip_no_rowsperstrip.sh | 7 +++++++ 4 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 test/images/ojpeg_single_strip_no_rowsperstrip.tiff create mode 100755 test/tiff2rgba-ojpeg_single_strip_no_rowsperstrip.sh diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index c89bb824..23b678cf 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -107,7 +107,8 @@ set(TESTSCRIPTS tiff2rgba-rgb-3c-8b.sh tiff2rgba-quad-tile.jpg.sh tiff2rgba-ojpeg_zackthecat_subsamp22_single_strip.sh - tiff2rgba-ojpeg_chewey_subsamp21_multi_strip.sh) + tiff2rgba-ojpeg_chewey_subsamp21_multi_strip.sh + tiff2rgba-ojpeg_single_strip_no_rowsperstrip.sh) # This list should contain all of the TIFF files in the 'images' # subdirectory which are intended to be used as input images for @@ -127,7 +128,8 @@ set(TIFFIMAGES images/quad-lzw-compat.tiff images/lzw-single-strip.tiff images/ojpeg_zackthecat_subsamp22_single_strip.tiff - images/ojpeg_chewey_subsamp21_multi_strip.tiff) + images/ojpeg_chewey_subsamp21_multi_strip.tiff + images/ojpeg_single_strip_no_rowsperstrip.tiff) set(BMPIMAGES images/palette-1c-8b.bmp diff --git a/test/Makefile.am b/test/Makefile.am index 420d7523..e7d239bd 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -57,7 +57,8 @@ JPEG_DEPENDENT_CHECK_PROG=raw_decode JPEG_DEPENDENT_TESTSCRIPTS=\ tiff2rgba-quad-tile.jpg.sh \ tiff2rgba-ojpeg_zackthecat_subsamp22_single_strip.sh \ - tiff2rgba-ojpeg_chewey_subsamp21_multi_strip.sh + tiff2rgba-ojpeg_chewey_subsamp21_multi_strip.sh \ + tiff2rgba-ojpeg_single_strip_no_rowsperstrip.sh else JPEG_DEPENDENT_CHECK_PROG= @@ -176,7 +177,8 @@ TIFFIMAGES = \ images/quad-lzw-compat.tiff \ images/lzw-single-strip.tiff \ images/ojpeg_zackthecat_subsamp22_single_strip.tiff \ - images/ojpeg_chewey_subsamp21_multi_strip.tiff + images/ojpeg_chewey_subsamp21_multi_strip.tiff \ + images/ojpeg_single_strip_no_rowsperstrip.tiff PNMIMAGES = \ images/minisblack-1c-8b.pgm \ diff --git a/test/images/ojpeg_single_strip_no_rowsperstrip.tiff b/test/images/ojpeg_single_strip_no_rowsperstrip.tiff new file mode 100644 index 0000000000000000000000000000000000000000..61611b9d0ebea16cc4fd9d7c476d81046ec34d3d GIT binary patch literal 8258 zcmdscXH*nRv~CYW7KSW22}o4Q(P3slhM?pqfD%x6mcYHh9OCoj6@LuCFd*x z3P>E15{4Y^9M8FTy|vzY>)pHFzgNAg>+9OPs=nU4s(W{rrY0Z+0IX&8%L2SUvcvnF z+E;*~sD1|Jd)kCA@d$We4LC^k*`T7P_QDlCj*QD@Igt&(PoNDMl7RVK0K}hKfGOXy3*M6Uo&rR7^le*nCcE2Liy zVGtSDA0a6f_!c@xalKnR^$Ms6cc)8VNVgTzjTH}_RO^yIU7A9--@Lwl(``(UTWtrV zaLHh4174I}mzX<6*XD#fi<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ewll(dwQ$}#CTj@gH_ z2-rT0MPN>Kh{zJHGWYx^Rh0_Twr64GP9N1*&e`3^%Z(ClZ`S+bw*|&R)5UK~)Dgnf zhJxisvnT|Ib+^aI-uc0Q4X6-Suvz)lfL-UY4?KK^EwEbOAFT!#$hhM!oaCNLP(%7L zTUzeADxjV%>C0NX%aczQBO|Yl%J(mmxUX4vTjBQriY=FTEN5*P#EvpHPYqz9ie6&q z8Kr%sFV_OwrPK&^AYh9!j25P`c3{yM+$S8Yd5NF+gO|wzM?*;;`Q<9>z3KLO_H*xi zzXBTUac`ZjfIU&zDy$q4guMc|FH}rxh2x$NE@4jhvZvllWxv)rkSkYc-LX5N8kw@I zyqF2t@WQF+jr7^|t#M4`TEBAD)rEb(c*-AK@Js@|z5{r3Ssrwc)qaslOtzL&WTV5x zYV>RG1hr1pj$a~H@KKJ&2Nvd4lNizL51igrFcwjZo8s!L%g&Hl1CpcueNΜJf;z zD^`z7_H%y-Kxhk^tvuBajr=&`OVy`ZTzm!eFJ4;UO0Iwb*5I!jfQBMnSPB!HkIiQy9neQLu>!yy!>9g_4iHT z5Eb&WZg(uMlW>7;NdbKqKRoR0C6kmkG%J6LS$0(EQMMgvfZVXp>prxm;Ck8dOe5hlouA`?-34zd2)A7;M^JzRiHJ!^$;ht(1mM3#f6Vho3?cykw`2f&9KP=| zeC`1VKwttwLNE~#5#C9lKztVfAq^2XF|8PagihD$hI=TzczkX(DUXs~JA;I^$LQkk zFf#J%j7-cdynHwL1q6j8rKDwK<>Zy`sUTI=)HU=C42_IU9-7+NKC!cRcS60{7u^YR4`v Date: Sun, 12 Jan 2020 14:53:59 +0100 Subject: [PATCH 017/180] _TIFFPartialReadStripArray: bring back support for non-conformant SLONG8 data type Such as in https://github.com/OSGeo/gdal/issues/2165 --- libtiff/tif_dirread.c | 49 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/libtiff/tif_dirread.c b/libtiff/tif_dirread.c index 6f909413..be6fe24d 100644 --- a/libtiff/tif_dirread.c +++ b/libtiff/tif_dirread.c @@ -3902,11 +3902,37 @@ 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: + 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: + 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; @@ -6034,6 +6060,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 +6138,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 +6148,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 +6158,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 +6168,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; } From f5e1d765eb8835cae0a10e2d7e23d3dca3507d07 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Thu, 23 Jan 2020 20:40:53 +0100 Subject: [PATCH 018/180] Adjust previous fix to avoid undue warning in some situations triggered by GDAL --- libtiff/tif_dirread.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/libtiff/tif_dirread.c b/libtiff/tif_dirread.c index be6fe24d..59037c91 100644 --- a/libtiff/tif_dirread.c +++ b/libtiff/tif_dirread.c @@ -3909,10 +3909,17 @@ TIFFReadDirectory(TIFF* tif) case TIFF_LONG8: break; default: - fip = TIFFFieldWithTag(tif,dp->tdir_tag); - TIFFWarningExt(tif->tif_clientdata,module, - "Invalid data type for tag %s", - fip ? fip->field_name : "unknown tagname"); + /* 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), @@ -3927,10 +3934,17 @@ TIFFReadDirectory(TIFF* tif) case TIFF_LONG8: break; default: - fip = TIFFFieldWithTag(tif,dp->tdir_tag); - TIFFWarningExt(tif->tif_clientdata,module, - "Invalid data type for tag %s", - fip ? fip->field_name : "unknown tagname"); + /* 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), From 58b16f47a82323c05ec81f0a821700beb8c2c5a0 Mon Sep 17 00:00:00 2001 From: Bob Friesenhahn Date: Sat, 25 Jan 2020 14:11:05 -0600 Subject: [PATCH 019/180] 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. --- libtiff/tif_config.vc.h | 19 +++++++++++++++---- nmake.opt | 12 +++++++++++- port/Makefile.vc | 36 ++++++++++++++++++++++++++++++++++-- port/libport.h | 8 ++++---- tools/tiffset.c | 4 ++++ 5 files changed, 68 insertions(+), 11 deletions(-) diff --git a/libtiff/tif_config.vc.h b/libtiff/tif_config.vc.h index 5cebfa02..78f3b204 100644 --- a/libtiff/tif_config.vc.h +++ b/libtiff/tif_config.vc.h @@ -104,11 +104,22 @@ /* 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 +# if _MSC_VER >= 1920 /* Visual Studio 2019 has 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/nmake.opt b/nmake.opt index ae544670..d59be640 100644 --- a/nmake.opt +++ b/nmake.opt @@ -29,6 +29,7 @@ # Usage examples (see details below): # nmake -f makefile.vc # nmake -f makefile.vc DEBUG=1 +# nmake -f makefile.vc clean # # ###### Edit the following lines to choose a feature set you need. ####### @@ -108,6 +109,15 @@ CHECK_JPEG_YCBCR_SUBSAMPLING = 1 ####################### Compiler related options. ####################### # +# If your MSVC does not provide strtol() and strtoul(), then these +# should be set to 0. +HAVE_STRTOL = 1 +HAVE_STRTOUL = 1 + +# Users of MSVC 19.20 ("Visual Studio 2019") and later should set these to 1 +HAVE_STRTOLL = 0 +HAVE_STRTOULL = 0 + # # Pick debug or optimized build flags. We default to an optimized build # with no debugging information. @@ -118,7 +128,7 @@ OPTFLAGS = /MDd /EHsc /W3 /D_CRT_SECURE_NO_DEPRECATE !ELSE OPTFLAGS = /Ox /MD /EHsc /W3 /D_CRT_SECURE_NO_DEPRECATE !ENDIF -#OPTFLAGS = /Zi +#OPTFLAGS = /Zi # # Uncomment following line to enable using Windows Common RunTime Library diff --git a/port/Makefile.vc b/port/Makefile.vc index 992d2696..501f7d74 100644 --- a/port/Makefile.vc +++ b/port/Makefile.vc @@ -23,13 +23,45 @@ # Makefile for MS Visual C and Watcom C compilers. # # To build: -# C:\libtiff\port> nmake /f makefile.vc +# C:\libtiff\port> nmake /f makefile.vc !INCLUDE ..\nmake.opt +!IF $(HAVE_STRTOL) +STRTOL_OBJ = +EXTRAFLAGS = -DHAVE_STRTOL $(EXTRAFLAGS) +!ELSE +STRTOL_OBJ = strtol.obj +!ENDIF + +!IF $(HAVE_STRTOUL) +STRTOUL_OBJ = +EXTRAFLAGS = -DHAVE_STRTOUL $(EXTRAFLAGS) +!ELSE +STRTOUL_OBJ = strtoul.obj +!ENDIF + +!IF $(HAVE_STRTOLL) +STRTOLL_OBJ = +EXTRAFLAGS = -DHAVE_STRTOLL $(EXTRAFLAGS) +!ELSE +STRTOLL_OBJ = strtoll.obj +!ENDIF + +!IF $(HAVE_STRTOULL) +STRTOULL_OBJ = +EXTRAFLAGS = -DHAVE_STRTOULL $(EXTRAFLAGS) +!ELSE +STRTOULL_OBJ = strtoull.obj +!ENDIF + OBJ = \ - snprintf.obj \ + snprintf.obj \ strcasecmp.obj \ + $(STRTOL_OBJ) \ + $(STRTOUL_OBJ) \ + $(STRTOLL_OBJ) \ + $(STRTOULL_OBJ) \ getopt.obj all: libport.lib diff --git a/port/libport.h b/port/libport.h index ff262638..24e559b6 100644 --- a/port/libport.h +++ b/port/libport.h @@ -36,16 +36,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/tools/tiffset.c b/tools/tiffset.c index 7ecc401b..fdfdf3cc 100644 --- a/tools/tiffset.c +++ b/tools/tiffset.c @@ -35,6 +35,10 @@ #include "tiffio.h" +#ifdef NEED_LIBPORT +# include "libport.h" +#endif + static char* usageMsg[] = { "usage: tiffset [options] filename", "where options are:", From 550f8708d25b913333052cb5c6d3d75f1afdff39 Mon Sep 17 00:00:00 2001 From: Bob Friesenhahn Date: Sun, 26 Jan 2020 19:17:23 -0600 Subject: [PATCH 020/180] 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. --- libtiff/tif_config.vc.h | 4 +++- nmake.opt | 7 +++---- port/libport.h | 8 ++++---- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/libtiff/tif_config.vc.h b/libtiff/tif_config.vc.h index 78f3b204..939594f8 100644 --- a/libtiff/tif_config.vc.h +++ b/libtiff/tif_config.vc.h @@ -116,7 +116,9 @@ # else # define HAVE_SNPRINTF 1 # endif -# if _MSC_VER >= 1920 /* Visual Studio 2019 has strtoll/strtoull */ +# 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 diff --git a/nmake.opt b/nmake.opt index d59be640..79b2fbbb 100644 --- a/nmake.opt +++ b/nmake.opt @@ -109,12 +109,11 @@ CHECK_JPEG_YCBCR_SUBSAMPLING = 1 ####################### Compiler related options. ####################### # -# If your MSVC does not provide strtol() and strtoul(), then these -# should be set to 0. + +# Indicate if the compiler provides strtol/strtoul/strtoll/strtoull. +# Users of MSVC++ 14.0 ("Visual Studio 2015") and later should set all of these to 1 HAVE_STRTOL = 1 HAVE_STRTOUL = 1 - -# Users of MSVC 19.20 ("Visual Studio 2019") and later should set these to 1 HAVE_STRTOLL = 0 HAVE_STRTOULL = 0 diff --git a/port/libport.h b/port/libport.h index 24e559b6..cb302ef4 100644 --- a/port/libport.h +++ b/port/libport.h @@ -36,16 +36,16 @@ int strcasecmp(const char *s1, const char *s2); # define HAVE_GETOPT 1 #endif -#if defined(HAVE_STRTOL) +#if !defined(HAVE_STRTOL) long strtol(const char *nptr, char **endptr, int base); #endif -#if defined(HAVE_STRTOLL) +#if !defined(HAVE_STRTOLL) long long strtoll(const char *nptr, char **endptr, int base); #endif -#if defined(HAVE_STRTOUL) +#if !defined(HAVE_STRTOUL) unsigned long strtoul(const char *nptr, char **endptr, int base); #endif -#if defined(HAVE_STRTOULL) +#if !defined(HAVE_STRTOULL) unsigned long long strtoull(const char *nptr, char **endptr, int base); #endif From ed3b07c4e214795931f8ab67cfe4be13755fa8f8 Mon Sep 17 00:00:00 2001 From: Bob Friesenhahn Date: Tue, 28 Jan 2020 08:16:05 -0600 Subject: [PATCH 021/180] 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. --- Makefile.vc | 3 +++ port/Makefile.vc | 2 ++ 2 files changed, 5 insertions(+) diff --git a/Makefile.vc b/Makefile.vc index 6e66c730..eeb5d04d 100644 --- a/Makefile.vc +++ b/Makefile.vc @@ -31,6 +31,9 @@ all: port lib tools port:: + cd libtiff + $(MAKE) /f Makefile.vc tif_config.h + cd.. cd port $(MAKE) /f Makefile.vc cd.. diff --git a/port/Makefile.vc b/port/Makefile.vc index 501f7d74..6122b192 100644 --- a/port/Makefile.vc +++ b/port/Makefile.vc @@ -55,6 +55,8 @@ EXTRAFLAGS = -DHAVE_STRTOULL $(EXTRAFLAGS) STRTOULL_OBJ = strtoull.obj !ENDIF +INCL = -I..\libtiff + OBJ = \ snprintf.obj \ strcasecmp.obj \ From 7a335a32ebbce103d429c82a8d60d25ead1ccf0e Mon Sep 17 00:00:00 2001 From: Bob Friesenhahn Date: Wed, 29 Jan 2020 08:03:39 -0600 Subject: [PATCH 022/180] 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. --- nmake.opt | 11 ++++------- port/Makefile.vc | 14 ++++++++++---- port/libport.h | 4 ++++ 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/nmake.opt b/nmake.opt index 79b2fbbb..d9bf15f1 100644 --- a/nmake.opt +++ b/nmake.opt @@ -110,12 +110,9 @@ CHECK_JPEG_YCBCR_SUBSAMPLING = 1 # -# Indicate if the compiler provides strtol/strtoul/strtoll/strtoull. -# Users of MSVC++ 14.0 ("Visual Studio 2015") and later should set all of these to 1 -HAVE_STRTOL = 1 -HAVE_STRTOUL = 1 -HAVE_STRTOLL = 0 -HAVE_STRTOULL = 0 +# Indicate if the compiler provides strtoll/strtoull (default 1) +# Users of MSVC++ 14.0 ("Visual Studio 2015") and later should set this to 1 +HAVE_STRTOLL = 1 # # Pick debug or optimized build flags. We default to an optimized build @@ -148,7 +145,7 @@ LD = link /nologo CFLAGS = $(OPTFLAGS) $(INCL) $(EXTRAFLAGS) CXXFLAGS = $(OPTFLAGS) $(INCL) $(EXTRAFLAGS) -EXTRAFLAGS = +EXTRAFLAGS = -DHAVE_CONFIG_H LIBS = # Name of the output shared library diff --git a/port/Makefile.vc b/port/Makefile.vc index 6122b192..e4471af5 100644 --- a/port/Makefile.vc +++ b/port/Makefile.vc @@ -27,30 +27,36 @@ !INCLUDE ..\nmake.opt +HAVE_STRTOL = 1 +HAVE_STRTOUL = 1 + +# strtoul()/strtoull() are provided together +!IF $(HAVE_STRTOLL) +HAVE_STRTOULL = 1 +!ELSE +HAVE_STRTOULL = 0 +!endif + !IF $(HAVE_STRTOL) STRTOL_OBJ = -EXTRAFLAGS = -DHAVE_STRTOL $(EXTRAFLAGS) !ELSE STRTOL_OBJ = strtol.obj !ENDIF !IF $(HAVE_STRTOUL) STRTOUL_OBJ = -EXTRAFLAGS = -DHAVE_STRTOUL $(EXTRAFLAGS) !ELSE STRTOUL_OBJ = strtoul.obj !ENDIF !IF $(HAVE_STRTOLL) STRTOLL_OBJ = -EXTRAFLAGS = -DHAVE_STRTOLL $(EXTRAFLAGS) !ELSE STRTOLL_OBJ = strtoll.obj !ENDIF !IF $(HAVE_STRTOULL) STRTOULL_OBJ = -EXTRAFLAGS = -DHAVE_STRTOULL $(EXTRAFLAGS) !ELSE STRTOULL_OBJ = strtoull.obj !ENDIF diff --git a/port/libport.h b/port/libport.h index cb302ef4..9f2dace1 100644 --- a/port/libport.h +++ b/port/libport.h @@ -24,6 +24,10 @@ #ifndef _LIBPORT_ #define _LIBPORT_ +#if defined(HAVE_CONFIG_H) +# include +#endif + int getopt(int argc, char * const argv[], const char *optstring); extern char *optarg; extern int opterr; From 37a02ad493586bfd21a6fb15c5d8deeaaaffc41b Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sat, 1 Feb 2020 18:11:08 +0100 Subject: [PATCH 023/180] 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. --- libtiff/tif_write.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libtiff/tif_write.c b/libtiff/tif_write.c index 33e803c1..f79330e9 100644 --- a/libtiff/tif_write.c +++ b/libtiff/tif_write.c @@ -533,6 +533,13 @@ TIFFSetupStrips(TIFF* tif) isUnspecified(tif, FIELD_ROWSPERSTRIP) ? td->td_samplesperpixel : TIFFNumberOfStrips(tif); td->td_nstrips = td->td_stripsperimage; + /* TIFFWriteDirectoryTagData has a limitation to 0x80000000U bytes */ + if( td->td_nstrips >= 0x80000000U / ((tif->tif_flags&TIFF_BIGTIFF)?0x8U:0x4U) ) + { + TIFFErrorExt(tif->tif_clientdata, "TIFFSetupStrips", + "Too large Strip/Tile Offsets/ByteCounts arrays"); + return 0; + } if (td->td_planarconfig == PLANARCONFIG_SEPARATE) td->td_stripsperimage /= td->td_samplesperpixel; td->td_stripoffset_p = (uint64 *) From 3334704ebcec6a8011fc5ef5d0904d6297a0b9ff Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Thu, 6 Feb 2020 01:25:03 +0100 Subject: [PATCH 024/180] tif_dirread.c: suppress CLang static Analyzer 9.0 false positive --- libtiff/tif_dirread.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libtiff/tif_dirread.c b/libtiff/tif_dirread.c index 59037c91..58f2eb53 100644 --- a/libtiff/tif_dirread.c +++ b/libtiff/tif_dirread.c @@ -5180,6 +5180,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) From ebf0864306f4f24ac25011cf5d752b94c897faa1 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Sat, 8 Feb 2020 11:17:08 +0100 Subject: [PATCH 025/180] 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. --- tools/tiff2ps.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tools/tiff2ps.c b/tools/tiff2ps.c index 5874aba6..31a318a8 100644 --- a/tools/tiff2ps.c +++ b/tools/tiff2ps.c @@ -2467,8 +2467,10 @@ PSDataColorContig(FILE* fd, TIFF* tif, uint32 w, uint32 h, int nc) } if (alpha) { int adjust; - cc = 0; - for (; (cc + nc) <= tf_bytesperrow; cc += samplesperpixel) { + /* + * the code inside this loop reads nc bytes + 1 extra byte (for adjust) + */ + for (cc = 0; (cc + nc) < tf_bytesperrow; cc += samplesperpixel) { DOBREAK(breaklen, nc, fd); /* * For images with alpha, matte against @@ -2486,8 +2488,10 @@ PSDataColorContig(FILE* fd, TIFF* tif, uint32 w, uint32 h, int nc) cp += es; } } else { - cc = 0; - for (; (cc + nc) <= tf_bytesperrow; cc += samplesperpixel) { + /* + * the code inside this loop reads nc bytes per iteration + */ + for (cc = 0; (cc + nc) <= tf_bytesperrow; cc += samplesperpixel) { DOBREAK(breaklen, nc, fd); switch (nc) { case 4: c = *cp++; PUTHEX(c,fd); From 31073933543e6f89397a5c72f5f061a57f2353f4 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Sat, 8 Feb 2020 13:27:51 +0100 Subject: [PATCH 026/180] tiff2pdf: palette bound check in t2p_sample_realize_palette() fixes #82 --- tools/tiff2pdf.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/tiff2pdf.c b/tools/tiff2pdf.c index 779c1662..bca54d53 100644 --- a/tools/tiff2pdf.c +++ b/tools/tiff2pdf.c @@ -3731,6 +3731,11 @@ tsize_t t2p_sample_realize_palette(T2P* t2p, unsigned char* buffer){ for(i=sample_count;i>0;i--){ palette_offset=buffer[i-1] * component_count; sample_offset= (i-1) * component_count; + if(palette_offset + component_count > t2p->pdf_palettesize){ + TIFFError(TIFF2PDF_MODULE, + "Error: palette_offset + component_count > t2p->pdf_palettesize"); + return 1; + } for(j=0;jpdf_palette[palette_offset+j]; } From 4f168b7368eaab89d803ae9527016d527ed83713 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Sat, 8 Feb 2020 13:43:35 +0100 Subject: [PATCH 027/180] 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 --- tools/tiffcrop.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/tiffcrop.c b/tools/tiffcrop.c index 29c19a2f..6cc5a2ce 100644 --- a/tools/tiffcrop.c +++ b/tools/tiffcrop.c @@ -4024,9 +4024,9 @@ combineSeparateSamples24bits (uint8 *in[], uint8 *out, uint32 cols, { src = in[s] + src_offset + src_byte; if (little_endian) - buff1 = (src[0] << 24) | (src[1] << 16) | (src[2] << 8) | src[3]; + buff1 = ((uint32)src[0] << 24) | ((uint32)src[1] << 16) | ((uint32)src[2] << 8) | (uint32)src[3]; else - buff1 = (src[3] << 24) | (src[2] << 16) | (src[1] << 8) | src[0]; + buff1 = ((uint32)src[3] << 24) | ((uint32)src[2] << 16) | ((uint32)src[1] << 8) | (uint32)src[0]; buff1 = (buff1 & matchbits) << (src_bit); /* If we have a full buffer's worth, write it out */ From 2cdc041d627a2ef00b443c39c56443d3e33cc0be Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Sat, 8 Feb 2020 17:54:51 +0100 Subject: [PATCH 028/180] libtiff.html: fix function casing fixes #68 / http://bugzilla.maptools.org/show_bug.cgi?id=2538 --- html/libtiff.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/html/libtiff.html b/html/libtiff.html index 56535d97..3f949ab3 100644 --- a/html/libtiff.html +++ b/html/libtiff.html @@ -518,9 +518,9 @@         TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &imagelength);
        buf = _TIFFmalloc(TIFFScanlineSize(tif));
        for (row = 0; row < imagelength; row++)
-             tiffreadscanline(tif, buf, row);
-         _tifffree(buf);
-         tiffclose(tif);
+             TIFFReadScanline(tif, buf, row, 0);
+         _TIFFfree(buf);
+         TIFFClose(tif);
    }
}

From 8c9dca34be96413611575fa3a46c0eddea75c72f Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Sat, 8 Feb 2020 18:02:15 +0100 Subject: [PATCH 029/180] libtiff.html: fix function casing --- html/libtiff.html | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/html/libtiff.html b/html/libtiff.html index 3f949ab3..d6b5eab3 100644 --- a/html/libtiff.html +++ b/html/libtiff.html @@ -547,17 +547,17 @@         buf = _TIFFmalloc(TIFFScanlineSize(tif));
        if (config == PLANARCONFIG_CONTIG) {
            for (row = 0; row < imagelength; row++)
-                 tiffreadscanline(tif, buf, row);
+                 TIFFReadScanline(tif, buf, row, 0);
        } else if (config == planarconfig_separate) {
            uint16 s, nsamples;
            
            tiffgetfield(tif, tifftag_samplesperpixel, &nsamples);
            for (s = 0; s < nsamples; s++)
                for (row = 0; row < imagelength; row++)
-                     tiffreadscanline(tif, buf, row, s);
+                     TIFFReadScanline(tif, buf, row, s);
        }
-         _tifffree(buf);
-         tiffclose(tif);
+         _TIFFfree(buf);
+         TIFFClose(tif);
    }
}

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

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

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

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

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

From bdcf1add10f657ec00d3e69c7b6c288d840387d2 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Sat, 8 Feb 2020 11:47:38 +0100 Subject: [PATCH 030/180] 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 --- tools/raw2tiff.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/tools/raw2tiff.c b/tools/raw2tiff.c index ab36ff4e..f00142cf 100644 --- a/tools/raw2tiff.c +++ b/tools/raw2tiff.c @@ -372,7 +372,7 @@ guessSize(int fd, TIFFDataType dtype, _TIFF_off_t hdr_size, uint32 nbands, _TIFF_stat_s filestat; uint32 w, h, scanlinesize, imagesize; uint32 depth = TIFFDataWidth(dtype); - float cor_coef = 0, tmp; + double cor_coef = 0, tmp; if (_TIFF_fstat_f(fd, &filestat) == -1) { fprintf(stderr, "Failed to obtain file size.\n"); @@ -419,22 +419,28 @@ guessSize(int fd, TIFFDataType dtype, _TIFF_off_t hdr_size, uint32 nbands, w++) { if (imagesize % w == 0) { scanlinesize = w * depth; + h = imagesize / w; + if (h < 2) + continue; + /* reads 2 lines at the middle of the image and calculate their correlation. + * it works for h >= 2. (in this case it will compare line 0 and line 1 */ buf1 = _TIFFmalloc(scanlinesize); buf2 = _TIFFmalloc(scanlinesize); - h = imagesize / w; do { - if (_TIFF_lseek_f(fd, hdr_size + (int)(h/2)*scanlinesize, + if (_TIFF_lseek_f(fd, hdr_size + (int)((h - 1)/2)*scanlinesize, SEEK_SET) == (_TIFF_off_t)-1) { fprintf(stderr, "seek error.\n"); fail=1; break; } + /* read line (h-1)/2 */ if (read(fd, buf1, scanlinesize) != (long) scanlinesize) { fprintf(stderr, "read error.\n"); fail=1; break; } + /* read line ((h-1)/2)+1 */ if (read(fd, buf2, scanlinesize) != (long) scanlinesize) { fprintf(stderr, "read error.\n"); @@ -445,11 +451,15 @@ guessSize(int fd, TIFFDataType dtype, _TIFF_off_t hdr_size, uint32 nbands, swapBytesInScanline(buf1, w, dtype); swapBytesInScanline(buf2, w, dtype); } - tmp = (float) fabs(correlation(buf1, buf2, - w, dtype)); - if (tmp > cor_coef) { - cor_coef = tmp; + if (0 == memcmp(buf1, buf2, scanlinesize)) { *width = w, *length = h; + } else { + tmp = fabs(correlation(buf1, buf2, + w, dtype)); + if (tmp > cor_coef) { + cor_coef = tmp; + *width = w, *length = h; + } } } while (0); @@ -564,6 +574,7 @@ correlation(void *buf1, void *buf2, uint32 n_elem, TIFFDataType dtype) M2 /= n_elem; D1 -= M1 * M1 * n_elem; D2 -= M2 * M2 * n_elem; + if (D1 * D2 == 0.0) return 0.0; /* avoid divide by zero */ K = (K - M1 * M2 * n_elem) / sqrt(D1 * D2); return K; From 16377d39eafe9b272d718d7936d26fd94b20402e Mon Sep 17 00:00:00 2001 From: Chris Degawa Date: Tue, 9 Apr 2019 13:18:30 -0500 Subject: [PATCH 031/180] 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. --- CMakeLists.txt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d0285be0..fbc74bbe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -203,7 +203,9 @@ else() endif() # Find libm, if available -find_library(M_LIBRARY m) +if(NOT MINGW) + find_library(M_LIBRARY m) +endif() check_include_file(assert.h HAVE_ASSERT_H) check_include_file(dlfcn.h HAVE_DLFCN_H) @@ -671,7 +673,7 @@ endif() # Libraries required by libtiff set(TIFF_LIBRARY_DEPS) -if(M_LIBRARY) +if(NOT MINGW AND M_LIBRARY) list(APPEND TIFF_LIBRARY_DEPS ${M_LIBRARY}) endif() if(ZLIB_LIBRARIES) From 6df997c786928757caea0dd68d26ea5f098f49df Mon Sep 17 00:00:00 2001 From: Su_Laus Date: Thu, 19 Dec 2019 22:04:44 +0100 Subject: [PATCH 032/180] 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 --- libtiff/tif_dir.c | 39 ++ libtiff/tif_dirinfo.c | 141 ++++- libtiff/tif_dirread.c | 25 +- libtiff/tif_dirwrite.c | 495 +++++++++++++++- libtiff/tiffiop.h | 3 + test/CMakeLists.txt | 3 + test/Makefile.am | 4 +- test/rational_precision2double.c | 990 +++++++++++++++++++++++++++++++ 8 files changed, 1655 insertions(+), 45 deletions(-) create mode 100644 test/rational_precision2double.c diff --git a/libtiff/tif_dir.c b/libtiff/tif_dir.c index 1e0a76c3..e59f1633 100644 --- a/libtiff/tif_dir.c +++ b/libtiff/tif_dir.c @@ -29,6 +29,7 @@ * (and also some miscellaneous stuff) */ #include "tiffiop.h" +#include /*--: for Rational2Double */ /* * These are used in the backwards compatibility code... @@ -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 schould 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)); @@ -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 schould 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; diff --git a/libtiff/tif_dirinfo.c b/libtiff/tif_dirinfo.c index e1f6b23e..2c80058a 100644 --- a/libtiff/tif_dirinfo.c +++ b/libtiff/tif_dirinfo.c @@ -50,6 +50,15 @@ static const TIFFFieldArray exifFieldArray; #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 behaviour 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 +84,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 }, @@ -163,7 +172,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 +184,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 }, @@ -219,8 +228,8 @@ tiffFields[] = { 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 }, @@ -229,17 +238,17 @@ exifFields[] = { { 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_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, 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 }, @@ -251,13 +260,13 @@ exifFields[] = { { 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,10 +274,10 @@ 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 }, @@ -502,6 +511,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) { diff --git a/libtiff/tif_dirread.c b/libtiff/tif_dirread.c index c5584fe6..5653035a 100644 --- a/libtiff/tif_dirread.c +++ b/libtiff/tif_dirread.c @@ -5213,7 +5213,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); @@ -5229,6 +5229,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; diff --git a/libtiff/tif_dirwrite.c b/libtiff/tif_dirwrite.c index 9e4d3060..6de1f7ea 100644 --- a/libtiff/tif_dirwrite.c +++ b/libtiff/tif_dirwrite.c @@ -28,6 +28,8 @@ * Directory Write Support Routines. */ #include "tiffiop.h" +#include /*--: for Rational2Double */ +#include /*--: for Rational2Double */ #ifdef HAVE_IEEEFP #define TIFFCvtNativeToIEEEFloat(tif, n, fp) @@ -154,6 +156,17 @@ 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); +void DoubleToRational(double f, uint32 *num, uint32 *denom); +void DoubleToSrational(double f, int32 *num, int32 *denom); +void DoubleToRational_direct(double value, unsigned long *num, unsigned long *denom); +void DoubleToSrational_direct(double value, long *num, long *denom); + #ifdef notdef static int TIFFWriteDirectoryTagCheckedFloat(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, float value); #endif @@ -796,12 +809,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 schould 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 schould 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 +1603,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 +2384,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 +2418,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 +2453,7 @@ TIFFWriteDirectoryTagCheckedRationalArray(TIFF* tif, uint32* ndir, TIFFDirEntry* } for (na=value, nb=m, nc=0; nctif_flags&TIFF_SWAB) TIFFSwabArrayOfLong(m,count*2); @@ -2424,6 +2505,7 @@ TIFFWriteDirectoryTagCheckedSrationalArray(TIFF* tif, uint32* ndir, TIFFDirEntry } for (na=value, nb=m, nc=0; nctif_flags&TIFF_SWAB) TIFFSwabArrayOfLong((uint32*)m,count*2); @@ -2468,6 +2554,385 @@ TIFFWriteDirectoryTagCheckedSrationalArray(TIFF* tif, uint32* ndir, TIFFDirEntry return(o); } +/*-- Rational2Double: additonal write functions for double arrays */ +static int +TIFFWriteDirectoryTagCheckedRationalDoubleArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, double* value) +{ + static const char module[] = "TIFFWriteDirectoryTagCheckedRationalDoubleArray"; + uint32* m; + double* na; + uint32* nb; + uint32 nc; + int o; + assert(sizeof(uint32)==4); + m=_TIFFmalloc(count*2*sizeof(uint32)); + if (m==NULL) + { + TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); + return(0); + } + for (na=value, nb=m, nc=0; nctif_flags&TIFF_SWAB) + TIFFSwabArrayOfLong(m,count*2); + o=TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_RATIONAL,count,count*8,&m[0]); + _TIFFfree(m); + return(o); +} /*-- TIFFWriteDirectoryTagCheckedRationalDoubleArray() ------- */ + +static int +TIFFWriteDirectoryTagCheckedSrationalDoubleArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, double* value) +{ + static const char module[] = "TIFFWriteDirectoryTagCheckedSrationalDoubleArray"; + int32* m; + double* na; + int32* nb; + uint32 nc; + int o; + assert(sizeof(int32)==4); + m=_TIFFmalloc(count*2*sizeof(int32)); + if (m==NULL) + { + TIFFErrorExt(tif->tif_clientdata,module,"Out of memory"); + return(0); + } + for (na=value, nb=m, nc=0; nctif_flags&TIFF_SWAB) + TIFFSwabArrayOfLong((uint32*)m,count*2); + o=TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_SRATIONAL,count,count*8,&m[0]); + _TIFFfree(m); + return(o); +} /*--- TIFFWriteDirectoryTagCheckedSrationalDoubleArray() -------- */ + + +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() -------------- */ + + +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() --------------*/ + + +//#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 euclidian 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) +------------------------------------------------------------------------*/ +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 accidentially lead to different accuracies just depending on the value. + * Therefore, blnUseSmallRange steers this behaviour. + * 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; + if (i > 0) break; /* if bigDenom is zero, exit loop, but execute loop just once */ + } + 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) +------------------------------------------------------------------------*/ +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. */ + if (value < 0) { + *num = *denom = 0; + TIFFErrorExt(0, "TIFFLib: DoubeToRational()", " Negative Value for Unsigned Rational given."); + return; + } + + /*-- Check for too big numbers (> ULONG_MAX) -- */ + if (value > 0xFFFFFFFFUL) { + *num = 0xFFFFFFFFUL; + *denom = 0; + return; + } + /*-- Check for easy integer numbers -- */ + if (value == (unsigned long)(value)) { + *num = (unsigned long)value; + *denom = 1; + return; + } + /*-- Check for too small numbers for "unsigned long" type rationals -- */ + if (value < 1.0 / (double)0xFFFFFFFFUL) { + *num = 0; + *denom = 0xFFFFFFFFUL; + return; + } + + /*-- There are two approaches using the Euclidean algorithm, + * which can accidentially 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) { + TIFFErrorExt(0, "TIFFLib: DoubeToRational()", " Num or Denom exceeds ULONG: val=%14.6f, num=%12llu, denom=%12llu | num2=%12llu, denom2=%12llu", value, ullNum, ullDenom, ullNum2, ullDenom2); + 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 = (unsigned long)ullNum; + *denom = (unsigned long)ullDenom; + } + else { + *num = (unsigned long)ullNum2; + *denom = (unsigned long)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) +------------------------------------------------------------------------*/ +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. */ + 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 == (long)(value)) { + *num = (long)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 accidentially lead to different accuracies just depending on the value. + * Try both and define which one was better. + * Furthermore, set behaviour 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) { + TIFFErrorExt(0, "TIFFLib: DoubeToSrational()", " Num or Denom exceeds LONG: val=%14.6f, num=%12llu, denom=%12llu | num2=%12llu, denom2=%12llu", neg*value, ullNum, ullDenom, ullNum2, ullDenom2); + 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 = (long)(neg * (long)ullNum); + *denom = (long)ullDenom; + } + else { + *num = (long)(neg * (long)ullNum2); + *denom = (long)ullDenom2; + } +} /*-- DoubleToSrational() --------------*/ + + + + + #ifdef notdef static int TIFFWriteDirectoryTagCheckedFloat(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, float value) diff --git a/libtiff/tiffiop.h b/libtiff/tiffiop.h index 45a79323..39b54c89 100644 --- a/libtiff/tiffiop.h +++ b/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/test/CMakeLists.txt b/test/CMakeLists.txt index a4216d56..f90ffb33 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -188,6 +188,9 @@ endif() add_executable(custom_dir custom_dir.c) target_link_libraries(custom_dir tiff port) +add_executable(rational_precision2double rational_precision2double.c) +target_link_libraries(rational_precision2double tiff port) + add_executable(defer_strile_loading defer_strile_loading.c) target_link_libraries(defer_strile_loading tiff port) diff --git a/test/Makefile.am b/test/Makefile.am index 90c2f3d1..a981ba3a 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -64,7 +64,7 @@ endif # Executable programs which need to be built in order to support tests check_PROGRAMS = \ ascii_tag long_tag short_tag strip_rw rewrite custom_dir \ - defer_strile_loading defer_strile_writing testtypes \ + rational_precision2double defer_strile_loading defer_strile_writing testtypes \ $(JPEG_DEPENDENT_CHECK_PROG) # Test scripts to execute @@ -203,6 +203,8 @@ raw_decode_SOURCES = raw_decode.c raw_decode_LDADD = $(LIBTIFF) custom_dir_SOURCES = custom_dir.c custom_dir_LDADD = $(LIBTIFF) +rational_precision2double_SOURCES = rational_precision2double.c +rational_precision2double_LDADD = $(LIBTIFF) defer_strile_loading_SOURCES = defer_strile_loading.c defer_strile_loading_LDADD = $(LIBTIFF) defer_strile_writing_SOURCES = defer_strile_writing.c diff --git a/test/rational_precision2double.c b/test/rational_precision2double.c new file mode 100644 index 00000000..63e2978d --- /dev/null +++ b/test/rational_precision2double.c @@ -0,0 +1,990 @@ + +/* + * Copyright (c) 2012, Frank Warmerdam + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +/* + * TIFF Library + * + * -- Module copied from custom_dir.c -- + *=========== Purpose =================================================================================== + * Extended and amended version for testing the TIFFSetField() / and TIFFGetField()- interface + * for custom fields of type RATIONAL when the TIFFLib internal precision is updated from FLOAT to DOUBLE! + * The external interface of already defined tags schould be kept. + * This is verified for some of those tags with this test. + * + */ + + +#define FOR_AUTO_TESTING +#ifdef FOR_AUTO_TESTING +/* Only for automake and CMake infrastructure the test should: + a.) delete any written testfiles when test passed (otherwise autotest will fail) + b.) goto failure, if any failure is detected, which is not necessary when test is initiated manually for debugging +*/ +#define GOTOFAILURE goto failure; +#else +#define GOTOFAILURE +#endif + + +#pragma warning( disable : 4101) + +#include "tif_config.h" +#include +#include +#include +#include + +#ifdef HAVE_UNISTD_H +# include +#endif + +#include "tiffio.h" +#include "tiffiop.h" +#include "tif_dir.h" +#include "tifftest.h" + + +#include "tif_dirwrite.c" + + +int write_test_tiff(TIFF *tif, const char *filenameRead, int blnAllCustomTags); + +#define SPP 3 /* Samples per pixel */ +const uint16 width = 1; +const uint16 length = 1; +const uint16 bps = 8; +const uint16 photometric = PHOTOMETRIC_RGB; +const uint16 rows_per_strip = 1; +const uint16 planarconfig = PLANARCONFIG_CONTIG; + +/*-- Additional custom TIFF tags for testing of Rational2Double precision --*/ +#define TIFFTAG_RATIONAL_DOUBLE 60000 +#define TIFFTAG_SRATIONAL_DOUBLE 60001 +#define TIFFTAG_RATIONAL_C0_DOUBLE 60002 +#define TIFFTAG_SRATIONAL_C16_DOUBLE 60003 + + +/*--- TIFFField Definition --- + field_tag: the tag number. For instance 277 for the SamplesPerPixel tag. Builtin tags will generally have a #define in tiff.h for each known tag. + field_readcount: The number of values which should be read. The special value TIFF_VARIABLE (-1) indicates that a variable number of values may be read. The special value TIFFTAG_SPP (-2) indicates that there should be one value for each sample as defined by TIFFTAG_SAMPLESPERPIXEL. The special value TIFF_VARIABLE2 (-3) is presumably similar to TIFF_VARIABLE though I am not sure what the distinction in behaviour is. This field is TIFF_VARIABLE for variable length ascii fields. + field_writecount: The number of values which should be written. Generally the same as field_readcount. A few built-in exceptions exist, but I haven't analysed why they differ. + field_type: Type of the field. One of TIFF_BYTE, TIFF_ASCII, TIFF_SHORT, TIFF_LONG, TIFF_RATIONAL, TIFF_SBYTE, TIFF_UNDEFINED, TIFF_SSHORT, TIFF_SLONG, TIFF_SRATIONAL, TIFF_FLOAT, TIFF_DOUBLE or TIFF_IFD. Note that some fields can support more than one type (for instance short and long). These fields should have multiple TIFFFieldInfos. + reserved: + set_field_type: TIFF_SETGET_DOUBLE + get_field_type: - not used - + field_bit: Built-in tags stored in special fields in the TIFF structure have assigned field numbers to distinguish them (ie. FIELD_SAMPLESPERPIXEL). New tags should generally just use FIELD_CUSTOM indicating they are stored in the generic tag list. + field_oktochange: TRUE if it is OK to change this tag value while an image is being written. FALSE for stuff that must be set once and then left unchanged (like ImageWidth, or PhotometricInterpretation for instance). + field_passcount: If TRUE, then the count value must be passed in TIFFSetField(), and TIFFGetField(), otherwise the count is not required. This should generally be TRUE for non-ascii variable count tags unless the count is implicit (such as with the colormap). + field_name: A name for the tag. Normally mixed case (studly caps) like "StripByteCounts" and relatively short. +*/ + +static const TIFFField +tifFieldInfo[] = { + { TIFFTAG_RATIONAL_DOUBLE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "Rational2Double_U_Double", NULL }, + { TIFFTAG_SRATIONAL_DOUBLE, 1, 1, TIFF_SRATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "Rational2Double_S_Double", NULL }, + { TIFFTAG_RATIONAL_C0_DOUBLE, 3, 3, TIFF_RATIONAL, 0, TIFF_SETGET_C0_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "Rational2Double_C0", NULL }, + { TIFFTAG_SRATIONAL_C16_DOUBLE, -1, -1, TIFF_SRATIONAL, 0, TIFF_SETGET_C16_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "Rational2Double_S_C16", NULL }, +}; + +#define N(a) (sizeof (a) / sizeof (a[0])) + +/*--- Add aditional Rational-Double Tags to TIFF + ref: html\addingtags.html but with new function _TIFFMergeFields(). +---*/ + +/* In libtiff 3.6.0 a new mechanism was introduced allowing libtiff to read unrecognised tags automatically. + When an unknown tags is encountered, it is automatically internally defined with a default name and a type derived from the tag value in the file. + Applications only need to predefine application specific tags if they need to be able to set them in a file, or if particular calling conventions + are desired for TIFFSetField() and TIFFGetField(). + When tags are autodefined like this the field_readcount and field_writecount values are always TIFF_VARIABLE. + The field_passcount is always TRUE, and the field_bit is FIELD_CUSTOM. The field name will be "Tag %d" where the %d is the tag number. +*/ + +/*The tags need to be defined for each TIFF file opened - and when reading they should be defined before the tags of the file are read, + yet a valid TIFF * is needed to merge the tags against. In order to get them registered at the appropriate part of the setup process, + it is necessary to register our merge function as an extender callback with libtiff. This is done with TIFFSetTagExtender(). + We also keep track of the previous tag extender (if any) so that we can call it from our extender allowing a chain of customizations to take effect. +*/ +static TIFFExtendProc _ParentExtender = NULL; +static void _XTIFFDefaultDirectory(TIFF *tif); + +static +void _XTIFFInitialize(void) +{ + static int first_time=1; + + if (! first_time) return; /* Been there. Done that. */ +first_time = 0; + +/* Grab the inherited method and install */ +_ParentExtender = TIFFSetTagExtender(_XTIFFDefaultDirectory); +} + +/* The extender callback is looks like this. +It merges in our new fields and then calls the next extender if there is one in effect. +*/ +static void +_XTIFFDefaultDirectory(TIFF *tif) +{ + uint32 n, nadded; + + /* Install the extended Tag field info */ + n = N(tifFieldInfo); + //_TIFFMergeFields(tif, const TIFFField info[], uint32 n); + nadded = _TIFFMergeFields(tif, tifFieldInfo, n); + + /* Since an XTIFF client module may have overridden + * the default directory method, we call it now to + * allow it to set up the rest of its own methods. + */ + + if (_ParentExtender) + (*_ParentExtender)(tif); +} + + +int +main() +{ + static const char filenameClassicTiff[] = "rationalPrecision2Double.tif"; + static const char filenameBigTiff[] = "rationalPrecision2Double_Big.tif"; + + TIFF *tif; + int ret; + int errorNo; + + /*-- Initialize TIFF-Extender to add additonal TIFF-Tags --*/ + _XTIFFInitialize(); + + fprintf(stderr, "==== Test if Set()/Get() interface for some custom rational tags behave as before change. ====\n"); + /* --- Test with Classic-TIFF ---*/ + /* delete file, if exists */ + ret = unlink(filenameClassicTiff); + errorNo = errno; + if (ret != 0 && errno != ENOENT) { + fprintf(stderr, "Can't delete test TIFF file %s.\n", filenameClassicTiff); + } + + /* We write the main directory as a simple image. */ + tif = TIFFOpen(filenameClassicTiff, "w+"); + if (!tif) { + fprintf(stderr, "Can't create test TIFF file %s.\n", filenameClassicTiff); + return 1; + } + fprintf(stderr, "-------- Test with ClassicTIFF started ----------\n"); + ret = write_test_tiff(tif, filenameClassicTiff, FALSE); + if (ret > 0) return(ret); + + /*--- Test with BIG-TIFF ---*/ + /* delete file, if exists */ + ret = unlink(filenameBigTiff); + if (ret != 0 && errno != ENOENT) { + fprintf(stderr, "Can't delete test TIFF file %s.\n", filenameBigTiff); + } + + tif = TIFFOpen(filenameBigTiff, "w8"); + if (!tif) { + fprintf(stderr, "Can't create test TIFF file %s.\n", filenameBigTiff); + return 1; + } + fprintf(stderr, "\n-------- Test with BigTIFF started ----------\n"); + ret = write_test_tiff(tif, filenameBigTiff, FALSE); + if (ret > 0) return(ret); + + + fprintf(stderr, "\n\n==== Test automatically, if all custom rational tags are written/read correctly. ====\n"); + /* --- Test with Classic-TIFF ---*/ + /* delete file, if exists */ + ret = unlink(filenameClassicTiff); + errorNo = errno; + if (ret != 0 && errno != ENOENT) { + fprintf(stderr, "Can't delete test TIFF file %s.\n", filenameClassicTiff); + } + + /* We write the main directory as a simple image. */ + tif = TIFFOpen(filenameClassicTiff, "w+"); + if (!tif) { + fprintf(stderr, "Can't create test TIFF file %s.\n", filenameClassicTiff); + return 1; + } + fprintf(stderr, "-------- Test with ClassicTIFF started ----------\n"); + ret = write_test_tiff(tif, filenameClassicTiff, TRUE); + if (ret > 0) return(ret); + + /*--- Test with BIG-TIFF ---*/ + /* delete file, if exists */ + ret = unlink(filenameBigTiff); + if (ret != 0 && errno != ENOENT) { + fprintf(stderr, "Can't delete test TIFF file %s.\n", filenameBigTiff); + } + + tif = TIFFOpen(filenameBigTiff, "w8"); + if (!tif) { + fprintf(stderr, "Can't create test TIFF file %s.\n", filenameBigTiff); + return 1; + } + fprintf(stderr, "\n-------- Test with BigTIFF started ----------\n"); + ret = write_test_tiff(tif, filenameBigTiff, TRUE); + return(ret); +} /* main() */ + + + + +int +write_test_tiff(TIFF* tif, const char* filenameRead, int blnAllCustomTags) { + unsigned char buf[SPP] = {0, 127, 255}; + /*-- Additional variables --*/ + int retCode, retCode2; + unsigned char* pGpsVersion; + char auxStr[200]; + float auxFloat = 0.0f; + double auxDouble = 0.0; + uint16 auxUint16 = 0; + uint32 auxUint32 = 0; + long auxLong = 0; + void* pVoid; + int blnIsRational2Double; + + int i, j; + long nTags; + + const TIFFFieldArray* tFieldArray; + const TIFFField** tifFields; /* actual field info */ + unsigned long tTag; + TIFFDataType tType; + short tWriteCount; + TIFFSetGetFieldType tSetFieldType; + unsigned short tFieldBit; + const TIFFField *fip; + char* tFieldName; + + +#define STRSIZE 1000 +#define N_SIZE 200 +#define VARIABLE_ARRAY_SIZE 6 + + /* -- Test data for writing -- */ + char auxCharArrayW[N_SIZE]; + short auxShortArrayW[N_SIZE]; + long auxLongArrayW[N_SIZE]; + float auxFloatArrayW[N_SIZE]; + double auxDoubleArrayW[N_SIZE]; + char auxTextArrayW[N_SIZE][STRSIZE]; + float auxFloatArrayN1[3] = {1.0f / 7.0f, 61.23456789012345f, 62.3f}; + float auxFloatArrayResolutions[4] = {5.456789f, 6.666666f, 0.0033f, 5.0f / 213.0f}; + + /* -- Variables for reading -- */ + uint16 count16 = 0; + union { + long Long; + short Short1; + short Short2[2]; + char Char[4]; + } auxLongUnion; + union { + double dbl; + float flt1; + float flt2; + } auxDblUnion; + + float* pFloat; + void* pVoidArray; + float* pFloatArray; + double* pDoubleArray; + char* pAscii; + char auxCharArray[2 * STRSIZE]; + short auxShortArray[2 * N_SIZE]; + long auxLongArray[2 * N_SIZE]; + float auxFloatArray[2 * N_SIZE]; + double auxDoubleArray[2 * N_SIZE]; + double dblDiff, dblDiffLimit; + float fltDiff, fltDiffLimit; +#define RATIONAL_EPS (1.0/30000.0) /* reduced difference of rational values, approx 3.3e-5 */ + + + /*-- Fill test data arrays for writing ----------- */ + for (i = 0; i < N_SIZE; i++) { + sprintf(auxTextArrayW[i], "N%d-String-%d_tttttttttttttttttttttttttttttx", i, i); + } + for (i = 0; i < N_SIZE; i++) { + auxCharArrayW[i] = (char)(i + 1); + } + for (i = 0; i < N_SIZE; i++) { + auxShortArrayW[i] = (short)(i + 1) * 7; + } + for (i = 0; i < N_SIZE; i++) { + auxLongArrayW[i] = (i + 1) * 133; + } + for (i = 0; i < N_SIZE; i++) { + auxFloatArrayW[i] = (float)((i + 1) * 133) / 3.3f; + } + for (i = 0; i < N_SIZE; i++) { + auxDoubleArrayW[i] = (double)((i + 1) * 3689) / 4.5697; + } + + /*-- Setup standard tags of a simple tiff file --*/ + if (!TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, width)) { + fprintf(stderr, "Can't set ImageWidth tag.\n"); + goto failure; + } + if (!TIFFSetField(tif, TIFFTAG_IMAGELENGTH, length)) { + fprintf(stderr, "Can't set ImageLength tag.\n"); + goto failure; + } + if (!TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, bps)) { + fprintf(stderr, "Can't set BitsPerSample tag.\n"); + goto failure; + } + if (!TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, SPP)) { + fprintf(stderr, "Can't set SamplesPerPixel tag.\n"); + goto failure; + } + if (!TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, rows_per_strip)) { + fprintf(stderr, "Can't set SamplesPerPixel tag.\n"); + goto failure; + } + if (!TIFFSetField(tif, TIFFTAG_PLANARCONFIG, planarconfig)) { + fprintf(stderr, "Can't set PlanarConfiguration tag.\n"); + goto failure; + } + if (!TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, photometric)) { + fprintf(stderr, "Can't set PhotometricInterpretation tag.\n"); + goto failure; + } + + /*--- Standard tags with TIFF_RATIONAL and TIFF_SETGET_DOUBLE to TIFF_SETGET_FLOAT change. --- + * They can be written either using float or double but have to be read using float. + -------------------------------------------------------------------------------------------- */ + if (!TIFFSetField(tif, TIFFTAG_XRESOLUTION, auxFloatArrayResolutions[0])) { + fprintf(stderr, "Can't set TIFFTAG_XRESOLUTION tag.\n"); + goto failure; + } + /* Test here the double input possibility */ + if (!TIFFSetField(tif, TIFFTAG_YRESOLUTION, (double)auxFloatArrayResolutions[1])) { + fprintf(stderr, "Can't set TIFFTAG_YRESOLUTION tag.\n"); + goto failure; + } + if (!TIFFSetField(tif, TIFFTAG_XPOSITION, auxFloatArrayResolutions[2])) { + fprintf(stderr, "Can't set TIFFTAG_XPOSITION tag.\n"); + goto failure; + } + if (!TIFFSetField(tif, TIFFTAG_YPOSITION, auxFloatArrayResolutions[3])) { + fprintf(stderr, "Can't set TIFFTAG_YPOSITION tag.\n"); + goto failure; + } + + /*--- Some additional FIELD_CUSTOM tags to check standard interface ---*/ + + /*- TIFFTAG_INKSET is a SHORT parameter (TIFF_SHORT, TIFF_SETGET_UINT16) with field_bit=FIELD_CUSTOM !! -*/ + if (!TIFFSetField(tif, TIFFTAG_INKSET, 34)) { + fprintf(stderr, "Can't set TIFFTAG_INKSET tag.\n"); + goto failure; + } + + /*- TIFFTAG_PIXAR_FOVCOT is a FLOAT parameter ( TIFF_FLOAT, TIFF_SETGET_FLOAT) with field_bit=FIELD_CUSTOM !! -*/ + /* - can be written with Double but has to be read with float parameter */ +#define PIXAR_FOVCOT_VAL 5.123456789123456789 + auxFloat = (float)PIXAR_FOVCOT_VAL; + /* if (!TIFFSetField(tif, TIFFTAG_PIXAR_FOVCOT, auxFloat )) { + fprintf (stderr, "Can't set TIFFTAG_PIXAR_FOVCOT tag.\n"); + goto failure; + } + */ + auxDouble = (double)PIXAR_FOVCOT_VAL; + if (!TIFFSetField(tif, TIFFTAG_PIXAR_FOVCOT, auxDouble)) { + fprintf(stderr, "Can't set TIFFTAG_PIXAR_FOVCOT tag.\n"); + goto failure; + } + /*- TIFFTAG_STONITS is a DOUBLE parameter (TIFF_DOUBLE, TIFF_SETGET_DOUBLE) with field_bit=FIELD_CUSTOM! + *-- Unfortunately, TIFF_SETGET_DOUBLE is used for TIFF_RATIONAL but those have to be read with FLOAT !!! + * Only TIFFTAG_STONITS is a TIFF_DOUBLE, which has to be read as DOUBLE!! + */ +#define STONITS_VAL 6.123456789123456789 + auxDouble = STONITS_VAL; + auxFloat = (float)auxDouble; + if (!TIFFSetField(tif, TIFFTAG_STONITS, auxDouble)) { + fprintf(stderr, "Can't set TIFFTAG_STONITS tag.\n"); + goto failure; + } + + + /*-- Additional tags to check Rational standard tags, which are also defined with field_bit=FIELD_CUSTOM */ + /* + The following standard tags have field_type = TIFF_RATIONAL with field_bit=FIELD_CUSTOM: + TIFFTAG_BASELINENOISE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE + TIFFTAG_BASELINESHARPNESS, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE + TIFFTAG_LINEARRESPONSELIMIT, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE + TIFFTAG_CHROMABLURRADIUS, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE + TIFFTAG_ANTIALIASSTRENGTH, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE + TIFFTAG_SHADOWSCALE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE + TIFFTAG_BESTQUALITYSCALE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE + and with Signed Rational: + TIFFTAG_BASELINEEXPOSURE, 1, 1, TIFF_SRATIONAL, 0, TIFF_SETGET_DOUBLE + Due to the fact that TIFFSetField() and TIFFGetField() interface is using va_args, variable promotion is applied, + which means: + If the actual argument is of type float, it is promoted to type double when function is to be made. + - Any signed or unsigned char, short, enumerated type, or bit field is converted to either a signed or an unsigned int + using integral promotion. + - Any argument of class type is passed by value as a data structure; the copy is created by binary copying instead + of by invoking the class’s copy constructor (if one exists). + So, if your argument types are of float type, you should expect the argument retrieved to be of type double + and it is char or short, you should expect it to be signed or unsigned int. Otherwise, the code will give you wrong results. + */ + + if (!blnAllCustomTags) { + /*--- TEST: First tag is written with FLOAT and second tag is written with DOUBLE parameter ---*/ + /*- TIFFTAG_SHADOWSCALE is a Rational parameter (TIFF_RATIONAL, TIFF_SETGET_DOUBLE) with field_bit=FIELD_CUSTOM! -*/ + #define SHADOWSCALE_VAL 15.123456789123456789 + auxFloat = (float)SHADOWSCALE_VAL; + if (!TIFFSetField(tif, TIFFTAG_SHADOWSCALE, auxFloat)) { + fprintf(stderr, "Can't set TIFFTAG_SHADOWSCALE tag.\n"); + goto failure; + } + + /*- TIFFTAG_BESTQUALITYSCALE is a Rational parameter (TIFF_RATIONAL, TIFF_SETGET_DOUBLE) with field_bit=FIELD_CUSTOM! -*/ + #define BESTQUALITYSCALE_VAL 17.123456789123456789 + auxDouble = BESTQUALITYSCALE_VAL; + if (!TIFFSetField(tif, TIFFTAG_BESTQUALITYSCALE, auxDouble)) { + fprintf(stderr, "Can't set TIFFTAG_BESTQUALITYSCALE tag.\n"); + goto failure; + } + + + /*- TIFFTAG_BASELINEEXPOSURE is a Rational parameter (TIFF_SRATIONAL, TIFF_SETGET_DOUBLE) with field_bit=FIELD_CUSTOM! -*/ + #define BASELINEEXPOSURE_VAL (-3.14159265358979323846) + /* + fprintf(stderr, "(-3.14159265358979323846) as float= %.18f, double=%.18f\n", (float)BASELINEEXPOSURE_VAL, (double)BASELINEEXPOSURE_VAL, BASELINEEXPOSURE_VAL); + fprintf(stderr, "(-3.141592742098056) as float= %.18f, double=%.18f\n", (float)(-3.141592742098056), (double)(-3.141592742098056)); + */ + auxDouble = BASELINEEXPOSURE_VAL; + if (!TIFFSetField(tif, TIFFTAG_BASELINEEXPOSURE, auxDouble)) { + fprintf(stderr, "Can't set TIFFTAG_BASELINEEXPOSURE tag.\n"); + goto failure; + } + + + /*--- For static or variable ARRAYs the case is different ---*/ + + /*- Variable Array: TIFFTAG_DECODE is a SRATIONAL parameter TIFF_SETGET_C16_FLOAT type FIELD_CUSTOM with passcount=1 and variable length of array. */ + if (!TIFFSetField(tif, TIFFTAG_DECODE, 3, auxFloatArrayN1)) { /* for TIFF_SETGET_C16_DOUBLE */ + fprintf(stderr, "Can't set TIFFTAG_DECODE tag.\n"); + goto failure; + } + + /*- Varable Array: TIFF_RATIONAL, 0, TIFF_SETGET_C16_FLOAT */ + if (!TIFFSetField(tif, TIFFTAG_BLACKLEVEL, 3, auxFloatArrayN1)) { /* for TIFF_SETGET_C16_FLOAT */ + fprintf(stderr, "Can't set TIFFTAG_BLACKLEVEL tag.\n"); + goto failure; + } + + /*-- Check, if the TiffLibrary is compiled with the new interface with Rational2Double or still uses the old definitions. */ + /* tags to check: TIFFTAG_BESTQUALITYSCALE, TIFFTAG_BASELINENOISE, TIFFTAG_BASELINESHARPNESS, */ + fip = TIFFFindField(tif, TIFFTAG_BESTQUALITYSCALE, TIFF_ANY); + tSetFieldType = fip->set_field_type; + if (tSetFieldType == TIFF_SETGET_DOUBLE) + blnIsRational2Double = FALSE; + else + blnIsRational2Double = TRUE; + + /*--- Write now additional Rational2Double test tags ---*/ + /*--- However, this additional tags are only written as Double correctly, + if blnIsRational2Double is defined! + ------------------------------------------------------*/ + if (blnIsRational2Double) { + if (!TIFFSetField(tif, TIFFTAG_RATIONAL_DOUBLE, auxDoubleArrayW[100])) { + fprintf(stderr, "Can't set TIFFTAG_RATIONAL_DOUBLE tag.\n"); + goto failure; + } + if (!TIFFSetField(tif, TIFFTAG_SRATIONAL_DOUBLE, (-1.0 * auxDoubleArrayW[101]))) { + fprintf(stderr, "Can't set TIFFTAG_SRATIONAL_DOUBLE tag.\n"); + goto failure; + } + if (!TIFFSetField(tif, TIFFTAG_RATIONAL_C0_DOUBLE, &auxDoubleArrayW[110])) { + fprintf(stderr, "Can't set TIFFTAG_RATIONAL_C0_DOUBLE tag.\n"); + goto failure; + } + if (!TIFFSetField(tif, TIFFTAG_SRATIONAL_C16_DOUBLE, 2, &auxDoubleArrayW[120])) { + fprintf(stderr, "Can't set TIFFTAG_SRATIONAL_C16_DOUBLE tag.\n"); + goto failure; + } + } + + } else { /* blnAllCustomTags */ + /*==== Automatically check all custom rational tags == WRITING ===*/ + /*-- Get array, where TIFF tag fields are defined --*/ + tFieldArray = _TIFFGetFields(); + nTags = tFieldArray->count; + + for (i = 0; i < nTags; i++) { + tTag = tFieldArray->fields[i].field_tag; + tType = tFieldArray->fields[i].field_type; /* e.g. TIFF_RATIONAL */ + tWriteCount = tFieldArray->fields[i].field_writecount; + tSetFieldType = tFieldArray->fields[i].set_field_type; /* e.g. TIFF_SETGET_C0_FLOAT */ + tFieldBit = tFieldArray->fields[i].field_bit; + tFieldName = tFieldArray->fields[i].field_name; + pVoid = NULL; + + if (tType == TIFF_RATIONAL && tFieldBit == FIELD_CUSTOM) { + /*-- dependent on set_field_type write value --*/ + switch (tSetFieldType) { + case TIFF_SETGET_FLOAT: + case TIFF_SETGET_DOUBLE: + if (tWriteCount == 1) { + /*-- All single values can be written with float or double parameter. Only value range should be in line. */ + if (!TIFFSetField(tif, tTag, auxDoubleArrayW[i])) { + fprintf(stderr, "Can't write %s\n", tFieldArray->fields[i].field_name); + goto failure; + } + } else { + fprintf(stderr, "WriteCount for .set_field_type %d should be 1! %s\n", tSetFieldType, tFieldArray->fields[i].field_name); + } + break; + case TIFF_SETGET_C0_FLOAT: + case TIFF_SETGET_C0_DOUBLE: + case TIFF_SETGET_C16_FLOAT: + case TIFF_SETGET_C16_DOUBLE: + case TIFF_SETGET_C32_FLOAT: + case TIFF_SETGET_C32_DOUBLE: + /* _Cxx_ just defines the size of the count parameter for the array as C0=char, C16=short or C32=long */ + /*-- Check, if it is a single parameter, a fixed array or a variable array */ + if (tWriteCount == 1) { + fprintf(stderr, "WriteCount for .set_field_type %d should be -1 or greather than 1! %s\n", tSetFieldType, tFieldArray->fields[i].field_name); + } else { + /*-- Either fix or variable array --*/ + /* For arrays, distinguishing between float or double is essential, even for writing */ + if (tSetFieldType == TIFF_SETGET_C0_FLOAT || tSetFieldType == TIFF_SETGET_C16_FLOAT || tSetFieldType == TIFF_SETGET_C32_FLOAT) + pVoid = &auxFloatArrayW[i]; else pVoid = &auxDoubleArrayW[i]; + /* Now decide between fixed or variable array */ + if (tWriteCount > 1) { + /* fixed array with needed arraysize defined in .field_writecount */ + if (!TIFFSetField(tif, tTag, pVoid)) { + fprintf(stderr, "Can't write %s\n", tFieldArray->fields[i].field_name); + goto failure; + } + } else { + /* special treatment of variable array */ + /* for test, use always arraysize of VARIABLE_ARRAY_SIZE */ + if (!TIFFSetField(tif, tTag, VARIABLE_ARRAY_SIZE, pVoid)) { + fprintf(stderr, "Can't write %s\n", tFieldArray->fields[i].field_name); + goto failure; + } + } + } + break; + default: + fprintf(stderr, "SetFieldType %d not defined within writing switch for %s.\n", tSetFieldType, tFieldName); + }; /*-- switch() --*/ + } /* if () */ + } /*-- for() --*/ + } /* blnAllCustomTags */ /*==== END END - Automatically check all custom rational tags == WRITING END ===*/ + + /*-- Write dummy pixel data. --*/ + if (!TIFFWriteScanline(tif, buf, 0, 0) < 0) { + fprintf (stderr, "Can't write image data.\n"); + goto failure; + } + + /*-- Write directory to file --*/ + /* Always WriteDirectory before using/creating another directory. */ + /* Not necessary before TIFFClose(), however, TIFFClose() uses TIFFReWriteDirectory(), which forces directory to be written at another location. */ + retCode = TIFFWriteDirectory(tif); + + /*-- Write File to disk and close file --*/ + /* TIFFClose() uses TIFFReWriteDirectory(), which forces directory to be written at another location. */ + /* Therefore, better use TIFFWriteDirectory() before. */ + TIFFClose(tif); + + fprintf (stderr, "-------- Continue Test ---------- reading ...\n"); + +/*========================= READING ============= READING ========================================*/ + /* Ok, now test whether we can read written values in the EXIF directory. */ + tif = TIFFOpen(filenameRead, "r"); + + + /*-- Read some parameters out of the main directory --*/ + + /*-- IMAGEWIDTH and -LENGTH are defined as TIFF_SETGET_UINT32 */ + retCode = TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &auxUint32 ); + if (auxUint32 != width) { + fprintf (stderr, "Read value of IMAGEWIDTH %d differs from set value %d\n", auxUint32, width); + GOTOFAILURE + } + retCode = TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &auxUint32 ); + if (auxUint32 != width) { + fprintf (stderr, "Read value of TIFFTAG_IMAGELENGTH %d differs from set value %d\n", auxUint32, length); + GOTOFAILURE + } + + /*--- Standard tags with TIFF_RATIONAL and TIFF_SETGET_DOUBLE to TIFF_SETGET_FLOAT change. --- + * They can be written either using float or double but have to be read using float. + -------------------------------------------------------------------------------------------- */ + dblDiffLimit = RATIONAL_EPS; + retCode = TIFFGetField(tif, TIFFTAG_XRESOLUTION, &auxFloat); + dblDiff = auxFloat - auxFloatArrayResolutions[0]; + if (fabs(dblDiff) > fabs(dblDiffLimit)) { + fprintf(stderr, "Read value of TIFFTAG_XRESOLUTION %f differs from set value %f\n", auxFloat, auxFloatArrayResolutions[0]); + GOTOFAILURE + } + retCode = TIFFGetField(tif, TIFFTAG_YRESOLUTION, &auxFloat); + dblDiff = auxFloat - auxFloatArrayResolutions[1]; + if (fabs(dblDiff) > fabs(dblDiffLimit)) { + fprintf(stderr, "Read value of TIFFTAG_YRESOLUTION %f differs from set value %f\n", auxFloat, auxFloatArrayResolutions[1]); + GOTOFAILURE + } + retCode = TIFFGetField(tif, TIFFTAG_XPOSITION, &auxFloat); + dblDiff = auxFloat - auxFloatArrayResolutions[2]; + if (fabs(dblDiff) > fabs(dblDiffLimit)) { + fprintf(stderr, "Read value of TIFFTAG_XPOSITION %f differs from set value %f\n", auxFloat, auxFloatArrayResolutions[2]); + GOTOFAILURE + } + retCode = TIFFGetField(tif, TIFFTAG_YPOSITION, &auxFloat); + dblDiff = auxFloat - auxFloatArrayResolutions[3]; + if (fabs(dblDiff) > fabs(dblDiffLimit)) { + fprintf(stderr, "Read value of TIFFTAG_YPOSITION %f differs from set value %f\n", auxFloat, auxFloatArrayResolutions[3]); + GOTOFAILURE + } + + + /*- TIFFTAG_INKSET is a SHORT parameter (TIFF_SHORT, TIFF_SETGET_UINT16) with field_bit=FIELD_CUSTOM !! -*/ + retCode = TIFFGetField(tif, TIFFTAG_INKSET, &auxUint16); + if (auxUint16 != 34) { + fprintf(stderr, "Read value of TIFFTAG_PIXAR_FOVCOT %d differs from set value %d\n", auxUint16, TIFFTAG_INKSET); + GOTOFAILURE + } + + /*- TIFFTAG_PIXAR_FOVCOT is a FLOAT parameter ( TIFF_FLOAT, TIFF_SETGET_FLOAT) with field_bit=FIELD_CUSTOM !! -*/ + /* - was written with Double but has to be read with Float */ + retCode = TIFFGetField(tif, TIFFTAG_PIXAR_FOVCOT, &auxFloat ); + if (auxFloat != (float)PIXAR_FOVCOT_VAL) { + fprintf (stderr, "Read value of TIFFTAG_PIXAR_FOVCOT %f differs from set value %f\n", auxFloat, PIXAR_FOVCOT_VAL); + GOTOFAILURE + } + + /*- TIFFTAG_STONITS is a DOUBLE parameter (TIFF_DOUBLE, TIFF_SETGET_DOUBLE) with field_bit=FIELD_CUSTOM!! -*/ + retCode = TIFFGetField(tif, TIFFTAG_STONITS, &auxDouble); + if (auxDouble != (double)STONITS_VAL) { + fprintf(stderr, "Read value of TIFFTAG_STONITS %f differs from set value %f\n", auxDouble, STONITS_VAL); + GOTOFAILURE + } + + + + + /*-- Check, if the TiffLibrary is compiled with the new interface with Rational2Double or still uses the old definitions. */ + /* tags to check: TIFFTAG_BESTQUALITYSCALE, TIFFTAG_BASELINENOISE, TIFFTAG_BASELINESHARPNESS, */ + fip = TIFFFindField(tif, TIFFTAG_BESTQUALITYSCALE, TIFF_ANY); + tSetFieldType = fip->set_field_type; + if (tSetFieldType == TIFF_SETGET_DOUBLE) + blnIsRational2Double = FALSE; + else + blnIsRational2Double = TRUE; + + + if (!blnAllCustomTags) { + + /*- TIFFTAG_BESTQUALITYSCALE is a Rational parameter (TIFF_RATIONAL, TIFF_SETGET_DOUBLE) with field_bit=FIELD_CUSTOM! + and written with double parameter -*/ + /*- Read into a union to test the correct precision (float or double) returned. + * Float-parameter should be correct, but double-parameter should give a wrong value + */ + auxDblUnion.dbl = 0; + retCode = TIFFGetField(tif, TIFFTAG_BESTQUALITYSCALE, &auxDblUnion.dbl); + dblDiffLimit = RATIONAL_EPS * (double)BESTQUALITYSCALE_VAL; + dblDiff = auxDblUnion.dbl - (double)BESTQUALITYSCALE_VAL; + fltDiff = auxDblUnion.flt1 - (float)BESTQUALITYSCALE_VAL; + if (!((fabs(dblDiff) > fabs(dblDiffLimit)) && !(fabs(fltDiff) > fabs(dblDiffLimit)))) { + fprintf(stderr, "Float-Read value of TIFFTAG_BESTQUALITYSCALE %.12f differs from set value %.12f too much,\n", auxDblUnion.flt1, BESTQUALITYSCALE_VAL); + fprintf(stderr, "whereas Double-Read value of TIFFTAG_BESTQUALITYSCALE %.12f is nearly equal to set value %.12f\n", auxDblUnion.dbl, BESTQUALITYSCALE_VAL); + GOTOFAILURE + } + + /*--- Now the same for a Signed Rational ---*/ + /*- TIFFTAG_BASELINEEXPOSURE is a Rational parameter (TIFF_SRATIONAL, TIFF_SETGET_DOUBLE) with field_bit=FIELD_CUSTOM! - + and written with double parameter - */ + /*- Read into a union to test the correct precision (float or double) returned. + * Float-parameter should be correct, but double-parameter should give a wrong value + */ + auxDblUnion.dbl = 0; + retCode = TIFFGetField(tif, TIFFTAG_BASELINEEXPOSURE, &auxDblUnion.dbl); + dblDiffLimit = RATIONAL_EPS * (double)BASELINEEXPOSURE_VAL; + dblDiff = auxDblUnion.dbl - (double)BASELINEEXPOSURE_VAL; + fltDiff = auxDblUnion.flt1 - (float)BASELINEEXPOSURE_VAL; + if (!((fabs(dblDiff) > fabs(dblDiffLimit)) && !(fabs(fltDiff) > fabs(dblDiffLimit)))) { + fprintf(stderr, "Float-Read value of TIFFTAG_BASELINEEXPOSURE %.12f differs from set value %.12f too much,\n", auxDblUnion.flt1, BASELINEEXPOSURE_VAL); + fprintf(stderr, "whereas Double-Read value of TIFFTAG_BESTQUALITYSCALE %.12f is nearly equal to set value %.12f\n", auxDblUnion.dbl, BASELINEEXPOSURE_VAL); + GOTOFAILURE + } + + /*- Variable Array: TIFFTAG_DECODE is a SRATIONAL parameter TIFF_SETGET_C16_FLOAT type FIELD_CUSTOM with passcount=1 and variable length of array. */ + retCode = TIFFGetField(tif, TIFFTAG_DECODE, &count16, &pVoidArray); + retCode = TIFFGetField(tif, TIFFTAG_DECODE, &count16, &pFloatArray); + /*- pVoidArray points to a Tiff-internal temporary memorypart. Thus, contents needs to be saved. */ + memcpy(&auxFloatArray, pVoidArray, (count16 * sizeof(auxFloatArray[0]))); + for (i = 0; i < count16; i++) { + dblDiffLimit = RATIONAL_EPS * auxFloatArrayN1[i]; + dblDiff = auxFloatArray[i] - auxFloatArrayN1[i]; + if (fabs(dblDiff) > fabs(dblDiffLimit)) { + fprintf(stderr, "Read value %d of TIFFTAG_DECODE Array %f differs from set value %f\n", i, auxFloatArray[i], auxFloatArrayN1[i]); + GOTOFAILURE + } + } + + retCode = TIFFGetField(tif, TIFFTAG_BLACKLEVEL, &count16, &pVoidArray); + /*- pVoidArray points to a Tiff-internal temporary memorypart. Thus, contents needs to be saved. */ + memcpy(&auxFloatArray, pVoidArray, (count16 * sizeof(auxFloatArray[0]))); + for (i = 0; i < count16; i++) { + dblDiffLimit = RATIONAL_EPS * auxFloatArrayN1[i]; + dblDiff = auxFloatArray[i] - auxFloatArrayN1[i]; + if (fabs(dblDiff) > fabs(dblDiffLimit)) { + fprintf(stderr, "Read value %d of TIFFTAG_BLACKLEVEL Array %f differs from set value %f\n", i, auxFloatArray[i], auxFloatArrayN1[i]); + GOTOFAILURE + } + } + + + /*--- Read now additional Rational2Double test tags --- + This should be now with nearly double precision + However, this additional tags are only read as Double, + if blnIsRational2Double is defined! + ------------------------------------------------------*/ + if (blnIsRational2Double) { + auxDblUnion.dbl = 0; + retCode = TIFFGetField(tif, TIFFTAG_RATIONAL_DOUBLE, &auxDblUnion.dbl); + if (!retCode) { fprintf(stderr, "Can't read %s\n", "TIFFTAG_RATIONAL_DOUBLE"); GOTOFAILURE } + dblDiffLimit = RATIONAL_EPS * auxDoubleArrayW[100]; + dblDiff = auxDblUnion.dbl - auxDoubleArrayW[100]; + if (fabs(dblDiff) > fabs(dblDiffLimit)) { + fprintf(stderr, "Read value of TIFFTAG_RATIONAL_DOUBLE %f differs from set value %f\n", auxDblUnion.dbl, auxDoubleArrayW[100]); + GOTOFAILURE + } + + auxDblUnion.dbl = 0; + retCode = TIFFGetField(tif, TIFFTAG_SRATIONAL_DOUBLE, &auxDblUnion.dbl); + if (!retCode) { fprintf(stderr, "Can't read %s\n", "TIFFTAG_SRATIONAL_DOUBLE"); GOTOFAILURE } + auxDouble = -1.0 * auxDoubleArrayW[101]; + dblDiffLimit = RATIONAL_EPS * auxDouble; + dblDiff = auxDblUnion.dbl - auxDouble; + if (fabs(dblDiff) > fabs(dblDiffLimit)) { + fprintf(stderr, "Read value of TIFFTAG_SRATIONAL_DOUBLE %f differs from set value %f\n", auxDblUnion.dbl, auxDouble); + GOTOFAILURE + } + + /*- Fixed Array: TIFFTAG_RATIONAL_C0_DOUBLE, 3, 3, TIFF_RATIONAL, 0, TIFF_SETGET_C0_DOUBLE */ + count16 = 3; /* set fixed array length for checking */ + retCode = TIFFGetField(tif, TIFFTAG_RATIONAL_C0_DOUBLE, &pVoidArray); + /*- pVoidArray points to a Tiff-internal temporary memorypart. Thus, contents needs to be saved. */ + memcpy(&auxDoubleArray, pVoidArray, (count16 * sizeof(auxDoubleArray[0]))); + for (i = 0; i < count16; i++) { + dblDiffLimit = RATIONAL_EPS * auxDoubleArrayW[110 + i]; + dblDiff = auxDoubleArray[i] - auxDoubleArrayW[110 + i]; + if (fabs(dblDiff) > fabs(dblDiffLimit)) { + fprintf(stderr, "Read value %d of TIFFTAG_RATIONAL_C0_DOUBLE Array %f differs from set value %f\n", i, auxDoubleArray[i], auxDoubleArrayW[110 + i]); + GOTOFAILURE + } + } + + /*- Variable Array: TIFFTAG_SRATIONAL_C16_DOUBLE, -1, -1, TIFF_SRATIONAL, 0, TIFF_SETGET_C16_DOUBLE */ + retCode = TIFFGetField(tif, TIFFTAG_SRATIONAL_C16_DOUBLE, &count16, &pVoidArray); + /*- pVoidArray points to a Tiff-internal temporary memorypart. Thus, contents needs to be saved. */ + memcpy(&auxDoubleArray, pVoidArray, (count16 * sizeof(auxDoubleArray[0]))); + for (i = 0; i < count16; i++) { + dblDiffLimit = RATIONAL_EPS * auxDoubleArrayW[120 + i]; + dblDiff = auxDoubleArray[i] - auxDoubleArrayW[120 + i]; + if (fabs(dblDiff) > fabs(dblDiffLimit)) { + fprintf(stderr, "Read value %d of TIFFTAG_SRATIONAL_C16_DOUBLE Array %f differs from set value %f\n", i, auxDoubleArray[i], auxDoubleArrayW[120 + i]); + GOTOFAILURE + } + } + } + + } else { /* blnAllCustomTags */ + /*==== Automatically check all custom rational tags == READING ===*/ + + /*-- Get array, where standard TIFF tag fields are defined --*/ + tFieldArray = _TIFFGetFields(); + nTags = tFieldArray->count; + + for (i = 0; i < nTags; i++) { + tTag = tFieldArray->fields[i].field_tag; + tType = tFieldArray->fields[i].field_type; /* e.g. TIFF_RATIONAL */ + tWriteCount = tFieldArray->fields[i].field_writecount; + tSetFieldType = tFieldArray->fields[i].set_field_type; /* e.g. TIFF_SETGET_C0_FLOAT */ + tFieldBit = tFieldArray->fields[i].field_bit; + tFieldName = tFieldArray->fields[i].field_name; + pVoid = NULL; + auxDblUnion.dbl = 0; + + if (tType == TIFF_RATIONAL && tFieldBit == FIELD_CUSTOM) { + /*-- dependent on set_field_type read value --*/ + switch (tSetFieldType) { + case TIFF_SETGET_FLOAT: + if (!TIFFGetField(tif, tTag, &auxFloat)) { + fprintf(stderr, "Can't read %s\n", tFieldArray->fields[i].field_name); + GOTOFAILURE + break; + } + /* compare read values with written ones */ + if (tType == TIFF_RATIONAL || tType == TIFF_SRATIONAL) dblDiffLimit = RATIONAL_EPS * auxDoubleArrayW[i]; else dblDiffLimit = 1e-6; + dblDiff = auxFloat - auxDoubleArrayW[i]; + if (fabs(dblDiff) > fabs(dblDiffLimit)) { + /*--: EXIFTAG_SUBJECTDISTANCE: LibTiff returns value of "-1.0" if numerator equals 4294967295 (0xFFFFFFFF) to indicate infinite distance! + * However, there are two other EXIF tags where numerator indicates a special value and six other cases where the denominator indicates special values, + * which are not treated within LibTiff!! + */ + if (!(tTag == EXIFTAG_SUBJECTDISTANCE && auxFloat == -1.0)) { + fprintf(stderr, "%d:Read value of %s %f differs from set value %f\n", i, tFieldName, auxFloat, auxDoubleArrayW[i]); + GOTOFAILURE + } + } + break; + case TIFF_SETGET_DOUBLE: + /*-- Unfortunately, TIFF_SETGET_DOUBLE is used for TIFF_RATIONAL but those have to be read with FLOAT !!! */ + /* Only after update with Rational2Double feature, also TIFF_RATIONAL can be read in double precision!!! */ + /* Therefore, use a union to avoid overflow in TIFFGetField() return value + * and depending on version check for the right interface here: + * - old interface: correct value should be here a float + * - new interface: correct value should be here a double + * Interface version (old/new) is determined above. + */ + if (!TIFFGetField(tif, tTag, &auxDblUnion.dbl)) { + fprintf(stderr, "Can't read %s\n", tFieldArray->fields[i].field_name); + GOTOFAILURE + break; + } + if (tType == TIFF_RATIONAL || tType == TIFF_SRATIONAL) { + if (blnIsRational2Double) { + /* New interface allows also double precision for TIFF_RATIONAL */ + auxDouble = auxDblUnion.dbl; + } + else { + /* Old interface reads TIFF_RATIONAL defined as TIFF_SETGET_DOUBLE alwasy as FLOAT */ + auxDouble = (double)auxDblUnion.flt1; + } + } else { + auxDouble = auxDblUnion.dbl; + } + /* compare read values with written ones */ + if (tType == TIFF_RATIONAL || tType == TIFF_SRATIONAL) dblDiffLimit = RATIONAL_EPS * auxDoubleArrayW[i]; else dblDiffLimit = 1e-6; + dblDiff = auxDouble - auxDoubleArrayW[i]; + if (fabs(dblDiff) > fabs(dblDiffLimit)) { + /*--: EXIFTAG_SUBJECTDISTANCE: LibTiff returns value of "-1.0" if numerator equals 4294967295 (0xFFFFFFFF) to indicate infinite distance! */ + if (!(tTag == EXIFTAG_SUBJECTDISTANCE && auxDouble == -1.0)) + fprintf(stderr, "%d:Read value of %s %f differs from set value %f\n", i, tFieldName, auxDouble, auxDoubleArrayW[i]); + GOTOFAILURE + } + break; + + case TIFF_SETGET_C0_FLOAT: + case TIFF_SETGET_C0_DOUBLE: + case TIFF_SETGET_C16_FLOAT: + case TIFF_SETGET_C16_DOUBLE: + case TIFF_SETGET_C32_FLOAT: + case TIFF_SETGET_C32_DOUBLE: + /* _Cxx_ just defines the size of the count parameter for the array as C0=char, C16=short or C32=long */ + /*-- Check, if it is a single parameter, a fixed array or a variable array */ + if (tWriteCount == 1) { + fprintf(stderr, "Reading: WriteCount for .set_field_type %d should be -1 or greather than 1! %s\n", tSetFieldType, tFieldArray->fields[i].field_name); + GOTOFAILURE + } else { + /*-- Either fix or variable array --*/ + /* For arrays, distinguishing between float or double is essential. */ + /* Now decide between fixed or variable array */ + if (tWriteCount > 1) { + /* fixed array with needed arraysize defined in .field_writecount */ + if (!TIFFGetField(tif, tTag, &pVoidArray)) { + fprintf(stderr, "Can't read %s\n", tFieldArray->fields[i].field_name); + GOTOFAILURE + break; + } + /* set tWriteCount to number of read samples for next steps */ + auxLong = tWriteCount; + } else { + /* Special treatment of variable array. */ + /* Dependent on Cxx, the count parameter is char, short or long. Therefore use unionLong! */ + if (!TIFFGetField(tif, tTag, &auxLongUnion, &pVoidArray)) { + fprintf(stderr, "Can't read %s\n", tFieldArray->fields[i].field_name); + GOTOFAILURE + break; + } + /* set tWriteCount to number of read samples for next steps */ + auxLong = auxLongUnion.Short1; + } + /* Save values from temporary array */ + if (tSetFieldType == TIFF_SETGET_C0_FLOAT || tSetFieldType == TIFF_SETGET_C16_FLOAT || tSetFieldType == TIFF_SETGET_C32_FLOAT) { + memcpy(&auxFloatArray, pVoidArray, (auxLong * sizeof(auxFloatArray[0]))); + /* compare read values with written ones */ + if (tType == TIFF_RATIONAL || tType == TIFF_SRATIONAL) dblDiffLimit = RATIONAL_EPS * auxDoubleArrayW[i]; else dblDiffLimit = 1e-6; + for (j = 0; j < auxLong; j++) { + dblDiff = auxFloatArray[j] - auxFloatArrayW[i + j]; + if (fabs(dblDiff) > fabs(dblDiffLimit)) { + /*if (auxFloatArray[j] != (float)auxFloatArrayW[i+j]) { */ + fprintf(stderr, "Read value %d of %s #%d %f differs from set value %f\n", i, tFieldName, j, auxFloatArray[j], auxFloatArrayW[i + j]); + GOTOFAILURE + } + } + } else { + memcpy(&auxDoubleArray, pVoidArray, (auxLong * sizeof(auxDoubleArray[0]))); + /* compare read values with written ones */ + if (tType == TIFF_RATIONAL || tType == TIFF_SRATIONAL) dblDiffLimit = RATIONAL_EPS * auxDoubleArrayW[i]; else dblDiffLimit = 1e-6; + for (j = 0; j < auxLong; j++) { + dblDiff = auxDoubleArray[j] - auxDoubleArrayW[i + j]; + if (fabs(dblDiff) > fabs(dblDiffLimit)) { + /*if (auxDoubleArray[j] != auxDoubleArrayW[i+j]) { */ + fprintf(stderr, "Read value %d of %s #%d %f differs from set value %f\n", i, tFieldName, j, auxDoubleArray[j], auxDoubleArrayW[i + j]); + GOTOFAILURE + } + } + } + } + break; + default: + fprintf(stderr, "SetFieldType %d not defined within reading switch for %s.\n", tSetFieldType, tFieldName); + }; /*-- switch() --*/ + } /* if () */ + } /*-- for() --*/ + + + } /* blnAllCustomTags */ /*==== END END - Automatically check all custom rational tags == READING END ===*/ + + + + TIFFClose(tif); + + /* All tests passed; delete file and exit with success status. */ +#ifdef FOR_AUTO_TESTING + unlink(filenameRead); +#endif + fprintf(stderr, "-------- Test finished OK ----------\n"); + return 0; + +failure: + /* + * Something goes wrong; close file and return unsuccessful status. + * Do not remove the file for further manual investigation. + */ + TIFFClose(tif); + fprintf(stderr, "-------- Test finished with FAILURE --------\n"); + return 1; +} From 8c4b470889b166dcb461efbdeec3ea0c8fc9b03d Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Thu, 27 Feb 2020 21:30:28 +0100 Subject: [PATCH 033/180] tif_dirwrite.c: qualify ToRationalEuclideanGCD() with static --- libtiff/tif_dirwrite.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libtiff/tif_dirwrite.c b/libtiff/tif_dirwrite.c index 6de1f7ea..d86c7b8f 100644 --- a/libtiff/tif_dirwrite.c +++ b/libtiff/tif_dirwrite.c @@ -2704,6 +2704,7 @@ void DoubleToSrational_direct(double value, long *num, long *denom) * 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, From edc16ac20a9eeeed1531855cf2da21359434f273 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Thu, 27 Feb 2020 21:50:59 +0100 Subject: [PATCH 034/180] tif_dirwrite.c: fix various warnings found when building GDAL with internal libtiff after 6df997c786928757caea0dd68d26ea5f098f49df changes --- libtiff/tif_dirwrite.c | 51 +++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/libtiff/tif_dirwrite.c b/libtiff/tif_dirwrite.c index d86c7b8f..e6e7000f 100644 --- a/libtiff/tif_dirwrite.c +++ b/libtiff/tif_dirwrite.c @@ -162,10 +162,12 @@ static int TIFFWriteDirectoryTagRationalDoubleArray(TIFF* tif, uint32* ndir, TIF 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); -void DoubleToRational(double f, uint32 *num, uint32 *denom); -void DoubleToSrational(double f, int32 *num, int32 *denom); -void DoubleToRational_direct(double value, unsigned long *num, unsigned long *denom); -void DoubleToSrational_direct(double value, long *num, long *denom); +static void DoubleToRational(double f, uint32 *num, uint32 *denom); +static void DoubleToSrational(double f, 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); @@ -2609,7 +2611,8 @@ TIFFWriteDirectoryTagCheckedSrationalDoubleArray(TIFF* tif, uint32* ndir, TIFFDi return(o); } /*--- TIFFWriteDirectoryTagCheckedSrationalDoubleArray() -------- */ - +#if 0 +static void DoubleToRational_direct(double value, unsigned long *num, unsigned long *denom) { /*--- OLD Code for debugging and comparison ---- */ @@ -2639,8 +2642,10 @@ void DoubleToRational_direct(double value, unsigned long *num, unsigned long *de *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 ----*/ @@ -2686,7 +2691,7 @@ void DoubleToSrational_direct(double value, long *num, long *denom) } } } /*-- DoubleToSrational_direct() --------------*/ - +#endif //#define DOUBLE2RAT_DEBUGOUTPUT /** ----- Rational2Double: Double To Rational Conversion ---------------------------------------------------------- @@ -2813,6 +2818,7 @@ void ToRationalEuclideanGCD(double value, int blnUseSignedRange, int blnUseSmall * 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 ---- */ @@ -2828,20 +2834,20 @@ void DoubleToRational(double value, uint32 *num, uint32 *denom) /*-- Check for too big numbers (> ULONG_MAX) -- */ if (value > 0xFFFFFFFFUL) { - *num = 0xFFFFFFFFUL; + *num = 0xFFFFFFFFU; *denom = 0; return; } /*-- Check for easy integer numbers -- */ if (value == (unsigned long)(value)) { - *num = (unsigned long)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 = 0xFFFFFFFFUL; + *denom = 0xFFFFFFFFU; return; } @@ -2853,7 +2859,11 @@ void DoubleToRational(double value, uint32 *num, uint32 *denom) 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: DoubeToRational()", " 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: DoubeToRational()", " Num or Denom exceeds ULONG: val=%14.6f, num=%12llu, denom=%12llu | num2=%12llu, denom2=%12llu", value, ullNum, ullDenom, ullNum2, ullDenom2); +#endif assert(0); } @@ -2861,12 +2871,12 @@ void DoubleToRational(double value, uint32 *num, uint32 *denom) dblDiff = fabs(value - ((double)ullNum / (double)ullDenom)); dblDiff2 = fabs(value - ((double)ullNum2 / (double)ullDenom2)); if (dblDiff < dblDiff2) { - *num = (unsigned long)ullNum; - *denom = (unsigned long)ullDenom; + *num = (uint32)ullNum; + *denom = (uint32)ullDenom; } else { - *num = (unsigned long)ullNum2; - *denom = (unsigned long)ullDenom2; + *num = (uint32)ullNum2; + *denom = (uint32)ullDenom2; } } /*-- DoubleToRational() -------------- */ @@ -2875,6 +2885,7 @@ void DoubleToRational(double value, uint32 *num, uint32 *denom) * 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 ----*/ @@ -2913,7 +2924,11 @@ void DoubleToSrational(double value, int32 *num, int32 *denom) 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: DoubeToSrational()", " 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: DoubeToSrational()", " 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); } @@ -2921,12 +2936,12 @@ void DoubleToSrational(double value, int32 *num, int32 *denom) dblDiff = fabs(value - ((double)ullNum / (double)ullDenom)); dblDiff2 = fabs(value - ((double)ullNum2 / (double)ullDenom2)); if (dblDiff < dblDiff2) { - *num = (long)(neg * (long)ullNum); - *denom = (long)ullDenom; + *num = (uint32)(neg * (long)ullNum); + *denom = (uint32)ullDenom; } else { - *num = (long)(neg * (long)ullNum2); - *denom = (long)ullDenom2; + *num = (uint32)(neg * (long)ullNum2); + *denom = (uint32)ullDenom2; } } /*-- DoubleToSrational() --------------*/ From 721120d0d7bac96d489c9ba5c1652730cc91419f Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Thu, 27 Feb 2020 22:00:41 +0100 Subject: [PATCH 035/180] rational_precision2double.c: fix many warnings, and do not build it on CMake on shared lib builds --- test/CMakeLists.txt | 4 ++++ test/rational_precision2double.c | 37 ++++++++------------------------ 2 files changed, 13 insertions(+), 28 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 183b64d4..50904599 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -194,8 +194,12 @@ endif() add_executable(custom_dir custom_dir.c) target_link_libraries(custom_dir tiff port) +if(NOT BUILD_SHARED_LIBS) add_executable(rational_precision2double rational_precision2double.c) target_link_libraries(rational_precision2double tiff port) +add_test(NAME "rational_precision2double" + COMMAND "rational_precision2double") +endif() add_executable(defer_strile_loading defer_strile_loading.c) target_link_libraries(defer_strile_loading tiff port) diff --git a/test/rational_precision2double.c b/test/rational_precision2double.c index 63e2978d..782fb9fa 100644 --- a/test/rational_precision2double.c +++ b/test/rational_precision2double.c @@ -46,8 +46,9 @@ #define GOTOFAILURE #endif - +#ifdef _MSC_VER #pragma warning( disable : 4101) +#endif #include "tif_config.h" #include @@ -153,6 +154,7 @@ _XTIFFDefaultDirectory(TIFF *tif) n = N(tifFieldInfo); //_TIFFMergeFields(tif, const TIFFField info[], uint32 n); nadded = _TIFFMergeFields(tif, tifFieldInfo, n); + (void)nadded; /* Since an XTIFF client module may have overridden * the default directory method, we call it now to @@ -182,7 +184,7 @@ main() /* delete file, if exists */ ret = unlink(filenameClassicTiff); errorNo = errno; - if (ret != 0 && errno != ENOENT) { + if (ret != 0 && errorNo != ENOENT) { fprintf(stderr, "Can't delete test TIFF file %s.\n", filenameClassicTiff); } @@ -199,7 +201,7 @@ main() /*--- Test with BIG-TIFF ---*/ /* delete file, if exists */ ret = unlink(filenameBigTiff); - if (ret != 0 && errno != ENOENT) { + if (ret != 0 && errorNo != ENOENT) { fprintf(stderr, "Can't delete test TIFF file %s.\n", filenameBigTiff); } @@ -218,7 +220,7 @@ main() /* delete file, if exists */ ret = unlink(filenameClassicTiff); errorNo = errno; - if (ret != 0 && errno != ENOENT) { + if (ret != 0 && errorNo != ENOENT) { fprintf(stderr, "Can't delete test TIFF file %s.\n", filenameClassicTiff); } @@ -256,9 +258,7 @@ int write_test_tiff(TIFF* tif, const char* filenameRead, int blnAllCustomTags) { unsigned char buf[SPP] = {0, 127, 255}; /*-- Additional variables --*/ - int retCode, retCode2; - unsigned char* pGpsVersion; - char auxStr[200]; + int retCode; float auxFloat = 0.0f; double auxDouble = 0.0; uint16 auxUint16 = 0; @@ -271,7 +271,6 @@ write_test_tiff(TIFF* tif, const char* filenameRead, int blnAllCustomTags) { long nTags; const TIFFFieldArray* tFieldArray; - const TIFFField** tifFields; /* actual field info */ unsigned long tTag; TIFFDataType tType; short tWriteCount; @@ -286,9 +285,6 @@ write_test_tiff(TIFF* tif, const char* filenameRead, int blnAllCustomTags) { #define VARIABLE_ARRAY_SIZE 6 /* -- Test data for writing -- */ - char auxCharArrayW[N_SIZE]; - short auxShortArrayW[N_SIZE]; - long auxLongArrayW[N_SIZE]; float auxFloatArrayW[N_SIZE]; double auxDoubleArrayW[N_SIZE]; char auxTextArrayW[N_SIZE][STRSIZE]; @@ -309,18 +305,12 @@ write_test_tiff(TIFF* tif, const char* filenameRead, int blnAllCustomTags) { float flt2; } auxDblUnion; - float* pFloat; void* pVoidArray; float* pFloatArray; - double* pDoubleArray; - char* pAscii; - char auxCharArray[2 * STRSIZE]; - short auxShortArray[2 * N_SIZE]; - long auxLongArray[2 * N_SIZE]; float auxFloatArray[2 * N_SIZE]; double auxDoubleArray[2 * N_SIZE]; double dblDiff, dblDiffLimit; - float fltDiff, fltDiffLimit; + float fltDiff; #define RATIONAL_EPS (1.0/30000.0) /* reduced difference of rational values, approx 3.3e-5 */ @@ -328,15 +318,6 @@ write_test_tiff(TIFF* tif, const char* filenameRead, int blnAllCustomTags) { for (i = 0; i < N_SIZE; i++) { sprintf(auxTextArrayW[i], "N%d-String-%d_tttttttttttttttttttttttttttttx", i, i); } - for (i = 0; i < N_SIZE; i++) { - auxCharArrayW[i] = (char)(i + 1); - } - for (i = 0; i < N_SIZE; i++) { - auxShortArrayW[i] = (short)(i + 1) * 7; - } - for (i = 0; i < N_SIZE; i++) { - auxLongArrayW[i] = (i + 1) * 133; - } for (i = 0; i < N_SIZE; i++) { auxFloatArrayW[i] = (float)((i + 1) * 133) / 3.3f; } @@ -601,7 +582,7 @@ write_test_tiff(TIFF* tif, const char* filenameRead, int blnAllCustomTags) { } /* blnAllCustomTags */ /*==== END END - Automatically check all custom rational tags == WRITING END ===*/ /*-- Write dummy pixel data. --*/ - if (!TIFFWriteScanline(tif, buf, 0, 0) < 0) { + if (TIFFWriteScanline(tif, buf, 0, 0) < 0) { fprintf (stderr, "Can't write image data.\n"); goto failure; } From 388a1dba724c6a6f5a2b40d4f72672bb6976a7b0 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Thu, 27 Feb 2020 22:02:58 +0100 Subject: [PATCH 036/180] tif_dirwrite.c: fix other warnings related to 6df997c786928757caea0dd68d26ea5f098f49df changes --- libtiff/tif_dirwrite.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libtiff/tif_dirwrite.c b/libtiff/tif_dirwrite.c index e6e7000f..59e3bad5 100644 --- a/libtiff/tif_dirwrite.c +++ b/libtiff/tif_dirwrite.c @@ -2839,7 +2839,7 @@ void DoubleToRational(double value, uint32 *num, uint32 *denom) return; } /*-- Check for easy integer numbers -- */ - if (value == (unsigned long)(value)) { + if (value == (uint32)(value)) { *num = (uint32)value; *denom = 1; return; @@ -2903,8 +2903,8 @@ void DoubleToSrational(double value, int32 *num, int32 *denom) return; } /*-- Check for easy numbers -- */ - if (value == (long)(value)) { - *num = (long)value; + if (value == (uint32)(value)) { + *num = (uint32)value; *denom = 1; return; } From facb37f1491c3ef54b0be6a5fb6e7fcef3acc7d4 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Fri, 28 Feb 2020 20:40:27 +0100 Subject: [PATCH 037/180] ToRationalEuclideanGCD: remove useless test that confuses Coverity Scan about a potential later modulo by zero --- libtiff/tif_dirwrite.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libtiff/tif_dirwrite.c b/libtiff/tif_dirwrite.c index 59e3bad5..97761106 100644 --- a/libtiff/tif_dirwrite.c +++ b/libtiff/tif_dirwrite.c @@ -2770,7 +2770,7 @@ void ToRationalEuclideanGCD(double value, int blnUseSignedRange, int blnUseSmall /* if bigDenom is not zero, calculate integer part of fraction. */ if (bigDenom == 0) { val = 0; - if (i > 0) break; /* if bigDenom is zero, exit loop, but execute loop just once */ + break; } else { val = bigNum / bigDenom; From a6fa499e200269e6abdf511807c13d224e18f182 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sat, 29 Feb 2020 01:17:17 +0100 Subject: [PATCH 038/180] typo fixes in code comments --- libtiff/tif_dir.c | 4 ++-- libtiff/tif_dirwrite.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libtiff/tif_dir.c b/libtiff/tif_dir.c index e59f1633..47927a84 100644 --- a/libtiff/tif_dir.c +++ b/libtiff/tif_dir.c @@ -710,7 +710,7 @@ _TIFFVSetField(TIFF* tif, uint32 tag, va_list ap) double v2 = va_arg(ap, double); _TIFFmemcpy(val, &v2, tv_size); } else { - /*-- default schould be tv_size == 4 */ + /*-- 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. */ @@ -1229,7 +1229,7 @@ _TIFFVGetField(TIFF* tif, uint32 tag, va_list ap) *va_arg(ap, double*) = *(double *)val; ret_val = 1; } else { - /*-- default schould be tv_size == 4 */ + /*-- 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. */ diff --git a/libtiff/tif_dirwrite.c b/libtiff/tif_dirwrite.c index 97761106..410c8adb 100644 --- a/libtiff/tif_dirwrite.c +++ b/libtiff/tif_dirwrite.c @@ -819,7 +819,7 @@ TIFFWriteDirectorySec(TIFF* tif, int isimage, int imagedone, uint64* pdiroff) if (!TIFFWriteDirectoryTagRationalDoubleArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value)) goto bad; } else { - /*-- default schould be tv_size == 4 */ + /*-- 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. */ @@ -838,7 +838,7 @@ TIFFWriteDirectorySec(TIFF* tif, int isimage, int imagedone, uint64* pdiroff) if (!TIFFWriteDirectoryTagSrationalDoubleArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value)) goto bad; } else { - /*-- default schould be tv_size == 4 */ + /*-- 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. */ @@ -2556,7 +2556,7 @@ TIFFWriteDirectoryTagCheckedSrationalArray(TIFF* tif, uint32* ndir, TIFFDirEntry return(o); } -/*-- Rational2Double: additonal write functions for double arrays */ +/*-- Rational2Double: additional write functions for double arrays */ static int TIFFWriteDirectoryTagCheckedRationalDoubleArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, double* value) { From c4710ee22625cc3104ac12b3a19298675b664d88 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Sun, 16 Feb 2020 18:51:49 +0100 Subject: [PATCH 039/180] tif_fax3.c: check buffer overflow in Fax4Decode() fixes #174 --- libtiff/tif_fax3.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libtiff/tif_fax3.c b/libtiff/tif_fax3.c index d11c9684..5ad52254 100644 --- a/libtiff/tif_fax3.c +++ b/libtiff/tif_fax3.c @@ -1453,6 +1453,8 @@ 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 overflow */ + return -1; (*sp->fill)(buf, thisrun, pa, lastx); SETVALUE(0); /* imaginary change for reference */ SWAP(uint32*, sp->curruns, sp->refruns); @@ -1468,6 +1470,8 @@ 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 overflow */ + return -1; (*sp->fill)(buf, thisrun, pa, lastx); UNCACHE_STATE(tif, sp); return ( sp->line ? 1 : -1); /* don't error on badly-terminated strips */ From df38126420f13fc7d66903eb28bfa6f6adeaf7ca Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Sat, 29 Feb 2020 11:24:49 +0100 Subject: [PATCH 040/180] Fax4Decode(): log error message in case of buffer overrun --- libtiff/tif_fax3.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/libtiff/tif_fax3.c b/libtiff/tif_fax3.c index 5ad52254..4809eabf 100644 --- a/libtiff/tif_fax3.c +++ b/libtiff/tif_fax3.c @@ -1453,8 +1453,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 overflow */ + 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); @@ -1470,8 +1475,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 overflow */ + 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 */ From 30222c13d66545b6e3a278059117be104cf341cd Mon Sep 17 00:00:00 2001 From: Su_Laus Date: Sat, 29 Feb 2020 17:59:59 +0100 Subject: [PATCH 041/180] 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). --- libtiff/tif_dirwrite.c | 18 +++++++++--------- test/rational_precision2double.c | 5 +++-- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/libtiff/tif_dirwrite.c b/libtiff/tif_dirwrite.c index 410c8adb..4c622804 100644 --- a/libtiff/tif_dirwrite.c +++ b/libtiff/tif_dirwrite.c @@ -162,8 +162,8 @@ static int TIFFWriteDirectoryTagRationalDoubleArray(TIFF* tif, uint32* ndir, TIF 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 f, uint32 *num, uint32 *denom); -static void DoubleToSrational(double f, int32 *num, int32 *denom); +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); @@ -2893,7 +2893,7 @@ void DoubleToSrational(double value, int32 *num, int32 *denom) double dblDiff, dblDiff2; unsigned long long ullNum, ullDenom, ullNum2, ullDenom2; - /*-- Check for negative values and use then the positive one for internal calculations. */ + /*-- 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) -- */ @@ -2903,8 +2903,8 @@ void DoubleToSrational(double value, int32 *num, int32 *denom) return; } /*-- Check for easy numbers -- */ - if (value == (uint32)(value)) { - *num = (uint32)value; + if (value == (int32)(value)) { + *num = (int32)(neg * value); *denom = 1; return; } @@ -2936,12 +2936,12 @@ void DoubleToSrational(double value, int32 *num, int32 *denom) dblDiff = fabs(value - ((double)ullNum / (double)ullDenom)); dblDiff2 = fabs(value - ((double)ullNum2 / (double)ullDenom2)); if (dblDiff < dblDiff2) { - *num = (uint32)(neg * (long)ullNum); - *denom = (uint32)ullDenom; + *num = (int32)(neg * (long)ullNum); + *denom = (int32)ullDenom; } else { - *num = (uint32)(neg * (long)ullNum2); - *denom = (uint32)ullDenom2; + *num = (int32)(neg * (long)ullNum2); + *denom = (int32)ullDenom2; } } /*-- DoubleToSrational() --------------*/ diff --git a/test/rational_precision2double.c b/test/rational_precision2double.c index 782fb9fa..e33cc97d 100644 --- a/test/rational_precision2double.c +++ b/test/rational_precision2double.c @@ -498,7 +498,8 @@ write_test_tiff(TIFF* tif, const char* filenameRead, int blnAllCustomTags) { fprintf(stderr, "Can't set TIFFTAG_RATIONAL_DOUBLE tag.\n"); goto failure; } - if (!TIFFSetField(tif, TIFFTAG_SRATIONAL_DOUBLE, (-1.0 * auxDoubleArrayW[101]))) { + /* test for plain integers */ + if (!TIFFSetField(tif, TIFFTAG_SRATIONAL_DOUBLE, (-1.0 ))) { fprintf(stderr, "Can't set TIFFTAG_SRATIONAL_DOUBLE tag.\n"); goto failure; } @@ -764,7 +765,7 @@ write_test_tiff(TIFF* tif, const char* filenameRead, int blnAllCustomTags) { auxDblUnion.dbl = 0; retCode = TIFFGetField(tif, TIFFTAG_SRATIONAL_DOUBLE, &auxDblUnion.dbl); if (!retCode) { fprintf(stderr, "Can't read %s\n", "TIFFTAG_SRATIONAL_DOUBLE"); GOTOFAILURE } - auxDouble = -1.0 * auxDoubleArrayW[101]; + auxDouble = -1.0; dblDiffLimit = RATIONAL_EPS * auxDouble; dblDiff = auxDblUnion.dbl - auxDouble; if (fabs(dblDiff) > fabs(dblDiffLimit)) { From 02bb01750fd03cdc4a429a02b26a6bdaa250ab4e Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Sat, 29 Feb 2020 23:30:07 +0100 Subject: [PATCH 042/180] 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 --- libtiff/tif_fax3.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/libtiff/tif_fax3.h b/libtiff/tif_fax3.h index abadcd97..861a5100 100644 --- a/libtiff/tif_fax3.h +++ b/libtiff/tif_fax3.h @@ -478,11 +478,9 @@ done1d: \ 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; \ From 72c4acef4b554c2f658802eb7529966334cd1c4a Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Sun, 1 Mar 2020 00:38:59 +0100 Subject: [PATCH 043/180] tif_fax3: better fix for CVE-2011-0192 There are some legitimate case which were forbidden by the previous fix --- libtiff/tif_fax3.c | 15 ++++++++------- libtiff/tif_fax3.h | 5 +++++ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/libtiff/tif_fax3.c b/libtiff/tif_fax3.c index 4809eabf..e82878f9 100644 --- a/libtiff/tif_fax3.c +++ b/libtiff/tif_fax3.c @@ -73,6 +73,7 @@ typedef struct { int EOLcnt; /* count of EOL codes recognized */ TIFFFaxFillFunc fill; /* fill routine */ uint32* runs; /* b&w runs for current/previous row */ + uint32 nruns; /* size of the refruns / curruns arrays */ uint32* refruns; /* runs for reference line */ uint32* curruns; /* runs for current line */ @@ -506,7 +507,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, @@ -539,26 +540,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 diff --git a/libtiff/tif_fax3.h b/libtiff/tif_fax3.h index 861a5100..f3073ef8 100644 --- a/libtiff/tif_fax3.h +++ b/libtiff/tif_fax3.h @@ -387,6 +387,11 @@ 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); \ + break; \ + } \ LOOKUP8(7, TIFFFaxMainTable, eof2d); \ switch (TabEnt->State) { \ case S_Pass: \ From 25b274126d80473effec5c3296b2c9d8fdb3305c Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sun, 1 Mar 2020 22:22:01 +0100 Subject: [PATCH 044/180] 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 --- libtiff/tif_dirread.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libtiff/tif_dirread.c b/libtiff/tif_dirread.c index dee22576..6523dd78 100644 --- a/libtiff/tif_dirread.c +++ b/libtiff/tif_dirread.c @@ -4441,6 +4441,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) From 794ec1ad50308c2335b39f5e5819c98212e76055 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Sun, 1 Mar 2020 22:25:29 +0100 Subject: [PATCH 045/180] 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 --- html/bigtiffpr.html | 2 +- html/build.html | 2 +- html/index.html | 2 +- html/libtiff.html | 2 +- html/support.html | 2 +- html/tools.html | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/html/bigtiffpr.html b/html/bigtiffpr.html index b7a36c6b..578c46f2 100644 --- a/html/bigtiffpr.html +++ b/html/bigtiffpr.html @@ -5,7 +5,7 @@ - +

Extending LibTiff library with support for the new BigTIFF format

LibTiff maintainers have started work on LibTiff 4.0, diff --git a/html/build.html b/html/build.html index 77fbc40b..fbd92d7d 100644 --- a/html/build.html +++ b/html/build.html @@ -5,7 +5,7 @@ "HTML Tidy for Linux (vers 25 March 2009), see www.w3.org"> Building the TIFF Software Distribution - +

Building the Software Distribution

diff --git a/html/index.html b/html/index.html index dca511e7..43d643be 100644 --- a/html/index.html +++ b/html/index.html @@ -10,7 +10,7 @@ --> - +

LibTIFF - TIFF Library and Utilities


diff --git a/html/libtiff.html b/html/libtiff.html index d6b5eab3..cda66b5a 100644 --- a/html/libtiff.html +++ b/html/libtiff.html @@ -10,7 +10,7 @@ --> - +
diff --git a/html/support.html b/html/support.html index 2330d40a..e29d2d0d 100644 --- a/html/support.html +++ b/html/support.html @@ -10,7 +10,7 @@ --> - +
diff --git a/html/tools.html b/html/tools.html index 7b99d71d..c669543a 100644 --- a/html/tools.html +++ b/html/tools.html @@ -5,7 +5,7 @@ "HTML Tidy for Solaris (vers 12 April 2005), see www.w3.org"> TIFF Tools Overview - +

TIFF Tools Overview

From 535830c277b19da4ee63eb67baaf98b433f9d031 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Sun, 1 Mar 2020 22:26:55 +0100 Subject: [PATCH 046/180] index.html: fix unclosed tag --- html/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/html/index.html b/html/index.html index 43d643be..9ed858b4 100644 --- a/html/index.html +++ b/html/index.html @@ -44,7 +44,7 @@ - +
git repositoryhttps://gitlab.com/libtiff/libtiffhttps://gitlab.com/libtiff/libtiff

From b351db8be1b4d3f712bdb9424a79d3174cc03202 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Thu, 5 Mar 2020 10:27:04 +0100 Subject: [PATCH 047/180] 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. --- libtiff/tif_fax3.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libtiff/tif_fax3.h b/libtiff/tif_fax3.h index f3073ef8..b8edc26e 100644 --- a/libtiff/tif_fax3.h +++ b/libtiff/tif_fax3.h @@ -514,7 +514,9 @@ done1d: \ goto eol2d; \ eof2d: \ prematureEOF(a0); \ - CLEANUP_RUNS(); \ + if (pa < thisrun + sp->nruns) { \ + CLEANUP_RUNS(); \ + } \ goto eoflab; \ } \ } \ From 690cc7a701415325be6813ec25e83bb832f1a984 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Thu, 5 Mar 2020 11:38:31 +0100 Subject: [PATCH 048/180] fix HTML files so they are valid according to https://validator.w3.org --- html/addingtags.html | 17 ++++++---- html/bigtiffdesign.html | 5 +-- html/bugs.html | 13 ++++--- html/build.html | 14 ++++---- html/contrib.html | 17 ++++++---- html/document.html | 11 ++++-- html/images.html | 11 ++++-- html/internals.html | 75 +++++++++++++++++++++++------------------ html/intro.html | 13 ++++--- html/misc.html | 16 +++++---- html/tools.html | 17 ++++++---- 11 files changed, 129 insertions(+), 80 deletions(-) diff --git a/html/addingtags.html b/html/addingtags.html index c61a2623..bd4b972a 100644 --- a/html/addingtags.html +++ b/html/addingtags.html @@ -1,11 +1,16 @@ + Modifying The TIFF Library + - - +

Defining New TIFF Tags @@ -198,8 +203,8 @@ If tag definitions are only required for writing custom tags, you can just call TIFFMergeFieldInfo() before setting new tags. The whole extender architecture can then be avoided.

-

Adding New Builtin Tags

- +

Adding New Builtin Tags

+

A similar approach is taken to the above. However, the TIFFFieldInfo should be added to the tiffFieldInfo[] list in tif_dirinfo.c. Ensure that new tags are added in sorted order by the tag number.

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

Adding New Codec-private Tags

- +

Adding New Codec-private Tags

+

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

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

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

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

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

    If you'd like to inform us about some kind of security issue that should not be disclosed for a period of time, then you can contact maintainers directly. diff --git a/html/build.html b/html/build.html index fbd92d7d..4186645b 100644 --- a/html/build.html +++ b/html/build.html @@ -1,14 +1,16 @@ - Building the TIFF Software Distribution + -

    Building the Software Distribution

    +

    cramps +Building the Software Distribution