> On 17 Oct 2015, at 17:28, Celal SAVUR <c.sa...@gmail.com> wrote:
> 
> Hello everyone,
> 
> I have some performance issue when I am using QPixmap.
> 
> I am getting image from buffer and I create QImage. After that using 
> QPixmap::fromImage(), creating pixmap  and set it to QGraphicPixmapItem to be 
> drawn in scene.
> 
> When I put the timer to see how much time Qt spending to create QPixmap, I 
> realize that I converting  from Qimage to QPixmap taking ~20 times more time 
> than crating Qimage from buffer.

If you are using the QImage(uchar *data, int width, int height, ..) overload, 
this is surprising as creating the image from raw pixel data only has to 
allocate the QImage d-pointer and otherwise use the data as is.

Converting that to a QPixmap will entail a QImage::convertToFormat() to map the 
image into a system specific pixel format, usually QImage::RGB32 or 
QImage::ARGB32_Premultiplied, but any given QPA backend may override that with 
an other format if that is more compatible with its raster backingstore.

> By the way, I am getting image approximately every 200 ms some times faster 
> than that.
> 
> Do you have any suggestion to increase the performance? 
> Can I draw QImage into scene  without Qpixmap convertion? How ?

There are a couple of options.

If you can provide the pixel data in a format compatible with the backingstore, 
the conversion can be simpler or just a no-op. 

You can also draw the image directly using QPainter::drawImage(). If you didn't 
set the QGraphicsView viewport to be an OpenGL enabled viewport, then the image 
will be converted to the right format on the fly. The actual drawing will then 
be a bit slower, but as you avoid the conversion, it should be a net win.

You can do that by implementing your own QGraphicsItem and draw the image in 
the virtual paint() function.

If you have a GL viewport, then the image needs to be uploaded to a GL texture. 
QPainter will do this and put the image into some GL_RGB or GL_RGBA data and 
might perform additional conversion before that, but drawing the image using 
QPainter::drawImage might still result in less conversion. 

Of course, if you have a GL viewport and some non-standard format, you can 
potentially speed it up further by implementing a QGraphicsItem which does raw 
GL, encapsulated by QPainter::beginNativePainting()/endNativePainting() and 
then upload to a texture of your choosing and then draw the texture with GL 
commands. 

cheers,
Gunnar

> 
> 
> 
> Thank you.
> 
> Celal
> 
> _______________________________________________
> Interest mailing list
> Interest@qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest

_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to