home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-12-04 | 2.9 KB | 107 lines | [TEXT/MPS ] |
- /*
- File: icm4.h
- Contains: Draw and Compress Functions
- Written by: DTS and QT Engineering
- Copyright: © 1992-1994 by Apple Computer, Inc., all rights reserved.
- Change History (most recent first):
- <1> 12/4/94 khs changed the format of the file to the new look and feel
- To Do:
- */
-
-
- // INCLUDES
- #include "icm.h"
-
-
- // FUNCTIONS
- void DrawFrame(const Rect* imageRect,
- long frameNum)
- {
- Str255 numStr;
-
- ForeColor(redColor);
- PaintRect(imageRect);
-
- ForeColor(blueColor);
- NumToString(frameNum, numStr);
- MoveTo(imageRect->right / 2, imageRect->bottom / 2);
- TextSize(imageRect->bottom / 3);
- DrawString(numStr);
- }
-
-
- void CompressSequence(short* dfRef,
- ImageDescriptionHandle* description)
- {
- GWorldPtr currWorld = nil;
- PixMapHandle currPixMap;
- CGrafPtr savedPort;
- GDHandle savedDevice;
- Handle buffer = nil;
- Ptr bufferAddr;
- long compressedSize;
- long dataLen;
- Rect imageRect;
- ImageSequence sequenceID = 0;
- short frameNum;
- OSErr error;
- CodecType codecKind = 'rle ';
-
- GetGWorld(&savedPort, &savedDevice);
- imageRect = savedPort->portRect;
- error = NewGWorld(&currWorld, 32, &imageRect, nil, nil, 0);
- CheckError(error, "\pNewGWorld");
- SetGWorld(currWorld, nil);
-
- currPixMap = currWorld->portPixMap;
- LockPixels(currPixMap);
-
- // allocate an embryonic image description structure and the
- // Image Compression Manager will resize
- *description = (ImageDescriptionHandle)NewHandle(4);
-
- error = CompressSequenceBegin(&sequenceID, currPixMap, nil,// tell ICM to allocate previous image buffer
- &imageRect, &imageRect, 0,// let ICM choose pixel depth
- codecKind, (CompressorComponent)anyCodec, codecNormalQuality,// spatial quality
- codecNormalQuality,// temporal quality
- 5, // at least 1 key frame every 5 frames
- nil, // use default color table
- codecFlagUpdatePrevious, *description);
- CheckError(error, "\pCompressSequenceBegin");
-
- error = GetMaxCompressionSize(currPixMap, &imageRect, 0,// let ICM choose pixel depth
- codecNormalQuality,// spatial quality
- codecKind, (CompressorComponent)anyCodec, &compressedSize);
- CheckError(error, "\pGetMaxCompressionSize");
-
- buffer = NewHandle(compressedSize);
- CheckError(MemError(), "\pNewHandle buffer");
- MoveHHi(buffer);
- HLock(buffer);
- bufferAddr = StripAddress(*buffer);
-
- for (frameNum = 1; frameNum <= 10; frameNum++)
- {
- DrawFrame(&imageRect, frameNum);
-
- error = CompressSequenceFrame(sequenceID, currPixMap, &imageRect, codecFlagUpdatePrevious, bufferAddr, &compressedSize, nil, nil);
- CheckError(error, "\pCompressSequenceFrame");
-
- dataLen = 4;
- error = FSWrite(*dfRef, &dataLen, &compressedSize);
- CheckError(error, "\pFSWrite length");
-
- error = FSWrite(*dfRef, &compressedSize, bufferAddr);
- CheckError(error, "\pFSWrite buffer");
- }
-
- error = CDSequenceEnd(sequenceID);
- CheckError(error, "\pCDSequenceEnd");
- DisposeGWorld(currWorld);
- SetGWorld(savedPort, savedDevice);
- if (buffer)
- DisposeHandle(buffer);
- }
-
-
-