home *** CD-ROM | disk | FTP | other *** search
/ QuickTime 2.0 Developer Kit / QuickTime 2.0 Developer Kit.iso / mac / MAC / Programming Stuff / Sample Code / Image Compression Mgr / Inside Mac ICM Code / icm5.c < prev    next >
Encoding:
Text File  |  1994-12-04  |  2.3 KB  |  98 lines  |  [TEXT/MPS ]

  1. /*
  2.   File:            icm5.c
  3.   Contains:        Sequence Play Functions
  4.   Written by:    DTS and QT Engineering
  5.   Copyright:    © 1992-1994 by Apple Computer, Inc., all rights reserved.
  6.   Change History (most recent first):
  7.   <1>         12/4/94    khs        changed the format of the file to the new look and feel
  8.   To Do:
  9. */
  10.  
  11.  
  12. // INCLUDE FILES 
  13. #include "icm.h"
  14.  
  15.  
  16. // FUNCTIONS
  17. void SequencePlay(void)
  18. {
  19.     ImageDescriptionHandle description;
  20.     long compressedSize;
  21.     Handle buffer = nil;
  22.     Ptr bufferAddr;
  23.     long dataLen;
  24.     long lastTicks;
  25.     ImageSequence sequenceID;
  26.     Rect imageRect;
  27.     StandardFileReply fileReply;
  28.     SFTypeList typeList =
  29.     {
  30.         'SEQU',  0, 0, 0
  31.     };
  32.     short dfRef = 0;                            // sequence data fork
  33.     short rfRef = 0;                            // sequence resource fork
  34.     OSErr error;
  35.  
  36.     StandardGetFile(nil, 1, typeList, &fileReply);
  37.     if (!fileReply.sfGood)
  38.         return;
  39.  
  40.     rfRef = FSpOpenResFile(&fileReply.sfFile, fsRdPerm);
  41.     CheckError(ResError(), "\pFSpOpenResFile");
  42.  
  43.     description = (ImageDescriptionHandle)Get1Resource('SEQU', 128);
  44.     CheckError(ResError(), "\pGet1Resource");
  45.  
  46.     DetachResource((Handle)description);
  47.     HNoPurge((Handle)description);
  48.     CloseResFile(rfRef);
  49.  
  50.     error = FSpOpenDF(&fileReply.sfFile, fsRdPerm, &dfRef);
  51.     CheckError(error, "\pFSpOpenDF");
  52.  
  53.     buffer = NewHandle(4);
  54.     CheckError(MemError(), "\pNewHandle buffer");
  55.  
  56.     SetRect(&imageRect, 0, 0, (**description).width, (**description).height);
  57.     error = DecompressSequenceBegin(&sequenceID, description, nil,// use the current port
  58.                                     nil,        // goto screen
  59.                                     &imageRect, nil,// no matrix
  60.                                     ditherCopy, nil,// no mask region
  61.                                     codecFlagUseImageBuffer, codecNormalQuality,// accuracy
  62.                                     (CompressorComponent)anyCodec);
  63.  
  64.     while (true)
  65.     {
  66.         dataLen = 4;
  67.         error = FSRead(dfRef, &dataLen, &compressedSize);
  68.         if (error == eofErr)
  69.             break;
  70.         CheckError(error, "\pFSRead");
  71.  
  72.         if (compressedSize > GetHandleSize(buffer))
  73.         {
  74.             HUnlock(buffer);
  75.             SetHandleSize(buffer, compressedSize);
  76.             CheckError(MemError(), "\pSetHandleSize");
  77.         }
  78.  
  79.         HLock(buffer);
  80.         bufferAddr = StripAddress(*buffer);
  81.         error = FSRead(dfRef, &compressedSize, bufferAddr);
  82.         CheckError(error, "\pFSRead");
  83.  
  84.         error = DecompressSequenceFrame(sequenceID, bufferAddr, 0,// flags
  85.                                         nil, nil);
  86.         CheckError(error, "\pDecompressSequenceFrame");
  87.  
  88.         Delay(30, &lastTicks);
  89.     }
  90.  
  91.     CDSequenceEnd(sequenceID);
  92.     FSClose(dfRef);
  93.     DisposeHandle(buffer);
  94.     DisposeHandle((Handle)description);
  95. }
  96.  
  97.  
  98.