AWARE SYSTEMS
TIFF and LibTiff Mail List Archive

Thread

2005.08.02 22:39 "[Tiff] Unable to read TIFF Directory", by David Abrames
2005.08.03 14:17 "Re: [Tiff] Unable to read TIFF Directory", by Andrey Kiselev
2005.08.03 17:02 "Re: [Tiff] Unable to read TIFF Directory", by David Abrames
2005.08.03 21:03 "Re: [Tiff] Unable to read TIFF Directory", by David Abrames

2005.08.03 17:02 "Re: [Tiff] Unable to read TIFF Directory", by David Abrames

On Tue, Aug 02, 2005 at 06:39:16PM -0400, David Abrames wrote:

I am getting the following error when I call the TIFFReadDirectory function:

*** TIFF ERROR in module: INTERNAL: No space to read TIFF directory.

This seems to be the result of a failure to allocate memory from a call to TIFFMalloc. The problem is as far as I can determine I have more than enough memory available as other calls to malloc work OK in the program that is calling the libtiff functions.

What I am doing is reading one multi-directory tiff file, updating the directory image and then creating a new directory and writing it to a new multi-directory tiff file.. The first directory is processed OK and I get a new tiff file with the one directory init. However the loop that is processing the tiff file is unable to read the next directory and produces the above error message.

Is there a TIFF function I need to call before calling TIFFReadDirectory to release the previous directory? I also tried TIFFSetDirectory and get the same results. Any suggestions would be appreciated.

You should use TIFFWriteDirectory() before switching to the next IFD. If you want open partially written file use TIFFCheckpointDirectory() instead.

Dear Andrey,

Thank you for your reply. Sorry I was not clear but I am calling TIFFWriteDirectory prior to calling TIFFReadDirectory. Here is a sample of what I am doing...

inTIFF = TIFFOpen("myTIFFfile", "r");
outTiff = TIFFOpen(myNewTiff", "w");

do
{
  getTIFFInfo(inTiff); // reads the directory tags

  setTIFFInfo(outTiff); // sets the directory tags
                         // from previous function

  image = getBitMap(inTiff); // uses TIFFReadEncodedStrip
                              // to build a bitmap image

  processImage(image); // processes the image

  createStrips(outTiff, image); // uses TIFFWriteEncodedStrip
                                 // to convert bitmap into strips
                                 // in the new directory of the
                                 // output tiff file

  TIFFWriteDirectory(outTiff);

} while(TIFFReadDirectory(inTiff));

TIFFClose(inTiff);
TIFFClose(outTiff);

The error message is caused by the call to TIFFReadDirectory in the while statement. Like I said I am getting the first directory (page) in the output tiff file and it is processed as I expect so the code is working up to the point where I try and get the next directory. I tried changing the TIFFReadDirectory to a TIFFSetDirectory and this produces the same error. I also tried to call malloc after the do-while loop and was able to allocate 1MB of memory successfully so I don't understand why libtiff thinks there is no space. I am sure I am missing something but I can't figure out what.

David