Updated blend semantics so blending uses the following formula:
authorSam Lantinga <slouken@libsdl.org>
Tue, 23 Jul 2013 08:06:49 -0700
changeset 75026ff02ff3cf06
parent 7501 b27825bb5879
child 7503 701f4a25df89
Updated blend semantics so blending uses the following formula:
dstRGB = (srcRGB * srcA) + (dstRGB * (1-srcA))
dstA = srcA + (dstA * (1-srcA))
This allows proper compositing semantics without requiring premultiplied alpha.

Needs full unit test coverage and bug fixes!
include/SDL_blendmode.h
include/SDL_surface.h
src/render/direct3d/SDL_render_d3d.c
src/render/opengl/SDL_glfuncs.h
src/render/opengl/SDL_render_gl.c
src/render/opengles/SDL_glesfuncs.h
src/render/opengles/SDL_render_gles.c
src/render/opengles2/SDL_gles2funcs.h
src/render/opengles2/SDL_render_gles2.c
src/video/SDL_blit.h
src/video/SDL_blit_0.c
src/video/SDL_blit_1.c
src/video/SDL_blit_A.c
src/video/SDL_blit_auto.c
src/video/sdlgenblit.pl
test/testrendertarget.c
test/testsprite2.c
     1.1 --- a/include/SDL_blendmode.h	Mon Jul 22 02:51:45 2013 -0700
     1.2 +++ b/include/SDL_blendmode.h	Tue Jul 23 08:06:49 2013 -0700
     1.3 @@ -39,10 +39,17 @@
     1.4   */
     1.5  typedef enum
     1.6  {
     1.7 -    SDL_BLENDMODE_NONE = 0x00000000,     /**< No blending */
     1.8 -    SDL_BLENDMODE_BLEND = 0x00000001,    /**< dst = (src * A) + (dst * (1-A)) */
     1.9 -    SDL_BLENDMODE_ADD = 0x00000002,      /**< dst = (src * A) + dst */
    1.10 -    SDL_BLENDMODE_MOD = 0x00000004       /**< dst = src * dst */
    1.11 +    SDL_BLENDMODE_NONE = 0x00000000,     /**< no blending
    1.12 +                                              dstRGBA = srcRGBA */
    1.13 +    SDL_BLENDMODE_BLEND = 0x00000001,    /**< alpha blending
    1.14 +                                              dstRGB = (srcRGB * srcA) + (dstRGB * (1-srcA))
    1.15 +                                              dstA = srcA + (dstA * (1-srcA)) */
    1.16 +    SDL_BLENDMODE_ADD = 0x00000002,      /**< additive blending
    1.17 +                                              dstRGB = (srcRGB * srcA) + dstRGB
    1.18 +                                              dstA = dstA */
    1.19 +    SDL_BLENDMODE_MOD = 0x00000004       /**< color modulate
    1.20 +                                              dstRGB = srcRGB * dstRGB
    1.21 +                                              dstA = dstA */
    1.22  } SDL_BlendMode;
    1.23  
    1.24  /* Ends C function definitions when using C++ */
     2.1 --- a/include/SDL_surface.h	Mon Jul 22 02:51:45 2013 -0700
     2.2 +++ b/include/SDL_surface.h	Tue Jul 23 08:06:49 2013 -0700
     2.3 @@ -399,44 +399,42 @@
     2.4   *
     2.5   *  The blit function should not be called on a locked surface.
     2.6   *
     2.7 - *  The blit semantics for surfaces with and without alpha and colorkey
     2.8 + *  The blit semantics for surfaces with and without blending and colorkey
     2.9   *  are defined as follows:
    2.10   *  \verbatim
    2.11      RGBA->RGB:
    2.12 -      SDL_SRCALPHA set:
    2.13 -        alpha-blend (using alpha-channel).
    2.14 +      Source surface blend mode set to SDL_BLENDMODE_BLEND:
    2.15 +        alpha-blend (using the source alpha-channel and per-surface alpha)
    2.16          SDL_SRCCOLORKEY ignored.
    2.17 -      SDL_SRCALPHA not set:
    2.18 +      Source surface blend mode set to SDL_BLENDMODE_NONE:
    2.19          copy RGB.
    2.20          if SDL_SRCCOLORKEY set, only copy the pixels matching the
    2.21          RGB values of the source color key, ignoring alpha in the
    2.22          comparison.
    2.23  
    2.24      RGB->RGBA:
    2.25 -      SDL_SRCALPHA set:
    2.26 -        alpha-blend (using the source per-surface alpha value);
    2.27 -        set destination alpha to opaque.
    2.28 -      SDL_SRCALPHA not set:
    2.29 +      Source surface blend mode set to SDL_BLENDMODE_BLEND:
    2.30 +        alpha-blend (using the source per-surface alpha)
    2.31 +      Source surface blend mode set to SDL_BLENDMODE_NONE:
    2.32          copy RGB, set destination alpha to source per-surface alpha value.
    2.33        both:
    2.34          if SDL_SRCCOLORKEY set, only copy the pixels matching the
    2.35          source color key.
    2.36  
    2.37      RGBA->RGBA:
    2.38 -      SDL_SRCALPHA set:
    2.39 -        alpha-blend (using the source alpha channel) the RGB values;
    2.40 -        leave destination alpha untouched. [Note: is this correct?]
    2.41 +      Source surface blend mode set to SDL_BLENDMODE_BLEND:
    2.42 +        alpha-blend (using the source alpha-channel and per-surface alpha)
    2.43          SDL_SRCCOLORKEY ignored.
    2.44 -      SDL_SRCALPHA not set:
    2.45 +      Source surface blend mode set to SDL_BLENDMODE_NONE:
    2.46          copy all of RGBA to the destination.
    2.47          if SDL_SRCCOLORKEY set, only copy the pixels matching the
    2.48          RGB values of the source color key, ignoring alpha in the
    2.49 -       comparison.
    2.50 +        comparison.
    2.51  
    2.52      RGB->RGB:
    2.53 -      SDL_SRCALPHA set:
    2.54 -        alpha-blend (using the source per-surface alpha value).
    2.55 -      SDL_SRCALPHA not set:
    2.56 +      Source surface blend mode set to SDL_BLENDMODE_BLEND:
    2.57 +        alpha-blend (using the source per-surface alpha)
    2.58 +      Source surface blend mode set to SDL_BLENDMODE_NONE:
    2.59          copy RGB.
    2.60        both:
    2.61          if SDL_SRCCOLORKEY set, only copy the pixels matching the
     3.1 --- a/src/render/direct3d/SDL_render_d3d.c	Mon Jul 22 02:51:45 2013 -0700
     3.2 +++ b/src/render/direct3d/SDL_render_d3d.c	Tue Jul 23 08:06:49 2013 -0700
     3.3 @@ -227,6 +227,7 @@
     3.4      D3DPRESENT_PARAMETERS pparams;
     3.5      SDL_bool updateSize;
     3.6      SDL_bool beginScene;
     3.7 +    SDL_bool enableSeparateAlphaBlend;
     3.8      D3DTEXTUREFILTERTYPE scaleMode;
     3.9      IDirect3DSurface9 *defaultRenderTarget;
    3.10      IDirect3DSurface9 *currentRenderTarget;
    3.11 @@ -615,6 +616,10 @@
    3.12          renderer->info.flags |= SDL_RENDERER_TARGETTEXTURE;
    3.13      }
    3.14  
    3.15 +    if (caps.PrimitiveMiscCaps & D3DPMISCCAPS_SEPARATEALPHABLEND) {
    3.16 +        data->enableSeparateAlphaBlend = SDL_TRUE;
    3.17 +    }
    3.18 +
    3.19      /* Set up parameters for rendering */
    3.20      IDirect3DDevice9_SetVertexShader(data->device, NULL);
    3.21      IDirect3DDevice9_SetFVF(data->device,
    3.22 @@ -637,6 +642,10 @@
    3.23                                            D3DTA_TEXTURE);
    3.24      IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_ALPHAARG2,
    3.25                                            D3DTA_DIFFUSE);
    3.26 +    /* Enable separate alpha blend function, if possible */
    3.27 +    if (data->enableSeparateAlphaBlend) {
    3.28 +        IDirect3DDevice9_SetRenderState(data->device, D3DRS_SEPARATEALPHABLENDENABLE, TRUE);
    3.29 +    }
    3.30      /* Disable second texture stage, since we're done */
    3.31      IDirect3DDevice9_SetTextureStageState(data->device, 1, D3DTSS_COLOROP,
    3.32                                            D3DTOP_DISABLE);
    3.33 @@ -979,6 +988,12 @@
    3.34                                          D3DBLEND_SRCALPHA);
    3.35          IDirect3DDevice9_SetRenderState(data->device, D3DRS_DESTBLEND,
    3.36                                          D3DBLEND_INVSRCALPHA);
    3.37 +        if (data->enableSeparateAlphaBlend) {
    3.38 +            IDirect3DDevice9_SetRenderState(data->device, D3DRS_SRCBLENDALPHA,
    3.39 +                                            D3DBLEND_ONE);
    3.40 +            IDirect3DDevice9_SetRenderState(data->device, D3DRS_DESTBLENDALPHA,
    3.41 +                                            D3DBLEND_INVSRCALPHA);
    3.42 +        }
    3.43          break;
    3.44      case SDL_BLENDMODE_ADD:
    3.45          IDirect3DDevice9_SetRenderState(data->device, D3DRS_ALPHABLENDENABLE,
    3.46 @@ -987,6 +1002,12 @@
    3.47                                          D3DBLEND_SRCALPHA);
    3.48          IDirect3DDevice9_SetRenderState(data->device, D3DRS_DESTBLEND,
    3.49                                          D3DBLEND_ONE);
    3.50 +        if (data->enableSeparateAlphaBlend) {
    3.51 +            IDirect3DDevice9_SetRenderState(data->device, D3DRS_SRCBLENDALPHA,
    3.52 +                                            D3DBLEND_ZERO);
    3.53 +            IDirect3DDevice9_SetRenderState(data->device, D3DRS_DESTBLENDALPHA,
    3.54 +                                            D3DBLEND_ONE);
    3.55 +        }
    3.56          break;
    3.57      case SDL_BLENDMODE_MOD:
    3.58          IDirect3DDevice9_SetRenderState(data->device, D3DRS_ALPHABLENDENABLE,
    3.59 @@ -995,6 +1016,12 @@
    3.60                                          D3DBLEND_ZERO);
    3.61          IDirect3DDevice9_SetRenderState(data->device, D3DRS_DESTBLEND,
    3.62                                          D3DBLEND_SRCCOLOR);
    3.63 +        if (data->enableSeparateAlphaBlend) {
    3.64 +            IDirect3DDevice9_SetRenderState(data->device, D3DRS_SRCBLENDALPHA,
    3.65 +                                            D3DBLEND_ZERO);
    3.66 +            IDirect3DDevice9_SetRenderState(data->device, D3DRS_DESTBLENDALPHA,
    3.67 +                                            D3DBLEND_ONE);
    3.68 +        }
    3.69          break;
    3.70      }
    3.71  }
     4.1 --- a/src/render/opengl/SDL_glfuncs.h	Mon Jul 22 02:51:45 2013 -0700
     4.2 +++ b/src/render/opengl/SDL_glfuncs.h	Tue Jul 23 08:06:49 2013 -0700
     4.3 @@ -15,6 +15,7 @@
     4.4                  (GLsizei, GLsizei, GLfloat, GLfloat, GLfloat, GLfloat,
     4.5                   const GLubyte *))
     4.6  SDL_PROC(void, glBlendFunc, (GLenum, GLenum))
     4.7 +SDL_PROC(void, glBlendFuncSeparate, (GLenum, GLenum, GLenum, GLenum))
     4.8  SDL_PROC_UNUSED(void, glCallList, (GLuint))
     4.9  SDL_PROC_UNUSED(void, glCallLists, (GLsizei, GLenum, const GLvoid *))
    4.10  SDL_PROC(void, glClear, (GLbitfield))
     5.1 --- a/src/render/opengl/SDL_render_gl.c	Mon Jul 22 02:51:45 2013 -0700
     5.2 +++ b/src/render/opengl/SDL_render_gl.c	Tue Jul 23 08:06:49 2013 -0700
     5.3 @@ -924,17 +924,17 @@
     5.4          case SDL_BLENDMODE_BLEND:
     5.5              data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
     5.6              data->glEnable(GL_BLEND);
     5.7 -            data->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
     5.8 +            data->glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
     5.9              break;
    5.10          case SDL_BLENDMODE_ADD:
    5.11              data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    5.12              data->glEnable(GL_BLEND);
    5.13 -            data->glBlendFunc(GL_SRC_ALPHA, GL_ONE);
    5.14 +            data->glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE, GL_ZERO, GL_ONE);
    5.15              break;
    5.16          case SDL_BLENDMODE_MOD:
    5.17              data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    5.18              data->glEnable(GL_BLEND);
    5.19 -            data->glBlendFunc(GL_ZERO, GL_SRC_COLOR);
    5.20 +            data->glBlendFuncSeparate(GL_ZERO, GL_SRC_COLOR, GL_ZERO, GL_ONE);
    5.21              break;
    5.22          }
    5.23          data->current.blendMode = blendMode;
     6.1 --- a/src/render/opengles/SDL_glesfuncs.h	Mon Jul 22 02:51:45 2013 -0700
     6.2 +++ b/src/render/opengles/SDL_glesfuncs.h	Tue Jul 23 08:06:49 2013 -0700
     6.3 @@ -1,5 +1,6 @@
     6.4  SDL_PROC(void, glBindTexture, (GLenum, GLuint))
     6.5  SDL_PROC(void, glBlendFunc, (GLenum, GLenum))
     6.6 +SDL_PROC(void, glBlendFuncSeparateOES, (GLenum, GLenum, GLenum, GLenum))
     6.7  SDL_PROC(void, glClear, (GLbitfield))
     6.8  SDL_PROC(void, glClearColor, (GLclampf, GLclampf, GLclampf, GLclampf))
     6.9  SDL_PROC(void, glColor4f, (GLfloat, GLfloat, GLfloat, GLfloat))
     7.1 --- a/src/render/opengles/SDL_render_gles.c	Mon Jul 22 02:51:45 2013 -0700
     7.2 +++ b/src/render/opengles/SDL_render_gles.c	Tue Jul 23 08:06:49 2013 -0700
     7.3 @@ -121,6 +121,7 @@
     7.4  
     7.5      SDL_bool useDrawTexture;
     7.6      SDL_bool GL_OES_draw_texture_supported;
     7.7 +    SDL_bool GL_OES_blend_func_separate_supported;
     7.8  } GLES_RenderData;
     7.9  
    7.10  typedef struct
    7.11 @@ -376,6 +377,10 @@
    7.12      }
    7.13      data->framebuffers = NULL;
    7.14  
    7.15 +    if (SDL_GL_ExtensionSupported("GL_OES_blend_func_separate")) {
    7.16 +        data->GL_OES_blend_func_separate_supported = SDL_TRUE;
    7.17 +    }
    7.18 +
    7.19      /* Set up parameters for rendering */
    7.20      GLES_ResetState(renderer);
    7.21  
    7.22 @@ -680,17 +685,29 @@
    7.23          case SDL_BLENDMODE_BLEND:
    7.24              data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    7.25              data->glEnable(GL_BLEND);
    7.26 -            data->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    7.27 +            if (data->GL_OES_blend_func_separate_supported) {
    7.28 +                data->glBlendFuncSeparateOES(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
    7.29 +            } else {
    7.30 +                data->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    7.31 +            }
    7.32              break;
    7.33          case SDL_BLENDMODE_ADD:
    7.34              data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    7.35              data->glEnable(GL_BLEND);
    7.36 -            data->glBlendFunc(GL_SRC_ALPHA, GL_ONE);
    7.37 +            if (data->GL_OES_blend_func_separate_supported) {
    7.38 +                data->glBlendFuncSeparateOES(GL_SRC_ALPHA, GL_ONE, GL_ZERO, GL_ONE);
    7.39 +            } else {
    7.40 +                data->glBlendFunc(GL_SRC_ALPHA, GL_ONE);
    7.41 +            }
    7.42              break;
    7.43          case SDL_BLENDMODE_MOD:
    7.44              data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    7.45              data->glEnable(GL_BLEND);
    7.46 -            data->glBlendFunc(GL_ZERO, GL_SRC_COLOR);
    7.47 +            if (data->GL_OES_blend_func_separate_supported) {
    7.48 +                data->glBlendFuncSeparateOES(GL_ZERO, GL_SRC_COLOR, GL_ZERO, GL_ONE);
    7.49 +            } else {
    7.50 +                data->glBlendFunc(GL_ZERO, GL_SRC_COLOR);
    7.51 +            }
    7.52              break;
    7.53          }
    7.54          data->current.blendMode = blendMode;
     8.1 --- a/src/render/opengles2/SDL_gles2funcs.h	Mon Jul 22 02:51:45 2013 -0700
     8.2 +++ b/src/render/opengles2/SDL_gles2funcs.h	Tue Jul 23 08:06:49 2013 -0700
     8.3 @@ -2,7 +2,7 @@
     8.4  SDL_PROC(void, glAttachShader, (GLuint, GLuint))
     8.5  SDL_PROC(void, glBindAttribLocation, (GLuint, GLuint, const char *))
     8.6  SDL_PROC(void, glBindTexture, (GLenum, GLuint))
     8.7 -SDL_PROC(void, glBlendFunc, (GLenum, GLenum))
     8.8 +SDL_PROC(void, glBlendFuncSeparate, (GLenum, GLenum, GLenum, GLenum))
     8.9  SDL_PROC(void, glClear, (GLbitfield))
    8.10  SDL_PROC(void, glClearColor, (GLclampf, GLclampf, GLclampf, GLclampf))
    8.11  SDL_PROC(void, glCompileShader, (GLuint))
     9.1 --- a/src/render/opengles2/SDL_render_gles2.c	Mon Jul 22 02:51:45 2013 -0700
     9.2 +++ b/src/render/opengles2/SDL_render_gles2.c	Tue Jul 23 08:06:49 2013 -0700
     9.3 @@ -994,15 +994,15 @@
     9.4              break;
     9.5          case SDL_BLENDMODE_BLEND:
     9.6              rdata->glEnable(GL_BLEND);
     9.7 -            rdata->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
     9.8 +            rdata->glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
     9.9              break;
    9.10          case SDL_BLENDMODE_ADD:
    9.11              rdata->glEnable(GL_BLEND);
    9.12 -            rdata->glBlendFunc(GL_SRC_ALPHA, GL_ONE);
    9.13 +            rdata->glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE, GL_ZERO, GL_ONE);
    9.14              break;
    9.15          case SDL_BLENDMODE_MOD:
    9.16              rdata->glEnable(GL_BLEND);
    9.17 -            rdata->glBlendFunc(GL_ZERO, GL_SRC_COLOR);
    9.18 +            rdata->glBlendFuncSeparate(GL_ZERO, GL_SRC_COLOR, GL_ZERO, GL_ONE);
    9.19              break;
    9.20          }
    9.21          rdata->current.blendMode = blendMode;
    10.1 --- a/src/video/SDL_blit.h	Mon Jul 22 02:51:45 2013 -0700
    10.2 +++ b/src/video/SDL_blit.h	Tue Jul 23 08:06:49 2013 -0700
    10.3 @@ -440,12 +440,22 @@
    10.4      }                                                                   \
    10.5  }
    10.6  
    10.7 -/* Blend the RGB values of two Pixels based on a source alpha value */
    10.8 -#define ALPHA_BLEND(sR, sG, sB, A, dR, dG, dB)                          \
    10.9 +/* Blend the RGB values of two pixels with an alpha value */
   10.10 +#define ALPHA_BLEND_RGB(sR, sG, sB, A, dR, dG, dB)                      \
   10.11  do {                                                                    \
   10.12 -    dR = ((((int)(sR-dR)*(int)A)/255)+dR);                              \
   10.13 -    dG = ((((int)(sG-dG)*(int)A)/255)+dG);                              \
   10.14 -    dB = ((((int)(sB-dB)*(int)A)/255)+dB);                              \
   10.15 +    dR = ((((unsigned)(sR-dR)*(unsigned)A)/255)+dR);                    \
   10.16 +    dG = ((((unsigned)(sG-dG)*(unsigned)A)/255)+dG);                    \
   10.17 +    dB = ((((unsigned)(sB-dB)*(unsigned)A)/255)+dB);                    \
   10.18 +} while(0)
   10.19 +
   10.20 +
   10.21 +/* Blend the RGBA values of two pixels */
   10.22 +#define ALPHA_BLEND_RGBA(sR, sG, sB, sA, dR, dG, dB, dA)                \
   10.23 +do {                                                                    \
   10.24 +    dR = ((((unsigned)(sR-dR)*(unsigned)sA)/255)+dR);                   \
   10.25 +    dG = ((((unsigned)(sG-dG)*(unsigned)sA)/255)+dG);                   \
   10.26 +    dB = ((((unsigned)(sB-dB)*(unsigned)sA)/255)+dB);                   \
   10.27 +    dA = ((unsigned)sA+(unsigned)dA-((unsigned)sA*dA)/255);             \
   10.28  } while(0)
   10.29  
   10.30  
    11.1 --- a/src/video/SDL_blit_0.c	Mon Jul 22 02:51:45 2013 -0700
    11.2 +++ b/src/video/SDL_blit_0.c	Tue Jul 23 08:06:49 2013 -0700
    11.3 @@ -363,7 +363,10 @@
    11.4      SDL_PixelFormat *dstfmt = info->dst_fmt;
    11.5      int dstbpp;
    11.6      int c;
    11.7 -    const int A = info->a;
    11.8 +    Uint32 pixel;
    11.9 +    unsigned sR, sG, sB;
   11.10 +    unsigned dR, dG, dB, dA;
   11.11 +    const unsigned A = info->a;
   11.12  
   11.13      /* Set up some basic variables */
   11.14      dstbpp = dstfmt->BytesPerPixel;
   11.15 @@ -377,15 +380,12 @@
   11.16              }
   11.17              bit = (byte & 0x80) >> 7;
   11.18              if (1) {
   11.19 -                Uint32 pixel;
   11.20 -                unsigned sR, sG, sB;
   11.21 -                unsigned dR, dG, dB;
   11.22                  sR = srcpal[bit].r;
   11.23                  sG = srcpal[bit].g;
   11.24                  sB = srcpal[bit].b;
   11.25 -                DISEMBLE_RGB(dst, dstbpp, dstfmt, pixel, dR, dG, dB);
   11.26 -                ALPHA_BLEND(sR, sG, sB, A, dR, dG, dB);
   11.27 -                ASSEMBLE_RGB(dst, dstbpp, dstfmt, dR, dG, dB);
   11.28 +                DISEMBLE_RGBA(dst, dstbpp, dstfmt, pixel, dR, dG, dB, dA);
   11.29 +                ALPHA_BLEND_RGBA(sR, sG, sB, A, dR, dG, dB, dA);
   11.30 +                ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA);
   11.31              }
   11.32              byte <<= 1;
   11.33              dst += dstbpp;
   11.34 @@ -409,7 +409,10 @@
   11.35      const SDL_Color *srcpal = srcfmt->palette->colors;
   11.36      int dstbpp;
   11.37      int c;
   11.38 -    const int A = info->a;
   11.39 +    Uint32 pixel;
   11.40 +    unsigned sR, sG, sB;
   11.41 +    unsigned dR, dG, dB, dA;
   11.42 +    const unsigned A = info->a;
   11.43      Uint32 ckey = info->colorkey;
   11.44  
   11.45      /* Set up some basic variables */
   11.46 @@ -424,15 +427,12 @@
   11.47              }
   11.48              bit = (byte & 0x80) >> 7;
   11.49              if (bit != ckey) {
   11.50 -                int sR, sG, sB;
   11.51 -                int dR, dG, dB;
   11.52 -                Uint32 pixel;
   11.53                  sR = srcpal[bit].r;
   11.54                  sG = srcpal[bit].g;
   11.55                  sB = srcpal[bit].b;
   11.56 -                DISEMBLE_RGB(dst, dstbpp, dstfmt, pixel, dR, dG, dB);
   11.57 -                ALPHA_BLEND(sR, sG, sB, A, dR, dG, dB);
   11.58 -                ASSEMBLE_RGB(dst, dstbpp, dstfmt, dR, dG, dB);
   11.59 +                DISEMBLE_RGBA(dst, dstbpp, dstfmt, pixel, dR, dG, dB, dA);
   11.60 +                ALPHA_BLEND_RGBA(sR, sG, sB, A, dR, dG, dB, dA);
   11.61 +                ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA);
   11.62              }
   11.63              byte <<= 1;
   11.64              dst += dstbpp;
    12.1 --- a/src/video/SDL_blit_1.c	Mon Jul 22 02:51:45 2013 -0700
    12.2 +++ b/src/video/SDL_blit_1.c	Tue Jul 23 08:06:49 2013 -0700
    12.3 @@ -437,30 +437,29 @@
    12.4      SDL_PixelFormat *dstfmt = info->dst_fmt;
    12.5      const SDL_Color *srcpal = info->src_fmt->palette->colors;
    12.6      int dstbpp;
    12.7 -    const int A = info->a;
    12.8 +    Uint32 pixel;
    12.9 +    unsigned sR, sG, sB;
   12.10 +    unsigned dR, dG, dB, dA;
   12.11 +    const unsigned A = info->a;
   12.12  
   12.13      /* Set up some basic variables */
   12.14      dstbpp = dstfmt->BytesPerPixel;
   12.15  
   12.16      while (height--) {
   12.17 -        int sR, sG, sB;
   12.18 -        int dR, dG, dB;
   12.19 -	    	/* *INDENT-OFF* */
   12.20 -	    	DUFFS_LOOP4(
   12.21 -			{
   12.22 -			        Uint32 pixel;
   12.23 -				sR = srcpal[*src].r;
   12.24 -				sG = srcpal[*src].g;
   12.25 -				sB = srcpal[*src].b;
   12.26 -				DISEMBLE_RGB(dst, dstbpp, dstfmt,
   12.27 -					     pixel, dR, dG, dB);
   12.28 -				ALPHA_BLEND(sR, sG, sB, A, dR, dG, dB);
   12.29 -			  	ASSEMBLE_RGB(dst, dstbpp, dstfmt, dR, dG, dB);
   12.30 -				src++;
   12.31 -				dst += dstbpp;
   12.32 -			},
   12.33 -			width);
   12.34 -	    	/* *INDENT-ON* */
   12.35 +        /* *INDENT-OFF* */
   12.36 +        DUFFS_LOOP4(
   12.37 +        {
   12.38 +            sR = srcpal[*src].r;
   12.39 +            sG = srcpal[*src].g;
   12.40 +            sB = srcpal[*src].b;
   12.41 +            DISEMBLE_RGBA(dst, dstbpp, dstfmt, pixel, dR, dG, dB, dA);
   12.42 +            ALPHA_BLEND_RGBA(sR, sG, sB, A, dR, dG, dB, dA);
   12.43 +            ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA);
   12.44 +            src++;
   12.45 +            dst += dstbpp;
   12.46 +        },
   12.47 +        width);
   12.48 +        /* *INDENT-ON* */
   12.49          src += srcskip;
   12.50          dst += dstskip;
   12.51      }
   12.52 @@ -479,26 +478,25 @@
   12.53      const SDL_Color *srcpal = info->src_fmt->palette->colors;
   12.54      Uint32 ckey = info->colorkey;
   12.55      int dstbpp;
   12.56 -    const int A = info->a;
   12.57 +    Uint32 pixel;
   12.58 +    unsigned sR, sG, sB;
   12.59 +    unsigned dR, dG, dB, dA;
   12.60 +    const unsigned A = info->a;
   12.61  
   12.62      /* Set up some basic variables */
   12.63      dstbpp = dstfmt->BytesPerPixel;
   12.64  
   12.65      while (height--) {
   12.66 -        int sR, sG, sB;
   12.67 -        int dR, dG, dB;
   12.68  		/* *INDENT-OFF* */
   12.69  		DUFFS_LOOP(
   12.70  		{
   12.71  			if ( *src != ckey ) {
   12.72 -			        Uint32 pixel;
   12.73  				sR = srcpal[*src].r;
   12.74  				sG = srcpal[*src].g;
   12.75  				sB = srcpal[*src].b;
   12.76 -				DISEMBLE_RGB(dst, dstbpp, dstfmt,
   12.77 -							pixel, dR, dG, dB);
   12.78 -				ALPHA_BLEND(sR, sG, sB, A, dR, dG, dB);
   12.79 -			  	ASSEMBLE_RGB(dst, dstbpp, dstfmt, dR, dG, dB);
   12.80 +				DISEMBLE_RGBA(dst, dstbpp, dstfmt, pixel, dR, dG, dB, dA);
   12.81 +				ALPHA_BLEND_RGBA(sR, sG, sB, A, dR, dG, dB, dA);
   12.82 +			  	ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA);
   12.83  			}
   12.84  			src++;
   12.85  			dst += dstbpp;
    13.1 --- a/src/video/SDL_blit_A.c	Mon Jul 22 02:51:45 2013 -0700
    13.2 +++ b/src/video/SDL_blit_A.c	Tue Jul 23 08:06:49 2013 -0700
    13.3 @@ -39,37 +39,28 @@
    13.4      SDL_PixelFormat *srcfmt = info->src_fmt;
    13.5      SDL_PixelFormat *dstfmt = info->dst_fmt;
    13.6      int srcbpp = srcfmt->BytesPerPixel;
    13.7 -
    13.8 +    Uint32 Pixel;
    13.9 +    unsigned sR, sG, sB;
   13.10 +    unsigned dR, dG, dB;
   13.11      const unsigned A = info->a;
   13.12  
   13.13      while (height--) {
   13.14  	    /* *INDENT-OFF* */
   13.15  	    DUFFS_LOOP4(
   13.16  	    {
   13.17 -		Uint32 Pixel;
   13.18 -		unsigned sR;
   13.19 -		unsigned sG;
   13.20 -		unsigned sB;
   13.21 -		unsigned dR;
   13.22 -		unsigned dG;
   13.23 -		unsigned dB;
   13.24  		DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, sR, sG, sB);
   13.25  		dR = dstfmt->palette->colors[*dst].r;
   13.26  		dG = dstfmt->palette->colors[*dst].g;
   13.27  		dB = dstfmt->palette->colors[*dst].b;
   13.28 -		ALPHA_BLEND(sR, sG, sB, A, dR, dG, dB);
   13.29 +		ALPHA_BLEND_RGB(sR, sG, sB, A, dR, dG, dB);
   13.30  		dR &= 0xff;
   13.31  		dG &= 0xff;
   13.32  		dB &= 0xff;
   13.33  		/* Pack RGB into 8bit pixel */
   13.34  		if ( palmap == NULL ) {
   13.35 -		    *dst =((dR>>5)<<(3+2))|
   13.36 -			  ((dG>>5)<<(2))|
   13.37 -			  ((dB>>6)<<(0));
   13.38 +		    *dst =((dR>>5)<<(3+2))|((dG>>5)<<(2))|((dB>>6)<<(0));
   13.39  		} else {
   13.40 -		    *dst = palmap[((dR>>5)<<(3+2))|
   13.41 -				  ((dG>>5)<<(2))  |
   13.42 -				  ((dB>>6)<<(0))];
   13.43 +		    *dst = palmap[((dR>>5)<<(3+2))|((dG>>5)<<(2))|((dB>>6)<<(0))];
   13.44  		}
   13.45  		dst++;
   13.46  		src += srcbpp;
   13.47 @@ -95,36 +86,27 @@
   13.48      SDL_PixelFormat *srcfmt = info->src_fmt;
   13.49      SDL_PixelFormat *dstfmt = info->dst_fmt;
   13.50      int srcbpp = srcfmt->BytesPerPixel;
   13.51 +    Uint32 Pixel;
   13.52 +    unsigned sR, sG, sB, sA;
   13.53 +    unsigned dR, dG, dB;
   13.54  
   13.55      while (height--) {
   13.56  	    /* *INDENT-OFF* */
   13.57  	    DUFFS_LOOP4(
   13.58  	    {
   13.59 -		Uint32 Pixel;
   13.60 -		unsigned sR;
   13.61 -		unsigned sG;
   13.62 -		unsigned sB;
   13.63 -		unsigned sA;
   13.64 -		unsigned dR;
   13.65 -		unsigned dG;
   13.66 -		unsigned dB;
   13.67  		DISEMBLE_RGBA(src,srcbpp,srcfmt,Pixel,sR,sG,sB,sA);
   13.68  		dR = dstfmt->palette->colors[*dst].r;
   13.69  		dG = dstfmt->palette->colors[*dst].g;
   13.70  		dB = dstfmt->palette->colors[*dst].b;
   13.71 -		ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB);
   13.72 +		ALPHA_BLEND_RGB(sR, sG, sB, sA, dR, dG, dB);
   13.73  		dR &= 0xff;
   13.74  		dG &= 0xff;
   13.75  		dB &= 0xff;
   13.76  		/* Pack RGB into 8bit pixel */
   13.77  		if ( palmap == NULL ) {
   13.78 -		    *dst =((dR>>5)<<(3+2))|
   13.79 -			  ((dG>>5)<<(2))|
   13.80 -			  ((dB>>6)<<(0));
   13.81 +		    *dst =((dR>>5)<<(3+2))|((dG>>5)<<(2))|((dB>>6)<<(0));
   13.82  		} else {
   13.83 -		    *dst = palmap[((dR>>5)<<(3+2))|
   13.84 -				  ((dG>>5)<<(2))  |
   13.85 -				  ((dB>>6)<<(0))  ];
   13.86 +		    *dst = palmap[((dR>>5)<<(3+2))|((dG>>5)<<(2))|((dB>>6)<<(0))];
   13.87  		}
   13.88  		dst++;
   13.89  		src += srcbpp;
   13.90 @@ -151,38 +133,29 @@
   13.91      SDL_PixelFormat *dstfmt = info->dst_fmt;
   13.92      int srcbpp = srcfmt->BytesPerPixel;
   13.93      Uint32 ckey = info->colorkey;
   13.94 -
   13.95 -    const int A = info->a;
   13.96 +    Uint32 Pixel;
   13.97 +    unsigned sR, sG, sB;
   13.98 +    unsigned dR, dG, dB;
   13.99 +    const unsigned A = info->a;
  13.100  
  13.101      while (height--) {
  13.102  	    /* *INDENT-OFF* */
  13.103  	    DUFFS_LOOP(
  13.104  	    {
  13.105 -		Uint32 Pixel;
  13.106 -		unsigned sR;
  13.107 -		unsigned sG;
  13.108 -		unsigned sB;
  13.109 -		unsigned dR;
  13.110 -		unsigned dG;
  13.111 -		unsigned dB;
  13.112  		DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, sR, sG, sB);
  13.113  		if ( Pixel != ckey ) {
  13.114  		    dR = dstfmt->palette->colors[*dst].r;
  13.115  		    dG = dstfmt->palette->colors[*dst].g;
  13.116  		    dB = dstfmt->palette->colors[*dst].b;
  13.117 -		    ALPHA_BLEND(sR, sG, sB, A, dR, dG, dB);
  13.118 +		    ALPHA_BLEND_RGB(sR, sG, sB, A, dR, dG, dB);
  13.119  		    dR &= 0xff;
  13.120  		    dG &= 0xff;
  13.121  		    dB &= 0xff;
  13.122  		    /* Pack RGB into 8bit pixel */
  13.123  		    if ( palmap == NULL ) {
  13.124 -			*dst =((dR>>5)<<(3+2))|
  13.125 -			      ((dG>>5)<<(2)) |
  13.126 -			      ((dB>>6)<<(0));
  13.127 +                *dst =((dR>>5)<<(3+2))|((dG>>5)<<(2))|((dB>>6)<<(0));
  13.128  		    } else {
  13.129 -			*dst = palmap[((dR>>5)<<(3+2))|
  13.130 -				      ((dG>>5)<<(2))  |
  13.131 -				      ((dB>>6)<<(0))  ];
  13.132 +                *dst = palmap[((dR>>5)<<(3+2))|((dG>>5)<<(2))|((dB>>6)<<(0))];
  13.133  		    }
  13.134  		}
  13.135  		dst++;
  13.136 @@ -417,807 +390,6 @@
  13.137  
  13.138  #endif /* __MMX__ */
  13.139  
  13.140 -#if SDL_ALTIVEC_BLITTERS
  13.141 -#if __MWERKS__
  13.142 -#pragma altivec_model on
  13.143 -#endif
  13.144 -#if HAVE_ALTIVEC_H
  13.145 -#include <altivec.h>
  13.146 -#endif
  13.147 -
  13.148 -#if (defined(__MACOSX__) && (__GNUC__ < 4))
  13.149 -#define VECUINT8_LITERAL(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \
  13.150 -        (vector unsigned char) ( a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p )
  13.151 -#define VECUINT16_LITERAL(a,b,c,d,e,f,g,h) \
  13.152 -        (vector unsigned short) ( a,b,c,d,e,f,g,h )
  13.153 -#else
  13.154 -#define VECUINT8_LITERAL(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \
  13.155 -        (vector unsigned char) { a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p }
  13.156 -#define VECUINT16_LITERAL(a,b,c,d,e,f,g,h) \
  13.157 -        (vector unsigned short) { a,b,c,d,e,f,g,h }
  13.158 -#endif
  13.159 -
  13.160 -#define UNALIGNED_PTR(x) (((size_t) x) & 0x0000000F)
  13.161 -#define VECPRINT(msg, v) do { \
  13.162 -    vector unsigned int tmpvec = (vector unsigned int)(v); \
  13.163 -    unsigned int *vp = (unsigned int *)&tmpvec; \
  13.164 -    printf("%s = %08X %08X %08X %08X\n", msg, vp[0], vp[1], vp[2], vp[3]); \
  13.165 -} while (0)
  13.166 -
  13.167 -/* the permuation vector that takes the high bytes out of all the appropriate shorts 
  13.168 -    (vector unsigned char)(
  13.169 -        0x00, 0x10, 0x02, 0x12,
  13.170 -        0x04, 0x14, 0x06, 0x16,
  13.171 -        0x08, 0x18, 0x0A, 0x1A,
  13.172 -        0x0C, 0x1C, 0x0E, 0x1E );
  13.173 -*/
  13.174 -#define VEC_MERGE_PERMUTE() (vec_add(vec_lvsl(0, (int*)NULL), (vector unsigned char)vec_splat_u16(0x0F)))
  13.175 -#define VEC_U32_24() (vec_add(vec_splat_u32(12), vec_splat_u32(12)))
  13.176 -#define VEC_ALPHA_MASK() ((vector unsigned char)vec_sl((vector unsigned int)vec_splat_s8(-1), VEC_U32_24()))
  13.177 -#define VEC_ALIGNER(src) ((UNALIGNED_PTR(src)) \
  13.178 -    ? vec_lvsl(0, src) \
  13.179 -    : vec_add(vec_lvsl(8, src), vec_splat_u8(8)))
  13.180 -
  13.181 -
  13.182 -#define VEC_MULTIPLY_ALPHA(vs, vd, valpha, mergePermute, v1_16, v8_16) do { \
  13.183 -    /* vtemp1 contains source AAGGAAGGAAGGAAGG */ \
  13.184 -    vector unsigned short vtemp1 = vec_mule(vs, valpha); \
  13.185 -    /* vtemp2 contains source RRBBRRBBRRBBRRBB */ \
  13.186 -    vector unsigned short vtemp2 = vec_mulo(vs, valpha); \
  13.187 -    /* valpha2 is 255-alpha */ \
  13.188 -    vector unsigned char valpha2 = vec_nor(valpha, valpha); \
  13.189 -    /* vtemp3 contains dest AAGGAAGGAAGGAAGG */ \
  13.190 -    vector unsigned short vtemp3 = vec_mule(vd, valpha2); \
  13.191 -    /* vtemp4 contains dest RRBBRRBBRRBBRRBB */ \
  13.192 -    vector unsigned short vtemp4 = vec_mulo(vd, valpha2); \
  13.193 -    /* add source and dest */ \
  13.194 -    vtemp1 = vec_add(vtemp1, vtemp3); \
  13.195 -    vtemp2 = vec_add(vtemp2, vtemp4); \
  13.196 -    /* vtemp1 = (vtemp1 + 1) + ((vtemp1 + 1) >> 8) */ \
  13.197 -    vtemp1 = vec_add(vtemp1, v1_16); \
  13.198 -    vtemp3 = vec_sr(vtemp1, v8_16); \
  13.199 -    vtemp1 = vec_add(vtemp1, vtemp3); \
  13.200 -    /* vtemp2 = (vtemp2 + 1) + ((vtemp2 + 1) >> 8) */ \
  13.201 -    vtemp2 = vec_add(vtemp2, v1_16); \
  13.202 -    vtemp4 = vec_sr(vtemp2, v8_16); \
  13.203 -    vtemp2 = vec_add(vtemp2, vtemp4); \
  13.204 -    /* (>>8) and get ARGBARGBARGBARGB */ \
  13.205 -    vd = (vector unsigned char)vec_perm(vtemp1, vtemp2, mergePermute); \
  13.206 -} while (0)
  13.207 -
  13.208 -/* Calculate the permute vector used for 32->32 swizzling */
  13.209 -static vector unsigned char
  13.210 -calc_swizzle32(const SDL_PixelFormat * srcfmt, const SDL_PixelFormat * dstfmt)
  13.211 -{
  13.212 -    /*
  13.213 -     * We have to assume that the bits that aren't used by other
  13.214 -     *  colors is alpha, and it's one complete byte, since some formats
  13.215 -     *  leave alpha with a zero mask, but we should still swizzle the bits.
  13.216 -     */
  13.217 -    /* ARGB */
  13.218 -    const static struct SDL_PixelFormat default_pixel_format = {
  13.219 -        0, NULL, 0, 0,
  13.220 -        {0, 0},
  13.221 -        0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000,
  13.222 -        0, 0, 0, 0,
  13.223 -        16, 8, 0, 24,
  13.224 -        0, NULL
  13.225 -    };
  13.226 -    if (!srcfmt) {
  13.227 -        srcfmt = &default_pixel_format;
  13.228 -    }
  13.229 -    if (!dstfmt) {
  13.230 -        dstfmt = &default_pixel_format;
  13.231 -    }
  13.232 -    const vector unsigned char plus = VECUINT8_LITERAL(0x00, 0x00, 0x00, 0x00,
  13.233 -                                                       0x04, 0x04, 0x04, 0x04,
  13.234 -                                                       0x08, 0x08, 0x08, 0x08,
  13.235 -                                                       0x0C, 0x0C, 0x0C,
  13.236 -                                                       0x0C);
  13.237 -    vector unsigned char vswiz;
  13.238 -    vector unsigned int srcvec;
  13.239 -#define RESHIFT(X) (3 - ((X) >> 3))
  13.240 -    Uint32 rmask = RESHIFT(srcfmt->Rshift) << (dstfmt->Rshift);
  13.241 -    Uint32 gmask = RESHIFT(srcfmt->Gshift) << (dstfmt->Gshift);
  13.242 -    Uint32 bmask = RESHIFT(srcfmt->Bshift) << (dstfmt->Bshift);
  13.243 -    Uint32 amask;
  13.244 -    /* Use zero for alpha if either surface doesn't have alpha */
  13.245 -    if (dstfmt->Amask) {
  13.246 -        amask =
  13.247 -            ((srcfmt->Amask) ? RESHIFT(srcfmt->
  13.248 -                                       Ashift) : 0x10) << (dstfmt->Ashift);
  13.249 -    } else {
  13.250 -        amask =
  13.251 -            0x10101010 & ((dstfmt->Rmask | dstfmt->Gmask | dstfmt->Bmask) ^
  13.252 -                          0xFFFFFFFF);
  13.253 -    }
  13.254 -#undef RESHIFT
  13.255 -    ((unsigned int *) (char *) &srcvec)[0] = (rmask | gmask | bmask | amask);
  13.256 -    vswiz = vec_add(plus, (vector unsigned char) vec_splat(srcvec, 0));
  13.257 -    return (vswiz);
  13.258 -}
  13.259 -
  13.260 -static void
  13.261 -Blit32to565PixelAlphaAltivec(SDL_BlitInfo * info)
  13.262 -{
  13.263 -    int height = info->dst_h;
  13.264 -    Uint8 *src = (Uint8 *) info->src;
  13.265 -    int srcskip = info->src_skip;
  13.266 -    Uint8 *dst = (Uint8 *) info->dst;
  13.267 -    int dstskip = info->dst_skip;
  13.268 -    SDL_PixelFormat *srcfmt = info->src_fmt;
  13.269 -
  13.270 -    vector unsigned char v0 = vec_splat_u8(0);
  13.271 -    vector unsigned short v8_16 = vec_splat_u16(8);
  13.272 -    vector unsigned short v1_16 = vec_splat_u16(1);
  13.273 -    vector unsigned short v2_16 = vec_splat_u16(2);
  13.274 -    vector unsigned short v3_16 = vec_splat_u16(3);
  13.275 -    vector unsigned int v8_32 = vec_splat_u32(8);
  13.276 -    vector unsigned int v16_32 = vec_add(v8_32, v8_32);
  13.277 -    vector unsigned short v3f =
  13.278 -        VECUINT16_LITERAL(0x003f, 0x003f, 0x003f, 0x003f,
  13.279 -                          0x003f, 0x003f, 0x003f, 0x003f);
  13.280 -    vector unsigned short vfc =
  13.281 -        VECUINT16_LITERAL(0x00fc, 0x00fc, 0x00fc, 0x00fc,
  13.282 -                          0x00fc, 0x00fc, 0x00fc, 0x00fc);
  13.283 -
  13.284 -    /* 
  13.285 -       0x10 - 0x1f is the alpha
  13.286 -       0x00 - 0x0e evens are the red
  13.287 -       0x01 - 0x0f odds are zero
  13.288 -     */
  13.289 -    vector unsigned char vredalpha1 = VECUINT8_LITERAL(0x10, 0x00, 0x01, 0x01,
  13.290 -                                                       0x10, 0x02, 0x01, 0x01,
  13.291 -                                                       0x10, 0x04, 0x01, 0x01,
  13.292 -                                                       0x10, 0x06, 0x01,
  13.293 -                                                       0x01);
  13.294 -    vector unsigned char vredalpha2 =
  13.295 -        (vector unsigned char) (vec_add((vector unsigned int) vredalpha1,
  13.296 -                                        vec_sl(v8_32, v16_32))
  13.297 -        );
  13.298 -    /*
  13.299 -       0x00 - 0x0f is ARxx ARxx ARxx ARxx
  13.300 -       0x11 - 0x0f odds are blue
  13.301 -     */
  13.302 -    vector unsigned char vblue1 = VECUINT8_LITERAL(0x00, 0x01, 0x02, 0x11,
  13.303 -                                                   0x04, 0x05, 0x06, 0x13,
  13.304 -                                                   0x08, 0x09, 0x0a, 0x15,
  13.305 -                                                   0x0c, 0x0d, 0x0e, 0x17);
  13.306 -    vector unsigned char vblue2 =
  13.307 -        (vector unsigned char) (vec_add((vector unsigned int) vblue1, v8_32)
  13.308 -        );
  13.309 -    /*
  13.310 -       0x00 - 0x0f is ARxB ARxB ARxB ARxB
  13.311 -       0x10 - 0x0e evens are green
  13.312 -     */
  13.313 -    vector unsigned char vgreen1 = VECUINT8_LITERAL(0x00, 0x01, 0x10, 0x03,
  13.314 -                                                    0x04, 0x05, 0x12, 0x07,
  13.315 -                                                    0x08, 0x09, 0x14, 0x0b,
  13.316 -                                                    0x0c, 0x0d, 0x16, 0x0f);
  13.317 -    vector unsigned char vgreen2 =
  13.318 -        (vector unsigned
  13.319 -         char) (vec_add((vector unsigned int) vgreen1, vec_sl(v8_32, v8_32))
  13.320 -        );
  13.321 -    vector unsigned char vgmerge = VECUINT8_LITERAL(0x00, 0x02, 0x00, 0x06,
  13.322 -                                                    0x00, 0x0a, 0x00, 0x0e,
  13.323 -                                                    0x00, 0x12, 0x00, 0x16,
  13.324 -                                                    0x00, 0x1a, 0x00, 0x1e);
  13.325 -    vector unsigned char mergePermute = VEC_MERGE_PERMUTE();
  13.326 -    vector unsigned char vpermute = calc_swizzle32(srcfmt, NULL);
  13.327 -    vector unsigned char valphaPermute =
  13.328 -        vec_and(vec_lvsl(0, (int *) NULL), vec_splat_u8(0xC));
  13.329 -
  13.330 -    vector unsigned short vf800 = (vector unsigned short) vec_splat_u8(-7);
  13.331 -    vf800 = vec_sl(vf800, vec_splat_u16(8));
  13.332 -
  13.333 -    while (height--) {
  13.334 -        int extrawidth;
  13.335 -        vector unsigned char valigner;
  13.336 -        vector unsigned char vsrc;
  13.337 -        vector unsigned char voverflow;
  13.338 -        int width = info->dst_w;
  13.339 -
  13.340 -#define ONE_PIXEL_BLEND(condition, widthvar) \
  13.341 -        while (condition) { \
  13.342 -            Uint32 Pixel; \
  13.343 -            unsigned sR, sG, sB, dR, dG, dB, sA; \
  13.344 -            DISEMBLE_RGBA(src, 4, srcfmt, Pixel, sR, sG, sB, sA); \
  13.345 -            if(sA) { \
  13.346 -                unsigned short dstpixel = *((unsigned short *)dst); \
  13.347 -                dR = (dstpixel >> 8) & 0xf8; \
  13.348 -                dG = (dstpixel >> 3) & 0xfc; \
  13.349 -                dB = (dstpixel << 3) & 0xf8; \
  13.350 -                ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB); \
  13.351 -                *((unsigned short *)dst) = ( \
  13.352 -                    ((dR & 0xf8) << 8) | ((dG & 0xfc) << 3) | (dB >> 3) \
  13.353 -                ); \
  13.354 -            } \
  13.355 -            src += 4; \
  13.356 -            dst += 2; \
  13.357 -            widthvar--; \
  13.358 -        }
  13.359 -        ONE_PIXEL_BLEND((UNALIGNED_PTR(dst)) && (width), width);
  13.360 -        extrawidth = (width % 8);
  13.361 -        valigner = VEC_ALIGNER(src);
  13.362 -        vsrc = (vector unsigned char) vec_ld(0, src);
  13.363 -        width -= extrawidth;
  13.364 -        while (width) {
  13.365 -            vector unsigned char valpha;
  13.366 -            vector unsigned char vsrc1, vsrc2;
  13.367 -            vector unsigned char vdst1, vdst2;
  13.368 -            vector unsigned short vR, vG, vB;
  13.369 -            vector unsigned short vpixel, vrpixel, vgpixel, vbpixel;
  13.370 -
  13.371 -            /* Load 8 pixels from src as ARGB */
  13.372 -            voverflow = (vector unsigned char) vec_ld(15, src);
  13.373 -            vsrc = vec_perm(vsrc, voverflow, valigner);
  13.374 -            vsrc1 = vec_perm(vsrc, vsrc, vpermute);
  13.375 -            src += 16;
  13.376 -            vsrc = (vector unsigned char) vec_ld(15, src);
  13.377 -            voverflow = vec_perm(voverflow, vsrc, valigner);
  13.378 -            vsrc2 = vec_perm(voverflow, voverflow, vpermute);
  13.379 -            src += 16;
  13.380 -
  13.381 -            /* Load 8 pixels from dst as XRGB */
  13.382 -            voverflow = vec_ld(0, dst);
  13.383 -            vR = vec_and((vector unsigned short) voverflow, vf800);
  13.384 -            vB = vec_sl((vector unsigned short) voverflow, v3_16);
  13.385 -            vG = vec_sl(vB, v2_16);
  13.386 -            vdst1 =
  13.387 -                (vector unsigned char) vec_perm((vector unsigned char) vR,
  13.388 -                                                (vector unsigned char) vR,
  13.389 -                                                vredalpha1);
  13.390 -            vdst1 = vec_perm(vdst1, (vector unsigned char) vB, vblue1);
  13.391 -            vdst1 = vec_perm(vdst1, (vector unsigned char) vG, vgreen1);
  13.392 -            vdst2 =
  13.393 -                (vector unsigned char) vec_perm((vector unsigned char) vR,
  13.394 -                                                (vector unsigned char) vR,
  13.395 -                                                vredalpha2);
  13.396 -            vdst2 = vec_perm(vdst2, (vector unsigned char) vB, vblue2);
  13.397 -            vdst2 = vec_perm(vdst2, (vector unsigned char) vG, vgreen2);
  13.398 -
  13.399 -            /* Alpha blend 8 pixels as ARGB */
  13.400 -            valpha = vec_perm(vsrc1, v0, valphaPermute);
  13.401 -            VEC_MULTIPLY_ALPHA(vsrc1, vdst1, valpha, mergePermute, v1_16,
  13.402 -                               v8_16);
  13.403 -            valpha = vec_perm(vsrc2, v0, valphaPermute);
  13.404 -            VEC_MULTIPLY_ALPHA(vsrc2, vdst2, valpha, mergePermute, v1_16,
  13.405 -                               v8_16);
  13.406 -
  13.407 -            /* Convert 8 pixels to 565 */
  13.408 -            vpixel = (vector unsigned short) vec_packpx((vector unsigned int)
  13.409 -                                                        vdst1,
  13.410 -                                                        (vector unsigned int)
  13.411 -                                                        vdst2);
  13.412 -            vgpixel = (vector unsigned short) vec_perm(vdst1, vdst2, vgmerge);
  13.413 -            vgpixel = vec_and(vgpixel, vfc);
  13.414 -            vgpixel = vec_sl(vgpixel, v3_16);
  13.415 -            vrpixel = vec_sl(vpixel, v1_16);
  13.416 -            vrpixel = vec_and(vrpixel, vf800);
  13.417 -            vbpixel = vec_and(vpixel, v3f);
  13.418 -            vdst1 =
  13.419 -                vec_or((vector unsigned char) vrpixel,
  13.420 -                       (vector unsigned char) vgpixel);
  13.421 -            vdst1 = vec_or(vdst1, (vector unsigned char) vbpixel);
  13.422 -
  13.423 -            /* Store 8 pixels */
  13.424 -            vec_st(vdst1, 0, dst);
  13.425 -
  13.426 -            width -= 8;
  13.427 -            dst += 16;
  13.428 -        }
  13.429 -        ONE_PIXEL_BLEND((extrawidth), extrawidth);
  13.430 -#undef ONE_PIXEL_BLEND
  13.431 -        src += srcskip;
  13.432 -        dst += dstskip;
  13.433 -    }
  13.434 -}
  13.435 -
  13.436 -static void
  13.437 -Blit32to32SurfaceAlphaKeyAltivec(SDL_BlitInfo * info)
  13.438 -{
  13.439 -    int height = info->dst_h;
  13.440 -    Uint32 *srcp = (Uint32 *) info->src;
  13.441 -    int srcskip = info->src_skip >> 2;
  13.442 -    Uint32 *dstp = (Uint32 *) info->dst;
  13.443 -    int dstskip = info->dst_skip >> 2;
  13.444 -    SDL_PixelFormat *srcfmt = info->src_fmt;
  13.445 -    SDL_PixelFormat *dstfmt = info->dst_fmt;
  13.446 -    unsigned sA = info->a;
  13.447 -    unsigned dA = dstfmt->Amask ? SDL_ALPHA_OPAQUE : 0;
  13.448 -    Uint32 rgbmask = srcfmt->Rmask | srcfmt->Gmask | srcfmt->Bmask;
  13.449 -    Uint32 ckey = info->colorkey;
  13.450 -    vector unsigned char mergePermute;
  13.451 -    vector unsigned char vsrcPermute;
  13.452 -    vector unsigned char vdstPermute;
  13.453 -    vector unsigned char vsdstPermute;
  13.454 -    vector unsigned char valpha;
  13.455 -    vector unsigned char valphamask;
  13.456 -    vector unsigned char vbits;
  13.457 -    vector unsigned char v0;
  13.458 -    vector unsigned short v1;
  13.459 -    vector unsigned short v8;
  13.460 -    vector unsigned int vckey;
  13.461 -    vector unsigned int vrgbmask;
  13.462 -
  13.463 -    mergePermute = VEC_MERGE_PERMUTE();
  13.464 -    v0 = vec_splat_u8(0);
  13.465 -    v1 = vec_splat_u16(1);
  13.466 -    v8 = vec_splat_u16(8);
  13.467 -
  13.468 -    /* set the alpha to 255 on the destination surf */
  13.469 -    valphamask = VEC_ALPHA_MASK();
  13.470 -
  13.471 -    vsrcPermute = calc_swizzle32(srcfmt, NULL);
  13.472 -    vdstPermute = calc_swizzle32(NULL, dstfmt);
  13.473 -    vsdstPermute = calc_swizzle32(dstfmt, NULL);
  13.474 -
  13.475 -    /* set a vector full of alpha and 255-alpha */
  13.476 -    ((unsigned char *) &valpha)[0] = sA;
  13.477 -    valpha = vec_splat(valpha, 0);
  13.478 -    vbits = (vector unsigned char) vec_splat_s8(-1);
  13.479 -
  13.480 -    ckey &= rgbmask;
  13.481 -    ((unsigned int *) (char *) &vckey)[0] = ckey;
  13.482 -    vckey = vec_splat(vckey, 0);
  13.483 -    ((unsigned int *) (char *) &vrgbmask)[0] = rgbmask;
  13.484 -    vrgbmask = vec_splat(vrgbmask, 0);
  13.485 -
  13.486 -    while (height--) {
  13.487 -        int width = info->dst_w;
  13.488 -#define ONE_PIXEL_BLEND(condition, widthvar) \
  13.489 -        while (condition) { \
  13.490 -            Uint32 Pixel; \
  13.491 -            unsigned sR, sG, sB, dR, dG, dB; \
  13.492 -            RETRIEVE_RGB_PIXEL(((Uint8 *)srcp), 4, Pixel); \
  13.493 -            if(sA && Pixel != ckey) { \
  13.494 -                RGB_FROM_PIXEL(Pixel, srcfmt, sR, sG, sB); \
  13.495 -                DISEMBLE_RGB(((Uint8 *)dstp), 4, dstfmt, Pixel, dR, dG, dB); \
  13.496 -                ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB); \
  13.497 -                ASSEMBLE_RGBA(((Uint8 *)dstp), 4, dstfmt, dR, dG, dB, dA); \
  13.498 -            } \
  13.499 -            dstp++; \
  13.500 -            srcp++; \
  13.501 -            widthvar--; \
  13.502 -        }
  13.503 -        ONE_PIXEL_BLEND((UNALIGNED_PTR(dstp)) && (width), width);
  13.504 -        if (width > 0) {
  13.505 -            int extrawidth = (width % 4);
  13.506 -            vector unsigned char valigner = VEC_ALIGNER(srcp);
  13.507 -            vector unsigned char vs = (vector unsigned char) vec_ld(0, srcp);
  13.508 -            width -= extrawidth;
  13.509 -            while (width) {
  13.510 -                vector unsigned char vsel;
  13.511 -                vector unsigned char voverflow;
  13.512 -                vector unsigned char vd;
  13.513 -                vector unsigned char vd_orig;
  13.514 -
  13.515 -                /* s = *srcp */
  13.516 -                voverflow = (vector unsigned char) vec_ld(15, srcp);
  13.517 -                vs = vec_perm(vs, voverflow, valigner);
  13.518 -
  13.519 -                /* vsel is set for items that match the key */
  13.520 -                vsel =
  13.521 -                    (vector unsigned char) vec_and((vector unsigned int) vs,
  13.522 -                                                   vrgbmask);
  13.523 -                vsel = (vector unsigned char) vec_cmpeq((vector unsigned int)
  13.524 -                                                        vsel, vckey);
  13.525 -
  13.526 -                /* permute to source format */
  13.527 -                vs = vec_perm(vs, valpha, vsrcPermute);
  13.528 -
  13.529 -                /* d = *dstp */
  13.530 -                vd = (vector unsigned char) vec_ld(0, dstp);
  13.531 -                vd_orig = vd = vec_perm(vd, v0, vsdstPermute);
  13.532 -
  13.533 -                VEC_MULTIPLY_ALPHA(vs, vd, valpha, mergePermute, v1, v8);
  13.534 -
  13.535 -                /* set the alpha channel to full on */
  13.536 -                vd = vec_or(vd, valphamask);
  13.537 -
  13.538 -                /* mask out color key */
  13.539 -                vd = vec_sel(vd, vd_orig, vsel);
  13.540 -
  13.541 -                /* permute to dest format */
  13.542 -                vd = vec_perm(vd, vbits, vdstPermute);
  13.543 -
  13.544 -                /* *dstp = res */
  13.545 -                vec_st((vector unsigned int) vd, 0, dstp);
  13.546 -
  13.547 -                srcp += 4;
  13.548 -                dstp += 4;
  13.549 -                width -= 4;
  13.550 -                vs = voverflow;
  13.551 -            }
  13.552 -            ONE_PIXEL_BLEND((extrawidth), extrawidth);
  13.553 -        }
  13.554 -#undef ONE_PIXEL_BLEND
  13.555 -
  13.556 -        srcp += srcskip;
  13.557 -        dstp += dstskip;
  13.558 -    }
  13.559 -}
  13.560 -
  13.561 -
  13.562 -static void
  13.563 -Blit32to32PixelAlphaAltivec(SDL_BlitInfo * info)
  13.564 -{
  13.565 -    int width = info->dst_w;
  13.566 -    int height = info->dst_h;
  13.567 -    Uint32 *srcp = (Uint32 *) info->src;
  13.568 -    int srcskip = info->src_skip >> 2;
  13.569 -    Uint32 *dstp = (Uint32 *) info->dst;
  13.570 -    int dstskip = info->dst_skip >> 2;
  13.571 -    SDL_PixelFormat *srcfmt = info->src_fmt;
  13.572 -    SDL_PixelFormat *dstfmt = info->dst_fmt;
  13.573 -    vector unsigned char mergePermute;
  13.574 -    vector unsigned char valphaPermute;
  13.575 -    vector unsigned char vsrcPermute;
  13.576 -    vector unsigned char vdstPermute;
  13.577 -    vector unsigned char vsdstPermute;
  13.578 -    vector unsigned char valphamask;
  13.579 -    vector unsigned char vpixelmask;
  13.580 -    vector unsigned char v0;
  13.581 -    vector unsigned short v1;
  13.582 -    vector unsigned short v8;
  13.583 -
  13.584 -    v0 = vec_splat_u8(0);
  13.585 -    v1 = vec_splat_u16(1);
  13.586 -    v8 = vec_splat_u16(8);
  13.587 -    mergePermute = VEC_MERGE_PERMUTE();
  13.588 -    valphamask = VEC_ALPHA_MASK();
  13.589 -    valphaPermute = vec_and(vec_lvsl(0, (int *) NULL), vec_splat_u8(0xC));
  13.590 -    vpixelmask = vec_nor(valphamask, v0);
  13.591 -    vsrcPermute = calc_swizzle32(srcfmt, NULL);
  13.592 -    vdstPermute = calc_swizzle32(NULL, dstfmt);
  13.593 -    vsdstPermute = calc_swizzle32(dstfmt, NULL);
  13.594 -
  13.595 -    while (height--) {
  13.596 -        width = info->dst_w;
  13.597 -#define ONE_PIXEL_BLEND(condition, widthvar) while ((condition)) { \
  13.598 -            Uint32 Pixel; \
  13.599 -            unsigned sR, sG, sB, dR, dG, dB, sA, dA; \
  13.600 -            DISEMBLE_RGBA((Uint8 *)srcp, 4, srcfmt, Pixel, sR, sG, sB, sA); \
  13.601 -            if(sA) { \
  13.602 -              DISEMBLE_RGBA((Uint8 *)dstp, 4, dstfmt, Pixel, dR, dG, dB, dA); \
  13.603 -              ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB); \
  13.604 -              ASSEMBLE_RGBA((Uint8 *)dstp, 4, dstfmt, dR, dG, dB, dA); \
  13.605 -            } \
  13.606 -            ++srcp; \
  13.607 -            ++dstp; \
  13.608 -            widthvar--; \
  13.609 -        }
  13.610 -        ONE_PIXEL_BLEND((UNALIGNED_PTR(dstp)) && (width), width);
  13.611 -        if (width > 0) {
  13.612 -            /* vsrcPermute */
  13.613 -            /* vdstPermute */
  13.614 -            int extrawidth = (width % 4);
  13.615 -            vector unsigned char valigner = VEC_ALIGNER(srcp);
  13.616 -            vector unsigned char vs = (vector unsigned char) vec_ld(0, srcp);
  13.617 -            width -= extrawidth;
  13.618 -            while (width) {
  13.619 -                vector unsigned char voverflow;
  13.620 -                vector unsigned char vd;
  13.621 -                vector unsigned char valpha;
  13.622 -                vector unsigned char vdstalpha;
  13.623 -                /* s = *srcp */
  13.624 -                voverflow = (vector unsigned char) vec_ld(15, srcp);
  13.625 -                vs = vec_perm(vs, voverflow, valigner);
  13.626 -                vs = vec_perm(vs, v0, vsrcPermute);
  13.627 -
  13.628 -                valpha = vec_perm(vs, v0, valphaPermute);
  13.629 -
  13.630 -                /* d = *dstp */
  13.631 -                vd = (vector unsigned char) vec_ld(0, dstp);
  13.632 -                vd = vec_perm(vd, v0, vsdstPermute);
  13.633 -                vdstalpha = vec_and(vd, valphamask);
  13.634 -
  13.635 -                VEC_MULTIPLY_ALPHA(vs, vd, valpha, mergePermute, v1, v8);
  13.636 -
  13.637 -                /* set the alpha to the dest alpha */
  13.638 -                vd = vec_and(vd, vpixelmask);
  13.639 -                vd = vec_or(vd, vdstalpha);
  13.640 -                vd = vec_perm(vd, v0, vdstPermute);
  13.641 -
  13.642 -                /* *dstp = res */
  13.643 -                vec_st((vector unsigned int) vd, 0, dstp);
  13.644 -
  13.645 -                srcp += 4;
  13.646 -                dstp += 4;
  13.647 -                width -= 4;
  13.648 -                vs = voverflow;
  13.649 -
  13.650 -            }
  13.651 -            ONE_PIXEL_BLEND((extrawidth), extrawidth);
  13.652 -        }
  13.653 -        srcp += srcskip;
  13.654 -        dstp += dstskip;
  13.655 -#undef ONE_PIXEL_BLEND
  13.656 -    }
  13.657 -}
  13.658 -
  13.659 -/* fast ARGB888->(A)RGB888 blending with pixel alpha */
  13.660 -static void
  13.661 -BlitRGBtoRGBPixelAlphaAltivec(SDL_BlitInfo * info)
  13.662 -{
  13.663 -    int width = info->dst_w;
  13.664 -    int height = info->dst_h;
  13.665 -    Uint32 *srcp = (Uint32 *) info->src;
  13.666 -    int srcskip = info->src_skip >> 2;
  13.667 -    Uint32 *dstp = (Uint32 *) info->dst;
  13.668 -    int dstskip = info->dst_skip >> 2;
  13.669 -    vector unsigned char mergePermute;
  13.670 -    vector unsigned char valphaPermute;
  13.671 -    vector unsigned char valphamask;
  13.672 -    vector unsigned char vpixelmask;
  13.673 -    vector unsigned char v0;
  13.674 -    vector unsigned short v1;
  13.675 -    vector unsigned short v8;
  13.676 -    v0 = vec_splat_u8(0);
  13.677 -    v1 = vec_splat_u16(1);
  13.678 -    v8 = vec_splat_u16(8);
  13.679 -    mergePermute = VEC_MERGE_PERMUTE();
  13.680 -    valphamask = VEC_ALPHA_MASK();
  13.681 -    valphaPermute = vec_and(vec_lvsl(0, (int *) NULL), vec_splat_u8(0xC));
  13.682 -
  13.683 -
  13.684 -    vpixelmask = vec_nor(valphamask, v0);
  13.685 -    while (height--) {
  13.686 -        width = info->dst_w;
  13.687 -#define ONE_PIXEL_BLEND(condition, widthvar) \
  13.688 -        while ((condition)) { \
  13.689 -            Uint32 dalpha; \
  13.690 -            Uint32 d; \
  13.691 -            Uint32 s1; \
  13.692 -            Uint32 d1; \
  13.693 -            Uint32 s = *srcp; \
  13.694 -            Uint32 alpha = s >> 24; \
  13.695 -            if(alpha) { \
  13.696 -              if(alpha == SDL_ALPHA_OPAQUE) { \
  13.697 -                *dstp = (s & 0x00ffffff) | (*dstp & 0xff000000); \
  13.698 -              } else { \
  13.699 -                d = *dstp; \
  13.700 -                dalpha = d & 0xff000000; \
  13.701 -                s1 = s & 0xff00ff; \
  13.702 -                d1 = d & 0xff00ff; \
  13.703 -                d1 = (d1 + ((s1 - d1) * alpha >> 8)) & 0xff00ff; \
  13.704 -                s &= 0xff00; \
  13.705 -                d &= 0xff00; \
  13.706 -                d = (d + ((s - d) * alpha >> 8)) & 0xff00; \
  13.707 -                *dstp = d1 | d | dalpha; \
  13.708 -              } \
  13.709 -            } \
  13.710 -            ++srcp; \
  13.711 -            ++dstp; \
  13.712 -            widthvar--; \
  13.713 -	    }
  13.714 -        ONE_PIXEL_BLEND((UNALIGNED_PTR(dstp)) && (width), width);
  13.715 -        if (width > 0) {
  13.716 -            int extrawidth = (width % 4);
  13.717 -            vector unsigned char valigner = VEC_ALIGNER(srcp);
  13.718 -            vector unsigned char vs = (vector unsigned char) vec_ld(0, srcp);
  13.719 -            width -= extrawidth;
  13.720 -            while (width) {
  13.721 -                vector unsigned char voverflow;
  13.722 -                vector unsigned char vd;
  13.723 -                vector unsigned char valpha;
  13.724 -                vector unsigned char vdstalpha;
  13.725 -                /* s = *srcp */
  13.726 -                voverflow = (vector unsigned char) vec_ld(15, srcp);
  13.727 -                vs = vec_perm(vs, voverflow, valigner);
  13.728 -
  13.729 -                valpha = vec_perm(vs, v0, valphaPermute);
  13.730 -
  13.731 -                /* d = *dstp */
  13.732 -                vd = (vector unsigned char) vec_ld(0, dstp);
  13.733 -                vdstalpha = vec_and(vd, valphamask);
  13.734 -
  13.735 -                VEC_MULTIPLY_ALPHA(vs, vd, valpha, mergePermute, v1, v8);
  13.736 -
  13.737 -                /* set the alpha to the dest alpha */
  13.738 -                vd = vec_and(vd, vpixelmask);
  13.739 -                vd = vec_or(vd, vdstalpha);
  13.740 -
  13.741 -                /* *dstp = res */
  13.742 -                vec_st((vector unsigned int) vd, 0, dstp);
  13.743 -
  13.744 -                srcp += 4;
  13.745 -                dstp += 4;
  13.746 -                width -= 4;
  13.747 -                vs = voverflow;
  13.748 -            }
  13.749 -            ONE_PIXEL_BLEND((extrawidth), extrawidth);
  13.750 -        }
  13.751 -        srcp += srcskip;
  13.752 -        dstp += dstskip;
  13.753 -    }
  13.754 -#undef ONE_PIXEL_BLEND
  13.755 -}
  13.756 -
  13.757 -static void
  13.758 -Blit32to32SurfaceAlphaAltivec(SDL_BlitInfo * info)
  13.759 -{
  13.760 -    /* XXX : 6 */
  13.761 -    int height = info->dst_h;
  13.762 -    Uint32 *srcp = (Uint32 *) info->src;
  13.763 -    int srcskip = info->src_skip >> 2;
  13.764 -    Uint32 *dstp = (Uint32 *) info->dst;
  13.765 -    int dstskip = info->dst_skip >> 2;
  13.766 -    SDL_PixelFormat *srcfmt = info->src_fmt;
  13.767 -    SDL_PixelFormat *dstfmt = info->dst_fmt;
  13.768 -    unsigned sA = info->a;
  13.769 -    unsigned dA = dstfmt->Amask ? SDL_ALPHA_OPAQUE : 0;
  13.770 -    vector unsigned char mergePermute;
  13.771 -    vector unsigned char vsrcPermute;
  13.772 -    vector unsigned char vdstPermute;
  13.773 -    vector unsigned char vsdstPermute;
  13.774 -    vector unsigned char valpha;
  13.775 -    vector unsigned char valphamask;
  13.776 -    vector unsigned char vbits;
  13.777 -    vector unsigned short v1;
  13.778 -    vector unsigned short v8;
  13.779 -
  13.780 -    mergePermute = VEC_MERGE_PERMUTE();
  13.781 -    v1 = vec_splat_u16(1);
  13.782 -    v8 = vec_splat_u16(8);
  13.783 -
  13.784 -    /* set the alpha to 255 on the destination surf */
  13.785 -    valphamask = VEC_ALPHA_MASK();
  13.786 -
  13.787 -    vsrcPermute = calc_swizzle32(srcfmt, NULL);
  13.788 -    vdstPermute = calc_swizzle32(NULL, dstfmt);
  13.789 -    vsdstPermute = calc_swizzle32(dstfmt, NULL);
  13.790 -
  13.791 -    /* set a vector full of alpha and 255-alpha */
  13.792 -    ((unsigned char *) &valpha)[0] = sA;
  13.793 -    valpha = vec_splat(valpha, 0);
  13.794 -    vbits = (vector unsigned char) vec_splat_s8(-1);
  13.795 -
  13.796 -    while (height--) {
  13.797 -        int width = info->dst_w;
  13.798 -#define ONE_PIXEL_BLEND(condition, widthvar) while ((condition)) { \
  13.799 -            Uint32 Pixel; \
  13.800 -            unsigned sR, sG, sB, dR, dG, dB; \
  13.801 -            DISEMBLE_RGB(((Uint8 *)srcp), 4, srcfmt, Pixel, sR, sG, sB); \
  13.802 -            DISEMBLE_RGB(((Uint8 *)dstp), 4, dstfmt, Pixel, dR, dG, dB); \
  13.803 -            ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB); \
  13.804 -            ASSEMBLE_RGBA(((Uint8 *)dstp), 4, dstfmt, dR, dG, dB, dA); \
  13.805 -            ++srcp; \
  13.806 -            ++dstp; \
  13.807 -            widthvar--; \
  13.808 -        }
  13.809 -        ONE_PIXEL_BLEND((UNALIGNED_PTR(dstp)) && (width), width);
  13.810 -        if (width > 0) {
  13.811 -            int extrawidth = (width % 4);
  13.812 -            vector unsigned char valigner = VEC_ALIGNER(srcp);
  13.813 -            vector unsigned char vs = (vector unsigned char) vec_ld(0, srcp);
  13.814 -            width -= extrawidth;
  13.815 -            while (width) {
  13.816 -                vector unsigned char voverflow;
  13.817 -                vector unsigned char vd;
  13.818 -
  13.819 -                /* s = *srcp */
  13.820 -                voverflow = (vector unsigned char) vec_ld(15, srcp);
  13.821 -                vs = vec_perm(vs, voverflow, valigner);
  13.822 -                vs = vec_perm(vs, valpha, vsrcPermute);
  13.823 -
  13.824 -                /* d = *dstp */
  13.825 -                vd = (vector unsigned char) vec_ld(0, dstp);
  13.826 -                vd = vec_perm(vd, vd, vsdstPermute);
  13.827 -
  13.828 -                VEC_MULTIPLY_ALPHA(vs, vd, valpha, mergePermute, v1, v8);
  13.829 -
  13.830 -                /* set the alpha channel to full on */
  13.831 -                vd = vec_or(vd, valphamask);
  13.832 -                vd = vec_perm(vd, vbits, vdstPermute);
  13.833 -
  13.834 -                /* *dstp = res */
  13.835 -                vec_st((vector unsigned int) vd, 0, dstp);
  13.836 -
  13.837 -                srcp += 4;
  13.838 -                dstp += 4;
  13.839 -                width -= 4;
  13.840 -                vs = voverflow;
  13.841 -            }
  13.842 -            ONE_PIXEL_BLEND((extrawidth), extrawidth);
  13.843 -        }
  13.844 -#undef ONE_PIXEL_BLEND
  13.845 -
  13.846 -        srcp += srcskip;
  13.847 -        dstp += dstskip;
  13.848 -    }
  13.849 -
  13.850 -}
  13.851 -
  13.852 -
  13.853 -/* fast RGB888->(A)RGB888 blending */
  13.854 -static void
  13.855 -BlitRGBtoRGBSurfaceAlphaAltivec(SDL_BlitInfo * info)
  13.856 -{
  13.857 -    unsigned alpha = info->a;
  13.858 -    int height = info->dst_h;
  13.859 -    Uint32 *srcp = (Uint32 *) info->src;
  13.860 -    int srcskip = info->src_skip >> 2;
  13.861 -    Uint32 *dstp = (Uint32 *) info->dst;
  13.862 -    int dstskip = info->dst_skip >> 2;
  13.863 -    vector unsigned char mergePermute;
  13.864 -    vector unsigned char valpha;
  13.865 -    vector unsigned char valphamask;
  13.866 -    vector unsigned short v1;
  13.867 -    vector unsigned short v8;
  13.868 -
  13.869 -    mergePermute = VEC_MERGE_PERMUTE();
  13.870 -    v1 = vec_splat_u16(1);
  13.871 -    v8 = vec_splat_u16(8);
  13.872 -
  13.873 -    /* set the alpha to 255 on the destination surf */
  13.874 -    valphamask = VEC_ALPHA_MASK();
  13.875 -
  13.876 -    /* set a vector full of alpha and 255-alpha */
  13.877 -    ((unsigned char *) &valpha)[0] = alpha;
  13.878 -    valpha = vec_splat(valpha, 0);
  13.879 -
  13.880 -    while (height--) {
  13.881 -        int width = info->dst_w;
  13.882 -#define ONE_PIXEL_BLEND(condition, widthvar) while ((condition)) { \
  13.883 -            Uint32 s = *srcp; \
  13.884 -            Uint32 d = *dstp; \
  13.885 -            Uint32 s1 = s & 0xff00ff; \
  13.886 -            Uint32 d1 = d & 0xff00ff; \
  13.887 -            d1 = (d1 + ((s1 - d1) * alpha >> 8)) \
  13.888 -                 & 0xff00ff; \
  13.889 -            s &= 0xff00; \
  13.890 -            d &= 0xff00; \
  13.891 -            d = (d + ((s - d) * alpha >> 8)) & 0xff00; \
  13.892 -            *dstp = d1 | d | 0xff000000; \
  13.893 -            ++srcp; \
  13.894 -            ++dstp; \
  13.895 -            widthvar--; \
  13.896 -        }
  13.897 -        ONE_PIXEL_BLEND((UNALIGNED_PTR(dstp)) && (width), width);
  13.898 -        if (width > 0) {
  13.899 -            int extrawidth = (width % 4);
  13.900 -            vector unsigned char valigner = VEC_ALIGNER(srcp);
  13.901 -            vector unsigned char vs = (vector unsigned char) vec_ld(0, srcp);
  13.902 -            width -= extrawidth;
  13.903 -            while (width) {
  13.904 -                vector unsigned char voverflow;
  13.905 -                vector unsigned char vd;
  13.906 -
  13.907 -                /* s = *srcp */
  13.908 -                voverflow = (vector unsigned char) vec_ld(15, srcp);
  13.909 -                vs = vec_perm(vs, voverflow, valigner);
  13.910 -
  13.911 -                /* d = *dstp */
  13.912 -                vd = (vector unsigned char) vec_ld(0, dstp);
  13.913 -
  13.914 -                VEC_MULTIPLY_ALPHA(vs, vd, valpha, mergePermute, v1, v8);
  13.915 -
  13.916 -                /* set the alpha channel to full on */
  13.917 -                vd = vec_or(vd, valphamask);
  13.918 -
  13.919 -                /* *dstp = res */
  13.920 -                vec_st((vector unsigned int) vd, 0, dstp);
  13.921 -
  13.922 -                srcp += 4;
  13.923 -                dstp += 4;
  13.924 -                width -= 4;
  13.925 -                vs = voverflow;
  13.926 -            }
  13.927 -            ONE_PIXEL_BLEND((extrawidth), extrawidth);
  13.928 -        }
  13.929 -#undef ONE_PIXEL_BLEND
  13.930 -
  13.931 -        srcp += srcskip;
  13.932 -        dstp += dstskip;
  13.933 -    }
  13.934 -}
  13.935 -
  13.936 -#if __MWERKS__
  13.937 -#pragma altivec_model off
  13.938 -#endif
  13.939 -#endif /* SDL_ALTIVEC_BLITTERS */
  13.940 -
  13.941  /* fast RGB888->(A)RGB888 blending with surface alpha=128 special case */
  13.942  static void
  13.943  BlitRGBtoRGBSurfaceAlpha128(SDL_BlitInfo * info)
  13.944 @@ -1984,24 +1156,19 @@
  13.945      SDL_PixelFormat *dstfmt = info->dst_fmt;
  13.946      int srcbpp = srcfmt->BytesPerPixel;
  13.947      int dstbpp = dstfmt->BytesPerPixel;
  13.948 -    unsigned sA = info->a;
  13.949 -    unsigned dA = dstfmt->Amask ? SDL_ALPHA_OPAQUE : 0;
  13.950 +    Uint32 Pixel;
  13.951 +    unsigned sR, sG, sB;
  13.952 +    unsigned dR, dG, dB, dA;
  13.953 +    const unsigned sA = info->a;
  13.954  
  13.955      if (sA) {
  13.956          while (height--) {
  13.957  	    /* *INDENT-OFF* */
  13.958  	    DUFFS_LOOP4(
  13.959  	    {
  13.960 -		Uint32 Pixel;
  13.961 -		unsigned sR;
  13.962 -		unsigned sG;
  13.963 -		unsigned sB;
  13.964 -		unsigned dR;
  13.965 -		unsigned dG;
  13.966 -		unsigned dB;
  13.967  		DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, sR, sG, sB);
  13.968 -		DISEMBLE_RGB(dst, dstbpp, dstfmt, Pixel, dR, dG, dB);
  13.969 -		ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB);
  13.970 +		DISEMBLE_RGBA(dst, dstbpp, dstfmt, Pixel, dR, dG, dB, dA);
  13.971 +		ALPHA_BLEND_RGBA(sR, sG, sB, sA, dR, dG, dB, dA);
  13.972  		ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA);
  13.973  		src += srcbpp;
  13.974  		dst += dstbpp;
  13.975 @@ -2029,25 +1196,20 @@
  13.976      Uint32 ckey = info->colorkey;
  13.977      int srcbpp = srcfmt->BytesPerPixel;
  13.978      int dstbpp = dstfmt->BytesPerPixel;
  13.979 -    unsigned sA = info->a;
  13.980 -    unsigned dA = dstfmt->Amask ? SDL_ALPHA_OPAQUE : 0;
  13.981 +    Uint32 Pixel;
  13.982 +    unsigned sR, sG, sB;
  13.983 +    unsigned dR, dG, dB, dA;
  13.984 +    const unsigned sA = info->a;
  13.985  
  13.986      while (height--) {
  13.987  	    /* *INDENT-OFF* */
  13.988  	    DUFFS_LOOP4(
  13.989  	    {
  13.990 -		Uint32 Pixel;
  13.991 -		unsigned sR;
  13.992 -		unsigned sG;
  13.993 -		unsigned sB;
  13.994 -		unsigned dR;
  13.995 -		unsigned dG;
  13.996 -		unsigned dB;
  13.997  		RETRIEVE_RGB_PIXEL(src, srcbpp, Pixel);
  13.998  		if(sA && Pixel != ckey) {
  13.999  		    RGB_FROM_PIXEL(Pixel, srcfmt, sR, sG, sB);
 13.1000 -		    DISEMBLE_RGB(dst, dstbpp, dstfmt, Pixel, dR, dG, dB);
 13.1001 -		    ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB);
 13.1002 +		    DISEMBLE_RGBA(dst, dstbpp, dstfmt, Pixel, dR, dG, dB, dA);
 13.1003 +		    ALPHA_BLEND_RGBA(sR, sG, sB, sA, dR, dG, dB, dA);
 13.1004  		    ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA);
 13.1005  		}
 13.1006  		src += srcbpp;
 13.1007 @@ -2072,9 +1234,11 @@
 13.1008      int dstskip = info->dst_skip;
 13.1009      SDL_PixelFormat *srcfmt = info->src_fmt;
 13.1010      SDL_PixelFormat *dstfmt = info->dst_fmt;
 13.1011 -
 13.1012      int srcbpp;
 13.1013      int dstbpp;
 13.1014 +    Uint32 Pixel;
 13.1015 +    unsigned sR, sG, sB, sA;
 13.1016 +    unsigned dR, dG, dB, dA;
 13.1017  
 13.1018      /* Set up some basic variables */
 13.1019      srcbpp = srcfmt->BytesPerPixel;
 13.1020 @@ -2084,20 +1248,11 @@
 13.1021  	    /* *INDENT-OFF* */
 13.1022  	    DUFFS_LOOP4(
 13.1023  	    {
 13.1024 -		Uint32 Pixel;
 13.1025 -		unsigned sR;
 13.1026 -		unsigned sG;
 13.1027 -		unsigned sB;
 13.1028 -		unsigned dR;
 13.1029 -		unsigned dG;
 13.1030 -		unsigned dB;
 13.1031 -		unsigned sA;
 13.1032 -		unsigned dA;
 13.1033  		DISEMBLE_RGBA(src, srcbpp, srcfmt, Pixel, sR, sG, sB, sA);
 13.1034  		if(sA) {
 13.1035 -		  DISEMBLE_RGBA(dst, dstbpp, dstfmt, Pixel, dR, dG, dB, dA);
 13.1036 -		  ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB);
 13.1037 -		  ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA);
 13.1038 +		    DISEMBLE_RGBA(dst, dstbpp, dstfmt, Pixel, dR, dG, dB, dA);
 13.1039 +		    ALPHA_BLEND_RGBA(sR, sG, sB, sA, dR, dG, dB, dA);
 13.1040 +		    ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA);
 13.1041  		}
 13.1042  		src += srcbpp;
 13.1043  		dst += dstbpp;
 13.1044 @@ -2124,13 +1279,6 @@
 13.1045              return BlitNto1PixelAlpha;
 13.1046  
 13.1047          case 2:
 13.1048 -#if SDL_ALTIVEC_BLITTERS
 13.1049 -            if (sf->BytesPerPixel == 4
 13.1050 -                && df->Gmask == 0x7e0 && df->Bmask == 0x1f
 13.1051 -                && SDL_HasAltiVec())
 13.1052 -                return Blit32to565PixelAlphaAltivec;
 13.1053 -            else
 13.1054 -#endif
 13.1055                  if (sf->BytesPerPixel == 4 && sf->Amask == 0xff000000
 13.1056                      && sf->Gmask == 0xff00
 13.1057                      && ((sf->Rmask == 0xff && df->Rmask == 0x1f)
 13.1058 @@ -2162,19 +1310,10 @@
 13.1059                  }
 13.1060  #endif /* __MMX__ || __3dNOW__ */
 13.1061                  if (sf->Amask == 0xff000000) {
 13.1062 -#if SDL_ALTIVEC_BLITTERS
 13.1063 -                    if (SDL_HasAltiVec())
 13.1064 -                        return BlitRGBtoRGBPixelAlphaAltivec;
 13.1065 -#endif
 13.1066                      return BlitRGBtoRGBPixelAlpha;
 13.1067                  }
 13.1068              }
 13.1069 -#if SDL_ALTIVEC_BLITTERS
 13.1070 -            if (sf->Amask && sf->BytesPerPixel == 4 && SDL_HasAltiVec())
 13.1071 -                return Blit32to32PixelAlphaAltivec;
 13.1072 -            else
 13.1073 -#endif
 13.1074 -                return BlitNtoNPixelAlpha;
 13.1075 +            return BlitNtoNPixelAlpha;
 13.1076  
 13.1077          case 3:
 13.1078          default:
 13.1079 @@ -2220,19 +1359,10 @@
 13.1080                          return BlitRGBtoRGBSurfaceAlphaMMX;
 13.1081  #endif
 13.1082                      if ((sf->Rmask | sf->Gmask | sf->Bmask) == 0xffffff) {
 13.1083 -#if SDL_ALTIVEC_BLITTERS
 13.1084 -                        if (SDL_HasAltiVec())
 13.1085 -                            return BlitRGBtoRGBSurfaceAlphaAltivec;
 13.1086 -#endif
 13.1087                          return BlitRGBtoRGBSurfaceAlpha;
 13.1088                      }
 13.1089                  }
 13.1090 -#if SDL_ALTIVEC_BLITTERS
 13.1091 -                if ((sf->BytesPerPixel == 4) && SDL_HasAltiVec())
 13.1092 -                    return Blit32to32SurfaceAlphaAltivec;
 13.1093 -                else
 13.1094 -#endif
 13.1095 -                    return BlitNtoNSurfaceAlpha;
 13.1096 +                return BlitNtoNSurfaceAlpha;
 13.1097  
 13.1098              case 3:
 13.1099              default:
 13.1100 @@ -2243,16 +1373,11 @@
 13.1101  
 13.1102      case SDL_COPY_COLORKEY | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND:
 13.1103          if (sf->Amask == 0) {
 13.1104 -            if (df->BytesPerPixel == 1)
 13.1105 +            if (df->BytesPerPixel == 1) {
 13.1106                  return BlitNto1SurfaceAlphaKey;
 13.1107 -            else
 13.1108 -#if SDL_ALTIVEC_BLITTERS
 13.1109 -            if (sf->BytesPerPixel == 4 && df->BytesPerPixel == 4 &&
 13.1110 -                    SDL_HasAltiVec())
 13.1111 -                return Blit32to32SurfaceAlphaKeyAltivec;
 13.1112 -            else
 13.1113 -#endif
 13.1114 +            } else {
 13.1115                  return BlitNtoNSurfaceAlphaKey;
 13.1116 +            }
 13.1117          }
 13.1118          break;
 13.1119      }
    14.1 --- a/src/video/SDL_blit_auto.c	Mon Jul 22 02:51:45 2013 -0700
    14.2 +++ b/src/video/SDL_blit_auto.c	Tue Jul 23 08:06:49 2013 -0700
    14.3 @@ -95,6 +95,7 @@
    14.4                  dstR = srcR + ((255 - srcA) * dstR) / 255;
    14.5                  dstG = srcG + ((255 - srcA) * dstG) / 255;
    14.6                  dstB = srcB + ((255 - srcA) * dstB) / 255;
    14.7 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
    14.8                  break;
    14.9              case SDL_COPY_ADD:
   14.10                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
   14.11 @@ -168,6 +169,7 @@
   14.12                  dstR = srcR + ((255 - srcA) * dstR) / 255;
   14.13                  dstG = srcG + ((255 - srcA) * dstG) / 255;
   14.14                  dstB = srcB + ((255 - srcA) * dstB) / 255;
   14.15 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
   14.16                  break;
   14.17              case SDL_COPY_ADD:
   14.18                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
   14.19 @@ -323,6 +325,7 @@
   14.20                  dstR = srcR + ((255 - srcA) * dstR) / 255;
   14.21                  dstG = srcG + ((255 - srcA) * dstG) / 255;
   14.22                  dstB = srcB + ((255 - srcA) * dstB) / 255;
   14.23 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
   14.24                  break;
   14.25              case SDL_COPY_ADD:
   14.26                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
   14.27 @@ -408,6 +411,7 @@
   14.28                  dstR = srcR + ((255 - srcA) * dstR) / 255;
   14.29                  dstG = srcG + ((255 - srcA) * dstG) / 255;
   14.30                  dstB = srcB + ((255 - srcA) * dstB) / 255;
   14.31 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
   14.32                  break;
   14.33              case SDL_COPY_ADD:
   14.34                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
   14.35 @@ -503,6 +507,7 @@
   14.36                  dstR = srcR + ((255 - srcA) * dstR) / 255;
   14.37                  dstG = srcG + ((255 - srcA) * dstG) / 255;
   14.38                  dstB = srcB + ((255 - srcA) * dstB) / 255;
   14.39 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
   14.40                  break;
   14.41              case SDL_COPY_ADD:
   14.42                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
   14.43 @@ -576,6 +581,7 @@
   14.44                  dstR = srcR + ((255 - srcA) * dstR) / 255;
   14.45                  dstG = srcG + ((255 - srcA) * dstG) / 255;
   14.46                  dstB = srcB + ((255 - srcA) * dstB) / 255;
   14.47 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
   14.48                  break;
   14.49              case SDL_COPY_ADD:
   14.50                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
   14.51 @@ -731,6 +737,7 @@
   14.52                  dstR = srcR + ((255 - srcA) * dstR) / 255;
   14.53                  dstG = srcG + ((255 - srcA) * dstG) / 255;
   14.54                  dstB = srcB + ((255 - srcA) * dstB) / 255;
   14.55 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
   14.56                  break;
   14.57              case SDL_COPY_ADD:
   14.58                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
   14.59 @@ -816,6 +823,7 @@
   14.60                  dstR = srcR + ((255 - srcA) * dstR) / 255;
   14.61                  dstG = srcG + ((255 - srcA) * dstG) / 255;
   14.62                  dstB = srcB + ((255 - srcA) * dstB) / 255;
   14.63 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
   14.64                  break;
   14.65              case SDL_COPY_ADD:
   14.66                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
   14.67 @@ -911,6 +919,7 @@
   14.68                  dstR = srcR + ((255 - srcA) * dstR) / 255;
   14.69                  dstG = srcG + ((255 - srcA) * dstG) / 255;
   14.70                  dstB = srcB + ((255 - srcA) * dstB) / 255;
   14.71 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
   14.72                  break;
   14.73              case SDL_COPY_ADD:
   14.74                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
   14.75 @@ -984,6 +993,7 @@
   14.76                  dstR = srcR + ((255 - srcA) * dstR) / 255;
   14.77                  dstG = srcG + ((255 - srcA) * dstG) / 255;
   14.78                  dstB = srcB + ((255 - srcA) * dstB) / 255;
   14.79 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
   14.80                  break;
   14.81              case SDL_COPY_ADD:
   14.82                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
   14.83 @@ -1139,6 +1149,7 @@
   14.84                  dstR = srcR + ((255 - srcA) * dstR) / 255;
   14.85                  dstG = srcG + ((255 - srcA) * dstG) / 255;
   14.86                  dstB = srcB + ((255 - srcA) * dstB) / 255;
   14.87 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
   14.88                  break;
   14.89              case SDL_COPY_ADD:
   14.90                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
   14.91 @@ -1224,6 +1235,7 @@
   14.92                  dstR = srcR + ((255 - srcA) * dstR) / 255;
   14.93                  dstG = srcG + ((255 - srcA) * dstG) / 255;
   14.94                  dstB = srcB + ((255 - srcA) * dstB) / 255;
   14.95 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
   14.96                  break;
   14.97              case SDL_COPY_ADD:
   14.98                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
   14.99 @@ -1319,6 +1331,7 @@
  14.100                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  14.101                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  14.102                  dstB = srcB + ((255 - srcA) * dstB) / 255;
  14.103 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
  14.104                  break;
  14.105              case SDL_COPY_ADD:
  14.106                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
  14.107 @@ -1392,6 +1405,7 @@
  14.108                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  14.109                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  14.110                  dstB = srcB + ((255 - srcA) * dstB) / 255;
  14.111 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
  14.112                  break;
  14.113              case SDL_COPY_ADD:
  14.114                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
  14.115 @@ -1547,6 +1561,7 @@
  14.116                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  14.117                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  14.118                  dstB = srcB + ((255 - srcA) * dstB) / 255;
  14.119 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
  14.120                  break;
  14.121              case SDL_COPY_ADD:
  14.122                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
  14.123 @@ -1632,6 +1647,7 @@
  14.124                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  14.125                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  14.126                  dstB = srcB + ((255 - srcA) * dstB) / 255;
  14.127 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
  14.128                  break;
  14.129              case SDL_COPY_ADD:
  14.130                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
  14.131 @@ -1722,6 +1738,7 @@
  14.132                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  14.133                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  14.134                  dstB = srcB + ((255 - srcA) * dstB) / 255;
  14.135 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
  14.136                  break;
  14.137              case SDL_COPY_ADD:
  14.138                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
  14.139 @@ -1795,6 +1812,7 @@
  14.140                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  14.141                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  14.142                  dstB = srcB + ((255 - srcA) * dstB) / 255;
  14.143 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
  14.144                  break;
  14.145              case SDL_COPY_ADD:
  14.146                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
  14.147 @@ -1950,6 +1968,7 @@
  14.148                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  14.149                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  14.150                  dstB = srcB + ((255 - srcA) * dstB) / 255;
  14.151 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
  14.152                  break;
  14.153              case SDL_COPY_ADD:
  14.154                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
  14.155 @@ -2035,6 +2054,7 @@
  14.156                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  14.157                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  14.158                  dstB = srcB + ((255 - srcA) * dstB) / 255;
  14.159 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
  14.160                  break;
  14.161              case SDL_COPY_ADD:
  14.162                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
  14.163 @@ -2130,6 +2150,7 @@
  14.164                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  14.165                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  14.166                  dstB = srcB + ((255 - srcA) * dstB) / 255;
  14.167 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
  14.168                  break;
  14.169              case SDL_COPY_ADD:
  14.170                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
  14.171 @@ -2203,6 +2224,7 @@
  14.172                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  14.173                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  14.174                  dstB = srcB + ((255 - srcA) * dstB) / 255;
  14.175 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
  14.176                  break;
  14.177              case SDL_COPY_ADD:
  14.178                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
  14.179 @@ -2358,6 +2380,7 @@
  14.180                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  14.181                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  14.182                  dstB = srcB + ((255 - srcA) * dstB) / 255;
  14.183 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
  14.184                  break;
  14.185              case SDL_COPY_ADD:
  14.186                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
  14.187 @@ -2443,6 +2466,7 @@
  14.188                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  14.189                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  14.190                  dstB = srcB + ((255 - srcA) * dstB) / 255;
  14.191 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
  14.192                  break;
  14.193              case SDL_COPY_ADD:
  14.194                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
  14.195 @@ -2538,6 +2562,7 @@
  14.196                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  14.197                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  14.198                  dstB = srcB + ((255 - srcA) * dstB) / 255;
  14.199 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
  14.200                  break;
  14.201              case SDL_COPY_ADD:
  14.202                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
  14.203 @@ -2611,6 +2636,7 @@
  14.204                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  14.205                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  14.206                  dstB = srcB + ((255 - srcA) * dstB) / 255;
  14.207 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
  14.208                  break;
  14.209              case SDL_COPY_ADD:
  14.210                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
  14.211 @@ -2766,6 +2792,7 @@
  14.212                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  14.213                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  14.214                  dstB = srcB + ((255 - srcA) * dstB) / 255;
  14.215 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
  14.216                  break;
  14.217              case SDL_COPY_ADD:
  14.218                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
  14.219 @@ -2851,6 +2878,7 @@
  14.220                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  14.221                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  14.222                  dstB = srcB + ((255 - srcA) * dstB) / 255;
  14.223 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
  14.224                  break;
  14.225              case SDL_COPY_ADD:
  14.226                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
  14.227 @@ -2946,6 +2974,7 @@
  14.228                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  14.229                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  14.230                  dstB = srcB + ((255 - srcA) * dstB) / 255;
  14.231 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
  14.232                  break;
  14.233              case SDL_COPY_ADD:
  14.234                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
  14.235 @@ -3019,6 +3048,7 @@
  14.236                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  14.237                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  14.238                  dstB = srcB + ((255 - srcA) * dstB) / 255;
  14.239 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
  14.240                  break;
  14.241              case SDL_COPY_ADD:
  14.242                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
  14.243 @@ -3174,6 +3204,7 @@
  14.244                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  14.245                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  14.246                  dstB = srcB + ((255 - srcA) * dstB) / 255;
  14.247 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
  14.248                  break;
  14.249              case SDL_COPY_ADD:
  14.250                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
  14.251 @@ -3259,6 +3290,7 @@
  14.252                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  14.253                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  14.254                  dstB = srcB + ((255 - srcA) * dstB) / 255;
  14.255 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
  14.256                  break;
  14.257              case SDL_COPY_ADD:
  14.258                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
  14.259 @@ -3349,6 +3381,7 @@
  14.260                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  14.261                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  14.262                  dstB = srcB + ((255 - srcA) * dstB) / 255;
  14.263 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
  14.264                  break;
  14.265              case SDL_COPY_ADD:
  14.266                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
  14.267 @@ -3422,6 +3455,7 @@
  14.268                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  14.269                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  14.270                  dstB = srcB + ((255 - srcA) * dstB) / 255;
  14.271 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
  14.272                  break;
  14.273              case SDL_COPY_ADD:
  14.274                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
  14.275 @@ -3577,6 +3611,7 @@
  14.276                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  14.277                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  14.278                  dstB = srcB + ((255 - srcA) * dstB) / 255;
  14.279 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
  14.280                  break;
  14.281              case SDL_COPY_ADD:
  14.282                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
  14.283 @@ -3662,6 +3697,7 @@
  14.284                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  14.285                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  14.286                  dstB = srcB + ((255 - srcA) * dstB) / 255;
  14.287 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
  14.288                  break;
  14.289              case SDL_COPY_ADD:
  14.290                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
  14.291 @@ -3757,6 +3793,7 @@
  14.292                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  14.293                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  14.294                  dstB = srcB + ((255 - srcA) * dstB) / 255;
  14.295 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
  14.296                  break;
  14.297              case SDL_COPY_ADD:
  14.298                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
  14.299 @@ -3830,6 +3867,7 @@
  14.300                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  14.301                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  14.302                  dstB = srcB + ((255 - srcA) * dstB) / 255;
  14.303 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
  14.304                  break;
  14.305              case SDL_COPY_ADD:
  14.306                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
  14.307 @@ -3985,6 +4023,7 @@
  14.308                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  14.309                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  14.310                  dstB = srcB + ((255 - srcA) * dstB) / 255;
  14.311 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
  14.312                  break;
  14.313              case SDL_COPY_ADD:
  14.314                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
  14.315 @@ -4070,6 +4109,7 @@
  14.316                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  14.317                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  14.318                  dstB = srcB + ((255 - srcA) * dstB) / 255;
  14.319 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
  14.320                  break;
  14.321              case SDL_COPY_ADD:
  14.322                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
  14.323 @@ -4165,6 +4205,7 @@
  14.324                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  14.325                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  14.326                  dstB = srcB + ((255 - srcA) * dstB) / 255;
  14.327 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
  14.328                  break;
  14.329              case SDL_COPY_ADD:
  14.330                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
  14.331 @@ -4238,6 +4279,7 @@
  14.332                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  14.333                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  14.334                  dstB = srcB + ((255 - srcA) * dstB) / 255;
  14.335 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
  14.336                  break;
  14.337              case SDL_COPY_ADD:
  14.338                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
  14.339 @@ -4393,6 +4435,7 @@
  14.340                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  14.341                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  14.342                  dstB = srcB + ((255 - srcA) * dstB) / 255;
  14.343 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
  14.344                  break;
  14.345              case SDL_COPY_ADD:
  14.346                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
  14.347 @@ -4478,6 +4521,7 @@
  14.348                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  14.349                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  14.350                  dstB = srcB + ((255 - srcA) * dstB) / 255;
  14.351 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
  14.352                  break;
  14.353              case SDL_COPY_ADD:
  14.354                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
  14.355 @@ -4573,6 +4617,7 @@
  14.356                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  14.357                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  14.358                  dstB = srcB + ((255 - srcA) * dstB) / 255;
  14.359 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
  14.360                  break;
  14.361              case SDL_COPY_ADD:
  14.362                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
  14.363 @@ -4646,6 +4691,7 @@
  14.364                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  14.365                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  14.366                  dstB = srcB + ((255 - srcA) * dstB) / 255;
  14.367 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
  14.368                  break;
  14.369              case SDL_COPY_ADD:
  14.370                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
  14.371 @@ -4801,6 +4847,7 @@
  14.372                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  14.373                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  14.374                  dstB = srcB + ((255 - srcA) * dstB) / 255;
  14.375 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
  14.376                  break;
  14.377              case SDL_COPY_ADD:
  14.378                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
  14.379 @@ -4886,6 +4933,7 @@
  14.380                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  14.381                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  14.382                  dstB = srcB + ((255 - srcA) * dstB) / 255;
  14.383 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
  14.384                  break;
  14.385              case SDL_COPY_ADD:
  14.386                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
  14.387 @@ -4981,6 +5029,7 @@
  14.388                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  14.389                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  14.390                  dstB = srcB + ((255 - srcA) * dstB) / 255;
  14.391 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
  14.392                  break;
  14.393              case SDL_COPY_ADD:
  14.394                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
  14.395 @@ -5054,6 +5103,7 @@
  14.396                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  14.397                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  14.398                  dstB = srcB + ((255 - srcA) * dstB) / 255;
  14.399 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
  14.400                  break;
  14.401              case SDL_COPY_ADD:
  14.402                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
  14.403 @@ -5209,6 +5259,7 @@
  14.404                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  14.405                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  14.406                  dstB = srcB + ((255 - srcA) * dstB) / 255;
  14.407 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
  14.408                  break;
  14.409              case SDL_COPY_ADD:
  14.410                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
  14.411 @@ -5294,6 +5345,7 @@
  14.412                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  14.413                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  14.414                  dstB = srcB + ((255 - srcA) * dstB) / 255;
  14.415 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
  14.416                  break;
  14.417              case SDL_COPY_ADD:
  14.418                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
  14.419 @@ -5389,6 +5441,7 @@
  14.420                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  14.421                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  14.422                  dstB = srcB + ((255 - srcA) * dstB) / 255;
  14.423 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
  14.424                  break;
  14.425              case SDL_COPY_ADD:
  14.426                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
  14.427 @@ -5462,6 +5515,7 @@
  14.428                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  14.429                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  14.430                  dstB = srcB + ((255 - srcA) * dstB) / 255;
  14.431 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
  14.432                  break;
  14.433              case SDL_COPY_ADD:
  14.434                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
  14.435 @@ -5617,6 +5671,7 @@
  14.436                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  14.437                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  14.438                  dstB = srcB + ((255 - srcA) * dstB) / 255;
  14.439 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
  14.440                  break;
  14.441              case SDL_COPY_ADD:
  14.442                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
  14.443 @@ -5702,6 +5757,7 @@
  14.444                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  14.445                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  14.446                  dstB = srcB + ((255 - srcA) * dstB) / 255;
  14.447 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
  14.448                  break;
  14.449              case SDL_COPY_ADD:
  14.450                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
  14.451 @@ -5797,6 +5853,7 @@
  14.452                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  14.453                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  14.454                  dstB = srcB + ((255 - srcA) * dstB) / 255;
  14.455 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
  14.456                  break;
  14.457              case SDL_COPY_ADD:
  14.458                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
  14.459 @@ -5870,6 +5927,7 @@
  14.460                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  14.461                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  14.462                  dstB = srcB + ((255 - srcA) * dstB) / 255;
  14.463 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
  14.464                  break;
  14.465              case SDL_COPY_ADD:
  14.466                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
  14.467 @@ -6025,6 +6083,7 @@
  14.468                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  14.469                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  14.470                  dstB = srcB + ((255 - srcA) * dstB) / 255;
  14.471 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
  14.472                  break;
  14.473              case SDL_COPY_ADD:
  14.474                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
  14.475 @@ -6110,6 +6169,7 @@
  14.476                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  14.477                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  14.478                  dstB = srcB + ((255 - srcA) * dstB) / 255;
  14.479 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
  14.480                  break;
  14.481              case SDL_COPY_ADD:
  14.482                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
  14.483 @@ -6205,6 +6265,7 @@
  14.484                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  14.485                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  14.486                  dstB = srcB + ((255 - srcA) * dstB) / 255;
  14.487 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
  14.488                  break;
  14.489              case SDL_COPY_ADD:
  14.490                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
  14.491 @@ -6278,6 +6339,7 @@
  14.492                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  14.493                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  14.494                  dstB = srcB + ((255 - srcA) * dstB) / 255;
  14.495 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
  14.496                  break;
  14.497              case SDL_COPY_ADD:
  14.498                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
  14.499 @@ -6433,6 +6495,7 @@
  14.500                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  14.501                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  14.502                  dstB = srcB + ((255 - srcA) * dstB) / 255;
  14.503 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
  14.504                  break;
  14.505              case SDL_COPY_ADD:
  14.506                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
  14.507 @@ -6518,6 +6581,7 @@
  14.508                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  14.509                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  14.510                  dstB = srcB + ((255 - srcA) * dstB) / 255;
  14.511 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
  14.512                  break;
  14.513              case SDL_COPY_ADD:
  14.514                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
  14.515 @@ -6613,6 +6677,7 @@
  14.516                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  14.517                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  14.518                  dstB = srcB + ((255 - srcA) * dstB) / 255;
  14.519 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
  14.520                  break;
  14.521              case SDL_COPY_ADD:
  14.522                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
  14.523 @@ -6686,6 +6751,7 @@
  14.524                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  14.525                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  14.526                  dstB = srcB + ((255 - srcA) * dstB) / 255;
  14.527 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
  14.528                  break;
  14.529              case SDL_COPY_ADD:
  14.530                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
  14.531 @@ -6841,6 +6907,7 @@
  14.532                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  14.533                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  14.534                  dstB = srcB + ((255 - srcA) * dstB) / 255;
  14.535 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
  14.536                  break;
  14.537              case SDL_COPY_ADD:
  14.538                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
  14.539 @@ -6926,6 +6993,7 @@
  14.540                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  14.541                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  14.542                  dstB = srcB + ((255 - srcA) * dstB) / 255;
  14.543 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
  14.544                  break;
  14.545              case SDL_COPY_ADD:
  14.546                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
  14.547 @@ -7021,6 +7089,7 @@
  14.548                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  14.549                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  14.550                  dstB = srcB + ((255 - srcA) * dstB) / 255;
  14.551 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
  14.552                  break;
  14.553              case SDL_COPY_ADD:
  14.554                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
  14.555 @@ -7094,6 +7163,7 @@
  14.556                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  14.557                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  14.558                  dstB = srcB + ((255 - srcA) * dstB) / 255;
  14.559 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
  14.560                  break;
  14.561              case SDL_COPY_ADD:
  14.562                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
  14.563 @@ -7249,6 +7319,7 @@
  14.564                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  14.565                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  14.566                  dstB = srcB + ((255 - srcA) * dstB) / 255;
  14.567 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
  14.568                  break;
  14.569              case SDL_COPY_ADD:
  14.570                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
  14.571 @@ -7334,6 +7405,7 @@
  14.572                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  14.573                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  14.574                  dstB = srcB + ((255 - srcA) * dstB) / 255;
  14.575 +                dstA = srcA + ((255 - srcA) * dstA) / 255;
  14.576                  break;
  14.577              case SDL_COPY_ADD:
  14.578                  dstR = srcR + dstR; if (dstR > 255) dstR = 255;
    15.1 --- a/src/video/sdlgenblit.pl	Mon Jul 22 02:51:45 2013 -0700
    15.2 +++ b/src/video/sdlgenblit.pl	Tue Jul 23 08:06:49 2013 -0700
    15.3 @@ -82,7 +82,7 @@
    15.4  /* DO NOT EDIT!  This file is generated by sdlgenblit.pl */
    15.5  /*
    15.6    Simple DirectMedia Layer
    15.7 -  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
    15.8 +  Copyright (C) 1997-2013 Sam Lantinga <slouken\@libsdl.org>
    15.9  
   15.10    This software is provided 'as-is', without any express or implied
   15.11    warranty.  In no event will the authors be held liable for any damages
   15.12 @@ -241,6 +241,7 @@
   15.13                  ${d}R = ${s}R + ((255 - ${s}A) * ${d}R) / 255;
   15.14                  ${d}G = ${s}G + ((255 - ${s}A) * ${d}G) / 255;
   15.15                  ${d}B = ${s}B + ((255 - ${s}A) * ${d}B) / 255;
   15.16 +                ${d}A = ${s}A + ((255 - ${s}A) * ${d}A) / 255;
   15.17                  break;
   15.18              case SDL_COPY_ADD:
   15.19                  ${d}R = ${s}R + ${d}R; if (${d}R > 255) ${d}R = 255;
    16.1 --- a/test/testrendertarget.c	Mon Jul 22 02:51:45 2013 -0700
    16.2 +++ b/test/testrendertarget.c	Tue Jul 23 08:06:49 2013 -0700
    16.3 @@ -88,6 +88,88 @@
    16.4  }
    16.5  
    16.6  void
    16.7 +DrawComposite(DrawState *s)
    16.8 +{
    16.9 +    SDL_Rect viewport, R;
   16.10 +    SDL_Texture *target, *A, *B;
   16.11 +
   16.12 +    static SDL_bool blend_tested = SDL_FALSE;
   16.13 +    if (!blend_tested) {
   16.14 +        SDL_Texture *A, *B;
   16.15 +        Uint32 P;
   16.16 +
   16.17 +        A = SDL_CreateTexture(s->renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, 1, 1);
   16.18 +        SDL_SetTextureBlendMode(A, SDL_BLENDMODE_BLEND);
   16.19 +
   16.20 +        B = SDL_CreateTexture(s->renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, 1, 1);
   16.21 +        SDL_SetTextureBlendMode(B, SDL_BLENDMODE_BLEND);
   16.22 +
   16.23 +        SDL_SetRenderTarget(s->renderer, A);
   16.24 +        SDL_SetRenderDrawColor(s->renderer, 0x00, 0x00, 0x00, 0x80);
   16.25 +        SDL_RenderFillRect(s->renderer, NULL);
   16.26 +
   16.27 +        SDL_SetRenderTarget(s->renderer, B);
   16.28 +        SDL_SetRenderDrawColor(s->renderer, 0x00, 0x00, 0x00, 0x00);
   16.29 +        SDL_RenderFillRect(s->renderer, NULL);
   16.30 +        SDL_RenderCopy(s->renderer, A, NULL, NULL);
   16.31 +        SDL_RenderReadPixels(s->renderer, NULL, SDL_PIXELFORMAT_ARGB8888, &P, sizeof(P));
   16.32 +
   16.33 +        printf("Blended pixel: 0x%8.8X\n", P);
   16.34 +
   16.35 +        SDL_DestroyTexture(A);
   16.36 +        SDL_DestroyTexture(B);
   16.37 +        blend_tested = SDL_TRUE;
   16.38 +    }
   16.39 +
   16.40 +    SDL_RenderGetViewport(s->renderer, &viewport);
   16.41 +
   16.42 +    target = SDL_CreateTexture(s->renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, viewport.w, viewport.h);
   16.43 +    SDL_SetTextureBlendMode(target, SDL_BLENDMODE_BLEND);
   16.44 +    SDL_SetRenderTarget(s->renderer, target);
   16.45 +
   16.46 +    /* Draw the background.
   16.47 +       This is solid black so when the sprite is copied to it, any per-pixel alpha will be blended through.
   16.48 +     */
   16.49 +    SDL_SetRenderDrawColor(s->renderer, 0x00, 0x00, 0x00, 0x00);
   16.50 +    SDL_RenderFillRect(s->renderer, NULL);
   16.51 +
   16.52 +    /* Scale and draw the sprite */
   16.53 +    s->sprite_rect.w += s->scale_direction;
   16.54 +    s->sprite_rect.h += s->scale_direction;
   16.55 +    if (s->scale_direction > 0) {
   16.56 +        if (s->sprite_rect.w >= viewport.w || s->sprite_rect.h >= viewport.h) {
   16.57 +            s->scale_direction = -1;
   16.58 +        }
   16.59 +    } else {
   16.60 +        if (s->sprite_rect.w <= 1 || s->sprite_rect.h <= 1) {
   16.61 +            s->scale_direction = 1;
   16.62 +        }
   16.63 +    }
   16.64 +    s->sprite_rect.x = (viewport.w - s->sprite_rect.w) / 2;
   16.65 +    s->sprite_rect.y = (viewport.h - s->sprite_rect.h) / 2;
   16.66 +
   16.67 +    SDL_RenderCopy(s->renderer, s->sprite, NULL, &s->sprite_rect);
   16.68 +
   16.69 +    SDL_SetRenderTarget(s->renderer, NULL);
   16.70 +    SDL_RenderCopy(s->renderer, s->background, NULL, NULL);
   16.71 +
   16.72 +    SDL_SetRenderDrawBlendMode(s->renderer, SDL_BLENDMODE_BLEND);
   16.73 +    SDL_SetRenderDrawColor(s->renderer, 0xff, 0x00, 0x00, 0x80);
   16.74 +    R.x = 0;
   16.75 +    R.y = 0;
   16.76 +    R.w = 100;
   16.77 +    R.h = 100;
   16.78 +    SDL_RenderFillRect(s->renderer, &R);
   16.79 +    SDL_SetRenderDrawBlendMode(s->renderer, SDL_BLENDMODE_NONE);
   16.80 +
   16.81 +    SDL_RenderCopy(s->renderer, target, NULL, NULL);
   16.82 +    SDL_DestroyTexture(target);
   16.83 +
   16.84 +    /* Update the screen! */
   16.85 +    SDL_RenderPresent(s->renderer);
   16.86 +}
   16.87 +
   16.88 +void
   16.89  Draw(DrawState *s)
   16.90  {
   16.91      SDL_Rect viewport;
   16.92 @@ -134,6 +216,7 @@
   16.93      SDL_Event event;
   16.94      int frames;
   16.95      Uint32 then, now;
   16.96 +    SDL_bool test_composite = SDL_FALSE;
   16.97  
   16.98      /* Initialize test framework */
   16.99      state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
  16.100 @@ -145,8 +228,17 @@
  16.101  
  16.102          consumed = SDLTest_CommonArg(state, i);
  16.103          if (consumed == 0) {
  16.104 -            fprintf(stderr, "Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state));
  16.105 -            return 1;
  16.106 +            consumed = -1;
  16.107 +            if (SDL_strcasecmp(argv[i], "--composite") == 0) {
  16.108 +                test_composite = SDL_TRUE;
  16.109 +                consumed = 1;
  16.110 +            }
  16.111 +        }
  16.112 +        if (consumed < 0) {
  16.113 +            fprintf(stderr,
  16.114 +                    "Usage: %s %s [--composite]\n",
  16.115 +                    argv[0], SDLTest_CommonUsage(state));
  16.116 +            quit(1);
  16.117          }
  16.118          i += consumed;
  16.119      }
  16.120 @@ -160,7 +252,11 @@
  16.121  
  16.122          drawstate->window = state->windows[i];
  16.123          drawstate->renderer = state->renderers[i];
  16.124 -        drawstate->sprite = LoadTexture(drawstate->renderer, "icon.bmp", SDL_TRUE);
  16.125 +        if (test_composite) {
  16.126 +            drawstate->sprite = LoadTexture(drawstate->renderer, "icon-alpha.bmp", SDL_TRUE);
  16.127 +        } else {
  16.128 +            drawstate->sprite = LoadTexture(drawstate->renderer, "icon.bmp", SDL_TRUE);
  16.129 +        }
  16.130          drawstate->background = LoadTexture(drawstate->renderer, "sample.bmp", SDL_FALSE);
  16.131          if (!drawstate->sprite || !drawstate->background) {
  16.132              quit(2);
  16.133 @@ -181,7 +277,11 @@
  16.134              SDLTest_CommonEvent(state, &event, &done);
  16.135          }
  16.136          for (i = 0; i < state->num_windows; ++i) {
  16.137 -            Draw(&drawstates[i]);
  16.138 +            if (test_composite) {
  16.139 +                DrawComposite(&drawstates[i]);
  16.140 +            } else {
  16.141 +                Draw(&drawstates[i]);
  16.142 +            }
  16.143          }
  16.144      }
  16.145  
    17.1 --- a/test/testsprite2.c	Mon Jul 22 02:51:45 2013 -0700
    17.2 +++ b/test/testsprite2.c	Tue Jul 23 08:06:49 2013 -0700
    17.3 @@ -56,7 +56,7 @@
    17.4  }
    17.5  
    17.6  int
    17.7 -LoadSprite(char *file)
    17.8 +LoadSprite(const char *file)
    17.9  {
   17.10      int i;
   17.11      SDL_Surface *temp;
   17.12 @@ -243,6 +243,7 @@
   17.13      SDL_Event event;
   17.14      Uint32 then, now, frames;
   17.15  	Uint64 seed;
   17.16 +    const char *icon = "icon.bmp";
   17.17  
   17.18      /* Initialize parameters */
   17.19      num_sprites = NUM_SPRITES;
   17.20 @@ -292,11 +293,14 @@
   17.21              } else if (SDL_isdigit(*argv[i])) {
   17.22                  num_sprites = SDL_atoi(argv[i]);
   17.23                  consumed = 1;
   17.24 +            } else if (argv[i][0] != '-') {
   17.25 +                icon = argv[i];
   17.26 +                consumed = 1;
   17.27              }
   17.28          }
   17.29          if (consumed < 0) {
   17.30              fprintf(stderr,
   17.31 -                    "Usage: %s %s [--blend none|blend|add|mod] [--cyclecolor] [--cyclealpha] [--iterations N]\n",
   17.32 +                    "Usage: %s %s [--blend none|blend|add|mod] [--cyclecolor] [--cyclealpha] [--iterations N] [num_sprites] [icon.bmp]\n",
   17.33                      argv[0], SDLTest_CommonUsage(state));
   17.34              quit(1);
   17.35          }
   17.36 @@ -318,7 +322,7 @@
   17.37          SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
   17.38          SDL_RenderClear(renderer);
   17.39      }
   17.40 -    if (LoadSprite("icon.bmp") < 0) {
   17.41 +    if (LoadSprite(icon) < 0) {
   17.42          quit(2);
   17.43      }
   17.44