test/testwin.c
branchSDL-1.3
changeset 1668 4da1ee79c9af
parent 1662 782fd950bd46
     1.1 --- a/test/testwin.c	Mon May 29 03:53:21 2006 +0000
     1.2 +++ b/test/testwin.c	Mon May 29 04:04:35 2006 +0000
     1.3 @@ -13,15 +13,15 @@
     1.4  
     1.5  /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
     1.6  static void
     1.7 -quit (int rc)
     1.8 +quit(int rc)
     1.9  {
    1.10 -    SDL_Quit ();
    1.11 -    exit (rc);
    1.12 +    SDL_Quit();
    1.13 +    exit(rc);
    1.14  }
    1.15  
    1.16  void
    1.17 -DrawPict (SDL_Surface * screen, char *bmpfile,
    1.18 -          int speedy, int flip, int nofade)
    1.19 +DrawPict(SDL_Surface * screen, char *bmpfile,
    1.20 +         int speedy, int flip, int nofade)
    1.21  {
    1.22      SDL_Surface *picture;
    1.23      SDL_Rect dest, update;
    1.24 @@ -33,27 +33,27 @@
    1.25      if (bmpfile == NULL) {
    1.26          bmpfile = "sample.bmp"; /* Sample image */
    1.27      }
    1.28 -    fprintf (stderr, "Loading picture: %s\n", bmpfile);
    1.29 -    picture = SDL_LoadBMP (bmpfile);
    1.30 +    fprintf(stderr, "Loading picture: %s\n", bmpfile);
    1.31 +    picture = SDL_LoadBMP(bmpfile);
    1.32      if (picture == NULL) {
    1.33 -        fprintf (stderr, "Couldn't load %s: %s\n", bmpfile, SDL_GetError ());
    1.34 +        fprintf(stderr, "Couldn't load %s: %s\n", bmpfile, SDL_GetError());
    1.35          return;
    1.36      }
    1.37  
    1.38      /* Set the display colors -- on a hicolor display this is a no-op */
    1.39      if (picture->format->palette) {
    1.40          ncolors = picture->format->palette->ncolors;
    1.41 -        colors = (SDL_Color *) malloc (ncolors * sizeof (SDL_Color));
    1.42 -        cmap = (SDL_Color *) malloc (ncolors * sizeof (SDL_Color));
    1.43 -        memcpy (colors, picture->format->palette->colors,
    1.44 -                ncolors * sizeof (SDL_Color));
    1.45 +        colors = (SDL_Color *) malloc(ncolors * sizeof(SDL_Color));
    1.46 +        cmap = (SDL_Color *) malloc(ncolors * sizeof(SDL_Color));
    1.47 +        memcpy(colors, picture->format->palette->colors,
    1.48 +               ncolors * sizeof(SDL_Color));
    1.49      } else {
    1.50          int r, g, b;
    1.51  
    1.52          /* Allocate 256 color palette */
    1.53          ncolors = 256;
    1.54 -        colors = (SDL_Color *) malloc (ncolors * sizeof (SDL_Color));
    1.55 -        cmap = (SDL_Color *) malloc (ncolors * sizeof (SDL_Color));
    1.56 +        colors = (SDL_Color *) malloc(ncolors * sizeof(SDL_Color));
    1.57 +        cmap = (SDL_Color *) malloc(ncolors * sizeof(SDL_Color));
    1.58  
    1.59          /* Set a 3,3,2 color cube */
    1.60          for (r = 0; r < 8; ++r) {
    1.61 @@ -67,44 +67,44 @@
    1.62              }
    1.63          }
    1.64      }
    1.65 -    NOTICE ("testwin: setting colors\n");
    1.66 -    if (!SDL_SetColors (screen, colors, 0, ncolors) &&
    1.67 +    NOTICE("testwin: setting colors\n");
    1.68 +    if (!SDL_SetColors(screen, colors, 0, ncolors) &&
    1.69          (screen->format->palette != NULL)) {
    1.70 -        fprintf (stderr,
    1.71 -                 "Warning: Couldn't set all of the colors, but SDL will map the image\n"
    1.72 -                 "         (colormap fading will suffer - try the -warp option)\n");
    1.73 +        fprintf(stderr,
    1.74 +                "Warning: Couldn't set all of the colors, but SDL will map the image\n"
    1.75 +                "         (colormap fading will suffer - try the -warp option)\n");
    1.76      }
    1.77  
    1.78      /* Set the screen to black (not really necessary) */
    1.79 -    if (SDL_LockSurface (screen) == 0) {
    1.80 +    if (SDL_LockSurface(screen) == 0) {
    1.81          Uint32 black;
    1.82          Uint8 *pixels;
    1.83  
    1.84 -        black = SDL_MapRGB (screen->format, 0, 0, 0);
    1.85 +        black = SDL_MapRGB(screen->format, 0, 0, 0);
    1.86          pixels = (Uint8 *) screen->pixels;
    1.87          for (i = 0; i < screen->h; ++i) {
    1.88 -            memset (pixels, black, screen->w * screen->format->BytesPerPixel);
    1.89 +            memset(pixels, black, screen->w * screen->format->BytesPerPixel);
    1.90              pixels += screen->pitch;
    1.91          }
    1.92 -        SDL_UnlockSurface (screen);
    1.93 -        SDL_UpdateRect (screen, 0, 0, 0, 0);
    1.94 +        SDL_UnlockSurface(screen);
    1.95 +        SDL_UpdateRect(screen, 0, 0, 0, 0);
    1.96      }
    1.97  
    1.98      /* Display the picture */
    1.99      if (speedy) {
   1.100          SDL_Surface *displayfmt;
   1.101  
   1.102 -        fprintf (stderr, "Converting picture\n");
   1.103 -        displayfmt = SDL_DisplayFormat (picture);
   1.104 +        fprintf(stderr, "Converting picture\n");
   1.105 +        displayfmt = SDL_DisplayFormat(picture);
   1.106          if (displayfmt == NULL) {
   1.107 -            fprintf (stderr, "Couldn't convert image: %s\n", SDL_GetError ());
   1.108 +            fprintf(stderr, "Couldn't convert image: %s\n", SDL_GetError());
   1.109              goto done;
   1.110          }
   1.111 -        SDL_FreeSurface (picture);
   1.112 +        SDL_FreeSurface(picture);
   1.113          picture = displayfmt;
   1.114      }
   1.115 -    printf ("(image surface located in %s memory)\n",
   1.116 -            (picture->flags & SDL_HWSURFACE) ? "video" : "system");
   1.117 +    printf("(image surface located in %s memory)\n",
   1.118 +           (picture->flags & SDL_HWSURFACE) ? "video" : "system");
   1.119      centered = (screen->w - picture->w) / 2;
   1.120      if (centered < 0) {
   1.121          centered = 0;
   1.122 @@ -112,29 +112,29 @@
   1.123      dest.y = (screen->h - picture->h) / 2;
   1.124      dest.w = picture->w;
   1.125      dest.h = picture->h;
   1.126 -    NOTICE ("testwin: moving image\n");
   1.127 +    NOTICE("testwin: moving image\n");
   1.128      for (i = 0; i <= centered; ++i) {
   1.129          dest.x = i;
   1.130          update = dest;
   1.131 -        if (SDL_BlitSurface (picture, NULL, screen, &update) < 0) {
   1.132 -            fprintf (stderr, "Blit failed: %s\n", SDL_GetError ());
   1.133 +        if (SDL_BlitSurface(picture, NULL, screen, &update) < 0) {
   1.134 +            fprintf(stderr, "Blit failed: %s\n", SDL_GetError());
   1.135              break;
   1.136          }
   1.137          if (flip) {
   1.138 -            SDL_Flip (screen);
   1.139 +            SDL_Flip(screen);
   1.140          } else {
   1.141 -            SDL_UpdateRects (screen, 1, &update);
   1.142 +            SDL_UpdateRects(screen, 1, &update);
   1.143          }
   1.144      }
   1.145  
   1.146  #ifdef SCREENSHOT
   1.147 -    if (SDL_SaveBMP (screen, "screen.bmp") < 0)
   1.148 -        printf ("Couldn't save screen: %s\n", SDL_GetError ());
   1.149 +    if (SDL_SaveBMP(screen, "screen.bmp") < 0)
   1.150 +        printf("Couldn't save screen: %s\n", SDL_GetError());
   1.151  #endif
   1.152  
   1.153  #ifndef BENCHMARK_SDL
   1.154      /* Let it sit there for a while */
   1.155 -    SDL_Delay (5 * 1000);
   1.156 +    SDL_Delay(5 * 1000);
   1.157  #endif
   1.158      /* Fade the colormap */
   1.159      if (!nofade) {
   1.160 @@ -146,13 +146,13 @@
   1.161              Sint16 r, g, b;
   1.162          } cdist[256];
   1.163  
   1.164 -        NOTICE ("testwin: fading out...\n");
   1.165 -        memcpy (cmap, colors, ncolors * sizeof (SDL_Color));
   1.166 +        NOTICE("testwin: fading out...\n");
   1.167 +        memcpy(cmap, colors, ncolors * sizeof(SDL_Color));
   1.168          maxstep = 32 - 1;
   1.169          final.r = 0xFF;
   1.170          final.g = 0x00;
   1.171          final.b = 0x00;
   1.172 -        memcpy (palcolors, colors, ncolors * sizeof (SDL_Color));
   1.173 +        memcpy(palcolors, colors, ncolors * sizeof(SDL_Color));
   1.174          for (i = 0; i < ncolors; ++i) {
   1.175              cdist[i].r = final.r - palcolors[i].r;
   1.176              cdist[i].g = final.g - palcolors[i].g;
   1.177 @@ -165,13 +165,13 @@
   1.178                  colors[c].g = palcolors[c].g + ((cdist[c].g * i)) / maxstep;
   1.179                  colors[c].b = palcolors[c].b + ((cdist[c].b * i)) / maxstep;
   1.180              }
   1.181 -            SDL_SetColors (screen, colors, 0, ncolors);
   1.182 -            SDL_Delay (1);
   1.183 +            SDL_SetColors(screen, colors, 0, ncolors);
   1.184 +            SDL_Delay(1);
   1.185          }
   1.186          final.r = 0x00;
   1.187          final.g = 0x00;
   1.188          final.b = 0x00;
   1.189 -        memcpy (palcolors, colors, ncolors * sizeof (SDL_Color));
   1.190 +        memcpy(palcolors, colors, ncolors * sizeof(SDL_Color));
   1.191          for (i = 0; i < ncolors; ++i) {
   1.192              cdist[i].r = final.r - palcolors[i].r;
   1.193              cdist[i].g = final.g - palcolors[i].g;
   1.194 @@ -185,17 +185,17 @@
   1.195                  colors[c].g = palcolors[c].g + ((cdist[c].g * i)) / maxstep;
   1.196                  colors[c].b = palcolors[c].b + ((cdist[c].b * i)) / maxstep;
   1.197              }
   1.198 -            SDL_SetColors (screen, colors, 0, ncolors);
   1.199 -            SDL_Delay (1);
   1.200 +            SDL_SetColors(screen, colors, 0, ncolors);
   1.201 +            SDL_Delay(1);
   1.202          }
   1.203          for (i = 0; i < ncolors; ++i) {
   1.204              colors[i].r = final.r;
   1.205              colors[i].g = final.g;
   1.206              colors[i].b = final.b;
   1.207          }
   1.208 -        SDL_SetColors (screen, colors, 0, ncolors);
   1.209 -        NOTICE ("testwin: fading in...\n");
   1.210 -        memcpy (palcolors, colors, ncolors * sizeof (SDL_Color));
   1.211 +        SDL_SetColors(screen, colors, 0, ncolors);
   1.212 +        NOTICE("testwin: fading in...\n");
   1.213 +        memcpy(palcolors, colors, ncolors * sizeof(SDL_Color));
   1.214          for (i = 0; i < ncolors; ++i) {
   1.215              cdist[i].r = cmap[i].r - palcolors[i].r;
   1.216              cdist[i].g = cmap[i].g - palcolors[i].g;
   1.217 @@ -208,22 +208,22 @@
   1.218                  colors[c].g = palcolors[c].g + ((cdist[c].g * i)) / maxstep;
   1.219                  colors[c].b = palcolors[c].b + ((cdist[c].b * i)) / maxstep;
   1.220              }
   1.221 -            SDL_SetColors (screen, colors, 0, ncolors);
   1.222 -            SDL_Delay (1);
   1.223 +            SDL_SetColors(screen, colors, 0, ncolors);
   1.224 +            SDL_Delay(1);
   1.225          }
   1.226 -        NOTICE ("testwin: fading over\n");
   1.227 +        NOTICE("testwin: fading over\n");
   1.228      }
   1.229  
   1.230    done:
   1.231      /* Free the picture and return */
   1.232 -    SDL_FreeSurface (picture);
   1.233 -    free (colors);
   1.234 -    free (cmap);
   1.235 +    SDL_FreeSurface(picture);
   1.236 +    free(colors);
   1.237 +    free(cmap);
   1.238      return;
   1.239  }
   1.240  
   1.241  int
   1.242 -main (int argc, char *argv[])
   1.243 +main(int argc, char *argv[])
   1.244  {
   1.245      SDL_Surface *screen;
   1.246      /* Options */
   1.247 @@ -252,67 +252,67 @@
   1.248      desired_bpp = 0;
   1.249      video_flags = 0;
   1.250  #endif
   1.251 -    if (SDL_Init (SDL_INIT_VIDEO) < 0) {
   1.252 -        fprintf (stderr, "Couldn't initialize SDL: %s\n", SDL_GetError ());
   1.253 +    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
   1.254 +        fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
   1.255          return (1);
   1.256      }
   1.257  
   1.258      while (argc > 1) {
   1.259 -        if (strcmp (argv[1], "-speedy") == 0) {
   1.260 +        if (strcmp(argv[1], "-speedy") == 0) {
   1.261              speedy = 1;
   1.262              argv += 1;
   1.263              argc -= 1;
   1.264 -        } else if (strcmp (argv[1], "-nofade") == 0) {
   1.265 +        } else if (strcmp(argv[1], "-nofade") == 0) {
   1.266              nofade = 1;
   1.267              argv += 1;
   1.268              argc -= 1;
   1.269 -        } else if (strcmp (argv[1], "-delay") == 0) {
   1.270 +        } else if (strcmp(argv[1], "-delay") == 0) {
   1.271              if (argv[2]) {
   1.272 -                delay = atoi (argv[2]);
   1.273 +                delay = atoi(argv[2]);
   1.274                  argv += 2;
   1.275                  argc -= 2;
   1.276              } else {
   1.277 -                fprintf (stderr, "The -delay option requires an argument\n");
   1.278 -                quit (1);
   1.279 +                fprintf(stderr, "The -delay option requires an argument\n");
   1.280 +                quit(1);
   1.281              }
   1.282 -        } else if (strcmp (argv[1], "-width") == 0) {
   1.283 -            if (argv[2] && ((w = atoi (argv[2])) > 0)) {
   1.284 +        } else if (strcmp(argv[1], "-width") == 0) {
   1.285 +            if (argv[2] && ((w = atoi(argv[2])) > 0)) {
   1.286                  argv += 2;
   1.287                  argc -= 2;
   1.288              } else {
   1.289 -                fprintf (stderr, "The -width option requires an argument\n");
   1.290 -                quit (1);
   1.291 +                fprintf(stderr, "The -width option requires an argument\n");
   1.292 +                quit(1);
   1.293              }
   1.294 -        } else if (strcmp (argv[1], "-height") == 0) {
   1.295 -            if (argv[2] && ((h = atoi (argv[2])) > 0)) {
   1.296 +        } else if (strcmp(argv[1], "-height") == 0) {
   1.297 +            if (argv[2] && ((h = atoi(argv[2])) > 0)) {
   1.298                  argv += 2;
   1.299                  argc -= 2;
   1.300              } else {
   1.301 -                fprintf (stderr, "The -height option requires an argument\n");
   1.302 -                quit (1);
   1.303 +                fprintf(stderr, "The -height option requires an argument\n");
   1.304 +                quit(1);
   1.305              }
   1.306 -        } else if (strcmp (argv[1], "-bpp") == 0) {
   1.307 +        } else if (strcmp(argv[1], "-bpp") == 0) {
   1.308              if (argv[2]) {
   1.309 -                desired_bpp = atoi (argv[2]);
   1.310 +                desired_bpp = atoi(argv[2]);
   1.311                  argv += 2;
   1.312                  argc -= 2;
   1.313              } else {
   1.314 -                fprintf (stderr, "The -bpp option requires an argument\n");
   1.315 -                quit (1);
   1.316 +                fprintf(stderr, "The -bpp option requires an argument\n");
   1.317 +                quit(1);
   1.318              }
   1.319 -        } else if (strcmp (argv[1], "-warp") == 0) {
   1.320 +        } else if (strcmp(argv[1], "-warp") == 0) {
   1.321              video_flags |= SDL_HWPALETTE;
   1.322              argv += 1;
   1.323              argc -= 1;
   1.324 -        } else if (strcmp (argv[1], "-hw") == 0) {
   1.325 +        } else if (strcmp(argv[1], "-hw") == 0) {
   1.326              video_flags |= SDL_HWSURFACE;
   1.327              argv += 1;
   1.328              argc -= 1;
   1.329 -        } else if (strcmp (argv[1], "-flip") == 0) {
   1.330 +        } else if (strcmp(argv[1], "-flip") == 0) {
   1.331              video_flags |= SDL_DOUBLEBUF;
   1.332              argv += 1;
   1.333              argc -= 1;
   1.334 -        } else if (strcmp (argv[1], "-fullscreen") == 0) {
   1.335 +        } else if (strcmp(argv[1], "-fullscreen") == 0) {
   1.336              video_flags |= SDL_FULLSCREEN;
   1.337              argv += 1;
   1.338              argc -= 1;
   1.339 @@ -321,35 +321,35 @@
   1.340      }
   1.341  
   1.342      /* Initialize the display */
   1.343 -    screen = SDL_SetVideoMode (w, h, desired_bpp, video_flags);
   1.344 +    screen = SDL_SetVideoMode(w, h, desired_bpp, video_flags);
   1.345      if (screen == NULL) {
   1.346 -        fprintf (stderr, "Couldn't set %dx%dx%d video mode: %s\n",
   1.347 -                 w, h, desired_bpp, SDL_GetError ());
   1.348 -        quit (1);
   1.349 +        fprintf(stderr, "Couldn't set %dx%dx%d video mode: %s\n",
   1.350 +                w, h, desired_bpp, SDL_GetError());
   1.351 +        quit(1);
   1.352      }
   1.353 -    printf ("Set%s %dx%dx%d mode\n",
   1.354 -            screen->flags & SDL_FULLSCREEN ? " fullscreen" : "",
   1.355 -            screen->w, screen->h, screen->format->BitsPerPixel);
   1.356 -    printf ("(video surface located in %s memory)\n",
   1.357 -            (screen->flags & SDL_HWSURFACE) ? "video" : "system");
   1.358 +    printf("Set%s %dx%dx%d mode\n",
   1.359 +           screen->flags & SDL_FULLSCREEN ? " fullscreen" : "",
   1.360 +           screen->w, screen->h, screen->format->BitsPerPixel);
   1.361 +    printf("(video surface located in %s memory)\n",
   1.362 +           (screen->flags & SDL_HWSURFACE) ? "video" : "system");
   1.363      if (screen->flags & SDL_DOUBLEBUF) {
   1.364 -        printf ("Double-buffering enabled\n");
   1.365 +        printf("Double-buffering enabled\n");
   1.366          flip = 1;
   1.367      }
   1.368  
   1.369      /* Set the window manager title bar */
   1.370 -    SDL_WM_SetCaption ("SDL test window", "testwin");
   1.371 +    SDL_WM_SetCaption("SDL test window", "testwin");
   1.372  
   1.373      /* Do all the drawing work */
   1.374  #ifdef BENCHMARK_SDL
   1.375 -    then = SDL_GetTicks ();
   1.376 -    DrawPict (screen, argv[1], speedy, flip, nofade);
   1.377 -    now = SDL_GetTicks ();
   1.378 -    printf ("Time: %d milliseconds\n", now - then);
   1.379 +    then = SDL_GetTicks();
   1.380 +    DrawPict(screen, argv[1], speedy, flip, nofade);
   1.381 +    now = SDL_GetTicks();
   1.382 +    printf("Time: %d milliseconds\n", now - then);
   1.383  #else
   1.384 -    DrawPict (screen, argv[1], speedy, flip, nofade);
   1.385 +    DrawPict(screen, argv[1], speedy, flip, nofade);
   1.386  #endif
   1.387 -    SDL_Delay (delay * 1000);
   1.388 -    SDL_Quit ();
   1.389 +    SDL_Delay(delay * 1000);
   1.390 +    SDL_Quit();
   1.391      return (0);
   1.392  }