test::OutputDevice Class Reference

The widget output device. NOT SURE THE WIDGET SIZE WILL BE CHANGED OR NOT. More...

#include <test_output_device.h>

Collaboration diagram for test::OutputDevice:
Collaboration graph
[legend]

Public Member Functions

 OutputDevice ()
 ~OutputDevice (void)
void set_color_depth (int c)
void map (OutputDeviceContext &context)
 Intialize the output device.
void invalidate_rectangle (const GdkRectangle &r)
 Invalidate a rectangle region.
void clear_background (const int color=0xff, bool flush=false)
 Clear background directly.
void draw_line (int x1, int y1, int x2, int y2)
 Draw a line by output device.
void draw_highlight_rectangle (const GdkRectangle &rect)
 Draw highlight rectangle.
void draw_image (const unsigned char *src, int width, int height, int row_stride, int xDest=0, int yDest=0)
 Copy data (2 dimensions) directly into virtual framebuffer.
void draw_image_with_transform (const unsigned char *src, int width, int height, int row_stride, int xDest=0, int yDest=0, int transform=PLUGIN_ORIENTATION_LANDSCAPE)
 Copy data (2 dimensions) directly into virtual framebuffer with transform. This function is helpful when caller does not want to reallocate memory. The caller should make sure the boundary should not exceed the range of framebuffer.

Detailed Description

The widget output device. NOT SURE THE WIDGET SIZE WILL BE CHANGED OR NOT.

Definition at line 52 of file test_output_device.h.


Constructor & Destructor Documentation

test::OutputDevice::OutputDevice (  ) 

Definition at line 35 of file test_output_device.cpp.

00036 : ctx()
00037 , shared_image(0)
00038 , color_dep(MONO_COLOR_DEPTH)
00039 , xor_gc(0)
00040 {
00041 }

test::OutputDevice::~OutputDevice ( void   ) 

Definition at line 43 of file test_output_device.cpp.

00044 {
00045     if (shared_image)
00046     {
00047         g_object_unref(shared_image);
00048     }
00049 
00050     if (xor_gc)
00051     {
00052         g_object_unref(xor_gc);
00053     }
00054 }


Member Function Documentation

void test::OutputDevice::clear_background ( const int  color = 0xff,
bool  flush = false 
)

Clear background directly.

Parameters:
color The background color.

Definition at line 106 of file test_output_device.cpp.

References test::OutputDeviceContext::gc, and test::OutputDeviceContext::widget.

00107 {
00108     update_shared_image(ctx.widget);
00109 
00110     // clear the image now
00111     unsigned char *p = (unsigned char *)shared_image->mem;
00112     memset(p, color, shared_image->height * shared_image->bpl);
00113 
00114     // draw the background immediately if necessary
00115     if (flush)
00116     {
00117         gdk_draw_image(ctx.widget->window, ctx.gc, shared_image, 0, 0, 
00118             ctx.widget->allocation.x, ctx.widget->allocation.y, 
00119             ctx.widget->allocation.width, ctx.widget->allocation.height); 
00120     }
00121 }

void test::OutputDevice::draw_highlight_rectangle ( const GdkRectangle &  rect  ) 

Draw highlight rectangle.

Parameters:
rect The GdkRectangle of the highlight area

Definition at line 134 of file test_output_device.cpp.

References test::OutputDeviceContext::widget.

00135 {
00136     gdk_draw_rectangle(ctx.widget->window, xor_gc, TRUE, rect.x, rect.y
00137        , rect.width, rect.height);
00138 }

void test::OutputDevice::draw_image ( const unsigned char *  src,
int  width,
int  height,
int  row_stride,
int  xDest = 0,
int  yDest = 0 
)

Copy data (2 dimensions) directly into virtual framebuffer.

Parameters:
src The source data buffer.
width The width of source data buffer.
row_stride number of bytes in a row.
height The height of source data buffer.
xDest The x destination in framebuffer.
yDest The y destination in framebuffer.

copy src (0, 0) - (width, height) to shared_image(xDest, yDest) - (xDest + width, yDest + height) copy data from shared_image to X server.

Definition at line 142 of file test_output_device.cpp.

References ARGB_COLOR_DEPTH, test::OutputDeviceContext::gc, MONO_COLOR_DEPTH, RGB_COLOR_DEPTH, and test::OutputDeviceContext::widget.

