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. Raw pixel data to QPixmap without copying data
Forum Updated to NodeBB v4.3 + New Features

Raw pixel data to QPixmap without copying data

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 9.7k 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.
  • D Offline
    D Offline
    david.luggen
    wrote on 23 Apr 2014, 10:44 last edited by
    #1

    Hey there,

    Is there a way I can create a QPixmap directly out of raw pixel data without copying this data?

    @
    QImage myImage = new QImage( ucharDataArray, w, h, w3, QImage::Format_RGB888);
    QPixmap *myPixmap = new QPixmap();
    *myPixmap = myPixmap->fromImage(*myImage);
    @

    As I create the QImage out of the data, this works to pass the data and not copy it. But when I try to create a QPixmap out uf the QImage it starts to copy the data. As I'm working with images that are of huge sizes (>1GB) this is something I need to avoid.

    One way would be to write a known Image header like the one from "BMP" in front of the data array, so the QPixmap::loadFromData method would regocnize the data as valable image. But this seems to be quite a hack. Does anyone know a simpler way? Thx for help!

    1 Reply Last reply
    0
    • S Offline
      S Offline
      stevenceuppens
      wrote on 23 Apr 2014, 12:20 last edited by
      #2

      Maybe, you can load your data direclty into a QPixmap?

      @bool QPixmap::loadFromData(...)@

      Steven CEUPPENS
      Developer / Architect
      Mobile: +32 479 65 93 10

      1 Reply Last reply
      0
      • D Offline
        D Offline
        david.luggen
        wrote on 23 Apr 2014, 13:06 last edited by
        #3

        Yes I tried that, but therefore I need to have raw data in a defined image format. These are BMP, GIF, JPG, JPEG, PNG, PBM, PGM, PPM , XBM, XPM.
        If I don't have any header, but only raw pixel data, the method doesn't accept the data as valable image and thus doesn't load anything.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          stevenceuppens
          wrote on 23 Apr 2014, 18:33 last edited by
          #4

          The QPixmap class is an off-screen image representation that can be used as a paint device.

          The QImage class provides a hardware-independent image representation that allows direct access to the pixel data, and can be used as a paint device.

          Both class are quite different in terms of implementation, and i don't think it's currently possible to copy without data-copy...

          Why do you need a QPixmap?

          Steven CEUPPENS
          Developer / Architect
          Mobile: +32 479 65 93 10

          1 Reply Last reply
          0
          • D Offline
            D Offline
            david.luggen
            wrote on 24 Apr 2014, 09:56 last edited by
            #5

            That may be the reason, that the implementation of both classes are different. Although I wonder how a QPixmap is representet. Because I can't think of a more naked representation, than a plain array that contains every pixel with 3 rgb 8-bit values in a row and the width information so you know where to start a new row.

            I need a QPixmap because its way faster to show it on screen than a QImage. Tried it once with QImage and the performance differences with such huge images are enormous.

            1 Reply Last reply
            0
            • A Offline
              A Offline
              agocs
              wrote on 25 Apr 2014, 11:16 last edited by
              #6

              If this is about Qt 5 then the difference between QImage and QPixmap is negligible on most platforms given that a QPixmap will usually be backed by a QImage under the hood.

              Qt 4 was different in this respect since QPixmap was more likely to be backed by a platform-specific native image type there. This is not the case in 5.

              1 Reply Last reply
              0
              • D Offline
                D Offline
                david.luggen
                wrote on 28 Apr 2014, 12:48 last edited by
                #7

                So in terms of Qt5 this means that if I put a QImage into my QGraphicsScene, the performance should stay the same or that it should be no problem to pass a QImage to a QPixmap without copying data?

                1 Reply Last reply
                0

                1/7

                23 Apr 2014, 10:44

                • Login

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