Does anyone know of a good fast algorithm to emulate
the 8bit palette shifts
on a 16bit surface? I could replace each pixel
manually but that goes very
slow…
Maybe i should try that in ASM?
I’m a little confused here… mainly due to the lack
of setup information (as 16 bit surfaces = RGB, not
palette).
If you have a source palettized image and a
corresponding 16 bit rgb surface for rendering, I’d do
something like the bellow (note: this only updates
changes in palette… if the source is animated, a
seperate algorythm will be needed for that).
void update (
SDL_Surface *src, //assumed 8 bits in example
SDL_Surface *dest, //assumed 16 bits
UInt8 palc_min,
UInt8 palc_max, //the minimum and maximum range of
palette changes… used to speed up destination
update.
UInt16 *palette //Palette pre-converted into 16 bit
format (points to array…very much optimizable!)
) {
assert( src->w == dest->w );
assert( src->h == dest->h );
if (SDL_MUSTLOCK(src)) SDL_LockSurface(src);
if (SDL_MUSTLOCK(dest)) SDL_LockSurface(dest);
UInt8 *src_pixel = (UInt8 *)src->pixels;
UInt16 *dest_pixel = (UInt16 *)dest->pixels;
unsigned int i = src->w * src->h;
while (i–)
{
if ((*src_pixel >= palc_min) && (*src_pixel <=
palc_max))
*dest_pixel = palette[*src_pixel];
dest_pixel++;
src_pixel++;
}
if (SDL_MUSTLOCK(src)) SDL_UnlockSurface(src);
if (SDL_MUSTLOCK(dest)) SDL_UnlockSurface(dest);
}
possible optimizations: maybe in asm (hopefully the
optimizer will do it), but if allways updating all the
(possibly) animated palletes, make them pushed all to
the back end and eliminate the palc_max parts (aka lay
out the palette so that, say, 0-200 are non animated,
and 201-255 are). This saves a comparison per pixel.
Hope some of that helps.
-Mike__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software