00148 {
00149     // check at first, should also check xDest and yDest.
00150     if (src == 0 || width <= 0 || height <= 0) 
00151     {
00152         return;
00153     }
00154     
00155     //Only cover the situation that global color depth is "8" and 
00156     //output device's color depth is "32"
00157     update_shared_image(width, height);
00158     
00159     unsigned char *dst = (unsigned char *)shared_image->mem +
00160           (shared_image->bpl * yDest + xDest);
00161 
00162     bool transform_result = false;
00163 
00164     switch(shared_image->bits_per_pixel)
00165     {
00166     case RGB_COLOR_DEPTH:
00167         {
00168             switch(color_dep)
00169             {
00170             case RGB_COLOR_DEPTH:
00171                 
00172                 transform_result = transform_bitmap_with_same_depth(src, dst,
00173                     width, height, row_stride);
00174 
00175                 break;
00176             case ARGB_COLOR_DEPTH:
00177                 
00178                 //Print "Unsupport" message
00179                 transform_result = transform_bitmap_ARGB_to_RGB(src, dst,
00180                     width, height, row_stride);
00181                 
00182                 break;
00183             case MONO_COLOR_DEPTH:
00184 
00185                 transform_result = transform_bitmap_MONO_to_RGB(src, dst,
00186                     width, height, row_stride);
00187                 
00188                 break;
00189             default:
00190                 
00191                 //Print "Unsupport" message
00192                 
00193                 break;
00194             }
00195             break;
00196         }
00197     case ARGB_COLOR_DEPTH:
00198         {
00199             switch(color_dep)
00200             {
00201             case RGB_COLOR_DEPTH:
00202                 
00203                 transform_result = transform_bitmap_RGB_to_ARGB(src, dst,
00204                     width, height, row_stride);
00205                 
00206                 break;
00207             case ARGB_COLOR_DEPTH:
00208 
00209                 transform_result = transform_bitmap_with_same_depth(src, dst,
00210                     width, height, row_stride);
00211                 
00212                 break;
00213             case MONO_COLOR_DEPTH:
00214                 
00215                 transform_result = transform_bitmap_MONO_to_ARGB(src, dst,
00216                     width, height, row_stride);
00217                 
00218                 break;
00219             default:
00220 
00221                 //Print "Unsupport" message
00222                 
00223                 break;
00224             }
00225             break;
00226         }
00227     case MONO_COLOR_DEPTH:
00228         {
00229             switch(color_dep)
00230             {
00231             case RGB_COLOR_DEPTH:
00232 
00233                 transform_result = transform_bitmap_RGB_to_MONO(src, dst,
00234                     width, height, row_stride);
00235                 
00236                 break;
00237             case ARGB_COLOR_DEPTH:
00238 
00239                 transform_result = transform_bitmap_ARGB_to_MONO(src, dst,
00240                     width, height, row_stride);
00241                 
00242                 break;
00243             case MONO_COLOR_DEPTH:
00244                 
00245                 transform_result = transform_bitmap_with_same_depth(src, dst,
00246                     width, height, row_stride);
00247                 
00248                 break;
00249             default:
00250                 //Print "Unsupport" message
00251                 break;
00252             }
00253             break;
00254         }
00255     }
00256 
00257     // copy the buffer to gtk widget drawable. use the shared memory automatically.
00258     // make sure the #ifdef USE_SHM is ture.
00259     if (transform_result)
00260     {
00261         gdk_draw_image(ctx.widget->window, ctx.gc, shared_image, 0, 0, 
00262                        xDest, yDest, width, height);    
00263     }
00264 }

void test::OutputDevice::draw_image_with_transform ( const unsigned char *  src,
int  width,
int  height,
int  row_stride,
int  xDest = 0,
int  yDest = 0,
int  transform = PLUGIN_ORIENTATION_LANDSCAPE 
)

Copy data (2 dimensions) directly into virtual framebuffer with transform. This function is helpful when caller does not want to reallocate memory. The caller should make sure the boundary should not exceed the range of framebuffer.

Parameters:
src The source data buffer, which will be copied with transformation.
width The width of source data buffer.
height The height of source data buffer.
row_stride The number of bytes in a row
xDest The absolute x destination in framebuffer.
yDest The absolute y destination in framebuffer. The (xDest, yDest) will be left-top corner of the buffer from landscape view.

Steps: 1. copy data from src to image buffer with transform. 2. draw the image on the widget. Caller should call clearBackground at first to update the image. Maybe we should update image here. TODO.

Definition at line 272 of file test_output_device.cpp.

References ARGB_COLOR_DEPTH, test::OutputDeviceContext::gc, MONO_COLOR_DEPTH, PLUGIN_ORIENTATION_LANDSCAPE, RGB_COLOR_DEPTH, and test::OutputDeviceContext::widget.

