2023.04.12 15:14 "[Tiff] TIffWriteDirectory() causes problems", by David C. Partridge
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.
// Go back to the first (main) directory, and set correct value of the
// EXIFIFD pointer. Note that the directory is reloaded from the file!
TIFFSetField(m_tiff, TIFFTAG_EXIFIFD, dir_offset_EXIF);
m_tiff = nullptr;
m_tiff should still be valid on exit
I also have code to write the image data:
Which starts like:
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
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