PDA

View Full Version : QImage direct pixel access.



hickscorp
7th May 2010, 09:19
Hello all,

i'm reading the docs from QImage (i'm using Qt 4.6 OpenSource), and it's said that pixel() and setPixel() are consumant (Which is obvious on big pictures), that's why i've been using direct pixel access with bits().
However, i'd like to get an answer to a question i'm having. i'm using bits() in two different contexts. The first one is to read an image and the second one is to write to an image (Because i'm applying a convolution matrix filter to the images, i need the input to be a different set of pixels than the output, since the convolution matrix needs access to the original until it's done).
So, i've been reading that calling the bits() method makes a deep copy of the image data, whatever the use will be... But isn't there a way to get access to those pixels without making a copy, e.g. by returning a const pointer instead of a copy?

Alternatively, isn't there a "pixel()" function which would be inline and using internally a pointer to a function based on image format / depth instead of the nasty switch i'm seeing?

Thanks,
Pierre.

tbscope
7th May 2010, 09:37
Check out the bits() const function:
http://doc.qt.nokia.com/4.6/qimage.html#bits-2

hickscorp
7th May 2010, 09:39
Thank you very much TBScope, i feel very dumb that it was right below the function i've been reading.
i suppose it's working like this:
QRgb const *tmpBits = (const QRgb*)tmpImg.bits();Can you confirm please? Ah no... It's going into the non-const version of the method. i guess i'll have to use a const uchar* instead of a const QRgb. How to force the "overloaded" method to be used?

i've just been testing a lot of things, casting the function result to const uchar*, static_casting, etc... Nothing ends in the const method, my breakpoint in the non-const is hit everytime. Any idea?

Pierre.

hickscorp
7th May 2010, 10:23
Replying to myself... The only way to get the const method to be called is to call it on a QImage const*. If anyone has a way to force it to call on a QImage*, please tell me.

Thanks,
Pierre.