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.23 02:24 "Re: JPEG'd TIFF problems on Mac", by Li Xiangfeng

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

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

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~