test/testwin.c
branchSDL-1.3
changeset 1662 782fd950bd46
parent 1659 14717b52abc0
child 1668 4da1ee79c9af
     1.1 --- a/test/testwin.c	Sun May 21 17:27:13 2006 +0000
     1.2 +++ b/test/testwin.c	Sun May 28 13:04:16 2006 +0000
     1.3 @@ -12,366 +12,344 @@
     1.4  #include "SDL.h"
     1.5  
     1.6  /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
     1.7 -static void quit(int rc)
     1.8 +static void
     1.9 +quit (int rc)
    1.10  {
    1.11 -	SDL_Quit();
    1.12 -	exit(rc);
    1.13 +    SDL_Quit ();
    1.14 +    exit (rc);
    1.15  }
    1.16  
    1.17 -void DrawPict(SDL_Surface *screen, char *bmpfile,
    1.18 -					int speedy, int flip, int nofade)
    1.19 +void
    1.20 +DrawPict (SDL_Surface * screen, char *bmpfile,
    1.21 +          int speedy, int flip, int nofade)
    1.22  {
    1.23 -	SDL_Surface *picture;
    1.24 -	SDL_Rect dest, update;
    1.25 -	int i, centered;
    1.26 -	int ncolors;
    1.27 -	SDL_Color *colors, *cmap;
    1.28 +    SDL_Surface *picture;
    1.29 +    SDL_Rect dest, update;
    1.30 +    int i, centered;
    1.31 +    int ncolors;
    1.32 +    SDL_Color *colors, *cmap;
    1.33  
    1.34 -	/* Load the image into a surface */
    1.35 -	if ( bmpfile == NULL ) {
    1.36 -		bmpfile = "sample.bmp";		/* Sample image */
    1.37 -	}
    1.38 -fprintf(stderr, "Loading picture: %s\n", bmpfile);
    1.39 -	picture = SDL_LoadBMP(bmpfile);
    1.40 -	if ( picture == NULL ) {
    1.41 -		fprintf(stderr, "Couldn't load %s: %s\n", bmpfile,
    1.42 -							SDL_GetError());
    1.43 -		return;
    1.44 -	}
    1.45 +    /* Load the image into a surface */
    1.46 +    if (bmpfile == NULL) {
    1.47 +        bmpfile = "sample.bmp"; /* Sample image */
    1.48 +    }
    1.49 +    fprintf (stderr, "Loading picture: %s\n", bmpfile);
    1.50 +    picture = SDL_LoadBMP (bmpfile);
    1.51 +    if (picture == NULL) {
    1.52 +        fprintf (stderr, "Couldn't load %s: %s\n", bmpfile, SDL_GetError ());
    1.53 +        return;
    1.54 +    }
    1.55  
    1.56 -	/* Set the display colors -- on a hicolor display this is a no-op */
    1.57 -	if ( picture->format->palette ) {
    1.58 -		ncolors = picture->format->palette->ncolors;
    1.59 -		colors  = (SDL_Color *)malloc(ncolors*sizeof(SDL_Color));
    1.60 -		cmap    = (SDL_Color *)malloc(ncolors*sizeof(SDL_Color));
    1.61 -		memcpy(colors, picture->format->palette->colors,
    1.62 -						ncolors*sizeof(SDL_Color));
    1.63 -	} else {
    1.64 -		int       r, g, b;
    1.65 +    /* Set the display colors -- on a hicolor display this is a no-op */
    1.66 +    if (picture->format->palette) {
    1.67 +        ncolors = picture->format->palette->ncolors;
    1.68 +        colors = (SDL_Color *) malloc (ncolors * sizeof (SDL_Color));
    1.69 +        cmap = (SDL_Color *) malloc (ncolors * sizeof (SDL_Color));
    1.70 +        memcpy (colors, picture->format->palette->colors,
    1.71 +                ncolors * sizeof (SDL_Color));
    1.72 +    } else {
    1.73 +        int r, g, b;
    1.74  
    1.75 -		/* Allocate 256 color palette */
    1.76 -		ncolors = 256;
    1.77 -		colors  = (SDL_Color *)malloc(ncolors*sizeof(SDL_Color));
    1.78 -		cmap    = (SDL_Color *)malloc(ncolors*sizeof(SDL_Color));
    1.79 +        /* Allocate 256 color palette */
    1.80 +        ncolors = 256;
    1.81 +        colors = (SDL_Color *) malloc (ncolors * sizeof (SDL_Color));
    1.82 +        cmap = (SDL_Color *) malloc (ncolors * sizeof (SDL_Color));
    1.83  
    1.84 -		/* Set a 3,3,2 color cube */
    1.85 -		for ( r=0; r<8; ++r ) {
    1.86 -			for ( g=0; g<8; ++g ) {
    1.87 -				for ( b=0; b<4; ++b ) {
    1.88 -					i = ((r<<5)|(g<<2)|b);
    1.89 -					colors[i].r = r<<5;
    1.90 -					colors[i].g = g<<5;
    1.91 -					colors[i].b = b<<6;
    1.92 -				}
    1.93 -			}
    1.94 -		}
    1.95 -	}
    1.96 -NOTICE("testwin: setting colors\n");
    1.97 -	if ( ! SDL_SetColors(screen, colors, 0, ncolors) &&
    1.98 -				(screen->format->palette != NULL) ) {
    1.99 -		fprintf(stderr,
   1.100 -"Warning: Couldn't set all of the colors, but SDL will map the image\n"
   1.101 -"         (colormap fading will suffer - try the -warp option)\n"
   1.102 -		);
   1.103 -	}
   1.104 +        /* Set a 3,3,2 color cube */
   1.105 +        for (r = 0; r < 8; ++r) {
   1.106 +            for (g = 0; g < 8; ++g) {
   1.107 +                for (b = 0; b < 4; ++b) {
   1.108 +                    i = ((r << 5) | (g << 2) | b);
   1.109 +                    colors[i].r = r << 5;
   1.110 +                    colors[i].g = g << 5;
   1.111 +                    colors[i].b = b << 6;
   1.112 +                }
   1.113 +            }
   1.114 +        }
   1.115 +    }
   1.116 +    NOTICE ("testwin: setting colors\n");
   1.117 +    if (!SDL_SetColors (screen, colors, 0, ncolors) &&
   1.118 +        (screen->format->palette != NULL)) {
   1.119 +        fprintf (stderr,
   1.120 +                 "Warning: Couldn't set all of the colors, but SDL will map the image\n"
   1.121 +                 "         (colormap fading will suffer - try the -warp option)\n");
   1.122 +    }
   1.123  
   1.124 -	/* Set the screen to black (not really necessary) */
   1.125 -	if ( SDL_LockSurface(screen) == 0 ) {
   1.126 -		Uint32 black;
   1.127 -		Uint8 *pixels;
   1.128 +    /* Set the screen to black (not really necessary) */
   1.129 +    if (SDL_LockSurface (screen) == 0) {
   1.130 +        Uint32 black;
   1.131 +        Uint8 *pixels;
   1.132  
   1.133 -		black = SDL_MapRGB(screen->format, 0, 0, 0);
   1.134 -		pixels = (Uint8 *)screen->pixels;
   1.135 -		for ( i=0; i<screen->h; ++i ) {
   1.136 -			memset(pixels, black,
   1.137 -				screen->w*screen->format->BytesPerPixel);
   1.138 -			pixels += screen->pitch;
   1.139 -		}
   1.140 -		SDL_UnlockSurface(screen);
   1.141 -		SDL_UpdateRect(screen, 0, 0, 0, 0);
   1.142 -	}
   1.143 -	
   1.144 -	/* Display the picture */
   1.145 -	if ( speedy ) {
   1.146 -		SDL_Surface *displayfmt;
   1.147 +        black = SDL_MapRGB (screen->format, 0, 0, 0);
   1.148 +        pixels = (Uint8 *) screen->pixels;
   1.149 +        for (i = 0; i < screen->h; ++i) {
   1.150 +            memset (pixels, black, screen->w * screen->format->BytesPerPixel);
   1.151 +            pixels += screen->pitch;
   1.152 +        }
   1.153 +        SDL_UnlockSurface (screen);
   1.154 +        SDL_UpdateRect (screen, 0, 0, 0, 0);
   1.155 +    }
   1.156  
   1.157 -fprintf(stderr, "Converting picture\n");
   1.158 -		displayfmt = SDL_DisplayFormat(picture);
   1.159 -		if ( displayfmt == NULL ) {
   1.160 -			fprintf(stderr,
   1.161 -				"Couldn't convert image: %s\n", SDL_GetError());
   1.162 -			goto done;
   1.163 -		}
   1.164 -		SDL_FreeSurface(picture);
   1.165 -		picture = displayfmt;
   1.166 -	}
   1.167 -	printf("(image surface located in %s memory)\n", 
   1.168 -			(picture->flags&SDL_HWSURFACE) ? "video" : "system");
   1.169 -	centered = (screen->w - picture->w)/2;
   1.170 -	if ( centered < 0 ) {
   1.171 -		centered = 0;
   1.172 -	}
   1.173 -	dest.y = (screen->h - picture->h)/2;
   1.174 -	dest.w = picture->w;
   1.175 -	dest.h = picture->h;
   1.176 -NOTICE("testwin: moving image\n");
   1.177 -	for ( i=0; i<=centered; ++i ) {
   1.178 -		dest.x = i;
   1.179 -		update = dest;
   1.180 -		if ( SDL_BlitSurface(picture, NULL, screen, &update) < 0 ) {
   1.181 -			fprintf(stderr, "Blit failed: %s\n", SDL_GetError());
   1.182 -			break;
   1.183 -		}
   1.184 -		if ( flip ) {
   1.185 -			SDL_Flip(screen);
   1.186 -		} else {
   1.187 -			SDL_UpdateRects(screen, 1, &update);
   1.188 -		}
   1.189 -	}
   1.190 +    /* Display the picture */
   1.191 +    if (speedy) {
   1.192 +        SDL_Surface *displayfmt;
   1.193 +
   1.194 +        fprintf (stderr, "Converting picture\n");
   1.195 +        displayfmt = SDL_DisplayFormat (picture);
   1.196 +        if (displayfmt == NULL) {
   1.197 +            fprintf (stderr, "Couldn't convert image: %s\n", SDL_GetError ());
   1.198 +            goto done;
   1.199 +        }
   1.200 +        SDL_FreeSurface (picture);
   1.201 +        picture = displayfmt;
   1.202 +    }
   1.203 +    printf ("(image surface located in %s memory)\n",
   1.204 +            (picture->flags & SDL_HWSURFACE) ? "video" : "system");
   1.205 +    centered = (screen->w - picture->w) / 2;
   1.206 +    if (centered < 0) {
   1.207 +        centered = 0;
   1.208 +    }
   1.209 +    dest.y = (screen->h - picture->h) / 2;
   1.210 +    dest.w = picture->w;
   1.211 +    dest.h = picture->h;
   1.212 +    NOTICE ("testwin: moving image\n");
   1.213 +    for (i = 0; i <= centered; ++i) {
   1.214 +        dest.x = i;
   1.215 +        update = dest;
   1.216 +        if (SDL_BlitSurface (picture, NULL, screen, &update) < 0) {
   1.217 +            fprintf (stderr, "Blit failed: %s\n", SDL_GetError ());
   1.218 +            break;
   1.219 +        }
   1.220 +        if (flip) {
   1.221 +            SDL_Flip (screen);
   1.222 +        } else {
   1.223 +            SDL_UpdateRects (screen, 1, &update);
   1.224 +        }
   1.225 +    }
   1.226  
   1.227  #ifdef SCREENSHOT
   1.228 -	if ( SDL_SaveBMP(screen, "screen.bmp") < 0 )
   1.229 -		printf("Couldn't save screen: %s\n", SDL_GetError());
   1.230 +    if (SDL_SaveBMP (screen, "screen.bmp") < 0)
   1.231 +        printf ("Couldn't save screen: %s\n", SDL_GetError ());
   1.232  #endif
   1.233  
   1.234  #ifndef BENCHMARK_SDL
   1.235 -	/* Let it sit there for a while */
   1.236 -	SDL_Delay(5*1000);
   1.237 +    /* Let it sit there for a while */
   1.238 +    SDL_Delay (5 * 1000);
   1.239  #endif
   1.240 -	/* Fade the colormap */
   1.241 -	if ( ! nofade ) {
   1.242 -		int maxstep;
   1.243 -		SDL_Color final;
   1.244 -		SDL_Color palcolors[256];
   1.245 -		struct {
   1.246 -			Sint16 r, g, b;
   1.247 -		} cdist[256];
   1.248 +    /* Fade the colormap */
   1.249 +    if (!nofade) {
   1.250 +        int maxstep;
   1.251 +        SDL_Color final;
   1.252 +        SDL_Color palcolors[256];
   1.253 +        struct
   1.254 +        {
   1.255 +            Sint16 r, g, b;
   1.256 +        } cdist[256];
   1.257  
   1.258 -NOTICE("testwin: fading out...\n");
   1.259 -		memcpy(cmap, colors, ncolors*sizeof(SDL_Color));
   1.260 -		maxstep = 32-1;
   1.261 -		final.r = 0xFF;
   1.262 -		final.g = 0x00;
   1.263 -		final.b = 0x00;
   1.264 -		memcpy(palcolors, colors, ncolors*sizeof(SDL_Color));
   1.265 -		for ( i=0; i<ncolors; ++i ) {
   1.266 -			cdist[i].r = final.r-palcolors[i].r;
   1.267 -			cdist[i].g = final.g-palcolors[i].g;
   1.268 -			cdist[i].b = final.b-palcolors[i].b;
   1.269 -		}
   1.270 -		for ( i=0; i<=maxstep/2; ++i ) {	/* halfway fade */
   1.271 -			int c;
   1.272 -			for ( c=0; c<ncolors; ++c ) {
   1.273 -				colors[c].r =
   1.274 -					palcolors[c].r+((cdist[c].r*i))/maxstep;
   1.275 -				colors[c].g =
   1.276 -					palcolors[c].g+((cdist[c].g*i))/maxstep;
   1.277 -				colors[c].b =
   1.278 -					palcolors[c].b+((cdist[c].b*i))/maxstep;
   1.279 -			}
   1.280 -			SDL_SetColors(screen, colors, 0, ncolors);
   1.281 -			SDL_Delay(1);
   1.282 -		}
   1.283 -		final.r = 0x00;
   1.284 -		final.g = 0x00;
   1.285 -		final.b = 0x00;
   1.286 -		memcpy(palcolors, colors, ncolors*sizeof(SDL_Color));
   1.287 -		for ( i=0; i<ncolors; ++i ) {
   1.288 -			cdist[i].r = final.r-palcolors[i].r;
   1.289 -			cdist[i].g = final.g-palcolors[i].g;
   1.290 -			cdist[i].b = final.b-palcolors[i].b;
   1.291 -		}
   1.292 -		maxstep /= 2;
   1.293 -		for ( i=0; i<=maxstep; ++i ) {		/* finish fade out */
   1.294 -			int c;
   1.295 -			for ( c=0; c<ncolors; ++c ) {
   1.296 -				colors[c].r =
   1.297 -					palcolors[c].r+((cdist[c].r*i))/maxstep;
   1.298 -				colors[c].g =
   1.299 -					palcolors[c].g+((cdist[c].g*i))/maxstep;
   1.300 -				colors[c].b =
   1.301 -					palcolors[c].b+((cdist[c].b*i))/maxstep;
   1.302 -			}
   1.303 -			SDL_SetColors(screen, colors, 0, ncolors);
   1.304 -			SDL_Delay(1);
   1.305 -		}
   1.306 -		for ( i=0; i<ncolors; ++i ) {
   1.307 -			colors[i].r = final.r;
   1.308 -			colors[i].g = final.g;
   1.309 -			colors[i].b = final.b;
   1.310 -		}
   1.311 -		SDL_SetColors(screen, colors, 0, ncolors);
   1.312 -NOTICE("testwin: fading in...\n");
   1.313 -		memcpy(palcolors, colors, ncolors*sizeof(SDL_Color));
   1.314 -		for ( i=0; i<ncolors; ++i ) {
   1.315 -			cdist[i].r = cmap[i].r-palcolors[i].r;
   1.316 -			cdist[i].g = cmap[i].g-palcolors[i].g;
   1.317 -			cdist[i].b = cmap[i].b-palcolors[i].b;
   1.318 -		}
   1.319 -		for ( i=0; i<=maxstep; ++i ) {	/* 32 step fade in */
   1.320 -			int c;
   1.321 -			for ( c=0; c<ncolors; ++c ) {
   1.322 -				colors[c].r =
   1.323 -					palcolors[c].r+((cdist[c].r*i))/maxstep;
   1.324 -				colors[c].g =
   1.325 -					palcolors[c].g+((cdist[c].g*i))/maxstep;
   1.326 -				colors[c].b =
   1.327 -					palcolors[c].b+((cdist[c].b*i))/maxstep;
   1.328 -			}
   1.329 -			SDL_SetColors(screen, colors, 0, ncolors);
   1.330 -			SDL_Delay(1);
   1.331 -		}
   1.332 -NOTICE("testwin: fading over\n");
   1.333 -	}
   1.334 -	
   1.335 -done:
   1.336 -	/* Free the picture and return */
   1.337 -	SDL_FreeSurface(picture);
   1.338 -	free(colors); free(cmap);
   1.339 -	return;
   1.340 +        NOTICE ("testwin: fading out...\n");
   1.341 +        memcpy (cmap, colors, ncolors * sizeof (SDL_Color));
   1.342 +        maxstep = 32 - 1;
   1.343 +        final.r = 0xFF;
   1.344 +        final.g = 0x00;
   1.345 +        final.b = 0x00;
   1.346 +        memcpy (palcolors, colors, ncolors * sizeof (SDL_Color));
   1.347 +        for (i = 0; i < ncolors; ++i) {
   1.348 +            cdist[i].r = final.r - palcolors[i].r;
   1.349 +            cdist[i].g = final.g - palcolors[i].g;
   1.350 +            cdist[i].b = final.b - palcolors[i].b;
   1.351 +        }
   1.352 +        for (i = 0; i <= maxstep / 2; ++i) {    /* halfway fade */
   1.353 +            int c;
   1.354 +            for (c = 0; c < ncolors; ++c) {
   1.355 +                colors[c].r = palcolors[c].r + ((cdist[c].r * i)) / maxstep;
   1.356 +                colors[c].g = palcolors[c].g + ((cdist[c].g * i)) / maxstep;
   1.357 +                colors[c].b = palcolors[c].b + ((cdist[c].b * i)) / maxstep;
   1.358 +            }
   1.359 +            SDL_SetColors (screen, colors, 0, ncolors);
   1.360 +            SDL_Delay (1);
   1.361 +        }
   1.362 +        final.r = 0x00;
   1.363 +        final.g = 0x00;
   1.364 +        final.b = 0x00;
   1.365 +        memcpy (palcolors, colors, ncolors * sizeof (SDL_Color));
   1.366 +        for (i = 0; i < ncolors; ++i) {
   1.367 +            cdist[i].r = final.r - palcolors[i].r;
   1.368 +            cdist[i].g = final.g - palcolors[i].g;
   1.369 +            cdist[i].b = final.b - palcolors[i].b;
   1.370 +        }
   1.371 +        maxstep /= 2;
   1.372 +        for (i = 0; i <= maxstep; ++i) {        /* finish fade out */
   1.373 +            int c;
   1.374 +            for (c = 0; c < ncolors; ++c) {
   1.375 +                colors[c].r = palcolors[c].r + ((cdist[c].r * i)) / maxstep;
   1.376 +                colors[c].g = palcolors[c].g + ((cdist[c].g * i)) / maxstep;
   1.377 +                colors[c].b = palcolors[c].b + ((cdist[c].b * i)) / maxstep;
   1.378 +            }
   1.379 +            SDL_SetColors (screen, colors, 0, ncolors);
   1.380 +            SDL_Delay (1);
   1.381 +        }
   1.382 +        for (i = 0; i < ncolors; ++i) {
   1.383 +            colors[i].r = final.r;
   1.384 +            colors[i].g = final.g;
   1.385 +            colors[i].b = final.b;
   1.386 +        }
   1.387 +        SDL_SetColors (screen, colors, 0, ncolors);
   1.388 +        NOTICE ("testwin: fading in...\n");
   1.389 +        memcpy (palcolors, colors, ncolors * sizeof (SDL_Color));
   1.390 +        for (i = 0; i < ncolors; ++i) {
   1.391 +            cdist[i].r = cmap[i].r - palcolors[i].r;
   1.392 +            cdist[i].g = cmap[i].g - palcolors[i].g;
   1.393 +            cdist[i].b = cmap[i].b - palcolors[i].b;
   1.394 +        }
   1.395 +        for (i = 0; i <= maxstep; ++i) {        /* 32 step fade in */
   1.396 +            int c;
   1.397 +            for (c = 0; c < ncolors; ++c) {
   1.398 +                colors[c].r = palcolors[c].r + ((cdist[c].r * i)) / maxstep;
   1.399 +                colors[c].g = palcolors[c].g + ((cdist[c].g * i)) / maxstep;
   1.400 +                colors[c].b = palcolors[c].b + ((cdist[c].b * i)) / maxstep;
   1.401 +            }
   1.402 +            SDL_SetColors (screen, colors, 0, ncolors);
   1.403 +            SDL_Delay (1);
   1.404 +        }
   1.405 +        NOTICE ("testwin: fading over\n");
   1.406 +    }
   1.407 +
   1.408 +  done:
   1.409 +    /* Free the picture and return */
   1.410 +    SDL_FreeSurface (picture);
   1.411 +    free (colors);
   1.412 +    free (cmap);
   1.413 +    return;
   1.414  }
   1.415  
   1.416 -int main(int argc, char *argv[])
   1.417 +int
   1.418 +main (int argc, char *argv[])
   1.419  {
   1.420 -	SDL_Surface *screen;
   1.421 -	/* Options */
   1.422 -	int speedy, flip, nofade;
   1.423 -	int delay;
   1.424 -	int w, h;
   1.425 -	int desired_bpp;
   1.426 -	Uint32 video_flags;
   1.427 +    SDL_Surface *screen;
   1.428 +    /* Options */
   1.429 +    int speedy, flip, nofade;
   1.430 +    int delay;
   1.431 +    int w, h;
   1.432 +    int desired_bpp;
   1.433 +    Uint32 video_flags;
   1.434  #ifdef BENCHMARK_SDL
   1.435 -	Uint32 then, now;
   1.436 +    Uint32 then, now;
   1.437  #endif
   1.438 -	/* Set default options and check command-line */
   1.439 -	speedy = 0;
   1.440 -	flip = 0;
   1.441 -	nofade = 0;
   1.442 -	delay = 1;
   1.443 +    /* Set default options and check command-line */
   1.444 +    speedy = 0;
   1.445 +    flip = 0;
   1.446 +    nofade = 0;
   1.447 +    delay = 1;
   1.448  
   1.449  #ifdef _WIN32_WCE
   1.450 -	w = 240;
   1.451 -	h = 320;
   1.452 -	desired_bpp = 8;
   1.453 -	video_flags = SDL_FULLSCREEN;
   1.454 +    w = 240;
   1.455 +    h = 320;
   1.456 +    desired_bpp = 8;
   1.457 +    video_flags = SDL_FULLSCREEN;
   1.458  #else
   1.459 -	w = 640;
   1.460 -	h = 480;
   1.461 -	desired_bpp = 0;
   1.462 -	video_flags = 0;
   1.463 +    w = 640;
   1.464 +    h = 480;
   1.465 +    desired_bpp = 0;
   1.466 +    video_flags = 0;
   1.467  #endif
   1.468 -	if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
   1.469 -		fprintf(stderr,
   1.470 -			"Couldn't initialize SDL: %s\n", SDL_GetError());
   1.471 -		return(1);
   1.472 -	}
   1.473 +    if (SDL_Init (SDL_INIT_VIDEO) < 0) {
   1.474 +        fprintf (stderr, "Couldn't initialize SDL: %s\n", SDL_GetError ());
   1.475 +        return (1);
   1.476 +    }
   1.477  
   1.478 -	while ( argc > 1 ) {
   1.479 -		if ( strcmp(argv[1], "-speedy") == 0 ) {
   1.480 -			speedy = 1;
   1.481 -			argv += 1;
   1.482 -			argc -= 1;
   1.483 -		} else
   1.484 -		if ( strcmp(argv[1], "-nofade") == 0 ) {
   1.485 -			nofade = 1;
   1.486 -			argv += 1;
   1.487 -			argc -= 1;
   1.488 -		} else
   1.489 -		if ( strcmp(argv[1], "-delay") == 0 ) {
   1.490 -			if ( argv[2] ) {
   1.491 -				delay = atoi(argv[2]);
   1.492 -				argv += 2;
   1.493 -				argc -= 2;
   1.494 -			} else {
   1.495 -				fprintf(stderr,
   1.496 -				"The -delay option requires an argument\n");
   1.497 -				quit(1);
   1.498 -			}
   1.499 -		} else
   1.500 -		if ( strcmp(argv[1], "-width") == 0 ) {
   1.501 -			if ( argv[2] && ((w = atoi(argv[2])) > 0) ) {
   1.502 -				argv += 2;
   1.503 -				argc -= 2;
   1.504 -			} else {
   1.505 -				fprintf(stderr,
   1.506 -				"The -width option requires an argument\n");
   1.507 -				quit(1);
   1.508 -			}
   1.509 -		} else
   1.510 -		if ( strcmp(argv[1], "-height") == 0 ) {
   1.511 -			if ( argv[2] && ((h = atoi(argv[2])) > 0) ) {
   1.512 -				argv += 2;
   1.513 -				argc -= 2;
   1.514 -			} else {
   1.515 -				fprintf(stderr,
   1.516 -				"The -height option requires an argument\n");
   1.517 -				quit(1);
   1.518 -			}
   1.519 -		} else
   1.520 -		if ( strcmp(argv[1], "-bpp") == 0 ) {
   1.521 -			if ( argv[2] ) {
   1.522 -				desired_bpp = atoi(argv[2]);
   1.523 -				argv += 2;
   1.524 -				argc -= 2;
   1.525 -			} else {
   1.526 -				fprintf(stderr,
   1.527 -				"The -bpp option requires an argument\n");
   1.528 -				quit(1);
   1.529 -			}
   1.530 -		} else
   1.531 -		if ( strcmp(argv[1], "-warp") == 0 ) {
   1.532 -			video_flags |= SDL_HWPALETTE;
   1.533 -			argv += 1;
   1.534 -			argc -= 1;
   1.535 -		} else
   1.536 -		if ( strcmp(argv[1], "-hw") == 0 ) {
   1.537 -			video_flags |= SDL_HWSURFACE;
   1.538 -			argv += 1;
   1.539 -			argc -= 1;
   1.540 -		} else
   1.541 -		if ( strcmp(argv[1], "-flip") == 0 ) {
   1.542 -			video_flags |= SDL_DOUBLEBUF;
   1.543 -			argv += 1;
   1.544 -			argc -= 1;
   1.545 -		} else
   1.546 -		if ( strcmp(argv[1], "-fullscreen") == 0 ) {
   1.547 -			video_flags |= SDL_FULLSCREEN;
   1.548 -			argv += 1;
   1.549 -			argc -= 1;
   1.550 -		} else
   1.551 -			break;
   1.552 -	}
   1.553 +    while (argc > 1) {
   1.554 +        if (strcmp (argv[1], "-speedy") == 0) {
   1.555 +            speedy = 1;
   1.556 +            argv += 1;
   1.557 +            argc -= 1;
   1.558 +        } else if (strcmp (argv[1], "-nofade") == 0) {
   1.559 +            nofade = 1;
   1.560 +            argv += 1;
   1.561 +            argc -= 1;
   1.562 +        } else if (strcmp (argv[1], "-delay") == 0) {
   1.563 +            if (argv[2]) {
   1.564 +                delay = atoi (argv[2]);
   1.565 +                argv += 2;
   1.566 +                argc -= 2;
   1.567 +            } else {
   1.568 +                fprintf (stderr, "The -delay option requires an argument\n");
   1.569 +                quit (1);
   1.570 +            }
   1.571 +        } else if (strcmp (argv[1], "-width") == 0) {
   1.572 +            if (argv[2] && ((w = atoi (argv[2])) > 0)) {
   1.573 +                argv += 2;
   1.574 +                argc -= 2;
   1.575 +            } else {
   1.576 +                fprintf (stderr, "The -width option requires an argument\n");
   1.577 +                quit (1);
   1.578 +            }
   1.579 +        } else if (strcmp (argv[1], "-height") == 0) {
   1.580 +            if (argv[2] && ((h = atoi (argv[2])) > 0)) {
   1.581 +                argv += 2;
   1.582 +                argc -= 2;
   1.583 +            } else {
   1.584 +                fprintf (stderr, "The -height option requires an argument\n");
   1.585 +                quit (1);
   1.586 +            }
   1.587 +        } else if (strcmp (argv[1], "-bpp") == 0) {
   1.588 +            if (argv[2]) {
   1.589 +                desired_bpp = atoi (argv[2]);
   1.590 +                argv += 2;
   1.591 +                argc -= 2;
   1.592 +            } else {
   1.593 +                fprintf (stderr, "The -bpp option requires an argument\n");
   1.594 +                quit (1);
   1.595 +            }
   1.596 +        } else if (strcmp (argv[1], "-warp") == 0) {
   1.597 +            video_flags |= SDL_HWPALETTE;
   1.598 +            argv += 1;
   1.599 +            argc -= 1;
   1.600 +        } else if (strcmp (argv[1], "-hw") == 0) {
   1.601 +            video_flags |= SDL_HWSURFACE;
   1.602 +            argv += 1;
   1.603 +            argc -= 1;
   1.604 +        } else if (strcmp (argv[1], "-flip") == 0) {
   1.605 +            video_flags |= SDL_DOUBLEBUF;
   1.606 +            argv += 1;
   1.607 +            argc -= 1;
   1.608 +        } else if (strcmp (argv[1], "-fullscreen") == 0) {
   1.609 +            video_flags |= SDL_FULLSCREEN;
   1.610 +            argv += 1;
   1.611 +            argc -= 1;
   1.612 +        } else
   1.613 +            break;
   1.614 +    }
   1.615  
   1.616 -	/* Initialize the display */
   1.617 -	screen = SDL_SetVideoMode(w, h, desired_bpp, video_flags);
   1.618 -	if ( screen == NULL ) {
   1.619 -		fprintf(stderr, "Couldn't set %dx%dx%d video mode: %s\n",
   1.620 -					w, h, desired_bpp, SDL_GetError());
   1.621 -		quit(1);
   1.622 -	}
   1.623 -	printf("Set%s %dx%dx%d mode\n",
   1.624 -			screen->flags & SDL_FULLSCREEN ? " fullscreen" : "",
   1.625 -			screen->w, screen->h, screen->format->BitsPerPixel);
   1.626 -	printf("(video surface located in %s memory)\n",
   1.627 -			(screen->flags&SDL_HWSURFACE) ? "video" : "system");
   1.628 -	if ( screen->flags & SDL_DOUBLEBUF ) {
   1.629 -		printf("Double-buffering enabled\n");
   1.630 -		flip = 1;
   1.631 -	}
   1.632 +    /* Initialize the display */
   1.633 +    screen = SDL_SetVideoMode (w, h, desired_bpp, video_flags);
   1.634 +    if (screen == NULL) {
   1.635 +        fprintf (stderr, "Couldn't set %dx%dx%d video mode: %s\n",
   1.636 +                 w, h, desired_bpp, SDL_GetError ());
   1.637 +        quit (1);
   1.638 +    }
   1.639 +    printf ("Set%s %dx%dx%d mode\n",
   1.640 +            screen->flags & SDL_FULLSCREEN ? " fullscreen" : "",
   1.641 +            screen->w, screen->h, screen->format->BitsPerPixel);
   1.642 +    printf ("(video surface located in %s memory)\n",
   1.643 +            (screen->flags & SDL_HWSURFACE) ? "video" : "system");
   1.644 +    if (screen->flags & SDL_DOUBLEBUF) {
   1.645 +        printf ("Double-buffering enabled\n");
   1.646 +        flip = 1;
   1.647 +    }
   1.648  
   1.649 -	/* Set the window manager title bar */
   1.650 -	SDL_WM_SetCaption("SDL test window", "testwin");
   1.651 +    /* Set the window manager title bar */
   1.652 +    SDL_WM_SetCaption ("SDL test window", "testwin");
   1.653  
   1.654 -	/* Do all the drawing work */
   1.655 +    /* Do all the drawing work */
   1.656  #ifdef BENCHMARK_SDL
   1.657 -	then = SDL_GetTicks();
   1.658 -	DrawPict(screen, argv[1], speedy, flip, nofade);
   1.659 -	now = SDL_GetTicks();
   1.660 -	printf("Time: %d milliseconds\n", now-then);
   1.661 +    then = SDL_GetTicks ();
   1.662 +    DrawPict (screen, argv[1], speedy, flip, nofade);
   1.663 +    now = SDL_GetTicks ();
   1.664 +    printf ("Time: %d milliseconds\n", now - then);
   1.665  #else
   1.666 -	DrawPict(screen, argv[1], speedy, flip, nofade);
   1.667 +    DrawPict (screen, argv[1], speedy, flip, nofade);
   1.668  #endif
   1.669 -	SDL_Delay(delay*1000);
   1.670 -	SDL_Quit();
   1.671 -	return(0);
   1.672 +    SDL_Delay (delay * 1000);
   1.673 +    SDL_Quit ();
   1.674 +    return (0);
   1.675  }