2000.03.28 18:37 "problem writting TIFF in Red Hat 6.1", by Thad Humphries

I'm using the libtiff.a that installs with Red Hat 6.1. I'm experiencing a failure writing a TIFF file when the same routine works with libtiff.a on Solaris. Both platforms use version 3.4 (according to the VERSION files).

The application method that is failing is shown below. It opens a file which contains some image data (bgimageRec), including TIFF data of COMPRESSION_CCITTFAX4. This is copied into a buffer with a memcpy() (buried in my ReadData() method) and then writes it to tif with TIFFWriteRawStrip(). The data is always bigendian

The problem is that when I call TIFFClose(tif), the Linux application quits (although I don't see a core file). The partial file that results is **exactly** the same as the TIFF created in Solaris *except* (1) the value of the offset of the first IFD is zero; and (2) the IFD is not written to the end of the file.

Any help or insight is greatly appreciated.

---------------- code follows ----------------
CCOLDTextApp::WriteTIFF (
        const char                      * filename,
        const FormBackgroundRec           bgimageRec,
        CDataStream                       formDataStream )
        TIFF    * tif = TIFFOpen( filename, "wb" );

        if ( tif != NULL )
                uint16    w = bgimageRec.pixWidth,
                          h = bgimageRec.pixLength;

                // Fields for all TIFF files.
                TIFFSetField( tif, TIFFTAG_IMAGEWIDTH, w );
                TIFFSetField( tif, TIFFTAG_IMAGELENGTH, h );


                TIFFSetField( tif, TIFFTAG_XRESOLUTION, (float)bgimageRec.resolution );
                TIFFSetField( tif, TIFFTAG_YRESOLUTION, (float)bgimageRec.resolution );

                // Called only for one bit images.
                TIFFSetField( tif, TIFFTAG_SAMPLESPERPIXEL, 1 );
                TIFFSetField( tif, TIFFTAG_BITSPERSAMPLE, 1 );

                // Required by libtiff.a

                // Other fields.
                TIFFSetField( tif, TIFFTAG_ROWSPERSTRIP, h );

                // The image itself.
                tdata_t         buf = _TIFFmalloc( bgimageRec.backLen );
                if ( buf == NULL )
                        TIFFClose( tif );
                        return kScanlineMallocErr;

                formDataStream.ReadData( buf, bgimageRec.backLen );

                tsize_t         result = TIFFWriteRawStrip( tif, 0, buf, bgimageRec.backLen );

                if ( result != bgimageRec.backLen )
                        _TIFFfree( buf );
                        TIFFClose( tif );
                        return -666;

                _TIFFfree( buf );
                TIFFClose( tif );
                return kTIFFOpenErr;

        return 0;
---------------- end of code ----------------

Thad Humphries                        "Who is this that darkens my counsel
Web Development Lead                   With words without knowledge?"
Phone: 540/675-3015, ext. 225                              - Job 38:1, NIV