home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / Libraries / VideoToolbox 95.04.18 / VideoToolboxSources / PixMapToPICT.Old.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-17  |  1.9 KB  |  64 lines  |  [TEXT/MMCC]

  1. /*
  2. PixMapToPICT.c
  3. Saves a section of a PixMap as a PICT file.
  4.  
  5. HISTORY:
  6. 9/28/93    mike schechter wrote it, based in part on PixMapToPostScript.c
  7. 9/29/93    dgp polished it, substituting a GWorld for a CPort, so that a
  8.             custom GDevice will be used, instead of whatever is current,
  9.             so we'll preserve our current pixel size and color table.
  10. */
  11.  
  12. #include "VideoToolbox.h"
  13.  
  14. void PixMapToPICT(char *filename,PixMap **pm,Rect *rectPtr
  15.     ,int pixelSize,ColorTable **cTable)
  16. {
  17.     FILE *file;
  18.     long buffer[128],n,value;
  19.     short error;
  20.     PicHandle pic;
  21.     CGrafPtr oldPort;
  22.     GDHandle oldDevice;
  23.     int i;
  24.     GWorldPtr world;
  25.     
  26.     pixelSize;    cTable;    // prevent "unused argument" warning
  27.     Gestalt(gestaltQuickdrawVersion,&value);
  28.     if(value<gestalt32BitQD)
  29.         PrintfExit("Sorry. PixMapToPICT requires 32-bit QuickDraw.\n");
  30.  
  31. /* draw pixmap into a Picture */
  32.     GetGWorld(&oldPort,&oldDevice);
  33.     error=NewGWorld(&world,(**pm).pixelSize,rectPtr,(**pm).pmTable,NULL,0);
  34.     if(error)PrintfExit("PixMapToPICT: NewGWorld error %d.\n",error);
  35.     SetGWorld(world,NULL);
  36.     LockPixels(world->portPixMap);
  37.     ClipRect(rectPtr);
  38.     pic=OpenPicture(rectPtr);
  39.     EraseRect(rectPtr);
  40.     CopyBits((BitMap *)*pm,(BitMap *)*world->portPixMap
  41.         ,rectPtr,rectPtr,srcCopy,NULL);
  42.     ClosePicture();
  43.     SetGWorld(oldPort,oldDevice);
  44.     DisposeGWorld(world);
  45.     if(EmptyRect(&(*pic)->picFrame))PrintfExit("PixMapToPICT: out of memory.\n");
  46.     
  47. /* save Picture to a file */
  48.     file=fopen(filename,"wb");
  49.     if(file==NULL)PrintfExit("PixMapToPICT: Error in opening file \"%s\".\n"
  50.         ,filename);
  51.     /* zero 512-byte header */
  52.     for(i=0;i<128;i++) buffer[i]=0;
  53.     if(128!=fwrite(buffer,4,128,file))
  54.         PrintfExit("PixMapToPICT: Error writing header of file \"%s\".\n",filename);
  55.     n=GetHandleSize((Handle)pic);
  56.     if(n&1 !=0)n++;    /* pad to even length */
  57.     if(n!=fwrite(*pic,1,n,file))
  58.         PrintfExit("PixMapToPICT: Error writing file \"%s\"\n",filename);
  59.     fclose(file);
  60.     SetFileInfo(filename,'PICT','ttxt');
  61.     KillPicture(pic);
  62. }
  63.  
  64.