PDA

View Full Version : Displaying an image from a char array



Cruz
30th October 2016, 16:15
Hello!

I have the task of programming a gui that displays a video stream. Images arrive in a raw pixelwise format as an RGB char array. So each three consecutive bytes describe the R,G, and B component of one pixel (not 32 bit aligned!). Now I'm looking for the best way to solve this with Qt.

Well, I could just draw the raw data as colored pixels (drawRect) in the paintEvent of a widget. This is probably going to be painfully slow.
If I do this off screen on a QPicture and then draw the QPicture on the widget, is it going to be faster?

Then there is QImage. I don't see a way how I could pour the raw data into the QImage with the fromData() or loadFromData() methods. It seems I will have to "set" the QImage pixel by pixel, and then convert it to QPixmap for drawing. This doesn't sound exactly fast either. Does any one have an idea / experience how I could accelerate this process? A high framerate and smooth display are quite crucial for this application.

Would it be better if I rewrite the raw 24 bit buffer to a 32 bit aligned buffer and then go the from-buffer-constructed or fromData() way with a QImage? But then there is still the conversion to QPixmap, and it sounds like my raw pixelwise buffer is actually already in the ideal format to be displayed on the screen. Any ideas?

Cruz

anda_skoa
30th October 2016, 18:22
First you could check if any of the QImage formats applies to your data, e.g. Format_RGB888.

If not you could consider providing a QImageIOHandler for your format.

High performance UI is often done via OpenGL, so you could have a look at that as well.

Cheers,
_