2004.02.06 19:21 "[Tiff] problem with group 4 compression", by Thomas Elsner

2004.02.06 19:21 "[Tiff] problem with group 4 compression", by Thomas Elsner

Hello,

I ve got a problem with using the library function TIFFWriteEncodedStrip. I use version 3.6.1 of libtiff under Windows NT with the compiler lcc-win32 from Nov 2003. I did some experiments with the example at http://www-106.ibm.com/developerworks/linux/library/l-libtiff/

The problem is: wangimg.exe under WinNT cannot read the image in most cases. irfanview (i_view32.exe) can, but has sometimes problems. If I read a "damaged" Group 4 with irfanview and export it there again as a Group 4, the new file can be read with wangimg.exe. How can I solve this problem?

In the appendix there are two (small) files: outputIRFAN.tif is the "corrupted" file, but converted with IRFAN. Before that the file has the incredible size of 1.18MByte. outputOK.tif shows, how the content should be.

The code I used is listed below.

 TIFF *image;
  // Open the TIFF file
  if((image = TIFFOpen("output.tif", "w")) == NULL){
    printf("Could not open output.tif for writing\n");
    exit(42);
  }

  // We need to set some values for basic tags before we can add any data
  TIFFSetField(image, TIFFTAG_SUBFILETYPE, 0);


  TIFFSetField(image, TIFFTAG_IMAGEWIDTH, 25 * 8);
  TIFFSetField(image, TIFFTAG_IMAGELENGTH, 144);
  TIFFSetField(image, TIFFTAG_BITSPERSAMPLE, 1);
  TIFFSetField(image, TIFFTAG_SAMPLESPERPIXEL, 1);
//  TIFFSetField(image, TIFFTAG_ROWSPERSTRIP, 144);
  TIFFSetField(image, TIFFTAG_ROWSPERSTRIP, 73);

  TIFFSetField(image, TIFFTAG_COMPRESSION, COMPRESSION_CCITTFAX4);
  TIFFSetField(image, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISWHITE);
  TIFFSetField(image, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);

  TIFFSetField(image, TIFFTAG_XRESOLUTION, 150.0);
  TIFFSetField(image, TIFFTAG_YRESOLUTION, 150.0);
  TIFFSetField(image, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH);

  TIFFWriteEncodedStrip(image, 0, buffer, 25 * 73);
  TIFFWriteEncodedStrip(image, 1, buffer, 25 * 71);


  // Close the file
  TIFFClose(image);
return(0);

Many thanks in advance.