Results 1 to 4 of 4

Thread: QImage direct pixel access.

  1. #1
    Join Date
    Dec 2006
    Posts
    160
    Thanks
    33
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QImage direct pixel access.

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QImage direct pixel access.

    Check out the bits() const function:
    http://doc.qt.nokia.com/4.6/qimage.html#bits-2

  3. The following user says thank you to tbscope for this useful post:

    hickscorp (7th May 2010)

  4. #3
    Join Date
    Dec 2006
    Posts
    160
    Thanks
    33
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QImage direct pixel access.

    Thank you very much TBScope, i feel very dumb that it was right below the function i've been reading.
    [EDIT]i suppose it's working like this:
    Qt Code:
    1. QRgb const *tmpBits = (const QRgb*)tmpImg.bits();
    To copy to clipboard, switch view to plain text mode 
    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?[/EDIT]

    Pierre.
    Last edited by hickscorp; 7th May 2010 at 10:10.

  5. #4
    Join Date
    Dec 2006
    Posts
    160
    Thanks
    33
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QImage direct pixel access.

    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.

Similar Threads

  1. Shifting a QImage up by 1 pixel row
    By MSUdom5 in forum Qt Programming
    Replies: 2
    Last Post: 7th May 2010, 10:25
  2. QImage Pixel Coordinations
    By strateng in forum Newbie
    Replies: 2
    Last Post: 6th May 2010, 10:00
  3. Exception (crash) when accessing QImage pixel
    By TheJim01 in forum Newbie
    Replies: 2
    Last Post: 19th February 2010, 21:53
  4. Multithreaded per pixel operations on QImage
    By N¤X in forum Qt Programming
    Replies: 8
    Last Post: 14th September 2009, 12:29
  5. QImage-Greyscale-8-bits-pixel
    By Ivan Labrador in forum Newbie
    Replies: 5
    Last Post: 3rd August 2008, 00:08

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.