2011.09.15 12:36 "Re: [Tiff] TIFFOpen fails on file with large image size.", by John

2011.09.15 11:08 "Re: [Tiff] TIFFOpen fails on file with large image size.", by DonM

Please reply to the list.

From: shlem@netvision.net.il

> Why TIFFWriteEncodedStrip() if you don't use compression?

> Try to use TIFFWriteRawStrip

The same thing happens with TiffWriteRawStrip. If I write the entire image as a single strip, I can write 100 frames in 0.1 secs. If I write the image as two strips, it takes 2.1 secs to write 100 frames (20x slower). When I try to open the single strip file, TIFFOpen crashes.

Don

>
> -----Original Message----- From: DonM
> Sent: Thursday, September 15, 2011 04:19
> To: tiff@lists.maptools.org

> Subject: [Tiff] TIFFOpen fails on file with large image size.

I am writing files using TiffWriteEncodedStrip where I write the entire image as one strip. I want to do this because it is significantly faster than writing images with multiple strips -- about 4X in my testing. I am capturing frames from a camera at 40 fps now and faster in the future so write performance is an issue.

I am able to write such files, and I can open them in a viewer (Irfanview). However, when I try to open these files myself, my application crashes in TIFFOpen. The call stack at the time of the crash seems to be corrupted. The last valid entry looks to be TiffReadDirectory, but from there it goes a little haywire. The actual crash is an assert in _fstat64.

If I change the writing to write two strips instead of 1, I have no problem opening and reading the file, but the write is about 4 times slower.

My images are 800 x 800 x 2 bytes (16 bit monochrome). I am running under Win7, VC++ 2008,32 bit, non-unicode. I have tested with both libtiff 4.0 and 3.9.5, and had the same results.

My write code looks like this:

int width = 800;

int height = 800;

int depth=2;
TIFF* tif = TIFFOpen("testimage.tiff", "w");
if (tif)
{
        for (int i=0; i<framecount; i++)

{

      TIFFSetField (tif, TIFFTAG_IMAGEWIDTH, width);
      TIFFSetField (tif, TIFFTAG_IMAGELENGTH, height);

TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8*depth);

TIFFSetField (tif, TIFFTAG_SAMPLESPERPIXEL, 1);
      TIFFSetField (tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
      TIFFSetField (tif, TIFFTAG_FILLORDER, FILLORDER_MSB2LSB);
      TIFFSetField (tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
      TIFFSetField (tif, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
      TIFFSetField (tif, TIFFTAG_ROWSPERSTRIP, height);

                        n = TIFFWriteEncodedStrip(tif, 0, pBuffer, width*height*depth);
                        n = TIFFWriteDirectory(tif);

}

  TIFFClose(tif);

}

I tried changing to 8 bit depth, and still had the problem. I have also tried smaller image sizes, and still had the problem. So it doesn't appear to be an overall size issue, but rather only having one strip.

Any suggestions for what I could do to fix or work around this?