Added 8-bit RGB source surface support to NtoN blitters
authorSam Lantinga <slouken@libsdl.org>
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 +#define BGRA8888_FROM_RGBA(Pixel, r, g, b, a)                           \
   1.237 +{                                                                       \
   1.238 +    Pixel = (b<<24)|(g<<16)|(r<<8)|a;                                   \
   1.239  }
   1.240 -#define ASSEMBLE_RGB(buf, bpp, fmt, r, g, b)                \
   1.241 -{                                   \
   1.242 -    switch (bpp) {                          \
   1.243 -        case 2: {                       \
   1.244 -            Uint16 Pixel;                   \
   1.245 -                                    \
   1.246 -            PIXEL_FROM_RGB(Pixel, fmt, r, g, b);        \
   1.247 -            *((Uint16 *)(buf)) = Pixel;     \
   1.248 -        }                           \
   1.249 -        break;                          \
   1.250 -                                    \
   1.251 -        case 3: {                       \
   1.252 -                        if (SDL_BYTEORDER == SDL_LIL_ENDIAN) {      \
   1.253 -                    *((buf)+fmt->Rshift/8) = r;     \
   1.254 -                *((buf)+fmt->Gshift/8) = g;     \
   1.255 -                *((buf)+fmt->Bshift/8) = b;     \
   1.256 -            } else {                    \
   1.257 -                    *((buf)+2-fmt->Rshift/8) = r;       \
   1.258 -                *((buf)+2-fmt->Gshift/8) = g;       \
   1.259 -                *((buf)+2-fmt->Bshift/8) = b;       \
   1.260 -            }                       \
   1.261 -        }                           \
   1.262 -        break;                          \
   1.263 -                                    \
   1.264 -        case 4: {                       \
   1.265 -            Uint32 Pixel;                   \
   1.266 -                                    \
   1.267 -            PIXEL_FROM_RGB(Pixel, fmt, r, g, b);        \
   1.268 -            *((Uint32 *)(buf)) = Pixel;         \
   1.269 -        }                           \
   1.270 -        break;                          \
   1.271 -    }                               \
   1.272 +#define ASSEMBLE_RGB(buf, bpp, fmt, r, g, b)                            \
   1.273 +{                                                                       \
   1.274 +    switch (bpp) {                                                      \
   1.275 +        case 1: {                                                       \
   1.276 +            Uint8 Pixel;                                                \
   1.277 +                                                                        \
   1.278 +            PIXEL_FROM_RGB(Pixel, fmt, r, g, b);                        \
   1.279 +            *((Uint8 *)(buf)) = Pixel;                                  \
   1.280 +        }                                                               \
   1.281 +        break;                                                          \
   1.282 +                                                                        \
   1.283 +        case 2: {                                                       \
   1.284 +            Uint16 Pixel;                                               \
   1.285 +                                                                        \
   1.286 +            PIXEL_FROM_RGB(Pixel, fmt, r, g, b);                        \
   1.287 +            *((Uint16 *)(buf)) = Pixel;                                 \
   1.288 +        }                                                               \
   1.289 +        break;                                                          \
   1.290 +                                                                        \
   1.291 +        case 3: {                                                       \
   1.292 +            if (SDL_BYTEORDER == SDL_LIL_ENDIAN) {                      \
   1.293 +                *((buf)+fmt->Rshift/8) = r;                             \
   1.294 +                *((buf)+fmt->Gshift/8) = g;                             \
   1.295 +                *((buf)+fmt->Bshift/8) = b;                             \
   1.296 +            } else {                                                    \
   1.297 +                *((buf)+2-fmt->Rshift/8) = r;                           \
   1.298 +                *((buf)+2-fmt->Gshift/8) = g;                           \
   1.299 +                *((buf)+2-fmt->Bshift/8) = b;                           \
   1.300 +            }                                                           \
   1.301 +        }                                                               \
   1.302 +        break;                                                          \
   1.303 +                                                                        \
   1.304 +        case 4: {                                                       \
   1.305 +            Uint32 Pixel;                                               \
   1.306 +                                                                        \
   1.307 +            PIXEL_FROM_RGB(Pixel, fmt, r, g, b);                        \
   1.308 +            *((Uint32 *)(buf)) = Pixel;                                 \
   1.309 +        }                                                               \
   1.310 +        break;                                                          \
   1.311 +    }                                                                   \
   1.312  }
   1.313  
   1.314  /* FIXME: Should we rescale alpha into 0..255 here? */
   1.315 -#define RGBA_FROM_PIXEL(Pixel, fmt, r, g, b, a)             \
   1.316 -{                                   \
   1.317 +#define RGBA_FROM_PIXEL(Pixel, fmt, r, g, b, a)                         \
   1.318 +{                                                                       \
   1.319      r = SDL_expand_byte[fmt->Rloss][((Pixel&fmt->Rmask)>>fmt->Rshift)]; \
   1.320      g = SDL_expand_byte[fmt->Gloss][((Pixel&fmt->Gmask)>>fmt->Gshift)]; \
   1.321      b = SDL_expand_byte[fmt->Bloss][((Pixel&fmt->Bmask)>>fmt->Bshift)]; \
   1.322      a = SDL_expand_byte[fmt->Aloss][((Pixel&fmt->Amask)>>fmt->Ashift)]; \
   1.323  }
   1.324 -#define RGBA_FROM_8888(Pixel, fmt, r, g, b, a)  \
   1.325 -{                       \
   1.326 -    r = (Pixel&fmt->Rmask)>>fmt->Rshift;    \
   1.327 -    g = (Pixel&fmt->Gmask)>>fmt->Gshift;    \
   1.328 -    b = (Pixel&fmt->Bmask)>>fmt->Bshift;    \
   1.329 -    a = (Pixel&fmt->Amask)>>fmt->Ashift;    \
   1.330 +#define RGBA_FROM_8888(Pixel, fmt, r, g, b, a)                          \
   1.331 +{                                                                       \
   1.332 +    r = (Pixel&fmt->Rmask)>>fmt->Rshift;                                \
   1.333 +    g = (Pixel&fmt->Gmask)>>fmt->Gshift;                                \
   1.334 +    b = (Pixel&fmt->Bmask)>>fmt->Bshift;                                \
   1.335 +    a = (Pixel&fmt->Amask)>>fmt->Ashift;                                \
   1.336  }
   1.337 -#define RGBA_FROM_RGBA8888(Pixel, r, g, b, a)               \
   1.338 -{                                   \
   1.339 -    r = (Pixel>>24);                        \
   1.340 -    g = ((Pixel>>16)&0xFF);                     \
   1.341 -    b = ((Pixel>>8)&0xFF);                      \
   1.342 -    a = (Pixel&0xFF);                       \
   1.343 +#define RGBA_FROM_RGBA8888(Pixel, r, g, b, a)                           \
   1.344 +{                                                                       \
   1.345 +    r = (Pixel>>24);                                                    \
   1.346 +    g = ((Pixel>>16)&0xFF);                                             \
   1.347 +    b = ((Pixel>>8)&0xFF);                                              \
   1.348 +    a = (Pixel&0xFF);                                                   \
   1.349  }
   1.350 -#define RGBA_FROM_ARGB8888(Pixel, r, g, b, a)               \
   1.351 -{                                   \
   1.352 -    r = ((Pixel>>16)&0xFF);                     \
   1.353 -    g = ((Pixel>>8)&0xFF);                      \
   1.354 -    b = (Pixel&0xFF);                       \
   1.355 -    a = (Pixel>>24);                        \
   1.356 +#define RGBA_FROM_ARGB8888(Pixel, r, g, b, a)                           \
   1.357 +{                                                                       \
   1.358 +    r = ((Pixel>>16)&0xFF);                                             \
   1.359 +    g = ((Pixel>>8)&0xFF);                                              \
   1.360 +    b = (Pixel&0xFF);                                                   \
   1.361 +    a = (Pixel>>24);                                                    \
   1.362  }
   1.363 -#define RGBA_FROM_ABGR8888(Pixel, r, g, b, a)               \
   1.364 -{                                   \
   1.365 -    r = (Pixel&0xFF);                       \
   1.366 -    g = ((Pixel>>8)&0xFF);                      \
   1.367 -    b = ((Pixel>>16)&0xFF);                     \
   1.368 -    a = (Pixel>>24);                        \
   1.369 +#define RGBA_FROM_ABGR8888(Pixel, r, g, b, a)                           \
   1.370 +{                                                                       \
   1.371 +    r = (Pixel&0xFF);                                                   \
   1.372 +    g = ((Pixel>>8)&0xFF);                                              \
   1.373 +    b = ((Pixel>>16)&0xFF);                                             \
   1.374 +    a = (Pixel>>24);                                                    \
   1.375  }
   1.376 -#define RGBA_FROM_BGRA8888(Pixel, r, g, b, a)               \
   1.377 -{                                   \
   1.378 -    r = ((Pixel>>8)&0xFF);                      \
   1.379 -    g = ((Pixel>>16)&0xFF);                     \
   1.380 -    b = (Pixel>>24);                        \
   1.381 -    a = (Pixel&0xFF);                       \
   1.382 +#define RGBA_FROM_BGRA8888(Pixel, r, g, b, a)                           \
   1.383 +{                                                                       \
   1.384 +    r = ((Pixel>>8)&0xFF);                                              \
   1.385 +    g = ((Pixel>>16)&0xFF);                                             \
   1.386 +    b = (Pixel>>24);                                                    \
   1.387 +    a = (Pixel&0xFF);                                                   \
   1.388  }
   1.389 -#define DISEMBLE_RGBA(buf, bpp, fmt, Pixel, r, g, b, a)            \
   1.390 -do {                                       \
   1.391 -    switch (bpp) {                             \
   1.392 -        case 2:                            \
   1.393 -            Pixel = *((Uint16 *)(buf));            \
   1.394 -            RGBA_FROM_PIXEL(Pixel, fmt, r, g, b, a);       \
   1.395 -        break;                             \
   1.396 -                                       \
   1.397 -        case 3: {                          \
   1.398 -            Pixel = 0; \
   1.399 -                        if (SDL_BYTEORDER == SDL_LIL_ENDIAN) {         \
   1.400 -                    r = *((buf)+fmt->Rshift/8);        \
   1.401 -                g = *((buf)+fmt->Gshift/8);        \
   1.402 -                b = *((buf)+fmt->Bshift/8);        \
   1.403 -            } else {                       \
   1.404 -                    r = *((buf)+2-fmt->Rshift/8);          \
   1.405 -                g = *((buf)+2-fmt->Gshift/8);          \
   1.406 -                b = *((buf)+2-fmt->Bshift/8);          \
   1.407 -            }                          \
   1.408 -            a = 0xFF;                      \
   1.409 -        }                              \
   1.410 -        break;                             \
   1.411 -                                       \
   1.412 -        case 4:                            \
   1.413 -            Pixel = *((Uint32 *)(buf));            \
   1.414 -            RGBA_FROM_PIXEL(Pixel, fmt, r, g, b, a);       \
   1.415 -        break;                             \
   1.416 -                                       \
   1.417 -        default:                           \
   1.418 -                /* stop gcc complaints */          \
   1.419 -                Pixel = 0;              \
   1.420 -                r = g = b = a = 0;      \
   1.421 -        break;                             \
   1.422 -    }                                  \
   1.423 +#define DISEMBLE_RGBA(buf, bpp, fmt, Pixel, r, g, b, a)                 \
   1.424 +do {                                                                    \
   1.425 +    switch (bpp) {                                                      \
   1.426 +        case 1:                                                         \
   1.427 +            Pixel = *((Uint8 *)(buf));                                  \
   1.428 +            RGBA_FROM_PIXEL(Pixel, fmt, r, g, b, a);                    \
   1.429 +        break;                                                          \
   1.430 +                                                                        \
   1.431 +        case 2:                                                         \
   1.432 +            Pixel = *((Uint16 *)(buf));                                 \
   1.433 +            RGBA_FROM_PIXEL(Pixel, fmt, r, g, b, a);                    \
   1.434 +        break;                                                          \
   1.435 +                                                                        \
   1.436 +        case 3: {                                                       \
   1.437 +            Pixel = 0;                                                  \
   1.438 +            if (SDL_BYTEORDER == SDL_LIL_ENDIAN) {                      \
   1.439 +                r = *((buf)+fmt->Rshift/8);                             \
   1.440 +                g = *((buf)+fmt->Gshift/8);                             \
   1.441 +                b = *((buf)+fmt->Bshift/8);                             \
   1.442 +            } else {                                                    \
   1.443 +                r = *((buf)+2-fmt->Rshift/8);                           \
   1.444 +                g = *((buf)+2-fmt->Gshift/8);                           \
   1.445 +                b = *((buf)+2-fmt->Bshift/8);                           \
   1.446 +            }                                                           \
   1.447 +            a = 0xFF;                                                   \
   1.448 +        }                                                               \
   1.449 +        break;                                                          \
   1.450 +                                                                        \
   1.451 +        case 4:                                                         \
   1.452 +            Pixel = *((Uint32 *)(buf));                                 \
   1.453 +            RGBA_FROM_PIXEL(Pixel, fmt, r, g, b, a);                    \
   1.454 +        break;                                                          \
   1.455 +                                                                        \
   1.456 +        default:                                                        \
   1.457 +            /* stop gcc complaints */                                   \
   1.458 +            Pixel = 0;                                                  \
   1.459 +            r = g = b = a = 0;                                          \
   1.460 +        break;                                                          \
   1.461 +    }                                                                   \
   1.462  } while (0)
   1.463  
   1.464  /* FIXME: this isn't correct, especially for Alpha (maximum != 255) */
   1.465 -#define PIXEL_FROM_RGBA(Pixel, fmt, r, g, b, a)             \
   1.466 -{                                   \
   1.467 -    Pixel = ((r>>fmt->Rloss)<<fmt->Rshift)|             \
   1.468 -        ((g>>fmt->Gloss)<<fmt->Gshift)|             \
   1.469 -        ((b>>fmt->Bloss)<<fmt->Bshift)|             \
   1.470 -        ((a>>fmt->Aloss)<<fmt->Ashift);             \
   1.471 +#define PIXEL_FROM_RGBA(Pixel, fmt, r, g, b, a)                         \
   1.472 +{                                                                       \
   1.473 +    Pixel = ((r>>fmt->Rloss)<<fmt->Rshift)|                             \
   1.474 +        ((g>>fmt->Gloss)<<fmt->Gshift)|                                 \
   1.475 +        ((b>>fmt->Bloss)<<fmt->Bshift)|                                 \
   1.476 +        ((a>>fmt->Aloss)<<fmt->Ashift);                                 \
   1.477  }
   1.478 -#define ASSEMBLE_RGBA(buf, bpp, fmt, r, g, b, a)            \
   1.479 -{                                   \
   1.480 -    switch (bpp) {                          \
   1.481 -        case 2: {                       \
   1.482 -            Uint16 Pixel;                   \
   1.483 -                                    \
   1.484 -            PIXEL_FROM_RGBA(Pixel, fmt, r, g, b, a);    \
   1.485 -            *((Uint16 *)(buf)) = Pixel;     \
   1.486 -        }                           \
   1.487 -        break;                          \
   1.488 -                                    \
   1.489 -        case 3: {                       \
   1.490 -                        if (SDL_BYTEORDER == SDL_LIL_ENDIAN) {      \
   1.491 -                    *((buf)+fmt->Rshift/8) = r;     \
   1.492 -                *((buf)+fmt->Gshift/8) = g;     \
   1.493 -                *((buf)+fmt->Bshift/8) = b;     \
   1.494 -            } else {                    \
   1.495 -                    *((buf)+2-fmt->Rshift/8) = r;       \
   1.496 -                *((buf)+2-fmt->Gshift/8) = g;       \
   1.497 -                *((buf)+2-fmt->Bshift/8) = b;       \
   1.498 -            }                       \
   1.499 -        }                           \
   1.500 -        break;                          \
   1.501 -                                    \
   1.502 -        case 4: {                       \
   1.503 -            Uint32 Pixel;                   \
   1.504 -                                    \
   1.505 -            PIXEL_FROM_RGBA(Pixel, fmt, r, g, b, a);    \
   1.506 -            *((Uint32 *)(buf)) = Pixel;         \
   1.507 -        }                           \
   1.508 -        break;                          \
   1.509 -    }                               \
   1.510 +#define ASSEMBLE_RGBA(buf, bpp, fmt, r, g, b, a)                        \
   1.511 +{                                                                       \
   1.512 +    switch (bpp) {                                                      \
   1.513 +        case 1: {                                                       \
   1.514 +            Uint8 Pixel;                                                \
   1.515 +                                                                        \
   1.516 +            PIXEL_FROM_RGBA(Pixel, fmt, r, g, b, a);                    \
   1.517 +            *((Uint8 *)(buf)) = Pixel;                                  \
   1.518 +        }                                                               \
   1.519 +        break;                                                          \
   1.520 +                                                                        \
   1.521 +        case 2: {                                                       \
   1.522 +            Uint16 Pixel;                                               \
   1.523 +                                                                        \
   1.524 +            PIXEL_FROM_RGBA(Pixel, fmt, r, g, b, a);                    \
   1.525 +            *((Uint16 *)(buf)) = Pixel;                                 \
   1.526 +        }                                                               \
   1.527 +        break;                                                          \
   1.528 +                                                                        \
   1.529 +        case 3: {                                                       \
   1.530 +            if (SDL_BYTEORDER == SDL_LIL_ENDIAN) {                      \
   1.531 +                *((buf)+fmt->Rshift/8) = r;                             \
   1.532 +                *((buf)+fmt->Gshift/8) = g;                             \
   1.533 +                *((buf)+fmt->Bshift/8) = b;                             \
   1.534 +            } else {                                                    \
   1.535 +                *((buf)+2-fmt->Rshift/8) = r;                           \
   1.536 +                *((buf)+2-fmt->Gshift/8) = g;                           \
   1.537 +                *((buf)+2-fmt->Bshift/8) = b;                           \
   1.538 +            }                                                           \
   1.539 +        }                                                               \
   1.540 +        break;                                                          \
   1.541 +                                                                        \
   1.542 +        case 4: {                                                       \
   1.543 +            Uint32 Pixel;                                               \
   1.544 +                                                                        \
   1.545 +            PIXEL_FROM_RGBA(Pixel, fmt, r, g, b, a);                    \
   1.546 +            *((Uint32 *)(buf)) = Pixel;                                 \
   1.547 +        }                                                               \
   1.548 +        break;                                                          \
   1.549 +    }                                                                   \
   1.550  }
   1.551  
   1.552  /* Blend the RGB values of two Pixels based on a source alpha value */
   1.553 -#define ALPHA_BLEND(sR, sG, sB, A, dR, dG, dB)  \
   1.554 -do {                        \
   1.555 -    dR = ((((int)(sR-dR)*(int)A)/255)+dR);  \
   1.556 -    dG = ((((int)(sG-dG)*(int)A)/255)+dG);  \
   1.557 -    dB = ((((int)(sB-dB)*(int)A)/255)+dB);  \
   1.558 +#define ALPHA_BLEND(sR, sG, sB, A, dR, dG, dB)                          \
   1.559 +do {                                                                    \
   1.560 +    dR = ((((int)(sR-dR)*(int)A)/255)+dR);                              \
   1.561 +    dG = ((((int)(sG-dG)*(int)A)/255)+dG);                              \
   1.562 +    dB = ((((int)(sB-dB)*(int)A)/255)+dB);                              \
   1.563  } while(0)
   1.564  
   1.565  
   1.566 @@ -413,74 +443,74 @@
   1.567  #ifdef USE_DUFFS_LOOP
   1.568  
   1.569  /* 8-times unrolled loop */
   1.570 -#define DUFFS_LOOP8(pixel_copy_increment, width)            \
   1.571 -{ int n = (width+7)/8;                          \
   1.572 -    switch (width & 7) {                        \
   1.573 -    case 0: do {    pixel_copy_increment;               \
   1.574 -    case 7:     pixel_copy_increment;               \
   1.575 -    case 6:     pixel_copy_increment;               \
   1.576 -    case 5:     pixel_copy_increment;               \
   1.577 -    case 4:     pixel_copy_increment;               \
   1.578 -    case 3:     pixel_copy_increment;               \
   1.579 -    case 2:     pixel_copy_increment;               \
   1.580 -    case 1:     pixel_copy_increment;               \
   1.581 -        } while ( --n > 0 );                    \
   1.582 -    }                               \
   1.583 +#define DUFFS_LOOP8(pixel_copy_increment, width)                        \
   1.584 +{ int n = (width+7)/8;                                                  \
   1.585 +    switch (width & 7) {                                                \
   1.586 +    case 0: do {    pixel_copy_increment;                               \
   1.587 +    case 7:     pixel_copy_increment;                                   \
   1.588 +    case 6:     pixel_copy_increment;                                   \
   1.589 +    case 5:     pixel_copy_increment;                                   \
   1.590 +    case 4:     pixel_copy_increment;                                   \
   1.591 +    case 3:     pixel_copy_increment;                                   \
   1.592 +    case 2:     pixel_copy_increment;                                   \
   1.593 +    case 1:     pixel_copy_increment;                                   \
   1.594 +        } while ( --n > 0 );                                            \
   1.595 +    }                                                                   \
   1.596  }
   1.597  
   1.598  /* 4-times unrolled loop */
   1.599 -#define DUFFS_LOOP4(pixel_copy_increment, width)            \
   1.600 -{ int n = (width+3)/4;                          \
   1.601 -    switch (width & 3) {                        \
   1.602 -    case 0: do {    pixel_copy_increment;               \
   1.603 -    case 3:     pixel_copy_increment;               \
   1.604 -    case 2:     pixel_copy_increment;               \
   1.605 -    case 1:     pixel_copy_increment;               \
   1.606 -        } while (--n > 0);                  \
   1.607 -    }                               \
   1.608 +#define DUFFS_LOOP4(pixel_copy_increment, width)                        \
   1.609 +{ int n = (width+3)/4;                                                  \
   1.610 +    switch (width & 3) {                                                \
   1.611 +    case 0: do {    pixel_copy_increment;                               \
   1.612 +    case 3:     pixel_copy_increment;                                   \
   1.613 +    case 2:     pixel_copy_increment;                                   \
   1.614 +    case 1:     pixel_copy_increment;                                   \
   1.615 +        } while (--n > 0);                                              \
   1.616 +    }                                                                   \
   1.617  }
   1.618  
   1.619  /* Use the 8-times version of the loop by default */
   1.620 -#define DUFFS_LOOP(pixel_copy_increment, width)             \
   1.621 +#define DUFFS_LOOP(pixel_copy_increment, width)                         \
   1.622      DUFFS_LOOP8(pixel_copy_increment, width)
   1.623  
   1.624  /* Special version of Duff's device for even more optimization */
   1.625 -#define DUFFS_LOOP_124(pixel_copy_increment1,               \
   1.626 -                       pixel_copy_increment2,               \
   1.627 -                       pixel_copy_increment4, width)            \
   1.628 -{ int n = width;                            \
   1.629 -    if (n & 1) {                            \
   1.630 -        pixel_copy_increment1; n -= 1;              \
   1.631 -    }                               \
   1.632 -    if (n & 2) {                            \
   1.633 -        pixel_copy_increment2; n -= 2;              \
   1.634 -    }                               \
   1.635 -    if (n) {                            \
   1.636 -        n = (n+7)/ 8;                       \
   1.637 -        switch (n & 4) {                    \
   1.638 -        case 0: do {    pixel_copy_increment4;          \
   1.639 -        case 4:     pixel_copy_increment4;          \
   1.640 -            } while (--n > 0);              \
   1.641 -        }                           \
   1.642 -    }                               \
   1.643 +#define DUFFS_LOOP_124(pixel_copy_increment1,                           \
   1.644 +                       pixel_copy_increment2,                           \
   1.645 +                       pixel_copy_increment4, width)                    \
   1.646 +{ int n = width;                                                        \
   1.647 +    if (n & 1) {                                                        \
   1.648 +        pixel_copy_increment1; n -= 1;                                  \
   1.649 +    }                                                                   \
   1.650 +    if (n & 2) {                                                        \
   1.651 +        pixel_copy_increment2; n -= 2;                                  \
   1.652 +    }                                                                   \
   1.653 +    if (n) {                                                            \
   1.654 +        n = (n+7)/ 8;                                                   \
   1.655 +        switch (n & 4) {                                                \
   1.656 +        case 0: do {    pixel_copy_increment4;                          \
   1.657 +        case 4:     pixel_copy_increment4;                              \
   1.658 +            } while (--n > 0);                                          \
   1.659 +        }                                                               \
   1.660 +    }                                                                   \
   1.661  }
   1.662  
   1.663  #else
   1.664  
   1.665  /* Don't use Duff's device to unroll loops */
   1.666 -#define DUFFS_LOOP(pixel_copy_increment, width)             \
   1.667 -{ int n;                                \
   1.668 -    for ( n=width; n > 0; --n ) {                   \
   1.669 -        pixel_copy_increment;                   \
   1.670 -    }                               \
   1.671 +#define DUFFS_LOOP(pixel_copy_increment, width)                         \
   1.672 +{ int n;                                                                \
   1.673 +    for ( n=width; n > 0; --n ) {                                       \
   1.674 +        pixel_copy_increment;                                           \
   1.675 +    }                                                                   \
   1.676  }
   1.677 -#define DUFFS_LOOP8(pixel_copy_increment, width)            \
   1.678 +#define DUFFS_LOOP8(pixel_copy_increment, width)                        \
   1.679      DUFFS_LOOP(pixel_copy_increment, width)
   1.680 -#define DUFFS_LOOP4(pixel_copy_increment, width)            \
   1.681 +#define DUFFS_LOOP4(pixel_copy_increment, width)                        \
   1.682      DUFFS_LOOP(pixel_copy_increment, width)
   1.683 -#define DUFFS_LOOP_124(pixel_copy_increment1,               \
   1.684 -                       pixel_copy_increment2,               \
   1.685 -                       pixel_copy_increment4, width)            \
   1.686 +#define DUFFS_LOOP_124(pixel_copy_increment1,                           \
   1.687 +                       pixel_copy_increment2,                           \
   1.688 +                       pixel_copy_increment4, width)                    \
   1.689      DUFFS_LOOP(pixel_copy_increment1, width)
   1.690  
   1.691  #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[] = {