Color Swapping on 8-bit Surfaces

Hi all,

I’m trying to substitute specific colors on an 8-bit RLE encoded surface that I created from a color-keyed bitmap. The surface has no alpha channel, and has a maximum of 4 colors (+ color key).

I’ve tried both SDL_setColors and SDL_setPalette, and they both seem to be hit and miss. I’m really wondering if there’s a way to replace specific colors with other specific colors via SDL_setColors or SDL_setPalette, or at least how an image’s colors are mapped into the surface’s palette.

e.g., my goal is to do something like,

SDL_Color pal[4];

pal[0].r = 0;
pal[0].g = 0;
pal[0].b = 0;
pal[3].r = 255;
pal[3].g = 255;
pal[3].b = 255;

SDL_SetPalette(image, SDL_LOGPAL, pal, 0, 4);

but this doesn’t seem to work. The color replacements seem to happen at random, or not at all.

I’m also wondering if I can make a surface transparent with a palette swap, e.g., by filling the palette with the color key?