You need to log in before you can comment on or make changes to this bug.
Created an attachment (id=650) [details] Rationals with double precision for custom tags --- Issue Description --- Custom parameters (like the updated GPS tags) are defined using TIFFField entries. Here, the size and parameter type for reading and writing is defined, also for rational values. There are two parameters defined in TIFFField for that: TIFFSetGetFieldType set_field_type; /* type to be passed to TIFFSetField */ TIFFSetGetFieldType get_field_type; /* type to be passed to TIFFGetField */ However, "get_field_type" is not used within the LibTiff code. Parameter "set_field_type" is used for both, reading and writing, instead. For rational values, the definition of "set_field_type" is completely ignored. Rational values, even when passed or read with DOUBLE-precision, are internally stored ALLWAYS as floating point SINGLE precision in "tif->tif_dir.td_customValues". Rational arrays have to be always floating point variable type! Otherwise errors will occur. This means that the LibTiff does not allow the handling of custom defined rational values in double precision, even if the rational representation would allow this precision. Such higher precision is necessary i.e. for GPS tags latitude and longitude values! --- Enhancement Patch: Custom rational parameter with double-precision --- In order to solve that issue, the LibTiff code is enhanced to allow custom defined rational values to be written and read in double precision. Only code for tags defined as FIELD_CUSTOM is changed. The enhancement is, that now the parameters of TIFFGetField() and TIFFSetField() routines for reading and writing rational values where "field_bit" is set to FIELD_CUSTOM have to respect also the definition of set_field_type: - for TIFF_SET_GET_**_DOUBLE "DOUBLE" parameter or array have to be passed - for TIFF_SET_GET_**_FLOAT "FLOAT" parameter or array have to be passed For easy location of the changes in the code and compatibility testing, the enhanced code is surrounded by #ifdef RATIONAL2DOUBLE -- #else clauses. RATIONAL2DOUBLE is defined in tiffiop.h. Later on, it could be moved to nmake.opt or omitted, if this feature will be included in the release library. The following two bugfixes and enhancements are also included: Bug 2539 - Wrong data type of GPS_IFD and EXIF_IFD tags http://bugzilla.maptools.org/show_bug.cgi?id=2539 Bug 2540 - GPS tags added as special CustomDirectoy http://bugzilla.maptools.org/show_bug.cgi?id=2540 Main changes are: - tif_dirread.c TIFFFetchNormalTag() enhanced with case TIFF_SETGET_C0_DOUBLE and GPS tag patch - tif_dirwrite.c new functions like TIFFWriteDirectoryTagSrationalDoubleArray() and the more precise conversion functions DoubleToRational() and DoubleToSrational() added. - tif_dirinfo.c TIFFFieldArray definitions amended, new function _TIFFSetGetFieldSize() and GPS tag patch. - tif_dir.c _TIFFVGetField(),_TIFFVSetField() enhanced for double precision rationals and GPS patch. - tiffiop.h definition of RATIONAL2DOUBLE - tiffio.h GPS patch only - tiff.h GPS patch only - tif_dir.h GPS patch only --- Compatibility with LibTiff 4.0.6 --- For standard tags within tiffFields[] with field_bit other than FIELD_CUSTOM the enhancement is not applied. Most tags within tiffFields[] which are rational values and with field_bit set to FIELD_CUSTOM are defined as TIFF_SETGET_**_FLOAT anyhow. Only some DNG tags and the EXIF tags with rational values are not compatible because they have TIFF_SETGET_DOUBLE definition (e.g. TIFFTAG_BESTQUALITYSCALE, TIFFTAG_BASELINEEXPOSURE, ...). Therefore, those DNG tag and EXIF tag definitions were redefined to TIFF_SETGET_FLOAT for the old compatible compilation in this enhancement when RATIONAL2DOUBLE is not defined. --- Patch --- The enhanced code is based on the LibTiff 4.0.6 sources and complete files and a patch-file are attached.
Bugzilla is no longer used for tracking libtiff issues. Remaining open tickets, such as this one, have been migrated to the libtiff GitLab instance at https://gitlab.com/libtiff/libtiff/issues . The migrated tickets have their summary prefixed with [BZ#XXXX] where XXXX is the initial Bugzilla issue number.