src/video/SDL_blit.h
author Sam Lantinga
Sun, 21 Dec 2008 08:28:25 +0000
changeset 2898 e40448bc7727
parent 2859 99210400e8b9
child 2899 a0c837a16e4c
permissions -rw-r--r--
Share code between fill and line drawing
Added general RGB surface format fallbacks to drawing code
Fixed issues with destination surface alpha channel
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2009 Sam Lantinga
     4 
     5     This library is free software; you can redistribute it and/or
     6     modify it under the terms of the GNU Lesser General Public
     7     License as published by the Free Software Foundation; either
     8     version 2.1 of the License, or (at your option) any later version.
     9 
    10     This library is distributed in the hope that it will be useful,
    11     but WITHOUT ANY WARRANTY; without even the implied warranty of
    12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    13     Lesser General Public License for more details.
    14 
    15     You should have received a copy of the GNU Lesser General Public
    16     License along with this library; if not, write to the Free Software
    17     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    18 
    19     Sam Lantinga
    20     slouken@libsdl.org
    21 */
    22 #include "SDL_config.h"
    23 
    24 #ifndef _SDL_blit_h
    25 #define _SDL_blit_h
    26 
    27 #ifdef __MMX__
    28 #include <mmintrin.h>
    29 #endif
    30 #ifdef __3dNOW__
    31 #include <mm3dnow.h>
    32 #endif
    33 #ifdef __SSE__
    34 #include <xmmintrin.h>
    35 #endif
    36 #ifdef __SSE2__
    37 #include <emmintrin.h>
    38 #endif
    39 
    40 #include "SDL_cpuinfo.h"
    41 #include "SDL_endian.h"
    42 #include "SDL_video.h"
    43 
    44 /* SDL blit copy flags */
    45 #define SDL_COPY_MODULATE_COLOR     0x00000001
    46 #define SDL_COPY_MODULATE_ALPHA     0x00000002
    47 #define SDL_COPY_MASK               0x00000010
    48 #define SDL_COPY_BLEND              0x00000020
    49 #define SDL_COPY_ADD                0x00000040
    50 #define SDL_COPY_MOD                0x00000080
    51 #define SDL_COPY_COLORKEY           0x00000100
    52 #define SDL_COPY_NEAREST            0x00000200
    53 #define SDL_COPY_RLE_DESIRED        0x00001000
    54 #define SDL_COPY_RLE_COLORKEY       0x00002000
    55 #define SDL_COPY_RLE_ALPHAKEY       0x00004000
    56 #define SDL_COPY_RLE_MASK           (SDL_COPY_RLE_DESIRED|SDL_COPY_RLE_COLORKEY|SDL_COPY_RLE_ALPHAKEY)
    57 
    58 /* SDL blit CPU flags */
    59 #define SDL_CPU_ANY                 0x00000000
    60 #define SDL_CPU_MMX                 0x00000001
    61 #define SDL_CPU_3DNOW               0x00000002
    62 #define SDL_CPU_SSE                 0x00000004
    63 #define SDL_CPU_SSE2                0x00000008
    64 #define SDL_CPU_ALTIVEC_PREFETCH    0x00000010
    65 #define SDL_CPU_ALTIVEC_NOPREFETCH  0x00000020
    66 
    67 typedef struct
    68 {
    69     Uint8 *src;
    70     int src_w, src_h;
    71     int src_pitch;
    72     int src_skip;
    73     Uint8 *dst;
    74     int dst_w, dst_h;
    75     int dst_pitch;
    76     int dst_skip;
    77     SDL_PixelFormat *src_fmt;
    78     SDL_PixelFormat *dst_fmt;
    79     Uint8 *table;
    80     int flags;
    81     Uint32 colorkey;
    82     Uint8 r, g, b, a;
    83 } SDL_BlitInfo;
    84 
    85 typedef void (SDLCALL * SDL_BlitFunc) (SDL_BlitInfo * info);
    86 
    87 typedef struct
    88 {
    89     Uint32 src_format;
    90     Uint32 dst_format;
    91     int flags;
    92     int cpu;
    93     SDL_BlitFunc func;
    94 } SDL_BlitFuncEntry;
    95 
    96 /* Blit mapping definition */
    97 typedef struct SDL_BlitMap
    98 {
    99     SDL_Surface *dst;
   100     int identity;
   101     SDL_blit blit;
   102     void *data;
   103     SDL_BlitInfo info;
   104 
   105     /* the version count matches the destination; mismatch indicates
   106        an invalid mapping */
   107     unsigned int format_version;
   108 } SDL_BlitMap;
   109 
   110 /* Functions found in SDL_blit.c */
   111 extern int SDL_CalculateBlit(SDL_Surface * surface);
   112 
   113 /* Functions found in SDL_blit_*.c */
   114 extern SDL_BlitFunc SDL_CalculateBlit0(SDL_Surface * surface);
   115 extern SDL_BlitFunc SDL_CalculateBlit1(SDL_Surface * surface);
   116 extern SDL_BlitFunc SDL_CalculateBlitN(SDL_Surface * surface);
   117 extern SDL_BlitFunc SDL_CalculateBlitA(SDL_Surface * surface);
   118 
   119 /*
   120  * Useful macros for blitting routines
   121  */
   122 
   123 #if defined(__GNUC__)
   124 #define DECLARE_ALIGNED(t,v,a)  t __attribute__((aligned(a))) v
   125 #elif defined(_MSC_VER)
   126 #define DECLARE_ALIGNED(t,v,a)  __declspec(align(a)) t v
   127 #else
   128 #define DECLARE_ALIGNED(t,v,a)  t v
   129 #endif
   130 
   131 #define FORMAT_EQUAL(A, B)						\
   132     ((A)->BitsPerPixel == (B)->BitsPerPixel				\
   133      && ((A)->Rmask == (B)->Rmask) && ((A)->Amask == (B)->Amask))
   134 
   135 /* Load pixel of the specified format from a buffer and get its R-G-B values */
   136 /* FIXME: rescale values to 0..255 here? */
   137 #define RGB_FROM_PIXEL(Pixel, fmt, r, g, b)				\
   138 {									\
   139 	r = (((Pixel&fmt->Rmask)>>fmt->Rshift)<<fmt->Rloss); 		\
   140 	g = (((Pixel&fmt->Gmask)>>fmt->Gshift)<<fmt->Gloss); 		\
   141 	b = (((Pixel&fmt->Bmask)>>fmt->Bshift)<<fmt->Bloss); 		\
   142 }
   143 #define RGB_FROM_RGB565(Pixel, r, g, b)					\
   144 {									\
   145 	r = (((Pixel&0xF800)>>11)<<3);		 			\
   146 	g = (((Pixel&0x07E0)>>5)<<2); 					\
   147 	b = ((Pixel&0x001F)<<3); 					\
   148 }
   149 #define RGB_FROM_RGB555(Pixel, r, g, b)					\
   150 {									\
   151 	r = (((Pixel&0x7C00)>>10)<<3);		 			\
   152 	g = (((Pixel&0x03E0)>>5)<<3); 					\
   153 	b = ((Pixel&0x001F)<<3); 					\
   154 }
   155 #define RGB_FROM_RGB888(Pixel, r, g, b)					\
   156 {									\
   157 	r = ((Pixel&0xFF0000)>>16);		 			\
   158 	g = ((Pixel&0xFF00)>>8);		 			\
   159 	b = (Pixel&0xFF);			 			\
   160 }
   161 #define RETRIEVE_RGB_PIXEL(buf, bpp, Pixel)				   \
   162 do {									   \
   163 	switch (bpp) {							   \
   164 		case 2:							   \
   165 			Pixel = *((Uint16 *)(buf));			   \
   166 		break;							   \
   167 									   \
   168 		case 3: {						   \
   169 		        Uint8 *B = (Uint8 *)(buf);			   \
   170 			if (SDL_BYTEORDER == SDL_LIL_ENDIAN) {		   \
   171 			        Pixel = B[0] + (B[1] << 8) + (B[2] << 16); \
   172 			} else {					   \
   173 			        Pixel = (B[0] << 16) + (B[1] << 8) + B[2]; \
   174 			}						   \
   175 		}							   \
   176 		break;							   \
   177 									   \
   178 		case 4:							   \
   179 			Pixel = *((Uint32 *)(buf));			   \
   180 		break;							   \
   181 									   \
   182 		default:						   \
   183 		        Pixel; /* stop gcc complaints */		   \
   184 		break;							   \
   185 	}								   \
   186 } while (0)
   187 
   188 #define DISEMBLE_RGB(buf, bpp, fmt, Pixel, r, g, b)			   \
   189 do {									   \
   190 	switch (bpp) {							   \
   191 		case 2:							   \
   192 			Pixel = *((Uint16 *)(buf));			   \
   193 			RGB_FROM_PIXEL(Pixel, fmt, r, g, b);		   \
   194 		break;							   \
   195 									   \
   196 		case 3:	{						   \
   197                         if (SDL_BYTEORDER == SDL_LIL_ENDIAN) {		   \
   198 			        r = *((buf)+fmt->Rshift/8);		   \
   199 				g = *((buf)+fmt->Gshift/8);		   \
   200 				b = *((buf)+fmt->Bshift/8);		   \
   201 			} else {					   \
   202 			        r = *((buf)+2-fmt->Rshift/8);		   \
   203 				g = *((buf)+2-fmt->Gshift/8);		   \
   204 				b = *((buf)+2-fmt->Bshift/8);		   \
   205 			}						   \
   206 		}							   \
   207 		break;							   \
   208 									   \
   209 		case 4:							   \
   210 			Pixel = *((Uint32 *)(buf));			   \
   211 			RGB_FROM_PIXEL(Pixel, fmt, r, g, b);		   \
   212 		break;							   \
   213 									   \
   214 		default:						   \
   215 		        Pixel; /* stop gcc complaints */		   \
   216 		break;							   \
   217 	}								   \
   218 } while (0)
   219 
   220 /* Assemble R-G-B values into a specified pixel format and store them */
   221 #define PIXEL_FROM_RGB(Pixel, fmt, r, g, b)				\
   222 {									\
   223 	Pixel = ((r>>fmt->Rloss)<<fmt->Rshift)|				\
   224 		((g>>fmt->Gloss)<<fmt->Gshift)|				\
   225 		((b>>fmt->Bloss)<<fmt->Bshift);				\
   226 }
   227 #define RGB565_FROM_RGB(Pixel, r, g, b)					\
   228 {									\
   229 	Pixel = ((r>>3)<<11)|((g>>2)<<5)|(b>>3);			\
   230 }
   231 #define RGB555_FROM_RGB(Pixel, r, g, b)					\
   232 {									\
   233 	Pixel = ((r>>3)<<10)|((g>>3)<<5)|(b>>3);			\
   234 }
   235 #define RGB888_FROM_RGB(Pixel, r, g, b)					\
   236 {									\
   237 	Pixel = (r<<16)|(g<<8)|b;					\
   238 }
   239 #define ASSEMBLE_RGB(buf, bpp, fmt, r, g, b) 				\
   240 {									\
   241 	switch (bpp) {							\
   242 		case 2: {						\
   243 			Uint16 Pixel;					\
   244 									\
   245 			PIXEL_FROM_RGB(Pixel, fmt, r, g, b);		\
   246 			*((Uint16 *)(buf)) = Pixel;			\
   247 		}							\
   248 		break;							\
   249 									\
   250 		case 3: {						\
   251                         if (SDL_BYTEORDER == SDL_LIL_ENDIAN) {		\
   252 			        *((buf)+fmt->Rshift/8) = r;		\
   253 				*((buf)+fmt->Gshift/8) = g;		\
   254 				*((buf)+fmt->Bshift/8) = b;		\
   255 			} else {					\
   256 			        *((buf)+2-fmt->Rshift/8) = r;		\
   257 				*((buf)+2-fmt->Gshift/8) = g;		\
   258 				*((buf)+2-fmt->Bshift/8) = b;		\
   259 			}						\
   260 		}							\
   261 		break;							\
   262 									\
   263 		case 4: {						\
   264 			Uint32 Pixel;					\
   265 									\
   266 			PIXEL_FROM_RGB(Pixel, fmt, r, g, b);		\
   267 			*((Uint32 *)(buf)) = Pixel;			\
   268 		}							\
   269 		break;							\
   270 	}								\
   271 }
   272 #define ASSEMBLE_RGB_AMASK(buf, bpp, fmt, r, g, b, Amask)		\
   273 {									\
   274 	switch (bpp) {							\
   275 		case 2: {						\
   276 			Uint16 *bufp;					\
   277 			Uint16 Pixel;					\
   278 									\
   279 			bufp = (Uint16 *)buf;				\
   280 			PIXEL_FROM_RGB(Pixel, fmt, r, g, b);		\
   281 			*bufp = Pixel | (*bufp & Amask);		\
   282 		}							\
   283 		break;							\
   284 									\
   285 		case 3: {						\
   286                         if (SDL_BYTEORDER == SDL_LIL_ENDIAN) {		\
   287 			        *((buf)+fmt->Rshift/8) = r;		\
   288 				*((buf)+fmt->Gshift/8) = g;		\
   289 				*((buf)+fmt->Bshift/8) = b;		\
   290 			} else {					\
   291 			        *((buf)+2-fmt->Rshift/8) = r;		\
   292 				*((buf)+2-fmt->Gshift/8) = g;		\
   293 				*((buf)+2-fmt->Bshift/8) = b;		\
   294 			}						\
   295 		}							\
   296 		break;							\
   297 									\
   298 		case 4: {						\
   299 			Uint32 *bufp;					\
   300 			Uint32 Pixel;					\
   301 									\
   302 			bufp = (Uint32 *)buf;				\
   303 			PIXEL_FROM_RGB(Pixel, fmt, r, g, b);		\
   304 			*bufp = Pixel | (*bufp & Amask);		\
   305 		}							\
   306 		break;							\
   307 	}								\
   308 }
   309 
   310 /* FIXME: Should we rescale alpha into 0..255 here? */
   311 #define RGBA_FROM_PIXEL(Pixel, fmt, r, g, b, a)				\
   312 {									\
   313 	r = ((Pixel&fmt->Rmask)>>fmt->Rshift)<<fmt->Rloss; 		\
   314 	g = ((Pixel&fmt->Gmask)>>fmt->Gshift)<<fmt->Gloss; 		\
   315 	b = ((Pixel&fmt->Bmask)>>fmt->Bshift)<<fmt->Bloss; 		\
   316 	a = ((Pixel&fmt->Amask)>>fmt->Ashift)<<fmt->Aloss;	 	\
   317 }
   318 #define RGBA_FROM_8888(Pixel, fmt, r, g, b, a)	\
   319 {						\
   320 	r = (Pixel&fmt->Rmask)>>fmt->Rshift;	\
   321 	g = (Pixel&fmt->Gmask)>>fmt->Gshift;	\
   322 	b = (Pixel&fmt->Bmask)>>fmt->Bshift;	\
   323 	a = (Pixel&fmt->Amask)>>fmt->Ashift;	\
   324 }
   325 #define RGBA_FROM_RGBA8888(Pixel, r, g, b, a)				\
   326 {									\
   327 	r = (Pixel>>24);						\
   328 	g = ((Pixel>>16)&0xFF);						\
   329 	b = ((Pixel>>8)&0xFF);						\
   330 	a = (Pixel&0xFF);						\
   331 }
   332 #define RGBA_FROM_ARGB8888(Pixel, r, g, b, a)				\
   333 {									\
   334 	r = ((Pixel>>16)&0xFF);						\
   335 	g = ((Pixel>>8)&0xFF);						\
   336 	b = (Pixel&0xFF);						\
   337 	a = (Pixel>>24);						\
   338 }
   339 #define RGBA_FROM_ABGR8888(Pixel, r, g, b, a)				\
   340 {									\
   341 	r = (Pixel&0xFF);						\
   342 	g = ((Pixel>>8)&0xFF);						\
   343 	b = ((Pixel>>16)&0xFF);						\
   344 	a = (Pixel>>24);						\
   345 }
   346 #define DISEMBLE_RGBA(buf, bpp, fmt, Pixel, r, g, b, a)			   \
   347 do {									   \
   348 	switch (bpp) {							   \
   349 		case 2:							   \
   350 			Pixel = *((Uint16 *)(buf));			   \
   351 			RGBA_FROM_PIXEL(Pixel, fmt, r, g, b, a);	   \
   352 		break;							   \
   353 									   \
   354 		case 3:	{						   \
   355                         if (SDL_BYTEORDER == SDL_LIL_ENDIAN) {		   \
   356 			        r = *((buf)+fmt->Rshift/8);		   \
   357 				g = *((buf)+fmt->Gshift/8);		   \
   358 				b = *((buf)+fmt->Bshift/8);		   \
   359 			} else {					   \
   360 			        r = *((buf)+2-fmt->Rshift/8);		   \
   361 				g = *((buf)+2-fmt->Gshift/8);		   \
   362 				b = *((buf)+2-fmt->Bshift/8);		   \
   363 			}						   \
   364 			a = 0xFF;					   \
   365 		}							   \
   366 		break;							   \
   367 									   \
   368 		case 4:							   \
   369 			Pixel = *((Uint32 *)(buf));			   \
   370 			RGBA_FROM_PIXEL(Pixel, fmt, r, g, b, a);	   \
   371 		break;							   \
   372 									   \
   373 		default:						   \
   374 		        Pixel; /* stop gcc complaints */		   \
   375 		break;							   \
   376 	}								   \
   377 } while (0)
   378 
   379 /* FIXME: this isn't correct, especially for Alpha (maximum != 255) */
   380 #define PIXEL_FROM_RGBA(Pixel, fmt, r, g, b, a)				\
   381 {									\
   382 	Pixel = ((r>>fmt->Rloss)<<fmt->Rshift)|				\
   383 		((g>>fmt->Gloss)<<fmt->Gshift)|				\
   384 		((b>>fmt->Bloss)<<fmt->Bshift)|				\
   385 		((a>>fmt->Aloss)<<fmt->Ashift);				\
   386 }
   387 #define ASSEMBLE_RGBA(buf, bpp, fmt, r, g, b, a)			\
   388 {									\
   389 	switch (bpp) {							\
   390 		case 2: {						\
   391 			Uint16 Pixel;					\
   392 									\
   393 			PIXEL_FROM_RGBA(Pixel, fmt, r, g, b, a);	\
   394 			*((Uint16 *)(buf)) = Pixel;			\
   395 		}							\
   396 		break;							\
   397 									\
   398 		case 3: {						\
   399                         if (SDL_BYTEORDER == SDL_LIL_ENDIAN) {		\
   400 			        *((buf)+fmt->Rshift/8) = r;		\
   401 				*((buf)+fmt->Gshift/8) = g;		\
   402 				*((buf)+fmt->Bshift/8) = b;		\
   403 			} else {					\
   404 			        *((buf)+2-fmt->Rshift/8) = r;		\
   405 				*((buf)+2-fmt->Gshift/8) = g;		\
   406 				*((buf)+2-fmt->Bshift/8) = b;		\
   407 			}						\
   408 		}							\
   409 		break;							\
   410 									\
   411 		case 4: {						\
   412 			Uint32 Pixel;					\
   413 									\
   414 			PIXEL_FROM_RGBA(Pixel, fmt, r, g, b, a);	\
   415 			*((Uint32 *)(buf)) = Pixel;			\
   416 		}							\
   417 		break;							\
   418 	}								\
   419 }
   420 
   421 /* Blend the RGB values of two Pixels based on a source alpha value */
   422 #define ALPHA_BLEND(sR, sG, sB, A, dR, dG, dB)	\
   423 do {						\
   424 	dR = (((sR-dR)*(A))>>8)+dR;		\
   425 	dG = (((sG-dG)*(A))>>8)+dG;		\
   426 	dB = (((sB-dB)*(A))>>8)+dB;		\
   427 } while(0)
   428 
   429 /* Blend the RGB values of two Pixels based on a source alpha value */
   430 #define ACCURATE_ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB)	\
   431 do {						\
   432     unsigned tR, tG, tB, tA; \
   433     tA = 255 - sA; \
   434     tR = 1 + (sR * sA) + (dR * tA); \
   435     dR = (tR + (tR >> 8)) >> 8; \
   436     tG = 1 + (sG * sA) + (dG * tA); \
   437     dG = (tG + (tG >> 8)) >> 8; \
   438     tB = 1 + (sB * sA) + (dB * tA); \
   439     dB = (tB + (tB >> 8)) >> 8; \
   440 } while(0)
   441 
   442 
   443 /* This is a very useful loop for optimizing blitters */
   444 #if defined(_MSC_VER) && (_MSC_VER == 1300)
   445 /* There's a bug in the Visual C++ 7 optimizer when compiling this code */
   446 #else
   447 #define USE_DUFFS_LOOP
   448 #endif
   449 #ifdef USE_DUFFS_LOOP
   450 
   451 /* 8-times unrolled loop */
   452 #define DUFFS_LOOP8(pixel_copy_increment, width)			\
   453 { int n = (width+7)/8;							\
   454 	switch (width & 7) {						\
   455 	case 0: do {	pixel_copy_increment;				\
   456 	case 7:		pixel_copy_increment;				\
   457 	case 6:		pixel_copy_increment;				\
   458 	case 5:		pixel_copy_increment;				\
   459 	case 4:		pixel_copy_increment;				\
   460 	case 3:		pixel_copy_increment;				\
   461 	case 2:		pixel_copy_increment;				\
   462 	case 1:		pixel_copy_increment;				\
   463 		} while ( --n > 0 );					\
   464 	}								\
   465 }
   466 
   467 /* 4-times unrolled loop */
   468 #define DUFFS_LOOP4(pixel_copy_increment, width)			\
   469 { int n = (width+3)/4;							\
   470 	switch (width & 3) {						\
   471 	case 0: do {	pixel_copy_increment;				\
   472 	case 3:		pixel_copy_increment;				\
   473 	case 2:		pixel_copy_increment;				\
   474 	case 1:		pixel_copy_increment;				\
   475 		} while ( --n > 0 );					\
   476 	}								\
   477 }
   478 
   479 /* 2 - times unrolled loop */
   480 #define DUFFS_LOOP_DOUBLE2(pixel_copy_increment,			\
   481 				double_pixel_copy_increment, width)	\
   482 { int n, w = width;							\
   483 	if( w & 1 ) {							\
   484 	    pixel_copy_increment;					\
   485 	    w--;							\
   486 	}								\
   487 	if ( w > 0 )	{						\
   488 	    n = ( w + 2) / 4;						\
   489 	    switch( w & 2 ) {						\
   490 	    case 0: do {	double_pixel_copy_increment;		\
   491 	    case 2:		double_pixel_copy_increment;		\
   492 		    } while ( --n > 0 );					\
   493 	    }								\
   494 	}								\
   495 }
   496 
   497 /* 2 - times unrolled loop 4 pixels */
   498 #define DUFFS_LOOP_QUATRO2(pixel_copy_increment,			\
   499 				double_pixel_copy_increment,		\
   500 				quatro_pixel_copy_increment, width)	\
   501 { int n, w = width;								\
   502         if(w & 1) {							\
   503 	  pixel_copy_increment;						\
   504 	  w--;								\
   505 	}								\
   506 	if(w & 2) {							\
   507 	  double_pixel_copy_increment;					\
   508 	  w -= 2;							\
   509 	}								\
   510 	if ( w > 0 ) {							\
   511 	    n = ( w + 7 ) / 8;						\
   512 	    switch( w & 4 ) {						\
   513 	    case 0: do {	quatro_pixel_copy_increment;		\
   514 	    case 4:		quatro_pixel_copy_increment;		\
   515 		    } while ( --n > 0 );					\
   516 	    }								\
   517 	}								\
   518 }
   519 
   520 /* Use the 8-times version of the loop by default */
   521 #define DUFFS_LOOP(pixel_copy_increment, width)				\
   522 	DUFFS_LOOP8(pixel_copy_increment, width)
   523 
   524 #else
   525 
   526 /* Don't use Duff's device to unroll loops */
   527 #define DUFFS_LOOP_DOUBLE2(pixel_copy_increment,			\
   528 			 double_pixel_copy_increment, width)		\
   529 { int n = width;								\
   530     if( n & 1 ) {							\
   531 	pixel_copy_increment;						\
   532 	n--;								\
   533     }									\
   534     n=n>>1;								\
   535     for(; n > 0; --n) {   						\
   536 	double_pixel_copy_increment;					\
   537     }									\
   538 }
   539 
   540 /* Don't use Duff's device to unroll loops */
   541 #define DUFFS_LOOP_QUATRO2(pixel_copy_increment,			\
   542 				double_pixel_copy_increment,		\
   543 				quatro_pixel_copy_increment, width)	\
   544 { int n = width;								\
   545         if(n & 1) {							\
   546 	  pixel_copy_increment;						\
   547 	  n--;								\
   548 	}								\
   549 	if(n & 2) {							\
   550 	  double_pixel_copy_increment;					\
   551 	  n -= 2;							\
   552 	}								\
   553 	n=n>>2;								\
   554 	for(; n > 0; --n) {   						\
   555 	  quatro_pixel_copy_increment;					\
   556         }								\
   557 }
   558 
   559 /* Don't use Duff's device to unroll loops */
   560 #define DUFFS_LOOP(pixel_copy_increment, width)				\
   561 { int n;								\
   562 	for ( n=width; n > 0; --n ) {					\
   563 		pixel_copy_increment;					\
   564 	}								\
   565 }
   566 #define DUFFS_LOOP8(pixel_copy_increment, width)			\
   567 	DUFFS_LOOP(pixel_copy_increment, width)
   568 #define DUFFS_LOOP4(pixel_copy_increment, width)			\
   569 	DUFFS_LOOP(pixel_copy_increment, width)
   570 
   571 #endif /* USE_DUFFS_LOOP */
   572 
   573 /* Prevent Visual C++ 6.0 from printing out stupid warnings */
   574 #if defined(_MSC_VER) && (_MSC_VER >= 600)
   575 #pragma warning(disable: 4550)
   576 #endif
   577 
   578 #endif /* _SDL_blit_h */
   579 
   580 /* vi: set ts=4 sw=4 expandtab: */