home *** CD-ROM | disk | FTP | other *** search
/ QuickTime 2.0 Beta / Quicktime 2.0 Beta.iso / Programming Stuff / Sample Code / DTS Sample Code / FastDitherUsingQT ƒ / FastDither.c next >
Encoding:
C/C++ Source or Header  |  1994-03-14  |  3.7 KB  |  152 lines  |  [TEXT/KAHL]

  1. /*
  2.     File:        FastDither.c
  3.  
  4.     Contains:    This short snippet shows how you can use QuickTime
  5.                 to get faster dithering.
  6.  
  7.     Written by:    John Wang
  8.  
  9.     Copyright:    © 1994 by Apple Computer, Inc., all rights reserved.
  10.  
  11.     Change History (most recent first):
  12.  
  13.         <1>        03/14/94    JW        Re-Created for Universal Headers.
  14.  
  15.     To Do:
  16.  
  17. */
  18.  
  19. #ifdef THINK_C
  20. #define        applec
  21. #endif
  22.  
  23. #include    <Types.h>
  24. #include    <Memory.h>
  25. #include    <QuickDraw.h>
  26. #include    <Palettes.h>
  27. #include    <QDOffscreen.h>
  28. #include    <Errors.h>
  29. #include    <Fonts.h>
  30. #include    <Dialogs.h>
  31. #include    <Windows.h>
  32. #include    <Menus.h>
  33. #include    <Events.h>
  34. #include    <Desk.h>
  35. #include    <DiskInit.h>
  36. #include    <OSUtils.h>
  37. #include    <Resources.h>
  38. #include    <ToolUtils.h>
  39. #include    <AppleEvents.h>
  40. #include    <EPPC.h>
  41. #include    <GestaltEqu.h>
  42. #include    <Processes.h>
  43. #include    <Balloons.h>
  44. #include    <Aliases.h>
  45. #include    <MixedMode.h>
  46. #include    <Scrap.h>
  47. #include    <LowMem.h>
  48.  
  49. #include    <ImageCompression.h>
  50.  
  51. WindowPtr    gWindow;
  52.  
  53. void    main(void);
  54. void    doTest(void);
  55.  
  56. /* ------------------------------------------------------------------------- */
  57.  
  58. void main(void)
  59. {
  60.     Rect bounds = {40, 40, 40, 40};
  61.  
  62.     MaxApplZone();
  63.     InitGraf(&qd.thePort);
  64.     InitFonts();
  65.     FlushEvents(0xffff,0);
  66.     InitWindows();
  67.     InitMenus();
  68.     InitDialogs(0);
  69.     TEInit();
  70.     InitCursor();
  71.     gWindow = NewCWindow(0L, &bounds, "\p", true, documentProc,
  72.                             (WindowPtr)-1L, false, 0L);
  73.     SetGWorld((CGrafPtr) gWindow, GetMainDevice());
  74.     doTest();
  75. }
  76.  
  77. void doTest(void)
  78. {
  79.     short                    i;
  80.     GWorldPtr                srcGWorld;
  81.     PixMapHandle            srcPixMap;
  82.     PicHandle                pict;
  83.     Rect                    pictBounds;
  84.     CGrafPtr                savedPort;
  85.     GDHandle                savedDevice;
  86.     ImageDescriptionHandle    desc;
  87.     Ptr                        imageData;
  88.     long                    size;
  89.     
  90.     //    Load the picture and define the source and dest rects.
  91.     pict = GetPicture(128);
  92.     pictBounds = (**pict).picFrame;
  93.     OffsetRect(&pictBounds, -pictBounds.left, -pictBounds.top);
  94.     SizeWindow(gWindow, pictBounds.right, pictBounds.bottom, true);
  95.     
  96.     //    Create a temporary offscreen used to store the pict.
  97.     if ( NewGWorld(&srcGWorld, 32, &pictBounds, nil, nil, 0) != noErr )
  98.         ExitToShell();
  99.     srcPixMap = GetGWorldPixMap(srcGWorld);    
  100.     LockPixels(srcPixMap);
  101.     
  102.     //    Draw the picture into the temporary gworld.    
  103.     GetGWorld(&savedPort, &savedDevice);
  104.     SetGWorld(srcGWorld, nil);
  105.     DrawPicture(pict, &pictBounds);
  106.     SetGWorld(savedPort, savedDevice);
  107.     
  108.     //    Now, compress the picture into a data buffer.
  109.     if ( GetMaxCompressionSize(srcPixMap, &(**srcPixMap).bounds, 32,
  110.                         codecNormalQuality, 'raw ', bestSpeedCodec, &size) )
  111.         ExitToShell();
  112.     imageData = NewPtr(size);
  113.     desc = (ImageDescriptionHandle) NewHandle(sizeof(ImageDescription));
  114.     if ( CompressImage(srcPixMap, &(**srcPixMap).bounds, codecNormalQuality,
  115.                     'raw ', desc, imageData) )
  116.         ExitToShell();
  117.     
  118.     //    Decompress the image to the window.    
  119.     SetWTitle(gWindow, "\pQuickTime ditherCopy");
  120.     for ( i=0; i<5; i++ ) {
  121.         EraseRect(&gWindow->portRect);
  122.         DecompressImage(imageData, desc, ((CGrafPtr)gWindow)->portPixMap, 
  123.                     &pictBounds, &gWindow->portRect, ditherCopy | 0x80, nil);
  124.     }
  125.     while ( !Button() );
  126.     
  127.     SetWTitle(gWindow, "\pQuickTime srcCopy");
  128.     for (i=0; i<5; i++) {
  129.         EraseRect(&gWindow->portRect);
  130.         DecompressImage(imageData, desc, ((CGrafPtr)gWindow)->portPixMap, 
  131.                     &pictBounds, &gWindow->portRect, srcCopy, nil);
  132.     }
  133.     while ( !Button() );
  134.     
  135.     SetWTitle(gWindow, "\pQuickDraw ditherCopy");
  136.     for ( i=0; i<5; i++ ) {
  137.         EraseRect(&gWindow->portRect);
  138.         CopyBits((BitMap *)*srcPixMap, &gWindow->portBits, &pictBounds,
  139.                     &gWindow->portRect, ditherCopy, nil);
  140.     }
  141.     while ( !Button() );
  142.     
  143.     SetWTitle(gWindow, "\pQuickDraw srcCopy");
  144.     for ( i=0; i<5; i++ ) {
  145.         EraseRect(&gWindow->portRect);
  146.         CopyBits((BitMap *)*srcPixMap, &gWindow->portBits, &pictBounds,
  147.                     &gWindow->portRect, srcCopy, nil);
  148.     }
  149.     while ( !Button() );
  150.  
  151.     DisposeGWorld( srcGWorld );    
  152. }