
Thread
2004.02.03 17:42 "[Tiff] Re: Recent Post you made about Custom Tags", by Frank Warmerdam
Bill,
Yes, as of libtiff 3.6.1 otherwise unrecognised tags (not quite properly called custom tags) are supported for pretty much normal access. You can use TIFFGetField() to fetch the values.
There are some caveats:
- If you are reading a tag that was not pre-defined, certain default conventions are applied to the TIFFGetField(), TIFFSetField() calling conventions. In particular, you will need pass two arguments TIFFGetField() for the value. A unsigned short * into which the count of field values will be placed, and a pointer to a pointer into which the pointer to the internal copy of the data will be placed.
- If you want to add the tag to a new file without having read the tag from a file then the system won't know the type of the field. You will need to define it to libtiff first. For this you need to provide a TIFFFieldInfo declaration for each field you want to write. For libgeotiff I do something like this:
/* Tiff info structure.
*
* Entry format:
* { TAGNUMBER, ReadCount, WriteCount, DataType, FIELDNUM,
* OkToChange, PassDirCountOnSet, AsciiName }
*
* For ReadCount, WriteCount, -1 = unknown.
*/
static const TIFFFieldInfo xtiffFieldInfo[] = {
/* XXX Insert Your tags here */
{ TIFFTAG_GEOPIXELSCALE, -1,-1, TIFF_DOUBLE, FIELD_CUSTOM,
TRUE, TRUE, "GeoPixelScale" },
{ TIFFTAG_INTERGRAPH_MATRIX,-1,-1, TIFF_DOUBLE, FIELD_CUSTOM,
TRUE, TRUE, "Intergraph TransformationMatrix" },
{ TIFFTAG_GEOTRANSMATRIX, -1,-1, TIFF_DOUBLE, FIELD_CUSTOM,
TRUE, TRUE, "GeoTransformationMatrix" },
{ TIFFTAG_GEOTIEPOINTS, -1,-1, TIFF_DOUBLE, FIELD_CUSTOM,
TRUE, TRUE, "GeoTiePoints" },
{ TIFFTAG_GEOKEYDIRECTORY,-1,-1, TIFF_SHORT, FIELD_CUSTOM,
TRUE, TRUE, "GeoKeyDirectory" },
{ TIFFTAG_GEODOUBLEPARAMS, -1,-1, TIFF_DOUBLE, FIELD_CUSTOM,
TRUE, TRUE, "GeoDoubleParams" },
{ TIFFTAG_GEOASCIIPARAMS, -1,-1, TIFF_ASCII, FIELD_CUSTOM,
TRUE, FALSE, "GeoASCIIParams" },
#ifdef JPL_TAG_SUPPORT
{ TIFFTAG_JPL_CARTO_IFD, 1, 1, TIFF_LONG, FIELD_CUSTOM,
TRUE, TRUE, "JPL Carto IFD offset" }, /** Don't use this! **/
#endif
};
#define N(a) (sizeof (a) / sizeof (a[0]))
static void _XTIFFLocalDefaultDirectory(TIFF *tif)
{
/* Install the extended Tag field info */
TIFFMergeFieldInfo(tif, xtiffFieldInfo, N(xtiffFieldInfo));
}
I have taken the liberty of cc:ing this to the tiff mailing list since this sort of question comes up fairly often. Clearly we need an FAQ or some better online documentation on the whole area of custom tags.
Best regards,
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up | Frank Warmerdam, warmerdam@pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush | Geospatial Programmer for Rent