Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members
QFrameBuffer.cpp
00001 /*********************************************************************** 00002 * * 00003 * ViTooKi * 00004 * * 00005 * title: QFrameBuffer.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: QFrameBuffer.cpp,v 1.4 2005/02/22 18:26:10 mkropfbe Exp $ 00041 * * 00042 ***********************************************************************/ 00043 00044 #include <qapplication.h> 00045 #include <qevent.h> 00046 #include <qimage.h> 00047 #include <qlabel.h> 00048 #include <qpixmap.h> 00049 #include "global.hpp" 00050 #include "IO.hpp" 00051 #include "Frame.hpp" 00052 #include "QFrameBuffer.hpp" 00053 #include "VideoFrameBuffer.hpp" 00054 00055 00056 00057 /*------------ QFrameBuffer methods --------------------------------------- */ 00058 00059 QFrameBuffer::QFrameBuffer(QLabel *qlabel, int depth, int numColors, bool gray, 00060 QEvent::Type eventType) 00061 : QWidget(qlabel), VideoFrameBuffer(gray) { 00062 00063 this->qlabel = qlabel; 00064 this->eventType = eventType; 00065 int real_depth = (depth == 24) ? 32 : depth; 00066 image = new QImage(qlabel->width(), qlabel->height(), real_depth, numColors); 00067 if (depth == 24) 00068 image->setAlphaBuffer(false); 00069 if (numColors > 0 && gray) { 00070 // initialize the color table to gray values 00071 int i; 00072 QRgb *ct = image->colorTable(); 00073 for (i=0; i < numColors; i++) 00074 ct[i] = qRgb(i, i, i); 00075 } 00076 hide(); // this widget should never be visible! 00077 } 00078 00079 QFrameBuffer::~QFrameBuffer() 00080 { 00081 delete image; 00082 } 00083 00084 /* 00085 * QApplication::postEvent() is thread-safe. 00086 */ 00087 void QFrameBuffer::postPaintEvent() 00088 { 00089 /* request repainting of qlabel without erasing it before */ 00090 QApplication::postEvent(this, new QCustomEvent(eventType)); 00091 } 00092 00093 void QFrameBuffer::customEvent(QCustomEvent *event) 00094 { 00095 int rval; 00096 if (event->type() != eventType) 00097 return; 00098 lock(); 00099 // bitblt into display 00100 rval = qlabel->pixmap()->convertFromImage(*image, 0); 00101 unlock(); 00102 if (rval) { 00103 dprintf_full("QFrameBuffer::customEvent() repainting qlabel\n"); 00104 /* repaint qlabel immediately, without erasing it before */ 00105 QPaintEvent paintEvent(qlabel->visibleRect(), false); 00106 QApplication::sendEvent(qlabel, &paintEvent); 00107 } else { 00108 dprintf_err("QFrameBuffer::paintEvent(): convertFromImage() failed!\n"); 00109 } 00110 }