[cairo] Pycairo + Pygame
Steve Chaplin
stevech1097 at yahoo.com.au
Wed Oct 12 15:39:26 PDT 2005
On Wed, 2005-10-12 at 00:34 -0700, Vladimir Vukicevic wrote:
> > So I presume now with this change we can do:
> >
> > import cairo
> > import pygame
> >
> > surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 100, 100)
> > import StringIO
> > buffer = StringIO.StringIO()
> > image = pygame.image.frombuffer(buffer)
>
> I'm assuming there's some kind of write_to_png(buffer) call right
> before the pygame.image.frombuffer?
>
> Ideally, you really want pycairo to allocate its own buffer for the
> cairo image surface, and let you access it, to pass it to pygame
> directly as a 32-bbp ARGB image. Otherwise, you waste lots of CPU
> doing png encoding/decoding for no reason, especially if you do this
> often...
>
> - Vlad
You can already do that with something like this:
import array
import cairo
width, height = 30*16, 30*9
data = array.array('c', 'a' * width * height * 4)
stride = width * 4
surface = cairo.ImageSurface.create_for_data (data, cairo.FORMAT_ARGB32,
width, height, stride);
'data' is a Python array object which supports the read/write buffer
protocol. It holds the cairo surface pixel-data in premultiplied ARGB32
format, can Pygame read that format?
Steve
Send instant messages to your online friends http://au.messenger.yahoo.com
More information about the cairo
mailing list