QLabelRenderer.cpp

00001 /*********************************************************************** 00002 * * 00003 * ViTooKi * 00004 * * 00005 * title: QLabelRenderer.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: QLabelRenderer.cpp,v 1.17 2006/01/20 15:37:18 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 "QLabelRenderer.hpp" 00053 #include "VideoRenderer.hpp" 00054 00055 00056 QLabelRenderer::QLabelRenderer(const VideoESInfo *_es, UncompressedVideoFrame::ColorSpace colorSpace, 00057 QLabel *qlabel, bool allowUpscaleX, QEvent::Type eventType) 00058 : VideoRenderer(_es, colorSpace, qlabel->width(), qlabel->height(), false, true, allowUpscaleX) 00059 { 00060 dprintf_full("QLabelRenderer Construct %s ES %p\n",this->url, this->es); 00061 this->qlabel = qlabel; 00062 if (!qlabel->pixmap()) { 00063 QPixmap pixmap(qlabel->width(), qlabel->height()); 00064 pixmap.fill(Qt::black); 00065 qlabel->setPixmap(pixmap); 00066 } 00067 qlabel->pixmap()->setOptimization(QPixmap::BestOptim); 00068 this->eventType = eventType; 00069 strcpy(this->url,"QLabelRenderer"); 00070 } 00071 00072 QLabelRenderer::~QLabelRenderer() 00073 { 00074 } 00075 00076 bool QLabelRenderer::updateDisplayRegion() { 00077 00078 if (!es || !es->isVisualStream() 00079 || !qlabel || !qlabel->width() || !qlabel->height()) { 00080 dprintf_err("QLabelRenderer::updateDisplayRegion(): invalid members: es = %p, qlabel = %p\n", 00081 es, qlabel); 00082 ::exit(1); 00083 return false; 00084 } 00085 00086 return VideoRenderer::updateDisplayRegion(); 00087 00088 } 00089 00090 bool QLabelRenderer::open() 00091 { 00092 if (!updateDisplayRegion()) { 00093 state = STREAMERR; 00094 return false; 00095 } 00096 /* initialize frameBuffer */ 00097 if (frameBuffer) { 00098 delete frameBuffer; 00099 frameBuffer = NULL; 00100 } 00101 switch (colorSpace) { 00102 case UncompressedVideoFrame::ColorSpaceGRAY8: 00103 frame_info.size = frame_info.width * frame_info.height; 00104 // construct a frame buffer with 8 bpp and a color table of size 256 00105 frameBuffer = new QFrameBuffer(qlabel, 8, 256, true, eventType); 00106 break; 00107 case UncompressedVideoFrame::ColorSpaceRGB24: 00108 frame_info.size = frame_info.width * frame_info.height * 3; 00109 frameBuffer = new QFrameBuffer(qlabel, 24, 0, false, eventType); 00110 break; 00111 case UncompressedVideoFrame::ColorSpaceRGB32: 00112 frame_info.size = frame_info.width * frame_info.height * 4; 00113 frameBuffer = new QFrameBuffer(qlabel, 32, 0, false, eventType); 00114 break; 00115 default: 00116 dprintf_err("QLabelRenderer::open(): invalid color space: %d\n", colorSpace); 00117 state = STREAMERR; 00118 return false; 00119 } 00120 00121 if (!frameBuffer) { 00122 dprintf_err("QLabelRenderer::open(): QFrameBuffer creation FAILED! (w = %d, h = %d)\n", 00123 qlabel->width(), qlabel->height()); 00124 state = STREAMERR; 00125 return false; 00126 } 00127 00128 //setVideoFrameBuffer(frameBuffer); 00129 state = OPEN; 00130 framesSeen = 0; 00131 currentFrameNumber = 0; 00132 dprintf_small("QLabelRenderer::open(): initialized frame and display regions:\n" 00133 " frame: width = %d, height = %d, size = %d, scaleX = %5.3f, scaleY = %5.3f\n" 00134 " display: x(%d:%d), y(%d:%d), width = %d, height = %d\n", 00135 frame_info.width, frame_info.height, frame_info.size, 00136 FIXED2DOUBLE(frame_info.scaleX), FIXED2DOUBLE(frame_info.scaleY), 00137 display_region.left, display_region.left + display_region.width, 00138 display_region.top, display_region.top + display_region.height, 00139 display_region.width, display_region.height); 00140 return true; 00141 } 00142 00143 00144 int QLabelRenderer::writeFrame(Frame * frm, ESInfo *out_es) 00145 { 00146 return VideoRenderer::writeFrame(frm); 00147 }