ImageBuffer


 public:

 // Constructor/Destructor for this buffer
 ImageBuffer()   { ready = FALSE; };
 virtual ~ImageBuffer() { ShiAssert( !IsReady() ); };
 

 // Functions used to set up and manage this buffer
 BOOL Setup( DisplayDevice *dev, int width, int height, MPRSurfaceType front, MPRSurfaceType back, HWND targetWin = NULL, BOOL clip = FALSE, BOOL fullScreen = FALSE );
 void Cleanup( void );
 BOOL IsReady( void ) { return ready; };
 void SetChromaKey( UInt32 RGBcolor );
 void UpdateFrontWindowRect( RECT *rect );

 // Used to get the properties of the under lying surfaces
 DisplayDevice *GetDisplayDevice( void ) { return device; };
 UInt   targetSurface( void ) { return backBuffer; };
 UInt   frontSurface( void ) { return frontBuffer; };

 int    targetXres( void ) { return width; };
 int    targetYres( void ) { return height; };
 int    targetStride( void ){ return backDescription.pitch; };

 void   GetColorMasks( UInt32 *r, UInt32 *g, UInt32* b );
 UInt32   RedMask(void) { return frontDescription.RBitMask; };
 UInt32   GreenMask(void) { return frontDescription.GBitMask; };
 UInt32   BlueMask(void) { return frontDescription.BBitMask; };
 int    RedShift(void) { return redShift; };
 int    GreenShift(void){ return greenShift; };
 int    BlueShift(void) { return blueShift; };

 int   PixelSize( void ) { return backDescription.RGBBitCount>>3; };

 // Used to allow direct pixel access to the back buffer
 void* Lock( void );
 void  Unlock( void );

 // Used to convert from a 32 bit color to a 16 bit pixel (assumes 16 bit display mode)
 UInt16  Pixel32toPixel16( UInt32 ABGR );
 UInt32  Pixel16toPixel32( UInt16 pixel );

 // Used to write a pixel to the back buffer surface (requires a Lock)
 void* Pixel( void* ptr, int row, int col )   { ShiAssert( ptr );
             return (BYTE*)ptr +
                  row*backDescription.pitch +
               col*PixelSize(); };

 // Used to control image compositing
 void Compose(            ImageBuffer *srcBuffer, RECT *srcRect, RECT *dstRect );
 void ComposeTransparent( ImageBuffer *srcBuffer, RECT *srcRect, RECT *dstRect );

 // Used to control image compositing with a clockwise rotation (in radians)
 void ComposeRot(      ImageBuffer *srcBuffer, RECT *srcRect, RECT *dstRect, float angle );
 void ComposeRoundRot( ImageBuffer *srcBuffer, RECT *srcRect, RECT *dstRect, float angle, int *startStopArray );

 // Swap rolls of front and back buffers (page flip, blt, or nothing depending on types)
 void SwapBuffers( UInt rc );

 // Helpful function to drop a screen capture to disk (BACK buffer to 24 bit RAW file)
 void BackBufferToRAW( char *filename );

  protected:
 BOOL ready;

 DisplayDevice   *device;

 MPRSurfaceType   frontType;
 UInt     frontBuffer;
    MPRSurfaceDescription frontDescription;
 HWND     win;
 RECT     frontRect;

 MPRSurfaceType   backType;
 UInt     backBuffer;
    MPRSurfaceDescription backDescription;

 int      width;
 int      height;

 int      redShift;
 int      greenShift;
 int      blueShift;

  protected:
 void ComputeColorShifts();