2006.01.27 00:18 "Re: [Tiff] Dead directories after TIFFRewriteDirectory()", by Joris Van Damme
It might also be that there are copying programs that will carry along all existing tags (custom or otherwise) but libtiff is not very handy for this.
It may be best to mention the following four issues that complicate matters, last of which is common enough and makes matters difficult:
- Some tags violate the spec, in that their tag data holds offsets to places in the TIFF file outside of that tag data. The MakerNote tag inside EXIF IFDs often has this behaviour. Tags that violate the spec this way, and are blindly copied by code that doesn't properly understand the tag and compensates, are bound to cause trouble for code that does when exposed to 'defragmented' TIFFs.
- Actually, the 'old-style' JPEG scheme specified in the TIFF 6.0 spec, itself, violates this rule. Properly copying or 'defragmenting' old-style JPEG-in-TIFF data is a complicated matter. (This is part of why the old-style JPEG-in-TIFF scheme is abandonded. Anyone looking to JPEG compress inside TIFF should read Technote2 or specification supplement 2, see http://www.awaresystems.be/imaging/tiff/faq.html#q4.)
- A small handfull of tags are a valid exception to the rule. This includes the StripOffsets and TileOffsets tags. These need special handling.
- Most common issue, though, is the ambiguity of the LONG datatype inside TIFF. A tag with a LONG datatype can hold a 32bit value or array of 32bit values, but it can also contain an offset to a private IFD (or more uncommon, an array of offsets to private IFDs). Blindly copying it, assuming it's a normal 32bit value when it's not, can next cause trouble for code that understands the tag and goes looking for an IFD at a position that only made sense in the non-defragmented version of the file.
- Roland, if you have some funds for this, I am willing and able to build code that 'defragments' a TIFF file, but bear in mind the above issues and consider the fact that despite some magic solving these problems to some degree, one can never fully guarantee such code in all circumstances.
Joris Van Damme
info@awaresystems.be
http://www.awaresystems.be/
Download your free TIFF tag viewer for windows here:
http://www.awaresystems.be/imaging/tiff/astifftagviewer.html