Moved the colorkey and per-surface alpha into the blit info,
authorSam Lantinga <slouken@libsdl.org>
Fri, 17 Aug 2007 00:54:53 +0000
changeset 2257340942cfda48
parent 2256 e893d24ad8db
child 2258 771bd3389e3a
Moved the colorkey and per-surface alpha into the blit info,
in preparation for support for general color channel modulation.

Removed and consolidated some data in the blit info.
include/SDL_pixels.h
src/video/SDL_RLEaccel.c
src/video/SDL_blit.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_N.c
src/video/SDL_pixels.c
src/video/SDL_surface.c
src/video/SDL_video.c
     1.1 --- a/include/SDL_pixels.h	Thu Aug 16 22:56:18 2007 +0000
     1.2 +++ b/include/SDL_pixels.h	Fri Aug 17 00:54:53 2007 +0000
     1.3 @@ -237,11 +237,6 @@
     1.4      Uint32 Gmask;
     1.5      Uint32 Bmask;
     1.6      Uint32 Amask;
     1.7 -
     1.8 -    /* RGB color key information */
     1.9 -    Uint32 colorkey;
    1.10 -    /* Alpha value information (per-surface alpha) */
    1.11 -    Uint8 alpha;
    1.12  } SDL_PixelFormat;
    1.13  
    1.14  /**
     2.1 --- a/src/video/SDL_RLEaccel.c	Thu Aug 16 22:56:18 2007 +0000
     2.2 +++ b/src/video/SDL_RLEaccel.c	Fri Aug 17 00:54:53 2007 +0000
     2.3 @@ -859,7 +859,7 @@
     2.4      y = dstrect->y;
     2.5      dstbuf = (Uint8 *) dst->pixels
     2.6          + y * dst->pitch + x * src->format->BytesPerPixel;
     2.7 -    srcbuf = (Uint8 *) src->map->sw_data->aux_data;
     2.8 +    srcbuf = (Uint8 *) src->map->data;
     2.9  
    2.10      {
    2.11          /* skip lines at the top if neccessary */
    2.12 @@ -906,7 +906,7 @@
    2.13      }
    2.14  
    2.15      alpha = (src->flags & SDL_SRCALPHA) == SDL_SRCALPHA
    2.16 -        ? src->format->alpha : 255;
    2.17 +        ? (src->map->cmod >> 24) : 255;
    2.18      /* if left or right edge clipping needed, call clip blit */
    2.19      if (srcrect->x || srcrect->w != src->w) {
    2.20          RLEClipBlit(w, srcbuf, dst, dstbuf, srcrect, alpha);
    2.21 @@ -1133,7 +1133,7 @@
    2.22      x = dstrect->x;
    2.23      y = dstrect->y;
    2.24      dstbuf = (Uint8 *) dst->pixels + y * dst->pitch + x * df->BytesPerPixel;
    2.25 -    srcbuf = (Uint8 *) src->map->sw_data->aux_data + sizeof(RLEDestFormat);
    2.26 +    srcbuf = (Uint8 *) src->map->data + sizeof(RLEDestFormat);
    2.27  
    2.28      {
    2.29          /* skip lines at the top if necessary */
    2.30 @@ -1628,7 +1628,7 @@
    2.31          Uint8 *p = SDL_realloc(rlebuf, dst - rlebuf);
    2.32          if (!p)
    2.33              p = rlebuf;
    2.34 -        surface->map->sw_data->aux_data = p;
    2.35 +        surface->map->data = p;
    2.36      }
    2.37  
    2.38      return 0;
    2.39 @@ -1715,7 +1715,7 @@
    2.40      skip = run = 0;
    2.41      dst = rlebuf;
    2.42      rgbmask = ~surface->format->Amask;
    2.43 -    ckey = surface->format->colorkey & rgbmask;
    2.44 +    ckey = surface->map->ckey & rgbmask;
    2.45      lastline = dst;
    2.46      getpix = getpixes[bpp - 1];
    2.47      w = surface->w;
    2.48 @@ -1794,7 +1794,7 @@
    2.49          Uint8 *p = SDL_realloc(rlebuf, dst - rlebuf);
    2.50          if (!p)
    2.51              p = rlebuf;
    2.52 -        surface->map->sw_data->aux_data = p;
    2.53 +        surface->map->data = p;
    2.54      }
    2.55  
    2.56      return (0);
    2.57 @@ -1859,7 +1859,7 @@
    2.58      Uint8 *srcbuf;
    2.59      Uint32 *dst;
    2.60      SDL_PixelFormat *sf = surface->format;
    2.61 -    RLEDestFormat *df = surface->map->sw_data->aux_data;
    2.62 +    RLEDestFormat *df = surface->map->data;
    2.63      int (*uncopy_opaque) (Uint32 *, void *, int,
    2.64                            RLEDestFormat *, SDL_PixelFormat *);
    2.65      int (*uncopy_transl) (Uint32 *, void *, int,
    2.66 @@ -1948,7 +1948,7 @@
    2.67                  }
    2.68  
    2.69                  /* fill it with the background colour */
    2.70 -                SDL_FillRect(surface, NULL, surface->format->colorkey);
    2.71 +                SDL_FillRect(surface, NULL, surface->map->ckey);
    2.72  
    2.73                  /* now render the encoded surface */
    2.74                  full.x = full.y = 0;
    2.75 @@ -1967,9 +1967,9 @@
    2.76              }
    2.77          }
    2.78  
    2.79 -        if (surface->map && surface->map->sw_data->aux_data) {
    2.80 -            SDL_free(surface->map->sw_data->aux_data);
    2.81 -            surface->map->sw_data->aux_data = NULL;
    2.82 +        if (surface->map && surface->map->data) {
    2.83 +            SDL_free(surface->map->data);
    2.84 +            surface->map->data = NULL;
    2.85          }
    2.86      }
    2.87  }
     3.1 --- a/src/video/SDL_blit.c	Thu Aug 16 22:56:18 2007 +0000
     3.2 +++ b/src/video/SDL_blit.c	Fri Aug 17 00:54:53 2007 +0000
     3.3 @@ -77,11 +77,12 @@
     3.4          info.d_width = dstrect->w;
     3.5          info.d_height = dstrect->h;
     3.6          info.d_skip = dst->pitch - info.d_width * dst->format->BytesPerPixel;
     3.7 -        info.aux_data = src->map->sw_data->aux_data;
     3.8          info.src = src->format;
     3.9          info.table = src->map->table;
    3.10          info.dst = dst->format;
    3.11 -        RunBlit = src->map->sw_data->blit;
    3.12 +        info.ckey = src->map->ckey;
    3.13 +        info.cmod = src->map->cmod;
    3.14 +        RunBlit = (SDL_loblit)src->map->data;
    3.15  
    3.16          /* Run the actual software blit */
    3.17          RunBlit(&info);
    3.18 @@ -166,20 +167,21 @@
    3.19  int
    3.20  SDL_CalculateBlit(SDL_Surface * surface)
    3.21  {
    3.22 +    SDL_loblit blit = NULL;
    3.23      int blit_index;
    3.24  
    3.25      /* Clean everything out to start */
    3.26      if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) {
    3.27          SDL_UnRLESurface(surface, 1);
    3.28      }
    3.29 -    surface->map->sw_blit = NULL;
    3.30 +    surface->map->blit = NULL;
    3.31  
    3.32      /* Get the blit function index, based on surface mode */
    3.33      /* { 0 = nothing, 1 = colorkey, 2 = alpha, 3 = colorkey+alpha } */
    3.34      blit_index = 0;
    3.35      blit_index |= (!!(surface->flags & SDL_SRCCOLORKEY)) << 0;
    3.36      if (surface->flags & SDL_SRCALPHA
    3.37 -        && (surface->format->alpha != SDL_ALPHA_OPAQUE
    3.38 +        && ((surface->map->cmod >> 24) != SDL_ALPHA_OPAQUE
    3.39              || surface->format->Amask)) {
    3.40          blit_index |= 2;
    3.41      }
    3.42 @@ -188,34 +190,28 @@
    3.43      if (surface->map->identity && blit_index == 0) {
    3.44          /* Handle overlapping blits on the same surface */
    3.45          if (surface == surface->map->dst) {
    3.46 -            surface->map->sw_data->blit = SDL_BlitCopyOverlap;
    3.47 +            blit = SDL_BlitCopyOverlap;
    3.48          } else {
    3.49 -            surface->map->sw_data->blit = SDL_BlitCopy;
    3.50 +            blit = SDL_BlitCopy;
    3.51          }
    3.52      } else {
    3.53          if (surface->format->BitsPerPixel < 8) {
    3.54 -            surface->map->sw_data->blit =
    3.55 -                SDL_CalculateBlit0(surface, blit_index);
    3.56 +            blit = SDL_CalculateBlit0(surface, blit_index);
    3.57          } else {
    3.58              switch (surface->format->BytesPerPixel) {
    3.59              case 1:
    3.60 -                surface->map->sw_data->blit =
    3.61 -                    SDL_CalculateBlit1(surface, blit_index);
    3.62 +                blit = SDL_CalculateBlit1(surface, blit_index);
    3.63                  break;
    3.64              case 2:
    3.65              case 3:
    3.66              case 4:
    3.67 -                surface->map->sw_data->blit =
    3.68 -                    SDL_CalculateBlitN(surface, blit_index);
    3.69 -                break;
    3.70 -            default:
    3.71 -                surface->map->sw_data->blit = NULL;
    3.72 +                blit = SDL_CalculateBlitN(surface, blit_index);
    3.73                  break;
    3.74              }
    3.75          }
    3.76      }
    3.77      /* Make sure we have a blit function */
    3.78 -    if (surface->map->sw_data->blit == NULL) {
    3.79 +    if (blit == NULL) {
    3.80          SDL_InvalidateMap(surface->map);
    3.81          SDL_SetError("Blit combination not supported");
    3.82          return (-1);
    3.83 @@ -227,15 +223,16 @@
    3.84              && (blit_index == 1
    3.85                  || (blit_index == 3 && !surface->format->Amask))) {
    3.86              if (SDL_RLESurface(surface) == 0)
    3.87 -                surface->map->sw_blit = SDL_RLEBlit;
    3.88 +                surface->map->blit = SDL_RLEBlit;
    3.89          } else if (blit_index == 2 && surface->format->Amask) {
    3.90              if (SDL_RLESurface(surface) == 0)
    3.91 -                surface->map->sw_blit = SDL_RLEAlphaBlit;
    3.92 +                surface->map->blit = SDL_RLEAlphaBlit;
    3.93          }
    3.94      }
    3.95  
    3.96 -    if (surface->map->sw_blit == NULL) {
    3.97 -        surface->map->sw_blit = SDL_SoftBlit;
    3.98 +    if (surface->map->blit == NULL) {
    3.99 +        surface->map->blit = SDL_SoftBlit;
   3.100 +        surface->map->data = blit;
   3.101      }
   3.102      return (0);
   3.103  }
     4.1 --- a/src/video/SDL_blit.h	Thu Aug 16 22:56:18 2007 +0000
     4.2 +++ b/src/video/SDL_blit.h	Fri Aug 17 00:54:53 2007 +0000
     4.3 @@ -45,30 +45,25 @@
     4.4      int d_width;
     4.5      int d_height;
     4.6      int d_skip;
     4.7 -    void *aux_data;
     4.8      SDL_PixelFormat *src;
     4.9      Uint8 *table;
    4.10      SDL_PixelFormat *dst;
    4.11 +    Uint32 ckey, cmod;
    4.12  } SDL_BlitInfo;
    4.13  
    4.14  /* The type definition for the low level blit functions */
    4.15  typedef void (*SDL_loblit) (SDL_BlitInfo * info);
    4.16  
    4.17 -/* This is the private info structure for software accelerated blits */
    4.18 -struct private_swaccel
    4.19 -{
    4.20 -    SDL_loblit blit;
    4.21 -    void *aux_data;
    4.22 -};
    4.23 -
    4.24  /* Blit mapping definition */
    4.25  typedef struct SDL_BlitMap
    4.26  {
    4.27      SDL_Surface *dst;
    4.28      int identity;
    4.29      Uint8 *table;
    4.30 -    SDL_blit sw_blit;
    4.31 -    struct private_swaccel *sw_data;
    4.32 +    SDL_blit blit;
    4.33 +    void *data;
    4.34 +    Uint32 ckey;    /* colorkey */
    4.35 +    Uint32 cmod;    /* ARGB modulation */
    4.36  
    4.37      /* the version count matches the destination; mismatch indicates
    4.38         an invalid mapping */
     5.1 --- a/src/video/SDL_blit_0.c	Thu Aug 16 22:56:18 2007 +0000
     5.2 +++ b/src/video/SDL_blit_0.c	Fri Aug 17 00:54:53 2007 +0000
     5.3 @@ -200,7 +200,7 @@
     5.4      Uint8 *dst = info->d_pixels;
     5.5      int srcskip = info->s_skip;
     5.6      int dstskip = info->d_skip;
     5.7 -    Uint32 ckey = info->src->colorkey;
     5.8 +    Uint32 ckey = info->ckey;
     5.9      Uint8 *palmap = info->table;
    5.10      int c;
    5.11  
    5.12 @@ -253,7 +253,7 @@
    5.13      Uint16 *dstp = (Uint16 *) info->d_pixels;
    5.14      int srcskip = info->s_skip;
    5.15      int dstskip = info->d_skip;
    5.16 -    Uint32 ckey = info->src->colorkey;
    5.17 +    Uint32 ckey = info->ckey;
    5.18      Uint8 *palmap = info->table;
    5.19      int c;
    5.20  
    5.21 @@ -288,7 +288,7 @@
    5.22      Uint8 *dst = info->d_pixels;
    5.23      int srcskip = info->s_skip;
    5.24      int dstskip = info->d_skip;
    5.25 -    Uint32 ckey = info->src->colorkey;
    5.26 +    Uint32 ckey = info->ckey;
    5.27      Uint8 *palmap = info->table;
    5.28      int c;
    5.29  
    5.30 @@ -322,7 +322,7 @@
    5.31      Uint32 *dstp = (Uint32 *) info->d_pixels;
    5.32      int srcskip = info->s_skip;
    5.33      int dstskip = info->d_skip;
    5.34 -    Uint32 ckey = info->src->colorkey;
    5.35 +    Uint32 ckey = info->ckey;
    5.36      Uint8 *palmap = info->table;
    5.37      int c;
    5.38  
    5.39 @@ -361,7 +361,7 @@
    5.40      SDL_PixelFormat *dstfmt = info->dst;
    5.41      int dstbpp;
    5.42      int c;
    5.43 -    const int A = info->src->alpha;
    5.44 +    const int A = (info->cmod >> 24);
    5.45  
    5.46      /* Set up some basic variables */
    5.47      dstbpp = dstfmt->BytesPerPixel;
    5.48 @@ -407,8 +407,8 @@
    5.49      const SDL_Color *srcpal = srcfmt->palette->colors;
    5.50      int dstbpp;
    5.51      int c;
    5.52 -    const int A = srcfmt->alpha;
    5.53 -    Uint32 ckey = srcfmt->colorkey;
    5.54 +    const int A = (info->cmod >> 24);
    5.55 +    Uint32 ckey = info->ckey;
    5.56  
    5.57      /* Set up some basic variables */
    5.58      dstbpp = dstfmt->BytesPerPixel;
     6.1 --- a/src/video/SDL_blit_1.c	Thu Aug 16 22:56:18 2007 +0000
     6.2 +++ b/src/video/SDL_blit_1.c	Fri Aug 17 00:54:53 2007 +0000
     6.3 @@ -290,7 +290,7 @@
     6.4      Uint8 *dst = info->d_pixels;
     6.5      int dstskip = info->d_skip;
     6.6      Uint8 *palmap = info->table;
     6.7 -    Uint32 ckey = info->src->colorkey;
     6.8 +    Uint32 ckey = info->ckey;
     6.9  
    6.10      if (palmap) {
    6.11          while (height--) {
    6.12 @@ -337,7 +337,7 @@
    6.13      Uint16 *dstp = (Uint16 *) info->d_pixels;
    6.14      int dstskip = info->d_skip;
    6.15      Uint16 *palmap = (Uint16 *) info->table;
    6.16 -    Uint32 ckey = info->src->colorkey;
    6.17 +    Uint32 ckey = info->ckey;
    6.18  
    6.19      /* Set up some basic variables */
    6.20      dstskip /= 2;
    6.21 @@ -369,7 +369,7 @@
    6.22      Uint8 *dst = info->d_pixels;
    6.23      int dstskip = info->d_skip;
    6.24      Uint8 *palmap = info->table;
    6.25 -    Uint32 ckey = info->src->colorkey;
    6.26 +    Uint32 ckey = info->ckey;
    6.27      int o;
    6.28  
    6.29      while (height--) {
    6.30 @@ -402,7 +402,7 @@
    6.31      Uint32 *dstp = (Uint32 *) info->d_pixels;
    6.32      int dstskip = info->d_skip;
    6.33      Uint32 *palmap = (Uint32 *) info->table;
    6.34 -    Uint32 ckey = info->src->colorkey;
    6.35 +    Uint32 ckey = info->ckey;
    6.36  
    6.37      /* Set up some basic variables */
    6.38      dstskip /= 4;
    6.39 @@ -436,7 +436,7 @@
    6.40      SDL_PixelFormat *dstfmt = info->dst;
    6.41      const SDL_Color *srcpal = info->src->palette->colors;
    6.42      int dstbpp;
    6.43 -    const int A = info->src->alpha;
    6.44 +    const int A = (info->cmod >> 24);
    6.45  
    6.46      /* Set up some basic variables */
    6.47      dstbpp = dstfmt->BytesPerPixel;
    6.48 @@ -477,9 +477,9 @@
    6.49      SDL_PixelFormat *srcfmt = info->src;
    6.50      SDL_PixelFormat *dstfmt = info->dst;
    6.51      const SDL_Color *srcpal = info->src->palette->colors;
    6.52 -    Uint32 ckey = srcfmt->colorkey;
    6.53 +    Uint32 ckey = info->ckey;
    6.54      int dstbpp;
    6.55 -    const int A = srcfmt->alpha;
    6.56 +    const int A = (info->cmod >> 24);
    6.57  
    6.58      /* Set up some basic variables */
    6.59      dstbpp = dstfmt->BytesPerPixel;
     7.1 --- a/src/video/SDL_blit_A.c	Thu Aug 16 22:56:18 2007 +0000
     7.2 +++ b/src/video/SDL_blit_A.c	Fri Aug 17 00:54:53 2007 +0000
     7.3 @@ -41,7 +41,7 @@
     7.4      SDL_PixelFormat *dstfmt = info->dst;
     7.5      int srcbpp = srcfmt->BytesPerPixel;
     7.6  
     7.7 -    const unsigned A = srcfmt->alpha;
     7.8 +    const unsigned A = (info->cmod >> 24);
     7.9  
    7.10      while (height--) {
    7.11  	    /* *INDENT-OFF* */
    7.12 @@ -152,9 +152,9 @@
    7.13      SDL_PixelFormat *srcfmt = info->src;
    7.14      SDL_PixelFormat *dstfmt = info->dst;
    7.15      int srcbpp = srcfmt->BytesPerPixel;
    7.16 -    Uint32 ckey = srcfmt->colorkey;
    7.17 +    Uint32 ckey = info->ckey;
    7.18  
    7.19 -    const int A = srcfmt->alpha;
    7.20 +    const int A = (info->cmod >> 24);
    7.21  
    7.22      while (height--) {
    7.23  	    /* *INDENT-OFF* */
    7.24 @@ -261,7 +261,7 @@
    7.25  {
    7.26      SDL_PixelFormat *df = info->dst;
    7.27      Uint32 chanmask = df->Rmask | df->Gmask | df->Bmask;
    7.28 -    unsigned alpha = info->src->alpha;
    7.29 +    unsigned alpha = (info->cmod >> 24);
    7.30  
    7.31      if (alpha == 128 && (df->Rmask | df->Gmask | df->Bmask) == 0x00FFFFFF) {
    7.32          /* only call a128 version when R,G,B occupy lower bits */
    7.33 @@ -718,7 +718,6 @@
    7.34  static void
    7.35  Blit32to32SurfaceAlphaKeyAltivec(SDL_BlitInfo * info)
    7.36  {
    7.37 -    unsigned alpha = info->src->alpha;
    7.38      int height = info->d_height;
    7.39      Uint32 *srcp = (Uint32 *) info->s_pixels;
    7.40      int srcskip = info->s_skip >> 2;
    7.41 @@ -726,10 +725,10 @@
    7.42      int dstskip = info->d_skip >> 2;
    7.43      SDL_PixelFormat *srcfmt = info->src;
    7.44      SDL_PixelFormat *dstfmt = info->dst;
    7.45 -    unsigned sA = srcfmt->alpha;
    7.46 +    unsigned sA = (info->cmod >> 24);
    7.47      unsigned dA = dstfmt->Amask ? SDL_ALPHA_OPAQUE : 0;
    7.48      Uint32 rgbmask = srcfmt->Rmask | srcfmt->Gmask | srcfmt->Bmask;
    7.49 -    Uint32 ckey = info->src->colorkey;
    7.50 +    Uint32 ckey = info->ckey;
    7.51      vector unsigned char mergePermute;
    7.52      vector unsigned char vsrcPermute;
    7.53      vector unsigned char vdstPermute;
    7.54 @@ -1041,7 +1040,6 @@
    7.55  Blit32to32SurfaceAlphaAltivec(SDL_BlitInfo * info)
    7.56  {
    7.57      /* XXX : 6 */
    7.58 -    unsigned alpha = info->src->alpha;
    7.59      int height = info->d_height;
    7.60      Uint32 *srcp = (Uint32 *) info->s_pixels;
    7.61      int srcskip = info->s_skip >> 2;
    7.62 @@ -1049,7 +1047,7 @@
    7.63      int dstskip = info->d_skip >> 2;
    7.64      SDL_PixelFormat *srcfmt = info->src;
    7.65      SDL_PixelFormat *dstfmt = info->dst;
    7.66 -    unsigned sA = srcfmt->alpha;
    7.67 +    unsigned sA = (info->cmod >> 24);
    7.68      unsigned dA = dstfmt->Amask ? SDL_ALPHA_OPAQUE : 0;
    7.69      vector unsigned char mergePermute;
    7.70      vector unsigned char vsrcPermute;
    7.71 @@ -1138,7 +1136,7 @@
    7.72  static void
    7.73  BlitRGBtoRGBSurfaceAlphaAltivec(SDL_BlitInfo * info)
    7.74  {
    7.75 -    unsigned alpha = info->src->alpha;
    7.76 +    unsigned alpha = (info->cmod >> 24);
    7.77      int height = info->d_height;
    7.78      Uint32 *srcp = (Uint32 *) info->s_pixels;
    7.79      int srcskip = info->s_skip >> 2;
    7.80 @@ -1251,7 +1249,7 @@
    7.81  static void
    7.82  BlitRGBtoRGBSurfaceAlpha(SDL_BlitInfo * info)
    7.83  {
    7.84 -    unsigned alpha = info->src->alpha;
    7.85 +    unsigned alpha = (info->cmod >> 24);
    7.86      if (alpha == 128) {
    7.87          BlitRGBtoRGBSurfaceAlpha128(info);
    7.88      } else {
    7.89 @@ -1560,7 +1558,7 @@
    7.90  static void
    7.91  Blit565to565SurfaceAlphaMMX(SDL_BlitInfo * info)
    7.92  {
    7.93 -    unsigned alpha = info->src->alpha;
    7.94 +    unsigned alpha = (info->cmod >> 24);
    7.95      if (alpha == 128) {
    7.96          Blit16to16SurfaceAlpha128(info, 0xf7de);
    7.97      } else {
    7.98 @@ -1697,7 +1695,7 @@
    7.99  static void
   7.100  Blit555to555SurfaceAlphaMMX(SDL_BlitInfo * info)
   7.101  {
   7.102 -    unsigned alpha = info->src->alpha;
   7.103 +    unsigned alpha = (info->cmod >> 24);
   7.104      if (alpha == 128) {
   7.105          Blit16to16SurfaceAlpha128(info, 0xfbde);
   7.106      } else {
   7.107 @@ -1837,7 +1835,7 @@
   7.108  static void
   7.109  Blit565to565SurfaceAlpha(SDL_BlitInfo * info)
   7.110  {
   7.111 -    unsigned alpha = info->src->alpha;
   7.112 +    unsigned alpha = (info->cmod >> 24);
   7.113      if (alpha == 128) {
   7.114          Blit16to16SurfaceAlpha128(info, 0xf7de);
   7.115      } else {
   7.116 @@ -1876,7 +1874,7 @@
   7.117  static void
   7.118  Blit555to555SurfaceAlpha(SDL_BlitInfo * info)
   7.119  {
   7.120 -    unsigned alpha = info->src->alpha;  /* downscale alpha to 5 bits */
   7.121 +    unsigned alpha = (info->cmod >> 24);  /* downscale alpha to 5 bits */
   7.122      if (alpha == 128) {
   7.123          Blit16to16SurfaceAlpha128(info, 0xfbde);
   7.124      } else {
   7.125 @@ -2018,7 +2016,7 @@
   7.126      SDL_PixelFormat *dstfmt = info->dst;
   7.127      int srcbpp = srcfmt->BytesPerPixel;
   7.128      int dstbpp = dstfmt->BytesPerPixel;
   7.129 -    unsigned sA = srcfmt->alpha;
   7.130 +    unsigned sA = (info->cmod >> 24);
   7.131      unsigned dA = dstfmt->Amask ? SDL_ALPHA_OPAQUE : 0;
   7.132  
   7.133      if (sA) {
   7.134 @@ -2060,10 +2058,10 @@
   7.135      int dstskip = info->d_skip;
   7.136      SDL_PixelFormat *srcfmt = info->src;
   7.137      SDL_PixelFormat *dstfmt = info->dst;
   7.138 -    Uint32 ckey = srcfmt->colorkey;
   7.139 +    Uint32 ckey = info->ckey;
   7.140      int srcbpp = srcfmt->BytesPerPixel;
   7.141      int dstbpp = dstfmt->BytesPerPixel;
   7.142 -    unsigned sA = srcfmt->alpha;
   7.143 +    unsigned sA = (info->cmod >> 24);
   7.144      unsigned dA = dstfmt->Amask ? SDL_ALPHA_OPAQUE : 0;
   7.145  
   7.146      while (height--) {
     8.1 --- a/src/video/SDL_blit_N.c	Thu Aug 16 22:56:18 2007 +0000
     8.2 +++ b/src/video/SDL_blit_N.c	Fri Aug 17 00:54:53 2007 +0000
     8.3 @@ -322,8 +322,8 @@
     8.4      vf800 = (vector unsigned short) vec_splat_u8(-7);
     8.5      vf800 = vec_sl(vf800, vec_splat_u16(8));
     8.6  
     8.7 -    if (dstfmt->Amask && srcfmt->alpha) {
     8.8 -        ((unsigned char *) &valpha)[0] = alpha = srcfmt->alpha;
     8.9 +    if (dstfmt->Amask && (info->cmod >> 24)) {
    8.10 +        ((unsigned char *) &valpha)[0] = alpha = (info->cmod >> 24);
    8.11          valpha = vec_splat(valpha, 0);
    8.12      } else {
    8.13          alpha = 0;
    8.14 @@ -470,8 +470,8 @@
    8.15      vf800 = (vector unsigned short) vec_splat_u8(-7);
    8.16      vf800 = vec_sl(vf800, vec_splat_u16(8));
    8.17  
    8.18 -    if (dstfmt->Amask && srcfmt->alpha) {
    8.19 -        ((unsigned char *) &valpha)[0] = alpha = srcfmt->alpha;
    8.20 +    if (dstfmt->Amask && (info->cmod >> 24)) {
    8.21 +        ((unsigned char *) &valpha)[0] = alpha = (info->cmod >> 24);
    8.22          valpha = vec_splat(valpha, 0);
    8.23      } else {
    8.24          alpha = 0;
    8.25 @@ -569,9 +569,9 @@
    8.26      SDL_PixelFormat *dstfmt = info->dst;
    8.27      int dstbpp = dstfmt->BytesPerPixel;
    8.28      int copy_alpha = (srcfmt->Amask && dstfmt->Amask);
    8.29 -    unsigned alpha = dstfmt->Amask ? srcfmt->alpha : 0;
    8.30 +    unsigned alpha = dstfmt->Amask ? (info->cmod >> 24) : 0;
    8.31      Uint32 rgbmask = srcfmt->Rmask | srcfmt->Gmask | srcfmt->Bmask;
    8.32 -    Uint32 ckey = info->src->colorkey;
    8.33 +    Uint32 ckey = info->ckey;
    8.34      vector unsigned int valpha;
    8.35      vector unsigned char vpermute;
    8.36      vector unsigned char vzero;
    8.37 @@ -687,9 +687,9 @@
    8.38      vector unsigned int vzero = vec_splat_u32(0);
    8.39      vector unsigned char vpermute = calc_swizzle32(srcfmt, dstfmt);
    8.40      if (dstfmt->Amask && !srcfmt->Amask) {
    8.41 -        if (srcfmt->alpha) {
    8.42 +        if ((info->cmod >> 24)) {
    8.43              vector unsigned char valpha;
    8.44 -            ((unsigned char *) &valpha)[0] = srcfmt->alpha;
    8.45 +            ((unsigned char *) &valpha)[0] = (info->cmod >> 24);
    8.46              vzero = (vector unsigned int) vec_splat(valpha, 0);
    8.47          }
    8.48      }
    8.49 @@ -766,9 +766,9 @@
    8.50      vector unsigned int vzero = vec_splat_u32(0);
    8.51      vector unsigned char vpermute = calc_swizzle32(srcfmt, dstfmt);
    8.52      if (dstfmt->Amask && !srcfmt->Amask) {
    8.53 -        if (srcfmt->alpha) {
    8.54 +        if ((info->cmod >> 24)) {
    8.55              vector unsigned char valpha;
    8.56 -            ((unsigned char *) &valpha)[0] = srcfmt->alpha;
    8.57 +            ((unsigned char *) &valpha)[0] = (info->cmod >> 24);
    8.58              vzero = (vector unsigned int) vec_splat(valpha, 0);
    8.59          }
    8.60      }
    8.61 @@ -2039,7 +2039,7 @@
    8.62  
    8.63      if (dstfmt->Amask) {
    8.64          /* RGB->RGBA, SET_ALPHA */
    8.65 -        Uint32 mask = (srcfmt->alpha >> dstfmt->Aloss) << dstfmt->Ashift;
    8.66 +        Uint32 mask = ((info->cmod >> 24) >> dstfmt->Aloss) << dstfmt->Ashift;
    8.67  
    8.68          while (height--) {
    8.69  			/* *INDENT-OFF* */
    8.70 @@ -2087,7 +2087,7 @@
    8.71      int srcbpp = srcfmt->BytesPerPixel;
    8.72      SDL_PixelFormat *dstfmt = info->dst;
    8.73      int dstbpp = dstfmt->BytesPerPixel;
    8.74 -    unsigned alpha = dstfmt->Amask ? srcfmt->alpha : 0;
    8.75 +    unsigned alpha = dstfmt->Amask ? (info->cmod >> 24) : 0;
    8.76  
    8.77      while (height--) {
    8.78  		/* *INDENT-OFF* */
    8.79 @@ -2150,7 +2150,7 @@
    8.80      int dstskip = info->d_skip;
    8.81      SDL_PixelFormat *srcfmt = info->src;
    8.82      const Uint8 *palmap = info->table;
    8.83 -    Uint32 ckey = srcfmt->colorkey;
    8.84 +    Uint32 ckey = info->ckey;
    8.85      Uint32 rgbmask = ~srcfmt->Amask;
    8.86      int srcbpp;
    8.87      Uint32 Pixel;
    8.88 @@ -2214,7 +2214,7 @@
    8.89      int srcskip = info->s_skip;
    8.90      Uint16 *dstp = (Uint16 *) info->d_pixels;
    8.91      int dstskip = info->d_skip;
    8.92 -    Uint32 ckey = info->src->colorkey;
    8.93 +    Uint32 ckey = info->ckey;
    8.94      Uint32 rgbmask = ~info->src->Amask;
    8.95  
    8.96      /* Set up some basic variables */
    8.97 @@ -2248,12 +2248,12 @@
    8.98      int srcskip = info->s_skip;
    8.99      Uint8 *dst = info->d_pixels;
   8.100      int dstskip = info->d_skip;
   8.101 -    Uint32 ckey = info->src->colorkey;
   8.102 +    Uint32 ckey = info->ckey;
   8.103      SDL_PixelFormat *srcfmt = info->src;
   8.104      SDL_PixelFormat *dstfmt = info->dst;
   8.105      int srcbpp = srcfmt->BytesPerPixel;
   8.106      int dstbpp = dstfmt->BytesPerPixel;
   8.107 -    unsigned alpha = dstfmt->Amask ? srcfmt->alpha : 0;
   8.108 +    unsigned alpha = dstfmt->Amask ? (info->cmod >> 24) : 0;
   8.109      Uint32 rgbmask = ~srcfmt->Amask;
   8.110  
   8.111      /* Set up some basic variables */
   8.112 @@ -2291,7 +2291,7 @@
   8.113      int srcskip = info->s_skip;
   8.114      Uint8 *dst = info->d_pixels;
   8.115      int dstskip = info->d_skip;
   8.116 -    Uint32 ckey = info->src->colorkey;
   8.117 +    Uint32 ckey = info->ckey;
   8.118      SDL_PixelFormat *srcfmt = info->src;
   8.119      SDL_PixelFormat *dstfmt = info->dst;
   8.120      Uint32 rgbmask = ~srcfmt->Amask;
   8.121 @@ -2332,70 +2332,69 @@
   8.122      int dstbpp;
   8.123      Uint32 dstR, dstG, dstB;
   8.124      Uint32 blit_features;
   8.125 -    void *aux_data;
   8.126      SDL_loblit blitfunc;
   8.127      enum
   8.128      { NO_ALPHA = 1, SET_ALPHA = 2, COPY_ALPHA = 4 } alpha;
   8.129  };
   8.130  static const struct blit_table normal_blit_1[] = {
   8.131      /* Default for 8-bit RGB source, an invalid combination */
   8.132 -    {0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL},
   8.133 +    {0, 0, 0, 0, 0, 0, 0, 0, NULL},
   8.134  };
   8.135  static const struct blit_table normal_blit_2[] = {
   8.136  #if SDL_ALTIVEC_BLITTERS
   8.137      /* has-altivec */
   8.138      {0x0000F800, 0x000007E0, 0x0000001F, 4, 0x00000000, 0x00000000,
   8.139       0x00000000,
   8.140 -     2, NULL, Blit_RGB565_32Altivec, NO_ALPHA | COPY_ALPHA | SET_ALPHA},
   8.141 +     2, Blit_RGB565_32Altivec, NO_ALPHA | COPY_ALPHA | SET_ALPHA},
   8.142      {0x00007C00, 0x000003E0, 0x0000001F, 4, 0x00000000, 0x00000000,
   8.143       0x00000000,
   8.144 -     2, NULL, Blit_RGB555_32Altivec, NO_ALPHA | COPY_ALPHA | SET_ALPHA},
   8.145 +     2, Blit_RGB555_32Altivec, NO_ALPHA | COPY_ALPHA | SET_ALPHA},
   8.146  #endif
   8.147      {0x0000F800, 0x000007E0, 0x0000001F, 4, 0x00FF0000, 0x0000FF00,
   8.148       0x000000FF,
   8.149 -     0, NULL, Blit_RGB565_ARGB8888, SET_ALPHA},
   8.150 +     0, Blit_RGB565_ARGB8888, SET_ALPHA},
   8.151      {0x0000F800, 0x000007E0, 0x0000001F, 4, 0x000000FF, 0x0000FF00,
   8.152       0x00FF0000,
   8.153 -     0, NULL, Blit_RGB565_ABGR8888, SET_ALPHA},
   8.154 +     0, Blit_RGB565_ABGR8888, SET_ALPHA},
   8.155      {0x0000F800, 0x000007E0, 0x0000001F, 4, 0xFF000000, 0x00FF0000,
   8.156       0x0000FF00,
   8.157 -     0, NULL, Blit_RGB565_RGBA8888, SET_ALPHA},
   8.158 +     0, Blit_RGB565_RGBA8888, SET_ALPHA},
   8.159      {0x0000F800, 0x000007E0, 0x0000001F, 4, 0x0000FF00, 0x00FF0000,
   8.160       0xFF000000,
   8.161 -     0, NULL, Blit_RGB565_BGRA8888, SET_ALPHA},
   8.162 +     0, Blit_RGB565_BGRA8888, SET_ALPHA},
   8.163  
   8.164      /* Default for 16-bit RGB source, used if no other blitter matches */
   8.165 -    {0, 0, 0, 0, 0, 0, 0, 0, NULL, BlitNtoN, 0}
   8.166 +    {0, 0, 0, 0, 0, 0, 0, 0, BlitNtoN, 0}
   8.167  };
   8.168  static const struct blit_table normal_blit_3[] = {
   8.169      /* Default for 24-bit RGB source, never optimized */
   8.170 -    {0, 0, 0, 0, 0, 0, 0, 0, NULL, BlitNtoN, 0}
   8.171 +    {0, 0, 0, 0, 0, 0, 0, 0, BlitNtoN, 0}
   8.172  };
   8.173  static const struct blit_table normal_blit_4[] = {
   8.174  #if SDL_ALTIVEC_BLITTERS
   8.175      /* has-altivec | dont-use-prefetch */
   8.176      {0x00000000, 0x00000000, 0x00000000, 4, 0x00000000, 0x00000000,
   8.177       0x00000000,
   8.178 -     6, NULL, ConvertAltivec32to32_noprefetch,
   8.179 +     6, ConvertAltivec32to32_noprefetch,
   8.180       NO_ALPHA | COPY_ALPHA | SET_ALPHA},
   8.181      /* has-altivec */
   8.182      {0x00000000, 0x00000000, 0x00000000, 4, 0x00000000, 0x00000000,
   8.183       0x00000000,
   8.184 -     2, NULL, ConvertAltivec32to32_prefetch,
   8.185 +     2, ConvertAltivec32to32_prefetch,
   8.186       NO_ALPHA | COPY_ALPHA | SET_ALPHA},
   8.187      /* has-altivec */
   8.188      {0x00000000, 0x00000000, 0x00000000, 2, 0x0000F800, 0x000007E0,
   8.189       0x0000001F,
   8.190 -     2, NULL, Blit_RGB888_RGB565Altivec, NO_ALPHA},
   8.191 +     2, Blit_RGB888_RGB565Altivec, NO_ALPHA},
   8.192  #endif
   8.193      {0x00FF0000, 0x0000FF00, 0x000000FF, 2, 0x0000F800, 0x000007E0,
   8.194       0x0000001F,
   8.195 -     0, NULL, Blit_RGB888_RGB565, NO_ALPHA},
   8.196 +     0, Blit_RGB888_RGB565, NO_ALPHA},
   8.197      {0x00FF0000, 0x0000FF00, 0x000000FF, 2, 0x00007C00, 0x000003E0,
   8.198       0x0000001F,
   8.199 -     0, NULL, Blit_RGB888_RGB555, NO_ALPHA},
   8.200 +     0, Blit_RGB888_RGB555, NO_ALPHA},
   8.201      /* Default for 32-bit RGB source, used if no other blitter matches */
   8.202 -    {0, 0, 0, 0, 0, 0, 0, 0, NULL, BlitNtoN, 0}
   8.203 +    {0, 0, 0, 0, 0, 0, 0, 0, BlitNtoN, 0}
   8.204  };
   8.205  static const struct blit_table *normal_blit[] = {
   8.206      normal_blit_1, normal_blit_2, normal_blit_3, normal_blit_4
   8.207 @@ -2407,7 +2406,6 @@
   8.208  SDL_loblit
   8.209  SDL_CalculateBlitN(SDL_Surface * surface, int blit_index)
   8.210  {
   8.211 -    struct private_swaccel *sdata;
   8.212      SDL_PixelFormat *srcfmt;
   8.213      SDL_PixelFormat *dstfmt;
   8.214      const struct blit_table *table;
   8.215 @@ -2415,7 +2413,6 @@
   8.216      SDL_loblit blitfun;
   8.217  
   8.218      /* Set up data for choosing the blit */
   8.219 -    sdata = surface->map->sw_data;
   8.220      srcfmt = surface->format;
   8.221      dstfmt = surface->map->dst->format;
   8.222  
   8.223 @@ -2486,7 +2483,6 @@
   8.224                   table[which].blit_features))
   8.225                  break;
   8.226          }
   8.227 -        sdata->aux_data = table[which].aux_data;
   8.228          blitfun = table[which].blitfunc;
   8.229  
   8.230          if (blitfun == BlitNtoN) {      /* default C fallback catch-all. Slow! */
     9.1 --- a/src/video/SDL_pixels.c	Thu Aug 16 22:56:18 2007 +0000
     9.2 +++ b/src/video/SDL_pixels.c	Fri Aug 17 00:54:53 2007 +0000
     9.3 @@ -351,7 +351,6 @@
     9.4          SDL_OutOfMemory();
     9.5          return (NULL);
     9.6      }
     9.7 -    format->alpha = SDL_ALPHA_OPAQUE;
     9.8  
     9.9      /* Set up the format */
    9.10      format->BitsPerPixel = bpp;
    9.11 @@ -669,12 +668,12 @@
    9.12  
    9.13  /* Map from Palette to BitField */
    9.14  static Uint8 *
    9.15 -Map1toN(SDL_PixelFormat * src, SDL_PixelFormat * dst)
    9.16 +Map1toN(SDL_PixelFormat * src, Uint32 cmod, SDL_PixelFormat * dst)
    9.17  {
    9.18      Uint8 *map;
    9.19      int i;
    9.20      int bpp;
    9.21 -    unsigned alpha;
    9.22 +    unsigned Amod, Rmod, Gmod, Bmod; 
    9.23      SDL_Palette *pal = src->palette;
    9.24  
    9.25      bpp = ((dst->BytesPerPixel == 3) ? 4 : dst->BytesPerPixel);
    9.26 @@ -684,12 +683,18 @@
    9.27          return (NULL);
    9.28      }
    9.29  
    9.30 -    alpha = dst->Amask ? src->alpha : 0;
    9.31 +    Amod = (cmod >> 24) & 0xFF;
    9.32 +    Rmod = (cmod >> 16) & 0xFF;
    9.33 +    Gmod = (cmod >> 8) & 0xFF;
    9.34 +    Bmod = (cmod >> 0) & 0xFF;
    9.35 +
    9.36      /* We memory copy to the pixel map so the endianness is preserved */
    9.37      for (i = 0; i < pal->ncolors; ++i) {
    9.38 -        ASSEMBLE_RGBA(&map[i * bpp], dst->BytesPerPixel, dst,
    9.39 -                      pal->colors[i].r, pal->colors[i].g,
    9.40 -                      pal->colors[i].b, alpha);
    9.41 +        Uint8 A = Amod;
    9.42 +        Uint8 R = (pal->colors[i].r * Rmod) / 255;
    9.43 +        Uint8 G = (pal->colors[i].g * Gmod) / 255;
    9.44 +        Uint8 B = (pal->colors[i].b * Bmod) / 255;
    9.45 +        ASSEMBLE_RGBA(&map[i * bpp], dst->BytesPerPixel, dst, R, G, B, A);
    9.46      }
    9.47      return (map);
    9.48  }
    9.49 @@ -720,15 +725,7 @@
    9.50          SDL_OutOfMemory();
    9.51          return (NULL);
    9.52      }
    9.53 -
    9.54 -    /* Allocate the software blit data */
    9.55 -    map->sw_data =
    9.56 -        (struct private_swaccel *) SDL_calloc(1, sizeof(*map->sw_data));
    9.57 -    if (map->sw_data == NULL) {
    9.58 -        SDL_FreeBlitMap(map);
    9.59 -        SDL_OutOfMemory();
    9.60 -        return (NULL);
    9.61 -    }
    9.62 +    map->cmod = 0xFFFFFFFF;
    9.63  
    9.64      /* It's ready to go */
    9.65      return (map);
    9.66 @@ -783,7 +780,7 @@
    9.67  
    9.68          default:
    9.69              /* Palette --> BitField */
    9.70 -            map->table = Map1toN(srcfmt, dstfmt);
    9.71 +            map->table = Map1toN(srcfmt, src->map->cmod, dstfmt);
    9.72              if (map->table == NULL) {
    9.73                  return (-1);
    9.74              }
    9.75 @@ -823,9 +820,6 @@
    9.76  {
    9.77      if (map) {
    9.78          SDL_InvalidateMap(map);
    9.79 -        if (map->sw_data != NULL) {
    9.80 -            SDL_free(map->sw_data);
    9.81 -        }
    9.82          SDL_free(map);
    9.83      }
    9.84  }
    10.1 --- a/src/video/SDL_surface.c	Thu Aug 16 22:56:18 2007 +0000
    10.2 +++ b/src/video/SDL_surface.c	Fri Aug 17 00:54:53 2007 +0000
    10.3 @@ -231,7 +231,7 @@
    10.4  
    10.5      /* Optimize away operations that don't change anything */
    10.6      if ((flag == (surface->flags & (SDL_SRCCOLORKEY | SDL_RLEACCELOK))) &&
    10.7 -        (key == surface->format->colorkey)) {
    10.8 +        (key == surface->map->ckey)) {
    10.9          return (0);
   10.10      }
   10.11  
   10.12 @@ -242,7 +242,7 @@
   10.13  
   10.14      if (flag) {
   10.15          surface->flags |= SDL_SRCCOLORKEY;
   10.16 -        surface->format->colorkey = key;
   10.17 +        surface->map->ckey = key;
   10.18          if (flag & SDL_RLEACCELOK) {
   10.19              surface->flags |= SDL_RLEACCELOK;
   10.20          } else {
   10.21 @@ -250,7 +250,7 @@
   10.22          }
   10.23      } else {
   10.24          surface->flags &= ~(SDL_SRCCOLORKEY | SDL_RLEACCELOK);
   10.25 -        surface->format->colorkey = 0;
   10.26 +        surface->map->ckey = 0;
   10.27      }
   10.28      SDL_InvalidateMap(surface->map);
   10.29      return (0);
   10.30 @@ -261,7 +261,7 @@
   10.31  SDL_SetAlpha(SDL_Surface * surface, Uint32 flag, Uint8 value)
   10.32  {
   10.33      Uint32 oldflags = surface->flags;
   10.34 -    Uint32 oldalpha = surface->format->alpha;
   10.35 +    Uint32 oldalpha = (surface->map->cmod >> 24);
   10.36  
   10.37      /* Sanity check the flag as it gets passed in */
   10.38      if (flag & SDL_SRCALPHA) {
   10.39 @@ -285,7 +285,8 @@
   10.40  
   10.41      if (flag) {
   10.42          surface->flags |= SDL_SRCALPHA;
   10.43 -        surface->format->alpha = value;
   10.44 +        surface->map->cmod &= 0x00FFFFFF;
   10.45 +        surface->map->cmod |= ((Uint32)value << 24);
   10.46          if (flag & SDL_RLEACCELOK) {
   10.47              surface->flags |= SDL_RLEACCELOK;
   10.48          } else {
   10.49 @@ -293,7 +294,7 @@
   10.50          }
   10.51      } else {
   10.52          surface->flags &= ~SDL_SRCALPHA;
   10.53 -        surface->format->alpha = SDL_ALPHA_OPAQUE;
   10.54 +        surface->map->cmod |= 0xFF000000;
   10.55      }
   10.56      /*
   10.57       * The representation for software surfaces is independent of
   10.58 @@ -412,7 +413,7 @@
   10.59              return (-1);
   10.60          }
   10.61      }
   10.62 -    return (src->map->sw_blit(src, srcrect, dst, dstrect));
   10.63 +    return (src->map->blit(src, srcrect, dst, dstrect));
   10.64  }
   10.65  
   10.66  
   10.67 @@ -601,7 +602,7 @@
   10.68          if ((flags & SDL_SRCCOLORKEY) != SDL_SRCCOLORKEY && format->Amask) {
   10.69              surface_flags &= ~SDL_SRCCOLORKEY;
   10.70          } else {
   10.71 -            colorkey = surface->format->colorkey;
   10.72 +            colorkey = surface->map->ckey;
   10.73              SDL_SetColorKey(surface, 0, 0);
   10.74          }
   10.75      }
   10.76 @@ -610,7 +611,7 @@
   10.77          if (format->Amask) {
   10.78              surface->flags &= ~SDL_SRCALPHA;
   10.79          } else {
   10.80 -            alpha = surface->format->alpha;
   10.81 +            alpha = (Uint8)(surface->map->cmod >> 24);
   10.82              SDL_SetAlpha(surface, 0, 0);
   10.83          }
   10.84      }
    11.1 --- a/src/video/SDL_video.c	Thu Aug 16 22:56:18 2007 +0000
    11.2 +++ b/src/video/SDL_video.c	Fri Aug 17 00:54:53 2007 +0000
    11.3 @@ -1595,7 +1595,7 @@
    11.4                                surface->pitch);
    11.5          }
    11.6      } else {
    11.7 -        Uint8 alpha;
    11.8 +        Uint32 cmod;
    11.9          SDL_Rect bounds;
   11.10          SDL_Surface dst;
   11.11  
   11.12 @@ -1648,6 +1648,7 @@
   11.13          }
   11.14  
   11.15          /* Copy over the alpha channel */
   11.16 +        cmod = surface->map->cmod;
   11.17          if (surface_flags & SDL_SRCALPHA) {
   11.18              if (fmt->Amask) {
   11.19                  surface->flags &= ~SDL_SRCALPHA;
   11.20 @@ -1655,7 +1656,6 @@
   11.21                  /* FIXME: Need to make sure the texture has an alpha channel
   11.22                   *        and copy 'alpha' into the texture alpha channel.
   11.23                   */
   11.24 -                alpha = surface->format->alpha;
   11.25                  SDL_SetAlpha(surface, 0, 0);
   11.26              }
   11.27          }
   11.28 @@ -1673,7 +1673,7 @@
   11.29              if (fmt->Amask) {
   11.30                  surface->flags |= SDL_SRCALPHA;
   11.31              } else {
   11.32 -                SDL_SetAlpha(surface, aflags, alpha);
   11.33 +                SDL_SetAlpha(surface, aflags, (cmod >> 24));
   11.34              }
   11.35          }
   11.36