Hi all, I have been meaning to make an account here for a while, but this problem is stumping me. My usual power-googling has returned nothing useful.
My pipeline ends in a texture rendered to the window with the format ARGB, but what I want to achieve is a palette swapping effect. To do this we begin with an INDEX8 surface, but I am trying to take advantage of SDL’s BlitSurface / BlitScaled functions to “guess” what the best colors are when converting from the original 8-bit surface to the destination 8-bit surface with the updated palette.
Simply changing the palette of the original with SDL_SetSurfacePalette produces a mangled image with poorly guessed mapping as is to be expected, but my attempted workaround involves taking advantage of the implicit conversion of SDL_BlitSurface/Scaled to make a “best guess” at the destination, and this works excellently for say, palettizing a window or a non-transparent image, as is discussed quite fully in this article. The problem is that doing so completely ignores the alpha channel, even if the palettes in both surfaces have a transparent color.
At first I thought it had something to do with the masks used in SDL_CreateRGBSurface. I’ve used the bigEndian define trick so that I can use RMASK, GMASK, BMASK, AMASK, but of course this doesn’t work at all with 8-bit surfaces (it fails to create the surface and complains about the pixel format). I understand the fundamental difference between an indexed image and an RGBA surface, but apart from my limited understanding of how these masks can actually be used to create a format (especially if you want something like ARGB and not RGBA), I have already ruled out this is not the problem.
The act of blitting itself ignores the transparency, and it doesn’t matter if I blit an eight bit surface to a thirty two bit surface, or an eight bit surface to an eight bit surface - it simply ignores the transparency and paints color from the new palette wherever the alpha channel should be.
I attempted to use CreateRGBSurfaceWithFormat instead, passing the INDEX8 pixel format, and it still does the same thing!
There has to be a way to do this. All I want is an effect similar to when you hit an enemy in Castlevania: Symphony of the Night, where an enemy adopts a new palette temporarily and cycles the position of the palette colors. I have gotten every step of this process to work but it’s not going to be much good if every time it happens, there is a huge block of color painting the back of the texture.
If anyone is able to clarify if this is possible, and if so, how, I would be extremely grateful!