SDL_Surface and RGBA array

How I can to convert SDL_Surface to RGBA array? I know there is SDL_GetRGBA
function, but how I can to extract pixel (Uint32 pixel for SDL_GetRGBA) with
some
coordinates from surface?

Thx!

I think this works (not on a computer w/ compiler atm)

SDL_Surface *suface;
//…whatever you do to load surface…
SDL_LockSurface( surface );
//surface->pixels = raw data in whatever pixel format
Uint8 r,g,b,a;
SDL_GetRGBA( *((Uint32 *)(suface->pixels + offset *
surface->format->ByesPerPixel )), surface->format ,
&r, &g, &b, &a );
//result now stored in r,g,b, and a.
SDL_UnlockSurface( surface );

You’ll probably want something faster than a
quadtuple(that a word?) indirect reference, check out
http://sdldoc.csn.ul.ie/sdlpixelformat.php for
information about the different ways pixels are stored
in suface->pixels.

— ALakazam wrote:> How I can to convert SDL_Surface to RGBA array? I

know there is SDL_GetRGBA
function, but how I can to extract pixel (Uint32
pixel for SDL_GetRGBA) with
some
coordinates from surface?

Thx!


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software

I believe SDL_Surface->pointer is actually a pointer to the pixels array
of
the surface!.. It’s should be all downhill from there…

Good Luck

Juan Ignacio Carniglia - Programmer - Buenos Aires, Argentina.> -----Original Message-----

From: sdl-admin at libsdl.org [mailto:sdl-admin at libsdl.org] On
Behalf Of ALakazam
Sent: Friday, August 29, 2003 10:48 AM
To: sdl at libsdl.org
Subject: [SDL] SDL_Surface and RGBA array

How I can to convert SDL_Surface to RGBA array? I know there
is SDL_GetRGBA function, but how I can to extract pixel
(Uint32 pixel for SDL_GetRGBA) with some coordinates from surface?

Thx!


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl