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. QImage buffer structure
QtWS25 Last Chance

QImage buffer structure

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 515 Views
  • 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.
  • F Offline
    F Offline
    fcarney
    wrote on 16 Jul 2020, 20:01 last edited by
    #1

    Does QImage store its data in a contiguous buffer? I know you can get a scanline pointer and a bits pointer. It says that those point to a single scanline at least. Can this pointer be used to access the entire image?

    I guess the alternative would to make a holder class that feeds it a buffer that is contiguous and access that buffer of data.

    I have a library that resizes images and it requires access to a buffer that is contiguous. So either I have to copy the data out line by line into a working buffer or provide a buffer to the QImage object in the first place.

    C++ is a perfectly valid school of magic.

    1 Reply Last reply
    0
    • F Offline
      F Offline
      fcarney
      wrote on 16 Jul 2020, 20:28 last edited by fcarney
      #2

      I should have just looked at the source code first.
      Yes, it is a continuous segment of memory. The scanline and bits functions return a pointer to this data that is stored as uchar*. The scanline functions actually return a calculated pointer into this data. So I could safely use the const version of these to prevent a detach and process the image data.

      So to access this I should just be using "const uchar *QImage::bits() const" for read only access.

      C++ is a perfectly valid school of magic.

      1 Reply Last reply
      1
      • C Offline
        C Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on 16 Jul 2020, 20:32 last edited by
        #3

        @fcarney said in QImage buffer structure:

        Can this pointer be used to access the entire image?

        Yes, for sure - otherwise it would be a very poor implementation and suboptimal implementation. Also the ctors show you that it's a contiguous buffer since some of them take exactly such a buffer without copying the buffer.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        F 1 Reply Last reply 16 Jul 2020, 20:35
        4
        • C Christian Ehrlicher
          16 Jul 2020, 20:32

          @fcarney said in QImage buffer structure:

          Can this pointer be used to access the entire image?

          Yes, for sure - otherwise it would be a very poor implementation and suboptimal implementation. Also the ctors show you that it's a contiguous buffer since some of them take exactly such a buffer without copying the buffer.

          F Offline
          F Offline
          fcarney
          wrote on 16 Jul 2020, 20:35 last edited by
          #4

          @Christian-Ehrlicher said in QImage buffer structure:

          ctors show you that it's a contiguous buffer since some of them take exactly such a buffer without copying the buffer

          Yes, but I didn't know if the internal implementation was different in that case. I really needed to look at the code and make sure. The documentation didn't lead me to believe this for certain. It is a good point though. Which is part of the reason I wondered.

          C++ is a perfectly valid school of magic.

          1 Reply Last reply
          1

          4/4

          16 Jul 2020, 20:35

          • Login

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