test/testbitmap.c
branchSDL-1.3
changeset 1668 4da1ee79c9af
parent 1662 782fd950bd46
     1.1 --- a/test/testbitmap.c	Mon May 29 03:53:21 2006 +0000
     1.2 +++ b/test/testbitmap.c	Mon May 29 04:04:35 2006 +0000
     1.3 @@ -10,22 +10,22 @@
     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  SDL_Surface *
    1.17 -LoadXBM (SDL_Surface * screen, int w, int h, Uint8 * bits)
    1.18 +LoadXBM(SDL_Surface * screen, int w, int h, Uint8 * bits)
    1.19  {
    1.20      SDL_Surface *bitmap;
    1.21      Uint8 *line;
    1.22  
    1.23      /* Allocate the bitmap */
    1.24 -    bitmap = SDL_CreateRGBSurface (SDL_SWSURFACE, w, h, 1, 0, 0, 0, 0);
    1.25 +    bitmap = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 1, 0, 0, 0, 0);
    1.26      if (bitmap == NULL) {
    1.27 -        fprintf (stderr, "Couldn't allocate bitmap: %s\n", SDL_GetError ());
    1.28 +        fprintf(stderr, "Couldn't allocate bitmap: %s\n", SDL_GetError());
    1.29          return (NULL);
    1.30      }
    1.31  
    1.32 @@ -33,7 +33,7 @@
    1.33      line = (Uint8 *) bitmap->pixels;
    1.34      w = (w + 7) / 8;
    1.35      while (h--) {
    1.36 -        memcpy (line, bits, w);
    1.37 +        memcpy(line, bits, w);
    1.38          /* X11 Bitmap images have the bits reversed */
    1.39          {
    1.40              int i, j;
    1.41 @@ -54,7 +54,7 @@
    1.42  }
    1.43  
    1.44  int
    1.45 -main (int argc, char *argv[])
    1.46 +main(int argc, char *argv[])
    1.47  {
    1.48      SDL_Surface *screen;
    1.49      SDL_Surface *bitmap;
    1.50 @@ -70,8 +70,8 @@
    1.51  
    1.52  
    1.53      /* Initialize SDL */
    1.54 -    if (SDL_Init (SDL_INIT_VIDEO) < 0) {
    1.55 -        fprintf (stderr, "Couldn't initialize SDL: %s\n", SDL_GetError ());
    1.56 +    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
    1.57 +        fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
    1.58          return (1);
    1.59      }
    1.60  
    1.61 @@ -79,28 +79,28 @@
    1.62      videoflags = SDL_SWSURFACE;
    1.63      while (argc > 1) {
    1.64          --argc;
    1.65 -        if (strcmp (argv[argc - 1], "-bpp") == 0) {
    1.66 -            video_bpp = atoi (argv[argc]);
    1.67 +        if (strcmp(argv[argc - 1], "-bpp") == 0) {
    1.68 +            video_bpp = atoi(argv[argc]);
    1.69              --argc;
    1.70 -        } else if (strcmp (argv[argc], "-warp") == 0) {
    1.71 +        } else if (strcmp(argv[argc], "-warp") == 0) {
    1.72              videoflags |= SDL_HWPALETTE;
    1.73 -        } else if (strcmp (argv[argc], "-hw") == 0) {
    1.74 +        } else if (strcmp(argv[argc], "-hw") == 0) {
    1.75              videoflags |= SDL_HWSURFACE;
    1.76 -        } else if (strcmp (argv[argc], "-fullscreen") == 0) {
    1.77 +        } else if (strcmp(argv[argc], "-fullscreen") == 0) {
    1.78              videoflags |= SDL_FULLSCREEN;
    1.79          } else {
    1.80 -            fprintf (stderr,
    1.81 -                     "Usage: %s [-bpp N] [-warp] [-hw] [-fullscreen]\n",
    1.82 -                     argv[0]);
    1.83 -            quit (1);
    1.84 +            fprintf(stderr,
    1.85 +                    "Usage: %s [-bpp N] [-warp] [-hw] [-fullscreen]\n",
    1.86 +                    argv[0]);
    1.87 +            quit(1);
    1.88          }
    1.89      }
    1.90  
    1.91      /* Set 640x480 video mode */
    1.92 -    if ((screen = SDL_SetVideoMode (640, 480, video_bpp, videoflags)) == NULL) {
    1.93 -        fprintf (stderr, "Couldn't set 640x480x%d video mode: %s\n",
    1.94 -                 video_bpp, SDL_GetError ());
    1.95 -        quit (2);
    1.96 +    if ((screen = SDL_SetVideoMode(640, 480, video_bpp, videoflags)) == NULL) {
    1.97 +        fprintf(stderr, "Couldn't set 640x480x%d video mode: %s\n",
    1.98 +                video_bpp, SDL_GetError());
    1.99 +        quit(2);
   1.100      }
   1.101  
   1.102      if (video_bpp == 8) {
   1.103 @@ -110,25 +110,25 @@
   1.104              palette[i].g = 255 - i;
   1.105              palette[i].b = 255 - i;
   1.106          }
   1.107 -        SDL_SetColors (screen, palette, 0, 256);
   1.108 +        SDL_SetColors(screen, palette, 0, 256);
   1.109      }
   1.110  
   1.111      /* Set the surface pixels and refresh! */
   1.112 -    if (SDL_LockSurface (screen) < 0) {
   1.113 -        fprintf (stderr, "Couldn't lock the display surface: %s\n",
   1.114 -                 SDL_GetError ());
   1.115 -        quit (2);
   1.116 +    if (SDL_LockSurface(screen) < 0) {
   1.117 +        fprintf(stderr, "Couldn't lock the display surface: %s\n",
   1.118 +                SDL_GetError());
   1.119 +        quit(2);
   1.120      }
   1.121      buffer = (Uint8 *) screen->pixels;
   1.122      if (screen->format->BytesPerPixel != 2) {
   1.123          for (i = 0; i < screen->h; ++i) {
   1.124 -            memset (buffer, (i * 255) / screen->h, screen->pitch);
   1.125 +            memset(buffer, (i * 255) / screen->h, screen->pitch);
   1.126              buffer += screen->pitch;
   1.127          }
   1.128      } else {
   1.129          for (i = 0; i < screen->h; ++i) {
   1.130              gradient = ((i * 255) / screen->h);
   1.131 -            color = SDL_MapRGB (screen->format, gradient, gradient, gradient);
   1.132 +            color = SDL_MapRGB(screen->format, gradient, gradient, gradient);
   1.133              buffer16 = (Uint16 *) buffer;
   1.134              for (k = 0; k < screen->w; k++) {
   1.135                  *(buffer16 + k) = color;
   1.136 @@ -136,21 +136,21 @@
   1.137              buffer += screen->pitch;
   1.138          }
   1.139      }
   1.140 -    SDL_UnlockSurface (screen);
   1.141 -    SDL_UpdateRect (screen, 0, 0, 0, 0);
   1.142 +    SDL_UnlockSurface(screen);
   1.143 +    SDL_UpdateRect(screen, 0, 0, 0, 0);
   1.144  
   1.145      /* Load the bitmap */
   1.146 -    bitmap = LoadXBM (screen, picture_width, picture_height,
   1.147 -                      (Uint8 *) picture_bits);
   1.148 +    bitmap = LoadXBM(screen, picture_width, picture_height,
   1.149 +                     (Uint8 *) picture_bits);
   1.150      if (bitmap == NULL) {
   1.151 -        quit (1);
   1.152 +        quit(1);
   1.153      }
   1.154  
   1.155      /* Wait for a keystroke */
   1.156      done = 0;
   1.157      while (!done) {
   1.158          /* Check for events */
   1.159 -        while (SDL_PollEvent (&event)) {
   1.160 +        while (SDL_PollEvent(&event)) {
   1.161              switch (event.type) {
   1.162              case SDL_MOUSEBUTTONDOWN:
   1.163                  {
   1.164 @@ -160,8 +160,8 @@
   1.165                      dst.y = event.button.y - bitmap->h / 2;
   1.166                      dst.w = bitmap->w;
   1.167                      dst.h = bitmap->h;
   1.168 -                    SDL_BlitSurface (bitmap, NULL, screen, &dst);
   1.169 -                    SDL_UpdateRects (screen, 1, &dst);
   1.170 +                    SDL_BlitSurface(bitmap, NULL, screen, &dst);
   1.171 +                    SDL_UpdateRects(screen, 1, &dst);
   1.172                  }
   1.173                  break;
   1.174              case SDL_KEYDOWN:
   1.175 @@ -176,7 +176,7 @@
   1.176              }
   1.177          }
   1.178      }
   1.179 -    SDL_FreeSurface (bitmap);
   1.180 -    SDL_Quit ();
   1.181 +    SDL_FreeSurface(bitmap);
   1.182 +    SDL_Quit();
   1.183      return (0);
   1.184  }