2006.05.25 17:24 "[Tiff] libtiff writes zero valued tile offsets and byte counts", by Thomas Sharpless

2006.06.08 18:44 "Re: [Tiff] libtiff writes zero valued tile offsets and byte counts", by Frank Warmerdam

My scanning camera app writes tiled tiff images using libtiff under Win32. The images

are readable by PhotoShop (6.01) but not by PaintShop Pro 7 or libtiff itself. The problem

seems to be that all the tile offsets and bytecounts in the file are zero (their number is

correct). Can anyone tell me why?

I creates the file thus:
    ptiff = TIFFOpen(OPFileName, "w");
    if( ptiff ) {

      TIFFSetField( ptiff, TIFFTAG_IMAGEWIDTH, pSC->img_cols );
      TIFFSetField( ptiff, TIFFTAG_IMAGELENGTH, pSC->img_rows );
      TIFFSetField( ptiff, TIFFTAG_COMPRESSION, 1 ); // uncompressed
      TIFFSetField( ptiff, TIFFTAG_PLANARCONFIG, 1 ); // contiguous
      TIFFSetField( ptiff, TIFFTAG_SAMPLESPERPIXEL, pSC->scn_cpp );

      if( pSC->scn_cpp == 1){   // greyscale

        TIFFSetField( ptiff, TIFFTAG_BITSPERSAMPLE, 8 * pSC->img_bpc );
        TIFFSetField( ptiff, TIFFTAG_PHOTOMETRIC, 1 ); // 0 is black
      } else { // RGB
        int n = 8 * pSC->img_bpc;
        TIFFSetField( ptiff, TIFFTAG_BITSPERSAMPLE, n, n, n );
        TIFFSetField( ptiff, TIFFTAG_PHOTOMETRIC, 2 ); // RGB
    // tile size
      TIFFSetField( ptiff, TIFFTAG_TILELENGTH, pTB->getHgt() );
      TIFFSetField( ptiff, TIFFTAG_TILEWIDTH, pTB->getWid() );
    // verify
      if (!TIFFCheckTile(ptiff, 0,0,0,0)) fail();

write each tile thus:
     if( TIFFWriteTile( ptiff, pdata, imgx, imgy, 0, 0 ) < 1 ) fail();

and call TIFFclose( ptiff ) at the end.


I don't see any obvious problem with the code you are showing. The normal conclusion with such a problem would be that either TIFFClose() didn't get called, or that you hadn't ever actually written out tiles, but had done something to flush out an empty directory (like a TIFFWriteCheck() and/or TIFFWriteDirectory()).

I don't know how Photoshop could read a file with all zero offsets and sizes for tiles. Sometimes I'm amazed at the amount of guessing applications will do to handle badly broken files.

Best regards,

I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam@pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam

and watch the world go round - Rush    | President OSGF, http://osgeo.org