QLabelRenderer Class Reference

This I/O class renders a gray-scale or RGB stream (via a QFrameBuffer) onto a QLabel widget. More...

#include <QLabelRenderer.hpp>

Inheritance diagram for QLabelRenderer:

VideoRenderer IO VThread List of all members.

Public Member Functions

 QLabelRenderer (const VideoESInfo *es, UncompressedVideoFrame::ColorSpace colorSpace, QLabel *qlabel, bool allowUpscaleX=false, QEvent::Type eventType=QEvent::User)
 Constructor.
virtual ~QLabelRenderer ()
 Destructor.
virtual int writeFrame (Frame *frm, ESInfo *out_es=NULL)
 Renders a frame to the destination QLabel widget.
virtual bool open ()
 Creates internal frame buffers and checks whether the stream to be rendered matches the widget dimensions.

Protected Member Functions

bool updateDisplayRegion ()
 Update frame_info (except size) and display_region.

Detailed Description

This I/O class renders a gray-scale or RGB stream (via a QFrameBuffer) onto a QLabel widget.

It is intended to be used as a DataSink connected to a DataChannel.

Video frames will be (down or up) scaled to fit into the QLabel widget by preserving the aspect ratio given in VideoESInfo.

The expected format of the gray-scale stream is: 1 byte per pixel.

The expected format of the RGB24 stream is: 3 bytes per pixel, in the order RGB (red, green, blue).

The expected format of the RGB32 stream is: 4 bytes per pixel, in the order BGRA (blue, green, red, alpha). This conforms to the PIX_FMT_RGBA32 format defined in ffmpeg/libavcodec/avcodec.h on little endian architectures.

Author:
Mario Taschwer
Version:
Id
QLabelRenderer.hpp,v 1.18 2006/01/20 15:37:18 mkropfbe Exp

Definition at line 82 of file QLabelRenderer.hpp.


Constructor & Destructor Documentation

QLabelRenderer::QLabelRenderer const VideoESInfo *  es,
UncompressedVideoFrame::ColorSpace  colorSpace,
QLabel *  qlabel,
bool  allowUpscaleX = false,
QEvent::Type  eventType = QEvent::User
 

Constructor.

If the parameters are invalid, the open() method will fail.

Parameters:
es elementary stream information about the video stream to be rendered.
colorSpace the color space of the video stream to be rendered; must be one of: UncompressedVideoFrame::ColorSpaceGRAY8, UncompressedVideoFrame::ColorSpaceRGB24, UncompressedVideoFrame::ColorSpaceRGB565 UncompressedVideoFrame::ColorSpaceRGB32.
qlabel the QLabel object to render frames on; if not already set, it will be initialized with a pixmap of the same size.
allowUpscaleX if true, video frames may be upscaled in x-dimension to fit the qlabel, which may result in significant quality loss, since a very simple upscaling algorithm is used.
eventType the custom event type used internally to request displaying a video frame on the qlabel widget. The value of this parameter should be in the range [QEvent::User, QEvent::MaxUser].
Definition at line 56 of file QLabelRenderer.cpp.

References UncompressedVideoFrame::ColorSpace.

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 }


Member Function Documentation

bool QLabelRenderer::open  )  [virtual]
 

Creates internal frame buffers and checks whether the stream to be rendered matches the widget dimensions.

Returns:
true on success, false on error.
See also:
IO::open()

Reimplemented from VideoRenderer.

Definition at line 90 of file QLabelRenderer.cpp.

References updateDisplayRegion().

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 }

bool QLabelRenderer::updateDisplayRegion  )  [protected]
 

Update frame_info (except size) and display_region.

This function is not thread-safe, and is internally called by the open() method.

Reimplemented from VideoRenderer.

Definition at line 76 of file QLabelRenderer.cpp.

References VideoRenderer::updateDisplayRegion().

Referenced by open().

00076 { 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 }

int QLabelRenderer::writeFrame Frame frm,
ESInfo out_es = NULL
[virtual]
 

Renders a frame to the destination QLabel widget.

Returns:
1 on success, 0 on error.

Reimplemented from VideoRenderer.

Definition at line 144 of file QLabelRenderer.cpp.

References VideoRenderer::writeFrame().

00145 { 00146 return VideoRenderer::writeFrame(frm); 00147 }


The documentation for this class was generated from the following files: