PDA

View Full Version : most efficient way to get a QPixmap from a QImage



caduel
11th June 2011, 00:13
I am rendering a page of postscript into a (png file which I load into a) QImage, then display that (by converting it into a QPixmap which I display on a QLabel).
For an A4 page (about a million pixels) this is all very fast - except the QImage to QPixmap conversion, which I do by QPixmap::fromImage().
Using a remote X11 connection this one step takes from 5 to 10 seconds... which is kind of annoying.

Is there a faster way to get something drawable out of a QImage?


Best regards
Christoph

wysota
11th June 2011, 00:28
No, unfortunately not. You might go through OpenGL by converting the image to an OpenGL texture and then rendering the texture to something that can be easily converted to a pixmap but it won't change the fact that the pixmap needs to be transfered to the X server which just takes time if the pixmap is big and the server is remote.

caduel
11th June 2011, 11:56
Ok, too bad.

I was hoping that there might be some tricky way to speed it up
(maybe using the fact that most parts of a (or at least my) postscript
document are empty (i.e. white). Or by some not obvious use of some
Flags or Format directives.

In an alternative approach I am rendering directly into a QPixmap.
This is way faster than going the QImage -> QPixmap way ... at least
until you enable antialiasing. Then it is just as slow.
Using antialising when going via QImage does not slow things (further) down.

Maybe it is worthwhile (for antialiasing) to go the QImage way and
split the resulting image in tiles. The drawing of completely empty tiles
might be optimized.
(I'd rather avoid complicating the code by different code paths for antialiasing and such, though.)

Best regards

wysota
11th June 2011, 12:00
I was hoping that there might be some tricky way to speed it up
Maybe you should focus on improving the client-server connection speed, e.g. by compressing the traffic between X and the client. If you're connecting through ssh, you can try issuing "ssh -Y -C" which will enable compression and trusted X11 forwarding.