test/testpalette.c
branchSDL-1.3
changeset 1662 782fd950bd46
parent 1659 14717b52abc0
child 1668 4da1ee79c9af
     1.1 --- a/test/testpalette.c	Sun May 21 17:27:13 2006 +0000
     1.2 +++ b/test/testpalette.c	Sun May 28 13:04:16 2006 +0000
     1.3 @@ -36,99 +36,105 @@
     1.4   * in Gimp, saving in PPM ascii format and formatting with Emacs macros.
     1.5   */
     1.6  static SDL_Color wavemap[] = {
     1.7 -    {0,2,103}, {0,7,110}, {0,13,117}, {0,19,125},
     1.8 -    {0,25,133}, {0,31,141}, {0,37,150}, {0,43,158},
     1.9 -    {0,49,166}, {0,55,174}, {0,61,182}, {0,67,190},
    1.10 -    {0,73,198}, {0,79,206}, {0,86,214}, {0,96,220},
    1.11 -    {5,105,224}, {12,112,226}, {19,120,227}, {26,128,229},
    1.12 -    {33,135,230}, {40,143,232}, {47,150,234}, {54,158,236},
    1.13 -    {61,165,238}, {68,173,239}, {75,180,241}, {82,188,242},
    1.14 -    {89,195,244}, {96,203,246}, {103,210,248}, {112,218,250},
    1.15 -    {124,224,250}, {135,226,251}, {146,229,251}, {156,231,252},
    1.16 -    {167,233,252}, {178,236,252}, {189,238,252}, {200,240,252},
    1.17 -    {211,242,252}, {222,244,252}, {233,247,252}, {242,249,252},
    1.18 -    {237,250,252}, {209,251,252}, {174,251,252}, {138,252,252},
    1.19 -    {102,251,252}, {63,250,252}, {24,243,252}, {7,225,252},
    1.20 -    {4,203,252}, {3,181,252}, {2,158,252}, {1,136,251},
    1.21 -    {0,111,248}, {0,82,234}, {0,63,213}, {0,50,192},
    1.22 -    {0,39,172}, {0,28,152}, {0,17,132}, {0,7,114}
    1.23 +    {0, 2, 103}, {0, 7, 110}, {0, 13, 117}, {0, 19, 125},
    1.24 +    {0, 25, 133}, {0, 31, 141}, {0, 37, 150}, {0, 43, 158},
    1.25 +    {0, 49, 166}, {0, 55, 174}, {0, 61, 182}, {0, 67, 190},
    1.26 +    {0, 73, 198}, {0, 79, 206}, {0, 86, 214}, {0, 96, 220},
    1.27 +    {5, 105, 224}, {12, 112, 226}, {19, 120, 227}, {26, 128, 229},
    1.28 +    {33, 135, 230}, {40, 143, 232}, {47, 150, 234}, {54, 158, 236},
    1.29 +    {61, 165, 238}, {68, 173, 239}, {75, 180, 241}, {82, 188, 242},
    1.30 +    {89, 195, 244}, {96, 203, 246}, {103, 210, 248}, {112, 218, 250},
    1.31 +    {124, 224, 250}, {135, 226, 251}, {146, 229, 251}, {156, 231, 252},
    1.32 +    {167, 233, 252}, {178, 236, 252}, {189, 238, 252}, {200, 240, 252},
    1.33 +    {211, 242, 252}, {222, 244, 252}, {233, 247, 252}, {242, 249, 252},
    1.34 +    {237, 250, 252}, {209, 251, 252}, {174, 251, 252}, {138, 252, 252},
    1.35 +    {102, 251, 252}, {63, 250, 252}, {24, 243, 252}, {7, 225, 252},
    1.36 +    {4, 203, 252}, {3, 181, 252}, {2, 158, 252}, {1, 136, 251},
    1.37 +    {0, 111, 248}, {0, 82, 234}, {0, 63, 213}, {0, 50, 192},
    1.38 +    {0, 39, 172}, {0, 28, 152}, {0, 17, 132}, {0, 7, 114}
    1.39  };
    1.40  
    1.41  /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
    1.42 -static void quit(int rc)
    1.43 +static void
    1.44 +quit (int rc)
    1.45  {
    1.46 -	SDL_Quit();
    1.47 -	exit(rc);
    1.48 +    SDL_Quit ();
    1.49 +    exit (rc);
    1.50  }
    1.51  
    1.52 -static void sdlerr(char *when)
    1.53 +static void
    1.54 +sdlerr (char *when)
    1.55  {
    1.56 -    fprintf(stderr, "SDL error: %s: %s\n", when, SDL_GetError());
    1.57 -    quit(1);
    1.58 +    fprintf (stderr, "SDL error: %s: %s\n", when, SDL_GetError ());
    1.59 +    quit (1);
    1.60  }
    1.61  
    1.62  /* create a background surface */
    1.63 -static SDL_Surface *make_bg(SDL_Surface *screen, int startcol)
    1.64 +static SDL_Surface *
    1.65 +make_bg (SDL_Surface * screen, int startcol)
    1.66  {
    1.67      int i;
    1.68 -    SDL_Surface *bg = SDL_CreateRGBSurface(SDL_SWSURFACE, screen->w, screen->h,
    1.69 -					   8, 0, 0, 0, 0);
    1.70 -    if(!bg)
    1.71 -	sdlerr("creating background surface");
    1.72 +    SDL_Surface *bg =
    1.73 +        SDL_CreateRGBSurface (SDL_SWSURFACE, screen->w, screen->h,
    1.74 +                              8, 0, 0, 0, 0);
    1.75 +    if (!bg)
    1.76 +        sdlerr ("creating background surface");
    1.77  
    1.78      /* set the palette to the logical screen palette so that blits
    1.79         won't be translated */
    1.80 -    SDL_SetColors(bg, screen->format->palette->colors, 0, 256);
    1.81 +    SDL_SetColors (bg, screen->format->palette->colors, 0, 256);
    1.82  
    1.83      /* Make a wavy background pattern using colours 0-63 */
    1.84 -    if(SDL_LockSurface(bg) < 0)
    1.85 -	sdlerr("locking background");
    1.86 -    for(i = 0; i < SCRH; i++) {
    1.87 -	Uint8 *p = (Uint8 *)bg->pixels + i * bg->pitch;
    1.88 -	int j, d;
    1.89 -	d = 0;
    1.90 -	for(j = 0; j < SCRW; j++) {
    1.91 -	    int v = MAX(d, -2);
    1.92 -	    v = MIN(v, 2);
    1.93 -	    if(i > 0)
    1.94 -		v += p[-bg->pitch] + 65 - startcol;
    1.95 -	    p[j] = startcol + (v & 63);
    1.96 -	    d += ((rand() >> 3) % 3) - 1;
    1.97 -	}
    1.98 +    if (SDL_LockSurface (bg) < 0)
    1.99 +        sdlerr ("locking background");
   1.100 +    for (i = 0; i < SCRH; i++) {
   1.101 +        Uint8 *p = (Uint8 *) bg->pixels + i * bg->pitch;
   1.102 +        int j, d;
   1.103 +        d = 0;
   1.104 +        for (j = 0; j < SCRW; j++) {
   1.105 +            int v = MAX (d, -2);
   1.106 +            v = MIN (v, 2);
   1.107 +            if (i > 0)
   1.108 +                v += p[-bg->pitch] + 65 - startcol;
   1.109 +            p[j] = startcol + (v & 63);
   1.110 +            d += ((rand () >> 3) % 3) - 1;
   1.111 +        }
   1.112      }
   1.113 -    SDL_UnlockSurface(bg);
   1.114 -    return(bg);
   1.115 +    SDL_UnlockSurface (bg);
   1.116 +    return (bg);
   1.117  }
   1.118  
   1.119  /*
   1.120   * Return a surface flipped horisontally. Only works for 8bpp;
   1.121   * extension to arbitrary bitness is left as an exercise for the reader.
   1.122   */
   1.123 -static SDL_Surface *hflip(SDL_Surface *s)
   1.124 +static SDL_Surface *
   1.125 +hflip (SDL_Surface * s)
   1.126  {
   1.127      int i;
   1.128 -    SDL_Surface *z = SDL_CreateRGBSurface(SDL_SWSURFACE, s->w, s->h, 8,
   1.129 -					  0, 0, 0, 0);
   1.130 +    SDL_Surface *z = SDL_CreateRGBSurface (SDL_SWSURFACE, s->w, s->h, 8,
   1.131 +                                           0, 0, 0, 0);
   1.132      /* copy palette */
   1.133 -    SDL_SetColors(z, s->format->palette->colors,
   1.134 -		  0, s->format->palette->ncolors);
   1.135 -    if(SDL_LockSurface(s) < 0 || SDL_LockSurface(z) < 0)
   1.136 -	sdlerr("locking flip images");
   1.137 +    SDL_SetColors (z, s->format->palette->colors,
   1.138 +                   0, s->format->palette->ncolors);
   1.139 +    if (SDL_LockSurface (s) < 0 || SDL_LockSurface (z) < 0)
   1.140 +        sdlerr ("locking flip images");
   1.141  
   1.142 -    for(i = 0; i < s->h; i++) {
   1.143 -	int j;
   1.144 -	Uint8 *from = (Uint8 *)s->pixels + i * s->pitch;
   1.145 -	Uint8 *to = (Uint8 *)z->pixels + i * z->pitch + s->w - 1;
   1.146 -	for(j = 0; j < s->w; j++)
   1.147 -	    to[-j] = from[j];
   1.148 +    for (i = 0; i < s->h; i++) {
   1.149 +        int j;
   1.150 +        Uint8 *from = (Uint8 *) s->pixels + i * s->pitch;
   1.151 +        Uint8 *to = (Uint8 *) z->pixels + i * z->pitch + s->w - 1;
   1.152 +        for (j = 0; j < s->w; j++)
   1.153 +            to[-j] = from[j];
   1.154      }
   1.155  
   1.156 -    SDL_UnlockSurface(z);
   1.157 -    SDL_UnlockSurface(s);
   1.158 +    SDL_UnlockSurface (z);
   1.159 +    SDL_UnlockSurface (s);
   1.160      return z;
   1.161  }
   1.162  
   1.163 -int main(int argc, char **argv)
   1.164 +int
   1.165 +main (int argc, char **argv)
   1.166  {
   1.167      SDL_Color cmap[256];
   1.168      SDL_Surface *screen;
   1.169 @@ -143,200 +149,204 @@
   1.170      int gamma_fade = 0;
   1.171      int gamma_ramp = 0;
   1.172  
   1.173 -    if(SDL_Init(SDL_INIT_VIDEO) < 0)
   1.174 -	sdlerr("initialising SDL");
   1.175 +    if (SDL_Init (SDL_INIT_VIDEO) < 0)
   1.176 +        sdlerr ("initialising SDL");
   1.177  
   1.178 -    while(--argc) {
   1.179 -	++argv;
   1.180 -	if(strcmp(*argv, "-hw") == 0)
   1.181 -	    vidflags |= SDL_HWSURFACE;
   1.182 -	else if(strcmp(*argv, "-fullscreen") == 0)
   1.183 -	    vidflags |= SDL_FULLSCREEN;
   1.184 -	else if(strcmp(*argv, "-nofade") == 0)
   1.185 -	    fade_max = 1;
   1.186 -	else if(strcmp(*argv, "-gamma") == 0)
   1.187 -	    gamma_fade = 1;
   1.188 -	else if(strcmp(*argv, "-gammaramp") == 0)
   1.189 -	    gamma_ramp = 1;
   1.190 -	else {
   1.191 -	    fprintf(stderr,
   1.192 -		    "usage: testpalette "
   1.193 -		    " [-hw] [-fullscreen] [-nofade] [-gamma] [-gammaramp]\n");
   1.194 -	    quit(1);
   1.195 -	}
   1.196 +    while (--argc) {
   1.197 +        ++argv;
   1.198 +        if (strcmp (*argv, "-hw") == 0)
   1.199 +            vidflags |= SDL_HWSURFACE;
   1.200 +        else if (strcmp (*argv, "-fullscreen") == 0)
   1.201 +            vidflags |= SDL_FULLSCREEN;
   1.202 +        else if (strcmp (*argv, "-nofade") == 0)
   1.203 +            fade_max = 1;
   1.204 +        else if (strcmp (*argv, "-gamma") == 0)
   1.205 +            gamma_fade = 1;
   1.206 +        else if (strcmp (*argv, "-gammaramp") == 0)
   1.207 +            gamma_ramp = 1;
   1.208 +        else {
   1.209 +            fprintf (stderr,
   1.210 +                     "usage: testpalette "
   1.211 +                     " [-hw] [-fullscreen] [-nofade] [-gamma] [-gammaramp]\n");
   1.212 +            quit (1);
   1.213 +        }
   1.214      }
   1.215  
   1.216      /* Ask explicitly for 8bpp and a hardware palette */
   1.217 -    if((screen = SDL_SetVideoMode(SCRW, SCRH, 8, vidflags | SDL_HWPALETTE)) == NULL) {
   1.218 -	fprintf(stderr, "error setting %dx%d 8bpp indexed mode: %s\n",
   1.219 -		SCRW, SCRH, SDL_GetError());
   1.220 -	quit(1);
   1.221 +    if ((screen =
   1.222 +         SDL_SetVideoMode (SCRW, SCRH, 8, vidflags | SDL_HWPALETTE)) == NULL)
   1.223 +    {
   1.224 +        fprintf (stderr, "error setting %dx%d 8bpp indexed mode: %s\n",
   1.225 +                 SCRW, SCRH, SDL_GetError ());
   1.226 +        quit (1);
   1.227      }
   1.228  
   1.229 -    if (vidflags & SDL_FULLSCREEN) SDL_ShowCursor (SDL_FALSE);
   1.230 +    if (vidflags & SDL_FULLSCREEN)
   1.231 +        SDL_ShowCursor (SDL_FALSE);
   1.232  
   1.233 -    if((boat[0] = SDL_LoadBMP("sail.bmp")) == NULL)
   1.234 -	sdlerr("loading sail.bmp");
   1.235 +    if ((boat[0] = SDL_LoadBMP ("sail.bmp")) == NULL)
   1.236 +        sdlerr ("loading sail.bmp");
   1.237      /* We've chosen magenta (#ff00ff) as colour key for the boat */
   1.238 -    SDL_SetColorKey(boat[0], SDL_SRCCOLORKEY | SDL_RLEACCEL,
   1.239 -		    SDL_MapRGB(boat[0]->format, 0xff, 0x00, 0xff));
   1.240 +    SDL_SetColorKey (boat[0], SDL_SRCCOLORKEY | SDL_RLEACCEL,
   1.241 +                     SDL_MapRGB (boat[0]->format, 0xff, 0x00, 0xff));
   1.242      boatcols = boat[0]->format->palette->ncolors;
   1.243 -    boat[1] = hflip(boat[0]);
   1.244 -    SDL_SetColorKey(boat[1], SDL_SRCCOLORKEY | SDL_RLEACCEL,
   1.245 -		    SDL_MapRGB(boat[1]->format, 0xff, 0x00, 0xff));
   1.246 +    boat[1] = hflip (boat[0]);
   1.247 +    SDL_SetColorKey (boat[1], SDL_SRCCOLORKEY | SDL_RLEACCEL,
   1.248 +                     SDL_MapRGB (boat[1]->format, 0xff, 0x00, 0xff));
   1.249  
   1.250      /*
   1.251       * First set the physical screen palette to black, so the user won't
   1.252       * see our initial drawing on the screen.
   1.253       */
   1.254 -    memset(cmap, 0, sizeof(cmap));
   1.255 -    SDL_SetPalette(screen, SDL_PHYSPAL, cmap, 0, 256);
   1.256 +    memset (cmap, 0, sizeof (cmap));
   1.257 +    SDL_SetPalette (screen, SDL_PHYSPAL, cmap, 0, 256);
   1.258  
   1.259      /*
   1.260       * Proper palette management is important when playing games with the
   1.261       * colormap. We have divided the palette as follows:
   1.262       *
   1.263 -     * index 0..(boatcols-1):		used for the boat
   1.264 -     * index boatcols..(boatcols+63):	used for the waves
   1.265 +     * index 0..(boatcols-1):           used for the boat
   1.266 +     * index boatcols..(boatcols+63):   used for the waves
   1.267       */
   1.268 -    SDL_SetPalette(screen, SDL_LOGPAL,
   1.269 -		   boat[0]->format->palette->colors, 0, boatcols);
   1.270 -    SDL_SetPalette(screen, SDL_LOGPAL, wavemap, boatcols, 64);
   1.271 +    SDL_SetPalette (screen, SDL_LOGPAL,
   1.272 +                    boat[0]->format->palette->colors, 0, boatcols);
   1.273 +    SDL_SetPalette (screen, SDL_LOGPAL, wavemap, boatcols, 64);
   1.274  
   1.275      /*
   1.276       * Now the logical screen palette is set, and will remain unchanged.
   1.277       * The boats already have the same palette so fast blits can be used.
   1.278       */
   1.279 -    memcpy(cmap, screen->format->palette->colors, 256 * sizeof(SDL_Color));
   1.280 +    memcpy (cmap, screen->format->palette->colors, 256 * sizeof (SDL_Color));
   1.281  
   1.282      /* save the index of the red colour for later */
   1.283 -    red = SDL_MapRGB(screen->format, 0xff, 0x00, 0x00);
   1.284 +    red = SDL_MapRGB (screen->format, 0xff, 0x00, 0x00);
   1.285  
   1.286 -    bg = make_bg(screen, boatcols); /* make a nice wavy background surface */
   1.287 +    bg = make_bg (screen, boatcols);    /* make a nice wavy background surface */
   1.288  
   1.289      /* initial screen contents */
   1.290 -    if(SDL_BlitSurface(bg, NULL, screen, NULL) < 0)
   1.291 -	sdlerr("blitting background to screen");
   1.292 -    SDL_Flip(screen);		/* actually put the background on screen */
   1.293 +    if (SDL_BlitSurface (bg, NULL, screen, NULL) < 0)
   1.294 +        sdlerr ("blitting background to screen");
   1.295 +    SDL_Flip (screen);          /* actually put the background on screen */
   1.296  
   1.297      /* determine initial boat placements */
   1.298 -    for(i = 0; i < NBOATS; i++) {
   1.299 -	boatx[i] = (rand() % (SCRW + boat[0]->w)) - boat[0]->w;
   1.300 -	boaty[i] = i * (SCRH - boat[0]->h) / (NBOATS - 1);
   1.301 -	boatdir[i] = ((rand() >> 5) & 1) * 2 - 1;
   1.302 +    for (i = 0; i < NBOATS; i++) {
   1.303 +        boatx[i] = (rand () % (SCRW + boat[0]->w)) - boat[0]->w;
   1.304 +        boaty[i] = i * (SCRH - boat[0]->h) / (NBOATS - 1);
   1.305 +        boatdir[i] = ((rand () >> 5) & 1) * 2 - 1;
   1.306      }
   1.307  
   1.308 -    start = SDL_GetTicks();
   1.309 +    start = SDL_GetTicks ();
   1.310      frames = 0;
   1.311      fade_dir = 1;
   1.312      fade_level = 0;
   1.313      do {
   1.314 -	SDL_Event e;
   1.315 -	SDL_Rect updates[NBOATS];
   1.316 -	SDL_Rect r;
   1.317 -	int redphase;
   1.318 +        SDL_Event e;
   1.319 +        SDL_Rect updates[NBOATS];
   1.320 +        SDL_Rect r;
   1.321 +        int redphase;
   1.322  
   1.323 -	/* A small event loop: just exit on any key or mouse button event */
   1.324 -	while(SDL_PollEvent(&e)) {
   1.325 -	    if(e.type == SDL_KEYDOWN || e.type == SDL_QUIT
   1.326 -	       || e.type == SDL_MOUSEBUTTONDOWN) {
   1.327 -		if(fade_dir < 0)
   1.328 -		    fade_level = 0;
   1.329 -		fade_dir = -1;
   1.330 -	    }
   1.331 -	}
   1.332 +        /* A small event loop: just exit on any key or mouse button event */
   1.333 +        while (SDL_PollEvent (&e)) {
   1.334 +            if (e.type == SDL_KEYDOWN || e.type == SDL_QUIT
   1.335 +                || e.type == SDL_MOUSEBUTTONDOWN) {
   1.336 +                if (fade_dir < 0)
   1.337 +                    fade_level = 0;
   1.338 +                fade_dir = -1;
   1.339 +            }
   1.340 +        }
   1.341  
   1.342 -	/* move boats */
   1.343 -	for(i = 0; i < NBOATS; i++) {
   1.344 -	    int old_x = boatx[i];
   1.345 -	    /* update boat position */
   1.346 -	    boatx[i] += boatdir[i] * SPEED;
   1.347 -	    if(boatx[i] <= -boat[0]->w || boatx[i] >= SCRW)
   1.348 -		boatdir[i] = -boatdir[i];
   1.349 +        /* move boats */
   1.350 +        for (i = 0; i < NBOATS; i++) {
   1.351 +            int old_x = boatx[i];
   1.352 +            /* update boat position */
   1.353 +            boatx[i] += boatdir[i] * SPEED;
   1.354 +            if (boatx[i] <= -boat[0]->w || boatx[i] >= SCRW)
   1.355 +                boatdir[i] = -boatdir[i];
   1.356  
   1.357 -	    /* paint over the old boat position */
   1.358 -	    r.x = old_x;
   1.359 -	    r.y = boaty[i];
   1.360 -	    r.w = boat[0]->w;
   1.361 -	    r.h = boat[0]->h;
   1.362 -	    if(SDL_BlitSurface(bg, &r, screen, &r) < 0)
   1.363 -		sdlerr("blitting background");
   1.364 +            /* paint over the old boat position */
   1.365 +            r.x = old_x;
   1.366 +            r.y = boaty[i];
   1.367 +            r.w = boat[0]->w;
   1.368 +            r.h = boat[0]->h;
   1.369 +            if (SDL_BlitSurface (bg, &r, screen, &r) < 0)
   1.370 +                sdlerr ("blitting background");
   1.371  
   1.372 -	    /* construct update rectangle (bounding box of old and new pos) */
   1.373 -	    updates[i].x = MIN(old_x, boatx[i]);
   1.374 -	    updates[i].y = boaty[i];
   1.375 -	    updates[i].w = boat[0]->w + SPEED;
   1.376 -	    updates[i].h = boat[0]->h;
   1.377 -	    /* clip update rectangle to screen */
   1.378 -	    if(updates[i].x < 0) {
   1.379 -		updates[i].w += updates[i].x;
   1.380 -		updates[i].x = 0;
   1.381 -	    }
   1.382 -	    if(updates[i].x + updates[i].w > SCRW)
   1.383 -		updates[i].w = SCRW - updates[i].x;
   1.384 -	}
   1.385 +            /* construct update rectangle (bounding box of old and new pos) */
   1.386 +            updates[i].x = MIN (old_x, boatx[i]);
   1.387 +            updates[i].y = boaty[i];
   1.388 +            updates[i].w = boat[0]->w + SPEED;
   1.389 +            updates[i].h = boat[0]->h;
   1.390 +            /* clip update rectangle to screen */
   1.391 +            if (updates[i].x < 0) {
   1.392 +                updates[i].w += updates[i].x;
   1.393 +                updates[i].x = 0;
   1.394 +            }
   1.395 +            if (updates[i].x + updates[i].w > SCRW)
   1.396 +                updates[i].w = SCRW - updates[i].x;
   1.397 +        }
   1.398  
   1.399 -	for(i = 0; i < NBOATS; i++) {
   1.400 -	    /* paint boat on new position */
   1.401 -	    r.x = boatx[i];
   1.402 -	    r.y = boaty[i];
   1.403 -	    if(SDL_BlitSurface(boat[(boatdir[i] + 1) / 2], NULL,
   1.404 -			       screen, &r) < 0)
   1.405 -		sdlerr("blitting boat");
   1.406 -	}
   1.407 +        for (i = 0; i < NBOATS; i++) {
   1.408 +            /* paint boat on new position */
   1.409 +            r.x = boatx[i];
   1.410 +            r.y = boaty[i];
   1.411 +            if (SDL_BlitSurface (boat[(boatdir[i] + 1) / 2], NULL,
   1.412 +                                 screen, &r) < 0)
   1.413 +                sdlerr ("blitting boat");
   1.414 +        }
   1.415  
   1.416 -	/* cycle wave palette */
   1.417 -	for(i = 0; i < 64; i++)
   1.418 -	    cmap[boatcols + ((i + frames) & 63)] = wavemap[i];
   1.419 +        /* cycle wave palette */
   1.420 +        for (i = 0; i < 64; i++)
   1.421 +            cmap[boatcols + ((i + frames) & 63)] = wavemap[i];
   1.422  
   1.423 -	if(fade_dir) {
   1.424 -	    /* Fade the entire palette in/out */
   1.425 -	    fade_level += fade_dir;
   1.426 +        if (fade_dir) {
   1.427 +            /* Fade the entire palette in/out */
   1.428 +            fade_level += fade_dir;
   1.429  
   1.430 -	    if(gamma_fade) {
   1.431 -		/* Fade linearly in gamma level (lousy) */
   1.432 -		float level = (float)fade_level / fade_max;
   1.433 -		if(SDL_SetGamma(level, level, level) < 0)
   1.434 -		    sdlerr("setting gamma");
   1.435 +            if (gamma_fade) {
   1.436 +                /* Fade linearly in gamma level (lousy) */
   1.437 +                float level = (float) fade_level / fade_max;
   1.438 +                if (SDL_SetGamma (level, level, level) < 0)
   1.439 +                    sdlerr ("setting gamma");
   1.440  
   1.441 -	    } else if(gamma_ramp) {
   1.442 -		/* Fade using gamma ramp (better) */
   1.443 -		Uint16 ramp[256];
   1.444 -		for(i = 0; i < 256; i++)
   1.445 -		    ramp[i] = (i * fade_level / fade_max) << 8;
   1.446 -		if(SDL_SetGammaRamp(ramp, ramp, ramp) < 0)
   1.447 -		    sdlerr("setting gamma ramp");
   1.448 +            } else if (gamma_ramp) {
   1.449 +                /* Fade using gamma ramp (better) */
   1.450 +                Uint16 ramp[256];
   1.451 +                for (i = 0; i < 256; i++)
   1.452 +                    ramp[i] = (i * fade_level / fade_max) << 8;
   1.453 +                if (SDL_SetGammaRamp (ramp, ramp, ramp) < 0)
   1.454 +                    sdlerr ("setting gamma ramp");
   1.455  
   1.456 -	    } else {
   1.457 -		/* Fade using direct palette manipulation (best) */
   1.458 -		memcpy(cmap, screen->format->palette->colors,
   1.459 -		       boatcols * sizeof(SDL_Color));
   1.460 -		for(i = 0; i < boatcols + 64; i++) {
   1.461 -		    cmap[i].r = cmap[i].r * fade_level / fade_max;
   1.462 -		    cmap[i].g = cmap[i].g * fade_level / fade_max;
   1.463 -		    cmap[i].b = cmap[i].b * fade_level / fade_max;
   1.464 -		}
   1.465 -	    }
   1.466 -	    if(fade_level == fade_max)
   1.467 -		fade_dir = 0;
   1.468 -	}
   1.469 +            } else {
   1.470 +                /* Fade using direct palette manipulation (best) */
   1.471 +                memcpy (cmap, screen->format->palette->colors,
   1.472 +                        boatcols * sizeof (SDL_Color));
   1.473 +                for (i = 0; i < boatcols + 64; i++) {
   1.474 +                    cmap[i].r = cmap[i].r * fade_level / fade_max;
   1.475 +                    cmap[i].g = cmap[i].g * fade_level / fade_max;
   1.476 +                    cmap[i].b = cmap[i].b * fade_level / fade_max;
   1.477 +                }
   1.478 +            }
   1.479 +            if (fade_level == fade_max)
   1.480 +                fade_dir = 0;
   1.481 +        }
   1.482  
   1.483 -	/* pulse the red colour (done after the fade, for a night effect) */
   1.484 -	redphase = frames % 64;
   1.485 -	cmap[red].r = (int)(255 * sin(redphase * M_PI / 63));
   1.486 +        /* pulse the red colour (done after the fade, for a night effect) */
   1.487 +        redphase = frames % 64;
   1.488 +        cmap[red].r = (int) (255 * sin (redphase * M_PI / 63));
   1.489  
   1.490 -	SDL_SetPalette(screen, SDL_PHYSPAL, cmap, 0, boatcols + 64);
   1.491 +        SDL_SetPalette (screen, SDL_PHYSPAL, cmap, 0, boatcols + 64);
   1.492  
   1.493 -	/* update changed areas of the screen */
   1.494 -	SDL_UpdateRects(screen, NBOATS, updates);
   1.495 -	frames++;
   1.496 -    } while(fade_level > 0);
   1.497 +        /* update changed areas of the screen */
   1.498 +        SDL_UpdateRects (screen, NBOATS, updates);
   1.499 +        frames++;
   1.500 +    }
   1.501 +    while (fade_level > 0);
   1.502  
   1.503 -    printf("%d frames, %.2f fps\n",
   1.504 -	   frames, 1000.0 * frames / (SDL_GetTicks() - start));
   1.505 +    printf ("%d frames, %.2f fps\n",
   1.506 +            frames, 1000.0 * frames / (SDL_GetTicks () - start));
   1.507  
   1.508 -    if (vidflags & SDL_FULLSCREEN) SDL_ShowCursor (SDL_TRUE);
   1.509 -    SDL_Quit();
   1.510 +    if (vidflags & SDL_FULLSCREEN)
   1.511 +        SDL_ShowCursor (SDL_TRUE);
   1.512 +    SDL_Quit ();
   1.513      return 0;
   1.514  }
   1.515 -