test/testoverlay2.c
changeset 1151 be9c9c8f6d53
parent 1030 6b8f0543337c
child 1439 4d3bb026cd16
     1.1 --- a/test/testoverlay2.c	Wed Sep 28 06:38:22 2005 +0000
     1.2 +++ b/test/testoverlay2.c	Wed Sep 28 11:36:20 2005 +0000
     1.3 @@ -41,6 +41,14 @@
     1.4      {222, 222, 222}, {231, 198, 165}, {231, 231, 231}, {239, 206, 173}
     1.5  };
     1.6  
     1.7 +
     1.8 +/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
     1.9 +static void quit(int rc)
    1.10 +{
    1.11 +	SDL_Quit();
    1.12 +	exit(rc);
    1.13 +}
    1.14 +
    1.15  /* All RGB2YUV conversion code and some other parts of code has been taken from testoverlay.c */
    1.16  
    1.17  /* NOTE: These RGB conversion functions are not intended for speed,
    1.18 @@ -288,6 +296,12 @@
    1.19      int overlay_format=SDL_YUY2_OVERLAY;
    1.20      int scale=5;
    1.21  
    1.22 +    if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) < 0)
    1.23 +    {
    1.24 +        fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
    1.25 +        return 3;
    1.26 +    }
    1.27 +
    1.28      while ( argc > 1 )
    1.29      {
    1.30          if (strcmp(argv[1], "-fps")== 0)
    1.31 @@ -298,12 +312,12 @@
    1.32                  if (fps==0)
    1.33                  {
    1.34                      fprintf(stderr, "The -fps option requires an argument [from 1 to 1000], default is 12.\n");
    1.35 -                    return -1;
    1.36 +                    quit(10);
    1.37                  }
    1.38                  if ((fps<0) || (fps>1000))
    1.39                  {
    1.40                      fprintf(stderr, "The -fps option must be in range from 1 to 1000, default is 12.\n");
    1.41 -                    return -1;
    1.42 +                    quit(10);
    1.43                  }
    1.44                  argv += 2;
    1.45                  argc -= 2;
    1.46 @@ -311,7 +325,7 @@
    1.47              else
    1.48              {
    1.49                  fprintf(stderr, "The -fps option requires an argument [from 1 to 1000], default is 12.\n");
    1.50 -                return -1;
    1.51 +                quit(10);
    1.52              }
    1.53          } else
    1.54          if (strcmp(argv[1], "-format") == 0)
    1.55 @@ -331,7 +345,7 @@
    1.56                  else
    1.57                  {
    1.58                      fprintf(stderr, "The -format option %s is not recognized, see help for info.\n", argv[2]);
    1.59 -                    return -1;
    1.60 +                    quit(10);
    1.61                  }
    1.62                  argv += 2;
    1.63                  argc -= 2;
    1.64 @@ -339,7 +353,7 @@
    1.65              else
    1.66              {
    1.67                  fprintf(stderr, "The -format option requires an argument, default is YUY2.\n");
    1.68 -                return -1;
    1.69 +                quit(10);
    1.70              }
    1.71          } else
    1.72          if (strcmp(argv[1], "-scale") == 0)
    1.73 @@ -350,12 +364,12 @@
    1.74                  if (scale==0)
    1.75                  {
    1.76                      fprintf(stderr, "The -scale option requires an argument [from 1 to 50], default is 5.\n");
    1.77 -                    return -1;
    1.78 +                    quit(10);
    1.79                  }
    1.80                  if ((scale<0) || (scale>50))
    1.81                  {
    1.82                      fprintf(stderr, "The -scale option must be in range from 1 to 50, default is 5.\n");
    1.83 -                    return -1;
    1.84 +                    quit(10);
    1.85                  }
    1.86                  argv += 2;
    1.87                  argc -= 2;
    1.88 @@ -363,17 +377,17 @@
    1.89              else
    1.90              {
    1.91                  fprintf(stderr, "The -fps option requires an argument [from 1 to 1000], default is 12.\n");
    1.92 -                return -1;
    1.93 +                quit(10);
    1.94              }
    1.95          } else
    1.96          if ((strcmp(argv[1], "-help") == 0 ) || (strcmp(argv[1], "-h") == 0))
    1.97          {
    1.98              PrintUsage(argv[0]);
    1.99 -            return 0;
   1.100 +            quit(0);
   1.101          } else
   1.102          {
   1.103              fprintf(stderr, "Unrecognized option: %s.\n", argv[1]);
   1.104 -            return -1;
   1.105 +            quit(10);
   1.106          }
   1.107          break;
   1.108      }
   1.109 @@ -383,7 +397,7 @@
   1.110      {
   1.111          fprintf(stderr, "Can't allocate memory for movie !\n");
   1.112          free(RawMooseData);
   1.113 -        return 1;
   1.114 +        quit(1);
   1.115      }
   1.116  
   1.117      /* load the trojan moose images */
   1.118 @@ -392,27 +406,19 @@
   1.119      {
   1.120          fprintf(stderr, "Can't find the file moose.dat !\n");
   1.121          free(RawMooseData);
   1.122 -        return 2;
   1.123 +        quit(2);
   1.124      }
   1.125     
   1.126      SDL_RWread(handle, RawMooseData, MOOSEFRAME_SIZE, MOOSEFRAMES_COUNT);
   1.127  
   1.128      SDL_RWclose(handle);
   1.129  
   1.130 -    if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) < 0)
   1.131 -    {
   1.132 -        fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
   1.133 -        free(RawMooseData);
   1.134 -        return 3;
   1.135 -    }
   1.136 -    atexit(SDL_Quit);
   1.137 -
   1.138      /* Set video mode */
   1.139      if ( (screen=SDL_SetVideoMode(MOOSEPIC_W*scale, MOOSEPIC_H*scale, 0, SDL_RESIZABLE | SDL_SWSURFACE)) == NULL )
   1.140      {
   1.141          fprintf(stderr, "Couldn't set video mode: %s\n", 0, SDL_GetError());
   1.142          free(RawMooseData);
   1.143 -        return 4;
   1.144 +        quit(4);
   1.145      }
   1.146  
   1.147      /* Set the window manager title bar */
   1.148 @@ -426,7 +432,7 @@
   1.149          {
   1.150              fprintf(stderr, "Couldn't create SDL_Surfaces:%s\n", 0, SDL_GetError());
   1.151              free(RawMooseData);
   1.152 -            return 5;
   1.153 +            quit(5);
   1.154          }
   1.155          SDL_SetColors(MooseFrame[i], MooseColors, 0, 84);
   1.156  
   1.157 @@ -462,7 +468,7 @@
   1.158  		if(!newsurf)
   1.159  		{
   1.160                      fprintf(stderr, "Couldn't convert picture to 32bits RGB: %s\n", SDL_GetError());
   1.161 -                    return 6;
   1.162 +                    quit(6);
   1.163  		}
   1.164  		SDL_FreeSurface(MooseFrame[i]);
   1.165  		MooseFrame[i]=newsurf;
   1.166 @@ -475,7 +481,7 @@
   1.167      if (!overlay)
   1.168      {
   1.169          fprintf(stderr, "Couldn't create overlay: %s\n", SDL_GetError());
   1.170 -        return 7;
   1.171 +        quit(7);
   1.172      }
   1.173  
   1.174      printf("Created %dx%dx%d %s %s overlay\n",overlay->w,overlay->h,overlay->planes,
   1.175 @@ -538,7 +544,7 @@
   1.176                       {
   1.177                           SDL_FreeSurface(MooseFrame[i]);
   1.178                       }
   1.179 -                     return 0;
   1.180 +                     quit(0);
   1.181              }
   1.182          }
   1.183  
   1.184 @@ -586,6 +592,7 @@
   1.185          SDL_Delay(1);
   1.186      }
   1.187  
   1.188 +	SDL_Quit();
   1.189      return 0;
   1.190  }
   1.191