X11FrameBuffer.cpp

00001 /*********************************************************************** 00002 * * 00003 * ViTooKi * 00004 * * 00005 * title: X11FrameBuffer.cpp * 00006 * * 00007 * * 00008 * * 00009 * ITEC institute of the University of Klagenfurt (Austria) * 00010 * http://www.itec.uni-klu.ac.at * 00011 * * 00012 * * 00013 * For more information visit the ViTooKi homepage: * 00014 * http://ViTooKi.sourceforge.net * 00015 * vitooki-user@lists.sourceforge.net * 00016 * vitooki-devel@lists.sourceforge.net * 00017 * * 00018 * This file is part of ViTooKi, a free video toolkit. * 00019 * ViTooKi is free software; you can redistribute it and/or * 00020 * modify it under the terms of the GNU General Public License * 00021 * as published by the Free Software Foundation; either version 2 * 00022 * of the License, or (at your option) any later version. * 00023 * * 00024 * This program is distributed in the hope that it will be useful, * 00025 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00026 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00027 * GNU General Public License for more details. * 00028 * * 00029 * You should have received a copy of the GNU General Public License * 00030 * along with this program; if not, write to the Free Software * 00031 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, * 00032 * MA 02111-1307, USA. * 00033 * * 00034 ***********************************************************************/ 00035 00036 /*********************************************************************** 00037 * * 00038 * REVISION HISTORY: * 00039 * * 00040 * $Id: X11FrameBuffer.cpp,v 1.7 2005/04/19 12:51:55 mkropfbe Exp $ 00041 * * 00042 ***********************************************************************/ 00043 00044 #ifndef WIN32 00045 00046 #include "global.hpp" 00047 #include "IO.hpp" 00048 #include "Frame.hpp" 00049 #include "X11FrameBuffer.hpp" 00050 #include "VideoFrameBuffer.hpp" 00051 00052 00053 00054 /*------------ X11FrameBuffer methods --------------------------------------- */ 00055 00056 X11FrameBuffer::X11FrameBuffer(Display *display, Window *xwin, int depth, bool gray, int width, int height) 00057 : VideoFrameBuffer(gray) 00058 { 00059 this->display = display; 00060 this->xwin = xwin; 00061 this->width = width; 00062 this->height = height; 00063 this->depth = depth; 00064 assert(depth % 8 == 0); 00065 00066 gc=XCreateGC(display, *xwin, 0, NULL); 00067 pixmap = (char*)calloc(width*height, sizeof(depth/8)); 00068 image = XCreateImage(display, CopyFromParent, 00069 depth, ZPixmap, 0, pixmap, 00070 width, height, 8 /*don't pad scanline*/, 0); //BitmapPad(display), 0); 00071 // row_size = width + (width % (BitmapPad(display)/8) != 0); 00072 row_size = width; 00073 00074 if (!image || !pixmap) { 00075 dprintf_err("Couldn't initialize blitbuffer at depth %i with dimension %ix%i\n",depth,width,height); 00076 ::exit(1); 00077 } 00078 dprintf_err("X11FrameBuffer: depth %i bit, row_size %i\n",depth, row_size); 00079 } 00080 00081 00082 X11FrameBuffer::~X11FrameBuffer() 00083 { 00084 if(image) 00085 XDestroyImage(image); 00086 image = NULL; 00087 //should be freed automatically by XDestroyImage 00088 if (pixmap) 00089 free(pixmap); 00090 pixmap = NULL; 00091 } 00092 00093 00094 void X11FrameBuffer::setPixel(int x, int y, uint value) { 00095 if (gray) 00096 value = value << 16 | value << 8 | value; 00097 00098 if (depth >=24) { 00099 pixel32 = (uint *)pixmap + y*row_size + x; 00100 *pixel32 = value; 00101 } else { 00102 pixel16 = (unsigned short int *)pixmap + y*row_size + x; 00103 *pixel16 = (unsigned short int) value; 00104 } 00105 } 00106 00107 00108 void X11FrameBuffer::bitBlt(AU *au) { 00109 dprintf_full("X11FrameBuffer::bitBlt AU->size %i\n", au->size); 00110 memcpy(pixmap, au->payload, au->size); 00111 } 00112 00113 00114 void X11FrameBuffer::postPaintEvent() 00115 { 00116 XPutImage(display, *xwin, gc, image, 0,0,0,0, width, height); 00117 XSync(display, 0); 00118 XFlush(display); 00119 } 00120 00121 00122 #endif /* WIN32 */