Sign in to follow this  
DeadXorAlive

Manipulating pixels in SDL

Recommended Posts

How would I manipulate a pixels (RGB) color value in SDL, based on what that color value is? I came this far, if i haven't made any mistakes:
//Putting a pixel somewhere, given that:
//...Image is an SDL_Surface*
//...x and y are the integer coordinates
//...Pixel is a Uint32 pixel value
Uint8* Ptr = (Uint8*) Image->pixels + y * Image->pitch + x * 4;
*(Uint32 *)Ptr = Pixel;
//Getting a pixel I assume one would simply do:
Uint32 TempPixel = *(Uint32 *)Ptr;  //Now temppixel == pixel

//Now I'm sort of stuck. I would like to, for example, change the RGB values of a pixel so that,
//all R, G and B values will be 255-R, etc. This will turn the pixel into it's negative.

//According to (my understanding of) the documentation:
TempPixel = Pixel & Image->format->Rmask;
TempPixel = Pixel >> Image->format->Rshift;
TempPixel = Pixel << Image->format->Rloss;
//Will yield the Uint8 value of the red component in TempPixel




Will I have to go through all this for every color component, and then call SDL_MapRGB? I just have a very basic understanding of bitwise operations, maybe I'm just on a wrong track here. [Edited by - DeadXorAlive on October 22, 2005 8:35:07 AM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this