From a8193c438fa1b2cfb273fc5b5ffe8ce0262f677a Mon Sep 17 00:00:00 2001 From: Su_Laus Date: Mon, 2 Mar 2020 22:50:05 +0100 Subject: [PATCH] EXIF 2.32 and GPS tags and functionality upgraded. - Existing EXIF field definition of tags is upgraded to EXIF version 2.3.2 - EXIF-GPS structure, tags and access functions are added as special CustomDirectory (like it was done for EXIF). - Test program custom_dir_EXIF_231.c added to test writing/reading of EXID IFD and GPS IFD tags and to highlight some quirks of IFD-handling and peculiarities of reading/writing the different data types. - Reading error for FileSource and SceneType tags corrected. - EXIF_GPS_upgrade rebased onto c8c5309b765ef4ff097d2aaffbdb8f403db8967d (Merge branch 'Rational2DoublePrecision_correction' into 'master') and adapted: - tif_dirinfo.c: All rational tags set to TIFF_SETGET_FLOAT but only the GPSTAG_ tags set to TIFF_SETGET_DOUBLE. - custom_dir_EXIF_231.c: Editorials amended and gcc warnigs fixed. - CMakeLists.txt: add_test(NAME "custom_dir_EXIF_231" COMMAND "custom_dir_EXIF_231") added. --- libtiff/libtiff.def | 8 +- libtiff/tif_dir.c | 11 + libtiff/tif_dir.h | 2 + libtiff/tif_dirinfo.c | 95 ++- libtiff/tif_dirread.c | 11 + libtiff/tiff.h | 74 +- libtiff/tiffio.h | 2 + test/CMakeLists.txt | 5 + test/Makefile.am | 4 +- test/custom_dir_EXIF_231.c | 1398 ++++++++++++++++++++++++++++++++++++ 10 files changed, 1600 insertions(+), 10 deletions(-) create mode 100644 test/custom_dir_EXIF_231.c diff --git a/libtiff/libtiff.def b/libtiff/libtiff.def index e34fac58..b2d03fe7 100644 --- a/libtiff/libtiff.def +++ b/libtiff/libtiff.def @@ -12,6 +12,7 @@ EXPORTS TIFFAccessTagMethods TIFFCreateCustomDirectory TIFFCreateDirectory TIFFCreateEXIFDirectory + TIFFCreateGPSDirectory TIFFCurrentDirOffset TIFFCurrentDirectory TIFFCurrentRow @@ -86,6 +87,7 @@ EXPORTS TIFFAccessTagMethods TIFFReadCustomDirectory TIFFReadDirectory TIFFReadEXIFDirectory + TIFFReadGPSDirectory TIFFReadEncodedStrip TIFFReadEncodedTile TIFFReadFromUserBuffer @@ -171,5 +173,7 @@ EXPORTS TIFFAccessTagMethods _TIFFmemcpy _TIFFmemset _TIFFrealloc - _TIFFMultiply32 - _TIFFMultiply64 + _TIFFMultiply32 + _TIFFMultiply64 + _TIFFGetExifFields + _TIFFGetGpsFields diff --git a/libtiff/tif_dir.c b/libtiff/tif_dir.c index 47927a84..998b69aa 100644 --- a/libtiff/tif_dir.c +++ b/libtiff/tif_dir.c @@ -1403,6 +1403,17 @@ TIFFCreateEXIFDirectory(TIFF* tif) return TIFFCreateCustomDirectory(tif, exifFieldArray); } +/* + * Creates the EXIF GPS custom directory + */ +int +TIFFCreateGPSDirectory(TIFF* tif) +{ + const TIFFFieldArray* gpsFieldArray; + gpsFieldArray = _TIFFGetGpsFields(); + return TIFFCreateCustomDirectory(tif, gpsFieldArray); +} + /* * Setup a default directory structure. */ diff --git a/libtiff/tif_dir.h b/libtiff/tif_dir.h index e7f06673..f608dd71 100644 --- a/libtiff/tif_dir.h +++ b/libtiff/tif_dir.h @@ -261,6 +261,7 @@ extern "C" { extern const TIFFFieldArray* _TIFFGetFields(void); extern const TIFFFieldArray* _TIFFGetExifFields(void); +extern const TIFFFieldArray* _TIFFGetGpsFields(void); extern void _TIFFSetupFields(TIFF* tif, const TIFFFieldArray* infoarray); extern void _TIFFPrintFieldInfo(TIFF*, FILE*); @@ -269,6 +270,7 @@ extern int _TIFFFillStriles(TIFF*); typedef enum { tfiatImage, tfiatExif, + tfiatGps, /* EXIF-GPS fields array type */ tfiatOther } TIFFFieldArrayType; diff --git a/libtiff/tif_dirinfo.c b/libtiff/tif_dirinfo.c index 591e0658..99b0a3ea 100644 --- a/libtiff/tif_dirinfo.c +++ b/libtiff/tif_dirinfo.c @@ -47,6 +47,7 @@ #endif static const TIFFFieldArray tiffFieldArray; static const TIFFFieldArray exifFieldArray; +static const TIFFFieldArray gpsFieldArray; #ifdef _MSC_VER #pragma warning( pop ) #endif @@ -149,9 +150,13 @@ tiffFields[] = { /* end Pixar tags */ { TIFFTAG_RICHTIFFIPTC, -3, -3, TIFF_UNDEFINED, 0, TIFF_SETGET_C32_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "RichTIFFIPTC", NULL }, { TIFFTAG_PHOTOSHOP, -3, -3, TIFF_BYTE, 0, TIFF_SETGET_C32_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "Photoshop", NULL }, - { TIFFTAG_EXIFIFD, 1, 1, TIFF_IFD8, 0, TIFF_SETGET_IFD8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "EXIFIFDOffset", (TIFFFieldArray*) &exifFieldArray }, + /*--: EXIFIFD and GPSIFD specified as TIFF_LONG by Aware-Systems and not TIFF_IFD8 as in original LibTiff. + * However, for IFD-like tags, libtiff uses the data type TIFF_IFD8 in tiffFields[]-tag definition combined with + * a special handling procedure in order to write either a 32-bit value and the TIFF_IFD type-id into ClassicTIFF files + * or a 64-bit value and the TIFF_IFD8 type-id into BigTIFF files. */ + { TIFFTAG_EXIFIFD, 1, 1, TIFF_IFD8, 0, TIFF_SETGET_IFD8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "EXIFIFDOffset", (TIFFFieldArray*) &exifFieldArray }, { TIFFTAG_ICCPROFILE, -3, -3, TIFF_UNDEFINED, 0, TIFF_SETGET_C32_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "ICC Profile", NULL }, - { TIFFTAG_GPSIFD, 1, 1, TIFF_IFD8, 0, TIFF_SETGET_IFD8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "GPSIFDOffset", NULL }, + { TIFFTAG_GPSIFD, 1, 1, TIFF_IFD8, 0, TIFF_SETGET_IFD8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "GPSIFDOffset", (TIFFFieldArray*) &gpsFieldArray }, { TIFFTAG_FAXRECVPARAMS, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UINT32, FIELD_CUSTOM, TRUE, FALSE, "FaxRecvParams", NULL }, { TIFFTAG_FAXSUBADDRESS, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_ASCII, FIELD_CUSTOM, TRUE, FALSE, "FaxSubAddress", NULL }, { TIFFTAG_FAXRECVTIME, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UINT32, FIELD_CUSTOM, TRUE, FALSE, "FaxRecvTime", NULL }, @@ -226,6 +231,9 @@ tiffFields[] = { /* begin pseudo tags */ }; +/* + * EXIF tags (Version 2.31, July 2016 plus version 2.32 May 2019) + */ static const TIFFField exifFields[] = { { EXIFTAG_EXPOSURETIME, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ExposureTime", NULL }, @@ -234,9 +242,18 @@ exifFields[] = { { EXIFTAG_SPECTRALSENSITIVITY, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SpectralSensitivity", NULL }, { EXIFTAG_ISOSPEEDRATINGS, -1, -1, TIFF_SHORT, 0, TIFF_SETGET_C16_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "ISOSpeedRatings", NULL }, { EXIFTAG_OECF, -1, -1, TIFF_UNDEFINED, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "OptoelectricConversionFactor", NULL }, + { EXIFTAG_SENSITIVITYTYPE, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SensitivityType", NULL }, + { EXIFTAG_STANDARDOUTPUTSENSITIVITY, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "StandardOutputSensitivity", NULL }, + { EXIFTAG_RECOMMENDEDEXPOSUREINDEX, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "RecommendedExposureIndex", NULL }, + { EXIFTAG_ISOSPEED, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ISOSpeed", NULL }, + { EXIFTAG_ISOSPEEDLATITUDEYYY, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ISOSpeedLatitudeyyy", NULL }, + { EXIFTAG_ISOSPEEDLATITUDEZZZ, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ISOSpeedLatitudezzz", NULL }, { EXIFTAG_EXIFVERSION, 4, 4, TIFF_UNDEFINED, 0, TIFF_SETGET_C0_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ExifVersion", NULL }, { EXIFTAG_DATETIMEORIGINAL, 20, 20, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "DateTimeOriginal", NULL }, { EXIFTAG_DATETIMEDIGITIZED, 20, 20, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "DateTimeDigitized", NULL }, + { EXIFTAG_OFFSETTIME, 7, 7, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "OffsetTime", NULL }, + { EXIFTAG_OFFSETTIMEORIGINAL, 7, 7, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "OffsetTimeOriginal", NULL }, + { EXIFTAG_OFFSETTIMEDIGITIZED, 7, 7, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "OffsetTimeDigitized", NULL }, { EXIFTAG_COMPONENTSCONFIGURATION, 4, 4, TIFF_UNDEFINED, 0, TIFF_SETGET_C0_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ComponentsConfiguration", NULL }, { EXIFTAG_COMPRESSEDBITSPERPIXEL, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "CompressedBitsPerPixel", NULL }, { EXIFTAG_SHUTTERSPEEDVALUE, 1, 1, TIFF_SRATIONAL, 0, TIFF_SETGET_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ShutterSpeedValue", NULL }, @@ -244,6 +261,9 @@ exifFields[] = { { EXIFTAG_BRIGHTNESSVALUE, 1, 1, TIFF_SRATIONAL, 0, TIFF_SETGET_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "BrightnessValue", NULL }, { EXIFTAG_EXPOSUREBIASVALUE, 1, 1, TIFF_SRATIONAL, 0, TIFF_SETGET_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ExposureBiasValue", NULL }, { EXIFTAG_MAXAPERTUREVALUE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "MaxApertureValue", NULL }, + /*--: EXIFTAG_SUBJECTDISTANCE: LibTiff returns value of "-1" if numerator equals 4294967295 (0xFFFFFFFF) to indicate infinite distance! + * However, there are two other EXIF tags where numerator indicates a special value and six other cases where the denominator indicates special values, + * which are not treated within LibTiff!! */ { EXIFTAG_SUBJECTDISTANCE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SubjectDistance", NULL }, { EXIFTAG_METERINGMODE, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "MeteringMode", NULL }, { EXIFTAG_LIGHTSOURCE, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "LightSource", NULL }, @@ -255,6 +275,12 @@ exifFields[] = { { EXIFTAG_SUBSECTIME, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SubSecTime", NULL }, { EXIFTAG_SUBSECTIMEORIGINAL, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SubSecTimeOriginal", NULL }, { EXIFTAG_SUBSECTIMEDIGITIZED, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SubSecTimeDigitized", NULL }, + { EXIFTAG_TEMPERATURE, 1, 1, TIFF_SRATIONAL, 0, TIFF_SETGET_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Temperature", NULL }, + { EXIFTAG_HUMIDITY, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Humidity", NULL }, + { EXIFTAG_PRESSURE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Pressure", NULL }, + { EXIFTAG_WATERDEPTH, 1, 1, TIFF_SRATIONAL, 0, TIFF_SETGET_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "WaterDepth", NULL }, + { EXIFTAG_ACCELERATION, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Acceleration", NULL }, + { EXIFTAG_CAMERAELEVATIONANGLE, 1, 1, TIFF_SRATIONAL, 0, TIFF_SETGET_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "CameraElevationAngle", NULL }, { EXIFTAG_FLASHPIXVERSION, 4, 4, TIFF_UNDEFINED, 0, TIFF_SETGET_C0_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FlashpixVersion", NULL }, { EXIFTAG_COLORSPACE, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ColorSpace", NULL }, { EXIFTAG_PIXELXDIMENSION, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "PixelXDimension", NULL }, @@ -283,13 +309,70 @@ exifFields[] = { { EXIFTAG_SHARPNESS, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Sharpness", NULL }, { EXIFTAG_DEVICESETTINGDESCRIPTION, -1, -1, TIFF_UNDEFINED, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "DeviceSettingDescription", NULL }, { EXIFTAG_SUBJECTDISTANCERANGE, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SubjectDistanceRange", NULL }, - { EXIFTAG_IMAGEUNIQUEID, 33, 33, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ImageUniqueID", NULL } + { EXIFTAG_IMAGEUNIQUEID, 33, 33, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ImageUniqueID", NULL }, + { EXIFTAG_CAMERAOWNERNAME, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "CameraOwnerName", NULL }, + { EXIFTAG_BODYSERIALNUMBER, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "BodySerialNumber", NULL }, + { EXIFTAG_LENSSPECIFICATION, 4, 4, TIFF_RATIONAL, 0, TIFF_SETGET_C0_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "LensSpecification", NULL }, + { EXIFTAG_LENSMAKE, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "LensMake", NULL }, + { EXIFTAG_LENSMODEL, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "LensModel", NULL }, + { EXIFTAG_LENSSERIALNUMBER, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "LensSerialNumber", NULL }, + { EXIFTAG_GAMMA, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Gamma", NULL }, + { EXIFTAG_COMPOSITEIMAGE, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "CompositeImage", NULL }, + { EXIFTAG_SOURCEIMAGENUMBEROFCOMPOSITEIMAGE, 2, 2, TIFF_SHORT, 0, TIFF_SETGET_C0_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SourceImageNumberOfCompositeImage", NULL }, + { EXIFTAG_SOURCEEXPOSURETIMESOFCOMPOSITEIMAGE, -1, -1, TIFF_UNDEFINED, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "SourceExposureTimesOfCompositeImage", NULL } +}; +/* + * EXIF-GPS tags (Version 2.31, July 2016; nothing changed for version 2.32 May 2019) + */ + +static TIFFField +gpsFields[] = { + /* For the GPS tag definitions in gpsFields[] the standard definition for Rationals is TIFF_SETGET_DOUBLE and TIFF_SETGET_C0_FLOAT. + *-- ATTENTION: After the upgrade with Rational2Double, the GPSTAG values can now be written and also read in double precision! + * In order to achieve double precision for GPS tags: + * Standard definitions for GPSTAG is kept to TIFF_SETGET_DOUBLE + * and TIFF_SETGET_C0_FLOAT is changed to TIFF_SETGET_C0_DOUBLE. + */ + { GPSTAG_VERSIONID , 4, 4, TIFF_BYTE , 0, TIFF_SETGET_C0_UINT8 , TIFF_SETGET_UINT8 , FIELD_CUSTOM , 1, 0, "VersionID", NULL }, + { GPSTAG_LATITUDEREF , 2, 2, TIFF_ASCII , 0, TIFF_SETGET_ASCII , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 0, "LatitudeRef", NULL }, + { GPSTAG_LATITUDE , 3, 3, TIFF_RATIONAL , 0, TIFF_SETGET_C0_DOUBLE , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 0, "Latitude", NULL }, + { GPSTAG_LONGITUDEREF , 2, 2, TIFF_ASCII , 0, TIFF_SETGET_ASCII , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 0, "LongitudeRef", NULL }, + { GPSTAG_LONGITUDE , 3, 3, TIFF_RATIONAL , 0, TIFF_SETGET_C0_DOUBLE , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 0, "Longitude", NULL }, + { GPSTAG_ALTITUDEREF , 1, 1, TIFF_BYTE , 0, TIFF_SETGET_UINT8 , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 0, "AltitudeRef", NULL }, + { GPSTAG_ALTITUDE , 1, 1, TIFF_RATIONAL , 0, TIFF_SETGET_DOUBLE , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 0, "Altitude", NULL }, + { GPSTAG_TIMESTAMP , 3, 3, TIFF_RATIONAL , 0, TIFF_SETGET_C0_DOUBLE , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 0, "TimeStamp", NULL }, + { GPSTAG_SATELLITES , -1, -1, TIFF_ASCII , 0, TIFF_SETGET_ASCII , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 0, "Satellites", NULL }, + { GPSTAG_STATUS , 2, 2, TIFF_ASCII , 0, TIFF_SETGET_ASCII , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 0, "Status", NULL }, + { GPSTAG_MEASUREMODE , 2, 2, TIFF_ASCII , 0, TIFF_SETGET_ASCII , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 0, "MeasureMode", NULL }, + { GPSTAG_DOP , 1, 1, TIFF_RATIONAL , 0, TIFF_SETGET_DOUBLE , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 0, "DOP", NULL }, + { GPSTAG_SPEEDREF , 2, 2, TIFF_ASCII , 0, TIFF_SETGET_ASCII , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 0, "SpeedRef", NULL }, + { GPSTAG_SPEED , 1, 1, TIFF_RATIONAL , 0, TIFF_SETGET_DOUBLE , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 0, "Speed", NULL }, + { GPSTAG_TRACKREF , 2, 2, TIFF_ASCII , 0, TIFF_SETGET_ASCII , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 0, "TrackRef", NULL }, + { GPSTAG_TRACK , 1, 1, TIFF_RATIONAL , 0, TIFF_SETGET_DOUBLE , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 0, "Track", NULL }, + { GPSTAG_IMGDIRECTIONREF , 2, 2, TIFF_ASCII , 0, TIFF_SETGET_ASCII , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 0, "ImgDirectionRef", NULL }, + { GPSTAG_IMGDIRECTION , 1, 1, TIFF_RATIONAL , 0, TIFF_SETGET_DOUBLE , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 0, "ImgDirection", NULL }, + { GPSTAG_MAPDATUM , -1, -1, TIFF_ASCII , 0, TIFF_SETGET_ASCII , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 0, "MapDatum", NULL }, + { GPSTAG_DESTLATITUDEREF , 2, 2, TIFF_ASCII , 0, TIFF_SETGET_ASCII , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 0, "DestLatitudeRef", NULL }, + { GPSTAG_DESTLATITUDE , 3, 3, TIFF_RATIONAL , 0, TIFF_SETGET_C0_DOUBLE , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 0, "DestLatitude", NULL }, + { GPSTAG_DESTLONGITUDEREF , 2, 2, TIFF_ASCII , 0, TIFF_SETGET_ASCII , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 0, "DestLongitudeRef", NULL }, + { GPSTAG_DESTLONGITUDE , 3, 3, TIFF_RATIONAL , 0, TIFF_SETGET_C0_DOUBLE , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 0, "DestLongitude", NULL }, + { GPSTAG_DESTBEARINGREF , 2, 2, TIFF_ASCII , 0, TIFF_SETGET_ASCII , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 0, "DestBearingRef", NULL }, + { GPSTAG_DESTBEARING , 1, 1, TIFF_RATIONAL , 0, TIFF_SETGET_DOUBLE , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 0, "DestBearing", NULL }, + { GPSTAG_DESTDISTANCEREF , 2, 2, TIFF_ASCII , 0, TIFF_SETGET_ASCII , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 0, "DestDistanceRef", NULL }, + { GPSTAG_DESTDISTANCE , 1, 1, TIFF_RATIONAL , 0, TIFF_SETGET_DOUBLE , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 0, "DestDistance", NULL }, + { GPSTAG_PROCESSINGMETHOD , -1, -1, TIFF_UNDEFINED , 0, TIFF_SETGET_C16_UINT8 , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 1, "ProcessingMethod", NULL }, + { GPSTAG_AREAINFORMATION , -1, -1, TIFF_UNDEFINED , 0, TIFF_SETGET_C16_UINT8 , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 1, "AreaInformation", NULL }, + { GPSTAG_DATESTAMP , 11, 11, TIFF_ASCII , 0, TIFF_SETGET_ASCII , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 0, "DateStamp", NULL }, + { GPSTAG_DIFFERENTIAL , 1, 1, TIFF_SHORT , 0, TIFF_SETGET_UINT16 , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 0, "Differential", NULL }, + { GPSTAG_GPSHPOSITIONINGERROR , 1, 1, TIFF_RATIONAL , 0, TIFF_SETGET_DOUBLE , TIFF_SETGET_UNDEFINED , FIELD_CUSTOM , 1, 0, "HorizontalPositioningError", NULL } }; static const TIFFFieldArray tiffFieldArray = { tfiatImage, 0, TIFFArrayCount(tiffFields), (TIFFField*) tiffFields }; static const TIFFFieldArray exifFieldArray = { tfiatExif, 0, TIFFArrayCount(exifFields), (TIFFField*) exifFields }; +static const TIFFFieldArray +gpsFieldArray = { tfiatGps, 0, TIFFArrayCount(gpsFields), (TIFFField*) gpsFields }; /* * We have our own local lfind() equivalent to avoid subtle differences @@ -322,6 +405,12 @@ _TIFFGetExifFields(void) return(&exifFieldArray); } +const TIFFFieldArray* +_TIFFGetGpsFields(void) +{ + return(&gpsFieldArray); +} + void _TIFFSetupFields(TIFF* tif, const TIFFFieldArray* fieldarray) { diff --git a/libtiff/tif_dirread.c b/libtiff/tif_dirread.c index dee22576..43c51afe 100644 --- a/libtiff/tif_dirread.c +++ b/libtiff/tif_dirread.c @@ -4545,6 +4545,17 @@ TIFFReadEXIFDirectory(TIFF* tif, toff_t diroff) return TIFFReadCustomDirectory(tif, diroff, exifFieldArray); } +/* + *--: EXIF-GPS custom directory reading as another special case of custom IFD. + */ +int +TIFFReadGPSDirectory(TIFF* tif, toff_t diroff) +{ + const TIFFFieldArray* gpsFieldArray; + gpsFieldArray = _TIFFGetGpsFields(); + return TIFFReadCustomDirectory(tif, diroff, gpsFieldArray); +} + static int EstimateStripByteCounts(TIFF* tif, TIFFDirEntry* dir, uint16 dircount) { diff --git a/libtiff/tiff.h b/libtiff/tiff.h index 5b0a0c90..abd17e73 100644 --- a/libtiff/tiff.h +++ b/libtiff/tiff.h @@ -119,6 +119,11 @@ typedef struct { * Tag data type information. * * Note: RATIONALs are the ratio of two 32-bit integer values. + *--: + * Note2: TIFF_IFD8 data type is used in tiffFields[]-tag definition in order to distinguish the write-handling + of those tags between ClassicTIFF and BigTiff: + For ClassicTIFF libtiff writes a 32-bit value and the TIFF_IFD type-id into the file + For BigTIFF libtiff writes a 64-bit value and the TIFF_IFD8 type-id into the file */ typedef enum { TIFF_NOTYPE = 0, /* placeholder */ @@ -626,8 +631,8 @@ typedef enum { #define EXIFTAG_EXPOSUREPROGRAM 34850 /* Exposure program */ #define EXIFTAG_SPECTRALSENSITIVITY 34852 /* Spectral sensitivity */ #define EXIFTAG_ISOSPEEDRATINGS 34855 /* ISO speed rating */ -#define EXIFTAG_OECF 34856 /* Optoelectric conversion - factor */ +#define EXIFTAG_PHOTOGRAPHICSENSITIVITY 34855 /* Photographic Sensitivity (new name for tag 34855) */ +#define EXIFTAG_OECF 34856 /* Optoelectric conversion factor */ #define EXIFTAG_EXIFVERSION 36864 /* Exif version */ #define EXIFTAG_DATETIMEORIGINAL 36867 /* Date and time of original data generation */ @@ -679,10 +684,71 @@ typedef enum { #define EXIFTAG_SHARPNESS 41994 /* Sharpness */ #define EXIFTAG_DEVICESETTINGDESCRIPTION 41995 /* Device settings description */ #define EXIFTAG_SUBJECTDISTANCERANGE 41996 /* Subject distance range */ -#define EXIFTAG_GAINCONTROL 41991 /* Gain control */ -#define EXIFTAG_GAINCONTROL 41991 /* Gain control */ #define EXIFTAG_IMAGEUNIQUEID 42016 /* Unique image ID */ +/*--: New for EXIF-Version 2.32, May 2019 ... */ +#define EXIFTAG_SENSITIVITYTYPE 34864 /* The SensitivityType tag indicates which one of the parameters of ISO12232 is the PhotographicSensitivity tag. */ +#define EXIFTAG_STANDARDOUTPUTSENSITIVITY 34865 /* This tag indicates the standard output sensitivity value of a camera or input device defined in ISO 12232. */ +#define EXIFTAG_RECOMMENDEDEXPOSUREINDEX 34866 /* recommended exposure index */ +#define EXIFTAG_ISOSPEED 34867 /* ISO speed value */ +#define EXIFTAG_ISOSPEEDLATITUDEYYY 34868 /* ISO speed latitude yyy */ +#define EXIFTAG_ISOSPEEDLATITUDEZZZ 34869 /* ISO speed latitude zzz */ +#define EXIFTAG_OFFSETTIME 36880 /* offset from UTC of the time of DateTime tag. */ +#define EXIFTAG_OFFSETTIMEORIGINAL 36881 /* offset from UTC of the time of DateTimeOriginal tag. */ +#define EXIFTAG_OFFSETTIMEDIGITIZED 36882 /* offset from UTC of the time of DateTimeDigitized tag. */ +#define EXIFTAG_TEMPERATURE 37888 /* Temperature as the ambient situation at the shot in dergee Celsius */ +#define EXIFTAG_HUMIDITY 37889 /* Humidity as the ambient situation at the shot in percent */ +#define EXIFTAG_PRESSURE 37890 /* Pressure as the ambient situation at the shot hecto-Pascal (hPa) */ +#define EXIFTAG_WATERDEPTH 37891 /* WaterDepth as the ambient situation at the shot in meter (m) */ +#define EXIFTAG_ACCELERATION 37892 /* Acceleration (a scalar regardless of direction) as the ambient situation at the shot in units of mGal (10-5 m/s^2) */ +#define EXIFTAG_CAMERAELEVATIONANGLE 37893 /* Elevation/depression. angle of the orientation of the camera(imaging optical axis) as the ambient situation at the shot in degree(°) from -180° to +180°. */ +#define EXIFTAG_CAMERAOWNERNAME 42032 /* owner of a camera */ +#define EXIFTAG_BODYSERIALNUMBER 42033 /* serial number of the body of the camera */ +#define EXIFTAG_LENSSPECIFICATION 42034 /* minimum focal length (in mm), maximum focal length (in mm), minimum F number in the minimum focal length, and minimum F number in the maximum focal length, */ +#define EXIFTAG_LENSMAKE 42035 /* the lens manufacturer */ +#define EXIFTAG_LENSMODEL 42036 /* the lens’s model name and model number */ +#define EXIFTAG_LENSSERIALNUMBER 42037 /* the serial number of the interchangeable lens */ +#define EXIFTAG_GAMMA 42240 /* value of coefficient gamma */ +#define EXIFTAG_COMPOSITEIMAGE 42080 /* composite image */ +#define EXIFTAG_SOURCEIMAGENUMBEROFCOMPOSITEIMAGE 42081 /* source image number of composite image */ +#define EXIFTAG_SOURCEEXPOSURETIMESOFCOMPOSITEIMAGE 42082 /* source exposure times of composite image */ + +/* + * EXIF-GPS tags (Version 2.31, July 2016) + */ +#define GPSTAG_VERSIONID 0 /* Indicates the version of GPSInfoIFD. */ +#define GPSTAG_LATITUDEREF 1 /* Indicates whether the latitude is north or south latitude. */ +#define GPSTAG_LATITUDE 2 /* Indicates the latitude. */ +#define GPSTAG_LONGITUDEREF 3 /* Indicates whether the longitude is east or west longitude. */ +#define GPSTAG_LONGITUDE 4 /* Indicates the longitude. */ +#define GPSTAG_ALTITUDEREF 5 /* Indicates the altitude used as the reference altitude. */ +#define GPSTAG_ALTITUDE 6 /* Indicates the altitude based on the reference in GPSAltitudeRef. */ +#define GPSTAG_TIMESTAMP 7 /* Indicates the time as UTC (Coordinated Universal Time). */ +#define GPSTAG_SATELLITES 8 /* Indicates the GPS satellites used for measurements. */ +#define GPSTAG_STATUS 9 /* Indicates the status of the GPS receiver when the image is recorded. */ +#define GPSTAG_MEASUREMODE 10 /* Indicates the GPS measurement mode. */ +#define GPSTAG_DOP 11 /* Indicates the GPS DOP (data degree of precision). */ +#define GPSTAG_SPEEDREF 12 /* Indicates the unit used to express the GPS receiver speed of movement. */ +#define GPSTAG_SPEED 13 /* Indicates the speed of GPS receiver movement. */ +#define GPSTAG_TRACKREF 14 /* Indicates the reference for giving the direction of GPS receiver movement. */ +#define GPSTAG_TRACK 15 /* Indicates the direction of GPS receiver movement. */ +#define GPSTAG_IMGDIRECTIONREF 16 /* Indicates the reference for giving the direction of the image when it is captured. */ +#define GPSTAG_IMGDIRECTION 17 /* Indicates the direction of the image when it was captured. */ +#define GPSTAG_MAPDATUM 18 /* Indicates the geodetic survey data used by the GPS receiver. (e.g. WGS-84) */ +#define GPSTAG_DESTLATITUDEREF 19 /* Indicates whether the latitude of the destination point is north or south latitude. */ +#define GPSTAG_DESTLATITUDE 20 /* Indicates the latitude of the destination point. */ +#define GPSTAG_DESTLONGITUDEREF 21 /* Indicates whether the longitude of the destination point is east or west longitude. */ +#define GPSTAG_DESTLONGITUDE 22 /* Indicates the longitude of the destination point. */ +#define GPSTAG_DESTBEARINGREF 23 /* Indicates the reference used for giving the bearing to the destination point. */ +#define GPSTAG_DESTBEARING 24 /* Indicates the bearing to the destination point. */ +#define GPSTAG_DESTDISTANCEREF 25 /* Indicates the unit used to express the distance to the destination point. */ +#define GPSTAG_DESTDISTANCE 26 /* Indicates the distance to the destination point. */ +#define GPSTAG_PROCESSINGMETHOD 27 /* A character string recording the name of the method used for location finding. */ +#define GPSTAG_AREAINFORMATION 28 /* A character string recording the name of the GPS area. */ +#define GPSTAG_DATESTAMP 29 /* A character string recording date and time information relative to UTC (Coordinated Universal Time). */ +#define GPSTAG_DIFFERENTIAL 30 /* Indicates whether differential correction is applied to the GPS receiver. */ +#define GPSTAG_GPSHPOSITIONINGERROR 31 /* Indicates horizontal positioning errors in meters. */ + #endif /* _TIFF_ */ /* vim: set ts=8 sts=8 sw=8 noet: */ diff --git a/libtiff/tiffio.h b/libtiff/tiffio.h index 198481d5..221dfa5a 100644 --- a/libtiff/tiffio.h +++ b/libtiff/tiffio.h @@ -350,6 +350,7 @@ extern int TIFFVGetFieldDefaulted(TIFF* tif, uint32 tag, va_list ap); extern int TIFFReadDirectory(TIFF* tif); extern int TIFFReadCustomDirectory(TIFF* tif, toff_t diroff, const TIFFFieldArray* infoarray); extern int TIFFReadEXIFDirectory(TIFF* tif, toff_t diroff); +extern int TIFFReadGPSDirectory(TIFF* tif, toff_t diroff); extern uint64 TIFFScanlineSize64(TIFF* tif); extern tmsize_t TIFFScanlineSize(TIFF* tif); extern uint64 TIFFRasterScanlineSize64(TIFF* tif); @@ -400,6 +401,7 @@ extern void TIFFFreeDirectory(TIFF*); extern int TIFFCreateDirectory(TIFF*); extern int TIFFCreateCustomDirectory(TIFF*,const TIFFFieldArray*); extern int TIFFCreateEXIFDirectory(TIFF*); +extern int TIFFCreateGPSDirectory(TIFF*); extern int TIFFLastDirectory(TIFF*); extern int TIFFSetDirectory(TIFF*, uint16); extern int TIFFSetSubDirectory(TIFF*, uint64); diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 50904599..c3bfef3e 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -201,6 +201,11 @@ add_test(NAME "rational_precision2double" COMMAND "rational_precision2double") endif() +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") + add_executable(defer_strile_loading defer_strile_loading.c) target_link_libraries(defer_strile_loading tiff port) diff --git a/test/Makefile.am b/test/Makefile.am index c70ce05f..e2783b76 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -67,7 +67,7 @@ endif # Executable programs which need to be built in order to support tests check_PROGRAMS = \ - ascii_tag long_tag short_tag strip_rw rewrite custom_dir \ + 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) @@ -212,6 +212,8 @@ custom_dir_SOURCES = custom_dir.c custom_dir_LDADD = $(LIBTIFF) rational_precision2double_SOURCES = rational_precision2double.c rational_precision2double_LDADD = $(LIBTIFF) +custom_dir_EXIF_231_SOURCES = custom_dir_EXIF_231.c +custom_dir_EXIF_231_LDADD = $(LIBTIFF) defer_strile_loading_SOURCES = defer_strile_loading.c defer_strile_loading_LDADD = $(LIBTIFF) defer_strile_writing_SOURCES = defer_strile_writing.c diff --git a/test/custom_dir_EXIF_231.c b/test/custom_dir_EXIF_231.c new file mode 100644 index 00000000..854b19a9 --- /dev/null +++ b/test/custom_dir_EXIF_231.c @@ -0,0 +1,1398 @@ + +/* + * Copyright (c) 2012, Frank Warmerdam + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +/* + * TIFF Library + * + * -- Module copied from custom_dir.c -- + *=========== Purpose =================================================================================== + * Extended and amended version for testing of EXIF 2.32, GPS and handling of custom fields. + * EXIF 2.32 and GPS are defined in amended files tif_dirinfo.c, tif_dirread.c, tiff.h, tiffio.h, tif_dir.h, tif_dir.c + * + *-- ATTENTION: After the upgrade with Rational2Double, the GPSTAG values are defined as double precision + * and need to be written and also read in double precision! + * In order to maintain this code for both cases, it is checked above if the TiffLibrary is + * compiled with the new interface with Rational2Double or still uses the old definitions, + * by setting blnIsRational2Double above. + * + */ + + +/*------------ + * This version writes the GPS and EXIF tags correctly, without additonal main-IFD and parameters! + * In contrary, custom_dir.c does write additional main-IFD and parameters to file. + -------------*/ + + +#define FOR_AUTO_TESTING +#ifdef FOR_AUTO_TESTING +/* Only for automake and CMake infrastructure the test should: + a.) delete any written testfiles when test passed (otherwise autotest will fail) + b.) goto failure, if any failure is detected, which is not necessary when test is initiated manually for debugging +*/ +#define GOTOFAILURE goto failure; +#define GOTOFAILURE_GPS goto failure; +#define GOTOFAILURE_ALL_EXIF goto failure; +#else +#define GOTOFAILURE +#define GOTOFAILURE_GPS +#define GOTOFAILURE_ALL_EXIF +#endif + + +#ifdef _MSC_VER +#pragma warning( disable : 4101) +#endif + +#include "tif_config.h" +#include +#include +#include +#include + +#ifdef HAVE_UNISTD_H +# include +#endif + +#include "tiffio.h" +#include "tiffiop.h" +#include "tif_dir.h" +#include "tifftest.h" + + + +int write_test_tiff(TIFF *tif, const char *filenameRead); + +static const char filename[] = "custom_dir_EXIF_231.tif"; +static const char filenameBigTiff[] = "custom_dir_EXIF_231_Big.tif"; + +#define SPP 3 /* Samples per pixel */ +const uint16 width = 1; +const uint16 length = 1; +const uint16 bps = 8; +const uint16 photometric = PHOTOMETRIC_RGB; +const uint16 rows_per_strip = 1; +const uint16 planarconfig = PLANARCONFIG_CONTIG; + + +int +main() +{ + TIFF *tif; + int ret, ret1, ret2; + + fprintf(stderr, "==== Test automatically if all EXIF and GPS tags are written/read correctly. ====\n"); + /* --- Test with Classic-TIFF ---*/ + /* delete file, if exists */ + ret = unlink(filename); + if (ret != 0 && errno != ENOENT) { + fprintf(stderr, "Can't delete test TIFF file %s.\n", filename); + } + + /* We write the main directory as a simple image. */ + tif = TIFFOpen(filename, "w+"); + if (!tif) { + fprintf(stderr, "Can't create test TIFF file %s.\n", filename); + return 1; + } + fprintf(stderr, "-------- Test with ClassicTIFF started ----------\n"); + ret1 = write_test_tiff(tif, filename); + + if (ret1 > 0) return(ret1); + + /*--- Test with BIG-TIFF ---*/ + /* delete file, if exists */ + ret = unlink(filenameBigTiff); + if (ret != 0 && errno != ENOENT) { + fprintf(stderr, "Can't delete test TIFF file %s.\n", filenameBigTiff); + } + + tif = TIFFOpen(filenameBigTiff, "w8"); + if (!tif) { + fprintf(stderr, "Can't create test TIFF file %s.\n", filenameBigTiff); + return 1; + } + fprintf(stderr, "\n\n-------- Test with BigTIFF started ----------\n"); + ret2 = write_test_tiff(tif, filenameBigTiff); + + if (ret2 > 0) return(ret2 + 10); else return(ret2); + +} /* main() */ + + + + + + + +int +write_test_tiff(TIFF *tif, const char *filenameRead) +{ + unsigned char buf[SPP] = { 0, 127, 255 }; + uint64 dir_offset = 0; + uint64 dir_offset_GPS = 0, dir_offset_EXIF = 0; + uint64 read_dir_offset = 0; + /*-- Additional variables --*/ + int retCode, retCode2; + unsigned char exifVersion[4] = {'0','2','3','1'}; /* EXIF 2.31 version is 4 characters of a string! */ + unsigned char gpsVersion[4] = {2,2,0,1}; /* GPS Version is 4 numbers! */ + unsigned char *pGpsVersion; + float auxFloat = 0.0f; + double auxDouble = 0.0; + char auxChar = 0; + uint32 auxUint32 = 0; + short auxShort=0; + long auxLong = 0; + void *pVoid; + int blnIsRational2Double; + + int i, j; + long nTags; + + const TIFFFieldArray* tFieldArray; + unsigned long tTag; + TIFFDataType tType; + short tWriteCount; + TIFFSetGetFieldType tSetFieldType; + char *tFieldName; + const TIFFField *fip; + + char blnFillGPSManually = 1; + +#define STRSIZE 1000 +#define N_SIZE 120 +#define VARIABLE_ARRAY_SIZE 6 + + /* -- Test data for writing -- */ + char auxCharArrayW[N_SIZE]; + short auxShortArrayW[N_SIZE]; + long auxLongArrayW[N_SIZE]; + float auxFloatArrayW[N_SIZE]; + double auxDoubleArrayW[N_SIZE]; + char auxTextArrayW[N_SIZE][STRSIZE]; + double auxDoubleArrayGPS1[3] = {1.0/7.0, 61.23456789012345, 62.0}; + double auxDoubleArrayGPS2[3] = {1.0/19.0, 88.34434, 15.12345678901234567890}; + double auxDoubleArrayGPSTime[3] = {22.0, 17.0, 15.3456789}; + double auxDoubleGPSAltitude = 3456.0; + double auxDoubleGPSDirection = 63.7; + float auxFloatArrayN1[3] = { 1.0f / 7.0f, 61.23456789012345f, 62.3f }; + float auxFloatArrayN2[3] = { -1.0f / 7.0f, -61.23456789012345f, -62.3f }; + + /* -- Variables for reading -- */ + uint16 count16 = 0; + union { + long Long; + short Short1; + short Short2[2]; + char Char[4]; + } unionLong; + union { + double dbl; + float flt1; + float flt2; + } auxDblUnion; + void *pVoidArray; + char *pAscii; + char auxCharArray[2*STRSIZE]; + short auxShortArray[2*N_SIZE]; + long auxLongArray[2*N_SIZE]; + float auxFloatArray[2*N_SIZE]; + double auxDoubleArray[2*N_SIZE]; + double dblDiff, dblDiffLimit; +#define RATIONAL_EPS (1.0/30000.0) /* reduced difference of rational values, approx 3.3e-5 */ + + /*-- Fill test data arrays for writing ----------- */ + for (i=0; iset_field_type; + if (tSetFieldType == TIFF_SETGET_DOUBLE) { + blnIsRational2Double = FALSE; + } else { + blnIsRational2Double = TRUE; + fprintf(stderr, "-- Rational2Double from TIFF tag detected --\n"); + } + +/*================== Write GPS and EXIF tags =====================*/ + + /*-- Set dummy EXIF/GPS tag in original tiff-structure in order to reserve space for final dir_offset value, */ + /* which is properly written at the end. */ + dir_offset = 0; /* Zero, in case no Custom-IFD is written */ + +#define WRITE_GPS_TAGS +#ifdef WRITE_GPS_TAGS + if (!TIFFSetField(tif, TIFFTAG_GPSIFD, dir_offset )) { + fprintf (stderr, "Can't write TIFFTAG_GPSIFD\n" ); + } +#endif + + /*------- And also do the same for the EXIF IFD tag here, because we have to save the main directory next ------*/ + /*-- Set dummy EXIF/GPS tag in original tiff-structure in order to reserve space for final dir_offset value, + * which is properly written at the end. + */ +#define WRITE_EXIF_TAGS +#ifdef WRITE_EXIF_TAGS + if (!TIFFSetField(tif, TIFFTAG_EXIFIFD, dir_offset )) { + fprintf (stderr, "Can't write TIFFTAG_EXIFIFD\n" ); + } +#endif + +#ifndef WRITEPIXELLAST + /*-- Write dummy pixel data. --*/ + if (TIFFWriteScanline(tif, buf, 0, 0) < 0) { + fprintf (stderr, "Can't write image data.\n"); + goto failure; + } +#endif + + +#ifdef WRITE_GPS_TAGS +#define READ_GPS_TAGS + /*================== Write GPS tags =====================*/ + + /*-- Save current tiff-directory to file before directory is changed. Otherwise it will be lost! */ + /* The tif-structure is overwritten/ freshly initialized by any "CreateDirectory" */ + /*retCode = TIFFCheckpointDirectory(tif);*/ /* does not cleanup Tiff-Structure */ + retCode = TIFFWriteDirectory(tif); /* cleanup Tiff-structure */ + + /*-- Now create a GPS directory. */ + if (TIFFCreateGPSDirectory(tif) != 0) { + fprintf (stderr, "TIFFCreateGPSDirectory() failed.\n" ); + goto failure; + } + + if (!TIFFSetField( tif, GPSTAG_VERSIONID, gpsVersion)) { + fprintf (stderr, "Can't write GPSTAG_VERSIONID\n" ); + goto failure; + } + + if (blnFillGPSManually) { + /*================= Write manually valid data to the GPS fields ==============*/ + if (!TIFFSetField( tif, GPSTAG_LATITUDEREF, "N\0")) { + fprintf (stderr, "Can't write GPSTAG_LATITUDEREF\n" ); + goto failure; + } + /*-- Unfortunately, Rational values are defined as SETGET_DOUBLE but are internally always stored as float. + * Single Rational values do not matter for writing, because TIFFSetField() uses va_arg() which performs "variables promotion" from type float to type double! + * However, for reading of Rational values ONLY float-variables are allowed - in contrary to the SETGET_DOUBLE specification at tiffFields[] in tif_dirinfo.c. + */ + /*-- ATTENTION: After the upgrade with Rational2Double, the GPSTAG values are defined as double precision + * and need to be written and also read in double precision! + * In order to maintain this code for both cases, it is checked above if the TiffLibrary is + * compiled with the new interface with Rational2Double or still uses the old definitions, + * by setting blnIsRational2Double above. + */ + if (blnIsRational2Double) { + fprintf(stderr, "-- GPS tags are written using Rational2Double --\n"); + } else { + fprintf(stderr, "-- GPS tags are written using standard --\n"); + } + if (!blnIsRational2Double) { + for (j = 0; j < 3; j++) auxFloatArray[j] = (float)auxDoubleArrayGPS1[j]; + if (!TIFFSetField(tif, GPSTAG_LATITUDE, auxFloatArray)) { + fprintf(stderr, "Can't write GPSTAG_LATITUDE\n"); + goto failure; + } + } else { + /* Rational2Double interface for GPSTAG */ + if (!TIFFSetField(tif, GPSTAG_LATITUDE, auxDoubleArrayGPS1)) { + fprintf(stderr, "Can't write GPSTAG_LATITUDE\n"); + goto failure; + } + } + if (!TIFFSetField( tif, GPSTAG_LONGITUDEREF, "W\0")) { + fprintf (stderr, "Can't write GPSTAG_LONGITUDEREF\n" ); + goto failure; + } + if (!blnIsRational2Double) { + for (j=0; j<3; j++) auxFloatArray[j] = (float)auxDoubleArrayGPS2[j]; + if (!TIFFSetField( tif, GPSTAG_LONGITUDE, auxFloatArray)) { + fprintf (stderr, "Can't write GPSTAG_LONGITUDE\n" ); + goto failure; + } + } else { + /* Rational2Double interface for GPSTAG */ + if (!TIFFSetField(tif, GPSTAG_LONGITUDE, auxDoubleArrayGPS2)) { + fprintf(stderr, "Can't write GPSTAG_LATITUDE\n"); + goto failure; + } + } + /*-- AltitudeRef: default is above sea level!! */ + if (!TIFFSetField( tif, GPSTAG_ALTITUDEREF, 0)) { + fprintf (stderr, "Can't write GPSTAG_ALTITUDEREF\n" ); + goto failure; + } + if (!TIFFSetField( tif, GPSTAG_ALTITUDE, auxDoubleGPSAltitude)) { + fprintf (stderr, "Can't write GPSTAG_ALTITUDE\n" ); + goto failure; + } + /*-- TimeStamp is only hh:mm:ss. See also DateTime string */ + if (!TIFFSetField( tif, GPSTAG_TIMESTAMP, auxDoubleArrayGPSTime)) { + fprintf (stderr, "Can't write GPSTAG_TIMESTAMP\n" ); + goto failure; + } + if (!TIFFSetField( tif, GPSTAG_DATESTAMP, "2012:11:04")) { + fprintf (stderr, "Can't write GPSTAG_DATESTAMP\n" ); + goto failure; + } + + if (!TIFFSetField( tif, GPSTAG_IMGDIRECTIONREF, "T\0")) { + fprintf (stderr, "Can't write GPSTAG_IMGDIRECTIONREF\n" ); + goto failure; + } + if (!TIFFSetField( tif, GPSTAG_IMGDIRECTION, auxDoubleGPSDirection)) { + fprintf (stderr, "Can't write GPSTAG_IMGDIRECTION\n" ); + goto failure; + } + + /*-- Type TIFF_UNDEFINED */ + if (!TIFFSetField( tif, GPSTAG_PROCESSINGMETHOD, 3, &auxCharArrayW[10])) { + fprintf (stderr, "Can't write GPSTAG_PROCESSINGMETHOD\n" ); + goto failure; + } + if (!TIFFSetField( tif, GPSTAG_AREAINFORMATION, 4, &auxCharArrayW[20])) { + fprintf (stderr, "Can't write GPSTAG_AREAINFORMATION\n" ); + goto failure; + } + + /*-- PSTAG_DIFFERENTIAL , 1, 1, TIFF_SHORT , 0, TIFF_SETGET_UINT16 */ + if (!TIFFSetField( tif, GPSTAG_DIFFERENTIAL, auxShortArrayW[5])) { + fprintf (stderr, "Can't write GPSTAG_DIFFERENTIAL\n" ); + goto failure; + } + + /* GPSTAG_GPSHPOSITIONINGERROR , 1, 1, TIFF_RATIONAL , 0, TIFF_SETGET_DOUBLE but here written in float-precision */ +#define GPSHPOSITIONINGERROR_VAL 0.369 + auxFloat = (float)GPSHPOSITIONINGERROR_VAL; + if (!TIFFSetField( tif, GPSTAG_GPSHPOSITIONINGERROR, auxFloat)) { + fprintf (stderr, "Can't write GPSTAG_GPSHPOSITIONINGERROR\n" ); + goto failure; + } + + } else { + /*================= Write arbitrary data to the GPS fields ==============*/ + + /*-- Get array, where GPS tag fields are defined --*/ + tFieldArray = _TIFFGetGpsFields(); + nTags = tFieldArray->count; + + /*-- TODO: fill in the for / switch part of EXIF writing, when finished and tested!! */ + + } /*-- if (blnFillGPSManually) --*/ + + + + + /*-- GPS - write custom directory GPS into file...---*/ + /* (Get back the offset of GPS directory) */ + if (!TIFFWriteCustomDirectory( tif, &dir_offset_GPS )) { + fprintf (stderr, "TIFFWriteCustomDirectory() with GPS failed.\n"); + goto failure; + } + + /*--- CheckpointDirectory at this place generates a second Main-IFD!!! */ + /* retCode = TIFFCheckpointDirectory(tif); */ + + /*-- Set / reload previously saved main directory from file ---*/ + if (!TIFFSetDirectory(tif, 0)) { + fprintf (stderr, "TIFFSetDirectory() within GPS failed.\n"); + goto failure; + } + + /*-- Write GPS tag reference / offset into GPSIFD tag in main directory --*/ + if (!TIFFSetField(tif, TIFFTAG_GPSIFD, dir_offset_GPS )) { + fprintf (stderr, "Can't write TIFFTAG_GPSIFD\n"); + goto failure; + } + + /*=============== END writing GPS tags ==========================*/ +#endif /*-- WRITE_GPS_TAGS --*/ + + +/*================== Write EXIF 2.31 tags =====================*/ + + /*-- Set dummy EXIF/GPS tag in original tiff-structure in order to reserve space for final dir_offset value, */ + /* which is properly written at the end.*/ + /*- We did this already above together with the GPS IFD-tag. Otherwise we would do this here !! --------*/ + /* if (!TIFFSetField(tif, TIFFTAG_EXIFIFD, dir_offset )) { + fprintf (stderr, "Can't write TIFFTAG_EXIFIFD\n" ); + } + */ + +#ifdef WRITE_EXIF_TAGS +#define READ_EXIF_TAGS + /*-- Save current tiff-directory to file before directory is changed. Otherwise it will be lost! + * The tif-structure is overwritten/ freshly initialized by any "CreateDirectory" + */ + + /*----- What is needed here ??? ---- + * In custom_dir.c only TIFFFreeDirectory( tif ); is used to set fields of another Sub-Directory + * TIFFFreeDirectory(tif); *-- Release storage associated with a directory, especially custom-fields. + *-- Using only TIFFFreeDirectory() here leads to an error!! + *-- Using here TIFFCheckpointDirectory() leads to an additional Main-IFD ?? + */ + /*retCode = TIFFCheckpointDirectory(tif);*/ /* does not cleanup Tiff-Structure */ + retCode = TIFFWriteDirectory(tif); /* cleanup Tiff-structure */ + + /*-- Now create an EXIF directory. */ + if (TIFFCreateEXIFDirectory(tif) != 0) { + fprintf (stderr, "TIFFCreateEXIFDirectory() failed.\n" ); + goto failure; + } + +#define WRITE_ALL_EXIF_TAGS +#ifdef WRITE_ALL_EXIF_TAGS +#define READ_ALL_EXIF_TAGS + /*================= EXIF: Write arbitrary data to the EXIF fields ==============*/ + /*-- Get array, where EXIF tag fields are defined + * EXIF tags are written automatically with the defined precision according to its tSetFieldType using the code below --*/ + tFieldArray = _TIFFGetExifFields(); + nTags = tFieldArray->count; + + for (i=0; ifields[i].field_tag; + tType = tFieldArray->fields[i].field_type; /* e.g. TIFF_RATIONAL */ + tWriteCount = tFieldArray->fields[i].field_writecount; + tSetFieldType = tFieldArray->fields[i].set_field_type; /* e.g. TIFF_SETGET_C0_FLOAT */ + tFieldName = tFieldArray->fields[i].field_name; + pVoid = NULL; + + /*-- dependent on set_field_type write value --*/ + switch (tSetFieldType) + { + case TIFF_SETGET_ASCII: + /* Either the stringlength is defined as a fixed length in .field_writecount or a NULL-terminated string is used. */ + /* Shorter strings than in auxTextArraxW need a NULL-termination. Therefore copy the string. */ + if (tWriteCount > 0) auxLong = tWriteCount-1; else auxLong = (long)strlen(auxTextArrayW[i])-1; + strncpy(auxCharArray, auxTextArrayW[i], auxLong); + auxCharArray[auxLong] = 0; + if (!TIFFSetField( tif, tTag, auxCharArray)) { + fprintf (stderr, "Can't write %s\n", tFieldArray->fields[i].field_name); + goto failure; + } + break; + case TIFF_SETGET_UINT8: + case TIFF_SETGET_UINT16: + case TIFF_SETGET_UINT32: + case TIFF_SETGET_IFD8: + case TIFF_SETGET_INT: + /*-- All those can be written with char, short or long parameter. Only value range should be in line. */ + if (!TIFFSetField( tif, tTag, auxLongArrayW[i])) { + fprintf (stderr, "Can't write %s\n", tFieldArray->fields[i].field_name); + goto failure; + } + break; + case TIFF_SETGET_SINT8: + case TIFF_SETGET_SINT16: + case TIFF_SETGET_SINT32: + /*-- All those can be written with char, short or long parameter. Only value range should be in line. */ + if (!TIFFSetField( tif, tTag, -1.0*auxLongArrayW[i])) { + fprintf (stderr, "Can't write %s\n", tFieldArray->fields[i].field_name); + goto failure; + } + break; + case TIFF_SETGET_FLOAT: + case TIFF_SETGET_DOUBLE: + if (tWriteCount == 1) { + /*-- All single values can be written with float or double parameter. Only value range should be in line. */ + if (!TIFFSetField( tif, tTag, auxDoubleArrayW[i])) { + fprintf (stderr, "Can't write %s\n", tFieldArray->fields[i].field_name); + goto failure; + } + } else { + fprintf (stderr, "WriteCount for .set_field_type %d should be 1! %s\n", tSetFieldType, tFieldArray->fields[i].field_name); + } + break; + case TIFF_SETGET_C0_FLOAT: + case TIFF_SETGET_C0_DOUBLE: + case TIFF_SETGET_C16_FLOAT: + case TIFF_SETGET_C16_DOUBLE: + case TIFF_SETGET_C32_FLOAT: + case TIFF_SETGET_C32_DOUBLE: + /* _Cxx_ just defines the size of the count parameter for the array as C0=char, C16=short or C32=long */ + /*-- Check, if it is a single parameter, a fixed array or a variable array */ + if (tWriteCount == 1) { + fprintf (stderr, "WriteCount for .set_field_type %d should be -1 or greather than 1! %s\n", tSetFieldType, tFieldArray->fields[i].field_name); + } else { + /*-- Either fix or variable array --*/ + /* For arrays, distinguishing between float or double is essential, even for writing */ + if (tSetFieldType == TIFF_SETGET_C0_FLOAT || tSetFieldType == TIFF_SETGET_C16_FLOAT || tSetFieldType == TIFF_SETGET_C32_FLOAT) + pVoid = &auxFloatArrayW[i]; else pVoid = &auxDoubleArrayW[i]; + /* Now decide between fixed or variable array */ + if (tWriteCount > 1) { + /* fixed array with needed arraysize defined in .field_writecount */ + if (!TIFFSetField( tif, tTag, pVoid)) { + fprintf (stderr, "Can't write %s\n", tFieldArray->fields[i].field_name); + goto failure; + } + } else { + /* special treatment of variable array */ + /* for test, use always arraysize of VARIABLE_ARRAY_SIZE */ + if (!TIFFSetField( tif, tTag, VARIABLE_ARRAY_SIZE, pVoid)) { + fprintf (stderr, "Can't write %s\n", tFieldArray->fields[i].field_name); + goto failure; + } + } + } + break; + case TIFF_SETGET_C0_UINT8: + case TIFF_SETGET_C0_SINT8: + case TIFF_SETGET_C16_UINT8: + case TIFF_SETGET_C16_SINT8: + case TIFF_SETGET_C32_UINT8: + case TIFF_SETGET_C32_SINT8: + /* For arrays, distinguishing between float or double is essential, even for writing */ + pVoid = &auxCharArrayW[i]; + case TIFF_SETGET_C0_UINT16: + case TIFF_SETGET_C0_SINT16: + case TIFF_SETGET_C16_UINT16: + case TIFF_SETGET_C16_SINT16: + case TIFF_SETGET_C32_UINT16: + case TIFF_SETGET_C32_SINT16: + if (pVoid == NULL) pVoid = &auxShortArrayW[i]; + case TIFF_SETGET_C0_UINT32: + case TIFF_SETGET_C0_SINT32: + case TIFF_SETGET_C16_UINT32: + case TIFF_SETGET_C16_SINT32: + case TIFF_SETGET_C32_UINT32: + case TIFF_SETGET_C32_SINT32: + if (pVoid == NULL) pVoid = &auxLongArrayW[i]; + /* _Cxx_ just defines the size of the count parameter for the array as C0=char, C16=short or C32=long */ + /*-- Check, if it is a single parameter, a fixed array or a variable array */ + if (tWriteCount == 1) { + fprintf (stderr, "WriteCount for .set_field_type %d should be -1 or greather than 1! %s\n", tSetFieldType, tFieldArray->fields[i].field_name); + } else { + /*-- Either fix or variable array --*/ + /* Now decide between fixed or variable array */ + if (tWriteCount > 1) { + /* fixed array with needed arraysize defined in .field_writecount */ + if (!TIFFSetField( tif, tTag, pVoid)) { + fprintf (stderr, "Can't write %s\n", tFieldArray->fields[i].field_name); + goto failure; + } + } else { + /* special treatment of variable array */ + /* for test, use always arraysize of VARIABLE_ARRAY_SIZE */ + if (!TIFFSetField( tif, tTag, VARIABLE_ARRAY_SIZE, pVoid)) { + fprintf (stderr, "Can't write %s\n", tFieldArray->fields[i].field_name); + goto failure; + } + } + } + break; + default: + fprintf (stderr, "SetFieldType %d not defined within writing switch for %s.\n", tSetFieldType, tFieldName); + }; /*-- switch() --*/ + } /*-- for() --*/ + /*================= EXIF: END Writing arbitrary data to the EXIF fields END END END ==============*/ +#endif /*-- WRITE_ALL_EXIF_TAGS --*/ + + /*--- Set valid EXIF version, which is a 4 byte string --*/ + if (!TIFFSetField( tif, EXIFTAG_EXIFVERSION, exifVersion)) { + fprintf (stderr, "Can't write EXIFTAG_EXIFVERSION\n" ); + goto failure; + } + + + /*-- EXIF - write custom directory EXIF into file...---*/ + /* (Get back the offset of EXIF directory) */ + if (!TIFFWriteCustomDirectory( tif, &dir_offset_EXIF )) { + fprintf (stderr, "TIFFWriteCustomDirectory() with EXIF failed.\n"); + goto failure; + } + + /*-- Go back to the first (main) directory, and set correct value of the EXIFIFD pointer. */ + /* (directory is reloaded from file!) */ + TIFFSetDirectory(tif, 0); + TIFFSetField(tif, TIFFTAG_EXIFIFD, dir_offset_EXIF ); +#endif /*-- WRITE_EXIF_TAGS --*/ + +#ifdef WRITEPIXELLAST + /*-- Write dummy pixel data. --*/ + if (TIFFWriteScanline(tif, buf, 0, 0) < 0) { + fprintf (stderr, "Can't write image data.\n"); + goto failure; + } +#endif + /*-- Write directory to file --*/ + /* Always WriteDirectory before using/creating another directory. */ + /* Not necessary before TIFFClose(), however, TIFFClose() uses TIFFReWriteDirectory(), which forces directory to be written at another location. */ + retCode = TIFFWriteDirectory(tif); + + /*-- Write File to disk and close file --*/ + /* TIFFClose() uses TIFFReWriteDirectory(), which forces directory to be written at another location. */ + /* Therefore, better use TIFFWriteDirectory() before. */ + TIFFClose(tif); + + fprintf (stderr, "-------- Continue Test ---------- reading ...\n"); + +/*========================= READING ============= READING ========================================*/ + /* Ok, now test whether we can read written values correctly. */ + tif = TIFFOpen(filenameRead, "r"); + + + /*-- Read some parameters out of the main directory --*/ + + /*-- IMAGEWIDTH and -LENGTH are defined as TIFF_SETGET_UINT32 */ + retCode = TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &auxUint32 ); + if (!retCode) { fprintf(stderr, "Can't read %s\n", "TIFFTAG_IMAGEWIDTH"); } + if (auxUint32 != width) { + fprintf (stderr, "Read value of IMAGEWIDTH %d differs from set value %d\n", auxUint32, width); + } + retCode = TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &auxUint32 ); + if (!retCode) { fprintf(stderr, "Can't read %s\n", "TIFFTAG_IMAGELENGTH"); } + if (auxUint32 != width) { + fprintf (stderr, "Read value of TIFFTAG_IMAGELENGTH %d differs from set value %d\n", auxUint32, length); + } + +#ifdef ADDITIONAL_TAGS + /*- TIFFTAG_PIXAR_FOVCOT is a FLOAT parameter of type FIELD_CUSTOM !! */ + retCode = TIFFGetField(tif, TIFFTAG_PIXAR_FOVCOT, &auxFloat ); + if (!retCode) { fprintf(stderr, "Can't read %s\n", "TIFFTAG_PIXAR_FOVCOT"); } + if (auxFloat != (float)PIXAR_FOVCOT_VAL) { + fprintf (stderr, "Read value of TIFFTAG_PIXAR_FOVCOT %f differs from set value %f\n", auxFloat, PIXAR_FOVCOT_VAL); + } + + /* - TIFFTAG_BESTQUALITYSCALE is a Rational parameter, FIELD_CUSTOM and TIFF_SETGET_FLOAT */ + retCode = TIFFGetField(tif, TIFFTAG_BESTQUALITYSCALE, &auxFloat ); + if (!retCode) { fprintf(stderr, "Can't read %s\n", "TIFFTAG_BESTQUALITYSCALE"); } + if (auxFloat != (float)BESTQUALITYSCALE_VAL) { + fprintf (stderr, "Read value of TIFFTAG_BESTQUALITYSCALE %f differs from set value %f\n", auxFloat, BESTQUALITYSCALE_VAL); + } + + /* - TIFFTAG_BASELINENOISE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT */ + retCode = TIFFGetField(tif, TIFFTAG_BASELINENOISE, &auxDblUnion.dbl); + if (!retCode) { fprintf(stderr, "Can't read %s\n", "TIFFTAG_BASELINENOISE"); } + if (auxDblUnion.flt1 != (float)BESTQUALITYSCALE_VAL) { + fprintf(stderr, "Read float value of TIFFTAG_BASELINENOISE %f differs from set value %f\n", auxDblUnion.flt1, BESTQUALITYSCALE_VAL); + } + + + /*- Variable Array: TIFFTAG_DECODE is a SRATIONAL parameter TIFF_SETGET_C16_FLOAT type FIELD_CUSTOM with passcount=1 and variable length of array. */ + retCode = TIFFGetField(tif, TIFFTAG_DECODE, &count16, &pVoidArray ); + if (!retCode) { fprintf(stderr, "Can't read %s\n", "TIFFTAG_DECODE"); } + /*- pVoidArray points to a Tiff-internal temporary memorypart. Thus, contents needs to be saved. */ + memcpy(&auxFloatArray, pVoidArray,(count16 * sizeof(auxFloatArray[0]))); + for (i=0; i fabs(dblDiffLimit)) { + fprintf (stderr, "Read value %d of TIFFTAG_DECODE Array %f differs from set value %f\n", i, auxFloatArray[i], auxFloatArrayN2[i]); + } + } + + retCode = TIFFGetField(tif, TIFFTAG_BLACKLEVEL, &count16, &pVoidArray); + if (!retCode) { fprintf(stderr, "Can't read %s\n", "TIFFTAG_BLACKLEVEL"); } + /*- pVoidArray points to a Tiff-internal temporary memorypart. Thus, contents needs to be saved. */ + memcpy(&auxFloatArray, pVoidArray, (count16 * sizeof(auxFloatArray[0]))); + for (i = 0; i fabs(dblDiffLimit)) { + fprintf(stderr, "Read value %d of TIFFTAG_BLACKLEVEL Array %f differs from set value %f\n", i, auxFloatArray[i], auxFloatArrayN1[i]); + } + } + + /*- Fixed Array: TIFFTAG_DEFAULTCROPSIZE, 2, 2, TIFF_RATIONAL, 0, TIFF_SETGET_C0_FLOAT */ + retCode = TIFFGetField(tif, TIFFTAG_DEFAULTCROPSIZE, &pVoidArray); + if (!retCode) { fprintf(stderr, "Can't read %s\n", "TIFFTAG_DEFAULTCROPSIZE"); } + /*- pVoidArray points to a Tiff-internal temporary memorypart. Thus, contents needs to be saved. */ + memcpy(&auxFloatArray, pVoidArray, (2 * sizeof(auxFloatArray[0]))); + for (i = 0; i < 2; i++) { + dblDiffLimit = RATIONAL_EPS * auxFloatArrayW[i]; + dblDiff = auxFloatArray[i] - auxFloatArrayW[i]; + if (fabs(dblDiff) > fabs(dblDiffLimit)) { + fprintf(stderr, "Read value %d of TIFFTAG_DEFAULTCROPSIZE Array %f differs from set value %f\n", i, auxFloatArray[i], auxFloatArrayW[i]); + } + } + +#endif /*-- ADDITIONAL_TAGS --*/ + + +#ifdef READ_GPS_TAGS +/*================== Reading GPS tags =====================*/ + /*-- First get offset to GPS-directory and set it active (this will destroy previously main directory fields in memory!) */ + retCode = TIFFGetField(tif, TIFFTAG_GPSIFD, &read_dir_offset ); + if (!retCode) {fprintf(stderr, "Can't read %s\n", "TIFFTAG_GPSIFD"); } + retCode = TIFFReadGPSDirectory(tif, read_dir_offset); + if (!retCode) { fprintf(stderr, "Can't read %s\n", "TIFFReadGPSDirectory()"); } + + /*-- Now read some parameters from GPS-directory --*/ + + /*-- Fixed Array: GPS-Version is a fixed array (of 4 characters) */ + retCode = TIFFGetField(tif, GPSTAG_VERSIONID, &pGpsVersion); + if (!retCode) { fprintf(stderr, "Can't read %s\n", "GPSTAG_VERSIONID"); } + else { + memcpy(auxCharArray, pGpsVersion, sizeof(gpsVersion)); + for (i = 0; i < 4; i++) { + if (auxCharArray[i] != pGpsVersion[i]) { + fprintf(stderr, "Read value %d of GPSTAG_VERSIONID %d differs from set value %d\n", i, auxCharArray[i], pGpsVersion[i]); + } + } + } + /*-- LATITUDEREF is a fixed String of one character plus ending zero. */ + retCode = TIFFGetField(tif, GPSTAG_LATITUDEREF, &pAscii); + if (!retCode) { fprintf(stderr, "Can't read %s\n", "GPSTAG_LATITUDEREF"); } + retCode2 = strncmp("N", pAscii, 1); + if (retCode2 != 0) { + fprintf (stderr, "Read value %d of GPSTAG_LATITUDEREF %s differs from set value %s\n", i, "N", pAscii); + } + + /*-- Fixed Array: Latitude is an array of 3 Rational-values. TIFFGetField() returns a pointer to a temporary float-/double-array. */ + /*-- ATTENTION: After the upgrade with Rational2Double, the GPSTAG values are defined as double precision + * and need to be written and also read in double precision! + * In order to maintain this code for both cases, it is checked above if the TiffLibrary is + * compiled with the new interface with Rational2Double or still uses the old definitions, + * by setting blnIsRational2Double above. + */ + if (blnIsRational2Double) { + fprintf(stderr, "-- GPS tags are read using Rational2Double --\n"); + } else { + fprintf(stderr, "-- GPS tags are read using standard --\n"); + } + retCode = TIFFGetField(tif, GPSTAG_LATITUDE, &pVoidArray); + if (!retCode) { fprintf(stderr, "Can't read %s\n", "GPSTAG_LATITUDE"); } + if (!blnIsRational2Double) { + /* Reset arrays for debugging purpose first */ + memset(auxFloatArray, 0, sizeof(auxFloatArray)); + memcpy(auxFloatArray, pVoidArray, 3*sizeof(float)); + /* for comparison copy to doubleArray */ + for (i=0; i<3; i++) auxDoubleArray[i] = (double)auxFloatArray[i]; + } else { + /* Rational2Double interface for GPSTAG reads double array */ + memset(auxDoubleArray, 0, sizeof(auxDoubleArray)); + memcpy(auxDoubleArray, pVoidArray, 3 * sizeof(double)); + } + for (i=0; i<3; i++) { + dblDiffLimit = RATIONAL_EPS*auxDoubleArrayGPS1[i]; + dblDiff = auxDoubleArray[i] - auxDoubleArrayGPS1[i]; + if (fabs(dblDiff) > fabs(dblDiffLimit)) { + fprintf (stderr, "Read value %d of GPSTAG_LATITUDE %f differs from set value %f\n", i, auxDoubleArray[i], auxDoubleArrayGPS1[i]); + } + } + + /*-- LONGITUDEREF is a fixed String of one character plus ending zero. */ + retCode = TIFFGetField(tif, GPSTAG_LONGITUDEREF, &pAscii); + if (!retCode) { fprintf(stderr, "Can't read %s\n", "GPSTAG_LONGITUDEREF"); } + retCode2 = strncmp("W", pAscii, 1); + if (retCode2 != 0) { + fprintf(stderr, "Read value %d of GPSTAG_LONGITUDEREF %s differs from set value %s\n", i, "W", pAscii); + } + + retCode = TIFFGetField(tif, GPSTAG_LONGITUDE, &pVoidArray); + if (!retCode) { fprintf(stderr, "Can't read %s\n", "GPSTAG_LONGITUDE"); } + if (!blnIsRational2Double) { + /* Reset arrays for debugging purpose first */ + memset(auxFloatArray, 0, sizeof(auxFloatArray)); + memcpy(auxFloatArray, pVoidArray, 3 * sizeof(float)); + /* for comparison copy to doubleArray */ + for (i = 0; i < 3; i++) auxDoubleArray[i] = (double)auxFloatArray[i]; + } else { + /* Rational2Double interface for GPSTAG reads double array */ + memset(auxDoubleArray, 0, sizeof(auxDoubleArray)); + memcpy(auxDoubleArray, pVoidArray, 3 * sizeof(double)); + } + for (i = 0; i < 3; i++) { + dblDiffLimit = RATIONAL_EPS * auxDoubleArrayGPS2[i]; + dblDiff = auxDoubleArray[i] - auxDoubleArrayGPS2[i]; + if (fabs(dblDiff) > fabs(dblDiffLimit)) { + fprintf(stderr, "Read value %d of GPSTAG_LONGITUDE %f differs from set value %f\n", i, auxDoubleArray[i], auxDoubleArrayGPS2[i]); + } + } + + /* TIFF_RATIONAL, TIFF_SETGET_DOUBLE */ + if (!TIFFGetField(tif, GPSTAG_ALTITUDE, &auxDblUnion.dbl)) { + fprintf(stderr, "Can't read GPSTAG_ALTITUDE\n"); + GOTOFAILURE_GPS + } + if (blnIsRational2Double) { + /* New interface allows also double precision for TIFF_RATIONAL */ + auxDouble = auxDblUnion.dbl; + } else { + /* Old interface reads TIFF_RATIONAL defined as TIFF_SETGET_DOUBLE alwasy as FLOAT */ + auxDouble = (double)auxDblUnion.flt1; + } + /* compare read values with written ones */ + dblDiffLimit = RATIONAL_EPS * auxDoubleGPSAltitude; + dblDiff = auxDouble - auxDoubleGPSAltitude; + if (fabs(dblDiff) > fabs(dblDiffLimit)) { + fprintf(stderr, "Read value of GPSTAG_ALTITUDE %f differs from set value %f\n", auxDouble, auxDoubleGPSAltitude); + GOTOFAILURE_GPS + } + + /*-- TimeStamp is only hh:mm:ss. See also DateTime string 3, TIFF_RATIONAL, TIFF_SETGET_C0_DOUBLE */ + retCode = TIFFGetField(tif, GPSTAG_TIMESTAMP, &pVoidArray); + if (!retCode) { fprintf(stderr, "Can't read %s\n", "GPSTAG_TIMESTAMP"); } + if (!blnIsRational2Double) { + /* Reset arrays for debugging purpose first */ + memset(auxFloatArray, 0, sizeof(auxFloatArray)); + memcpy(auxFloatArray, pVoidArray, 3 * sizeof(float)); + /* for comparison copy to doubleArray */ + for (i = 0; i < 3; i++) auxDoubleArray[i] = (double)auxFloatArray[i]; + } else { + /* Rational2Double interface for GPSTAG reads double array */ + memset(auxDoubleArray, 0, sizeof(auxDoubleArray)); + memcpy(auxDoubleArray, pVoidArray, 3 * sizeof(double)); + } + for (i = 0; i < 3; i++) { + dblDiffLimit = RATIONAL_EPS * auxDoubleArrayGPSTime[i]; + dblDiff = auxDoubleArray[i] - auxDoubleArrayGPSTime[i]; + if (fabs(dblDiff) > fabs(dblDiffLimit)) { + fprintf(stderr, "Read value %d of GPSTAG_TIMESTAMP %f differs from set value %f\n", i, auxDoubleArray[i], auxDoubleArrayGPS2[i]); + GOTOFAILURE_GPS + } + } + + /* GPSTAG_IMGDIRECTION --- TIFF_RATIONAL, TIFF_SETGET_DOUBLE */ + if (!TIFFGetField(tif, GPSTAG_IMGDIRECTION, &auxDblUnion.dbl)) { + fprintf(stderr, "Can't read GPSTAG_IMGDIRECTION\n"); + GOTOFAILURE_GPS + } + if (blnIsRational2Double) { + /* New interface allows also double precision for TIFF_RATIONAL */ + auxDouble = auxDblUnion.dbl; + } else { + /* Old interface reads TIFF_RATIONAL defined as TIFF_SETGET_DOUBLE alwasy as FLOAT */ + auxDouble = (double)auxDblUnion.flt1; + } + /* compare read values with written ones */ + dblDiffLimit = RATIONAL_EPS * auxDoubleGPSDirection; + dblDiff = auxDouble - auxDoubleGPSDirection; + if (fabs(dblDiff) > fabs(dblDiffLimit)) { + fprintf(stderr, "Read value of GPSTAG_IMGDIRECTION %f differs from set value %f\n", auxDouble, auxDoubleGPSDirection); + GOTOFAILURE_GPS + } + + /*-- GPSTAG_DIFFERENTIAL , 1, 1, TIFF_SHORT , 0, TIFF_SETGET_UINT16 */ + retCode = TIFFGetField(tif, GPSTAG_DIFFERENTIAL, &auxShort); + if (!retCode) { fprintf(stderr, "Can't read %s\n", "GPSTAG_DIFFERENTIAL"); } + if (auxShort != auxShortArrayW[5]) { + fprintf(stderr, "Read value of GPSTAG_DIFFERENTIAL %d differs from set value %d\n", auxShort, auxShortArrayW[5]); + GOTOFAILURE_GPS + } + + /*-- GPSHPOSITIONINGERROR - new tag for EXIF 2.31 --*/ + if (!TIFFGetField(tif, GPSTAG_GPSHPOSITIONINGERROR, &auxDblUnion.dbl)) { + fprintf(stderr, "Can't read GPSTAG_GPSHPOSITIONINGERROR\n"); + GOTOFAILURE_GPS + } + if (blnIsRational2Double) { + /* New interface allows also double precision for TIFF_RATIONAL */ + auxDouble = auxDblUnion.dbl; + } else { + /* Old interface reads TIFF_RATIONAL defined as TIFF_SETGET_DOUBLE alwasy as FLOAT */ + auxDouble = (double)auxDblUnion.flt1; + } + /* compare read values with written ones */ + auxFloat = (float)GPSHPOSITIONINGERROR_VAL; + dblDiffLimit = RATIONAL_EPS * auxFloat; + dblDiff = auxDouble - auxFloat; + if (fabs(dblDiff) > fabs(dblDiffLimit)) { + fprintf(stderr, "Read value of GPSTAG_GPSHPOSITIONINGERROR %f differs from set value %f\n", auxDouble, auxFloat); + GOTOFAILURE_GPS + } + + /*=============== END reading GPS tags ==========================*/ +#endif /*-- READ_GPS_TAGS --*/ + + + +/*================== Reading EXIF 2.31 tags =====================*/ + + /*--- Firstly, get EXIF directory offset from main directory. */ + + /*-- Go back to the first (main) directory, and get value of the EXIFIFD directory- offset. */ + /* (directory is reloaded from file!) */ + TIFFSetDirectory(tif, 0); + retCode = TIFFGetField(tif, TIFFTAG_EXIFIFD, &read_dir_offset ); + +#ifdef READ_EXIF_TAGS + /*-- Now read EXIF directory from file into memory --*/ + retCode = TIFFReadEXIFDirectory(tif, read_dir_offset); + + /*-- Now get some parameters from EXIF-directory (already read into memory) --*/ + retCode = TIFFGetField(tif, EXIFTAG_EXIFVERSION, &pAscii); + + +#ifdef READ_ALL_EXIF_TAGS + /*-- Get array, where EXIF tag fields are defined --*/ + tFieldArray = _TIFFGetExifFields(); + nTags = tFieldArray->count; + /*-- Check, if the TiffLibrary is compiled with the new interface with Rational2Double or still uses the old definitions. */ + /* tif points to EXIF tags, so TIFFFindField() can only access the EXIF tag fields */ + fip = TIFFFindField(tif, EXIFTAG_EXPOSURETIME, TIFF_ANY); + tSetFieldType = fip->set_field_type; + if (tSetFieldType == TIFF_SETGET_DOUBLE) { + blnIsRational2Double = FALSE; + fprintf(stderr, "-- EXIF tags read with standard --\n"); + } else { + blnIsRational2Double = TRUE; + fprintf(stderr, "-- Rational2Double for reading EXIF tags detected --\n"); + } + + for (i=0; ifields[i].field_tag; + tType = tFieldArray->fields[i].field_type; /* e.g. TIFF_RATIONAL */ + tWriteCount = tFieldArray->fields[i].field_writecount; + tSetFieldType = tFieldArray->fields[i].set_field_type; /* e.g. TIFF_SETGET_C0_FLOAT */ + tFieldName = tFieldArray->fields[i].field_name; + pVoid = NULL; + + /*-- dependent on set_field_type read value --*/ + switch (tSetFieldType) + { + case TIFF_SETGET_ASCII: + /* Either the stringlength is defined as a fixed length in .field_writecount or a NULL-terminated string is used. */ + if (!TIFFGetField( tif, tTag, &pAscii)) { + fprintf (stderr, "Can't read %s\n", tFieldArray->fields[i].field_name); + GOTOFAILURE_ALL_EXIF + break; + } + /* Save string from temporary buffer and compare with written string. */ + strncpy(auxCharArray, pAscii, sizeof(auxCharArray)); + if (tWriteCount > 0) auxLong = tWriteCount-1; else auxLong = (long)strlen(auxCharArray); + retCode2 = strncmp(auxCharArray, auxTextArrayW[i], auxLong); + if (retCode2 != 0) { + fprintf (stderr, "%d:Read value of %s %s differs from set value %s\n", i, tFieldName, auxCharArray, auxTextArrayW[i]); + GOTOFAILURE_ALL_EXIF + } + break; + /*-- For reading, the parameter size is to be observed !! */ + case TIFF_SETGET_UINT8: + case TIFF_SETGET_SINT8: + if (!TIFFGetField( tif, tTag, &auxChar)) { + fprintf (stderr, "Can't read %s\n", tFieldArray->fields[i].field_name); + GOTOFAILURE_ALL_EXIF + break; + } + /* compare read values with written ones */ + auxLong = auxChar; + if (auxLong != (char)auxLongArrayW[i]) { + fprintf (stderr, "%d:Read value of %s %ld differs from set value %ld\n", i, tFieldName, auxLong, auxLongArrayW[i]); + } + break; + case TIFF_SETGET_UINT16: + case TIFF_SETGET_SINT16: + if (!TIFFGetField( tif, tTag, &auxShort)) { + fprintf (stderr, "Can't read %s\n", tFieldArray->fields[i].field_name); + GOTOFAILURE_ALL_EXIF + break; + } + /* compare read values with written ones */ + auxLong = auxShort; + if (auxLong != (short)auxLongArrayW[i]) { + fprintf (stderr, "%d:Read value of %s %ld differs from set value %ld\n", i, tFieldName, auxLong, auxLongArrayW[i]); + } + break; + case TIFF_SETGET_UINT32: + case TIFF_SETGET_SINT32: + case TIFF_SETGET_IFD8: + case TIFF_SETGET_INT: + if (!TIFFGetField( tif, tTag, &auxUint32)) { + fprintf (stderr, "Can't read %s\n", tFieldArray->fields[i].field_name); + GOTOFAILURE_ALL_EXIF + break; + } + /* compare read values with written ones */ + auxLong = auxUint32; + if (auxLong != auxLongArrayW[i]) { + fprintf (stderr, "%d:Read value of %s %ld differs from set value %ld\n", i, tFieldName, auxLong, auxLongArrayW[i]); + } + break; + case TIFF_SETGET_FLOAT: + if (!TIFFGetField( tif, tTag, &auxFloat)) { + fprintf (stderr, "Can't read %s\n", tFieldArray->fields[i].field_name); + GOTOFAILURE_ALL_EXIF + break; + } + /* compare read values with written ones */ + if (tType == TIFF_RATIONAL || tType == TIFF_SRATIONAL) dblDiffLimit = RATIONAL_EPS*auxDoubleArrayW[i]; else dblDiffLimit = 1e-6; + dblDiff = auxFloat - auxDoubleArrayW[i]; + if (fabs(dblDiff) > fabs(dblDiffLimit)) { + /*--: EXIFTAG_SUBJECTDISTANCE: LibTiff returns value of "-1.0" if numerator equals 4294967295 (0xFFFFFFFF) to indicate infinite distance! + * However, there are two other EXIF tags where numerator indicates a special value and six other cases where the denominator indicates special values, + * which are not treated within LibTiff!! + */ + if (!(tTag == EXIFTAG_SUBJECTDISTANCE && auxFloat == -1.0)) { + fprintf (stderr, "%d:Read value of %s %f differs from set value %f\n", i, tFieldName, auxFloat, auxDoubleArrayW[i]); + GOTOFAILURE_ALL_EXIF + } + } + break; + case TIFF_SETGET_DOUBLE: + /*-- Unfortunately, TIFF_SETGET_DOUBLE is used for TIFF_RATIONAL but those have to be read with FLOAT !!! */ + /* Only TIFFTAG_STONITS is a TIFF_DOUBLE, which has to be read as DOUBLE!! */ + /*-- ATTENTION: ---- + * Only after update with Rational2Double feature, also TIFF_RATIONAL can be read in double precision!!! + * Therefore, use a union to avoid overflow in TIFFGetField() return value + * and depending on version check for the right interface here: + * - old interface: correct value should be here a float + * - new interface: correct value should be here a double + * Interface version (old/new) is determined above. + -------------------*/ + if (!TIFFGetField(tif, tTag, &auxDblUnion.dbl)) { + fprintf(stderr, "Can't read %s\n", tFieldArray->fields[i].field_name); + GOTOFAILURE_ALL_EXIF + break; + } + if (tType == TIFF_RATIONAL || tType == TIFF_SRATIONAL) { + if (blnIsRational2Double) { + /* New interface allows also double precision for TIFF_RATIONAL */ + auxDouble = auxDblUnion.dbl; + } + else { + /* Old interface reads TIFF_RATIONAL defined as TIFF_SETGET_DOUBLE alwasy as FLOAT */ + auxDouble = (double)auxDblUnion.flt1; + } + } + else { + auxDouble = auxDblUnion.dbl; + } + /* compare read values with written ones */ + if (tType == TIFF_RATIONAL || tType == TIFF_SRATIONAL) dblDiffLimit = RATIONAL_EPS*auxDoubleArrayW[i]; else dblDiffLimit = 1e-6; + dblDiff = auxDouble - auxDoubleArrayW[i]; + if (fabs(dblDiff) > fabs(dblDiffLimit)) { + /*--: EXIFTAG_SUBJECTDISTANCE: LibTiff returns value of "-1.0" if numerator equals 4294967295 (0xFFFFFFFF) to indicate infinite distance! */ + if (!(tTag == EXIFTAG_SUBJECTDISTANCE && auxDouble == -1.0)) { + fprintf (stderr, "%d:Read value of %s %f differs from set value %f\n", i, tFieldName, auxDouble, auxDoubleArrayW[i]); + GOTOFAILURE_ALL_EXIF + } + } + break; + + case TIFF_SETGET_C0_FLOAT: + case TIFF_SETGET_C0_DOUBLE: + case TIFF_SETGET_C16_FLOAT: + case TIFF_SETGET_C16_DOUBLE: + case TIFF_SETGET_C32_FLOAT: + case TIFF_SETGET_C32_DOUBLE: + /* _Cxx_ just defines the size of the count parameter for the array as C0=char, C16=short or C32=long */ + /*-- Check, if it is a single parameter, a fixed array or a variable array */ + if (tWriteCount == 1) { + fprintf (stderr, "Reading: WriteCount for .set_field_type %d should be -1 or greather than 1! %s\n", tSetFieldType, tFieldArray->fields[i].field_name); + } else { + /*-- Either fix or variable array --*/ + /* For arrays, distinguishing between float or double is essential. */ + /* Now decide between fixed or variable array */ + if (tWriteCount > 1) { + /* fixed array with needed arraysize defined in .field_writecount */ + if (!TIFFGetField( tif, tTag, &pVoidArray)) { + fprintf (stderr, "Can't read %s\n", tFieldArray->fields[i].field_name); + GOTOFAILURE_ALL_EXIF + break; + } + /* set tWriteCount to number of read samples for next steps */ + auxLong = tWriteCount; + } else { + /* Special treatment of variable array. */ + /* Dependent on Cxx, the count parameter is char, short or long. Therefore use unionLong! */ + if (!TIFFGetField( tif, tTag, &unionLong, &pVoidArray)) { + fprintf (stderr, "Can't read %s\n", tFieldArray->fields[i].field_name); + GOTOFAILURE_ALL_EXIF + break; + } + /* set tWriteCount to number of read samples for next steps */ + auxLong = unionLong.Short1; + } + /* Save values from temporary array */ + if (tSetFieldType == TIFF_SETGET_C0_FLOAT || tSetFieldType == TIFF_SETGET_C16_FLOAT || tSetFieldType == TIFF_SETGET_C32_FLOAT) { + memcpy(&auxFloatArray, pVoidArray,(auxLong * sizeof(auxFloatArray[0]))); + /* compare read values with written ones */ + if (tType == TIFF_RATIONAL || tType == TIFF_SRATIONAL) dblDiffLimit = RATIONAL_EPS*auxDoubleArrayW[i]; else dblDiffLimit = 1e-6; + for (j=0; j fabs(dblDiffLimit)) { + /*if (auxFloatArray[j] != (float)auxFloatArrayW[i+j]) { */ + fprintf (stderr, "Read value %d of %s #%d %f differs from set value %f\n", i, tFieldName, j, auxFloatArray[j], auxFloatArrayW[i+j]); + GOTOFAILURE_ALL_EXIF + } + } + } else { + memcpy(&auxDoubleArray, pVoidArray,(auxLong * sizeof(auxDoubleArray[0]))); + /* compare read values with written ones */ + if (tType == TIFF_RATIONAL || tType == TIFF_SRATIONAL) dblDiffLimit = RATIONAL_EPS*auxDoubleArrayW[i]; else dblDiffLimit = 1e-6; + for (j=0; j fabs(dblDiffLimit)) { + /*if (auxDoubleArray[j] != auxDoubleArrayW[i+j]) { */ + fprintf (stderr, "Read value %d of %s #%d %f differs from set value %f\n", i, tFieldName, j, auxDoubleArray[j], auxDoubleArrayW[i+j]); + GOTOFAILURE_ALL_EXIF + } + } + } + } + break; + case TIFF_SETGET_C0_UINT8: + case TIFF_SETGET_C0_SINT8: + case TIFF_SETGET_C16_UINT8: + case TIFF_SETGET_C16_SINT8: + case TIFF_SETGET_C32_UINT8: + case TIFF_SETGET_C32_SINT8: + /* For arrays, distinguishing between float or double is essential, even for writing */ + pVoid = &auxCharArrayW[i]; + case TIFF_SETGET_C0_UINT16: + case TIFF_SETGET_C0_SINT16: + case TIFF_SETGET_C16_UINT16: + case TIFF_SETGET_C16_SINT16: + case TIFF_SETGET_C32_UINT16: + case TIFF_SETGET_C32_SINT16: + if (pVoid == NULL) pVoid = &auxShortArrayW[i]; + case TIFF_SETGET_C0_UINT32: + case TIFF_SETGET_C0_SINT32: + case TIFF_SETGET_C16_UINT32: + case TIFF_SETGET_C16_SINT32: + case TIFF_SETGET_C32_UINT32: + case TIFF_SETGET_C32_SINT32: + if (pVoid == NULL) pVoid = &auxLongArrayW[i]; + /* _Cxx_ just defines the size of the count parameter for the array as C0=char, C16=short or C32=long */ + /*-- Check, if it is a single parameter, a fixed array or a variable array */ + if (tWriteCount == 1) { + fprintf (stderr, "WriteCount for .set_field_type %d should be -1 or greather than 1! %s\n", tSetFieldType, tFieldArray->fields[i].field_name); + } else { + /*-- Either fix or variable array --*/ + /* Now decide between fixed or variable array */ + if (tWriteCount > 1) { + /* fixed array with needed arraysize defined in .field_writecount */ + if (!TIFFGetField( tif, tTag, &pVoidArray)) { + fprintf (stderr, "Can't read %s\n", tFieldArray->fields[i].field_name); + GOTOFAILURE_ALL_EXIF + break; + } + /* set tWriteCount to number of read samples for next steps */ + auxLong = tWriteCount; + } else { + /* special treatment of variable array */ + /* for test, use always arraysize of VARIABLE_ARRAY_SIZE */ + if (!TIFFGetField( tif, tTag, &unionLong, &pVoidArray)) { + fprintf (stderr, "Can't read %s\n", tFieldArray->fields[i].field_name); + GOTOFAILURE_ALL_EXIF + break; + } + /* set tWriteCount to number of read samples for next steps */ + auxLong = unionLong.Short1; + } + /* Save values from temporary array */ + if (tSetFieldType == TIFF_SETGET_C0_UINT8 || tSetFieldType == TIFF_SETGET_C0_SINT8 || + tSetFieldType == TIFF_SETGET_C16_UINT8 || tSetFieldType == TIFF_SETGET_C16_SINT8 || + tSetFieldType == TIFF_SETGET_C32_UINT8 || tSetFieldType == TIFF_SETGET_C32_SINT8 ) { + memcpy(&auxCharArray, pVoidArray,(auxLong * sizeof(auxCharArray[0]))); + /* Compare and check values */ + for (j=0; j