[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Re: [pygame] Getting RAW surface data..



Ah, PERFECT! Forget the other mail I just sent.. ;)
Thanks!

// Wigren

-----Original Message-----
From: Pete Shinners <shredwheat@attbi.com>
To: pygame-users@seul.org
Date: Thu, 10 Oct 2002 08:12:38 -0700
Subject: Re: [pygame] Getting RAW surface data..

Per Wigren wrote:
> How can I get the raw RGBA pixel data from a Surface in Pygame?
> like s->pixels in C...
> 
> I need it to be able to send RGBA32 data to my mplayer-filter so we can show 
> nice transparent menus on the mplayer videoscreen in Freevo.. ;) ( 
> http://freevo.sf.net )

i'm not sure what types of functions there are for an mplayer filter. i am
guessing you will want to use "pygame.image.tostring()" to send raw pixel
data to another library. this is the function you use to send an image to
things like PIL or OpenGL.

the tostring() function can pack the pixel data in a couple different
formats. you pass the format as a string, i'm pretty sure you will want
"RGBA". as a convenience, tostring() can also vertically flip the image
data, which opengl needs. http://pygame.org/docs/ref/pygame_image.html#tostring

the other option would be to use the surfarray to get a Numerica array of
the pixel data. this could be faster, since you can create arrays directly
from the surface pixels, no need to make a copy. unfortunately surfarray
doesn't support "rgba" right now. you can get "rgb" in one array, and then
the alpha in another.

i think our favorite numeric wizard, korruptor, is working on this, but in
any event, the next version of pygame will probably give you RGBA arrays if
you use it on a surface with pixel alphas.


____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org



____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org