Until now, I have only used 8-bit BMP’s that I converted to PNG. Now I am
using 24-bit PNG files and not having that palette of course killed my
color-key blitting.
How do you typically do RLE/transparent blitting with high-color surfaces
using SDL_SetColorKey()/ SDL_BlitSurface() ?
Formats that support color keys (TGA, PNG, GIF) will set the colour key
automatically (in SDL_image 1.0.9 and later) to the “transparent” index
(the one you see as transparent when editing the image in Gimp, for
instance). This is normally restricted to 8-bit images. (PNG supports
colour keys for 24-bit images, and SDL_image contains (untested) code for
taking care of it, but I don’t know of any program that generates it.)
Of course, here is what I currently do for 8-bit images:
color_key = SDL_MapRGB(srcimg->format,0x00,0x00,0xFF);
SDL_SetColorKey(srcimg, SDL_SRCCOLORKEY|SDL_RLEACCEL,color_key);
That should still work very well. Remember to call SDL_SetColorKey before
you call SDL_DisplayFormat. And make certain you don’t use that colour
elsewhere! Note that the 24->16bpp conversion is not one-to-one, so the
colour key should be distinct.
If you find the alpha channel convenient for editing and storing images
but don’t want the slowdown, you can easily convert it to a colour key
using something like
for (x, y) in image
if pixel(x, y) has transparent alpha
set_pixel(x, y, colour_key)
else if pixel(x, y) == colour_key
set_pixel(x, y, ersatz)
With the colour key #ff00ff the ersatz can be, say, #f700f7.