Message-ID: v03130309b506a420a44e@[198.206.216.113]
To: TIFF Mailing List <tiff@olympiakos.com>
Subject: problem writting TIFF in Red Hat 6.1
From: Thad Humphries <thad@mindwrap.com>
Date: Tue, 28 Mar 2000 13:37:55 -0500
Sender: owner-tiff@olympiakos.com


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 ----------------
Int32
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_COMPRESSION,
COMPRESSION_CCITTFAX4 );

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

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

                // Required by libtiff.a
                TIFFSetField( tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG );

                // 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 );
        }
        else
        {
                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



