diff src/video/SDL_RLEaccel.c @ 1895:c121d94672cb

SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 10 Jul 2006 21:04:37 +0000
parents 84de7511f79f
children 926294b2bb4e
line wrap: on
line diff
--- a/src/video/SDL_RLEaccel.c	Thu Jul 06 18:01:37 2006 +0000
+++ b/src/video/SDL_RLEaccel.c	Mon Jul 10 21:04:37 2006 +0000
@@ -545,7 +545,7 @@
     } while(0)
 
 #endif
-    
+
 /*
  * Special case: 50% alpha (alpha=128)
  * This is treated specially because it can be optimized very well, and
@@ -704,7 +704,7 @@
     } while(0)
 
 #else
-	
+
 #define CHOOSE_BLIT(blitter, alpha, fmt)				\
     do {								\
         if(alpha == 255) {						\
@@ -779,8 +779,9 @@
  * This takes care of the case when the surface is clipped on the left and/or
  * right. Top clipping has already been taken care of.
  */
-static void RLEClipBlit(int w, Uint8 *srcbuf, SDL_Surface *dst,
-			Uint8 *dstbuf, SDL_Rect *srcrect, unsigned alpha)
+static void
+RLEClipBlit(int w, Uint8 * srcbuf, SDL_Surface * dst,
+            Uint8 * dstbuf, SDL_Rect * srcrect, unsigned alpha)
 {
     SDL_PixelFormat *fmt = dst->format;
 
@@ -836,34 +837,35 @@
 
 
 /* blit a colorkeyed RLE surface */
-int SDL_RLEBlit(SDL_Surface *src, SDL_Rect *srcrect,
-		SDL_Surface *dst, SDL_Rect *dstrect)
+int
+SDL_RLEBlit(SDL_Surface * src, SDL_Rect * srcrect,
+            SDL_Surface * dst, SDL_Rect * dstrect)
 {
-	Uint8 *dstbuf;
-	Uint8 *srcbuf;
-	int x, y;
-	int w = src->w;
-	unsigned alpha;
+    Uint8 *dstbuf;
+    Uint8 *srcbuf;
+    int x, y;
+    int w = src->w;
+    unsigned alpha;
 
-	/* Lock the destination if necessary */
-	if ( SDL_MUSTLOCK(dst) ) {
-		if ( SDL_LockSurface(dst) < 0 ) {
-			return(-1);
-		}
-	}
+    /* Lock the destination if necessary */
+    if (SDL_MUSTLOCK(dst)) {
+        if (SDL_LockSurface(dst) < 0) {
+            return (-1);
+        }
+    }
 
-	/* Set up the source and destination pointers */
-	x = dstrect->x;
-	y = dstrect->y;
-	dstbuf = (Uint8 *)dst->pixels
-	         + y * dst->pitch + x * src->format->BytesPerPixel;
-	srcbuf = (Uint8 *)src->map->sw_data->aux_data;
+    /* Set up the source and destination pointers */
+    x = dstrect->x;
+    y = dstrect->y;
+    dstbuf = (Uint8 *) dst->pixels
+        + y * dst->pitch + x * src->format->BytesPerPixel;
+    srcbuf = (Uint8 *) src->map->sw_data->aux_data;
 
-	{
-	    /* skip lines at the top if neccessary */
-	    int vskip = srcrect->y;
-	    int ofs = 0;
-	    if(vskip) {
+    {
+        /* skip lines at the top if neccessary */
+        int vskip = srcrect->y;
+        int ofs = 0;
+        if (vskip) {
 
 #define RLESKIP(bpp, Type)			\
 		for(;;) {			\
@@ -883,25 +885,33 @@
 		    }				\
 		}
 
-		switch(src->format->BytesPerPixel) {
-		case 1: RLESKIP(1, Uint8); break;
-		case 2: RLESKIP(2, Uint8); break;
-		case 3: RLESKIP(3, Uint8); break;
-		case 4: RLESKIP(4, Uint16); break;
-		}
+            switch (src->format->BytesPerPixel) {
+            case 1:
+                RLESKIP(1, Uint8);
+                break;
+            case 2:
+                RLESKIP(2, Uint8);
+                break;
+            case 3:
+                RLESKIP(3, Uint8);
+                break;
+            case 4:
+                RLESKIP(4, Uint16);
+                break;
+            }
 
 #undef RLESKIP
 
-	    }
-	}
+        }
+    }
 
-	alpha = (src->flags & SDL_SRCALPHA) == SDL_SRCALPHA
-	        ? src->format->alpha : 255;
-	/* if left or right edge clipping needed, call clip blit */
-	if ( srcrect->x || srcrect->w != src->w ) {
-	    RLEClipBlit(w, srcbuf, dst, dstbuf, srcrect, alpha);
-	} else {
-	    SDL_PixelFormat *fmt = src->format;
+    alpha = (src->flags & SDL_SRCALPHA) == SDL_SRCALPHA
+        ? src->format->alpha : 255;
+    /* if left or right edge clipping needed, call clip blit */
+    if (srcrect->x || srcrect->w != src->w) {
+        RLEClipBlit(w, srcbuf, dst, dstbuf, srcrect, alpha);
+    } else {
+        SDL_PixelFormat *fmt = src->format;
 
 #define RLEBLIT(bpp, Type, do_blit)					      \
 	    do {							      \
@@ -927,17 +937,17 @@
 		}							      \
 	    } while(0)
 
-	    CHOOSE_BLIT(RLEBLIT, alpha, fmt);
+        CHOOSE_BLIT(RLEBLIT, alpha, fmt);
 
 #undef RLEBLIT
-	}
+    }
 
-done:
-	/* Unlock the destination if necessary */
-	if ( SDL_MUSTLOCK(dst) ) {
-		SDL_UnlockSurface(dst);
-	}
-	return(0);
+  done:
+    /* Unlock the destination if necessary */
+    if (SDL_MUSTLOCK(dst)) {
+        SDL_UnlockSurface(dst);
+    }
+    return (0);
 }
 
 #undef OPAQUE_BLIT
@@ -995,24 +1005,26 @@
 
 /* used to save the destination format in the encoding. Designed to be
    macro-compatible with SDL_PixelFormat but without the unneeded fields */
