2018.01.19 15:34 "[Tiff] Modifying field values without rewriting the whole directory", by

2018.01.19 15:34 "[Tiff] Modifying field values without rewriting the whole directory", by

Is it possible to make small edits to the field values within a directory without doing an expensive rewrite of the entire directory contents? That is, with the libtiff API (it's fairly easy to manually edit it with my own code, but a bit hairier than I'd like and I'd like to make use of the existing libtiff functionality where possible). I don't want to add any extra fields, rather to modify some already existing values in-place.

#include <tiff.h>
#include <tiffio.h>

int main()
{
   auto tiff = TIFFOpen("test.tiff", "r+");
   TIFFSetField(tiff, TIFFTAG_XRESOLUTION, 100.0);
   TIFFSetField(tiff, TIFFTAG_YRESOLUTION, 200.0);
   TIFFCheckpointDirectory(tiff); // or TIFFRewriteDirectory(tiff)
   TIFFClose(tiff);
}

This works, but I'm getting a whole new directly created, which I would prefer to avoid. While in this case I'm changing some trivial values, it would also be useful to update e.g. SUBIFD tags when appending reduced versions of images to the file. I don't want to copy all the tile offsets+sizes and all the other metadata, just a single offset. Similarly for updating the image description, where I can append the string to the file and update the pointer to it.

Thanks,

Roger