Hi David

 

The TIFF documentation of TIFF WriteDirectory() says: 

"
<http://www.simplesystems.org/libtiff/functions/TIFFWriteDirectory.html#c.TI
FFWriteDirectory> TIFFWriteDirectory() will write the contents of the
current directory (IFD) to the file and setup to create a new directory
(IFD) using
<http://www.simplesystems.org/libtiff/functions/TIFFCreateDirectory.html#c.T
IFFCreateDirectory> TIFFCreateDirectory(). "

 

This means that then m_tiff points to a new, empty directory and therefore
TiffScanlineSize() returns zero.

 

If you want to go back to the previously written IFD you have to use
TIFFSetDirectory(m_tiff, dirnumber), which re-reads the IFD (dirnumber) from
file.

Or you could first write the image data straight after "TIFFSetField(m_tiff,
TIFFTAG_EXIFID, dir_offset_EXIF);" and then call TIFFWriteDirectory() just
before TIFFClose().

 

Regards

Su

 

Von: Tiff [mailto:[email protected]] Im Auftrag von David C.
Partridge
Gesendet: Mittwoch, 12. April 2023 17:14
An: [email protected]
Betreff: [Tiff] TIffWriteDirectory() causes problems

 

So the code I have to open a TIFF file ends as follows:

                    //

                    // Now that all the EXIF tags are written, need to write
the EXIF

                    // custom directory into the file...

                    // 

                    // WriteCustomDirectory returns the actual offset of the
EXIF directory.

                    //

                    TIFFWriteCustomDirectory(m_tiff, &dir_offset_EXIF);

 

                    // Go back to the first (main) directory, and set
correct value of the

                    // EXIFIFD pointer. Note that the directory is reloaded
from the file!

                    //

                    TIFFSetDirectory(m_tiff, 0);

                    TIFFSetField(m_tiff, TIFFTAG_EXIFIFD, dir_offset_EXIF);

 

             }

             else

             {

                    TIFFClose(m_tiff);

                    m_tiff = nullptr;

             };

       };

 

       return bResult;

};

m_tiff should still be valid on exit

I also have code to write the image data:

Which starts like:

bool CTIFFWriter::Write()

{

       ZFUNCTRACE_RUNTIME();

       bool         bResult = false;

       bool         bError = false;

 

       //

    // Multipliers of 256.0 and 65536.0 were not correct and resulted in a
fully saturated

       // pixel being written with a value of zero because the value
overflowed the data type 

       // which was being stored.   Change the code to use UCHAR_MAX and
USHRT_MAX

       //

 

       if (m_tiff)

       {

             tmsize_t            scanLineSize;

             tdata_t                   buff;

 

             scanLineSize = TIFFScanlineSize(m_tiff);

That works but ends up with the root IFD being written at the end of the
file what TIFFClose calls TIFFReWriteDirectory().

If I insert TIFFWriteDIrectory(m_tiff); immediately after the line that
reads TIFFSetField(m_tiff, TIFFTAG_EXIFID, dir_offset_EXIF);

 

then when I call into Write the value returned by TiffScanlinesSize() is
ZERO!

WHY is that and what can/should it do to fix this

 

Thanks, David 

 

_______________________________________________
Tiff mailing list
[email protected]
https://lists.osgeo.org/mailman/listinfo/tiff

Reply via email to