[Interest] Convertion between QImage to QPixmap taking to much time.

Celal SAVUR c.savur at gmail.com
Tue Oct 20 21:32:02 CEST 2015


Thank you Allan and Gunnar,

I have tried the some of your method but no luck. When I used
Qt::NoFormatConversion flag. If I  do not enable the openGL for my graphic
view, It does not draw a image and it just crash. but whenever I enable the
openGL, it draw but speed is same, in addition to that sometimes,
graphicview cannot draw all image, it just draw half of it and rest of
image is black.

I try also try to implement my own GraphicsItem but when I call
painter.drawimage(0,0, image); it crash. I could not figure out why It
crash. With same code, if I change drawimage to drawline, it works fine.


Do you think is a good to convert raw image data to a known format (XPM) on
fly and load to Qpixmap ? If yes , do you have any suggestion to do that.

thank you in advance.












Celal SAVUR



On Mon, Oct 19, 2015 at 7:09 AM, Gunnar Sletta <gunnar at sletta.org> wrote:

>
> > On 19 Oct 2015, at 13:00, Gunnar Sletta <gunnar at sletta.org> wrote:
> >
> >
> >> On 17 Oct 2015, at 17:28, Celal SAVUR <c.savur at 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.
>
> Bah.. Completely forgot about the Qt::NoImageConversion flag that Allan
> mentioned. That saves you going through QPainter::drawImage() and a bit of
> implementation work :)
>
> >
> > 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 at qt-project.org
> >> http://lists.qt-project.org/mailman/listinfo/interest
> >
> > _______________________________________________
> > Interest mailing list
> > Interest at qt-project.org
> > http://lists.qt-project.org/mailman/listinfo/interest
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20151020/93ef6f00/attachment.html>


More information about the Interest mailing list