test_output_device.h

Go to the documentation of this file.
00001 /*
00002  * File Name: test_output_device.h
00003  */
00004 
00005 /*
00006  * This file is part of uds-plugin-pdf.
00007  *
00008  * uds-plugin-pdf is free software: you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation, either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * uds-plugin-pdf is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program. If not, see <http://www.gnu.org/licenses/>.
00020  */
00021 
00022 /**
00023  * Copyright (C) 2008 iRex Technologies B.V.
00024  * All rights reserved.
00025  */
00026 
00027 #ifndef TEST_OUTPUT_DEVICE_H_
00028 #define TEST_OUTPUT_DEVICE_H_
00029 
00030 #include <gtk/gtkwidget.h>
00031 #include <gdk-pixbuf/gdk-pixbuf-core.h>
00032 
00033 namespace test
00034 {
00035 
00036 #define PLUGIN_ORIENTATION_LANDSCAPE    0
00037 #define PLUGIN_ORIENTATION_PORTRAIT     1
00038 
00039 #define MONO_COLOR_DEPTH            8
00040 #define RGB_COLOR_DEPTH             24
00041 #define ARGB_COLOR_DEPTH            32 
00042 #define DEFAULT_ALPHA_VALUE         0
00043 
00044 /// @brief Output device context.
00045 struct OutputDeviceContext
00046 {
00047     GtkWidget *widget;
00048     GdkGC     *gc;
00049 };
00050 
00051 /// @brief The widget output device. NOT SURE THE WIDGET SIZE WILL BE CHANGED OR NOT.
00052 class OutputDevice
00053 {
00054 public:
00055     OutputDevice();
00056     ~OutputDevice(void);
00057 
00058     // Set color depth
00059     void set_color_depth(int c) {color_dep = c;}
00060 
00061     /// @brief Intialize the output device
00062     /// @param Output Device Context
00063     void map(OutputDeviceContext &context);
00064 
00065     /// @brief Invalidate a rectangle region
00066     /// @param rect The rectangle of the region
00067     void invalidate_rectangle(const GdkRectangle &r);
00068 
00069     /// @brief Clear background directly.
00070     /// @param color The background color.
00071     void clear_background(const int color = 0xff, bool flush = false);
00072 
00073     /// @brief Draw a line by output device.
00074     /// @param x1 The x-coordination of start point.
00075     /// @param y1 The y-coordination of srart point.
00076     /// @param x2 The x-coordination of end point.
00077     /// @param y2 The y-coordination of end point.
00078     void draw_line(int x1, int y1, int x2, int y2);
00079 
00080     /// @brief Draw highlight rectangle
00081     /// @param rect The GdkRectangle of the highlight area
00082     void draw_highlight_rectangle(const GdkRectangle &rect);
00083 
00084     /// @brief Copy data (2 dimensions) directly into virtual framebuffer.
00085     /// @param src The source data buffer.
00086     /// @param width The width of source data buffer.  
00087     /// @param row_stride number of bytes in a row.
00088     /// @param height The height of source data buffer.
00089     /// @param xDest The x destination in framebuffer.
00090     /// @param yDest The y destination in framebuffer.
00091     void draw_image(const unsigned char *src, 
00092                     int width, 
00093                     int height,
00094                     int row_stride,
00095                     int xDest = 0,
00096                     int yDest = 0);
00097 
00098     /// @brief Copy data (2 dimensions) directly into virtual framebuffer with transform.
00099     /// This function is helpful when caller does not want to reallocate memory.
00100     /// The caller should make sure the boundary should not exceed the range of framebuffer.
00101     /// @param src The source data buffer, which will be copied with transformation.
00102     /// @param width The width of source data buffer. 
00103     /// @param height The height of source data buffer.
00104     /// @param row_stride The number of bytes in a row
00105     /// @param xDest The absolute x destination in framebuffer.
00106     /// @param yDest The absolute y destination in framebuffer.
00107     /// The (xDest, yDest) will be left-top corner of the buffer from landscape view.
00108     void draw_image_with_transform(const unsigned char *src,
00109                                    int width, 
00110                                    int height,
00111                                    int row_stride,
00112                                    int xDest = 0, 
00113                                    int yDest = 0,
00114                                    int transform = PLUGIN_ORIENTATION_LANDSCAPE);
00115 
00116 private:
00117     /// @brief Update the shared image so that it always has the same size 
00118     /// as the associated widget.
00119     void update_shared_image(GtkWidget *widget);
00120 
00121     /// @brief Update the shared image so that it fits for the appropriate
00122     /// size.
00123     void update_shared_image(int width, int height);
00124 
00125     /// @brief Transform the bitmap
00126     /// Transform the bitmap with the same color depth
00127     bool transform_bitmap_with_same_depth(const unsigned char *src,
00128                                           unsigned char *dst,
00129                                           int width,
00130                                           int height, 
00131                                           int row_stride,
00132                                           int transform = 
00133                                               PLUGIN_ORIENTATION_PORTRAIT);
00134 
00135     /// Transform the bitmap from 8-depth to 24-depth
00136     bool transform_bitmap_MONO_to_RGB(const unsigned char *src,
00137                                       unsigned char *dst,
00138                                       int width,
00139                                       int height, 
00140                                       int row_stride,
00141                                       int transform = 
00142                                           PLUGIN_ORIENTATION_PORTRAIT);
00143 
00144     /// Transform the bitmap from 8-depth to 32-depth
00145     bool transform_bitmap_MONO_to_ARGB(const unsigned char *src,
00146                                        unsigned char *dst,
00147                                        int width,
00148                                        int height, 
00149                                        int row_stride,
00150                                        int transform = 
00151                                            PLUGIN_ORIENTATION_PORTRAIT);
00152 
00153     /// Transform the bitmap from 24-depth to 8-depth
00154     bool transform_bitmap_RGB_to_MONO(const unsigned char *src,
00155                                       unsigned char *dst,
00156                                       int width,
00157                                       int height, 
00158                                       int row_stride,
00159                                       int transform = 
00160                                           PLUGIN_ORIENTATION_PORTRAIT);
00161 
00162     /// Transform the bitmap from 24-depth to 32-depth
00163     bool transform_bitmap_RGB_to_ARGB(const unsigned char *src,
00164                                       unsigned char *dst,
00165                                       int width,
00166                                       int height, 
00167                                       int row_stride,
00168                                       int transform = 
00169                                           PLUGIN_ORIENTATION_PORTRAIT);
00170 
00171     /// Transform the bitmap from 32-depth to 8-depth
00172     bool transform_bitmap_ARGB_to_MONO(const unsigned char *src,
00173                                        unsigned char *dst,
00174                                        int width,
00175                                        int height, 
00176                                        int row_stride,
00177                                        int transform = 
00178                                            PLUGIN_ORIENTATION_PORTRAIT);
00179 
00180     /// Transform the bitmap from 32-depth to 24-depth
00181     bool transform_bitmap_ARGB_to_RGB(const unsigned char *src,
00182                                       unsigned char *dst,
00183                                       int width,
00184                                       int height, 
00185                                       int row_stride,
00186                                       int transform = 
00187                                           PLUGIN_ORIENTATION_PORTRAIT);
00188 
00189 private:
00190     // The widget reference.
00191     OutputDeviceContext ctx;
00192 
00193     // Draw on the shared image.
00194     GdkImage  *shared_image;
00195 
00196     // Current color depth
00197     int       color_dep;
00198 
00199     // XOR GC
00200     GdkGC     *xor_gc;
00201 
00202 };
00203 
00204 }; //namespace test
00205 
00206 #endif
00207 
00208 
Generated by  doxygen 1.6.2-20100208