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