home *** CD-ROM | disk | FTP | other *** search
/ QuickTime 2.0 Developer Kit / QuickTime 2.0 Developer Kit.iso / mac / MAC / Programming Stuff / Sample Code / Codecs / Std Compression Examples / Example1.c next >
Encoding:
C/C++ Source or Header  |  1994-12-04  |  3.8 KB  |  135 lines  |  [TEXT/MPS ]

  1. /*
  2.   File:            Example1.c
  3.   Contains:        Compression of PICT Files
  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. //    The following sample code shows the simplest case of asking the user for a picture file
  13. //    to be compressed, asking them for some compression settings, then compressing the
  14. //    picture file with those settings and quitting.
  15. //
  16. //    This is only a marginally practical example.  A real application would not want to use
  17. //    the various calls exactly in the manner described below.  It is more useful as a
  18. //    demonstration of how the calls behave in different situations.
  19.  
  20.  
  21. // INCLUDE FILES
  22. #include <menus.h>
  23. #include <fonts.h>
  24. #include <osevents.h>
  25. #include <components.h>
  26. #include <quicktimecomponents.h>
  27.  
  28.  
  29. // FUNCTION PROTOTYPES
  30. void Example1(void);
  31.  
  32.  
  33. // FUNCTIONS
  34. void Example1(void)
  35. {
  36.     ComponentResult result;
  37.     Point where;
  38.     ComponentInstance ci;
  39.     short sref;
  40.     SFTypeList typeList;
  41.     SFReply reply;
  42.  
  43.     //    Tell SFGetFilePreview to center on the best monitor.
  44.  
  45.     where.h = where.v = -2;
  46.  
  47.     //    Show only 'PICT' files in the file list.
  48.  
  49.     typeList[0] = 'PICT';
  50.  
  51.     //    Ask user to select PICT file to be compressed.
  52.  
  53.     SFGetFilePreview(where, "\p", nil, 1, typeList, nil, &reply);
  54.     if (reply.good)
  55.     {
  56.  
  57.         //    If they selected a file, open that file.
  58.  
  59.         result = FSOpen(reply.fName, reply.vRefNum, &sref);
  60.         if (!result)
  61.         {
  62.  
  63.             //    Open the Standard Compression Dialog component.
  64.  
  65.             ci = OpenDefaultComponent(StandardCompressionType, StandardCompressionSubType);
  66.             if (ci)
  67.             {
  68.  
  69.                 //    If the component opened successfully, set the picture file to
  70.                 //    be the test image shown in the dialog.  Passing nil for srcRect
  71.                 //    means use the entire image.  Passing 0 for testFlags means
  72.                 //    to use the default system method of displaying the test image
  73.                 //    which is currently a combination of cropping and scaling.
  74.  
  75.                 SCSetTestImagePictFile(ci, sref, nil, 0);
  76.  
  77.                 //    We don't need to explicitly set default compression settings
  78.                 //    in this example.  SCCompressPictureFile will see that no
  79.                 //    defaults have been set since the component has been open
  80.                 //    and call SCDefaultPictFileSettings with the test image for you.
  81.                 //    If other defaults did exist, the following call would need to be made:
  82.                 //
  83.                 //        result = SCDefaultPictFileSettings(ci,sref);
  84.  
  85.                 //    Again, because no settings exist yet, SCCompressPictureFile will
  86.                 //    call SCRequestImageSettings automatically to get settings from
  87.                 //    the user.  If other settings had been made previously, the following
  88.                 //    call would have to be made to explicitly ask the user for settings:
  89.                 //
  90.                 //        result = SCRequestImageSettings(ci);
  91.  
  92.                 //    Compress the picture file with the settings chosen by the user.
  93.                 //    The settings include any custom color table found in the source
  94.                 //    picture if still appropriate for the depth chosen by the user.
  95.                 //
  96.                 //    Note that we are able to pass the source file ref for both the
  97.                 //    source and destination picture files.  In this case, the picture
  98.                 //    file will be compressed in place.  It would probably be better to
  99.                 //    ask the user for a name to save the compressed file as, rather than
  100.                 //    compressing it in place.
  101.                 //
  102.                 //    Also note that the result code returned could include scUserCancelled.
  103.  
  104.                 result = SCCompressPictureFile(ci, sref, sref);
  105.  
  106.                 //    Close the Standard Compression Dialog component.
  107.  
  108.                 CloseComponent(ci);
  109.             }
  110.  
  111.             //    Close the source picture file.
  112.  
  113.             FSClose(sref);
  114.         }
  115.     }
  116. }
  117.  
  118.  
  119. // MAIN FUNCTION
  120. void main(void)
  121. {
  122.     InitGraf(&qd.thePort);
  123.     InitFonts();
  124.     FlushEvents(everyEvent, 0);
  125.     InitWindows();
  126.     InitMenus();
  127.     InitDialogs(nil);
  128.     InitCursor();
  129.     MaxApplZone();
  130.  
  131.     Example1();
  132. }
  133.  
  134.  
  135.