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. QPainter, draw pixel buffer via QImage, but result is composited wrong
QtWS25 Last Chance

QPainter, draw pixel buffer via QImage, but result is composited wrong

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 991 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.
  • D Offline
    D Offline
    DavidLudwig
    wrote on last edited by
    #1

    Hello,

    I am working on an app that needs to take raw pixel data and display it on-screen. This is partially working for me, in that I can display the pixel buffer, however, the colors are often wrong. If I try to display a black image, the end result can be dark gray. If I try to display a red image, the image can be a bit off-red.

    The raw pixel buffer is represented by a C-style array, with each pixel being 32 bits in size and with four 8-bit channels, laid out as XRGB, with the 'X' channel needing to be ignored. The pixel buffer gets wrapped via QImage, using QImage::Format_RGB32.

    The problem I encounter is that the pixel buffer's 'X' channel appears to be getting used as if it were an alpha channel. If this is set to 0xff for each pixel, the tinting goes away. If it is set to 0x00, my image is tinted.

    Code that demos this is shown at https://gist.github.com/DavidLudwig/6d460e1c67e9f44ca754e1ef6868ef28

    This sample code is supposed to show a black window, however, the result is gray for me. Here's a screenshot: Screenshot

    Any thoughts on what's up, or perhaps how to fix? Modifying each pixel's 'X' channel is not a viable option, unfortunately.

    1 Reply Last reply
    0
    • Kent-DorfmanK Offline
      Kent-DorfmanK Offline
      Kent-Dorfman
      wrote on last edited by
      #2

      The behaviour you describe is as I would expect from RGB32, as it is essentially AARRGGBB where the alpha is 0xff.

      Unless you can find a recognized bitmap format that ignores the alpha then you WILL have to manually make sure it is set to 0xff in every sample. That means iterating through the array and manually setting it.

      1 Reply Last reply
      0
      • D Offline
        D Offline
        DavidLudwig
        wrote on last edited by
        #3

        Thanks for the reply, Kent.

        Do you have any idea if another solution might be to use a second, black widget, to effectively serve as a background behind the image?

        1 Reply Last reply
        0
        • Kent-DorfmanK Offline
          Kent-DorfmanK Offline
          Kent-Dorfman
          wrote on last edited by
          #4

          cannot think of another solution, other than iterating through the source. Of course you can optimize that to some extent with some fancy iteration logic and using pointer references whenever possible.

          1 Reply Last reply
          0
          • Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #5

            You can try to load it as ARGB32 and then let Qt convert it to RGB32. Then the alpha value should be set to 0xff everywhere. See https://code.woboq.org/qt5/qtbase/src/gui/image/qimage_conversions.cpp.html#_ZL20fetchRGB32ToARGB32PMPjPKhiiPK7QVectorIjEP11QDitherInfo

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

            1 Reply Last reply
            1

            • Login

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