AWARE [SYSTEMS] Imaging expertise for the Delphi developer
AWare Systems, Imaging expertise for the Delphi developer, Home TIFF and LibTiff Mailing List Archive

LibTiff Mailing List

TIFF and LibTiff Mailing List Archive
February 2004

Previous Thread
Next Thread

Previous by Thread
Next by Thread

Previous by Date
Next by Date

Contact

The TIFF Mailing List Homepage
This list is run by Frank Warmerdam
Archive maintained by AWare Systems



Valid HTML 4.01!



2004.02.03 17:42 "Re: Recent Post you made about Custom Tags", by Frank Warmerdam

Bill Cassanova wrote:
> I thought I remembered seeing a message from the libtiff users group about
> Custom tags now being
> fully supported in a newer version of libtiff.  Was I correct or was the post in
> reference to something
> else possibly non-related.

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:

  o 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.

  o 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