/****************************************************************************/ /* */ /* Application: Compressed PICT Info */ /* */ /* Description: This snippet shows how to use the StdPix proc to */ /* intercept and display the compression type and depth */ /* of any compressed PICT within a PICT resource. The */ /* same procedure can be used to gather other information */ /* about the compressed PICT. Note that all compressed */ /* PICTs get passed into StdPix before getting decom- */ /* pressed and passed to StdBits. */ /* */ /* Files: Compressed PICT Info.¹ */ /* Compressed PICT Info.¹.rsrc */ /* Compressed PICT Info.c */ /* */ /* Programmer: Edgar Lee */ /* Organization: Apple Computer, Inc. */ /* Department: Developer Technical Support, DTS */ /* Language: C (Think C version 5.0.2) */ /* Date Created: 10-20-92 */ /* */ /****************************************************************************/ #include #include /* Constant Declarations */ #define WWIDTH 170 #define WHEIGHT 220 #define WLEFT (((screenBits.bounds.right - screenBits.bounds.left) - WWIDTH) / 2) #define WTOP (((screenBits.bounds.bottom - screenBits.bounds.top) - WHEIGHT) / 2) /* Global Variable Definitions */ CodecType gCodec = 'unkn'; int gDepth; void initMac(); void checkForQuickTime(); void createWindow(); void doEventLoop(); void doBottleneckTest(); main() { initMac(); checkForQuickTime(); createWindow(); doEventLoop(); } void initMac() { MaxApplZone(); InitGraf( &thePort ); InitFonts(); InitWindows(); InitMenus(); TEInit(); InitDialogs( nil ); InitCursor(); FlushEvents( 0, everyEvent ); } void checkForQuickTime() { long version; if (Gestalt( gestaltQuickTime, &version ) != noErr) { ParamText( "\pQuickTime not installed. Please install, then try again.", "\p", "\p", "\p" ); Alert( 128, nil ); ExitToShell(); } } void createWindow() { Rect rect; WindowPtr window; SetRect( &rect, WLEFT, WTOP, WLEFT + WWIDTH, WTOP + WHEIGHT ); window = NewCWindow( 0L, &rect, "\pStdPix", true, documentProc, (WindowPtr)-1L, true, 0L ); SetPort( window ); TextMode( srcCopy ); TextSize( 9 ); TextFont( geneva ); } pascal void myStdPix( PixMapPtr src, Rect *srcRect, MatrixRecordPtr matrix, short mode, RgnHandle mask, PixMapPtr matte, Rect *matteRect, short flags ) { ImageDescriptionHandle desc; Ptr data; long bufferSize; GetCompressedPixMapInfo( src, &desc, &data, &bufferSize, nil, nil ); gCodec = (**desc).cType; gDepth = (**desc).depth; } pascal void myTextProc( short byteCount, Ptr textBuf, Point numer, Point denom ) { } pascal void myLineProc( Point newPt ) { } pascal void myRectProc( GrafVerb verb, Rect *r ) { } pascal void myRRectProc( GrafVerb verb, Rect *r, short ovalWidth, short ovalHeight ) { } pascal void myOvalProc( GrafVerb verb, Rect *r ) { } pascal void myArcProc( GrafVerb verb, Rect *r, short startAngle, short arcAngle ) { } pascal void myPolyProc( GrafVerb verb, PolyHandle poly ) { } pascal void myRgnProc( GrafVerb verb, RgnHandle rgn ) { } pascal void myBitsProc( BitMap *bitPtr, Rect *srcRect, Rect *dstRect, short mode, RgnHandle maskRgn ) { } void DrawCompressionType( CodecType codec, int col, int row ) { MoveTo( col, row ); if (codec == 'rpza') DrawString( "\pVideo Compression" ); else if (codec == 'jpeg') DrawString( "\pJPEG Compression" ); else if (codec == 'rle ') DrawString( "\pAnimation Compression" ); else if (codec == 'raw ') DrawString( "\pRaw Compression" ); else if (codec == 'smc ') DrawString( "\pGraphics Compression" ); else DrawString( "\pUnknown Compression" ); } void DrawCompressionDepth( int depth, int col, int row ) { Str255 string; NumToString( (long)depth, string ); MoveTo( col, row ); DrawString( "\pImage Depth:" ); MoveTo( col + 70, row ); DrawString( string ); } void doBottleneckTest() { int i; PicHandle picture; Rect rect; CQDProcs bottlenecks; /* Define our own bottlenecks to do nothing. */ SetStdCProcs( &bottlenecks ); bottlenecks.textProc = (Ptr)myTextProc; bottlenecks.lineProc = (Ptr)myLineProc; bottlenecks.rectProc = (Ptr)myRectProc; bottlenecks.rRectProc = (Ptr)myRRectProc; bottlenecks.ovalProc = (Ptr)myOvalProc; bottlenecks.arcProc = (Ptr)myArcProc; bottlenecks.polyProc = (Ptr)myPolyProc; bottlenecks.rgnProc = (Ptr)myRgnProc; bottlenecks.bitsProc = (Ptr)myBitsProc; bottlenecks.newProc1 = (Ptr)myStdPix; /* pixProc */ for (i = 0; i < Count1Resources( 'PICT' ); i++) { /* Load & draw pictures from resource. */ picture = (PicHandle)Get1IndResource( 'PICT', i + 1 ); rect = (**picture).picFrame; OffsetRect( &rect, -rect.left, -rect.top ); OffsetRect( &rect, 10, ((rect.bottom - rect.top) + 10) * i + 10 ); DrawPicture( picture, &rect ); /* Install our custom bottlenecks to intercept any compressed images. */ (*(qd.thePort)).grafProcs = (QDProcs *)&bottlenecks; DrawPicture( picture, &((**picture).picFrame) ); /* Switch back to the default procs. */ (*(qd.thePort)).grafProcs = 0L; /* Free any memory used by the picture. */ ReleaseResource( picture ); /* Display the compression type. */ DrawCompressionType( gCodec, rect.right + 10, rect.top + 10 ); DrawCompressionDepth( gDepth, rect.right + 10, rect.top + 25 ); gCodec = 'unkn'; } } void doEventLoop() { EventRecord event; WindowPtr window; short clickArea; Rect screenRect; for (;;) { if (WaitNextEvent( everyEvent, &event, 0, nil )) { if (event.what == mouseDown) { clickArea = FindWindow( event.where, &window ); if (clickArea == inDrag) { screenRect = (**GetGrayRgn()).rgnBBox; DragWindow( window, event.where, &screenRect ); } else if (clickArea == inContent) { if (window != FrontWindow()) SelectWindow( window ); } else if (clickArea == inGoAway) if (TrackGoAway( window, event.where )) return; } else if (event.what == updateEvt) { window = (WindowPtr)event.message; SetPort( window ); BeginUpdate( window ); doBottleneckTest(); EndUpdate( window ); } } } }