comparison src/video/SDL_pixels.c @ 2257:340942cfda48

Moved the colorkey and per-surface alpha into the blit info, in preparation for support for general color channel modulation. Removed and consolidated some data in the blit info.
author Sam Lantinga <slouken@libsdl.org>
date Fri, 17 Aug 2007 00:54:53 +0000
parents 2c835d58faad
children 202ddfd1cfb1
comparison
equal deleted inserted replaced
2256:e893d24ad8db 2257:340942cfda48
349 format = SDL_calloc(1, sizeof(*format)); 349 format = SDL_calloc(1, sizeof(*format));
350 if (format == NULL) { 350 if (format == NULL) {
351 SDL_OutOfMemory(); 351 SDL_OutOfMemory();
352 return (NULL); 352 return (NULL);
353 } 353 }
354 format->alpha = SDL_ALPHA_OPAQUE;
355 354
356 /* Set up the format */ 355 /* Set up the format */
357 format->BitsPerPixel = bpp; 356 format->BitsPerPixel = bpp;
358 format->BytesPerPixel = (bpp + 7) / 8; 357 format->BytesPerPixel = (bpp + 7) / 8;
359 if (Rmask || Bmask || Gmask) { /* Packed pixels with custom mask */ 358 if (Rmask || Bmask || Gmask) { /* Packed pixels with custom mask */
667 return (map); 666 return (map);
668 } 667 }
669 668
670 /* Map from Palette to BitField */ 669 /* Map from Palette to BitField */
671 static Uint8 * 670 static Uint8 *
672 Map1toN(SDL_PixelFormat * src, SDL_PixelFormat * dst) 671 Map1toN(SDL_PixelFormat * src, Uint32 cmod, SDL_PixelFormat * dst)
673 { 672 {
674 Uint8 *map; 673 Uint8 *map;
675 int i; 674 int i;
676 int bpp; 675 int bpp;
677 unsigned alpha; 676 unsigned Amod, Rmod, Gmod, Bmod;
678 SDL_Palette *pal = src->palette; 677 SDL_Palette *pal = src->palette;
679 678
680 bpp = ((dst->BytesPerPixel == 3) ? 4 : dst->BytesPerPixel); 679 bpp = ((dst->BytesPerPixel == 3) ? 4 : dst->BytesPerPixel);
681 map = (Uint8 *) SDL_malloc(pal->ncolors * bpp); 680 map = (Uint8 *) SDL_malloc(pal->ncolors * bpp);
682 if (map == NULL) { 681 if (map == NULL) {
683 SDL_OutOfMemory(); 682 SDL_OutOfMemory();
684 return (NULL); 683 return (NULL);
685 } 684 }
686 685
687 alpha = dst->Amask ? src->alpha : 0; 686 Amod = (cmod >> 24) & 0xFF;
687 Rmod = (cmod >> 16) & 0xFF;
688 Gmod = (cmod >> 8) & 0xFF;
689 Bmod = (cmod >> 0) & 0xFF;
690
688 /* We memory copy to the pixel map so the endianness is preserved */ 691 /* We memory copy to the pixel map so the endianness is preserved */
689 for (i = 0; i < pal->ncolors; ++i) { 692 for (i = 0; i < pal->ncolors; ++i) {
690 ASSEMBLE_RGBA(&map[i * bpp], dst->BytesPerPixel, dst, 693 Uint8 A = Amod;
691 pal->colors[i].r, pal->colors[i].g, 694 Uint8 R = (pal->colors[i].r * Rmod) / 255;
692 pal->colors[i].b, alpha); 695 Uint8 G = (pal->colors[i].g * Gmod) / 255;
696 Uint8 B = (pal->colors[i].b * Bmod) / 255;
697 ASSEMBLE_RGBA(&map[i * bpp], dst->BytesPerPixel, dst, R, G, B, A);
693 } 698 }
694 return (map); 699 return (map);
695 } 700 }
696 701
697 /* Map from BitField to Dithered-Palette to Palette */ 702 /* Map from BitField to Dithered-Palette to Palette */
718 map = (SDL_BlitMap *) SDL_calloc(1, sizeof(*map)); 723 map = (SDL_BlitMap *) SDL_calloc(1, sizeof(*map));
719 if (map == NULL) { 724 if (map == NULL) {
720 SDL_OutOfMemory(); 725 SDL_OutOfMemory();
721 return (NULL); 726 return (NULL);
722 } 727 }
723 728 map->cmod = 0xFFFFFFFF;
724 /* Allocate the software blit data */
725 map->sw_data =
726 (struct private_swaccel *) SDL_calloc(1, sizeof(*map->sw_data));
727 if (map->sw_data == NULL) {
728 SDL_FreeBlitMap(map);
729 SDL_OutOfMemory();
730 return (NULL);
731 }
732 729
733 /* It's ready to go */ 730 /* It's ready to go */
734 return (map); 731 return (map);
735 } 732 }
736 733
781 map->identity = 0; 778 map->identity = 0;
782 break; 779 break;
783 780
784 default: 781 default:
785 /* Palette --> BitField */ 782 /* Palette --> BitField */
786 map->table = Map1toN(srcfmt, dstfmt); 783 map->table = Map1toN(srcfmt, src->map->cmod, dstfmt);
787 if (map->table == NULL) { 784 if (map->table == NULL) {
788 return (-1); 785 return (-1);
789 } 786 }
790 break; 787 break;
791 } 788 }
821 void 818 void
822 SDL_FreeBlitMap(SDL_BlitMap * map) 819 SDL_FreeBlitMap(SDL_BlitMap * map)
823 { 820 {
824 if (map) { 821 if (map) {
825 SDL_InvalidateMap(map); 822 SDL_InvalidateMap(map);
826 if (map->sw_data != NULL) {
827 SDL_free(map->sw_data);
828 }
829 SDL_free(map); 823 SDL_free(map);
830 } 824 }
831 } 825 }
832 826
833 /* vi: set ts=4 sw=4 expandtab: */ 827 /* vi: set ts=4 sw=4 expandtab: */