[Qt-interest] QPixmap / QImage performance question
Lucas Jacobs
lucas.jacobs at mines.sdsmt.edu
Sat Jul 25 07:12:05 CEST 2009
Greetings qt-interest.
I've been tasked with porting an image processing library from wx to
Qt. This library used a simple abstraction of wx's image object,
allowing functions to work with blocks of pixels stored in either HSI
or RGB format (4 bytes per pixel) before copying the block back into
the wx image object and redisplaying the image.
I don't know much about wx, but having used QImage/QPixmap before in
homework assignments and such, I know that QPixmap generally cannot be
accessed like a block of pixels, and that carelessly copying QImages
to QPixmaps with QPixmap::fromImage() can cause poor overall
performance when working with large images. Checking the Qt internal
source code last night, fromImage() seems to copy the entire pixel
data stored in QImage to native image handles, changing the pixel
format and applying alpha changes if necessary. (The image
manipulation routines will likely expect at least 24 bits per pixel,
so I expect that using 32-bit pixels with a zero alpha channel for
every image, even those with a much smaller palette, would be ideal -
and in this case, only the conversion to the native image handle
format would be carried out, if there's anything really to be done.)
I need a way to allow repeated changes with read/write access to every
pixel in large images, displaying the altered image in preferably a
QGraphicsPixmapItem, without a lot of overhead in copying memory. With
the improvements to QPixmap::fromImage() on Windows in Qt 4.5, is the
best course of action to use QImage to access the image (perhaps in a
derived class with the ability to read/write pixels in HSI or RGB
formats) and QPixmap to display it? Should I instead look into
providing an alternative abstraction that uses
QPixmap::toWinHBITMAP(), QPixmap::x11PictureHandle() and
QPixmap::toMacCGImageRef() instead to provide direct read/write access
to the pixel data contained already in a QPixmap?
Thanks for your time.
- Lucas
More information about the Qt-interest-old
mailing list