comparison src/video/SDL_yuv_sw.c @ 1668:4da1ee79c9af SDL-1.3

more tweaking indent options
author Sam Lantinga <slouken@libsdl.org>
date Mon, 29 May 2006 04:04:35 +0000
parents 782fd950bd46
children 8e754b82cecc
comparison
equal deleted inserted replaced
1667:1fddae038bc8 1668:4da1ee79c9af
121 121
122 122
123 /* The colorspace conversion functions */ 123 /* The colorspace conversion functions */
124 124
125 #if 0 /*defined(__GNUC__) && defined(__i386__) && SDL_ASSEMBLY_ROUTINES */ 125 #if 0 /*defined(__GNUC__) && defined(__i386__) && SDL_ASSEMBLY_ROUTINES */
126 extern void Color565DitherYV12MMX1X (int *colortab, Uint32 * rgb_2_pix, 126 extern void Color565DitherYV12MMX1X(int *colortab, Uint32 * rgb_2_pix,
127 unsigned char *lum, unsigned char *cr, 127 unsigned char *lum, unsigned char *cr,
128 unsigned char *cb, unsigned char *out, 128 unsigned char *cb, unsigned char *out,
129 int rows, int cols, int mod); 129 int rows, int cols, int mod);
130 extern void ColorRGBDitherYV12MMX1X (int *colortab, Uint32 * rgb_2_pix, 130 extern void ColorRGBDitherYV12MMX1X(int *colortab, Uint32 * rgb_2_pix,
131 unsigned char *lum, unsigned char *cr, 131 unsigned char *lum, unsigned char *cr,
132 unsigned char *cb, unsigned char *out, 132 unsigned char *cb, unsigned char *out,
133 int rows, int cols, int mod); 133 int rows, int cols, int mod);
134 #endif 134 #endif
135 135
136 static void 136 static void
137 Color16DitherYV12Mod1X (int *colortab, Uint32 * rgb_2_pix, 137 Color16DitherYV12Mod1X(int *colortab, Uint32 * rgb_2_pix,
138 unsigned char *lum, unsigned char *cr, 138 unsigned char *lum, unsigned char *cr,
139 unsigned char *cb, unsigned char *out, 139 unsigned char *cb, unsigned char *out,
140 int rows, int cols, int mod) 140 int rows, int cols, int mod)
141 { 141 {
142 unsigned short *row1; 142 unsigned short *row1;
143 unsigned short *row2; 143 unsigned short *row2;
144 unsigned char *lum2; 144 unsigned char *lum2;
145 int x, y; 145 int x, y;
202 row2 += mod; 202 row2 += mod;
203 } 203 }
204 } 204 }
205 205
206 static void 206 static void
207 Color24DitherYV12Mod1X (int *colortab, Uint32 * rgb_2_pix, 207 Color24DitherYV12Mod1X(int *colortab, Uint32 * rgb_2_pix,
208 unsigned char *lum, unsigned char *cr, 208 unsigned char *lum, unsigned char *cr,
209 unsigned char *cb, unsigned char *out, 209 unsigned char *cb, unsigned char *out,
210 int rows, int cols, int mod) 210 int rows, int cols, int mod)
211 { 211 {
212 unsigned int value; 212 unsigned int value;
213 unsigned char *row1; 213 unsigned char *row1;
214 unsigned char *row2; 214 unsigned char *row2;
215 unsigned char *lum2; 215 unsigned char *lum2;
282 row2 += mod; 282 row2 += mod;
283 } 283 }
284 } 284 }
285 285
286 static void 286 static void
287 Color32DitherYV12Mod1X (int *colortab, Uint32 * rgb_2_pix, 287 Color32DitherYV12Mod1X(int *colortab, Uint32 * rgb_2_pix,
288 unsigned char *lum, unsigned char *cr, 288 unsigned char *lum, unsigned char *cr,
289 unsigned char *cb, unsigned char *out, 289 unsigned char *cb, unsigned char *out,
290 int rows, int cols, int mod) 290 int rows, int cols, int mod)
291 { 291 {
292 unsigned int *row1; 292 unsigned int *row1;
293 unsigned int *row2; 293 unsigned int *row2;
294 unsigned char *lum2; 294 unsigned char *lum2;
295 int x, y; 295 int x, y;
353 * In this function I make use of a nasty trick. The tables have the lower 353 * In this function I make use of a nasty trick. The tables have the lower
354 * 16 bits replicated in the upper 16. This means I can write ints and get 354 * 16 bits replicated in the upper 16. This means I can write ints and get
355 * the horisontal doubling for free (almost). 355 * the horisontal doubling for free (almost).
356 */ 356 */
357 static void 357 static void
358 Color16DitherYV12Mod2X (int *colortab, Uint32 * rgb_2_pix, 358 Color16DitherYV12Mod2X(int *colortab, Uint32 * rgb_2_pix,
359 unsigned char *lum, unsigned char *cr, 359 unsigned char *lum, unsigned char *cr,
360 unsigned char *cb, unsigned char *out, 360 unsigned char *cb, unsigned char *out,
361 int rows, int cols, int mod) 361 int rows, int cols, int mod)
362 { 362 {
363 unsigned int *row1 = (unsigned int *) out; 363 unsigned int *row1 = (unsigned int *) out;
364 const int next_row = cols + (mod / 2); 364 const int next_row = cols + (mod / 2);
365 unsigned int *row2 = row1 + 2 * next_row; 365 unsigned int *row2 = row1 + 2 * next_row;
366 unsigned char *lum2; 366 unsigned char *lum2;
426 row2 += mod; 426 row2 += mod;
427 } 427 }
428 } 428 }
429 429
430 static void 430 static void
431 Color24DitherYV12Mod2X (int *colortab, Uint32 * rgb_2_pix, 431 Color24DitherYV12Mod2X(int *colortab, Uint32 * rgb_2_pix,
432 unsigned char *lum, unsigned char *cr, 432 unsigned char *lum, unsigned char *cr,
433 unsigned char *cb, unsigned char *out, 433 unsigned char *cb, unsigned char *out,
434 int rows, int cols, int mod) 434 int rows, int cols, int mod)
435 { 435 {
436 unsigned int value; 436 unsigned int value;
437 unsigned char *row1 = out; 437 unsigned char *row1 = out;
438 const int next_row = (cols * 2 + mod) * 3; 438 const int next_row = (cols * 2 + mod) * 3;
439 unsigned char *row2 = row1 + 2 * next_row; 439 unsigned char *row2 = row1 + 2 * next_row;
520 row2 += mod; 520 row2 += mod;
521 } 521 }
522 } 522 }
523 523
524 static void 524 static void
525 Color32DitherYV12Mod2X (int *colortab, Uint32 * rgb_2_pix, 525 Color32DitherYV12Mod2X(int *colortab, Uint32 * rgb_2_pix,
526 unsigned char *lum, unsigned char *cr, 526 unsigned char *lum, unsigned char *cr,
527 unsigned char *cb, unsigned char *out, 527 unsigned char *cb, unsigned char *out,
528 int rows, int cols, int mod) 528 int rows, int cols, int mod)
529 { 529 {
530 unsigned int *row1 = (unsigned int *) out; 530 unsigned int *row1 = (unsigned int *) out;
531 const int next_row = cols * 2 + mod; 531 const int next_row = cols * 2 + mod;
532 unsigned int *row2 = row1 + 2 * next_row; 532 unsigned int *row2 = row1 + 2 * next_row;
533 unsigned char *lum2; 533 unsigned char *lum2;
593 row2 += mod; 593 row2 += mod;
594 } 594 }
595 } 595 }
596 596
597 static void 597 static void
598 Color16DitherYUY2Mod1X (int *colortab, Uint32 * rgb_2_pix, 598 Color16DitherYUY2Mod1X(int *colortab, Uint32 * rgb_2_pix,
599 unsigned char *lum, unsigned char *cr, 599 unsigned char *lum, unsigned char *cr,
600 unsigned char *cb, unsigned char *out, 600 unsigned char *cb, unsigned char *out,
601 int rows, int cols, int mod) 601 int rows, int cols, int mod)
602 { 602 {
603 unsigned short *row; 603 unsigned short *row;
604 int x, y; 604 int x, y;
605 int cr_r; 605 int cr_r;
606 int crb_g; 606 int crb_g;
639 row += mod; 639 row += mod;
640 } 640 }
641 } 641 }
642 642
643 static void 643 static void
644 Color24DitherYUY2Mod1X (int *colortab, Uint32 * rgb_2_pix, 644 Color24DitherYUY2Mod1X(int *colortab, Uint32 * rgb_2_pix,
645 unsigned char *lum, unsigned char *cr, 645 unsigned char *lum, unsigned char *cr,
646 unsigned char *cb, unsigned char *out, 646 unsigned char *cb, unsigned char *out,
647 int rows, int cols, int mod) 647 int rows, int cols, int mod)
648 { 648 {
649 unsigned int value; 649 unsigned int value;
650 unsigned char *row; 650 unsigned char *row;
651 int x, y; 651 int x, y;
652 int cr_r; 652 int cr_r;
689 row += mod; 689 row += mod;
690 } 690 }
691 } 691 }
692 692
693 static void 693 static void
694 Color32DitherYUY2Mod1X (int *colortab, Uint32 * rgb_2_pix, 694 Color32DitherYUY2Mod1X(int *colortab, Uint32 * rgb_2_pix,
695 unsigned char *lum, unsigned char *cr, 695 unsigned char *lum, unsigned char *cr,
696 unsigned char *cb, unsigned char *out, 696 unsigned char *cb, unsigned char *out,
697 int rows, int cols, int mod) 697 int rows, int cols, int mod)
698 { 698 {
699 unsigned int *row; 699 unsigned int *row;
700 int x, y; 700 int x, y;
701 int cr_r; 701 int cr_r;
702 int crb_g; 702 int crb_g;
737 * In this function I make use of a nasty trick. The tables have the lower 737 * In this function I make use of a nasty trick. The tables have the lower
738 * 16 bits replicated in the upper 16. This means I can write ints and get 738 * 16 bits replicated in the upper 16. This means I can write ints and get
739 * the horisontal doubling for free (almost). 739 * the horisontal doubling for free (almost).
740 */ 740 */
741 static void 741 static void
742 Color16DitherYUY2Mod2X (int *colortab, Uint32 * rgb_2_pix, 742 Color16DitherYUY2Mod2X(int *colortab, Uint32 * rgb_2_pix,
743 unsigned char *lum, unsigned char *cr, 743 unsigned char *lum, unsigned char *cr,
744 unsigned char *cb, unsigned char *out, 744 unsigned char *cb, unsigned char *out,
745 int rows, int cols, int mod) 745 int rows, int cols, int mod)
746 { 746 {
747 unsigned int *row = (unsigned int *) out; 747 unsigned int *row = (unsigned int *) out;
748 const int next_row = cols + (mod / 2); 748 const int next_row = cols + (mod / 2);
749 int x, y; 749 int x, y;
750 int cr_r; 750 int cr_r;
783 row += next_row; 783 row += next_row;
784 } 784 }
785 } 785 }
786 786
787 static void 787 static void
788 Color24DitherYUY2Mod2X (int *colortab, Uint32 * rgb_2_pix, 788 Color24DitherYUY2Mod2X(int *colortab, Uint32 * rgb_2_pix,
789 unsigned char *lum, unsigned char *cr, 789 unsigned char *lum, unsigned char *cr,
790 unsigned char *cb, unsigned char *out, 790 unsigned char *cb, unsigned char *out,
791 int rows, int cols, int mod) 791 int rows, int cols, int mod)
792 { 792 {
793 unsigned int value; 793 unsigned int value;
794 unsigned char *row = out; 794 unsigned char *row = out;
795 const int next_row = (cols * 2 + mod) * 3; 795 const int next_row = (cols * 2 + mod) * 3;
796 int x, y; 796 int x, y;
839 row += next_row; 839 row += next_row;
840 } 840 }
841 } 841 }
842 842
843 static void 843 static void
844 Color32DitherYUY2Mod2X (int *colortab, Uint32 * rgb_2_pix, 844 Color32DitherYUY2Mod2X(int *colortab, Uint32 * rgb_2_pix,
845 unsigned char *lum, unsigned char *cr, 845 unsigned char *lum, unsigned char *cr,
846 unsigned char *cb, unsigned char *out, 846 unsigned char *cb, unsigned char *out,
847 int rows, int cols, int mod) 847 int rows, int cols, int mod)
848 { 848 {
849 unsigned int *row = (unsigned int *) out; 849 unsigned int *row = (unsigned int *) out;
850 const int next_row = cols * 2 + mod; 850 const int next_row = cols * 2 + mod;
851 int x, y; 851 int x, y;
852 int cr_r; 852 int cr_r;
891 /* 891 /*
892 * How many 1 bits are there in the Uint32. 892 * How many 1 bits are there in the Uint32.
893 * Low performance, do not call often. 893 * Low performance, do not call often.
894 */ 894 */
895 static int 895 static int
896 number_of_bits_set (Uint32 a) 896 number_of_bits_set(Uint32 a)
897 { 897 {
898 if (!a) 898 if (!a)
899 return 0; 899 return 0;
900 if (a & 1) 900 if (a & 1)
901 return 1 + number_of_bits_set (a >> 1); 901 return 1 + number_of_bits_set(a >> 1);
902 return (number_of_bits_set (a >> 1)); 902 return (number_of_bits_set(a >> 1));
903 } 903 }
904 904
905 /* 905 /*
906 * How many 0 bits are there at least significant end of Uint32. 906 * How many 0 bits are there at least significant end of Uint32.
907 * Low performance, do not call often. 907 * Low performance, do not call often.
908 */ 908 */
909 static int 909 static int
910 free_bits_at_bottom (Uint32 a) 910 free_bits_at_bottom(Uint32 a)
911 { 911 {
912 /* assume char is 8 bits */ 912 /* assume char is 8 bits */
913 if (!a) 913 if (!a)
914 return sizeof (Uint32) * 8; 914 return sizeof(Uint32) * 8;
915 if (((Sint32) a) & 1l) 915 if (((Sint32) a) & 1l)
916 return 0; 916 return 0;
917 return 1 + free_bits_at_bottom (a >> 1); 917 return 1 + free_bits_at_bottom(a >> 1);
918 } 918 }
919 919
920 920
921 SDL_Overlay * 921 SDL_Overlay *
922 SDL_CreateYUV_SW (_THIS, int width, int height, Uint32 format, 922 SDL_CreateYUV_SW(_THIS, int width, int height, Uint32 format,
923 SDL_Surface * display) 923 SDL_Surface * display)
924 { 924 {
925 SDL_Overlay *overlay; 925 SDL_Overlay *overlay;
926 struct private_yuvhwdata *swdata; 926 struct private_yuvhwdata *swdata;
927 int *Cr_r_tab; 927 int *Cr_r_tab;
928 int *Cr_g_tab; 928 int *Cr_g_tab;
937 937
938 /* Only RGB packed pixel conversion supported */ 938 /* Only RGB packed pixel conversion supported */
939 if ((display->format->BytesPerPixel != 2) && 939 if ((display->format->BytesPerPixel != 2) &&
940 (display->format->BytesPerPixel != 3) && 940 (display->format->BytesPerPixel != 3) &&
941 (display->format->BytesPerPixel != 4)) { 941 (display->format->BytesPerPixel != 4)) {
942 SDL_SetError ("Can't use YUV data on non 16/24/32 bit surfaces"); 942 SDL_SetError("Can't use YUV data on non 16/24/32 bit surfaces");
943 return (NULL); 943 return (NULL);
944 } 944 }
945 945
946 /* Verify that we support the format */ 946 /* Verify that we support the format */
947 switch (format) { 947 switch (format) {
950 case SDL_YUY2_OVERLAY: 950 case SDL_YUY2_OVERLAY:
951 case SDL_UYVY_OVERLAY: 951 case SDL_UYVY_OVERLAY:
952 case SDL_YVYU_OVERLAY: 952 case SDL_YVYU_OVERLAY:
953 break; 953 break;
954 default: 954 default:
955 SDL_SetError ("Unsupported YUV format"); 955 SDL_SetError("Unsupported YUV format");
956 return (NULL); 956 return (NULL);
957 } 957 }
958 958
959 /* Create the overlay structure */ 959 /* Create the overlay structure */
960 overlay = (SDL_Overlay *) SDL_malloc (sizeof *overlay); 960 overlay = (SDL_Overlay *) SDL_malloc(sizeof *overlay);
961 if (overlay == NULL) { 961 if (overlay == NULL) {
962 SDL_OutOfMemory (); 962 SDL_OutOfMemory();
963 return (NULL); 963 return (NULL);
964 } 964 }
965 SDL_memset (overlay, 0, (sizeof *overlay)); 965 SDL_memset(overlay, 0, (sizeof *overlay));
966 966
967 /* Fill in the basic members */ 967 /* Fill in the basic members */
968 overlay->format = format; 968 overlay->format = format;
969 overlay->w = width; 969 overlay->w = width;
970 overlay->h = height; 970 overlay->h = height;
971 971
972 /* Set up the YUV surface function structure */ 972 /* Set up the YUV surface function structure */
973 overlay->hwfuncs = &sw_yuvfuncs; 973 overlay->hwfuncs = &sw_yuvfuncs;
974 974
975 /* Create the pixel data and lookup tables */ 975 /* Create the pixel data and lookup tables */
976 swdata = (struct private_yuvhwdata *) SDL_malloc (sizeof *swdata); 976 swdata = (struct private_yuvhwdata *) SDL_malloc(sizeof *swdata);
977 overlay->hwdata = swdata; 977 overlay->hwdata = swdata;
978 if (swdata == NULL) { 978 if (swdata == NULL) {
979 SDL_OutOfMemory (); 979 SDL_OutOfMemory();
980 SDL_FreeYUVOverlay (overlay); 980 SDL_FreeYUVOverlay(overlay);
981 return (NULL); 981 return (NULL);
982 } 982 }
983 swdata->stretch = NULL; 983 swdata->stretch = NULL;
984 swdata->display = display; 984 swdata->display = display;
985 swdata->pixels = (Uint8 *) SDL_malloc (width * height * 2); 985 swdata->pixels = (Uint8 *) SDL_malloc(width * height * 2);
986 swdata->colortab = (int *) SDL_malloc (4 * 256 * sizeof (int)); 986 swdata->colortab = (int *) SDL_malloc(4 * 256 * sizeof(int));
987 Cr_r_tab = &swdata->colortab[0 * 256]; 987 Cr_r_tab = &swdata->colortab[0 * 256];
988 Cr_g_tab = &swdata->colortab[1 * 256]; 988 Cr_g_tab = &swdata->colortab[1 * 256];
989 Cb_g_tab = &swdata->colortab[2 * 256]; 989 Cb_g_tab = &swdata->colortab[2 * 256];
990 Cb_b_tab = &swdata->colortab[3 * 256]; 990 Cb_b_tab = &swdata->colortab[3 * 256];
991 swdata->rgb_2_pix = (Uint32 *) SDL_malloc (3 * 768 * sizeof (Uint32)); 991 swdata->rgb_2_pix = (Uint32 *) SDL_malloc(3 * 768 * sizeof(Uint32));
992 r_2_pix_alloc = &swdata->rgb_2_pix[0 * 768]; 992 r_2_pix_alloc = &swdata->rgb_2_pix[0 * 768];
993 g_2_pix_alloc = &swdata->rgb_2_pix[1 * 768]; 993 g_2_pix_alloc = &swdata->rgb_2_pix[1 * 768];
994 b_2_pix_alloc = &swdata->rgb_2_pix[2 * 768]; 994 b_2_pix_alloc = &swdata->rgb_2_pix[2 * 768];
995 if (!swdata->pixels || !swdata->colortab || !swdata->rgb_2_pix) { 995 if (!swdata->pixels || !swdata->colortab || !swdata->rgb_2_pix) {
996 SDL_OutOfMemory (); 996 SDL_OutOfMemory();
997 SDL_FreeYUVOverlay (overlay); 997 SDL_FreeYUVOverlay(overlay);
998 return (NULL); 998 return (NULL);
999 } 999 }
1000 1000
1001 /* Generate the tables for the display surface */ 1001 /* Generate the tables for the display surface */
1002 for (i = 0; i < 256; i++) { 1002 for (i = 0; i < 256; i++) {
1015 */ 1015 */
1016 Rmask = display->format->Rmask; 1016 Rmask = display->format->Rmask;
1017 Gmask = display->format->Gmask; 1017 Gmask = display->format->Gmask;
1018 Bmask = display->format->Bmask; 1018 Bmask = display->format->Bmask;
1019 for (i = 0; i < 256; ++i) { 1019 for (i = 0; i < 256; ++i) {
1020 r_2_pix_alloc[i + 256] = i >> (8 - number_of_bits_set (Rmask)); 1020 r_2_pix_alloc[i + 256] = i >> (8 - number_of_bits_set(Rmask));
1021 r_2_pix_alloc[i + 256] <<= free_bits_at_bottom (Rmask); 1021 r_2_pix_alloc[i + 256] <<= free_bits_at_bottom(Rmask);
1022 g_2_pix_alloc[i + 256] = i >> (8 - number_of_bits_set (Gmask)); 1022 g_2_pix_alloc[i + 256] = i >> (8 - number_of_bits_set(Gmask));
1023 g_2_pix_alloc[i + 256] <<= free_bits_at_bottom (Gmask); 1023 g_2_pix_alloc[i + 256] <<= free_bits_at_bottom(Gmask);
1024 b_2_pix_alloc[i + 256] = i >> (8 - number_of_bits_set (Bmask)); 1024 b_2_pix_alloc[i + 256] = i >> (8 - number_of_bits_set(Bmask));
1025 b_2_pix_alloc[i + 256] <<= free_bits_at_bottom (Bmask); 1025 b_2_pix_alloc[i + 256] <<= free_bits_at_bottom(Bmask);
1026 } 1026 }
1027 1027
1028 /* 1028 /*
1029 * If we have 16-bit output depth, then we double the value 1029 * If we have 16-bit output depth, then we double the value
1030 * in the top word. This means that we can write out both 1030 * in the top word. This means that we can write out both
1058 case SDL_YV12_OVERLAY: 1058 case SDL_YV12_OVERLAY:
1059 case SDL_IYUV_OVERLAY: 1059 case SDL_IYUV_OVERLAY:
1060 if (display->format->BytesPerPixel == 2) { 1060 if (display->format->BytesPerPixel == 2) {
1061 #if 0 /*defined(__GNUC__) && defined(__i386__) && SDL_ASSEMBLY_ROUTINES */ 1061 #if 0 /*defined(__GNUC__) && defined(__i386__) && SDL_ASSEMBLY_ROUTINES */
1062 /* inline assembly functions */ 1062 /* inline assembly functions */
1063 if (SDL_HasMMX () && (Rmask == 0xF800) && 1063 if (SDL_HasMMX() && (Rmask == 0xF800) &&
1064 (Gmask == 0x07E0) && (Bmask == 0x001F) && (width & 15) == 0) { 1064 (Gmask == 0x07E0) && (Bmask == 0x001F) && (width & 15) == 0) {
1065 /*printf("Using MMX 16-bit 565 dither\n");*/ 1065 /*printf("Using MMX 16-bit 565 dither\n");*/
1066 swdata->Display1X = Color565DitherYV12MMX1X; 1066 swdata->Display1X = Color565DitherYV12MMX1X;
1067 } else { 1067 } else {
1068 /*printf("Using C 16-bit dither\n");*/ 1068 /*printf("Using C 16-bit dither\n");*/
1078 swdata->Display2X = Color24DitherYV12Mod2X; 1078 swdata->Display2X = Color24DitherYV12Mod2X;
1079 } 1079 }
1080 if (display->format->BytesPerPixel == 4) { 1080 if (display->format->BytesPerPixel == 4) {
1081 #if 0 /*defined(__GNUC__) && defined(__i386__) && SDL_ASSEMBLY_ROUTINES */ 1081 #if 0 /*defined(__GNUC__) && defined(__i386__) && SDL_ASSEMBLY_ROUTINES */
1082 /* inline assembly functions */ 1082 /* inline assembly functions */
1083 if (SDL_HasMMX () && (Rmask == 0x00FF0000) && 1083 if (SDL_HasMMX() && (Rmask == 0x00FF0000) &&
1084 (Gmask == 0x0000FF00) && 1084 (Gmask == 0x0000FF00) &&
1085 (Bmask == 0x000000FF) && (width & 15) == 0) { 1085 (Bmask == 0x000000FF) && (width & 15) == 0) {
1086 /*printf("Using MMX 32-bit dither\n");*/ 1086 /*printf("Using MMX 32-bit dither\n");*/
1087 swdata->Display1X = ColorRGBDitherYV12MMX1X; 1087 swdata->Display1X = ColorRGBDitherYV12MMX1X;
1088 } else { 1088 } else {
1147 /* We're all done.. */ 1147 /* We're all done.. */
1148 return (overlay); 1148 return (overlay);
1149 } 1149 }
1150 1150
1151 int 1151 int
1152 SDL_LockYUV_SW (_THIS, SDL_Overlay * overlay) 1152 SDL_LockYUV_SW(_THIS, SDL_Overlay * overlay)
1153 { 1153 {
1154 return (0); 1154 return (0);
1155 } 1155 }
1156 1156
1157 void 1157 void
1158 SDL_UnlockYUV_SW (_THIS, SDL_Overlay * overlay) 1158 SDL_UnlockYUV_SW(_THIS, SDL_Overlay * overlay)
1159 { 1159 {
1160 return; 1160 return;
1161 } 1161 }
1162 1162
1163 int 1163 int
1164 SDL_DisplayYUV_SW (_THIS, SDL_Overlay * overlay, SDL_Rect * src, 1164 SDL_DisplayYUV_SW(_THIS, SDL_Overlay * overlay, SDL_Rect * src,
1165 SDL_Rect * dst) 1165 SDL_Rect * dst)
1166 { 1166 {
1167 struct private_yuvhwdata *swdata; 1167 struct private_yuvhwdata *swdata;
1168 int stretch; 1168 int stretch;
1169 int scale_2x; 1169 int scale_2x;
1170 SDL_Surface *display; 1170 SDL_Surface *display;
1190 } 1190 }
1191 } 1191 }
1192 if (stretch) { 1192 if (stretch) {
1193 if (!swdata->stretch) { 1193 if (!swdata->stretch) {
1194 display = swdata->display; 1194 display = swdata->display;
1195 swdata->stretch = SDL_CreateRGBSurface (SDL_SWSURFACE, 1195 swdata->stretch = SDL_CreateRGBSurface(SDL_SWSURFACE,
1196 overlay->w, 1196 overlay->w,
1197 overlay->h, 1197 overlay->h,
1198 display->format-> 1198 display->format->
1199 BitsPerPixel, 1199 BitsPerPixel,
1200 display->format-> 1200 display->format->
1201 Rmask, 1201 Rmask,
1202 display->format-> 1202 display->format->
1203 Gmask, 1203 Gmask,
1204 display->format-> 1204 display->format->Bmask, 0);
1205 Bmask, 0);
1206 if (!swdata->stretch) { 1205 if (!swdata->stretch) {
1207 return (-1); 1206 return (-1);
1208 } 1207 }
1209 } 1208 }
1210 display = swdata->stretch; 1209 display = swdata->stretch;
1236 lum = overlay->pixels[0]; 1235 lum = overlay->pixels[0];
1237 Cr = lum + 1; 1236 Cr = lum + 1;
1238 Cb = lum + 3; 1237 Cb = lum + 3;
1239 break; 1238 break;
1240 default: 1239 default:
1241 SDL_SetError ("Unsupported YUV format in blit"); 1240 SDL_SetError("Unsupported YUV format in blit");
1242 return (-1); 1241 return (-1);
1243 } 1242 }
1244 if (SDL_MUSTLOCK (display)) { 1243 if (SDL_MUSTLOCK(display)) {
1245 if (SDL_LockSurface (display) < 0) { 1244 if (SDL_LockSurface(display) < 0) {
1246 return (-1); 1245 return (-1);
1247 } 1246 }
1248 } 1247 }
1249 if (stretch) { 1248 if (stretch) {
1250 dstp = (Uint8 *) swdata->stretch->pixels; 1249 dstp = (Uint8 *) swdata->stretch->pixels;
1255 } 1254 }
1256 mod = (display->pitch / display->format->BytesPerPixel); 1255 mod = (display->pitch / display->format->BytesPerPixel);
1257 1256
1258 if (scale_2x) { 1257 if (scale_2x) {
1259 mod -= (overlay->w * 2); 1258 mod -= (overlay->w * 2);
1260 swdata->Display2X (swdata->colortab, swdata->rgb_2_pix, 1259 swdata->Display2X(swdata->colortab, swdata->rgb_2_pix,
1261 lum, Cr, Cb, dstp, overlay->h, overlay->w, mod); 1260 lum, Cr, Cb, dstp, overlay->h, overlay->w, mod);
1262 } else { 1261 } else {
1263 mod -= overlay->w; 1262 mod -= overlay->w;
1264 swdata->Display1X (swdata->colortab, swdata->rgb_2_pix, 1263 swdata->Display1X(swdata->colortab, swdata->rgb_2_pix,
1265 lum, Cr, Cb, dstp, overlay->h, overlay->w, mod); 1264 lum, Cr, Cb, dstp, overlay->h, overlay->w, mod);
1266 } 1265 }
1267 if (SDL_MUSTLOCK (display)) { 1266 if (SDL_MUSTLOCK(display)) {
1268 SDL_UnlockSurface (display); 1267 SDL_UnlockSurface(display);
1269 } 1268 }
1270 if (stretch) { 1269 if (stretch) {
1271 display = swdata->display; 1270 display = swdata->display;
1272 SDL_SoftStretch (swdata->stretch, src, display, dst); 1271 SDL_SoftStretch(swdata->stretch, src, display, dst);
1273 } 1272 }
1274 SDL_UpdateRects (display, 1, dst); 1273 SDL_UpdateRects(display, 1, dst);
1275 1274
1276 return (0); 1275 return (0);
1277 } 1276 }
1278 1277
1279 void 1278 void
1280 SDL_FreeYUV_SW (_THIS, SDL_Overlay * overlay) 1279 SDL_FreeYUV_SW(_THIS, SDL_Overlay * overlay)
1281 { 1280 {
1282 struct private_yuvhwdata *swdata; 1281 struct private_yuvhwdata *swdata;
1283 1282
1284 swdata = overlay->hwdata; 1283 swdata = overlay->hwdata;
1285 if (swdata) { 1284 if (swdata) {
1286 if (swdata->stretch) { 1285 if (swdata->stretch) {
1287 SDL_FreeSurface (swdata->stretch); 1286 SDL_FreeSurface(swdata->stretch);
1288 } 1287 }
1289 if (swdata->pixels) { 1288 if (swdata->pixels) {
1290 SDL_free (swdata->pixels); 1289 SDL_free(swdata->pixels);
1291 } 1290 }
1292 if (swdata->colortab) { 1291 if (swdata->colortab) {
1293 SDL_free (swdata->colortab); 1292 SDL_free(swdata->colortab);
1294 } 1293 }
1295 if (swdata->rgb_2_pix) { 1294 if (swdata->rgb_2_pix) {
1296 SDL_free (swdata->rgb_2_pix); 1295 SDL_free(swdata->rgb_2_pix);
1297 } 1296 }
1298 SDL_free (swdata); 1297 SDL_free(swdata);
1299 } 1298 }
1300 } 1299 }
1301 1300
1302 /* vi: set ts=4 sw=4 expandtab: */ 1301 /* vi: set ts=4 sw=4 expandtab: */