Note that there are some explanatory texts on larger screens.

plurals
  1. POQuickest way to convert Cairo Surface to Pygame on OS-X
    primarykey
    data
    text
    <p>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.</p> <p>My next approach was to try PyGame. Using the examples in the <a href="http://www.pygame.org/wiki/CairoPygame" rel="nofollow noreferrer">wiki</a> 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:</p> <ol> <li>Draw to an offscreen cairo ImageSurface and then use Numpy to convert the pixel buffer to a Pygame surface.</li> <li>Share the same memory for both surfaces</li> </ol> <p>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 is for a 800x800 window.</p> <p>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. </p> <p>So now for the questions:</p> <ol> <li>Is it possible to change the pixel format used by either library on the mac to be compatible with each other?</li> <li>If it is not possible what is the fastest way to do the conversion purely in Python?</li> <li>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?</li> <li>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?</li> </ol> <p>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload