Jump to content
  • Advertisement
Sign in to follow this  
DeadXorAlive

Manipulating pixels in SDL

This topic is 4626 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

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
Advertisement
Ah yes. I did check the wiki, but I just overlooked the SDL_GetRGB function, how dumb. Thank you very much.

EDIT: Just want to add how happy I am now I can manipulate those pixels! [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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!