test/testoverlay2.c
branchSDL-1.3
changeset 1662 782fd950bd46
parent 1642 f1211a4b7380
child 1668 4da1ee79c9af
     1.1 --- a/test/testoverlay2.c	Sun May 21 17:27:13 2006 +0000
     1.2 +++ b/test/testoverlay2.c	Sun May 28 13:04:16 2006 +0000
     1.3 @@ -17,36 +17,120 @@
     1.4  #define MOOSEFRAME_SIZE (MOOSEPIC_W * MOOSEPIC_H)
     1.5  #define MOOSEFRAMES_COUNT 10
     1.6  
     1.7 -SDL_Color MooseColors[84]={
     1.8 -    { 49,  49,  49}, { 66,  24,   0}, { 66,  33,   0}, { 66,  66,  66},
     1.9 -    { 66, 115,  49}, { 74,  33,   0}, { 74,  41,  16}, { 82,  33,   8},
    1.10 -    { 82,  41,   8}, { 82,  49,  16}, { 82,  82,  82}, { 90,  41,   8},
    1.11 -    { 90,  41,  16}, { 90,  57,  24}, { 99,  49,  16}, { 99,  66,  24},
    1.12 -    { 99,  66,  33}, { 99,  74,  33}, {107,  57,  24}, {107,  82,  41},
    1.13 -    {115,  57,  33}, {115,  66,  33}, {115,  66,  41}, {115,  74,   0},
    1.14 -    {115,  90,  49}, {115, 115, 115}, {123,  82,   0}, {123,  99,  57},
    1.15 -    {132,  66,  41}, {132,  74,  41}, {132,  90,   8}, {132,  99,  33},
    1.16 -    {132,  99,  66}, {132, 107,  66}, {140,  74,  49}, {140,  99,  16},
    1.17 -    {140, 107,  74}, {140, 115,  74}, {148, 107,  24}, {148, 115,  82},
    1.18 -    {148, 123,  74}, {148, 123,  90}, {156, 115,  33}, {156, 115,  90},
    1.19 -    {156, 123,  82}, {156, 132,  82}, {156, 132,  99}, {156, 156, 156},
    1.20 -    {165, 123,  49}, {165, 123,  90}, {165, 132,  82}, {165, 132,  90},
    1.21 -    {165, 132,  99}, {165, 140,  90}, {173, 132,  57}, {173, 132,  99},
    1.22 -    {173, 140, 107}, {173, 140, 115}, {173, 148,  99}, {173, 173, 173},
    1.23 -    {181, 140,  74}, {181, 148, 115}, {181, 148, 123}, {181, 156, 107},
    1.24 -    {189, 148, 123}, {189, 156,  82}, {189, 156, 123}, {189, 156, 132},
    1.25 -    {189, 189, 189}, {198, 156, 123}, {198, 165, 132}, {206, 165,  99},
    1.26 -    {206, 165, 132}, {206, 173, 140}, {206, 206, 206}, {214, 173, 115},
    1.27 -    {214, 173, 140}, {222, 181, 148}, {222, 189, 132}, {222, 189, 156},
    1.28 -    {222, 222, 222}, {231, 198, 165}, {231, 231, 231}, {239, 206, 173}
    1.29 +SDL_Color MooseColors[84] = {
    1.30 +    {49, 49, 49}
    1.31 +    , {66, 24, 0}
    1.32 +    , {66, 33, 0}
    1.33 +    , {66, 66, 66}
    1.34 +    ,
    1.35 +    {66, 115, 49}
    1.36 +    , {74, 33, 0}
    1.37 +    , {74, 41, 16}
    1.38 +    , {82, 33, 8}
    1.39 +    ,
    1.40 +    {82, 41, 8}
    1.41 +    , {82, 49, 16}
    1.42 +    , {82, 82, 82}
    1.43 +    , {90, 41, 8}
    1.44 +    ,
    1.45 +    {90, 41, 16}
    1.46 +    , {90, 57, 24}
    1.47 +    , {99, 49, 16}
    1.48 +    , {99, 66, 24}
    1.49 +    ,
    1.50 +    {99, 66, 33}
    1.51 +    , {99, 74, 33}
    1.52 +    , {107, 57, 24}
    1.53 +    , {107, 82, 41}
    1.54 +    ,
    1.55 +    {115, 57, 33}
    1.56 +    , {115, 66, 33}
    1.57 +    , {115, 66, 41}
    1.58 +    , {115, 74, 0}
    1.59 +    ,
    1.60 +    {115, 90, 49}
    1.61 +    , {115, 115, 115}
    1.62 +    , {123, 82, 0}
    1.63 +    , {123, 99, 57}
    1.64 +    ,
    1.65 +    {132, 66, 41}
    1.66 +    , {132, 74, 41}
    1.67 +    , {132, 90, 8}
    1.68 +    , {132, 99, 33}
    1.69 +    ,
    1.70 +    {132, 99, 66}
    1.71 +    , {132, 107, 66}
    1.72 +    , {140, 74, 49}
    1.73 +    , {140, 99, 16}
    1.74 +    ,
    1.75 +    {140, 107, 74}
    1.76 +    , {140, 115, 74}
    1.77 +    , {148, 107, 24}
    1.78 +    , {148, 115, 82}
    1.79 +    ,
    1.80 +    {148, 123, 74}
    1.81 +    , {148, 123, 90}
    1.82 +    , {156, 115, 33}
    1.83 +    , {156, 115, 90}
    1.84 +    ,
    1.85 +    {156, 123, 82}
    1.86 +    , {156, 132, 82}
    1.87 +    , {156, 132, 99}
    1.88 +    , {156, 156, 156}
    1.89 +    ,
    1.90 +    {165, 123, 49}
    1.91 +    , {165, 123, 90}
    1.92 +    , {165, 132, 82}
    1.93 +    , {165, 132, 90}
    1.94 +    ,
    1.95 +    {165, 132, 99}
    1.96 +    , {165, 140, 90}
    1.97 +    , {173, 132, 57}
    1.98 +    , {173, 132, 99}
    1.99 +    ,
   1.100 +    {173, 140, 107}
   1.101 +    , {173, 140, 115}
   1.102 +    , {173, 148, 99}
   1.103 +    , {173, 173, 173}
   1.104 +    ,
   1.105 +    {181, 140, 74}
   1.106 +    , {181, 148, 115}
   1.107 +    , {181, 148, 123}
   1.108 +    , {181, 156, 107}
   1.109 +    ,
   1.110 +    {189, 148, 123}
   1.111 +    , {189, 156, 82}
   1.112 +    , {189, 156, 123}
   1.113 +    , {189, 156, 132}
   1.114 +    ,
   1.115 +    {189, 189, 189}
   1.116 +    , {198, 156, 123}
   1.117 +    , {198, 165, 132}
   1.118 +    , {206, 165, 99}
   1.119 +    ,
   1.120 +    {206, 165, 132}
   1.121 +    , {206, 173, 140}
   1.122 +    , {206, 206, 206}
   1.123 +    , {214, 173, 115}
   1.124 +    ,
   1.125 +    {214, 173, 140}
   1.126 +    , {222, 181, 148}
   1.127 +    , {222, 189, 132}
   1.128 +    , {222, 189, 156}
   1.129 +    ,
   1.130 +    {222, 222, 222}
   1.131 +    , {231, 198, 165}
   1.132 +    , {231, 231, 231}
   1.133 +    , {239, 206, 173}
   1.134  };
   1.135  
   1.136  
   1.137  /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
   1.138 -static void quit(int rc)
   1.139 +static void
   1.140 +quit (int rc)
   1.141  {
   1.142 -	SDL_Quit();
   1.143 -	exit(rc);
   1.144 +    SDL_Quit ();
   1.145 +    exit (rc);
   1.146  }
   1.147  
   1.148  /* All RGB2YUV conversion code and some other parts of code has been taken from testoverlay.c */
   1.149 @@ -55,12 +139,12 @@
   1.150           only as examples.
   1.151  */
   1.152  
   1.153 -void RGBtoYUV(Uint8 *rgb, int *yuv, int monochrome, int luminance)
   1.154 +void
   1.155 +RGBtoYUV (Uint8 * rgb, int *yuv, int monochrome, int luminance)
   1.156  {
   1.157 -    if (monochrome)
   1.158 -    {
   1.159 -#if 1 /* these are the two formulas that I found on the FourCC site... */
   1.160 -        yuv[0] = 0.299*rgb[0] + 0.587*rgb[1] + 0.114*rgb[2];
   1.161 +    if (monochrome) {
   1.162 +#if 1                           /* these are the two formulas that I found on the FourCC site... */
   1.163 +        yuv[0] = 0.299 * rgb[0] + 0.587 * rgb[1] + 0.114 * rgb[2];
   1.164          yuv[1] = 128;
   1.165          yuv[2] = 128;
   1.166  #else
   1.167 @@ -68,13 +152,11 @@
   1.168          yuv[1] = 128;
   1.169          yuv[2] = 128;
   1.170  #endif
   1.171 -    }
   1.172 -    else
   1.173 -    {
   1.174 -#if 1 /* these are the two formulas that I found on the FourCC site... */
   1.175 -        yuv[0] = 0.299*rgb[0] + 0.587*rgb[1] + 0.114*rgb[2];
   1.176 -        yuv[1] = (rgb[2]-yuv[0])*0.565 + 128;
   1.177 -        yuv[2] = (rgb[0]-yuv[0])*0.713 + 128;
   1.178 +    } else {
   1.179 +#if 1                           /* these are the two formulas that I found on the FourCC site... */
   1.180 +        yuv[0] = 0.299 * rgb[0] + 0.587 * rgb[1] + 0.114 * rgb[2];
   1.181 +        yuv[1] = (rgb[2] - yuv[0]) * 0.565 + 128;
   1.182 +        yuv[2] = (rgb[0] - yuv[0]) * 0.713 + 128;
   1.183  #else
   1.184          yuv[0] = (0.257 * rgb[0]) + (0.504 * rgb[1]) + (0.098 * rgb[2]) + 16;
   1.185          yuv[1] = 128 - (0.148 * rgb[0]) - (0.291 * rgb[1]) + (0.439 * rgb[2]);
   1.186 @@ -82,519 +164,486 @@
   1.187  #endif
   1.188      }
   1.189  
   1.190 -    if (luminance!=100)
   1.191 -    {
   1.192 -        yuv[0]=yuv[0]*luminance/100;
   1.193 -        if (yuv[0]>255)
   1.194 -            yuv[0]=255;
   1.195 +    if (luminance != 100) {
   1.196 +        yuv[0] = yuv[0] * luminance / 100;
   1.197 +        if (yuv[0] > 255)
   1.198 +            yuv[0] = 255;
   1.199      }
   1.200  }
   1.201  
   1.202 -void ConvertRGBtoYV12(SDL_Surface *s, SDL_Overlay *o, int monochrome, int luminance)
   1.203 +void
   1.204 +ConvertRGBtoYV12 (SDL_Surface * s, SDL_Overlay * o, int monochrome,
   1.205 +                  int luminance)
   1.206  {
   1.207 -	int x,y;
   1.208 -	int yuv[3];
   1.209 -	Uint8 *p,*op[3];
   1.210 +    int x, y;
   1.211 +    int yuv[3];
   1.212 +    Uint8 *p, *op[3];
   1.213  
   1.214 -	SDL_LockSurface(s);
   1.215 -	SDL_LockYUVOverlay(o);
   1.216 +    SDL_LockSurface (s);
   1.217 +    SDL_LockYUVOverlay (o);
   1.218  
   1.219 -	/* Convert */
   1.220 -	for(y=0; y<s->h && y<o->h; y++)
   1.221 -	{
   1.222 -		p=((Uint8 *) s->pixels)+s->pitch*y;
   1.223 -		op[0]=o->pixels[0]+o->pitches[0]*y;
   1.224 -		op[1]=o->pixels[1]+o->pitches[1]*(y/2);
   1.225 -		op[2]=o->pixels[2]+o->pitches[2]*(y/2);
   1.226 -		for(x=0; x<s->w && x<o->w; x++)
   1.227 -		{
   1.228 -			RGBtoYUV(p, yuv, monochrome, luminance);
   1.229 -			*(op[0]++)=yuv[0];
   1.230 -			if(x%2==0 && y%2==0)
   1.231 -			{
   1.232 -				*(op[1]++)=yuv[2];
   1.233 -				*(op[2]++)=yuv[1];
   1.234 -			}
   1.235 -			p+=s->format->BytesPerPixel;
   1.236 -		}
   1.237 -	}
   1.238 +    /* Convert */
   1.239 +    for (y = 0; y < s->h && y < o->h; y++) {
   1.240 +        p = ((Uint8 *) s->pixels) + s->pitch * y;
   1.241 +        op[0] = o->pixels[0] + o->pitches[0] * y;
   1.242 +        op[1] = o->pixels[1] + o->pitches[1] * (y / 2);
   1.243 +        op[2] = o->pixels[2] + o->pitches[2] * (y / 2);
   1.244 +        for (x = 0; x < s->w && x < o->w; x++) {
   1.245 +            RGBtoYUV (p, yuv, monochrome, luminance);
   1.246 +            *(op[0]++) = yuv[0];
   1.247 +            if (x % 2 == 0 && y % 2 == 0) {
   1.248 +                *(op[1]++) = yuv[2];
   1.249 +                *(op[2]++) = yuv[1];
   1.250 +            }
   1.251 +            p += s->format->BytesPerPixel;
   1.252 +        }
   1.253 +    }
   1.254  
   1.255 -	SDL_UnlockYUVOverlay(o);
   1.256 -	SDL_UnlockSurface(s);
   1.257 +    SDL_UnlockYUVOverlay (o);
   1.258 +    SDL_UnlockSurface (s);
   1.259  }
   1.260  
   1.261 -void ConvertRGBtoIYUV(SDL_Surface *s, SDL_Overlay *o, int monochrome, int luminance)
   1.262 +void
   1.263 +ConvertRGBtoIYUV (SDL_Surface * s, SDL_Overlay * o, int monochrome,
   1.264 +                  int luminance)
   1.265  {
   1.266 -	int x,y;
   1.267 -	int yuv[3];
   1.268 -	Uint8 *p,*op[3];
   1.269 +    int x, y;
   1.270 +    int yuv[3];
   1.271 +    Uint8 *p, *op[3];
   1.272  
   1.273 -	SDL_LockSurface(s);
   1.274 -	SDL_LockYUVOverlay(o);
   1.275 +    SDL_LockSurface (s);
   1.276 +    SDL_LockYUVOverlay (o);
   1.277  
   1.278 -	/* Convert */
   1.279 -	for(y=0; y<s->h && y<o->h; y++)
   1.280 -	{
   1.281 -		p=((Uint8 *) s->pixels)+s->pitch*y;
   1.282 -		op[0]=o->pixels[0]+o->pitches[0]*y;
   1.283 -		op[1]=o->pixels[1]+o->pitches[1]*(y/2);
   1.284 -		op[2]=o->pixels[2]+o->pitches[2]*(y/2);
   1.285 -		for(x=0; x<s->w && x<o->w; x++)
   1.286 -		{
   1.287 -			RGBtoYUV(p,yuv, monochrome, luminance);
   1.288 -			*(op[0]++)=yuv[0];
   1.289 -			if(x%2==0 && y%2==0)
   1.290 -			{
   1.291 -				*(op[1]++)=yuv[1];
   1.292 -				*(op[2]++)=yuv[2];
   1.293 -			}
   1.294 -			p+=s->format->BytesPerPixel;
   1.295 -		}
   1.296 -	}
   1.297 +    /* Convert */
   1.298 +    for (y = 0; y < s->h && y < o->h; y++) {
   1.299 +        p = ((Uint8 *) s->pixels) + s->pitch * y;
   1.300 +        op[0] = o->pixels[0] + o->pitches[0] * y;
   1.301 +        op[1] = o->pixels[1] + o->pitches[1] * (y / 2);
   1.302 +        op[2] = o->pixels[2] + o->pitches[2] * (y / 2);
   1.303 +        for (x = 0; x < s->w && x < o->w; x++) {
   1.304 +            RGBtoYUV (p, yuv, monochrome, luminance);
   1.305 +            *(op[0]++) = yuv[0];
   1.306 +            if (x % 2 == 0 && y % 2 == 0) {
   1.307 +                *(op[1]++) = yuv[1];
   1.308 +                *(op[2]++) = yuv[2];
   1.309 +            }
   1.310 +            p += s->format->BytesPerPixel;
   1.311 +        }
   1.312 +    }
   1.313  
   1.314 -	SDL_UnlockYUVOverlay(o);
   1.315 -	SDL_UnlockSurface(s);
   1.316 +    SDL_UnlockYUVOverlay (o);
   1.317 +    SDL_UnlockSurface (s);
   1.318  }
   1.319  
   1.320 -void ConvertRGBtoUYVY(SDL_Surface *s, SDL_Overlay *o, int monochrome, int luminance)
   1.321 +void
   1.322 +ConvertRGBtoUYVY (SDL_Surface * s, SDL_Overlay * o, int monochrome,
   1.323 +                  int luminance)
   1.324  {
   1.325 -	int x,y;
   1.326 -	int yuv[3];
   1.327 -	Uint8 *p,*op;
   1.328 +    int x, y;
   1.329 +    int yuv[3];
   1.330 +    Uint8 *p, *op;
   1.331  
   1.332 -	SDL_LockSurface(s);
   1.333 -	SDL_LockYUVOverlay(o);
   1.334 +    SDL_LockSurface (s);
   1.335 +    SDL_LockYUVOverlay (o);
   1.336  
   1.337 -	for(y=0; y<s->h && y<o->h; y++)
   1.338 -	{
   1.339 -		p=((Uint8 *) s->pixels)+s->pitch*y;
   1.340 -		op=o->pixels[0]+o->pitches[0]*y;
   1.341 -		for(x=0; x<s->w && x<o->w; x++)
   1.342 -		{
   1.343 -			RGBtoYUV(p, yuv, monochrome, luminance);
   1.344 -			if(x%2==0)
   1.345 -			{
   1.346 -				*(op++)=yuv[1];
   1.347 -				*(op++)=yuv[0];
   1.348 -				*(op++)=yuv[2];
   1.349 -			}
   1.350 -			else
   1.351 -				*(op++)=yuv[0];
   1.352 +    for (y = 0; y < s->h && y < o->h; y++) {
   1.353 +        p = ((Uint8 *) s->pixels) + s->pitch * y;
   1.354 +        op = o->pixels[0] + o->pitches[0] * y;
   1.355 +        for (x = 0; x < s->w && x < o->w; x++) {
   1.356 +            RGBtoYUV (p, yuv, monochrome, luminance);
   1.357 +            if (x % 2 == 0) {
   1.358 +                *(op++) = yuv[1];
   1.359 +                *(op++) = yuv[0];
   1.360 +                *(op++) = yuv[2];
   1.361 +            } else
   1.362 +                *(op++) = yuv[0];
   1.363  
   1.364 -			p+=s->format->BytesPerPixel;
   1.365 -		}
   1.366 -	}
   1.367 +            p += s->format->BytesPerPixel;
   1.368 +        }
   1.369 +    }
   1.370  
   1.371 -	SDL_UnlockYUVOverlay(o);
   1.372 -	SDL_UnlockSurface(s);
   1.373 +    SDL_UnlockYUVOverlay (o);
   1.374 +    SDL_UnlockSurface (s);
   1.375  }
   1.376  
   1.377 -void ConvertRGBtoYVYU(SDL_Surface *s, SDL_Overlay *o, int monochrome, int luminance)
   1.378 +void
   1.379 +ConvertRGBtoYVYU (SDL_Surface * s, SDL_Overlay * o, int monochrome,
   1.380 +                  int luminance)
   1.381  {
   1.382 -	int x,y;
   1.383 -	int yuv[3];
   1.384 -	Uint8 *p,*op;
   1.385 +    int x, y;
   1.386 +    int yuv[3];
   1.387 +    Uint8 *p, *op;
   1.388  
   1.389 -	SDL_LockSurface(s);
   1.390 -	SDL_LockYUVOverlay(o);
   1.391 +    SDL_LockSurface (s);
   1.392 +    SDL_LockYUVOverlay (o);
   1.393  
   1.394 -	for(y=0; y<s->h && y<o->h; y++)
   1.395 -	{
   1.396 -		p=((Uint8 *) s->pixels)+s->pitch*y;
   1.397 -		op=o->pixels[0]+o->pitches[0]*y;
   1.398 -		for(x=0; x<s->w && x<o->w; x++)
   1.399 -		{
   1.400 -			RGBtoYUV(p,yuv, monochrome, luminance);
   1.401 -			if(x%2==0)
   1.402 -			{
   1.403 -				*(op++)=yuv[0];
   1.404 -				*(op++)=yuv[2];
   1.405 -				op[1]=yuv[1];
   1.406 -			}
   1.407 -			else
   1.408 -			{
   1.409 -				*op=yuv[0];
   1.410 -				op+=2;
   1.411 -			}
   1.412 +    for (y = 0; y < s->h && y < o->h; y++) {
   1.413 +        p = ((Uint8 *) s->pixels) + s->pitch * y;
   1.414 +        op = o->pixels[0] + o->pitches[0] * y;
   1.415 +        for (x = 0; x < s->w && x < o->w; x++) {
   1.416 +            RGBtoYUV (p, yuv, monochrome, luminance);
   1.417 +            if (x % 2 == 0) {
   1.418 +                *(op++) = yuv[0];
   1.419 +                *(op++) = yuv[2];
   1.420 +                op[1] = yuv[1];
   1.421 +            } else {
   1.422 +                *op = yuv[0];
   1.423 +                op += 2;
   1.424 +            }
   1.425  
   1.426 -			p+=s->format->BytesPerPixel;
   1.427 -		}
   1.428 -	}
   1.429 +            p += s->format->BytesPerPixel;
   1.430 +        }
   1.431 +    }
   1.432  
   1.433 -	SDL_UnlockYUVOverlay(o);
   1.434 -	SDL_UnlockSurface(s);
   1.435 +    SDL_UnlockYUVOverlay (o);
   1.436 +    SDL_UnlockSurface (s);
   1.437  }
   1.438  
   1.439 -void ConvertRGBtoYUY2(SDL_Surface *s, SDL_Overlay *o, int monochrome, int luminance)
   1.440 +void
   1.441 +ConvertRGBtoYUY2 (SDL_Surface * s, SDL_Overlay * o, int monochrome,
   1.442 +                  int luminance)
   1.443  {
   1.444 -	int x,y;
   1.445 -	int yuv[3];
   1.446 -	Uint8 *p,*op;
   1.447 +    int x, y;
   1.448 +    int yuv[3];
   1.449 +    Uint8 *p, *op;
   1.450  
   1.451 -	SDL_LockSurface(s);
   1.452 -	SDL_LockYUVOverlay(o);
   1.453 -        
   1.454 -	for(y=0; y<s->h && y<o->h; y++)
   1.455 -	{
   1.456 -		p=((Uint8 *) s->pixels)+s->pitch*y;
   1.457 -		op=o->pixels[0]+o->pitches[0]*y;
   1.458 -		for(x=0; x<s->w && x<o->w; x++)
   1.459 -		{
   1.460 -			RGBtoYUV(p,yuv, monochrome, luminance);
   1.461 -			if(x%2==0)
   1.462 -			{
   1.463 -				*(op++)=yuv[0];
   1.464 -				*(op++)=yuv[1];
   1.465 -				op[1]=yuv[2];
   1.466 -			}
   1.467 -			else
   1.468 -			{
   1.469 -				*op=yuv[0];
   1.470 -				op+=2;
   1.471 -			}
   1.472 +    SDL_LockSurface (s);
   1.473 +    SDL_LockYUVOverlay (o);
   1.474  
   1.475 -			p+=s->format->BytesPerPixel;
   1.476 -		}
   1.477 -	}
   1.478 +    for (y = 0; y < s->h && y < o->h; y++) {
   1.479 +        p = ((Uint8 *) s->pixels) + s->pitch * y;
   1.480 +        op = o->pixels[0] + o->pitches[0] * y;
   1.481 +        for (x = 0; x < s->w && x < o->w; x++) {
   1.482 +            RGBtoYUV (p, yuv, monochrome, luminance);
   1.483 +            if (x % 2 == 0) {
   1.484 +                *(op++) = yuv[0];
   1.485 +                *(op++) = yuv[1];
   1.486 +                op[1] = yuv[2];
   1.487 +            } else {
   1.488 +                *op = yuv[0];
   1.489 +                op += 2;
   1.490 +            }
   1.491  
   1.492 -	SDL_UnlockYUVOverlay(o);
   1.493 -	SDL_UnlockSurface(s);
   1.494 +            p += s->format->BytesPerPixel;
   1.495 +        }
   1.496 +    }
   1.497 +
   1.498 +    SDL_UnlockYUVOverlay (o);
   1.499 +    SDL_UnlockSurface (s);
   1.500  }
   1.501  
   1.502 -static void PrintUsage(char *argv0)
   1.503 +static void
   1.504 +PrintUsage (char *argv0)
   1.505  {
   1.506 -    fprintf(stderr, "Usage: %s [arg] [arg] [arg] ...\n", argv0);
   1.507 -    fprintf(stderr, "\n");
   1.508 -    fprintf(stderr, "Where 'arg' is any of the following options:\n");
   1.509 -    fprintf(stderr, "\n");
   1.510 -    fprintf(stderr, "	-fps <frames per second>\n");
   1.511 -    fprintf(stderr, "	-format <fmt> (one of the: YV12, IYUV, YUY2, UYVY, YVYU)\n");
   1.512 -    fprintf(stderr, "	-scale <scale factor> (initial scale of the overlay)\n");
   1.513 -    fprintf(stderr, "	-help (shows this help)\n");
   1.514 -    fprintf(stderr, "\n");
   1.515 -    fprintf(stderr, "Press ESC to exit, or SPACE to freeze the movie while application running.\n");
   1.516 -    fprintf(stderr, "\n");
   1.517 +    fprintf (stderr, "Usage: %s [arg] [arg] [arg] ...\n", argv0);
   1.518 +    fprintf (stderr, "\n");
   1.519 +    fprintf (stderr, "Where 'arg' is any of the following options:\n");
   1.520 +    fprintf (stderr, "\n");
   1.521 +    fprintf (stderr, "	-fps <frames per second>\n");
   1.522 +    fprintf (stderr,
   1.523 +             "	-format <fmt> (one of the: YV12, IYUV, YUY2, UYVY, YVYU)\n");
   1.524 +    fprintf (stderr,
   1.525 +             "	-scale <scale factor> (initial scale of the overlay)\n");
   1.526 +    fprintf (stderr, "	-help (shows this help)\n");
   1.527 +    fprintf (stderr, "\n");
   1.528 +    fprintf (stderr,
   1.529 +             "Press ESC to exit, or SPACE to freeze the movie while application running.\n");
   1.530 +    fprintf (stderr, "\n");
   1.531  }
   1.532  
   1.533 -int main(int argc, char **argv)
   1.534 +int
   1.535 +main (int argc, char **argv)
   1.536  {
   1.537 -    Uint8* RawMooseData;
   1.538 -    SDL_RWops* handle;
   1.539 -    SDL_Surface* screen;
   1.540 -    SDL_Surface* MooseFrame[MOOSEFRAMES_COUNT];
   1.541 -    SDL_Overlay* overlay;
   1.542 +    Uint8 *RawMooseData;
   1.543 +    SDL_RWops *handle;
   1.544 +    SDL_Surface *screen;
   1.545 +    SDL_Surface *MooseFrame[MOOSEFRAMES_COUNT];
   1.546 +    SDL_Overlay *overlay;
   1.547      SDL_Rect overlayrect;
   1.548      SDL_Event event;
   1.549      Uint32 lastftick;
   1.550 -    int paused=0;
   1.551 -    int resized=0;
   1.552 +    int paused = 0;
   1.553 +    int resized = 0;
   1.554      int i;
   1.555 -    int fps=12;
   1.556 +    int fps = 12;
   1.557      int fpsdelay;
   1.558 -    int overlay_format=SDL_YUY2_OVERLAY;
   1.559 -    int scale=5;
   1.560 +    int overlay_format = SDL_YUY2_OVERLAY;
   1.561 +    int scale = 5;
   1.562  
   1.563 -    if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) < 0)
   1.564 -    {
   1.565 -        fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
   1.566 +    if (SDL_Init (SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) < 0) {
   1.567 +        fprintf (stderr, "Couldn't initialize SDL: %s\n", SDL_GetError ());
   1.568          return 3;
   1.569      }
   1.570  
   1.571 -    while ( argc > 1 )
   1.572 -    {
   1.573 -        if (strcmp(argv[1], "-fps")== 0)
   1.574 -        {
   1.575 -            if (argv[2])
   1.576 -            {
   1.577 -                fps = atoi(argv[2]);
   1.578 -                if (fps==0)
   1.579 -                {
   1.580 -                    fprintf(stderr, "The -fps option requires an argument [from 1 to 1000], default is 12.\n");
   1.581 -                    quit(10);
   1.582 +    while (argc > 1) {
   1.583 +        if (strcmp (argv[1], "-fps") == 0) {
   1.584 +            if (argv[2]) {
   1.585 +                fps = atoi (argv[2]);
   1.586 +                if (fps == 0) {
   1.587 +                    fprintf (stderr,
   1.588 +                             "The -fps option requires an argument [from 1 to 1000], default is 12.\n");
   1.589 +                    quit (10);
   1.590                  }
   1.591 -                if ((fps<0) || (fps>1000))
   1.592 -                {
   1.593 -                    fprintf(stderr, "The -fps option must be in range from 1 to 1000, default is 12.\n");
   1.594 -                    quit(10);
   1.595 +                if ((fps < 0) || (fps > 1000)) {
   1.596 +                    fprintf (stderr,
   1.597 +                             "The -fps option must be in range from 1 to 1000, default is 12.\n");
   1.598 +                    quit (10);
   1.599                  }
   1.600                  argv += 2;
   1.601                  argc -= 2;
   1.602 +            } else {
   1.603 +                fprintf (stderr,
   1.604 +                         "The -fps option requires an argument [from 1 to 1000], default is 12.\n");
   1.605 +                quit (10);
   1.606              }
   1.607 -            else
   1.608 -            {
   1.609 -                fprintf(stderr, "The -fps option requires an argument [from 1 to 1000], default is 12.\n");
   1.610 -                quit(10);
   1.611 -            }
   1.612 -        } else
   1.613 -        if (strcmp(argv[1], "-format") == 0)
   1.614 -        {
   1.615 -            if (argv[2])
   1.616 -            {
   1.617 -                if (!strcmp(argv[2],"YV12"))
   1.618 +        } else if (strcmp (argv[1], "-format") == 0) {
   1.619 +            if (argv[2]) {
   1.620 +                if (!strcmp (argv[2], "YV12"))
   1.621                      overlay_format = SDL_YV12_OVERLAY;
   1.622 -                else if(!strcmp(argv[2],"IYUV"))
   1.623 +                else if (!strcmp (argv[2], "IYUV"))
   1.624                      overlay_format = SDL_IYUV_OVERLAY;
   1.625 -                else if(!strcmp(argv[2],"YUY2"))
   1.626 +                else if (!strcmp (argv[2], "YUY2"))
   1.627                      overlay_format = SDL_YUY2_OVERLAY;
   1.628 -                else if(!strcmp(argv[2],"UYVY"))
   1.629 +                else if (!strcmp (argv[2], "UYVY"))
   1.630                      overlay_format = SDL_UYVY_OVERLAY;
   1.631 -                else if(!strcmp(argv[2],"YVYU"))
   1.632 +                else if (!strcmp (argv[2], "YVYU"))
   1.633                      overlay_format = SDL_YVYU_OVERLAY;
   1.634 -                else
   1.635 -                {
   1.636 -                    fprintf(stderr, "The -format option %s is not recognized, see help for info.\n", argv[2]);
   1.637 -                    quit(10);
   1.638 +                else {
   1.639 +                    fprintf (stderr,
   1.640 +                             "The -format option %s is not recognized, see help for info.\n",
   1.641 +                             argv[2]);
   1.642 +                    quit (10);
   1.643                  }
   1.644                  argv += 2;
   1.645                  argc -= 2;
   1.646 +            } else {
   1.647 +                fprintf (stderr,
   1.648 +                         "The -format option requires an argument, default is YUY2.\n");
   1.649 +                quit (10);
   1.650              }
   1.651 -            else
   1.652 -            {
   1.653 -                fprintf(stderr, "The -format option requires an argument, default is YUY2.\n");
   1.654 -                quit(10);
   1.655 -            }
   1.656 -        } else
   1.657 -        if (strcmp(argv[1], "-scale") == 0)
   1.658 -        {
   1.659 -            if (argv[2])
   1.660 -            {
   1.661 -                scale = atoi(argv[2]);
   1.662 -                if (scale==0)
   1.663 -                {
   1.664 -                    fprintf(stderr, "The -scale option requires an argument [from 1 to 50], default is 5.\n");
   1.665 -                    quit(10);
   1.666 +        } else if (strcmp (argv[1], "-scale") == 0) {
   1.667 +            if (argv[2]) {
   1.668 +                scale = atoi (argv[2]);
   1.669 +                if (scale == 0) {
   1.670 +                    fprintf (stderr,
   1.671 +                             "The -scale option requires an argument [from 1 to 50], default is 5.\n");
   1.672 +                    quit (10);
   1.673                  }
   1.674 -                if ((scale<0) || (scale>50))
   1.675 -                {
   1.676 -                    fprintf(stderr, "The -scale option must be in range from 1 to 50, default is 5.\n");
   1.677 -                    quit(10);
   1.678 +                if ((scale < 0) || (scale > 50)) {
   1.679 +                    fprintf (stderr,
   1.680 +                             "The -scale option must be in range from 1 to 50, default is 5.\n");
   1.681 +                    quit (10);
   1.682                  }
   1.683                  argv += 2;
   1.684                  argc -= 2;
   1.685 +            } else {
   1.686 +                fprintf (stderr,
   1.687 +                         "The -fps option requires an argument [from 1 to 1000], default is 12.\n");
   1.688 +                quit (10);
   1.689              }
   1.690 -            else
   1.691 -            {
   1.692 -                fprintf(stderr, "The -fps option requires an argument [from 1 to 1000], default is 12.\n");
   1.693 -                quit(10);
   1.694 -            }
   1.695 -        } else
   1.696 -        if ((strcmp(argv[1], "-help") == 0 ) || (strcmp(argv[1], "-h") == 0))
   1.697 -        {
   1.698 -            PrintUsage(argv[0]);
   1.699 -            quit(0);
   1.700 -        } else
   1.701 -        {
   1.702 -            fprintf(stderr, "Unrecognized option: %s.\n", argv[1]);
   1.703 -            quit(10);
   1.704 +        } else if ((strcmp (argv[1], "-help") == 0)
   1.705 +                   || (strcmp (argv[1], "-h") == 0)) {
   1.706 +            PrintUsage (argv[0]);
   1.707 +            quit (0);
   1.708 +        } else {
   1.709 +            fprintf (stderr, "Unrecognized option: %s.\n", argv[1]);
   1.710 +            quit (10);
   1.711          }
   1.712          break;
   1.713      }
   1.714 -   
   1.715 -    RawMooseData=(Uint8*)malloc(MOOSEFRAME_SIZE * MOOSEFRAMES_COUNT);
   1.716 -    if (RawMooseData==NULL)
   1.717 -    {
   1.718 -        fprintf(stderr, "Can't allocate memory for movie !\n");
   1.719 -        free(RawMooseData);
   1.720 -        quit(1);
   1.721 +
   1.722 +    RawMooseData = (Uint8 *) malloc (MOOSEFRAME_SIZE * MOOSEFRAMES_COUNT);
   1.723 +    if (RawMooseData == NULL) {
   1.724 +        fprintf (stderr, "Can't allocate memory for movie !\n");
   1.725 +        free (RawMooseData);
   1.726 +        quit (1);
   1.727      }
   1.728  
   1.729      /* load the trojan moose images */
   1.730 -    handle=SDL_RWFromFile("moose.dat", "rb");
   1.731 -    if (handle==NULL)
   1.732 -    {
   1.733 -        fprintf(stderr, "Can't find the file moose.dat !\n");
   1.734 -        free(RawMooseData);
   1.735 -        quit(2);
   1.736 +    handle = SDL_RWFromFile ("moose.dat", "rb");
   1.737 +    if (handle == NULL) {
   1.738 +        fprintf (stderr, "Can't find the file moose.dat !\n");
   1.739 +        free (RawMooseData);
   1.740 +        quit (2);
   1.741      }
   1.742 -   
   1.743 -    SDL_RWread(handle, RawMooseData, MOOSEFRAME_SIZE, MOOSEFRAMES_COUNT);
   1.744  
   1.745 -    SDL_RWclose(handle);
   1.746 +    SDL_RWread (handle, RawMooseData, MOOSEFRAME_SIZE, MOOSEFRAMES_COUNT);
   1.747 +
   1.748 +    SDL_RWclose (handle);
   1.749  
   1.750      /* Set video mode */
   1.751 -    if ( (screen=SDL_SetVideoMode(MOOSEPIC_W*scale, MOOSEPIC_H*scale, 0, SDL_RESIZABLE | SDL_SWSURFACE)) == NULL )
   1.752 -    {
   1.753 -        fprintf(stderr, "Couldn't set video mode: %s\n", SDL_GetError());
   1.754 -        free(RawMooseData);
   1.755 -        quit(4);
   1.756 +    if ((screen =
   1.757 +         SDL_SetVideoMode (MOOSEPIC_W * scale, MOOSEPIC_H * scale, 0,
   1.758 +                           SDL_RESIZABLE | SDL_SWSURFACE)) == NULL) {
   1.759 +        fprintf (stderr, "Couldn't set video mode: %s\n", SDL_GetError ());
   1.760 +        free (RawMooseData);
   1.761 +        quit (4);
   1.762      }
   1.763  
   1.764      /* Set the window manager title bar */
   1.765 -    SDL_WM_SetCaption("SDL test overlay: running moose", "testoverlay2");
   1.766 +    SDL_WM_SetCaption ("SDL test overlay: running moose", "testoverlay2");
   1.767  
   1.768 -    for (i=0; i<MOOSEFRAMES_COUNT; i++)
   1.769 -    {
   1.770 -        MooseFrame[i]=SDL_CreateRGBSurfaceFrom(RawMooseData+i*MOOSEFRAME_SIZE, MOOSEPIC_W,
   1.771 -                                               MOOSEPIC_H, 8, MOOSEPIC_W, 0, 0, 0, 0);
   1.772 -        if (MooseFrame[i]==NULL)
   1.773 +    for (i = 0; i < MOOSEFRAMES_COUNT; i++) {
   1.774 +        MooseFrame[i] =
   1.775 +            SDL_CreateRGBSurfaceFrom (RawMooseData + i * MOOSEFRAME_SIZE,
   1.776 +                                      MOOSEPIC_W, MOOSEPIC_H, 8, MOOSEPIC_W,
   1.777 +                                      0, 0, 0, 0);
   1.778 +        if (MooseFrame[i] == NULL) {
   1.779 +            fprintf (stderr, "Couldn't create SDL_Surfaces:%s\n",
   1.780 +                     SDL_GetError ());
   1.781 +            free (RawMooseData);
   1.782 +            quit (5);
   1.783 +        }
   1.784 +        SDL_SetColors (MooseFrame[i], MooseColors, 0, 84);
   1.785 +
   1.786          {
   1.787 -            fprintf(stderr, "Couldn't create SDL_Surfaces:%s\n", SDL_GetError());
   1.788 -            free(RawMooseData);
   1.789 -            quit(5);
   1.790 +            SDL_Surface *newsurf;
   1.791 +            SDL_PixelFormat format;
   1.792 +
   1.793 +            format.palette = NULL;
   1.794 +            format.BitsPerPixel = 32;
   1.795 +            format.BytesPerPixel = 4;
   1.796 +#if SDL_BYTEORDER == SDL_LIL_ENDIAN
   1.797 +            format.Rshift = 0;
   1.798 +            format.Gshift = 8;
   1.799 +            format.Bshift = 16;
   1.800 +#else
   1.801 +            format.Rshift = 24;
   1.802 +            format.Gshift = 16;
   1.803 +            format.Bshift = 8;
   1.804 +#endif
   1.805 +            format.Ashift = 0;
   1.806 +            format.Rmask = 0xff << format.Rshift;
   1.807 +            format.Gmask = 0xff << format.Gshift;
   1.808 +            format.Bmask = 0xff << format.Bshift;
   1.809 +            format.Amask = 0;
   1.810 +            format.Rloss = 0;
   1.811 +            format.Gloss = 0;
   1.812 +            format.Bloss = 0;
   1.813 +            format.Aloss = 8;
   1.814 +            format.colorkey = 0;
   1.815 +            format.alpha = 0;
   1.816 +
   1.817 +            newsurf =
   1.818 +                SDL_ConvertSurface (MooseFrame[i], &format, SDL_SWSURFACE);
   1.819 +            if (!newsurf) {
   1.820 +                fprintf (stderr,
   1.821 +                         "Couldn't convert picture to 32bits RGB: %s\n",
   1.822 +                         SDL_GetError ());
   1.823 +                quit (6);
   1.824 +            }
   1.825 +            SDL_FreeSurface (MooseFrame[i]);
   1.826 +            MooseFrame[i] = newsurf;
   1.827          }
   1.828 -        SDL_SetColors(MooseFrame[i], MooseColors, 0, 84);
   1.829 -
   1.830 -	{
   1.831 -		SDL_Surface *newsurf;
   1.832 -		SDL_PixelFormat format;
   1.833 -
   1.834 -		format.palette=NULL;
   1.835 -		format.BitsPerPixel=32;
   1.836 -		format.BytesPerPixel=4;
   1.837 -#if SDL_BYTEORDER == SDL_LIL_ENDIAN
   1.838 -		format.Rshift=0;
   1.839 -		format.Gshift=8;
   1.840 -		format.Bshift=16;
   1.841 -#else
   1.842 -		format.Rshift=24;
   1.843 -		format.Gshift=16;
   1.844 -		format.Bshift=8;
   1.845 -#endif
   1.846 -		format.Ashift=0;
   1.847 -		format.Rmask=0xff<<format.Rshift;
   1.848 -		format.Gmask=0xff<<format.Gshift;
   1.849 -		format.Bmask=0xff<<format.Bshift;
   1.850 -		format.Amask=0;
   1.851 -		format.Rloss=0;
   1.852 -		format.Gloss=0;
   1.853 -		format.Bloss=0;
   1.854 -		format.Aloss=8;
   1.855 -		format.colorkey=0;
   1.856 -		format.alpha=0;
   1.857 -
   1.858 -		newsurf=SDL_ConvertSurface(MooseFrame[i], &format, SDL_SWSURFACE);
   1.859 -		if(!newsurf)
   1.860 -		{
   1.861 -                    fprintf(stderr, "Couldn't convert picture to 32bits RGB: %s\n", SDL_GetError());
   1.862 -                    quit(6);
   1.863 -		}
   1.864 -		SDL_FreeSurface(MooseFrame[i]);
   1.865 -		MooseFrame[i]=newsurf;
   1.866 -	}
   1.867      }
   1.868  
   1.869 -    free(RawMooseData);
   1.870 +    free (RawMooseData);
   1.871  
   1.872 -    overlay=SDL_CreateYUVOverlay(MOOSEPIC_W, MOOSEPIC_H, overlay_format, screen);
   1.873 -    if (!overlay)
   1.874 -    {
   1.875 -        fprintf(stderr, "Couldn't create overlay: %s\n", SDL_GetError());
   1.876 -        quit(7);
   1.877 +    overlay =
   1.878 +        SDL_CreateYUVOverlay (MOOSEPIC_W, MOOSEPIC_H, overlay_format, screen);
   1.879 +    if (!overlay) {
   1.880 +        fprintf (stderr, "Couldn't create overlay: %s\n", SDL_GetError ());
   1.881 +        quit (7);
   1.882      }
   1.883  
   1.884 -    printf("Created %dx%dx%d %s %s overlay\n",overlay->w,overlay->h,overlay->planes,
   1.885 -           overlay->hw_overlay?"hardware":"software",
   1.886 -           overlay->format==SDL_YV12_OVERLAY?"YV12":
   1.887 -           overlay->format==SDL_IYUV_OVERLAY?"IYUV":
   1.888 -           overlay->format==SDL_YUY2_OVERLAY?"YUY2":
   1.889 -           overlay->format==SDL_UYVY_OVERLAY?"UYVY":
   1.890 -           overlay->format==SDL_YVYU_OVERLAY?"YVYU":
   1.891 -           "Unknown");
   1.892 +    printf ("Created %dx%dx%d %s %s overlay\n", overlay->w, overlay->h,
   1.893 +            overlay->planes, overlay->hw_overlay ? "hardware" : "software",
   1.894 +            overlay->format == SDL_YV12_OVERLAY ? "YV12" : overlay->format ==
   1.895 +            SDL_IYUV_OVERLAY ? "IYUV" : overlay->format ==
   1.896 +            SDL_YUY2_OVERLAY ? "YUY2" : overlay->format ==
   1.897 +            SDL_UYVY_OVERLAY ? "UYVY" : overlay->format ==
   1.898 +            SDL_YVYU_OVERLAY ? "YVYU" : "Unknown");
   1.899  
   1.900 -    for(i=0; i<overlay->planes; i++)
   1.901 -    {
   1.902 -        printf("  plane %d: pitch=%d\n", i, overlay->pitches[i]);
   1.903 +    for (i = 0; i < overlay->planes; i++) {
   1.904 +        printf ("  plane %d: pitch=%d\n", i, overlay->pitches[i]);
   1.905      }
   1.906  
   1.907 -    overlayrect.x=0;
   1.908 -    overlayrect.y=0;
   1.909 -    overlayrect.w=MOOSEPIC_W*scale;
   1.910 -    overlayrect.h=MOOSEPIC_H*scale;
   1.911 +    overlayrect.x = 0;
   1.912 +    overlayrect.y = 0;
   1.913 +    overlayrect.w = MOOSEPIC_W * scale;
   1.914 +    overlayrect.h = MOOSEPIC_H * scale;
   1.915  
   1.916      /* set the start frame */
   1.917 -    i=0;
   1.918 -    fpsdelay=1000/fps;
   1.919 +    i = 0;
   1.920 +    fpsdelay = 1000 / fps;
   1.921  
   1.922      /* Ignore key up events, they don't even get filtered */
   1.923 -    SDL_EventState(SDL_KEYUP, SDL_IGNORE);
   1.924 +    SDL_EventState (SDL_KEYUP, SDL_IGNORE);
   1.925  
   1.926 -    lastftick=SDL_GetTicks();
   1.927 +    lastftick = SDL_GetTicks ();
   1.928  
   1.929      /* Loop, waiting for QUIT or RESIZE */
   1.930 -    while (1)
   1.931 -    {
   1.932 -        if (SDL_PollEvent(&event))
   1.933 -        {
   1.934 -            switch (event.type)
   1.935 -            {
   1.936 -                case SDL_VIDEORESIZE:
   1.937 -                     screen=SDL_SetVideoMode(event.resize.w, event.resize.h, 0, SDL_RESIZABLE | SDL_SWSURFACE);
   1.938 -                     overlayrect.w=event.resize.w;
   1.939 -                     overlayrect.h=event.resize.h;
   1.940 -                     if (paused)
   1.941 -                     {
   1.942 -                         resized=1;
   1.943 -                     }
   1.944 -                     break;
   1.945 -                case SDL_MOUSEBUTTONDOWN:
   1.946 -                     overlayrect.x = event.button.x - overlayrect.w/2;
   1.947 -                     overlayrect.y = event.button.y - overlayrect.h/2;
   1.948 -                     break;
   1.949 -                case SDL_KEYDOWN:
   1.950 -                     if (event.key.keysym.sym == SDLK_SPACE)
   1.951 -                     {
   1.952 -                         paused=!paused;
   1.953 -                         break;
   1.954 -                     }
   1.955 -                     if (event.key.keysym.sym != SDLK_ESCAPE)
   1.956 -                     {
   1.957 -                         break;
   1.958 -                     }
   1.959 -                case SDL_QUIT:
   1.960 -                     SDL_FreeYUVOverlay(overlay);
   1.961 -                     for (i=0; i<MOOSEFRAMES_COUNT; i++)
   1.962 -                     {
   1.963 -                         SDL_FreeSurface(MooseFrame[i]);
   1.964 -                     }
   1.965 -                     quit(0);
   1.966 +    while (1) {
   1.967 +        if (SDL_PollEvent (&event)) {
   1.968 +            switch (event.type) {
   1.969 +            case SDL_VIDEORESIZE:
   1.970 +                screen =
   1.971 +                    SDL_SetVideoMode (event.resize.w, event.resize.h, 0,
   1.972 +                                      SDL_RESIZABLE | SDL_SWSURFACE);
   1.973 +                overlayrect.w = event.resize.w;
   1.974 +                overlayrect.h = event.resize.h;
   1.975 +                if (paused) {
   1.976 +                    resized = 1;
   1.977 +                }
   1.978 +                break;
   1.979 +            case SDL_MOUSEBUTTONDOWN:
   1.980 +                overlayrect.x = event.button.x - overlayrect.w / 2;
   1.981 +                overlayrect.y = event.button.y - overlayrect.h / 2;
   1.982 +                break;
   1.983 +            case SDL_KEYDOWN:
   1.984 +                if (event.key.keysym.sym == SDLK_SPACE) {
   1.985 +                    paused = !paused;
   1.986 +                    break;
   1.987 +                }
   1.988 +                if (event.key.keysym.sym != SDLK_ESCAPE) {
   1.989 +                    break;
   1.990 +                }
   1.991 +            case SDL_QUIT:
   1.992 +                SDL_FreeYUVOverlay (overlay);
   1.993 +                for (i = 0; i < MOOSEFRAMES_COUNT; i++) {
   1.994 +                    SDL_FreeSurface (MooseFrame[i]);
   1.995 +                }
   1.996 +                quit (0);
   1.997              }
   1.998          }
   1.999  
  1.1000 -        if ((!paused)||(resized))
  1.1001 -        {
  1.1002 -            if (((SDL_GetTicks()-lastftick)>fpsdelay)||(resized))
  1.1003 -            {
  1.1004 -                lastftick=SDL_GetTicks();
  1.1005 +        if ((!paused) || (resized)) {
  1.1006 +            if (((SDL_GetTicks () - lastftick) > fpsdelay) || (resized)) {
  1.1007 +                lastftick = SDL_GetTicks ();
  1.1008  
  1.1009 -                switch (overlay_format)
  1.1010 -                {
  1.1011 -                    case SDL_YUY2_OVERLAY:
  1.1012 -                         ConvertRGBtoYUY2(MooseFrame[i], overlay, 0, 100);
  1.1013 -                         break;
  1.1014 -                    case SDL_YV12_OVERLAY:
  1.1015 -                         ConvertRGBtoYV12(MooseFrame[i], overlay, 0, 100);
  1.1016 -                         break;
  1.1017 -                    case SDL_UYVY_OVERLAY:
  1.1018 -                         ConvertRGBtoUYVY(MooseFrame[i], overlay, 0, 100);
  1.1019 -                         break;
  1.1020 -                    case SDL_YVYU_OVERLAY:
  1.1021 -                         ConvertRGBtoYVYU(MooseFrame[i], overlay, 0, 100);
  1.1022 -                         break;
  1.1023 -                    case SDL_IYUV_OVERLAY:
  1.1024 -                         ConvertRGBtoIYUV(MooseFrame[i], overlay, 0, 100);
  1.1025 -                         break;
  1.1026 +                switch (overlay_format) {
  1.1027 +                case SDL_YUY2_OVERLAY:
  1.1028 +                    ConvertRGBtoYUY2 (MooseFrame[i], overlay, 0, 100);
  1.1029 +                    break;
  1.1030 +                case SDL_YV12_OVERLAY:
  1.1031 +                    ConvertRGBtoYV12 (MooseFrame[i], overlay, 0, 100);
  1.1032 +                    break;
  1.1033 +                case SDL_UYVY_OVERLAY:
  1.1034 +                    ConvertRGBtoUYVY (MooseFrame[i], overlay, 0, 100);
  1.1035 +                    break;
  1.1036 +                case SDL_YVYU_OVERLAY:
  1.1037 +                    ConvertRGBtoYVYU (MooseFrame[i], overlay, 0, 100);
  1.1038 +                    break;
  1.1039 +                case SDL_IYUV_OVERLAY:
  1.1040 +                    ConvertRGBtoIYUV (MooseFrame[i], overlay, 0, 100);
  1.1041 +                    break;
  1.1042                  }
  1.1043  
  1.1044 -                SDL_DisplayYUVOverlay(overlay, &overlayrect);
  1.1045 -                if (!resized)
  1.1046 -                {
  1.1047 +                SDL_DisplayYUVOverlay (overlay, &overlayrect);
  1.1048 +                if (!resized) {
  1.1049                      i++;
  1.1050 -                    if (i==10)
  1.1051 -                    {
  1.1052 -                        i=0;
  1.1053 +                    if (i == 10) {
  1.1054 +                        i = 0;
  1.1055                      }
  1.1056 -                }
  1.1057 -                else
  1.1058 -                {
  1.1059 -                    resized=0;
  1.1060 +                } else {
  1.1061 +                    resized = 0;
  1.1062                  }
  1.1063              }
  1.1064          }
  1.1065          /* kind of timeslice to OS */
  1.1066 -        SDL_Delay(1);
  1.1067 +        SDL_Delay (1);
  1.1068      }
  1.1069  
  1.1070 -	SDL_Quit();
  1.1071 +    SDL_Quit ();
  1.1072      return 0;
  1.1073  }
  1.1074 -