summaryrefslogtreecommitdiff
path: root/tiff/test
diff options
context:
space:
mode:
Diffstat (limited to 'tiff/test')
-rw-r--r--tiff/test/CMakeLists.txt47
-rw-r--r--tiff/test/Makefile.am28
-rw-r--r--tiff/test/Makefile.in129
-rw-r--r--tiff/test/common.sh3
-rw-r--r--tiff/test/custom_dir_EXIF_231.c1398
-rw-r--r--tiff/test/defer_strile_loading.c13
-rw-r--r--tiff/test/images/README.txt3
-rw-r--r--tiff/test/images/deflate-last-strip-extra-data.tiffbin0 -> 12789 bytes
-rw-r--r--tiff/test/images/ojpeg_chewey_subsamp21_multi_strip.tiffbin0 -> 39752 bytes
-rw-r--r--tiff/test/images/ojpeg_single_strip_no_rowsperstrip.tiffbin0 -> 8258 bytes
-rw-r--r--tiff/test/images/ojpeg_zackthecat_subsamp22_single_strip.tiffbin0 -> 8258 bytes
-rw-r--r--tiff/test/images/rgb-3c-16b.ppmbin0 -> 142305 bytes
-rw-r--r--tiff/test/images/testfax4.tiffbin0 -> 39637 bytes
-rwxr-xr-xtiff/test/ppm2tiff_pbm.sh1
-rwxr-xr-xtiff/test/ppm2tiff_pgm.sh1
-rwxr-xr-xtiff/test/ppm2tiff_ppm.sh7
-rw-r--r--tiff/test/rational_precision2double.c972
-rw-r--r--tiff/test/refs/o-deflate-last-strip-extra-data.tiffbin0 -> 12560 bytes
-rw-r--r--tiff/test/refs/o-testfax4.tiffbin0 -> 106326 bytes
-rwxr-xr-xtiff/test/testdeflatelaststripextradata.sh43
-rwxr-xr-xtiff/test/testfax4.sh24
-rwxr-xr-xtiff/test/tiff2ps-EPS1.sh2
-rwxr-xr-xtiff/test/tiff2ps-PS1.sh3
-rwxr-xr-xtiff/test/tiff2ps-PS2.sh2
-rwxr-xr-xtiff/test/tiff2ps-PS3.sh2
-rwxr-xr-xtiff/test/tiff2rgba-ojpeg_chewey_subsamp21_multi_strip.sh7
-rwxr-xr-xtiff/test/tiff2rgba-ojpeg_single_strip_no_rowsperstrip.sh7
-rwxr-xr-xtiff/test/tiff2rgba-ojpeg_zackthecat_subsamp22_single_strip.sh7
28 files changed, 2664 insertions, 35 deletions
diff --git a/tiff/test/CMakeLists.txt b/tiff/test/CMakeLists.txt
index a4216d56d..bffb8bf77 100644
--- a/tiff/test/CMakeLists.txt
+++ b/tiff/test/CMakeLists.txt
@@ -105,7 +105,12 @@ set(TESTSCRIPTS
tiff2rgba-palette-1c-8b.sh
tiff2rgba-rgb-3c-16b.sh
tiff2rgba-rgb-3c-8b.sh
- tiff2rgba-quad-tile.jpg.sh)
+ tiff2rgba-quad-tile.jpg.sh
+ tiff2rgba-ojpeg_zackthecat_subsamp22_single_strip.sh
+ tiff2rgba-ojpeg_chewey_subsamp21_multi_strip.sh
+ tiff2rgba-ojpeg_single_strip_no_rowsperstrip.sh
+ testfax4.sh
+ testdeflatelaststripextradata.sh)
# This list should contain all of the TIFF files in the 'images'
# subdirectory which are intended to be used as input images for
@@ -123,7 +128,11 @@ set(TIFFIMAGES
images/rgb-3c-8b.tiff
images/quad-tile.jpg.tiff
images/quad-lzw-compat.tiff
- images/lzw-single-strip.tiff)
+ images/lzw-single-strip.tiff
+ images/ojpeg_zackthecat_subsamp22_single_strip.tiff
+ images/ojpeg_chewey_subsamp21_multi_strip.tiff
+ images/ojpeg_single_strip_no_rowsperstrip.tiff
+ images/testfax4.tiff)
set(BMPIMAGES
images/palette-1c-8b.bmp
@@ -135,6 +144,7 @@ set(GIFIMAGES
set(PNMIMAGES
images/minisblack-1c-8b.pgm
images/miniswhite-1c-1b.pbm
+ images/rgb-3c-16b.ppm
images/rgb-3c-8b.ppm)
# All uncompressed image files
@@ -188,6 +198,20 @@ endif()
add_executable(custom_dir custom_dir.c)
target_link_libraries(custom_dir tiff port)
+if(NOT BUILD_SHARED_LIBS)
+add_executable(rational_precision2double rational_precision2double.c)
+target_link_libraries(rational_precision2double tiff port)
+add_test(NAME "rational_precision2double"
+ COMMAND "rational_precision2double")
+endif()
+
+if(NOT BUILD_SHARED_LIBS)
+add_executable(custom_dir_EXIF_231 custom_dir_EXIF_231.c)
+target_link_libraries(custom_dir_EXIF_231 tiff port)
+add_test(NAME "custom_dir_EXIF_231"
+ COMMAND "custom_dir_EXIF_231")
+endif()
+
add_executable(defer_strile_loading defer_strile_loading.c)
target_link_libraries(defer_strile_loading tiff port)
@@ -197,6 +221,24 @@ target_link_libraries(defer_strile_writing tiff port)
add_executable(testtypes testtypes.c)
target_link_libraries(testtypes tiff port)
+if(WEBP_SUPPORT AND EMSCRIPTEN)
+ # Emscripten is pretty finnicky about linker flags.
+ # It needs --shared-memory if and only if atomics or bulk-memory is used.
+ foreach(target ascii_tag
+ custom_dir
+ defer_strile_loading
+ defer_strile_writing
+ long_tag
+ rewrite
+ short_tag
+ strip_rw)
+ target_link_options(${target} PUBLIC "-Wl,--shared-memory")
+ endforeach()
+ if(JPEG_SUPPORT)
+ target_link_options(raw_decode PUBLIC "-Wl,--shared-memory")
+ endif()
+endif()
+
set(TEST_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/output")
file(MAKE_DIRECTORY "${TEST_OUTPUT}")
@@ -338,6 +380,7 @@ add_convert_test(gif2tiff palette "" "images/palette-1c-8b.gif" TRUE)
# PPM
add_convert_test(ppm2tiff miniswhite "" "images/miniswhite-1c-1b.pbm" TRUE)
add_convert_test(ppm2tiff minisblack "" "images/minisblack-1c-8b.pgm" TRUE)
+add_convert_test(ppm2tiff rgb "" "images/rgb-3c-16b.ppm" TRUE)
add_convert_test(ppm2tiff rgb "" "images/rgb-3c-8b.ppm" TRUE)
# tiffcp
diff --git a/tiff/test/Makefile.am b/tiff/test/Makefile.am
index 90c2f3d1e..4973b6147 100644
--- a/tiff/test/Makefile.am
+++ b/tiff/test/Makefile.am
@@ -55,7 +55,11 @@ CLEANFILES = test_packbits.tif o-*
if HAVE_JPEG
JPEG_DEPENDENT_CHECK_PROG=raw_decode
JPEG_DEPENDENT_TESTSCRIPTS=\
- tiff2rgba-quad-tile.jpg.sh
+ tiff2rgba-quad-tile.jpg.sh \
+ tiff2rgba-ojpeg_zackthecat_subsamp22_single_strip.sh \
+ tiff2rgba-ojpeg_chewey_subsamp21_multi_strip.sh \
+ tiff2rgba-ojpeg_single_strip_no_rowsperstrip.sh
+
else
JPEG_DEPENDENT_CHECK_PROG=
JPEG_DEPENDENT_TESTSCRIPTS=
@@ -63,8 +67,8 @@ endif
# Executable programs which need to be built in order to support tests
check_PROGRAMS = \
- ascii_tag long_tag short_tag strip_rw rewrite custom_dir \
- defer_strile_loading defer_strile_writing testtypes \
+ ascii_tag long_tag short_tag strip_rw rewrite custom_dir custom_dir_EXIF_231 \
+ rational_precision2double defer_strile_loading defer_strile_writing testtypes \
$(JPEG_DEPENDENT_CHECK_PROG)
# Test scripts to execute
@@ -145,6 +149,8 @@ TESTSCRIPTS = \
tiff2rgba-palette-1c-8b.sh \
tiff2rgba-rgb-3c-16b.sh \
tiff2rgba-rgb-3c-8b.sh \
+ testfax4.sh \
+ testdeflatelaststripextradata.sh \
$(JPEG_DEPENDENT_TESTSCRIPTS)
# This list should contain the references files
@@ -153,7 +159,9 @@ REFFILES = \
refs/o-tiff2ps-EPS1.ps \
refs/o-tiff2ps-PS1.ps \
refs/o-tiff2ps-PS2.ps \
- refs/o-tiff2ps-PS3.ps
+ refs/o-tiff2ps-PS3.ps \
+ refs/o-testfax4.tiff \
+ refs/o-deflate-last-strip-extra-data.tiff
# This list should contain all of the TIFF files in the 'images'
# subdirectory which are intended to be used as input images for
@@ -171,11 +179,17 @@ TIFFIMAGES = \
images/rgb-3c-8b.tiff \
images/quad-tile.jpg.tiff \
images/quad-lzw-compat.tiff \
- images/lzw-single-strip.tiff
+ images/lzw-single-strip.tiff \
+ images/ojpeg_zackthecat_subsamp22_single_strip.tiff \
+ images/ojpeg_chewey_subsamp21_multi_strip.tiff \
+ images/ojpeg_single_strip_no_rowsperstrip.tiff \
+ images/testfax4.tiff \
+ images/deflate-last-strip-extra-data.tiff
PNMIMAGES = \
images/minisblack-1c-8b.pgm \
images/miniswhite-1c-1b.pbm \
+ images/rgb-3c-16b.ppm \
images/rgb-3c-8b.ppm
# This list should include all of the files in the 'images'
@@ -203,6 +217,10 @@ raw_decode_SOURCES = raw_decode.c
raw_decode_LDADD = $(LIBTIFF)
custom_dir_SOURCES = custom_dir.c
custom_dir_LDADD = $(LIBTIFF)
+rational_precision2double_SOURCES = rational_precision2double.c
+rational_precision2double_LDADD = $(LIBTIFF)
+custom_dir_EXIF_231_SOURCES = custom_dir_EXIF_231.c
+custom_dir_EXIF_231_LDADD = $(LIBTIFF)
defer_strile_loading_SOURCES = defer_strile_loading.c
defer_strile_loading_LDADD = $(LIBTIFF)
defer_strile_writing_SOURCES = defer_strile_writing.c
diff --git a/tiff/test/Makefile.in b/tiff/test/Makefile.in
index 5a2f0607a..15b7b8265 100644
--- a/tiff/test/Makefile.in
+++ b/tiff/test/Makefile.in
@@ -1,7 +1,7 @@
-# Makefile.in generated by automake 1.16.1 from Makefile.am.
+# Makefile.in generated by automake 1.16.2 from Makefile.am.
# @configure_input@
-# Copyright (C) 1994-2018 Free Software Foundation, Inc.
+# Copyright (C) 1994-2020 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -117,9 +117,10 @@ TESTS = $(check_PROGRAMS) $(am__EXEEXT_3)
XFAIL_TESTS =
check_PROGRAMS = ascii_tag$(EXEEXT) long_tag$(EXEEXT) \
short_tag$(EXEEXT) strip_rw$(EXEEXT) rewrite$(EXEEXT) \
- custom_dir$(EXEEXT) defer_strile_loading$(EXEEXT) \
- defer_strile_writing$(EXEEXT) testtypes$(EXEEXT) \
- $(am__EXEEXT_1)
+ custom_dir$(EXEEXT) custom_dir_EXIF_231$(EXEEXT) \
+ rational_precision2double$(EXEEXT) \
+ defer_strile_loading$(EXEEXT) defer_strile_writing$(EXEEXT) \
+ testtypes$(EXEEXT) $(am__EXEEXT_1)
subdir = test
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/acinclude.m4 \
@@ -146,6 +147,9 @@ am__v_lt_1 =
am_custom_dir_OBJECTS = custom_dir.$(OBJEXT)
custom_dir_OBJECTS = $(am_custom_dir_OBJECTS)
custom_dir_DEPENDENCIES = $(LIBTIFF)
+am_custom_dir_EXIF_231_OBJECTS = custom_dir_EXIF_231.$(OBJEXT)
+custom_dir_EXIF_231_OBJECTS = $(am_custom_dir_EXIF_231_OBJECTS)
+custom_dir_EXIF_231_DEPENDENCIES = $(LIBTIFF)
am_defer_strile_loading_OBJECTS = defer_strile_loading.$(OBJEXT)
defer_strile_loading_OBJECTS = $(am_defer_strile_loading_OBJECTS)
defer_strile_loading_DEPENDENCIES = $(LIBTIFF)
@@ -155,6 +159,11 @@ defer_strile_writing_DEPENDENCIES = $(LIBTIFF)
am_long_tag_OBJECTS = long_tag.$(OBJEXT) check_tag.$(OBJEXT)
long_tag_OBJECTS = $(am_long_tag_OBJECTS)
long_tag_DEPENDENCIES = $(LIBTIFF)
+am_rational_precision2double_OBJECTS = \
+ rational_precision2double.$(OBJEXT)
+rational_precision2double_OBJECTS = \
+ $(am_rational_precision2double_OBJECTS)
+rational_precision2double_DEPENDENCIES = $(LIBTIFF)
am_raw_decode_OBJECTS = raw_decode.$(OBJEXT)
raw_decode_OBJECTS = $(am_raw_decode_OBJECTS)
raw_decode_DEPENDENCIES = $(LIBTIFF)
@@ -188,8 +197,10 @@ depcomp = $(SHELL) $(top_srcdir)/config/depcomp
am__maybe_remake_depfiles = depfiles
am__depfiles_remade = ./$(DEPDIR)/ascii_tag.Po \
./$(DEPDIR)/check_tag.Po ./$(DEPDIR)/custom_dir.Po \
+ ./$(DEPDIR)/custom_dir_EXIF_231.Po \
./$(DEPDIR)/defer_strile_loading.Po \
./$(DEPDIR)/defer_strile_writing.Po ./$(DEPDIR)/long_tag.Po \
+ ./$(DEPDIR)/rational_precision2double.Po \
./$(DEPDIR)/raw_decode.Po ./$(DEPDIR)/rewrite_tag.Po \
./$(DEPDIR)/short_tag.Po ./$(DEPDIR)/strip.Po \
./$(DEPDIR)/strip_rw.Po ./$(DEPDIR)/test_arrays.Po \
@@ -214,15 +225,17 @@ am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
am__v_CCLD_0 = @echo " CCLD " $@;
am__v_CCLD_1 =
SOURCES = $(ascii_tag_SOURCES) $(custom_dir_SOURCES) \
- $(defer_strile_loading_SOURCES) \
+ $(custom_dir_EXIF_231_SOURCES) $(defer_strile_loading_SOURCES) \
$(defer_strile_writing_SOURCES) $(long_tag_SOURCES) \
- $(raw_decode_SOURCES) $(rewrite_SOURCES) $(short_tag_SOURCES) \
- $(strip_rw_SOURCES) testtypes.c
+ $(rational_precision2double_SOURCES) $(raw_decode_SOURCES) \
+ $(rewrite_SOURCES) $(short_tag_SOURCES) $(strip_rw_SOURCES) \
+ testtypes.c
DIST_SOURCES = $(ascii_tag_SOURCES) $(custom_dir_SOURCES) \
- $(defer_strile_loading_SOURCES) \
+ $(custom_dir_EXIF_231_SOURCES) $(defer_strile_loading_SOURCES) \
$(defer_strile_writing_SOURCES) $(long_tag_SOURCES) \
- $(raw_decode_SOURCES) $(rewrite_SOURCES) $(short_tag_SOURCES) \
- $(strip_rw_SOURCES) testtypes.c
+ $(rational_precision2double_SOURCES) $(raw_decode_SOURCES) \
+ $(rewrite_SOURCES) $(short_tag_SOURCES) $(strip_rw_SOURCES) \
+ testtypes.c
am__can_run_installinfo = \
case $$AM_UPDATE_INFO_DIR in \
n|no|NO) false;; \
@@ -432,7 +445,10 @@ am__set_TESTS_bases = \
bases=`echo $$bases`
RECHECK_LOGS = $(TEST_LOGS)
AM_RECURSIVE_TARGETS = check recheck
-@HAVE_JPEG_TRUE@am__EXEEXT_2 = tiff2rgba-quad-tile.jpg.sh
+@HAVE_JPEG_TRUE@am__EXEEXT_2 = tiff2rgba-quad-tile.jpg.sh \
+@HAVE_JPEG_TRUE@ tiff2rgba-ojpeg_zackthecat_subsamp22_single_strip.sh \
+@HAVE_JPEG_TRUE@ tiff2rgba-ojpeg_chewey_subsamp21_multi_strip.sh \
+@HAVE_JPEG_TRUE@ tiff2rgba-ojpeg_single_strip_no_rowsperstrip.sh
am__EXEEXT_3 = ppm2tiff_pbm.sh ppm2tiff_pgm.sh ppm2tiff_ppm.sh \
fax2tiff.sh tiffcp-g3.sh tiffcp-g3-1d.sh tiffcp-g3-1d-fill.sh \
tiffcp-g3-2d.sh tiffcp-g3-2d-fill.sh tiffcp-g4.sh \
@@ -481,7 +497,8 @@ am__EXEEXT_3 = ppm2tiff_pbm.sh ppm2tiff_pgm.sh ppm2tiff_ppm.sh \
tiff2rgba-minisblack-2c-8b-alpha.sh \
tiff2rgba-miniswhite-1c-1b.sh tiff2rgba-palette-1c-1b.sh \
tiff2rgba-palette-1c-4b.sh tiff2rgba-palette-1c-8b.sh \
- tiff2rgba-rgb-3c-16b.sh tiff2rgba-rgb-3c-8b.sh $(am__EXEEXT_2)
+ tiff2rgba-rgb-3c-16b.sh tiff2rgba-rgb-3c-8b.sh testfax4.sh \
+ testdeflatelaststripextradata.sh $(am__EXEEXT_2)
TEST_SUITE_LOG = test-suite.log
TEST_EXTENSIONS = @EXEEXT@ .test
LOG_DRIVER = $(SHELL) $(top_srcdir)/config/test-driver
@@ -679,7 +696,10 @@ CLEANFILES = test_packbits.tif o-*
@HAVE_JPEG_TRUE@JPEG_DEPENDENT_CHECK_PROG = raw_decode
@HAVE_JPEG_FALSE@JPEG_DEPENDENT_TESTSCRIPTS =
@HAVE_JPEG_TRUE@JPEG_DEPENDENT_TESTSCRIPTS = \
-@HAVE_JPEG_TRUE@ tiff2rgba-quad-tile.jpg.sh
+@HAVE_JPEG_TRUE@ tiff2rgba-quad-tile.jpg.sh \
+@HAVE_JPEG_TRUE@ tiff2rgba-ojpeg_zackthecat_subsamp22_single_strip.sh \
+@HAVE_JPEG_TRUE@ tiff2rgba-ojpeg_chewey_subsamp21_multi_strip.sh \
+@HAVE_JPEG_TRUE@ tiff2rgba-ojpeg_single_strip_no_rowsperstrip.sh
# Test scripts to execute
@@ -760,6 +780,8 @@ TESTSCRIPTS = \
tiff2rgba-palette-1c-8b.sh \
tiff2rgba-rgb-3c-16b.sh \
tiff2rgba-rgb-3c-8b.sh \
+ testfax4.sh \
+ testdeflatelaststripextradata.sh \
$(JPEG_DEPENDENT_TESTSCRIPTS)
@@ -769,7 +791,9 @@ REFFILES = \
refs/o-tiff2ps-EPS1.ps \
refs/o-tiff2ps-PS1.ps \
refs/o-tiff2ps-PS2.ps \
- refs/o-tiff2ps-PS3.ps
+ refs/o-tiff2ps-PS3.ps \
+ refs/o-testfax4.tiff \
+ refs/o-deflate-last-strip-extra-data.tiff
# This list should contain all of the TIFF files in the 'images'
@@ -788,11 +812,17 @@ TIFFIMAGES = \
images/rgb-3c-8b.tiff \
images/quad-tile.jpg.tiff \
images/quad-lzw-compat.tiff \
- images/lzw-single-strip.tiff
+ images/lzw-single-strip.tiff \
+ images/ojpeg_zackthecat_subsamp22_single_strip.tiff \
+ images/ojpeg_chewey_subsamp21_multi_strip.tiff \
+ images/ojpeg_single_strip_no_rowsperstrip.tiff \
+ images/testfax4.tiff \
+ images/deflate-last-strip-extra-data.tiff
PNMIMAGES = \
images/minisblack-1c-8b.pgm \
images/miniswhite-1c-1b.pbm \
+ images/rgb-3c-16b.ppm \
images/rgb-3c-8b.ppm
@@ -820,6 +850,10 @@ raw_decode_SOURCES = raw_decode.c
raw_decode_LDADD = $(LIBTIFF)
custom_dir_SOURCES = custom_dir.c
custom_dir_LDADD = $(LIBTIFF)
+rational_precision2double_SOURCES = rational_precision2double.c
+rational_precision2double_LDADD = $(LIBTIFF)
+custom_dir_EXIF_231_SOURCES = custom_dir_EXIF_231.c
+custom_dir_EXIF_231_LDADD = $(LIBTIFF)
defer_strile_loading_SOURCES = defer_strile_loading.c
defer_strile_loading_LDADD = $(LIBTIFF)
defer_strile_writing_SOURCES = defer_strile_writing.c
@@ -876,6 +910,10 @@ custom_dir$(EXEEXT): $(custom_dir_OBJECTS) $(custom_dir_DEPENDENCIES) $(EXTRA_cu
@rm -f custom_dir$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(custom_dir_OBJECTS) $(custom_dir_LDADD) $(LIBS)
+custom_dir_EXIF_231$(EXEEXT): $(custom_dir_EXIF_231_OBJECTS) $(custom_dir_EXIF_231_DEPENDENCIES) $(EXTRA_custom_dir_EXIF_231_DEPENDENCIES)
+ @rm -f custom_dir_EXIF_231$(EXEEXT)
+ $(AM_V_CCLD)$(LINK) $(custom_dir_EXIF_231_OBJECTS) $(custom_dir_EXIF_231_LDADD) $(LIBS)
+
defer_strile_loading$(EXEEXT): $(defer_strile_loading_OBJECTS) $(defer_strile_loading_DEPENDENCIES) $(EXTRA_defer_strile_loading_DEPENDENCIES)
@rm -f defer_strile_loading$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(defer_strile_loading_OBJECTS) $(defer_strile_loading_LDADD) $(LIBS)
@@ -888,6 +926,10 @@ long_tag$(EXEEXT): $(long_tag_OBJECTS) $(long_tag_DEPENDENCIES) $(EXTRA_long_tag
@rm -f long_tag$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(long_tag_OBJECTS) $(long_tag_LDADD) $(LIBS)
+rational_precision2double$(EXEEXT): $(rational_precision2double_OBJECTS) $(rational_precision2double_DEPENDENCIES) $(EXTRA_rational_precision2double_DEPENDENCIES)
+ @rm -f rational_precision2double$(EXEEXT)
+ $(AM_V_CCLD)$(LINK) $(rational_precision2double_OBJECTS) $(rational_precision2double_LDADD) $(LIBS)
+
raw_decode$(EXEEXT): $(raw_decode_OBJECTS) $(raw_decode_DEPENDENCIES) $(EXTRA_raw_decode_DEPENDENCIES)
@rm -f raw_decode$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(raw_decode_OBJECTS) $(raw_decode_LDADD) $(LIBS)
@@ -917,9 +959,11 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ascii_tag.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/check_tag.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/custom_dir.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/custom_dir_EXIF_231.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/defer_strile_loading.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/defer_strile_writing.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/long_tag.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rational_precision2double.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/raw_decode.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rewrite_tag.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/short_tag.Po@am__quote@ # am--include-marker
@@ -1196,6 +1240,20 @@ custom_dir.log: custom_dir$(EXEEXT)
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
+custom_dir_EXIF_231.log: custom_dir_EXIF_231$(EXEEXT)
+ @p='custom_dir_EXIF_231$(EXEEXT)'; \
+ b='custom_dir_EXIF_231'; \
+ $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
+ --log-file $$b.log --trs-file $$b.trs \
+ $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
+ "$$tst" $(AM_TESTS_FD_REDIRECT)
+rational_precision2double.log: rational_precision2double$(EXEEXT)
+ @p='rational_precision2double$(EXEEXT)'; \
+ b='rational_precision2double'; \
+ $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
+ --log-file $$b.log --trs-file $$b.trs \
+ $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
+ "$$tst" $(AM_TESTS_FD_REDIRECT)
defer_strile_loading.log: defer_strile_loading$(EXEEXT)
@p='defer_strile_loading$(EXEEXT)'; \
b='defer_strile_loading'; \
@@ -1756,6 +1814,20 @@ tiff2rgba-rgb-3c-8b.sh.log: tiff2rgba-rgb-3c-8b.sh
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
+testfax4.sh.log: testfax4.sh
+ @p='testfax4.sh'; \
+ b='testfax4.sh'; \
+ $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
+ --log-file $$b.log --trs-file $$b.trs \
+ $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
+ "$$tst" $(AM_TESTS_FD_REDIRECT)
+testdeflatelaststripextradata.sh.log: testdeflatelaststripextradata.sh
+ @p='testdeflatelaststripextradata.sh'; \
+ b='testdeflatelaststripextradata.sh'; \
+ $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
+ --log-file $$b.log --trs-file $$b.trs \
+ $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
+ "$$tst" $(AM_TESTS_FD_REDIRECT)
tiff2rgba-quad-tile.jpg.sh.log: tiff2rgba-quad-tile.jpg.sh
@p='tiff2rgba-quad-tile.jpg.sh'; \
b='tiff2rgba-quad-tile.jpg.sh'; \
@@ -1763,6 +1835,27 @@ tiff2rgba-quad-tile.jpg.sh.log: tiff2rgba-quad-tile.jpg.sh
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
+tiff2rgba-ojpeg_zackthecat_subsamp22_single_strip.sh.log: tiff2rgba-ojpeg_zackthecat_subsamp22_single_strip.sh
+ @p='tiff2rgba-ojpeg_zackthecat_subsamp22_single_strip.sh'; \
+ b='tiff2rgba-ojpeg_zackthecat_subsamp22_single_strip.sh'; \
+ $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
+ --log-file $$b.log --trs-file $$b.trs \
+ $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
+ "$$tst" $(AM_TESTS_FD_REDIRECT)
+tiff2rgba-ojpeg_chewey_subsamp21_multi_strip.sh.log: tiff2rgba-ojpeg_chewey_subsamp21_multi_strip.sh
+ @p='tiff2rgba-ojpeg_chewey_subsamp21_multi_strip.sh'; \
+ b='tiff2rgba-ojpeg_chewey_subsamp21_multi_strip.sh'; \
+ $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
+ --log-file $$b.log --trs-file $$b.trs \
+ $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
+ "$$tst" $(AM_TESTS_FD_REDIRECT)
+tiff2rgba-ojpeg_single_strip_no_rowsperstrip.sh.log: tiff2rgba-ojpeg_single_strip_no_rowsperstrip.sh
+ @p='tiff2rgba-ojpeg_single_strip_no_rowsperstrip.sh'; \
+ b='tiff2rgba-ojpeg_single_strip_no_rowsperstrip.sh'; \
+ $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
+ --log-file $$b.log --trs-file $$b.trs \
+ $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
+ "$$tst" $(AM_TESTS_FD_REDIRECT)
.test.log:
@p='$<'; \
$(am__set_b); \
@@ -1860,9 +1953,11 @@ distclean: distclean-am
-rm -f ./$(DEPDIR)/ascii_tag.Po
-rm -f ./$(DEPDIR)/check_tag.Po
-rm -f ./$(DEPDIR)/custom_dir.Po
+ -rm -f ./$(DEPDIR)/custom_dir_EXIF_231.Po
-rm -f ./$(DEPDIR)/defer_strile_loading.Po
-rm -f ./$(DEPDIR)/defer_strile_writing.Po
-rm -f ./$(DEPDIR)/long_tag.Po
+ -rm -f ./$(DEPDIR)/rational_precision2double.Po
-rm -f ./$(DEPDIR)/raw_decode.Po
-rm -f ./$(DEPDIR)/rewrite_tag.Po
-rm -f ./$(DEPDIR)/short_tag.Po
@@ -1918,9 +2013,11 @@ maintainer-clean: maintainer-clean-am
-rm -f ./$(DEPDIR)/ascii_tag.Po
-rm -f ./$(DEPDIR)/check_tag.Po
-rm -f ./$(DEPDIR)/custom_dir.Po
+ -rm -f ./$(DEPDIR)/custom_dir_EXIF_231.Po
-rm -f ./$(DEPDIR)/defer_strile_loading.Po
-rm -f ./$(DEPDIR)/defer_strile_writing.Po
-rm -f ./$(DEPDIR)/long_tag.Po
+ -rm -f ./$(DEPDIR)/rational_precision2double.Po
-rm -f ./$(DEPDIR)/raw_decode.Po
-rm -f ./$(DEPDIR)/rewrite_tag.Po
-rm -f ./$(DEPDIR)/short_tag.Po
diff --git a/tiff/test/common.sh b/tiff/test/common.sh
index 5bebcd374..0219ab3a9 100644
--- a/tiff/test/common.sh
+++ b/tiff/test/common.sh
@@ -46,10 +46,11 @@ IMG_LZW_SINGLE_STROP=${IMAGES}/lzw-single-strip.tiff
IMG_MINISWHITE_1C_1B_PBM=${IMAGES}/miniswhite-1c-1b.pbm
IMG_MINISBLACK_1C_8B_PGM=${IMAGES}/minisblack-1c-8b.pgm
+IMG_RGB_3C_16B_PPM=${IMAGES}/rgb-3c-16b.ppm
IMG_RGB_3C_8B_PPM=${IMAGES}/rgb-3c-8b.ppm
# All uncompressed image files
-IMG_UNCOMPRESSED="${IMG_MINISBLACK_1C_16B} ${IMG_MINISBLACK_1C_8B} ${IMG_MINISWHITE_1C_1B} ${IMG_PALETTE_1C_1B} ${IMG_PALETTE_1C_4B} ${IMG_PALETTE_1C_4B} ${IMG_PALETTE_1C_8B} ${IMG_RGB_3C_8B}"
+IMG_UNCOMPRESSED="${IMG_MINISBLACK_1C_16B} ${IMG_MINISBLACK_1C_8B} ${IMG_MINISWHITE_1C_1B} ${IMG_PALETTE_1C_1B} ${IMG_PALETTE_1C_4B} ${IMG_PALETTE_1C_4B} ${IMG_PALETTE_1C_8B} ${IMG_RGB_3C_8B} ${IMG_RGB_3C_16B}"
#
# Test a simple convert-like command.
diff --git a/tiff/test/custom_dir_EXIF_231.c b/tiff/test/custom_dir_EXIF_231.c
new file mode 100644
index 000000000..4c70e48fa
--- /dev/null
+++ b/tiff/test/custom_dir_EXIF_231.c
@@ -0,0 +1,1398 @@
+
+/*
+ * Copyright (c) 2012, Frank Warmerdam <warmerdam@pobox.com>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and
+ * its documentation for any purpose is hereby granted without fee, provided
+ * that (i) the above copyright notices and this permission notice appear in
+ * all copies of the software and related documentation, and (ii) the names of
+ * Sam Leffler and Silicon Graphics may not be used in any advertising or
+ * publicity relating to the software without the specific, prior written
+ * permission of Sam Leffler and Silicon Graphics.
+ *
+ * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
+ * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
+ * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
+ * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+ * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
+ * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
+
+/*
+ * TIFF Library
+ *
+ * -- Module copied from custom_dir.c --
+ *=========== Purpose ===================================================================================
+ * Extended and amended version for testing of EXIF 2.32, GPS and handling of custom fields.
+ * EXIF 2.32 and GPS are defined in amended files tif_dirinfo.c, tif_dirread.c, tiff.h, tiffio.h, tif_dir.h, tif_dir.c
+ *
+ *-- ATTENTION: After the upgrade with Rational2Double, the GPSTAG values are defined as double precision
+ * and need to be written and also read in double precision!
+ * In order to maintain this code for both cases, it is checked above if the TiffLibrary is
+ * compiled with the new interface with Rational2Double or still uses the old definitions,
+ * by setting blnIsRational2Double above.
+ *
+ */
+
+
+/*------------
+ * This version writes the GPS and EXIF tags correctly, without additonal main-IFD and parameters!
+ * In contrary, custom_dir.c does write additional main-IFD and parameters to file.
+ -------------*/
+
+
+#define FOR_AUTO_TESTING
+#ifdef FOR_AUTO_TESTING
+/* Only for automake and CMake infrastructure the test should:
+ a.) delete any written testfiles when test passed (otherwise autotest will fail)
+ b.) goto failure, if any failure is detected, which is not necessary when test is initiated manually for debugging
+*/
+#define GOTOFAILURE goto failure;
+#define GOTOFAILURE_GPS goto failure;
+#define GOTOFAILURE_ALL_EXIF goto failure;
+#else
+#define GOTOFAILURE
+#define GOTOFAILURE_GPS
+#define GOTOFAILURE_ALL_EXIF
+#endif
+
+
+#ifdef _MSC_VER
+#pragma warning( disable : 4101)
+#endif
+
+#include "tif_config.h"
+#include <stdio.h>
+#include <string.h>
+#include <math.h>
+#include <errno.h>
+
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+
+#include "tiffio.h"
+#include "tiffiop.h"
+#include "tif_dir.h"
+#include "tifftest.h"
+
+
+
+int write_test_tiff(TIFF *tif, const char *filenameRead);
+
+static const char filename[] = "custom_dir_EXIF_231.tif";
+static const char filenameBigTiff[] = "custom_dir_EXIF_231_Big.tif";
+
+#define SPP 3 /* Samples per pixel */
+const uint16 width = 1;
+const uint16 length = 1;
+const uint16 bps = 8;
+const uint16 photometric = PHOTOMETRIC_RGB;
+const uint16 rows_per_strip = 1;
+const uint16 planarconfig = PLANARCONFIG_CONTIG;
+
+
+int
+main()
+{
+ TIFF *tif;
+ int ret, ret1, ret2;
+
+ fprintf(stderr, "==== Test automatically if all EXIF and GPS tags are written/read correctly. ====\n");
+ /* --- Test with Classic-TIFF ---*/
+ /* delete file, if exists */
+ ret = unlink(filename);
+ if (ret != 0 && errno != ENOENT) {
+ fprintf(stderr, "Can't delete test TIFF file %s.\n", filename);
+ }
+
+ /* We write the main directory as a simple image. */
+ tif = TIFFOpen(filename, "w+");
+ if (!tif) {
+ fprintf(stderr, "Can't create test TIFF file %s.\n", filename);
+ return 1;
+ }
+ fprintf(stderr, "-------- Test with ClassicTIFF started ----------\n");
+ ret1 = write_test_tiff(tif, filename);
+
+ if (ret1 > 0) return(ret1);
+
+ /*--- Test with BIG-TIFF ---*/
+ /* delete file, if exists */
+ ret = unlink(filenameBigTiff);
+ if (ret != 0 && errno != ENOENT) {
+ fprintf(stderr, "Can't delete test TIFF file %s.\n", filenameBigTiff);
+ }
+
+ tif = TIFFOpen(filenameBigTiff, "w8");
+ if (!tif) {
+ fprintf(stderr, "Can't create test TIFF file %s.\n", filenameBigTiff);
+ return 1;
+ }
+ fprintf(stderr, "\n\n-------- Test with BigTIFF started ----------\n");
+ ret2 = write_test_tiff(tif, filenameBigTiff);
+
+ if (ret2 > 0) return(ret2 + 10); else return(ret2);
+
+} /* main() */
+
+
+
+
+
+
+
+int
+write_test_tiff(TIFF *tif, const char *filenameRead)
+{
+ unsigned char buf[SPP] = { 0, 127, 255 };
+ uint64 dir_offset = 0;
+ uint64 dir_offset_GPS = 0, dir_offset_EXIF = 0;
+ uint64 read_dir_offset = 0;
+ /*-- Additional variables --*/
+ int retCode, retCode2;
+ unsigned char exifVersion[4] = {'0','2','3','1'}; /* EXIF 2.31 version is 4 characters of a string! */
+ unsigned char gpsVersion[4] = {2,2,0,1}; /* GPS Version is 4 numbers! */
+ unsigned char *pGpsVersion;
+ float auxFloat = 0.0f;
+ double auxDouble = 0.0;
+ char auxChar = 0;
+ uint32 auxUint32 = 0;
+ short auxShort=0;
+ long auxLong = 0;
+ void *pVoid;
+ int blnIsRational2Double;
+
+ int i, j;
+ long nTags;
+
+ const TIFFFieldArray* tFieldArray;
+ unsigned long tTag;
+ TIFFDataType tType;
+ short tWriteCount;
+ TIFFSetGetFieldType tSetFieldType;
+ char *tFieldName;
+ const TIFFField *fip;
+
+ char blnFillGPSManually = 1;
+
+#define STRSIZE 1000
+#define N_SIZE 120
+#define VARIABLE_ARRAY_SIZE 6
+
+ /* -- Test data for writing -- */
+ char auxCharArrayW[N_SIZE];
+ short auxShortArrayW[N_SIZE];
+ long auxLongArrayW[N_SIZE];
+ float auxFloatArrayW[N_SIZE];
+ double auxDoubleArrayW[N_SIZE];
+ char auxTextArrayW[N_SIZE][STRSIZE];
+ double auxDoubleArrayGPS1[3] = {1.0/7.0, 61.23456789012345, 62.0};
+ double auxDoubleArrayGPS2[3] = {1.0/19.0, 88.34434, 15.12345678901234567890};
+ double auxDoubleArrayGPSTime[3] = {22.0, 17.0, 15.3456789};
+ double auxDoubleGPSAltitude = 3456.0;
+ double auxDoubleGPSDirection = 63.7;
+ float auxFloatArrayN1[3] = { 1.0f / 7.0f, 61.23456789012345f, 62.3f };
+ float auxFloatArrayN2[3] = { -1.0f / 7.0f, -61.23456789012345f, -62.3f };
+
+ /* -- Variables for reading -- */
+ uint16 count16 = 0;
+ union {
+ long Long;
+ short Short1;
+ short Short2[2];
+ char Char[4];
+ } unionLong;
+ union {
+ double dbl;
+ float flt1;
+ float flt2;
+ } auxDblUnion;
+ void *pVoidArray;
+ char *pAscii;
+ char auxCharArray[2*STRSIZE];
+ short auxShortArray[2*N_SIZE];
+ long auxLongArray[2*N_SIZE];
+ float auxFloatArray[2*N_SIZE];
+ double auxDoubleArray[2*N_SIZE];
+ double dblDiff, dblDiffLimit;
+#define RATIONAL_EPS (1.0/30000.0) /* reduced difference of rational values, approx 3.3e-5 */
+
+ /*-- Fill test data arrays for writing ----------- */
+ for (i=0; i<N_SIZE; i++) {
+ sprintf(auxTextArrayW[i],"N%d-String-%d_tttttttttttttttttttttttttttttx", i, i);
+ }
+ for (i=0; i<N_SIZE; i++) {
+ auxCharArrayW[i] = (char)(i+1);
+ }
+ for (i=0; i<N_SIZE; i++) {
+ auxShortArrayW[i] = (short)(i+1)*7;
+ }
+ for (i=0; i<N_SIZE; i++) {
+ auxLongArrayW[i] = (i+1)*133;
+ }
+ for (i=0; i<N_SIZE; i++) {
+ auxFloatArrayW[i] = (float)((i+1)*133)/3.3f;
+ }
+ for (i=0; i<N_SIZE; i++) {
+ auxDoubleArrayW[i] = (double)((i+1)*3689)/4.5697;
+ }
+
+ /*-- Setup standard tags of a simple tiff file --*/
+ if (!TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, width)) {
+ fprintf (stderr, "Can't set ImageWidth tag.\n");
+ goto failure;
+ }
+ if (!TIFFSetField(tif, TIFFTAG_IMAGELENGTH, length)) {
+ fprintf (stderr, "Can't set ImageLength tag.\n");
+ goto failure;
+ }
+ if (!TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, bps)) {
+ fprintf (stderr, "Can't set BitsPerSample tag.\n");
+ goto failure;
+ }
+ if (!TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, SPP)) {
+ fprintf (stderr, "Can't set SamplesPerPixel tag.\n");
+ goto failure;
+ }
+ if (!TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, rows_per_strip)) {
+ fprintf (stderr, "Can't set SamplesPerPixel tag.\n");
+ goto failure;
+ }
+ if (!TIFFSetField(tif, TIFFTAG_PLANARCONFIG, planarconfig)) {
+ fprintf (stderr, "Can't set PlanarConfiguration tag.\n");
+ goto failure;
+ }
+ if (!TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, photometric)) {
+ fprintf (stderr, "Can't set PhotometricInterpretation tag.\n");
+ goto failure;
+ }
+
+#define ADDITIONAL_TAGS
+#ifdef ADDITIONAL_TAGS
+ /*-- Additional tags to check Rational standard tags, which are also defined as FIELD_CUSTOM */
+
+ /*- TIFFTAG_INKSET is a SHORT parameter (TIFF_SHORT, TIFF_SETGET_UINT16) with field_bit=FIELD_CUSTOM !! -*/
+ if (!TIFFSetField(tif, TIFFTAG_INKSET, 34)) {
+ fprintf(stderr, "Can't set TIFFTAG_INKSET tag.\n");
+ goto failure;
+ }
+
+ /*- TIFFTAG_PIXAR_FOVCOT is a FLOAT parameter ( TIFF_FLOAT, TIFF_SETGET_FLOAT) with field_bit=FIELD_CUSTOM !! -*/
+ /* - can be written with Double but has to be read with float parameter */
+#define PIXAR_FOVCOT_VAL 5.123456789123456789
+ auxFloat = (float)PIXAR_FOVCOT_VAL;
+ auxDouble = (double)PIXAR_FOVCOT_VAL;
+ if (!TIFFSetField(tif, TIFFTAG_PIXAR_FOVCOT, auxDouble)) {
+ fprintf(stderr, "Can't set TIFFTAG_PIXAR_FOVCOT tag.\n");
+ goto failure;
+ }
+ /*- TIFFTAG_STONITS is a DOUBLE parameter (TIFF_DOUBLE, TIFF_SETGET_DOUBLE) with field_bit=FIELD_CUSTOM!
+ * Only TIFFTAG_STONITS is a TIFF_DOUBLE, which has to be read as DOUBLE!!
+ */
+#define STONITS_VAL 6.123456789123456789
+ auxDouble = STONITS_VAL;
+ auxFloat = (float)auxDouble;
+ if (!TIFFSetField(tif, TIFFTAG_STONITS, auxDouble)) {
+ fprintf(stderr, "Can't set TIFFTAG_STONITS tag.\n");
+ goto failure;
+ }
+
+ /*- TIFFTAG_YCBCRPOSITIONING is a SHORT parameter */
+ auxLong = auxShort = 5;
+ if (!TIFFSetField(tif, TIFFTAG_YCBCRPOSITIONING, auxLong )) {
+ fprintf (stderr, "Can't set TIFFTAG_YCBCRPOSITIONING tag.\n");
+ goto failure;
+ }
+
+ /* - TIFFTAG_BESTQUALITYSCALE is a Rational parameter, FIELD_CUSTOM and TIFF_SETGET_DOUBLE */
+ /* With Rational2Double upgrade tag is redefined to TIFF_SETGET_FLOAT, but can be still written with double. */
+#define BESTQUALITYSCALE_VAL 15.3
+ auxDouble = BESTQUALITYSCALE_VAL;
+ if (!TIFFSetField(tif, TIFFTAG_BESTQUALITYSCALE, auxDouble )) {
+ fprintf (stderr, "Can't set TIFFTAG_BESTQUALITYSCALE tag.\n");
+ goto failure;
+ }
+
+ /* - TIFFTAG_BASELINENOISE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT */
+ if (!TIFFSetField(tif, TIFFTAG_BASELINENOISE, auxDouble)) {
+ fprintf(stderr, "Can't set TIFFTAG_BASELINENOISE tag.\n");
+ goto failure;
+ }
+
+
+ /*--- For static or variable ARRAYs the case is different ---*/
+/*- Variable Array: TIFFTAG_DECODE is a SRATIONAL parameter TIFF_SETGET_C16_FLOAT type FIELD_CUSTOM with passcount=1 and variable length of array. */
+ if (!TIFFSetField(tif, TIFFTAG_DECODE, 3, auxFloatArrayN2)) {
+ fprintf(stderr, "Can't set TIFFTAG_DECODE tag.\n");
+ goto failure;
+ }
+
+ /*- Varable Array: TIFF_RATIONAL, 0, TIFF_SETGET_C16_FLOAT */
+ if (!TIFFSetField(tif, TIFFTAG_BLACKLEVEL, 3, auxFloatArrayN1)) {
+ fprintf(stderr, "Can't set TIFFTAG_BLACKLEVEL tag.\n");
+ goto failure;
+ }
+
+ /*- Fixed Array: TIFFTAG_DEFAULTCROPSIZE, 2, 2, TIFF_RATIONAL, 0, TIFF_SETGET_C0_FLOAT */
+ if (!TIFFSetField(tif, TIFFTAG_DEFAULTCROPSIZE, &auxFloatArrayW[0])) {
+ fprintf(stderr, "Can't set TIFFTAG_DEFAULTCROPSIZE tag.\n");
+ goto failure;
+ }
+#endif /* -- ADDITIONAL_TAGS -- */
+
+/*================== Rational2Double Interface Check =====================*/
+ /*-- Check, if the TiffLibrary is compiled with the new interface with Rational2Double or still uses the old definitions.
+ For that, TIFF_RATIONAL tags with FIELD_CUSTOM are changed from TIFF_SETGET_DOUBLE to TIFF_SETGET_FLOAT for the
+ new interface in order to prevent the old reading behaviour.
+ Tags to check: TIFFTAG_BESTQUALITYSCALE, TIFFTAG_BASELINENOISE, TIFFTAG_BASELINESHARPNESS
+ */
+ fip = TIFFFindField(tif, TIFFTAG_BESTQUALITYSCALE, TIFF_ANY);
+ tSetFieldType = fip->set_field_type;
+ if (tSetFieldType == TIFF_SETGET_DOUBLE) {
+ blnIsRational2Double = FALSE;
+ } else {
+ blnIsRational2Double = TRUE;
+ fprintf(stderr, "-- Rational2Double from TIFF tag detected --\n");
+ }
+
+/*================== Write GPS and EXIF tags =====================*/
+
+ /*-- Set dummy EXIF/GPS tag in original tiff-structure in order to reserve space for final dir_offset value, */
+ /* which is properly written at the end. */
+ dir_offset = 0; /* Zero, in case no Custom-IFD is written */
+
+#define WRITE_GPS_TAGS
+#ifdef WRITE_GPS_TAGS
+ if (!TIFFSetField(tif, TIFFTAG_GPSIFD, dir_offset )) {
+ fprintf (stderr, "Can't write TIFFTAG_GPSIFD\n" );
+ }
+#endif
+
+ /*------- And also do the same for the EXIF IFD tag here, because we have to save the main directory next ------*/
+ /*-- Set dummy EXIF/GPS tag in original tiff-structure in order to reserve space for final dir_offset value,
+ * which is properly written at the end.
+ */
+#define WRITE_EXIF_TAGS
+#ifdef WRITE_EXIF_TAGS
+ if (!TIFFSetField(tif, TIFFTAG_EXIFIFD, dir_offset )) {
+ fprintf (stderr, "Can't write TIFFTAG_EXIFIFD\n" );
+ }
+#endif
+
+#ifndef WRITEPIXELLAST
+ /*-- Write dummy pixel data. --*/
+ if (TIFFWriteScanline(tif, buf, 0, 0) < 0) {
+ fprintf (stderr, "Can't write image data.\n");
+ goto failure;
+ }
+#endif
+
+
+#ifdef WRITE_GPS_TAGS
+#define READ_GPS_TAGS
+ /*================== Write GPS tags =====================*/
+
+ /*-- Save current tiff-directory to file before directory is changed. Otherwise it will be lost! */
+ /* The tif-structure is overwritten/ freshly initialized by any "CreateDirectory" */
+ /*retCode = TIFFCheckpointDirectory(tif);*/ /* does not cleanup Tiff-Structure */
+ retCode = TIFFWriteDirectory(tif); /* cleanup Tiff-structure */
+
+ /*-- Now create a GPS directory. */
+ if (TIFFCreateGPSDirectory(tif) != 0) {
+ fprintf (stderr, "TIFFCreateGPSDirectory() failed.\n" );
+ goto failure;
+ }
+
+ if (!TIFFSetField( tif, GPSTAG_VERSIONID, gpsVersion)) {
+ fprintf (stderr, "Can't write GPSTAG_VERSIONID\n" );
+ goto failure;
+ }
+
+ if (blnFillGPSManually) {
+ /*================= Write manually valid data to the GPS fields ==============*/
+ if (!TIFFSetField( tif, GPSTAG_LATITUDEREF, "N\0")) {
+ fprintf (stderr, "Can't write GPSTAG_LATITUDEREF\n" );
+ goto failure;
+ }
+ /*-- Unfortunately, Rational values are defined as SETGET_DOUBLE but are internally always stored as float.
+ * Single Rational values do not matter for writing, because TIFFSetField() uses va_arg() which performs "variables promotion" from type float to type double!
+ * However, for reading of Rational values ONLY float-variables are allowed - in contrary to the SETGET_DOUBLE specification at tiffFields[] in tif_dirinfo.c.
+ */
+ /*-- ATTENTION: After the upgrade with Rational2Double, the GPSTAG values are defined as double precision
+ * and need to be written and also read in double precision!
+ * In order to maintain this code for both cases, it is checked above if the TiffLibrary is
+ * compiled with the new interface with Rational2Double or still uses the old definitions,
+ * by setting blnIsRational2Double above.
+ */
+ if (blnIsRational2Double) {
+ fprintf(stderr, "-- GPS tags are written using Rational2Double --\n");
+ } else {
+ fprintf(stderr, "-- GPS tags are written using standard --\n");
+ }
+ if (!blnIsRational2Double) {
+ for (j = 0; j < 3; j++) auxFloatArray[j] = (float)auxDoubleArrayGPS1[j];
+ if (!TIFFSetField(tif, GPSTAG_LATITUDE, auxFloatArray)) {
+ fprintf(stderr, "Can't write GPSTAG_LATITUDE\n");
+ goto failure;
+ }
+ } else {
+ /* Rational2Double interface for GPSTAG */
+ if (!TIFFSetField(tif, GPSTAG_LATITUDE, auxDoubleArrayGPS1)) {
+ fprintf(stderr, "Can't write GPSTAG_LATITUDE\n");
+ goto failure;
+ }
+ }
+ if (!TIFFSetField( tif, GPSTAG_LONGITUDEREF, "W\0")) {
+ fprintf (stderr, "Can't write GPSTAG_LONGITUDEREF\n" );
+ goto failure;
+ }
+ if (!blnIsRational2Double) {
+ for (j=0; j<3; j++) auxFloatArray[j] = (float)auxDoubleArrayGPS2[j];
+ if (!TIFFSetField( tif, GPSTAG_LONGITUDE, auxFloatArray)) {
+ fprintf (stderr, "Can't write GPSTAG_LONGITUDE\n" );
+ goto failure;
+ }
+ } else {
+ /* Rational2Double interface for GPSTAG */
+ if (!TIFFSetField(tif, GPSTAG_LONGITUDE, auxDoubleArrayGPS2)) {
+ fprintf(stderr, "Can't write GPSTAG_LATITUDE\n");
+ goto failure;
+ }
+ }
+ /*-- AltitudeRef: default is above sea level!! */
+ if (!TIFFSetField( tif, GPSTAG_ALTITUDEREF, 0)) {
+ fprintf (stderr, "Can't write GPSTAG_ALTITUDEREF\n" );
+ goto failure;
+ }
+ if (!TIFFSetField( tif, GPSTAG_ALTITUDE, auxDoubleGPSAltitude)) {
+ fprintf (stderr, "Can't write GPSTAG_ALTITUDE\n" );
+ goto failure;
+ }
+ /*-- TimeStamp is only hh:mm:ss. See also DateTime string */
+ if (!TIFFSetField( tif, GPSTAG_TIMESTAMP, auxDoubleArrayGPSTime)) {
+ fprintf (stderr, "Can't write GPSTAG_TIMESTAMP\n" );
+ goto failure;
+ }
+ if (!TIFFSetField( tif, GPSTAG_DATESTAMP, "2012:11:04")) {
+ fprintf (stderr, "Can't write GPSTAG_DATESTAMP\n" );
+ goto failure;
+ }
+
+ if (!TIFFSetField( tif, GPSTAG_IMGDIRECTIONREF, "T\0")) {
+ fprintf (stderr, "Can't write GPSTAG_IMGDIRECTIONREF\n" );
+ goto failure;
+ }
+ if (!TIFFSetField( tif, GPSTAG_IMGDIRECTION, auxDoubleGPSDirection)) {
+ fprintf (stderr, "Can't write GPSTAG_IMGDIRECTION\n" );
+ goto failure;
+ }
+
+ /*-- Type TIFF_UNDEFINED */
+ if (!TIFFSetField( tif, GPSTAG_PROCESSINGMETHOD, 3, &auxCharArrayW[10])) {
+ fprintf (stderr, "Can't write GPSTAG_PROCESSINGMETHOD\n" );
+ goto failure;
+ }
+ if (!TIFFSetField( tif, GPSTAG_AREAINFORMATION, 4, &auxCharArrayW[20])) {
+ fprintf (stderr, "Can't write GPSTAG_AREAINFORMATION\n" );
+ goto failure;
+ }
+
+ /*-- PSTAG_DIFFERENTIAL , 1, 1, TIFF_SHORT , 0, TIFF_SETGET_UINT16 */
+ if (!TIFFSetField( tif, GPSTAG_DIFFERENTIAL, auxShortArrayW[5])) {
+ fprintf (stderr, "Can't write GPSTAG_DIFFERENTIAL\n" );
+ goto failure;
+ }
+
+ /* GPSTAG_GPSHPOSITIONINGERROR , 1, 1, TIFF_RATIONAL , 0, TIFF_SETGET_DOUBLE but here written in float-precision */
+#define GPSHPOSITIONINGERROR_VAL 0.369
+ auxFloat = (float)GPSHPOSITIONINGERROR_VAL;
+ if (!TIFFSetField( tif, GPSTAG_GPSHPOSITIONINGERROR, auxFloat)) {
+ fprintf (stderr, "Can't write GPSTAG_GPSHPOSITIONINGERROR\n" );
+ goto failure;
+ }
+
+ } else {
+ /*================= Write arbitrary data to the GPS fields ==============*/
+
+ /*-- Get array, where GPS tag fields are defined --*/
+ tFieldArray = _TIFFGetGpsFields();
+ nTags = tFieldArray->count;
+
+ /*-- TODO: fill in the for / switch part of EXIF writing, when finished and tested!! */
+
+ } /*-- if (blnFillGPSManually) --*/
+
+
+
+
+ /*-- GPS - write custom directory GPS into file...---*/
+ /* (Get back the offset of GPS directory) */
+ if (!TIFFWriteCustomDirectory( tif, &dir_offset_GPS )) {
+ fprintf (stderr, "TIFFWriteCustomDirectory() with GPS failed.\n");
+ goto failure;
+ }
+
+ /*--- CheckpointDirectory at this place generates a second Main-IFD!!! */
+ /* retCode = TIFFCheckpointDirectory(tif); */
+
+ /*-- Set / reload previously saved main directory from file ---*/
+ if (!TIFFSetDirectory(tif, 0)) {
+ fprintf (stderr, "TIFFSetDirectory() within GPS failed.\n");
+ goto failure;
+ }
+
+ /*-- Write GPS tag reference / offset into GPSIFD tag in main directory --*/
+ if (!TIFFSetField(tif, TIFFTAG_GPSIFD, dir_offset_GPS )) {
+ fprintf (stderr, "Can't write TIFFTAG_GPSIFD\n");
+ goto failure;
+ }
+
+ /*=============== END writing GPS tags ==========================*/
+#endif /*-- WRITE_GPS_TAGS --*/
+
+
+/*================== Write EXIF 2.31 tags =====================*/
+
+ /*-- Set dummy EXIF/GPS tag in original tiff-structure in order to reserve space for final dir_offset value, */
+ /* which is properly written at the end.*/
+ /*- We did this already above together with the GPS IFD-tag. Otherwise we would do this here !! --------*/
+ /* if (!TIFFSetField(tif, TIFFTAG_EXIFIFD, dir_offset )) {
+ fprintf (stderr, "Can't write TIFFTAG_EXIFIFD\n" );
+ }
+ */
+
+#ifdef WRITE_EXIF_TAGS
+#define READ_EXIF_TAGS
+ /*-- Save current tiff-directory to file before directory is changed. Otherwise it will be lost!
+ * The tif-structure is overwritten/ freshly initialized by any "CreateDirectory"
+ */
+
+ /*----- What is needed here ??? ----
+ * In custom_dir.c only TIFFFreeDirectory( tif ); is used to set fields of another Sub-Directory
+ * TIFFFreeDirectory(tif); *-- Release storage associated with a directory, especially custom-fields.
+ *-- Using only TIFFFreeDirectory() here leads to an error!!
+ *-- Using here TIFFCheckpointDirectory() leads to an additional Main-IFD ??
+ */
+ /*retCode = TIFFCheckpointDirectory(tif);*/ /* does not cleanup Tiff-Structure */
+ retCode = TIFFWriteDirectory(tif); /* cleanup Tiff-structure */
+
+ /*-- Now create an EXIF directory. */
+ if (TIFFCreateEXIFDirectory(tif) != 0) {
+ fprintf (stderr, "TIFFCreateEXIFDirectory() failed.\n" );
+ goto failure;
+ }
+
+#define WRITE_ALL_EXIF_TAGS
+#ifdef WRITE_ALL_EXIF_TAGS
+#define READ_ALL_EXIF_TAGS
+ /*================= EXIF: Write arbitrary data to the EXIF fields ==============*/
+ /*-- Get array, where EXIF tag fields are defined
+ * EXIF tags are written automatically with the defined precision according to its tSetFieldType using the code below --*/
+ tFieldArray = _TIFFGetExifFields();
+ nTags = tFieldArray->count;
+
+ for (i=0; i<nTags; i++) {
+ tTag = tFieldArray->fields[i].field_tag;
+ tType = tFieldArray->fields[i].field_type; /* e.g. TIFF_RATIONAL */
+ tWriteCount = tFieldArray->fields[i].field_writecount;
+ tSetFieldType = tFieldArray->fields[i].set_field_type; /* e.g. TIFF_SETGET_C0_FLOAT */
+ tFieldName = tFieldArray->fields[i].field_name;
+ pVoid = NULL;
+
+ /*-- dependent on set_field_type write value --*/
+ switch (tSetFieldType)
+ {
+ case TIFF_SETGET_ASCII:
+ /* Either the stringlength is defined as a fixed length in .field_writecount or a NULL-terminated string is used. */
+ /* Shorter strings than in auxTextArraxW need a NULL-termination. Therefore copy the string. */
+ if (tWriteCount > 0) auxLong = tWriteCount-1; else auxLong = (long)strlen(auxTextArrayW[i])-1;
+ strncpy(auxCharArray, auxTextArrayW[i], auxLong);
+ auxCharArray[auxLong] = 0;
+ if (!TIFFSetField( tif, tTag, auxCharArray)) {
+ fprintf (stderr, "Can't write %s\n", tFieldArray->fields[i].field_name);
+ goto failure;
+ }
+ break;
+ case TIFF_SETGET_UINT8:
+ case TIFF_SETGET_UINT16:
+ case TIFF_SETGET_UINT32:
+ case TIFF_SETGET_IFD8:
+ case TIFF_SETGET_INT:
+ /*-- All those can be written with char, short or long parameter. Only value range should be in line. */
+ if (!TIFFSetField( tif, tTag, auxLongArrayW[i])) {
+ fprintf (stderr, "Can't write %s\n", tFieldArray->fields[i].field_name);
+ goto failure;
+ }
+ break;
+ case TIFF_SETGET_SINT8:
+ case TIFF_SETGET_SINT16:
+ case TIFF_SETGET_SINT32:
+ /*-- All those can be written with char, short or long parameter. Only value range should be in line. */
+ if (!TIFFSetField( tif, tTag, -1.0*auxLongArrayW[i])) {
+ fprintf (stderr, "Can't write %s\n", tFieldArray->fields[i].field_name);
+ goto failure;
+ }
+ break;
+ case TIFF_SETGET_FLOAT:
+ case TIFF_SETGET_DOUBLE:
+ if (tWriteCount == 1) {
+ /*-- All single values can be written with float or double parameter. Only value range should be in line. */
+ if (!TIFFSetField( tif, tTag, auxDoubleArrayW[i])) {
+ fprintf (stderr, "Can't write %s\n", tFieldArray->fields[i].field_name);
+ goto failure;
+ }
+ } else {
+ fprintf (stderr, "WriteCount for .set_field_type %d should be 1! %s\n", tSetFieldType, tFieldArray->fields[i].field_name);
+ }
+ break;
+ case TIFF_SETGET_C0_FLOAT:
+ case TIFF_SETGET_C0_DOUBLE:
+ case TIFF_SETGET_C16_FLOAT:
+ case TIFF_SETGET_C16_DOUBLE:
+ case TIFF_SETGET_C32_FLOAT:
+ case TIFF_SETGET_C32_DOUBLE:
+ /* _Cxx_ just defines the size of the count parameter for the array as C0=char, C16=short or C32=long */
+ /*-- Check, if it is a single parameter, a fixed array or a variable array */
+ if (tWriteCount == 1) {
+ fprintf (stderr, "WriteCount for .set_field_type %d should be -1 or greather than 1! %s\n", tSetFieldType, tFieldArray->fields[i].field_name);
+ } else {
+ /*-- Either fix or variable array --*/
+ /* For arrays, distinguishing between float or double is essential, even for writing */
+ if (tSetFieldType == TIFF_SETGET_C0_FLOAT || tSetFieldType == TIFF_SETGET_C16_FLOAT || tSetFieldType == TIFF_SETGET_C32_FLOAT)
+ pVoid = &auxFloatArrayW[i]; else pVoid = &auxDoubleArrayW[i];
+ /* Now decide between fixed or variable array */
+ if (tWriteCount > 1) {
+ /* fixed array with needed arraysize defined in .field_writecount */
+ if (!TIFFSetField( tif, tTag, pVoid)) {
+ fprintf (stderr, "Can't write %s\n", tFieldArray->fields[i].field_name);
+ goto failure;
+ }
+ } else {
+ /* special treatment of variable array */
+ /* for test, use always arraysize of VARIABLE_ARRAY_SIZE */
+ if (!TIFFSetField( tif, tTag, VARIABLE_ARRAY_SIZE, pVoid)) {
+ fprintf (stderr, "Can't write %s\n", tFieldArray->fields[i].field_name);
+ goto failure;
+ }
+ }
+ }
+ break;
+ case TIFF_SETGET_C0_UINT8:
+ case TIFF_SETGET_C0_SINT8:
+ case TIFF_SETGET_C16_UINT8:
+ case TIFF_SETGET_C16_SINT8:
+ case TIFF_SETGET_C32_UINT8:
+ case TIFF_SETGET_C32_SINT8:
+ /* For arrays, distinguishing between float or double is essential, even for writing */
+ pVoid = &auxCharArrayW[i];
+ case TIFF_SETGET_C0_UINT16:
+ case TIFF_SETGET_C0_SINT16:
+ case TIFF_SETGET_C16_UINT16:
+ case TIFF_SETGET_C16_SINT16:
+ case TIFF_SETGET_C32_UINT16:
+ case TIFF_SETGET_C32_SINT16:
+ if (pVoid == NULL) pVoid = &auxShortArrayW[i];
+ case TIFF_SETGET_C0_UINT32:
+ case TIFF_SETGET_C0_SINT32:
+ case TIFF_SETGET_C16_UINT32:
+ case TIFF_SETGET_C16_SINT32:
+ case TIFF_SETGET_C32_UINT32:
+ case TIFF_SETGET_C32_SINT32:
+ if (pVoid == NULL) pVoid = &auxLongArrayW[i];
+ /* _Cxx_ just defines the size of the count parameter for the array as C0=char, C16=short or C32=long */
+ /*-- Check, if it is a single parameter, a fixed array or a variable array */
+ if (tWriteCount == 1) {
+ fprintf (stderr, "WriteCount for .set_field_type %d should be -1 or greather than 1! %s\n", tSetFieldType, tFieldArray->fields[i].field_name);
+ } else {
+ /*-- Either fix or variable array --*/
+ /* Now decide between fixed or variable array */
+ if (tWriteCount > 1) {
+ /* fixed array with needed arraysize defined in .field_writecount */
+ if (!TIFFSetField( tif, tTag, pVoid)) {
+ fprintf (stderr, "Can't write %s\n", tFieldArray->fields[i].field_name);
+ goto failure;
+ }
+ } else {
+ /* special treatment of variable array */
+ /* for test, use always arraysize of VARIABLE_ARRAY_SIZE */
+ if (!TIFFSetField( tif, tTag, VARIABLE_ARRAY_SIZE, pVoid)) {
+ fprintf (stderr, "Can't write %s\n", tFieldArray->fields[i].field_name);
+ goto failure;
+ }
+ }
+ }
+ break;
+ default:
+ fprintf (stderr, "SetFieldType %d not defined within writing switch for %s.\n", tSetFieldType, tFieldName);
+ }; /*-- switch() --*/
+ } /*-- for() --*/
+ /*================= EXIF: END Writing arbitrary data to the EXIF fields END END END ==============*/
+#endif /*-- WRITE_ALL_EXIF_TAGS --*/
+
+ /*--- Set valid EXIF version, which is a 4 byte string --*/
+ if (!TIFFSetField( tif, EXIFTAG_EXIFVERSION, exifVersion)) {
+ fprintf (stderr, "Can't write EXIFTAG_EXIFVERSION\n" );
+ goto failure;
+ }
+
+
+ /*-- EXIF - write custom directory EXIF into file...---*/
+ /* (Get back the offset of EXIF directory) */
+ if (!TIFFWriteCustomDirectory( tif, &dir_offset_EXIF )) {
+ fprintf (stderr, "TIFFWriteCustomDirectory() with EXIF failed.\n");
+ goto failure;
+ }
+
+ /*-- Go back to the first (main) directory, and set correct value of the EXIFIFD pointer. */
+ /* (directory is reloaded from file!) */
+ TIFFSetDirectory(tif, 0);
+ TIFFSetField(tif, TIFFTAG_EXIFIFD, dir_offset_EXIF );
+#endif /*-- WRITE_EXIF_TAGS --*/
+
+#ifdef WRITEPIXELLAST
+ /*-- Write dummy pixel data. --*/
+ if (TIFFWriteScanline(tif, buf, 0, 0) < 0) {
+ fprintf (stderr, "Can't write image data.\n");
+ goto failure;
+ }
+#endif
+ /*-- Write directory to file --*/
+ /* Always WriteDirectory before using/creating another directory. */
+ /* Not necessary before TIFFClose(), however, TIFFClose() uses TIFFReWriteDirectory(), which forces directory to be written at another location. */
+ retCode = TIFFWriteDirectory(tif);
+
+ /*-- Write File to disk and close file --*/
+ /* TIFFClose() uses TIFFReWriteDirectory(), which forces directory to be written at another location. */
+ /* Therefore, better use TIFFWriteDirectory() before. */
+ TIFFClose(tif);
+
+ fprintf (stderr, "-------- Continue Test ---------- reading ...\n");
+
+/*========================= READING ============= READING ========================================*/
+ /* Ok, now test whether we can read written values correctly. */
+ tif = TIFFOpen(filenameRead, "r");
+
+
+ /*-- Read some parameters out of the main directory --*/
+
+ /*-- IMAGEWIDTH and -LENGTH are defined as TIFF_SETGET_UINT32 */
+ retCode = TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &auxUint32 );
+ if (!retCode) { fprintf(stderr, "Can't read %s\n", "TIFFTAG_IMAGEWIDTH"); }
+ if (auxUint32 != width) {
+ fprintf (stderr, "Read value of IMAGEWIDTH %d differs from set value %d\n", auxUint32, width);
+ }
+ retCode = TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &auxUint32 );
+ if (!retCode) { fprintf(stderr, "Can't read %s\n", "TIFFTAG_IMAGELENGTH"); }
+ if (auxUint32 != width) {
+ fprintf (stderr, "Read value of TIFFTAG_IMAGELENGTH %d differs from set value %d\n", auxUint32, length);
+ }
+
+#ifdef ADDITIONAL_TAGS
+ /*- TIFFTAG_PIXAR_FOVCOT is a FLOAT parameter of type FIELD_CUSTOM !! */
+ retCode = TIFFGetField(tif, TIFFTAG_PIXAR_FOVCOT, &auxFloat );
+ if (!retCode) { fprintf(stderr, "Can't read %s\n", "TIFFTAG_PIXAR_FOVCOT"); }
+ if (auxFloat != (float)PIXAR_FOVCOT_VAL) {
+ fprintf (stderr, "Read value of TIFFTAG_PIXAR_FOVCOT %f differs from set value %f\n", auxFloat, PIXAR_FOVCOT_VAL);
+ }
+
+ /* - TIFFTAG_BESTQUALITYSCALE is a Rational parameter, FIELD_CUSTOM and TIFF_SETGET_FLOAT */
+ retCode = TIFFGetField(tif, TIFFTAG_BESTQUALITYSCALE, &auxFloat );
+ if (!retCode) { fprintf(stderr, "Can't read %s\n", "TIFFTAG_BESTQUALITYSCALE"); }
+ if (auxFloat != (float)BESTQUALITYSCALE_VAL) {
+ fprintf (stderr, "Read value of TIFFTAG_BESTQUALITYSCALE %f differs from set value %f\n", auxFloat, BESTQUALITYSCALE_VAL);
+ }
+
+ /* - TIFFTAG_BASELINENOISE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT */
+ retCode = TIFFGetField(tif, TIFFTAG_BASELINENOISE, &auxDblUnion.dbl);
+ if (!retCode) { fprintf(stderr, "Can't read %s\n", "TIFFTAG_BASELINENOISE"); }
+ if (auxDblUnion.flt1 != (float)BESTQUALITYSCALE_VAL) {
+ fprintf(stderr, "Read float value of TIFFTAG_BASELINENOISE %f differs from set value %f\n", auxDblUnion.flt1, BESTQUALITYSCALE_VAL);
+ }
+
+
+ /*- Variable Array: TIFFTAG_DECODE is a SRATIONAL parameter TIFF_SETGET_C16_FLOAT type FIELD_CUSTOM with passcount=1 and variable length of array. */
+ retCode = TIFFGetField(tif, TIFFTAG_DECODE, &count16, &pVoidArray );
+ if (!retCode) { fprintf(stderr, "Can't read %s\n", "TIFFTAG_DECODE"); }
+ /*- pVoidArray points to a Tiff-internal temporary memorypart. Thus, contents needs to be saved. */
+ memcpy(&auxFloatArray, pVoidArray,(count16 * sizeof(auxFloatArray[0])));
+ for (i=0; i<count16; i++) {
+ dblDiffLimit = RATIONAL_EPS*auxFloatArrayN2[i];
+ dblDiff = auxFloatArray[i] - auxFloatArrayN2[i];
+ if (fabs(dblDiff) > fabs(dblDiffLimit)) {
+ fprintf (stderr, "Read value %d of TIFFTAG_DECODE Array %f differs from set value %f\n", i, auxFloatArray[i], auxFloatArrayN2[i]);
+ }
+ }
+
+ retCode = TIFFGetField(tif, TIFFTAG_BLACKLEVEL, &count16, &pVoidArray);
+ if (!retCode) { fprintf(stderr, "Can't read %s\n", "TIFFTAG_BLACKLEVEL"); }
+ /*- pVoidArray points to a Tiff-internal temporary memorypart. Thus, contents needs to be saved. */
+ memcpy(&auxFloatArray, pVoidArray, (count16 * sizeof(auxFloatArray[0])));
+ for (i = 0; i<count16; i++) {
+ dblDiffLimit = RATIONAL_EPS*auxFloatArrayN1[i];
+ dblDiff = auxFloatArray[i] - auxFloatArrayN1[i];
+ if (fabs(dblDiff) > fabs(dblDiffLimit)) {
+ fprintf(stderr, "Read value %d of TIFFTAG_BLACKLEVEL Array %f differs from set value %f\n", i, auxFloatArray[i], auxFloatArrayN1[i]);
+ }
+ }
+
+ /*- Fixed Array: TIFFTAG_DEFAULTCROPSIZE, 2, 2, TIFF_RATIONAL, 0, TIFF_SETGET_C0_FLOAT */
+ retCode = TIFFGetField(tif, TIFFTAG_DEFAULTCROPSIZE, &pVoidArray);
+ if (!retCode) { fprintf(stderr, "Can't read %s\n", "TIFFTAG_DEFAULTCROPSIZE"); }
+ /*- pVoidArray points to a Tiff-internal temporary memorypart. Thus, contents needs to be saved. */
+ memcpy(&auxFloatArray, pVoidArray, (2 * sizeof(auxFloatArray[0])));
+ for (i = 0; i < 2; i++) {
+ dblDiffLimit = RATIONAL_EPS * auxFloatArrayW[i];
+ dblDiff = auxFloatArray[i] - auxFloatArrayW[i];
+ if (fabs(dblDiff) > fabs(dblDiffLimit)) {
+ fprintf(stderr, "Read value %d of TIFFTAG_DEFAULTCROPSIZE Array %f differs from set value %f\n", i, auxFloatArray[i], auxFloatArrayW[i]);
+ }
+ }
+
+#endif /*-- ADDITIONAL_TAGS --*/
+
+
+#ifdef READ_GPS_TAGS
+/*================== Reading GPS tags =====================*/
+ /*-- First get offset to GPS-directory and set it active (this will destroy previously main directory fields in memory!) */
+ retCode = TIFFGetField(tif, TIFFTAG_GPSIFD, &read_dir_offset );
+ if (!retCode) {fprintf(stderr, "Can't read %s\n", "TIFFTAG_GPSIFD"); }
+ retCode = TIFFReadGPSDirectory(tif, read_dir_offset);
+ if (!retCode) { fprintf(stderr, "Can't read %s\n", "TIFFReadGPSDirectory()"); }
+
+ /*-- Now read some parameters from GPS-directory --*/
+
+ /*-- Fixed Array: GPS-Version is a fixed array (of 4 characters) */
+ retCode = TIFFGetField(tif, GPSTAG_VERSIONID, &pGpsVersion);
+ if (!retCode) { fprintf(stderr, "Can't read %s\n", "GPSTAG_VERSIONID"); }
+ else {
+ memcpy(auxCharArray, pGpsVersion, sizeof(gpsVersion));
+ for (i = 0; i < 4; i++) {
+ if (auxCharArray[i] != pGpsVersion[i]) {
+ fprintf(stderr, "Read value %d of GPSTAG_VERSIONID %d differs from set value %d\n", i, auxCharArray[i], pGpsVersion[i]);
+ }
+ }
+ }
+ /*-- LATITUDEREF is a fixed String of one character plus ending zero. */
+ retCode = TIFFGetField(tif, GPSTAG_LATITUDEREF, &pAscii);
+ if (!retCode) { fprintf(stderr, "Can't read %s\n", "GPSTAG_LATITUDEREF"); }
+ retCode2 = strncmp("N", pAscii, 1);
+ if (retCode2 != 0) {
+ fprintf (stderr, "Read value %d of GPSTAG_LATITUDEREF %s differs from set value %s\n", i, "N", pAscii);
+ }
+
+ /*-- Fixed Array: Latitude is an array of 3 Rational-values. TIFFGetField() returns a pointer to a temporary float-/double-array. */
+ /*-- ATTENTION: After the upgrade with Rational2Double, the GPSTAG values are defined as double precision
+ * and need to be written and also read in double precision!
+ * In order to maintain this code for both cases, it is checked above if the TiffLibrary is
+ * compiled with the new interface with Rational2Double or still uses the old definitions,
+ * by setting blnIsRational2Double above.
+ */
+ if (blnIsRational2Double) {
+ fprintf(stderr, "-- GPS tags are read using Rational2Double --\n");
+ } else {
+ fprintf(stderr, "-- GPS tags are read using standard --\n");
+ }
+ retCode = TIFFGetField(tif, GPSTAG_LATITUDE, &pVoidArray);
+ if (!retCode) { fprintf(stderr, "Can't read %s\n", "GPSTAG_LATITUDE"); }
+ if (!blnIsRational2Double) {
+ /* Reset arrays for debugging purpose first */
+ memset(auxFloatArray, 0, sizeof(auxFloatArray));
+ memcpy(auxFloatArray, pVoidArray, 3*sizeof(float));
+ /* for comparison copy to doubleArray */
+ for (i=0; i<3; i++) auxDoubleArray[i] = (double)auxFloatArray[i];
+ } else {
+ /* Rational2Double interface for GPSTAG reads double array */
+ memset(auxDoubleArray, 0, sizeof(auxDoubleArray));
+ memcpy(auxDoubleArray, pVoidArray, 3 * sizeof(double));
+ }
+ for (i=0; i<3; i++) {
+ dblDiffLimit = RATIONAL_EPS*auxDoubleArrayGPS1[i];
+ dblDiff = auxDoubleArray[i] - auxDoubleArrayGPS1[i];
+ if (fabs(dblDiff) > fabs(dblDiffLimit)) {
+ fprintf (stderr, "Read value %d of GPSTAG_LATITUDE %f differs from set value %f\n", i, auxDoubleArray[i], auxDoubleArrayGPS1[i]);
+ }
+ }
+
+ /*-- LONGITUDEREF is a fixed String of one character plus ending zero. */
+ retCode = TIFFGetField(tif, GPSTAG_LONGITUDEREF, &pAscii);
+ if (!retCode) { fprintf(stderr, "Can't read %s\n", "GPSTAG_LONGITUDEREF"); }
+ retCode2 = strncmp("W", pAscii, 1);
+ if (retCode2 != 0) {
+ fprintf(stderr, "Read value %d of GPSTAG_LONGITUDEREF %s differs from set value %s\n", i, "W", pAscii);
+ }
+
+ retCode = TIFFGetField(tif, GPSTAG_LONGITUDE, &pVoidArray);
+ if (!retCode) { fprintf(stderr, "Can't read %s\n", "GPSTAG_LONGITUDE"); }
+ if (!blnIsRational2Double) {
+ /* Reset arrays for debugging purpose first */
+ memset(auxFloatArray, 0, sizeof(auxFloatArray));
+ memcpy(auxFloatArray, pVoidArray, 3 * sizeof(float));
+ /* for comparison copy to doubleArray */
+ for (i = 0; i < 3; i++) auxDoubleArray[i] = (double)auxFloatArray[i];
+ } else {
+ /* Rational2Double interface for GPSTAG reads double array */
+ memset(auxDoubleArray, 0, sizeof(auxDoubleArray));
+ memcpy(auxDoubleArray, pVoidArray, 3 * sizeof(double));
+ }
+ for (i = 0; i < 3; i++) {
+ dblDiffLimit = RATIONAL_EPS * auxDoubleArrayGPS2[i];
+ dblDiff = auxDoubleArray[i] - auxDoubleArrayGPS2[i];
+ if (fabs(dblDiff) > fabs(dblDiffLimit)) {
+ fprintf(stderr, "Read value %d of GPSTAG_LONGITUDE %f differs from set value %f\n", i, auxDoubleArray[i], auxDoubleArrayGPS2[i]);
+ }
+ }
+
+ /* TIFF_RATIONAL, TIFF_SETGET_DOUBLE */
+ if (!TIFFGetField(tif, GPSTAG_ALTITUDE, &auxDblUnion.dbl)) {
+ fprintf(stderr, "Can't read GPSTAG_ALTITUDE\n");
+ GOTOFAILURE_GPS
+ }
+ if (blnIsRational2Double) {
+ /* New interface allows also double precision for TIFF_RATIONAL */
+ auxDouble = auxDblUnion.dbl;
+ } else {
+ /* Old interface reads TIFF_RATIONAL defined as TIFF_SETGET_DOUBLE alwasy as FLOAT */
+ auxDouble = (double)auxDblUnion.flt1;
+ }
+ /* compare read values with written ones */
+ dblDiffLimit = RATIONAL_EPS * auxDoubleGPSAltitude;
+ dblDiff = auxDouble - auxDoubleGPSAltitude;
+ if (fabs(dblDiff) > fabs(dblDiffLimit)) {
+ fprintf(stderr, "Read value of GPSTAG_ALTITUDE %f differs from set value %f\n", auxDouble, auxDoubleGPSAltitude);
+ GOTOFAILURE_GPS
+ }
+
+ /*-- TimeStamp is only hh:mm:ss. See also DateTime string 3, TIFF_RATIONAL, TIFF_SETGET_C0_DOUBLE */
+ retCode = TIFFGetField(tif, GPSTAG_TIMESTAMP, &pVoidArray);
+ if (!retCode) { fprintf(stderr, "Can't read %s\n", "GPSTAG_TIMESTAMP"); }
+ if (!blnIsRational2Double) {
+ /* Reset arrays for debugging purpose first */
+ memset(auxFloatArray, 0, sizeof(auxFloatArray));
+ memcpy(auxFloatArray, pVoidArray, 3 * sizeof(float));
+ /* for comparison copy to doubleArray */
+ for (i = 0; i < 3; i++) auxDoubleArray[i] = (double)auxFloatArray[i];
+ } else {
+ /* Rational2Double interface for GPSTAG reads double array */
+ memset(auxDoubleArray, 0, sizeof(auxDoubleArray));
+ memcpy(auxDoubleArray, pVoidArray, 3 * sizeof(double));
+ }
+ for (i = 0; i < 3; i++) {
+ dblDiffLimit = RATIONAL_EPS * auxDoubleArrayGPSTime[i];
+ dblDiff = auxDoubleArray[i] - auxDoubleArrayGPSTime[i];
+ if (fabs(dblDiff) > fabs(dblDiffLimit)) {
+ fprintf(stderr, "Read value %d of GPSTAG_TIMESTAMP %f differs from set value %f\n", i, auxDoubleArray[i], auxDoubleArrayGPS2[i]);
+ GOTOFAILURE_GPS
+ }
+ }
+
+ /* GPSTAG_IMGDIRECTION --- TIFF_RATIONAL, TIFF_SETGET_DOUBLE */
+ if (!TIFFGetField(tif, GPSTAG_IMGDIRECTION, &auxDblUnion.dbl)) {
+ fprintf(stderr, "Can't read GPSTAG_IMGDIRECTION\n");
+ GOTOFAILURE_GPS
+ }
+ if (blnIsRational2Double) {
+ /* New interface allows also double precision for TIFF_RATIONAL */
+ auxDouble = auxDblUnion.dbl;
+ } else {
+ /* Old interface reads TIFF_RATIONAL defined as TIFF_SETGET_DOUBLE alwasy as FLOAT */
+ auxDouble = (double)auxDblUnion.flt1;
+ }
+ /* compare read values with written ones */
+ dblDiffLimit = RATIONAL_EPS * auxDoubleGPSDirection;
+ dblDiff = auxDouble - auxDoubleGPSDirection;
+ if (fabs(dblDiff) > fabs(dblDiffLimit)) {
+ fprintf(stderr, "Read value of GPSTAG_IMGDIRECTION %f differs from set value %f\n", auxDouble, auxDoubleGPSDirection);
+ GOTOFAILURE_GPS
+ }
+
+ /*-- GPSTAG_DIFFERENTIAL , 1, 1, TIFF_SHORT , 0, TIFF_SETGET_UINT16 */
+ retCode = TIFFGetField(tif, GPSTAG_DIFFERENTIAL, &auxShort);
+ if (!retCode) { fprintf(stderr, "Can't read %s\n", "GPSTAG_DIFFERENTIAL"); }
+ if (auxShort != auxShortArrayW[5]) {
+ fprintf(stderr, "Read value of GPSTAG_DIFFERENTIAL %d differs from set value %d\n", auxShort, auxShortArrayW[5]);
+ GOTOFAILURE_GPS
+ }
+
+ /*-- GPSHPOSITIONINGERROR - new tag for EXIF 2.31 --*/
+ if (!TIFFGetField(tif, GPSTAG_GPSHPOSITIONINGERROR, &auxDblUnion.dbl)) {
+ fprintf(stderr, "Can't read GPSTAG_GPSHPOSITIONINGERROR\n");
+ GOTOFAILURE_GPS
+ }
+ if (blnIsRational2Double) {
+ /* New interface allows also double precision for TIFF_RATIONAL */
+ auxDouble = auxDblUnion.dbl;
+ } else {
+ /* Old interface reads TIFF_RATIONAL defined as TIFF_SETGET_DOUBLE alwasy as FLOAT */
+ auxDouble = (double)auxDblUnion.flt1;
+ }
+ /* compare read values with written ones */
+ auxFloat = (float)GPSHPOSITIONINGERROR_VAL;
+ dblDiffLimit = RATIONAL_EPS * auxFloat;
+ dblDiff = auxDouble - auxFloat;
+ if (fabs(dblDiff) > fabs(dblDiffLimit)) {
+ fprintf(stderr, "Read value of GPSTAG_GPSHPOSITIONINGERROR %f differs from set value %f\n", auxDouble, auxFloat);
+ GOTOFAILURE_GPS
+ }
+
+ /*=============== END reading GPS tags ==========================*/
+#endif /*-- READ_GPS_TAGS --*/
+
+
+
+/*================== Reading EXIF 2.31 tags =====================*/
+
+ /*--- Firstly, get EXIF directory offset from main directory. */
+
+ /*-- Go back to the first (main) directory, and get value of the EXIFIFD directory- offset. */
+ /* (directory is reloaded from file!) */
+ TIFFSetDirectory(tif, 0);
+ retCode = TIFFGetField(tif, TIFFTAG_EXIFIFD, &read_dir_offset );
+
+#ifdef READ_EXIF_TAGS
+ /*-- Now read EXIF directory from file into memory --*/
+ retCode = TIFFReadEXIFDirectory(tif, read_dir_offset);
+
+ /*-- Now get some parameters from EXIF-directory (already read into memory) --*/
+ retCode = TIFFGetField(tif, EXIFTAG_EXIFVERSION, &pAscii);
+
+
+#ifdef READ_ALL_EXIF_TAGS
+ /*-- Get array, where EXIF tag fields are defined --*/
+ tFieldArray = _TIFFGetExifFields();
+ nTags = tFieldArray->count;
+ /*-- Check, if the TiffLibrary is compiled with the new interface with Rational2Double or still uses the old definitions. */
+ /* tif points to EXIF tags, so TIFFFindField() can only access the EXIF tag fields */
+ fip = TIFFFindField(tif, EXIFTAG_EXPOSURETIME, TIFF_ANY);
+ tSetFieldType = fip->set_field_type;
+ if (tSetFieldType == TIFF_SETGET_DOUBLE) {
+ blnIsRational2Double = FALSE;
+ fprintf(stderr, "-- EXIF tags read with standard --\n");
+ } else {
+ blnIsRational2Double = TRUE;
+ fprintf(stderr, "-- Rational2Double for reading EXIF tags detected --\n");
+ }
+
+ for (i=0; i<nTags; i++) {
+ tTag = tFieldArray->fields[i].field_tag;
+ tType = tFieldArray->fields[i].field_type; /* e.g. TIFF_RATIONAL */
+ tWriteCount = tFieldArray->fields[i].field_writecount;
+ tSetFieldType = tFieldArray->fields[i].set_field_type; /* e.g. TIFF_SETGET_C0_FLOAT */
+ tFieldName = tFieldArray->fields[i].field_name;
+ pVoid = NULL;
+
+ /*-- dependent on set_field_type read value --*/
+ switch (tSetFieldType)
+ {
+ case TIFF_SETGET_ASCII:
+ /* Either the stringlength is defined as a fixed length in .field_writecount or a NULL-terminated string is used. */
+ if (!TIFFGetField( tif, tTag, &pAscii)) {
+ fprintf (stderr, "Can't read %s\n", tFieldArray->fields[i].field_name);
+ GOTOFAILURE_ALL_EXIF
+ break;
+ }
+ /* Save string from temporary buffer and compare with written string. */
+ strncpy(auxCharArray, pAscii, sizeof(auxCharArray));
+ if (tWriteCount > 0) auxLong = tWriteCount-1; else auxLong = (long)strlen(auxCharArray);
+ retCode2 = strncmp(auxCharArray, auxTextArrayW[i], auxLong);
+ if (retCode2 != 0) {
+ fprintf (stderr, "%d:Read value of %s %s differs from set value %s\n", i, tFieldName, auxCharArray, auxTextArrayW[i]);
+ GOTOFAILURE_ALL_EXIF
+ }
+ break;
+ /*-- For reading, the parameter size is to be observed !! */
+ case TIFF_SETGET_UINT8:
+ case TIFF_SETGET_SINT8:
+ if (!TIFFGetField( tif, tTag, &auxChar)) {
+ fprintf (stderr, "Can't read %s\n", tFieldArray->fields[i].field_name);
+ GOTOFAILURE_ALL_EXIF
+ break;
+ }
+ /* compare read values with written ones */
+ auxLong = auxChar;
+ if (auxLong != (char)auxLongArrayW[i]) {
+ fprintf (stderr, "%d:Read value of %s %ld differs from set value %ld\n", i, tFieldName, auxLong, auxLongArrayW[i]);
+ }
+ break;
+ case TIFF_SETGET_UINT16:
+ case TIFF_SETGET_SINT16:
+ if (!TIFFGetField( tif, tTag, &auxShort)) {
+ fprintf (stderr, "Can't read %s\n", tFieldArray->fields[i].field_name);
+ GOTOFAILURE_ALL_EXIF
+ break;
+ }
+ /* compare read values with written ones */
+ auxLong = auxShort;
+ if (auxLong != (short)auxLongArrayW[i]) {
+ fprintf (stderr, "%d:Read value of %s %ld differs from set value %ld\n", i, tFieldName, auxLong, auxLongArrayW[i]);
+ }
+ break;
+ case TIFF_SETGET_UINT32:
+ case TIFF_SETGET_SINT32:
+ case TIFF_SETGET_IFD8:
+ case TIFF_SETGET_INT:
+ if (!TIFFGetField( tif, tTag, &auxUint32)) {
+ fprintf (stderr, "Can't read %s\n", tFieldArray->fields[i].field_name);
+ GOTOFAILURE_ALL_EXIF
+ break;
+ }
+ /* compare read values with written ones */
+ auxLong = auxUint32;
+ if (auxLong != auxLongArrayW[i]) {
+ fprintf (stderr, "%d:Read value of %s %ld differs from set value %ld\n", i, tFieldName, auxLong, auxLongArrayW[i]);
+ }
+ break;
+ case TIFF_SETGET_FLOAT:
+ if (!TIFFGetField( tif, tTag, &auxFloat)) {
+ fprintf (stderr, "Can't read %s\n", tFieldArray->fields[i].field_name);
+ GOTOFAILURE_ALL_EXIF
+ break;
+ }
+ /* compare read values with written ones */
+ if (tType == TIFF_RATIONAL || tType == TIFF_SRATIONAL) dblDiffLimit = RATIONAL_EPS*auxDoubleArrayW[i]; else dblDiffLimit = 1e-6;
+ dblDiff = auxFloat - auxDoubleArrayW[i];
+ if (fabs(dblDiff) > fabs(dblDiffLimit)) {
+ /*--: EXIFTAG_SUBJECTDISTANCE: LibTiff returns value of "-1.0" if numerator equals 4294967295 (0xFFFFFFFF) to indicate infinite distance!
+ * However, there are two other EXIF tags where numerator indicates a special value and six other cases where the denominator indicates special values,
+ * which are not treated within LibTiff!!
+ */
+ if (!(tTag == EXIFTAG_SUBJECTDISTANCE && auxFloat == -1.0)) {
+ fprintf (stderr, "%d:Read value of %s %f differs from set value %f\n", i, tFieldName, auxFloat, auxDoubleArrayW[i]);
+ GOTOFAILURE_ALL_EXIF
+ }
+ }
+ break;
+ case TIFF_SETGET_DOUBLE:
+ /*-- Unfortunately, TIFF_SETGET_DOUBLE is used for TIFF_RATIONAL but those have to be read with FLOAT !!! */
+ /* Only TIFFTAG_STONITS is a TIFF_DOUBLE, which has to be read as DOUBLE!! */
+ /*-- ATTENTION: ----
+ * Only after update with Rational2Double feature, also TIFF_RATIONAL can be read in double precision!!!
+ * Therefore, use a union to avoid overflow in TIFFGetField() return value
+ * and depending on version check for the right interface here:
+ * - old interface: correct value should be here a float
+ * - new interface: correct value should be here a double
+ * Interface version (old/new) is determined above.
+ -------------------*/
+ if (!TIFFGetField(tif, tTag, &auxDblUnion.dbl)) {
+ fprintf(stderr, "Can't read %s\n", tFieldArray->fields[i].field_name);
+ GOTOFAILURE_ALL_EXIF
+ break;
+ }
+ if (tType == TIFF_RATIONAL || tType == TIFF_SRATIONAL) {
+ if (blnIsRational2Double) {
+ /* New interface allows also double precision for TIFF_RATIONAL */
+ auxDouble = auxDblUnion.dbl;
+ }
+ else {
+ /* Old interface reads TIFF_RATIONAL defined as TIFF_SETGET_DOUBLE alwasy as FLOAT */
+ auxDouble = (double)auxDblUnion.flt1;
+ }
+ }
+ else {
+ auxDouble = auxDblUnion.dbl;
+ }
+ /* compare read values with written ones */
+ if (tType == TIFF_RATIONAL || tType == TIFF_SRATIONAL) dblDiffLimit = RATIONAL_EPS*auxDoubleArrayW[i]; else dblDiffLimit = 1e-6;
+ dblDiff = auxDouble - auxDoubleArrayW[i];
+ if (fabs(dblDiff) > fabs(dblDiffLimit)) {
+ /*--: EXIFTAG_SUBJECTDISTANCE: LibTiff returns value of "-1.0" if numerator equals 4294967295 (0xFFFFFFFF) to indicate infinite distance! */
+ if (!(tTag == EXIFTAG_SUBJECTDISTANCE && auxDouble == -1.0)) {
+ fprintf (stderr, "%d:Read value of %s %f differs from set value %f\n", i, tFieldName, auxDouble, auxDoubleArrayW[i]);
+ GOTOFAILURE_ALL_EXIF
+ }
+ }
+ break;
+
+ case TIFF_SETGET_C0_FLOAT:
+ case TIFF_SETGET_C0_DOUBLE:
+ case TIFF_SETGET_C16_FLOAT:
+ case TIFF_SETGET_C16_DOUBLE:
+ case TIFF_SETGET_C32_FLOAT:
+ case TIFF_SETGET_C32_DOUBLE:
+ /* _Cxx_ just defines the size of the count parameter for the array as C0=char, C16=short or C32=long */
+ /*-- Check, if it is a single parameter, a fixed array or a variable array */
+ if (tWriteCount == 1) {
+ fprintf (stderr, "Reading: WriteCount for .set_field_type %d should be -1 or greather than 1! %s\n", tSetFieldType, tFieldArray->fields[i].field_name);
+ } else {
+ /*-- Either fix or variable array --*/
+ /* For arrays, distinguishing between float or double is essential. */
+ /* Now decide between fixed or variable array */
+ if (tWriteCount > 1) {
+ /* fixed array with needed arraysize defined in .field_writecount */
+ if (!TIFFGetField( tif, tTag, &pVoidArray)) {
+ fprintf (stderr, "Can't read %s\n", tFieldArray->fields[i].field_name);
+ GOTOFAILURE_ALL_EXIF
+ break;
+ }
+ /* set tWriteCount to number of read samples for next steps */
+ auxLong = tWriteCount;
+ } else {
+ /* Special treatment of variable array. */
+ /* Dependent on Cxx, the count parameter is char, short or long. Therefore use unionLong! */
+ if (!TIFFGetField( tif, tTag, &unionLong, &pVoidArray)) {
+ fprintf (stderr, "Can't read %s\n", tFieldArray->fields[i].field_name);
+ GOTOFAILURE_ALL_EXIF
+ break;
+ }
+ /* set tWriteCount to number of read samples for next steps */
+ auxLong = unionLong.Short1;
+ }
+ /* Save values from temporary array */
+ if (tSetFieldType == TIFF_SETGET_C0_FLOAT || tSetFieldType == TIFF_SETGET_C16_FLOAT || tSetFieldType == TIFF_SETGET_C32_FLOAT) {
+ memcpy(&auxFloatArray, pVoidArray,(auxLong * sizeof(auxFloatArray[0])));
+ /* compare read values with written ones */
+ if (tType == TIFF_RATIONAL || tType == TIFF_SRATIONAL) dblDiffLimit = RATIONAL_EPS*auxDoubleArrayW[i]; else dblDiffLimit = 1e-6;
+ for (j=0; j<auxLong; j++) {
+ dblDiff = auxFloatArray[j] - auxFloatArrayW[i+j];
+ if (fabs(dblDiff) > fabs(dblDiffLimit)) {
+ /*if (auxFloatArray[j] != (float)auxFloatArrayW[i+j]) { */
+ fprintf (stderr, "Read value %d of %s #%d %f differs from set value %f\n", i, tFieldName, j, auxFloatArray[j], auxFloatArrayW[i+j]);
+ GOTOFAILURE_ALL_EXIF
+ }
+ }
+ } else {
+ memcpy(&auxDoubleArray, pVoidArray,(auxLong * sizeof(auxDoubleArray[0])));
+ /* compare read values with written ones */
+ if (tType == TIFF_RATIONAL || tType == TIFF_SRATIONAL) dblDiffLimit = RATIONAL_EPS*auxDoubleArrayW[i]; else dblDiffLimit = 1e-6;
+ for (j=0; j<auxLong; j++) {
+ dblDiff = auxDoubleArray[j] - auxDoubleArrayW[i+j];
+ if (fabs(dblDiff) > fabs(dblDiffLimit)) {
+ /*if (auxDoubleArray[j] != auxDoubleArrayW[i+j]) { */
+ fprintf (stderr, "Read value %d of %s #%d %f differs from set value %f\n", i, tFieldName, j, auxDoubleArray[j], auxDoubleArrayW[i+j]);
+ GOTOFAILURE_ALL_EXIF
+ }
+ }
+ }
+ }
+ break;
+ case TIFF_SETGET_C0_UINT8:
+ case TIFF_SETGET_C0_SINT8:
+ case TIFF_SETGET_C16_UINT8:
+ case TIFF_SETGET_C16_SINT8:
+ case TIFF_SETGET_C32_UINT8:
+ case TIFF_SETGET_C32_SINT8:
+ /* For arrays, distinguishing between float or double is essential, even for writing */
+ pVoid = &auxCharArrayW[i];
+ case TIFF_SETGET_C0_UINT16:
+ case TIFF_SETGET_C0_SINT16:
+ case TIFF_SETGET_C16_UINT16:
+ case TIFF_SETGET_C16_SINT16:
+ case TIFF_SETGET_C32_UINT16:
+ case TIFF_SETGET_C32_SINT16:
+ if (pVoid == NULL) pVoid = &auxShortArrayW[i];
+ case TIFF_SETGET_C0_UINT32:
+ case TIFF_SETGET_C0_SINT32:
+ case TIFF_SETGET_C16_UINT32:
+ case TIFF_SETGET_C16_SINT32:
+ case TIFF_SETGET_C32_UINT32:
+ case TIFF_SETGET_C32_SINT32:
+ if (pVoid == NULL) pVoid = &auxLongArrayW[i];
+ /* _Cxx_ just defines the size of the count parameter for the array as C0=char, C16=short or C32=long */
+ /*-- Check, if it is a single parameter, a fixed array or a variable array */
+ if (tWriteCount == 1) {
+ fprintf (stderr, "WriteCount for .set_field_type %d should be -1 or greather than 1! %s\n", tSetFieldType, tFieldArray->fields[i].field_name);
+ } else {
+ /*-- Either fix or variable array --*/
+ /* Now decide between fixed or variable array */
+ if (tWriteCount > 1) {
+ /* fixed array with needed arraysize defined in .field_writecount */
+ if (!TIFFGetField( tif, tTag, &pVoidArray)) {
+ fprintf (stderr, "Can't read %s\n", tFieldArray->fields[i].field_name);
+ GOTOFAILURE_ALL_EXIF
+ break;
+ }
+ /* set tWriteCount to number of read samples for next steps */
+ auxLong = tWriteCount;
+ } else {
+ /* special treatment of variable array */
+ /* for test, use always arraysize of VARIABLE_ARRAY_SIZE */
+ if (!TIFFGetField( tif, tTag, &unionLong, &pVoidArray)) {
+ fprintf (stderr, "Can't read %s\n", tFieldArray->fields[i].field_name);
+ GOTOFAILURE_ALL_EXIF
+ break;
+ }
+ /* set tWriteCount to number of read samples for next steps */
+ auxLong = unionLong.Short1;
+ }
+ /* Save values from temporary array */
+ if (tSetFieldType == TIFF_SETGET_C0_UINT8 || tSetFieldType == TIFF_SETGET_C0_SINT8 ||
+ tSetFieldType == TIFF_SETGET_C16_UINT8 || tSetFieldType == TIFF_SETGET_C16_SINT8 ||
+ tSetFieldType == TIFF_SETGET_C32_UINT8 || tSetFieldType == TIFF_SETGET_C32_SINT8 ) {
+ memcpy(&auxCharArray, pVoidArray,(auxLong * sizeof(auxCharArray[0])));
+ /* Compare and check values */
+ for (j=0; j<auxLong; j++) {
+ if (tTag == EXIFTAG_EXIFVERSION) {
+ /*-- Use exifVersion[] instead of auxCharArrayW[] for differently set EXIFVERSION tag */
+ if (auxCharArray[j] != exifVersion[j]) {
+ fprintf(stderr, "Read value %d of %s #%d %d differs from set value %d\n", i, tFieldName, j, auxCharArray[j], auxCharArrayW[i + j]);
+ GOTOFAILURE_ALL_EXIF
+ }
+ } else {
+ if (auxCharArray[j] != auxCharArrayW[i + j]) {
+ fprintf(stderr, "Read value %d of %s #%d %d differs from set value %d\n", i, tFieldName, j, auxCharArray[j], auxCharArrayW[i + j]);
+ GOTOFAILURE_ALL_EXIF
+ }
+ }
+ }
+ } else if (tSetFieldType == TIFF_SETGET_C0_UINT16 || tSetFieldType == TIFF_SETGET_C0_SINT16 ||
+ tSetFieldType == TIFF_SETGET_C16_UINT16 || tSetFieldType == TIFF_SETGET_C16_SINT16 ||
+ tSetFieldType == TIFF_SETGET_C32_UINT16 || tSetFieldType == TIFF_SETGET_C32_SINT16 ) {
+ memcpy(&auxShortArray, pVoidArray,(auxLong * sizeof(auxShortArray[0])));
+ /* Compare and check values */
+ for (j=0; j<auxLong; j++) {
+ if (auxShortArray[j] != auxShortArrayW[i+j]) {
+ fprintf (stderr, "Read value %d of %s #%d %d differs from set value %d\n", i, tFieldName, j, auxShortArray[j], auxShortArrayW[i+j]);
+ GOTOFAILURE_ALL_EXIF
+ }
+ }
+ } else if (tSetFieldType == TIFF_SETGET_C0_UINT32 || tSetFieldType == TIFF_SETGET_C0_SINT32 ||
+ tSetFieldType == TIFF_SETGET_C16_UINT32 || tSetFieldType == TIFF_SETGET_C16_SINT32 ||
+ tSetFieldType == TIFF_SETGET_C32_UINT32 || tSetFieldType == TIFF_SETGET_C32_SINT32 ) {
+ memcpy(&auxLongArray, pVoidArray,(auxLong * sizeof(auxLongArray[0])));
+ /* Compare and check values */
+ for (j=0; j<auxLong; j++) {
+ if (auxLongArray[j] != auxLongArrayW[i+j]) {
+ fprintf (stderr, "Read value %d of %s #%d %ld differs from set value %ld\n", i, tFieldName, j, auxLongArray[j], auxLongArrayW[i+j]);
+ GOTOFAILURE_ALL_EXIF
+ }
+ }
+ } else {
+ fprintf (stderr, "SetFieldType %d not defined within switch case reading for UINT for %s.\n", tSetFieldType, tFieldName);
+ GOTOFAILURE
+ }
+ }
+ break;
+ default:
+ fprintf (stderr, "SetFieldType %d not defined within writing switch for %s.\n", tSetFieldType, tFieldName);
+ GOTOFAILURE
+ }; /*-- switch() --*/
+ } /*-- for() --*/
+ /*================= EXIF: END Reading arbitrary data to the EXIF fields END END END ==============*/
+#endif /*-- READ_ALL_EXIF_TAGS --*/
+#endif /*-- READ_EXIF_TAGS --*/
+
+
+
+
+ TIFFClose(tif);
+
+ /* All tests passed; delete file and exit with success status. */
+#ifdef FOR_AUTO_TESTING
+ unlink(filenameRead);
+#endif
+ fprintf(stderr, "-------- Test finished OK ----------\n");
+ return 0;
+
+failure:
+ /*
+ * Something goes wrong; close file and return unsuccessful status.
+ * Do not remove the file for further manual investigation.
+ */
+ TIFFClose(tif);
+ fprintf(stderr, "-------- Test finished with FAILURE --------\n");
+ return 1;
+}
diff --git a/tiff/test/defer_strile_loading.c b/tiff/test/defer_strile_loading.c
index b444c01f2..b22803243 100644
--- a/tiff/test/defer_strile_loading.c
+++ b/tiff/test/defer_strile_loading.c
@@ -148,11 +148,15 @@ int test(int classictif, int height, int tiled)
assert(err == 0);
size = TIFFGetStrileByteCountWithErr(tif, j, &err);
+ (void)size;
assert(size == 256);
assert(err == 0);
fseek(f, offset, SEEK_SET);
- fread(inputbuffer, 256, 1, f);
+ {
+ size_t nread = fread(inputbuffer, 256, 1, f);
+ (void)nread;
+ }
memset(tilebuffer,0, 256);
ret = TIFFReadFromUserBuffer(tif, j,
@@ -204,12 +208,15 @@ int test(int classictif, int height, int tiled)
assert(err == 0);
size = TIFFGetStrileByteCountWithErr(tif, j, &err);
+ (void)size;
assert(size == 1);
assert(err == 0);
fseek(f, offset, SEEK_SET);
- fread(inputbuffer, 1, 1, f);
-
+ {
+ size_t nread = fread(inputbuffer, 1, 1, f);
+ (void)nread;
+ }
memset(tilebuffer,0, 1);
ret = TIFFReadFromUserBuffer(tif, j,
inputbuffer, 1,
diff --git a/tiff/test/images/README.txt b/tiff/test/images/README.txt
index b6447d8ee..4a7ad8297 100644
--- a/tiff/test/images/README.txt
+++ b/tiff/test/images/README.txt
@@ -30,3 +30,6 @@ PNM files:
G3 Fax files :
miniswhite-1c-1b.g3
+
+deflate-last-strip-extra-data.tiff is
+https://github.com/OSGeo/gdal/blob/master/autotest/alg/data/utmsmall_near.tiff
diff --git a/tiff/test/images/deflate-last-strip-extra-data.tiff b/tiff/test/images/deflate-last-strip-extra-data.tiff
new file mode 100644
index 000000000..e3ee9dcc0
--- /dev/null
+++ b/tiff/test/images/deflate-last-strip-extra-data.tiff
Binary files differ
diff --git a/tiff/test/images/ojpeg_chewey_subsamp21_multi_strip.tiff b/tiff/test/images/ojpeg_chewey_subsamp21_multi_strip.tiff
new file mode 100644
index 000000000..8b04d473d
--- /dev/null
+++ b/tiff/test/images/ojpeg_chewey_subsamp21_multi_strip.tiff
Binary files differ
diff --git a/tiff/test/images/ojpeg_single_strip_no_rowsperstrip.tiff b/tiff/test/images/ojpeg_single_strip_no_rowsperstrip.tiff
new file mode 100644
index 000000000..61611b9d0
--- /dev/null
+++ b/tiff/test/images/ojpeg_single_strip_no_rowsperstrip.tiff
Binary files differ
diff --git a/tiff/test/images/ojpeg_zackthecat_subsamp22_single_strip.tiff b/tiff/test/images/ojpeg_zackthecat_subsamp22_single_strip.tiff
new file mode 100644
index 000000000..15185b688
--- /dev/null
+++ b/tiff/test/images/ojpeg_zackthecat_subsamp22_single_strip.tiff
Binary files differ
diff --git a/tiff/test/images/rgb-3c-16b.ppm b/tiff/test/images/rgb-3c-16b.ppm
new file mode 100644
index 000000000..c1cd4b644
--- /dev/null
+++ b/tiff/test/images/rgb-3c-16b.ppm
Binary files differ
diff --git a/tiff/test/images/testfax4.tiff b/tiff/test/images/testfax4.tiff
new file mode 100644
index 000000000..f7f2629ca
--- /dev/null
+++ b/tiff/test/images/testfax4.tiff
Binary files differ
diff --git a/tiff/test/ppm2tiff_pbm.sh b/tiff/test/ppm2tiff_pbm.sh
index 68d9e4590..fb6c3cf77 100755
--- a/tiff/test/ppm2tiff_pbm.sh
+++ b/tiff/test/ppm2tiff_pbm.sh
@@ -1,5 +1,4 @@
#!/bin/sh
-# Generated file, master is Makefile.am
. ${srcdir:-.}/common.sh
infile="$IMG_MINISWHITE_1C_1B_PBM"
outfile="o-ppm2tiff_pbm.tiff"
diff --git a/tiff/test/ppm2tiff_pgm.sh b/tiff/test/ppm2tiff_pgm.sh
index 001ec7064..603523482 100755
--- a/tiff/test/ppm2tiff_pgm.sh
+++ b/tiff/test/ppm2tiff_pgm.sh
@@ -1,5 +1,4 @@
#!/bin/sh
-# Generated file, master is Makefile.am
. ${srcdir:-.}/common.sh
infile="$IMG_MINISBLACK_1C_8B_PGM"
outfile="o-ppm2tiff_pgm.tiff"
diff --git a/tiff/test/ppm2tiff_ppm.sh b/tiff/test/ppm2tiff_ppm.sh
index 8a81527bc..576ab3e09 100755
--- a/tiff/test/ppm2tiff_ppm.sh
+++ b/tiff/test/ppm2tiff_ppm.sh
@@ -1,7 +1,10 @@
#!/bin/sh
-# Generated file, master is Makefile.am
. ${srcdir:-.}/common.sh
infile="$IMG_RGB_3C_8B_PPM"
-outfile="o-ppm2tiff_ppm.tiff"
+outfile="o-ppm2tiff_8b_ppm.tiff"
+f_test_convert "$PPM2TIFF" $infile $outfile
+f_tiffinfo_validate $outfile
+infile="$IMG_RGB_3C_16B_PPM"
+outfile="o-ppm2tiff_16b_ppm.tiff"
f_test_convert "$PPM2TIFF" $infile $outfile
f_tiffinfo_validate $outfile
diff --git a/tiff/test/rational_precision2double.c b/tiff/test/rational_precision2double.c
new file mode 100644
index 000000000..e33cc97d1
--- /dev/null
+++ b/tiff/test/rational_precision2double.c
@@ -0,0 +1,972 @@
+
+/*
+ * Copyright (c) 2012, Frank Warmerdam <warmerdam@pobox.com>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and
+ * its documentation for any purpose is hereby granted without fee, provided
+ * that (i) the above copyright notices and this permission notice appear in
+ * all copies of the software and related documentation, and (ii) the names of
+ * Sam Leffler and Silicon Graphics may not be used in any advertising or
+ * publicity relating to the software without the specific, prior written
+ * permission of Sam Leffler and Silicon Graphics.
+ *
+ * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
+ * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
+ * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
+ * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+ * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
+ * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
+
+/*
+ * TIFF Library
+ *
+ * -- Module copied from custom_dir.c --
+ *=========== Purpose ===================================================================================
+ * Extended and amended version for testing the TIFFSetField() / and TIFFGetField()- interface
+ * for custom fields of type RATIONAL when the TIFFLib internal precision is updated from FLOAT to DOUBLE!
+ * The external interface of already defined tags schould be kept.
+ * This is verified for some of those tags with this test.
+ *
+ */
+
+
+#define FOR_AUTO_TESTING
+#ifdef FOR_AUTO_TESTING
+/* Only for automake and CMake infrastructure the test should:
+ a.) delete any written testfiles when test passed (otherwise autotest will fail)
+ b.) goto failure, if any failure is detected, which is not necessary when test is initiated manually for debugging
+*/
+#define GOTOFAILURE goto failure;
+#else
+#define GOTOFAILURE
+#endif
+
+#ifdef _MSC_VER
+#pragma warning( disable : 4101)
+#endif
+
+#include "tif_config.h"
+#include <stdio.h>
+#include <string.h>
+#include <math.h>
+#include <errno.h>
+
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+
+#include "tiffio.h"
+#include "tiffiop.h"
+#include "tif_dir.h"
+#include "tifftest.h"
+
+
+#include "tif_dirwrite.c"
+
+
+int write_test_tiff(TIFF *tif, const char *filenameRead, int blnAllCustomTags);
+
+#define SPP 3 /* Samples per pixel */
+const uint16 width = 1;
+const uint16 length = 1;
+const uint16 bps = 8;
+const uint16 photometric = PHOTOMETRIC_RGB;
+const uint16 rows_per_strip = 1;
+const uint16 planarconfig = PLANARCONFIG_CONTIG;
+
+/*-- Additional custom TIFF tags for testing of Rational2Double precision --*/
+#define TIFFTAG_RATIONAL_DOUBLE 60000
+#define TIFFTAG_SRATIONAL_DOUBLE 60001
+#define TIFFTAG_RATIONAL_C0_DOUBLE 60002
+#define TIFFTAG_SRATIONAL_C16_DOUBLE 60003
+
+
+/*--- TIFFField Definition ---
+ field_tag: the tag number. For instance 277 for the SamplesPerPixel tag. Builtin tags will generally have a #define in tiff.h for each known tag.
+ field_readcount: The number of values which should be read. The special value TIFF_VARIABLE (-1) indicates that a variable number of values may be read. The special value TIFFTAG_SPP (-2) indicates that there should be one value for each sample as defined by TIFFTAG_SAMPLESPERPIXEL. The special value TIFF_VARIABLE2 (-3) is presumably similar to TIFF_VARIABLE though I am not sure what the distinction in behaviour is. This field is TIFF_VARIABLE for variable length ascii fields.
+ field_writecount: The number of values which should be written. Generally the same as field_readcount. A few built-in exceptions exist, but I haven't analysed why they differ.
+ field_type: Type of the field. One of TIFF_BYTE, TIFF_ASCII, TIFF_SHORT, TIFF_LONG, TIFF_RATIONAL, TIFF_SBYTE, TIFF_UNDEFINED, TIFF_SSHORT, TIFF_SLONG, TIFF_SRATIONAL, TIFF_FLOAT, TIFF_DOUBLE or TIFF_IFD. Note that some fields can support more than one type (for instance short and long). These fields should have multiple TIFFFieldInfos.
+ reserved:
+ set_field_type: TIFF_SETGET_DOUBLE
+ get_field_type: - not used -
+ field_bit: Built-in tags stored in special fields in the TIFF structure have assigned field numbers to distinguish them (ie. FIELD_SAMPLESPERPIXEL). New tags should generally just use FIELD_CUSTOM indicating they are stored in the generic tag list.
+ field_oktochange: TRUE if it is OK to change this tag value while an image is being written. FALSE for stuff that must be set once and then left unchanged (like ImageWidth, or PhotometricInterpretation for instance).
+ field_passcount: If TRUE, then the count value must be passed in TIFFSetField(), and TIFFGetField(), otherwise the count is not required. This should generally be TRUE for non-ascii variable count tags unless the count is implicit (such as with the colormap).
+ field_name: A name for the tag. Normally mixed case (studly caps) like "StripByteCounts" and relatively short.
+*/
+
+static const TIFFField
+tifFieldInfo[] = {
+ { TIFFTAG_RATIONAL_DOUBLE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "Rational2Double_U_Double", NULL },
+ { TIFFTAG_SRATIONAL_DOUBLE, 1, 1, TIFF_SRATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "Rational2Double_S_Double", NULL },
+ { TIFFTAG_RATIONAL_C0_DOUBLE, 3, 3, TIFF_RATIONAL, 0, TIFF_SETGET_C0_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "Rational2Double_C0", NULL },
+ { TIFFTAG_SRATIONAL_C16_DOUBLE, -1, -1, TIFF_SRATIONAL, 0, TIFF_SETGET_C16_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "Rational2Double_S_C16", NULL },
+};
+
+#define N(a) (sizeof (a) / sizeof (a[0]))
+
+/*--- Add aditional Rational-Double Tags to TIFF
+ ref: html\addingtags.html but with new function _TIFFMergeFields().
+---*/
+
+/* In libtiff 3.6.0 a new mechanism was introduced allowing libtiff to read unrecognised tags automatically.
+ When an unknown tags is encountered, it is automatically internally defined with a default name and a type derived from the tag value in the file.
+ Applications only need to predefine application specific tags if they need to be able to set them in a file, or if particular calling conventions
+ are desired for TIFFSetField() and TIFFGetField().
+ When tags are autodefined like this the field_readcount and field_writecount values are always TIFF_VARIABLE.
+ The field_passcount is always TRUE, and the field_bit is FIELD_CUSTOM. The field name will be "Tag %d" where the %d is the tag number.
+*/
+
+/*The tags need to be defined for each TIFF file opened - and when reading they should be defined before the tags of the file are read,
+ yet a valid TIFF * is needed to merge the tags against. In order to get them registered at the appropriate part of the setup process,
+ it is necessary to register our merge function as an extender callback with libtiff. This is done with TIFFSetTagExtender().
+ We also keep track of the previous tag extender (if any) so that we can call it from our extender allowing a chain of customizations to take effect.
+*/
+static TIFFExtendProc _ParentExtender = NULL;
+static void _XTIFFDefaultDirectory(TIFF *tif);
+
+static
+void _XTIFFInitialize(void)
+{
+ static int first_time=1;
+
+ if (! first_time) return; /* Been there. Done that. */
+first_time = 0;
+
+/* Grab the inherited method and install */
+_ParentExtender = TIFFSetTagExtender(_XTIFFDefaultDirectory);
+}
+
+/* The extender callback is looks like this.
+It merges in our new fields and then calls the next extender if there is one in effect.
+*/
+static void
+_XTIFFDefaultDirectory(TIFF *tif)
+{
+ uint32 n, nadded;
+
+ /* Install the extended Tag field info */
+ n = N(tifFieldInfo);
+ //_TIFFMergeFields(tif, const TIFFField info[], uint32 n);
+ nadded = _TIFFMergeFields(tif, tifFieldInfo, n);
+ (void)nadded;
+
+ /* Since an XTIFF client module may have overridden
+ * the default directory method, we call it now to
+ * allow it to set up the rest of its own methods.
+ */
+
+ if (_ParentExtender)
+ (*_ParentExtender)(tif);
+}
+
+
+int
+main()
+{
+ static const char filenameClassicTiff[] = "rationalPrecision2Double.tif";
+ static const char filenameBigTiff[] = "rationalPrecision2Double_Big.tif";
+
+ TIFF *tif;
+ int ret;
+ int errorNo;
+
+ /*-- Initialize TIFF-Extender to add additonal TIFF-Tags --*/
+ _XTIFFInitialize();
+
+ fprintf(stderr, "==== Test if Set()/Get() interface for some custom rational tags behave as before change. ====\n");
+ /* --- Test with Classic-TIFF ---*/
+ /* delete file, if exists */
+ ret = unlink(filenameClassicTiff);
+ errorNo = errno;
+ if (ret != 0 && errorNo != ENOENT) {
+ fprintf(stderr, "Can't delete test TIFF file %s.\n", filenameClassicTiff);
+ }
+
+ /* We write the main directory as a simple image. */
+ tif = TIFFOpen(filenameClassicTiff, "w+");
+ if (!tif) {
+ fprintf(stderr, "Can't create test TIFF file %s.\n", filenameClassicTiff);
+ return 1;
+ }
+ fprintf(stderr, "-------- Test with ClassicTIFF started ----------\n");
+ ret = write_test_tiff(tif, filenameClassicTiff, FALSE);
+ if (ret > 0) return(ret);
+
+ /*--- Test with BIG-TIFF ---*/
+ /* delete file, if exists */
+ ret = unlink(filenameBigTiff);
+ if (ret != 0 && errorNo != ENOENT) {
+ fprintf(stderr, "Can't delete test TIFF file %s.\n", filenameBigTiff);
+ }
+
+ tif = TIFFOpen(filenameBigTiff, "w8");
+ if (!tif) {
+ fprintf(stderr, "Can't create test TIFF file %s.\n", filenameBigTiff);
+ return 1;
+ }
+ fprintf(stderr, "\n-------- Test with BigTIFF started ----------\n");
+ ret = write_test_tiff(tif, filenameBigTiff, FALSE);
+ if (ret > 0) return(ret);
+
+
+ fprintf(stderr, "\n\n==== Test automatically, if all custom rational tags are written/read correctly. ====\n");
+ /* --- Test with Classic-TIFF ---*/
+ /* delete file, if exists */
+ ret = unlink(filenameClassicTiff);
+ errorNo = errno;
+ if (ret != 0 && errorNo != ENOENT) {
+ fprintf(stderr, "Can't delete test TIFF file %s.\n", filenameClassicTiff);
+ }
+
+ /* We write the main directory as a simple image. */
+ tif = TIFFOpen(filenameClassicTiff, "w+");
+ if (!tif) {
+ fprintf(stderr, "Can't create test TIFF file %s.\n", filenameClassicTiff);
+ return 1;
+ }
+ fprintf(stderr, "-------- Test with ClassicTIFF started ----------\n");
+ ret = write_test_tiff(tif, filenameClassicTiff, TRUE);
+ if (ret > 0) return(ret);
+
+ /*--- Test with BIG-TIFF ---*/
+ /* delete file, if exists */
+ ret = unlink(filenameBigTiff);
+ if (ret != 0 && errno != ENOENT) {
+ fprintf(stderr, "Can't delete test TIFF file %s.\n", filenameBigTiff);
+ }
+
+ tif = TIFFOpen(filenameBigTiff, "w8");
+ if (!tif) {
+ fprintf(stderr, "Can't create test TIFF file %s.\n", filenameBigTiff);
+ return 1;
+ }
+ fprintf(stderr, "\n-------- Test with BigTIFF started ----------\n");
+ ret = write_test_tiff(tif, filenameBigTiff, TRUE);
+ return(ret);
+} /* main() */
+
+
+
+
+int
+write_test_tiff(TIFF* tif, const char* filenameRead, int blnAllCustomTags) {
+ unsigned char buf[SPP] = {0, 127, 255};
+ /*-- Additional variables --*/
+ int retCode;
+ float auxFloat = 0.0f;
+ double auxDouble = 0.0;
+ uint16 auxUint16 = 0;
+ uint32 auxUint32 = 0;
+ long auxLong = 0;
+ void* pVoid;
+ int blnIsRational2Double;
+
+ int i, j;
+ long nTags;
+
+ const TIFFFieldArray* tFieldArray;
+ unsigned long tTag;
+ TIFFDataType tType;
+ short tWriteCount;
+ TIFFSetGetFieldType tSetFieldType;
+ unsigned short tFieldBit;
+ const TIFFField *fip;
+ char* tFieldName;
+
+
+#define STRSIZE 1000
+#define N_SIZE 200
+#define VARIABLE_ARRAY_SIZE 6
+
+ /* -- Test data for writing -- */
+ float auxFloatArrayW[N_SIZE];
+ double auxDoubleArrayW[N_SIZE];
+ char auxTextArrayW[N_SIZE][STRSIZE];
+ float auxFloatArrayN1[3] = {1.0f / 7.0f, 61.23456789012345f, 62.3f};
+ float auxFloatArrayResolutions[4] = {5.456789f, 6.666666f, 0.0033f, 5.0f / 213.0f};
+
+ /* -- Variables for reading -- */
+ uint16 count16 = 0;
+ union {
+ long Long;
+ short Short1;
+ short Short2[2];
+ char Char[4];
+ } auxLongUnion;
+ union {
+ double dbl;
+ float flt1;
+ float flt2;
+ } auxDblUnion;
+
+ void* pVoidArray;
+ float* pFloatArray;
+ float auxFloatArray[2 * N_SIZE];
+ double auxDoubleArray[2 * N_SIZE];
+ double dblDiff, dblDiffLimit;
+ float fltDiff;
+#define RATIONAL_EPS (1.0/30000.0) /* reduced difference of rational values, approx 3.3e-5 */
+
+
+ /*-- Fill test data arrays for writing ----------- */
+ for (i = 0; i < N_SIZE; i++) {
+ sprintf(auxTextArrayW[i], "N%d-String-%d_tttttttttttttttttttttttttttttx", i, i);
+ }
+ for (i = 0; i < N_SIZE; i++) {
+ auxFloatArrayW[i] = (float)((i + 1) * 133) / 3.3f;
+ }
+ for (i = 0; i < N_SIZE; i++) {
+ auxDoubleArrayW[i] = (double)((i + 1) * 3689) / 4.5697;
+ }
+
+ /*-- Setup standard tags of a simple tiff file --*/
+ if (!TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, width)) {
+ fprintf(stderr, "Can't set ImageWidth tag.\n");
+ goto failure;
+ }
+ if (!TIFFSetField(tif, TIFFTAG_IMAGELENGTH, length)) {
+ fprintf(stderr, "Can't set ImageLength tag.\n");
+ goto failure;
+ }
+ if (!TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, bps)) {
+ fprintf(stderr, "Can't set BitsPerSample tag.\n");
+ goto failure;
+ }
+ if (!TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, SPP)) {
+ fprintf(stderr, "Can't set SamplesPerPixel tag.\n");
+ goto failure;
+ }
+ if (!TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, rows_per_strip)) {
+ fprintf(stderr, "Can't set SamplesPerPixel tag.\n");
+ goto failure;
+ }
+ if (!TIFFSetField(tif, TIFFTAG_PLANARCONFIG, planarconfig)) {
+ fprintf(stderr, "Can't set PlanarConfiguration tag.\n");
+ goto failure;
+ }
+ if (!TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, photometric)) {
+ fprintf(stderr, "Can't set PhotometricInterpretation tag.\n");
+ goto failure;
+ }
+
+ /*--- Standard tags with TIFF_RATIONAL and TIFF_SETGET_DOUBLE to TIFF_SETGET_FLOAT change. ---
+ * They can be written either using float or double but have to be read using float.
+ -------------------------------------------------------------------------------------------- */
+ if (!TIFFSetField(tif, TIFFTAG_XRESOLUTION, auxFloatArrayResolutions[0])) {
+ fprintf(stderr, "Can't set TIFFTAG_XRESOLUTION tag.\n");
+ goto failure;
+ }
+ /* Test here the double input possibility */
+ if (!TIFFSetField(tif, TIFFTAG_YRESOLUTION, (double)auxFloatArrayResolutions[1])) {
+ fprintf(stderr, "Can't set TIFFTAG_YRESOLUTION tag.\n");
+ goto failure;
+ }
+ if (!TIFFSetField(tif, TIFFTAG_XPOSITION, auxFloatArrayResolutions[2])) {
+ fprintf(stderr, "Can't set TIFFTAG_XPOSITION tag.\n");
+ goto failure;
+ }
+ if (!TIFFSetField(tif, TIFFTAG_YPOSITION, auxFloatArrayResolutions[3])) {
+ fprintf(stderr, "Can't set TIFFTAG_YPOSITION tag.\n");
+ goto failure;
+ }
+
+ /*--- Some additional FIELD_CUSTOM tags to check standard interface ---*/
+
+ /*- TIFFTAG_INKSET is a SHORT parameter (TIFF_SHORT, TIFF_SETGET_UINT16) with field_bit=FIELD_CUSTOM !! -*/
+ if (!TIFFSetField(tif, TIFFTAG_INKSET, 34)) {
+ fprintf(stderr, "Can't set TIFFTAG_INKSET tag.\n");
+ goto failure;
+ }
+
+ /*- TIFFTAG_PIXAR_FOVCOT is a FLOAT parameter ( TIFF_FLOAT, TIFF_SETGET_FLOAT) with field_bit=FIELD_CUSTOM !! -*/
+ /* - can be written with Double but has to be read with float parameter */
+#define PIXAR_FOVCOT_VAL 5.123456789123456789
+ auxFloat = (float)PIXAR_FOVCOT_VAL;
+ /* if (!TIFFSetField(tif, TIFFTAG_PIXAR_FOVCOT, auxFloat )) {
+ fprintf (stderr, "Can't set TIFFTAG_PIXAR_FOVCOT tag.\n");
+ goto failure;
+ }
+ */
+ auxDouble = (double)PIXAR_FOVCOT_VAL;
+ if (!TIFFSetField(tif, TIFFTAG_PIXAR_FOVCOT, auxDouble)) {
+ fprintf(stderr, "Can't set TIFFTAG_PIXAR_FOVCOT tag.\n");
+ goto failure;
+ }
+ /*- TIFFTAG_STONITS is a DOUBLE parameter (TIFF_DOUBLE, TIFF_SETGET_DOUBLE) with field_bit=FIELD_CUSTOM!
+ *-- Unfortunately, TIFF_SETGET_DOUBLE is used for TIFF_RATIONAL but those have to be read with FLOAT !!!
+ * Only TIFFTAG_STONITS is a TIFF_DOUBLE, which has to be read as DOUBLE!!
+ */
+#define STONITS_VAL 6.123456789123456789
+ auxDouble = STONITS_VAL;
+ auxFloat = (float)auxDouble;
+ if (!TIFFSetField(tif, TIFFTAG_STONITS, auxDouble)) {
+ fprintf(stderr, "Can't set TIFFTAG_STONITS tag.\n");
+ goto failure;
+ }
+
+
+ /*-- Additional tags to check Rational standard tags, which are also defined with field_bit=FIELD_CUSTOM */
+ /*
+ The following standard tags have field_type = TIFF_RATIONAL with field_bit=FIELD_CUSTOM:
+ TIFFTAG_BASELINENOISE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE
+ TIFFTAG_BASELINESHARPNESS, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE
+ TIFFTAG_LINEARRESPONSELIMIT, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE
+ TIFFTAG_CHROMABLURRADIUS, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE
+ TIFFTAG_ANTIALIASSTRENGTH, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE
+ TIFFTAG_SHADOWSCALE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE
+ TIFFTAG_BESTQUALITYSCALE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE
+ and with Signed Rational:
+ TIFFTAG_BASELINEEXPOSURE, 1, 1, TIFF_SRATIONAL, 0, TIFF_SETGET_DOUBLE
+ Due to the fact that TIFFSetField() and TIFFGetField() interface is using va_args, variable promotion is applied,
+ which means:
+ If the actual argument is of type float, it is promoted to type double when function is to be made.
+ - Any signed or unsigned char, short, enumerated type, or bit field is converted to either a signed or an unsigned int
+ using integral promotion.
+ - Any argument of class type is passed by value as a data structure; the copy is created by binary copying instead
+ of by invoking the class’s copy constructor (if one exists).
+ So, if your argument types are of float type, you should expect the argument retrieved to be of type double
+ and it is char or short, you should expect it to be signed or unsigned int. Otherwise, the code will give you wrong results.
+ */
+
+ if (!blnAllCustomTags) {
+ /*--- TEST: First tag is written with FLOAT and second tag is written with DOUBLE parameter ---*/
+ /*- TIFFTAG_SHADOWSCALE is a Rational parameter (TIFF_RATIONAL, TIFF_SETGET_DOUBLE) with field_bit=FIELD_CUSTOM! -*/
+ #define SHADOWSCALE_VAL 15.123456789123456789
+ auxFloat = (float)SHADOWSCALE_VAL;
+ if (!TIFFSetField(tif, TIFFTAG_SHADOWSCALE, auxFloat)) {
+ fprintf(stderr, "Can't set TIFFTAG_SHADOWSCALE tag.\n");
+ goto failure;
+ }
+
+ /*- TIFFTAG_BESTQUALITYSCALE is a Rational parameter (TIFF_RATIONAL, TIFF_SETGET_DOUBLE) with field_bit=FIELD_CUSTOM! -*/
+ #define BESTQUALITYSCALE_VAL 17.123456789123456789
+ auxDouble = BESTQUALITYSCALE_VAL;
+ if (!TIFFSetField(tif, TIFFTAG_BESTQUALITYSCALE, auxDouble)) {
+ fprintf(stderr, "Can't set TIFFTAG_BESTQUALITYSCALE tag.\n");
+ goto failure;
+ }
+
+
+ /*- TIFFTAG_BASELINEEXPOSURE is a Rational parameter (TIFF_SRATIONAL, TIFF_SETGET_DOUBLE) with field_bit=FIELD_CUSTOM! -*/
+ #define BASELINEEXPOSURE_VAL (-3.14159265358979323846)
+ /*
+ fprintf(stderr, "(-3.14159265358979323846) as float= %.18f, double=%.18f\n", (float)BASELINEEXPOSURE_VAL, (double)BASELINEEXPOSURE_VAL, BASELINEEXPOSURE_VAL);
+ fprintf(stderr, "(-3.141592742098056) as float= %.18f, double=%.18f\n", (float)(-3.141592742098056), (double)(-3.141592742098056));
+ */
+ auxDouble = BASELINEEXPOSURE_VAL;
+ if (!TIFFSetField(tif, TIFFTAG_BASELINEEXPOSURE, auxDouble)) {
+ fprintf(stderr, "Can't set TIFFTAG_BASELINEEXPOSURE tag.\n");
+ goto failure;
+ }
+
+
+ /*--- For static or variable ARRAYs the case is different ---*/
+
+ /*- Variable Array: TIFFTAG_DECODE is a SRATIONAL parameter TIFF_SETGET_C16_FLOAT type FIELD_CUSTOM with passcount=1 and variable length of array. */
+ if (!TIFFSetField(tif, TIFFTAG_DECODE, 3, auxFloatArrayN1)) { /* for TIFF_SETGET_C16_DOUBLE */
+ fprintf(stderr, "Can't set TIFFTAG_DECODE tag.\n");
+ goto failure;
+ }
+
+ /*- Varable Array: TIFF_RATIONAL, 0, TIFF_SETGET_C16_FLOAT */
+ if (!TIFFSetField(tif, TIFFTAG_BLACKLEVEL, 3, auxFloatArrayN1)) { /* for TIFF_SETGET_C16_FLOAT */
+ fprintf(stderr, "Can't set TIFFTAG_BLACKLEVEL tag.\n");
+ goto failure;
+ }
+
+ /*-- Check, if the TiffLibrary is compiled with the new interface with Rational2Double or still uses the old definitions. */
+ /* tags to check: TIFFTAG_BESTQUALITYSCALE, TIFFTAG_BASELINENOISE, TIFFTAG_BASELINESHARPNESS, */
+ fip = TIFFFindField(tif, TIFFTAG_BESTQUALITYSCALE, TIFF_ANY);
+ tSetFieldType = fip->set_field_type;
+ if (tSetFieldType == TIFF_SETGET_DOUBLE)
+ blnIsRational2Double = FALSE;
+ else
+ blnIsRational2Double = TRUE;
+
+ /*--- Write now additional Rational2Double test tags ---*/
+ /*--- However, this additional tags are only written as Double correctly,
+ if blnIsRational2Double is defined!
+ ------------------------------------------------------*/
+ if (blnIsRational2Double) {
+ if (!TIFFSetField(tif, TIFFTAG_RATIONAL_DOUBLE, auxDoubleArrayW[100])) {
+ fprintf(stderr, "Can't set TIFFTAG_RATIONAL_DOUBLE tag.\n");
+ goto failure;
+ }
+ /* test for plain integers */
+ if (!TIFFSetField(tif, TIFFTAG_SRATIONAL_DOUBLE, (-1.0 ))) {
+ fprintf(stderr, "Can't set TIFFTAG_SRATIONAL_DOUBLE tag.\n");
+ goto failure;
+ }
+ if (!TIFFSetField(tif, TIFFTAG_RATIONAL_C0_DOUBLE, &auxDoubleArrayW[110])) {
+ fprintf(stderr, "Can't set TIFFTAG_RATIONAL_C0_DOUBLE tag.\n");
+ goto failure;
+ }
+ if (!TIFFSetField(tif, TIFFTAG_SRATIONAL_C16_DOUBLE, 2, &auxDoubleArrayW[120])) {
+ fprintf(stderr, "Can't set TIFFTAG_SRATIONAL_C16_DOUBLE tag.\n");
+ goto failure;
+ }
+ }
+
+ } else { /* blnAllCustomTags */
+ /*==== Automatically check all custom rational tags == WRITING ===*/
+ /*-- Get array, where TIFF tag fields are defined --*/
+ tFieldArray = _TIFFGetFields();
+ nTags = tFieldArray->count;
+
+ for (i = 0; i < nTags; i++) {
+ tTag = tFieldArray->fields[i].field_tag;
+ tType = tFieldArray->fields[i].field_type; /* e.g. TIFF_RATIONAL */
+ tWriteCount = tFieldArray->fields[i].field_writecount;
+ tSetFieldType = tFieldArray->fields[i].set_field_type; /* e.g. TIFF_SETGET_C0_FLOAT */
+ tFieldBit = tFieldArray->fields[i].field_bit;
+ tFieldName = tFieldArray->fields[i].field_name;
+ pVoid = NULL;
+
+ if (tType == TIFF_RATIONAL && tFieldBit == FIELD_CUSTOM) {
+ /*-- dependent on set_field_type write value --*/
+ switch (tSetFieldType) {
+ case TIFF_SETGET_FLOAT:
+ case TIFF_SETGET_DOUBLE:
+ if (tWriteCount == 1) {
+ /*-- All single values can be written with float or double parameter. Only value range should be in line. */
+ if (!TIFFSetField(tif, tTag, auxDoubleArrayW[i])) {
+ fprintf(stderr, "Can't write %s\n", tFieldArray->fields[i].field_name);
+ goto failure;
+ }
+ } else {
+ fprintf(stderr, "WriteCount for .set_field_type %d should be 1! %s\n", tSetFieldType, tFieldArray->fields[i].field_name);
+ }
+ break;
+ case TIFF_SETGET_C0_FLOAT:
+ case TIFF_SETGET_C0_DOUBLE:
+ case TIFF_SETGET_C16_FLOAT:
+ case TIFF_SETGET_C16_DOUBLE:
+ case TIFF_SETGET_C32_FLOAT:
+ case TIFF_SETGET_C32_DOUBLE:
+ /* _Cxx_ just defines the size of the count parameter for the array as C0=char, C16=short or C32=long */
+ /*-- Check, if it is a single parameter, a fixed array or a variable array */
+ if (tWriteCount == 1) {
+ fprintf(stderr, "WriteCount for .set_field_type %d should be -1 or greather than 1! %s\n", tSetFieldType, tFieldArray->fields[i].field_name);
+ } else {
+ /*-- Either fix or variable array --*/
+ /* For arrays, distinguishing between float or double is essential, even for writing */
+ if (tSetFieldType == TIFF_SETGET_C0_FLOAT || tSetFieldType == TIFF_SETGET_C16_FLOAT || tSetFieldType == TIFF_SETGET_C32_FLOAT)
+ pVoid = &auxFloatArrayW[i]; else pVoid = &auxDoubleArrayW[i];
+ /* Now decide between fixed or variable array */
+ if (tWriteCount > 1) {
+ /* fixed array with needed arraysize defined in .field_writecount */
+ if (!TIFFSetField(tif, tTag, pVoid)) {
+ fprintf(stderr, "Can't write %s\n", tFieldArray->fields[i].field_name);
+ goto failure;
+ }
+ } else {
+ /* special treatment of variable array */
+ /* for test, use always arraysize of VARIABLE_ARRAY_SIZE */
+ if (!TIFFSetField(tif, tTag, VARIABLE_ARRAY_SIZE, pVoid)) {
+ fprintf(stderr, "Can't write %s\n", tFieldArray->fields[i].field_name);
+ goto failure;
+ }
+ }
+ }
+ break;
+ default:
+ fprintf(stderr, "SetFieldType %d not defined within writing switch for %s.\n", tSetFieldType, tFieldName);
+ }; /*-- switch() --*/
+ } /* if () */
+ } /*-- for() --*/
+ } /* blnAllCustomTags */ /*==== END END - Automatically check all custom rational tags == WRITING END ===*/
+
+ /*-- Write dummy pixel data. --*/
+ if (TIFFWriteScanline(tif, buf, 0, 0) < 0) {
+ fprintf (stderr, "Can't write image data.\n");
+ goto failure;
+ }
+
+ /*-- Write directory to file --*/
+ /* Always WriteDirectory before using/creating another directory. */
+ /* Not necessary before TIFFClose(), however, TIFFClose() uses TIFFReWriteDirectory(), which forces directory to be written at another location. */
+ retCode = TIFFWriteDirectory(tif);
+
+ /*-- Write File to disk and close file --*/
+ /* TIFFClose() uses TIFFReWriteDirectory(), which forces directory to be written at another location. */
+ /* Therefore, better use TIFFWriteDirectory() before. */
+ TIFFClose(tif);
+
+ fprintf (stderr, "-------- Continue Test ---------- reading ...\n");
+
+/*========================= READING ============= READING ========================================*/
+ /* Ok, now test whether we can read written values in the EXIF directory. */
+ tif = TIFFOpen(filenameRead, "r");
+
+
+ /*-- Read some parameters out of the main directory --*/
+
+ /*-- IMAGEWIDTH and -LENGTH are defined as TIFF_SETGET_UINT32 */
+ retCode = TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &auxUint32 );
+ if (auxUint32 != width) {
+ fprintf (stderr, "Read value of IMAGEWIDTH %d differs from set value %d\n", auxUint32, width);
+ GOTOFAILURE
+ }
+ retCode = TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &auxUint32 );
+ if (auxUint32 != width) {
+ fprintf (stderr, "Read value of TIFFTAG_IMAGELENGTH %d differs from set value %d\n", auxUint32, length);
+ GOTOFAILURE
+ }
+
+ /*--- Standard tags with TIFF_RATIONAL and TIFF_SETGET_DOUBLE to TIFF_SETGET_FLOAT change. ---
+ * They can be written either using float or double but have to be read using float.
+ -------------------------------------------------------------------------------------------- */
+ dblDiffLimit = RATIONAL_EPS;
+ retCode = TIFFGetField(tif, TIFFTAG_XRESOLUTION, &auxFloat);
+ dblDiff = auxFloat - auxFloatArrayResolutions[0];
+ if (fabs(dblDiff) > fabs(dblDiffLimit)) {
+ fprintf(stderr, "Read value of TIFFTAG_XRESOLUTION %f differs from set value %f\n", auxFloat, auxFloatArrayResolutions[0]);
+ GOTOFAILURE
+ }
+ retCode = TIFFGetField(tif, TIFFTAG_YRESOLUTION, &auxFloat);
+ dblDiff = auxFloat - auxFloatArrayResolutions[1];
+ if (fabs(dblDiff) > fabs(dblDiffLimit)) {
+ fprintf(stderr, "Read value of TIFFTAG_YRESOLUTION %f differs from set value %f\n", auxFloat, auxFloatArrayResolutions[1]);
+ GOTOFAILURE
+ }
+ retCode = TIFFGetField(tif, TIFFTAG_XPOSITION, &auxFloat);
+ dblDiff = auxFloat - auxFloatArrayResolutions[2];
+ if (fabs(dblDiff) > fabs(dblDiffLimit)) {
+ fprintf(stderr, "Read value of TIFFTAG_XPOSITION %f differs from set value %f\n", auxFloat, auxFloatArrayResolutions[2]);
+ GOTOFAILURE
+ }
+ retCode = TIFFGetField(tif, TIFFTAG_YPOSITION, &auxFloat);
+ dblDiff = auxFloat - auxFloatArrayResolutions[3];
+ if (fabs(dblDiff) > fabs(dblDiffLimit)) {
+ fprintf(stderr, "Read value of TIFFTAG_YPOSITION %f differs from set value %f\n", auxFloat, auxFloatArrayResolutions[3]);
+ GOTOFAILURE
+ }
+
+
+ /*- TIFFTAG_INKSET is a SHORT parameter (TIFF_SHORT, TIFF_SETGET_UINT16) with field_bit=FIELD_CUSTOM !! -*/
+ retCode = TIFFGetField(tif, TIFFTAG_INKSET, &auxUint16);
+ if (auxUint16 != 34) {
+ fprintf(stderr, "Read value of TIFFTAG_PIXAR_FOVCOT %d differs from set value %d\n", auxUint16, TIFFTAG_INKSET);
+ GOTOFAILURE
+ }
+
+ /*- TIFFTAG_PIXAR_FOVCOT is a FLOAT parameter ( TIFF_FLOAT, TIFF_SETGET_FLOAT) with field_bit=FIELD_CUSTOM !! -*/
+ /* - was written with Double but has to be read with Float */
+ retCode = TIFFGetField(tif, TIFFTAG_PIXAR_FOVCOT, &auxFloat );
+ if (auxFloat != (float)PIXAR_FOVCOT_VAL) {
+ fprintf (stderr, "Read value of TIFFTAG_PIXAR_FOVCOT %f differs from set value %f\n", auxFloat, PIXAR_FOVCOT_VAL);
+ GOTOFAILURE
+ }
+
+ /*- TIFFTAG_STONITS is a DOUBLE parameter (TIFF_DOUBLE, TIFF_SETGET_DOUBLE) with field_bit=FIELD_CUSTOM!! -*/
+ retCode = TIFFGetField(tif, TIFFTAG_STONITS, &auxDouble);
+ if (auxDouble != (double)STONITS_VAL) {
+ fprintf(stderr, "Read value of TIFFTAG_STONITS %f differs from set value %f\n", auxDouble, STONITS_VAL);
+ GOTOFAILURE
+ }
+
+
+
+
+ /*-- Check, if the TiffLibrary is compiled with the new interface with Rational2Double or still uses the old definitions. */
+ /* tags to check: TIFFTAG_BESTQUALITYSCALE, TIFFTAG_BASELINENOISE, TIFFTAG_BASELINESHARPNESS, */
+ fip = TIFFFindField(tif, TIFFTAG_BESTQUALITYSCALE, TIFF_ANY);
+ tSetFieldType = fip->set_field_type;
+ if (tSetFieldType == TIFF_SETGET_DOUBLE)
+ blnIsRational2Double = FALSE;
+ else
+ blnIsRational2Double = TRUE;
+
+
+ if (!blnAllCustomTags) {
+
+ /*- TIFFTAG_BESTQUALITYSCALE is a Rational parameter (TIFF_RATIONAL, TIFF_SETGET_DOUBLE) with field_bit=FIELD_CUSTOM!
+ and written with double parameter -*/
+ /*- Read into a union to test the correct precision (float or double) returned.
+ * Float-parameter should be correct, but double-parameter should give a wrong value
+ */
+ auxDblUnion.dbl = 0;
+ retCode = TIFFGetField(tif, TIFFTAG_BESTQUALITYSCALE, &auxDblUnion.dbl);
+ dblDiffLimit = RATIONAL_EPS * (double)BESTQUALITYSCALE_VAL;
+ dblDiff = auxDblUnion.dbl - (double)BESTQUALITYSCALE_VAL;
+ fltDiff = auxDblUnion.flt1 - (float)BESTQUALITYSCALE_VAL;
+ if (!((fabs(dblDiff) > fabs(dblDiffLimit)) && !(fabs(fltDiff) > fabs(dblDiffLimit)))) {
+ fprintf(stderr, "Float-Read value of TIFFTAG_BESTQUALITYSCALE %.12f differs from set value %.12f too much,\n", auxDblUnion.flt1, BESTQUALITYSCALE_VAL);
+ fprintf(stderr, "whereas Double-Read value of TIFFTAG_BESTQUALITYSCALE %.12f is nearly equal to set value %.12f\n", auxDblUnion.dbl, BESTQUALITYSCALE_VAL);
+ GOTOFAILURE
+ }
+
+ /*--- Now the same for a Signed Rational ---*/
+ /*- TIFFTAG_BASELINEEXPOSURE is a Rational parameter (TIFF_SRATIONAL, TIFF_SETGET_DOUBLE) with field_bit=FIELD_CUSTOM! -
+ and written with double parameter - */
+ /*- Read into a union to test the correct precision (float or double) returned.
+ * Float-parameter should be correct, but double-parameter should give a wrong value
+ */
+ auxDblUnion.dbl = 0;
+ retCode = TIFFGetField(tif, TIFFTAG_BASELINEEXPOSURE, &auxDblUnion.dbl);
+ dblDiffLimit = RATIONAL_EPS * (double)BASELINEEXPOSURE_VAL;
+ dblDiff = auxDblUnion.dbl - (double)BASELINEEXPOSURE_VAL;
+ fltDiff = auxDblUnion.flt1 - (float)BASELINEEXPOSURE_VAL;
+ if (!((fabs(dblDiff) > fabs(dblDiffLimit)) && !(fabs(fltDiff) > fabs(dblDiffLimit)))) {
+ fprintf(stderr, "Float-Read value of TIFFTAG_BASELINEEXPOSURE %.12f differs from set value %.12f too much,\n", auxDblUnion.flt1, BASELINEEXPOSURE_VAL);
+ fprintf(stderr, "whereas Double-Read value of TIFFTAG_BESTQUALITYSCALE %.12f is nearly equal to set value %.12f\n", auxDblUnion.dbl, BASELINEEXPOSURE_VAL);
+ GOTOFAILURE
+ }
+
+ /*- Variable Array: TIFFTAG_DECODE is a SRATIONAL parameter TIFF_SETGET_C16_FLOAT type FIELD_CUSTOM with passcount=1 and variable length of array. */
+ retCode = TIFFGetField(tif, TIFFTAG_DECODE, &count16, &pVoidArray);
+ retCode = TIFFGetField(tif, TIFFTAG_DECODE, &count16, &pFloatArray);
+ /*- pVoidArray points to a Tiff-internal temporary memorypart. Thus, contents needs to be saved. */
+ memcpy(&auxFloatArray, pVoidArray, (count16 * sizeof(auxFloatArray[0])));
+ for (i = 0; i < count16; i++) {
+ dblDiffLimit = RATIONAL_EPS * auxFloatArrayN1[i];
+ dblDiff = auxFloatArray[i] - auxFloatArrayN1[i];
+ if (fabs(dblDiff) > fabs(dblDiffLimit)) {
+ fprintf(stderr, "Read value %d of TIFFTAG_DECODE Array %f differs from set value %f\n", i, auxFloatArray[i], auxFloatArrayN1[i]);
+ GOTOFAILURE
+ }
+ }
+
+ retCode = TIFFGetField(tif, TIFFTAG_BLACKLEVEL, &count16, &pVoidArray);
+ /*- pVoidArray points to a Tiff-internal temporary memorypart. Thus, contents needs to be saved. */
+ memcpy(&auxFloatArray, pVoidArray, (count16 * sizeof(auxFloatArray[0])));
+ for (i = 0; i < count16; i++) {
+ dblDiffLimit = RATIONAL_EPS * auxFloatArrayN1[i];
+ dblDiff = auxFloatArray[i] - auxFloatArrayN1[i];
+ if (fabs(dblDiff) > fabs(dblDiffLimit)) {
+ fprintf(stderr, "Read value %d of TIFFTAG_BLACKLEVEL Array %f differs from set value %f\n", i, auxFloatArray[i], auxFloatArrayN1[i]);
+ GOTOFAILURE
+ }
+ }
+
+
+ /*--- Read now additional Rational2Double test tags ---
+ This should be now with nearly double precision
+ However, this additional tags are only read as Double,
+ if blnIsRational2Double is defined!
+ ------------------------------------------------------*/
+ if (blnIsRational2Double) {
+ auxDblUnion.dbl = 0;
+ retCode = TIFFGetField(tif, TIFFTAG_RATIONAL_DOUBLE, &auxDblUnion.dbl);
+ if (!retCode) { fprintf(stderr, "Can't read %s\n", "TIFFTAG_RATIONAL_DOUBLE"); GOTOFAILURE }
+ dblDiffLimit = RATIONAL_EPS * auxDoubleArrayW[100];
+ dblDiff = auxDblUnion.dbl - auxDoubleArrayW[100];
+ if (fabs(dblDiff) > fabs(dblDiffLimit)) {
+ fprintf(stderr, "Read value of TIFFTAG_RATIONAL_DOUBLE %f differs from set value %f\n", auxDblUnion.dbl, auxDoubleArrayW[100]);
+ GOTOFAILURE
+ }
+
+ auxDblUnion.dbl = 0;
+ retCode = TIFFGetField(tif, TIFFTAG_SRATIONAL_DOUBLE, &auxDblUnion.dbl);
+ if (!retCode) { fprintf(stderr, "Can't read %s\n", "TIFFTAG_SRATIONAL_DOUBLE"); GOTOFAILURE }
+ auxDouble = -1.0;
+ dblDiffLimit = RATIONAL_EPS * auxDouble;
+ dblDiff = auxDblUnion.dbl - auxDouble;
+ if (fabs(dblDiff) > fabs(dblDiffLimit)) {
+ fprintf(stderr, "Read value of TIFFTAG_SRATIONAL_DOUBLE %f differs from set value %f\n", auxDblUnion.dbl, auxDouble);
+ GOTOFAILURE
+ }
+
+ /*- Fixed Array: TIFFTAG_RATIONAL_C0_DOUBLE, 3, 3, TIFF_RATIONAL, 0, TIFF_SETGET_C0_DOUBLE */
+ count16 = 3; /* set fixed array length for checking */
+ retCode = TIFFGetField(tif, TIFFTAG_RATIONAL_C0_DOUBLE, &pVoidArray);
+ /*- pVoidArray points to a Tiff-internal temporary memorypart. Thus, contents needs to be saved. */
+ memcpy(&auxDoubleArray, pVoidArray, (count16 * sizeof(auxDoubleArray[0])));
+ for (i = 0; i < count16; i++) {
+ dblDiffLimit = RATIONAL_EPS * auxDoubleArrayW[110 + i];
+ dblDiff = auxDoubleArray[i] - auxDoubleArrayW[110 + i];
+ if (fabs(dblDiff) > fabs(dblDiffLimit)) {
+ fprintf(stderr, "Read value %d of TIFFTAG_RATIONAL_C0_DOUBLE Array %f differs from set value %f\n", i, auxDoubleArray[i], auxDoubleArrayW[110 + i]);
+ GOTOFAILURE
+ }
+ }
+
+ /*- Variable Array: TIFFTAG_SRATIONAL_C16_DOUBLE, -1, -1, TIFF_SRATIONAL, 0, TIFF_SETGET_C16_DOUBLE */
+ retCode = TIFFGetField(tif, TIFFTAG_SRATIONAL_C16_DOUBLE, &count16, &pVoidArray);
+ /*- pVoidArray points to a Tiff-internal temporary memorypart. Thus, contents needs to be saved. */
+ memcpy(&auxDoubleArray, pVoidArray, (count16 * sizeof(auxDoubleArray[0])));
+ for (i = 0; i < count16; i++) {
+ dblDiffLimit = RATIONAL_EPS * auxDoubleArrayW[120 + i];
+ dblDiff = auxDoubleArray[i] - auxDoubleArrayW[120 + i];
+ if (fabs(dblDiff) > fabs(dblDiffLimit)) {
+ fprintf(stderr, "Read value %d of TIFFTAG_SRATIONAL_C16_DOUBLE Array %f differs from set value %f\n", i, auxDoubleArray[i], auxDoubleArrayW[120 + i]);
+ GOTOFAILURE
+ }
+ }
+ }
+
+ } else { /* blnAllCustomTags */
+ /*==== Automatically check all custom rational tags == READING ===*/
+
+ /*-- Get array, where standard TIFF tag fields are defined --*/
+ tFieldArray = _TIFFGetFields();
+ nTags = tFieldArray->count;
+
+ for (i = 0; i < nTags; i++) {
+ tTag = tFieldArray->fields[i].field_tag;
+ tType = tFieldArray->fields[i].field_type; /* e.g. TIFF_RATIONAL */
+ tWriteCount = tFieldArray->fields[i].field_writecount;
+ tSetFieldType = tFieldArray->fields[i].set_field_type; /* e.g. TIFF_SETGET_C0_FLOAT */
+ tFieldBit = tFieldArray->fields[i].field_bit;
+ tFieldName = tFieldArray->fields[i].field_name;
+ pVoid = NULL;
+ auxDblUnion.dbl = 0;
+
+ if (tType == TIFF_RATIONAL && tFieldBit == FIELD_CUSTOM) {
+ /*-- dependent on set_field_type read value --*/
+ switch (tSetFieldType) {
+ case TIFF_SETGET_FLOAT:
+ if (!TIFFGetField(tif, tTag, &auxFloat)) {
+ fprintf(stderr, "Can't read %s\n", tFieldArray->fields[i].field_name);
+ GOTOFAILURE
+ break;
+ }
+ /* compare read values with written ones */
+ if (tType == TIFF_RATIONAL || tType == TIFF_SRATIONAL) dblDiffLimit = RATIONAL_EPS * auxDoubleArrayW[i]; else dblDiffLimit = 1e-6;
+ dblDiff = auxFloat - auxDoubleArrayW[i];
+ if (fabs(dblDiff) > fabs(dblDiffLimit)) {
+ /*--: EXIFTAG_SUBJECTDISTANCE: LibTiff returns value of "-1.0" if numerator equals 4294967295 (0xFFFFFFFF) to indicate infinite distance!
+ * However, there are two other EXIF tags where numerator indicates a special value and six other cases where the denominator indicates special values,
+ * which are not treated within LibTiff!!
+ */
+ if (!(tTag == EXIFTAG_SUBJECTDISTANCE && auxFloat == -1.0)) {
+ fprintf(stderr, "%d:Read value of %s %f differs from set value %f\n", i, tFieldName, auxFloat, auxDoubleArrayW[i]);
+ GOTOFAILURE
+ }
+ }
+ break;
+ case TIFF_SETGET_DOUBLE:
+ /*-- Unfortunately, TIFF_SETGET_DOUBLE is used for TIFF_RATIONAL but those have to be read with FLOAT !!! */
+ /* Only after update with Rational2Double feature, also TIFF_RATIONAL can be read in double precision!!! */
+ /* Therefore, use a union to avoid overflow in TIFFGetField() return value
+ * and depending on version check for the right interface here:
+ * - old interface: correct value should be here a float
+ * - new interface: correct value should be here a double
+ * Interface version (old/new) is determined above.
+ */
+ if (!TIFFGetField(tif, tTag, &auxDblUnion.dbl)) {
+ fprintf(stderr, "Can't read %s\n", tFieldArray->fields[i].field_name);
+ GOTOFAILURE
+ break;
+ }
+ if (tType == TIFF_RATIONAL || tType == TIFF_SRATIONAL) {
+ if (blnIsRational2Double) {
+ /* New interface allows also double precision for TIFF_RATIONAL */
+ auxDouble = auxDblUnion.dbl;
+ }
+ else {
+ /* Old interface reads TIFF_RATIONAL defined as TIFF_SETGET_DOUBLE alwasy as FLOAT */
+ auxDouble = (double)auxDblUnion.flt1;
+ }
+ } else {
+ auxDouble = auxDblUnion.dbl;
+ }
+ /* compare read values with written ones */
+ if (tType == TIFF_RATIONAL || tType == TIFF_SRATIONAL) dblDiffLimit = RATIONAL_EPS * auxDoubleArrayW[i]; else dblDiffLimit = 1e-6;
+ dblDiff = auxDouble - auxDoubleArrayW[i];
+ if (fabs(dblDiff) > fabs(dblDiffLimit)) {
+ /*--: EXIFTAG_SUBJECTDISTANCE: LibTiff returns value of "-1.0" if numerator equals 4294967295 (0xFFFFFFFF) to indicate infinite distance! */
+ if (!(tTag == EXIFTAG_SUBJECTDISTANCE && auxDouble == -1.0))
+ fprintf(stderr, "%d:Read value of %s %f differs from set value %f\n", i, tFieldName, auxDouble, auxDoubleArrayW[i]);
+ GOTOFAILURE
+ }
+ break;
+
+ case TIFF_SETGET_C0_FLOAT:
+ case TIFF_SETGET_C0_DOUBLE:
+ case TIFF_SETGET_C16_FLOAT:
+ case TIFF_SETGET_C16_DOUBLE:
+ case TIFF_SETGET_C32_FLOAT:
+ case TIFF_SETGET_C32_DOUBLE:
+ /* _Cxx_ just defines the size of the count parameter for the array as C0=char, C16=short or C32=long */
+ /*-- Check, if it is a single parameter, a fixed array or a variable array */
+ if (tWriteCount == 1) {
+ fprintf(stderr, "Reading: WriteCount for .set_field_type %d should be -1 or greather than 1! %s\n", tSetFieldType, tFieldArray->fields[i].field_name);
+ GOTOFAILURE
+ } else {
+ /*-- Either fix or variable array --*/
+ /* For arrays, distinguishing between float or double is essential. */
+ /* Now decide between fixed or variable array */
+ if (tWriteCount > 1) {
+ /* fixed array with needed arraysize defined in .field_writecount */
+ if (!TIFFGetField(tif, tTag, &pVoidArray)) {
+ fprintf(stderr, "Can't read %s\n", tFieldArray->fields[i].field_name);
+ GOTOFAILURE
+ break;
+ }
+ /* set tWriteCount to number of read samples for next steps */
+ auxLong = tWriteCount;
+ } else {
+ /* Special treatment of variable array. */
+ /* Dependent on Cxx, the count parameter is char, short or long. Therefore use unionLong! */
+ if (!TIFFGetField(tif, tTag, &auxLongUnion, &pVoidArray)) {
+ fprintf(stderr, "Can't read %s\n", tFieldArray->fields[i].field_name);
+ GOTOFAILURE
+ break;
+ }
+ /* set tWriteCount to number of read samples for next steps */
+ auxLong = auxLongUnion.Short1;
+ }
+ /* Save values from temporary array */
+ if (tSetFieldType == TIFF_SETGET_C0_FLOAT || tSetFieldType == TIFF_SETGET_C16_FLOAT || tSetFieldType == TIFF_SETGET_C32_FLOAT) {
+ memcpy(&auxFloatArray, pVoidArray, (auxLong * sizeof(auxFloatArray[0])));
+ /* compare read values with written ones */
+ if (tType == TIFF_RATIONAL || tType == TIFF_SRATIONAL) dblDiffLimit = RATIONAL_EPS * auxDoubleArrayW[i]; else dblDiffLimit = 1e-6;
+ for (j = 0; j < auxLong; j++) {
+ dblDiff = auxFloatArray[j] - auxFloatArrayW[i + j];
+ if (fabs(dblDiff) > fabs(dblDiffLimit)) {
+ /*if (auxFloatArray[j] != (float)auxFloatArrayW[i+j]) { */
+ fprintf(stderr, "Read value %d of %s #%d %f differs from set value %f\n", i, tFieldName, j, auxFloatArray[j], auxFloatArrayW[i + j]);
+ GOTOFAILURE
+ }
+ }
+ } else {
+ memcpy(&auxDoubleArray, pVoidArray, (auxLong * sizeof(auxDoubleArray[0])));
+ /* compare read values with written ones */
+ if (tType == TIFF_RATIONAL || tType == TIFF_SRATIONAL) dblDiffLimit = RATIONAL_EPS * auxDoubleArrayW[i]; else dblDiffLimit = 1e-6;
+ for (j = 0; j < auxLong; j++) {
+ dblDiff = auxDoubleArray[j] - auxDoubleArrayW[i + j];
+ if (fabs(dblDiff) > fabs(dblDiffLimit)) {
+ /*if (auxDoubleArray[j] != auxDoubleArrayW[i+j]) { */
+ fprintf(stderr, "Read value %d of %s #%d %f differs from set value %f\n", i, tFieldName, j, auxDoubleArray[j], auxDoubleArrayW[i + j]);
+ GOTOFAILURE
+ }
+ }
+ }
+ }
+ break;
+ default:
+ fprintf(stderr, "SetFieldType %d not defined within reading switch for %s.\n", tSetFieldType, tFieldName);
+ }; /*-- switch() --*/
+ } /* if () */
+ } /*-- for() --*/
+
+
+ } /* blnAllCustomTags */ /*==== END END - Automatically check all custom rational tags == READING END ===*/
+
+
+
+ TIFFClose(tif);
+
+ /* All tests passed; delete file and exit with success status. */
+#ifdef FOR_AUTO_TESTING
+ unlink(filenameRead);
+#endif
+ fprintf(stderr, "-------- Test finished OK ----------\n");
+ return 0;
+
+failure:
+ /*
+ * Something goes wrong; close file and return unsuccessful status.
+ * Do not remove the file for further manual investigation.
+ */
+ TIFFClose(tif);
+ fprintf(stderr, "-------- Test finished with FAILURE --------\n");
+ return 1;
+}
diff --git a/tiff/test/refs/o-deflate-last-strip-extra-data.tiff b/tiff/test/refs/o-deflate-last-strip-extra-data.tiff
new file mode 100644
index 000000000..5d56fe546
--- /dev/null
+++ b/tiff/test/refs/o-deflate-last-strip-extra-data.tiff
Binary files differ
diff --git a/tiff/test/refs/o-testfax4.tiff b/tiff/test/refs/o-testfax4.tiff
new file mode 100644
index 000000000..cad450456
--- /dev/null
+++ b/tiff/test/refs/o-testfax4.tiff
Binary files differ
diff --git a/tiff/test/testdeflatelaststripextradata.sh b/tiff/test/testdeflatelaststripextradata.sh
new file mode 100755
index 000000000..115eb226f
--- /dev/null
+++ b/tiff/test/testdeflatelaststripextradata.sh
@@ -0,0 +1,43 @@
+#!/bin/sh
+#
+# check decoding of a deflate compressed file whose last strip which should
+# contain data for only 4 lines has more in it.
+. ${srcdir:-.}/common.sh
+infile="${IMAGES}/deflate-last-strip-extra-data.tiff"
+outfile="o-deflate-last-strip-extra-data.tiff"
+rm -f $outfile
+echo "$MEMCHECK ${TIFFCP} -c zip $infile $outfile"
+eval "$MEMCHECK ${TIFFCP} -c zip $infile $outfile"
+status=$?
+if [ $status != 0 ] ; then
+ echo "Returned failed status $status!"
+ echo "Output (if any) is in \"${outfile}\"."
+ exit $status
+fi
+echo "$MEMCHECK ${TIFFCMP} $outfile ${REFS}/$outfile"
+eval "$MEMCHECK ${TIFFCMP} $outfile ${REFS}/$outfile"
+status=$?
+if [ $status != 0 ] ; then
+ echo "Returned failed status $status!"
+ echo "\"${outfile}\" differs from reference file."
+ exit $status
+fi
+
+outfile="o-deflate-last-strip-extra-data-tiled.tiff"
+rm -f $outfile
+echo "$MEMCHECK ${TIFFCP} -c zip -t -w 256 -l 256 $infile $outfile"
+eval "$MEMCHECK ${TIFFCP} -c zip -t -w 256 -l 256 $infile $outfile"
+status=$?
+if [ $status != 0 ] ; then
+ echo "Returned failed status $status!"
+ echo "Output (if any) is in \"${outfile}\"."
+ exit $status
+fi
+echo "$MEMCHECK ${TIFFCMP} $outfile ${REFS}/o-deflate-last-strip-extra-data.tiff"
+eval "$MEMCHECK ${TIFFCMP} $outfile ${REFS}/o-deflate-last-strip-extra-data.tiff"
+status=$?
+if [ $status != 0 ] ; then
+ echo "Returned failed status $status!"
+ echo "\"${outfile}\" differs from reference file."
+ exit $status
+fi
diff --git a/tiff/test/testfax4.sh b/tiff/test/testfax4.sh
new file mode 100755
index 000000000..6f465e8ff
--- /dev/null
+++ b/tiff/test/testfax4.sh
@@ -0,0 +1,24 @@
+#!/bin/sh
+#
+# check decoding of a CCITT Group 4 encoded TIFF
+# with 0 length runs
+. ${srcdir:-.}/common.sh
+infile="${IMAGES}/testfax4.tiff"
+outfile="o-testfax4.tiff"
+rm -f $outfile
+echo "$MEMCHECK ${TIFFCP} -c lzw $infile $outfile"
+eval "$MEMCHECK ${TIFFCP} -c lzw $infile $outfile"
+status=$?
+if [ $status != 0 ] ; then
+ echo "Returned failed status $status!"
+ echo "Output (if any) is in \"${outfile}\"."
+ exit $status
+fi
+echo "$MEMCHECK ${TIFFCMP} $outfile ${REFS}/$outfile"
+eval "$MEMCHECK ${TIFFCMP} $outfile ${REFS}/$outfile"
+status=$?
+if [ $status != 0 ] ; then
+ echo "Returned failed status $status!"
+ echo "\"${outfile}\" differs from reference file."
+ exit $status
+fi
diff --git a/tiff/test/tiff2ps-EPS1.sh b/tiff/test/tiff2ps-EPS1.sh
index b1dc82e70..150039ef4 100755
--- a/tiff/test/tiff2ps-EPS1.sh
+++ b/tiff/test/tiff2ps-EPS1.sh
@@ -5,4 +5,4 @@
PSFILE=o-tiff2ps-EPS1.ps
. ${srcdir:-.}/common.sh
f_test_stdout "${TIFF2PS} -e -1" "${IMG_MINISWHITE_1C_1B}" "${PSFILE}"
-diff -I '%%\(CreationDate\|Title\):*' -u "${REFS}/${PSFILE}" "${PSFILE}" || exit 1
+diff -I '%%CreationDate:.*' -I '%%Title:.*' -u "${REFS}/${PSFILE}" "${PSFILE}" || exit 1
diff --git a/tiff/test/tiff2ps-PS1.sh b/tiff/test/tiff2ps-PS1.sh
index 73171b989..ef08b13b7 100755
--- a/tiff/test/tiff2ps-PS1.sh
+++ b/tiff/test/tiff2ps-PS1.sh
@@ -5,4 +5,5 @@
PSFILE="o-tiff2ps-PS1.ps"
. ${srcdir:-.}/common.sh
f_test_stdout "${TIFF2PS} -a -p -1" "${IMG_MINISWHITE_1C_1B}" "${PSFILE}"
-diff -I '%%\(CreationDate\|Title\):*' -u "${REFS}/${PSFILE}" "${PSFILE}" || exit 1
+#diff -I '%%(CreationDate|Title):.*' -u "${REFS}/${PSFILE}" "${PSFILE}" || exit 1
+diff -I '%%CreationDate:.*' -I '%%Title:.*' -u "${REFS}/${PSFILE}" "${PSFILE}" || exit 1
diff --git a/tiff/test/tiff2ps-PS2.sh b/tiff/test/tiff2ps-PS2.sh
index 9d3a521d6..b130b08ce 100755
--- a/tiff/test/tiff2ps-PS2.sh
+++ b/tiff/test/tiff2ps-PS2.sh
@@ -5,4 +5,4 @@
PSFILE=o-tiff2ps-PS2.ps
. ${srcdir:-.}/common.sh
f_test_stdout "${TIFF2PS} -a -p -2" "${IMG_MINISWHITE_1C_1B}" "${PSFILE}"
-diff -I '%%\(CreationDate\|Title\):*' -u "${REFS}/${PSFILE}" "${PSFILE}" || exit 1
+diff -I '%%CreationDate:.*' -I '%%Title:.*' -u "${REFS}/${PSFILE}" "${PSFILE}" || exit 1
diff --git a/tiff/test/tiff2ps-PS3.sh b/tiff/test/tiff2ps-PS3.sh
index eb55b9a04..d22be09a8 100755
--- a/tiff/test/tiff2ps-PS3.sh
+++ b/tiff/test/tiff2ps-PS3.sh
@@ -5,4 +5,4 @@
PSFILE=o-tiff2ps-PS3.ps
. ${srcdir:-.}/common.sh
f_test_stdout "${TIFF2PS} -a -p -3" "${IMG_MINISWHITE_1C_1B}" "${PSFILE}"
-diff -I '%%\(CreationDate\|Title\):*' -u "${REFS}/${PSFILE}" "${PSFILE}" || exit 1
+diff -I '%%CreationDate:.*' -I '%%Title:.*' -u "${REFS}/${PSFILE}" "${PSFILE}" || exit 1
diff --git a/tiff/test/tiff2rgba-ojpeg_chewey_subsamp21_multi_strip.sh b/tiff/test/tiff2rgba-ojpeg_chewey_subsamp21_multi_strip.sh
new file mode 100755
index 000000000..d1225c943
--- /dev/null
+++ b/tiff/test/tiff2rgba-ojpeg_chewey_subsamp21_multi_strip.sh
@@ -0,0 +1,7 @@
+#!/bin/sh
+# Generated file, master is Makefile.am
+. ${srcdir:-.}/common.sh
+infile="$srcdir/images/ojpeg_chewey_subsamp21_multi_strip.tiff"
+outfile="o-tiff2rgba-ojpeg_chewey_subsamp21_multi_strip.tiff"
+f_test_convert "$TIFF2RGBA" $infile $outfile
+f_tiffinfo_validate $outfile
diff --git a/tiff/test/tiff2rgba-ojpeg_single_strip_no_rowsperstrip.sh b/tiff/test/tiff2rgba-ojpeg_single_strip_no_rowsperstrip.sh
new file mode 100755
index 000000000..d69c99dcc
--- /dev/null
+++ b/tiff/test/tiff2rgba-ojpeg_single_strip_no_rowsperstrip.sh
@@ -0,0 +1,7 @@
+#!/bin/sh
+# Generated file, master is Makefile.am
+. ${srcdir:-.}/common.sh
+infile="$srcdir/images/ojpeg_single_strip_no_rowsperstrip.tiff"
+outfile="o-tiff2rgba-ojpeg_single_strip_no_rowsperstrip.tiff"
+f_test_convert "$TIFF2RGBA" $infile $outfile
+f_tiffinfo_validate $outfile
diff --git a/tiff/test/tiff2rgba-ojpeg_zackthecat_subsamp22_single_strip.sh b/tiff/test/tiff2rgba-ojpeg_zackthecat_subsamp22_single_strip.sh
new file mode 100755
index 000000000..ca23a12d2
--- /dev/null
+++ b/tiff/test/tiff2rgba-ojpeg_zackthecat_subsamp22_single_strip.sh
@@ -0,0 +1,7 @@
+#!/bin/sh
+# Generated file, master is Makefile.am
+. ${srcdir:-.}/common.sh
+infile="$srcdir/images/ojpeg_zackthecat_subsamp22_single_strip.tiff"
+outfile="o-tiff2rgba-ojpeg_zackthecat_subsamp22_single_strip.tiff"
+f_test_convert "$TIFF2RGBA" $infile $outfile
+f_tiffinfo_validate $outfile