GP2X Sdl - Getting Raw Pixel Data From A Bitmap


p0is0n

Still Fresh
Joined
Aug 29, 2007
Messages
24
Age
38
Location
UK
Website
Visit site
Hi,

What i want to do is to load in a bitmap, then check the colour value of each pixel in the bitmap.
I know that a SDL_Surface can return a void pointer to the pixel data, but after that i'm kinda lost :huh:

My question is how would i go about getting the pixel colour data from a bitmap loaded into SDL?

I'm guessing i need to cast the void pointer returned by "sdlSurface->pixels" to something, but as i said, i am completely lost here.

If anyone can help explain to me how this would be done, or point me in the direction of some material that could help, it would be much appreciated.

Thanks in advance!
 
Thanks a lot for the link.

I can now access each pixel in my image, i do still have a question though:

How do i get the colour of the pixel, i mean ..... i guess thats what im getting, but how is it stored?
If i'm doing it right black is 0,
and white is 65535

Does anyone know if this is right?
If it is then how would i know what colour is what??

Thanks again!
 
Depends what format you're using on the bitmap.

16bit uses 5 (or 6 for green) bits for each primary colour (red, green, blue). I think there's macros to convert to and from normal 8 bit R,G,B values.

If it's 8 bit then there will also be a pallete of 256 colours.
 
Thanks,
I'm using 16bit.
I'll look into convertng the values into something understandable.
 
SDL_GetRGB will do the job.

Probably not that fast though as they will be unpacking 2 bytes to 3 bytes.
 
Thankyou very much!!!
You just saved me loads of conversions!
Works perfectly, i'm not too bothered about times just yet, it's only ever done at load time anyway.

Thanks again!!
 
Back
Top