PDA

View Full Version : Loading a QPixmap from raw data



pherthyl
27th January 2008, 01:15
Hi,

For a computer vision class I'm writing a program to capture images from a webcam using opencv and then displaying it in a Qt GUI. The capture all works, and I copy the 3 channel OpenCV image to the 4 byte aligned format necessary for Qt in my capture thread (here's a fast implementation of that: http://www.qtcentre.org/forum/p-qimage-data-via-ffmpeg-post61293/postcount7.html ). Then in my widget's paint event I have this:



void RenderWidget::paintEvent(QPaintEvent*) {
QPainter painter(this);
if(imageData) {
QImage tImg(imageData, 640, 480, QImage::Format_RGB32);
painter.drawImage(QPoint(0,0), tImg);
}
else {
painter.setBrush(Qt::black);
painter.drawRect(rect());
}
}


This works fine and displays correctly, but I really don't like the fact that I'm creating a QImage only to then have it converted to a QPixmap for painting which wastes time (about 5-8% CPU time of a Athlon 64 3200 running at 1GHz)

QPixmap has a loadFromData function but it seems to expect an image encoded in PNG/GIF/JPG and won't take my raw 0xffRRGGBB data.
Is there any way to load a QPixmap from raw data like that or paint that data on screen in a more direct manner (OpenGL is not an option)?

wysota
27th January 2008, 10:12
You will always have to convert between image and pixmap, because image data is stored locally and pixmap data is stored on the X server.

By the way... as far as I know the conversion on Windows is almost transparent so you shouldn't have an overhead here.