src/video/SDL_RLEaccel.c
changeset 2266 e61ad15a205f
parent 2262 bee005ace1bf
child 2267 c785543d1843
     1.1 --- a/src/video/SDL_RLEaccel.c	Fri Aug 17 06:58:20 2007 +0000
     1.2 +++ b/src/video/SDL_RLEaccel.c	Sat Aug 18 01:44:21 2007 +0000
     1.3 @@ -905,8 +905,7 @@
     1.4          }
     1.5      }
     1.6  
     1.7 -    alpha = (src->flags & SDL_SRCALPHA) == SDL_SRCALPHA
     1.8 -        ? src->map->info.a : 255;
     1.9 +    alpha = src->map->info.a;
    1.10      /* if left or right edge clipping needed, call clip blit */
    1.11      if (srcrect->x || srcrect->w != src->w) {
    1.12          RLEClipBlit(w, srcbuf, dst, dstbuf, srcrect, alpha);
    1.13 @@ -1803,7 +1802,7 @@
    1.14  int
    1.15  SDL_RLESurface(SDL_Surface * surface)
    1.16  {
    1.17 -    int retcode;
    1.18 +    int flags;
    1.19  
    1.20      /* Clear any previous RLE conversion */
    1.21      if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) {
    1.22 @@ -1812,35 +1811,45 @@
    1.23  
    1.24      /* We don't support RLE encoding of bitmaps */
    1.25      if (surface->format->BitsPerPixel < 8) {
    1.26 -        return (-1);
    1.27 +        return -1;
    1.28      }
    1.29  
    1.30 -    /* Lock the surface if it's in hardware */
    1.31 -    if (SDL_MUSTLOCK(surface)) {
    1.32 -        if (SDL_LockSurface(surface) < 0) {
    1.33 -            return (-1);
    1.34 -        }
    1.35 +    /* Make sure the pixels are available */
    1.36 +    if (!surface->pixels) {
    1.37 +        return -1;
    1.38 +    }
    1.39 +
    1.40 +    /* If we don't have colorkey or blending, nothing to do... */
    1.41 +    flags = surface->map->info.flags;
    1.42 +    if(!(flags & (SDL_COPY_COLORKEY|SDL_COPY_BLEND))) {
    1.43 +        return -1;
    1.44      }
    1.45  
    1.46 -    /* Encode */
    1.47 -    if ((surface->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) {
    1.48 -        retcode = RLEColorkeySurface(surface);
    1.49 -    } else {
    1.50 -        if ((surface->flags & SDL_SRCALPHA) == SDL_SRCALPHA
    1.51 -            && surface->format->Amask != 0)
    1.52 -            retcode = RLEAlphaSurface(surface);
    1.53 -        else
    1.54 -            retcode = -1;       /* no RLE for per-surface alpha sans ckey */
    1.55 +    /* Pass on combinations not supported */
    1.56 +    if ((flags & SDL_COPY_MODULATE_COLOR) ||
    1.57 +        (flags & (SDL_COPY_ADD|SDL_COPY_MOD)) ||
    1.58 +        (flags & SDL_COPY_NEAREST)) {
    1.59 +        return -1;
    1.60      }
    1.61  
    1.62 -    /* Unlock the surface if it's in hardware */
    1.63 -    if (SDL_MUSTLOCK(surface)) {
    1.64 -        SDL_UnlockSurface(surface);
    1.65 +    /* Encode and set up the blit */
    1.66 +    if (!surface->format->Amask || !(flags & SDL_COPY_BLEND)) {
    1.67 +        if (!surface->map->identity) {
    1.68 +            return -1;
    1.69 +        }
    1.70 +        if (RLEColorkeySurface(surface) < 0) {
    1.71 +            return -1;
    1.72 +        }
    1.73 +        surface->map->blit = SDL_RLEBlit;
    1.74 +        surface->map->info.flags |= SDL_COPY_RLE_COLORKEY;
    1.75 +    } else {
    1.76 +        if (RLEAlphaSurface(surface) < 0) {
    1.77 +            return -1;
    1.78 +        }
    1.79 +        surface->map->blit = SDL_RLEAlphaBlit;
    1.80 +        surface->map->info.flags |= SDL_COPY_RLE_ALPHAKEY;
    1.81      }
    1.82  
    1.83 -    if (retcode < 0)
    1.84 -        return -1;
    1.85 -
    1.86      /* The surface is now accelerated */
    1.87      surface->flags |= SDL_RLEACCEL;
    1.88  
    1.89 @@ -1931,13 +1940,12 @@
    1.90  void
    1.91  SDL_UnRLESurface(SDL_Surface * surface, int recode)
    1.92  {
    1.93 -    if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) {
    1.94 +    if (surface->flags & SDL_RLEACCEL) {
    1.95          surface->flags &= ~SDL_RLEACCEL;
    1.96  
    1.97          if (recode && !(surface->flags & SDL_PREALLOC)) {
    1.98 -            if ((surface->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) {
    1.99 +            if (surface->map->info.flags & SDL_COPY_RLE_COLORKEY) {
   1.100                  SDL_Rect full;
   1.101 -                unsigned alpha_flag;
   1.102  
   1.103                  /* re-create the original surface */
   1.104                  surface->pixels = SDL_malloc(surface->h * surface->pitch);
   1.105 @@ -1954,10 +1962,7 @@
   1.106                  full.x = full.y = 0;
   1.107                  full.w = surface->w;
   1.108                  full.h = surface->h;
   1.109 -                alpha_flag = surface->flags & SDL_SRCALPHA;
   1.110 -                surface->flags &= ~SDL_SRCALPHA;        /* opaque blit */
   1.111                  SDL_RLEBlit(surface, &full, surface, &full);
   1.112 -                surface->flags |= alpha_flag;
   1.113              } else {
   1.114                  if (!UnRLEAlpha(surface)) {
   1.115                      /* Oh crap... */
   1.116 @@ -1966,8 +1971,9 @@
   1.117                  }
   1.118              }
   1.119          }
   1.120 +        surface->map->info.flags &= (SDL_COPY_RLE_COLORKEY|SDL_COPY_RLE_ALPHAKEY);
   1.121  
   1.122 -        if (surface->map && surface->map->data) {
   1.123 +        if (surface->map->data) {
   1.124              SDL_free(surface->map->data);
   1.125              surface->map->data = NULL;
   1.126          }