2012.09.06 17:10 "Re: [Tiff] Managing the buffer", by John
On 6 September 2012 16:30, <Robert.Atwood@diamond.ac.uk> wrote:
I would like (for complicated reasons) to write a large number of TIFF images that are the same size. I wish to have a pre-allocated buffer and not allocate a new buffer each time I want to write an image.
The simplest solution is probably something like this:
- allocate large memory buffer p for image
- for each image to be written:
---- update the memory buffer p with the pixels you want to write
---- tif = TIFFOpen (filename, "w")
---- TIFFSetField (tif, TIFFTAG_IMAGEWIDTH, width);
---- etc. for the rest of the header
---- for y = 0; y < height; y++:
-------- TIFFWriteScanline (tif, p + y * sizeof (line), y, 0 );
---- TIFFClose (tif)
Something like that will have no trouble at all saturating your disc write.
You could also use a higher-level library to do the writing for you, but of course that adds another dependency which you might want to avoid. For example, vips (my library) would hide some of the detail for you.