[cairo] using ARGB32 surfaces with pygame

Jayesh Salvi jayeshsalvi at gmail.com
Fri Feb 20 07:39:59 PST 2009


I am creating FORMAT_ARGB32 surfaces using pycairo and while rendering 
them as pygame images, I found them to have different colors. It looked 
like there was some incompatibility in RGB order between pycairo and 
pygame. After spending some time, I found following code segment 
somewhere which fixed the colors.

        buf = surface.get_data()
        a = numpy.frombuffer(buf,numpy.uint8)
        a.shape = (surface.get_width(),
        tmp = copy(a[:,:,0])
        a[:,:,0] = a[:,:,2]
        a[:,:,2] = tmp
        return a

It looks like two colors are swapped (I suppose R and B, but I am not 
sure). But it works.

My question is can I avoid doing this? In my app this operation will 
occur many times and hence will affect the performance of GUI. Also it 
adds a dependency on numpy.

I found an old discussion on the mailing list that mentions "ABGR" color 
format (which I suppose is what pygame is expecting above)


But at present I didn't find any such format option in pycairo. All 
FORMATs that are there today are:

Can somebody shed some light?

code <http://code.google.com/p/altcanvas/> | twit 
<http://www.twitter.com/jyro> | blog <http://jyro.blogspot.com>

More information about the cairo mailing list