home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Snippets / Extract PICT Colors / Extract.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-04  |  2.8 KB  |  105 lines  |  [TEXT/MMCC]

  1. /**********************************************************************************************
  2. This code shows how use the Picture Utilities Package to extract the colors from a PICT file. 
  3. Error checking will have to be added. Written by Steve Wagy, CIS 70471,1640.
  4. **********************************************************************************************/
  5.  
  6. /********************************************************************
  7.  Ported to Metrowerks CodeWarrior by Paul Celestin on 4 November 1994
  8.  ********************************************************************/
  9.  
  10. #include <Files.h>
  11. #include <PictUtil.h>
  12. #include <QuickDraw.h>
  13.  
  14. short            globalRef, numTypes;
  15. long            longCount, myEOF, filePos;         
  16. WindowRecord    wStorage;
  17. CQDProcs        myProcs;   
  18. CQDProcsPtr       savedProcs;
  19. Rect              myRect, rect;         
  20. OSErr              err;
  21. PicHandle         myPic;
  22. WindowPtr        myWindow;                          
  23. PaletteHandle    thePalette;        
  24. SFReply            reply;
  25. PictInfo        thePictInfo;
  26. Point            where;
  27. SFTypeList        typeList;
  28. short             lockerr;
  29.  
  30.  
  31. pascal void GetPICTData(Ptr dataPtr,int byteCount)
  32.     longCount = byteCount;
  33.     err = FSRead(globalRef,&longCount,dataPtr);
  34.  
  35.  
  36. main()
  37. {
  38.     ToolBoxInit();
  39.     Open();
  40. }
  41.  
  42.  
  43. ToolBoxInit()
  44. {
  45.     MaxApplZone();
  46.     MoreMasters();
  47.     MoreMasters();
  48.     InitGraf(&qd.thePort);
  49.     InitFonts();
  50.     FlushEvents(everyEvent,0);
  51.     InitWindows();
  52.     InitMenus();
  53.     TEInit();
  54.     InitDialogs(0L);
  55.     InitCursor();
  56. }
  57.  
  58.  
  59. Open()
  60. {    
  61.     where.h = 150;                
  62.     where.v = 120;
  63.     typeList[0] = 'PICT';
  64.     numTypes = 1;
  65.     
  66.     SFGetFile(where,"\p",0L,numTypes,typeList,0L,&reply);
  67.     if    (!reply.good)
  68.         return;
  69.     err = FSOpen(reply.fName,reply.vRefNum,&globalRef);
  70.     myPic = (PicHandle)NewHandle(sizeof(Picture));
  71.     err = SetFPos(globalRef,fsFromStart,512);
  72.     err = GetEOF(globalRef,&myEOF);
  73.     longCount = sizeof(Picture);
  74.     err = FSRead(globalRef,&longCount,*myPic);
  75.     rect = (*myPic)->picFrame;
  76.     myRect.top = rect.top + 20;
  77.     myRect.bottom = rect.bottom + 20;
  78.     myRect.left = rect.left;  
  79.     myRect.right = rect.right;
  80.     myWindow = NewCWindow(&wStorage,&myRect,reply.fName,true,2,(WindowPtr)(-1),false,0L);
  81.     SetPort(myWindow);
  82.     SetStdCProcs(&myProcs);  
  83.     myProcs.getPicProc = (QDGetPicUPP)GetPICTData;
  84.     savedProcs = (CQDProcsPtr)(*qd.thePort).grafProcs;
  85.     (*qd.thePort).grafProcs = (QDProcsPtr)&myProcs;
  86.     err = GetFPos(globalRef,&filePos);
  87.     err = GetPictInfo(myPic,&thePictInfo,returnColorTable,256,systemMethod,0);
  88.     err = SetFPos(globalRef,fsFromStart,filePos);
  89.     thePalette = NewPalette(256,thePictInfo.theColorTable,pmTolerant,0);
  90.     SetPalette(myWindow,thePalette,true);
  91.     DrawPicture(myPic,&myWindow->portRect);
  92.     err = FSClose(globalRef);
  93.     (*qd.thePort).grafProcs = (QDProcsPtr)savedProcs;
  94.  
  95.     while    (!Button());
  96.     CloseWindow(myWindow);
  97.     DisposeHandle((Handle)myPic);
  98.     DisposeHandle((Handle)thePictInfo.theColorTable);
  99.     DisposePalette(thePalette);
  100.     ExitToShell();
  101. }   
  102.  
  103.