1 #include "SDL.h"
main(int argc,char * argv[])2 int main(int argc, char* argv[]) {
3 SDL_Surface* screen = SDL_SetVideoMode(640, 480, 8, SDL_DOUBLEBUF|SDL_HWSURFACE|SDL_HWPALETTE);
4 SDL_Surface* refpal = SDL_LoadBMP("pic.bmp");
5 SDL_Surface* bnwpal = SDL_LoadBMP("bnw.bmp");
6
7 /* Normal blit */
8 SDL_SetPalette(screen, SDL_LOGPAL, refpal->format->palette->colors, 0, 256);
9 SDL_SetPalette(screen, SDL_PHYSPAL, refpal->format->palette->colors, 0, 256);
10 SDL_BlitSurface(refpal, NULL, screen, NULL);
11 SDL_Flip(screen);
12 SDL_Delay(1000);
13
14 /* Blit on B&W physical palette: everything is B&W */
15 SDL_SetPalette(screen, SDL_PHYSPAL, bnwpal->format->palette->colors, 0, 256);
16 SDL_BlitSurface(refpal, NULL, screen, NULL);
17 SDL_Flip(screen);
18 SDL_Delay(1000);
19
20 /* Dither (DisplayFormat) when screen physical palette is changed:
21 screen logical palette (same as pic.bmp) is used, no change */
22 SDL_Surface* testorig = SDL_LoadBMP("pic.bmp");
23 SDL_SetPalette(screen, SDL_PHYSPAL, bnwpal->format->palette->colors, 0, 256);
24 SDL_Surface* testblit = SDL_DisplayFormat(testorig);
25 SDL_SetPalette(screen, SDL_PHYSPAL, refpal->format->palette->colors, 0, 256);
26 SDL_BlitSurface(testblit, NULL, screen, NULL);
27 SDL_Flip(screen);
28 SDL_Delay(1000);
29 SDL_FreeSurface(testblit);
30
31 /* Dither (DisplayFormat) when screen logical palette is changed:
32 screen logical palette (same as bnw.bmp) is used, the heart is
33 B&W, rest of the screen unchanged */
34 SDL_SetPalette(screen, SDL_LOGPAL, bnwpal->format->palette->colors, 0, 256);
35 testblit = SDL_DisplayFormat(testorig);
36 SDL_SetPalette(screen, SDL_PHYSPAL, refpal->format->palette->colors, 0, 256);
37 SDL_BlitSurface(testblit, NULL, screen, NULL);
38 SDL_Flip(screen);
39 SDL_Delay(1000);
40 SDL_FreeSurface(testblit);
41 }
42
43 /**
44 * Local Variables:
45 * compile-command: "gcc -g paltest.c `sdl-config --cflags --libs` -lSDL_mixer"
46 * End:
47 */
48