Question

I am using pycairo (actually cairocffi) on Ubuntu 12.04. The library on the system is cairo 1.10. I've created an empty ImageSurface, having an ARGB32 format. If, for example, I try to fill a semi-transparent white rectangle (RGBA(1,1,1,0.5)), I see a semi-transparent grey rectangle.

This is the same for every semi-transparent pixel drawn on a semi-transparent background : it seems cairo considers that blending with a transparent pixel is the same thing as blending with a black pixel... The same issue applies to antialiased shapes drawn on transparent surfaces: they have dark unexpected borders.

There is no reference to this behaviour, nowhere. So I am wondering, is this the expected behaviour of cairo ? How can I fix this ?

Was it helpful?

Solution

I have finally found what was wrong with cairo and the bad alpha blending. Cairo supports ARGB32 surface, but only with premultiplied alpha. That is, every component of a pixel is stored premultiplied with the alpha component.

I have not found an answer for this over the internet, and I assume premultiplied alpha is not suited for the type of operation I'm doing. I switched to PyQt4, used ARGB32 images without premultiplication, and it worked like a charm.

I also tried with PyQt4 premultiplied alpha images, and reproduced the problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top