src/video/SDL_blit.h
changeset 7191 75360622e65f
parent 6885 700f1b25f77f
child 7364 e21bd6987b86
     1.1 --- a/src/video/SDL_blit.h	Sat May 18 12:48:50 2013 -0700
     1.2 +++ b/src/video/SDL_blit.h	Sat May 18 14:17:52 2013 -0700
     1.3 @@ -118,289 +118,289 @@
     1.4  #endif
     1.5  
     1.6  /* Load pixel of the specified format from a buffer and get its R-G-B values */
     1.7 -#define RGB_FROM_PIXEL(Pixel, fmt, r, g, b)				\
     1.8 -{									\
     1.9 -	r = SDL_expand_byte[fmt->Rloss][((Pixel&fmt->Rmask)>>fmt->Rshift)]; \
    1.10 -	g = SDL_expand_byte[fmt->Gloss][((Pixel&fmt->Gmask)>>fmt->Gshift)]; \
    1.11 -	b = SDL_expand_byte[fmt->Bloss][((Pixel&fmt->Bmask)>>fmt->Bshift)]; \
    1.12 +#define RGB_FROM_PIXEL(Pixel, fmt, r, g, b)             \
    1.13 +{                                   \
    1.14 +    r = SDL_expand_byte[fmt->Rloss][((Pixel&fmt->Rmask)>>fmt->Rshift)]; \
    1.15 +    g = SDL_expand_byte[fmt->Gloss][((Pixel&fmt->Gmask)>>fmt->Gshift)]; \
    1.16 +    b = SDL_expand_byte[fmt->Bloss][((Pixel&fmt->Bmask)>>fmt->Bshift)]; \
    1.17  }
    1.18 -#define RGB_FROM_RGB565(Pixel, r, g, b)					\
    1.19 -{									\
    1.20 -	r = SDL_expand_byte[3][((Pixel&0xF800)>>11)];		 			\
    1.21 -	g = SDL_expand_byte[2][((Pixel&0x07E0)>>5)]; 					\
    1.22 -	b = SDL_expand_byte[3][(Pixel&0x001F)]; 					\
    1.23 +#define RGB_FROM_RGB565(Pixel, r, g, b)                 \
    1.24 +{                                   \
    1.25 +    r = SDL_expand_byte[3][((Pixel&0xF800)>>11)];                   \
    1.26 +    g = SDL_expand_byte[2][((Pixel&0x07E0)>>5)];                    \
    1.27 +    b = SDL_expand_byte[3][(Pixel&0x001F)];                     \
    1.28  }
    1.29 -#define RGB_FROM_RGB555(Pixel, r, g, b)					\
    1.30 -{									\
    1.31 -	r = SDL_expand_byte[3][((Pixel&0x7C00)>>10)];		 			\
    1.32 -	g = SDL_expand_byte[3][((Pixel&0x03E0)>>5)]; 					\
    1.33 -	b = SDL_expand_byte[3][(Pixel&0x001F)]; 					\
    1.34 +#define RGB_FROM_RGB555(Pixel, r, g, b)                 \
    1.35 +{                                   \
    1.36 +    r = SDL_expand_byte[3][((Pixel&0x7C00)>>10)];                   \
    1.37 +    g = SDL_expand_byte[3][((Pixel&0x03E0)>>5)];                    \
    1.38 +    b = SDL_expand_byte[3][(Pixel&0x001F)];                     \
    1.39  }
    1.40 -#define RGB_FROM_RGB888(Pixel, r, g, b)					\
    1.41 -{									\
    1.42 -	r = ((Pixel&0xFF0000)>>16);		 			\
    1.43 -	g = ((Pixel&0xFF00)>>8);		 			\
    1.44 -	b = (Pixel&0xFF);			 			\
    1.45 +#define RGB_FROM_RGB888(Pixel, r, g, b)                 \
    1.46 +{                                   \
    1.47 +    r = ((Pixel&0xFF0000)>>16);                 \
    1.48 +    g = ((Pixel&0xFF00)>>8);                    \
    1.49 +    b = (Pixel&0xFF);                       \
    1.50  }
    1.51 -#define RETRIEVE_RGB_PIXEL(buf, bpp, Pixel)				   \
    1.52 -do {									   \
    1.53 -	switch (bpp) {							   \
    1.54 -		case 2:							   \
    1.55 -			Pixel = *((Uint16 *)(buf));			   \
    1.56 -		break;							   \
    1.57 -									   \
    1.58 -		case 3: {						   \
    1.59 -		        Uint8 *B = (Uint8 *)(buf);			   \
    1.60 -			if (SDL_BYTEORDER == SDL_LIL_ENDIAN) {		   \
    1.61 -			        Pixel = B[0] + (B[1] << 8) + (B[2] << 16); \
    1.62 -			} else {					   \
    1.63 -			        Pixel = (B[0] << 16) + (B[1] << 8) + B[2]; \
    1.64 -			}						   \
    1.65 -		}							   \
    1.66 -		break;							   \
    1.67 -									   \
    1.68 -		case 4:							   \
    1.69 -			Pixel = *((Uint32 *)(buf));			   \
    1.70 -		break;							   \
    1.71 -									   \
    1.72 -		default:						   \
    1.73 -		        Pixel = 0; /* stop gcc complaints */		   \
    1.74 -		break;							   \
    1.75 -	}								   \
    1.76 +#define RETRIEVE_RGB_PIXEL(buf, bpp, Pixel)                \
    1.77 +do {                                       \
    1.78 +    switch (bpp) {                             \
    1.79 +        case 2:                            \
    1.80 +            Pixel = *((Uint16 *)(buf));            \
    1.81 +        break;                             \
    1.82 +                                       \
    1.83 +        case 3: {                          \
    1.84 +                Uint8 *B = (Uint8 *)(buf);             \
    1.85 +            if (SDL_BYTEORDER == SDL_LIL_ENDIAN) {         \
    1.86 +                    Pixel = B[0] + (B[1] << 8) + (B[2] << 16); \
    1.87 +            } else {                       \
    1.88 +                    Pixel = (B[0] << 16) + (B[1] << 8) + B[2]; \
    1.89 +            }                          \
    1.90 +        }                              \
    1.91 +        break;                             \
    1.92 +                                       \
    1.93 +        case 4:                            \
    1.94 +            Pixel = *((Uint32 *)(buf));            \
    1.95 +        break;                             \
    1.96 +                                       \
    1.97 +        default:                           \
    1.98 +                Pixel = 0; /* stop gcc complaints */           \
    1.99 +        break;                             \
   1.100 +    }                                  \
   1.101  } while (0)
   1.102  
   1.103 -#define DISEMBLE_RGB(buf, bpp, fmt, Pixel, r, g, b)			   \
   1.104 -do {									   \
   1.105 -	switch (bpp) {							   \
   1.106 -		case 2:							   \
   1.107 -			Pixel = *((Uint16 *)(buf));			   \
   1.108 -			RGB_FROM_PIXEL(Pixel, fmt, r, g, b);		   \
   1.109 -		break;							   \
   1.110 -									   \
   1.111 -		case 3:	{						   \
   1.112 +#define DISEMBLE_RGB(buf, bpp, fmt, Pixel, r, g, b)            \
   1.113 +do {                                       \
   1.114 +    switch (bpp) {                             \
   1.115 +        case 2:                            \
   1.116 +            Pixel = *((Uint16 *)(buf));            \
   1.117 +            RGB_FROM_PIXEL(Pixel, fmt, r, g, b);           \
   1.118 +        break;                             \
   1.119 +                                       \
   1.120 +        case 3: {                          \
   1.121              Pixel = 0;                  \
   1.122 -                        if (SDL_BYTEORDER == SDL_LIL_ENDIAN) {		   \
   1.123 -			        r = *((buf)+fmt->Rshift/8);		   \
   1.124 -				g = *((buf)+fmt->Gshift/8);		   \
   1.125 -				b = *((buf)+fmt->Bshift/8);		   \
   1.126 -			} else {					   \
   1.127 -			        r = *((buf)+2-fmt->Rshift/8);		   \
   1.128 -				g = *((buf)+2-fmt->Gshift/8);		   \
   1.129 -				b = *((buf)+2-fmt->Bshift/8);		   \
   1.130 -			}						   \
   1.131 -		}							   \
   1.132 -		break;							   \
   1.133 -									   \
   1.134 -		case 4:							   \
   1.135 -			Pixel = *((Uint32 *)(buf));			   \
   1.136 -			RGB_FROM_PIXEL(Pixel, fmt, r, g, b);		   \
   1.137 -		break;							   \
   1.138 -									   \
   1.139 -		default:						   \
   1.140 -                /* stop gcc complaints */		   \
   1.141 -		        Pixel = 0;              \
   1.142 +                        if (SDL_BYTEORDER == SDL_LIL_ENDIAN) {         \
   1.143 +                    r = *((buf)+fmt->Rshift/8);        \
   1.144 +                g = *((buf)+fmt->Gshift/8);        \
   1.145 +                b = *((buf)+fmt->Bshift/8);        \
   1.146 +            } else {                       \
   1.147 +                    r = *((buf)+2-fmt->Rshift/8);          \
   1.148 +                g = *((buf)+2-fmt->Gshift/8);          \
   1.149 +                b = *((buf)+2-fmt->Bshift/8);          \
   1.150 +            }                          \
   1.151 +        }                              \
   1.152 +        break;                             \
   1.153 +                                       \
   1.154 +        case 4:                            \
   1.155 +            Pixel = *((Uint32 *)(buf));            \
   1.156 +            RGB_FROM_PIXEL(Pixel, fmt, r, g, b);           \
   1.157 +        break;                             \
   1.158 +                                       \
   1.159 +        default:                           \
   1.160 +                /* stop gcc complaints */          \
   1.161 +                Pixel = 0;              \
   1.162                  r = g = b = 0;          \
   1.163 -		break;							   \
   1.164 -	}								   \
   1.165 +        break;                             \
   1.166 +    }                                  \
   1.167  } while (0)
   1.168  
   1.169  /* Assemble R-G-B values into a specified pixel format and store them */
   1.170 -#define PIXEL_FROM_RGB(Pixel, fmt, r, g, b)				\
   1.171 -{									\
   1.172 -	Pixel = ((r>>fmt->Rloss)<<fmt->Rshift)|				\
   1.173 -		((g>>fmt->Gloss)<<fmt->Gshift)|				\
   1.174 -		((b>>fmt->Bloss)<<fmt->Bshift)| \
   1.175 -        fmt->Amask;				\
   1.176 +#define PIXEL_FROM_RGB(Pixel, fmt, r, g, b)             \
   1.177 +{                                   \
   1.178 +    Pixel = ((r>>fmt->Rloss)<<fmt->Rshift)|             \
   1.179 +        ((g>>fmt->Gloss)<<fmt->Gshift)|             \
   1.180 +        ((b>>fmt->Bloss)<<fmt->Bshift)| \
   1.181 +        fmt->Amask;             \
   1.182  }
   1.183 -#define RGB565_FROM_RGB(Pixel, r, g, b)					\
   1.184 -{									\
   1.185 -	Pixel = ((r>>3)<<11)|((g>>2)<<5)|(b>>3);			\
   1.186 +#define RGB565_FROM_RGB(Pixel, r, g, b)                 \
   1.187 +{                                   \
   1.188 +    Pixel = ((r>>3)<<11)|((g>>2)<<5)|(b>>3);            \
   1.189  }
   1.190 -#define RGB555_FROM_RGB(Pixel, r, g, b)					\
   1.191 -{									\
   1.192 -	Pixel = ((r>>3)<<10)|((g>>3)<<5)|(b>>3);			\
   1.193 +#define RGB555_FROM_RGB(Pixel, r, g, b)                 \
   1.194 +{                                   \
   1.195 +    Pixel = ((r>>3)<<10)|((g>>3)<<5)|(b>>3);            \
   1.196  }
   1.197 -#define RGB888_FROM_RGB(Pixel, r, g, b)					\
   1.198 -{									\
   1.199 -	Pixel = (r<<16)|(g<<8)|b;					\
   1.200 +#define RGB888_FROM_RGB(Pixel, r, g, b)                 \
   1.201 +{                                   \
   1.202 +    Pixel = (r<<16)|(g<<8)|b;                   \
   1.203  }
   1.204 -#define ARGB8888_FROM_RGBA(Pixel, r, g, b, a)				\
   1.205 -{									\
   1.206 -	Pixel = (a<<24)|(r<<16)|(g<<8)|b;				\
   1.207 +#define ARGB8888_FROM_RGBA(Pixel, r, g, b, a)               \
   1.208 +{                                   \
   1.209 +    Pixel = (a<<24)|(r<<16)|(g<<8)|b;               \
   1.210  }
   1.211 -#define RGBA8888_FROM_RGBA(Pixel, r, g, b, a)				\
   1.212 -{									\
   1.213 -	Pixel = (r<<24)|(g<<16)|(b<<8)|a;				\
   1.214 +#define RGBA8888_FROM_RGBA(Pixel, r, g, b, a)               \
   1.215 +{                                   \
   1.216 +    Pixel = (r<<24)|(g<<16)|(b<<8)|a;               \
   1.217  }
   1.218 -#define ABGR8888_FROM_RGBA(Pixel, r, g, b, a)				\
   1.219 -{									\
   1.220 -	Pixel = (a<<24)|(b<<16)|(g<<8)|r;				\
   1.221 +#define ABGR8888_FROM_RGBA(Pixel, r, g, b, a)               \
   1.222 +{                                   \
   1.223 +    Pixel = (a<<24)|(b<<16)|(g<<8)|r;               \
   1.224  }
   1.225 -#define BGRA8888_FROM_RGBA(Pixel, r, g, b, a)				\
   1.226 -{									\
   1.227 -	Pixel = (b<<24)|(g<<16)|(r<<8)|a;				\
   1.228 +#define BGRA8888_FROM_RGBA(Pixel, r, g, b, a)               \
   1.229 +{                                   \
   1.230 +    Pixel = (b<<24)|(g<<16)|(r<<8)|a;               \
   1.231  }
   1.232 -#define ASSEMBLE_RGB(buf, bpp, fmt, r, g, b) 				\
   1.233 -{									\
   1.234 -	switch (bpp) {							\
   1.235 -		case 2: {						\
   1.236 -			Uint16 Pixel;					\
   1.237 -									\
   1.238 -			PIXEL_FROM_RGB(Pixel, fmt, r, g, b);		\
   1.239 -			*((Uint16 *)(buf)) = Pixel;		\
   1.240 -		}							\
   1.241 -		break;							\
   1.242 -									\
   1.243 -		case 3: {						\
   1.244 -                        if (SDL_BYTEORDER == SDL_LIL_ENDIAN) {		\
   1.245 -			        *((buf)+fmt->Rshift/8) = r;		\
   1.246 -				*((buf)+fmt->Gshift/8) = g;		\
   1.247 -				*((buf)+fmt->Bshift/8) = b;		\
   1.248 -			} else {					\
   1.249 -			        *((buf)+2-fmt->Rshift/8) = r;		\
   1.250 -				*((buf)+2-fmt->Gshift/8) = g;		\
   1.251 -				*((buf)+2-fmt->Bshift/8) = b;		\
   1.252 -			}						\
   1.253 -		}							\
   1.254 -		break;							\
   1.255 -									\
   1.256 -		case 4: {						\
   1.257 -			Uint32 Pixel;					\
   1.258 -									\
   1.259 -			PIXEL_FROM_RGB(Pixel, fmt, r, g, b);		\
   1.260 -			*((Uint32 *)(buf)) = Pixel;			\
   1.261 -		}							\
   1.262 -		break;							\
   1.263 -	}								\
   1.264 +#define ASSEMBLE_RGB(buf, bpp, fmt, r, g, b)                \
   1.265 +{                                   \
   1.266 +    switch (bpp) {                          \
   1.267 +        case 2: {                       \
   1.268 +            Uint16 Pixel;                   \
   1.269 +                                    \
   1.270 +            PIXEL_FROM_RGB(Pixel, fmt, r, g, b);        \
   1.271 +            *((Uint16 *)(buf)) = Pixel;     \
   1.272 +        }                           \
   1.273 +        break;                          \
   1.274 +                                    \
   1.275 +        case 3: {                       \
   1.276 +                        if (SDL_BYTEORDER == SDL_LIL_ENDIAN) {      \
   1.277 +                    *((buf)+fmt->Rshift/8) = r;     \
   1.278 +                *((buf)+fmt->Gshift/8) = g;     \
   1.279 +                *((buf)+fmt->Bshift/8) = b;     \
   1.280 +            } else {                    \
   1.281 +                    *((buf)+2-fmt->Rshift/8) = r;       \
   1.282 +                *((buf)+2-fmt->Gshift/8) = g;       \
   1.283 +                *((buf)+2-fmt->Bshift/8) = b;       \
   1.284 +            }                       \
   1.285 +        }                           \
   1.286 +        break;                          \
   1.287 +                                    \
   1.288 +        case 4: {                       \
   1.289 +            Uint32 Pixel;                   \
   1.290 +                                    \
   1.291 +            PIXEL_FROM_RGB(Pixel, fmt, r, g, b);        \
   1.292 +            *((Uint32 *)(buf)) = Pixel;         \
   1.293 +        }                           \
   1.294 +        break;                          \
   1.295 +    }                               \
   1.296  }
   1.297  
   1.298  /* FIXME: Should we rescale alpha into 0..255 here? */
   1.299 -#define RGBA_FROM_PIXEL(Pixel, fmt, r, g, b, a)				\
   1.300 -{									\
   1.301 -	r = SDL_expand_byte[fmt->Rloss][((Pixel&fmt->Rmask)>>fmt->Rshift)]; \
   1.302 -	g = SDL_expand_byte[fmt->Gloss][((Pixel&fmt->Gmask)>>fmt->Gshift)]; \
   1.303 -	b = SDL_expand_byte[fmt->Bloss][((Pixel&fmt->Bmask)>>fmt->Bshift)]; \
   1.304 -	a = SDL_expand_byte[fmt->Aloss][((Pixel&fmt->Amask)>>fmt->Ashift)]; \
   1.305 +#define RGBA_FROM_PIXEL(Pixel, fmt, r, g, b, a)             \
   1.306 +{                                   \
   1.307 +    r = SDL_expand_byte[fmt->Rloss][((Pixel&fmt->Rmask)>>fmt->Rshift)]; \
   1.308 +    g = SDL_expand_byte[fmt->Gloss][((Pixel&fmt->Gmask)>>fmt->Gshift)]; \
   1.309 +    b = SDL_expand_byte[fmt->Bloss][((Pixel&fmt->Bmask)>>fmt->Bshift)]; \
   1.310 +    a = SDL_expand_byte[fmt->Aloss][((Pixel&fmt->Amask)>>fmt->Ashift)]; \
   1.311  }
   1.312 -#define RGBA_FROM_8888(Pixel, fmt, r, g, b, a)	\
   1.313 -{						\
   1.314 -	r = (Pixel&fmt->Rmask)>>fmt->Rshift;	\
   1.315 -	g = (Pixel&fmt->Gmask)>>fmt->Gshift;	\
   1.316 -	b = (Pixel&fmt->Bmask)>>fmt->Bshift;	\
   1.317 -	a = (Pixel&fmt->Amask)>>fmt->Ashift;	\
   1.318 +#define RGBA_FROM_8888(Pixel, fmt, r, g, b, a)  \
   1.319 +{                       \
   1.320 +    r = (Pixel&fmt->Rmask)>>fmt->Rshift;    \
   1.321 +    g = (Pixel&fmt->Gmask)>>fmt->Gshift;    \
   1.322 +    b = (Pixel&fmt->Bmask)>>fmt->Bshift;    \
   1.323 +    a = (Pixel&fmt->Amask)>>fmt->Ashift;    \
   1.324  }
   1.325 -#define RGBA_FROM_RGBA8888(Pixel, r, g, b, a)				\
   1.326 -{									\
   1.327 -	r = (Pixel>>24);						\
   1.328 -	g = ((Pixel>>16)&0xFF);						\
   1.329 -	b = ((Pixel>>8)&0xFF);						\
   1.330 -	a = (Pixel&0xFF);						\
   1.331 +#define RGBA_FROM_RGBA8888(Pixel, r, g, b, a)               \
   1.332 +{                                   \
   1.333 +    r = (Pixel>>24);                        \
   1.334 +    g = ((Pixel>>16)&0xFF);                     \
   1.335 +    b = ((Pixel>>8)&0xFF);                      \
   1.336 +    a = (Pixel&0xFF);                       \
   1.337  }
   1.338 -#define RGBA_FROM_ARGB8888(Pixel, r, g, b, a)				\
   1.339 -{									\
   1.340 -	r = ((Pixel>>16)&0xFF);						\
   1.341 -	g = ((Pixel>>8)&0xFF);						\
   1.342 -	b = (Pixel&0xFF);						\
   1.343 -	a = (Pixel>>24);						\
   1.344 +#define RGBA_FROM_ARGB8888(Pixel, r, g, b, a)               \
   1.345 +{                                   \
   1.346 +    r = ((Pixel>>16)&0xFF);                     \
   1.347 +    g = ((Pixel>>8)&0xFF);                      \
   1.348 +    b = (Pixel&0xFF);                       \
   1.349 +    a = (Pixel>>24);                        \
   1.350  }
   1.351 -#define RGBA_FROM_ABGR8888(Pixel, r, g, b, a)				\
   1.352 -{									\
   1.353 -	r = (Pixel&0xFF);						\
   1.354 -	g = ((Pixel>>8)&0xFF);						\
   1.355 -	b = ((Pixel>>16)&0xFF);						\
   1.356 -	a = (Pixel>>24);						\
   1.357 +#define RGBA_FROM_ABGR8888(Pixel, r, g, b, a)               \
   1.358 +{                                   \
   1.359 +    r = (Pixel&0xFF);                       \
   1.360 +    g = ((Pixel>>8)&0xFF);                      \
   1.361 +    b = ((Pixel>>16)&0xFF);                     \
   1.362 +    a = (Pixel>>24);                        \
   1.363  }
   1.364 -#define RGBA_FROM_BGRA8888(Pixel, r, g, b, a)				\
   1.365 -{									\
   1.366 -	r = ((Pixel>>8)&0xFF);						\
   1.367 -	g = ((Pixel>>16)&0xFF);						\
   1.368 -	b = (Pixel>>24);						\
   1.369 -	a = (Pixel&0xFF);						\
   1.370 +#define RGBA_FROM_BGRA8888(Pixel, r, g, b, a)               \
   1.371 +{                                   \
   1.372 +    r = ((Pixel>>8)&0xFF);                      \
   1.373 +    g = ((Pixel>>16)&0xFF);                     \
   1.374 +    b = (Pixel>>24);                        \
   1.375 +    a = (Pixel&0xFF);                       \
   1.376  }
   1.377 -#define DISEMBLE_RGBA(buf, bpp, fmt, Pixel, r, g, b, a)			   \
   1.378 -do {									   \
   1.379 -	switch (bpp) {							   \
   1.380 -		case 2:							   \
   1.381 -			Pixel = *((Uint16 *)(buf));			   \
   1.382 -			RGBA_FROM_PIXEL(Pixel, fmt, r, g, b, a);	   \
   1.383 -		break;							   \
   1.384 -									   \
   1.385 -		case 3:	{						   \
   1.386 +#define DISEMBLE_RGBA(buf, bpp, fmt, Pixel, r, g, b, a)            \
   1.387 +do {                                       \
   1.388 +    switch (bpp) {                             \
   1.389 +        case 2:                            \
   1.390 +            Pixel = *((Uint16 *)(buf));            \
   1.391 +            RGBA_FROM_PIXEL(Pixel, fmt, r, g, b, a);       \
   1.392 +        break;                             \
   1.393 +                                       \
   1.394 +        case 3: {                          \
   1.395              Pixel = 0; \
   1.396 -                        if (SDL_BYTEORDER == SDL_LIL_ENDIAN) {		   \
   1.397 -			        r = *((buf)+fmt->Rshift/8);		   \
   1.398 -				g = *((buf)+fmt->Gshift/8);		   \
   1.399 -				b = *((buf)+fmt->Bshift/8);		   \
   1.400 -			} else {					   \
   1.401 -			        r = *((buf)+2-fmt->Rshift/8);		   \
   1.402 -				g = *((buf)+2-fmt->Gshift/8);		   \
   1.403 -				b = *((buf)+2-fmt->Bshift/8);		   \
   1.404 -			}						   \
   1.405 -			a = 0xFF;					   \
   1.406 -		}							   \
   1.407 -		break;							   \
   1.408 -									   \
   1.409 -		case 4:							   \
   1.410 -			Pixel = *((Uint32 *)(buf));			   \
   1.411 -			RGBA_FROM_PIXEL(Pixel, fmt, r, g, b, a);	   \
   1.412 -		break;							   \
   1.413 -									   \
   1.414 -		default:						   \
   1.415 -                /* stop gcc complaints */		   \
   1.416 -		        Pixel = 0;              \
   1.417 +                        if (SDL_BYTEORDER == SDL_LIL_ENDIAN) {         \
   1.418 +                    r = *((buf)+fmt->Rshift/8);        \
   1.419 +                g = *((buf)+fmt->Gshift/8);        \
   1.420 +                b = *((buf)+fmt->Bshift/8);        \
   1.421 +            } else {                       \
   1.422 +                    r = *((buf)+2-fmt->Rshift/8);          \
   1.423 +                g = *((buf)+2-fmt->Gshift/8);          \
   1.424 +                b = *((buf)+2-fmt->Bshift/8);          \
   1.425 +            }                          \
   1.426 +            a = 0xFF;                      \
   1.427 +        }                              \
   1.428 +        break;                             \
   1.429 +                                       \
   1.430 +        case 4:                            \
   1.431 +            Pixel = *((Uint32 *)(buf));            \
   1.432 +            RGBA_FROM_PIXEL(Pixel, fmt, r, g, b, a);       \
   1.433 +        break;                             \
   1.434 +                                       \
   1.435 +        default:                           \
   1.436 +                /* stop gcc complaints */          \
   1.437 +                Pixel = 0;              \
   1.438                  r = g = b = a = 0;      \
   1.439 -		break;							   \
   1.440 -	}								   \
   1.441 +        break;                             \
   1.442 +    }                                  \
   1.443  } while (0)
   1.444  
   1.445  /* FIXME: this isn't correct, especially for Alpha (maximum != 255) */
   1.446 -#define PIXEL_FROM_RGBA(Pixel, fmt, r, g, b, a)				\
   1.447 -{									\
   1.448 -	Pixel = ((r>>fmt->Rloss)<<fmt->Rshift)|				\
   1.449 -		((g>>fmt->Gloss)<<fmt->Gshift)|				\
   1.450 -		((b>>fmt->Bloss)<<fmt->Bshift)|				\
   1.451 -		((a>>fmt->Aloss)<<fmt->Ashift);				\
   1.452 +#define PIXEL_FROM_RGBA(Pixel, fmt, r, g, b, a)             \
   1.453 +{                                   \
   1.454 +    Pixel = ((r>>fmt->Rloss)<<fmt->Rshift)|             \
   1.455 +        ((g>>fmt->Gloss)<<fmt->Gshift)|             \
   1.456 +        ((b>>fmt->Bloss)<<fmt->Bshift)|             \
   1.457 +        ((a>>fmt->Aloss)<<fmt->Ashift);             \
   1.458  }
   1.459 -#define ASSEMBLE_RGBA(buf, bpp, fmt, r, g, b, a)			\
   1.460 -{									\
   1.461 -	switch (bpp) {							\
   1.462 -		case 2: {						\
   1.463 -			Uint16 Pixel;					\
   1.464 -									\
   1.465 -			PIXEL_FROM_RGBA(Pixel, fmt, r, g, b, a);	\
   1.466 -			*((Uint16 *)(buf)) = Pixel;		\
   1.467 -		}							\
   1.468 -		break;							\
   1.469 -									\
   1.470 -		case 3: {						\
   1.471 -                        if (SDL_BYTEORDER == SDL_LIL_ENDIAN) {		\
   1.472 -			        *((buf)+fmt->Rshift/8) = r;		\
   1.473 -				*((buf)+fmt->Gshift/8) = g;		\
   1.474 -				*((buf)+fmt->Bshift/8) = b;		\
   1.475 -			} else {					\
   1.476 -			        *((buf)+2-fmt->Rshift/8) = r;		\
   1.477 -				*((buf)+2-fmt->Gshift/8) = g;		\
   1.478 -				*((buf)+2-fmt->Bshift/8) = b;		\
   1.479 -			}						\
   1.480 -		}							\
   1.481 -		break;							\
   1.482 -									\
   1.483 -		case 4: {						\
   1.484 -			Uint32 Pixel;					\
   1.485 -									\
   1.486 -			PIXEL_FROM_RGBA(Pixel, fmt, r, g, b, a);	\
   1.487 -			*((Uint32 *)(buf)) = Pixel;			\
   1.488 -		}							\
   1.489 -		break;							\
   1.490 -	}								\
   1.491 +#define ASSEMBLE_RGBA(buf, bpp, fmt, r, g, b, a)            \
   1.492 +{                                   \
   1.493 +    switch (bpp) {                          \
   1.494 +        case 2: {                       \
   1.495 +            Uint16 Pixel;                   \
   1.496 +                                    \
   1.497 +            PIXEL_FROM_RGBA(Pixel, fmt, r, g, b, a);    \
   1.498 +            *((Uint16 *)(buf)) = Pixel;     \
   1.499 +        }                           \
   1.500 +        break;                          \
   1.501 +                                    \
   1.502 +        case 3: {                       \
   1.503 +                        if (SDL_BYTEORDER == SDL_LIL_ENDIAN) {      \
   1.504 +                    *((buf)+fmt->Rshift/8) = r;     \
   1.505 +                *((buf)+fmt->Gshift/8) = g;     \
   1.506 +                *((buf)+fmt->Bshift/8) = b;     \
   1.507 +            } else {                    \
   1.508 +                    *((buf)+2-fmt->Rshift/8) = r;       \
   1.509 +                *((buf)+2-fmt->Gshift/8) = g;       \
   1.510 +                *((buf)+2-fmt->Bshift/8) = b;       \
   1.511 +            }                       \
   1.512 +        }                           \
   1.513 +        break;                          \
   1.514 +                                    \
   1.515 +        case 4: {                       \
   1.516 +            Uint32 Pixel;                   \
   1.517 +                                    \
   1.518 +            PIXEL_FROM_RGBA(Pixel, fmt, r, g, b, a);    \
   1.519 +            *((Uint32 *)(buf)) = Pixel;         \
   1.520 +        }                           \
   1.521 +        break;                          \
   1.522 +    }                               \
   1.523  }
   1.524  
   1.525  /* Blend the RGB values of two Pixels based on a source alpha value */
   1.526 -#define ALPHA_BLEND(sR, sG, sB, A, dR, dG, dB)	\
   1.527 -do {						\
   1.528 -	dR = ((((int)(sR-dR)*(int)A)/255)+dR);	\
   1.529 -	dG = ((((int)(sG-dG)*(int)A)/255)+dG);	\
   1.530 -	dB = ((((int)(sB-dB)*(int)A)/255)+dB);	\
   1.531 +#define ALPHA_BLEND(sR, sG, sB, A, dR, dG, dB)  \
   1.532 +do {                        \
   1.533 +    dR = ((((int)(sR-dR)*(int)A)/255)+dR);  \
   1.534 +    dG = ((((int)(sG-dG)*(int)A)/255)+dG);  \
   1.535 +    dB = ((((int)(sB-dB)*(int)A)/255)+dB);  \
   1.536  } while(0)
   1.537  
   1.538  
   1.539 @@ -413,75 +413,75 @@
   1.540  #ifdef USE_DUFFS_LOOP
   1.541  
   1.542  /* 8-times unrolled loop */
   1.543 -#define DUFFS_LOOP8(pixel_copy_increment, width)			\
   1.544 -{ int n = (width+7)/8;							\
   1.545 -	switch (width & 7) {						\
   1.546 -	case 0: do {	pixel_copy_increment;				\
   1.547 -	case 7:		pixel_copy_increment;				\
   1.548 -	case 6:		pixel_copy_increment;				\
   1.549 -	case 5:		pixel_copy_increment;				\
   1.550 -	case 4:		pixel_copy_increment;				\
   1.551 -	case 3:		pixel_copy_increment;				\
   1.552 -	case 2:		pixel_copy_increment;				\
   1.553 -	case 1:		pixel_copy_increment;				\
   1.554 -		} while ( --n > 0 );					\
   1.555 -	}								\
   1.556 +#define DUFFS_LOOP8(pixel_copy_increment, width)            \
   1.557 +{ int n = (width+7)/8;                          \
   1.558 +    switch (width & 7) {                        \
   1.559 +    case 0: do {    pixel_copy_increment;               \
   1.560 +    case 7:     pixel_copy_increment;               \
   1.561 +    case 6:     pixel_copy_increment;               \
   1.562 +    case 5:     pixel_copy_increment;               \
   1.563 +    case 4:     pixel_copy_increment;               \
   1.564 +    case 3:     pixel_copy_increment;               \
   1.565 +    case 2:     pixel_copy_increment;               \
   1.566 +    case 1:     pixel_copy_increment;               \
   1.567 +        } while ( --n > 0 );                    \
   1.568 +    }                               \
   1.569  }
   1.570  
   1.571  /* 4-times unrolled loop */
   1.572 -#define DUFFS_LOOP4(pixel_copy_increment, width)			\
   1.573 -{ int n = (width+3)/4;							\
   1.574 -	switch (width & 3) {						\
   1.575 -	case 0: do {	pixel_copy_increment;				\
   1.576 -	case 3:		pixel_copy_increment;				\
   1.577 -	case 2:		pixel_copy_increment;				\
   1.578 -	case 1:		pixel_copy_increment;				\
   1.579 -		} while (--n > 0);					\
   1.580 -	}								\
   1.581 +#define DUFFS_LOOP4(pixel_copy_increment, width)            \
   1.582 +{ int n = (width+3)/4;                          \
   1.583 +    switch (width & 3) {                        \
   1.584 +    case 0: do {    pixel_copy_increment;               \
   1.585 +    case 3:     pixel_copy_increment;               \
   1.586 +    case 2:     pixel_copy_increment;               \
   1.587 +    case 1:     pixel_copy_increment;               \
   1.588 +        } while (--n > 0);                  \
   1.589 +    }                               \
   1.590  }
   1.591  
   1.592  /* Use the 8-times version of the loop by default */
   1.593 -#define DUFFS_LOOP(pixel_copy_increment, width)				\
   1.594 -	DUFFS_LOOP8(pixel_copy_increment, width)
   1.595 +#define DUFFS_LOOP(pixel_copy_increment, width)             \
   1.596 +    DUFFS_LOOP8(pixel_copy_increment, width)
   1.597  
   1.598  /* Special version of Duff's device for even more optimization */
   1.599 -#define DUFFS_LOOP_124(pixel_copy_increment1,				\
   1.600 -                       pixel_copy_increment2,				\
   1.601 -                       pixel_copy_increment4, width)			\
   1.602 -{ int n = width;							\
   1.603 -	if (n & 1) {							\
   1.604 -		pixel_copy_increment1; n -= 1;				\
   1.605 -	}								\
   1.606 -	if (n & 2) {							\
   1.607 -		pixel_copy_increment2; n -= 2;				\
   1.608 -	}								\
   1.609 -	if (n) {							\
   1.610 -		n = (n+7)/ 8;						\
   1.611 -		switch (n & 4) {					\
   1.612 -		case 0: do {	pixel_copy_increment4;			\
   1.613 -		case 4:		pixel_copy_increment4;			\
   1.614 -			} while (--n > 0);				\
   1.615 -		}							\
   1.616 -	}								\
   1.617 +#define DUFFS_LOOP_124(pixel_copy_increment1,               \
   1.618 +                       pixel_copy_increment2,               \
   1.619 +                       pixel_copy_increment4, width)            \
   1.620 +{ int n = width;                            \
   1.621 +    if (n & 1) {                            \
   1.622 +        pixel_copy_increment1; n -= 1;              \
   1.623 +    }                               \
   1.624 +    if (n & 2) {                            \
   1.625 +        pixel_copy_increment2; n -= 2;              \
   1.626 +    }                               \
   1.627 +    if (n) {                            \
   1.628 +        n = (n+7)/ 8;                       \
   1.629 +        switch (n & 4) {                    \
   1.630 +        case 0: do {    pixel_copy_increment4;          \
   1.631 +        case 4:     pixel_copy_increment4;          \
   1.632 +            } while (--n > 0);              \
   1.633 +        }                           \
   1.634 +    }                               \
   1.635  }
   1.636  
   1.637  #else
   1.638  
   1.639  /* Don't use Duff's device to unroll loops */
   1.640 -#define DUFFS_LOOP(pixel_copy_increment, width)				\
   1.641 -{ int n;								\
   1.642 -	for ( n=width; n > 0; --n ) {					\
   1.643 -		pixel_copy_increment;					\
   1.644 -	}								\
   1.645 +#define DUFFS_LOOP(pixel_copy_increment, width)             \
   1.646 +{ int n;                                \
   1.647 +    for ( n=width; n > 0; --n ) {                   \
   1.648 +        pixel_copy_increment;                   \
   1.649 +    }                               \
   1.650  }
   1.651 -#define DUFFS_LOOP8(pixel_copy_increment, width)			\
   1.652 -	DUFFS_LOOP(pixel_copy_increment, width)
   1.653 -#define DUFFS_LOOP4(pixel_copy_increment, width)			\
   1.654 -	DUFFS_LOOP(pixel_copy_increment, width)
   1.655 -#define DUFFS_LOOP_124(pixel_copy_increment1,				\
   1.656 -                       pixel_copy_increment2,				\
   1.657 -                       pixel_copy_increment4, width)			\
   1.658 -	DUFFS_LOOP(pixel_copy_increment1, width)
   1.659 +#define DUFFS_LOOP8(pixel_copy_increment, width)            \
   1.660 +    DUFFS_LOOP(pixel_copy_increment, width)
   1.661 +#define DUFFS_LOOP4(pixel_copy_increment, width)            \
   1.662 +    DUFFS_LOOP(pixel_copy_increment, width)
   1.663 +#define DUFFS_LOOP_124(pixel_copy_increment1,               \
   1.664 +                       pixel_copy_increment2,               \
   1.665 +                       pixel_copy_increment4, width)            \
   1.666 +    DUFFS_LOOP(pixel_copy_increment1, width)
   1.667  
   1.668  #endif /* USE_DUFFS_LOOP */
   1.669