AWARE SYSTEMS
TIFF and LibTiff Mail List Archive

Thread

1999.04.22 20:54 "JPEG'd TIFF problems on Mac", by Eric Shapiro
1999.04.23 02:24 "Re: JPEG'd TIFF problems on Mac", by Li Xiangfeng
1999.04.23 02:59 "Re: JPEG'd TIFF problems on Mac", by Eric Shapiro
1999.04.23 14:20 "Re: JPEG'd TIFF problems on Mac", by Eric Shapiro
1999.04.23 18:43 "Re: JPEG'd TIFF problems on Mac", by Tom Lane
1999.04.24 14:50 "Re: JPEG'd TIFF problems on Mac", by Eric Shapiro
1999.04.24 14:53 "Re: JPEG'd TIFF problems on Mac", by Tom Lane
1999.04.24 15:20 "Re: JPEG'd TIFF problems on Mac", by Eric Shapiro

1999.04.22 20:54 "JPEG'd TIFF problems on Mac", by Eric Shapiro

I am still having problems writing JPEG'd TIFF files on a Mac.

My TIFF files have the directory shown below. The stripoffsets and stripbytecounts appear "interesting" and possibly wrong.

Does this problem look familiar to anyone?

I do not get an error writing the file, but I cannot read it back in and neither can Adobe ImageReady. The source code is also shown below.

Thanks!

Eric Shapiro
shapiro@relium.com

--------- the file directory ------------

Dumping TIFF file...
Magic Word= 'MM' (Motorola)
directory offset=$137e
numDirEntries=15
DirEntry (0): IMAGEWIDTH type=<short> count=1 value=$140 
DirEntry (1): IMAGELENGTH type=<short> count=1 value=$f0 
DirEntry (2): BITSPERSAMPLE type=<short> count=3 value=$8 8 8 
DirEntry (3): COMPRESSION=NEWJPEG type=<short> count=1 value=$7 
DirEntry (4): PHOTOMETRIC=YCBCR type=<short> count=1 value=$6 
DirEntry (5): STRIPOFFSETS type=<long> count=3 value=$8 0 0 
DirEntry (6): ORIENTATION=$1 type=<short> count=1 value=$1 
DirEntry (7): SAMPLESPERPIXEL=3 type=<short> count=1 value=$3 
DirEntry (8): STRIPBYTECOUNTS type=<long> count=3 value=$1375 0 0 
DirEntry (9): MINSAMPLEVALUE type=<short> count=3 value=$0 0 0 
DirEntry (10): MAXSAMPLEVALUE type=<short> count=3 value=$ff ff ff 
DirEntry (11): PLANARCONFIG=1 type=<short> count=1 value=$1 
DirEntry (12): TIFFTAG=305 type=<ascii> count=5 value=$0 1 0 ff 0 
DirEntry (13): JPEGTABLES type=<undef> count=574 value=$0 1 0 ff etc etc
DirEntry (14): REFERENCEBLACKWHITE=0 type=<rational> count=6
value=$100ff/ff0000[0.00393683] 0/91bf758[0] 92087c0/ab800008[0.0532191]
80/48a80[0.000430108] 920/81ecc001[1.07167e-06] 91bf7f0/8000[4663.94] 

---------- the source code (stripped a bit) ---------------

 theTIFF = TIFFFdOpen( fileID, "TIFFWriteTest", "w" );
 if ( theTIFF == 0 ) { DebugStr( "\pTIFFFdOpen failed." ); goto DONE; }
 fileID = 0;    // it now belongs to TIFF code
 
 TIFFSetField(theTIFF, TIFFTAG_COMPRESSION,COMPRESSION_JPEG);
 TIFFSetField(theTIFF, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_YCBCR);
 TIFFSetField(theTIFF, TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RGB);
 TIFFSetField(theTIFF, TIFFTAG_IMAGEWIDTH, kWidth);
 TIFFSetField(theTIFF, TIFFTAG_IMAGELENGTH, kHeight);
 TIFFSetField(theTIFF, TIFFTAG_BITSPERSAMPLE, 8);
 TIFFSetField(theTIFF, TIFFTAG_SAMPLESPERPIXEL, 3);
 TIFFSetField(theTIFF, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
 TIFFSetField(theTIFF, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
 TIFFSetField(theTIFF, TIFFTAG_SOFTWARE, "Spot");
 TIFFSetField(theTIFF, TIFFTAG_MINSAMPLEVALUE, 0);
 TIFFSetField(theTIFF, TIFFTAG_MAXSAMPLEVALUE, 255);
 
  // note: the gworld is already locked
 PixMapHandle theMap = GetGWorldPixMap( theWorld );
 int    rowBytes = (**theMap).rowBytes & 0x3FFF;
 unsigned char * sourceBuffer = (unsigned char*) GetPixBaseAddr( theMap );
 
 destRowBuffer = (unsigned char*) _TIFFmalloc( 3 * kWidth );
 if ( !destRowBuffer ) { DebugStr( "\pCan't allocate row buffer" ); goto
DONE; }
 
 for ( int rowCount = 0; rowCount < kHeight; rowCount++ )
 {
  unsigned char *destRowPtr = destRowBuffer;
  unsigned long *sourceRowPtr = (unsigned long*)( sourceBuffer + rowCount *
rowBytes );
  
  for ( int colCount = 0; colCount < kWidth; colCount++ )
  {
   unsigned long pixelValue = sourceRowPtr[ colCount ];
   
   *destRowPtr++ = (pixelValue >> 16) & 0xFF;
   *destRowPtr++ = (pixelValue >> 8) & 0xFF;
   *destRowPtr++ = (pixelValue & 0xFF);
  }
  
  if ( TIFFWriteScanline( theTIFF, destRowBuffer, rowCount, 0 ) < 0 )
  {
   DebugStr( "\pTIFFWriteScanline failed." );
   goto DONE;
  }
 }

 if ( TIFFWriteDirectory(theTIFF) == 0 )
 {
  DebugStr( "\pCan't write directory." );
  goto DONE;
 }