00279 {
00280     // copy data to gdkImage, check at first.
00281     if (src == 0 || width <= 0 || height <= 0) 
00282     {
00283         return;
00284     }        
00285 
00286     unsigned char * dst = 0;
00287 
00288     if (transform == PLUGIN_ORIENTATION_LANDSCAPE)
00289     {
00290         update_shared_image(height, width);     
00291     }
00292     else
00293     {
00294         update_shared_image(width, height);
00295     }
00296     
00297     dst = (unsigned char *)shared_image->mem +
00298           (shared_image->bpl * yDest + xDest);
00299 
00300     bool transform_result = false;
00301     
00302     switch(shared_image->bits_per_pixel)
00303     {
00304     case RGB_COLOR_DEPTH:
00305         {
00306             switch(color_dep)
00307             {
00308             case RGB_COLOR_DEPTH:
00309                 
00310                 transform_result = transform_bitmap_with_same_depth(src, dst,
00311                     width, height, row_stride, transform);
00312 
00313                 break;
00314             case ARGB_COLOR_DEPTH:
00315                 
00316                 //Print "Unsupport" message
00317                 
00318                 break;
00319             case MONO_COLOR_DEPTH:
00320 
00321                 transform_result = transform_bitmap_MONO_to_RGB(src, dst,
00322                     width, height, row_stride, transform);
00323                 
00324                 break;
00325             default:
00326                 
00327                 //Print "Unsupport" message
00328                 
00329                 break;
00330             }
00331             break;
00332         }
00333     case ARGB_COLOR_DEPTH:
00334         {
00335             switch(color_dep)
00336             {
00337             case RGB_COLOR_DEPTH:
00338                 
00339                 transform_result = transform_bitmap_RGB_to_ARGB(src, dst,
00340                     width, height, row_stride, transform);
00341                 
00342                 break;
00343             case ARGB_COLOR_DEPTH:
00344 
00345                 transform_result = transform_bitmap_with_same_depth(src, dst,
00346                     width, height, row_stride, transform);
00347                 
00348                 break;
00349             case MONO_COLOR_DEPTH:
00350                 
00351                 transform_result = transform_bitmap_MONO_to_ARGB(src, dst,
00352                     width, height, row_stride, transform);
00353                 
00354                 break;
00355             default:
00356 
00357                 //Print "Unsupport" message
00358                 
00359                 break;
00360             }
00361             break;
00362         }
00363     case MONO_COLOR_DEPTH:
00364         {
00365             switch(color_dep)
00366             {
00367             case RGB_COLOR_DEPTH:
00368 
00369                 transform_result = transform_bitmap_RGB_to_MONO(src, dst,
00370                     width, height, row_stride, transform);
00371                 
00372                 break;
00373             case ARGB_COLOR_DEPTH:
00374 
00375                 transform_result = transform_bitmap_ARGB_to_MONO(src, dst,
00376                     width, height, row_stride, transform);
00377                 
00378                 break;
00379             case MONO_COLOR_DEPTH:
00380                 
00381                 transform_result = transform_bitmap_with_same_depth(src, dst,
00382                     width, height, row_stride, transform);
00383                 
00384                 break;
00385             default:
00386                 //Print "Unsupport" message
00387                 break;
00388             }
00389             break;
00390         }
00391     }
00392 
00393     if (transform_result)
00394     {
00395         gdk_draw_image(ctx.widget->window, ctx.gc, shared_image, 0, 0, 
00396                        xDest, yDest, height, width);
00397     }
00398 }

void test::OutputDevice::draw_line ( int  x1,
int  y1,
int  x2,
int  y2 
)

Draw a line by output device.

Parameters:
x1 The x-coordination of start point.
y1 The y-coordination of srart point.
x2 The x-coordination of end point.
y2 The y-coordination of end point.

Definition at line 129 of file test_output_device.cpp.

References test::OutputDeviceContext::gc, and test::OutputDeviceContext::widget.

00130 {
00131     gdk_draw_line(ctx.widget->window, ctx.gc, x1, y1, x2, y2);
00132 }

void test::OutputDevice::invalidate_rectangle ( const GdkRectangle &  r  ) 

Invalidate a rectangle region.

Parameters:
rect The rectangle of the region

Definition at line 123 of file test_output_device.cpp.

References test::OutputDeviceContext::widget.

00124 {
00125     GdkRectangle rect = r;
00126     gdk_window_invalidate_rect(ctx.widget->window, &rect, TRUE);
00127 }

void test::OutputDevice::map ( OutputDeviceContext context  ) 

Intialize the output device.

Parameters:
Output Device Context

Definition at line 56 of file test_output_device.cpp.

References test::OutputDeviceContext::gc, and test::OutputDeviceContext::widget.

00057 {
00058     ctx.widget = context.widget;
00059     ctx.gc     = context.gc;
00060 
00061     if (xor_gc)
00062     {
00063         g_object_unref(xor_gc);
00064     }
00065 
00066     xor_gc = gdk_gc_new(ctx.widget->window);
00067 
00068     gdk_gc_set_function(xor_gc, GDK_XOR);
00069 
00070     GdkColor color = {0xffffffff, 0xffff, 0xffff, 0xffff};
00071 
00072     gdk_gc_set_foreground(xor_gc, &color);
00073 }

void test::OutputDevice::set_color_depth ( int  c  )  [inline]

Definition at line 59 of file test_output_device.h.

00059 {color_dep = c;}


The documentation for this class was generated from the following files:
Generated by  doxygen 1.6.2-20100208