2006.06.07 11:39 "[Tiff] Editing a tiff image using libtiff", by Sachin Garg

2006.06.12 13:59 "Re: [Tiff] Editing a tiff image using libtiff", by Sachin Garg

On 6/7/06, Joris <joris.at.lebbeke@skynet.be> wrote:

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.

Thanks Joris, your understanding of the question is correct. My primary concern is changed tile size. (Image size etc will stay the same.)

Appending is a good option, but will waste space and it does changes the order of blocks/tags.

My assumption here is that users might expect that a program doing minor edits will not restructure the entire file. (Imagine a huge tiff image where someone has saved the tiles in an order which minimize seeking etc... like in pyramidal tiffs.) I could be wrong in assuming that people might be structuring tiff images as per their requirements, I myself haven't worked on such applications.

To maintain the order, I am just a bit overwhelmed by the complexity of having to update offsets of the all tags/values after the changed tile. Is it actually hard or is it just me? It will be really great if this can be possible using libtiff.

Sachin Garg [India]
www.sachingarg.com | www.c10n.info