Is QImage::pixel(int x, int y) expensive?



  • I've been searching around for a little bit to see if QImage::pixel() is an expensive call to make. If it is, is there a better solution for monochrome format?

    I'm aware of how to use QImage::scanLine(), but it's a pain in this case because a pixel within a monochrome image represents a single bit within a byte within the array of bytes in the image data. So if I'm given a pixel's X and Y, I need to find what byte the bit is located in, retrieve that through scanLine(), and then extract the appropriate bit from the returned byte.

    I wrote code to do this already, but for some weird reason my 80*80 pixel image has a bytesperline of 12, when I expected it to be 10. Anybody know why this would happen?

    Whatever function I use to extract the pixel data must be fast; my software needs to poll every single pixel in the image.

    Thanks guys!



  • [quote author="pcdangio" date="1412868627"]
    I wrote code to do this already, but for some weird reason my 80*80 pixel image has a bytesperline of 12, when I expected it to be 10. Anybody know why this would happen?
    [/quote]

    I found the answer to this particular part of the problem: scanLine() is aligned to a 32bit boundary, meaning each scanline must have a length that is a multiple of 4 bytes (aka 32 bits). That's why bytesperline returns 12 instead of 10... the scanlines are padded with 2 extra bytes to meet the 32 bit boundary (12 is a multiple of 4bytes/32bits, whereas 10 s not).


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.