2006.05.23 16:01 "[Tiff] Problems with image tiff Compression CCITT 1D in Windows NT", by Jeronimo Torres

2006.07.14 05:47 "Re: [Tiff] The problem of Convert tiff", by

Hi Joris:

  First,Thank for your reply.

    I convert Tiff  with LibTiff. I develop tiff for the Dialogic. The Dialogic require the tiff of TIFF/F class. So i must convert the all format of tiff  to   TIFF/F class.

  this is my code:

/////////////////////////////////////////////////////////////////////////
void CheckTiffToReeDaTif(CString szTiffPathName)
{
 char time_Buff[20];
 TIFF *image;
 TIFF *srcImage;
 CString strTempTiff,strTime;;
 LONG lv,wv,rowperstrip;
 long CurrentPage = GetTiffPageCount(szTiffPathName);;
 CTime ltime;
 LONG stripbytecount,stripoffset;
 image = TIFFOpen("C:\\ReedaSend_Temp.tiff", "w");

srcImage = TIFFOpen(szTiffPathName, "r");

TIFFGetField(srcImage, TIFFTAG_IMAGEWIDTH, &wv);
TIFFGetField(srcImage, TIFFTAG_IMAGELENGTH, &lv);
for (uint32 x =0;x<CurrentPage;x++) {
 int readResult =TIFFSetDirectory (srcImage, (tdir_t )x);
 if (readResult==0) break;
 ltime=CTime::GetCurrentTime();

strTime.Format("%d-%2d-%2d %2d:%2d:%2d",ltime.GetYear(),ltime.GetMonth(),ltime.GetDay(),ltime.GetHour(), ltime.GetMinute(), ltime.GetSecond()); TIFFSetField(image, TIFFTAG_SOFTWARE, "GlobalReeDa"); strcpy(time_Buff,strTime.GetBuffer(strTime.GetLength())); strTime.ReleaseBuffer(); time_Buff[20]='\0'; TIFFGetField(srcImage,TIFFTAG_ROWSPERSTRIP,&rowperstrip);

TIFFGetField(srcImage,TIFFTAG_STRIPOFFSETS,&stripoffset);

TIFFGetField(srcImage,TIFFTAG_STRIPBYTECOUNTS,&stripbytecount); TIFFSetField(image, TIFFTAG_DATETIME, time_Buff);

TIFFSetField(image, TIFFTAG_SUBFILETYPE, FILETYPE_PAGE);

TIFFSetField(image, TIFFTAG_IMAGEWIDTH, wv);

TIFFSetField(image, TIFFTAG_SAMPLESPERPIXEL, 1);

TIFFSetField(image, TIFFTAG_BITSPERSAMPLE, 1);

TIFFSetField(image, TIFFTAG_FILLORDER, FILLORDER_LSB2MSB);

TIFFSetField(image, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);

TIFFSetField(image, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISWHITE);

TIFFSetField(image, TIFFTAG_XRESOLUTION, 204.0);

TIFFSetField(image, TIFFTAG_YRESOLUTION, 196.0);

TIFFSetField(image, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH);

TIFFSetField(image, TIFFTAG_COMPRESSION, COMPRESSION_CCITTFAX3);

TIFFSetField(image, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);

TIFFSetField(image, TIFFTAG_GROUP3OPTIONS, 0);

TIFFSetField(image, TIFFTAG_FAXMODE, FAXMODE_CLASSF);

TIFFSetField(image, TIFFTAG_ROWSPERSTRIP,rowperstrip);

TIFFSetField(image, TIFFTAG_PAGENUMBER, x, CurrentPage); //TIFFSetField(image, TIFFTAG_PAGENUMBER, l_todalpages); TIFFSetField(image, TIFFTAG_IMAGELENGTH, lv);

TIFFSetField(image, TIFFTAG_BADFAXLINES, 0);

TIFFSetField(image, TIFFTAG_CLEANFAXDATA, CLEANFAXDATA_CLEAN); tsize_t stripsize = TIFFStripSize(srcImage);

tdata_t buf = _TIFFmalloc(stripsize);
uint32 rowsperstrip;

(void) TIFFGetFieldDefaulted(srcImage, TIFFTAG_ROWSPERSTRIP, &rowsperstrip); tstrip_t s, ns = TIFFNumberOfStrips(srcImage);

  uint32 row = 0;
  for (s = 0; s < ns; s++) {
   tsize_t cc = (row + rowsperstrip > lv)?
    TIFFVStripSize(srcImage, lv - row): stripsize;
   TIFFReadEncodedStrip(srcImage, s, buf, cc);
   if (TIFFWriteEncodedStrip(image, s, buf, cc) < 0) {
    _TIFFfree(buf);
   }
   row += rowsperstrip;
  }
  TIFFWriteDirectory(image);
  _TIFFfree(buf);
 }
 TIFFClose(srcImage);
 TIFFClose(image);
}

//////////////////////////////////////////////////////////////////////

----- Original Message -----
From: "Joris" <joris.at.lebbeke@skynet.be>
To: "<hotmail>xiaotiger666" <xiaotiger666@hotmail.com>; "tiff" <tiff@lists.maptools.org>
Sent: Friday, July 14, 2006 12:41 PM
Subject: Re: [Tiff] The problem of Convert tiff

Robert Zhang wrote:

After i convert a tiff of Wang Tiff to a tiff of TIFF/F Class, The converted tiff of TIFF/F Class cannot display in windows.

That doesn't necessarily mean the TIFFs bad. I've seen reports of the standard viewer in WinXP failing on legit TIFFs, and the Wang/Kodak thing that grew from (presumably) certainly isn't perfect either.

However, in this case, the converted TIFF is indeed bad as can be seen from the tagdump.

SamplesPerPixel (1 Short): 1

ImageLength (1 Short): 2272

RowsPerStrip (1 Short): 2272

This would imply a single-strip TIFF. But, looking at the StripOffsets and StripByteCounts tags...

StripByteCounts (16 Long): 1806, 2557, 7627, 4459, 7301,

StripOffsets (16 Long): 8, 1814, 4371, 11998, 16457,

...reveals there are 16 strips instead. The StripByteCounts look like they may indicate proper strips, given the ByteCounts of the strips in the original and the extend of the conversion. So my guess is possibly the RowsPerStrip value only is incorrect and might need to be 146 instead.

So you ought to be investigating a bug in the conversion code. Are you using LibTiff? If so, may be good to post the relevant code for us to look at.