[Qt-interest] QPixmap / QImage performance question

tangke tangk at lemote.com
Sat Jul 25 14:40:24 CEST 2009


On 07/25/2009 01:12 PM, Lucas Jacobs wrote:
> 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
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>    

    * *QImage <qimage.html#QImage-4>* ( uchar * /data/, int /width/, int
      /height/, Format /format/ )
    * *QImage <qimage.html#QImage-5>* ( const uchar * /data/, int
      /width/, int /height/, Format /format/ )
    * *QImage <qimage.html#QImage-6>* ( uchar * /data/, int /width/, int
      /height/, int /bytesPerLine/, Format /format/ )
    * *QImage <qimage.html#QImage-7>* ( const uchar * /data/, int
      /width/, int /height/, int /bytesPerLine/, Format /format/)

  the four contruct function will create the QImage object, and use the 
buffer named data with the format, when you change the data, such as 
data[100], the image will change immediately.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090725/ce5b150a/attachment.html 


More information about the Qt-interest-old mailing list