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