Fast Color Change

Hi guys,
I have a small problem. I'm working on an emulator for game ROM's, and the part I'm working on right now create a bitmap (at least it is supposed to do so). I have 13 different palettes (each has 16 different colors, COLORREF format:
1
2
3
4
struct _palette
{
    COLORREF Colors[16];
} Pals[13];

) and a big BYTE array with the actual image. Each BYTE refers to one entry of the selected palette. For the final image, I need 13 bitmaps of the raw image (BYTE array), one with each palette. Until now, I just create 13 bitmaps and then use SetPixel() to draw the image 13 times with different palettes. Works fine, except the fact that the image has around 200,000 pixel. Therefore my application needs 3-4 second, just to draw the images.
I thought that there has to be a solution, that allows me to just draw the image once, and then make 12 copies with different colors. I tried to use Logical Palettes with AnimatePalette() (Yes, I used PC_RESERVED for my PALETTEENTRY colors), but it turned out that I have to redraw the image anyways.


So I ask you: Do you know a way how i can change the color of a bitmap without redrawing it?


(Here an example how my code looks like (not my actual code, I shortened it to the most necessary parts, I know that it doesn't work like it is shown here):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void DrawBitmaps(void)
{
    HDC hdc = [...];
    HBITMAP Image = [...];
    _palette Pals[13] = [...];
    BYTE *RawImage = {...};
    int width = [...],
        height = [...], j = 0;
    SelectObject(hdc, Image);

    for(int i = 0 ; i < 13 ; i++)
        for(int y = 0 ; y < height ; y++)
            for(int x = 0 ; x < width ; x++)
                SetPixel(hdc, x, y, Pals[i].Colors[RawImage[j++]]);
}
I'm not sure, but this may help you...
http://www.codeproject.com/KB/graphics/PaletteAni.aspx
First of all, thank you very much, Moooce, for your fast answer. Unfortunately, I tried this code example already. It works with LOGPALETTE and AnimatePalette(), and therefore it needs a redraw additionally to the palette change. I'm looking for a way to change the colors of the image without redrawing it.
Ahh, I didn't look at it completely, but thought that was what the article was about, You know more :-)
Are you sure that your display driver is capable of pallet animations (there is a driver raster capability I believe that reports if it's possable or not)?
I would assume it's impossable to do a pallete rotation on a 32 or 16bit color depth without some kind of redraw.
Have you looked into using OpenGL or DirectX?
With DirectX you could make a pallet based texture and copy it to a 32bit screen using different pallets (Although I've not tried this myself).
This may even be possable with GDI using Hbitmaps rather that setpixel, but again I'm not sure, but maybe some ideas for some Google searches.
Again, thanks for the fast answer Moooce. Your ideas are good, although I try to avoid DirectX or OpenGL, I try to keep it plain C without using frameworks, etc. that are not written by me. But your idea to work with GDI and HBitmaps sounds good, I think I'll expand my research in that direction. (By the way: I'm not quit sure, whether you understand my question fully, to avoid the risk I'll explain it a little bit further: I don't try to change the palette of an image displayed by the display driver; I try to change the palette of the bitmap itself. Or at least copy the image (BitBlt()) to another bitmap, that just allows other colors and forces the colors of the image to change during the copy-process.)
Topic archived. No new replies allowed.