Quickest way to convert Cairo Surface to Pygame on OS-X
I'm looking for a way to draw smooth animations in Python. I want to use cairo, partly because I like the sub-pixel filtering and partly because I'm familiar with the API. My first approach was to use a GTK.DrawingArea as the target for a cairo surface. While the drawing was quick I couldn't find any reliable way to tie the display / buffering to the vertical sync so the animation was jerky and unreliable.
My next approach was to try PyGame. Using the examples in the wiki as a starting point I've written some simple code to animate various bouncing balls. The different approaches on the linked page fall into two categories:
- Draw to an offscreen cairo ImageSurface and then use Numpy to convert the pixel buffer to a Pygame surface.
- Share the same memory for both surfaces
The first approach sucks for performance as the conversion takes about 10ms, which is most of the time-slice that I have for 60hz frames. I'm running the code on a Macbook-pro with 2.2Ghz Core2Duo and an Nvidia 8400. The time is very dependent on the size of the surface, this开发者_如何学C is for a 800x800 window.
The second approach surfaces from the ordering of pixel coordinates. Both cairo and pygame insist that they can only use RGB pixel ordering and don't support conversion. The problem is that when I setup a pygame surface it uses BGRA pixel ordering, which completely shafts me.
So now for the questions:
- Is it possible to change the pixel format used by either library on the mac to be compatible with each other?
- If it is not possible what is the fastest way to do the conversion purely in Python?
- If the fastest Python way still sucks up most of the time for a frame then how can I interface to some C code to do the conversion?
- Depending on how complex the interface to C is, how much point is there in using pygame instead of just writing the SDL interface in C?
.
This tutorial also could help you: http://www.pygame.org/wiki/CairoPygame
These may be of help pygame #cairo , squirtle svg pygame
And another thread: SVG rendering in a PyGame application
精彩评论