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 / icm4.c < prev    next >
Encoding:
Text File  |  1994-12-04  |  2.9 KB  |  107 lines  |  [TEXT/MPS ]

  1. /*
  2.   File:            icm4.h
  3.   Contains:        Draw and Compress 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. // INCLUDES
  13. #include "icm.h"
  14.  
  15.  
  16. // FUNCTIONS
  17. void DrawFrame(const Rect* imageRect,
  18.                long frameNum)
  19. {
  20.     Str255 numStr;
  21.  
  22.     ForeColor(redColor);
  23.     PaintRect(imageRect);
  24.  
  25.     ForeColor(blueColor);
  26.     NumToString(frameNum, numStr);
  27.     MoveTo(imageRect->right / 2, imageRect->bottom / 2);
  28.     TextSize(imageRect->bottom / 3);
  29.     DrawString(numStr);
  30. }
  31.  
  32.  
  33. void CompressSequence(short* dfRef,
  34.                       ImageDescriptionHandle* description)
  35. {
  36.     GWorldPtr currWorld = nil;
  37.     PixMapHandle currPixMap;
  38.     CGrafPtr savedPort;
  39.     GDHandle savedDevice;
  40.     Handle buffer = nil;
  41.     Ptr bufferAddr;
  42.     long compressedSize;
  43.     long dataLen;
  44.     Rect imageRect;
  45.     ImageSequence sequenceID = 0;
  46.     short frameNum;
  47.     OSErr error;
  48.     CodecType codecKind = 'rle ';
  49.  
  50.     GetGWorld(&savedPort, &savedDevice);
  51.     imageRect = savedPort->portRect;
  52.     error = NewGWorld(&currWorld, 32, &imageRect, nil, nil, 0);
  53.     CheckError(error, "\pNewGWorld");
  54.     SetGWorld(currWorld, nil);
  55.  
  56.     currPixMap = currWorld->portPixMap;
  57.     LockPixels(currPixMap);
  58.  
  59.     //    allocate an embryonic image description structure and the
  60.     //    Image Compression Manager will resize
  61.     *description = (ImageDescriptionHandle)NewHandle(4);
  62.  
  63.     error = CompressSequenceBegin(&sequenceID, currPixMap, nil,// tell ICM to allocate previous image buffer
  64.                                   &imageRect, &imageRect, 0,// let ICM choose pixel depth
  65.                                   codecKind, (CompressorComponent)anyCodec, codecNormalQuality,// spatial quality 
  66.                                   codecNormalQuality,// temporal quality 
  67.                                   5,            // at least 1 key frame every 5 frames
  68.                                   nil,            // use default color table
  69.                                   codecFlagUpdatePrevious, *description);
  70.     CheckError(error, "\pCompressSequenceBegin");
  71.  
  72.     error = GetMaxCompressionSize(currPixMap, &imageRect, 0,// let ICM choose pixel depth
  73.                                   codecNormalQuality,// spatial quality 
  74.                                   codecKind, (CompressorComponent)anyCodec, &compressedSize);
  75.     CheckError(error, "\pGetMaxCompressionSize");
  76.  
  77.     buffer = NewHandle(compressedSize);
  78.     CheckError(MemError(), "\pNewHandle buffer");
  79.     MoveHHi(buffer);
  80.     HLock(buffer);
  81.     bufferAddr = StripAddress(*buffer);
  82.  
  83.     for (frameNum = 1; frameNum <= 10; frameNum++)
  84.     {
  85.         DrawFrame(&imageRect, frameNum);
  86.  
  87.         error = CompressSequenceFrame(sequenceID, currPixMap, &imageRect, codecFlagUpdatePrevious, bufferAddr, &compressedSize, nil, nil);
  88.         CheckError(error, "\pCompressSequenceFrame");
  89.  
  90.         dataLen = 4;
  91.         error = FSWrite(*dfRef, &dataLen, &compressedSize);
  92.         CheckError(error, "\pFSWrite length");
  93.  
  94.         error = FSWrite(*dfRef, &compressedSize, bufferAddr);
  95.         CheckError(error, "\pFSWrite buffer");
  96.     }
  97.  
  98.     error = CDSequenceEnd(sequenceID);
  99.     CheckError(error, "\pCDSequenceEnd");
  100.     DisposeGWorld(currWorld);
  101.     SetGWorld(savedPort, savedDevice);
  102.     if (buffer)
  103.         DisposeHandle(buffer);
  104. }
  105.  
  106.  
  107.