| 1 |
/* |
| 2 |
* Copyright (c) 2012, Frank Warmerdam <[email protected]> |
| 3 |
* |
| 4 |
* Permission to use, copy, modify, distribute, and sell this software and |
| 5 |
* its documentation for any purpose is hereby granted without fee, provided |
| 6 |
* that (i) the above copyright notices and this permission notice appear in |
| 7 |
* all copies of the software and related documentation, and (ii) the names of |
| 8 |
* Sam Leffler and Silicon Graphics may not be used in any advertising or |
| 9 |
* publicity relating to the software without the specific, prior written |
| 10 |
* permission of Sam Leffler and Silicon Graphics. |
| 11 |
* |
| 12 |
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, |
| 13 |
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY |
| 14 |
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. |
| 15 |
* |
| 16 |
* IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR |
| 17 |
* ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, |
| 18 |
* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, |
| 19 |
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF |
| 20 |
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE |
| 21 |
* OF THIS SOFTWARE. |
| 22 |
*/ |
| 23 |
|
| 24 |
/* |
| 25 |
* TIFF Library |
| 26 |
* |
| 27 |
* -- Module copied from custom_dir.c -- |
| 28 |
*=========== Purpose |
| 29 |
*=================================================================================== |
| 30 |
* Extended and amended version for testing of EXIF 2.32, GPS and handling of |
| 31 |
*custom fields. EXIF 2.32 and GPS are defined in amended files tif_dirinfo.c, |
| 32 |
*tif_dirread.c, tiff.h, tiffio.h, tif_dir.h, tif_dir.c |
| 33 |
* |
| 34 |
*-- ATTENTION: After the upgrade with Rational2Double, the GPSTAG values are |
| 35 |
*defined as double precision and need to be written and also read in double |
| 36 |
*precision! In order to maintain this code for both cases, it is checked above |
| 37 |
*if the TiffLibrary is compiled with the new interface with Rational2Double or |
| 38 |
*still uses the old definitions, by setting blnIsRational2Double above. |
| 39 |
* |
| 40 |
*/ |
| 41 |
|
| 42 |
/*------------ |
| 43 |
* This version writes the GPS and EXIF tags correctly, without additional |
| 44 |
main-IFD and parameters! |
| 45 |
* In contrary, custom_dir.c does write additional main-IFD and parameters to |
| 46 |
file. |
| 47 |
-------------*/ |
| 48 |
|
| 49 |
#define FOR_AUTO_TESTING |
| 50 |
#ifdef FOR_AUTO_TESTING |
| 51 |
/* Only for automake and CMake infrastructure the test should: |
| 52 |
a.) delete any written testfiles when test passed (otherwise autotest |
| 53 |
will fail) b.) goto failure, if any failure is detected, which is not |
| 54 |
necessary when test is initiated manually for debugging |
| 55 |
*/ |
| 56 |
#define GOTOFAILURE goto failure; |
| 57 |
#define GOTOFAILURE_GPS goto failure; |
| 58 |
#define GOTOFAILURE_ALL_EXIF goto failure; |
| 59 |
#else |
| 60 |
#define GOTOFAILURE |
| 61 |
#define GOTOFAILURE_GPS |
| 62 |
#define GOTOFAILURE_ALL_EXIF |
| 63 |
#endif |
| 64 |
|
| 65 |
#ifdef _MSC_VER |
| 66 |
#pragma warning(disable : 4101) |
| 67 |
#endif |
| 68 |
|
| 69 |
#include "tif_config.h" //necessary for linux compiler |
| 70 |
|
| 71 |
#include <errno.h> |
| 72 |
#include <math.h> |
| 73 |
#include <stdbool.h> |
| 74 |
#include <stdio.h> |
| 75 |
#include <string.h> |
| 76 |
|
| 77 |
#ifdef HAVE_UNISTD_H |
| 78 |
#include <unistd.h> |
| 79 |
#endif |
| 80 |
|
| 81 |
#include "tiffio.h" |
| 82 |
#include "tiffiop.h" |
| 83 |
|
| 84 |
int write_test_tiff(TIFF *tif, const char *filenameRead); |
| 85 |
|
| 86 |
static const char filename[] = "custom_dir_EXIF_231.tif"; |
| 87 |
static const char filenameBigTiff[] = "custom_dir_EXIF_231_Big.tif"; |
| 88 |
|
| 89 |
#define SPP 3 /* Samples per pixel */ |
| 90 |
const uint16_t width = 1; |
| 91 |
const uint16_t length = 1; |
| 92 |
const uint16_t bps = 8; |
| 93 |
const uint16_t photometric = PHOTOMETRIC_RGB; |
| 94 |
const uint16_t rows_per_strip = 1; |
| 95 |
const uint16_t planarconfig = PLANARCONFIG_CONTIG; |
| 96 |
|
| 97 |
int main() |
| 98 |
{ |
| 99 |
TIFF *tif; |
| 100 |
int ret, ret1, ret2; |
| 101 |
|
| 102 |
fprintf(stderr, "==== Test automatically if all EXIF and GPS tags are " |
| 103 |
"written/read correctly. ====\n"); |
| 104 |
/* --- Test with Classic-TIFF ---*/ |
| 105 |
/* delete file, if exists */ |
| 106 |
ret = unlink(filename); |
| 107 |
if (ret != 0 && errno != ENOENT) |
| 108 |
{ |
| 109 |
fprintf(stderr, "Can't delete test TIFF file %s.\n", filename); |
| 110 |
} |
| 111 |
|
| 112 |
/* We write the main directory as a simple image. */ |
| 113 |
tif = TIFFOpen(filename, "w+"); |
| 114 |
if (!tif) |
| 115 |
{ |
| 116 |
fprintf(stderr, "Can't create test TIFF file %s.\n", filename); |
| 117 |
return 1; |
| 118 |
} |
| 119 |
fprintf(stderr, "-------- Test with ClassicTIFF started ----------\n"); |
| 120 |
ret1 = write_test_tiff(tif, filename); |
| 121 |
|
| 122 |
if (ret1 > 0) |
| 123 |
return (ret1); |
| 124 |
|
| 125 |
/*--- Test with BIG-TIFF ---*/ |
| 126 |
/* delete file, if exists */ |
| 127 |
ret = unlink(filenameBigTiff); |
| 128 |
if (ret != 0 && errno != ENOENT) |
| 129 |
{ |
| 130 |
fprintf(stderr, "Can't delete test TIFF file %s.\n", filenameBigTiff); |
| 131 |
} |
| 132 |
|
| 133 |
tif = TIFFOpen(filenameBigTiff, "w8"); |
| 134 |
if (!tif) |
| 135 |
{ |
| 136 |
fprintf(stderr, "Can't create test TIFF file %s.\n", filenameBigTiff); |
| 137 |
return 1; |
| 138 |
} |
| 139 |
fprintf(stderr, "\n\n-------- Test with BigTIFF started ----------\n"); |
| 140 |
ret2 = write_test_tiff(tif, filenameBigTiff); |
| 141 |
|
| 142 |
if (ret2 > 0) |
| 143 |
return (ret2 + 10); |
| 144 |
else |
| 145 |
return (ret2); |
| 146 |
|
| 147 |
} /* main() */ |
| 148 |
|
| 149 |
int write_test_tiff(TIFF *tif, const char *filenameRead) |
| 150 |
{ |
| 151 |
unsigned char buf[SPP] = {0, 127, 255}; |
| 152 |
uint64_t dir_offset = 0; |
| 153 |
uint64_t dir_offset_GPS = 0, dir_offset_EXIF = 0; |
| 154 |
uint64_t read_dir_offset = 0; |
| 155 |
/*-- Additional variables --*/ |
| 156 |
int retCode, retCode2; |
| 157 |
unsigned char exifVersion[4] = { |
| 158 |
'0', '2', '3', |
| 159 |
'1'}; /* EXIF 2.31 version is 4 characters of a string! */ |
| 160 |
unsigned char gpsVersion[4] = {2, 2, 0, 1}; /* GPS Version is 4 numbers! */ |
| 161 |
unsigned char *pGpsVersion; |
| 162 |
float auxFloat = 0.0f; |
| 163 |
double auxDouble = 0.0; |
| 164 |
char auxChar = 0; |
| 165 |
uint32_t auxUint32 = 0; |
| 166 |
short auxShort = 0; |
| 167 |
int32_t auxInt32 = 0; |
| 168 |
void *pVoid; |
| 169 |
int blnIsRational2Double; |
| 170 |
|
| 171 |
int i, j; |
| 172 |
int32_t nTags; |
| 173 |
|
| 174 |
const TIFFFieldArray *tFieldArray; |
| 175 |
uint32_t tTag; |
| 176 |
TIFFDataType tType; |
| 177 |
short tWriteCount; |
| 178 |
TIFFSetGetFieldType tSetFieldType; |
| 179 |
char *tFieldName; |
| 180 |
const TIFFField *fip; |
| 181 |
|
| 182 |
char blnFillGPSManually = 1; |
| 183 |
|
| 184 |
#define STRSIZE 1000 |
| 185 |
#define N_SIZE 120 |
| 186 |
#define VARIABLE_ARRAY_SIZE 6 |
| 187 |
|
| 188 |
/* -- Test data for writing -- */ |
| 189 |
char auxCharArrayW[N_SIZE]; |
| 190 |
short auxShortArrayW[N_SIZE]; |
| 191 |
int32_t auxInt32ArrayW[N_SIZE]; |
| 192 |
float auxFloatArrayW[N_SIZE]; |
| 193 |
double auxDoubleArrayW[N_SIZE]; |
| 194 |
char auxTextArrayW[N_SIZE][STRSIZE]; |
| 195 |
double auxDoubleArrayGPS1[3] = {1.0 / 7.0, 61.23456789012345, 62.0}; |
| 196 |
double auxDoubleArrayGPS2[3] = {1.0 / 19.0, 88.34434, |
| 197 |
15.12345678901234567890}; |
| 198 |
double auxDoubleArrayGPSTime[3] = {22.0, 17.0, 15.3456789}; |
| 199 |
double auxDoubleGPSAltitude = 3456.0; |
| 200 |
double auxDoubleGPSDirection = 63.7; |
| 201 |
float auxFloatArrayN1[3] = {1.0f / 7.0f, 61.23456789012345f, 62.3f}; |
| 202 |
float auxFloatArrayN2[3] = {-1.0f / 7.0f, -61.23456789012345f, -62.3f}; |
| 203 |
float auxFloatArrayResolutions[4] = {5.456789f, 6.666666f, 0.0033f, |
| 204 |
5.0f / 213.0f}; |
| 205 |
|
| 206 |
/* -- Variables for reading -- */ |
| 207 |
uint16_t count16 = 0; |
| 208 |
union |
| 209 |
{ |
| 210 |
int32_t Int32; |
| 211 |
short Short1; |
| 212 |
short Short2[2]; |
| 213 |
char Char[4]; |
| 214 |
} unionInt32; |
| 215 |
union |
| 216 |
{ |
| 217 |
double dbl; |
| 218 |
float flt1; |
| 219 |
float flt2; |
| 220 |
} auxDblUnion; |
| 221 |
void *pVoidArray; |
| 222 |
char *pAscii; |
| 223 |
char auxCharArray[2 * STRSIZE]; |
| 224 |
short auxShortArray[2 * N_SIZE]; |
| 225 |
int32_t auxInt32Array[2 * N_SIZE]; |
| 226 |
float auxFloatArray[2 * N_SIZE]; |
| 227 |
double auxDoubleArray[2 * N_SIZE]; |
| 228 |
double dblDiff, dblDiffLimit; |
| 229 |
#define RATIONAL_EPS \ |
| 230 |
(1.0 / 30000.0) /* reduced difference of rational values, approx 3.3e-5 */ |
| 231 |
|
| 232 |
/*-- Fill test data arrays for writing ----------- */ |
| 233 |
for (i = 0; i < N_SIZE; i++) |
| 234 |
{ |
| 235 |
sprintf(auxTextArrayW[i], |
| 236 |
"N%d-String-%d_tttttttttttttttttttttttttttttx", i, i); |
| 237 |
} |
| 238 |
for (i = 0; i < N_SIZE; i++) |
| 239 |
{ |
| 240 |
auxCharArrayW[i] = (char)(i + 1); |
| 241 |
} |
| 242 |
for (i = 0; i < N_SIZE; i++) |
| 243 |
{ |
| 244 |
auxShortArrayW[i] = (short)(i + 1) * 7; |
| 245 |
} |
| 246 |
for (i = 0; i < N_SIZE; i++) |
| 247 |
{ |
| 248 |
auxInt32ArrayW[i] = (i + 1) * 133; |
| 249 |
} |
| 250 |
for (i = 0; i < N_SIZE; i++) |
| 251 |
{ |
| 252 |
auxFloatArrayW[i] = (float)((i + 1) * 133) / 3.3f; |
| 253 |
} |
| 254 |
for (i = 0; i < N_SIZE; i++) |
| 255 |
{ |
| 256 |
auxDoubleArrayW[i] = (double)((i + 1) * 3689) / 4.5697; |
| 257 |
} |
| 258 |
|
| 259 |
/*-- Setup standard tags of a simple tiff file --*/ |
| 260 |
if (!TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, width)) |
| 261 |
{ |
| 262 |
fprintf(stderr, "Can't set ImageWidth tag.\n"); |
| 263 |
goto failure; |
| 264 |
} |
| 265 |
if (!TIFFSetField(tif, TIFFTAG_IMAGELENGTH, length)) |
| 266 |
{ |
| 267 |
fprintf(stderr, "Can't set ImageLength tag.\n"); |
| 268 |
goto failure; |
| 269 |
} |
| 270 |
if (!TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, bps)) |
| 271 |
{ |
| 272 |
fprintf(stderr, "Can't set BitsPerSample tag.\n"); |
| 273 |
goto failure; |
| 274 |
} |
| 275 |
if (!TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, SPP)) |
| 276 |
{ |
| 277 |
fprintf(stderr, "Can't set SamplesPerPixel tag.\n"); |
| 278 |
goto failure; |
| 279 |
} |
| 280 |
if (!TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, rows_per_strip)) |
| 281 |
{ |
| 282 |
fprintf(stderr, "Can't set SamplesPerPixel tag.\n"); |
| 283 |
goto failure; |
| 284 |
} |
| 285 |
if (!TIFFSetField(tif, TIFFTAG_PLANARCONFIG, planarconfig)) |
| 286 |
{ |
| 287 |
fprintf(stderr, "Can't set PlanarConfiguration tag.\n"); |
| 288 |
goto failure; |
| 289 |
} |
| 290 |
if (!TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, photometric)) |
| 291 |
{ |
| 292 |
fprintf(stderr, "Can't set PhotometricInterpretation tag.\n"); |
| 293 |
goto failure; |
| 294 |
} |
| 295 |
|
| 296 |
if (!TIFFSetField(tif, TIFFTAG_XRESOLUTION, auxFloatArrayResolutions[0])) |
| 297 |
{ |
| 298 |
fprintf(stderr, "Can't set TIFFTAG_XRESOLUTION tag.\n"); |
| 299 |
goto failure; |
| 300 |
} |
| 301 |
if (!TIFFSetField(tif, TIFFTAG_YRESOLUTION, auxFloatArrayResolutions[1])) |
| 302 |
{ |
| 303 |
fprintf(stderr, "Can't set TIFFTAG_YRESOLUTION tag.\n"); |
| 304 |
goto failure; |
| 305 |
} |
| 306 |
if (!TIFFSetField(tif, TIFFTAG_XPOSITION, auxFloatArrayResolutions[2])) |
| 307 |
{ |
| 308 |
fprintf(stderr, "Can't set TIFFTAG_XPOSITION tag.\n"); |
| 309 |
goto failure; |
| 310 |
} |
| 311 |
if (!TIFFSetField(tif, TIFFTAG_YPOSITION, auxFloatArrayResolutions[3])) |
| 312 |
{ |
| 313 |
fprintf(stderr, "Can't set TIFFTAG_YPOSITION tag.\n"); |
| 314 |
goto failure; |
| 315 |
} |
| 316 |
|
| 317 |
#define ADDITIONAL_TAGS |
| 318 |
#ifdef ADDITIONAL_TAGS |
| 319 |
/*-- Additional tags to check Rational standard tags, which are also defined |
| 320 |
* as FIELD_CUSTOM */ |
| 321 |
|
| 322 |
/*- TIFFTAG_INKSET is a SHORT parameter (TIFF_SHORT, TIFF_SETGET_UINT16) |
| 323 |
* with field_bit=FIELD_CUSTOM !! -*/ |
| 324 |
if (!TIFFSetField(tif, TIFFTAG_INKSET, 34)) |
| 325 |
{ |
| 326 |
fprintf(stderr, "Can't set TIFFTAG_INKSET tag.\n"); |
| 327 |
goto failure; |
| 328 |
} |
| 329 |
|
| 330 |
/*- TIFFTAG_PIXAR_FOVCOT is a FLOAT parameter ( TIFF_FLOAT, |
| 331 |
* TIFF_SETGET_FLOAT) with field_bit=FIELD_CUSTOM !! -*/ |
| 332 |
/* - can be written with Double but has to be read with float parameter */ |
| 333 |
#define PIXAR_FOVCOT_VAL 5.123456789123456789 |
| 334 |
auxFloat = (float)PIXAR_FOVCOT_VAL; |
| 335 |
auxDouble = (double)PIXAR_FOVCOT_VAL; |
| 336 |
if (!TIFFSetField(tif, TIFFTAG_PIXAR_FOVCOT, auxDouble)) |
| 337 |
{ |
| 338 |
fprintf(stderr, "Can't set TIFFTAG_PIXAR_FOVCOT tag.\n"); |
| 339 |
goto failure; |
| 340 |
} |
| 341 |
/*- TIFFTAG_STONITS is a DOUBLE parameter (TIFF_DOUBLE, TIFF_SETGET_DOUBLE) |
| 342 |
* with field_bit=FIELD_CUSTOM! Only TIFFTAG_STONITS is a TIFF_DOUBLE, which |
| 343 |
* has to be read as DOUBLE!! |
| 344 |
*/ |
| 345 |
#define STONITS_VAL 6.123456789123456789 |
| 346 |
auxDouble = STONITS_VAL; |
| 347 |
auxFloat = (float)auxDouble; |
| 348 |
if (!TIFFSetField(tif, TIFFTAG_STONITS, auxDouble)) |
| 349 |
{ |
| 350 |
fprintf(stderr, "Can't set TIFFTAG_STONITS tag.\n"); |
| 351 |
goto failure; |
| 352 |
} |
| 353 |
|
| 354 |
/*- TIFFTAG_YCBCRPOSITIONING is a SHORT parameter */ |
| 355 |
auxInt32 = auxShort = 5; |
| 356 |
if (!TIFFSetField(tif, TIFFTAG_YCBCRPOSITIONING, auxInt32)) |
| 357 |
{ |
| 358 |
fprintf(stderr, "Can't set TIFFTAG_YCBCRPOSITIONING tag.\n"); |
| 359 |
goto failure; |
| 360 |
} |
| 361 |
|
| 362 |
/* - TIFFTAG_BESTQUALITYSCALE is a Rational parameter, FIELD_CUSTOM and |
| 363 |
* TIFF_SETGET_DOUBLE */ |
| 364 |
/* With Rational2Double upgrade tag is redefined to TIFF_SETGET_FLOAT, but |
| 365 |
* can be still written with double. */ |
| 366 |
#define BESTQUALITYSCALE_VAL 15.3 |
| 367 |
auxDouble = BESTQUALITYSCALE_VAL; |
| 368 |
if (!TIFFSetField(tif, TIFFTAG_BESTQUALITYSCALE, auxDouble)) |
| 369 |
{ |
| 370 |
fprintf(stderr, "Can't set TIFFTAG_BESTQUALITYSCALE tag.\n"); |
| 371 |
goto failure; |
| 372 |
} |
| 373 |
|
| 374 |
/* - TIFFTAG_BASELINENOISE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT */ |
| 375 |
if (!TIFFSetField(tif, TIFFTAG_BASELINENOISE, auxDouble)) |
| 376 |
{ |
| 377 |
fprintf(stderr, "Can't set TIFFTAG_BASELINENOISE tag.\n"); |
| 378 |
goto failure; |
| 379 |
} |
| 380 |
|
| 381 |
/*--- For static or variable ARRAYs the case is different ---*/ |
| 382 |
/*- Variable Array: TIFFTAG_DECODE is a SRATIONAL parameter |
| 383 |
* TIFF_SETGET_C16_FLOAT type FIELD_CUSTOM with passcount=1 and variable |
| 384 |
* length of array. */ |
| 385 |
if (!TIFFSetField(tif, TIFFTAG_DECODE, 3, auxFloatArrayN2)) |
| 386 |
{ |
| 387 |
fprintf(stderr, "Can't set TIFFTAG_DECODE tag.\n"); |
| 388 |
goto failure; |
| 389 |
} |
| 390 |
|
| 391 |
/*- Variable Array: TIFF_RATIONAL, 0, TIFF_SETGET_C16_FLOAT */ |
| 392 |
if (!TIFFSetField(tif, TIFFTAG_BLACKLEVEL, 3, auxFloatArrayN1)) |
| 393 |
{ |
| 394 |
fprintf(stderr, "Can't set TIFFTAG_BLACKLEVEL tag.\n"); |
| 395 |
goto failure; |
| 396 |
} |
| 397 |
|
| 398 |
/*- Fixed Array: TIFFTAG_DEFAULTCROPSIZE, 2, 2, TIFF_RATIONAL, 0, |
| 399 |
* TIFF_SETGET_C0_FLOAT */ |
| 400 |
if (!TIFFSetField(tif, TIFFTAG_DEFAULTCROPSIZE, &auxFloatArrayW[0])) |
| 401 |
{ |
| 402 |
fprintf(stderr, "Can't set TIFFTAG_DEFAULTCROPSIZE tag.\n"); |
| 403 |
goto failure; |
| 404 |
} |
| 405 |
#endif /* -- ADDITIONAL_TAGS -- */ |
| 406 |
|
| 407 |
/*================== Rational2Double Interface Check =====================*/ |
| 408 |
/*-- Check, if the TiffLibrary is compiled with the new interface with |
| 409 |
Rational2Double or still uses the old definitions. For that, |
| 410 |
TIFF_RATIONAL tags with FIELD_CUSTOM are changed from TIFF_SETGET_DOUBLE |
| 411 |
to TIFF_SETGET_FLOAT for the new interface in order to prevent the old |
| 412 |
reading behavior. Tags to check: TIFFTAG_BESTQUALITYSCALE, |
| 413 |
TIFFTAG_BASELINENOISE, TIFFTAG_BASELINESHARPNESS |
| 414 |
*/ |
| 415 |
fip = TIFFFindField(tif, TIFFTAG_BESTQUALITYSCALE, TIFF_ANY); |
| 416 |
tSetFieldType = fip->set_field_type; |
| 417 |
if (tSetFieldType == TIFF_SETGET_DOUBLE) |
| 418 |
{ |
| 419 |
blnIsRational2Double = FALSE; |
| 420 |
} |
| 421 |
else |
| 422 |
{ |
| 423 |
blnIsRational2Double = TRUE; |
| 424 |
fprintf(stderr, "-- Rational2Double from TIFF tag detected --\n"); |
| 425 |
} |
| 426 |
|
| 427 |
/*================== Write GPS and EXIF tags =====================*/ |
| 428 |
|
| 429 |
/*-- Set dummy EXIF/GPS tag in original tiff-structure in order to reserve |
| 430 |
* space for final dir_offset value, */ |
| 431 |
/* which is properly written at the end. */ |
| 432 |
dir_offset = 0; /* Zero, in case no Custom-IFD is written */ |
| 433 |
|
| 434 |
#define WRITE_GPS_TAGS |
| 435 |
#ifdef WRITE_GPS_TAGS |
| 436 |
if (!TIFFSetField(tif, TIFFTAG_GPSIFD, dir_offset)) |
| 437 |
{ |
| 438 |
fprintf(stderr, "Can't write TIFFTAG_GPSIFD\n"); |
| 439 |
} |
| 440 |
#endif |
| 441 |
|
| 442 |
/*------- And also do the same for the EXIF IFD tag here, because we have to |
| 443 |
* save the main directory next ------*/ |
| 444 |
/*-- Set dummy EXIF/GPS tag in original tiff-structure in order to reserve |
| 445 |
* space for final dir_offset value, which is properly written at the end. |
| 446 |
*/ |
| 447 |
#define WRITE_EXIF_TAGS |
| 448 |
#ifdef WRITE_EXIF_TAGS |
| 449 |
if (!TIFFSetField(tif, TIFFTAG_EXIFIFD, dir_offset)) |
| 450 |
{ |
| 451 |
fprintf(stderr, "Can't write TIFFTAG_EXIFIFD\n"); |
| 452 |
} |
| 453 |
#endif |
| 454 |
|
| 455 |
#ifndef WRITEPIXELLAST |
| 456 |
/*-- Write dummy pixel data. --*/ |
| 457 |
if (TIFFWriteScanline(tif, buf, 0, 0) < 0) |
| 458 |
{ |
| 459 |
fprintf(stderr, "Can't write image data.\n"); |
| 460 |
goto failure; |
| 461 |
} |
| 462 |
#endif |
| 463 |
|
| 464 |
#ifdef WRITE_GPS_TAGS |
| 465 |
#define READ_GPS_TAGS |
| 466 |
/*================== Write GPS tags =====================*/ |
| 467 |
|
| 468 |
/*-- Save current tiff-directory to file before directory is changed. |
| 469 |
* Otherwise it will be lost! */ |
| 470 |
/* The tif-structure is overwritten/ freshly initialized by any |
| 471 |
* "CreateDirectory" */ |
| 472 |
/*retCode = TIFFCheckpointDirectory(tif);*/ /* does not cleanup |
| 473 |
Tiff-Structure */ |
| 474 |
retCode = TIFFWriteDirectory(tif); /* cleanup Tiff-structure */ |
| 475 |
|
| 476 |
/*-- Now create a GPS directory. */ |
| 477 |
if (TIFFCreateGPSDirectory(tif) != 0) |
| 478 |
{ |
| 479 |
fprintf(stderr, "TIFFCreateGPSDirectory() failed.\n"); |
| 480 |
goto failure; |
| 481 |
} |
| 482 |
|
| 483 |
if (!TIFFSetField(tif, GPSTAG_VERSIONID, gpsVersion)) |
| 484 |
{ |
| 485 |
fprintf(stderr, "Can't write GPSTAG_VERSIONID\n"); |
| 486 |
goto failure; |
| 487 |
} |
| 488 |
|
| 489 |
if (blnFillGPSManually) |
| 490 |
{ |
| 491 |
/*================= Write manually valid data to the GPS fields |
| 492 |
* ==============*/ |
| 493 |
if (!TIFFSetField(tif, GPSTAG_LATITUDEREF, "N\0")) |
| 494 |
{ |
| 495 |
fprintf(stderr, "Can't write GPSTAG_LATITUDEREF\n"); |
| 496 |
goto failure; |
| 497 |
} |
| 498 |
/*-- Unfortunately, Rational values are defined as SETGET_DOUBLE but are |
| 499 |
* internally always stored as float. Single Rational values do not |
| 500 |
* matter for writing, because TIFFSetField() uses va_arg() which |
| 501 |
* performs "variables promotion" from type float to type double! |
| 502 |
* However, for reading of Rational values ONLY float-variables are |
| 503 |
* allowed - in contrary to the SETGET_DOUBLE specification at |
| 504 |
* tiffFields[] in tif_dirinfo.c. |
| 505 |
*/ |
| 506 |
/*-- ATTENTION: After the upgrade with Rational2Double, the GPSTAG |
| 507 |
* values are defined as double precision and need to be written and |
| 508 |
* also read in double precision! In order to maintain this code for |
| 509 |
* both cases, it is checked above if the TiffLibrary is compiled with |
| 510 |
* the new interface with Rational2Double or still uses the old |
| 511 |
* definitions, by setting blnIsRational2Double above. |
| 512 |
*/ |
| 513 |
if (blnIsRational2Double) |
| 514 |
{ |
| 515 |
fprintf(stderr, |
| 516 |
"-- GPS tags are written using Rational2Double --\n"); |
| 517 |
} |
| 518 |
else |
| 519 |
{ |
| 520 |
fprintf(stderr, "-- GPS tags are written using standard --\n"); |
| 521 |
} |
| 522 |
if (!blnIsRational2Double) |
| 523 |
{ |
| 524 |
for (j = 0; j < 3; j++) |
| 525 |
auxFloatArray[j] = (float)auxDoubleArrayGPS1[j]; |
| 526 |
if (!TIFFSetField(tif, GPSTAG_LATITUDE, auxFloatArray)) |
| 527 |
{ |
| 528 |
fprintf(stderr, "Can't write GPSTAG_LATITUDE\n"); |
| 529 |
goto failure; |
| 530 |
} |
| 531 |
} |
| 532 |
else |
| 533 |
{ |
| 534 |
/* Rational2Double interface for GPSTAG */ |
| 535 |
if (!TIFFSetField(tif, GPSTAG_LATITUDE, auxDoubleArrayGPS1)) |
| 536 |
{ |
| 537 |
fprintf(stderr, "Can't write GPSTAG_LATITUDE\n"); |
| 538 |
goto failure; |
| 539 |
} |
| 540 |
} |
| 541 |
if (!TIFFSetField(tif, GPSTAG_LONGITUDEREF, "W\0")) |
| 542 |
{ |
| 543 |
fprintf(stderr, "Can't write GPSTAG_LONGITUDEREF\n"); |
| 544 |
goto failure; |
| 545 |
} |
| 546 |
if (!blnIsRational2Double) |
| 547 |
{ |
| 548 |
for (j = 0; j < 3; j++) |
| 549 |
auxFloatArray[j] = (float)auxDoubleArrayGPS2[j]; |
| 550 |
if (!TIFFSetField(tif, GPSTAG_LONGITUDE, auxFloatArray)) |
| 551 |
{ |
| 552 |
fprintf(stderr, "Can't write GPSTAG_LONGITUDE\n"); |
| 553 |
goto failure; |
| 554 |
} |
| 555 |
} |
| 556 |
else |
| 557 |
{ |
| 558 |
/* Rational2Double interface for GPSTAG */ |
| 559 |
if (!TIFFSetField(tif, GPSTAG_LONGITUDE, auxDoubleArrayGPS2)) |
| 560 |
{ |
| 561 |
fprintf(stderr, "Can't write GPSTAG_LONGITUDE\n"); |
| 562 |
goto failure; |
| 563 |
} |
| 564 |
} |
| 565 |
/*-- AltitudeRef: default is above sea level!! */ |
| 566 |
if (!TIFFSetField(tif, GPSTAG_ALTITUDEREF, 0)) |
| 567 |
{ |
| 568 |
fprintf(stderr, "Can't write GPSTAG_ALTITUDEREF\n"); |
| 569 |
goto failure; |
| 570 |
} |
| 571 |
if (!TIFFSetField(tif, GPSTAG_ALTITUDE, auxDoubleGPSAltitude)) |
| 572 |
{ |
| 573 |
fprintf(stderr, "Can't write GPSTAG_ALTITUDE\n"); |
| 574 |
goto failure; |
| 575 |
} |
| 576 |
/*-- TimeStamp is only hh:mm:ss. See also DateTime string */ |
| 577 |
if (!TIFFSetField(tif, GPSTAG_TIMESTAMP, auxDoubleArrayGPSTime)) |
| 578 |
{ |
| 579 |
fprintf(stderr, "Can't write GPSTAG_TIMESTAMP\n"); |
| 580 |
goto failure; |
| 581 |
} |
| 582 |
if (!TIFFSetField(tif, GPSTAG_DATESTAMP, "2012:11:04")) |
| 583 |
{ |
| 584 |
fprintf(stderr, "Can't write GPSTAG_DATESTAMP\n"); |
| 585 |
goto failure; |
| 586 |
} |
| 587 |
|
| 588 |
if (!TIFFSetField(tif, GPSTAG_IMGDIRECTIONREF, "T\0")) |
| 589 |
{ |
| 590 |
fprintf(stderr, "Can't write GPSTAG_IMGDIRECTIONREF\n"); |
| 591 |
goto failure; |
| 592 |
} |
| 593 |
if (!TIFFSetField(tif, GPSTAG_IMGDIRECTION, auxDoubleGPSDirection)) |
| 594 |
{ |
| 595 |
fprintf(stderr, "Can't write GPSTAG_IMGDIRECTION\n"); |
| 596 |
goto failure; |
| 597 |
} |
| 598 |
|
| 599 |
/*-- Type TIFF_UNDEFINED */ |
| 600 |
if (!TIFFSetField(tif, GPSTAG_PROCESSINGMETHOD, 3, &auxCharArrayW[10])) |
| 601 |
{ |
| 602 |
fprintf(stderr, "Can't write GPSTAG_PROCESSINGMETHOD\n"); |
| 603 |
goto failure; |
| 604 |
} |
| 605 |
if (!TIFFSetField(tif, GPSTAG_AREAINFORMATION, 4, &auxCharArrayW[20])) |
| 606 |
{ |
| 607 |
fprintf(stderr, "Can't write GPSTAG_AREAINFORMATION\n"); |
| 608 |
goto failure; |
| 609 |
} |
| 610 |
|
| 611 |
/*-- PSTAG_DIFFERENTIAL , 1, 1, TIFF_SHORT , 0, |
| 612 |
* TIFF_SETGET_UINT16 */ |
| 613 |
if (!TIFFSetField(tif, GPSTAG_DIFFERENTIAL, auxShortArrayW[5])) |
| 614 |
{ |
| 615 |
fprintf(stderr, "Can't write GPSTAG_DIFFERENTIAL\n"); |
| 616 |
goto failure; |
| 617 |
} |
| 618 |
|
| 619 |
/* GPSTAG_GPSHPOSITIONINGERROR , 1, 1, TIFF_RATIONAL , 0, |
| 620 |
* TIFF_SETGET_DOUBLE but here written in float-precision */ |
| 621 |
#define GPSHPOSITIONINGERROR_VAL 0.369 |
| 622 |
auxFloat = (float)GPSHPOSITIONINGERROR_VAL; |
| 623 |
if (!TIFFSetField(tif, GPSTAG_GPSHPOSITIONINGERROR, auxFloat)) |
| 624 |
{ |
| 625 |
fprintf(stderr, "Can't write GPSTAG_GPSHPOSITIONINGERROR\n"); |
| 626 |
goto failure; |
| 627 |
} |
| 628 |
} |
| 629 |
else |
| 630 |
{ |
| 631 |
/*================= Write arbitrary data to the GPS fields |
| 632 |
* ==============*/ |
| 633 |
|
| 634 |
/*-- Get array, where GPS tag fields are defined --*/ |
| 635 |
tFieldArray = _TIFFGetGpsFields(); |
| 636 |
nTags = tFieldArray->count; |
| 637 |
|
| 638 |
/*-- TODO: fill in the for / switch part of EXIF writing, when finished |
| 639 |
* and tested!! */ |
| 640 |
|
| 641 |
} /*-- if (blnFillGPSManually) --*/ |
| 642 |
|
| 643 |
/*-- GPS - write custom directory GPS into file...---*/ |
| 644 |
/* (Get back the offset of GPS directory) */ |
| 645 |
if (!TIFFWriteCustomDirectory(tif, &dir_offset_GPS)) |
| 646 |
{ |
| 647 |
fprintf(stderr, "TIFFWriteCustomDirectory() with GPS failed.\n"); |
| 648 |
goto failure; |
| 649 |
} |
| 650 |
|
| 651 |
/*--- CheckpointDirectory at this place generates a second Main-IFD!!! */ |
| 652 |
/* retCode = TIFFCheckpointDirectory(tif); */ |
| 653 |
|
| 654 |
/*-- Set / reload previously saved main directory from file ---*/ |
| 655 |
if (!TIFFSetDirectory(tif, 0)) |
| 656 |
{ |
| 657 |
fprintf(stderr, "TIFFSetDirectory() within GPS failed.\n"); |
| 658 |
goto failure; |
| 659 |
} |
| 660 |
|
| 661 |
/*-- Write GPS tag reference / offset into GPSIFD tag in main directory --*/ |
| 662 |
if (!TIFFSetField(tif, TIFFTAG_GPSIFD, dir_offset_GPS)) |
| 663 |
{ |
| 664 |
fprintf(stderr, "Can't write TIFFTAG_GPSIFD\n"); |
| 665 |
goto failure; |
| 666 |
} |
| 667 |
|
| 668 |
/*=============== END writing GPS tags ==========================*/ |
| 669 |
#endif /*-- WRITE_GPS_TAGS --*/ |
| 670 |
|
| 671 |
/*================== Write EXIF 2.31 tags =====================*/ |
| 672 |
|
| 673 |
/*-- Set dummy EXIF/GPS tag in original tiff-structure in order to reserve |
| 674 |
* space for final dir_offset value, */ |
| 675 |
/* which is properly written at the end.*/ |
| 676 |
/*- We did this already above together with the GPS IFD-tag. Otherwise we |
| 677 |
* would do this here !! --------*/ |
| 678 |
/* if (!TIFFSetField(tif, TIFFTAG_EXIFIFD, dir_offset )) { |
| 679 |
fprintf (stderr, "Can't write TIFFTAG_EXIFIFD\n" ); |
| 680 |
} |
| 681 |
*/ |
| 682 |
|
| 683 |
#ifdef WRITE_EXIF_TAGS |
| 684 |
#define READ_EXIF_TAGS |
| 685 |
/*-- Save current tiff-directory to file before directory is changed. |
| 686 |
* Otherwise it will be lost! The tif-structure is overwritten/ freshly |
| 687 |
* initialized by any "CreateDirectory" |
| 688 |
*/ |
| 689 |
|
| 690 |
/*----- What is needed here ??? ---- |
| 691 |
* In custom_dir.c only TIFFFreeDirectory( tif ); is used to set |
| 692 |
*fields of another Sub-Directory TIFFFreeDirectory(tif); *-- Release |
| 693 |
*storage associated with a directory, especially custom-fields. |
| 694 |
*-- Using only TIFFFreeDirectory() here leads to an error!! |
| 695 |
*-- Using here TIFFCheckpointDirectory() leads to an additional Main-IFD ?? |
| 696 |
*/ |
| 697 |
/*retCode = TIFFCheckpointDirectory(tif);*/ /* does not cleanup |
| 698 |
Tiff-Structure */ |
| 699 |
retCode = TIFFWriteDirectory(tif); /* cleanup Tiff-structure */ |
| 700 |
|
| 701 |
/*-- Now create an EXIF directory. */ |
| 702 |
if (TIFFCreateEXIFDirectory(tif) != 0) |
| 703 |
{ |
| 704 |
fprintf(stderr, "TIFFCreateEXIFDirectory() failed.\n"); |
| 705 |
goto failure; |
| 706 |
} |
| 707 |
|
| 708 |
#define WRITE_ALL_EXIF_TAGS |
| 709 |
#ifdef WRITE_ALL_EXIF_TAGS |
| 710 |
#define READ_ALL_EXIF_TAGS |
| 711 |
/*================= EXIF: Write arbitrary data to the EXIF fields |
| 712 |
* ==============*/ |
| 713 |
/*-- Get array, where EXIF tag fields are defined |
| 714 |
* EXIF tags are written automatically with the defined precision |
| 715 |
* according to its tSetFieldType using the code below --*/ |
| 716 |
tFieldArray = _TIFFGetExifFields(); |
| 717 |
nTags = tFieldArray->count; |
| 718 |
|
| 719 |
for (i = 0; i < nTags; i++) |
| 720 |
{ |
| 721 |
bool deferredSetField = false; |
| 722 |
tTag = tFieldArray->fields[i].field_tag; |
| 723 |
tType = tFieldArray->fields[i].field_type; /* e.g. TIFF_RATIONAL */ |
| 724 |
tWriteCount = tFieldArray->fields[i].field_writecount; |
| 725 |
tSetFieldType = tFieldArray->fields[i] |
| 726 |
.set_field_type; /* e.g. TIFF_SETGET_C0_FLOAT */ |
| 727 |
tFieldName = tFieldArray->fields[i].field_name; |
| 728 |
pVoid = NULL; |
| 729 |
|
| 730 |
/*-- dependent on set_field_type write value --*/ |
| 731 |
switch (tSetFieldType) |
| 732 |
{ |
| 733 |
case TIFF_SETGET_ASCII: |
| 734 |
/* Either the stringlength is defined as a fixed length in |
| 735 |
* .field_writecount or a NULL-terminated string is used. */ |
| 736 |
/* Shorter strings than in auxTextArraxW need a |
| 737 |
* NULL-termination. Therefore copy the string. */ |
| 738 |
if (tWriteCount > 0) |
| 739 |
auxInt32 = tWriteCount - 1; |
| 740 |
else |
| 741 |
auxInt32 = (int32_t)strlen(auxTextArrayW[i]) - 1; |
| 742 |
strncpy(auxCharArray, auxTextArrayW[i], auxInt32); |
| 743 |
auxCharArray[auxInt32] = 0; |
| 744 |
if (!TIFFSetField(tif, tTag, auxCharArray)) |
| 745 |
{ |
| 746 |
fprintf(stderr, "Can't write %s\n", |
| 747 |
tFieldArray->fields[i].field_name); |
| 748 |
goto failure; |
| 749 |
} |
| 750 |
break; |
| 751 |
case TIFF_SETGET_UINT8: |
| 752 |
case TIFF_SETGET_UINT16: |
| 753 |
case TIFF_SETGET_UINT32: |
| 754 |
case TIFF_SETGET_IFD8: |
| 755 |
case TIFF_SETGET_INT: |
| 756 |
/*-- All those can be written with char, short or long |
| 757 |
* parameter. Only value range should be in line. */ |
| 758 |
if (!TIFFSetField(tif, tTag, auxInt32ArrayW[i])) |
| 759 |
{ |
| 760 |
fprintf(stderr, "Can't write %s\n", |
| 761 |
tFieldArray->fields[i].field_name); |
| 762 |
goto failure; |
| 763 |
} |
| 764 |
break; |
| 765 |
case TIFF_SETGET_SINT8: |
| 766 |
case TIFF_SETGET_SINT16: |
| 767 |
case TIFF_SETGET_SINT32: |
| 768 |
/*-- All those can be written with char, short or long |
| 769 |
* parameter. Only value range should be in line. */ |
| 770 |
if (!TIFFSetField(tif, tTag, -1.0 * auxInt32ArrayW[i])) |
| 771 |
{ |
| 772 |
fprintf(stderr, "Can't write %s\n", |
| 773 |
tFieldArray->fields[i].field_name); |
| 774 |
goto failure; |
| 775 |
} |
| 776 |
break; |
| 777 |
case TIFF_SETGET_FLOAT: |
| 778 |
case TIFF_SETGET_DOUBLE: |
| 779 |
if (tWriteCount == 1) |
| 780 |
{ |
| 781 |
/*-- All single values can be written with float or double |
| 782 |
* parameter. Only value range should be in line. */ |
| 783 |
if (!TIFFSetField(tif, tTag, auxDoubleArrayW[i])) |
| 784 |
{ |
| 785 |
fprintf(stderr, "Can't write %s\n", |
| 786 |
tFieldArray->fields[i].field_name); |
| 787 |
goto failure; |
| 788 |
} |
| 789 |
} |
| 790 |
else |
| 791 |
{ |
| 792 |
fprintf( |
| 793 |
stderr, |
| 794 |
"WriteCount for .set_field_type %d should be 1! %s\n", |
| 795 |
tSetFieldType, tFieldArray->fields[i].field_name); |
| 796 |
} |
| 797 |
break; |
| 798 |
case TIFF_SETGET_C0_FLOAT: |
| 799 |
case TIFF_SETGET_C0_DOUBLE: |
| 800 |
case TIFF_SETGET_C16_FLOAT: |
| 801 |
case TIFF_SETGET_C16_DOUBLE: |
| 802 |
case TIFF_SETGET_C32_FLOAT: |
| 803 |
case TIFF_SETGET_C32_DOUBLE: |
| 804 |
/* _Cxx_ just defines the size of the count parameter for the |
| 805 |
* array as C0=char, C16=short or C32=long */ |
| 806 |
/*-- Check, if it is a single parameter, a fixed array or a |
| 807 |
* variable array */ |
| 808 |
if (tWriteCount == 1) |
| 809 |
{ |
| 810 |
fprintf(stderr, |
| 811 |
"WriteCount for .set_field_type %d should be -1 or " |
| 812 |
"greater than 1! %s\n", |
| 813 |
tSetFieldType, tFieldArray->fields[i].field_name); |
| 814 |
} |
| 815 |
else |
| 816 |
{ |
| 817 |
/*-- Either fix or variable array --*/ |
| 818 |
/* For arrays, distinguishing between float or double is |
| 819 |
* essential, even for writing */ |
| 820 |
if (tSetFieldType == TIFF_SETGET_C0_FLOAT || |
| 821 |
tSetFieldType == TIFF_SETGET_C16_FLOAT || |
| 822 |
tSetFieldType == TIFF_SETGET_C32_FLOAT) |
| 823 |
pVoid = &auxFloatArrayW[i]; |
| 824 |
else |
| 825 |
pVoid = &auxDoubleArrayW[i]; |
| 826 |
/* Now decide between fixed or variable array */ |
| 827 |
if (tWriteCount > 1) |
| 828 |
{ |
| 829 |
/* fixed array with needed arraysize defined in |
| 830 |
* .field_writecount */ |
| 831 |
if (!TIFFSetField(tif, tTag, pVoid)) |
| 832 |
{ |
| 833 |
fprintf(stderr, "Can't write %s\n", |
| 834 |
tFieldArray->fields[i].field_name); |
| 835 |
goto failure; |
| 836 |
} |
| 837 |
} |
| 838 |
else |
| 839 |
{ |
| 840 |
/* special treatment of variable array */ |
| 841 |
/* for test, use always arraysize of VARIABLE_ARRAY_SIZE |
| 842 |
*/ |
| 843 |
if (!TIFFSetField(tif, tTag, VARIABLE_ARRAY_SIZE, |
| 844 |
pVoid)) |
| 845 |
{ |
| 846 |
fprintf(stderr, "Can't write %s\n", |
| 847 |
tFieldArray->fields[i].field_name); |
| 848 |
goto failure; |
| 849 |
} |
| 850 |
} |
| 851 |
} |
| 852 |
break; |
| 853 |
case TIFF_SETGET_C0_UINT8: |
| 854 |
case TIFF_SETGET_C0_SINT8: |
| 855 |
case TIFF_SETGET_C16_UINT8: |
| 856 |
case TIFF_SETGET_C16_SINT8: |
| 857 |
case TIFF_SETGET_C32_UINT8: |
| 858 |
case TIFF_SETGET_C32_SINT8: |
| 859 |
/* For arrays, distinguishing between float or double is |
| 860 |
* essential, even for writing */ |
| 861 |
pVoid = &auxCharArrayW[i]; |
| 862 |
deferredSetField = true; |
| 863 |
break; |
| 864 |
case TIFF_SETGET_C0_UINT16: |
| 865 |
case TIFF_SETGET_C0_SINT16: |
| 866 |
case TIFF_SETGET_C16_UINT16: |
| 867 |
case TIFF_SETGET_C16_SINT16: |
| 868 |
case TIFF_SETGET_C32_UINT16: |
| 869 |
case TIFF_SETGET_C32_SINT16: |
| 870 |
pVoid = &auxShortArrayW[i]; |
| 871 |
deferredSetField = true; |
| 872 |
break; |
| 873 |
case TIFF_SETGET_C0_UINT32: |
| 874 |
case TIFF_SETGET_C0_SINT32: |
| 875 |
case TIFF_SETGET_C16_UINT32: |
| 876 |
case TIFF_SETGET_C16_SINT32: |
| 877 |
case TIFF_SETGET_C32_UINT32: |
| 878 |
case TIFF_SETGET_C32_SINT32: |
| 879 |
pVoid = &auxInt32ArrayW[i]; |
| 880 |
deferredSetField = true; |
| 881 |
break; |
| 882 |
default: |
| 883 |
fprintf(stderr, |
| 884 |
"SetFieldType %d not defined within writing switch for " |
| 885 |
"%s.\n", |
| 886 |
tSetFieldType, tFieldName); |
| 887 |
}; /*-- switch() --*/ |
| 888 |
|
| 889 |
if (deferredSetField) |
| 890 |
{ |
| 891 |
/* _Cxx_ just defines the size of the count parameter for the array |
| 892 |
* as C0=char, C16=short or C32=long */ |
| 893 |
/*-- Check, if it is a single parameter, a fixed array or a variable |
| 894 |
* array */ |
| 895 |
if (tWriteCount == 1) |
| 896 |
{ |
| 897 |
fprintf(stderr, |
| 898 |
"WriteCount for .set_field_type %d should be -1 or " |
| 899 |
"greater than 1! %s\n", |
| 900 |
tSetFieldType, tFieldArray->fields[i].field_name); |
| 901 |
} |
| 902 |
else |
| 903 |
{ |
| 904 |
/*-- Either fix or variable array --*/ |
| 905 |
/* Now decide between fixed or variable array */ |
| 906 |
if (tWriteCount > 1) |
| 907 |
{ |
| 908 |
/* fixed array with needed arraysize defined in |
| 909 |
* .field_writecount */ |
| 910 |
if (!TIFFSetField(tif, tTag, pVoid)) |
| 911 |
{ |
| 912 |
fprintf(stderr, "Can't write %s\n", |
| 913 |
tFieldArray->fields[i].field_name); |
| 914 |
goto failure; |
| 915 |
} |
| 916 |
} |
| 917 |
else |
| 918 |
{ |
| 919 |
/* special treatment of variable array */ |
| 920 |
/* for test, use always arraysize of VARIABLE_ARRAY_SIZE */ |
| 921 |
if (!TIFFSetField(tif, tTag, VARIABLE_ARRAY_SIZE, pVoid)) |
| 922 |
{ |
| 923 |
fprintf(stderr, "Can't write %s\n", |
| 924 |
tFieldArray->fields[i].field_name); |
| 925 |
goto failure; |
| 926 |
} |
| 927 |
} |
| 928 |
} |
| 929 |
} |
| 930 |
} /*-- for() --*/ |
| 931 |
/*================= EXIF: END Writing arbitrary data to the EXIF fields END |
| 932 |
* END END ==============*/ |
| 933 |
#endif /*-- WRITE_ALL_EXIF_TAGS --*/ |
| 934 |
|
| 935 |
/*--- Set valid EXIF version, which is a 4 byte string --*/ |
| 936 |
if (!TIFFSetField(tif, EXIFTAG_EXIFVERSION, exifVersion)) |
| 937 |
{ |
| 938 |
fprintf(stderr, "Can't write EXIFTAG_EXIFVERSION\n"); |
| 939 |
goto failure; |
| 940 |
} |
| 941 |
|
| 942 |
/*-- EXIF - write custom directory EXIF into file...---*/ |
| 943 |
/* (Get back the offset of EXIF directory) */ |
| 944 |
if (!TIFFWriteCustomDirectory(tif, &dir_offset_EXIF)) |
| 945 |
{ |
| 946 |
fprintf(stderr, "TIFFWriteCustomDirectory() with EXIF failed.\n"); |
| 947 |
goto failure; |
| 948 |
} |
| 949 |
|
| 950 |
/*-- Go back to the first (main) directory, and set correct value of the |
| 951 |
* EXIFIFD pointer. */ |
| 952 |
/* (directory is reloaded from file!) */ |
| 953 |
TIFFSetDirectory(tif, 0); |
| 954 |
TIFFSetField(tif, TIFFTAG_EXIFIFD, dir_offset_EXIF); |
| 955 |
#endif /*-- WRITE_EXIF_TAGS --*/ |
| 956 |
|
| 957 |
#ifdef WRITEPIXELLAST |
| 958 |
/*-- Write dummy pixel data. --*/ |
| 959 |
if (TIFFWriteScanline(tif, buf, 0, 0) < 0) |
| 960 |
{ |
| 961 |
fprintf(stderr, "Can't write image data.\n"); |
| 962 |
goto failure; |
| 963 |
} |
| 964 |
#endif |
| 965 |
/*-- Write directory to file --*/ |
| 966 |
/* Always WriteDirectory before using/creating another directory. */ |
| 967 |
/* Not necessary before TIFFClose(), however, TIFFClose() uses |
| 968 |
* TIFFReWriteDirectory(), which forces directory to be written at another |
| 969 |
* location. */ |
| 970 |
retCode = TIFFWriteDirectory(tif); |
| 971 |
|
| 972 |
/*-- Write File to disk and close file --*/ |
| 973 |
/* TIFFClose() uses TIFFReWriteDirectory(), which forces directory to be |
| 974 |
* written at another location. */ |
| 975 |
/* Therefore, better use TIFFWriteDirectory() before. */ |
| 976 |
TIFFClose(tif); |
| 977 |
|
| 978 |
fprintf(stderr, "-------- Continue Test ---------- reading ...\n"); |
| 979 |
|
| 980 |
/*========================= READING ============= READING |
| 981 |
* ========================================*/ |
| 982 |
/* Ok, now test whether we can read written values correctly. */ |
| 983 |
tif = TIFFOpen(filenameRead, "r"); |
| 984 |
|
| 985 |
/*-- Read some parameters out of the main directory --*/ |
| 986 |
|
| 987 |
/*-- IMAGEWIDTH and -LENGTH are defined as TIFF_SETGET_UINT32 */ |
| 988 |
retCode = TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &auxUint32); |
| 989 |
if (!retCode) |
| 990 |
{ |
| 991 |
fprintf(stderr, "Can't read %s\n", "TIFFTAG_IMAGEWIDTH"); |
| 992 |
} |
| 993 |
if (auxUint32 != width) |
| 994 |
{ |
| 995 |
fprintf(stderr, |
| 996 |
"Read value of IMAGEWIDTH %" PRIu32 |
| 997 |
" differs from set value %" PRIu16 "\n", |
| 998 |
auxUint32, width); |
| 999 |
} |
| 1000 |
retCode = TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &auxUint32); |
| 1001 |
if (!retCode) |
| 1002 |
{ |
| 1003 |
fprintf(stderr, "Can't read %s\n", "TIFFTAG_IMAGELENGTH"); |
| 1004 |
} |
| 1005 |
if (auxUint32 != length) |
| 1006 |
{ |
| 1007 |
fprintf(stderr, |
| 1008 |
"Read value of TIFFTAG_IMAGELENGTH %" PRIu32 |
| 1009 |
" differs from set value %" PRIu16 "\n", |
| 1010 |
auxUint32, length); |
| 1011 |
} |
| 1012 |
|
| 1013 |
#ifdef ADDITIONAL_TAGS |
| 1014 |
/*- TIFFTAG_PIXAR_FOVCOT is a FLOAT parameter of type FIELD_CUSTOM !! */ |
| 1015 |
retCode = TIFFGetField(tif, TIFFTAG_PIXAR_FOVCOT, &auxFloat); |
| 1016 |
if (!retCode) |
| 1017 |
{ |
| 1018 |
fprintf(stderr, "Can't read %s\n", "TIFFTAG_PIXAR_FOVCOT"); |
| 1019 |
} |
| 1020 |
if (auxFloat != (float)PIXAR_FOVCOT_VAL) |
| 1021 |
{ |
| 1022 |
fprintf( |
| 1023 |
stderr, |
| 1024 |
"Read value of TIFFTAG_PIXAR_FOVCOT %f differs from set value %f\n", |
| 1025 |
auxFloat, PIXAR_FOVCOT_VAL); |
| 1026 |
} |
| 1027 |
|
| 1028 |
/* - TIFFTAG_BESTQUALITYSCALE is a Rational parameter, FIELD_CUSTOM and |
| 1029 |
* TIFF_SETGET_FLOAT */ |
| 1030 |
retCode = TIFFGetField(tif, TIFFTAG_BESTQUALITYSCALE, &auxFloat); |
| 1031 |
if (!retCode) |
| 1032 |
{ |
| 1033 |
fprintf(stderr, "Can't read %s\n", "TIFFTAG_BESTQUALITYSCALE"); |
| 1034 |
} |
| 1035 |
if (auxFloat != (float)BESTQUALITYSCALE_VAL) |
| 1036 |
{ |
| 1037 |
fprintf(stderr, |
| 1038 |
"Read value of TIFFTAG_BESTQUALITYSCALE %f differs from set " |
| 1039 |
"value %f\n", |
| 1040 |
auxFloat, BESTQUALITYSCALE_VAL); |
| 1041 |
} |
| 1042 |
|
| 1043 |
/* - TIFFTAG_BASELINENOISE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT */ |
| 1044 |
retCode = TIFFGetField(tif, TIFFTAG_BASELINENOISE, &auxDblUnion.dbl); |
| 1045 |
if (!retCode) |
| 1046 |
{ |
| 1047 |
fprintf(stderr, "Can't read %s\n", "TIFFTAG_BASELINENOISE"); |
| 1048 |
} |
| 1049 |
if (auxDblUnion.flt1 != (float)BESTQUALITYSCALE_VAL) |
| 1050 |
{ |
| 1051 |
fprintf(stderr, |
| 1052 |
"Read float value of TIFFTAG_BASELINENOISE %f differs from set " |
| 1053 |
"value %f\n", |
| 1054 |
auxDblUnion.flt1, BESTQUALITYSCALE_VAL); |
| 1055 |
} |
| 1056 |
|
| 1057 |
/*- Variable Array: TIFFTAG_DECODE is a SRATIONAL parameter |
| 1058 |
* TIFF_SETGET_C16_FLOAT type FIELD_CUSTOM with passcount=1 and variable |
| 1059 |
* length of array. */ |
| 1060 |
retCode = TIFFGetField(tif, TIFFTAG_DECODE, &count16, &pVoidArray); |
| 1061 |
if (!retCode) |
| 1062 |
{ |
| 1063 |
fprintf(stderr, "Can't read %s\n", "TIFFTAG_DECODE"); |
| 1064 |
} |
| 1065 |
/*- pVoidArray points to a Tiff-internal temporary memorypart. Thus, |
| 1066 |
* contents needs to be saved. */ |
| 1067 |
memcpy(&auxFloatArray, pVoidArray, (count16 * sizeof(auxFloatArray[0]))); |
| 1068 |
for (i = 0; i < count16; i++) |
| 1069 |
{ |
| 1070 |
dblDiffLimit = RATIONAL_EPS * auxFloatArrayN2[i]; |
| 1071 |
dblDiff = auxFloatArray[i] - auxFloatArrayN2[i]; |
| 1072 |
if (fabs(dblDiff) > fabs(dblDiffLimit)) |
| 1073 |
{ |
| 1074 |
fprintf(stderr, |
| 1075 |
"Read value %d of TIFFTAG_DECODE Array %f differs from set " |
| 1076 |
"value %f\n", |
| 1077 |
i, auxFloatArray[i], auxFloatArrayN2[i]); |
| 1078 |
} |
| 1079 |
} |
| 1080 |
|
| 1081 |
retCode = TIFFGetField(tif, TIFFTAG_BLACKLEVEL, &count16, &pVoidArray); |
| 1082 |
if (!retCode) |
| 1083 |
{ |
| 1084 |
fprintf(stderr, "Can't read %s\n", "TIFFTAG_BLACKLEVEL"); |
| 1085 |
} |
| 1086 |
/*- pVoidArray points to a Tiff-internal temporary memorypart. Thus, |
| 1087 |
* contents needs to be saved. */ |
| 1088 |
memcpy(&auxFloatArray, pVoidArray, (count16 * sizeof(auxFloatArray[0]))); |
| 1089 |
for (i = 0; i < count16; i++) |
| 1090 |
{ |
| 1091 |
dblDiffLimit = RATIONAL_EPS * auxFloatArrayN1[i]; |
| 1092 |
dblDiff = auxFloatArray[i] - auxFloatArrayN1[i]; |
| 1093 |
if (fabs(dblDiff) > fabs(dblDiffLimit)) |
| 1094 |
{ |
| 1095 |
fprintf(stderr, |
| 1096 |
"Read value %d of TIFFTAG_BLACKLEVEL Array %f differs from " |
| 1097 |
"set value %f\n", |
| 1098 |
i, auxFloatArray[i], auxFloatArrayN1[i]); |
| 1099 |
} |
| 1100 |
} |
| 1101 |
|
| 1102 |
/*- Fixed Array: TIFFTAG_DEFAULTCROPSIZE, 2, 2, TIFF_RATIONAL, 0, |
| 1103 |
* TIFF_SETGET_C0_FLOAT */ |
| 1104 |
retCode = TIFFGetField(tif, TIFFTAG_DEFAULTCROPSIZE, &pVoidArray); |
| 1105 |
if (!retCode) |
| 1106 |
{ |
| 1107 |
fprintf(stderr, "Can't read %s\n", "TIFFTAG_DEFAULTCROPSIZE"); |
| 1108 |
} |
| 1109 |
/*- pVoidArray points to a Tiff-internal temporary memorypart. Thus, |
| 1110 |
* contents needs to be saved. */ |
| 1111 |
memcpy(&auxFloatArray, pVoidArray, (2 * sizeof(auxFloatArray[0]))); |
| 1112 |
for (i = 0; i < 2; i++) |
| 1113 |
{ |
| 1114 |
dblDiffLimit = RATIONAL_EPS * auxFloatArrayW[i]; |
| 1115 |
dblDiff = auxFloatArray[i] - auxFloatArrayW[i]; |
| 1116 |
if (fabs(dblDiff) > fabs(dblDiffLimit)) |
| 1117 |
{ |
| 1118 |
fprintf(stderr, |
| 1119 |
"Read value %d of TIFFTAG_DEFAULTCROPSIZE Array %f differs " |
| 1120 |
"from set value %f\n", |
| 1121 |
i, auxFloatArray[i], auxFloatArrayW[i]); |
| 1122 |
} |
| 1123 |
} |
| 1124 |
|
| 1125 |
#endif /*-- ADDITIONAL_TAGS --*/ |
| 1126 |
|
| 1127 |
#ifdef READ_GPS_TAGS |
| 1128 |
/*================== Reading GPS tags =====================*/ |
| 1129 |
/*-- First get offset to GPS-directory and set it active (this will destroy |
| 1130 |
* previously main directory fields in memory!) */ |
| 1131 |
retCode = TIFFGetField(tif, TIFFTAG_GPSIFD, &read_dir_offset); |
| 1132 |
if (!retCode) |
| 1133 |
{ |
| 1134 |
fprintf(stderr, "Can't read %s\n", "TIFFTAG_GPSIFD"); |
| 1135 |
} |
| 1136 |
retCode = TIFFReadGPSDirectory(tif, read_dir_offset); |
| 1137 |
if (!retCode) |
| 1138 |
{ |
| 1139 |
fprintf(stderr, "Can't read %s\n", "TIFFReadGPSDirectory()"); |
| 1140 |
} |
| 1141 |
|
| 1142 |
/*-- Now read some parameters from GPS-directory --*/ |
| 1143 |
|
| 1144 |
/*-- Fixed Array: GPS-Version is a fixed array (of 4 characters) */ |
| 1145 |
retCode = TIFFGetField(tif, GPSTAG_VERSIONID, &pGpsVersion); |
| 1146 |
if (!retCode) |
| 1147 |
{ |
| 1148 |
fprintf(stderr, "Can't read %s\n", "GPSTAG_VERSIONID"); |
| 1149 |
} |
| 1150 |
else |
| 1151 |
{ |
| 1152 |
memcpy(auxCharArray, pGpsVersion, sizeof(gpsVersion)); |
| 1153 |
for (i = 0; i < 4; i++) |
| 1154 |
{ |
| 1155 |
if (auxCharArray[i] != pGpsVersion[i]) |
| 1156 |
{ |
| 1157 |
fprintf(stderr, |
| 1158 |
"Read value %d of GPSTAG_VERSIONID %d differs from set " |
| 1159 |
"value %d\n", |
| 1160 |
i, auxCharArray[i], pGpsVersion[i]); |
| 1161 |
} |
| 1162 |
} |
| 1163 |
} |
| 1164 |
/*-- LATITUDEREF is a fixed String of one character plus ending zero. */ |
| 1165 |
retCode = TIFFGetField(tif, GPSTAG_LATITUDEREF, &pAscii); |
| 1166 |
if (!retCode) |
| 1167 |
{ |
| 1168 |
fprintf(stderr, "Can't read %s\n", "GPSTAG_LATITUDEREF"); |
| 1169 |
} |
| 1170 |
retCode2 = strncmp("N", pAscii, 1); |
| 1171 |
if (retCode2 != 0) |
| 1172 |
{ |
| 1173 |
fprintf(stderr, |
| 1174 |
"Read value %d of GPSTAG_LATITUDEREF %s differs from set value " |
| 1175 |
"%s\n", |
| 1176 |
i, "N", pAscii); |
| 1177 |
} |
| 1178 |
|
| 1179 |
/*-- Fixed Array: Latitude is an array of 3 Rational-values. TIFFGetField() |
| 1180 |
* returns a pointer to a temporary float-/double-array. */ |
| 1181 |
/*-- ATTENTION: After the upgrade with Rational2Double, the GPSTAG values |
| 1182 |
* are defined as double precision and need to be written and also read in |
| 1183 |
* double precision! In order to maintain this code for both cases, it is |
| 1184 |
* checked above if the TiffLibrary is compiled with the new interface with |
| 1185 |
* Rational2Double or still uses the old definitions, by setting |
| 1186 |
* blnIsRational2Double above. |
| 1187 |
*/ |
| 1188 |
if (blnIsRational2Double) |
| 1189 |
{ |
| 1190 |
fprintf(stderr, "-- GPS tags are read using Rational2Double --\n"); |
| 1191 |
} |
| 1192 |
else |
| 1193 |
{ |
| 1194 |
fprintf(stderr, "-- GPS tags are read using standard --\n"); |
| 1195 |
} |
| 1196 |
retCode = TIFFGetField(tif, GPSTAG_LATITUDE, &pVoidArray); |
| 1197 |
if (!retCode) |
| 1198 |
{ |
| 1199 |
fprintf(stderr, "Can't read %s\n", "GPSTAG_LATITUDE"); |
| 1200 |
} |
| 1201 |
if (!blnIsRational2Double) |
| 1202 |
{ |
| 1203 |
/* Reset arrays for debugging purpose first */ |
| 1204 |
memset(auxFloatArray, 0, sizeof(auxFloatArray)); |
| 1205 |
memcpy(auxFloatArray, pVoidArray, 3 * sizeof(float)); |
| 1206 |
/* for comparison copy to doubleArray */ |
| 1207 |
for (i = 0; i < 3; i++) |
| 1208 |
auxDoubleArray[i] = (double)auxFloatArray[i]; |
| 1209 |
} |
| 1210 |
else |
| 1211 |
{ |
| 1212 |
/* Rational2Double interface for GPSTAG reads double array */ |
| 1213 |
memset(auxDoubleArray, 0, sizeof(auxDoubleArray)); |
| 1214 |
memcpy(auxDoubleArray, pVoidArray, 3 * sizeof(double)); |
| 1215 |
} |
| 1216 |
for (i = 0; i < 3; i++) |
| 1217 |
{ |
| 1218 |
dblDiffLimit = RATIONAL_EPS * auxDoubleArrayGPS1[i]; |
| 1219 |
dblDiff = auxDoubleArray[i] - auxDoubleArrayGPS1[i]; |
| 1220 |
if (fabs(dblDiff) > fabs(dblDiffLimit)) |
| 1221 |
{ |
| 1222 |
fprintf(stderr, |
| 1223 |
"Read value %d of GPSTAG_LATITUDE %f differs from set " |
| 1224 |
"value %f\n", |
| 1225 |
i, auxDoubleArray[i], auxDoubleArrayGPS1[i]); |
| 1226 |
} |
| 1227 |
} |
| 1228 |
|
| 1229 |
/*-- LONGITUDEREF is a fixed String of one character plus ending zero. */ |
| 1230 |
retCode = TIFFGetField(tif, GPSTAG_LONGITUDEREF, &pAscii); |
| 1231 |
if (!retCode) |
| 1232 |
{ |
| 1233 |
fprintf(stderr, "Can't read %s\n", "GPSTAG_LONGITUDEREF"); |
| 1234 |
} |
| 1235 |
retCode2 = strncmp("W", pAscii, 1); |
| 1236 |
if (retCode2 != 0) |
| 1237 |
{ |
| 1238 |
fprintf(stderr, |
| 1239 |
"Read value %d of GPSTAG_LONGITUDEREF %s differs from set " |
| 1240 |
"value %s\n", |
| 1241 |
i, "W", pAscii); |
| 1242 |
} |
| 1243 |
|
| 1244 |
retCode = TIFFGetField(tif, GPSTAG_LONGITUDE, &pVoidArray); |
| 1245 |
if (!retCode) |
| 1246 |
{ |
| 1247 |
fprintf(stderr, "Can't read %s\n", "GPSTAG_LONGITUDE"); |
| 1248 |
} |
| 1249 |
if (!blnIsRational2Double) |
| 1250 |
{ |
| 1251 |
/* Reset arrays for debugging purpose first */ |
| 1252 |
memset(auxFloatArray, 0, sizeof(auxFloatArray)); |
| 1253 |
memcpy(auxFloatArray, pVoidArray, 3 * sizeof(float)); |
| 1254 |
/* for comparison copy to doubleArray */ |
| 1255 |
for (i = 0; i < 3; i++) |
| 1256 |
auxDoubleArray[i] = (double)auxFloatArray[i]; |
| 1257 |
} |
| 1258 |
else |
| 1259 |
{ |
| 1260 |
/* Rational2Double interface for GPSTAG reads double array */ |
| 1261 |
memset(auxDoubleArray, 0, sizeof(auxDoubleArray)); |
| 1262 |
memcpy(auxDoubleArray, pVoidArray, 3 * sizeof(double)); |
| 1263 |
} |
| 1264 |
for (i = 0; i < 3; i++) |
| 1265 |
{ |
| 1266 |
dblDiffLimit = RATIONAL_EPS * auxDoubleArrayGPS2[i]; |
| 1267 |
dblDiff = auxDoubleArray[i] - auxDoubleArrayGPS2[i]; |
| 1268 |
if (fabs(dblDiff) > fabs(dblDiffLimit)) |
| 1269 |
{ |
| 1270 |
fprintf(stderr, |
| 1271 |
"Read value %d of GPSTAG_LONGITUDE %f differs from set " |
| 1272 |
"value %f\n", |
| 1273 |
i, auxDoubleArray[i], auxDoubleArrayGPS2[i]); |
| 1274 |
} |
| 1275 |
} |
| 1276 |
|
| 1277 |
/* TIFF_RATIONAL, TIFF_SETGET_DOUBLE */ |
| 1278 |
if (!TIFFGetField(tif, GPSTAG_ALTITUDE, &auxDblUnion.dbl)) |
| 1279 |
{ |
| 1280 |
fprintf(stderr, "Can't read GPSTAG_ALTITUDE\n"); |
| 1281 |
GOTOFAILURE_GPS |
| 1282 |
} |
| 1283 |
if (blnIsRational2Double) |
| 1284 |
{ |
| 1285 |
/* New interface allows also double precision for TIFF_RATIONAL */ |
| 1286 |
auxDouble = auxDblUnion.dbl; |
| 1287 |
} |
| 1288 |
else |
| 1289 |
{ |
| 1290 |
/* Old interface reads TIFF_RATIONAL defined as TIFF_SETGET_DOUBLE |
| 1291 |
* always as FLOAT */ |
| 1292 |
auxDouble = (double)auxDblUnion.flt1; |
| 1293 |
} |
| 1294 |
/* compare read values with written ones */ |
| 1295 |
dblDiffLimit = RATIONAL_EPS * auxDoubleGPSAltitude; |
| 1296 |
dblDiff = auxDouble - auxDoubleGPSAltitude; |
| 1297 |
if (fabs(dblDiff) > fabs(dblDiffLimit)) |
| 1298 |
{ |
| 1299 |
fprintf(stderr, |
| 1300 |
"Read value of GPSTAG_ALTITUDE %f differs from set value %f\n", |
| 1301 |
auxDouble, auxDoubleGPSAltitude); |
| 1302 |
GOTOFAILURE_GPS |
| 1303 |
} |
| 1304 |
|
| 1305 |
/*-- TimeStamp is only hh:mm:ss. See also DateTime string 3, TIFF_RATIONAL, |
| 1306 |
* TIFF_SETGET_C0_DOUBLE */ |
| 1307 |
retCode = TIFFGetField(tif, GPSTAG_TIMESTAMP, &pVoidArray); |
| 1308 |
if (!retCode) |
| 1309 |
{ |
| 1310 |
fprintf(stderr, "Can't read %s\n", "GPSTAG_TIMESTAMP"); |
| 1311 |
} |
| 1312 |
if (!blnIsRational2Double) |
| 1313 |
{ |
| 1314 |
/* Reset arrays for debugging purpose first */ |
| 1315 |
memset(auxFloatArray, 0, sizeof(auxFloatArray)); |
| 1316 |
memcpy(auxFloatArray, pVoidArray, 3 * sizeof(float)); |
| 1317 |
/* for comparison copy to doubleArray */ |
| 1318 |
for (i = 0; i < 3; i++) |
| 1319 |
auxDoubleArray[i] = (double)auxFloatArray[i]; |
| 1320 |
} |
| 1321 |
else |
| 1322 |
{ |
| 1323 |
/* Rational2Double interface for GPSTAG reads double array */ |
| 1324 |
memset(auxDoubleArray, 0, sizeof(auxDoubleArray)); |
| 1325 |
memcpy(auxDoubleArray, pVoidArray, 3 * sizeof(double)); |
| 1326 |
} |
| 1327 |
for (i = 0; i < 3; i++) |
| 1328 |
{ |
| 1329 |
dblDiffLimit = RATIONAL_EPS * auxDoubleArrayGPSTime[i]; |
| 1330 |
dblDiff = auxDoubleArray[i] - auxDoubleArrayGPSTime[i]; |
| 1331 |
if (fabs(dblDiff) > fabs(dblDiffLimit)) |
| 1332 |
{ |
| 1333 |
fprintf(stderr, |
| 1334 |
"Read value %d of GPSTAG_TIMESTAMP %f differs from set " |
| 1335 |
"value %f\n", |
| 1336 |
i, auxDoubleArray[i], auxDoubleArrayGPS2[i]); |
| 1337 |
GOTOFAILURE_GPS |
| 1338 |
} |
| 1339 |
} |
| 1340 |
|
| 1341 |
/* GPSTAG_IMGDIRECTION --- TIFF_RATIONAL, TIFF_SETGET_DOUBLE */ |
| 1342 |
if (!TIFFGetField(tif, GPSTAG_IMGDIRECTION, &auxDblUnion.dbl)) |
| 1343 |
{ |
| 1344 |
fprintf(stderr, "Can't read GPSTAG_IMGDIRECTION\n"); |
| 1345 |
GOTOFAILURE_GPS |
| 1346 |
} |
| 1347 |
if (blnIsRational2Double) |
| 1348 |
{ |
| 1349 |
/* New interface allows also double precision for TIFF_RATIONAL */ |
| 1350 |
auxDouble = auxDblUnion.dbl; |
| 1351 |
} |
| 1352 |
else |
| 1353 |
{ |
| 1354 |
/* Old interface reads TIFF_RATIONAL defined as TIFF_SETGET_DOUBLE |
| 1355 |
* always as FLOAT */ |
| 1356 |
auxDouble = (double)auxDblUnion.flt1; |
| 1357 |
} |
| 1358 |
/* compare read values with written ones */ |
| 1359 |
dblDiffLimit = RATIONAL_EPS * auxDoubleGPSDirection; |
| 1360 |
dblDiff = auxDouble - auxDoubleGPSDirection; |
| 1361 |
if (fabs(dblDiff) > fabs(dblDiffLimit)) |
| 1362 |
{ |
| 1363 |
fprintf( |
| 1364 |
stderr, |
| 1365 |
"Read value of GPSTAG_IMGDIRECTION %f differs from set value %f\n", |
| 1366 |
auxDouble, auxDoubleGPSDirection); |
| 1367 |
GOTOFAILURE_GPS |
| 1368 |
} |
| 1369 |
|
| 1370 |
/*-- GPSTAG_DIFFERENTIAL , 1, 1, TIFF_SHORT , 0, |
| 1371 |
* TIFF_SETGET_UINT16 |
| 1372 |
*/ |
| 1373 |
retCode = TIFFGetField(tif, GPSTAG_DIFFERENTIAL, &auxShort); |
| 1374 |
if (!retCode) |
| 1375 |
{ |
| 1376 |
fprintf(stderr, "Can't read %s\n", "GPSTAG_DIFFERENTIAL"); |
| 1377 |
} |
| 1378 |
if (auxShort != auxShortArrayW[5]) |
| 1379 |
{ |
| 1380 |
fprintf( |
| 1381 |
stderr, |
| 1382 |
"Read value of GPSTAG_DIFFERENTIAL %d differs from set value %d\n", |
| 1383 |
auxShort, auxShortArrayW[5]); |
| 1384 |
GOTOFAILURE_GPS |
| 1385 |
} |
| 1386 |
|
| 1387 |
/*-- GPSHPOSITIONINGERROR - new tag for EXIF 2.31 --*/ |
| 1388 |
if (!TIFFGetField(tif, GPSTAG_GPSHPOSITIONINGERROR, &auxDblUnion.dbl)) |
| 1389 |
{ |
| 1390 |
fprintf(stderr, "Can't read GPSTAG_GPSHPOSITIONINGERROR\n"); |
| 1391 |
GOTOFAILURE_GPS |
| 1392 |
} |
| 1393 |
if (blnIsRational2Double) |
| 1394 |
{ |
| 1395 |
/* New interface allows also double precision for TIFF_RATIONAL */ |
| 1396 |
auxDouble = auxDblUnion.dbl; |
| 1397 |
} |
| 1398 |
else |
| 1399 |
{ |
| 1400 |
/* Old interface reads TIFF_RATIONAL defined as TIFF_SETGET_DOUBLE |
| 1401 |
* always as FLOAT */ |
| 1402 |
auxDouble = (double)auxDblUnion.flt1; |
| 1403 |
} |
| 1404 |
/* compare read values with written ones */ |
| 1405 |
auxFloat = (float)GPSHPOSITIONINGERROR_VAL; |
| 1406 |
dblDiffLimit = RATIONAL_EPS * auxFloat; |
| 1407 |
dblDiff = auxDouble - auxFloat; |
| 1408 |
if (fabs(dblDiff) > fabs(dblDiffLimit)) |
| 1409 |
{ |
| 1410 |
fprintf(stderr, |
| 1411 |
"Read value of GPSTAG_GPSHPOSITIONINGERROR %f differs from set " |
| 1412 |
"value %f\n", |
| 1413 |
auxDouble, auxFloat); |
| 1414 |
GOTOFAILURE_GPS |
| 1415 |
} |
| 1416 |
|
| 1417 |
/*=============== END reading GPS tags ==========================*/ |
| 1418 |
#endif /*-- READ_GPS_TAGS --*/ |
| 1419 |
|
| 1420 |
/*================== Reading EXIF 2.31 tags =====================*/ |
| 1421 |
|
| 1422 |
/*--- Firstly, get EXIF directory offset from main directory. */ |
| 1423 |
|
| 1424 |
/*-- Go back to the first (main) directory, and get value of the EXIFIFD |
| 1425 |
* directory- offset. */ |
| 1426 |
/* (directory is reloaded from file!) */ |
| 1427 |
TIFFSetDirectory(tif, 0); |
| 1428 |
retCode = TIFFGetField(tif, TIFFTAG_EXIFIFD, &read_dir_offset); |
| 1429 |
|
| 1430 |
#ifdef READ_EXIF_TAGS |
| 1431 |
/*-- Now read EXIF directory from file into memory --*/ |
| 1432 |
retCode = TIFFReadEXIFDirectory(tif, read_dir_offset); |
| 1433 |
|
| 1434 |
/*-- Now get some parameters from EXIF-directory (already read into memory) |
| 1435 |
* --*/ |
| 1436 |
retCode = TIFFGetField(tif, EXIFTAG_EXIFVERSION, &pAscii); |
| 1437 |
|
| 1438 |
#ifdef READ_ALL_EXIF_TAGS |
| 1439 |
/*-- Get array, where EXIF tag fields are defined --*/ |
| 1440 |
tFieldArray = _TIFFGetExifFields(); |
| 1441 |
nTags = tFieldArray->count; |
| 1442 |
/*-- Check, if the TiffLibrary is compiled with the new interface with |
| 1443 |
* Rational2Double or still uses the old definitions. */ |
| 1444 |
/* tif points to EXIF tags, so TIFFFindField() can only access the EXIF tag |
| 1445 |
* fields */ |
| 1446 |
fip = TIFFFindField(tif, EXIFTAG_EXPOSURETIME, TIFF_ANY); |
| 1447 |
tSetFieldType = fip->set_field_type; |
| 1448 |
if (tSetFieldType == TIFF_SETGET_DOUBLE) |
| 1449 |
{ |
| 1450 |
blnIsRational2Double = FALSE; |
| 1451 |
fprintf(stderr, "-- EXIF tags read with standard --\n"); |
| 1452 |
} |
| 1453 |
else |
| 1454 |
{ |
| 1455 |
blnIsRational2Double = TRUE; |
| 1456 |
fprintf(stderr, |
| 1457 |
"-- Rational2Double for reading EXIF tags detected --\n"); |
| 1458 |
} |
| 1459 |
|
| 1460 |
for (i = 0; i < nTags; i++) |
| 1461 |
{ |
| 1462 |
bool deferredSetField = false; |
| 1463 |
tTag = tFieldArray->fields[i].field_tag; |
| 1464 |
tType = tFieldArray->fields[i].field_type; /* e.g. TIFF_RATIONAL */ |
| 1465 |
tWriteCount = tFieldArray->fields[i].field_writecount; |
| 1466 |
tSetFieldType = tFieldArray->fields[i] |
| 1467 |
.set_field_type; /* e.g. TIFF_SETGET_C0_FLOAT */ |
| 1468 |
tFieldName = tFieldArray->fields[i].field_name; |
| 1469 |
|
| 1470 |
/*-- dependent on set_field_type read value --*/ |
| 1471 |
switch (tSetFieldType) |
| 1472 |
{ |
| 1473 |
case TIFF_SETGET_ASCII: |
| 1474 |
/* Either the stringlength is defined as a fixed length in |
| 1475 |
* .field_writecount or a NULL-terminated string is used. */ |
| 1476 |
if (!TIFFGetField(tif, tTag, &pAscii)) |
| 1477 |
{ |
| 1478 |
fprintf(stderr, "Can't read %s\n", |
| 1479 |
tFieldArray->fields[i].field_name); |
| 1480 |
GOTOFAILURE_ALL_EXIF |
| 1481 |
break; |
| 1482 |
} |
| 1483 |
/* Save string from temporary buffer and compare with written |
| 1484 |
* string. */ |
| 1485 |
strncpy(auxCharArray, pAscii, sizeof(auxCharArray) - 1u); |
| 1486 |
auxCharArray[sizeof(auxCharArray) - 1u] = '\0'; |
| 1487 |
if (tWriteCount > 0) |
| 1488 |
auxInt32 = tWriteCount - 1; |
| 1489 |
else |
| 1490 |
auxInt32 = (int32_t)strlen(auxCharArray); |
| 1491 |
retCode2 = strncmp(auxCharArray, auxTextArrayW[i], auxInt32); |
| 1492 |
if (retCode2 != 0) |
| 1493 |
{ |
| 1494 |
fprintf( |
| 1495 |
stderr, |
| 1496 |
"%d:Read value of %s %s differs from set value %s\n", i, |
| 1497 |
tFieldName, auxCharArray, auxTextArrayW[i]); |
| 1498 |
GOTOFAILURE_ALL_EXIF |
| 1499 |
} |
| 1500 |
break; |
| 1501 |
/*-- For reading, the parameter size is to be observed !! */ |
| 1502 |
case TIFF_SETGET_UINT8: |
| 1503 |
case TIFF_SETGET_SINT8: |
| 1504 |
if (!TIFFGetField(tif, tTag, &auxChar)) |
| 1505 |
{ |
| 1506 |
fprintf(stderr, "Can't read %s\n", |
| 1507 |
tFieldArray->fields[i].field_name); |
| 1508 |
GOTOFAILURE_ALL_EXIF |
| 1509 |
break; |
| 1510 |
} |
| 1511 |
/* compare read values with written ones */ |
| 1512 |
auxInt32 = auxChar; |
| 1513 |
if (auxInt32 != (char)auxInt32ArrayW[i]) |
| 1514 |
{ |
| 1515 |
fprintf( |
| 1516 |
stderr, |
| 1517 |
"%d:Read value of %s %d differs from set value %d\n", i, |
| 1518 |
tFieldName, auxInt32, auxInt32ArrayW[i]); |
| 1519 |
} |
| 1520 |
break; |
| 1521 |
case TIFF_SETGET_UINT16: |
| 1522 |
case TIFF_SETGET_SINT16: |
| 1523 |
if (!TIFFGetField(tif, tTag, &auxShort)) |
| 1524 |
{ |
| 1525 |
fprintf(stderr, "Can't read %s\n", |
| 1526 |
tFieldArray->fields[i].field_name); |
| 1527 |
GOTOFAILURE_ALL_EXIF |
| 1528 |
break; |
| 1529 |
} |
| 1530 |
/* compare read values with written ones */ |
| 1531 |
auxInt32 = auxShort; |
| 1532 |
if (auxInt32 != (short)auxInt32ArrayW[i]) |
| 1533 |
{ |
| 1534 |
fprintf( |
| 1535 |
stderr, |
| 1536 |
"%d:Read value of %s %d differs from set value %d\n", i, |
| 1537 |
tFieldName, auxInt32, auxInt32ArrayW[i]); |
| 1538 |
} |
| 1539 |
break; |
| 1540 |
case TIFF_SETGET_UINT32: |
| 1541 |
case TIFF_SETGET_SINT32: |
| 1542 |
case TIFF_SETGET_IFD8: |
| 1543 |
case TIFF_SETGET_INT: |
| 1544 |
if (!TIFFGetField(tif, tTag, &auxUint32)) |
| 1545 |
{ |
| 1546 |
fprintf(stderr, "Can't read %s\n", |
| 1547 |
tFieldArray->fields[i].field_name); |
| 1548 |
GOTOFAILURE_ALL_EXIF |
| 1549 |
break; |
| 1550 |
} |
| 1551 |
/* compare read values with written ones */ |
| 1552 |
auxInt32 = auxUint32; |
| 1553 |
if (auxInt32 != auxInt32ArrayW[i]) |
| 1554 |
{ |
| 1555 |
fprintf( |
| 1556 |
stderr, |
| 1557 |
"%d:Read value of %s %d differs from set value %d\n", i, |
| 1558 |
tFieldName, auxInt32, auxInt32ArrayW[i]); |
| 1559 |
} |
| 1560 |
break; |
| 1561 |
case TIFF_SETGET_FLOAT: |
| 1562 |
if (!TIFFGetField(tif, tTag, &auxFloat)) |
| 1563 |
{ |
| 1564 |
fprintf(stderr, "Can't read %s\n", |
| 1565 |
tFieldArray->fields[i].field_name); |
| 1566 |
GOTOFAILURE_ALL_EXIF |
| 1567 |
break; |
| 1568 |
} |
| 1569 |
/* compare read values with written ones */ |
| 1570 |
if (tType == TIFF_RATIONAL || tType == TIFF_SRATIONAL) |
| 1571 |
dblDiffLimit = RATIONAL_EPS * auxDoubleArrayW[i]; |
| 1572 |
else |
| 1573 |
dblDiffLimit = 1e-6; |
| 1574 |
dblDiff = auxFloat - auxDoubleArrayW[i]; |
| 1575 |
if (fabs(dblDiff) > fabs(dblDiffLimit)) |
| 1576 |
{ |
| 1577 |
/*--: EXIFTAG_SUBJECTDISTANCE: LibTiff returns value of |
| 1578 |
* "-1.0" if numerator equals 4294967295 (0xFFFFFFFF) to |
| 1579 |
* indicate infinite distance! However, there are two other |
| 1580 |
* EXIF tags where numerator indicates a special value and |
| 1581 |
* six other cases where the denominator indicates special |
| 1582 |
* values, which are not treated within LibTiff!! |
| 1583 |
*/ |
| 1584 |
if (!(tTag == EXIFTAG_SUBJECTDISTANCE && auxFloat == -1.0)) |
| 1585 |
{ |
| 1586 |
fprintf(stderr, |
| 1587 |
"%d:Read value of %s %f differs from set value " |
| 1588 |
"%f\n", |
| 1589 |
i, tFieldName, auxFloat, auxDoubleArrayW[i]); |
| 1590 |
GOTOFAILURE_ALL_EXIF |
| 1591 |
} |
| 1592 |
} |
| 1593 |
break; |
| 1594 |
case TIFF_SETGET_DOUBLE: |
| 1595 |
/*-- Unfortunately, TIFF_SETGET_DOUBLE is used for TIFF_RATIONAL |
| 1596 |
* but those have to be read with FLOAT !!! */ |
| 1597 |
/* Only TIFFTAG_STONITS is a TIFF_DOUBLE, which has to be read |
| 1598 |
* as DOUBLE!! */ |
| 1599 |
/*-- ATTENTION: ---- |
| 1600 |
* Only after update with Rational2Double feature, also |
| 1601 |
TIFF_RATIONAL can be read in double precision!!! |
| 1602 |
* Therefore, use a union to avoid overflow in TIFFGetField() |
| 1603 |
return value |
| 1604 |
* and depending on version check for the right interface |
| 1605 |
here: |
| 1606 |
* - old interface: correct value should be here a float |
| 1607 |
* - new interface: correct value should be here a double |
| 1608 |
* Interface version (old/new) is determined above. |
| 1609 |
-------------------*/ |
| 1610 |
if (!TIFFGetField(tif, tTag, &auxDblUnion.dbl)) |
| 1611 |
{ |
| 1612 |
fprintf(stderr, "Can't read %s\n", |
| 1613 |
tFieldArray->fields[i].field_name); |
| 1614 |
GOTOFAILURE_ALL_EXIF |
| 1615 |
break; |
| 1616 |
} |
| 1617 |
if (tType == TIFF_RATIONAL || tType == TIFF_SRATIONAL) |
| 1618 |
{ |
| 1619 |
if (blnIsRational2Double) |
| 1620 |
{ |
| 1621 |
/* New interface allows also double precision for |
| 1622 |
* TIFF_RATIONAL */ |
| 1623 |
auxDouble = auxDblUnion.dbl; |
| 1624 |
} |
| 1625 |
else |
| 1626 |
{ |
| 1627 |
/* Old interface reads TIFF_RATIONAL defined as |
| 1628 |
* TIFF_SETGET_DOUBLE always as FLOAT */ |
| 1629 |
auxDouble = (double)auxDblUnion.flt1; |
| 1630 |
} |
| 1631 |
} |
| 1632 |
else |
| 1633 |
{ |
| 1634 |
auxDouble = auxDblUnion.dbl; |
| 1635 |
} |
| 1636 |
/* compare read values with written ones */ |
| 1637 |
if (tType == TIFF_RATIONAL || tType == TIFF_SRATIONAL) |
| 1638 |
dblDiffLimit = RATIONAL_EPS * auxDoubleArrayW[i]; |
| 1639 |
else |
| 1640 |
dblDiffLimit = 1e-6; |
| 1641 |
dblDiff = auxDouble - auxDoubleArrayW[i]; |
| 1642 |
if (fabs(dblDiff) > fabs(dblDiffLimit)) |
| 1643 |
{ |
| 1644 |
/*--: EXIFTAG_SUBJECTDISTANCE: LibTiff returns value of |
| 1645 |
* "-1.0" if numerator equals 4294967295 (0xFFFFFFFF) to |
| 1646 |
* indicate infinite distance! */ |
| 1647 |
if (!(tTag == EXIFTAG_SUBJECTDISTANCE && auxDouble == -1.0)) |
| 1648 |
{ |
| 1649 |
fprintf(stderr, |
| 1650 |
"%d:Read value of %s %f differs from set value " |
| 1651 |
"%f\n", |
| 1652 |
i, tFieldName, auxDouble, auxDoubleArrayW[i]); |
| 1653 |
GOTOFAILURE_ALL_EXIF |
| 1654 |
} |
| 1655 |
} |
| 1656 |
break; |
| 1657 |
|
| 1658 |
case TIFF_SETGET_C0_FLOAT: |
| 1659 |
case TIFF_SETGET_C0_DOUBLE: |
| 1660 |
case TIFF_SETGET_C16_FLOAT: |
| 1661 |
case TIFF_SETGET_C16_DOUBLE: |
| 1662 |
case TIFF_SETGET_C32_FLOAT: |
| 1663 |
case TIFF_SETGET_C32_DOUBLE: |
| 1664 |
/* _Cxx_ just defines the size of the count parameter for the |
| 1665 |
* array as C0=char, C16=short or C32=long */ |
| 1666 |
/*-- Check, if it is a single parameter, a fixed array or a |
| 1667 |
* variable array */ |
| 1668 |
if (tWriteCount == 1) |
| 1669 |
{ |
| 1670 |
fprintf(stderr, |
| 1671 |
"Reading: WriteCount for .set_field_type %d should " |
| 1672 |
"be -1 or greater than 1! %s\n", |
| 1673 |
tSetFieldType, tFieldArray->fields[i].field_name); |
| 1674 |
} |
| 1675 |
else |
| 1676 |
{ |
| 1677 |
/*-- Either fix or variable array --*/ |
| 1678 |
/* For arrays, distinguishing between float or double is |
| 1679 |
* essential. */ |
| 1680 |
/* Now decide between fixed or variable array */ |
| 1681 |
if (tWriteCount > 1) |
| 1682 |
{ |
| 1683 |
/* fixed array with needed arraysize defined in |
| 1684 |
* .field_writecount */ |
| 1685 |
if (!TIFFGetField(tif, tTag, &pVoidArray)) |
| 1686 |
{ |
| 1687 |
fprintf(stderr, "Can't read %s\n", |
| 1688 |
tFieldArray->fields[i].field_name); |
| 1689 |
GOTOFAILURE_ALL_EXIF |
| 1690 |
break; |
| 1691 |
} |
| 1692 |
/* set tWriteCount to number of read samples for next |
| 1693 |
* steps */ |
| 1694 |
auxInt32 = tWriteCount; |
| 1695 |
} |
| 1696 |
else |
| 1697 |
{ |
| 1698 |
/* Special treatment of variable array. */ |
| 1699 |
/* Dependent on Cxx, the count parameter is char, short |
| 1700 |
* or long. Therefore use unionInt32! */ |
| 1701 |
if (!TIFFGetField(tif, tTag, &unionInt32, &pVoidArray)) |
| 1702 |
{ |
| 1703 |
fprintf(stderr, "Can't read %s\n", |
| 1704 |
tFieldArray->fields[i].field_name); |
| 1705 |
GOTOFAILURE_ALL_EXIF |
| 1706 |
break; |
| 1707 |
} |
| 1708 |
/* set tWriteCount to number of read samples for next |
| 1709 |
* steps */ |
| 1710 |
auxInt32 = unionInt32.Short1; |
| 1711 |
} |
| 1712 |
/* Save values from temporary array */ |
| 1713 |
if (tSetFieldType == TIFF_SETGET_C0_FLOAT || |
| 1714 |
tSetFieldType == TIFF_SETGET_C16_FLOAT || |
| 1715 |
tSetFieldType == TIFF_SETGET_C32_FLOAT) |
| 1716 |
{ |
| 1717 |
memcpy(&auxFloatArray, pVoidArray, |
| 1718 |
(auxInt32 * sizeof(auxFloatArray[0]))); |
| 1719 |
/* compare read values with written ones */ |
| 1720 |
if (tType == TIFF_RATIONAL || tType == TIFF_SRATIONAL) |
| 1721 |
dblDiffLimit = RATIONAL_EPS * auxDoubleArrayW[i]; |
| 1722 |
else |
| 1723 |
dblDiffLimit = 1e-6; |
| 1724 |
for (j = 0; j < auxInt32; j++) |
| 1725 |
{ |
| 1726 |
dblDiff = auxFloatArray[j] - auxFloatArrayW[i + j]; |
| 1727 |
if (fabs(dblDiff) > fabs(dblDiffLimit)) |
| 1728 |
{ |
| 1729 |
/*if (auxFloatArray[j] != |
| 1730 |
* (float)auxFloatArrayW[i+j]) { */ |
| 1731 |
fprintf(stderr, |
| 1732 |
"Read value %d of %s #%d %f differs " |
| 1733 |
"from set value %f\n", |
| 1734 |
i, tFieldName, j, auxFloatArray[j], |
| 1735 |
auxFloatArrayW[i + j]); |
| 1736 |
GOTOFAILURE_ALL_EXIF |
| 1737 |
} |
| 1738 |
} |
| 1739 |
} |
| 1740 |
else |
| 1741 |
{ |
| 1742 |
memcpy(&auxDoubleArray, pVoidArray, |
| 1743 |
(auxInt32 * sizeof(auxDoubleArray[0]))); |
| 1744 |
/* compare read values with written ones */ |
| 1745 |
if (tType == TIFF_RATIONAL || tType == TIFF_SRATIONAL) |
| 1746 |
dblDiffLimit = RATIONAL_EPS * auxDoubleArrayW[i]; |
| 1747 |
else |
| 1748 |
dblDiffLimit = 1e-6; |
| 1749 |
for (j = 0; j < auxInt32; j++) |
| 1750 |
{ |
| 1751 |
dblDiff = |
| 1752 |
auxDoubleArray[j] - auxDoubleArrayW[i + j]; |
| 1753 |
if (fabs(dblDiff) > fabs(dblDiffLimit)) |
| 1754 |
{ |
| 1755 |
/*if (auxDoubleArray[j] != auxDoubleArrayW[i+j]) |
| 1756 |
* { */ |
| 1757 |
fprintf(stderr, |
| 1758 |
"Read value %d of %s #%d %f differs " |
| 1759 |
"from set value %f\n", |
| 1760 |
i, tFieldName, j, auxDoubleArray[j], |
| 1761 |
auxDoubleArrayW[i + j]); |
| 1762 |
GOTOFAILURE_ALL_EXIF |
| 1763 |
} |
| 1764 |
} |
| 1765 |
} |
| 1766 |
} |
| 1767 |
break; |
| 1768 |
case TIFF_SETGET_C0_UINT8: |
| 1769 |
case TIFF_SETGET_C0_SINT8: |
| 1770 |
case TIFF_SETGET_C16_UINT8: |
| 1771 |
case TIFF_SETGET_C16_SINT8: |
| 1772 |
case TIFF_SETGET_C32_UINT8: |
| 1773 |
case TIFF_SETGET_C32_SINT8: |
| 1774 |
/* For arrays, distinguishing between float or double is |
| 1775 |
* essential, even for writing */ |
| 1776 |
deferredSetField = true; |
| 1777 |
break; |
| 1778 |
case TIFF_SETGET_C0_UINT16: |
| 1779 |
case TIFF_SETGET_C0_SINT16: |
| 1780 |
case TIFF_SETGET_C16_UINT16: |
| 1781 |
case TIFF_SETGET_C16_SINT16: |
| 1782 |
case TIFF_SETGET_C32_UINT16: |
| 1783 |
case TIFF_SETGET_C32_SINT16: |
| 1784 |
deferredSetField = true; |
| 1785 |
break; |
| 1786 |
case TIFF_SETGET_C0_UINT32: |
| 1787 |
case TIFF_SETGET_C0_SINT32: |
| 1788 |
case TIFF_SETGET_C16_UINT32: |
| 1789 |
case TIFF_SETGET_C16_SINT32: |
| 1790 |
case TIFF_SETGET_C32_UINT32: |
| 1791 |
case TIFF_SETGET_C32_SINT32: |
| 1792 |
deferredSetField = true; |
| 1793 |
break; |
| 1794 |
default: |
| 1795 |
fprintf(stderr, |
| 1796 |
"SetFieldType %d not defined within writing switch for " |
| 1797 |
"%s.\n", |
| 1798 |
tSetFieldType, tFieldName); |
| 1799 |
GOTOFAILURE |
| 1800 |
}; /*-- switch() --*/ |
| 1801 |
|
| 1802 |
if (deferredSetField) |
| 1803 |
{ |
| 1804 |
/* _Cxx_ just defines the size of the count parameter for the array |
| 1805 |
* as C0=char, C16=short or C32=long */ |
| 1806 |
/*-- Check, if it is a single parameter, a fixed array or a variable |
| 1807 |
* array */ |
| 1808 |
if (tWriteCount == 1) |
| 1809 |
{ |
| 1810 |
fprintf(stderr, |
| 1811 |
"WriteCount for .set_field_type %d should be -1 or " |
| 1812 |
"greater than 1! %s\n", |
| 1813 |
tSetFieldType, tFieldArray->fields[i].field_name); |
| 1814 |
} |
| 1815 |
else |
| 1816 |
{ |
| 1817 |
/*-- Either fix or variable array --*/ |
| 1818 |
/* Now decide between fixed or variable array */ |
| 1819 |
if (tWriteCount > 1) |
| 1820 |
{ |
| 1821 |
/* fixed array with needed arraysize defined in |
| 1822 |
* .field_writecount */ |
| 1823 |
if (!TIFFGetField(tif, tTag, &pVoidArray)) |
| 1824 |
{ |
| 1825 |
fprintf(stderr, "Can't read %s\n", |
| 1826 |
tFieldArray->fields[i].field_name); |
| 1827 |
GOTOFAILURE_ALL_EXIF |
| 1828 |
break; |
| 1829 |
} |
| 1830 |
/* set tWriteCount to number of read samples for next steps |
| 1831 |
*/ |
| 1832 |
auxInt32 = tWriteCount; |
| 1833 |
} |
| 1834 |
else |
| 1835 |
{ |
| 1836 |
/* special treatment of variable array */ |
| 1837 |
/* for test, use always arraysize of VARIABLE_ARRAY_SIZE */ |
| 1838 |
if (!TIFFGetField(tif, tTag, &unionInt32, &pVoidArray)) |
| 1839 |
{ |
| 1840 |
fprintf(stderr, "Can't read %s\n", |
| 1841 |
tFieldArray->fields[i].field_name); |
| 1842 |
GOTOFAILURE_ALL_EXIF |
| 1843 |
break; |
| 1844 |
} |
| 1845 |
/* set tWriteCount to number of read samples for next steps |
| 1846 |
*/ |
| 1847 |
auxInt32 = unionInt32.Short1; |
| 1848 |
} |
| 1849 |
/* Save values from temporary array */ |
| 1850 |
if (tSetFieldType == TIFF_SETGET_C0_UINT8 || |
| 1851 |
tSetFieldType == TIFF_SETGET_C0_SINT8 || |
| 1852 |
tSetFieldType == TIFF_SETGET_C16_UINT8 || |
| 1853 |
tSetFieldType == TIFF_SETGET_C16_SINT8 || |
| 1854 |
tSetFieldType == TIFF_SETGET_C32_UINT8 || |
| 1855 |
tSetFieldType == TIFF_SETGET_C32_SINT8) |
| 1856 |
{ |
| 1857 |
memcpy(&auxCharArray, pVoidArray, |
| 1858 |
(auxInt32 * sizeof(auxCharArray[0]))); |
| 1859 |
/* Compare and check values */ |
| 1860 |
for (j = 0; j < auxInt32; j++) |
| 1861 |
{ |
| 1862 |
if (tTag == EXIFTAG_EXIFVERSION) |
| 1863 |
{ |
| 1864 |
/*-- Use exifVersion[] instead of auxCharArrayW[] |
| 1865 |
* for differently set EXIFVERSION tag */ |
| 1866 |
if (auxCharArray[j] != exifVersion[j]) |
| 1867 |
{ |
| 1868 |
fprintf(stderr, |
| 1869 |
"Read value %d of %s #%d %d differs " |
| 1870 |
"from set value %d\n", |
| 1871 |
i, tFieldName, j, auxCharArray[j], |
| 1872 |
auxCharArrayW[i + j]); |
| 1873 |
GOTOFAILURE_ALL_EXIF |
| 1874 |
} |
| 1875 |
} |
| 1876 |
else |
| 1877 |
{ |
| 1878 |
if (auxCharArray[j] != auxCharArrayW[i + j]) |
| 1879 |
{ |
| 1880 |
fprintf(stderr, |
| 1881 |
"Read value %d of %s #%d %d differs " |
| 1882 |
"from set value %d\n", |
| 1883 |
i, tFieldName, j, auxCharArray[j], |
| 1884 |
auxCharArrayW[i + j]); |
| 1885 |
GOTOFAILURE_ALL_EXIF |
| 1886 |
} |
| 1887 |
} |
| 1888 |
} |
| 1889 |
} |
| 1890 |
else if (tSetFieldType == TIFF_SETGET_C0_UINT16 || |
| 1891 |
tSetFieldType == TIFF_SETGET_C0_SINT16 || |
| 1892 |
tSetFieldType == TIFF_SETGET_C16_UINT16 || |
| 1893 |
tSetFieldType == TIFF_SETGET_C16_SINT16 || |
| 1894 |
tSetFieldType == TIFF_SETGET_C32_UINT16 || |
| 1895 |
tSetFieldType == TIFF_SETGET_C32_SINT16) |
| 1896 |
{ |
| 1897 |
memcpy(&auxShortArray, pVoidArray, |
| 1898 |
(auxInt32 * sizeof(auxShortArray[0]))); |
| 1899 |
/* Compare and check values */ |
| 1900 |
for (j = 0; j < auxInt32; j++) |
| 1901 |
{ |
| 1902 |
if (auxShortArray[j] != auxShortArrayW[i + j]) |
| 1903 |
{ |
| 1904 |
fprintf(stderr, |
| 1905 |
"Read value %d of %s #%d %d differs from " |
| 1906 |
"set value %d\n", |
| 1907 |
i, tFieldName, j, auxShortArray[j], |
| 1908 |
auxShortArrayW[i + j]); |
| 1909 |
GOTOFAILURE_ALL_EXIF |
| 1910 |
} |
| 1911 |
} |
| 1912 |
} |
| 1913 |
else if (tSetFieldType == TIFF_SETGET_C0_UINT32 || |
| 1914 |
tSetFieldType == TIFF_SETGET_C0_SINT32 || |
| 1915 |
tSetFieldType == TIFF_SETGET_C16_UINT32 || |
| 1916 |
tSetFieldType == TIFF_SETGET_C16_SINT32 || |
| 1917 |
tSetFieldType == TIFF_SETGET_C32_UINT32 || |
| 1918 |
tSetFieldType == TIFF_SETGET_C32_SINT32) |
| 1919 |
{ |
| 1920 |
memcpy(&auxInt32Array, pVoidArray, |
| 1921 |
(auxInt32 * sizeof(auxInt32Array[0]))); |
| 1922 |
/* Compare and check values */ |
| 1923 |
for (j = 0; j < auxInt32; j++) |
| 1924 |
{ |
| 1925 |
if (auxInt32Array[j] != auxInt32ArrayW[i + j]) |
| 1926 |
{ |
| 1927 |
fprintf(stderr, |
| 1928 |
"Read value %d of %s #%d %d differs from " |
| 1929 |
"set value %d\n", |
| 1930 |
i, tFieldName, j, auxInt32Array[j], |
| 1931 |
auxInt32ArrayW[i + j]); |
| 1932 |
GOTOFAILURE_ALL_EXIF |
| 1933 |
} |
| 1934 |
} |
| 1935 |
} |
| 1936 |
else |
| 1937 |
{ |
| 1938 |
fprintf(stderr, |
| 1939 |
"SetFieldType %d not defined within switch case " |
| 1940 |
"reading for UINT for %s.\n", |
| 1941 |
tSetFieldType, tFieldName); |
| 1942 |
GOTOFAILURE |
| 1943 |
} |
| 1944 |
} |
| 1945 |
} |
| 1946 |
} /*-- for() --*/ |
| 1947 |
/*================= EXIF: END Reading arbitrary data to the EXIF fields END |
| 1948 |
* END END ==============*/ |
| 1949 |
#endif /*-- READ_ALL_EXIF_TAGS --*/ |
| 1950 |
#endif /*-- READ_EXIF_TAGS --*/ |
| 1951 |
|
| 1952 |
TIFFClose(tif); |
| 1953 |
|
| 1954 |
/* All tests passed; delete file and exit with success status. */ |
| 1955 |
#ifdef FOR_AUTO_TESTING |
| 1956 |
unlink(filenameRead); |
| 1957 |
#endif |
| 1958 |
fprintf(stderr, "-------- Test finished OK ----------\n"); |
| 1959 |
return 0; |
| 1960 |
|
| 1961 |
failure: |
| 1962 |
/* |
| 1963 |
* Something goes wrong; close file and return unsuccessful status. |
| 1964 |
* Do not remove the file for further manual investigation. |
| 1965 |
*/ |
| 1966 |
TIFFClose(tif); |
| 1967 |
fprintf(stderr, "-------- Test finished with FAILURE --------\n"); |
| 1968 |
return 1; |
| 1969 |
} |