Discussion:
Unable to read TIFF Directory
David Abrames
2005-08-02 22:39:16 UTC
Permalink
Hello,

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.

Thank you in advance
David Abrames
Andrey Kiselev
2005-08-03 14:17:09 UTC
Permalink
Post by David Abrames
*** 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.

Regards,
Andrey
--
Andrey V. Kiselev
Home phone: +7 812 5970603 ICQ# 26871517
_______________________________________________
Tiff mailing list: ***@lists.maptools.org
http://lists.maptools.org/mailman/listinfo/tiff
http://www.remotesensing.org/libtiff/
David Abrames
2005-08-03 17:02:29 UTC
Permalink
Post by Andrey Kiselev
Post by David Abrames
I am getting the following error when I call the TIFFReadDirectory
*** 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.
Regards,
Andrey
--
Andrey V. Kiselev
Home phone: +7 812 5970603 ICQ# 26871517
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

_______________________________________________
Tiff mailing list: ***@lists.maptools.org
http://lists.maptools.org/mailman/listinfo/tiff
http://www.remotesensing.org/libtiff/
David Abrames
2005-08-03 21:03:00 UTC
Permalink
Hello,

OK I have some more information. I discovered that if I tried the simple
directory counting routine in the examples that it also fails on the
TIFFReadDirectory call. I am using the TIFFClientOpen to open the source
tiff as this resides in memory. So it appears that my problem may be
related to how I implemented the contrib/mfs code. Is there anyone that
used the contrib/mfs (memory file system) code? I placed printf statements
in the mfs routines and they do not seem to get called.

Regards
David

Continue reading on narkive:
Search results for 'Unable to read TIFF Directory' (Questions and Answers)
7
replies
Picture Resize Software?
started 2007-04-27 03:43:06 UTC
software
Loading...