home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C++ / Snippets / QuickCamObjects / CQuickCam.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-05  |  4.6 KB  |  119 lines  |  [TEXT/CWIE]

  1. #pragma once
  2. //    © Paul B. Beeken, Work In Progress, 1994-5
  3. //    Knowledge Software Consulting.
  4. //
  5. //    Please, please, please, in the unlikely event you should use this stuff
  6. //    for some commercial application I would appreciate you contacting me.  If
  7. //    its for your own use, use away. Send email: knowsoft@ios.com
  8. //    My personal philosophy closely adheres to that of GNU software.  I offer this
  9. //    in the hope that others will improve and expand upon it.  Post your additions,
  10. //    leave this notice in place and add your own comments.
  11. //
  12. //    As always: this file is presented as is with no warrantees expressed or implied.
  13. //    Swim at your own risk, etc. etc.
  14. //
  15. //    CQuickCam
  16. //
  17. //    A c++ object library for the Connectix QuickCam using the
  18. //    standardized vdig functions outlined in the Ch. 8 of QTComponents.
  19. //    Yeah, you could do much of this seamlessly with Ch. 6 but with alot
  20. //    of loss of control and performance.  Some considerable experimentation
  21. //    has gone into this object and many related threads along this line.
  22. //    I think this provides the best trade off of flexability and control
  23. //
  24. //    Notes in general:  There are sometimes many ways to handle the 
  25. //        output of a vdig.  It can preview directly to the screen (if it is
  26. //        a cGrafPort) or to a pixmap.  Multiple buffering is an option and
  27. //        can be a very effective method given the serial data stream nature of 
  28. //        this kind of digitizer.  It can allow the greatest flexability
  29. //        and smoothness of updating.  It may not be the best solution for a
  30. //        particular application.
  31. //
  32. //    QuickCam in particular:
  33. //        The B&W camera is a 4 bit machine whose vdig doesn't do DMA.
  34. //        This object always buffers the data and the instatiator is responsible
  35. //        for updating.  Previewing is done by copying the GWorld pixmap to a 
  36. //        rectangle in a given cGrafport.  There are a couple of ways to accumulate
  37. //        data to the pixMap.  One is to use a buffers and the other is to write
  38. //        to a pixmap.  The former allows async grabs while the later does not.
  39. //        The routines outlined here allow either.  By specifying 0 for buffers,
  40. //        the vdig writes directly to the pixmap without any overhead associated
  41. //        with buffers.  Any value from 1 to 3 will allow you to write to different
  42. //        rectangles in the same pixmap but  will allow async grabs.  This may
  43. //        allow for some performance imporvements.
  44. //        The QuickCam vdig doesn't seem to like more than 3 buffers.  Why would you
  45. //        need more?  Actually this makes sense.  One would be the writethrubuffer
  46. //        the other two are the alternating capture buffers.
  47. //
  48. //
  49. //    Current version 0.8        © Paul B. Beeken, Knowledge Software Consulting.
  50. //
  51. //    11/08/95    Finished basic object after creating various types of LPane
  52. //            derivatives.  This object borrows the from the best of them.  Its
  53. //            creation also eliminates the dependance on MW PowerPlant.
  54. //    12/04/95    Completed spot metering and fixed a memory leak.
  55. //
  56. //    Wishlist:    Sequential capture to moov.
  57. //                Include methods for capturing from a subset rect in vdig bounds.
  58. //                Motion triggering.
  59.  
  60. #include    <quicktimeComponents.h>
  61.  
  62. enum    {
  63.     modemPort    = 0,
  64.     printerPort
  65.         };
  66.  
  67.  
  68. class    CQuickCam    {
  69.     public:
  70.  
  71.         CQuickCam( short inSrc=modemPort, short nBuffers=1 );
  72.         ~CQuickCam( void );
  73.  
  74.         // These methods control the digitizer.
  75.             // update the video buffer.
  76.         void            UpdateVideo( void );
  77.             // draw the of the last filled buffer to a rect within the given port
  78.         void            DrawVideo( CGrafPtr gw, const Rect& r );
  79.             // optimize the video Rect to r.
  80.         Rect            OptVideoRect( const Rect& r );    // sets vdig rect to optimal size for given Rect.
  81.                                                         // returns it for use by caller.
  82.             // Get and set the brighness.
  83.         void            Brightness( unsigned short v );
  84.         unsigned short    Brightness( void );
  85.         void            SpotMeter( unsigned short b );    // Set target brightness
  86.         void            SpotMeter( const Rect& r );        // Spot meter in r
  87.  
  88.             // Choose the input source (0:modem, 1:printer);
  89.         void            InputSource( short src );
  90.         short            InputSource( void );        
  91.  
  92.             // Set default video characteristics
  93.         void            SetDefaults( void );
  94.  
  95.             // Grab a pict.
  96.         PicHandle        GrabPict( void );
  97.             // We need to be able to instantiate and add sequences to a moov file.
  98.             //        to be continued...
  99.  
  100.             // Return the current InfoRecord.
  101.         DigitizerInfo    GetInfoRecord( void );
  102.  
  103.     protected:
  104.         void            SetUpBuffers( short n=1 );
  105.         void            ClearUpBuffers( void );
  106.  
  107.     private:    // for exposure only, don't play unless you know what's going on.
  108.         short            bufferCount;
  109.         short            bufferIndex;
  110.         
  111.         VideoDigitizerComponent    vdig;            // Instance of a vdig
  112.         DigitizerInfo            vdigInfo;        // Information
  113.         GWorldPtr                gWorld;            // gWorld for capture (could be current port)
  114.  
  115.         Rect                    videoFrame;
  116.         MatrixRecord            videoMatrix;
  117.         float                    bright;
  118.     
  119.     };