2018.06.29 10:08 "[Tiff] Writing tiles out of order", by Roger Leigh

2018.06.29 10:27 "Re: [Tiff] Writing tiles out of order", by Even Rouault

On vendredi 29 juin 2018 11:08:00 CEST Roger Leigh wrote:

Right now I'm using libtiff to write tiled images completely in order: each tile of each plane in ascending order, adding new IFDs as needed. One of my users has asked if it's possible to stripe writes across directories. That is, for example, to write Tile 0 of IFDs 0-12, then Tile 1 of IFDs 0-12 etc.

Looking at the API, it's possible to visit previously written IFDs, but you have to call TIFFRewriteIFD, which gets expensive to duplicate when you have 10k-100k tiles per image and will be rewriting that many times over. If I reopen an old IFD and then call TIFFWrite*Tile, should I expect this to work, and update the existing IFD tile offsets+sizes in place, or is this strictly forbidden?

Update in place, and switching between IFD, works. GDAL does this in some scenarios. But as you pointed, if your IFD have many tiles/strips, loading and rewriting the offset and bytecount arrays each time you switch from IFD can be time expensive.

If performance is terrible, what you could potentially do is create the structure of the TIFF (ie all IFDs but without writing any tile/strip), close it, and then re-open it in update mode as many times as you have IFDs, and use a given TIF handle for a given IFD. Multiple handles in update on the same file is probably to be considered undefined behaviour, but I believe (untested though !) that given the current implementation of libtiff, that should work, since it uses TIFFSeekFile(tif, 0, SEEK_END) to get the offset of a new tile/ strip (assuming the implementation of seek() you use actually seeks to the file, and doesn't cache the file size). Of course, do not write in a multi- treaded way...

Even

--
Spatialys - Geospatial professional services
http://www.spatialys.com