title: Speed up writing multiple image TIFF?
body: <p>I'm trying to write stacks of images to TIFF files. The images are of size 256*256 pixels, each stack containing 1000 images. Writing one of those files takes about 4 minutes - so there's most likely something wrong with my code.</p>
  
  <p>Here's what I'm doing:</p>
  
  <pre><code>void Tiff_WriterSplit(float data[], int PicNum, int WIDTH, int LENGTH, char PATH[]) {
       int i;
       int rows = LENGTH, columns = WIDTH;
       TIFF* tif;
  
       if (PicNum == 0)
           tif = TIFFOpen(PATH, "w");
       else
           tif = TIFFOpen(PATH, "a");
  
       TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, columns);
       TIFFSetField(tif, TIFFTAG_IMAGELENGTH, rows);
       TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 1);
       TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 32);
       TIFFSetField(tif, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_IEEEFP);
  
       for (i = 0; i &lt; rows; i++)
           TIFFWriteScanline(tif, &amp;data[i * columns], i, 0);
  
       TIFFWriteDirectory(tif);
       TIFFClose(tif);
  }
  </code></pre>
  
  <p>This function <code>Tiff_WriterSplit</code> will be called for each image of the stack. The first image will have <code>PicNum = 0</code> to open the tiff file in <code>w</code> mode, all the following images will have a <code>PicNum &gt; 0</code> to open it in <code>a</code> mode. Writing this starts at about 40 MB/s and gets slower and slower with increasing filesize - down to about 1 MB/s. How can I optimize the performance?</p>