You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Saturday, May 29th 2010, 12:12am

Optimizing draw on X11 QImage/QPixmap

I am trying to optimally display a real time radar image; basically I receive a proprietary radar image message make a function call to an internal library which fills in a uchar buffer that I pass in. I can tell the function to generate an 8 Bit Indexed, 16 Bit RGB or 32 RGB. I am receiving newly processed buffers at a 10Hz rate.

Right now, I am taking the processed buffer and calling:

Source code

1
2
image_32Bit = new QImage(image_buf_32Bit,width(),height(),width()*4,QImage::Format_RGB32);
update();

and then within paintEvent():

Source code

1
2
QPainter painter(this);
painter.drawImage(0,0,*image_32Bit);


When I make the image full screen 1280x1024, the process takes about 10% CPU on Windows (not bad), but on Linux the process is running ~40% CPU and X is running at ~30%.

Should I be using QPixmap for this instead of QImage? QPixmap doesn't seem to have the same constructor calls where I can say Format_RGB32, and it seems like loadFromData() is expecting an image properly formatted with header information, my buffer is only pixel data.

So I guess the questions are: #1: Is QImage or QPixmap the optimal class for this situation? #2: Are there other techniques I should be using to optimize this in the code, and #3: Are there other things I can do to optimize for X11?

Thanks for any help!

2

Saturday, May 29th 2010, 6:11am

Quoted

#1: Is QImage or QPixmap the optimal class for this situation?

The QT documentation says:"QImage is designed and optimized for I/O, and for direct pixel access and manipulation, while QPixmap is designed and optimized for showing images on screen". My suggestion is, you should try with QPixmat.

Quoted

#2: Are there other techniques I should be using to optimize this in the code

QGLPixelBuffer uses hardware acceleration and has a method toImage().

Quoted

#3: Are there other things I can do to optimize for X11

You can use QGLWidget(which also uses hardware acceleration) to put the pixmap inside it. This will translate all the drawing instruction to OpenGL ones, thus accelerate the drawing.

3

Sunday, May 30th 2010, 2:09am

Thanks for the info, I will take a look at the QGL Classes for hardware acceleration.

As far as QPixmap goes, I'm still not sure how to get my uchar buffer into the QPixmap properly. The uchar buffer can be 8 Bit Indexed, 16 Bit RGB or 32 Bit RGB, but there is no header data in the buffer; pixel one starts at the first index in the buffer.

None of the Constructors look like they match what I'm trying to do. The only thing that makes sense is creating a QPixmap and then calling:

Source code

1
loadFromData ( const uchar * data, uint len, const char * format = 0, Qt::ImageConversionFlags flags = Qt::AutoColor )

But char * format in this case (I believe) is looking for a standard image format like "BMP", "GIF", "PNG", etc, this doesn't make sense in my case. The format parmas in QImage such as: QImage::Format_Indexed8, Format_RGB32, and Format_RGB16 are what I think I need.

I've tried:

Source code

1
2
3
pixmap_32Bit = new QPixmap();
pixmap_32Bit.loadFromData(image_buf_32Bit,width()*height()*4); 
update();

And then in paintEvent():

Source code

1
2
QPainter painter(this);
painter.drawPixmap(0,0,* pixmap_32Bit);

But got nothing in my widget.