PNG IHDR ; IDATxܻn0K )(pA7LeG{ §㻢|ذaÆ 6lذaÆ 6lذaÆ 6lom$^yذag5 bÆ 6lذaÆ 6lذa{ 6lذaÆ `}HFkm,mӪôô!x|'ܢ˟;E:9&ᶒ}{v]n&6 h_tڠ͵-ҫZ;Z$.Pkž)!o>}leQfJTu іچ\X=8Rن4`Vwl>nG^is"ms$ui?wbs[m6K4O.4%/bC%tMז -lG6mrz2s%9s@-k9=)kB5\+͂ZsٲRn~GRCwIcIn7jJhۛNCS|j08yiHKֶۛkɈ+;SzL /F*\Ԕ#"5m2[S=gnaPeғL lذaÆ 6l^ḵaÆ 6lذaÆ 6lذa; _ذaÆ 6lذaÆ 6lذaÆ R IENDB`
typedef struct { ttag_t field_tag; /* field's tag */ short field_readcount; /* read count/TIFF_VARIABLE/TIFF_SPP */ short field_writecount; /* write count/TIFF_VARIABLE */ TIFFDataType field_type; /* type of associated data */ unsigned short field_bit; /* bit in fieldsset bit vector */ unsigned char field_oktochange;/* if true, can change while writing */ unsigned char field_passcount;/* if true, pass dir count on set */ char *field_name; /* ASCII name */ } TIFFFieldInfo;
Various functions exist for getting the internal TIFFFieldInfo definitions, including _TIFFFindFieldInfo(), and _TIFFFindFieldInfoByName(). See tif_dirinfo.c for details. There must be some mechanism to get the whole list, though I don't see it off hand.
When tags are autodefined like this the field_readcount and field_writecount values are always TIFF_VARIABLE. The field_passcount is always TRUE, and the field_bit is FIELD_CUSTOM. The field name will be "Tag %d" where the %d is the tag number.
The libgeotiff library provides geospatial information extentions within a TIFF file. First, a set of TIFFFieldInfo's is prepared with information on the new tags:
static const TIFFFieldInfo xtiffFieldInfo[] = { /* XXX Insert Your tags here */ { TIFFTAG_GEOPIXELSCALE, -1,-1, TIFF_DOUBLE, FIELD_CUSTOM, TRUE, TRUE, "GeoPixelScale" }, { 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" } };In order to define the tags, we call TIFFMergeFieldInfo() on the desired TIFF handle with the list of TIFFFieldInfos.
#define N(a) (sizeof (a) / sizeof (a[0])) /* Install the extended Tag field info */ TIFFMergeFieldInfo(tif, xtiffFieldInfo, N(xtiffFieldInfo));The tags need to be defined for each TIFF file opened - and when reading they should be defined before the tags of the file are read, yet a valid TIFF * is needed to merge the tags against. In order to get them registered at the appropriate part of the setup process, it is necessary to register our merge function as an extender callback with libtiff. This is done with TIFFSetTagExtender(). We also keep track of the previous tag extender (if any) so that we can call it from our extender allowing a chain of customizations to take effect.
static TIFFExtendProc _ParentExtender = NULL; static void _XTIFFInitialize(void) { static int first_time=1; if (! first_time) return; /* Been there. Done that. */ first_time = 0; /* Grab the inherited method and install */ _ParentExtender = TIFFSetTagExtender(_XTIFFDefaultDirectory); }The extender callback is looks like this. It merges in our new fields and then calls the next extender if there is one in effect.
static void _XTIFFDefaultDirectory(TIFF *tif) { /* Install the extended Tag field info */ TIFFMergeFieldInfo(tif, xtiffFieldInfo, N(xtiffFieldInfo)); /* Since an XTIFF client module may have overridden * the default directory method, we call it now to * allow it to set up the rest of its own methods. */ if (_ParentExtender) (*_ParentExtender)(tif); }The above approach ensures that our new definitions are used when reading or writing any TIFF file. However, since on reading we already have default definitions for tags, it is usually not critical to pre-define them. If tag definitions are only required for writing custom tags, you can just call TIFFMergeFieldInfo() before setting new tags. The whole extender architecture can then be avoided.
Adding New Builtin Tags
A similar approach is taken to the above. However, the TIFFFieldInfo
should be added to the tiffFieldInfo[] list in tif_dirinfo.c. Ensure that
new tags are added in sorted order by the tag number.
Normally new built-in tags should be defined with FIELD_CUSTOM; however, if it is desirable for the tag value to have it's own field in the TIFFDirectory structure, then you will need to #define a new FIELD_ value for it, and add appropriate handling as follows:
If you want to maintain portability, beware of making assumptions
about data types. Use the typedefs (uint16, etc. when dealing with
data on disk and t*_t when stuff is in memory) and be careful about
passing items through printf or similar vararg interfaces.
Adding New Codec-private Tags
To add tags that are meaningful only when a particular compression
algorithm is used follow these steps:
sp->vgetparent = tif->tif_vgetfield; tif->tif_vgetfield = fooVGetField; /* hook for codec tags */ sp->vsetparent = tif->tif_vsetfield; tif->tif_vsetfield = fooVSetField; /* hook for codec tags */ tif->tif_printdir = fooPrintDir; /* hook for codec tags */(Actually you may decide not to override the tif_printdir method, but rather just specify it).
_TIFFMergeFieldInfo(tif, fooFieldInfo, N(fooFieldInfo));(where N is a macro used liberaly throughout the distributed code).