src/video/SDL_RLEaccel.c
changeset 1895 c121d94672cb
parent 1456 84de7511f79f
child 2222 926294b2bb4e
     1.1 --- a/src/video/SDL_RLEaccel.c	Thu Jul 06 18:01:37 2006 +0000
     1.2 +++ b/src/video/SDL_RLEaccel.c	Mon Jul 10 21:04:37 2006 +0000
     1.3 @@ -545,7 +545,7 @@
     1.4      } while(0)
     1.5  
     1.6  #endif
     1.7 -    
     1.8 +
     1.9  /*
    1.10   * Special case: 50% alpha (alpha=128)
    1.11   * This is treated specially because it can be optimized very well, and
    1.12 @@ -704,7 +704,7 @@
    1.13      } while(0)
    1.14  
    1.15  #else
    1.16 -	
    1.17 +
    1.18  #define CHOOSE_BLIT(blitter, alpha, fmt)				\
    1.19      do {								\
    1.20          if(alpha == 255) {						\
    1.21 @@ -779,8 +779,9 @@
    1.22   * This takes care of the case when the surface is clipped on the left and/or
    1.23   * right. Top clipping has already been taken care of.
    1.24   */
    1.25 -static void RLEClipBlit(int w, Uint8 *srcbuf, SDL_Surface *dst,
    1.26 -			Uint8 *dstbuf, SDL_Rect *srcrect, unsigned alpha)
    1.27 +static void
    1.28 +RLEClipBlit(int w, Uint8 * srcbuf, SDL_Surface * dst,
    1.29 +            Uint8 * dstbuf, SDL_Rect * srcrect, unsigned alpha)
    1.30  {
    1.31      SDL_PixelFormat *fmt = dst->format;
    1.32  
    1.33 @@ -836,34 +837,35 @@
    1.34  
    1.35  
    1.36  /* blit a colorkeyed RLE surface */
    1.37 -int SDL_RLEBlit(SDL_Surface *src, SDL_Rect *srcrect,
    1.38 -		SDL_Surface *dst, SDL_Rect *dstrect)
    1.39 +int
    1.40 +SDL_RLEBlit(SDL_Surface * src, SDL_Rect * srcrect,
    1.41 +            SDL_Surface * dst, SDL_Rect * dstrect)
    1.42  {
    1.43 -	Uint8 *dstbuf;
    1.44 -	Uint8 *srcbuf;
    1.45 -	int x, y;
    1.46 -	int w = src->w;
    1.47 -	unsigned alpha;
    1.48 +    Uint8 *dstbuf;
    1.49 +    Uint8 *srcbuf;
    1.50 +    int x, y;
    1.51 +    int w = src->w;
    1.52 +    unsigned alpha;
    1.53  
    1.54 -	/* Lock the destination if necessary */
    1.55 -	if ( SDL_MUSTLOCK(dst) ) {
    1.56 -		if ( SDL_LockSurface(dst) < 0 ) {
    1.57 -			return(-1);
    1.58 -		}
    1.59 -	}
    1.60 +    /* Lock the destination if necessary */
    1.61 +    if (SDL_MUSTLOCK(dst)) {
    1.62 +        if (SDL_LockSurface(dst) < 0) {
    1.63 +            return (-1);
    1.64 +        }
    1.65 +    }
    1.66  
    1.67 -	/* Set up the source and destination pointers */
    1.68 -	x = dstrect->x;
    1.69 -	y = dstrect->y;
    1.70 -	dstbuf = (Uint8 *)dst->pixels
    1.71 -	         + y * dst->pitch + x * src->format->BytesPerPixel;
    1.72 -	srcbuf = (Uint8 *)src->map->sw_data->aux_data;
    1.73 +    /* Set up the source and destination pointers */
    1.74 +    x = dstrect->x;
    1.75 +    y = dstrect->y;
    1.76 +    dstbuf = (Uint8 *) dst->pixels
    1.77 +        + y * dst->pitch + x * src->format->BytesPerPixel;
    1.78 +    srcbuf = (Uint8 *) src->map->sw_data->aux_data;
    1.79  
    1.80 -	{
    1.81 -	    /* skip lines at the top if neccessary */
    1.82 -	    int vskip = srcrect->y;
    1.83 -	    int ofs = 0;
    1.84 -	    if(vskip) {
    1.85 +    {
    1.86 +        /* skip lines at the top if neccessary */
    1.87 +        int vskip = srcrect->y;
    1.88 +        int ofs = 0;
    1.89 +        if (vskip) {
    1.90  
    1.91  #define RLESKIP(bpp, Type)			\
    1.92  		for(;;) {			\
    1.93 @@ -883,25 +885,33 @@
    1.94  		    }				\
    1.95  		}
    1.96  
    1.97 -		switch(src->format->BytesPerPixel) {
    1.98 -		case 1: RLESKIP(1, Uint8); break;
    1.99 -		case 2: RLESKIP(2, Uint8); break;
   1.100 -		case 3: RLESKIP(3, Uint8); break;
   1.101 -		case 4: RLESKIP(4, Uint16); break;
   1.102 -		}
   1.103 +            switch (src->format->BytesPerPixel) {
   1.104 +            case 1:
   1.105 +                RLESKIP(1, Uint8);
   1.106 +                break;
   1.107 +            case 2:
   1.108 +                RLESKIP(2, Uint8);
   1.109 +                break;
   1.110 +            case 3:
   1.111 +                RLESKIP(3, Uint8);
   1.112 +                break;
   1.113 +            case 4:
   1.114 +                RLESKIP(4, Uint16);
   1.115 +                break;
   1.116 +            }
   1.117  
   1.118  #undef RLESKIP
   1.119  
   1.120 -	    }
   1.121 -	}
   1.122 +        }
   1.123 +    }
   1.124  
   1.125 -	alpha = (src->flags & SDL_SRCALPHA) == SDL_SRCALPHA
   1.126 -	        ? src->format->alpha : 255;
   1.127 -	/* if left or right edge clipping needed, call clip blit */
   1.128 -	if ( srcrect->x || srcrect->w != src->w ) {
   1.129 -	    RLEClipBlit(w, srcbuf, dst, dstbuf, srcrect, alpha);
   1.130 -	} else {
   1.131 -	    SDL_PixelFormat *fmt = src->format;
   1.132 +    alpha = (src->flags & SDL_SRCALPHA) == SDL_SRCALPHA
   1.133 +        ? src->format->alpha : 255;
   1.134 +    /* if left or right edge clipping needed, call clip blit */
   1.135 +    if (srcrect->x || srcrect->w != src->w) {
   1.136 +        RLEClipBlit(w, srcbuf, dst, dstbuf, srcrect, alpha);
   1.137 +    } else {
   1.138 +        SDL_PixelFormat *fmt = src->format;
   1.139  
   1.140  #define RLEBLIT(bpp, Type, do_blit)					      \
   1.141  	    do {							      \
   1.142 @@ -927,17 +937,17 @@
   1.143  		}							      \
   1.144  	    } while(0)
   1.145  
   1.146 -	    CHOOSE_BLIT(RLEBLIT, alpha, fmt);
   1.147 +        CHOOSE_BLIT(RLEBLIT, alpha, fmt);
   1.148  
   1.149  #undef RLEBLIT
   1.150 -	}
   1.151 +    }
   1.152  
   1.153 -done:
   1.154 -	/* Unlock the destination if necessary */
   1.155 -	if ( SDL_MUSTLOCK(dst) ) {
   1.156 -		SDL_UnlockSurface(dst);
   1.157 -	}
   1.158 -	return(0);
   1.159 +  done:
   1.160 +    /* Unlock the destination if necessary */
   1.161 +    if (SDL_MUSTLOCK(dst)) {
   1.162 +        SDL_UnlockSurface(dst);
   1.163 +    }
   1.164 +    return (0);
   1.165  }
   1.166  
   1.167  #undef OPAQUE_BLIT
   1.168 @@ -995,24 +1005,26 @@
   1.169  
   1.170  /* used to save the destination format in the encoding. Designed to be
   1.171     macro-compatible with SDL_PixelFormat but without the unneeded fields */
   1.172 -typedef struct {
   1.173 -	Uint8  BytesPerPixel;
   1.174 -	Uint8  Rloss;
   1.175 -	Uint8  Gloss;
   1.176 -	Uint8  Bloss;
   1.177 -	Uint8  Rshift;
   1.178 -	Uint8  Gshift;
   1.179 -	Uint8  Bshift;
   1.180 -	Uint8  Ashift;
   1.181 -	Uint32 Rmask;
   1.182 -	Uint32 Gmask;
   1.183 -	Uint32 Bmask;
   1.184 -	Uint32 Amask;
   1.185 +typedef struct
   1.186 +{
   1.187 +    Uint8 BytesPerPixel;
   1.188 +    Uint8 Rloss;
   1.189 +    Uint8 Gloss;
   1.190 +    Uint8 Bloss;
   1.191 +    Uint8 Rshift;
   1.192 +    Uint8 Gshift;
   1.193 +    Uint8 Bshift;
   1.194 +    Uint8 Ashift;
   1.195 +    Uint32 Rmask;
   1.196 +    Uint32 Gmask;
   1.197 +    Uint32 Bmask;
   1.198 +    Uint32 Amask;
   1.199  } RLEDestFormat;
   1.200  
   1.201  /* blit a pixel-alpha RLE surface clipped at the right and/or left edges */
   1.202 -static void RLEAlphaClipBlit(int w, Uint8 *srcbuf, SDL_Surface *dst,
   1.203 -			     Uint8 *dstbuf, SDL_Rect *srcrect)
   1.204 +static void
   1.205 +RLEAlphaClipBlit(int w, Uint8 * srcbuf, SDL_Surface * dst,
   1.206 +                 Uint8 * dstbuf, SDL_Rect * srcrect)
   1.207  {
   1.208      SDL_PixelFormat *df = dst->format;
   1.209      /*
   1.210 @@ -1088,23 +1100,23 @@
   1.211  	} while(--linecount);						  \
   1.212      } while(0)
   1.213  
   1.214 -    switch(df->BytesPerPixel) {
   1.215 +    switch (df->BytesPerPixel) {
   1.216      case 2:
   1.217 -	if(df->Gmask == 0x07e0 || df->Rmask == 0x07e0
   1.218 -	   || df->Bmask == 0x07e0)
   1.219 -	    RLEALPHACLIPBLIT(Uint16, Uint8, BLIT_TRANSL_565);
   1.220 -	else
   1.221 -	    RLEALPHACLIPBLIT(Uint16, Uint8, BLIT_TRANSL_555);
   1.222 -	break;
   1.223 +        if (df->Gmask == 0x07e0 || df->Rmask == 0x07e0 || df->Bmask == 0x07e0)
   1.224 +            RLEALPHACLIPBLIT(Uint16, Uint8, BLIT_TRANSL_565);
   1.225 +        else
   1.226 +            RLEALPHACLIPBLIT(Uint16, Uint8, BLIT_TRANSL_555);
   1.227 +        break;
   1.228      case 4:
   1.229 -	RLEALPHACLIPBLIT(Uint32, Uint16, BLIT_TRANSL_888);
   1.230 -	break;
   1.231 +        RLEALPHACLIPBLIT(Uint32, Uint16, BLIT_TRANSL_888);
   1.232 +        break;
   1.233      }
   1.234  }
   1.235  
   1.236  /* blit a pixel-alpha RLE surface */
   1.237 -int SDL_RLEAlphaBlit(SDL_Surface *src, SDL_Rect *srcrect,
   1.238 -		     SDL_Surface *dst, SDL_Rect *dstrect)
   1.239 +int
   1.240 +SDL_RLEAlphaBlit(SDL_Surface * src, SDL_Rect * srcrect,
   1.241 +                 SDL_Surface * dst, SDL_Rect * dstrect)
   1.242  {
   1.243      int x, y;
   1.244      int w = src->w;
   1.245 @@ -1112,84 +1124,88 @@
   1.246      SDL_PixelFormat *df = dst->format;
   1.247  
   1.248      /* Lock the destination if necessary */
   1.249 -    if ( SDL_MUSTLOCK(dst) ) {
   1.250 -	if ( SDL_LockSurface(dst) < 0 ) {
   1.251 -	    return -1;
   1.252 -	}
   1.253 +    if (SDL_MUSTLOCK(dst)) {
   1.254 +        if (SDL_LockSurface(dst) < 0) {
   1.255 +            return -1;
   1.256 +        }
   1.257      }
   1.258  
   1.259      x = dstrect->x;
   1.260      y = dstrect->y;
   1.261 -    dstbuf = (Uint8 *)dst->pixels
   1.262 -	     + y * dst->pitch + x * df->BytesPerPixel;
   1.263 -    srcbuf = (Uint8 *)src->map->sw_data->aux_data + sizeof(RLEDestFormat);
   1.264 +    dstbuf = (Uint8 *) dst->pixels + y * dst->pitch + x * df->BytesPerPixel;
   1.265 +    srcbuf = (Uint8 *) src->map->sw_data->aux_data + sizeof(RLEDestFormat);
   1.266  
   1.267      {
   1.268 -	/* skip lines at the top if necessary */
   1.269 -	int vskip = srcrect->y;
   1.270 -	if(vskip) {
   1.271 -	    int ofs;
   1.272 -	    if(df->BytesPerPixel == 2) {
   1.273 -		/* the 16/32 interleaved format */
   1.274 -		do {
   1.275 -		    /* skip opaque line */
   1.276 -		    ofs = 0;
   1.277 -		    do {
   1.278 -			int run;
   1.279 -			ofs += srcbuf[0];
   1.280 -			run = srcbuf[1];
   1.281 -			srcbuf += 2;
   1.282 -			if(run) {
   1.283 -			    srcbuf += 2 * run;
   1.284 -			    ofs += run;
   1.285 -			} else if(!ofs)
   1.286 -			    goto done;
   1.287 -		    } while(ofs < w);
   1.288 +        /* skip lines at the top if necessary */
   1.289 +        int vskip = srcrect->y;
   1.290 +        if (vskip) {
   1.291 +            int ofs;
   1.292 +            if (df->BytesPerPixel == 2) {
   1.293 +                /* the 16/32 interleaved format */
   1.294 +                do {
   1.295 +                    /* skip opaque line */
   1.296 +                    ofs = 0;
   1.297 +                    do {
   1.298 +                        int run;
   1.299 +                        ofs += srcbuf[0];
   1.300 +                        run = srcbuf[1];
   1.301 +                        srcbuf += 2;
   1.302 +                        if (run) {
   1.303 +                            srcbuf += 2 * run;
   1.304 +                            ofs += run;
   1.305 +                        } else if (!ofs)
   1.306 +                            goto done;
   1.307 +                    }
   1.308 +                    while (ofs < w);
   1.309  
   1.310 -		    /* skip padding */
   1.311 -		    srcbuf += (uintptr_t)srcbuf & 2;
   1.312 +                    /* skip padding */
   1.313 +                    srcbuf += (uintptr_t) srcbuf & 2;
   1.314  
   1.315 -		    /* skip translucent line */
   1.316 -		    ofs = 0;
   1.317 -		    do {
   1.318 -			int run;
   1.319 -			ofs += ((Uint16 *)srcbuf)[0];
   1.320 -			run = ((Uint16 *)srcbuf)[1];
   1.321 -			srcbuf += 4 * (run + 1);
   1.322 -			ofs += run;
   1.323 -		    } while(ofs < w);
   1.324 -		} while(--vskip);
   1.325 -	    } else {
   1.326 -		/* the 32/32 interleaved format */
   1.327 -		vskip <<= 1;	/* opaque and translucent have same format */
   1.328 -		do {
   1.329 -		    ofs = 0;
   1.330 -		    do {
   1.331 -			int run;
   1.332 -			ofs += ((Uint16 *)srcbuf)[0];
   1.333 -			run = ((Uint16 *)srcbuf)[1];
   1.334 -			srcbuf += 4;
   1.335 -			if(run) {
   1.336 -			    srcbuf += 4 * run;
   1.337 -			    ofs += run;
   1.338 -			} else if(!ofs)
   1.339 -			    goto done;
   1.340 -		    } while(ofs < w);
   1.341 -		} while(--vskip);
   1.342 -	    }
   1.343 -	}
   1.344 +                    /* skip translucent line */
   1.345 +                    ofs = 0;
   1.346 +                    do {
   1.347 +                        int run;
   1.348 +                        ofs += ((Uint16 *) srcbuf)[0];
   1.349 +                        run = ((Uint16 *) srcbuf)[1];
   1.350 +                        srcbuf += 4 * (run + 1);
   1.351 +                        ofs += run;
   1.352 +                    }
   1.353 +                    while (ofs < w);
   1.354 +                }
   1.355 +                while (--vskip);
   1.356 +            } else {
   1.357 +                /* the 32/32 interleaved format */
   1.358 +                vskip <<= 1;    /* opaque and translucent have same format */
   1.359 +                do {
   1.360 +                    ofs = 0;
   1.361 +                    do {
   1.362 +                        int run;
   1.363 +                        ofs += ((Uint16 *) srcbuf)[0];
   1.364 +                        run = ((Uint16 *) srcbuf)[1];
   1.365 +                        srcbuf += 4;
   1.366 +                        if (run) {
   1.367 +                            srcbuf += 4 * run;
   1.368 +                            ofs += run;
   1.369 +                        } else if (!ofs)
   1.370 +                            goto done;
   1.371 +                    }
   1.372 +                    while (ofs < w);
   1.373 +                }
   1.374 +                while (--vskip);
   1.375 +            }
   1.376 +        }
   1.377      }
   1.378  
   1.379      /* if left or right edge clipping needed, call clip blit */
   1.380 -    if(srcrect->x || srcrect->w != src->w) {
   1.381 -	RLEAlphaClipBlit(w, srcbuf, dst, dstbuf, srcrect);
   1.382 +    if (srcrect->x || srcrect->w != src->w) {
   1.383 +        RLEAlphaClipBlit(w, srcbuf, dst, dstbuf, srcrect);
   1.384      } else {
   1.385  
   1.386 -	/*
   1.387 -	 * non-clipped blitter. Ptype is the destination pixel type,
   1.388 -	 * Ctype the translucent count type, and do_blend the
   1.389 -	 * macro to blend one pixel.
   1.390 -	 */
   1.391 +        /*
   1.392 +         * non-clipped blitter. Ptype is the destination pixel type,
   1.393 +         * Ctype the translucent count type, and do_blend the
   1.394 +         * macro to blend one pixel.
   1.395 +         */
   1.396  #define RLEALPHABLIT(Ptype, Ctype, do_blend)				 \
   1.397  	do {								 \
   1.398  	    int linecount = srcrect->h;					 \
   1.399 @@ -1235,24 +1251,24 @@
   1.400  	    } while(--linecount);					 \
   1.401  	} while(0)
   1.402  
   1.403 -	switch(df->BytesPerPixel) {
   1.404 -	case 2:
   1.405 -	    if(df->Gmask == 0x07e0 || df->Rmask == 0x07e0
   1.406 -	       || df->Bmask == 0x07e0)
   1.407 -		RLEALPHABLIT(Uint16, Uint8, BLIT_TRANSL_565);
   1.408 -	    else
   1.409 -		RLEALPHABLIT(Uint16, Uint8, BLIT_TRANSL_555);
   1.410 -	    break;
   1.411 -	case 4:
   1.412 -	    RLEALPHABLIT(Uint32, Uint16, BLIT_TRANSL_888);
   1.413 -	    break;
   1.414 -	}
   1.415 +        switch (df->BytesPerPixel) {
   1.416 +        case 2:
   1.417 +            if (df->Gmask == 0x07e0 || df->Rmask == 0x07e0
   1.418 +                || df->Bmask == 0x07e0)
   1.419 +                RLEALPHABLIT(Uint16, Uint8, BLIT_TRANSL_565);
   1.420 +            else
   1.421 +                RLEALPHABLIT(Uint16, Uint8, BLIT_TRANSL_555);
   1.422 +            break;
   1.423 +        case 4:
   1.424 +            RLEALPHABLIT(Uint32, Uint16, BLIT_TRANSL_888);
   1.425 +            break;
   1.426 +        }
   1.427      }
   1.428  
   1.429 - done:
   1.430 +  done:
   1.431      /* Unlock the destination if necessary */
   1.432 -    if ( SDL_MUSTLOCK(dst) ) {
   1.433 -	SDL_UnlockSurface(dst);
   1.434 +    if (SDL_MUSTLOCK(dst)) {
   1.435 +        SDL_UnlockSurface(dst);
   1.436      }
   1.437      return 0;
   1.438  }
   1.439 @@ -1268,34 +1284,36 @@
   1.440   */
   1.441  
   1.442  /* encode 32bpp rgb + a into 16bpp rgb, losing alpha */
   1.443 -static int copy_opaque_16(void *dst, Uint32 *src, int n,
   1.444 -			  SDL_PixelFormat *sfmt, SDL_PixelFormat *dfmt)
   1.445 +static int
   1.446 +copy_opaque_16(void *dst, Uint32 * src, int n,
   1.447 +               SDL_PixelFormat * sfmt, SDL_PixelFormat * dfmt)
   1.448  {
   1.449      int i;
   1.450      Uint16 *d = dst;
   1.451 -    for(i = 0; i < n; i++) {
   1.452 -	unsigned r, g, b;
   1.453 -	RGB_FROM_PIXEL(*src, sfmt, r, g, b);
   1.454 -	PIXEL_FROM_RGB(*d, dfmt, r, g, b);
   1.455 -	src++;
   1.456 -	d++;
   1.457 +    for (i = 0; i < n; i++) {
   1.458 +        unsigned r, g, b;
   1.459 +        RGB_FROM_PIXEL(*src, sfmt, r, g, b);
   1.460 +        PIXEL_FROM_RGB(*d, dfmt, r, g, b);
   1.461 +        src++;
   1.462 +        d++;
   1.463      }
   1.464      return n * 2;
   1.465  }
   1.466  
   1.467  /* decode opaque pixels from 16bpp to 32bpp rgb + a */
   1.468 -static int uncopy_opaque_16(Uint32 *dst, void *src, int n,
   1.469 -			    RLEDestFormat *sfmt, SDL_PixelFormat *dfmt)
   1.470 +static int
   1.471 +uncopy_opaque_16(Uint32 * dst, void *src, int n,
   1.472 +                 RLEDestFormat * sfmt, SDL_PixelFormat * dfmt)
   1.473  {
   1.474      int i;
   1.475      Uint16 *s = src;
   1.476      unsigned alpha = dfmt->Amask ? 255 : 0;
   1.477 -    for(i = 0; i < n; i++) {
   1.478 -	unsigned r, g, b;
   1.479 -	RGB_FROM_PIXEL(*s, sfmt, r, g, b);
   1.480 -	PIXEL_FROM_RGBA(*dst, dfmt, r, g, b, alpha);
   1.481 -	s++;
   1.482 -	dst++;
   1.483 +    for (i = 0; i < n; i++) {
   1.484 +        unsigned r, g, b;
   1.485 +        RGB_FROM_PIXEL(*s, sfmt, r, g, b);
   1.486 +        PIXEL_FROM_RGBA(*dst, dfmt, r, g, b, alpha);
   1.487 +        s++;
   1.488 +        dst++;
   1.489      }
   1.490      return n * 2;
   1.491  }
   1.492 @@ -1303,89 +1321,94 @@
   1.493  
   1.494  
   1.495  /* encode 32bpp rgb + a into 32bpp G0RAB format for blitting into 565 */
   1.496 -static int copy_transl_565(void *dst, Uint32 *src, int n,
   1.497 -			   SDL_PixelFormat *sfmt, SDL_PixelFormat *dfmt)
   1.498 +static int
   1.499 +copy_transl_565(void *dst, Uint32 * src, int n,
   1.500 +                SDL_PixelFormat * sfmt, SDL_PixelFormat * dfmt)
   1.501  {
   1.502      int i;
   1.503      Uint32 *d = dst;
   1.504 -    for(i = 0; i < n; i++) {
   1.505 -	unsigned r, g, b, a;
   1.506 -	Uint16 pix;
   1.507 -	RGBA_FROM_8888(*src, sfmt, r, g, b, a);
   1.508 -	PIXEL_FROM_RGB(pix, dfmt, r, g, b);
   1.509 -	*d = ((pix & 0x7e0) << 16) | (pix & 0xf81f) | ((a << 2) & 0x7e0);
   1.510 -	src++;
   1.511 -	d++;
   1.512 +    for (i = 0; i < n; i++) {
   1.513 +        unsigned r, g, b, a;
   1.514 +        Uint16 pix;
   1.515 +        RGBA_FROM_8888(*src, sfmt, r, g, b, a);
   1.516 +        PIXEL_FROM_RGB(pix, dfmt, r, g, b);
   1.517 +        *d = ((pix & 0x7e0) << 16) | (pix & 0xf81f) | ((a << 2) & 0x7e0);
   1.518 +        src++;
   1.519 +        d++;
   1.520      }
   1.521      return n * 4;
   1.522  }
   1.523  
   1.524  /* encode 32bpp rgb + a into 32bpp G0RAB format for blitting into 555 */
   1.525 -static int copy_transl_555(void *dst, Uint32 *src, int n,
   1.526 -			   SDL_PixelFormat *sfmt, SDL_PixelFormat *dfmt)
   1.527 +static int
   1.528 +copy_transl_555(void *dst, Uint32 * src, int n,
   1.529 +                SDL_PixelFormat * sfmt, SDL_PixelFormat * dfmt)
   1.530  {
   1.531      int i;
   1.532      Uint32 *d = dst;
   1.533 -    for(i = 0; i < n; i++) {
   1.534 -	unsigned r, g, b, a;
   1.535 -	Uint16 pix;
   1.536 -	RGBA_FROM_8888(*src, sfmt, r, g, b, a);
   1.537 -	PIXEL_FROM_RGB(pix, dfmt, r, g, b);
   1.538 -	*d = ((pix & 0x3e0) << 16) | (pix & 0xfc1f) | ((a << 2) & 0x3e0);
   1.539 -	src++;
   1.540 -	d++;
   1.541 +    for (i = 0; i < n; i++) {
   1.542 +        unsigned r, g, b, a;
   1.543 +        Uint16 pix;
   1.544 +        RGBA_FROM_8888(*src, sfmt, r, g, b, a);
   1.545 +        PIXEL_FROM_RGB(pix, dfmt, r, g, b);
   1.546 +        *d = ((pix & 0x3e0) << 16) | (pix & 0xfc1f) | ((a << 2) & 0x3e0);
   1.547 +        src++;
   1.548 +        d++;
   1.549      }
   1.550      return n * 4;
   1.551  }
   1.552  
   1.553  /* decode translucent pixels from 32bpp GORAB to 32bpp rgb + a */
   1.554 -static int uncopy_transl_16(Uint32 *dst, void *src, int n,
   1.555 -			    RLEDestFormat *sfmt, SDL_PixelFormat *dfmt)
   1.556 +static int
   1.557 +uncopy_transl_16(Uint32 * dst, void *src, int n,
   1.558 +                 RLEDestFormat * sfmt, SDL_PixelFormat * dfmt)
   1.559  {
   1.560      int i;
   1.561      Uint32 *s = src;
   1.562 -    for(i = 0; i < n; i++) {
   1.563 -	unsigned r, g, b, a;
   1.564 -	Uint32 pix = *s++;
   1.565 -	a = (pix & 0x3e0) >> 2;
   1.566 -	pix = (pix & ~0x3e0) | pix >> 16;
   1.567 -	RGB_FROM_PIXEL(pix, sfmt, r, g, b);
   1.568 -	PIXEL_FROM_RGBA(*dst, dfmt, r, g, b, a);
   1.569 -	dst++;
   1.570 +    for (i = 0; i < n; i++) {
   1.571 +        unsigned r, g, b, a;
   1.572 +        Uint32 pix = *s++;
   1.573 +        a = (pix & 0x3e0) >> 2;
   1.574 +        pix = (pix & ~0x3e0) | pix >> 16;
   1.575 +        RGB_FROM_PIXEL(pix, sfmt, r, g, b);
   1.576 +        PIXEL_FROM_RGBA(*dst, dfmt, r, g, b, a);
   1.577 +        dst++;
   1.578      }
   1.579      return n * 4;
   1.580  }
   1.581  
   1.582  /* encode 32bpp rgba into 32bpp rgba, keeping alpha (dual purpose) */
   1.583 -static int copy_32(void *dst, Uint32 *src, int n,
   1.584 -		   SDL_PixelFormat *sfmt, SDL_PixelFormat *dfmt)
   1.585 +static int
   1.586 +copy_32(void *dst, Uint32 * src, int n,
   1.587 +        SDL_PixelFormat * sfmt, SDL_PixelFormat * dfmt)
   1.588  {
   1.589      int i;
   1.590      Uint32 *d = dst;
   1.591 -    for(i = 0; i < n; i++) {
   1.592 -	unsigned r, g, b, a;
   1.593 -	Uint32 pixel;
   1.594 -	RGBA_FROM_8888(*src, sfmt, r, g, b, a);
   1.595 -	PIXEL_FROM_RGB(pixel, dfmt, r, g, b);
   1.596 -	*d++ = pixel | a << 24;
   1.597 -	src++;
   1.598 +    for (i = 0; i < n; i++) {
   1.599 +        unsigned r, g, b, a;
   1.600 +        Uint32 pixel;
   1.601 +        RGBA_FROM_8888(*src, sfmt, r, g, b, a);
   1.602 +        PIXEL_FROM_RGB(pixel, dfmt, r, g, b);
   1.603 +        *d++ = pixel | a << 24;
   1.604 +        src++;
   1.605      }
   1.606      return n * 4;
   1.607  }
   1.608  
   1.609  /* decode 32bpp rgba into 32bpp rgba, keeping alpha (dual purpose) */
   1.610 -static int uncopy_32(Uint32 *dst, void *src, int n,
   1.611 -		     RLEDestFormat *sfmt, SDL_PixelFormat *dfmt)
   1.612 +static int
   1.613 +uncopy_32(Uint32 * dst, void *src, int n,
   1.614 +          RLEDestFormat * sfmt, SDL_PixelFormat * dfmt)
   1.615  {
   1.616      int i;
   1.617      Uint32 *s = src;
   1.618 -    for(i = 0; i < n; i++) {
   1.619 -	unsigned r, g, b, a;
   1.620 -	Uint32 pixel = *s++;
   1.621 -	RGB_FROM_PIXEL(pixel, sfmt, r, g, b);
   1.622 -	a = pixel >> 24;
   1.623 -	PIXEL_FROM_RGBA(*dst, dfmt, r, g, b, a);
   1.624 -	dst++;
   1.625 +    for (i = 0; i < n; i++) {
   1.626 +        unsigned r, g, b, a;
   1.627 +        Uint32 pixel = *s++;
   1.628 +        RGB_FROM_PIXEL(pixel, sfmt, r, g, b);
   1.629 +        a = pixel >> 24;
   1.630 +        PIXEL_FROM_RGBA(*dst, dfmt, r, g, b, a);
   1.631 +        dst++;
   1.632      }
   1.633      return n * 4;
   1.634  }
   1.635 @@ -1396,7 +1419,8 @@
   1.636      ((unsigned)((((pixel) & fmt->Amask) >> fmt->Ashift) - 1U) < 254U)
   1.637  
   1.638  /* convert surface to be quickly alpha-blittable onto dest, if possible */
   1.639 -static int RLEAlphaSurface(SDL_Surface *surface)
   1.640 +static int
   1.641 +RLEAlphaSurface(SDL_Surface * surface)
   1.642  {
   1.643      SDL_Surface *dest;
   1.644      SDL_PixelFormat *df;
   1.645 @@ -1405,97 +1429,97 @@
   1.646      int max_transl_run = 65535;
   1.647      unsigned masksum;
   1.648      Uint8 *rlebuf, *dst;
   1.649 -    int (*copy_opaque)(void *, Uint32 *, int,
   1.650 -		       SDL_PixelFormat *, SDL_PixelFormat *);
   1.651 -    int (*copy_transl)(void *, Uint32 *, int,
   1.652 -		       SDL_PixelFormat *, SDL_PixelFormat *);
   1.653 +    int (*copy_opaque) (void *, Uint32 *, int,
   1.654 +                        SDL_PixelFormat *, SDL_PixelFormat *);
   1.655 +    int (*copy_transl) (void *, Uint32 *, int,
   1.656 +                        SDL_PixelFormat *, SDL_PixelFormat *);
   1.657  
   1.658      dest = surface->map->dst;
   1.659 -    if(!dest)
   1.660 -	return -1;
   1.661 +    if (!dest)
   1.662 +        return -1;
   1.663      df = dest->format;
   1.664 -    if(surface->format->BitsPerPixel != 32)
   1.665 -	return -1;		/* only 32bpp source supported */
   1.666 +    if (surface->format->BitsPerPixel != 32)
   1.667 +        return -1;              /* only 32bpp source supported */
   1.668  
   1.669      /* find out whether the destination is one we support,
   1.670         and determine the max size of the encoded result */
   1.671      masksum = df->Rmask | df->Gmask | df->Bmask;
   1.672 -    switch(df->BytesPerPixel) {
   1.673 +    switch (df->BytesPerPixel) {
   1.674      case 2:
   1.675 -	/* 16bpp: only support 565 and 555 formats */
   1.676 -	switch(masksum) {
   1.677 -	case 0xffff:
   1.678 -	    if(df->Gmask == 0x07e0
   1.679 -	       || df->Rmask == 0x07e0 || df->Bmask == 0x07e0) {
   1.680 -		copy_opaque = copy_opaque_16;
   1.681 -		copy_transl = copy_transl_565;
   1.682 -	    } else
   1.683 -		return -1;
   1.684 -	    break;
   1.685 -	case 0x7fff:
   1.686 -	    if(df->Gmask == 0x03e0
   1.687 -	       || df->Rmask == 0x03e0 || df->Bmask == 0x03e0) {
   1.688 -		copy_opaque = copy_opaque_16;
   1.689 -		copy_transl = copy_transl_555;
   1.690 -	    } else
   1.691 -		return -1;
   1.692 -	    break;
   1.693 -	default:
   1.694 -	    return -1;
   1.695 -	}
   1.696 -	max_opaque_run = 255;	/* runs stored as bytes */
   1.697 +        /* 16bpp: only support 565 and 555 formats */
   1.698 +        switch (masksum) {
   1.699 +        case 0xffff:
   1.700 +            if (df->Gmask == 0x07e0
   1.701 +                || df->Rmask == 0x07e0 || df->Bmask == 0x07e0) {
   1.702 +                copy_opaque = copy_opaque_16;
   1.703 +                copy_transl = copy_transl_565;
   1.704 +            } else
   1.705 +                return -1;
   1.706 +            break;
   1.707 +        case 0x7fff:
   1.708 +            if (df->Gmask == 0x03e0
   1.709 +                || df->Rmask == 0x03e0 || df->Bmask == 0x03e0) {
   1.710 +                copy_opaque = copy_opaque_16;
   1.711 +                copy_transl = copy_transl_555;
   1.712 +            } else
   1.713 +                return -1;
   1.714 +            break;
   1.715 +        default:
   1.716 +            return -1;
   1.717 +        }
   1.718 +        max_opaque_run = 255;   /* runs stored as bytes */
   1.719  
   1.720 -	/* worst case is alternating opaque and translucent pixels,
   1.721 -	   with room for alignment padding between lines */
   1.722 -	maxsize = surface->h * (2 + (4 + 2) * (surface->w + 1)) + 2;
   1.723 -	break;
   1.724 +        /* worst case is alternating opaque and translucent pixels,
   1.725 +           with room for alignment padding between lines */
   1.726 +        maxsize = surface->h * (2 + (4 + 2) * (surface->w + 1)) + 2;
   1.727 +        break;
   1.728      case 4:
   1.729 -	if(masksum != 0x00ffffff)
   1.730 -	    return -1;		/* requires unused high byte */
   1.731 -	copy_opaque = copy_32;
   1.732 -	copy_transl = copy_32;
   1.733 -	max_opaque_run = 255;	/* runs stored as short ints */
   1.734 +        if (masksum != 0x00ffffff)
   1.735 +            return -1;          /* requires unused high byte */
   1.736 +        copy_opaque = copy_32;
   1.737 +        copy_transl = copy_32;
   1.738 +        max_opaque_run = 255;   /* runs stored as short ints */
   1.739  
   1.740 -	/* worst case is alternating opaque and translucent pixels */
   1.741 -	maxsize = surface->h * 2 * 4 * (surface->w + 1) + 4;
   1.742 -	break;
   1.743 +        /* worst case is alternating opaque and translucent pixels */
   1.744 +        maxsize = surface->h * 2 * 4 * (surface->w + 1) + 4;
   1.745 +        break;
   1.746      default:
   1.747 -	return -1;		/* anything else unsupported right now */
   1.748 +        return -1;              /* anything else unsupported right now */
   1.749      }
   1.750  
   1.751      maxsize += sizeof(RLEDestFormat);
   1.752 -    rlebuf = (Uint8 *)SDL_malloc(maxsize);
   1.753 -    if(!rlebuf) {
   1.754 -	SDL_OutOfMemory();
   1.755 -	return -1;
   1.756 +    rlebuf = (Uint8 *) SDL_malloc(maxsize);
   1.757 +    if (!rlebuf) {
   1.758 +        SDL_OutOfMemory();
   1.759 +        return -1;
   1.760      }
   1.761      {
   1.762 -	/* save the destination format so we can undo the encoding later */
   1.763 -	RLEDestFormat *r = (RLEDestFormat *)rlebuf;
   1.764 -	r->BytesPerPixel = df->BytesPerPixel;
   1.765 -	r->Rloss = df->Rloss;
   1.766 -	r->Gloss = df->Gloss;
   1.767 -	r->Bloss = df->Bloss;
   1.768 -	r->Rshift = df->Rshift;
   1.769 -	r->Gshift = df->Gshift;
   1.770 -	r->Bshift = df->Bshift;
   1.771 -	r->Ashift = df->Ashift;
   1.772 -	r->Rmask = df->Rmask;
   1.773 -	r->Gmask = df->Gmask;
   1.774 -	r->Bmask = df->Bmask;
   1.775 -	r->Amask = df->Amask;
   1.776 +        /* save the destination format so we can undo the encoding later */
   1.777 +        RLEDestFormat *r = (RLEDestFormat *) rlebuf;
   1.778 +        r->BytesPerPixel = df->BytesPerPixel;
   1.779 +        r->Rloss = df->Rloss;
   1.780 +        r->Gloss = df->Gloss;
   1.781 +        r->Bloss = df->Bloss;
   1.782 +        r->Rshift = df->Rshift;
   1.783 +        r->Gshift = df->Gshift;
   1.784 +        r->Bshift = df->Bshift;
   1.785 +        r->Ashift = df->Ashift;
   1.786 +        r->Rmask = df->Rmask;
   1.787 +        r->Gmask = df->Gmask;
   1.788 +        r->Bmask = df->Bmask;
   1.789 +        r->Amask = df->Amask;
   1.790      }
   1.791      dst = rlebuf + sizeof(RLEDestFormat);
   1.792  
   1.793      /* Do the actual encoding */
   1.794      {
   1.795 -	int x, y;
   1.796 -	int h = surface->h, w = surface->w;
   1.797 -	SDL_PixelFormat *sf = surface->format;
   1.798 -	Uint32 *src = (Uint32 *)surface->pixels;
   1.799 -	Uint8 *lastline = dst;	/* end of last non-blank line */
   1.800 +        int x, y;
   1.801 +        int h = surface->h, w = surface->w;
   1.802 +        SDL_PixelFormat *sf = surface->format;
   1.803 +        Uint32 *src = (Uint32 *) surface->pixels;
   1.804 +        Uint8 *lastline = dst;  /* end of last non-blank line */
   1.805  
   1.806 -	/* opaque counts are 8 or 16 bits, depending on target depth */
   1.807 +        /* opaque counts are 8 or 16 bits, depending on target depth */
   1.808  #define ADD_OPAQUE_COUNTS(n, m)			\
   1.809  	if(df->BytesPerPixel == 4) {		\
   1.810  	    ((Uint16 *)dst)[0] = n;		\
   1.811 @@ -1507,119 +1531,123 @@
   1.812  	    dst += 2;				\
   1.813  	}
   1.814  
   1.815 -	/* translucent counts are always 16 bit */
   1.816 +        /* translucent counts are always 16 bit */
   1.817  #define ADD_TRANSL_COUNTS(n, m)		\
   1.818  	(((Uint16 *)dst)[0] = n, ((Uint16 *)dst)[1] = m, dst += 4)
   1.819  
   1.820 -	for(y = 0; y < h; y++) {
   1.821 -	    int runstart, skipstart;
   1.822 -	    int blankline = 0;
   1.823 -	    /* First encode all opaque pixels of a scan line */
   1.824 -	    x = 0;
   1.825 -	    do {
   1.826 -		int run, skip, len;
   1.827 -		skipstart = x;
   1.828 -		while(x < w && !ISOPAQUE(src[x], sf))
   1.829 -		    x++;
   1.830 -		runstart = x;
   1.831 -		while(x < w && ISOPAQUE(src[x], sf))
   1.832 -		    x++;
   1.833 -		skip = runstart - skipstart;
   1.834 -		if(skip == w)
   1.835 -		    blankline = 1;
   1.836 -		run = x - runstart;
   1.837 -		while(skip > max_opaque_run) {
   1.838 -		    ADD_OPAQUE_COUNTS(max_opaque_run, 0);
   1.839 -		    skip -= max_opaque_run;
   1.840 -		}
   1.841 -		len = MIN(run, max_opaque_run);
   1.842 -		ADD_OPAQUE_COUNTS(skip, len);
   1.843 -		dst += copy_opaque(dst, src + runstart, len, sf, df);
   1.844 -		runstart += len;
   1.845 -		run -= len;
   1.846 -		while(run) {
   1.847 -		    len = MIN(run, max_opaque_run);
   1.848 -		    ADD_OPAQUE_COUNTS(0, len);
   1.849 -		    dst += copy_opaque(dst, src + runstart, len, sf, df);
   1.850 -		    runstart += len;
   1.851 -		    run -= len;
   1.852 -		}
   1.853 -	    } while(x < w);
   1.854 +        for (y = 0; y < h; y++) {
   1.855 +            int runstart, skipstart;
   1.856 +            int blankline = 0;
   1.857 +            /* First encode all opaque pixels of a scan line */
   1.858 +            x = 0;
   1.859 +            do {
   1.860 +                int run, skip, len;
   1.861 +                skipstart = x;
   1.862 +                while (x < w && !ISOPAQUE(src[x], sf))
   1.863 +                    x++;
   1.864 +                runstart = x;
   1.865 +                while (x < w && ISOPAQUE(src[x], sf))
   1.866 +                    x++;
   1.867 +                skip = runstart - skipstart;
   1.868 +                if (skip == w)
   1.869 +                    blankline = 1;
   1.870 +                run = x - runstart;
   1.871 +                while (skip > max_opaque_run) {
   1.872 +                    ADD_OPAQUE_COUNTS(max_opaque_run, 0);
   1.873 +                    skip -= max_opaque_run;
   1.874 +                }
   1.875 +                len = MIN(run, max_opaque_run);
   1.876 +                ADD_OPAQUE_COUNTS(skip, len);
   1.877 +                dst += copy_opaque(dst, src + runstart, len, sf, df);
   1.878 +                runstart += len;
   1.879 +                run -= len;
   1.880 +                while (run) {
   1.881 +                    len = MIN(run, max_opaque_run);
   1.882 +                    ADD_OPAQUE_COUNTS(0, len);
   1.883 +                    dst += copy_opaque(dst, src + runstart, len, sf, df);
   1.884 +                    runstart += len;
   1.885 +                    run -= len;
   1.886 +                }
   1.887 +            }
   1.888 +            while (x < w);
   1.889  
   1.890 -	    /* Make sure the next output address is 32-bit aligned */
   1.891 -	    dst += (uintptr_t)dst & 2;
   1.892 +            /* Make sure the next output address is 32-bit aligned */
   1.893 +            dst += (uintptr_t) dst & 2;
   1.894  
   1.895 -	    /* Next, encode all translucent pixels of the same scan line */
   1.896 -	    x = 0;
   1.897 -	    do {
   1.898 -		int run, skip, len;
   1.899 -		skipstart = x;
   1.900 -		while(x < w && !ISTRANSL(src[x], sf))
   1.901 -		    x++;
   1.902 -		runstart = x;
   1.903 -		while(x < w && ISTRANSL(src[x], sf))
   1.904 -		    x++;
   1.905 -		skip = runstart - skipstart;
   1.906 -		blankline &= (skip == w);
   1.907 -		run = x - runstart;
   1.908 -		while(skip > max_transl_run) {
   1.909 -		    ADD_TRANSL_COUNTS(max_transl_run, 0);
   1.910 -		    skip -= max_transl_run;
   1.911 -		}
   1.912 -		len = MIN(run, max_transl_run);
   1.913 -		ADD_TRANSL_COUNTS(skip, len);
   1.914 -		dst += copy_transl(dst, src + runstart, len, sf, df);
   1.915 -		runstart += len;
   1.916 -		run -= len;
   1.917 -		while(run) {
   1.918 -		    len = MIN(run, max_transl_run);
   1.919 -		    ADD_TRANSL_COUNTS(0, len);
   1.920 -		    dst += copy_transl(dst, src + runstart, len, sf, df);
   1.921 -		    runstart += len;
   1.922 -		    run -= len;
   1.923 -		}
   1.924 -		if(!blankline)
   1.925 -		    lastline = dst;
   1.926 -	    } while(x < w);
   1.927 +            /* Next, encode all translucent pixels of the same scan line */
   1.928 +            x = 0;
   1.929 +            do {
   1.930 +                int run, skip, len;
   1.931 +                skipstart = x;
   1.932 +                while (x < w && !ISTRANSL(src[x], sf))
   1.933 +                    x++;
   1.934 +                runstart = x;
   1.935 +                while (x < w && ISTRANSL(src[x], sf))
   1.936 +                    x++;
   1.937 +                skip = runstart - skipstart;
   1.938 +                blankline &= (skip == w);
   1.939 +                run = x - runstart;
   1.940 +                while (skip > max_transl_run) {
   1.941 +                    ADD_TRANSL_COUNTS(max_transl_run, 0);
   1.942 +                    skip -= max_transl_run;
   1.943 +                }
   1.944 +                len = MIN(run, max_transl_run);
   1.945 +                ADD_TRANSL_COUNTS(skip, len);
   1.946 +                dst += copy_transl(dst, src + runstart, len, sf, df);
   1.947 +                runstart += len;
   1.948 +                run -= len;
   1.949 +                while (run) {
   1.950 +                    len = MIN(run, max_transl_run);
   1.951 +                    ADD_TRANSL_COUNTS(0, len);
   1.952 +                    dst += copy_transl(dst, src + runstart, len, sf, df);
   1.953 +                    runstart += len;
   1.954 +                    run -= len;
   1.955 +                }
   1.956 +                if (!blankline)
   1.957 +                    lastline = dst;
   1.958 +            }
   1.959 +            while (x < w);
   1.960  
   1.961 -	    src += surface->pitch >> 2;
   1.962 -	}
   1.963 -	dst = lastline;		/* back up past trailing blank lines */
   1.964 -	ADD_OPAQUE_COUNTS(0, 0);
   1.965 +            src += surface->pitch >> 2;
   1.966 +        }
   1.967 +        dst = lastline;         /* back up past trailing blank lines */
   1.968 +        ADD_OPAQUE_COUNTS(0, 0);
   1.969      }
   1.970  
   1.971  #undef ADD_OPAQUE_COUNTS
   1.972  #undef ADD_TRANSL_COUNTS
   1.973  
   1.974      /* Now that we have it encoded, release the original pixels */
   1.975 -    if((surface->flags & SDL_PREALLOC) != SDL_PREALLOC
   1.976 -       && (surface->flags & SDL_HWSURFACE) != SDL_HWSURFACE) {
   1.977 -	SDL_free( surface->pixels );
   1.978 -	surface->pixels = NULL;
   1.979 +    if (!(surface->flags & SDL_PREALLOC) && !(surface->flags & SDL_HWSURFACE)) {
   1.980 +        SDL_free(surface->pixels);
   1.981 +        surface->pixels = NULL;
   1.982      }
   1.983  
   1.984      /* realloc the buffer to release unused memory */
   1.985      {
   1.986 -	Uint8 *p = SDL_realloc(rlebuf, dst - rlebuf);
   1.987 -	if(!p)
   1.988 -	    p = rlebuf;
   1.989 -	surface->map->sw_data->aux_data = p;
   1.990 +        Uint8 *p = SDL_realloc(rlebuf, dst - rlebuf);
   1.991 +        if (!p)
   1.992 +            p = rlebuf;
   1.993 +        surface->map->sw_data->aux_data = p;
   1.994      }
   1.995  
   1.996      return 0;
   1.997  }
   1.998  
   1.999 -static Uint32 getpix_8(Uint8 *srcbuf)
  1.1000 +static Uint32
  1.1001 +getpix_8(Uint8 * srcbuf)
  1.1002  {
  1.1003      return *srcbuf;
  1.1004  }
  1.1005  
  1.1006 -static Uint32 getpix_16(Uint8 *srcbuf)
  1.1007 +static Uint32
  1.1008 +getpix_16(Uint8 * srcbuf)
  1.1009  {
  1.1010 -    return *(Uint16 *)srcbuf;
  1.1011 +    return *(Uint16 *) srcbuf;
  1.1012  }
  1.1013  
  1.1014 -static Uint32 getpix_24(Uint8 *srcbuf)
  1.1015 +static Uint32
  1.1016 +getpix_24(Uint8 * srcbuf)
  1.1017  {
  1.1018  #if SDL_BYTEORDER == SDL_LIL_ENDIAN
  1.1019      return srcbuf[0] + (srcbuf[1] << 8) + (srcbuf[2] << 16);
  1.1020 @@ -1628,68 +1656,70 @@
  1.1021  #endif
  1.1022  }
  1.1023  
  1.1024 -static Uint32 getpix_32(Uint8 *srcbuf)
  1.1025 +static Uint32
  1.1026 +getpix_32(Uint8 * srcbuf)
  1.1027  {
  1.1028 -    return *(Uint32 *)srcbuf;
  1.1029 +    return *(Uint32 *) srcbuf;
  1.1030  }
  1.1031  
  1.1032 -typedef Uint32 (*getpix_func)(Uint8 *);
  1.1033 +typedef Uint32(*getpix_func) (Uint8 *);
  1.1034  
  1.1035  static getpix_func getpixes[4] = {
  1.1036      getpix_8, getpix_16, getpix_24, getpix_32
  1.1037  };
  1.1038  
  1.1039 -static int RLEColorkeySurface(SDL_Surface *surface)
  1.1040 +static int
  1.1041 +RLEColorkeySurface(SDL_Surface * surface)
  1.1042  {
  1.1043 -        Uint8 *rlebuf, *dst;
  1.1044 -	int maxn;
  1.1045 -	int y;
  1.1046 -	Uint8 *srcbuf, *curbuf, *lastline;
  1.1047 -	int maxsize = 0;
  1.1048 -	int skip, run;
  1.1049 -	int bpp = surface->format->BytesPerPixel;
  1.1050 -	getpix_func getpix;
  1.1051 -	Uint32 ckey, rgbmask;
  1.1052 -	int w, h;
  1.1053 +    Uint8 *rlebuf, *dst;
  1.1054 +    int maxn;
  1.1055 +    int y;
  1.1056 +    Uint8 *srcbuf, *curbuf, *lastline;
  1.1057 +    int maxsize = 0;
  1.1058 +    int skip, run;
  1.1059 +    int bpp = surface->format->BytesPerPixel;
  1.1060 +    getpix_func getpix;
  1.1061 +    Uint32 ckey, rgbmask;
  1.1062 +    int w, h;
  1.1063  
  1.1064 -	/* calculate the worst case size for the compressed surface */
  1.1065 -	switch(bpp) {
  1.1066 -	case 1:
  1.1067 -	    /* worst case is alternating opaque and transparent pixels,
  1.1068 -	       starting with an opaque pixel */
  1.1069 -	    maxsize = surface->h * 3 * (surface->w / 2 + 1) + 2;
  1.1070 -	    break;
  1.1071 -	case 2:
  1.1072 -	case 3:
  1.1073 -	    /* worst case is solid runs, at most 255 pixels wide */
  1.1074 -	    maxsize = surface->h * (2 * (surface->w / 255 + 1)
  1.1075 -				    + surface->w * bpp) + 2;
  1.1076 -	    break;
  1.1077 -	case 4:
  1.1078 -	    /* worst case is solid runs, at most 65535 pixels wide */
  1.1079 -	    maxsize = surface->h * (4 * (surface->w / 65535 + 1)
  1.1080 -				    + surface->w * 4) + 4;
  1.1081 -	    break;
  1.1082 -	}
  1.1083 +    /* calculate the worst case size for the compressed surface */
  1.1084 +    switch (bpp) {
  1.1085 +    case 1:
  1.1086 +        /* worst case is alternating opaque and transparent pixels,
  1.1087 +           starting with an opaque pixel */
  1.1088 +        maxsize = surface->h * 3 * (surface->w / 2 + 1) + 2;
  1.1089 +        break;
  1.1090 +    case 2:
  1.1091 +    case 3:
  1.1092 +        /* worst case is solid runs, at most 255 pixels wide */
  1.1093 +        maxsize = surface->h * (2 * (surface->w / 255 + 1)
  1.1094 +                                + surface->w * bpp) + 2;
  1.1095 +        break;
  1.1096 +    case 4:
  1.1097 +        /* worst case is solid runs, at most 65535 pixels wide */
  1.1098 +        maxsize = surface->h * (4 * (surface->w / 65535 + 1)
  1.1099 +                                + surface->w * 4) + 4;
  1.1100 +        break;
  1.1101 +    }
  1.1102  
  1.1103 -	rlebuf = (Uint8 *)SDL_malloc(maxsize);
  1.1104 -	if ( rlebuf == NULL ) {
  1.1105 -		SDL_OutOfMemory();
  1.1106 -		return(-1);
  1.1107 -	}
  1.1108 +    rlebuf = (Uint8 *) SDL_malloc(maxsize);
  1.1109 +    if (rlebuf == NULL) {
  1.1110 +        SDL_OutOfMemory();
  1.1111 +        return (-1);
  1.1112 +    }
  1.1113  
  1.1114 -	/* Set up the conversion */
  1.1115 -	srcbuf = (Uint8 *)surface->pixels;
  1.1116 -	curbuf = srcbuf;
  1.1117 -	maxn = bpp == 4 ? 65535 : 255;
  1.1118 -	skip = run = 0;
  1.1119 -	dst = rlebuf;
  1.1120 -	rgbmask = ~surface->format->Amask;
  1.1121 -	ckey = surface->format->colorkey & rgbmask;
  1.1122 -	lastline = dst;
  1.1123 -	getpix = getpixes[bpp - 1];
  1.1124 -	w = surface->w;
  1.1125 -	h = surface->h;
  1.1126 +    /* Set up the conversion */
  1.1127 +    srcbuf = (Uint8 *) surface->pixels;
  1.1128 +    curbuf = srcbuf;
  1.1129 +    maxn = bpp == 4 ? 65535 : 255;
  1.1130 +    skip = run = 0;
  1.1131 +    dst = rlebuf;
  1.1132 +    rgbmask = ~surface->format->Amask;
  1.1133 +    ckey = surface->format->colorkey & rgbmask;
  1.1134 +    lastline = dst;
  1.1135 +    getpix = getpixes[bpp - 1];
  1.1136 +    w = surface->w;
  1.1137 +    h = surface->h;
  1.1138  
  1.1139  #define ADD_COUNTS(n, m)			\
  1.1140  	if(bpp == 4) {				\
  1.1141 @@ -1702,118 +1732,119 @@
  1.1142  	    dst += 2;				\
  1.1143  	}
  1.1144  
  1.1145 -	for(y = 0; y < h; y++) {
  1.1146 -	    int x = 0;
  1.1147 -	    int blankline = 0;
  1.1148 -	    do {
  1.1149 -		int run, skip, len;
  1.1150 -		int runstart;
  1.1151 -		int skipstart = x;
  1.1152 +    for (y = 0; y < h; y++) {
  1.1153 +        int x = 0;
  1.1154 +        int blankline = 0;
  1.1155 +        do {
  1.1156 +            int run, skip, len;
  1.1157 +            int runstart;
  1.1158 +            int skipstart = x;
  1.1159  
  1.1160 -		/* find run of transparent, then opaque pixels */
  1.1161 -		while(x < w && (getpix(srcbuf + x * bpp) & rgbmask) == ckey)
  1.1162 -		    x++;
  1.1163 -		runstart = x;
  1.1164 -		while(x < w && (getpix(srcbuf + x * bpp) & rgbmask) != ckey)
  1.1165 -		    x++;
  1.1166 -		skip = runstart - skipstart;
  1.1167 -		if(skip == w)
  1.1168 -		    blankline = 1;
  1.1169 -		run = x - runstart;
  1.1170 +            /* find run of transparent, then opaque pixels */
  1.1171 +            while (x < w && (getpix(srcbuf + x * bpp) & rgbmask) == ckey)
  1.1172 +                x++;
  1.1173 +            runstart = x;
  1.1174 +            while (x < w && (getpix(srcbuf + x * bpp) & rgbmask) != ckey)
  1.1175 +                x++;
  1.1176 +            skip = runstart - skipstart;
  1.1177 +            if (skip == w)
  1.1178 +                blankline = 1;
  1.1179 +            run = x - runstart;
  1.1180  
  1.1181 -		/* encode segment */
  1.1182 -		while(skip > maxn) {
  1.1183 -		    ADD_COUNTS(maxn, 0);
  1.1184 -		    skip -= maxn;
  1.1185 -		}
  1.1186 -		len = MIN(run, maxn);
  1.1187 -		ADD_COUNTS(skip, len);
  1.1188 -		SDL_memcpy(dst, srcbuf + runstart * bpp, len * bpp);
  1.1189 -		dst += len * bpp;
  1.1190 -		run -= len;
  1.1191 -		runstart += len;
  1.1192 -		while(run) {
  1.1193 -		    len = MIN(run, maxn);
  1.1194 -		    ADD_COUNTS(0, len);
  1.1195 -		    SDL_memcpy(dst, srcbuf + runstart * bpp, len * bpp);
  1.1196 -		    dst += len * bpp;
  1.1197 -		    runstart += len;
  1.1198 -		    run -= len;
  1.1199 -		}
  1.1200 -		if(!blankline)
  1.1201 -		    lastline = dst;
  1.1202 -	    } while(x < w);
  1.1203 +            /* encode segment */
  1.1204 +            while (skip > maxn) {
  1.1205 +                ADD_COUNTS(maxn, 0);
  1.1206 +                skip -= maxn;
  1.1207 +            }
  1.1208 +            len = MIN(run, maxn);
  1.1209 +            ADD_COUNTS(skip, len);
  1.1210 +            SDL_memcpy(dst, srcbuf + runstart * bpp, len * bpp);
  1.1211 +            dst += len * bpp;
  1.1212 +            run -= len;
  1.1213 +            runstart += len;
  1.1214 +            while (run) {
  1.1215 +                len = MIN(run, maxn);
  1.1216 +                ADD_COUNTS(0, len);
  1.1217 +                SDL_memcpy(dst, srcbuf + runstart * bpp, len * bpp);
  1.1218 +                dst += len * bpp;
  1.1219 +                runstart += len;
  1.1220 +                run -= len;
  1.1221 +            }
  1.1222 +            if (!blankline)
  1.1223 +                lastline = dst;
  1.1224 +        }
  1.1225 +        while (x < w);
  1.1226  
  1.1227 -	    srcbuf += surface->pitch;
  1.1228 -	}
  1.1229 -	dst = lastline;		/* back up bast trailing blank lines */
  1.1230 -	ADD_COUNTS(0, 0);
  1.1231 +        srcbuf += surface->pitch;
  1.1232 +    }
  1.1233 +    dst = lastline;             /* back up bast trailing blank lines */
  1.1234 +    ADD_COUNTS(0, 0);
  1.1235  
  1.1236  #undef ADD_COUNTS
  1.1237  
  1.1238 -	/* Now that we have it encoded, release the original pixels */
  1.1239 -	if((surface->flags & SDL_PREALLOC) != SDL_PREALLOC
  1.1240 -	   && (surface->flags & SDL_HWSURFACE) != SDL_HWSURFACE) {
  1.1241 -	    SDL_free( surface->pixels );
  1.1242 -	    surface->pixels = NULL;
  1.1243 -	}
  1.1244 +    /* Now that we have it encoded, release the original pixels */
  1.1245 +    if (!(surface->flags & SDL_PREALLOC) && !(surface->flags & SDL_HWSURFACE)) {
  1.1246 +        SDL_free(surface->pixels);
  1.1247 +        surface->pixels = NULL;
  1.1248 +    }
  1.1249  
  1.1250 -	/* realloc the buffer to release unused memory */
  1.1251 -	{
  1.1252 -	    /* If realloc returns NULL, the original block is left intact */
  1.1253 -	    Uint8 *p = SDL_realloc(rlebuf, dst - rlebuf);
  1.1254 -	    if(!p)
  1.1255 -		p = rlebuf;
  1.1256 -	    surface->map->sw_data->aux_data = p;
  1.1257 -	}
  1.1258 +    /* realloc the buffer to release unused memory */
  1.1259 +    {
  1.1260 +        /* If realloc returns NULL, the original block is left intact */
  1.1261 +        Uint8 *p = SDL_realloc(rlebuf, dst - rlebuf);
  1.1262 +        if (!p)
  1.1263 +            p = rlebuf;
  1.1264 +        surface->map->sw_data->aux_data = p;
  1.1265 +    }
  1.1266  
  1.1267 -	return(0);
  1.1268 +    return (0);
  1.1269  }
  1.1270  
  1.1271 -int SDL_RLESurface(SDL_Surface *surface)
  1.1272 +int
  1.1273 +SDL_RLESurface(SDL_Surface * surface)
  1.1274  {
  1.1275 -	int retcode;
  1.1276 +    int retcode;
  1.1277  
  1.1278 -	/* Clear any previous RLE conversion */
  1.1279 -	if ( (surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL ) {
  1.1280 -		SDL_UnRLESurface(surface, 1);
  1.1281 -	}
  1.1282 +    /* Clear any previous RLE conversion */
  1.1283 +    if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) {
  1.1284 +        SDL_UnRLESurface(surface, 1);
  1.1285 +    }
  1.1286  
  1.1287 -	/* We don't support RLE encoding of bitmaps */
  1.1288 -	if ( surface->format->BitsPerPixel < 8 ) {
  1.1289 -		return(-1);
  1.1290 -	}
  1.1291 +    /* We don't support RLE encoding of bitmaps */
  1.1292 +    if (surface->format->BitsPerPixel < 8) {
  1.1293 +        return (-1);
  1.1294 +    }
  1.1295  
  1.1296 -	/* Lock the surface if it's in hardware */
  1.1297 -	if ( SDL_MUSTLOCK(surface) ) {
  1.1298 -		if ( SDL_LockSurface(surface) < 0 ) {
  1.1299 -			return(-1);
  1.1300 -		}
  1.1301 -	}
  1.1302 +    /* Lock the surface if it's in hardware */
  1.1303 +    if (SDL_MUSTLOCK(surface)) {
  1.1304 +        if (SDL_LockSurface(surface) < 0) {
  1.1305 +            return (-1);
  1.1306 +        }
  1.1307 +    }
  1.1308  
  1.1309 -	/* Encode */
  1.1310 -	if((surface->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) {
  1.1311 -	    retcode = RLEColorkeySurface(surface);
  1.1312 -	} else {
  1.1313 -	    if((surface->flags & SDL_SRCALPHA) == SDL_SRCALPHA
  1.1314 -	       && surface->format->Amask != 0)
  1.1315 -		retcode = RLEAlphaSurface(surface);
  1.1316 -	    else
  1.1317 -		retcode = -1;	/* no RLE for per-surface alpha sans ckey */
  1.1318 -	}
  1.1319 +    /* Encode */
  1.1320 +    if ((surface->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) {
  1.1321 +        retcode = RLEColorkeySurface(surface);
  1.1322 +    } else {
  1.1323 +        if ((surface->flags & SDL_SRCALPHA) == SDL_SRCALPHA
  1.1324 +            && surface->format->Amask != 0)
  1.1325 +            retcode = RLEAlphaSurface(surface);
  1.1326 +        else
  1.1327 +            retcode = -1;       /* no RLE for per-surface alpha sans ckey */
  1.1328 +    }
  1.1329  
  1.1330 -	/* Unlock the surface if it's in hardware */
  1.1331 -	if ( SDL_MUSTLOCK(surface) ) {
  1.1332 -		SDL_UnlockSurface(surface);
  1.1333 -	}
  1.1334 +    /* Unlock the surface if it's in hardware */
  1.1335 +    if (SDL_MUSTLOCK(surface)) {
  1.1336 +        SDL_UnlockSurface(surface);
  1.1337 +    }
  1.1338  
  1.1339 -	if(retcode < 0)
  1.1340 -	    return -1;
  1.1341 +    if (retcode < 0)
  1.1342 +        return -1;
  1.1343  
  1.1344 -	/* The surface is now accelerated */
  1.1345 -	surface->flags |= SDL_RLEACCEL;
  1.1346 +    /* The surface is now accelerated */
  1.1347 +    surface->flags |= SDL_RLEACCEL;
  1.1348  
  1.1349 -	return(0);
  1.1350 +    return (0);
  1.1351  }
  1.1352  
  1.1353  /*
  1.1354 @@ -1822,122 +1853,126 @@
  1.1355   * completely transparent pixels will be lost, and colour and alpha depth
  1.1356   * may have been reduced (when encoding for 16bpp targets).
  1.1357   */
  1.1358 -static SDL_bool UnRLEAlpha(SDL_Surface *surface)
  1.1359 +static SDL_bool
  1.1360 +UnRLEAlpha(SDL_Surface * surface)
  1.1361  {
  1.1362      Uint8 *srcbuf;
  1.1363      Uint32 *dst;
  1.1364      SDL_PixelFormat *sf = surface->format;
  1.1365      RLEDestFormat *df = surface->map->sw_data->aux_data;
  1.1366 -    int (*uncopy_opaque)(Uint32 *, void *, int,
  1.1367 -			 RLEDestFormat *, SDL_PixelFormat *);
  1.1368 -    int (*uncopy_transl)(Uint32 *, void *, int,
  1.1369 -			 RLEDestFormat *, SDL_PixelFormat *);
  1.1370 +    int (*uncopy_opaque) (Uint32 *, void *, int,
  1.1371 +                          RLEDestFormat *, SDL_PixelFormat *);
  1.1372 +    int (*uncopy_transl) (Uint32 *, void *, int,
  1.1373 +                          RLEDestFormat *, SDL_PixelFormat *);
  1.1374      int w = surface->w;
  1.1375      int bpp = df->BytesPerPixel;
  1.1376  
  1.1377 -    if(bpp == 2) {
  1.1378 -	uncopy_opaque = uncopy_opaque_16;
  1.1379 -	uncopy_transl = uncopy_transl_16;
  1.1380 +    if (bpp == 2) {
  1.1381 +        uncopy_opaque = uncopy_opaque_16;
  1.1382 +        uncopy_transl = uncopy_transl_16;
  1.1383      } else {
  1.1384 -	uncopy_opaque = uncopy_transl = uncopy_32;
  1.1385 +        uncopy_opaque = uncopy_transl = uncopy_32;
  1.1386      }
  1.1387  
  1.1388      surface->pixels = SDL_malloc(surface->h * surface->pitch);
  1.1389 -    if ( !surface->pixels ) {
  1.1390 -        return(SDL_FALSE);
  1.1391 +    if (!surface->pixels) {
  1.1392 +        return (SDL_FALSE);
  1.1393      }
  1.1394      /* fill background with transparent pixels */
  1.1395      SDL_memset(surface->pixels, 0, surface->h * surface->pitch);
  1.1396  
  1.1397      dst = surface->pixels;
  1.1398 -    srcbuf = (Uint8 *)(df + 1);
  1.1399 -    for(;;) {
  1.1400 -	/* copy opaque pixels */
  1.1401 -	int ofs = 0;
  1.1402 -	do {
  1.1403 -	    unsigned run;
  1.1404 -	    if(bpp == 2) {
  1.1405 -		ofs += srcbuf[0];
  1.1406 -		run = srcbuf[1];
  1.1407 -		srcbuf += 2;
  1.1408 -	    } else {
  1.1409 -		ofs += ((Uint16 *)srcbuf)[0];
  1.1410 -		run = ((Uint16 *)srcbuf)[1];
  1.1411 -		srcbuf += 4;
  1.1412 -	    }
  1.1413 -	    if(run) {
  1.1414 -		srcbuf += uncopy_opaque(dst + ofs, srcbuf, run, df, sf);
  1.1415 -		ofs += run;
  1.1416 -	    } else if(!ofs)
  1.1417 -		return(SDL_TRUE);
  1.1418 -	} while(ofs < w);
  1.1419 +    srcbuf = (Uint8 *) (df + 1);
  1.1420 +    for (;;) {
  1.1421 +        /* copy opaque pixels */
  1.1422 +        int ofs = 0;
  1.1423 +        do {
  1.1424 +            unsigned run;
  1.1425 +            if (bpp == 2) {
  1.1426 +                ofs += srcbuf[0];
  1.1427 +                run = srcbuf[1];
  1.1428 +                srcbuf += 2;
  1.1429 +            } else {
  1.1430 +                ofs += ((Uint16 *) srcbuf)[0];
  1.1431 +                run = ((Uint16 *) srcbuf)[1];
  1.1432 +                srcbuf += 4;
  1.1433 +            }
  1.1434 +            if (run) {
  1.1435 +                srcbuf += uncopy_opaque(dst + ofs, srcbuf, run, df, sf);
  1.1436 +                ofs += run;
  1.1437 +            } else if (!ofs)
  1.1438 +                return (SDL_TRUE);
  1.1439 +        }
  1.1440 +        while (ofs < w);
  1.1441  
  1.1442 -	/* skip padding if needed */
  1.1443 -	if(bpp == 2)
  1.1444 -	    srcbuf += (uintptr_t)srcbuf & 2;
  1.1445 -	
  1.1446 -	/* copy translucent pixels */
  1.1447 -	ofs = 0;
  1.1448 -	do {
  1.1449 -	    unsigned run;
  1.1450 -	    ofs += ((Uint16 *)srcbuf)[0];
  1.1451 -	    run = ((Uint16 *)srcbuf)[1];
  1.1452 -	    srcbuf += 4;
  1.1453 -	    if(run) {
  1.1454 -		srcbuf += uncopy_transl(dst + ofs, srcbuf, run, df, sf);
  1.1455 -		ofs += run;
  1.1456 -	    }
  1.1457 -	} while(ofs < w);
  1.1458 -	dst += surface->pitch >> 2;
  1.1459 +        /* skip padding if needed */
  1.1460 +        if (bpp == 2)
  1.1461 +            srcbuf += (uintptr_t) srcbuf & 2;
  1.1462 +
  1.1463 +        /* copy translucent pixels */
  1.1464 +        ofs = 0;
  1.1465 +        do {
  1.1466 +            unsigned run;
  1.1467 +            ofs += ((Uint16 *) srcbuf)[0];
  1.1468 +            run = ((Uint16 *) srcbuf)[1];
  1.1469 +            srcbuf += 4;
  1.1470 +            if (run) {
  1.1471 +                srcbuf += uncopy_transl(dst + ofs, srcbuf, run, df, sf);
  1.1472 +                ofs += run;
  1.1473 +            }
  1.1474 +        }
  1.1475 +        while (ofs < w);
  1.1476 +        dst += surface->pitch >> 2;
  1.1477      }
  1.1478      /* Make the compiler happy */
  1.1479 -    return(SDL_TRUE);
  1.1480 +    return (SDL_TRUE);
  1.1481  }
  1.1482  
  1.1483 -void SDL_UnRLESurface(SDL_Surface *surface, int recode)
  1.1484 +void
  1.1485 +SDL_UnRLESurface(SDL_Surface * surface, int recode)
  1.1486  {
  1.1487 -    if ( (surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL ) {
  1.1488 -	surface->flags &= ~SDL_RLEACCEL;
  1.1489 -
  1.1490 -	if(recode && (surface->flags & SDL_PREALLOC) != SDL_PREALLOC
  1.1491 -	   && (surface->flags & SDL_HWSURFACE) != SDL_HWSURFACE) {
  1.1492 -	    if((surface->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) {
  1.1493 -		SDL_Rect full;
  1.1494 -		unsigned alpha_flag;
  1.1495 +    if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) {
  1.1496 +        surface->flags &= ~SDL_RLEACCEL;
  1.1497  
  1.1498 -		/* re-create the original surface */
  1.1499 -		surface->pixels = SDL_malloc(surface->h * surface->pitch);
  1.1500 -		if ( !surface->pixels ) {
  1.1501 -			/* Oh crap... */
  1.1502 -			surface->flags |= SDL_RLEACCEL;
  1.1503 -			return;
  1.1504 -		}
  1.1505 +        if (recode && !(surface->flags & SDL_PREALLOC)
  1.1506 +            && !(surface->flags & SDL_HWSURFACE)) {
  1.1507 +            if ((surface->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) {
  1.1508 +                SDL_Rect full;
  1.1509 +                unsigned alpha_flag;
  1.1510  
  1.1511 -		/* fill it with the background colour */
  1.1512 -		SDL_FillRect(surface, NULL, surface->format->colorkey);
  1.1513 +                /* re-create the original surface */
  1.1514 +                surface->pixels = SDL_malloc(surface->h * surface->pitch);
  1.1515 +                if (!surface->pixels) {
  1.1516 +                    /* Oh crap... */
  1.1517 +                    surface->flags |= SDL_RLEACCEL;
  1.1518 +                    return;
  1.1519 +                }
  1.1520  
  1.1521 -		/* now render the encoded surface */
  1.1522 -		full.x = full.y = 0;
  1.1523 -		full.w = surface->w;
  1.1524 -		full.h = surface->h;
  1.1525 -		alpha_flag = surface->flags & SDL_SRCALPHA;
  1.1526 -		surface->flags &= ~SDL_SRCALPHA; /* opaque blit */
  1.1527 -		SDL_RLEBlit(surface, &full, surface, &full);
  1.1528 -		surface->flags |= alpha_flag;
  1.1529 -	    } else {
  1.1530 -		if ( !UnRLEAlpha(surface) ) {
  1.1531 -		    /* Oh crap... */
  1.1532 -		    surface->flags |= SDL_RLEACCEL;
  1.1533 -		    return;
  1.1534 -		}
  1.1535 -	    }
  1.1536 -	}
  1.1537 +                /* fill it with the background colour */
  1.1538 +                SDL_FillRect(surface, NULL, surface->format->colorkey);
  1.1539  
  1.1540 -	if ( surface->map && surface->map->sw_data->aux_data ) {
  1.1541 -	    SDL_free(surface->map->sw_data->aux_data);
  1.1542 -	    surface->map->sw_data->aux_data = NULL;
  1.1543 -	}
  1.1544 +                /* now render the encoded surface */
  1.1545 +                full.x = full.y = 0;
  1.1546 +                full.w = surface->w;
  1.1547 +                full.h = surface->h;
  1.1548 +                alpha_flag = surface->flags & SDL_SRCALPHA;
  1.1549 +                surface->flags &= ~SDL_SRCALPHA;        /* opaque blit */
  1.1550 +                SDL_RLEBlit(surface, &full, surface, &full);
  1.1551 +                surface->flags |= alpha_flag;
  1.1552 +            } else {
  1.1553 +                if (!UnRLEAlpha(surface)) {
  1.1554 +                    /* Oh crap... */
  1.1555 +                    surface->flags |= SDL_RLEACCEL;
  1.1556 +                    return;
  1.1557 +                }
  1.1558 +            }
  1.1559 +        }
  1.1560 +
  1.1561 +        if (surface->map && surface->map->sw_data->aux_data) {
  1.1562 +            SDL_free(surface->map->sw_data->aux_data);
  1.1563 +            surface->map->sw_data->aux_data = NULL;
  1.1564 +        }
  1.1565      }
  1.1566  }
  1.1567  
  1.1568 -
  1.1569 +/* vi: set ts=4 sw=4 expandtab: */