More work in progress integrating SDL_Surface and the new SDL_Texture API
authorSam Lantinga <slouken@libsdl.org>
Sat, 18 Aug 2007 01:44:21 +0000
changeset 2266e61ad15a205f
parent 2265 265bb136af92
child 2267 c785543d1843
More work in progress integrating SDL_Surface and the new SDL_Texture API
include/SDL_compat.h
include/SDL_video.h
src/SDL_compat.c
src/video/SDL_RLEaccel.c
src/video/SDL_blit.c
src/video/SDL_blit.h
src/video/SDL_surface.c
src/video/SDL_video.c
     1.1 --- a/include/SDL_compat.h	Fri Aug 17 06:58:20 2007 +0000
     1.2 +++ b/include/SDL_compat.h	Sat Aug 18 01:44:21 2007 +0000
     1.3 @@ -37,6 +37,8 @@
     1.4  #endif
     1.5  
     1.6  #define SDL_SWSURFACE       0x00000000  /* Not used */
     1.7 +//#define SDL_SRCALPHA        0x00010000
     1.8 +//#define SDL_SRCCOLORKEY     0x00020000
     1.9  #define SDL_ANYFORMAT       0x00100000
    1.10  #define SDL_HWPALETTE       0x00200000
    1.11  #define SDL_DOUBLEBUF       0x00400000
    1.12 @@ -146,6 +148,8 @@
    1.13  extern DECLSPEC void SDLCALL SDL_UpdateRect(SDL_Surface * screen, Sint32 x,
    1.14                                              Sint32 y, Uint32 w, Uint32 h);
    1.15  extern DECLSPEC int SDLCALL SDL_Flip(SDL_Surface * screen);
    1.16 +extern DECLSPEC int SDLCALL SDL_SetAlpha(SDL_Surface * surface, Uint32 flag,
    1.17 +                                         Uint8 alpha);
    1.18  extern DECLSPEC SDL_Surface *SDLCALL SDL_DisplayFormat(SDL_Surface * surface);
    1.19  extern DECLSPEC SDL_Surface *SDLCALL SDL_DisplayFormatAlpha(SDL_Surface *
    1.20                                                              surface);
     2.1 --- a/include/SDL_video.h	Fri Aug 17 06:58:20 2007 +0000
     2.2 +++ b/include/SDL_video.h	Sat Aug 18 01:44:21 2007 +0000
     2.3 @@ -265,10 +265,7 @@
     2.4  /* These are the currently supported flags for the SDL_surface */
     2.5  /* Used internally (read-only) */
     2.6  #define SDL_PREALLOC        0x00000001  /* Surface uses preallocated memory */
     2.7 -#define SDL_SRCALPHA        0x00000004  /* Blit uses source alpha blending */
     2.8 -#define SDL_SRCCOLORKEY     0x00000008  /* Blit uses a source color key */
     2.9 -#define SDL_RLEACCELOK      0x00000010  /* Private flag */
    2.10 -#define SDL_RLEACCEL        0x00000020  /* Surface is RLE encoded */
    2.11 +#define SDL_RLEACCEL        0x00000001  /* Surface is RLE encoded */
    2.12  
    2.13  /* Evaluates to true if the surface needs to be locked before access */
    2.14  #define SDL_MUSTLOCK(S)	(((S)->flags & SDL_RLEACCEL) != 0)
    2.15 @@ -1401,34 +1398,157 @@
    2.16  		SDL_SaveBMP_RW(surface, SDL_RWFromFile(file, "wb"), 1)
    2.17  
    2.18  /*
    2.19 - * Sets the color key (transparent pixel) in a blittable surface.
    2.20 - * If 'flag' is SDL_SRCCOLORKEY (optionally OR'd with SDL_RLEACCEL), 
    2.21 - * 'key' will be the transparent pixel in the source image of a blit.
    2.22 - * SDL_RLEACCEL requests RLE acceleration for the surface if present,
    2.23 - * and removes RLE acceleration if absent.
    2.24 - * If 'flag' is 0, this function clears any current color key.
    2.25 - * This function returns 0, or -1 if there was an error.
    2.26 + * \fn int SDL_SetSurfaceRLE(SDL_Surface *surface, int flag)
    2.27 + *
    2.28 + * \brief Sets the RLE acceleration hint for a surface.
    2.29 + *
    2.30 + * \return 0 on success, or -1 if the surface is not valid
    2.31 + *
    2.32 + * \note If RLE is enabled, colorkey and alpha blending blits are much faster,
    2.33 + *       but the surface must be locked before directly accessing the pixels.
    2.34   */
    2.35 -extern DECLSPEC int SDLCALL SDL_SetColorKey
    2.36 -    (SDL_Surface * surface, Uint32 flag, Uint32 key);
    2.37 +extern DECLSPEC int SDLCALL SDL_SetSurfaceRLE(SDL_Surface *surface, int flag);
    2.38  
    2.39  /*
    2.40 - * This function sets the alpha value for the entire surface, as opposed to
    2.41 - * using the alpha component of each pixel. This value measures the range
    2.42 - * of transparency of the surface, 0 being completely transparent to 255
    2.43 - * being completely opaque. An 'alpha' value of 255 causes blits to be
    2.44 - * opaque, the source pixels copied to the destination (the default). Note
    2.45 - * that per-surface alpha can be combined with colorkey transparency.
    2.46 + * \fn int SDL_SetColorKey(SDL_Surface *surface, Uint32 flag, Uint32 key)
    2.47 + *
    2.48 + * \brief Sets the color key (transparent pixel) in a blittable surface.
    2.49 + *
    2.50 + * \param surface The surface to update
    2.51 + * \param flag Non-zero to enable colorkey and 0 to disable colorkey 
    2.52 + * \param key The transparent pixel in the native surface format
    2.53 + *
    2.54 + * \return 0 on success, or -1 if the surface is not valid
    2.55 + */
    2.56 +extern DECLSPEC int SDLCALL SDL_SetColorKey(SDL_Surface *surface, Uint32 flag, Uint32 key);
    2.57 +
    2.58 +/**
    2.59 + * \fn int SDL_SetSurfaceColorMod(SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b)
    2.60 + *
    2.61 + * \brief Set an additional color value used in blit operations
    2.62 + *
    2.63 + * \param surface The surface to update
    2.64 + * \param r The red source color value multiplied into blit operations
    2.65 + * \param g The green source color value multiplied into blit operations
    2.66 + * \param b The blue source color value multiplied into blit operations
    2.67 + *
    2.68 + * \return 0 on success, or -1 if the surface is not valid
    2.69 + *
    2.70 + * \sa SDL_GetSurfaceColorMod()
    2.71 + */
    2.72 +extern DECLSPEC int SDLCALL SDL_SetSurfaceColorMod(SDL_Surface *surface,
    2.73 +                                                   Uint8 r, Uint8 g, Uint8 b);
    2.74 +
    2.75 +
    2.76 +/**
    2.77 + * \fn int SDL_GetSurfaceColorMod(SDL_Surface *surface, Uint8 *r, Uint8 *g, Uint8 *b)
    2.78 + *
    2.79 + * \brief Get the additional color value used in blit operations
    2.80 + *
    2.81 + * \param surface The surface to query
    2.82 + * \param r A pointer filled in with the source red color value
    2.83 + * \param g A pointer filled in with the source green color value
    2.84 + * \param b A pointer filled in with the source blue color value
    2.85 + *
    2.86 + * \return 0 on success, or -1 if the surface is not valid
    2.87 + *
    2.88 + * \sa SDL_SetSurfaceColorMod()
    2.89 + */
    2.90 +extern DECLSPEC int SDLCALL SDL_GetSurfaceColorMod(SDL_Surface *surface,
    2.91 +                                                   Uint8 * r, Uint8 * g,
    2.92 +                                                   Uint8 * b);
    2.93 +
    2.94 +/**
    2.95 + * \fn int SDL_SetSurfaceAlphaMod(SDL_Surface *surface, Uint8 alpha)
    2.96 + *
    2.97 + * \brief Set an additional alpha value used in blit operations
    2.98 + *
    2.99 + * \param surface The surface to update
   2.100 + * \param alpha The source alpha value multiplied into blit operations.
   2.101 + *
   2.102 + * \return 0 on success, or -1 if the surface is not valid
   2.103 + *
   2.104 + * \sa SDL_GetSurfaceAlphaMod()
   2.105 + */
   2.106 +extern DECLSPEC int SDLCALL SDL_SetSurfaceAlphaMod(SDL_Surface *surface,
   2.107 +                                                   Uint8 alpha);
   2.108 +
   2.109 +/**
   2.110 + * \fn int SDL_GetSurfaceAlphaMod(SDL_Surface *surface, Uint8 *alpha)
   2.111 + *
   2.112 + * \brief Get the additional alpha value used in blit operations
   2.113   *
   2.114 - * If 'flag' is 0, alpha blending is disabled for the surface.
   2.115 - * If 'flag' is SDL_SRCALPHA, alpha blending is enabled for the surface.
   2.116 - * OR:ing the flag with SDL_RLEACCEL requests RLE acceleration for the
   2.117 - * surface; if SDL_RLEACCEL is not specified, the RLE accel will be removed.
   2.118 + * \param surface The surface to query
   2.119 + * \param alpha A pointer filled in with the source alpha value
   2.120 + *
   2.121 + * \return 0 on success, or -1 if the surface is not valid
   2.122 + *
   2.123 + * \sa SDL_SetSurfaceAlphaMod()
   2.124 + */
   2.125 +extern DECLSPEC int SDLCALL SDL_GetSurfaceAlphaMod(SDL_Surface *surface,
   2.126 +                                                   Uint8 * alpha);
   2.127 +
   2.128 +/**
   2.129 + * \fn int SDL_SetSurfaceBlendMode(SDL_Surface *surface, int blendMode)
   2.130 + *
   2.131 + * \brief Set the blend mode used for blit operations
   2.132 + *
   2.133 + * \param surface The surface to update
   2.134 + * \param blendMode SDL_TextureBlendMode to use for blit blending
   2.135 + *
   2.136 + * \return 0 on success, or -1 if the parameters are not valid
   2.137 + *
   2.138 + * \sa SDL_GetSurfaceBlendMode()
   2.139 + */
   2.140 +extern DECLSPEC int SDLCALL SDL_SetSurfaceBlendMode(SDL_Surface *surface,
   2.141 +                                                    int blendMode);
   2.142 +
   2.143 +/**
   2.144 + * \fn int SDL_GetSurfaceBlendMode(SDL_Surface *surface, int *blendMode)
   2.145 + *
   2.146 + * \brief Get the blend mode used for blit operations
   2.147 + *
   2.148 + * \param surface The surface to query
   2.149 + * \param blendMode A pointer filled in with the current blend mode
   2.150 + *
   2.151 + * \return 0 on success, or -1 if the surface is not valid
   2.152   *
   2.153 - * The 'alpha' parameter is ignored for surfaces that have an alpha channel.
   2.154 + * \sa SDL_SetSurfaceBlendMode()
   2.155   */
   2.156 -extern DECLSPEC int SDLCALL SDL_SetAlpha(SDL_Surface * surface, Uint32 flag,
   2.157 -                                         Uint8 alpha);
   2.158 +extern DECLSPEC int SDLCALL SDL_GetSurfaceBlendMode(SDL_Surface *surface,
   2.159 +                                                    int *blendMode);
   2.160 +
   2.161 +/**
   2.162 + * \fn int SDL_SetSurfaceScaleMode(SDL_Surface *surface, int scaleMode)
   2.163 + *
   2.164 + * \brief Set the scale mode used for blit operations
   2.165 + *
   2.166 + * \param surface The surface to update
   2.167 + * \param scaleMode SDL_TextureScaleMode to use for blit scaling
   2.168 + *
   2.169 + * \return 0 on success, or -1 if the surface is not valid or the scale mode is not supported
   2.170 + *
   2.171 + * \note If the scale mode is not supported, the closest supported mode is chosen.  Currently only SDL_TEXTURESCALEMODE_FAST is supported on surfaces.
   2.172 + *
   2.173 + * \sa SDL_GetSurfaceScaleMode()
   2.174 + */
   2.175 +extern DECLSPEC int SDLCALL SDL_SetSurfaceScaleMode(SDL_Surface *surface,
   2.176 +                                                    int scaleMode);
   2.177 +
   2.178 +/**
   2.179 + * \fn int SDL_GetSurfaceScaleMode(SDL_Surface *surface, int *scaleMode)
   2.180 + *
   2.181 + * \brief Get the scale mode used for blit operations
   2.182 + *
   2.183 + * \param surface The surface to query
   2.184 + * \param scaleMode A pointer filled in with the current scale mode
   2.185 + *
   2.186 + * \return 0 on success, or -1 if the surface is not valid
   2.187 + *
   2.188 + * \sa SDL_SetSurfaceScaleMode()
   2.189 + */
   2.190 +extern DECLSPEC int SDLCALL SDL_GetSurfaceScaleMode(SDL_Surface *surface,
   2.191 +                                                    int *scaleMode);
   2.192  
   2.193  /*
   2.194   * Sets the clipping rectangle for the destination surface in a blit.
     3.1 --- a/src/SDL_compat.c	Fri Aug 17 06:58:20 2007 +0000
     3.2 +++ b/src/SDL_compat.c	Sat Aug 18 01:44:21 2007 +0000
     3.3 @@ -589,6 +589,22 @@
     3.4      return SDL_PublicSurface;
     3.5  }
     3.6  
     3.7 +int
     3.8 +SDL_SetAlpha(SDL_Surface * surface, Uint32 flag, Uint8 value)
     3.9 +{
    3.10 +    if (flag & SDL_RLEACCEL) {
    3.11 +        SDL_SetSurfaceRLE(surface, 1);
    3.12 +    }
    3.13 +    if (flag) {
    3.14 +        SDL_SetSurfaceAlphaMod(surface, value);
    3.15 +        SDL_SetSurfaceBlendMode(surface, SDL_TEXTUREBLENDMODE_BLEND);
    3.16 +    } else {
    3.17 +        SDL_SetSurfaceAlphaMod(surface, 0xFF);
    3.18 +        SDL_SetSurfaceBlendMode(surface, SDL_TEXTUREBLENDMODE_NONE);
    3.19 +    }
    3.20 +    return 0;
    3.21 +}
    3.22 +
    3.23  SDL_Surface *
    3.24  SDL_DisplayFormat(SDL_Surface * surface)
    3.25  {
    3.26 @@ -600,15 +616,7 @@
    3.27      }
    3.28  
    3.29      /* Set the flags appropriate for copying to display surface */
    3.30 -    flags = SDL_SWSURFACE;
    3.31 -#ifdef AUTORLE_DISPLAYFORMAT
    3.32 -    flags |= (surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA));
    3.33 -    flags |= SDL_RLEACCELOK;
    3.34 -#else
    3.35 -    flags |=
    3.36 -        surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA | SDL_RLEACCELOK);
    3.37 -#endif
    3.38 -    return SDL_ConvertSurface(surface, SDL_PublicSurface->format, flags);
    3.39 +    return SDL_ConvertSurface(surface, SDL_PublicSurface->format, SDL_RLEACCELOK);
    3.40  }
    3.41  
    3.42  SDL_Surface *
    3.43 @@ -658,8 +666,7 @@
    3.44          break;
    3.45      }
    3.46      format = SDL_AllocFormat(32, rmask, gmask, bmask, amask);
    3.47 -    flags = surface->flags & (SDL_SRCALPHA | SDL_RLEACCELOK);
    3.48 -    converted = SDL_ConvertSurface(surface, format, flags);
    3.49 +    converted = SDL_ConvertSurface(surface, format, SDL_RLEACCELOK);
    3.50      SDL_FreeFormat(format);
    3.51      return converted;
    3.52  }
     4.1 --- a/src/video/SDL_RLEaccel.c	Fri Aug 17 06:58:20 2007 +0000
     4.2 +++ b/src/video/SDL_RLEaccel.c	Sat Aug 18 01:44:21 2007 +0000
     4.3 @@ -905,8 +905,7 @@
     4.4          }
     4.5      }
     4.6  
     4.7 -    alpha = (src->flags & SDL_SRCALPHA) == SDL_SRCALPHA
     4.8 -        ? src->map->info.a : 255;
     4.9 +    alpha = src->map->info.a;
    4.10      /* if left or right edge clipping needed, call clip blit */
    4.11      if (srcrect->x || srcrect->w != src->w) {
    4.12          RLEClipBlit(w, srcbuf, dst, dstbuf, srcrect, alpha);
    4.13 @@ -1803,7 +1802,7 @@
    4.14  int
    4.15  SDL_RLESurface(SDL_Surface * surface)
    4.16  {
    4.17 -    int retcode;
    4.18 +    int flags;
    4.19  
    4.20      /* Clear any previous RLE conversion */
    4.21      if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) {
    4.22 @@ -1812,35 +1811,45 @@
    4.23  
    4.24      /* We don't support RLE encoding of bitmaps */
    4.25      if (surface->format->BitsPerPixel < 8) {
    4.26 -        return (-1);
    4.27 +        return -1;
    4.28      }
    4.29  
    4.30 -    /* Lock the surface if it's in hardware */
    4.31 -    if (SDL_MUSTLOCK(surface)) {
    4.32 -        if (SDL_LockSurface(surface) < 0) {
    4.33 -            return (-1);
    4.34 -        }
    4.35 +    /* Make sure the pixels are available */
    4.36 +    if (!surface->pixels) {
    4.37 +        return -1;
    4.38 +    }
    4.39 +
    4.40 +    /* If we don't have colorkey or blending, nothing to do... */
    4.41 +    flags = surface->map->info.flags;
    4.42 +    if(!(flags & (SDL_COPY_COLORKEY|SDL_COPY_BLEND))) {
    4.43 +        return -1;
    4.44      }
    4.45  
    4.46 -    /* Encode */
    4.47 -    if ((surface->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) {
    4.48 -        retcode = RLEColorkeySurface(surface);
    4.49 -    } else {
    4.50 -        if ((surface->flags & SDL_SRCALPHA) == SDL_SRCALPHA
    4.51 -            && surface->format->Amask != 0)
    4.52 -            retcode = RLEAlphaSurface(surface);
    4.53 -        else
    4.54 -            retcode = -1;       /* no RLE for per-surface alpha sans ckey */
    4.55 +    /* Pass on combinations not supported */
    4.56 +    if ((flags & SDL_COPY_MODULATE_COLOR) ||
    4.57 +        (flags & (SDL_COPY_ADD|SDL_COPY_MOD)) ||
    4.58 +        (flags & SDL_COPY_NEAREST)) {
    4.59 +        return -1;
    4.60      }
    4.61  
    4.62 -    /* Unlock the surface if it's in hardware */
    4.63 -    if (SDL_MUSTLOCK(surface)) {
    4.64 -        SDL_UnlockSurface(surface);
    4.65 +    /* Encode and set up the blit */
    4.66 +    if (!surface->format->Amask || !(flags & SDL_COPY_BLEND)) {
    4.67 +        if (!surface->map->identity) {
    4.68 +            return -1;
    4.69 +        }
    4.70 +        if (RLEColorkeySurface(surface) < 0) {
    4.71 +            return -1;
    4.72 +        }
    4.73 +        surface->map->blit = SDL_RLEBlit;
    4.74 +        surface->map->info.flags |= SDL_COPY_RLE_COLORKEY;
    4.75 +    } else {
    4.76 +        if (RLEAlphaSurface(surface) < 0) {
    4.77 +            return -1;
    4.78 +        }
    4.79 +        surface->map->blit = SDL_RLEAlphaBlit;
    4.80 +        surface->map->info.flags |= SDL_COPY_RLE_ALPHAKEY;
    4.81      }
    4.82  
    4.83 -    if (retcode < 0)
    4.84 -        return -1;
    4.85 -
    4.86      /* The surface is now accelerated */
    4.87      surface->flags |= SDL_RLEACCEL;
    4.88  
    4.89 @@ -1931,13 +1940,12 @@
    4.90  void
    4.91  SDL_UnRLESurface(SDL_Surface * surface, int recode)
    4.92  {
    4.93 -    if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) {
    4.94 +    if (surface->flags & SDL_RLEACCEL) {
    4.95          surface->flags &= ~SDL_RLEACCEL;
    4.96  
    4.97          if (recode && !(surface->flags & SDL_PREALLOC)) {
    4.98 -            if ((surface->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) {
    4.99 +            if (surface->map->info.flags & SDL_COPY_RLE_COLORKEY) {
   4.100                  SDL_Rect full;
   4.101 -                unsigned alpha_flag;
   4.102  
   4.103                  /* re-create the original surface */
   4.104                  surface->pixels = SDL_malloc(surface->h * surface->pitch);
   4.105 @@ -1954,10 +1962,7 @@
   4.106                  full.x = full.y = 0;
   4.107                  full.w = surface->w;
   4.108                  full.h = surface->h;
   4.109 -                alpha_flag = surface->flags & SDL_SRCALPHA;
   4.110 -                surface->flags &= ~SDL_SRCALPHA;        /* opaque blit */
   4.111                  SDL_RLEBlit(surface, &full, surface, &full);
   4.112 -                surface->flags |= alpha_flag;
   4.113              } else {
   4.114                  if (!UnRLEAlpha(surface)) {
   4.115                      /* Oh crap... */
   4.116 @@ -1966,8 +1971,9 @@
   4.117                  }
   4.118              }
   4.119          }
   4.120 +        surface->map->info.flags &= (SDL_COPY_RLE_COLORKEY|SDL_COPY_RLE_ALPHAKEY);
   4.121  
   4.122 -        if (surface->map && surface->map->data) {
   4.123 +        if (surface->map->data) {
   4.124              SDL_free(surface->map->data);
   4.125              surface->map->data = NULL;
   4.126          }
     5.1 --- a/src/video/SDL_blit.c	Fri Aug 17 06:58:20 2007 +0000
     5.2 +++ b/src/video/SDL_blit.c	Sat Aug 18 01:44:21 2007 +0000
     5.3 @@ -206,7 +206,8 @@
     5.4  SDL_CalculateBlit(SDL_Surface * surface)
     5.5  {
     5.6      SDL_BlitFunc blit = NULL;
     5.7 -    SDL_Surface *dst = surface->map->dst;
     5.8 +    SDL_BlitMap *map = surface->map;
     5.9 +    SDL_Surface *dst = map->dst;
    5.10      Uint32 src_format;
    5.11      Uint32 dst_format;
    5.12  
    5.13 @@ -214,67 +215,48 @@
    5.14      if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) {
    5.15          SDL_UnRLESurface(surface, 1);
    5.16      }
    5.17 -    surface->map->blit = NULL;
    5.18 -    surface->map->info.src_fmt = surface->format;
    5.19 -    surface->map->info.src_pitch = surface->pitch;
    5.20 -    surface->map->info.dst_fmt = dst->format;
    5.21 -    surface->map->info.dst_pitch = dst->pitch;
    5.22 +    map->blit = SDL_SoftBlit;
    5.23 +    map->info.src_fmt = surface->format;
    5.24 +    map->info.src_pitch = surface->pitch;
    5.25 +    map->info.dst_fmt = dst->format;
    5.26 +    map->info.dst_pitch = dst->pitch;
    5.27  
    5.28 +    /* See if we can do RLE acceleration */
    5.29 +    if (surface->flags & SDL_RLEACCELOK) {
    5.30 +        if (SDL_RLESurface(surface) == 0) {
    5.31 +            return 0;
    5.32 +        }
    5.33 +    }
    5.34 +
    5.35 +    /* Choose a standard blit function */
    5.36      src_format = SDL_MasksToPixelFormatEnum(surface->format->BitsPerPixel, surface->format->Rmask, surface->format->Gmask, surface->format->Bmask, surface->format->Amask);
    5.37      dst_format = SDL_MasksToPixelFormatEnum(dst->format->BitsPerPixel, dst->format->Rmask, dst->format->Gmask, dst->format->Bmask, dst->format->Amask);
    5.38  
    5.39 -    /* Check for special "identity" case -- copy blit */
    5.40 -    if (surface->map->identity && !surface->map->info.flags) {
    5.41 +    if (map->identity && !map->info.flags) {
    5.42          /* Handle overlapping blits on the same surface */
    5.43          if (surface == dst) {
    5.44              blit = SDL_BlitCopyOverlap;
    5.45          } else {
    5.46              blit = SDL_BlitCopy;
    5.47          }
    5.48 +    } else if (surface->format->BitsPerPixel < 8) {
    5.49 +        blit = SDL_ChooseBlitFunc(src_format, dst_format, map->info.flags, SDL_BlitFuncTable0);
    5.50 +    } else if (surface->format->BytesPerPixel == 1) {
    5.51 +        blit = SDL_ChooseBlitFunc(src_format, dst_format, map->info.flags, SDL_BlitFuncTable1);
    5.52      } else {
    5.53 -        if (surface->format->BitsPerPixel < 8) {
    5.54 -            blit = SDL_ChooseBlitFunc(src_format, dst_format, surface->map->info.flags, SDL_BlitFuncTable0);
    5.55 -        } else {
    5.56 -            switch (surface->format->BytesPerPixel) {
    5.57 -            case 1:
    5.58 -                blit = SDL_ChooseBlitFunc(src_format, dst_format, surface->map->info.flags, SDL_BlitFuncTable1);
    5.59 -                break;
    5.60 -            case 2:
    5.61 -            case 3:
    5.62 -            case 4:
    5.63 -                blit = SDL_ChooseBlitFunc(src_format, dst_format, surface->map->info.flags, SDL_BlitFuncTableN);
    5.64 -                break;
    5.65 -            }
    5.66 -        }
    5.67 +        blit = SDL_ChooseBlitFunc(src_format, dst_format, map->info.flags, SDL_BlitFuncTableN);
    5.68      }
    5.69      if (blit == NULL) {
    5.70 -        blit = SDL_ChooseBlitFunc(src_format, dst_format, surface->map->info.flags, SDL_GeneratedBlitFuncTable);
    5.71 +        blit = SDL_ChooseBlitFunc(src_format, dst_format, map->info.flags, SDL_GeneratedBlitFuncTable);
    5.72      }
    5.73  
    5.74      /* Make sure we have a blit function */
    5.75      if (blit == NULL) {
    5.76 -        SDL_InvalidateMap(surface->map);
    5.77 +        SDL_InvalidateMap(map);
    5.78          SDL_SetError("Blit combination not supported");
    5.79          return (-1);
    5.80      }
    5.81  
    5.82 -    /* Choose software blitting function */
    5.83 -    if ((surface->flags & SDL_RLEACCELOK) && !(surface->map->flags & () {
    5.84 -        if (surface->map->identity && (surface->map->flags & SDL_COPY_COLORKEY)
    5.85 -            && (blit_index == 1
    5.86 -                || (blit_index == 3 && !surface->format->Amask))) {
    5.87 -            if (SDL_RLESurface(surface) == 0)
    5.88 -                surface->map->blit = SDL_RLEBlit;
    5.89 -        } else if (blit_index == 2 && surface->format->Amask) {
    5.90 -            if (SDL_RLESurface(surface) == 0)
    5.91 -                surface->map->blit = SDL_RLEAlphaBlit;
    5.92 -        }
    5.93 -    }
    5.94 -
    5.95 -    if (surface->map->blit == NULL) {
    5.96 -        surface->map->blit = SDL_SoftBlit;
    5.97 -        surface->map->data = blit;
    5.98 -    }
    5.99      return (0);
   5.100  }
   5.101  
     6.1 --- a/src/video/SDL_blit.h	Fri Aug 17 06:58:20 2007 +0000
     6.2 +++ b/src/video/SDL_blit.h	Sat Aug 18 01:44:21 2007 +0000
     6.3 @@ -41,23 +41,26 @@
     6.4  #include "SDL_endian.h"
     6.5  
     6.6  /* SDL blit copy flags */
     6.7 -#define SDL_COPY_MODULATE_COLOR     0x0001
     6.8 -#define SDL_COPY_MODULATE_ALPHA     0x0002
     6.9 -#define SDL_COPY_MASK               0x0010
    6.10 -#define SDL_COPY_BLEND              0x0020
    6.11 -#define SDL_COPY_ADD                0x0040
    6.12 -#define SDL_COPY_MOD                0x0080
    6.13 -#define SDL_COPY_COLORKEY           0x0100
    6.14 -#define SDL_COPY_NEAREST            0x0200
    6.15 +#define SDL_COPY_MODULATE_COLOR     0x00000001
    6.16 +#define SDL_COPY_MODULATE_ALPHA     0x00000002
    6.17 +#define SDL_COPY_MASK               0x00000010
    6.18 +#define SDL_COPY_BLEND              0x00000020
    6.19 +#define SDL_COPY_ADD                0x00000040
    6.20 +#define SDL_COPY_MOD                0x00000080
    6.21 +#define SDL_COPY_COLORKEY           0x00000100
    6.22 +#define SDL_COPY_NEAREST            0x00000200
    6.23 +#define SDL_COPY_RLE_DESIRED        0x00001000
    6.24 +#define SDL_COPY_RLE_COLORKEY       0x00002000
    6.25 +#define SDL_COPY_RLE_ALPHAKEY       0x00004000
    6.26  
    6.27  /* SDL blit CPU flags */
    6.28 -#define SDL_CPU_ANY                 0x0000
    6.29 -#define SDL_CPU_MMX                 0x0001
    6.30 -#define SDL_CPU_3DNOW               0x0002
    6.31 -#define SDL_CPU_SSE                 0x0004
    6.32 -#define SDL_CPU_SSE2                0x0008
    6.33 -#define SDL_CPU_ALTIVEC_PREFETCH    0x0010
    6.34 -#define SDL_CPU_ALTIVEC_NOPREFETCH  0x0020
    6.35 +#define SDL_CPU_ANY                 0x00000000
    6.36 +#define SDL_CPU_MMX                 0x00000001
    6.37 +#define SDL_CPU_3DNOW               0x00000002
    6.38 +#define SDL_CPU_SSE                 0x00000004
    6.39 +#define SDL_CPU_SSE2                0x00000008
    6.40 +#define SDL_CPU_ALTIVEC_PREFETCH    0x00000010
    6.41 +#define SDL_CPU_ALTIVEC_NOPREFETCH  0x00000020
    6.42  
    6.43  typedef struct {
    6.44      Uint8 *src;
     7.1 --- a/src/video/SDL_surface.c	Fri Aug 17 06:58:20 2007 +0000
     7.2 +++ b/src/video/SDL_surface.c	Sat Aug 18 01:44:21 2007 +0000
     7.3 @@ -212,153 +212,251 @@
     7.4      return 0;
     7.5  }
     7.6  
     7.7 -/*
     7.8 - * Set the color key in a blittable surface
     7.9 - */
    7.10 -int
    7.11 -SDL_SetColorKey(SDL_Surface * surface, Uint32 flag, Uint32 key)
    7.12 +int SDL_SetSurfaceRLE(SDL_Surface *surface, int flag)
    7.13  {
    7.14 -    /* Sanity check the flag as it gets passed in */
    7.15 -    if (flag & SDL_SRCCOLORKEY) {
    7.16 -        if (flag & (SDL_RLEACCEL | SDL_RLEACCELOK)) {
    7.17 -            flag = (SDL_SRCCOLORKEY | SDL_RLEACCELOK);
    7.18 -        } else {
    7.19 -            flag = SDL_SRCCOLORKEY;
    7.20 -        }
    7.21 -    } else {
    7.22 -        flag = 0;
    7.23 -    }
    7.24 +    Uint32 flags;
    7.25  
    7.26 -    /* Optimize away operations that don't change anything */
    7.27 -    if ((flag == (surface->flags & (SDL_SRCCOLORKEY | SDL_RLEACCELOK))) &&
    7.28 -        (key == surface->map->ckey)) {
    7.29 -        return (0);
    7.30 -    }
    7.31 -
    7.32 -    /* UnRLE surfaces before we change the colorkey */
    7.33 -    if (surface->flags & SDL_RLEACCEL) {
    7.34 -        SDL_UnRLESurface(surface, 1);
    7.35 +    if (!surface) {
    7.36 +        return -1;
    7.37      }
    7.38  
    7.39      if (flag) {
    7.40 -        surface->flags |= SDL_SRCCOLORKEY;
    7.41 -        surface->map->ckey = key;
    7.42 -        if (flag & SDL_RLEACCELOK) {
    7.43 -            surface->flags |= SDL_RLEACCELOK;
    7.44 -        } else {
    7.45 -            surface->flags &= ~SDL_RLEACCELOK;
    7.46 -        }
    7.47 +        surface->flags |= SDL_RLEACCELOK;
    7.48      } else {
    7.49 -        surface->flags &= ~(SDL_SRCCOLORKEY | SDL_RLEACCELOK);
    7.50 -        surface->map->ckey = 0;
    7.51 +        surface->flags &= ~SDL_RLEACCELOK;
    7.52      }
    7.53 -    SDL_InvalidateMap(surface->map);
    7.54 -    return (0);
    7.55 +    if (surface->flags != flags) {
    7.56 +        SDL_InvalidateMap(surface->map);
    7.57 +    }
    7.58 +    return 0;
    7.59  }
    7.60  
    7.61 -/* This function sets the alpha channel of a surface */
    7.62 -int
    7.63 -SDL_SetAlpha(SDL_Surface * surface, Uint32 flag, Uint8 value)
    7.64 +int SDL_SetColorKey(SDL_Surface *surface, Uint32 flag, Uint32 key)
    7.65  {
    7.66 -    Uint32 oldflags = surface->flags;
    7.67 -    Uint32 oldalpha = (surface->map->cmod >> 24);
    7.68 +    int flags;
    7.69  
    7.70 -    /* Sanity check the flag as it gets passed in */
    7.71 -    if (flag & SDL_SRCALPHA) {
    7.72 -        if (flag & (SDL_RLEACCEL | SDL_RLEACCELOK)) {
    7.73 -            flag = (SDL_SRCALPHA | SDL_RLEACCELOK);
    7.74 -        } else {
    7.75 -            flag = SDL_SRCALPHA;
    7.76 -        }
    7.77 -    } else {
    7.78 -        flag = 0;
    7.79 +    if (!surface) {
    7.80 +        return -1;
    7.81 +    }
    7.82 +
    7.83 +    if (flag & SDL_RLEACCEL) {
    7.84 +        SDL_SetSurfaceRLE(surface, 1);
    7.85      }
    7.86  
    7.87 -    /* Optimize away operations that don't change anything */
    7.88 -    if ((flag == (surface->flags & (SDL_SRCALPHA | SDL_RLEACCELOK))) &&
    7.89 -        (!flag || value == oldalpha)) {
    7.90 -        return (0);
    7.91 +    flags = surface->map->info.flags;
    7.92 +    if (flag) {
    7.93 +        surface->map->info.flags |= SDL_COPY_COLORKEY;
    7.94 +        surface->map->info.colorkey = key;
    7.95 +    } else {
    7.96 +        surface->map->info.flags &= ~SDL_COPY_COLORKEY;
    7.97 +    }
    7.98 +    if (surface->map->info.flags != flags) {
    7.99 +        SDL_InvalidateMap(surface->map);
   7.100 +    }
   7.101 +    return 0;
   7.102 +}
   7.103 +
   7.104 +int SDL_SetSurfaceColorMod(SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b)
   7.105 +{
   7.106 +    int flags;
   7.107 +
   7.108 +    if (!surface) {
   7.109 +        return -1;
   7.110      }
   7.111  
   7.112 -    if (!(flag & SDL_RLEACCELOK) && (surface->flags & SDL_RLEACCEL))
   7.113 -        SDL_UnRLESurface(surface, 1);
   7.114 +    surface->map->info.r = r;
   7.115 +    surface->map->info.g = g;
   7.116 +    surface->map->info.b = b;
   7.117  
   7.118 -    if (flag) {
   7.119 -        surface->flags |= SDL_SRCALPHA;
   7.120 -        surface->map->cmod &= 0x00FFFFFF;
   7.121 -        surface->map->cmod |= ((Uint32) value << 24);
   7.122 -        if (flag & SDL_RLEACCELOK) {
   7.123 -            surface->flags |= SDL_RLEACCELOK;
   7.124 -        } else {
   7.125 -            surface->flags &= ~SDL_RLEACCELOK;
   7.126 -        }
   7.127 +    flags = surface->map->info.flags;
   7.128 +    if (r != 0xFF || g != 0xFF || b != 0xFF) {
   7.129 +        surface->map->info.flags |= SDL_COPY_MODULATE_COLOR;
   7.130      } else {
   7.131 -        surface->flags &= ~SDL_SRCALPHA;
   7.132 -        surface->map->cmod |= 0xFF000000;
   7.133 +        surface->map->info.flags &= ~SDL_COPY_MODULATE_COLOR;
   7.134      }
   7.135 -    /*
   7.136 -     * The representation for software surfaces is independent of
   7.137 -     * per-surface alpha, so no need to invalidate the blit mapping
   7.138 -     * if just the alpha value was changed. (If either is 255, we still
   7.139 -     * need to invalidate.)
   7.140 -     */
   7.141 -    if (oldflags != surface->flags
   7.142 -        || (((oldalpha + 1) ^ (value + 1)) & 0x100)) {
   7.143 +    if (surface->map->info.flags != flags) {
   7.144          SDL_InvalidateMap(surface->map);
   7.145      }
   7.146 -    return (0);
   7.147 +    return 0;
   7.148  }
   7.149  
   7.150 -int
   7.151 -SDL_SetAlphaChannel(SDL_Surface * surface, Uint8 value)
   7.152 +
   7.153 +int SDL_GetSurfaceColorMod(SDL_Surface *surface, Uint8 * r, Uint8 * g, Uint8 * b)
   7.154  {
   7.155 -    int row, col;
   7.156 -    int offset;
   7.157 -    Uint8 *buf;
   7.158 -
   7.159 -    if ((surface->format->Amask != 0xFF000000) &&
   7.160 -        (surface->format->Amask != 0x000000FF)) {
   7.161 -        SDL_SetError("Unsupported surface alpha mask format");
   7.162 +    if (!surface) {
   7.163          return -1;
   7.164      }
   7.165 -#if SDL_BYTEORDER == SDL_LIL_ENDIAN
   7.166 -    if (surface->format->Amask == 0xFF000000) {
   7.167 -        offset = 3;
   7.168 -    } else {
   7.169 -        offset = 0;
   7.170 +
   7.171 +    if (r) {
   7.172 +        *r = surface->map->info.r;
   7.173 +    }
   7.174 +    if (g) {
   7.175 +        *g = surface->map->info.g;
   7.176 +    }
   7.177 +    if (b) {
   7.178 +        *b = surface->map->info.b;
   7.179      }
   7.180 -#else
   7.181 -    if (surface->format->Amask == 0xFF000000) {
   7.182 -        offset = 0;
   7.183 -    } else {
   7.184 -        offset = 3;
   7.185 +    return 0;
   7.186 +}
   7.187 +
   7.188 +int SDL_SetSurfaceAlphaMod(SDL_Surface *surface, Uint8 alpha)
   7.189 +{
   7.190 +    int flags;
   7.191 +
   7.192 +    if (!surface) {
   7.193 +        return -1;
   7.194      }
   7.195 -#endif /* Byte ordering */
   7.196  
   7.197 -    /* Quickly set the alpha channel of an RGBA or ARGB surface */
   7.198 -    if (SDL_MUSTLOCK(surface)) {
   7.199 -        if (SDL_LockSurface(surface) < 0) {
   7.200 -            return -1;
   7.201 -        }
   7.202 +    surface->map->info.a = alpha;
   7.203 +
   7.204 +    flags = surface->map->info.flags;
   7.205 +    if (alpha != 0xFF) {
   7.206 +        surface->map->info.flags |= SDL_COPY_MODULATE_ALPHA;
   7.207 +    } else {
   7.208 +        surface->map->info.flags &= ~SDL_COPY_MODULATE_ALPHA;
   7.209 +    }
   7.210 +    if (surface->map->info.flags != flags) {
   7.211 +        SDL_InvalidateMap(surface->map);
   7.212      }
   7.213 -    row = surface->h;
   7.214 -    while (row--) {
   7.215 -        col = surface->w;
   7.216 -        buf = (Uint8 *) surface->pixels + row * surface->pitch + offset;
   7.217 -        while (col--) {
   7.218 -            *buf = value;
   7.219 -            buf += 4;
   7.220 -        }
   7.221 +    return 0;
   7.222 +}
   7.223 +
   7.224 +int SDL_GetSurfaceAlphaMod(SDL_Surface *surface, Uint8 * alpha)
   7.225 +{
   7.226 +    if (!surface) {
   7.227 +        return -1;
   7.228      }
   7.229 -    if (SDL_MUSTLOCK(surface)) {
   7.230 -        SDL_UnlockSurface(surface);
   7.231 +
   7.232 +    if (alpha) {
   7.233 +        *alpha = surface->map->info.a;
   7.234      }
   7.235      return 0;
   7.236  }
   7.237  
   7.238 -/*
   7.239 - * Set the clipping rectangle for a blittable surface
   7.240 - */
   7.241 +int SDL_SetSurfaceBlendMode(SDL_Surface *surface, int blendMode)
   7.242 +{
   7.243 +    int flags, status;
   7.244 +
   7.245 +    if (!surface) {
   7.246 +        return -1;
   7.247 +    }
   7.248 +
   7.249 +    status = 0;
   7.250 +    flags = surface->map->info.flags;
   7.251 +    surface->map->info.flags &= ~(SDL_COPY_MASK|SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD);
   7.252 +    switch (blendMode) {
   7.253 +    case SDL_TEXTUREBLENDMODE_NONE:
   7.254 +        break;
   7.255 +    case SDL_TEXTUREBLENDMODE_MASK:
   7.256 +        surface->map->info.flags |= SDL_COPY_MASK;
   7.257 +        break;
   7.258 +    case SDL_TEXTUREBLENDMODE_BLEND:
   7.259 +        surface->map->info.flags |= SDL_COPY_BLEND;
   7.260 +        break;
   7.261 +    case SDL_TEXTUREBLENDMODE_ADD:
   7.262 +        surface->map->info.flags |= SDL_COPY_ADD;
   7.263 +        break;
   7.264 +    case SDL_TEXTUREBLENDMODE_MOD:
   7.265 +        surface->map->info.flags |= SDL_COPY_MOD;
   7.266 +        break;
   7.267 +    default:
   7.268 +        SDL_Unsupported();
   7.269 +        status = -1;
   7.270 +        break;
   7.271 +    }
   7.272 +
   7.273 +    if (surface->map->info.flags != flags) {
   7.274 +        SDL_InvalidateMap(surface->map);
   7.275 +    }
   7.276 +    return status;
   7.277 +}
   7.278 +
   7.279 +int SDL_GetSurfaceBlendMode(SDL_Surface *surface, int *blendMode)
   7.280 +{
   7.281 +    if (!surface) {
   7.282 +        return -1;
   7.283 +    }
   7.284 +
   7.285 +    if (!blendMode) {
   7.286 +        return 0;
   7.287 +    }
   7.288 +
   7.289 +    switch(surface->map->info.flags & (SDL_COPY_MASK|SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
   7.290 +    case SDL_COPY_MASK:
   7.291 +        *blendMode = SDL_TEXTUREBLENDMODE_MASK:
   7.292 +        break;
   7.293 +    case SDL_COPY_BLEND:
   7.294 +        *blendMode = SDL_TEXTUREBLENDMODE_BLEND:
   7.295 +        break;
   7.296 +    case SDL_COPY_ADD:
   7.297 +        *blendMode = SDL_TEXTUREBLENDMODE_ADD:
   7.298 +        break;
   7.299 +    case SDL_COPY_MOD:
   7.300 +        *blendMode = SDL_TEXTUREBLENDMODE_MOD:
   7.301 +        break;
   7.302 +    default:
   7.303 +        *blendMode = SDL_TEXTUREBLENDMODE_NONE:
   7.304 +        break;
   7.305 +    }
   7.306 +    return 0;
   7.307 +}
   7.308 +
   7.309 +int SDL_SetSurfaceScaleMode(SDL_Surface *surface, int scaleMode)
   7.310 +{
   7.311 +    int flags, status;
   7.312 +
   7.313 +    if (!surface) {
   7.314 +        return -1;
   7.315 +    }
   7.316 +
   7.317 +    status = 0;
   7.318 +    flags = surface->map->info.flags;
   7.319 +    surface->map->info.flags &= ~(SDL_COPY_NEAREST);
   7.320 +    switch (scaleMode) {
   7.321 +    case SDL_TEXTURESCALEMODE_NONE:
   7.322 +        break;
   7.323 +    case SDL_TEXTURESCALEMODE_FAST:
   7.324 +        surface->map->info.flags |= SDL_COPY_NEAREST;
   7.325 +        break;
   7.326 +    case SDL_TEXTURESCALEMODE_SLOW:
   7.327 +    case SDL_TEXTURESCALEMODE_BEST:
   7.328 +        SDL_Unsupported();
   7.329 +        surface->map->info.flags |= SDL_COPY_NEAREST;
   7.330 +        status = -1;
   7.331 +        break;
   7.332 +    default:
   7.333 +        SDL_Unsupported();
   7.334 +        status = -1;
   7.335 +        break;
   7.336 +    }
   7.337 +
   7.338 +    if (surface->map->info.flags != flags) {
   7.339 +        SDL_InvalidateMap(surface->map);
   7.340 +    }
   7.341 +    return status;
   7.342 +}
   7.343 +
   7.344 +int SDL_GetSurfaceScaleMode(SDL_Surface *surface, int *scaleMode)
   7.345 +{
   7.346 +    if (!surface) {
   7.347 +        return -1;
   7.348 +    }
   7.349 +
   7.350 +    if (!scaleMode) {
   7.351 +        return 0;
   7.352 +    }
   7.353 +
   7.354 +    switch(surface->map->info.flags & (SDL_COPY_LINEAR)) {
   7.355 +    case SDL_COPY_LINEAR:
   7.356 +        *scaleMode = SDL_TEXTURESCALEMODE_FAST:
   7.357 +        break;
   7.358 +    default:
   7.359 +        *scaleMode = SDL_TEXTURESCALEMODE_NONE:
   7.360 +        break;
   7.361 +    }
   7.362 +    return 0;
   7.363 +}
   7.364 +
   7.365  SDL_bool
   7.366  SDL_SetClipRect(SDL_Surface * surface, const SDL_Rect * rect)
   7.367  {
   7.368 @@ -557,9 +655,7 @@
   7.369                     SDL_PixelFormat * format, Uint32 flags)
   7.370  {
   7.371      SDL_Surface *convert;
   7.372 -    Uint32 colorkey = 0;
   7.373 -    Uint8 alpha = 0;
   7.374 -    Uint32 surface_flags;
   7.375 +    Uint32 copy_flags;
   7.376      SDL_Rect bounds;
   7.377  
   7.378      /* Check for empty destination palette! (results in empty image) */
   7.379 @@ -578,8 +674,7 @@
   7.380      }
   7.381  
   7.382      /* Create a new surface with the desired format */
   7.383 -    convert = SDL_CreateRGBSurface(flags,
   7.384 -                                   surface->w, surface->h,
   7.385 +    convert = SDL_CreateRGBSurface(0, surface->w, surface->h,
   7.386                                     format->BitsPerPixel, format->Rmask,
   7.387                                     format->Gmask, format->Bmask,
   7.388                                     format->Amask);
   7.389 @@ -595,26 +690,9 @@
   7.390          convert->format->palette->ncolors = format->palette->ncolors;
   7.391      }
   7.392  
   7.393 -    /* Save the original surface color key and alpha */
   7.394 -    surface_flags = surface->flags;
   7.395 -    if ((surface_flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) {
   7.396 -        /* Convert colourkeyed surfaces to RGBA if requested */
   7.397 -        if ((flags & SDL_SRCCOLORKEY) != SDL_SRCCOLORKEY && format->Amask) {
   7.398 -            surface_flags &= ~SDL_SRCCOLORKEY;
   7.399 -        } else {
   7.400 -            colorkey = surface->map->ckey;
   7.401 -            SDL_SetColorKey(surface, 0, 0);
   7.402 -        }
   7.403 -    }
   7.404 -    if ((surface_flags & SDL_SRCALPHA) == SDL_SRCALPHA) {
   7.405 -        /* Copy over the alpha channel to RGBA if requested */
   7.406 -        if (format->Amask) {
   7.407 -            surface->flags &= ~SDL_SRCALPHA;
   7.408 -        } else {
   7.409 -            alpha = (Uint8) (surface->map->cmod >> 24);
   7.410 -            SDL_SetAlpha(surface, 0, 0);
   7.411 -        }
   7.412 -    }
   7.413 +    /* Save the original copy flags */
   7.414 +    copy_flags = surface->map->info.flags;
   7.415 +    surface->map->info.flags = 0;
   7.416  
   7.417      /* Copy over the image data */
   7.418      bounds.x = 0;
   7.419 @@ -624,30 +702,25 @@
   7.420      SDL_LowerBlit(surface, &bounds, convert, &bounds);
   7.421  
   7.422      /* Clean up the original surface, and update converted surface */
   7.423 -    if (convert != NULL) {
   7.424 -        SDL_SetClipRect(convert, &surface->clip_rect);
   7.425 -    }
   7.426 -    if ((surface_flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) {
   7.427 -        Uint32 cflags = surface_flags & (SDL_SRCCOLORKEY | SDL_RLEACCELOK);
   7.428 -        if (convert != NULL) {
   7.429 -            Uint8 keyR, keyG, keyB;
   7.430 +    SDL_SetClipRect(convert, &surface->clip_rect);
   7.431 +    if (copy_flags & SDL_COPY_COLORKEY) {
   7.432 +        Uint8 keyR, keyG, keyB, keyA;
   7.433  
   7.434 -            SDL_GetRGB(colorkey, surface->format, &keyR, &keyG, &keyB);
   7.435 -            SDL_SetColorKey(convert, cflags | (flags & SDL_RLEACCELOK),
   7.436 -                            SDL_MapRGB(convert->format, keyR, keyG, keyB));
   7.437 -        }
   7.438 -        SDL_SetColorKey(surface, cflags, colorkey);
   7.439 +        SDL_GetRGBA(colorkey, surface->format, &keyR, &keyG, &keyB, &keyA);
   7.440 +        SDL_SetColorKey(convert, 1,
   7.441 +                        SDL_MapRGBA(convert->format, keyR, keyG, keyB, keyA));
   7.442      }
   7.443 -    if ((surface_flags & SDL_SRCALPHA) == SDL_SRCALPHA) {
   7.444 -        Uint32 aflags = surface_flags & (SDL_SRCALPHA | SDL_RLEACCELOK);
   7.445 -        if (convert != NULL) {
   7.446 -            SDL_SetAlpha(convert, aflags | (flags & SDL_RLEACCELOK), alpha);
   7.447 -        }
   7.448 -        if (format->Amask) {
   7.449 -            surface->flags |= SDL_SRCALPHA;
   7.450 -        } else {
   7.451 -            SDL_SetAlpha(surface, aflags, alpha);
   7.452 -        }
   7.453 +    convert->map->info.r = surface->map->info.r;
   7.454 +    convert->map->info.g = surface->map->info.g;
   7.455 +    convert->map->info.b = surface->map->info.b;
   7.456 +    convert->map->info.a = surface->map->info.a;
   7.457 +    convert->map->info.flags = copy_flags;
   7.458 +    surface->map->info.flags = copy_flags;
   7.459 +
   7.460 +    /* Enable alpha blending by default if the new surface has an
   7.461 +     * alpha channel or alpha modulation */
   7.462 +    if (format->Amask || (copy_flags & SDL_COPY_MODULATE_ALPHA)) {
   7.463 +        SDL_SetSurfaceBlendMode(convert, SDL_TEXTUREBLENDMODE_BLEND);
   7.464      }
   7.465  
   7.466      /* We're ready to go! */
     8.1 --- a/src/video/SDL_video.c	Fri Aug 17 06:58:20 2007 +0000
     8.2 +++ b/src/video/SDL_video.c	Sat Aug 18 01:44:21 2007 +0000
     8.3 @@ -1535,8 +1535,7 @@
     8.4  SDL_CreateTextureFromSurface(Uint32 format, SDL_Surface * surface)
     8.5  {
     8.6      SDL_TextureID textureID;
     8.7 -    Uint32 surface_flags = surface->flags;
     8.8 -    SDL_PixelFormat *fmt = surface->format;
     8.9 +    SDL_PixelFormat *fmt;
    8.10      int bpp;
    8.11      Uint32 Rmask, Gmask, Bmask, Amask;
    8.12  
    8.13 @@ -1544,6 +1543,7 @@
    8.14          SDL_SetError("SDL_CreateTextureFromSurface() passed NULL surface");
    8.15          return 0;
    8.16      }
    8.17 +    fmt = surface->format;
    8.18  
    8.19      if (format) {
    8.20          if (!SDL_PixelFormatEnumToMasks
    8.21 @@ -1552,7 +1552,7 @@
    8.22              return 0;
    8.23          }
    8.24      } else {
    8.25 -        if (fmt->Amask || !(surface_flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA))) {
    8.26 +        if (surface->format->Amask || !(flags & (SDL_COPY_COLORKEY|SDL_COPY_MASK|SDL_COPY_BLEND))) {
    8.27              bpp = fmt->BitsPerPixel;
    8.28              Rmask = fmt->Rmask;
    8.29              Gmask = fmt->Gmask;
    8.30 @@ -1595,92 +1595,38 @@
    8.31                                surface->pitch);
    8.32          }
    8.33      } else {
    8.34 -        Uint32 cmod;
    8.35 -        SDL_Rect bounds;
    8.36 -        SDL_Surface dst;
    8.37 +        SDL_PixelFormat *dst_fmt;
    8.38 +        SDL_Surface *dst = NULL;
    8.39  
    8.40          /* Set up a destination surface for the texture update */
    8.41 -        SDL_zero(dst);
    8.42 -        dst.format = SDL_AllocFormat(bpp, Rmask, Gmask, Bmask, Amask);
    8.43 -        if (!dst.format) {
    8.44 -            SDL_DestroyTexture(textureID);
    8.45 -            return 0;
    8.46 -        }
    8.47 -        dst.w = surface->w;
    8.48 -        dst.h = surface->h;
    8.49 -        dst.pitch = SDL_CalculatePitch(&dst);
    8.50 -        dst.pixels = SDL_malloc(dst.h * dst.pitch);
    8.51 -        if (!dst.pixels) {
    8.52 -            SDL_DestroyTexture(textureID);
    8.53 -            SDL_FreeFormat(dst.format);
    8.54 -            SDL_OutOfMemory();
    8.55 -            return 0;
    8.56 -        }
    8.57 -
    8.58 -        /* Copy the palette if any */
    8.59 -        if (SDL_ISPIXELFORMAT_INDEXED(format)) {
    8.60 -            if (fmt->palette) {
    8.61 -                SDL_SetTexturePalette(textureID, fmt->palette->colors, 0,
    8.62 -                                      fmt->palette->ncolors);
    8.63 -                SDL_SetSurfacePalette(&dst, fmt->palette);
    8.64 -            } else {
    8.65 -                dst.format->palette =
    8.66 -                    SDL_AllocPalette((1 << SDL_BITSPERPIXEL(format)));
    8.67 -                if (!dst.format->palette) {
    8.68 -                    SDL_DestroyTexture(textureID);
    8.69 -                    SDL_FreeFormat(dst.format);
    8.70 -                    return 0;
    8.71 +        dst_fmt = SDL_AllocFormat(bpp, Rmask, Gmask, Bmask, Amask);
    8.72 +        if (dst_fmt) {
    8.73 +            if (SDL_ISPIXELFORMAT_INDEXED(format)) {
    8.74 +                dst_fmt->palette = SDL_AllocPalette((1 << SDL_BITSPERPIXEL(format)));
    8.75 +                if (dst_fmt->palette) {
    8.76 +                    if (fmt->palette) {
    8.77 +fixme
    8.78 +                    } else {
    8.79 +                        SDL_DitherColors(dst_fmt->palette->colors, SDL_BITSPERPIXEL(format));
    8.80 +                    }
    8.81                  }
    8.82 -                SDL_DitherColors(dst.format->palette->colors,
    8.83 -                                 SDL_BITSPERPIXEL(format));
    8.84 +                if (fmt->palette) {
    8.85 +                    dst_fmt->palette = fmt->palette;
    8.86 +                } else {
    8.87 +                }
    8.88              }
    8.89 -        }
    8.90  
    8.91 -        /* Make the texture transparent if the surface has colorkey */
    8.92 -        if (surface_flags & SDL_SRCCOLORKEY) {
    8.93 -            int row;
    8.94 -            int length = dst.w * dst.format->BytesPerPixel;
    8.95 -            Uint8 *p = (Uint8 *) dst.pixels;
    8.96 -            for (row = 0; row < dst.h; ++row) {
    8.97 -                SDL_memset(p, 0, length);
    8.98 -                p += dst.pitch;
    8.99 +            cvt = SDL_ConvertSurface(surface, fmt, 0);
   8.100 +            if (cvt) {
   8.101 +                SDL_UpdateTexture(textureID, NULL, cvt->pixels, cvt->pitch);
   8.102 +                SDL_FreeSurface(cvt);
   8.103              }
   8.104 -        }
   8.105 -
   8.106 -        /* Copy over the alpha channel */
   8.107 -        cmod = surface->map->cmod;
   8.108 -        if (surface_flags & SDL_SRCALPHA) {
   8.109 -            if (fmt->Amask) {
   8.110 -                surface->flags &= ~SDL_SRCALPHA;
   8.111 -            } else {
   8.112 -                /* FIXME: Need to make sure the texture has an alpha channel
   8.113 -                 *        and copy 'alpha' into the texture alpha channel.
   8.114 -                 */
   8.115 -                SDL_SetAlpha(surface, 0, 0);
   8.116 -            }
   8.117 +            SDL_FreeFormat(fmt);
   8.118          }
   8.119 -
   8.120 -        /* Copy over the image data */
   8.121 -        bounds.x = 0;
   8.122 -        bounds.y = 0;
   8.123 -        bounds.w = surface->w;
   8.124 -        bounds.h = surface->h;
   8.125 -        SDL_LowerBlit(surface, &bounds, &dst, &bounds);
   8.126 +    }
   8.127  
   8.128 -        /* Clean up the original surface */
   8.129 -        if ((surface_flags & SDL_SRCALPHA) == SDL_SRCALPHA) {
   8.130 -            Uint32 aflags = surface_flags & (SDL_SRCALPHA | SDL_RLEACCELOK);
   8.131 -            if (fmt->Amask) {
   8.132 -                surface->flags |= SDL_SRCALPHA;
   8.133 -            } else {
   8.134 -                SDL_SetAlpha(surface, aflags, (cmod >> 24));
   8.135 -            }
   8.136 -        }
   8.137 -
   8.138 -        /* Update the texture */
   8.139 -        SDL_UpdateTexture(textureID, NULL, dst.pixels, dst.pitch);
   8.140 -        SDL_free(dst.pixels);
   8.141 -        SDL_FreeFormat(dst.format);
   8.142 +    if (SDL_ISPIXELFORMAT_INDEXED(format) && fmt->palette) {
   8.143 +        SDL_SetTexturePalette(textureID, fmt->palette->colors, 0, fmt->palette->ncolors);
   8.144      }
   8.145  
   8.146      return textureID;