SDLFrameBuffer Class Reference

This class serves as a frame buffer and event handler of a SDL RGB Surface widget for displaying video frames. More...

#include <SDLFrameBuffer.hpp>

Inheritance diagram for SDLFrameBuffer:

VideoFrameBuffer List of all members.

Public Member Functions

 SDLFrameBuffer (SDL_Surface *surface, int depth, bool gray, int width, int height)
 Constructor.
virtual ~SDLFrameBuffer ()
 Destructor.
void setPixel (int x, int y, uint value)
 Set a pixel in the frame buffer.
void bitBlt (AU *au)
 does the fast bitblitting of the full (and unscaled) Frame
void lock ()
 Lock the mutex protecting the frame buffer.
void unlock ()
 Unlock the mutex locked by lock().
void postPaintEvent ()
 Post a custom event for this object to display the frame buffer on the SDL surface.

Protected Attributes

SDL_Surface * image
SDL_Surface * surface
int width
int height

Detailed Description

This class serves as a frame buffer and event handler of a SDL RGB Surface widget for displaying video frames.

Author:
Michael Kropfberger
Version:
Id
SDLFrameBuffer.hpp,v 1.6 2005/01/16 16:35:12 mkropfbe Exp

Definition at line 61 of file SDLFrameBuffer.hpp.


Constructor & Destructor Documentation

SDLFrameBuffer::SDLFrameBuffer SDL_Surface *  surface,
int  depth,
bool  gray,
int  width,
int  height
 

Constructor.

Parameters:
surface the SDL_Surface of the actual SDL window on the display
depth the color depth of the frame buffer (8, 24, 32).
numColors the color table size of the frame buffer (if depth == 8).
gray if true and numColors > 0, set the color table entries to all gray values.
Definition at line 54 of file SDLFrameBuffer.cpp.
00055 : VideoFrameBuffer(gray) 00056 { 00057 this->surface = surface; 00058 this->width = width; 00059 this->height = height; 00060 assert(depth % 8 == 0); 00061 00062 /* 00063 #if SDL_BYTEORDER == SDL_BIG_ENDIAN 00064 rmask = 0xff000000; 00065 gmask = 0x00ff0000; 00066 bmask = 0x0000ff00; 00067 amask = 0x000000ff; 00068 #else 00069 rmask = 0x000000ff; 00070 gmask = 0x0000ff00; 00071 bmask = 0x00ff0000; 00072 amask = 0xff000000; 00073 #endif 00074 00075 rmask = 0x00000020; 00076 gmask = 0x000007E0; 00077 bmask = 0x0000F800; 00078 00079 rmask = 0x0000000F; 00080 gmask = 0x000000F0; 00081 bmask = 0x00000F00; 00082 00083 //rmask = 0xFFFFFFFF; 00084 //gmask = 0xFFFFFFFF; 00085 //bmask = 0xFFFFFFFF; 00086 */ 00087 00088 /* 00089 Uint32 rmask, gmask, bmask, amask; 00090 amask=rmask=gmask=bmask=0; 00091 image = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, depth, rmask, gmask, bmask, amask); 00092 00093 if (image == NULL) { 00094 dprintf_err("Couldn't initialize blitbuffer with dimension %ix%i depth %i\n",width,height, depth); 00095 ::exit(1); 00096 } 00097 SDL_SetAlpha(image,0,0xff); 00098 dprintf_full("SDLFrameBuffer: initialize blitbuffer with dimension %ix%i depth %i, bpp %i, no aplpha blending\n", 00099 width,height, image->format->BitsPerPixel, image->format->BytesPerPixel); 00100 */ 00101 }


Member Function Documentation

void SDLFrameBuffer::lock  )  [inline]
 

Lock the mutex protecting the frame buffer.

This function will block the calling thread until the mutex can be obtained.

See also:
unlock()

Reimplemented from VideoFrameBuffer.

Definition at line 91 of file SDLFrameBuffer.hpp.

00091 { 00092 if ( SDL_MUSTLOCK(surface) ) 00093 { 00094 if ( SDL_LockSurface(surface) < 0 ) { 00095 ::exit(4); 00096 } 00097 } 00098 }

void SDLFrameBuffer::postPaintEvent  )  [virtual]
 

Post a custom event for this object to display the frame buffer on the SDL surface.

This is thread-safe and will cause the GUI thread to invoke customEvent(). We need to use custom events, as hidden widgets will not receive paint events.

Implements VideoFrameBuffer.

Definition at line 156 of file SDLFrameBuffer.cpp.

00156 { 00157 /* 00158 if (SDL_MUSTLOCK(surface)) { 00159 if (SDL_LockSurface(surface) < 0) { 00160 ::exit(2); 00161 } 00162 } 00163 00164 if(SDL_BlitSurface(image, NULL, surface, NULL) < 0) 00165 fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError()); 00166 00167 if (SDL_MUSTLOCK(surface)) { 00168 SDL_UnlockSurface(surface); 00169 } 00170 */ 00171 SDL_UpdateRect(surface, 0, 0, 0, 0); 00172 }

void SDLFrameBuffer::setPixel int  x,
int  y,
uint  value
[inline, virtual]
 

Set a pixel in the frame buffer.

the frame buffer should be locked before setPixel() by calling the lock() method.

Reimplemented from VideoFrameBuffer.

Definition at line 111 of file SDLFrameBuffer.cpp.

00111 { 00112 00113 int bpp = surface->format->BytesPerPixel; 00114 Uint8 *p = (Uint8 *)(surface->pixels) + y * surface->pitch + x * bpp; 00115 00116 // dprintf_full("SDLFrameBuffer::setPixel image pitch %i bpp %i %x %x\n",image->pitch,image->format->BytesPerPixel,p,value); 00117 // printf("%x\t",value); 00118 00119 switch(bpp) { 00120 case 1: 00121 *p = (Uint8)value; 00122 break; 00123 00124 case 2: 00125 *(Uint16 *)p = value; 00126 break; 00127 00128 case 3: 00129 if(SDL_BYTEORDER == SDL_BIG_ENDIAN) { 00130 p[0] = (value >> 16) & 0xff; 00131 p[1] = (value >> 8) & 0xff; 00132 p[2] = value & 0xff; 00133 } else { 00134 p[0] = value & 0xff; 00135 p[1] = (value >> 8) & 0xff; 00136 p[2] = (value >> 16) & 0xff; 00137 } 00138 break; 00139 00140 case 4: 00141 if (gray) 00142 value = value << 16 | value << 8 | value; 00143 *(Uint32 *)p = value; 00144 break; 00145 } 00146 }


The documentation for this class was generated from the following files: