Jump to content
  • Advertisement
Sign in to follow this  
raptorstrike

getting individual pixle color from bitmap

This topic is 4981 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

my thread name pretty much says it all. how would you do that in SDL i know that there is a pixle data * and a mask[RBG] within that struct but i cant really see it as a statement or algorithm can some one help me out here can i do somthing like this SDK_Surface* X; X = SDL_LoadBMP("foo.bmp"); if(X->SDL_PixleFormat->Rmask == 0) that kinda thing? i cant help but think there has to be an array there some were

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Alright you have to do this, there is a function in the SDL documentation here it is. . .


Uint32 getpixel(SDL_Surface *surface, int x, int y)
{
int bpp = surface->format->BytesPerPixel;
/* Here p is the address to the pixel we want to retrieve */
Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp;

switch(bpp) {
case 1:
return *p;

case 2:
return *(Uint16 *)p;

case 3:
if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
return p[0]

then do this


SDL_Surface* X;

X = SDL_LoadBMP("foo.bmp")
int xcoor, ycoor;
Uint8 R, G, B;
SDL_GetRGB(getpixel(X, xcoor, ycoor), X->format, &R, &G, &B);

Share this post


Link to post
Share on other sites
THANKS a ton i found that Get_RGB() but couldnt figure out what was wrong with the way i was calling and i never would have discovered that getpixel function had you not mentioned it. thanks!![grin][grin]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!