comparison src/video/SDL_pixels.c @ 2267:c785543d1843

Okay, still some bugs, but everything builds again...
author Sam Lantinga <slouken@libsdl.org>
date Sat, 18 Aug 2007 05:39:09 +0000
parents 202ddfd1cfb1
children 12ea0fdc0df2
comparison
equal deleted inserted replaced
2266:e61ad15a205f 2267:c785543d1843
666 return (map); 666 return (map);
667 } 667 }
668 668
669 /* Map from Palette to BitField */ 669 /* Map from Palette to BitField */
670 static Uint8 * 670 static Uint8 *
671 Map1toN(SDL_PixelFormat * src, Uint32 cmod, SDL_PixelFormat * dst) 671 Map1toN(SDL_PixelFormat * src, Uint8 Rmod, Uint8 Gmod, Uint8 Bmod, Uint8 Amod,
672 SDL_PixelFormat * dst)
672 { 673 {
673 Uint8 *map; 674 Uint8 *map;
674 int i; 675 int i;
675 int bpp; 676 int bpp;
676 unsigned Amod, Rmod, Gmod, Bmod;
677 SDL_Palette *pal = src->palette; 677 SDL_Palette *pal = src->palette;
678 678
679 bpp = ((dst->BytesPerPixel == 3) ? 4 : dst->BytesPerPixel); 679 bpp = ((dst->BytesPerPixel == 3) ? 4 : dst->BytesPerPixel);
680 map = (Uint8 *) SDL_malloc(pal->ncolors * bpp); 680 map = (Uint8 *) SDL_malloc(pal->ncolors * bpp);
681 if (map == NULL) { 681 if (map == NULL) {
682 SDL_OutOfMemory(); 682 SDL_OutOfMemory();
683 return (NULL); 683 return (NULL);
684 } 684 }
685 685
686 Amod = (cmod >> 24) & 0xFF;
687 Rmod = (cmod >> 16) & 0xFF;
688 Gmod = (cmod >> 8) & 0xFF;
689 Bmod = (cmod >> 0) & 0xFF;
690
691 /* We memory copy to the pixel map so the endianness is preserved */ 686 /* We memory copy to the pixel map so the endianness is preserved */
692 for (i = 0; i < pal->ncolors; ++i) { 687 for (i = 0; i < pal->ncolors; ++i) {
693 Uint8 A = Amod; 688 Uint8 A = Amod;
694 Uint8 R = (pal->colors[i].r * Rmod) / 255; 689 Uint8 R = (Uint8) ((pal->colors[i].r * Rmod) / 255);
695 Uint8 G = (pal->colors[i].g * Gmod) / 255; 690 Uint8 G = (Uint8) ((pal->colors[i].g * Gmod) / 255);
696 Uint8 B = (pal->colors[i].b * Bmod) / 255; 691 Uint8 B = (Uint8) ((pal->colors[i].b * Bmod) / 255);
697 ASSEMBLE_RGBA(&map[i * bpp], dst->BytesPerPixel, dst, R, G, B, A); 692 ASSEMBLE_RGBA(&map[i * bpp], dst->BytesPerPixel, dst, R, G, B, A);
698 } 693 }
699 return (map); 694 return (map);
700 } 695 }
701 696
723 map = (SDL_BlitMap *) SDL_calloc(1, sizeof(*map)); 718 map = (SDL_BlitMap *) SDL_calloc(1, sizeof(*map));
724 if (map == NULL) { 719 if (map == NULL) {
725 SDL_OutOfMemory(); 720 SDL_OutOfMemory();
726 return (NULL); 721 return (NULL);
727 } 722 }
728 map->cmod = 0xFFFFFFFF; 723 map->info.r = 0xFF;
724 map->info.g = 0xFF;
725 map->info.b = 0xFF;
726 map->info.a = 0xFF;
729 727
730 /* It's ready to go */ 728 /* It's ready to go */
731 return (map); 729 return (map);
732 } 730 }
733 731
737 if (!map) { 735 if (!map) {
738 return; 736 return;
739 } 737 }
740 map->dst = NULL; 738 map->dst = NULL;
741 map->format_version = (unsigned int) -1; 739 map->format_version = (unsigned int) -1;
742 if (map->table) { 740 if (map->info.table) {
743 SDL_free(map->table); 741 SDL_free(map->info.table);
744 map->table = NULL; 742 map->info.table = NULL;
745 } 743 }
746 } 744 }
747 int 745 int
748 SDL_MapSurface(SDL_Surface * src, SDL_Surface * dst) 746 SDL_MapSurface(SDL_Surface * src, SDL_Surface * dst)
749 { 747 {
765 switch (srcfmt->BytesPerPixel) { 763 switch (srcfmt->BytesPerPixel) {
766 case 1: 764 case 1:
767 switch (dstfmt->BytesPerPixel) { 765 switch (dstfmt->BytesPerPixel) {
768 case 1: 766 case 1:
769 /* Palette --> Palette */ 767 /* Palette --> Palette */
770 map->table = 768 map->info.table =
771 Map1to1(srcfmt->palette, dstfmt->palette, &map->identity); 769 Map1to1(srcfmt->palette, dstfmt->palette, &map->identity);
772 if (!map->identity) { 770 if (!map->identity) {
773 if (map->table == NULL) { 771 if (map->info.table == NULL) {
774 return (-1); 772 return (-1);
775 } 773 }
776 } 774 }
777 if (srcfmt->BitsPerPixel != dstfmt->BitsPerPixel) 775 if (srcfmt->BitsPerPixel != dstfmt->BitsPerPixel)
778 map->identity = 0; 776 map->identity = 0;
779 break; 777 break;
780 778
781 default: 779 default:
782 /* Palette --> BitField */ 780 /* Palette --> BitField */
783 map->table = Map1toN(srcfmt, src->map->cmod, dstfmt); 781 map->info.table =
784 if (map->table == NULL) { 782 Map1toN(srcfmt, src->map->info.r, src->map->info.g,
783 src->map->info.b, src->map->info.a, dstfmt);
784 if (map->info.table == NULL) {
785 return (-1); 785 return (-1);
786 } 786 }
787 break; 787 break;
788 } 788 }
789 break; 789 break;
790 default: 790 default:
791 switch (dstfmt->BytesPerPixel) { 791 switch (dstfmt->BytesPerPixel) {
792 case 1: 792 case 1:
793 /* BitField --> Palette */ 793 /* BitField --> Palette */
794 map->table = MapNto1(srcfmt, dstfmt, &map->identity); 794 map->info.table = MapNto1(srcfmt, dstfmt, &map->identity);
795 if (!map->identity) { 795 if (!map->identity) {
796 if (map->table == NULL) { 796 if (map->info.table == NULL) {
797 return (-1); 797 return (-1);
798 } 798 }
799 } 799 }
800 map->identity = 0; /* Don't optimize to copy */ 800 map->identity = 0; /* Don't optimize to copy */
801 break; 801 break;