Results 1 to 2 of 2

Thread: Create QPixmap with alpha channel and not premultiplied color channels

  1. #1
    Join Date
    Apr 2011
    Posts
    5
    Qt products

    Default Create QPixmap with alpha channel and not premultiplied color channels

    Hi I posted this before on stackoverflow and got no responses.

    I would like to create a QPixmap to draw on using a QPainter. The QPixmap should support transparency without using premultiplied color channels.

    Currently I do this by creating a QPixmap with the desired dimensions and filling it with a QColor that has been set to zero for each channel (including alpha).

    Qt Code:
    1. tex = QtGui.QPixmap(width, height)
    2. c = QtGui.QColor(0)
    3. c.setAlpha(0)
    4. tex.fill(c)
    To copy to clipboard, switch view to plain text mode 

    This adds transparency to the QPixmap. However, if I draw to the QPixmap using a QPainter, the drawn color values are premultiplied by the alpha value of the source. I don't want this because the QPixmap is later used as a texture in a QGLWidget and upon rendering the alpha channel of the QPixmap (now the alpha of the source that was drawn using the QPainter) is again multiplied against the color channels, so that the alpha is multiplied twice.

    If I use a QImage with format QtGui.QImage.Format_ARGB32 in place of the QPixmap, then the color channels are not premultiplied and the alpha is applied only once. However this is too slow during rendering. I have tried to draw on QImages with the above format and then convert to QPixmaps, but got the same result (premultiplied color channels again being multiplied by the alpha channel). The Qt docs say,

    Depending on the system, QPixmap is stored using a RGB32 or a premultiplied alpha format. If the image has an alpha channel, and if the system allows, the preferred format is premultiplied alpha.
    I am using X (Linux). Is there any way to force a QPixmap to not premultiply the color channels when that QPixmap has an alpha channel?

  2. #2
    Join Date
    Apr 2011
    Posts
    5
    Qt products

    Default Re: Create QPixmap with alpha channel and not premultiplied color channels

    I ended up using QImages and optimizing my code by minimizing the number of QGLWidget::bindTextures I was calling. I still have not received a satisfactory answer about how premultiplied QPixmaps can be used as semi-transparent textures, but I'm satisfied with my program performance and won't be checking this thread anymore.

Similar Threads

  1. QGLWidget renderPixmap and alpha channel
    By omega in forum Newbie
    Replies: 1
    Last Post: 12th September 2015, 01:55
  2. alpha channel problems
    By codebehind in forum Qt Programming
    Replies: 2
    Last Post: 28th February 2010, 22:24
  3. SVG to alpha channel QPixmaps?
    By WinchellChung in forum Newbie
    Replies: 5
    Last Post: 24th August 2007, 21:07
  4. Replies: 2
    Last Post: 3rd November 2006, 22:20
  5. Alpha channel weirdness with QGLContext
    By renaissanz in forum Qt Programming
    Replies: 2
    Last Post: 15th March 2006, 16:10

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.