src/video/SDL_surface.c
branchSDL-1.3
changeset 1662 782fd950bd46
parent 1456 84de7511f79f
child 1666 6e7ec5cb83c3
     1.1 --- a/src/video/SDL_surface.c	Sun May 21 17:27:13 2006 +0000
     1.2 +++ b/src/video/SDL_surface.c	Sun May 28 13:04:16 2006 +0000
     1.3 @@ -34,365 +34,373 @@
     1.4  /*
     1.5   * Create an empty RGB surface of the appropriate depth
     1.6   */
     1.7 -SDL_Surface * SDL_CreateRGBSurface (Uint32 flags,
     1.8 -			int width, int height, int depth,
     1.9 -			Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)
    1.10 +SDL_Surface *
    1.11 +SDL_CreateRGBSurface (Uint32 flags,
    1.12 +                      int width, int height, int depth,
    1.13 +                      Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)
    1.14  {
    1.15 -	SDL_VideoDevice *video = current_video;
    1.16 -	SDL_VideoDevice *this  = current_video;
    1.17 -	SDL_Surface *screen;
    1.18 -	SDL_Surface *surface;
    1.19 +    SDL_VideoDevice *_this = SDL_GetVideoDevice ();
    1.20 +    SDL_Surface *screen;
    1.21 +    SDL_Surface *surface;
    1.22  
    1.23 -	/* Make sure the size requested doesn't overflow our datatypes */
    1.24 -	/* Next time I write a library like SDL, I'll use int for size. :) */
    1.25 -	if ( width >= 16384 || height >= 65536 ) {
    1.26 -		SDL_SetError("Width or height is too large");
    1.27 -		return(NULL);
    1.28 -	}
    1.29 +    /* Make sure the size requested doesn't overflow our datatypes */
    1.30 +    /* Next time I write a library like SDL, I'll use int for size. :) */
    1.31 +    if (width >= 16384 || height >= 65536) {
    1.32 +        SDL_SetError ("Width or height is too large");
    1.33 +        return (NULL);
    1.34 +    }
    1.35  
    1.36 -	/* Check to see if we desire the surface in video memory */
    1.37 -	if ( video ) {
    1.38 -		screen = SDL_PublicSurface;
    1.39 -	} else {
    1.40 -		screen = NULL;
    1.41 -	}
    1.42 -	if ( screen && ((screen->flags&SDL_HWSURFACE) == SDL_HWSURFACE) ) {
    1.43 -		if ( (flags&(SDL_SRCCOLORKEY|SDL_SRCALPHA)) != 0 ) {
    1.44 -			flags |= SDL_HWSURFACE;
    1.45 -		}
    1.46 -		if ( (flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY ) {
    1.47 -			if ( ! current_video->info.blit_hw_CC ) {
    1.48 -				flags &= ~SDL_HWSURFACE;
    1.49 -			}
    1.50 -		}
    1.51 -		if ( (flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {
    1.52 -			if ( ! current_video->info.blit_hw_A ) {
    1.53 -				flags &= ~SDL_HWSURFACE;
    1.54 -			}
    1.55 -		}
    1.56 -	} else {
    1.57 -		flags &= ~SDL_HWSURFACE;
    1.58 -	}
    1.59 +    /* Check to see if we desire the surface in video memory */
    1.60 +    if (_this) {
    1.61 +        screen = SDL_PublicSurface;
    1.62 +    } else {
    1.63 +        screen = NULL;
    1.64 +    }
    1.65 +    if (screen && ((screen->flags & SDL_HWSURFACE) == SDL_HWSURFACE)) {
    1.66 +        if ((flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA)) != 0) {
    1.67 +            flags |= SDL_HWSURFACE;
    1.68 +        }
    1.69 +        if ((flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) {
    1.70 +            if (!_this->info.blit_hw_CC) {
    1.71 +                flags &= ~SDL_HWSURFACE;
    1.72 +            }
    1.73 +        }
    1.74 +        if ((flags & SDL_SRCALPHA) == SDL_SRCALPHA) {
    1.75 +            if (!_this->info.blit_hw_A) {
    1.76 +                flags &= ~SDL_HWSURFACE;
    1.77 +            }
    1.78 +        }
    1.79 +    } else {
    1.80 +        flags &= ~SDL_HWSURFACE;
    1.81 +    }
    1.82  
    1.83 -	/* Allocate the surface */
    1.84 -	surface = (SDL_Surface *)SDL_malloc(sizeof(*surface));
    1.85 -	if ( surface == NULL ) {
    1.86 -		SDL_OutOfMemory();
    1.87 -		return(NULL);
    1.88 -	}
    1.89 -	surface->flags = SDL_SWSURFACE;
    1.90 -	if ( (flags & SDL_HWSURFACE) == SDL_HWSURFACE ) {
    1.91 -		if ((Amask) && (video->displayformatalphapixel))
    1.92 -		{
    1.93 -			depth = video->displayformatalphapixel->BitsPerPixel;
    1.94 -			Rmask = video->displayformatalphapixel->Rmask;
    1.95 -			Gmask = video->displayformatalphapixel->Gmask;
    1.96 -			Bmask = video->displayformatalphapixel->Bmask;
    1.97 -			Amask = video->displayformatalphapixel->Amask;
    1.98 -		}
    1.99 -		else
   1.100 -		{
   1.101 -			depth = screen->format->BitsPerPixel;
   1.102 -			Rmask = screen->format->Rmask;
   1.103 -			Gmask = screen->format->Gmask;
   1.104 -			Bmask = screen->format->Bmask;
   1.105 -			Amask = screen->format->Amask;
   1.106 -		}
   1.107 -	}
   1.108 -	surface->format = SDL_AllocFormat(depth, Rmask, Gmask, Bmask, Amask);
   1.109 -	if ( surface->format == NULL ) {
   1.110 -		SDL_free(surface);
   1.111 -		return(NULL);
   1.112 -	}
   1.113 -	if ( Amask ) {
   1.114 -		surface->flags |= SDL_SRCALPHA;
   1.115 -	}
   1.116 -	surface->w = width;
   1.117 -	surface->h = height;
   1.118 -	surface->pitch = SDL_CalculatePitch(surface);
   1.119 -	surface->pixels = NULL;
   1.120 -	surface->offset = 0;
   1.121 -	surface->hwdata = NULL;
   1.122 -	surface->locked = 0;
   1.123 -	surface->map = NULL;
   1.124 -	surface->unused1 = 0;
   1.125 -	SDL_SetClipRect(surface, NULL);
   1.126 -	SDL_FormatChanged(surface);
   1.127 +    /* Allocate the surface */
   1.128 +    surface = (SDL_Surface *) SDL_malloc (sizeof (*surface));
   1.129 +    if (surface == NULL) {
   1.130 +        SDL_OutOfMemory ();
   1.131 +        return (NULL);
   1.132 +    }
   1.133 +    surface->flags = SDL_SWSURFACE;
   1.134 +    if ((flags & SDL_HWSURFACE) == SDL_HWSURFACE) {
   1.135 +        if ((Amask) && (_this->displayformatalphapixel)) {
   1.136 +            depth = _this->displayformatalphapixel->BitsPerPixel;
   1.137 +            Rmask = _this->displayformatalphapixel->Rmask;
   1.138 +            Gmask = _this->displayformatalphapixel->Gmask;
   1.139 +            Bmask = _this->displayformatalphapixel->Bmask;
   1.140 +            Amask = _this->displayformatalphapixel->Amask;
   1.141 +        } else {
   1.142 +            depth = screen->format->BitsPerPixel;
   1.143 +            Rmask = screen->format->Rmask;
   1.144 +            Gmask = screen->format->Gmask;
   1.145 +            Bmask = screen->format->Bmask;
   1.146 +            Amask = screen->format->Amask;
   1.147 +        }
   1.148 +    }
   1.149 +    surface->format = SDL_AllocFormat (depth, Rmask, Gmask, Bmask, Amask);
   1.150 +    if (surface->format == NULL) {
   1.151 +        SDL_free (surface);
   1.152 +        return (NULL);
   1.153 +    }
   1.154 +    if (Amask) {
   1.155 +        surface->flags |= SDL_SRCALPHA;
   1.156 +    }
   1.157 +    surface->w = width;
   1.158 +    surface->h = height;
   1.159 +    surface->pitch = SDL_CalculatePitch (surface);
   1.160 +    surface->pixels = NULL;
   1.161 +    surface->offset = 0;
   1.162 +    surface->hwdata = NULL;
   1.163 +    surface->locked = 0;
   1.164 +    surface->map = NULL;
   1.165 +    surface->unused1 = 0;
   1.166 +    SDL_SetClipRect (surface, NULL);
   1.167 +    SDL_FormatChanged (surface);
   1.168  
   1.169 -	/* Get the pixels */
   1.170 -	if ( ((flags&SDL_HWSURFACE) == SDL_SWSURFACE) || 
   1.171 -				(video->AllocHWSurface(this, surface) < 0) ) {
   1.172 -		if ( surface->w && surface->h ) {
   1.173 -			surface->pixels = SDL_malloc(surface->h*surface->pitch);
   1.174 -			if ( surface->pixels == NULL ) {
   1.175 -				SDL_FreeSurface(surface);
   1.176 -				SDL_OutOfMemory();
   1.177 -				return(NULL);
   1.178 -			}
   1.179 -			/* This is important for bitmaps */
   1.180 -			SDL_memset(surface->pixels, 0, surface->h*surface->pitch);
   1.181 -		}
   1.182 -	}
   1.183 +    /* Get the pixels */
   1.184 +    if (((flags & SDL_HWSURFACE) == SDL_SWSURFACE) ||
   1.185 +        (_this->AllocHWSurface (_this, surface) < 0)) {
   1.186 +        if (surface->w && surface->h) {
   1.187 +            surface->pixels = SDL_malloc (surface->h * surface->pitch);
   1.188 +            if (surface->pixels == NULL) {
   1.189 +                SDL_FreeSurface (surface);
   1.190 +                SDL_OutOfMemory ();
   1.191 +                return (NULL);
   1.192 +            }
   1.193 +            /* This is important for bitmaps */
   1.194 +            SDL_memset (surface->pixels, 0, surface->h * surface->pitch);
   1.195 +        }
   1.196 +    }
   1.197  
   1.198 -	/* Allocate an empty mapping */
   1.199 -	surface->map = SDL_AllocBlitMap();
   1.200 -	if ( surface->map == NULL ) {
   1.201 -		SDL_FreeSurface(surface);
   1.202 -		return(NULL);
   1.203 -	}
   1.204 +    /* Allocate an empty mapping */
   1.205 +    surface->map = SDL_AllocBlitMap ();
   1.206 +    if (surface->map == NULL) {
   1.207 +        SDL_FreeSurface (surface);
   1.208 +        return (NULL);
   1.209 +    }
   1.210  
   1.211 -	/* The surface is ready to go */
   1.212 -	surface->refcount = 1;
   1.213 +    /* The surface is ready to go */
   1.214 +    surface->refcount = 1;
   1.215  #ifdef CHECK_LEAKS
   1.216 -	++surfaces_allocated;
   1.217 +    ++surfaces_allocated;
   1.218  #endif
   1.219 -	return(surface);
   1.220 +    return (surface);
   1.221  }
   1.222 +
   1.223  /*
   1.224   * Create an RGB surface from an existing memory buffer
   1.225   */
   1.226 -SDL_Surface * SDL_CreateRGBSurfaceFrom (void *pixels,
   1.227 -			int width, int height, int depth, int pitch,
   1.228 -			Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)
   1.229 +SDL_Surface *
   1.230 +SDL_CreateRGBSurfaceFrom (void *pixels,
   1.231 +                          int width, int height, int depth, int pitch,
   1.232 +                          Uint32 Rmask, Uint32 Gmask, Uint32 Bmask,
   1.233 +                          Uint32 Amask)
   1.234  {
   1.235 -	SDL_Surface *surface;
   1.236 +    SDL_Surface *surface;
   1.237  
   1.238 -	surface = SDL_CreateRGBSurface(SDL_SWSURFACE, 0, 0, depth,
   1.239 -	                               Rmask, Gmask, Bmask, Amask);
   1.240 -	if ( surface != NULL ) {
   1.241 -		surface->flags |= SDL_PREALLOC;
   1.242 -		surface->pixels = pixels;
   1.243 -		surface->w = width;
   1.244 -		surface->h = height;
   1.245 -		surface->pitch = pitch;
   1.246 -		SDL_SetClipRect(surface, NULL);
   1.247 -	}
   1.248 -	return(surface);
   1.249 +    surface = SDL_CreateRGBSurface (SDL_SWSURFACE, 0, 0, depth,
   1.250 +                                    Rmask, Gmask, Bmask, Amask);
   1.251 +    if (surface != NULL) {
   1.252 +        surface->flags |= SDL_PREALLOC;
   1.253 +        surface->pixels = pixels;
   1.254 +        surface->w = width;
   1.255 +        surface->h = height;
   1.256 +        surface->pitch = pitch;
   1.257 +        SDL_SetClipRect (surface, NULL);
   1.258 +    }
   1.259 +    return (surface);
   1.260  }
   1.261 +
   1.262  /*
   1.263   * Set the color key in a blittable surface
   1.264   */
   1.265 -int SDL_SetColorKey (SDL_Surface *surface, Uint32 flag, Uint32 key)
   1.266 +int
   1.267 +SDL_SetColorKey (SDL_Surface * surface, Uint32 flag, Uint32 key)
   1.268  {
   1.269 -	/* Sanity check the flag as it gets passed in */
   1.270 -	if ( flag & SDL_SRCCOLORKEY ) {
   1.271 -		if ( flag & (SDL_RLEACCEL|SDL_RLEACCELOK) ) {
   1.272 -			flag = (SDL_SRCCOLORKEY | SDL_RLEACCELOK);
   1.273 -		} else {
   1.274 -			flag = SDL_SRCCOLORKEY;
   1.275 -		}
   1.276 -	} else {
   1.277 -		flag = 0;
   1.278 -	}
   1.279 +    /* Sanity check the flag as it gets passed in */
   1.280 +    if (flag & SDL_SRCCOLORKEY) {
   1.281 +        if (flag & (SDL_RLEACCEL | SDL_RLEACCELOK)) {
   1.282 +            flag = (SDL_SRCCOLORKEY | SDL_RLEACCELOK);
   1.283 +        } else {
   1.284 +            flag = SDL_SRCCOLORKEY;
   1.285 +        }
   1.286 +    } else {
   1.287 +        flag = 0;
   1.288 +    }
   1.289  
   1.290 -	/* Optimize away operations that don't change anything */
   1.291 -	if ( (flag == (surface->flags & (SDL_SRCCOLORKEY|SDL_RLEACCELOK))) &&
   1.292 -	     (key == surface->format->colorkey) ) {
   1.293 -		return(0);
   1.294 -	}
   1.295 +    /* Optimize away operations that don't change anything */
   1.296 +    if ((flag == (surface->flags & (SDL_SRCCOLORKEY | SDL_RLEACCELOK))) &&
   1.297 +        (key == surface->format->colorkey)) {
   1.298 +        return (0);
   1.299 +    }
   1.300  
   1.301 -	/* UnRLE surfaces before we change the colorkey */
   1.302 -	if ( surface->flags & SDL_RLEACCEL ) {
   1.303 -	        SDL_UnRLESurface(surface, 1);
   1.304 -	}
   1.305 +    /* UnRLE surfaces before we change the colorkey */
   1.306 +    if (surface->flags & SDL_RLEACCEL) {
   1.307 +        SDL_UnRLESurface (surface, 1);
   1.308 +    }
   1.309  
   1.310 -	if ( flag ) {
   1.311 -		SDL_VideoDevice *video = current_video;
   1.312 -		SDL_VideoDevice *this  = current_video;
   1.313 +    if (flag) {
   1.314 +        SDL_VideoDevice *_this = SDL_GetVideoDevice ();
   1.315  
   1.316 +        surface->flags |= SDL_SRCCOLORKEY;
   1.317 +        surface->format->colorkey = key;
   1.318 +        if ((surface->flags & SDL_HWACCEL) == SDL_HWACCEL) {
   1.319 +            if ((_this->SetHWColorKey == NULL) ||
   1.320 +                (_this->SetHWColorKey (_this, surface, key) < 0)) {
   1.321 +                surface->flags &= ~SDL_HWACCEL;
   1.322 +            }
   1.323 +        }
   1.324 +        if (flag & SDL_RLEACCELOK) {
   1.325 +            surface->flags |= SDL_RLEACCELOK;
   1.326 +        } else {
   1.327 +            surface->flags &= ~SDL_RLEACCELOK;
   1.328 +        }
   1.329 +    } else {
   1.330 +        surface->flags &= ~(SDL_SRCCOLORKEY | SDL_RLEACCELOK);
   1.331 +        surface->format->colorkey = 0;
   1.332 +    }
   1.333 +    SDL_InvalidateMap (surface->map);
   1.334 +    return (0);
   1.335 +}
   1.336  
   1.337 -		surface->flags |= SDL_SRCCOLORKEY;
   1.338 -		surface->format->colorkey = key;
   1.339 -		if ( (surface->flags & SDL_HWACCEL) == SDL_HWACCEL ) {
   1.340 -			if ( (video->SetHWColorKey == NULL) ||
   1.341 -			     (video->SetHWColorKey(this, surface, key) < 0) ) {
   1.342 -				surface->flags &= ~SDL_HWACCEL;
   1.343 -			}
   1.344 -		}
   1.345 -		if ( flag & SDL_RLEACCELOK ) {
   1.346 -			surface->flags |= SDL_RLEACCELOK;
   1.347 -		} else {
   1.348 -			surface->flags &= ~SDL_RLEACCELOK;
   1.349 -		}
   1.350 -	} else {
   1.351 -		surface->flags &= ~(SDL_SRCCOLORKEY|SDL_RLEACCELOK);
   1.352 -		surface->format->colorkey = 0;
   1.353 -	}
   1.354 -	SDL_InvalidateMap(surface->map);
   1.355 -	return(0);
   1.356 +/* This function sets the alpha channel of a surface */
   1.357 +int
   1.358 +SDL_SetAlpha (SDL_Surface * surface, Uint32 flag, Uint8 value)
   1.359 +{
   1.360 +    Uint32 oldflags = surface->flags;
   1.361 +    Uint32 oldalpha = surface->format->alpha;
   1.362 +
   1.363 +    /* Sanity check the flag as it gets passed in */
   1.364 +    if (flag & SDL_SRCALPHA) {
   1.365 +        if (flag & (SDL_RLEACCEL | SDL_RLEACCELOK)) {
   1.366 +            flag = (SDL_SRCALPHA | SDL_RLEACCELOK);
   1.367 +        } else {
   1.368 +            flag = SDL_SRCALPHA;
   1.369 +        }
   1.370 +    } else {
   1.371 +        flag = 0;
   1.372 +    }
   1.373 +
   1.374 +    /* Optimize away operations that don't change anything */
   1.375 +    if ((flag == (surface->flags & (SDL_SRCALPHA | SDL_RLEACCELOK))) &&
   1.376 +        (!flag || value == oldalpha)) {
   1.377 +        return (0);
   1.378 +    }
   1.379 +
   1.380 +    if (!(flag & SDL_RLEACCELOK) && (surface->flags & SDL_RLEACCEL))
   1.381 +        SDL_UnRLESurface (surface, 1);
   1.382 +
   1.383 +    if (flag) {
   1.384 +        SDL_VideoDevice *_this = SDL_GetVideoDevice ();
   1.385 +
   1.386 +        surface->flags |= SDL_SRCALPHA;
   1.387 +        surface->format->alpha = value;
   1.388 +        if ((surface->flags & SDL_HWACCEL) == SDL_HWACCEL) {
   1.389 +            if ((_this->SetHWAlpha == NULL) ||
   1.390 +                (_this->SetHWAlpha (_this, surface, value) < 0)) {
   1.391 +                surface->flags &= ~SDL_HWACCEL;
   1.392 +            }
   1.393 +        }
   1.394 +        if (flag & SDL_RLEACCELOK) {
   1.395 +            surface->flags |= SDL_RLEACCELOK;
   1.396 +        } else {
   1.397 +            surface->flags &= ~SDL_RLEACCELOK;
   1.398 +        }
   1.399 +    } else {
   1.400 +        surface->flags &= ~SDL_SRCALPHA;
   1.401 +        surface->format->alpha = SDL_ALPHA_OPAQUE;
   1.402 +    }
   1.403 +    /*
   1.404 +     * The representation for software surfaces is independent of
   1.405 +     * per-surface alpha, so no need to invalidate the blit mapping
   1.406 +     * if just the alpha value was changed. (If either is 255, we still
   1.407 +     * need to invalidate.)
   1.408 +     */
   1.409 +    if ((surface->flags & SDL_HWACCEL) == SDL_HWACCEL
   1.410 +        || oldflags != surface->flags
   1.411 +        || (((oldalpha + 1) ^ (value + 1)) & 0x100))
   1.412 +        SDL_InvalidateMap (surface->map);
   1.413 +    return (0);
   1.414  }
   1.415 -/* This function sets the alpha channel of a surface */
   1.416 -int SDL_SetAlpha (SDL_Surface *surface, Uint32 flag, Uint8 value)
   1.417 +
   1.418 +int
   1.419 +SDL_SetAlphaChannel (SDL_Surface * surface, Uint8 value)
   1.420  {
   1.421 -	Uint32 oldflags = surface->flags;
   1.422 -	Uint32 oldalpha = surface->format->alpha;
   1.423 +    int row, col;
   1.424 +    int offset;
   1.425 +    Uint8 *buf;
   1.426  
   1.427 -	/* Sanity check the flag as it gets passed in */
   1.428 -	if ( flag & SDL_SRCALPHA ) {
   1.429 -		if ( flag & (SDL_RLEACCEL|SDL_RLEACCELOK) ) {
   1.430 -			flag = (SDL_SRCALPHA | SDL_RLEACCELOK);
   1.431 -		} else {
   1.432 -			flag = SDL_SRCALPHA;
   1.433 -		}
   1.434 -	} else {
   1.435 -		flag = 0;
   1.436 -	}
   1.437 -
   1.438 -	/* Optimize away operations that don't change anything */
   1.439 -	if ( (flag == (surface->flags & (SDL_SRCALPHA|SDL_RLEACCELOK))) &&
   1.440 -	     (!flag || value == oldalpha) ) {
   1.441 -		return(0);
   1.442 -	}
   1.443 -
   1.444 -	if(!(flag & SDL_RLEACCELOK) && (surface->flags & SDL_RLEACCEL))
   1.445 -		SDL_UnRLESurface(surface, 1);
   1.446 -
   1.447 -	if ( flag ) {
   1.448 -		SDL_VideoDevice *video = current_video;
   1.449 -		SDL_VideoDevice *this  = current_video;
   1.450 -
   1.451 -		surface->flags |= SDL_SRCALPHA;
   1.452 -		surface->format->alpha = value;
   1.453 -		if ( (surface->flags & SDL_HWACCEL) == SDL_HWACCEL ) {
   1.454 -			if ( (video->SetHWAlpha == NULL) ||
   1.455 -			     (video->SetHWAlpha(this, surface, value) < 0) ) {
   1.456 -				surface->flags &= ~SDL_HWACCEL;
   1.457 -			}
   1.458 -		}
   1.459 -		if ( flag & SDL_RLEACCELOK ) {
   1.460 -		        surface->flags |= SDL_RLEACCELOK;
   1.461 -		} else {
   1.462 -		        surface->flags &= ~SDL_RLEACCELOK;
   1.463 -		}
   1.464 -	} else {
   1.465 -		surface->flags &= ~SDL_SRCALPHA;
   1.466 -		surface->format->alpha = SDL_ALPHA_OPAQUE;
   1.467 -	}
   1.468 -	/*
   1.469 -	 * The representation for software surfaces is independent of
   1.470 -	 * per-surface alpha, so no need to invalidate the blit mapping
   1.471 -	 * if just the alpha value was changed. (If either is 255, we still
   1.472 -	 * need to invalidate.)
   1.473 -	 */
   1.474 -	if((surface->flags & SDL_HWACCEL) == SDL_HWACCEL
   1.475 -	   || oldflags != surface->flags
   1.476 -	   || (((oldalpha + 1) ^ (value + 1)) & 0x100))
   1.477 -		SDL_InvalidateMap(surface->map);
   1.478 -	return(0);
   1.479 -}
   1.480 -int SDL_SetAlphaChannel(SDL_Surface *surface, Uint8 value)
   1.481 -{
   1.482 -	int row, col;
   1.483 -	int offset;
   1.484 -	Uint8 *buf;
   1.485 -
   1.486 -	if ( (surface->format->Amask != 0xFF000000) &&
   1.487 -	     (surface->format->Amask != 0x000000FF) ) {
   1.488 -		SDL_SetError("Unsupported surface alpha mask format");
   1.489 -		return -1;
   1.490 -	}
   1.491 -
   1.492 +    if ((surface->format->Amask != 0xFF000000) &&
   1.493 +        (surface->format->Amask != 0x000000FF)) {
   1.494 +        SDL_SetError ("Unsupported surface alpha mask format");
   1.495 +        return -1;
   1.496 +    }
   1.497  #if SDL_BYTEORDER == SDL_LIL_ENDIAN
   1.498 -	if ( surface->format->Amask == 0xFF000000 ) {
   1.499 -			offset = 3;
   1.500 -	} else {
   1.501 -			offset = 0;
   1.502 -	}
   1.503 +    if (surface->format->Amask == 0xFF000000) {
   1.504 +        offset = 3;
   1.505 +    } else {
   1.506 +        offset = 0;
   1.507 +    }
   1.508  #else
   1.509 -	if ( surface->format->Amask == 0xFF000000 ) {
   1.510 -			offset = 0;
   1.511 -	} else {
   1.512 -			offset = 3;
   1.513 -	}
   1.514 +    if (surface->format->Amask == 0xFF000000) {
   1.515 +        offset = 0;
   1.516 +    } else {
   1.517 +        offset = 3;
   1.518 +    }
   1.519  #endif /* Byte ordering */
   1.520  
   1.521 -	/* Quickly set the alpha channel of an RGBA or ARGB surface */
   1.522 -	if ( SDL_MUSTLOCK(surface) ) {
   1.523 -		if ( SDL_LockSurface(surface) < 0 ) {
   1.524 -			return -1;
   1.525 -		}
   1.526 -	}
   1.527 -	row = surface->h;
   1.528 -	while (row--) {
   1.529 -		col = surface->w;
   1.530 -		buf = (Uint8 *)surface->pixels + row * surface->pitch + offset;
   1.531 -		while(col--) {
   1.532 -			*buf = value;
   1.533 -			buf += 4;
   1.534 -		}
   1.535 -	}
   1.536 -	if ( SDL_MUSTLOCK(surface) ) {
   1.537 -		SDL_UnlockSurface(surface);
   1.538 -	}
   1.539 -	return 0;
   1.540 +    /* Quickly set the alpha channel of an RGBA or ARGB surface */
   1.541 +    if (SDL_MUSTLOCK (surface)) {
   1.542 +        if (SDL_LockSurface (surface) < 0) {
   1.543 +            return -1;
   1.544 +        }
   1.545 +    }
   1.546 +    row = surface->h;
   1.547 +    while (row--) {
   1.548 +        col = surface->w;
   1.549 +        buf = (Uint8 *) surface->pixels + row * surface->pitch + offset;
   1.550 +        while (col--) {
   1.551 +            *buf = value;
   1.552 +            buf += 4;
   1.553 +        }
   1.554 +    }
   1.555 +    if (SDL_MUSTLOCK (surface)) {
   1.556 +        SDL_UnlockSurface (surface);
   1.557 +    }
   1.558 +    return 0;
   1.559  }
   1.560  
   1.561  /*
   1.562   * A function to calculate the intersection of two rectangles:
   1.563   * return true if the rectangles intersect, false otherwise
   1.564   */
   1.565 -static __inline__
   1.566 -SDL_bool SDL_IntersectRect(const SDL_Rect *A, const SDL_Rect *B, SDL_Rect *intersection)
   1.567 +static __inline__ SDL_bool
   1.568 +SDL_IntersectRect (const SDL_Rect * A, const SDL_Rect * B,
   1.569 +                   SDL_Rect * intersection)
   1.570  {
   1.571 -	int Amin, Amax, Bmin, Bmax;
   1.572 +    int Amin, Amax, Bmin, Bmax;
   1.573  
   1.574 -	/* Horizontal intersection */
   1.575 -	Amin = A->x;
   1.576 -	Amax = Amin + A->w;
   1.577 -	Bmin = B->x;
   1.578 -	Bmax = Bmin + B->w;
   1.579 -	if(Bmin > Amin)
   1.580 -	        Amin = Bmin;
   1.581 -	intersection->x = Amin;
   1.582 -	if(Bmax < Amax)
   1.583 -	        Amax = Bmax;
   1.584 -	intersection->w = Amax - Amin > 0 ? Amax - Amin : 0;
   1.585 +    /* Horizontal intersection */
   1.586 +    Amin = A->x;
   1.587 +    Amax = Amin + A->w;
   1.588 +    Bmin = B->x;
   1.589 +    Bmax = Bmin + B->w;
   1.590 +    if (Bmin > Amin)
   1.591 +        Amin = Bmin;
   1.592 +    intersection->x = Amin;
   1.593 +    if (Bmax < Amax)
   1.594 +        Amax = Bmax;
   1.595 +    intersection->w = Amax - Amin > 0 ? Amax - Amin : 0;
   1.596  
   1.597 -	/* Vertical intersection */
   1.598 -	Amin = A->y;
   1.599 -	Amax = Amin + A->h;
   1.600 -	Bmin = B->y;
   1.601 -	Bmax = Bmin + B->h;
   1.602 -	if(Bmin > Amin)
   1.603 -	        Amin = Bmin;
   1.604 -	intersection->y = Amin;
   1.605 -	if(Bmax < Amax)
   1.606 -	        Amax = Bmax;
   1.607 -	intersection->h = Amax - Amin > 0 ? Amax - Amin : 0;
   1.608 +    /* Vertical intersection */
   1.609 +    Amin = A->y;
   1.610 +    Amax = Amin + A->h;
   1.611 +    Bmin = B->y;
   1.612 +    Bmax = Bmin + B->h;
   1.613 +    if (Bmin > Amin)
   1.614 +        Amin = Bmin;
   1.615 +    intersection->y = Amin;
   1.616 +    if (Bmax < Amax)
   1.617 +        Amax = Bmax;
   1.618 +    intersection->h = Amax - Amin > 0 ? Amax - Amin : 0;
   1.619  
   1.620 -	return (intersection->w && intersection->h);
   1.621 +    return (intersection->w && intersection->h);
   1.622  }
   1.623 +
   1.624  /*
   1.625   * Set the clipping rectangle for a blittable surface
   1.626   */
   1.627 -SDL_bool SDL_SetClipRect(SDL_Surface *surface, const SDL_Rect *rect)
   1.628 +SDL_bool
   1.629 +SDL_SetClipRect (SDL_Surface * surface, const SDL_Rect * rect)
   1.630  {
   1.631 -	SDL_Rect full_rect;
   1.632 +    SDL_Rect full_rect;
   1.633  
   1.634 -	/* Don't do anything if there's no surface to act on */
   1.635 -	if ( ! surface ) {
   1.636 -		return SDL_FALSE;
   1.637 -	}
   1.638 +    /* Don't do anything if there's no surface to act on */
   1.639 +    if (!surface) {
   1.640 +        return SDL_FALSE;
   1.641 +    }
   1.642  
   1.643 -	/* Set up the full surface rectangle */
   1.644 -	full_rect.x = 0;
   1.645 -	full_rect.y = 0;
   1.646 -	full_rect.w = surface->w;
   1.647 -	full_rect.h = surface->h;
   1.648 +    /* Set up the full surface rectangle */
   1.649 +    full_rect.x = 0;
   1.650 +    full_rect.y = 0;
   1.651 +    full_rect.w = surface->w;
   1.652 +    full_rect.h = surface->h;
   1.653  
   1.654 -	/* Set the clipping rectangle */
   1.655 -	if ( ! rect ) {
   1.656 -		surface->clip_rect = full_rect;
   1.657 -		return 1;
   1.658 -	}
   1.659 -	return SDL_IntersectRect(rect, &full_rect, &surface->clip_rect);
   1.660 +    /* Set the clipping rectangle */
   1.661 +    if (!rect) {
   1.662 +        surface->clip_rect = full_rect;
   1.663 +        return 1;
   1.664 +    }
   1.665 +    return SDL_IntersectRect (rect, &full_rect, &surface->clip_rect);
   1.666  }
   1.667 -void SDL_GetClipRect(SDL_Surface *surface, SDL_Rect *rect)
   1.668 +
   1.669 +void
   1.670 +SDL_GetClipRect (SDL_Surface * surface, SDL_Rect * rect)
   1.671  {
   1.672 -	if ( surface && rect ) {
   1.673 -		*rect = surface->clip_rect;
   1.674 -	}
   1.675 +    if (surface && rect) {
   1.676 +        *rect = surface->clip_rect;
   1.677 +    }
   1.678  }
   1.679 +
   1.680  /* 
   1.681   * Set up a blit between two surfaces -- split into three parts:
   1.682   * The upper part, SDL_UpperBlit(), performs clipping and rectangle 
   1.683 @@ -404,538 +412,526 @@
   1.684   * you know exactly what you are doing, you can optimize your code
   1.685   * by calling the one(s) you need.
   1.686   */
   1.687 -int SDL_LowerBlit (SDL_Surface *src, SDL_Rect *srcrect,
   1.688 -				SDL_Surface *dst, SDL_Rect *dstrect)
   1.689 +int
   1.690 +SDL_LowerBlit (SDL_Surface * src, SDL_Rect * srcrect,
   1.691 +               SDL_Surface * dst, SDL_Rect * dstrect)
   1.692  {
   1.693 -	SDL_blit do_blit;
   1.694 -	SDL_Rect hw_srcrect;
   1.695 -	SDL_Rect hw_dstrect;
   1.696 +    SDL_blit do_blit;
   1.697  
   1.698 -	/* Check to make sure the blit mapping is valid */
   1.699 -	if ( (src->map->dst != dst) ||
   1.700 -             (src->map->dst->format_version != src->map->format_version) ) {
   1.701 -		if ( SDL_MapSurface(src, dst) < 0 ) {
   1.702 -			return(-1);
   1.703 -		}
   1.704 -	}
   1.705 +    /* Check to make sure the blit mapping is valid */
   1.706 +    if ((src->map->dst != dst) ||
   1.707 +        (src->map->dst->format_version != src->map->format_version)) {
   1.708 +        if (SDL_MapSurface (src, dst) < 0) {
   1.709 +            return (-1);
   1.710 +        }
   1.711 +    }
   1.712  
   1.713 -	/* Figure out which blitter to use */
   1.714 -	if ( (src->flags & SDL_HWACCEL) == SDL_HWACCEL ) {
   1.715 -		if ( src == SDL_VideoSurface ) {
   1.716 -			hw_srcrect = *srcrect;
   1.717 -			hw_srcrect.x += current_video->offset_x;
   1.718 -			hw_srcrect.y += current_video->offset_y;
   1.719 -			srcrect = &hw_srcrect;
   1.720 -		}
   1.721 -		if ( dst == SDL_VideoSurface ) {
   1.722 -			hw_dstrect = *dstrect;
   1.723 -			hw_dstrect.x += current_video->offset_x;
   1.724 -			hw_dstrect.y += current_video->offset_y;
   1.725 -			dstrect = &hw_dstrect;
   1.726 -		}
   1.727 -		do_blit = src->map->hw_blit;
   1.728 -	} else {
   1.729 -		do_blit = src->map->sw_blit;
   1.730 -	}
   1.731 -	return(do_blit(src, srcrect, dst, dstrect));
   1.732 +    /* Figure out which blitter to use */
   1.733 +    if ((src->flags & SDL_HWACCEL) == SDL_HWACCEL) {
   1.734 +        do_blit = src->map->hw_blit;
   1.735 +    } else {
   1.736 +        do_blit = src->map->sw_blit;
   1.737 +    }
   1.738 +    return (do_blit (src, srcrect, dst, dstrect));
   1.739  }
   1.740  
   1.741  
   1.742 -int SDL_UpperBlit (SDL_Surface *src, SDL_Rect *srcrect,
   1.743 -		   SDL_Surface *dst, SDL_Rect *dstrect)
   1.744 +int
   1.745 +SDL_UpperBlit (SDL_Surface * src, SDL_Rect * srcrect,
   1.746 +               SDL_Surface * dst, SDL_Rect * dstrect)
   1.747  {
   1.748 -        SDL_Rect fulldst;
   1.749 -	int srcx, srcy, w, h;
   1.750 +    SDL_Rect fulldst;
   1.751 +    int srcx, srcy, w, h;
   1.752  
   1.753 -	/* Make sure the surfaces aren't locked */
   1.754 -	if ( ! src || ! dst ) {
   1.755 -		SDL_SetError("SDL_UpperBlit: passed a NULL surface");
   1.756 -		return(-1);
   1.757 -	}
   1.758 -	if ( src->locked || dst->locked ) {
   1.759 -		SDL_SetError("Surfaces must not be locked during blit");
   1.760 -		return(-1);
   1.761 -	}
   1.762 +    /* Make sure the surfaces aren't locked */
   1.763 +    if (!src || !dst) {
   1.764 +        SDL_SetError ("SDL_UpperBlit: passed a NULL surface");
   1.765 +        return (-1);
   1.766 +    }
   1.767 +    if (src->locked || dst->locked) {
   1.768 +        SDL_SetError ("Surfaces must not be locked during blit");
   1.769 +        return (-1);
   1.770 +    }
   1.771  
   1.772 -	/* If the destination rectangle is NULL, use the entire dest surface */
   1.773 -	if ( dstrect == NULL ) {
   1.774 -	        fulldst.x = fulldst.y = 0;
   1.775 -		dstrect = &fulldst;
   1.776 -	}
   1.777 +    /* If the destination rectangle is NULL, use the entire dest surface */
   1.778 +    if (dstrect == NULL) {
   1.779 +        fulldst.x = fulldst.y = 0;
   1.780 +        dstrect = &fulldst;
   1.781 +    }
   1.782  
   1.783 -	/* clip the source rectangle to the source surface */
   1.784 -	if(srcrect) {
   1.785 -	        int maxw, maxh;
   1.786 -	
   1.787 -		srcx = srcrect->x;
   1.788 -		w = srcrect->w;
   1.789 -		if(srcx < 0) {
   1.790 -		        w += srcx;
   1.791 -			dstrect->x -= srcx;
   1.792 -			srcx = 0;
   1.793 -		}
   1.794 -		maxw = src->w - srcx;
   1.795 -		if(maxw < w)
   1.796 -			w = maxw;
   1.797 +    /* clip the source rectangle to the source surface */
   1.798 +    if (srcrect) {
   1.799 +        int maxw, maxh;
   1.800  
   1.801 -		srcy = srcrect->y;
   1.802 -		h = srcrect->h;
   1.803 -		if(srcy < 0) {
   1.804 -		        h += srcy;
   1.805 -			dstrect->y -= srcy;
   1.806 -			srcy = 0;
   1.807 -		}
   1.808 -		maxh = src->h - srcy;
   1.809 -		if(maxh < h)
   1.810 -			h = maxh;
   1.811 -	    
   1.812 -	} else {
   1.813 -	        srcx = srcy = 0;
   1.814 -		w = src->w;
   1.815 -		h = src->h;
   1.816 -	}
   1.817 +        srcx = srcrect->x;
   1.818 +        w = srcrect->w;
   1.819 +        if (srcx < 0) {
   1.820 +            w += srcx;
   1.821 +            dstrect->x -= srcx;
   1.822 +            srcx = 0;
   1.823 +        }
   1.824 +        maxw = src->w - srcx;
   1.825 +        if (maxw < w)
   1.826 +            w = maxw;
   1.827  
   1.828 -	/* clip the destination rectangle against the clip rectangle */
   1.829 -	{
   1.830 -	        SDL_Rect *clip = &dst->clip_rect;
   1.831 -		int dx, dy;
   1.832 +        srcy = srcrect->y;
   1.833 +        h = srcrect->h;
   1.834 +        if (srcy < 0) {
   1.835 +            h += srcy;
   1.836 +            dstrect->y -= srcy;
   1.837 +            srcy = 0;
   1.838 +        }
   1.839 +        maxh = src->h - srcy;
   1.840 +        if (maxh < h)
   1.841 +            h = maxh;
   1.842  
   1.843 -		dx = clip->x - dstrect->x;
   1.844 -		if(dx > 0) {
   1.845 -			w -= dx;
   1.846 -			dstrect->x += dx;
   1.847 -			srcx += dx;
   1.848 -		}
   1.849 -		dx = dstrect->x + w - clip->x - clip->w;
   1.850 -		if(dx > 0)
   1.851 -			w -= dx;
   1.852 +    } else {
   1.853 +        srcx = srcy = 0;
   1.854 +        w = src->w;
   1.855 +        h = src->h;
   1.856 +    }
   1.857  
   1.858 -		dy = clip->y - dstrect->y;
   1.859 -		if(dy > 0) {
   1.860 -			h -= dy;
   1.861 -			dstrect->y += dy;
   1.862 -			srcy += dy;
   1.863 -		}
   1.864 -		dy = dstrect->y + h - clip->y - clip->h;
   1.865 -		if(dy > 0)
   1.866 -			h -= dy;
   1.867 -	}
   1.868 +    /* clip the destination rectangle against the clip rectangle */
   1.869 +    {
   1.870 +        SDL_Rect *clip = &dst->clip_rect;
   1.871 +        int dx, dy;
   1.872  
   1.873 -	if(w > 0 && h > 0) {
   1.874 -	        SDL_Rect sr;
   1.875 -	        sr.x = srcx;
   1.876 -		sr.y = srcy;
   1.877 -		sr.w = dstrect->w = w;
   1.878 -		sr.h = dstrect->h = h;
   1.879 -		return SDL_LowerBlit(src, &sr, dst, dstrect);
   1.880 -	}
   1.881 -	dstrect->w = dstrect->h = 0;
   1.882 -	return 0;
   1.883 +        dx = clip->x - dstrect->x;
   1.884 +        if (dx > 0) {
   1.885 +            w -= dx;
   1.886 +            dstrect->x += dx;
   1.887 +            srcx += dx;
   1.888 +        }
   1.889 +        dx = dstrect->x + w - clip->x - clip->w;
   1.890 +        if (dx > 0)
   1.891 +            w -= dx;
   1.892 +
   1.893 +        dy = clip->y - dstrect->y;
   1.894 +        if (dy > 0) {
   1.895 +            h -= dy;
   1.896 +            dstrect->y += dy;
   1.897 +            srcy += dy;
   1.898 +        }
   1.899 +        dy = dstrect->y + h - clip->y - clip->h;
   1.900 +        if (dy > 0)
   1.901 +            h -= dy;
   1.902 +    }
   1.903 +
   1.904 +    if (w > 0 && h > 0) {
   1.905 +        SDL_Rect sr;
   1.906 +        sr.x = srcx;
   1.907 +        sr.y = srcy;
   1.908 +        sr.w = dstrect->w = w;
   1.909 +        sr.h = dstrect->h = h;
   1.910 +        return SDL_LowerBlit (src, &sr, dst, dstrect);
   1.911 +    }
   1.912 +    dstrect->w = dstrect->h = 0;
   1.913 +    return 0;
   1.914  }
   1.915  
   1.916 -static int SDL_FillRect1(SDL_Surface *dst, SDL_Rect *dstrect, Uint32 color)
   1.917 +static int
   1.918 +SDL_FillRect1 (SDL_Surface * dst, SDL_Rect * dstrect, Uint32 color)
   1.919  {
   1.920 -	/* FIXME: We have to worry about packing order.. *sigh* */
   1.921 -	SDL_SetError("1-bpp rect fill not yet implemented");
   1.922 -	return -1;
   1.923 +    /* FIXME: We have to worry about packing order.. *sigh* */
   1.924 +    SDL_SetError ("1-bpp rect fill not yet implemented");
   1.925 +    return -1;
   1.926  }
   1.927  
   1.928 -static int SDL_FillRect4(SDL_Surface *dst, SDL_Rect *dstrect, Uint32 color)
   1.929 +static int
   1.930 +SDL_FillRect4 (SDL_Surface * dst, SDL_Rect * dstrect, Uint32 color)
   1.931  {
   1.932 -	/* FIXME: We have to worry about packing order.. *sigh* */
   1.933 -	SDL_SetError("4-bpp rect fill not yet implemented");
   1.934 -	return -1;
   1.935 +    /* FIXME: We have to worry about packing order.. *sigh* */
   1.936 +    SDL_SetError ("4-bpp rect fill not yet implemented");
   1.937 +    return -1;
   1.938  }
   1.939  
   1.940  /* 
   1.941   * This function performs a fast fill of the given rectangle with 'color'
   1.942   */
   1.943 -int SDL_FillRect(SDL_Surface *dst, SDL_Rect *dstrect, Uint32 color)
   1.944 +int
   1.945 +SDL_FillRect (SDL_Surface * dst, SDL_Rect * dstrect, Uint32 color)
   1.946  {
   1.947 -	SDL_VideoDevice *video = current_video;
   1.948 -	SDL_VideoDevice *this  = current_video;
   1.949 -	int x, y;
   1.950 -	Uint8 *row;
   1.951 +    SDL_VideoDevice *_this = SDL_GetVideoDevice ();
   1.952 +    int x, y;
   1.953 +    Uint8 *row;
   1.954  
   1.955 -	/* This function doesn't work on surfaces < 8 bpp */
   1.956 -	if ( dst->format->BitsPerPixel < 8 ) {
   1.957 -		switch(dst->format->BitsPerPixel) {
   1.958 -		    case 1:
   1.959 -			return SDL_FillRect1(dst, dstrect, color);
   1.960 -			break;
   1.961 -		    case 4:
   1.962 -			return SDL_FillRect4(dst, dstrect, color);
   1.963 -			break;
   1.964 -		    default:
   1.965 -			SDL_SetError("Fill rect on unsupported surface format");
   1.966 -			return(-1);
   1.967 -			break;
   1.968 -		}
   1.969 -	}
   1.970 +    /* This function doesn't work on surfaces < 8 bpp */
   1.971 +    if (dst->format->BitsPerPixel < 8) {
   1.972 +        switch (dst->format->BitsPerPixel) {
   1.973 +        case 1:
   1.974 +            return SDL_FillRect1 (dst, dstrect, color);
   1.975 +            break;
   1.976 +        case 4:
   1.977 +            return SDL_FillRect4 (dst, dstrect, color);
   1.978 +            break;
   1.979 +        default:
   1.980 +            SDL_SetError ("Fill rect on unsupported surface format");
   1.981 +            return (-1);
   1.982 +            break;
   1.983 +        }
   1.984 +    }
   1.985  
   1.986 -	/* If 'dstrect' == NULL, then fill the whole surface */
   1.987 -	if ( dstrect ) {
   1.988 -		/* Perform clipping */
   1.989 -		if ( !SDL_IntersectRect(dstrect, &dst->clip_rect, dstrect) ) {
   1.990 -			return(0);
   1.991 -		}
   1.992 -	} else {
   1.993 -		dstrect = &dst->clip_rect;
   1.994 -	}
   1.995 +    /* If 'dstrect' == NULL, then fill the whole surface */
   1.996 +    if (dstrect) {
   1.997 +        /* Perform clipping */
   1.998 +        if (!SDL_IntersectRect (dstrect, &dst->clip_rect, dstrect)) {
   1.999 +            return (0);
  1.1000 +        }
  1.1001 +    } else {
  1.1002 +        dstrect = &dst->clip_rect;
  1.1003 +    }
  1.1004  
  1.1005 -	/* Check for hardware acceleration */
  1.1006 -	if ( ((dst->flags & SDL_HWSURFACE) == SDL_HWSURFACE) &&
  1.1007 -					video->info.blit_fill ) {
  1.1008 -		SDL_Rect hw_rect;
  1.1009 -		if ( dst == SDL_VideoSurface ) {
  1.1010 -			hw_rect = *dstrect;
  1.1011 -			hw_rect.x += current_video->offset_x;
  1.1012 -			hw_rect.y += current_video->offset_y;
  1.1013 -			dstrect = &hw_rect;
  1.1014 -		}
  1.1015 -		return(video->FillHWRect(this, dst, dstrect, color));
  1.1016 -	}
  1.1017 +    /* Check for hardware acceleration */
  1.1018 +    if (((dst->flags & SDL_HWSURFACE) == SDL_HWSURFACE) &&
  1.1019 +        _this->info.blit_fill) {
  1.1020 +        return (_this->FillHWRect (_this, dst, dstrect, color));
  1.1021 +    }
  1.1022  
  1.1023 -	/* Perform software fill */
  1.1024 -	if ( SDL_LockSurface(dst) != 0 ) {
  1.1025 -		return(-1);
  1.1026 -	}
  1.1027 -	row = (Uint8 *)dst->pixels+dstrect->y*dst->pitch+
  1.1028 -			dstrect->x*dst->format->BytesPerPixel;
  1.1029 -	if ( dst->format->palette || (color == 0) ) {
  1.1030 -		x = dstrect->w*dst->format->BytesPerPixel;
  1.1031 -		if ( !color && !((uintptr_t)row&3) && !(x&3) && !(dst->pitch&3) ) {
  1.1032 -			int n = x >> 2;
  1.1033 -			for ( y=dstrect->h; y; --y ) {
  1.1034 -				SDL_memset4(row, 0, n);
  1.1035 -				row += dst->pitch;
  1.1036 -			}
  1.1037 -		} else {
  1.1038 +    /* Perform software fill */
  1.1039 +    if (SDL_LockSurface (dst) != 0) {
  1.1040 +        return (-1);
  1.1041 +    }
  1.1042 +    row = (Uint8 *) dst->pixels + dstrect->y * dst->pitch +
  1.1043 +        dstrect->x * dst->format->BytesPerPixel;
  1.1044 +    if (dst->format->palette || (color == 0)) {
  1.1045 +        x = dstrect->w * dst->format->BytesPerPixel;
  1.1046 +        if (!color && !((uintptr_t) row & 3) && !(x & 3)
  1.1047 +            && !(dst->pitch & 3)) {
  1.1048 +            int n = x >> 2;
  1.1049 +            for (y = dstrect->h; y; --y) {
  1.1050 +                SDL_memset4 (row, 0, n);
  1.1051 +                row += dst->pitch;
  1.1052 +            }
  1.1053 +        } else {
  1.1054  #ifdef __powerpc__
  1.1055 -			/*
  1.1056 -			 * SDL_memset() on PPC (both glibc and codewarrior) uses
  1.1057 -			 * the dcbz (Data Cache Block Zero) instruction, which
  1.1058 -			 * causes an alignment exception if the destination is
  1.1059 -			 * uncachable, so only use it on software surfaces
  1.1060 -			 */
  1.1061 -			if((dst->flags & SDL_HWSURFACE) == SDL_HWSURFACE) {
  1.1062 -				if(dstrect->w >= 8) {
  1.1063 -					/*
  1.1064 -					 * 64-bit stores are probably most
  1.1065 -					 * efficient to uncached video memory
  1.1066 -					 */
  1.1067 -					double fill;
  1.1068 -					SDL_memset(&fill, color, (sizeof fill));
  1.1069 -					for(y = dstrect->h; y; y--) {
  1.1070 -						Uint8 *d = row;
  1.1071 -						unsigned n = x;
  1.1072 -						unsigned nn;
  1.1073 -						Uint8 c = color;
  1.1074 -						double f = fill;
  1.1075 -						while((unsigned long)d
  1.1076 -						      & (sizeof(double) - 1)) {
  1.1077 -							*d++ = c;
  1.1078 -							n--;
  1.1079 -						}
  1.1080 -						nn = n / (sizeof(double) * 4);
  1.1081 -						while(nn) {
  1.1082 -							((double *)d)[0] = f;
  1.1083 -							((double *)d)[1] = f;
  1.1084 -							((double *)d)[2] = f;
  1.1085 -							((double *)d)[3] = f;
  1.1086 -							d += 4*sizeof(double);
  1.1087 -							nn--;
  1.1088 -						}
  1.1089 -						n &= ~(sizeof(double) * 4 - 1);
  1.1090 -						nn = n / sizeof(double);
  1.1091 -						while(nn) {
  1.1092 -							*(double *)d = f;
  1.1093 -							d += sizeof(double);
  1.1094 -							nn--;
  1.1095 -						}
  1.1096 -						n &= ~(sizeof(double) - 1);
  1.1097 -						while(n) {
  1.1098 -							*d++ = c;
  1.1099 -							n--;
  1.1100 -						}
  1.1101 -						row += dst->pitch;
  1.1102 -					}
  1.1103 -				} else {
  1.1104 -					/* narrow boxes */
  1.1105 -					for(y = dstrect->h; y; y--) {
  1.1106 -						Uint8 *d = row;
  1.1107 -						Uint8 c = color;
  1.1108 -						int n = x;
  1.1109 -						while(n) {
  1.1110 -							*d++ = c;
  1.1111 -							n--;
  1.1112 -						}
  1.1113 -						row += dst->pitch;
  1.1114 -					}
  1.1115 -				}
  1.1116 -			} else
  1.1117 +            /*
  1.1118 +             * SDL_memset() on PPC (both glibc and codewarrior) uses
  1.1119 +             * the dcbz (Data Cache Block Zero) instruction, which
  1.1120 +             * causes an alignment exception if the destination is
  1.1121 +             * uncachable, so only use it on software surfaces
  1.1122 +             */
  1.1123 +            if ((dst->flags & SDL_HWSURFACE) == SDL_HWSURFACE) {
  1.1124 +                if (dstrect->w >= 8) {
  1.1125 +                    /*
  1.1126 +                     * 64-bit stores are probably most
  1.1127 +                     * efficient to uncached video memory
  1.1128 +                     */
  1.1129 +                    double fill;
  1.1130 +                    SDL_memset (&fill, color, (sizeof fill));
  1.1131 +                    for (y = dstrect->h; y; y--) {
  1.1132 +                        Uint8 *d = row;
  1.1133 +                        unsigned n = x;
  1.1134 +                        unsigned nn;
  1.1135 +                        Uint8 c = color;
  1.1136 +                        double f = fill;
  1.1137 +                        while ((unsigned long) d & (sizeof (double) - 1)) {
  1.1138 +                            *d++ = c;
  1.1139 +                            n--;
  1.1140 +                        }
  1.1141 +                        nn = n / (sizeof (double) * 4);
  1.1142 +                        while (nn) {
  1.1143 +                            ((double *) d)[0] = f;
  1.1144 +                            ((double *) d)[1] = f;
  1.1145 +                            ((double *) d)[2] = f;
  1.1146 +                            ((double *) d)[3] = f;
  1.1147 +                            d += 4 * sizeof (double);
  1.1148 +                            nn--;
  1.1149 +                        }
  1.1150 +                        n &= ~(sizeof (double) * 4 - 1);
  1.1151 +                        nn = n / sizeof (double);
  1.1152 +                        while (nn) {
  1.1153 +                            *(double *) d = f;
  1.1154 +                            d += sizeof (double);
  1.1155 +                            nn--;
  1.1156 +                        }
  1.1157 +                        n &= ~(sizeof (double) - 1);
  1.1158 +                        while (n) {
  1.1159 +                            *d++ = c;
  1.1160 +                            n--;
  1.1161 +                        }
  1.1162 +                        row += dst->pitch;
  1.1163 +                    }
  1.1164 +                } else {
  1.1165 +                    /* narrow boxes */
  1.1166 +                    for (y = dstrect->h; y; y--) {
  1.1167 +                        Uint8 *d = row;
  1.1168 +                        Uint8 c = color;
  1.1169 +                        int n = x;
  1.1170 +                        while (n) {
  1.1171 +                            *d++ = c;
  1.1172 +                            n--;
  1.1173 +                        }
  1.1174 +                        row += dst->pitch;
  1.1175 +                    }
  1.1176 +                }
  1.1177 +            } else
  1.1178  #endif /* __powerpc__ */
  1.1179 -			{
  1.1180 -				for(y = dstrect->h; y; y--) {
  1.1181 -					SDL_memset(row, color, x);
  1.1182 -					row += dst->pitch;
  1.1183 -				}
  1.1184 -			}
  1.1185 -		}
  1.1186 -	} else {
  1.1187 -		switch (dst->format->BytesPerPixel) {
  1.1188 -		    case 2:
  1.1189 -			for ( y=dstrect->h; y; --y ) {
  1.1190 -				Uint16 *pixels = (Uint16 *)row;
  1.1191 -				Uint16 c = (Uint16)color;
  1.1192 -				Uint32 cc = (Uint32)c << 16 | c;
  1.1193 -				int n = dstrect->w;
  1.1194 -				if((uintptr_t)pixels & 3) {
  1.1195 -					*pixels++ = c;
  1.1196 -					n--;
  1.1197 -				}
  1.1198 -				if(n >> 1)
  1.1199 -					SDL_memset4(pixels, cc, n >> 1);
  1.1200 -				if(n & 1)
  1.1201 -					pixels[n - 1] = c;
  1.1202 -				row += dst->pitch;
  1.1203 -			}
  1.1204 -			break;
  1.1205 +            {
  1.1206 +                for (y = dstrect->h; y; y--) {
  1.1207 +                    SDL_memset (row, color, x);
  1.1208 +                    row += dst->pitch;
  1.1209 +                }
  1.1210 +            }
  1.1211 +        }
  1.1212 +    } else {
  1.1213 +        switch (dst->format->BytesPerPixel) {
  1.1214 +        case 2:
  1.1215 +            for (y = dstrect->h; y; --y) {
  1.1216 +                Uint16 *pixels = (Uint16 *) row;
  1.1217 +                Uint16 c = (Uint16) color;
  1.1218 +                Uint32 cc = (Uint32) c << 16 | c;
  1.1219 +                int n = dstrect->w;
  1.1220 +                if ((uintptr_t) pixels & 3) {
  1.1221 +                    *pixels++ = c;
  1.1222 +                    n--;
  1.1223 +                }
  1.1224 +                if (n >> 1)
  1.1225 +                    SDL_memset4 (pixels, cc, n >> 1);
  1.1226 +                if (n & 1)
  1.1227 +                    pixels[n - 1] = c;
  1.1228 +                row += dst->pitch;
  1.1229 +            }
  1.1230 +            break;
  1.1231  
  1.1232 -		    case 3:
  1.1233 -			#if SDL_BYTEORDER == SDL_BIG_ENDIAN
  1.1234 -				color <<= 8;
  1.1235 -			#endif
  1.1236 -			for ( y=dstrect->h; y; --y ) {
  1.1237 -				Uint8 *pixels = row;
  1.1238 -				for ( x=dstrect->w; x; --x ) {
  1.1239 -					SDL_memcpy(pixels, &color, 3);
  1.1240 -					pixels += 3;
  1.1241 -				}
  1.1242 -				row += dst->pitch;
  1.1243 -			}
  1.1244 -			break;
  1.1245 +        case 3:
  1.1246 +#if SDL_BYTEORDER == SDL_BIG_ENDIAN
  1.1247 +            color <<= 8;
  1.1248 +#endif
  1.1249 +            for (y = dstrect->h; y; --y) {
  1.1250 +                Uint8 *pixels = row;
  1.1251 +                for (x = dstrect->w; x; --x) {
  1.1252 +                    SDL_memcpy (pixels, &color, 3);
  1.1253 +                    pixels += 3;
  1.1254 +                }
  1.1255 +                row += dst->pitch;
  1.1256 +            }
  1.1257 +            break;
  1.1258  
  1.1259 -		    case 4:
  1.1260 -			for(y = dstrect->h; y; --y) {
  1.1261 -				SDL_memset4(row, color, dstrect->w);
  1.1262 -				row += dst->pitch;
  1.1263 -			}
  1.1264 -			break;
  1.1265 -		}
  1.1266 -	}
  1.1267 -	SDL_UnlockSurface(dst);
  1.1268 +        case 4:
  1.1269 +            for (y = dstrect->h; y; --y) {
  1.1270 +                SDL_memset4 (row, color, dstrect->w);
  1.1271 +                row += dst->pitch;
  1.1272 +            }
  1.1273 +            break;
  1.1274 +        }
  1.1275 +    }
  1.1276 +    SDL_UnlockSurface (dst);
  1.1277  
  1.1278 -	/* We're done! */
  1.1279 -	return(0);
  1.1280 +    /* We're done! */
  1.1281 +    return (0);
  1.1282  }
  1.1283  
  1.1284  /*
  1.1285   * Lock a surface to directly access the pixels
  1.1286   */
  1.1287 -int SDL_LockSurface (SDL_Surface *surface)
  1.1288 +int
  1.1289 +SDL_LockSurface (SDL_Surface * surface)
  1.1290  {
  1.1291 -	if ( ! surface->locked ) {
  1.1292 -		/* Perform the lock */
  1.1293 -		if ( surface->flags & (SDL_HWSURFACE|SDL_ASYNCBLIT) ) {
  1.1294 -			SDL_VideoDevice *video = current_video;
  1.1295 -			SDL_VideoDevice *this  = current_video;
  1.1296 -			if ( video->LockHWSurface(this, surface) < 0 ) {
  1.1297 -				return(-1);
  1.1298 -			}
  1.1299 -		}
  1.1300 -		if ( surface->flags & SDL_RLEACCEL ) {
  1.1301 -			SDL_UnRLESurface(surface, 1);
  1.1302 -			surface->flags |= SDL_RLEACCEL;	/* save accel'd state */
  1.1303 -		}
  1.1304 -		/* This needs to be done here in case pixels changes value */
  1.1305 -		surface->pixels = (Uint8 *)surface->pixels + surface->offset;
  1.1306 -	}
  1.1307 +    if (!surface->locked) {
  1.1308 +        /* Perform the lock */
  1.1309 +        if (surface->flags & SDL_HWSURFACE) {
  1.1310 +            SDL_VideoDevice *_this = SDL_GetVideoDevice ();
  1.1311 +            if (_this->LockHWSurface (_this, surface) < 0) {
  1.1312 +                return (-1);
  1.1313 +            }
  1.1314 +        }
  1.1315 +        if (surface->flags & SDL_RLEACCEL) {
  1.1316 +            SDL_UnRLESurface (surface, 1);
  1.1317 +            surface->flags |= SDL_RLEACCEL;     /* save accel'd state */
  1.1318 +        }
  1.1319 +        /* This needs to be done here in case pixels changes value */
  1.1320 +        surface->pixels = (Uint8 *) surface->pixels + surface->offset;
  1.1321 +    }
  1.1322  
  1.1323 -	/* Increment the surface lock count, for recursive locks */
  1.1324 -	++surface->locked;
  1.1325 +    /* Increment the surface lock count, for recursive locks */
  1.1326 +    ++surface->locked;
  1.1327  
  1.1328 -	/* Ready to go.. */
  1.1329 -	return(0);
  1.1330 +    /* Ready to go.. */
  1.1331 +    return (0);
  1.1332  }
  1.1333 +
  1.1334  /*
  1.1335   * Unlock a previously locked surface
  1.1336   */
  1.1337 -void SDL_UnlockSurface (SDL_Surface *surface)
  1.1338 +void
  1.1339 +SDL_UnlockSurface (SDL_Surface * surface)
  1.1340  {
  1.1341 -	/* Only perform an unlock if we are locked */
  1.1342 -	if ( ! surface->locked || (--surface->locked > 0) ) {
  1.1343 -		return;
  1.1344 -	}
  1.1345 +    /* Only perform an unlock if we are locked */
  1.1346 +    if (!surface->locked || (--surface->locked > 0)) {
  1.1347 +        return;
  1.1348 +    }
  1.1349  
  1.1350 -	/* Perform the unlock */
  1.1351 -	surface->pixels = (Uint8 *)surface->pixels - surface->offset;
  1.1352 +    /* Perform the unlock */
  1.1353 +    surface->pixels = (Uint8 *) surface->pixels - surface->offset;
  1.1354  
  1.1355 -	/* Unlock hardware or accelerated surfaces */
  1.1356 -	if ( surface->flags & (SDL_HWSURFACE|SDL_ASYNCBLIT) ) {
  1.1357 -		SDL_VideoDevice *video = current_video;
  1.1358 -		SDL_VideoDevice *this  = current_video;
  1.1359 -		video->UnlockHWSurface(this, surface);
  1.1360 -	} else {
  1.1361 -		/* Update RLE encoded surface with new data */
  1.1362 -		if ( (surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL ) {
  1.1363 -		        surface->flags &= ~SDL_RLEACCEL; /* stop lying */
  1.1364 -			SDL_RLESurface(surface);
  1.1365 -		}
  1.1366 -	}
  1.1367 +    /* Unlock hardware or accelerated surfaces */
  1.1368 +    if (surface->flags & SDL_HWSURFACE) {
  1.1369 +        SDL_VideoDevice *_this = SDL_GetVideoDevice ();
  1.1370 +        _this->UnlockHWSurface (_this, surface);
  1.1371 +    } else {
  1.1372 +        /* Update RLE encoded surface with new data */
  1.1373 +        if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) {
  1.1374 +            surface->flags &= ~SDL_RLEACCEL;    /* stop lying */
  1.1375 +            SDL_RLESurface (surface);
  1.1376 +        }
  1.1377 +    }
  1.1378  }
  1.1379  
  1.1380  /* 
  1.1381   * Convert a surface into the specified pixel format.
  1.1382   */
  1.1383 -SDL_Surface * SDL_ConvertSurface (SDL_Surface *surface,
  1.1384 -					SDL_PixelFormat *format, Uint32 flags)
  1.1385 +SDL_Surface *
  1.1386 +SDL_ConvertSurface (SDL_Surface * surface,
  1.1387 +                    SDL_PixelFormat * format, Uint32 flags)
  1.1388  {
  1.1389 -	SDL_Surface *convert;
  1.1390 -	Uint32 colorkey = 0;
  1.1391 -	Uint8 alpha = 0;
  1.1392 -	Uint32 surface_flags;
  1.1393 -	SDL_Rect bounds;
  1.1394 +    SDL_Surface *convert;
  1.1395 +    Uint32 colorkey = 0;
  1.1396 +    Uint8 alpha = 0;
  1.1397 +    Uint32 surface_flags;
  1.1398 +    SDL_Rect bounds;
  1.1399  
  1.1400 -	/* Check for empty destination palette! (results in empty image) */
  1.1401 -	if ( format->palette != NULL ) {
  1.1402 -		int i;
  1.1403 -		for ( i=0; i<format->palette->ncolors; ++i ) {
  1.1404 -			if ( (format->palette->colors[i].r != 0) ||
  1.1405 -			     (format->palette->colors[i].g != 0) ||
  1.1406 -			     (format->palette->colors[i].b != 0) )
  1.1407 -				break;
  1.1408 -		}
  1.1409 -		if ( i == format->palette->ncolors ) {
  1.1410 -			SDL_SetError("Empty destination palette");
  1.1411 -			return(NULL);
  1.1412 -		}
  1.1413 -	}
  1.1414 +    /* Check for empty destination palette! (results in empty image) */
  1.1415 +    if (format->palette != NULL) {
  1.1416 +        int i;
  1.1417 +        for (i = 0; i < format->palette->ncolors; ++i) {
  1.1418 +            if ((format->palette->colors[i].r != 0) ||
  1.1419 +                (format->palette->colors[i].g != 0) ||
  1.1420 +                (format->palette->colors[i].b != 0))
  1.1421 +                break;
  1.1422 +        }
  1.1423 +        if (i == format->palette->ncolors) {
  1.1424 +            SDL_SetError ("Empty destination palette");
  1.1425 +            return (NULL);
  1.1426 +        }
  1.1427 +    }
  1.1428  
  1.1429 -	/* Only create hw surfaces with alpha channel if hw alpha blits
  1.1430 -	   are supported */
  1.1431 -	if(format->Amask != 0 && (flags & SDL_HWSURFACE)) {
  1.1432 -		const SDL_VideoInfo *vi = SDL_GetVideoInfo();
  1.1433 -		if(!vi || !vi->blit_hw_A)
  1.1434 -			flags &= ~SDL_HWSURFACE;
  1.1435 -	}
  1.1436 +    /* Only create hw surfaces with alpha channel if hw alpha blits
  1.1437 +       are supported */
  1.1438 +    if (format->Amask != 0 && (flags & SDL_HWSURFACE)) {
  1.1439 +        const SDL_VideoInfo *vi = SDL_GetVideoInfo ();
  1.1440 +        if (!vi || !vi->blit_hw_A)
  1.1441 +            flags &= ~SDL_HWSURFACE;
  1.1442 +    }
  1.1443  
  1.1444 -	/* Create a new surface with the desired format */
  1.1445 -	convert = SDL_CreateRGBSurface(flags,
  1.1446 -				surface->w, surface->h, format->BitsPerPixel,
  1.1447 -		format->Rmask, format->Gmask, format->Bmask, format->Amask);
  1.1448 -	if ( convert == NULL ) {
  1.1449 -		return(NULL);
  1.1450 -	}
  1.1451 +    /* Create a new surface with the desired format */
  1.1452 +    convert = SDL_CreateRGBSurface (flags,
  1.1453 +                                    surface->w, surface->h,
  1.1454 +                                    format->BitsPerPixel, format->Rmask,
  1.1455 +                                    format->Gmask, format->Bmask,
  1.1456 +                                    format->Amask);
  1.1457 +    if (convert == NULL) {
  1.1458 +        return (NULL);
  1.1459 +    }
  1.1460  
  1.1461 -	/* Copy the palette if any */
  1.1462 -	if ( format->palette && convert->format->palette ) {
  1.1463 -		SDL_memcpy(convert->format->palette->colors,
  1.1464 -				format->palette->colors,
  1.1465 -				format->palette->ncolors*sizeof(SDL_Color));
  1.1466 -		convert->format->palette->ncolors = format->palette->ncolors;
  1.1467 -	}
  1.1468 +    /* Copy the palette if any */
  1.1469 +    if (format->palette && convert->format->palette) {
  1.1470 +        SDL_memcpy (convert->format->palette->colors,
  1.1471 +                    format->palette->colors,
  1.1472 +                    format->palette->ncolors * sizeof (SDL_Color));
  1.1473 +        convert->format->palette->ncolors = format->palette->ncolors;
  1.1474 +    }
  1.1475  
  1.1476 -	/* Save the original surface color key and alpha */
  1.1477 -	surface_flags = surface->flags;
  1.1478 -	if ( (surface_flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY ) {
  1.1479 -		/* Convert colourkeyed surfaces to RGBA if requested */
  1.1480 -		if((flags & SDL_SRCCOLORKEY) != SDL_SRCCOLORKEY
  1.1481 -		   && format->Amask) {
  1.1482 -			surface_flags &= ~SDL_SRCCOLORKEY;
  1.1483 -		} else {
  1.1484 -			colorkey = surface->format->colorkey;
  1.1485 -			SDL_SetColorKey(surface, 0, 0);
  1.1486 -		}
  1.1487 -	}
  1.1488 -	if ( (surface_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {
  1.1489 -		/* Copy over the alpha channel to RGBA if requested */
  1.1490 -		if ( format->Amask ) {
  1.1491 -			surface->flags &= ~SDL_SRCALPHA;
  1.1492 -		} else {
  1.1493 -			alpha = surface->format->alpha;
  1.1494 -			SDL_SetAlpha(surface, 0, 0);
  1.1495 -		}
  1.1496 -	}
  1.1497 +    /* Save the original surface color key and alpha */
  1.1498 +    surface_flags = surface->flags;
  1.1499 +    if ((surface_flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) {
  1.1500 +        /* Convert colourkeyed surfaces to RGBA if requested */
  1.1501 +        if ((flags & SDL_SRCCOLORKEY) != SDL_SRCCOLORKEY && format->Amask) {
  1.1502 +            surface_flags &= ~SDL_SRCCOLORKEY;
  1.1503 +        } else {
  1.1504 +            colorkey = surface->format->colorkey;
  1.1505 +            SDL_SetColorKey (surface, 0, 0);
  1.1506 +        }
  1.1507 +    }
  1.1508 +    if ((surface_flags & SDL_SRCALPHA) == SDL_SRCALPHA) {
  1.1509 +        /* Copy over the alpha channel to RGBA if requested */
  1.1510 +        if (format->Amask) {
  1.1511 +            surface->flags &= ~SDL_SRCALPHA;
  1.1512 +        } else {
  1.1513 +            alpha = surface->format->alpha;
  1.1514 +            SDL_SetAlpha (surface, 0, 0);
  1.1515 +        }
  1.1516 +    }
  1.1517  
  1.1518 -	/* Copy over the image data */
  1.1519 -	bounds.x = 0;
  1.1520 -	bounds.y = 0;
  1.1521 -	bounds.w = surface->w;
  1.1522 -	bounds.h = surface->h;
  1.1523 -	SDL_LowerBlit(surface, &bounds, convert, &bounds);
  1.1524 +    /* Copy over the image data */
  1.1525 +    bounds.x = 0;
  1.1526 +    bounds.y = 0;
  1.1527 +    bounds.w = surface->w;
  1.1528 +    bounds.h = surface->h;
  1.1529 +    SDL_LowerBlit (surface, &bounds, convert, &bounds);
  1.1530  
  1.1531 -	/* Clean up the original surface, and update converted surface */
  1.1532 -	if ( convert != NULL ) {
  1.1533 -		SDL_SetClipRect(convert, &surface->clip_rect);
  1.1534 -	}
  1.1535 -	if ( (surface_flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY ) {
  1.1536 -		Uint32 cflags = surface_flags&(SDL_SRCCOLORKEY|SDL_RLEACCELOK);
  1.1537 -		if ( convert != NULL ) {
  1.1538 -			Uint8 keyR, keyG, keyB;
  1.1539 +    /* Clean up the original surface, and update converted surface */
  1.1540 +    if (convert != NULL) {
  1.1541 +        SDL_SetClipRect (convert, &surface->clip_rect);
  1.1542 +    }
  1.1543 +    if ((surface_flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) {
  1.1544 +        Uint32 cflags = surface_flags & (SDL_SRCCOLORKEY | SDL_RLEACCELOK);
  1.1545 +        if (convert != NULL) {
  1.1546 +            Uint8 keyR, keyG, keyB;
  1.1547  
  1.1548 -			SDL_GetRGB(colorkey,surface->format,&keyR,&keyG,&keyB);
  1.1549 -			SDL_SetColorKey(convert, cflags|(flags&SDL_RLEACCELOK),
  1.1550 -				SDL_MapRGB(convert->format, keyR, keyG, keyB));
  1.1551 -		}
  1.1552 -		SDL_SetColorKey(surface, cflags, colorkey);
  1.1553 -	}
  1.1554 -	if ( (surface_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {
  1.1555 -		Uint32 aflags = surface_flags&(SDL_SRCALPHA|SDL_RLEACCELOK);
  1.1556 -		if ( convert != NULL ) {
  1.1557 -		        SDL_SetAlpha(convert, aflags|(flags&SDL_RLEACCELOK),
  1.1558 -				alpha);
  1.1559 -		}
  1.1560 -		if ( format->Amask ) {
  1.1561 -			surface->flags |= SDL_SRCALPHA;
  1.1562 -		} else {
  1.1563 -			SDL_SetAlpha(surface, aflags, alpha);
  1.1564 -		}
  1.1565 -	}
  1.1566 +            SDL_GetRGB (colorkey, surface->format, &keyR, &keyG, &keyB);
  1.1567 +            SDL_SetColorKey (convert, cflags | (flags & SDL_RLEACCELOK),
  1.1568 +                             SDL_MapRGB (convert->format, keyR, keyG, keyB));
  1.1569 +        }
  1.1570 +        SDL_SetColorKey (surface, cflags, colorkey);
  1.1571 +    }
  1.1572 +    if ((surface_flags & SDL_SRCALPHA) == SDL_SRCALPHA) {
  1.1573 +        Uint32 aflags = surface_flags & (SDL_SRCALPHA | SDL_RLEACCELOK);
  1.1574 +        if (convert != NULL) {
  1.1575 +            SDL_SetAlpha (convert, aflags | (flags & SDL_RLEACCELOK), alpha);
  1.1576 +        }
  1.1577 +        if (format->Amask) {
  1.1578 +            surface->flags |= SDL_SRCALPHA;
  1.1579 +        } else {
  1.1580 +            SDL_SetAlpha (surface, aflags, alpha);
  1.1581 +        }
  1.1582 +    }
  1.1583  
  1.1584 -	/* We're ready to go! */
  1.1585 -	return(convert);
  1.1586 +    /* We're ready to go! */
  1.1587 +    return (convert);
  1.1588  }
  1.1589  
  1.1590  /*
  1.1591   * Free a surface created by the above function.
  1.1592   */
  1.1593 -void SDL_FreeSurface (SDL_Surface *surface)
  1.1594 +void
  1.1595 +SDL_FreeSurface (SDL_Surface * surface)
  1.1596  {
  1.1597 -	/* Free anything that's not NULL, and not the screen surface */
  1.1598 -	if ((surface == NULL) ||
  1.1599 -	    (current_video &&
  1.1600 -	    ((surface == SDL_ShadowSurface)||(surface == SDL_VideoSurface)))) {
  1.1601 -		return;
  1.1602 -	}
  1.1603 -	if ( --surface->refcount > 0 ) {
  1.1604 -		return;
  1.1605 -	}
  1.1606 -	while ( surface->locked > 0 ) {
  1.1607 -		SDL_UnlockSurface(surface);
  1.1608 -	}
  1.1609 -	if ( (surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL ) {
  1.1610 -	        SDL_UnRLESurface(surface, 0);
  1.1611 -	}
  1.1612 -	if ( surface->format ) {
  1.1613 -		SDL_FreeFormat(surface->format);
  1.1614 -		surface->format = NULL;
  1.1615 -	}
  1.1616 -	if ( surface->map != NULL ) {
  1.1617 -		SDL_FreeBlitMap(surface->map);
  1.1618 -		surface->map = NULL;
  1.1619 -	}
  1.1620 -	if ( surface->hwdata ) {
  1.1621 -		SDL_VideoDevice *video = current_video;
  1.1622 -		SDL_VideoDevice *this  = current_video;
  1.1623 -		video->FreeHWSurface(this, surface);
  1.1624 -	}
  1.1625 -	if ( surface->pixels &&
  1.1626 -	     ((surface->flags & SDL_PREALLOC) != SDL_PREALLOC) ) {
  1.1627 -		SDL_free(surface->pixels);
  1.1628 -	}
  1.1629 -	SDL_free(surface);
  1.1630 +    SDL_VideoDevice *_this = SDL_GetVideoDevice ();
  1.1631 +
  1.1632 +    /* Free anything that's not NULL, and not the screen surface */
  1.1633 +    if ((surface == NULL) ||
  1.1634 +        (_this &&
  1.1635 +         ((surface == SDL_ShadowSurface) || (surface == SDL_VideoSurface)))) {
  1.1636 +        return;
  1.1637 +    }
  1.1638 +    if (--surface->refcount > 0) {
  1.1639 +        return;
  1.1640 +    }
  1.1641 +    while (surface->locked > 0) {
  1.1642 +        SDL_UnlockSurface (surface);
  1.1643 +    }
  1.1644 +    if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) {
  1.1645 +        SDL_UnRLESurface (surface, 0);
  1.1646 +    }
  1.1647 +    if (surface->format) {
  1.1648 +        SDL_FreeFormat (surface->format);
  1.1649 +        surface->format = NULL;
  1.1650 +    }
  1.1651 +    if (surface->map != NULL) {
  1.1652 +        SDL_FreeBlitMap (surface->map);
  1.1653 +        surface->map = NULL;
  1.1654 +    }
  1.1655 +    if (surface->hwdata) {
  1.1656 +        SDL_VideoDevice *_this = SDL_GetVideoDevice ();
  1.1657 +        _this->FreeHWSurface (_this, surface);
  1.1658 +    }
  1.1659 +    if (surface->pixels && ((surface->flags & SDL_PREALLOC) != SDL_PREALLOC)) {
  1.1660 +        SDL_free (surface->pixels);
  1.1661 +    }
  1.1662 +    SDL_free (surface);
  1.1663  #ifdef CHECK_LEAKS
  1.1664 -	--surfaces_allocated;
  1.1665 +    --surfaces_allocated;
  1.1666  #endif
  1.1667  }
  1.1668 +
  1.1669 +/* vi: set ts=4 sw=4 expandtab: */