Status: Read
Received: from [207.113.13.68] by phillip.cerious.com (NTMail 3.03.0017/7.aaxh) with ESMTP id pcrews for <pcrews@cerious.com>; Thu, 22 Apr 1999 22:32:47 -0400
Received: from localhost (bin@localhost)
	by gate7.olympiakos.com (8.8.7/8.8.7) with SMTP id WAA27244;
	Thu, 22 Apr 1999 22:15:53 -0400
Received: by gate7.olympiakos.com (bulk_mailer v1.9); Thu, 22 Apr 1999 22:13:19 -0400
Received: (from majordom@localhost)
	by gate7.olympiakos.com (8.8.7/8.8.7) id WAA27180
	for tiff-outgoing; Thu, 22 Apr 1999 22:13:18 -0400
X-Authentication-Warning: gate7.olympiakos.com: majordom set sender to owner-tiff@olympiakos.com using -f
Received: from popo.canotec.co.jp (popo.canotec.co.jp [202.228.180.1])
	by gate7.olympiakos.com (8.8.7/8.8.7) with ESMTP id WAA27177
	for <tiff@olympiakos.com>; Thu, 22 Apr 1999 22:13:11 -0400
Received: from [192.168.1.192] (peko.canotec.co.jp [202.228.180.193]) by popo.canotec.co.jp (8.8.3/3.5W) with ESMTP id LAA24138 for <tiff@olympiakos.com>; Fri, 23 Apr 1999 11:12:22 +0900 (JST)
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
X-Sender: li_xiangfeng@canotec.co.jp
X-Mailer: Macintosh Eudora Pro Version 4.0.1J
Message-Id: <v04010500b345869721fe@canotec.co.jp>
In-Reply-To: <1287322349-160967783@private.relium.com>
Date: Fri, 23 Apr 1999 11:24:18 +0900
To: tiff@olympiakos.com
From: Li Xiangfeng <li_xiangfeng@canotec.co.jp>
Subject: Re: JPEG'd TIFF problems on Mac
Sender: owner-tiff@olympiakos.com


 I do not known what type of Macintosh you are using? 68K or PPC?
It seems
  1. QuickDraw mybe not 32 bits
  2. LockPixels is not used
  3. kHeight, KWIDTH mybe not correct
try it again with the following modification.
--------------------------------------------------------------------------

	 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 );

	 //check theMap
	 if(!theMap) {					//ADD by Li
	 	DebugStr( "\ptheMap == NULL !" ); 		//ADD by Li
	 	goto DONE; 				//ADD by Li
	 }						//ADD by Li

	 //check 32bit ?
	if((*theMap)->pixelSize != 32) {
	//ADD by Li
	 	DebugStr( "\pIf world isn't 32 bit, don't do anything !" );
	//ADD by Li
	 	goto DONE; 					//ADD by Li
	 }							//ADD by Li

	//lock  theMap !!!
	HLock((Handle)theMap);					//ADD by Li
	if(LockPixels(theMap)) {
	//ADD by Li
		DebugStr( "\pIf world isn't 32 bit, do nothing here !" );
	//ADD by Li
		goto DONE; 					//ADD by Li
	}							//ADD by Li

	unsigned char * sourceBuffer = (unsigned char*) GetPixBaseAddr(
theMap );

	//int    rowBytes = (**theMap).rowBytes & 0x3FFF;
	//ADD by Li
	int    rowBytes = (**theMap).rowBytes & 0x7FFF;
	//MOD by Li

	//get size
	short width = (**srcPixMap).bounds.right-(**srcPixMap).bounds.left;
	//ADD by Li
	short height = (**srcPixMap).bounds.bottom-(**srcPixMap).bounds.top;
	//ADD by Li

	// does kWidth <=  width
	//      kHeight <= height ?
	// if not, the following "for loop" seems something wrong ...


	 destRowBuffer = (unsigned char*) _TIFFmalloc( 3 * kWidth );
	 if ( !destRowBuffer ) {
	 	DebugStr( "\pCan't allocate row buffer" );
	 	goto DONE;
	 }

	//store MMU mode
	char mmuMode = true32b;					//ADD by Li
	SwapMMUMode(&mmuMode);					//ADD by Li


	 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;
		}
	}

	// Restore the previous MMU mode
	SwapMMUMode(&mmuMode);					//ADD by Li

	// unlock
	UnlockPixels(theMap);					//ADD by Li
	HUnlock((Handle)theMap);
	//ADD by Li


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

--------------------------------------------------------------------------

At 4:54 PM -0400 99.4.22, Eric Shapiro wrote:
>
> 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;
>  }

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Li Xiangfeng
Canotec Co., Inc.,
Product Development Section
Meisan-Takahama BLDG.,
12-23 Kounan 2-chome, Minato-ku,
Tokyo 108, Japan
TEL:+81-35-460-8740
FAX:+81-35-460-8751
e-mail:li_xiangfeng@canotec.co.jp
http://www.canotec.co.jp
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
