2006.06.07 12:51 "Re: [Tiff] Editing a tiff image using libtiff", by Joris Van Damme
I am coding an application where I want to do a minor edit in a tiff image. The problem is that even a minor edit can change the compressed image size, and this will mean that all the offsets everywhere to all the tags/values after the compressed image data will have to updated.
afaik, libtiff rewrites the entire tiff image with the directory at the end. However in cases where a user might have structured a tiff file as per his specific requirements, such restructuring for a minor edit may be too much to ask.
I will like to be able to do this minor image edit while maintaining the existing tiff structure, but updating all the offsets seems an overwhelming task. Any suggestions on how I should tackle this situation?
I'm not sure what you mean by 'restructuring' or 'have structured a tiff'...
Are you refering to the order of the different data blocks? In that case, you're not talking about TIFF. There is no need for any specific order of data blocks in TIFF. Thus, you can hold on to any that you don't change in this 'minor edit' operation, and have the new IFD point to exactly those old locations. Any that do change, you can append to the file, or, if the new size does not exceed the old, write in the old location. Next, you can write an updated IFD, again, either appended to the file, taking care to update old offset at the end of previous IFD, or, if size of new IFD does not exceed old, you can overwrite the old IFD.
For example, suppose your minor edit operation does not affect image size or anything, but merely changes a single tile. You can compute the new tile size by pre-compressing it, worst case. If it fits the old space, it fits, and the only thing that need updating is one entry in the TileByteCounts tag. If it doesn't fit, append it, and the updating is limited to one entry in the TileOffsets and one entry in the TileByteCounts tag. This tag value or these tag values, can be changed in place, since their size does not change. Thus, neither does the IFD itself change, and you can leave that as it is.
Does this help? Or am I not understanding your question?
As to how to do this with LibTiff... That's another issue. But you seem to indicate you're not using LibTiff anyway.
Joris Van Damme
Download your free TIFF tag viewer for windows here: