[cairo] using ARGB32 surfaces with pygame
Jayesh Salvi
jayeshsalvi at gmail.com
Fri Feb 20 07:39:59 PST 2009
Hi,
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(),
surface.get_height(),4)
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)
http://lists.cairographics.org/archives/cairo/2005-January/002637.html
But at present I didn't find any such format option in pycairo. All
FORMATs that are there today are:
['FORMAT_A1', 'FORMAT_A8', 'FORMAT_ARGB32', 'FORMAT_RGB16_565',
'FORMAT_RGB24']
Can somebody shed some light?
Thanks,
--
Jayesh
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