2010.08.20 08:16 "[Tiff] TIFFWriteScanline works on Windows and Linux but fails on Mac", by Dennis_Mølhom_Hansen

2010.08.23 10:18 "Re: [Tiff] TIFFWriteScanline works on Windows and Linux but fails on Mac", by Dennis_Mølhom_Hansen

Update: any compression seems to fail on mac, only uncompressed work. Any ideas where to look for a cause/solution?

2010/8/23 Dennis Mølhom Hansen <molholm@gmail.com>:

I have narrowed down my problem a bit, first I found that the following is needed on Mac:

TIFFSetField(tiffImage, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);

Even though the tif spec. clearly stats that: "If SamplesPerPixel is 1, PlanarConfiguration is irrelevant, and need not be included."

Futhermore, i'm now able to save my image correct if I do not use compression. But I needed LWZ compression, any ideas why TIFFSetField(tiffImage, TIFFTAG_COMPRESSION, COMPRESSION_LZW); make TIFFWriteScanline fail?

2010/8/20 Dennis Mølhom Hansen <molholm@gmail.com>:

I use libtiff3.9.4 for reading and writing TIFF files in c++ on mac 10.6.4. My project is written to be portable and runs without any issues on both Windows 32-bit og Ubuntu 64-bit. But on the mac the Libtiff function TIFFWriteScanline always fails (it returns != 1). The

>> TIFF file is created, but it does not have any contents. I'am able to

read the LZW compressed images but i'm not able to write it. Furthermore the program also works for CCITT Group4 images on windows and linux, but read scanline fails on the mac.

I have tried both libtiff3.8.2 and libtiff4.0.0beta6 without any luck.

Any ideas why libtiff won't write scanlines on the mac when it works fine on linux?

Code:

// set baseline tags
TIFFSetField(tiffImage, TIFFTAG_IMAGEWIDTH, 7368);

TIFFSetField(tiffImage, TIFFTAG_IMAGELENGTH, 4757);

TIFFSetField(tiffImage, TIFFTAG_BITSPERSAMPLE, 8);

TIFFSetField(tiffImage, TIFFTAG_SAMPLESPERPIXEL, 1);

TIFFSetField(tiffImage, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);

TIFFSetField(tiffImage, TIFFTAG_COMPRESSION, COMPRESSION_LZW);

TIFFSetField(tiffImage, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);

TIFFSetField(tiffImage, TIFFTAG_THRESHHOLDING, 1);

TIFFSetField(tiffImage, TIFFTAG_XRESOLUTION, 400;

TIFFSetField(tiffImage, TIFFTAG_YRESOLUTION, 400);

TIFFSetField(tiffImage, TIFFTAG_RESOLUTIONUNIT, 2);

>> uint32  rowsPerStrip;

rowsPerStrip = tiffData->height;

rowsPerStrip = TIFFDefaultStripSize(tiffImage, rowsPerStrip); TIFFSetField(tiffImage, TIFFTAG_ROWSPERSTRIP, rowsPerStrip); TIFFSetupStrips(tiffImage);

// row buffer
scanlineSize = TIFFScanlineSize(tiffImage);
scanline = (unsigned char*) _TIFFmalloc(scanlineSize);

// write image
for (int i = 0; i < iplImage->height; i++)
{

>>   memcpy(scanline, iplImage->imageData + iplImage->widthStep*i, scanlineSize); >>   if(TIFFWriteScanline(tiffImage, scanline, i, 0) != 1){

>>      //Error
>>   }

}

// clean up
_TIFFfree(scanline);

Regards,
Dennis