[SDL] SDL Color-masking Blitting?

Jonathan Dearborn grimfang4 at hotmail.com
Mon Feb 4 15:55:46 PST 2008

Hey Taylor,

There are at least two ways about this.  If you are restricting yourself to a single-color swap like black for dark magenta, you should use a colorkeyed surface:

SDL_Surface* colorSwapSingle(SDL_Surface* surface, Uint32 oldColor, Uint32 newColor)
SDL_SetColorKey(surface, SDL_SRCCOLORKEY, oldColor);
        SDL_Surface* result = SDL_CreateRGBSurface(SDL_SWSURFACE,surface->w,surface->h,32, 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF);
        SDL_Surface* result = SDL_CreateRGBSurface(SDL_SWSURFACE,surface->w,surface->h,32, 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000);
SDL_FillRect(result, NULL, newColor);
SDL_BlitSurface(surface, NULL, result, NULL);
return result;

Otherwise, attached is some code for a very slow blitter that you can tweak to fit your needs.  I think I included all the code you need.  It's all in SPriG at http://pubpages.unh.edu/~jmb97 in case you're interested in that.  If there are any problems, just tell me.

Jonny D

From: terinfire at hotmail.com
To: sdl at lists.libsdl.org
Date: Mon, 4 Feb 2008 10:58:33 -0600
Subject: [SDL] SDL Color-masking Blitting?

I was curious if there was a built-in way to mask a surface and then blit it.  Basically, say I have a font or an image, and it is black and white -- nothing else.  I want to be able to mask the image (say with color 255,0,128, so I have a kind of dark red-magenta), and then blit it.  Is there a way that is built in?  If not, then am I basically just needing to write my own specialized Blit function to do this?  Or if anyone's already done this and is kind and doesn't mind divulging some open-source code, that'd be pretty cool too!

Need to know the score, the latest news, or you need your Hotmail®-get your "fix". Check it out.

Need to know the score, the latest news, or you need your Hotmail®-get your "fix".
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20080204/285fd4d8/attachment-0008.htm>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: Custom Blitter.txt
URL: <http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20080204/285fd4d8/attachment-0008.txt>

More information about the SDL mailing list