Converting 16 bit bitmaps to 8 bit bitmaps

Hi I’m trying to convert 16 and 24 bit bitmaps to 8 bit surfaces. The only
problem is I am getting blank images. Below is the code I have written. I
think I should be using SDL_ConvertSurface but I don’t know what fields to
fill out and if I should fill out the palette how would I do that?

SDL_Surface* surf,* bitmap_surface;
SDL_PixelFormat format;

surf = IMG_Load (“BLOODCR_a0000000.bmp”);

bitmap_surface = SDL_CreateRGBSurface(SDL_SWSURFACE, surf->w, surf->h, 8,
0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);

SDL_BlitSurface(surf, NULL, bitmap_surface, NULL);

// bitmap_surface = SDL_ConvertSurface(surf, &format, SDL_SWSURFACE);

SDL_SaveBMP(bitmap_surface, “BLOODCR_a0000000.bmp”);

SDL_FreeSurface(surf);
SDL_FreeSurface(bitmap_surface);_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com

Hi I’m trying to convert 16 and 24 bit bitmaps to 8 bit surfaces. The only
problem is I am getting blank images. Below is the code I have written. I
think I should be using SDL_ConvertSurface but I don’t know what fields to
fill out and if I should fill out the palette how would I do that?

Yes, you need to fill out the palette.
Find 256 colors that most closely match your image (or use a standard 332 cube)
and fill the bitmap_surface palette with those values. There is an example
of setting a grayscale palette in test/graywin.c in the SDL source archive.

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment