Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Is QImage::pixel(int x, int y) expensive?

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

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 800 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pcdangio
    wrote on last edited by
    #1

    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!

    1 Reply Last reply
    0
    • P Offline
      P Offline
      pcdangio
      wrote on last edited by
      #2

      [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).

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved