roentgen b75cab
roentgen b75cab
NOTE:  Sept/2004 
roentgen b75cab
roentgen b75cab
The following described approach to managing tag extensions has been
roentgen b75cab
mostly superceeded since libtiff 3.6.0.  The described approach requires
roentgen b75cab
internal knowledge of the libtiff API and tends to be very fragile 
roentgen b75cab
in the face of libtiff upgrades.  
roentgen b75cab
roentgen b75cab
Please read over the html/addingtags.html in preference to the below
roentgen b75cab
described approach.
roentgen b75cab
roentgen b75cab
roentgen b75cab
roentgen b75cab
==================================
roentgen b75cab
roentgen b75cab
Client module for adding to LIBTIFF tagset
roentgen b75cab
-------------------------------------------
roentgen b75cab
  Author: Niles Ritter
roentgen b75cab
roentgen b75cab
roentgen b75cab
  
roentgen b75cab
roentgen b75cab
In the past, users of the "libtiff" package had to modify the
roentgen b75cab
source code of the library if they required additional private tags
roentgen b75cab
or codes not recognized by libtiff. Thus, whenever
roentgen b75cab
a new revision of libtiff came out the client would have to
roentgen b75cab
perform modifications to six or seven different files to re-install
roentgen b75cab
their tags.
roentgen b75cab
roentgen b75cab
The latest versions of libtiff now provide client software new routines, 
roentgen b75cab
giving them the opportunity to install private extensions at runtime,
roentgen b75cab
rather than compile-time. This means that the client may encapsulate
roentgen b75cab
all of their private tags into a separate module, which need only
roentgen b75cab
be recompiled when new versions of libtiff are released; no manual
roentgen b75cab
editing of files is required.
roentgen b75cab
roentgen b75cab
How it works
roentgen b75cab
------------
roentgen b75cab
roentgen b75cab
The mechanism for overriding the tag access has been enabled with
roentgen b75cab
a single new routine, which has the following calling sequence:
roentgen b75cab
roentgen b75cab
  TIFFExtendProc old_extender;
roentgen b75cab
  
roentgen b75cab
  old_extender = TIFFSetTagExtender(tag_extender);
roentgen b75cab
roentgen b75cab
which must be called prior to opening or creating TIFF files.
roentgen b75cab
roentgen b75cab
This routine sets a static pointer to the user-specified function
roentgen b75cab
<tag_extender>, which in turn is called by TIFFDefaultDirectory(),</tag_extender>
roentgen b75cab
just after the usual TIFFSetField() and TIFFGetField() methods
roentgen b75cab
are defined, and just before the compression tag is set. It also
roentgen b75cab
returns a pointer to the previously-defined value of the tag-extender,
roentgen b75cab
so that multiple clients may be installed.
roentgen b75cab
roentgen b75cab
The TIFFExtendProc method that you define should be used to override
roentgen b75cab
the TIFF file's "vsetfield" and "vgetfield" methods, so that you
roentgen b75cab
can trap your new, private tags, and install their values into
roentgen b75cab
a private directory structure. For your convienience, a new pointer
roentgen b75cab
has also been added to the "TIFF" file structure:
roentgen b75cab
roentgen b75cab
	tidata_t	tif_clientdir;	/* client TIFF directory */
roentgen b75cab
roentgen b75cab
into which you may install whatever private directory structures you like.
roentgen b75cab
You should also override the tag-printing method from within your
roentgen b75cab
"vsetfield" method, to permit the symbolic printing of your new tags.
roentgen b75cab
roentgen b75cab
roentgen b75cab
Example Client Code:
roentgen b75cab
--------------------
roentgen b75cab
roentgen b75cab
An example module has been provided as a template for installing
roentgen b75cab
your own tags into a client tag extender. The module is called
roentgen b75cab
"xtif_dir.c", and defines all of the interface routines, tag field
roentgen b75cab
access, tag printing, etc. for most purpose. 
roentgen b75cab
roentgen b75cab
To see how the client module operates, there are three "fake"
roentgen b75cab
tags currently installed. If you use the existing makefile you can
roentgen b75cab
build them with:
roentgen b75cab
roentgen b75cab
     make all -f Makefile.gcc  !or Makefile.mpw
roentgen b75cab
     maketif
roentgen b75cab
     listtif
roentgen b75cab
  
roentgen b75cab
This will build two example programs called "maketif" and "listtif" 
roentgen b75cab
and then run them. These programs do nothing more than create a small
roentgen b75cab
file called "newtif.tif", install the fake tags, and then list them out
roentgen b75cab
using TIFFPrintDirectory().
roentgen b75cab
roentgen b75cab
Installing Private Tags
roentgen b75cab
-----------------------
roentgen b75cab
roentgen b75cab
To use this module for installing your own tags, edit each of the files
roentgen b75cab
roentgen b75cab
    xtif_dir.c
roentgen b75cab
    xtiffio.h
roentgen b75cab
    xtiffiop.h
roentgen b75cab
    
roentgen b75cab
and search for the string "XXX". At these locations the comments
roentgen b75cab
will direct you how to install your own tag values, define their
roentgen b75cab
types, etc. Three examples tags are currently installed, demonstrating
roentgen b75cab
how to implement multi-valued tags, single-valued tags, and ASCII tags.
roentgen b75cab
The examples are not valid, registered tags, so you must replace them with
roentgen b75cab
your own.
roentgen b75cab
roentgen b75cab
To test the routines, also edit the test programs "maketif.c" and
roentgen b75cab
"listtif.c" and replace the portions of the code that set the
roentgen b75cab
private tag values and list them.
roentgen b75cab
roentgen b75cab
Once you have edited these files, you may build the client module
roentgen b75cab
with the Makefile provided, and run the test programs.
roentgen b75cab
roentgen b75cab
To use these files in your own code, the "xtif_dir.c" module defines
roentgen b75cab
replacement routines for the standard "TIFFOpen()" "TIFFFdOpen",
roentgen b75cab
and "TIFFClose()" routines, called XTIFFOpen, XTIFFFdOpen and XTIFFClose.
roentgen b75cab
You must use these routines in order to have the extended tag handlers
roentgen b75cab
installed. Once installed, the standard TIFFGetField() and TIFFSetField
roentgen b75cab
routines may be used as before.
roentgen b75cab
roentgen b75cab
Adding Extended Tags to "tools"
roentgen b75cab
-------------------------------
roentgen b75cab
To create an extended-tag savvy "tiffinfo" program or other utility, you may
roentgen b75cab
simply recompile and link the tools to your "libxtiff" library, adding 
roentgen b75cab
roentgen b75cab
   -DTIFFOpen=XTIFFOpen -DTIFFClose=XTIFFClose -DTIFFFdOpen=XTIFFFdOpen
roentgen b75cab
roentgen b75cab
to the compile statement.
roentgen b75cab
roentgen b75cab
Bugs, Comments Etc:
roentgen b75cab
------------------
roentgen b75cab
 Send all reports and suggestions to ndr@tazboy.jpl.nasa.gov
roentgen b75cab
 (Niles Ritter).