home *** CD-ROM | disk | FTP | other *** search
- /*
- File: FastDither.c
-
- Contains: This short snippet shows how you can use QuickTime
- to get faster dithering.
-
- Written by: John Wang
-
- Copyright: © 1994 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <1> 03/14/94 JW Re-Created for Universal Headers.
-
- To Do:
-
- */
-
- #ifdef THINK_C
- #define applec
- #endif
-
- #include <Types.h>
- #include <Memory.h>
- #include <QuickDraw.h>
- #include <Palettes.h>
- #include <QDOffscreen.h>
- #include <Errors.h>
- #include <Fonts.h>
- #include <Dialogs.h>
- #include <Windows.h>
- #include <Menus.h>
- #include <Events.h>
- #include <Desk.h>
- #include <DiskInit.h>
- #include <OSUtils.h>
- #include <Resources.h>
- #include <ToolUtils.h>
- #include <AppleEvents.h>
- #include <EPPC.h>
- #include <GestaltEqu.h>
- #include <Processes.h>
- #include <Balloons.h>
- #include <Aliases.h>
- #include <MixedMode.h>
- #include <Scrap.h>
- #include <LowMem.h>
-
- #include <ImageCompression.h>
-
- WindowPtr gWindow;
-
- void main(void);
- void doTest(void);
-
- /* ------------------------------------------------------------------------- */
-
- void main(void)
- {
- Rect bounds = {40, 40, 40, 40};
-
- MaxApplZone();
- InitGraf(&qd.thePort);
- InitFonts();
- FlushEvents(0xffff,0);
- InitWindows();
- InitMenus();
- InitDialogs(0);
- TEInit();
- InitCursor();
- gWindow = NewCWindow(0L, &bounds, "\p", true, documentProc,
- (WindowPtr)-1L, false, 0L);
- SetGWorld((CGrafPtr) gWindow, GetMainDevice());
- doTest();
- }
-
- void doTest(void)
- {
- short i;
- GWorldPtr srcGWorld;
- PixMapHandle srcPixMap;
- PicHandle pict;
- Rect pictBounds;
- CGrafPtr savedPort;
- GDHandle savedDevice;
- ImageDescriptionHandle desc;
- Ptr imageData;
- long size;
-
- // Load the picture and define the source and dest rects.
- pict = GetPicture(128);
- pictBounds = (**pict).picFrame;
- OffsetRect(&pictBounds, -pictBounds.left, -pictBounds.top);
- SizeWindow(gWindow, pictBounds.right, pictBounds.bottom, true);
-
- // Create a temporary offscreen used to store the pict.
- if ( NewGWorld(&srcGWorld, 32, &pictBounds, nil, nil, 0) != noErr )
- ExitToShell();
- srcPixMap = GetGWorldPixMap(srcGWorld);
- LockPixels(srcPixMap);
-
- // Draw the picture into the temporary gworld.
- GetGWorld(&savedPort, &savedDevice);
- SetGWorld(srcGWorld, nil);
- DrawPicture(pict, &pictBounds);
- SetGWorld(savedPort, savedDevice);
-
- // Now, compress the picture into a data buffer.
- if ( GetMaxCompressionSize(srcPixMap, &(**srcPixMap).bounds, 32,
- codecNormalQuality, 'raw ', bestSpeedCodec, &size) )
- ExitToShell();
- imageData = NewPtr(size);
- desc = (ImageDescriptionHandle) NewHandle(sizeof(ImageDescription));
- if ( CompressImage(srcPixMap, &(**srcPixMap).bounds, codecNormalQuality,
- 'raw ', desc, imageData) )
- ExitToShell();
-
- // Decompress the image to the window.
- SetWTitle(gWindow, "\pQuickTime ditherCopy");
- for ( i=0; i<5; i++ ) {
- EraseRect(&gWindow->portRect);
- DecompressImage(imageData, desc, ((CGrafPtr)gWindow)->portPixMap,
- &pictBounds, &gWindow->portRect, ditherCopy | 0x80, nil);
- }
- while ( !Button() );
-
- SetWTitle(gWindow, "\pQuickTime srcCopy");
- for (i=0; i<5; i++) {
- EraseRect(&gWindow->portRect);
- DecompressImage(imageData, desc, ((CGrafPtr)gWindow)->portPixMap,
- &pictBounds, &gWindow->portRect, srcCopy, nil);
- }
- while ( !Button() );
-
- SetWTitle(gWindow, "\pQuickDraw ditherCopy");
- for ( i=0; i<5; i++ ) {
- EraseRect(&gWindow->portRect);
- CopyBits((BitMap *)*srcPixMap, &gWindow->portBits, &pictBounds,
- &gWindow->portRect, ditherCopy, nil);
- }
- while ( !Button() );
-
- SetWTitle(gWindow, "\pQuickDraw srcCopy");
- for ( i=0; i<5; i++ ) {
- EraseRect(&gWindow->portRect);
- CopyBits((BitMap *)*srcPixMap, &gWindow->portBits, &pictBounds,
- &gWindow->portRect, srcCopy, nil);
- }
- while ( !Button() );
-
- DisposeGWorld( srcGWorld );
- }