Commit ed659a7d authored by Sam Lantinga's avatar Sam Lantinga

Fixed bug #90

The palette -> RGBA blit wasn't following the rule:
 * RGB->RGBA:
 *     SDL_SRCALPHA not set:
 *      copy RGB, set destination alpha to source per-surface alpha value.

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%401561
parent ec2060c8
...@@ -456,44 +456,46 @@ static Uint8 *Map1to1(SDL_Palette *src, SDL_Palette *dst, int *identical) ...@@ -456,44 +456,46 @@ static Uint8 *Map1to1(SDL_Palette *src, SDL_Palette *dst, int *identical)
return(map); return(map);
} }
/* Map from Palette to BitField */ /* Map from Palette to BitField */
static Uint8 *Map1toN(SDL_Palette *src, SDL_PixelFormat *dst) static Uint8 *Map1toN(SDL_PixelFormat *src, SDL_PixelFormat *dst)
{ {
Uint8 *map; Uint8 *map;
int i; int i;
int bpp; int bpp;
unsigned alpha; unsigned alpha;
SDL_Palette *pal = src->palette;
bpp = ((dst->BytesPerPixel == 3) ? 4 : dst->BytesPerPixel); bpp = ((dst->BytesPerPixel == 3) ? 4 : dst->BytesPerPixel);
map = (Uint8 *)SDL_malloc(src->ncolors*bpp); map = (Uint8 *)SDL_malloc(pal->ncolors*bpp);
if ( map == NULL ) { if ( map == NULL ) {
SDL_OutOfMemory(); SDL_OutOfMemory();
return(NULL); return(NULL);
} }
alpha = dst->Amask ? SDL_ALPHA_OPAQUE : 0; alpha = dst->Amask ? src->alpha : 0;
/* We memory copy to the pixel map so the endianness is preserved */ /* We memory copy to the pixel map so the endianness is preserved */
for ( i=0; i<src->ncolors; ++i ) { for ( i=0; i<pal->ncolors; ++i ) {
ASSEMBLE_RGBA(&map[i*bpp], dst->BytesPerPixel, dst, ASSEMBLE_RGBA(&map[i*bpp], dst->BytesPerPixel, dst,
src->colors[i].r, src->colors[i].g, pal->colors[i].r, pal->colors[i].g,
src->colors[i].b, alpha); pal->colors[i].b, alpha);
} }
return(map); return(map);
} }
/* Map from BitField to Dithered-Palette to Palette */ /* Map from BitField to Dithered-Palette to Palette */
static Uint8 *MapNto1(SDL_PixelFormat *src, SDL_Palette *dst, int *identical) static Uint8 *MapNto1(SDL_PixelFormat *src, SDL_PixelFormat *dst, int *identical)
{ {
/* Generate a 256 color dither palette */ /* Generate a 256 color dither palette */
SDL_Palette dithered; SDL_Palette dithered;
SDL_Color colors[256]; SDL_Color colors[256];
SDL_Palette *pal = dst->palette;
/* SDL_DitherColors does not initialize the 'unused' component of colors, /* SDL_DitherColors does not initialize the 'unused' component of colors,
but Map1to1 compares it against dst, so we should initialize it. */ but Map1to1 compares it against pal, so we should initialize it. */
SDL_memset(colors, 0, sizeof(colors)); SDL_memset(colors, 0, sizeof(colors));
dithered.ncolors = 256; dithered.ncolors = 256;
SDL_DitherColors(colors, 8); SDL_DitherColors(colors, 8);
dithered.colors = colors; dithered.colors = colors;
return(Map1to1(&dithered, dst, identical)); return(Map1to1(&dithered, pal, identical));
} }
SDL_BlitMap *SDL_AllocBlitMap(void) SDL_BlitMap *SDL_AllocBlitMap(void)
...@@ -573,7 +575,7 @@ int SDL_MapSurface (SDL_Surface *src, SDL_Surface *dst) ...@@ -573,7 +575,7 @@ int SDL_MapSurface (SDL_Surface *src, SDL_Surface *dst)
default: default:
/* Palette --> BitField */ /* Palette --> BitField */
map->table = Map1toN(srcfmt->palette, dstfmt); map->table = Map1toN(srcfmt, dstfmt);
if ( map->table == NULL ) { if ( map->table == NULL ) {
return(-1); return(-1);
} }
...@@ -584,8 +586,7 @@ int SDL_MapSurface (SDL_Surface *src, SDL_Surface *dst) ...@@ -584,8 +586,7 @@ int SDL_MapSurface (SDL_Surface *src, SDL_Surface *dst)
switch (dstfmt->BytesPerPixel) { switch (dstfmt->BytesPerPixel) {
case 1: case 1:
/* BitField --> Palette */ /* BitField --> Palette */
map->table = MapNto1(srcfmt, map->table = MapNto1(srcfmt, dstfmt, &map->identity);
dstfmt->palette, &map->identity);
if ( ! map->identity ) { if ( ! map->identity ) {
if ( map->table == NULL ) { if ( map->table == NULL ) {
return(-1); return(-1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment