comparison src/video/SDL_blit_N.c @ 91:e85e03f195b4

From: "Markus F.X.J. Oberhumer" Subject: SDL CVS patches below you will find some small patches against the current SDL CVS. It adresses these things: 1) Use "&" instead of "%" in some cases. For negative signed integers (x % 8) is not always (x & 7), and the compiler can produce slightly faster code when using "&" here. 2) Some const issues.
author Sam Lantinga <slouken@lokigames.com>
date Sat, 07 Jul 2001 20:20:17 +0000
parents 74212992fb08
children e8157fcb3114
comparison
equal deleted inserted replaced
90:ee1f71c10889 91:e85e03f195b4
76 #ifndef USE_DUFFS_LOOP 76 #ifndef USE_DUFFS_LOOP
77 int c; 77 int c;
78 #endif 78 #endif
79 int width, height; 79 int width, height;
80 Uint32 *src; 80 Uint32 *src;
81 Uint8 *map, *dst; 81 const Uint8 *map;
82 Uint8 *dst;
82 int srcskip, dstskip; 83 int srcskip, dstskip;
83 84
84 /* Set up some basic variables */ 85 /* Set up some basic variables */
85 width = info->d_width; 86 width = info->d_width;
86 height = info->d_height; 87 height = info->d_height;
105 RGB888_RGB332(*dst++, *src); 106 RGB888_RGB332(*dst++, *src);
106 ++src; 107 ++src;
107 RGB888_RGB332(*dst++, *src); 108 RGB888_RGB332(*dst++, *src);
108 ++src; 109 ++src;
109 } 110 }
110 switch ( width % 4 ) { 111 switch ( width & 3 ) {
111 case 3: 112 case 3:
112 RGB888_RGB332(*dst++, *src); 113 RGB888_RGB332(*dst++, *src);
113 ++src; 114 ++src;
114 case 2: 115 case 2:
115 RGB888_RGB332(*dst++, *src); 116 RGB888_RGB332(*dst++, *src);
146 ++src; 147 ++src;
147 RGB888_RGB332(pixel, *src); 148 RGB888_RGB332(pixel, *src);
148 *dst++ = map[pixel]; 149 *dst++ = map[pixel];
149 ++src; 150 ++src;
150 } 151 }
151 switch ( width % 4 ) { 152 switch ( width & 3 ) {
152 case 3: 153 case 3:
153 RGB888_RGB332(pixel, *src); 154 RGB888_RGB332(pixel, *src);
154 *dst++ = map[pixel]; 155 *dst++ = map[pixel];
155 ++src; 156 ++src;
156 case 2: 157 case 2:
233 RGB888_RGB555_TWO(dst, src); 234 RGB888_RGB555_TWO(dst, src);
234 src += 2; 235 src += 2;
235 dst += 2; 236 dst += 2;
236 } 237 }
237 /* Get any leftovers */ 238 /* Get any leftovers */
238 switch (width % 4) { 239 switch (width & 3) {
239 case 3: 240 case 3:
240 RGB888_RGB555(dst, src); 241 RGB888_RGB555(dst, src);
241 ++src; 242 ++src;
242 ++dst; 243 ++dst;
243 case 2: 244 case 2:
264 RGB888_RGB555_TWO(dst, src); 265 RGB888_RGB555_TWO(dst, src);
265 src += 2; 266 src += 2;
266 dst += 2; 267 dst += 2;
267 } 268 }
268 /* Get any leftovers */ 269 /* Get any leftovers */
269 switch (width % 4) { 270 switch (width & 3) {
270 case 3: 271 case 3:
271 RGB888_RGB555(dst, src); 272 RGB888_RGB555(dst, src);
272 ++src; 273 ++src;
273 ++dst; 274 ++dst;
274 case 2: 275 case 2:
353 RGB888_RGB565_TWO(dst, src); 354 RGB888_RGB565_TWO(dst, src);
354 src += 2; 355 src += 2;
355 dst += 2; 356 dst += 2;
356 } 357 }
357 /* Get any leftovers */ 358 /* Get any leftovers */
358 switch (width % 4) { 359 switch (width & 3) {
359 case 3: 360 case 3:
360 RGB888_RGB565(dst, src); 361 RGB888_RGB565(dst, src);
361 ++src; 362 ++src;
362 ++dst; 363 ++dst;
363 case 2: 364 case 2:
384 RGB888_RGB565_TWO(dst, src); 385 RGB888_RGB565_TWO(dst, src);
385 src += 2; 386 src += 2;
386 dst += 2; 387 dst += 2;
387 } 388 }
388 /* Get any leftovers */ 389 /* Get any leftovers */
389 switch (width % 4) { 390 switch (width & 3) {
390 case 3: 391 case 3:
391 RGB888_RGB565(dst, src); 392 RGB888_RGB565(dst, src);
392 ++src; 393 ++src;
393 ++dst; 394 ++dst;
394 case 2: 395 case 2:
416 #if ( SDL_BYTEORDER == SDL_LIL_ENDIAN ) 417 #if ( SDL_BYTEORDER == SDL_LIL_ENDIAN )
417 #define RGB565_32(dst, src, map) (map[src[0]*2] + map[src[1]*2+1]) 418 #define RGB565_32(dst, src, map) (map[src[0]*2] + map[src[1]*2+1])
418 #else /* ( SDL_BYTEORDER == SDL_BIG_ENDIAN ) */ 419 #else /* ( SDL_BYTEORDER == SDL_BIG_ENDIAN ) */
419 #define RGB565_32(dst, src, map) (map[src[1]*2] + map[src[0]*2+1]) 420 #define RGB565_32(dst, src, map) (map[src[1]*2] + map[src[0]*2+1])
420 #endif 421 #endif
421 static void Blit_RGB565_32(SDL_BlitInfo *info, Uint32 *map) 422 static void Blit_RGB565_32(SDL_BlitInfo *info, const Uint32 *map)
422 { 423 {
423 #ifndef USE_DUFFS_LOOP 424 #ifndef USE_DUFFS_LOOP
424 int c; 425 int c;
425 #endif 426 #endif
426 int width, height; 427 int width, height;
459 src += 2; 460 src += 2;
460 *dst++ = RGB565_32(dst, src, map); 461 *dst++ = RGB565_32(dst, src, map);
461 src += 2; 462 src += 2;
462 } 463 }
463 /* Get any leftovers */ 464 /* Get any leftovers */
464 switch (width % 4) { 465 switch (width & 3) {
465 case 3: 466 case 3:
466 *dst++ = RGB565_32(dst, src, map); 467 *dst++ = RGB565_32(dst, src, map);
467 src += 2; 468 src += 2;
468 case 2: 469 case 2:
469 *dst++ = RGB565_32(dst, src, map); 470 *dst++ = RGB565_32(dst, src, map);
478 } 479 }
479 #endif /* USE_DUFFS_LOOP */ 480 #endif /* USE_DUFFS_LOOP */
480 } 481 }
481 482
482 /* Special optimized blit for RGB 5-6-5 --> ARGB 8-8-8-8 */ 483 /* Special optimized blit for RGB 5-6-5 --> ARGB 8-8-8-8 */
483 static Uint32 RGB565_ARGB8888_LUT[512] = { 484 static const Uint32 RGB565_ARGB8888_LUT[512] = {
484 0x00000000, 0xff000000, 0x00000008, 0xff002000, 485 0x00000000, 0xff000000, 0x00000008, 0xff002000,
485 0x00000010, 0xff004000, 0x00000018, 0xff006100, 486 0x00000010, 0xff004000, 0x00000018, 0xff006100,
486 0x00000020, 0xff008100, 0x00000029, 0xff00a100, 487 0x00000020, 0xff008100, 0x00000029, 0xff00a100,
487 0x00000031, 0xff00c200, 0x00000039, 0xff00e200, 488 0x00000031, 0xff00c200, 0x00000039, 0xff00e200,
488 0x00000041, 0xff080000, 0x0000004a, 0xff082000, 489 0x00000041, 0xff080000, 0x0000004a, 0xff082000,
614 { 615 {
615 Blit_RGB565_32(info, RGB565_ARGB8888_LUT); 616 Blit_RGB565_32(info, RGB565_ARGB8888_LUT);
616 } 617 }
617 618
618 /* Special optimized blit for RGB 5-6-5 --> ABGR 8-8-8-8 */ 619 /* Special optimized blit for RGB 5-6-5 --> ABGR 8-8-8-8 */
619 static Uint32 RGB565_ABGR8888_LUT[512] = { 620 static const Uint32 RGB565_ABGR8888_LUT[512] = {
620 0xff000000, 0x00000000, 0xff080000, 0x00002000, 621 0xff000000, 0x00000000, 0xff080000, 0x00002000,
621 0xff100000, 0x00004000, 0xff180000, 0x00006100, 622 0xff100000, 0x00004000, 0xff180000, 0x00006100,
622 0xff200000, 0x00008100, 0xff290000, 0x0000a100, 623 0xff200000, 0x00008100, 0xff290000, 0x0000a100,
623 0xff310000, 0x0000c200, 0xff390000, 0x0000e200, 624 0xff310000, 0x0000c200, 0xff390000, 0x0000e200,
624 0xff410000, 0x00000008, 0xff4a0000, 0x00002008, 625 0xff410000, 0x00000008, 0xff4a0000, 0x00002008,
750 { 751 {
751 Blit_RGB565_32(info, RGB565_ABGR8888_LUT); 752 Blit_RGB565_32(info, RGB565_ABGR8888_LUT);
752 } 753 }
753 754
754 /* Special optimized blit for RGB 5-6-5 --> RGBA 8-8-8-8 */ 755 /* Special optimized blit for RGB 5-6-5 --> RGBA 8-8-8-8 */
755 static Uint32 RGB565_RGBA8888_LUT[512] = { 756 static const Uint32 RGB565_RGBA8888_LUT[512] = {
756 0x000000ff, 0x00000000, 0x000008ff, 0x00200000, 757 0x000000ff, 0x00000000, 0x000008ff, 0x00200000,
757 0x000010ff, 0x00400000, 0x000018ff, 0x00610000, 758 0x000010ff, 0x00400000, 0x000018ff, 0x00610000,
758 0x000020ff, 0x00810000, 0x000029ff, 0x00a10000, 759 0x000020ff, 0x00810000, 0x000029ff, 0x00a10000,
759 0x000031ff, 0x00c20000, 0x000039ff, 0x00e20000, 760 0x000031ff, 0x00c20000, 0x000039ff, 0x00e20000,
760 0x000041ff, 0x08000000, 0x00004aff, 0x08200000, 761 0x000041ff, 0x08000000, 0x00004aff, 0x08200000,
886 { 887 {
887 Blit_RGB565_32(info, RGB565_RGBA8888_LUT); 888 Blit_RGB565_32(info, RGB565_RGBA8888_LUT);
888 } 889 }
889 890
890 /* Special optimized blit for RGB 5-6-5 --> BGRA 8-8-8-8 */ 891 /* Special optimized blit for RGB 5-6-5 --> BGRA 8-8-8-8 */
891 static Uint32 RGB565_BGRA8888_LUT[512] = { 892 static const Uint32 RGB565_BGRA8888_LUT[512] = {
892 0x00000000, 0x000000ff, 0x08000000, 0x002000ff, 893 0x00000000, 0x000000ff, 0x08000000, 0x002000ff,
893 0x10000000, 0x004000ff, 0x18000000, 0x006100ff, 894 0x10000000, 0x004000ff, 0x18000000, 0x006100ff,
894 0x20000000, 0x008100ff, 0x29000000, 0x00a100ff, 895 0x20000000, 0x008100ff, 0x29000000, 0x00a100ff,
895 0x31000000, 0x00c200ff, 0x39000000, 0x00e200ff, 896 0x31000000, 0x00c200ff, 0x39000000, 0x00e200ff,
896 0x41000000, 0x000008ff, 0x4a000000, 0x002008ff, 897 0x41000000, 0x000008ff, 0x4a000000, 0x002008ff,
1037 int c; 1038 int c;
1038 #endif 1039 #endif
1039 int pixel; 1040 int pixel;
1040 int width, height; 1041 int width, height;
1041 Uint32 *src; 1042 Uint32 *src;
1042 Uint8 *map, *dst; 1043 const Uint8 *map;
1044 Uint8 *dst;
1043 int srcskip, dstskip; 1045 int srcskip, dstskip;
1044 1046
1045 /* Set up some basic variables */ 1047 /* Set up some basic variables */
1046 width = info->d_width; 1048 width = info->d_width;
1047 height = info->d_height; 1049 height = info->d_height;
1076 ++src; 1078 ++src;
1077 RGB888_RGB332(pixel, *src); 1079 RGB888_RGB332(pixel, *src);
1078 *dst++ = map[pixel]; 1080 *dst++ = map[pixel];
1079 ++src; 1081 ++src;
1080 } 1082 }
1081 switch ( width % 4 ) { 1083 switch ( width & 3 ) {
1082 case 3: 1084 case 3:
1083 RGB888_RGB332(pixel, *src); 1085 RGB888_RGB332(pixel, *src);
1084 *dst++ = map[pixel]; 1086 *dst++ = map[pixel];
1085 ++src; 1087 ++src;
1086 case 2: 1088 case 2:
1101 { 1103 {
1102 #ifndef USE_DUFFS_LOOP 1104 #ifndef USE_DUFFS_LOOP
1103 int c; 1105 int c;
1104 #endif 1106 #endif
1105 int width, height; 1107 int width, height;
1106 Uint8 *src, *map, *dst; 1108 Uint8 *src;
1109 const Uint8 *map;
1110 Uint8 *dst;
1107 int srcskip, dstskip; 1111 int srcskip, dstskip;
1108 int srcbpp; 1112 int srcbpp;
1109 Uint32 pixel; 1113 Uint32 pixel;
1110 int sR, sG, sB; 1114 int sR, sG, sB;
1111 SDL_PixelFormat *srcfmt; 1115 SDL_PixelFormat *srcfmt;
1257 Uint8 *src = info->s_pixels; 1261 Uint8 *src = info->s_pixels;
1258 int srcskip = info->s_skip; 1262 int srcskip = info->s_skip;
1259 Uint8 *dst = info->d_pixels; 1263 Uint8 *dst = info->d_pixels;
1260 int dstskip = info->d_skip; 1264 int dstskip = info->d_skip;
1261 SDL_PixelFormat *srcfmt = info->src; 1265 SDL_PixelFormat *srcfmt = info->src;
1262 Uint8 *palmap = info->table; 1266 const Uint8 *palmap = info->table;
1263 Uint32 ckey = srcfmt->colorkey; 1267 Uint32 ckey = srcfmt->colorkey;
1264 Uint32 rgbmask = ~srcfmt->Amask; 1268 Uint32 rgbmask = ~srcfmt->Amask;
1265 int srcbpp; 1269 int srcbpp;
1266 Uint32 pixel; 1270 Uint32 pixel;
1267 Uint8 sR, sG, sB; 1271 Uint8 sR, sG, sB;
1429 Uint32 cpu_flags; 1433 Uint32 cpu_flags;
1430 void *aux_data; 1434 void *aux_data;
1431 SDL_loblit blitfunc; 1435 SDL_loblit blitfunc;
1432 enum { NO_ALPHA, SET_ALPHA, COPY_ALPHA } alpha; 1436 enum { NO_ALPHA, SET_ALPHA, COPY_ALPHA } alpha;
1433 }; 1437 };
1434 static struct blit_table normal_blit_1[] = { 1438 static const struct blit_table normal_blit_1[] = {
1435 /* Default for 8-bit RGB source, an invalid combination */ 1439 /* Default for 8-bit RGB source, an invalid combination */
1436 { 0,0,0, 0, 0,0,0, 0, NULL, NULL }, 1440 { 0,0,0, 0, 0,0,0, 0, NULL, NULL },
1437 }; 1441 };
1438 static struct blit_table normal_blit_2[] = { 1442 static const struct blit_table normal_blit_2[] = {
1439 #ifdef USE_ASMBLIT 1443 #ifdef USE_ASMBLIT
1440 { 0x0000F800,0x000007E0,0x0000001F, 2, 0x0000001F,0x000007E0,0x0000F800, 1444 { 0x0000F800,0x000007E0,0x0000001F, 2, 0x0000001F,0x000007E0,0x0000F800,
1441 0, ConvertX86p16_16BGR565, ConvertX86, NO_ALPHA }, 1445 0, ConvertX86p16_16BGR565, ConvertX86, NO_ALPHA },
1442 { 0x0000F800,0x000007E0,0x0000001F, 2, 0x00007C00,0x000003E0,0x0000001F, 1446 { 0x0000F800,0x000007E0,0x0000001F, 2, 0x00007C00,0x000003E0,0x0000001F,
1443 0, ConvertX86p16_16RGB555, ConvertX86, NO_ALPHA }, 1447 0, ConvertX86p16_16RGB555, ConvertX86, NO_ALPHA },
1454 0, NULL, Blit_RGB565_BGRA8888, SET_ALPHA }, 1458 0, NULL, Blit_RGB565_BGRA8888, SET_ALPHA },
1455 1459
1456 /* Default for 16-bit RGB source, used if no other blitter matches */ 1460 /* Default for 16-bit RGB source, used if no other blitter matches */
1457 { 0,0,0, 0, 0,0,0, 0, NULL, BlitNtoN, 0 } 1461 { 0,0,0, 0, 0,0,0, 0, NULL, BlitNtoN, 0 }
1458 }; 1462 };
1459 static struct blit_table normal_blit_3[] = { 1463 static const struct blit_table normal_blit_3[] = {
1460 /* Default for 24-bit RGB source, never optimized */ 1464 /* Default for 24-bit RGB source, never optimized */
1461 { 0,0,0, 0, 0,0,0, 0, NULL, BlitNtoN, 0 } 1465 { 0,0,0, 0, 0,0,0, 0, NULL, BlitNtoN, 0 }
1462 }; 1466 };
1463 static struct blit_table normal_blit_4[] = { 1467 static const struct blit_table normal_blit_4[] = {
1464 #ifdef USE_ASMBLIT 1468 #ifdef USE_ASMBLIT
1465 { 0x00FF0000,0x0000FF00,0x000000FF, 2, 0x0000F800,0x000007E0,0x0000001F, 1469 { 0x00FF0000,0x0000FF00,0x000000FF, 2, 0x0000F800,0x000007E0,0x0000001F,
1466 MMX_CPU, ConvertMMXpII32_16RGB565, ConvertMMX, NO_ALPHA }, 1470 MMX_CPU, ConvertMMXpII32_16RGB565, ConvertMMX, NO_ALPHA },
1467 { 0x00FF0000,0x0000FF00,0x000000FF, 2, 0x0000F800,0x000007E0,0x0000001F, 1471 { 0x00FF0000,0x0000FF00,0x000000FF, 2, 0x0000F800,0x000007E0,0x0000001F,
1468 0, ConvertX86p32_16RGB565, ConvertX86, NO_ALPHA }, 1472 0, ConvertX86p32_16RGB565, ConvertX86, NO_ALPHA },
1495 0, NULL, Blit_RGB888_RGB555, NO_ALPHA }, 1499 0, NULL, Blit_RGB888_RGB555, NO_ALPHA },
1496 #endif 1500 #endif
1497 /* Default for 32-bit RGB source, used if no other blitter matches */ 1501 /* Default for 32-bit RGB source, used if no other blitter matches */
1498 { 0,0,0, 0, 0,0,0, 0, NULL, BlitNtoN, 0 } 1502 { 0,0,0, 0, 0,0,0, 0, NULL, BlitNtoN, 0 }
1499 }; 1503 };
1500 static struct blit_table *normal_blit[] = { 1504 static const struct blit_table *normal_blit[] = {
1501 normal_blit_1, normal_blit_2, normal_blit_3, normal_blit_4 1505 normal_blit_1, normal_blit_2, normal_blit_3, normal_blit_4
1502 }; 1506 };
1503 1507
1504 SDL_loblit SDL_CalculateBlitN(SDL_Surface *surface, int blit_index) 1508 SDL_loblit SDL_CalculateBlitN(SDL_Surface *surface, int blit_index)
1505 { 1509 {
1506 struct private_swaccel *sdata; 1510 struct private_swaccel *sdata;
1507 SDL_PixelFormat *srcfmt; 1511 SDL_PixelFormat *srcfmt;
1508 SDL_PixelFormat *dstfmt; 1512 SDL_PixelFormat *dstfmt;
1509 struct blit_table *table; 1513 const struct blit_table *table;
1510 int which; 1514 int which;
1511 SDL_loblit blitfun; 1515 SDL_loblit blitfun;
1512 1516
1513 /* Set up data for choosing the blit */ 1517 /* Set up data for choosing the blit */
1514 sdata = surface->map->sw_data; 1518 sdata = surface->map->sw_data;