-typedef struct {
-	Uint8  BytesPerPixel;
-	Uint8  Rloss;
-	Uint8  Gloss;
-	Uint8  Bloss;
-	Uint8  Rshift;
-	Uint8  Gshift;
-	Uint8  Bshift;
-	Uint8  Ashift;
-	Uint32 Rmask;
-	Uint32 Gmask;
-	Uint32 Bmask;
-	Uint32 Amask;
+typedef struct
+{
+    Uint8 BytesPerPixel;
+    Uint8 Rloss;
+    Uint8 Gloss;
+    Uint8 Bloss;
+    Uint8 Rshift;
+    Uint8 Gshift;
+    Uint8 Bshift;
+    Uint8 Ashift;
+    Uint32 Rmask;
+    Uint32 Gmask;
+    Uint32 Bmask;
+    Uint32 Amask;
 } RLEDestFormat;
 
 /* blit a pixel-alpha RLE surface clipped at the right and/or left edges */
-static void RLEAlphaClipBlit(int w, Uint8 *srcbuf, SDL_Surface *dst,
-			     Uint8 *dstbuf, SDL_Rect *srcrect)
+static void
+RLEAlphaClipBlit(int w, Uint8 * srcbuf, SDL_Surface * dst,
+                 Uint8 * dstbuf, SDL_Rect * srcrect)
 {
     SDL_PixelFormat *df = dst->format;
     /*
@@ -1088,23 +1100,23 @@
 	} while(--linecount);						  \
     } while(0)
 
-    switch(df->BytesPerPixel) {
+    switch (df->BytesPerPixel) {
     case 2:
-	if(df->Gmask == 0x07e0 || df->Rmask == 0x07e0
-	   || df->Bmask == 0x07e0)
-	    RLEALPHACLIPBLIT(Uint16, Uint8, BLIT_TRANSL_565);
-	else
-	    RLEALPHACLIPBLIT(Uint16, Uint8, BLIT_TRANSL_555);
-	break;
+        if (df->Gmask == 0x07e0 || df->Rmask == 0x07e0 || df->Bmask == 0x07e0)
+            RLEALPHACLIPBLIT(Uint16, Uint8, BLIT_TRANSL_565);
+        else
+            RLEALPHACLIPBLIT(Uint16, Uint8, BLIT_TRANSL_555);
+        break;
     case 4:
-	RLEALPHACLIPBLIT(Uint32, Uint16, BLIT_TRANSL_888);
-	break;
+        RLEALPHACLIPBLIT(Uint32, Uint16, BLIT_TRANSL_888);
+        break;
     }
 }
 
 /* blit a pixel-alpha RLE surface */
-int SDL_RLEAlphaBlit(SDL_Surface *src, SDL_Rect *srcrect,
-		     SDL_Surface *dst, SDL_Rect *dstrect)
+int
+SDL_RLEAlphaBlit(SDL_Surface * src, SDL_Rect * srcrect,
+                 SDL_Surface * dst, SDL_Rect * dstrect)
 {
     int x, y;
     int w = src->w;
@@ -1112,84 +1124,88 @@
     SDL_PixelFormat *df = dst->format;
 
     /* Lock the destination if necessary */
-    if ( SDL_MUSTLOCK(dst) ) {
-	if ( SDL_LockSurface(dst) < 0 ) {
-	    return -1;
-	}
+    if (SDL_MUSTLOCK(dst)) {
+        if (SDL_LockSurface(dst) < 0) {
+            return -1;
+        }
     }
 
     x = dstrect->x;
     y = dstrect->y;
-    dstbuf = (Uint8 *)dst->pixels
-	     + y * dst->pitch + x * df->BytesPerPixel;
-    srcbuf = (Uint8 *)src->map->sw_data->aux_data + sizeof(RLEDestFormat);
+    dstbuf = (Uint8 *) dst->pixels + y * dst->pitch + x * df->BytesPerPixel;
+    srcbuf = (Uint8 *) src->map->sw_data->aux_data + sizeof(RLEDestFormat);
 
     {
-	/* skip lines at the top if necessary */
-	int vskip = srcrect->y;
-	if(vskip) {
-	    int ofs;
-	    if(df->BytesPerPixel == 2) {
-		/* the 16/32 interleaved format */
-		do {
-		    /* skip opaque line */
-		    ofs = 0;
-		    do {
-			int run;
-			ofs += srcbuf[0];
-			run = srcbuf[1];
-			srcbuf += 2;
-			if(run) {
-			    srcbuf += 2 * run;
-			    ofs += run;
-			} else if(!ofs)
-			    goto done;
-		    } while(ofs < w);
+        /* skip lines at the top if necessary */
+        int vskip = srcrect->y;
+        if (vskip) {
+            int ofs;
+            if (df->BytesPerPixel == 2) {
+                /* the 16/32 interleaved format */
+                do {
+                    /* skip opaque line */
+                    ofs = 0;
+                    do {
+                        int run;
+                        ofs += srcbuf[0];
+                        run = srcbuf[1];
+                        srcbuf += 2;
+                        if (run) {
+                            srcbuf += 2 * run;
+                            ofs += run;
+                        } else if (!ofs)
+                            goto done;
+                    }
+                    while (ofs < w);
 
-		    /* skip padding */
-		    srcbuf += (uintptr_t)srcbuf & 2;
+                    /* skip padding */
+                    srcbuf += (uintptr_t) srcbuf & 2;
 
-		    /* skip translucent line */
-		    ofs = 0;
-		    do {
-			int run;
-			ofs += ((Uint16 *)srcbuf)[0];
-			run = ((Uint16 *)srcbuf)[1];
-			srcbuf += 4 * (run + 1);
-			ofs += run;
-		    } while(ofs < w);
-		} while(--vskip);
-	    } else {
-		/* the 32/32 interleaved format */
-		vskip <<= 1;	/* opaque and translucent have same format */
-		do {
-		    ofs = 0;
-		    do {
-			int run;
-			ofs += ((Uint16 *)srcbuf)[0];
-			run = ((Uint16 *)srcbuf)[1];
-			srcbuf += 4;
-			if(run) {
-			    srcbuf += 4 * run;
-			    ofs += run;
-			} else if(!ofs)
-			    goto done;
-		    } while(ofs < w);
-		} while(--vskip);
-	    }
-	}
+                    /* skip translucent line */
+                    ofs = 0;
+                    do {
+                        int run;
+                        ofs += ((Uint16 *) srcbuf)[0];
+                        run = ((Uint16 *) srcbuf)[1];
+                        srcbuf += 4 * (run + 1);
+                        ofs += run;
+                    }
+                    while (ofs < w);
+                }
+                while (--vskip);
+            } else {
+                /* the 32/32 interleaved format */
+                vskip <<= 1;    /* opaque and translucent have same format */
+                do {
+                    ofs = 0;
+                    do {
+                        int run;
+                        ofs += ((Uint16 *) srcbuf)[0];
+                        run = ((Uint16 *) srcbuf)[1];
+                        srcbuf += 4;
+                        if (run) {
+                            srcbuf += 4 * run;
+                            ofs += run;
+                        } else if (!ofs)
+                            goto done;
+                    }
+                    while (ofs < w);
+                }
+                while (--vskip);
+            }
+        }
     }
 
     /* if left or right edge clipping needed, call clip blit */
-    if(srcrect->x || srcrect->w != src->w) {
-	RLEAlphaClipBlit(w, srcbuf, dst, dstbuf, srcrect);
+    if (srcrect->x || srcrect->w != src->w) {
+        RLEAlphaClipBlit(w, srcbuf, dst, dstbuf, srcrect);
     } else {
 
-	/*
-	 * non-clipped blitter. Ptype is the destination pixel type,
-	 * Ctype the translucent count type, and do_blend the
-	 * macro to blend one pixel.
-	 */
+        /*
+         * non-clipped blitter. Ptype is the destination pixel type,
+         * Ctype the translucent count type, and do_blend the
+         * macro to blend one pixel.
+         */
 #define RLEALPHABLIT(Ptype, Ctype, do_blend)				 \
 	do {								 \
 	    int linecount = srcrect->h;					 \
@@ -1235,24 +1251,24 @@
 	    } while(--linecount);					 \
 	} while(0)
 
-	switch(df->BytesPerPixel) {
-	case 2:
-	    if(df->Gmask == 0x07e0 || df->Rmask == 0x07e0
-	       || df->Bmask == 0x07e0)
-		RLEALPHABLIT(Uint16, Uint8, BLIT_TRANSL_565);
-	    else
-		RLEALPHABLIT(Uint16, Uint8, BLIT_TRANSL_555);
-	    break;
-	case 4:
-	    RLEALPHABLIT(Uint32, Uint16, BLIT_TRANSL_888);
-	    break;
-	}
+        switch (df->BytesPerPixel) {
+        case 2:
+            if (df->Gmask == 0x07e0 || df->Rmask == 0x07e0
+                || df->Bmask == 0x07e0)
+                RLEALPHABLIT(Uint16, Uint8, BLIT_TRANSL_565);
+            else
+                RLEALPHABLIT(Uint16, Uint8, BLIT_TRANSL_555);
+            break;
+        case 4:
+            RLEALPHABLIT(Uint32, Uint16, BLIT_TRANSL_888);
+            break;
+        }
     }
 
- done:
+  done:
     /* Unlock the destination if necessary */
-    if ( SDL_MUSTLOCK(dst) ) {
-	SDL_UnlockSurface(dst);
+    if (SDL_MUSTLOCK(dst)) {
+        SDL_UnlockSurface(dst);
     }
     return 0;
 }
@@ -1268,34 +1284,36 @@
  */
 
 /* encode 32bpp rgb + a into 16bpp rgb, losing alpha */
-static int copy_opaque_16(void *dst, Uint32 *src, int n,
-			  SDL_PixelFormat *sfmt, SDL_PixelFormat *dfmt)
+static int
+copy_opaque_16(void *dst, Uint32 * src, int n,
+               SDL_PixelFormat * sfmt, SDL_PixelFormat * dfmt)
 {
     int i;
     Uint16 *d = dst;
-    for(i = 0; i < n; i++) {
-	unsigned r, g, b;
-	RGB_FROM_PIXEL(*src, sfmt, r, g, b);
-	PIXEL_FROM_RGB(*d, dfmt, r, g, b);
-	src++;
-	d++;
+    for (i = 0; i < n; i++) {
+        unsigned r, g, b;
+        RGB_FROM_PIXEL(*src, sfmt, r, g, b);
+        PIXEL_FROM_RGB(*d, dfmt, r, g, b);
+        src++;
+        d++;
     }
     return n * 2;
 }
 
 /* decode opaque pixels from 16bpp to 32bpp rgb + a */
-static int uncopy_opaque_16(Uint32 *dst, void *src, int n,
-			    RLEDestFormat *sfmt, SDL_PixelFormat *dfmt)
+static int
+uncopy_opaque_16(Uint32 * dst, void *src, int n,
+                 RLEDestFormat * sfmt, SDL_PixelFormat * dfmt)
 {
     int i;
     Uint16 *s = src;
     unsigned alpha = dfmt->Amask ? 255 : 0;
-    for(i = 0; i < n; i++) {
-	unsigned r, g, b;
-	RGB_FROM_PIXEL(*s, sfmt, r, g, b);
-	PIXEL_FROM_RGBA(*dst, dfmt, r, g, b, alpha);
-	s++;
-	dst++;
+    for (i = 0; i < n; i++) {
+        unsigned r, g, b;
+        RGB_FROM_PIXEL(*s, sfmt, r, g, b);
+        PIXEL_FROM_RGBA(*dst, dfmt, r, g, b, alpha);
+        s++;
+        dst++;
     }
     return n * 2;
 }
@@ -1303,89 +1321,94 @@
 
 
 /* encode 32bpp rgb + a into 32bpp G0RAB format for blitting into 565 */
-static int copy_transl_565(void *dst, Uint32 *src, int n,
-			   SDL_PixelFormat *sfmt, SDL_PixelFormat *dfmt)
+static int
+copy_transl_565(void *dst, Uint32 * src, int n,
+                SDL_PixelFormat * sfmt, SDL_PixelFormat * dfmt)
 {
     int i;
     Uint32 *d = dst;
-    for(i = 0; i < n; i++) {
-	unsigned r, g, b, a;
-	Uint16 pix;
-	RGBA_FROM_8888(*src, sfmt, r, g, b, a);
-	PIXEL_FROM_RGB(pix, dfmt, r, g, b);
-	*d = ((pix & 0x7e0) << 16) | (pix & 0xf81f) | ((a << 2) & 0x7e0);
-	src++;
-	d++;
+    for (i = 0; i < n; i++) {
+        unsigned r, g, b, a;
+        Uint16 pix;
+        RGBA_FROM_8888(*src, sfmt, r, g, b, a);
+        PIXEL_FROM_RGB(pix, dfmt, r, g, b);
+        *d = ((pix & 0x7e0) << 16) | (pix & 0xf81f) | ((a << 2) & 0x7e0);
+        src++;
+        d++;
     }
     return n * 4;
 }
 
 /* encode 32bpp rgb + a into 32bpp G0RAB format for blitting into 555 */
-static int copy_transl_555(void *dst, Uint32 *src, int n,
-			   SDL_PixelFormat *sfmt, SDL_PixelFormat *dfmt)
+static int
+copy_transl_555(void *dst, Uint32 * src, int n,
+                SDL_PixelFormat * sfmt, SDL_PixelFormat * dfmt)
 {
     int i;
     Uint32 *d = dst;
-    for(i = 0; i < n; i++) {
-	unsigned r, g, b, a;
-	Uint16 pix;
-	RGBA_FROM_8888(*src, sfmt, r, g, b, a);
-	PIXEL_FROM_RGB(pix, dfmt, r, g, b);
-	*d = ((pix & 0x3e0) << 16) | (pix & 0xfc1f) | ((a << 2) & 0x3e0);
-	src++;
-	d++;
+    for (i = 0; i < n; i++) {
+        unsigned r, g, b, a;
+        Uint16 pix;
+        RGBA_FROM_8888(*src, sfmt, r, g, b, a);
+        PIXEL_FROM_RGB(pix, dfmt, r, g, b);
+        *d = ((pix & 0x3e0) << 16) | (pix & 0xfc1f) | ((a << 2) & 0x3e0);
+        src++;
+        d++;
     }
     return n * 4;
 }
 
 /* decode translucent pixels from 32bpp GORAB to 32bpp rgb + a */
-static int uncopy_transl_16(Uint32 *dst, void *src, int n,
-			    RLEDestFormat *sfmt, SDL_PixelFormat *dfmt)
+static int
+uncopy_transl_16(Uint32 * dst, void *src, int n,
+                 RLEDestFormat * sfmt, SDL_PixelFormat * dfmt)
 {
     int i;
     Uint32 *s = src;
-    for(i = 0; i < n; i++) {
-	unsigned r, g, b, a;
-	Uint32 pix = *s++;
-	a = (pix & 0x3e0) >> 2;
-	pix = (pix & ~0x3e0) | pix >> 16;
-	RGB_FROM_PIXEL(pix, sfmt, r, g, b);
-	PIXEL_FROM_RGBA(*dst, dfmt, r, g, b, a);
-	dst++;
+    for (i = 0; i < n; i++) {
+        unsigned r, g, b, a;
+        Uint32 pix = *s++;
+        a = (pix & 0x3e0) >> 2;
+        pix = (pix & ~0x3e0) | pix >> 16;
+        RGB_FROM_PIXEL(pix, sfmt, r, g, b);
+        PIXEL_FROM_RGBA(*dst, dfmt, r, g, b, a);
+        dst++;
     }
     return n * 4;
 }
 
 /* encode 32bpp rgba into 32bpp rgba, keeping alpha (dual purpose) */
-static int copy_32(void *dst, Uint32 *src, int n,
-		   SDL_PixelFormat *sfmt, SDL_PixelFormat *dfmt)
+static int
+copy_32(void *dst, Uint32 * src, int n,
+        SDL_PixelFormat * sfmt, SDL_PixelFormat * dfmt)
 {
     int i;
     Uint32 *d = dst;
-    for(i = 0; i < n; i++) {
-	unsigned r, g, b, a;
-	Uint32 pixel;
-	RGBA_FROM_8888(*src, sfmt, r, g, b, a);
-	PIXEL_FROM_RGB(pixel, dfmt, r, g, b);
-	*d++ = pixel | a << 24;
-	src++;
+    for (i = 0; i < n; i++) {
+        unsigned r, g, b, a;
+        Uint32 pixel;
+        RGBA_FROM_8888(*src, sfmt, r, g, b, a);
+        PIXEL_FROM_RGB(pixel, dfmt, r, g, b);
+        *d++ = pixel | a << 24;
+        src++;
     }
     return n * 4;
 }
 
 /* decode 32bpp rgba into 32bpp rgba, keeping alpha (dual purpose) */
-static int uncopy_32(Uint32 *dst, void *src, int n,
-		     RLEDestFormat *sfmt, SDL_PixelFormat *dfmt)
+static int
+uncopy_32(Uint32 * dst, void *src, int n,
+          RLEDestFormat * sfmt, SDL_PixelFormat * dfmt)
 {
     int i;
     Uint32 *s = src;
-    for(i = 0; i < n; i++) {
-	unsigned r, g, b, a;
-	Uint32 pixel = *s++;
-	RGB_FROM_PIXEL(pixel, sfmt, r, g, b);
-	a = pixel >> 24;
-	PIXEL_FROM_RGBA(*dst, dfmt, r, g, b, a);
-	dst++;
+    for (i = 0; i < n; i++) {
+        unsigned r, g, b, a;
+        Uint32 pixel = *s++;
+        RGB_FROM_PIXEL(pixel, sfmt, r, g, b);
+        a = pixel >> 24;
+        PIXEL_FROM_RGBA(*dst, dfmt, r, g, b, a);
+        dst++;
     }
     return n * 4;
 }
@@ -1396,7 +1419,8 @@
     ((unsigned)((((pixel) & fmt->Amask) >> fmt->Ashift) - 1U) < 254U)
 
 /* convert surface to be quickly alpha-blittable onto dest, if possible */
-static int RLEAlphaSurface(SDL_Surface *surface)
+static int
+RLEAlphaSurface(SDL_Surface * surface)
 {
     SDL_Surface *dest;
     SDL_PixelFormat *df;
@@ -1405,97 +1429,97 @@
     int max_transl_run = 65535;
     unsigned masksum;
     Uint8 *rlebuf, *dst;
-    int (*copy_opaque)(void *, Uint32 *, int,
-		       SDL_PixelFormat *, SDL_PixelFormat *);
-    int (*copy_transl)(void *, Uint32 *, int,
-		       SDL_PixelFormat *, SDL_PixelFormat *);
+    int (*copy_opaque) (void *, Uint32 *, int,
+                        SDL_PixelFormat *, SDL_PixelFormat *);
+    int (*copy_transl) (void *, Uint32 *, int,
+                        SDL_PixelFormat *, SDL_PixelFormat *);
 
     dest = surface->map->dst;
-    if(!dest)
-	return -1;
+    if (!dest)
+        return -1;
     df = dest->format;
-    if(surface->format->BitsPerPixel != 32)
-	return -1;		/* only 32bpp source supported */
+    if (surface->format->BitsPerPixel != 32)
+        return -1;              /* only 32bpp source supported */
 
     /* find out whether the destination is one we support,
        and determine the max size of the encoded result */
     masksum = df->Rmask | df->Gmask | df->Bmask;
-    switch(df->BytesPerPixel) {
+    switch (df->BytesPerPixel) {
     case 2:
-	/* 16bpp: only support 565 and 555 formats */
-	switch(masksum) {
-	case 0xffff:
-	    if(df->Gmask == 0x07e0
-	       || df->Rmask == 0x07e0 || df->Bmask == 0x07e0) {
-		copy_opaque = copy_opaque_16;
-		copy_transl = copy_transl_565;
-	    } else
-		return -1;
-	    break;
-	case 0x7fff:
-	    if(df->Gmask == 0x03e0
-	       || df->Rmask == 0x03e0 || df->Bmask == 0x03e0) {
-		copy_opaque = copy_opaque_16;
-		copy_transl = copy_transl_555;
-	    } else
-		return -1;
-	    break;
-	default:
-	    return -1;
-	}
-	max_opaque_run = 255;	/* runs stored as bytes */
+        /* 16bpp: only support 565 and 555 formats */
+        switch (masksum) {
+        case 0xffff:
+            if (df->Gmask == 0x07e0
+                || df->Rmask == 0x07e0 || df->Bmask == 0x07e0) {
+                copy_opaque = copy_opaque_16;
+                copy_transl = copy_transl_565;
+            } else
+                return -1;
+            break;
+        case 0x7fff:
+            if (df->Gmask == 0x03e0
+                || df->Rmask == 0x03e0 || df->Bmask == 0x03e0) {
+                copy_opaque = copy_opaque_16;
+                copy_transl = copy_transl_555;
+            } else
+                return -1;
+            break;
+        default:
+            return -1;
+        }
+        max_opaque_run = 255;   /* runs stored as bytes */
 
-	/* worst case is alternating opaque and translucent pixels,
-	   with room for alignment padding between lines */
-	maxsize = surface->h * (2 + (4 + 2) * (surface->w + 1)) + 2;
-	break;
+        /* worst case is alternating opaque and translucent pixels,
+           with room for alignment padding between lines */
+        maxsize = surface->h * (2 + (4 + 2) * (surface->w + 1)) + 2;
+        break;
     case 4:
-	if(masksum != 0x00ffffff)
-	    return -1;		/* requires unused high byte */
-	copy_opaque = copy_32;
-	copy_transl = copy_32;
-	max_opaque_run = 255;	/* runs stored as short ints */
+        if (masksum != 0x00ffffff)
+            return -1;          /* requires unused high byte */
+        copy_opaque = copy_32;
+        copy_transl = copy_32;
+        max_opaque_run = 255;   /* runs stored as short ints */
 
-	/* worst case is alternating opaque and translucent pixels */
-	maxsize = surface->h * 2 * 4 * (surface->w + 1) + 4;
-	break;
+        /* worst case is alternating opaque and translucent pixels */
+        maxsize = surface->h * 2 * 4 * (surface->w + 1) + 4;
+        break;
     default:
-	return -1;		/* anything else unsupported right now */
+        return -1;              /* anything else unsupported right now */
     }
 
     maxsize += sizeof(RLEDestFormat);
-    rlebuf = (Uint8 *)SDL_malloc(maxsize);
-    if(!rlebuf) {
-	SDL_OutOfMemory();
-	return -1;
+    rlebuf = (Uint8 *) SDL_malloc(maxsize);
+    if (!rlebuf) {
+        SDL_OutOfMemory();
+        return -1;
     }
     {
-	/* save the destination format so we can undo the encoding later */
-	RLEDestFormat *r = (RLEDestFormat *)rlebuf;
-	r->BytesPerPixel = df->BytesPerPixel;
-	r->Rloss = df->Rloss;
-	r->Gloss = df->Gloss;
-	r->Bloss = df->Bloss;
-	r->Rshift = df->Rshift;
-	r->Gshift = df->Gshift;
-	r->Bshift = df->Bshift;
-	r->Ashift = df->Ashift;
-	r->Rmask = df->Rmask;
-	r->Gmask = df->Gmask;
-	r->Bmask = df->Bmask;
-	r->Amask = df->Amask;
+        /* save the destination format so we can undo the encoding later */
+        RLEDestFormat *r = (RLEDestFormat *) rlebuf;
+        r->BytesPerPixel = df->BytesPerPixel;
+        r->Rloss = df->Rloss;
+        r->Gloss = df->Gloss;
+        r->Bloss = df->Bloss;
+        r->Rshift = df->Rshift;
+        r->Gshift = df->Gshift;
+        r->Bshift = df->Bshift;
+        r->Ashift = df->Ashift;
+        r->Rmask = df->Rmask;
+        r->Gmask = df->Gmask;
+        r->Bmask = df->Bmask;
+        r->Amask = df->Amask;
     }
     dst = rlebuf + sizeof(RLEDestFormat);
 
     /* Do the actual encoding */
     {
-	int x, y;
-	int h = surface->h, w = surface->w;
-	SDL_PixelFormat *sf = surface->format;
-	Uint32 *src = (Uint32 *)surface->pixels;
-	Uint8 *lastline = dst;	/* end of last non-blank line */
+        int x, y;
+        int h = surface->h, w = surface->w;
+        SDL_PixelFormat *sf = surface->format;
+        Uint32 *src = (Uint32 *) surface->pixels;
+        Uint8 *lastline = dst;  /* end of last non-blank line */
 
-	/* opaque counts are 8 or 16 bits, depending on target depth */
+        /* opaque counts are 8 or 16 bits, depending on target depth */
 #define ADD_OPAQUE_COUNTS(n, m)			\
 	if(df->BytesPerPixel == 4) {		\
 	    ((Uint16 *)dst)[0] = n;		\
@@ -1507,119 +1531,123 @@
 	    dst += 2;				\
 	}
 
-	/* translucent counts are always 16 bit */
+        /* translucent counts are always 16 bit */
 #define ADD_TRANSL_COUNTS(n, m)		\
 	(((Uint16 *)dst)[0] = n, ((Uint16 *)dst)[1] = m, dst += 4)
 
-	for(y = 0; y < h; y++) {
-	    int runstart, skipstart;
-	    int blankline = 0;
-	    /* First encode all opaque pixels of a scan line */
-	    x = 0;
-	    do {
-		int run, skip, len;
-		skipstart = x;
-		while(x < w && !ISOPAQUE(src[x], sf))
-		    x++;
-		runstart = x;
-		while(x < w && ISOPAQUE(src[x], sf))
-		    x++;
-		skip = runstart - skipstart;
-		if(skip == w)
-		    blankline = 1;
-		run = x - runstart;
-		while(skip > max_opaque_run) {
-		    ADD_OPAQUE_COUNTS(max_opaque_run, 0);
-		    skip -= max_opaque_run;
-		}
-		len = MIN(run, max_opaque_run);
-		ADD_OPAQUE_COUNTS(skip, len);
-		dst += copy_opaque(dst, src + runstart, len, sf, df);
-		runstart += len;
-		run -= len;
-		while(run) {
-		    len = MIN(run, max_opaque_run);
-		    ADD_OPAQUE_COUNTS(0, len);
-		    dst += copy_opaque(dst, src + runstart, len, sf, df);
-		    runstart += len;
-		    run -= len;
-		}
-	    } while(x < w);
+        for (y = 0; y < h; y++) {
+            int runstart, skipstart;
+            int blankline = 0;
+            /* First encode all opaque pixels of a scan line */
+            x = 0;
+            do {
+                int run, skip, len;
+                skipstart = x;
+                while (x < w && !ISOPAQUE(src[x], sf))
+                    x++;
+                runstart = x;
+                while (x < w && ISOPAQUE(src[x], sf))
+                    x++;
+                skip = runstart - skipstart;
+                if (skip == w)
+                    blankline = 1;
+                run = x - runstart;
+                while (skip > max_opaque_run) {
+                    ADD_OPAQUE_COUNTS(max_opaque_run, 0);
+                    skip -= max_opaque_run;
+                }
+                len = MIN(run, max_opaque_run);
+                ADD_OPAQUE_COUNTS(skip, len);
+                dst += copy_opaque(dst, src + runstart, len, sf, df);
+                runstart += len;
+                run -= len;
+                while (run) {
+                    len = MIN(run, max_opaque_run);
+                    ADD_OPAQUE_COUNTS(0, len);
+                    dst += copy_opaque(dst, src + runstart, len, sf, df);
+                    runstart += len;
+                    run -= len;
+                }
+            }
+            while (x < w);
 
-	    /* Make sure the next output address is 32-bit aligned */
-	    dst += (uintptr_t)dst & 2;
+            /* Make sure the next output address is 32-bit aligned */
+            dst += (uintptr_t) dst & 2;
 
-	    /* Next, encode all translucent pixels of the same scan line */
-	    x = 0;
-	    do {
-		int run, skip, len;
-		skipstart = x;
-		while(x < w && !ISTRANSL(src[x], sf))
-		    x++;
-		runstart = x;
-		while(x < w && ISTRANSL(src[x], sf))
-		    x++;
-		skip = runstart - skipstart;
-		blankline &= (skip == w);
-		run = x - runstart;
-		while(skip > max_transl_run) {
-		    ADD_TRANSL_COUNTS(max_transl_run, 0);
-		    skip -= max_transl_run;
-		}
-		len = MIN(run, max_transl_run);
-		ADD_TRANSL_COUNTS(skip, len);
-		dst += copy_transl(dst, src + runstart, len, sf, df);
-		runstart += len;
-		run -= len;
-		while(run) {
-		    len = MIN(run, max_transl_run);
-		    ADD_TRANSL_COUNTS(0, len);
-		    dst += copy_transl(dst, src + runstart, len, sf, df);
-		    runstart += len;
-		    run -= len;
-		}
-		if(!blankline)
-		    lastline = dst;
-	    } while(x < w);
+            /* Next, encode all translucent pixels of the same scan line */
+            x = 0;
+            do {
+                int run, skip, len;
+                skipstart = x;
+                while (x < w && !ISTRANSL(src[x], sf))
+                    x++;
+                runstart = x;
+                while (x < w && ISTRANSL(src[x], sf))
+                    x++;
+                skip = runstart - skipstart;
+                blankline &= (skip == w);
+                run = x - runstart;
+                while (skip > max_transl_run) {
+                    ADD_TRANSL_COUNTS(max_transl_run, 0);
+                    skip -= max_transl_run;
+                }
+                len = MIN(run, max_transl_run);
+                ADD_TRANSL_COUNTS(skip, len);
+                dst += copy_transl(dst, src + runstart, len, sf, df);
+                runstart += len;
+                run -= len;
+                while (run) {
+                    len = MIN(run, max_transl_run);
+                    ADD_TRANSL_COUNTS(0, len);
+                    dst += copy_transl(dst, src + runstart, len, sf, df);
+                    runstart += len;
+                    run -= len;
+                }
+                if (!blankline)
+                    lastline = dst;
+            }
+            while (x < w);
 
-	    src += surface->pitch >> 2;
-	}
-	dst = lastline;		/* back up past trailing blank lines */
-	ADD_OPAQUE_COUNTS(0, 0);
+            src += surface->pitch >> 2;
+        }
+        dst = lastline;         /* back up past trailing blank lines */
+        ADD_OPAQUE_COUNTS(0, 0);
     }
 
 #undef ADD_OPAQUE_COUNTS
 #undef ADD_TRANSL_COUNTS
 
     /* Now that we have it encoded, release the original pixels */
-    if((surface->flags & SDL_PREALLOC) != SDL_PREALLOC
-       && (surface->flags & SDL_HWSURFACE) != SDL_HWSURFACE) {
-	SDL_free( surface->pixels );
-	surface->pixels = NULL;
+    if (!(surface->flags & SDL_PREALLOC) && !(surface->flags & SDL_HWSURFACE)) {
+        SDL_free(surface->pixels);
+        surface->pixels = NULL;
     }
 
     /* realloc the buffer to release unused memory */
     {
-	Uint8 *p = SDL_realloc(rlebuf, dst - rlebuf);
-	if(!p)
-	    p = rlebuf;
-	surface->map->sw_data->aux_data = p;
+        Uint8 *p = SDL_realloc(rlebuf, dst - rlebuf);
+        if (!p)
+            p = rlebuf;
+        surface->map->sw_data->aux_data = p;
     }
 
     return 0;
 }
 
-static Uint32 getpix_8(Uint8 *srcbuf)
+static Uint32
+getpix_8(Uint8 * srcbuf)
 {
     return *srcbuf;
 }
 
-static Uint32 getpix_16(Uint8 *srcbuf)
+static Uint32
+getpix_16(Uint8 * srcbuf)
 {
-    return *(Uint16 *)srcbuf;
+    return *(Uint16 *) srcbuf;
 }
 
-static Uint32 getpix_24(Uint8 *srcbuf)
+static Uint32
+getpix_24(Uint8 * srcbuf)
 {
 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
     return srcbuf[0] + (srcbuf[1] << 8) + (srcbuf[2] << 16);
@@ -1628,68 +1656,70 @@
 #endif
 }
 
-static Uint32 getpix_32(Uint8 *srcbuf)
+static Uint32
+getpix_32(Uint8 * srcbuf)
 {
-    return *(Uint32 *)srcbuf;
+    return *(Uint32 *) srcbuf;
 }
 
-typedef Uint32 (*getpix_func)(Uint8 *);
+typedef Uint32(*getpix_func) (Uint8 *);
 
 static getpix_func getpixes[4] = {
     getpix_8, getpix_16, getpix_24, getpix_32
 };
 
-static int RLEColorkeySurface(SDL_Surface *surface)
+static int
+RLEColorkeySurface(SDL_Surface * surface)
 {
-        Uint8 *rlebuf, *dst;
-	int maxn;
-	int y;
-	Uint8 *srcbuf, *curbuf, *lastline;
-	int maxsize = 0;
-	int skip, run;
-	int bpp = surface->format->BytesPerPixel;
-	getpix_func getpix;
-	Uint32 ckey, rgbmask;
-	int w, h;
+    Uint8 *rlebuf, *dst;
+    int maxn;
+    int y;
+    Uint8 *srcbuf, *curbuf, *lastline;
+    int maxsize = 0;
+    int skip, run;
+    int bpp = surface->format->BytesPerPixel;
+    getpix_func getpix;
+    Uint32 ckey, rgbmask;
+    int w, h;
 
-	/* calculate the worst case size for the compressed surface */
-	switch(bpp) {
-	case 1:
-	    /* worst case is alternating opaque and transparent pixels,
-	       starting with an opaque pixel */
-	    maxsize = surface->h * 3 * (surface->w / 2 + 1) + 2;
-	    break;
-	case 2:
-	case 3:
-	    /* worst case is solid runs, at most 255 pixels wide */
-	    maxsize = surface->h * (2 * (surface->w / 255 + 1)
-				    + surface->w * bpp) + 2;
-	    break;
-	case 4:
-	    /* worst case is solid runs, at most 65535 pixels wide */
-	    maxsize = surface->h * (4 * (surface->w / 65535 + 1)
-				    + surface->w * 4) + 4;
-	    break;
-	}
+    /* calculate the worst case size for the compressed surface */
+    switch (bpp) {
+    case 1:
+        /* worst case is alternating opaque and transparent pixels,
+           starting with an opaque pixel */
+        maxsize = surface->h * 3 * (surface->w / 2 + 1) + 2;
+        break;
+    case 2:
+    case 3:
+        /* worst case is solid runs, at most 255 pixels wide */
+        maxsize = surface->h * (2 * (surface->w / 255 + 1)
+                                + surface->w * bpp) + 2;
+        break;
+    case 4:
+        /* worst case is solid runs, at most 65535 pixels wide */
+        maxsize = surface->h * (4 * (surface->w / 65535 + 1)
+                                + surface->w * 4) + 4;
+        break;
+    }
 
-	rlebuf = (Uint8 *)SDL_malloc(maxsize);
-	if ( rlebuf == NULL ) {
-		SDL_OutOfMemory();
-		return(-1);
-	}
+    rlebuf = (Uint8 *) SDL_malloc(maxsize);
+    if (rlebuf == NULL) {
+        SDL_OutOfMemory();
+        return (-1);
+    }
 
-	/* Set up the conversion */
-	srcbuf = (Uint8 *)surface->pixels;
-	curbuf = srcbuf;
-	maxn = bpp == 4 ? 65535 : 255;
-	skip = run = 0;
-	dst = rlebuf;
-	rgbmask = ~surface->format->Amask;
-	ckey = surface->format->colorkey & rgbmask;
-	lastline = dst;
-	getpix = getpixes[bpp - 1];
-	w = surface->w;
-	h = surface->h;
+    /* Set up the conversion */
+    srcbuf = (Uint8 *) surface->pixels;
+    curbuf = srcbuf;
+    maxn = bpp == 4 ? 65535 : 255;
+    skip = run = 0;
+    dst = rlebuf;
+    rgbmask = ~surface->format->Amask;
+    ckey = surface->format->colorkey & rgbmask;
+    lastline = dst;
+    getpix = getpixes[bpp - 1];
+    w = surface->w;
+    h = surface->h;
 
 #define ADD_COUNTS(n, m)			\
 	if(bpp == 4) {				\
@@ -1702,118 +1732,119 @@
 	    dst += 2;				\
 	}
 
-	for(y = 0; y < h; y++) {
-	    int x = 0;
-	    int blankline = 0;
-	    do {
-		int run, skip, len;
-		int runstart;
-		int skipstart = x;
+    for (y = 0; y < h; y++) {
+        int x = 0;
+        int blankline = 0;
+        do {
+            int run, skip, len;
+            int runstart;
+            int skipstart = x;
 
-		/* find run of transparent, then opaque pixels */
-		while(x < w && (getpix(srcbuf + x * bpp) & rgbmask) == ckey)
-		    x++;
-		runstart = x;
-		while(x < w && (getpix(srcbuf + x * bpp) & rgbmask) != ckey)
-		    x++;
-		skip = runstart - skipstart;
-		if(skip == w)
-		    blankline = 1;
-		run = x - runstart;
+            /* find run of transparent, then opaque pixels */
+            while (x < w && (getpix(srcbuf + x * bpp) & rgbmask) == ckey)
+                x++;
+            runstart = x;
+            while (x < w && (getpix(srcbuf + x * bpp) & rgbmask) != ckey)
+                x++;
+            skip = runstart - skipstart;
+            if (skip == w)
+                blankline = 1;
+            run = x - runstart;
 
-		/* encode segment */
-		while(skip > maxn) {
-		    ADD_COUNTS(maxn, 0);
-		    skip -= maxn;
-		}
-		len = MIN(run, maxn);
-		ADD_COUNTS(skip, len);
-		SDL_memcpy(dst, srcbuf + runstart * bpp, len * bpp);
-		dst += len * bpp;
-		run -= len;
-		runstart += len;
-		while(run) {
-		    len = MIN(run, maxn);
-		    ADD_COUNTS(0, len);
-		    SDL_memcpy(dst, srcbuf + runstart * bpp, len * bpp);
-		    dst += len * bpp;
-		    runstart += len;
-		    run -= len;
-		}
-		if(!blankline)
-		    lastline = dst;
-	    } while(x < w);
+            /* encode segment */
+            while (skip > maxn) {
+                ADD_COUNTS(maxn, 0);
+                skip -= maxn;
+            }
+            len = MIN(run, maxn);
+            ADD_COUNTS(skip, len);
+            SDL_memcpy(dst, srcbuf + runstart * bpp, len * bpp);
+            dst += len * bpp;
+            run -= len;
+            runstart += len;
+            while (run) {
+                len = MIN(run, maxn);
+                ADD_COUNTS(0, len);
+                SDL_memcpy(dst, srcbuf + runstart * bpp, len * bpp);
+                dst += len * bpp;
+                runstart += len;
+                run -= len;
+            }
+            if (!blankline)
+                lastline = dst;
+        }
+        while (x < w);
 
-	    srcbuf += surface->pitch;
-	}
-	dst = lastline;		/* back up bast trailing blank lines */
-	ADD_COUNTS(0, 0);
+        srcbuf += surface->pitch;
+    }
+    dst = lastline;             /* back up bast trailing blank lines */
+    ADD_COUNTS(0, 0);
 
 #undef ADD_COUNTS
 
-	/* Now that we have it encoded, release the original pixels */
-	if((surface->flags & SDL_PREALLOC) != SDL_PREALLOC
-	   && (surface->flags & SDL_HWSURFACE) != SDL_HWSURFACE) {
-	    SDL_free( surface->pixels );
-	    surface->pixels = NULL;
-	}
+    /* Now that we have it encoded, release the original pixels */
+    if (!(surface->flags & SDL_PREALLOC) && !(surface->flags & SDL_HWSURFACE)) {
+        SDL_free(surface->pixels);
+        surface->pixels = NULL;
+    }
 
-	/* realloc the buffer to release unused memory */
-	{
-	    /* If realloc returns NULL, the original block is left intact */
-	    Uint8 *p = SDL_realloc(rlebuf, dst - rlebuf);
-	    if(!p)
-		p = rlebuf;
-	    surface->map->sw_data->aux_data = p;
-	}
+    /* realloc the buffer to release unused memory */
+    {
+        /* If realloc returns NULL, the original block is left intact */
+        Uint8 *p = SDL_realloc(rlebuf, dst - rlebuf);
+        if (!p)
+            p = rlebuf;
+        surface->map->sw_data->aux_data = p;
+    }
 
-	return(0);
+    return (0);
 }
 
-int SDL_RLESurface(SDL_Surface *surface)
+int
+SDL_RLESurface(SDL_Surface * surface)
 {
-	int retcode;
+    int retcode;
 
-	/* Clear any previous RLE conversion */
-	if ( (surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL ) {
-		SDL_UnRLESurface(surface, 1);
-	}
+    /* Clear any previous RLE conversion */
+    if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) {
+        SDL_UnRLESurface(surface, 1);
+    }
 
-	/* We don't support RLE encoding of bitmaps */
-	if ( surface->format->BitsPerPixel < 8 ) {
-		return(-1);
-	}
+    /* We don't support RLE encoding of bitmaps */
+    if (surface->format->BitsPerPixel < 8) {
+        return (-1);
+    }
 
-	/* Lock the surface if it's in hardware */
-	if ( SDL_MUSTLOCK(surface) ) {
-		if ( SDL_LockSurface(surface) < 0 ) {
-			return(-1);
-		}
-	}
+    /* Lock the surface if it's in hardware */
+    if (SDL_MUSTLOCK(surface)) {
+        if (SDL_LockSurface(surface) < 0) {
+            return (-1);
+        }
+    }
 
-	/* Encode */
-	if((surface->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) {
-	    retcode = RLEColorkeySurface(surface);
-	} else {
-	    if((surface->flags & SDL_SRCALPHA) == SDL_SRCALPHA
-	       && surface->format->Amask != 0)
-		retcode = RLEAlphaSurface(surface);
-	    else
-		retcode = -1;	/* no RLE for per-surface alpha sans ckey */
-	}
+    /* Encode */
+    if ((surface->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) {
+        retcode = RLEColorkeySurface(surface);
+    } else {
+        if ((surface->flags & SDL_SRCALPHA) == SDL_SRCALPHA
+            && surface->format->Amask != 0)
+            retcode = RLEAlphaSurface(surface);
+        else
+            retcode = -1;       /* no RLE for per-surface alpha sans ckey */
+    }
 
-	/* Unlock the surface if it's in hardware */
-	if ( SDL_MUSTLOCK(surface) ) {
-		SDL_UnlockSurface(surface);
-	}
+    /* Unlock the surface if it's in hardware */
+    if (SDL_MUSTLOCK(surface)) {
+        SDL_UnlockSurface(surface);
+    }
 
-	if(retcode < 0)
-	    return -1;
+    if (retcode < 0)
+        return -1;
 
-	/* The surface is now accelerated */
-	surface->flags |= SDL_RLEACCEL;
+    /* The surface is now accelerated */
+    surface->flags |= SDL_RLEACCEL;
 
-	return(0);
+    return (0);
 }
 
 /*
@@ -1822,122 +1853,126 @@
  * completely transparent pixels will be lost, and colour and alpha depth
  * may have been reduced (when encoding for 16bpp targets).
  */
-static SDL_bool UnRLEAlpha(SDL_Surface *surface)
+static SDL_bool
+UnRLEAlpha(SDL_Surface * surface)
 {
     Uint8 *srcbuf;
     Uint32 *dst;
     SDL_PixelFormat *sf = surface->format;
     RLEDestFormat *df = surface->map->sw_data->aux_data;
-    int (*uncopy_opaque)(Uint32 *, void *, int,
-			 RLEDestFormat *, SDL_PixelFormat *);
-    int (*uncopy_transl)(Uint32 *, void *, int,
-			 RLEDestFormat *, SDL_PixelFormat *);
+    int (*uncopy_opaque) (Uint32 *, void *, int,
+                          RLEDestFormat *, SDL_PixelFormat *);
+    int (*uncopy_transl) (Uint32 *, void *, int,
+                          RLEDestFormat *, SDL_PixelFormat *);
     int w = surface->w;
     int bpp = df->BytesPerPixel;
 
-    if(bpp == 2) {
-	uncopy_opaque = uncopy_opaque_16;
-	uncopy_transl = uncopy_transl_16;
+    if (bpp == 2) {
+        uncopy_opaque = uncopy_opaque_16;
+        uncopy_transl = uncopy_transl_16;
     } else {
-	uncopy_opaque = uncopy_transl = uncopy_32;
+        uncopy_opaque = uncopy_transl = uncopy_32;
     }
 
     surface->pixels = SDL_malloc(surface->h * surface->pitch);
-    if ( !surface->pixels ) {
-        return(SDL_FALSE);
+    if (!surface->pixels) {
+        return (SDL_FALSE);
     }
     /* fill background with transparent pixels */
     SDL_memset(surface->pixels, 0, surface->h * surface->pitch);
 
     dst = surface->pixels;
-    srcbuf = (Uint8 *)(df + 1);
-    for(;;) {
-	/* copy opaque pixels */
-	int ofs = 0;
-	do {
-	    unsigned run;
-	    if(bpp == 2) {
-		ofs += srcbuf[0];
-		run = srcbuf[1];
-		srcbuf += 2;
-	    } else {
-		ofs += ((Uint16 *)srcbuf)[0];
-		run = ((Uint16 *)srcbuf)[1];
-		srcbuf += 4;
-	    }
-	    if(run) {
-		srcbuf += uncopy_opaque(dst + ofs, srcbuf, run, df, sf);
-		ofs += run;
-	    } else if(!ofs)
-		return(SDL_TRUE);
-	} while(ofs < w);
+    srcbuf = (Uint8 *) (df + 1);
+    for (;;) {
+        /* copy opaque pixels */
+        int ofs = 0;
+        do {
+            unsigned run;
+            if (bpp == 2) {
+                ofs += srcbuf[0];
+                run = srcbuf[1];
+                srcbuf += 2;
+            } else {
+                ofs += ((Uint16 *) srcbuf)[0];
+                run = ((Uint16 *) srcbuf)[1];
+                srcbuf += 4;
+            }
+            if (run) {
+                srcbuf += uncopy_opaque(dst + ofs, srcbuf, run, df, sf);
+                ofs += run;
+            } else if (!ofs)
+                return (SDL_TRUE);
+        }
+        while (ofs < w);
 
-	/* skip padding if needed */
-	if(bpp == 2)
-	    srcbuf += (uintptr_t)srcbuf & 2;
-	
-	/* copy translucent pixels */
-	ofs = 0;
-	do {
-	    unsigned run;
-	    ofs += ((Uint16 *)srcbuf)[0];
-	    run = ((Uint16 *)srcbuf)[1];
-	    srcbuf += 4;
-	    if(run) {
-		srcbuf += uncopy_transl(dst + ofs, srcbuf, run, df, sf);
-		ofs += run;
-	    }
-	} while(ofs < w);
-	dst += surface->pitch >> 2;
+        /* skip padding if needed */
+        if (bpp == 2)
+            srcbuf += (uintptr_t) srcbuf & 2;
+
+        /* copy translucent pixels */
+        ofs = 0;
+        do {
+            unsigned run;
+            ofs += ((Uint16 *) srcbuf)[0];
+            run = ((Uint16 *) srcbuf)[1];
+            srcbuf += 4;
+            if (run) {
+                srcbuf += uncopy_transl(dst + ofs, srcbuf, run, df, sf);
+                ofs += run;
+            }
+        }
+        while (ofs < w);
+        dst += surface->pitch >> 2;
     }
     /* Make the compiler happy */
-    return(SDL_TRUE);
+    return (SDL_TRUE);
 }
 
-void SDL_UnRLESurface(SDL_Surface *surface, int recode)
+void
+SDL_UnRLESurface(SDL_Surface * surface, int recode)
 {
-    if ( (surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL ) {
-	surface->flags &= ~SDL_RLEACCEL;
-
-	if(recode && (surface->flags & SDL_PREALLOC) != SDL_PREALLOC
-	   && (surface->flags & SDL_HWSURFACE) != SDL_HWSURFACE) {
-	    if((surface->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) {
-		SDL_Rect full;
-		unsigned alpha_flag;
+    if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) {
+        surface->flags &= ~SDL_RLEACCEL;
 
-		/* re-create the original surface */
-		surface->pixels = SDL_malloc(surface->h * surface->pitch);
-		if ( !surface->pixels ) {
-			/* Oh crap... */
-			surface->flags |= SDL_RLEACCEL;
-			return;
-		}
+        if (recode && !(surface->flags & SDL_PREALLOC)
+            && !(surface->flags & SDL_HWSURFACE)) {
+            if ((surface->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) {
+                SDL_Rect full;
+                unsigned alpha_flag;
 
-		/* fill it with the background colour */
-		SDL_FillRect(surface, NULL, surface->format->colorkey);
+                /* re-create the original surface */
+                surface->pixels = SDL_malloc(surface->h * surface->pitch);
+                if (!surface->pixels) {
+                    /* Oh crap... */
+                    surface->flags |= SDL_RLEACCEL;
+                    return;
+                }
 
-		/* now render the encoded surface */
-		full.x = full.y = 0;
-		full.w = surface->w;
-		full.h = surface->h;
-		alpha_flag = surface->flags & SDL_SRCALPHA;
-		surface->flags &= ~SDL_SRCALPHA; /* opaque blit */
-		SDL_RLEBlit(surface, &full, surface, &full);
-		surface->flags |= alpha_flag;
-	    } else {
-		if ( !UnRLEAlpha(surface) ) {
-		    /* Oh crap... */
-		    surface->flags |= SDL_RLEACCEL;
-		    return;
-		}
-	    }
-	}
+                /* fill it with the background colour */
+                SDL_FillRect(surface, NULL, surface->format->colorkey);
 
-	if ( surface->map && surface->map->sw_data->aux_data ) {
-	    SDL_free(surface->map->sw_data->aux_data);
-	    surface->map->sw_data->aux_data = NULL;
-	}
+                /* now render the encoded surface */
+                full.x = full.y = 0;
+                full.w = surface->w;
+                full.h = surface->h;
+                alpha_flag = surface->flags & SDL_SRCALPHA;
+                surface->flags &= ~SDL_SRCALPHA;        /* opaque blit */
+                SDL_RLEBlit(surface, &full, surface, &full);
+                surface->flags |= alpha_flag;
+            } else {
+                if (!UnRLEAlpha(surface)) {
+                    /* Oh crap... */
+                    surface->flags |= SDL_RLEACCEL;
+                    return;
+                }
+            }
+        }
+
+        if (surface->map && surface->map->sw_data->aux_data) {
+            SDL_free(surface->map->sw_data->aux_data);
+            surface->map->sw_data->aux_data = NULL;
+        }
     }
 }
 
-
+/* vi: set ts=4 sw=4 expandtab: */