comparison src/video/SDL_blit_N.c @ 1162:2651158f59b8

Enable altivec blitters on PowerPC Linux, and some fixes for recent GCCs versions.
author Ryan C. Gordon <icculus@icculus.org>
date Thu, 20 Oct 2005 06:55:26 +0000
parents d0ae4dff7208
children 867f521591e5
comparison
equal deleted inserted replaced
1161:05d4b93b911e 1162:2651158f59b8
34 #include "SDL_cpuinfo.h" 34 #include "SDL_cpuinfo.h"
35 35
36 /* Functions to blit from N-bit surfaces to other surfaces */ 36 /* Functions to blit from N-bit surfaces to other surfaces */
37 37
38 #ifdef USE_ALTIVEC_BLITTERS 38 #ifdef USE_ALTIVEC_BLITTERS
39 #include <altivec.h>
39 #include <assert.h> 40 #include <assert.h>
41 #include <stdlib.h>
40 #ifdef MACOSX 42 #ifdef MACOSX
41 #include <sys/sysctl.h> 43 #include <sys/sysctl.h>
42 #include <stdlib.h>
43 static size_t GetL3CacheSize( void ) 44 static size_t GetL3CacheSize( void )
44 { 45 {
45 const char key[] = "hw.l3cachesize"; 46 const char key[] = "hw.l3cachesize";
46 u_int64_t result = 0; 47 u_int64_t result = 0;
47 size_t typeSize = sizeof( result ); 48 size_t typeSize = sizeof( result );
57 { 58 {
58 /* XXX: Just guess G4 */ 59 /* XXX: Just guess G4 */
59 return 2097152; 60 return 2097152;
60 } 61 }
61 #endif /* MACOSX */ 62 #endif /* MACOSX */
63
64 #if ((defined MACOSX) && (__GNUC__ < 4))
65 #define VECUINT8_LITERAL(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \
66 (vector unsigned char) ( a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p )
67 #define VECUINT16_LITERAL(a,b,c,d,e,f,g,h) \
68 (vector unsigned short) ( a,b,c,d,e,f,g,h )
69 #else
70 #define VECUINT8_LITERAL(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \
71 (vector unsigned char) { a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p }
72 #define VECUINT16_LITERAL(a,b,c,d,e,f,g,h) \
73 (vector unsigned short) { a,b,c,d,e,f,g,h }
74 #endif
62 75
63 #define UNALIGNED_PTR(x) (((size_t) x) & 0x0000000F) 76 #define UNALIGNED_PTR(x) (((size_t) x) & 0x0000000F)
64 #define VSWIZZLE32(a,b,c,d) (vector unsigned char) \ 77 #define VSWIZZLE32(a,b,c,d) (vector unsigned char) \
65 ( 0x00+a, 0x00+b, 0x00+c, 0x00+d, \ 78 ( 0x00+a, 0x00+b, 0x00+c, 0x00+d, \
66 0x04+a, 0x04+b, 0x04+c, 0x04+d, \ 79 0x04+a, 0x04+b, 0x04+c, 0x04+d, \
110 srcfmt = &default_pixel_format; 123 srcfmt = &default_pixel_format;
111 } 124 }
112 if (!dstfmt) { 125 if (!dstfmt) {
113 dstfmt = &default_pixel_format; 126 dstfmt = &default_pixel_format;
114 } 127 }
115 vector unsigned char plus = (vector unsigned char)( 0x00, 0x00, 0x00, 0x00, 128 vector unsigned char plus = VECUINT8_LITERAL(
129 0x00, 0x00, 0x00, 0x00,
116 0x04, 0x04, 0x04, 0x04, 130 0x04, 0x04, 0x04, 0x04,
117 0x08, 0x08, 0x08, 0x08, 131 0x08, 0x08, 0x08, 0x08,
118 0x0C, 0x0C, 0x0C, 0x0C ); 132 0x0C, 0x0C, 0x0C, 0x0C );
119 vector unsigned char vswiz; 133 vector unsigned char vswiz;
120 vector unsigned int srcvec; 134 vector unsigned int srcvec;
128 amask = ((srcfmt->Amask) ? RESHIFT(srcfmt->Ashift) : 0x10) << (dstfmt->Ashift); 142 amask = ((srcfmt->Amask) ? RESHIFT(srcfmt->Ashift) : 0x10) << (dstfmt->Ashift);
129 } else { 143 } else {
130 amask = 0x10101010 & ((dstfmt->Rmask | dstfmt->Gmask | dstfmt->Bmask) ^ 0xFFFFFFFF); 144 amask = 0x10101010 & ((dstfmt->Rmask | dstfmt->Gmask | dstfmt->Bmask) ^ 0xFFFFFFFF);
131 } 145 }
132 #undef RESHIFT 146 #undef RESHIFT
133 ((unsigned int *)&srcvec)[0] = (rmask | gmask | bmask | amask); 147 ((unsigned int *)(char*)&srcvec)[0] = (rmask | gmask | bmask | amask);
134 vswiz = vec_add(plus, (vector unsigned char)vec_splat(srcvec, 0)); 148 vswiz = vec_add(plus, (vector unsigned char)vec_splat(srcvec, 0));
135 return(vswiz); 149 return(vswiz);
136 } 150 }
137 151
138 static void Blit_RGB888_RGB565(SDL_BlitInfo *info); 152 static void Blit_RGB888_RGB565(SDL_BlitInfo *info);
143 Uint8 *dst = (Uint8 *) info->d_pixels; 157 Uint8 *dst = (Uint8 *) info->d_pixels;
144 int dstskip = info->d_skip; 158 int dstskip = info->d_skip;
145 SDL_PixelFormat *srcfmt = info->src; 159 SDL_PixelFormat *srcfmt = info->src;
146 vector unsigned char valpha = vec_splat_u8(0); 160 vector unsigned char valpha = vec_splat_u8(0);
147 vector unsigned char vpermute = calc_swizzle32(srcfmt, NULL); 161 vector unsigned char vpermute = calc_swizzle32(srcfmt, NULL);
148 vector unsigned char vgmerge = (vector unsigned char)( 162 vector unsigned char vgmerge = VECUINT8_LITERAL(
149 0x00, 0x02, 0x00, 0x06, 163 0x00, 0x02, 0x00, 0x06,
150 0x00, 0x0a, 0x00, 0x0e, 164 0x00, 0x0a, 0x00, 0x0e,
151 0x00, 0x12, 0x00, 0x16, 165 0x00, 0x12, 0x00, 0x16,
152 0x00, 0x1a, 0x00, 0x1e); 166 0x00, 0x1a, 0x00, 0x1e);
153 vector unsigned short v1 = vec_splat_u16(1); 167 vector unsigned short v1 = vec_splat_u16(1);
154 vector unsigned short v3 = vec_splat_u16(3); 168 vector unsigned short v3 = vec_splat_u16(3);
155 vector unsigned short v3f = (vector unsigned short)( 169 vector unsigned short v3f = VECUINT16_LITERAL(
156 0x003f, 0x003f, 0x003f, 0x003f, 170 0x003f, 0x003f, 0x003f, 0x003f,
157 0x003f, 0x003f, 0x003f, 0x003f); 171 0x003f, 0x003f, 0x003f, 0x003f);
158 vector unsigned short vfc = (vector unsigned short)( 172 vector unsigned short vfc = VECUINT16_LITERAL(
159 0x00fc, 0x00fc, 0x00fc, 0x00fc, 173 0x00fc, 0x00fc, 0x00fc, 0x00fc,
160 0x00fc, 0x00fc, 0x00fc, 0x00fc); 174 0x00fc, 0x00fc, 0x00fc, 0x00fc);
161 vector unsigned short vf800 = (vector unsigned short)vec_splat_u8(-7); 175 vector unsigned short vf800 = (vector unsigned short)vec_splat_u8(-7);
162 vf800 = vec_sl(vf800, vec_splat_u16(8)); 176 vf800 = vec_sl(vf800, vec_splat_u16(8));
163 177
170 int extrawidth; 184 int extrawidth;
171 185
172 /* do scalar until we can align... */ 186 /* do scalar until we can align... */
173 #define ONE_PIXEL_BLEND(condition, widthvar) \ 187 #define ONE_PIXEL_BLEND(condition, widthvar) \
174 while (condition) { \ 188 while (condition) { \
175 Uint32 pixel; \ 189 Uint32 Pixel; \
176 unsigned sR, sG, sB, sA; \ 190 unsigned sR, sG, sB, sA; \
177 DISEMBLE_RGBA((Uint8 *)src, 4, srcfmt, pixel, \ 191 DISEMBLE_RGBA((Uint8 *)src, 4, srcfmt, Pixel, \
178 sR, sG, sB, sA); \ 192 sR, sG, sB, sA); \
179 *(Uint16 *)(dst) = (((sR << 8) & 0x0000F800) | \ 193 *(Uint16 *)(dst) = (((sR << 8) & 0x0000F800) | \
180 ((sG << 3) & 0x000007E0) | \ 194 ((sG << 3) & 0x000007E0) | \
181 ((sB >> 3) & 0x0000001F)); \ 195 ((sB >> 3) & 0x0000001F)); \
182 dst += 2; \ 196 dst += 2; \
257 /* 271 /*
258 0x10 - 0x1f is the alpha 272 0x10 - 0x1f is the alpha
259 0x00 - 0x0e evens are the red 273 0x00 - 0x0e evens are the red
260 0x01 - 0x0f odds are zero 274 0x01 - 0x0f odds are zero
261 */ 275 */
262 vector unsigned char vredalpha1 = (vector unsigned char)( 276 vector unsigned char vredalpha1 = VECUINT8_LITERAL(
263 0x10, 0x00, 0x01, 0x01, 277 0x10, 0x00, 0x01, 0x01,
264 0x10, 0x02, 0x01, 0x01, 278 0x10, 0x02, 0x01, 0x01,
265 0x10, 0x04, 0x01, 0x01, 279 0x10, 0x04, 0x01, 0x01,
266 0x10, 0x06, 0x01, 0x01 280 0x10, 0x06, 0x01, 0x01
267 ); 281 );
268 vector unsigned char vredalpha2 = (vector unsigned char)( 282 vector unsigned char vredalpha2 = (vector unsigned char) (
269 vec_add((vector unsigned int)vredalpha1, vec_sl(v8, v16)) 283 vec_add((vector unsigned int)vredalpha1, vec_sl(v8, v16))
270 ); 284 );
271 /* 285 /*
272 0x00 - 0x0f is ARxx ARxx ARxx ARxx 286 0x00 - 0x0f is ARxx ARxx ARxx ARxx
273 0x11 - 0x0f odds are blue 287 0x11 - 0x0f odds are blue
274 */ 288 */
275 vector unsigned char vblue1 = (vector unsigned char)( 289 vector unsigned char vblue1 = VECUINT8_LITERAL(
276 0x00, 0x01, 0x02, 0x11, 290 0x00, 0x01, 0x02, 0x11,
277 0x04, 0x05, 0x06, 0x13, 291 0x04, 0x05, 0x06, 0x13,
278 0x08, 0x09, 0x0a, 0x15, 292 0x08, 0x09, 0x0a, 0x15,
279 0x0c, 0x0d, 0x0e, 0x17 293 0x0c, 0x0d, 0x0e, 0x17
280 ); 294 );
283 ); 297 );
284 /* 298 /*
285 0x00 - 0x0f is ARxB ARxB ARxB ARxB 299 0x00 - 0x0f is ARxB ARxB ARxB ARxB
286 0x10 - 0x0e evens are green 300 0x10 - 0x0e evens are green
287 */ 301 */
288 vector unsigned char vgreen1 = (vector unsigned char)( 302 vector unsigned char vgreen1 = VECUINT8_LITERAL(
289 0x00, 0x01, 0x10, 0x03, 303 0x00, 0x01, 0x10, 0x03,
290 0x04, 0x05, 0x12, 0x07, 304 0x04, 0x05, 0x12, 0x07,
291 0x08, 0x09, 0x14, 0x0b, 305 0x08, 0x09, 0x14, 0x0b,
292 0x0c, 0x0d, 0x16, 0x0f 306 0x0c, 0x0d, 0x16, 0x0f
293 ); 307 );
321 335
322 /* do scalar until we can align... */ 336 /* do scalar until we can align... */
323 #define ONE_PIXEL_BLEND(condition, widthvar) \ 337 #define ONE_PIXEL_BLEND(condition, widthvar) \
324 while (condition) { \ 338 while (condition) { \
325 unsigned sR, sG, sB; \ 339 unsigned sR, sG, sB; \
326 unsigned short pixel = *((unsigned short *)src); \ 340 unsigned short Pixel = *((unsigned short *)src); \
327 sR = (pixel >> 8) & 0xf8; \ 341 sR = (Pixel >> 8) & 0xf8; \
328 sG = (pixel >> 3) & 0xfc; \ 342 sG = (Pixel >> 3) & 0xfc; \
329 sB = (pixel << 3) & 0xf8; \ 343 sB = (Pixel << 3) & 0xf8; \
330 ASSEMBLE_RGBA(dst, 4, dstfmt, sR, sG, sB, alpha); \ 344 ASSEMBLE_RGBA(dst, 4, dstfmt, sR, sG, sB, alpha); \
331 src += 2; \ 345 src += 2; \
332 dst += 4; \ 346 dst += 4; \
333 widthvar--; \ 347 widthvar--; \
334 } 348 }
402 /* 416 /*
403 0x10 - 0x1f is the alpha 417 0x10 - 0x1f is the alpha
404 0x00 - 0x0e evens are the red 418 0x00 - 0x0e evens are the red
405 0x01 - 0x0f odds are zero 419 0x01 - 0x0f odds are zero
406 */ 420 */
407 vector unsigned char vredalpha1 = (vector unsigned char)( 421 vector unsigned char vredalpha1 = VECUINT8_LITERAL(
408 0x10, 0x00, 0x01, 0x01, 422 0x10, 0x00, 0x01, 0x01,
409 0x10, 0x02, 0x01, 0x01, 423 0x10, 0x02, 0x01, 0x01,
410 0x10, 0x04, 0x01, 0x01, 424 0x10, 0x04, 0x01, 0x01,
411 0x10, 0x06, 0x01, 0x01 425 0x10, 0x06, 0x01, 0x01
412 ); 426 );
415 ); 429 );
416 /* 430 /*
417 0x00 - 0x0f is ARxx ARxx ARxx ARxx 431 0x00 - 0x0f is ARxx ARxx ARxx ARxx
418 0x11 - 0x0f odds are blue 432 0x11 - 0x0f odds are blue
419 */ 433 */
420 vector unsigned char vblue1 = (vector unsigned char)( 434 vector unsigned char vblue1 = VECUINT8_LITERAL(
421 0x00, 0x01, 0x02, 0x11, 435 0x00, 0x01, 0x02, 0x11,
422 0x04, 0x05, 0x06, 0x13, 436 0x04, 0x05, 0x06, 0x13,
423 0x08, 0x09, 0x0a, 0x15, 437 0x08, 0x09, 0x0a, 0x15,
424 0x0c, 0x0d, 0x0e, 0x17 438 0x0c, 0x0d, 0x0e, 0x17
425 ); 439 );
428 ); 442 );
429 /* 443 /*
430 0x00 - 0x0f is ARxB ARxB ARxB ARxB 444 0x00 - 0x0f is ARxB ARxB ARxB ARxB
431 0x10 - 0x0e evens are green 445 0x10 - 0x0e evens are green
432 */ 446 */
433 vector unsigned char vgreen1 = (vector unsigned char)( 447 vector unsigned char vgreen1 = VECUINT8_LITERAL(
434 0x00, 0x01, 0x10, 0x03, 448 0x00, 0x01, 0x10, 0x03,
435 0x04, 0x05, 0x12, 0x07, 449 0x04, 0x05, 0x12, 0x07,
436 0x08, 0x09, 0x14, 0x0b, 450 0x08, 0x09, 0x14, 0x0b,
437 0x0c, 0x0d, 0x16, 0x0f 451 0x0c, 0x0d, 0x16, 0x0f
438 ); 452 );
466 480
467 /* do scalar until we can align... */ 481 /* do scalar until we can align... */
468 #define ONE_PIXEL_BLEND(condition, widthvar) \ 482 #define ONE_PIXEL_BLEND(condition, widthvar) \
469 while (condition) { \ 483 while (condition) { \
470 unsigned sR, sG, sB; \ 484 unsigned sR, sG, sB; \
471 unsigned short pixel = *((unsigned short *)src); \ 485 unsigned short Pixel = *((unsigned short *)src); \
472 sR = (pixel >> 7) & 0xf8; \ 486 sR = (Pixel >> 7) & 0xf8; \
473 sG = (pixel >> 2) & 0xf8; \ 487 sG = (Pixel >> 2) & 0xf8; \
474 sB = (pixel << 3) & 0xf8; \ 488 sB = (Pixel << 3) & 0xf8; \
475 ASSEMBLE_RGBA(dst, 4, dstfmt, sR, sG, sB, alpha); \ 489 ASSEMBLE_RGBA(dst, 4, dstfmt, sR, sG, sB, alpha); \
476 src += 2; \ 490 src += 2; \
477 dst += 4; \ 491 dst += 4; \
478 widthvar--; \ 492 widthvar--; \
479 } 493 }
563 valpha = (vector unsigned int)vec_splat((vector unsigned char)valpha, 0); 577 valpha = (vector unsigned int)vec_splat((vector unsigned char)valpha, 0);
564 } else { 578 } else {
565 valpha = (vector unsigned int)vzero; 579 valpha = (vector unsigned int)vzero;
566 } 580 }
567 ckey &= rgbmask; 581 ckey &= rgbmask;
568 ((unsigned int *)&vckey)[0] = ckey; 582 ((unsigned int *)(char*)&vckey)[0] = ckey;
569 vckey = vec_splat(vckey, 0); 583 vckey = vec_splat(vckey, 0);
570 ((unsigned int *)&vrgbmask)[0] = rgbmask; 584 ((unsigned int *)(char*)&vrgbmask)[0] = rgbmask;
571 vrgbmask = vec_splat(vrgbmask, 0); 585 vrgbmask = vec_splat(vrgbmask, 0);
572 586
573 while (height--) { 587 while (height--) {
574 #define ONE_PIXEL_BLEND(condition, widthvar) \ 588 #define ONE_PIXEL_BLEND(condition, widthvar) \
575 if (copy_alpha) { \ 589 if (copy_alpha) { \
576 while (condition) { \ 590 while (condition) { \
577 Uint32 pixel; \ 591 Uint32 Pixel; \
578 unsigned sR, sG, sB, sA; \ 592 unsigned sR, sG, sB, sA; \
579 DISEMBLE_RGBA((Uint8 *)srcp, srcbpp, srcfmt, pixel, \ 593 DISEMBLE_RGBA((Uint8 *)srcp, srcbpp, srcfmt, Pixel, \
580 sR, sG, sB, sA); \ 594 sR, sG, sB, sA); \
581 if ( (pixel & rgbmask) != ckey ) { \ 595 if ( (Pixel & rgbmask) != ckey ) { \
582 ASSEMBLE_RGBA((Uint8 *)dstp, dstbpp, dstfmt, \ 596 ASSEMBLE_RGBA((Uint8 *)dstp, dstbpp, dstfmt, \
583 sR, sG, sB, sA); \ 597 sR, sG, sB, sA); \
584 } \ 598 } \
585 ((Uint8 *)dstp) += dstbpp; \ 599 dstp = (Uint32 *) (((Uint8 *) dstp) + dstbpp); \
586 ((Uint8 *)srcp) += srcbpp; \ 600 srcp = (Uint32 *) (((Uint8 *) srcp) + srcbpp); \
587 widthvar--; \ 601 widthvar--; \
588 } \ 602 } \
589 } else { \ 603 } else { \
590 while (condition) { \ 604 while (condition) { \
591 Uint32 pixel; \ 605 Uint32 Pixel; \
592 unsigned sR, sG, sB; \ 606 unsigned sR, sG, sB; \
593 RETRIEVE_RGB_PIXEL((Uint8 *)srcp, srcbpp, pixel); \ 607 RETRIEVE_RGB_PIXEL((Uint8 *)srcp, srcbpp, Pixel); \
594 if ( pixel != ckey ) { \ 608 if ( Pixel != ckey ) { \
595 RGB_FROM_PIXEL(pixel, srcfmt, sR, sG, sB); \ 609 RGB_FROM_PIXEL(Pixel, srcfmt, sR, sG, sB); \
596 ASSEMBLE_RGBA((Uint8 *)dstp, dstbpp, dstfmt, \ 610 ASSEMBLE_RGBA((Uint8 *)dstp, dstbpp, dstfmt, \
597 sR, sG, sB, alpha); \ 611 sR, sG, sB, alpha); \
598 } \ 612 } \
599 ((Uint8 *)dstp) += dstbpp; \ 613 dstp = (Uint32 *) (((Uint8 *)dstp) + dstbpp); \
600 ((Uint8 *)srcp) += srcbpp; \ 614 srcp = (Uint32 *) (((Uint8 *)srcp) + srcbpp); \
601 widthvar--; \ 615 widthvar--; \
602 } \ 616 } \
603 } 617 }
604 int width = info->d_width; 618 int width = info->d_width;
605 ONE_PIXEL_BLEND((UNALIGNED_PTR(dstp)) && (width), width); 619 ONE_PIXEL_BLEND((UNALIGNED_PTR(dstp)) && (width), width);
817 /* Feature 1 is has-MMX */ 831 /* Feature 1 is has-MMX */
818 | ((SDL_HasMMX()) ? 1 : 0) 832 | ((SDL_HasMMX()) ? 1 : 0)
819 /* Feature 2 is has-AltiVec */ 833 /* Feature 2 is has-AltiVec */
820 | ((SDL_HasAltiVec()) ? 2 : 0) 834 | ((SDL_HasAltiVec()) ? 2 : 0)
821 /* Feature 4 is dont-use-prefetch */ 835 /* Feature 4 is dont-use-prefetch */
836 /* !!!! FIXME: Check for G5 or later, not the cache size! Always prefetch on a G4. */
822 | ((GetL3CacheSize() == 0) ? 4 : 0) 837 | ((GetL3CacheSize() == 0) ? 4 : 0)
823 ); 838 );
824 } 839 }
825 } 840 }
826 return features; 841 return features;
909 #endif /* USE_DUFFS_LOOP */ 924 #endif /* USE_DUFFS_LOOP */
910 src += srcskip; 925 src += srcskip;
911 dst += dstskip; 926 dst += dstskip;
912 } 927 }
913 } else { 928 } else {
914 int pixel; 929 int Pixel;
915 930
916 while ( height-- ) { 931 while ( height-- ) {
917 #ifdef USE_DUFFS_LOOP 932 #ifdef USE_DUFFS_LOOP
918 DUFFS_LOOP( 933 DUFFS_LOOP(
919 RGB888_RGB332(pixel, *src); 934 RGB888_RGB332(Pixel, *src);
920 *dst++ = map[pixel]; 935 *dst++ = map[Pixel];
921 ++src; 936 ++src;
922 , width); 937 , width);
923 #else 938 #else
924 for ( c=width/4; c; --c ) { 939 for ( c=width/4; c; --c ) {
925 /* Pack RGB into 8bit pixel */ 940 /* Pack RGB into 8bit pixel */
926 RGB888_RGB332(pixel, *src); 941 RGB888_RGB332(Pixel, *src);
927 *dst++ = map[pixel]; 942 *dst++ = map[Pixel];
928 ++src; 943 ++src;
929 RGB888_RGB332(pixel, *src); 944 RGB888_RGB332(Pixel, *src);
930 *dst++ = map[pixel]; 945 *dst++ = map[Pixel];
931 ++src; 946 ++src;
932 RGB888_RGB332(pixel, *src); 947 RGB888_RGB332(Pixel, *src);
933 *dst++ = map[pixel]; 948 *dst++ = map[Pixel];
934 ++src; 949 ++src;
935 RGB888_RGB332(pixel, *src); 950 RGB888_RGB332(Pixel, *src);
936 *dst++ = map[pixel]; 951 *dst++ = map[Pixel];
937 ++src; 952 ++src;
938 } 953 }
939 switch ( width & 3 ) { 954 switch ( width & 3 ) {
940 case 3: 955 case 3:
941 RGB888_RGB332(pixel, *src); 956 RGB888_RGB332(Pixel, *src);
942 *dst++ = map[pixel]; 957 *dst++ = map[Pixel];
943 ++src; 958 ++src;
944 case 2: 959 case 2:
945 RGB888_RGB332(pixel, *src); 960 RGB888_RGB332(Pixel, *src);
946 *dst++ = map[pixel]; 961 *dst++ = map[Pixel];
947 ++src; 962 ++src;
948 case 1: 963 case 1:
949 RGB888_RGB332(pixel, *src); 964 RGB888_RGB332(Pixel, *src);
950 *dst++ = map[pixel]; 965 *dst++ = map[Pixel];
951 ++src; 966 ++src;
952 } 967 }
953 #endif /* USE_DUFFS_LOOP */ 968 #endif /* USE_DUFFS_LOOP */
954 src += srcskip; 969 src += srcskip;
955 dst += dstskip; 970 dst += dstskip;
1818 static void Blit_RGB888_index8_map(SDL_BlitInfo *info) 1833 static void Blit_RGB888_index8_map(SDL_BlitInfo *info)
1819 { 1834 {
1820 #ifndef USE_DUFFS_LOOP 1835 #ifndef USE_DUFFS_LOOP
1821 int c; 1836 int c;
1822 #endif 1837 #endif
1823 int pixel; 1838 int Pixel;
1824 int width, height; 1839 int width, height;
1825 Uint32 *src; 1840 Uint32 *src;
1826 const Uint8 *map; 1841 const Uint8 *map;
1827 Uint8 *dst; 1842 Uint8 *dst;
1828 int srcskip, dstskip; 1843 int srcskip, dstskip;
1837 map = info->table; 1852 map = info->table;
1838 1853
1839 #ifdef USE_DUFFS_LOOP 1854 #ifdef USE_DUFFS_LOOP
1840 while ( height-- ) { 1855 while ( height-- ) {
1841 DUFFS_LOOP( 1856 DUFFS_LOOP(
1842 RGB888_RGB332(pixel, *src); 1857 RGB888_RGB332(Pixel, *src);
1843 *dst++ = map[pixel]; 1858 *dst++ = map[Pixel];
1844 ++src; 1859 ++src;
1845 , width); 1860 , width);
1846 src += srcskip; 1861 src += srcskip;
1847 dst += dstskip; 1862 dst += dstskip;
1848 } 1863 }
1849 #else 1864 #else
1850 while ( height-- ) { 1865 while ( height-- ) {
1851 for ( c=width/4; c; --c ) { 1866 for ( c=width/4; c; --c ) {
1852 /* Pack RGB into 8bit pixel */ 1867 /* Pack RGB into 8bit pixel */
1853 RGB888_RGB332(pixel, *src); 1868 RGB888_RGB332(Pixel, *src);
1854 *dst++ = map[pixel]; 1869 *dst++ = map[Pixel];
1855 ++src; 1870 ++src;
1856 RGB888_RGB332(pixel, *src); 1871 RGB888_RGB332(Pixel, *src);
1857 *dst++ = map[pixel]; 1872 *dst++ = map[Pixel];
1858 ++src; 1873 ++src;
1859 RGB888_RGB332(pixel, *src); 1874 RGB888_RGB332(Pixel, *src);
1860 *dst++ = map[pixel]; 1875 *dst++ = map[Pixel];
1861 ++src; 1876 ++src;
1862 RGB888_RGB332(pixel, *src); 1877 RGB888_RGB332(Pixel, *src);
1863 *dst++ = map[pixel]; 1878 *dst++ = map[Pixel];
1864 ++src; 1879 ++src;
1865 } 1880 }
1866 switch ( width & 3 ) { 1881 switch ( width & 3 ) {
1867 case 3: 1882 case 3:
1868 RGB888_RGB332(pixel, *src); 1883 RGB888_RGB332(Pixel, *src);
1869 *dst++ = map[pixel]; 1884 *dst++ = map[Pixel];
1870 ++src; 1885 ++src;
1871 case 2: 1886 case 2:
1872 RGB888_RGB332(pixel, *src); 1887 RGB888_RGB332(Pixel, *src);
1873 *dst++ = map[pixel]; 1888 *dst++ = map[Pixel];
1874 ++src; 1889 ++src;
1875 case 1: 1890 case 1:
1876 RGB888_RGB332(pixel, *src); 1891 RGB888_RGB332(Pixel, *src);
1877 *dst++ = map[pixel]; 1892 *dst++ = map[Pixel];
1878 ++src; 1893 ++src;
1879 } 1894 }
1880 src += srcskip; 1895 src += srcskip;
1881 dst += dstskip; 1896 dst += dstskip;
1882 } 1897 }
1891 Uint8 *src; 1906 Uint8 *src;
1892 const Uint8 *map; 1907 const Uint8 *map;
1893 Uint8 *dst; 1908 Uint8 *dst;
1894 int srcskip, dstskip; 1909 int srcskip, dstskip;
1895 int srcbpp; 1910 int srcbpp;
1896 Uint32 pixel; 1911 Uint32 Pixel;
1897 int sR, sG, sB; 1912 int sR, sG, sB;
1898 SDL_PixelFormat *srcfmt; 1913 SDL_PixelFormat *srcfmt;
1899 1914
1900 /* Set up some basic variables */ 1915 /* Set up some basic variables */
1901 width = info->d_width; 1916 width = info->d_width;
1910 1925
1911 if ( map == NULL ) { 1926 if ( map == NULL ) {
1912 while ( height-- ) { 1927 while ( height-- ) {
1913 #ifdef USE_DUFFS_LOOP 1928 #ifdef USE_DUFFS_LOOP
1914 DUFFS_LOOP( 1929 DUFFS_LOOP(
1915 DISEMBLE_RGB(src, srcbpp, srcfmt, pixel, 1930 DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel,
1916 sR, sG, sB); 1931 sR, sG, sB);
1917 if ( 1 ) { 1932 if ( 1 ) {
1918 /* Pack RGB into 8bit pixel */ 1933 /* Pack RGB into 8bit pixel */
1919 *dst = ((sR>>5)<<(3+2))| 1934 *dst = ((sR>>5)<<(3+2))|
1920 ((sG>>5)<<(2)) | 1935 ((sG>>5)<<(2)) |
1923 dst++; 1938 dst++;
1924 src += srcbpp; 1939 src += srcbpp;
1925 , width); 1940 , width);
1926 #else 1941 #else
1927 for ( c=width; c; --c ) { 1942 for ( c=width; c; --c ) {
1928 DISEMBLE_RGB(src, srcbpp, srcfmt, pixel, 1943 DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel,
1929 sR, sG, sB); 1944 sR, sG, sB);
1930 if ( 1 ) { 1945 if ( 1 ) {
1931 /* Pack RGB into 8bit pixel */ 1946 /* Pack RGB into 8bit pixel */
1932 *dst = ((sR>>5)<<(3+2))| 1947 *dst = ((sR>>5)<<(3+2))|
1933 ((sG>>5)<<(2)) | 1948 ((sG>>5)<<(2)) |
1942 } 1957 }
1943 } else { 1958 } else {
1944 while ( height-- ) { 1959 while ( height-- ) {
1945 #ifdef USE_DUFFS_LOOP 1960 #ifdef USE_DUFFS_LOOP
1946 DUFFS_LOOP( 1961 DUFFS_LOOP(
1947 DISEMBLE_RGB(src, srcbpp, srcfmt, pixel, 1962 DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel,
1948 sR, sG, sB); 1963 sR, sG, sB);
1949 if ( 1 ) { 1964 if ( 1 ) {
1950 /* Pack RGB into 8bit pixel */ 1965 /* Pack RGB into 8bit pixel */
1951 *dst = map[((sR>>5)<<(3+2))| 1966 *dst = map[((sR>>5)<<(3+2))|
1952 ((sG>>5)<<(2)) | 1967 ((sG>>5)<<(2)) |
1955 dst++; 1970 dst++;
1956 src += srcbpp; 1971 src += srcbpp;
1957 , width); 1972 , width);
1958 #else 1973 #else
1959 for ( c=width; c; --c ) { 1974 for ( c=width; c; --c ) {
1960 DISEMBLE_RGB(src, srcbpp, srcfmt, pixel, 1975 DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel,
1961 sR, sG, sB); 1976 sR, sG, sB);
1962 if ( 1 ) { 1977 if ( 1 ) {
1963 /* Pack RGB into 8bit pixel */ 1978 /* Pack RGB into 8bit pixel */
1964 *dst = map[((sR>>5)<<(3+2))| 1979 *dst = map[((sR>>5)<<(3+2))|
1965 ((sG>>5)<<(2)) | 1980 ((sG>>5)<<(2)) |
1989 unsigned alpha = dstfmt->Amask ? srcfmt->alpha : 0; 2004 unsigned alpha = dstfmt->Amask ? srcfmt->alpha : 0;
1990 2005
1991 while ( height-- ) { 2006 while ( height-- ) {
1992 DUFFS_LOOP( 2007 DUFFS_LOOP(
1993 { 2008 {
1994 Uint32 pixel; 2009 Uint32 Pixel;
1995 unsigned sR; 2010 unsigned sR;
1996 unsigned sG; 2011 unsigned sG;
1997 unsigned sB; 2012 unsigned sB;
1998 DISEMBLE_RGB(src, srcbpp, srcfmt, pixel, sR, sG, sB); 2013 DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, sR, sG, sB);
1999 ASSEMBLE_RGBA(dst, dstbpp, dstfmt, sR, sG, sB, alpha); 2014 ASSEMBLE_RGBA(dst, dstbpp, dstfmt, sR, sG, sB, alpha);
2000 dst += dstbpp; 2015 dst += dstbpp;
2001 src += srcbpp; 2016 src += srcbpp;
2002 }, 2017 },
2003 width); 2018 width);
2021 int c; 2036 int c;
2022 2037
2023 /* FIXME: should map alpha to [0..255] correctly! */ 2038 /* FIXME: should map alpha to [0..255] correctly! */
2024 while ( height-- ) { 2039 while ( height-- ) {
2025 for ( c=width; c; --c ) { 2040 for ( c=width; c; --c ) {
2026 Uint32 pixel; 2041 Uint32 Pixel;
2027 unsigned sR, sG, sB, sA; 2042 unsigned sR, sG, sB, sA;
2028 DISEMBLE_RGBA(src, srcbpp, srcfmt, pixel, 2043 DISEMBLE_RGBA(src, srcbpp, srcfmt, Pixel,
2029 sR, sG, sB, sA); 2044 sR, sG, sB, sA);
2030 ASSEMBLE_RGBA(dst, dstbpp, dstfmt, 2045 ASSEMBLE_RGBA(dst, dstbpp, dstfmt,
2031 sR, sG, sB, sA); 2046 sR, sG, sB, sA);
2032 dst += dstbpp; 2047 dst += dstbpp;
2033 src += srcbpp; 2048 src += srcbpp;
2048 SDL_PixelFormat *srcfmt = info->src; 2063 SDL_PixelFormat *srcfmt = info->src;
2049 const Uint8 *palmap = info->table; 2064 const Uint8 *palmap = info->table;
2050 Uint32 ckey = srcfmt->colorkey; 2065 Uint32 ckey = srcfmt->colorkey;
2051 Uint32 rgbmask = ~srcfmt->Amask; 2066 Uint32 rgbmask = ~srcfmt->Amask;
2052 int srcbpp; 2067 int srcbpp;
2053 Uint32 pixel; 2068 Uint32 Pixel;
2054 Uint8 sR, sG, sB; 2069 Uint8 sR, sG, sB;
2055 2070
2056 /* Set up some basic variables */ 2071 /* Set up some basic variables */
2057 srcbpp = srcfmt->BytesPerPixel; 2072 srcbpp = srcfmt->BytesPerPixel;
2058 ckey &= rgbmask; 2073 ckey &= rgbmask;
2059 2074
2060 if ( palmap == NULL ) { 2075 if ( palmap == NULL ) {
2061 while ( height-- ) { 2076 while ( height-- ) {
2062 DUFFS_LOOP( 2077 DUFFS_LOOP(
2063 { 2078 {
2064 DISEMBLE_RGB(src, srcbpp, srcfmt, pixel, 2079 DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel,
2065 sR, sG, sB); 2080 sR, sG, sB);
2066 if ( (pixel & rgbmask) != ckey ) { 2081 if ( (Pixel & rgbmask) != ckey ) {
2067 /* Pack RGB into 8bit pixel */ 2082 /* Pack RGB into 8bit pixel */
2068 *dst = ((sR>>5)<<(3+2))| 2083 *dst = ((sR>>5)<<(3+2))|
2069 ((sG>>5)<<(2)) | 2084 ((sG>>5)<<(2)) |
2070 ((sB>>6)<<(0)) ; 2085 ((sB>>6)<<(0)) ;
2071 } 2086 }
2078 } 2093 }
2079 } else { 2094 } else {
2080 while ( height-- ) { 2095 while ( height-- ) {
2081 DUFFS_LOOP( 2096 DUFFS_LOOP(
2082 { 2097 {
2083 DISEMBLE_RGB(src, srcbpp, srcfmt, pixel, 2098 DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel,
2084 sR, sG, sB); 2099 sR, sG, sB);
2085 if ( (pixel & rgbmask) != ckey ) { 2100 if ( (Pixel & rgbmask) != ckey ) {
2086 /* Pack RGB into 8bit pixel */ 2101 /* Pack RGB into 8bit pixel */
2087 *dst = palmap[((sR>>5)<<(3+2))| 2102 *dst = palmap[((sR>>5)<<(3+2))|
2088 ((sG>>5)<<(2)) | 2103 ((sG>>5)<<(2)) |
2089 ((sB>>6)<<(0)) ]; 2104 ((sB>>6)<<(0)) ];
2090 } 2105 }
2145 unsigned alpha = dstfmt->Amask ? srcfmt->alpha : 0; 2160 unsigned alpha = dstfmt->Amask ? srcfmt->alpha : 0;
2146 2161
2147 while ( height-- ) { 2162 while ( height-- ) {
2148 DUFFS_LOOP( 2163 DUFFS_LOOP(
2149 { 2164 {
2150 Uint32 pixel; 2165 Uint32 Pixel;
2151 unsigned sR; 2166 unsigned sR;
2152 unsigned sG; 2167 unsigned sG;
2153 unsigned sB; 2168 unsigned sB;
2154 RETRIEVE_RGB_PIXEL(src, srcbpp, pixel); 2169 RETRIEVE_RGB_PIXEL(src, srcbpp, Pixel);
2155 if ( pixel != ckey ) { 2170 if ( Pixel != ckey ) {
2156 RGB_FROM_PIXEL(pixel, srcfmt, sR, sG, sB); 2171 RGB_FROM_PIXEL(Pixel, srcfmt, sR, sG, sB);
2157 ASSEMBLE_RGBA(dst, dstbpp, dstfmt, 2172 ASSEMBLE_RGBA(dst, dstbpp, dstfmt,
2158 sR, sG, sB, alpha); 2173 sR, sG, sB, alpha);
2159 } 2174 }
2160 dst += dstbpp; 2175 dst += dstbpp;
2161 src += srcbpp; 2176 src += srcbpp;
2179 SDL_PixelFormat *dstfmt = info->dst; 2194 SDL_PixelFormat *dstfmt = info->dst;
2180 Uint32 rgbmask = ~srcfmt->Amask; 2195 Uint32 rgbmask = ~srcfmt->Amask;
2181 2196
2182 Uint8 srcbpp; 2197 Uint8 srcbpp;
2183 Uint8 dstbpp; 2198 Uint8 dstbpp;
2184 Uint32 pixel; 2199 Uint32 Pixel;
2185 Uint8 sR, sG, sB, sA; 2200 Uint8 sR, sG, sB, sA;
2186 2201
2187 /* Set up some basic variables */ 2202 /* Set up some basic variables */
2188 srcbpp = srcfmt->BytesPerPixel; 2203 srcbpp = srcfmt->BytesPerPixel;
2189 dstbpp = dstfmt->BytesPerPixel; 2204 dstbpp = dstfmt->BytesPerPixel;
2191 2206
2192 /* FIXME: should map alpha to [0..255] correctly! */ 2207 /* FIXME: should map alpha to [0..255] correctly! */
2193 while ( height-- ) { 2208 while ( height-- ) {
2194 DUFFS_LOOP( 2209 DUFFS_LOOP(
2195 { 2210 {
2196 DISEMBLE_RGBA(src, srcbpp, srcfmt, pixel, 2211 DISEMBLE_RGBA(src, srcbpp, srcfmt, Pixel,
2197 sR, sG, sB, sA); 2212 sR, sG, sB, sA);
2198 if ( (pixel & rgbmask) != ckey ) { 2213 if ( (Pixel & rgbmask) != ckey ) {
2199 ASSEMBLE_RGBA(dst, dstbpp, dstfmt, 2214 ASSEMBLE_RGBA(dst, dstbpp, dstfmt,
2200 sR, sG, sB, sA); 2215 sR, sG, sB, sA);
2201 } 2216 }
2202 dst += dstbpp; 2217 dst += dstbpp;
2203 src += srcbpp; 2218 src += srcbpp;