The fastest way to convert Cairo Surface to Pygame on OS-X

I am looking for a way to draw smooth animations in Python. I want to use cairo, partly because I like sub-pixel filtering and partly because I'm familiar with the API. My first approach was to use GTK.DrawingArea as a target for the surface of Cairo. While the drawing was quick, I couldn’t find a reliable way to link the display / buffering with vertical sync so that the animation was jerky and unreliable.

My next approach was to try PyGame. Using the examples in the wiki as a starting point, I wrote simple code to animate various jumping balls. The different approaches on the linked page fall into two categories:

  • Draw an off-screen 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, since the conversion takes about 10 ms, which is most of the time fragment that I have for 60 Hz frames. I run the code on a Macbook-pro with 2.2Ghz Core2Duo and Nvidia 8400. The time depends very much on the size of the surface, this is for a 800x800 window.

The second approach addresses the ordering of pixel coordinates. Both cairo and pygame insist that they can only use RGB spelling and do not support conversion. The problem is that when I set up the pygame surface, it uses the BGRA pixel order, which changes completely.

So now for the questions:

  • , mac ?
  • ,       Python?
  • Python , C ?
  • , C , pygame SDL C?

.

+3

Source: https://habr.com/ru/post/1760027/


All Articles