7 static SDL_Color screenpal
[MAX_COLORS
];
10 // clear out all palette entries
11 void palette_reset(void)
16 // given a paletted surface add it's colors in to the screen colormap
17 // then return a surface with the color indexes remapped ready to
18 // be displayed on the screen. insfc is either freed, or reused to
19 // create the returned surface.
20 SDL_Surface
*palette_add(SDL_Surface
*sfc
)
22 SDL_Palette
*pal
= sfc
->format
->palette
;
23 int remap
[MAX_COLORS
];
26 if (sfc
->format
->BitsPerPixel
> 8)
28 staterr("palette_add: input surface is > 8bpp");
32 stat("palette_add: adding %d colors to screen palette...", pal
->ncolors
);
33 for(i
=0;i
<pal
->ncolors
;i
++)
35 remap
[i
] = palette_alloc(pal
->colors
[i
].r
, pal
->colors
[i
].g
, pal
->colors
[i
].b
);
40 SDL_SetColors(screen
->GetSDLSurface(), screenpal
, 0, ncolors
);
43 // remap indexes in surface
46 uint8_t *pixels = (uint8_t *)sfc->pixels + (y * sfc->pitch);
50 *pixels = remap[*pixels];
59 // add the given color to the screen palette and return it's index.
60 int palette_alloc(uint8_t r
, uint8_t g
, uint8_t b
)
64 for(i
=0;i
<ncolors
;i
++)
66 if (screenpal
[i
].r
== r
&& \
67 screenpal
[i
].g
== g
&& \
74 if (ncolors
>= MAX_COLORS
)
76 staterr("palette_alloc: out of color space!");
80 screenpal
[ncolors
].r
= r
;
81 screenpal
[ncolors
].g
= g
;
82 screenpal
[ncolors
].b
= b
;