[solved]Alpha composition in a QGraphicsScene with two overlayed QPixmap
-
I have a main window with 2 QGraphicsScene, each containing 2 QPixmap.
For both QGraphicsScene, the first QPixmap is a greyscale image.
And the second one (drawn on top) is a color ARGB image with transparency.If the ARGB image has binary transparency (0 or 255) the rendering is exactly what I expect.
But if this image has semi transparent pixel, then the composition is a total mess."Correct (binary transparency)":http://pix.wefrag.com/i/a/d/2/d/f/44739f9da96542a083a794ed2eff5531.png :
!http://pix.wefrag.com/i/a/d/2/d/f/th15044739f9da96542a083a794ed2eff5531.png(correct)!
"Incorrect":http://pix.wefrag.com/i/3/9/4/3/c/44740cc2d86c965681266a8ab130904f.png
!http://pix.wefrag.com/i/3/9/4/3/c/th15044740cc2d86c965681266a8ab130904f.png(incorrect)!
"Overlay renderered on white":http://pix.wefrag.com/i/9/d/6/e/e/44741efd1dd259bfbd164bb8f92c6b34.png
!http://pix.wefrag.com/i/9/d/6/e/e/th15044741efd1dd259bfbd164bb8f92c6b34.png(white)!What am I forgetting?
Thanks a lot for your help! -
Thanks for your answer.
I first fill a 4 channel uchar[] buffer that I convert to a QImage with: @QImage image(buffer, imgW, imgH, 4*imgW, QImage::Format_ARGB32_Premultiplied);@ I tried to save a png @image.save("overlay2.png");@ but when I open it with photoshop:- the background is transparent
- the colored pixels are not (just like if they had been merged with a white background)
I have the feeling that my alpha are not correct, but can I trust that png to debug my code?
-
I fixed a few mistakes, but I still have one big issue:
- pixels with alpha=0 are transparent
- pixels with alpha=255 show a correct color
- pixels with alpha€[1-254] have a correct transparency but they are gray!!??
EDIT: fixed by removing the premultiplied flag. If you had not asked for my images, I'm not sure I had searched bugs in this place!