comparison src/video/SDL_pixels.c @ 1557:61c237f69076

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.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 20 Mar 2006 06:37:58 +0000
parents d910939febfa
children 782fd950bd46 c121d94672cb cd5b5c52a37e
comparison
equal deleted inserted replaced
1556:011b633fa0c9 1557:61c237f69076
454 src->colors[i].r, src->colors[i].g, src->colors[i].b); 454 src->colors[i].r, src->colors[i].g, src->colors[i].b);
455 } 455 }
456 return(map); 456 return(map);
457 } 457 }
458 /* Map from Palette to BitField */ 458 /* Map from Palette to BitField */
459 static Uint8 *Map1toN(SDL_Palette *src, SDL_PixelFormat *dst) 459 static Uint8 *Map1toN(SDL_PixelFormat *src, SDL_PixelFormat *dst)
460 { 460 {
461 Uint8 *map; 461 Uint8 *map;
462 int i; 462 int i;
463 int bpp; 463 int bpp;
464 unsigned alpha; 464 unsigned alpha;
465 SDL_Palette *pal = src->palette;
465 466
466 bpp = ((dst->BytesPerPixel == 3) ? 4 : dst->BytesPerPixel); 467 bpp = ((dst->BytesPerPixel == 3) ? 4 : dst->BytesPerPixel);
467 map = (Uint8 *)SDL_malloc(src->ncolors*bpp); 468 map = (Uint8 *)SDL_malloc(pal->ncolors*bpp);
468 if ( map == NULL ) { 469 if ( map == NULL ) {
469 SDL_OutOfMemory(); 470 SDL_OutOfMemory();
470 return(NULL); 471 return(NULL);
471 } 472 }
472 473
473 alpha = dst->Amask ? SDL_ALPHA_OPAQUE : 0; 474 alpha = dst->Amask ? src->alpha : 0;
474 /* We memory copy to the pixel map so the endianness is preserved */ 475 /* We memory copy to the pixel map so the endianness is preserved */
475 for ( i=0; i<src->ncolors; ++i ) { 476 for ( i=0; i<pal->ncolors; ++i ) {
476 ASSEMBLE_RGBA(&map[i*bpp], dst->BytesPerPixel, dst, 477 ASSEMBLE_RGBA(&map[i*bpp], dst->BytesPerPixel, dst,
477 src->colors[i].r, src->colors[i].g, 478 pal->colors[i].r, pal->colors[i].g,
478 src->colors[i].b, alpha); 479 pal->colors[i].b, alpha);
479 } 480 }
480 return(map); 481 return(map);
481 } 482 }
482 /* Map from BitField to Dithered-Palette to Palette */ 483 /* Map from BitField to Dithered-Palette to Palette */
483 static Uint8 *MapNto1(SDL_PixelFormat *src, SDL_Palette *dst, int *identical) 484 static Uint8 *MapNto1(SDL_PixelFormat *src, SDL_PixelFormat *dst, int *identical)
484 { 485 {
485 /* Generate a 256 color dither palette */ 486 /* Generate a 256 color dither palette */
486 SDL_Palette dithered; 487 SDL_Palette dithered;
487 SDL_Color colors[256]; 488 SDL_Color colors[256];
489 SDL_Palette *pal = dst->palette;
488 490
489 /* SDL_DitherColors does not initialize the 'unused' component of colors, 491 /* SDL_DitherColors does not initialize the 'unused' component of colors,
490 but Map1to1 compares it against dst, so we should initialize it. */ 492 but Map1to1 compares it against pal, so we should initialize it. */
491 SDL_memset(colors, 0, sizeof(colors)); 493 SDL_memset(colors, 0, sizeof(colors));
492 494
493 dithered.ncolors = 256; 495 dithered.ncolors = 256;
494 SDL_DitherColors(colors, 8); 496 SDL_DitherColors(colors, 8);
495 dithered.colors = colors; 497 dithered.colors = colors;
496 return(Map1to1(&dithered, dst, identical)); 498 return(Map1to1(&dithered, pal, identical));
497 } 499 }
498 500
499 SDL_BlitMap *SDL_AllocBlitMap(void) 501 SDL_BlitMap *SDL_AllocBlitMap(void)
500 { 502 {
501 SDL_BlitMap *map; 503 SDL_BlitMap *map;
571 map->identity = 0; 573 map->identity = 0;
572 break; 574 break;
573 575
574 default: 576 default:
575 /* Palette --> BitField */ 577 /* Palette --> BitField */
576 map->table = Map1toN(srcfmt->palette, dstfmt); 578 map->table = Map1toN(srcfmt, dstfmt);
577 if ( map->table == NULL ) { 579 if ( map->table == NULL ) {
578 return(-1); 580 return(-1);
579 } 581 }
580 break; 582 break;
581 } 583 }
582 break; 584 break;
583 default: 585 default:
584 switch (dstfmt->BytesPerPixel) { 586 switch (dstfmt->BytesPerPixel) {
585 case 1: 587 case 1:
586 /* BitField --> Palette */ 588 /* BitField --> Palette */
587 map->table = MapNto1(srcfmt, 589 map->table = MapNto1(srcfmt, dstfmt, &map->identity);
588 dstfmt->palette, &map->identity);
589 if ( ! map->identity ) { 590 if ( ! map->identity ) {
590 if ( map->table == NULL ) { 591 if ( map->table == NULL ) {
591 return(-1); 592 return(-1);
592 } 593 }
593 } 594 }