src/video/SDL_surface.c
changeset 2267 c785543d1843
parent 2266 e61ad15a205f
child 2328 91e601d9df8b
     1.1 --- a/src/video/SDL_surface.c	Sat Aug 18 01:44:21 2007 +0000
     1.2 +++ b/src/video/SDL_surface.c	Sat Aug 18 05:39:09 2007 +0000
     1.3 @@ -53,9 +53,6 @@
     1.4          SDL_FreeSurface(surface);
     1.5          return NULL;
     1.6      }
     1.7 -    if (Amask) {
     1.8 -        surface->flags |= SDL_SRCALPHA;
     1.9 -    }
    1.10      surface->w = width;
    1.11      surface->h = height;
    1.12      surface->pitch = SDL_CalculatePitch(surface);
    1.13 @@ -138,6 +135,11 @@
    1.14      }
    1.15      SDL_FormatChanged(surface);
    1.16  
    1.17 +    /* By default surface with an alpha mask are set up for blending */
    1.18 +    if (Amask) {
    1.19 +        SDL_SetSurfaceBlendMode(surface, SDL_TEXTUREBLENDMODE_BLEND);
    1.20 +    }
    1.21 +
    1.22      /* The surface is ready to go */
    1.23      surface->refcount = 1;
    1.24  #ifdef CHECK_LEAKS
    1.25 @@ -212,26 +214,29 @@
    1.26      return 0;
    1.27  }
    1.28  
    1.29 -int SDL_SetSurfaceRLE(SDL_Surface *surface, int flag)
    1.30 +int
    1.31 +SDL_SetSurfaceRLE(SDL_Surface * surface, int flag)
    1.32  {
    1.33 -    Uint32 flags;
    1.34 +    int flags;
    1.35  
    1.36      if (!surface) {
    1.37          return -1;
    1.38      }
    1.39  
    1.40 +    flags = surface->map->info.flags;
    1.41      if (flag) {
    1.42 -        surface->flags |= SDL_RLEACCELOK;
    1.43 +        surface->map->info.flags |= SDL_COPY_RLE_DESIRED;
    1.44      } else {
    1.45 -        surface->flags &= ~SDL_RLEACCELOK;
    1.46 +        surface->map->info.flags &= ~SDL_COPY_RLE_DESIRED;
    1.47      }
    1.48 -    if (surface->flags != flags) {
    1.49 +    if (surface->map->info.flags != flags) {
    1.50          SDL_InvalidateMap(surface->map);
    1.51      }
    1.52      return 0;
    1.53  }
    1.54  
    1.55 -int SDL_SetColorKey(SDL_Surface *surface, Uint32 flag, Uint32 key)
    1.56 +int
    1.57 +SDL_SetColorKey(SDL_Surface * surface, Uint32 flag, Uint32 key)
    1.58  {
    1.59      int flags;
    1.60  
    1.61 @@ -253,10 +258,19 @@
    1.62      if (surface->map->info.flags != flags) {
    1.63          SDL_InvalidateMap(surface->map);
    1.64      }
    1.65 +
    1.66 +    /* Compatibility mode */
    1.67 +    if (surface->map->info.flags & SDL_COPY_COLORKEY) {
    1.68 +        surface->flags |= SDL_SRCCOLORKEY;
    1.69 +    } else {
    1.70 +        surface->flags &= ~SDL_SRCCOLORKEY;
    1.71 +    }
    1.72 +
    1.73      return 0;
    1.74  }
    1.75  
    1.76 -int SDL_SetSurfaceColorMod(SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b)
    1.77 +int
    1.78 +SDL_SetSurfaceColorMod(SDL_Surface * surface, Uint8 r, Uint8 g, Uint8 b)
    1.79  {
    1.80      int flags;
    1.81  
    1.82 @@ -281,7 +295,8 @@
    1.83  }
    1.84  
    1.85  
    1.86 -int SDL_GetSurfaceColorMod(SDL_Surface *surface, Uint8 * r, Uint8 * g, Uint8 * b)
    1.87 +int
    1.88 +SDL_GetSurfaceColorMod(SDL_Surface * surface, Uint8 * r, Uint8 * g, Uint8 * b)
    1.89  {
    1.90      if (!surface) {
    1.91          return -1;
    1.92 @@ -299,7 +314,8 @@
    1.93      return 0;
    1.94  }
    1.95  
    1.96 -int SDL_SetSurfaceAlphaMod(SDL_Surface *surface, Uint8 alpha)
    1.97 +int
    1.98 +SDL_SetSurfaceAlphaMod(SDL_Surface * surface, Uint8 alpha)
    1.99  {
   1.100      int flags;
   1.101  
   1.102 @@ -321,7 +337,8 @@
   1.103      return 0;
   1.104  }
   1.105  
   1.106 -int SDL_GetSurfaceAlphaMod(SDL_Surface *surface, Uint8 * alpha)
   1.107 +int
   1.108 +SDL_GetSurfaceAlphaMod(SDL_Surface * surface, Uint8 * alpha)
   1.109  {
   1.110      if (!surface) {
   1.111          return -1;
   1.112 @@ -333,7 +350,8 @@
   1.113      return 0;
   1.114  }
   1.115  
   1.116 -int SDL_SetSurfaceBlendMode(SDL_Surface *surface, int blendMode)
   1.117 +int
   1.118 +SDL_SetSurfaceBlendMode(SDL_Surface * surface, int blendMode)
   1.119  {
   1.120      int flags, status;
   1.121  
   1.122 @@ -343,7 +361,8 @@
   1.123  
   1.124      status = 0;
   1.125      flags = surface->map->info.flags;
   1.126 -    surface->map->info.flags &= ~(SDL_COPY_MASK|SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD);
   1.127 +    surface->map->info.flags &=
   1.128 +        ~(SDL_COPY_MASK | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD);
   1.129      switch (blendMode) {
   1.130      case SDL_TEXTUREBLENDMODE_NONE:
   1.131          break;
   1.132 @@ -368,10 +387,19 @@
   1.133      if (surface->map->info.flags != flags) {
   1.134          SDL_InvalidateMap(surface->map);
   1.135      }
   1.136 +
   1.137 +    /* Compatibility mode */
   1.138 +    if (surface->map->info.flags & SDL_COPY_BLEND) {
   1.139 +        surface->flags |= SDL_SRCALPHA;
   1.140 +    } else {
   1.141 +        surface->flags &= ~SDL_SRCALPHA;
   1.142 +    }
   1.143 +
   1.144      return status;
   1.145  }
   1.146  
   1.147 -int SDL_GetSurfaceBlendMode(SDL_Surface *surface, int *blendMode)
   1.148 +int
   1.149 +SDL_GetSurfaceBlendMode(SDL_Surface * surface, int *blendMode)
   1.150  {
   1.151      if (!surface) {
   1.152          return -1;
   1.153 @@ -381,27 +409,30 @@
   1.154          return 0;
   1.155      }
   1.156  
   1.157 -    switch(surface->map->info.flags & (SDL_COPY_MASK|SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
   1.158 +    switch (surface->map->info.
   1.159 +            flags & (SDL_COPY_MASK | SDL_COPY_BLEND | SDL_COPY_ADD |
   1.160 +                     SDL_COPY_MOD)) {
   1.161      case SDL_COPY_MASK:
   1.162 -        *blendMode = SDL_TEXTUREBLENDMODE_MASK:
   1.163 +        *blendMode = SDL_TEXTUREBLENDMODE_MASK;
   1.164          break;
   1.165      case SDL_COPY_BLEND:
   1.166 -        *blendMode = SDL_TEXTUREBLENDMODE_BLEND:
   1.167 +        *blendMode = SDL_TEXTUREBLENDMODE_BLEND;
   1.168          break;
   1.169      case SDL_COPY_ADD:
   1.170 -        *blendMode = SDL_TEXTUREBLENDMODE_ADD:
   1.171 +        *blendMode = SDL_TEXTUREBLENDMODE_ADD;
   1.172          break;
   1.173      case SDL_COPY_MOD:
   1.174 -        *blendMode = SDL_TEXTUREBLENDMODE_MOD:
   1.175 +        *blendMode = SDL_TEXTUREBLENDMODE_MOD;
   1.176          break;
   1.177      default:
   1.178 -        *blendMode = SDL_TEXTUREBLENDMODE_NONE:
   1.179 +        *blendMode = SDL_TEXTUREBLENDMODE_NONE;
   1.180          break;
   1.181      }
   1.182      return 0;
   1.183  }
   1.184  
   1.185 -int SDL_SetSurfaceScaleMode(SDL_Surface *surface, int scaleMode)
   1.186 +int
   1.187 +SDL_SetSurfaceScaleMode(SDL_Surface * surface, int scaleMode)
   1.188  {
   1.189      int flags, status;
   1.190  
   1.191 @@ -436,7 +467,8 @@
   1.192      return status;
   1.193  }
   1.194  
   1.195 -int SDL_GetSurfaceScaleMode(SDL_Surface *surface, int *scaleMode)
   1.196 +int
   1.197 +SDL_GetSurfaceScaleMode(SDL_Surface * surface, int *scaleMode)
   1.198  {
   1.199      if (!surface) {
   1.200          return -1;
   1.201 @@ -446,12 +478,12 @@
   1.202          return 0;
   1.203      }
   1.204  
   1.205 -    switch(surface->map->info.flags & (SDL_COPY_LINEAR)) {
   1.206 -    case SDL_COPY_LINEAR:
   1.207 -        *scaleMode = SDL_TEXTURESCALEMODE_FAST:
   1.208 +    switch (surface->map->info.flags & (SDL_COPY_NEAREST)) {
   1.209 +    case SDL_COPY_NEAREST:
   1.210 +        *scaleMode = SDL_TEXTURESCALEMODE_FAST;
   1.211          break;
   1.212      default:
   1.213 -        *scaleMode = SDL_TEXTURESCALEMODE_NONE:
   1.214 +        *scaleMode = SDL_TEXTURESCALEMODE_NONE;
   1.215          break;
   1.216      }
   1.217      return 0;
   1.218 @@ -706,7 +738,8 @@
   1.219      if (copy_flags & SDL_COPY_COLORKEY) {
   1.220          Uint8 keyR, keyG, keyB, keyA;
   1.221  
   1.222 -        SDL_GetRGBA(colorkey, surface->format, &keyR, &keyG, &keyB, &keyA);
   1.223 +        SDL_GetRGBA(surface->map->info.colorkey, surface->format, &keyR,
   1.224 +                    &keyG, &keyB, &keyA);
   1.225          SDL_SetColorKey(convert, 1,
   1.226                          SDL_MapRGBA(convert->format, keyR, keyG, keyB, keyA));
   1.227      }