Question

TIFFWriteScanline works on Windows and Linux but fails on Mac

Updated question:

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);
Was it helpful?

Solution 2

I moved this question to the LibTiff mailing list a long time ago, but i forgot to give the answer here, so here it is:

I inserted printf and modified some TiffError messages in the Libtiff code, and it turned out that these changes did not show anywhere when my program failed. After searching for at few hours i found that the built-in Libtiff library in OpenCV (libhighgui.dylib) was the cause of my headache. I know OpenCV uses Libtiff but I do not use the build-in version since it does not provide the full functionality of Libtiff. I reinstalled OpenCV2.1.0 without Libtiff and it solved the issue (it might just have been the order of the included dependencies that was causing trouble).

I'm now able to write LWZ compressed images. For more details see the LibTiff mailing list.

OTHER TIPS

It's hard to tell with the information you've given, but my best guess is that you compiled libtiff without support for the particular output format you are using.

Also, if TIFFWriteScanline returns -1, there should be an error message unless you have substituted your own error handler. This should be a useful clue as to what is going on.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top