I have black and white SDL_Surface and I'm trying to change colors, for example from black to white and from white to red. I did it. But it is working too long. Here is code.
SDL_Surface* tempSurface = SDL_DisplayFormat(textSurface);
for(int i=0;i<256;i++){
SDL_SetColorKey(textSurface,SDL_SRCCOLORKEY,SDL_MapRGB(textSurface->format,i,i,i));
SDL_FillRect(tempSurface, 0, SDL_MapRGB(tempSurface->format, 255, i, i));
SDL_BlitSurface(textSurface,0,tempSurface,0);
SDL_FreeSurface(textSurface);
textSurface=tempSurface;
tempSurface = SDL_DisplayFormat(textSurface);
}
SDL_FreeSurface(tempSurface);
How to optimize this algorithm? Or you can suggest another way?
PS It works for a few seconds, but it needs to run very fast. It is C code, but it is not important. SDL is compatible with both languages.
C?C++? So this is working but not fast enough? – talnicolas Mar 20 '12 at 19:03