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 / Example2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-04  |  4.6 KB  |  160 lines  |  [TEXT/MPS ]

  1. /*
  2.   File:            Example2.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. //    The following sample code is similar to the previous example except
  12. //    that it requests files to compress until the user cancels and shows
  13. //    a slightly different use of the Standard Compression Dialog calls.
  14. //
  15. //    This example is not a description of the "right" way to use these
  16. //    calls in an application.  It should be used for comparison with the
  17. //    other examples.  Example 3 is a better example of the "right" way to
  18. //    do things.
  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 Example2(void);
  31.  
  32.  
  33. // FUNCTIONS
  34. void Example2(void)
  35. {
  36.     ComponentResult result;
  37.     Point where;
  38.     ComponentInstance ci;
  39.     short sref;
  40.     SFTypeList typeList;
  41.     SFReply reply;
  42.  
  43.     //    Open the Standard Compression Dialog component.
  44.  
  45.     ci = OpenDefaultComponent(StandardCompressionType, StandardCompressionSubType);
  46.     if (ci)
  47.     {
  48.  
  49.         //    Tell SFGetFilePreview to center on the best monitor.
  50.  
  51.         where.h = where.v = -2;
  52.  
  53.         //    Show only 'PICT' files in the file list.
  54.  
  55.         typeList[0] = 'PICT';
  56.  
  57.         //    Keep asking the user for files until they cancel.
  58.  
  59.         reply.good = true;
  60.         while (reply.good)
  61.         {
  62.  
  63.             //    Ask user to select PICT file to be compressed.
  64.  
  65.             SFGetFilePreview(where, "\p", nil, 1, typeList, nil, &reply);
  66.             if (reply.good)
  67.             {
  68.  
  69.                 //    If they selected a file, open that file.
  70.  
  71.                 result = FSOpen(reply.fName, reply.vRefNum, &sref);
  72.                 if (!result)
  73.                 {
  74.  
  75.                     //    If the file opened successfully, set the picture file to
  76.                     //    be the test image shown in the dialog.  Passing nil for srcRect
  77.                     //    means use the entire image.  Passing 0 for testFlags means
  78.                     //    to use the default system method of displaying the test image
  79.                     //    which is currently a combination of cropping and scaling.
  80.  
  81.                     SCSetTestImagePictFile(ci, sref, nil, 0);
  82.  
  83.                     //    Because we may have already made default settings in a previous
  84.                     //    pass through this loop, we need to set defaults specific to the
  85.                     //    current picture file.  This is particularly important because
  86.                     //    defaults for the previous picture may include a color table
  87.                     //    that is not appropriate for the current picture.
  88.                     //
  89.                     //    There is a drawback to this approach.  If the user wants to use
  90.                     //    settings different from the defaults for several pictures, they
  91.                     //    have to change the settings each time the compression dialog comes
  92.                     //    up.  The next example will show a better way of handling this problem
  93.                     //    using the custom button.
  94.  
  95.                     result = SCDefaultPictFileSettings(ci, sref, false);
  96.                     if (!result)
  97.                     {
  98.  
  99.                         //    Now that we know there are current defaults settings, we must
  100.                         //    explicitly request settings from the user.  In the previous
  101.                         //    example, SCCompressPictureFile requested settings from the user
  102.                         //    for us because no default settings had been made.
  103.                         //
  104.                         //    Note that the result code returned could include scUserCancelled.
  105.  
  106.                         result = SCRequestImageSettings(ci);
  107.                         if (!result)
  108.                         {
  109.  
  110.                             //    Compress the picture file with the settings chosen by the user.
  111.                             //    The settings include any custom color table found in the source
  112.                             //    picture if still appropriate for the depth chosen by the user.
  113.                             //
  114.                             //    Again note that we are able to pass the source file ref for both the
  115.                             //    source and destination picture files.  In this case, the picture
  116.                             //    file will be compressed in place.  It would probably be better to
  117.                             //    ask the user for a name to save the compressed file as, rather than
  118.                             //    compressing it in place.
  119.  
  120.                             result = SCCompressPictureFile(ci, sref, sref);
  121.  
  122.                             //    Another implementation would be to clear out the current settings
  123.                             //    by calling SCSetInfo(ci,scSettingsStateType,nil) after calling
  124.                             //    SCSetTestImagePictfile.  We would then no longer need the calls
  125.                             //    to SCDefaultPictFileSettings and SCRequestImageSettings because
  126.                             //    SCCompressPictureFile would do that for us as it did in the first example.
  127.                         }
  128.                     }
  129.  
  130.                     //    Close the source picture file.
  131.  
  132.                     FSClose(sref);
  133.                 }
  134.             }
  135.         }
  136.  
  137.         //    Close the Standard Compression Dialog component.
  138.  
  139.         CloseComponent(ci);
  140.     }
  141. }
  142.  
  143.  
  144. // MAIN FUNCTION
  145. void main(void)
  146. {
  147.     InitGraf(&qd.thePort);
  148.     InitFonts();
  149.     FlushEvents(everyEvent, 0);
  150.     InitWindows();
  151.     InitMenus();
  152.     InitDialogs(nil);
  153.     InitCursor();
  154.     MaxApplZone();
  155.  
  156.     Example2();
  157. }
  158.  
  159.  
  160.