test/testoverlay2.c
changeset 672 5955fa16d4b8
child 673 63419da96d13
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/testoverlay2.c	Fri Aug 08 21:31:18 2003 +0000
     1.3 @@ -0,0 +1,572 @@
     1.4 +/********************************************************************************
     1.5 + *                                                                              *
     1.6 + * Test of the overlay used for moved pictures, test more closed to real life.  *
     1.7 + * Running trojan moose :) Coded by Mike Gorchak.                               *
     1.8 + *                                                                              *
     1.9 + ********************************************************************************/
    1.10 +
    1.11 +#include "SDL.h"
    1.12 +
    1.13 +#define MOOSEPIC_W 64
    1.14 +#define MOOSEPIC_H 88
    1.15 +
    1.16 +#define MOOSEFRAME_SIZE (MOOSEPIC_W * MOOSEPIC_H)
    1.17 +#define MOOSEFRAMES_COUNT 10
    1.18 +
    1.19 +SDL_Color MooseColors[84]={
    1.20 +    { 49,  49,  49}, { 66,  24,   0}, { 66,  33,   0}, { 66,  66,  66},
    1.21 +    { 66, 115,  49}, { 74,  33,   0}, { 74,  41,  16}, { 82,  33,   8},
    1.22 +    { 82,  41,   8}, { 82,  49,  16}, { 82,  82,  82}, { 90,  41,   8},
    1.23 +    { 90,  41,  16}, { 90,  57,  24}, { 99,  49,  16}, { 99,  66,  24},
    1.24 +    { 99,  66,  33}, { 99,  74,  33}, {107,  57,  24}, {107,  82,  41},
    1.25 +    {115,  57,  33}, {115,  66,  33}, {115,  66,  41}, {115,  74,   0},
    1.26 +    {115,  90,  49}, {115, 115, 115}, {123,  82,   0}, {123,  99,  57},
    1.27 +    {132,  66,  41}, {132,  74,  41}, {132,  90,   8}, {132,  99,  33},
    1.28 +    {132,  99,  66}, {132, 107,  66}, {140,  74,  49}, {140,  99,  16},
    1.29 +    {140, 107,  74}, {140, 115,  74}, {148, 107,  24}, {148, 115,  82},
    1.30 +    {148, 123,  74}, {148, 123,  90}, {156, 115,  33}, {156, 115,  90},
    1.31 +    {156, 123,  82}, {156, 132,  82}, {156, 132,  99}, {156, 156, 156},
    1.32 +    {165, 123,  49}, {165, 123,  90}, {165, 132,  82}, {165, 132,  90},
    1.33 +    {165, 132,  99}, {165, 140,  90}, {173, 132,  57}, {173, 132,  99},
    1.34 +    {173, 140, 107}, {173, 140, 115}, {173, 148,  99}, {173, 173, 173},
    1.35 +    {181, 140,  74}, {181, 148, 115}, {181, 148, 123}, {181, 156, 107},
    1.36 +    {189, 148, 123}, {189, 156,  82}, {189, 156, 123}, {189, 156, 132},
    1.37 +    {189, 189, 189}, {198, 156, 123}, {198, 165, 132}, {206, 165,  99},
    1.38 +    {206, 165, 132}, {206, 173, 140}, {206, 206, 206}, {214, 173, 115},
    1.39 +    {214, 173, 140}, {222, 181, 148}, {222, 189, 132}, {222, 189, 156},
    1.40 +    {222, 222, 222}, {231, 198, 165}, {231, 231, 231}, {239, 206, 173}
    1.41 +};
    1.42 +
    1.43 +/* All RGB2YUV conversion code and some other parts of code has been taken from testoverlay.c */
    1.44 +
    1.45 +/* NOTE: These RGB conversion functions are not intended for speed,
    1.46 +         only as examples.
    1.47 +*/
    1.48 +
    1.49 +void RGBtoYUV(Uint8 *rgb, int *yuv, int monochrome, int luminance)
    1.50 +{
    1.51 +    int i;
    1.52 +
    1.53 +    if (monochrome)
    1.54 +    {
    1.55 +#if 1 /* these are the two formulas that I found on the FourCC site... */
    1.56 +        yuv[0] = 0.299*rgb[0] + 0.587*rgb[1] + 0.114*rgb[2];
    1.57 +        yuv[1] = 128;
    1.58 +        yuv[2] = 128;
    1.59 +#else
    1.60 +        yuv[0] = (0.257 * rgb[0]) + (0.504 * rgb[1]) + (0.098 * rgb[2]) + 16;
    1.61 +        yuv[1] = 128;
    1.62 +        yuv[2] = 128;
    1.63 +#endif
    1.64 +    }
    1.65 +    else
    1.66 +    {
    1.67 +#if 1 /* these are the two formulas that I found on the FourCC site... */
    1.68 +        yuv[0] = 0.299*rgb[0] + 0.587*rgb[1] + 0.114*rgb[2];
    1.69 +        yuv[1] = (rgb[2]-yuv[0])*0.565 + 128;
    1.70 +        yuv[2] = (rgb[0]-yuv[0])*0.713 + 128;
    1.71 +#else
    1.72 +        yuv[0] = (0.257 * rgb[0]) + (0.504 * rgb[1]) + (0.098 * rgb[2]) + 16;
    1.73 +        yuv[1] = 128 - (0.148 * rgb[0]) - (0.291 * rgb[1]) + (0.439 * rgb[2]);
    1.74 +        yuv[2] = 128 + (0.439 * rgb[0]) - (0.368 * rgb[1]) - (0.071 * rgb[2]);
    1.75 +#endif
    1.76 +    }
    1.77 +
    1.78 +    if (luminance!=100)
    1.79 +    {
    1.80 +        yuv[0]=yuv[0]*luminance/100;
    1.81 +        if (yuv[0]>255)
    1.82 +            yuv[0]=255;
    1.83 +    }
    1.84 +}
    1.85 +
    1.86 +ConvertRGBtoYV12(SDL_Surface *s, SDL_Overlay *o, int monochrome, int luminance)
    1.87 +{
    1.88 +	int x,y;
    1.89 +	int yuv[3];
    1.90 +	Uint8 *p,*op[3];
    1.91 +
    1.92 +	SDL_LockSurface(s);
    1.93 +	SDL_LockYUVOverlay(o);
    1.94 +
    1.95 +	/* Convert */
    1.96 +	for(y=0; y<s->h && y<o->h; y++)
    1.97 +	{
    1.98 +		p=((Uint8 *) s->pixels)+s->pitch*y;
    1.99 +		op[0]=o->pixels[0]+o->pitches[0]*y;
   1.100 +		op[1]=o->pixels[1]+o->pitches[1]*(y/2);
   1.101 +		op[2]=o->pixels[2]+o->pitches[2]*(y/2);
   1.102 +		for(x=0; x<s->w && x<o->w; x++)
   1.103 +		{
   1.104 +			RGBtoYUV(p, yuv, monochrome, luminance);
   1.105 +			*(op[0]++)=yuv[0];
   1.106 +			if(x%2==0 && y%2==0)
   1.107 +			{
   1.108 +				*(op[1]++)=yuv[2];
   1.109 +				*(op[2]++)=yuv[1];
   1.110 +			}
   1.111 +			p+=s->format->BytesPerPixel;
   1.112 +		}
   1.113 +	}
   1.114 +
   1.115 +	SDL_UnlockYUVOverlay(o);
   1.116 +	SDL_UnlockSurface(s);
   1.117 +}
   1.118 +
   1.119 +ConvertRGBtoIYUV(SDL_Surface *s, SDL_Overlay *o, int monochrome, int luminance)
   1.120 +{
   1.121 +	int x,y;
   1.122 +	int yuv[3];
   1.123 +	Uint8 *p,*op[3];
   1.124 +
   1.125 +	SDL_LockSurface(s);
   1.126 +	SDL_LockYUVOverlay(o);
   1.127 +
   1.128 +	/* Convert */
   1.129 +	for(y=0; y<s->h && y<o->h; y++)
   1.130 +	{
   1.131 +		p=((Uint8 *) s->pixels)+s->pitch*y;
   1.132 +		op[0]=o->pixels[0]+o->pitches[0]*y;
   1.133 +		op[1]=o->pixels[1]+o->pitches[1]*(y/2);
   1.134 +		op[2]=o->pixels[2]+o->pitches[2]*(y/2);
   1.135 +		for(x=0; x<s->w && x<o->w; x++)
   1.136 +		{
   1.137 +			RGBtoYUV(p,yuv, monochrome, luminance);
   1.138 +			*(op[0]++)=yuv[0];
   1.139 +			if(x%2==0 && y%2==0)
   1.140 +			{
   1.141 +				*(op[1]++)=yuv[1];
   1.142 +				*(op[2]++)=yuv[2];
   1.143 +			}
   1.144 +			p+=s->format->BytesPerPixel;
   1.145 +		}
   1.146 +	}
   1.147 +
   1.148 +	SDL_UnlockYUVOverlay(o);
   1.149 +	SDL_UnlockSurface(s);
   1.150 +}
   1.151 +
   1.152 +ConvertRGBtoUYVY(SDL_Surface *s, SDL_Overlay *o, int monochrome, int luminance)
   1.153 +{
   1.154 +	int x,y;
   1.155 +	int yuv[3];
   1.156 +	Uint8 *p,*op;
   1.157 +
   1.158 +	SDL_LockSurface(s);
   1.159 +	SDL_LockYUVOverlay(o);
   1.160 +
   1.161 +	for(y=0; y<s->h && y<o->h; y++)
   1.162 +	{
   1.163 +		p=((Uint8 *) s->pixels)+s->pitch*y;
   1.164 +		op=o->pixels[0]+o->pitches[0]*y;
   1.165 +		for(x=0; x<s->w && x<o->w; x++)
   1.166 +		{
   1.167 +			RGBtoYUV(p, yuv, monochrome, luminance);
   1.168 +			if(x%2==0)
   1.169 +			{
   1.170 +				*(op++)=yuv[1];
   1.171 +				*(op++)=yuv[0];
   1.172 +				*(op++)=yuv[2];
   1.173 +			}
   1.174 +			else
   1.175 +				*(op++)=yuv[0];
   1.176 +
   1.177 +			p+=s->format->BytesPerPixel;
   1.178 +		}
   1.179 +	}
   1.180 +
   1.181 +	SDL_UnlockYUVOverlay(o);
   1.182 +	SDL_UnlockSurface(s);
   1.183 +}
   1.184 +
   1.185 +ConvertRGBtoYVYU(SDL_Surface *s, SDL_Overlay *o, int monochrome, int luminance)
   1.186 +{
   1.187 +	int x,y;
   1.188 +	int yuv[3];
   1.189 +	Uint8 *p,*op;
   1.190 +
   1.191 +	SDL_LockSurface(s);
   1.192 +	SDL_LockYUVOverlay(o);
   1.193 +
   1.194 +	for(y=0; y<s->h && y<o->h; y++)
   1.195 +	{
   1.196 +		p=((Uint8 *) s->pixels)+s->pitch*y;
   1.197 +		op=o->pixels[0]+o->pitches[0]*y;
   1.198 +		for(x=0; x<s->w && x<o->w; x++)
   1.199 +		{
   1.200 +			RGBtoYUV(p,yuv, monochrome, luminance);
   1.201 +			if(x%2==0)
   1.202 +			{
   1.203 +				*(op++)=yuv[0];
   1.204 +				*(op++)=yuv[2];
   1.205 +				op[1]=yuv[1];
   1.206 +			}
   1.207 +			else
   1.208 +			{
   1.209 +				*op=yuv[0];
   1.210 +				op+=2;
   1.211 +			}
   1.212 +
   1.213 +			p+=s->format->BytesPerPixel;
   1.214 +		}
   1.215 +	}
   1.216 +
   1.217 +	SDL_UnlockYUVOverlay(o);
   1.218 +	SDL_UnlockSurface(s);
   1.219 +}
   1.220 +
   1.221 +ConvertRGBtoYUY2(SDL_Surface *s, SDL_Overlay *o, int monochrome, int luminance)
   1.222 +{
   1.223 +	int x,y;
   1.224 +	int yuv[3];
   1.225 +	Uint8 *p,*op;
   1.226 +
   1.227 +	SDL_LockSurface(s);
   1.228 +	SDL_LockYUVOverlay(o);
   1.229 +        
   1.230 +	for(y=0; y<s->h && y<o->h; y++)
   1.231 +	{
   1.232 +		p=((Uint8 *) s->pixels)+s->pitch*y;
   1.233 +		op=o->pixels[0]+o->pitches[0]*y;
   1.234 +		for(x=0; x<s->w && x<o->w; x++)
   1.235 +		{
   1.236 +			RGBtoYUV(p,yuv, monochrome, luminance);
   1.237 +			if(x%2==0)
   1.238 +			{
   1.239 +				*(op++)=yuv[0];
   1.240 +				*(op++)=yuv[1];
   1.241 +				op[1]=yuv[2];
   1.242 +			}
   1.243 +			else
   1.244 +			{
   1.245 +				*op=yuv[0];
   1.246 +				op+=2;
   1.247 +			}
   1.248 +
   1.249 +			p+=s->format->BytesPerPixel;
   1.250 +		}
   1.251 +	}
   1.252 +
   1.253 +	SDL_UnlockYUVOverlay(o);
   1.254 +	SDL_UnlockSurface(s);
   1.255 +}
   1.256 +
   1.257 +void Draw()
   1.258 +{
   1.259 +}
   1.260 +
   1.261 +static void PrintUsage(char *argv0)
   1.262 +{
   1.263 +    fprintf(stderr, "Usage: %s [arg] [arg] [arg] ...\n", argv0);
   1.264 +    fprintf(stderr, "Where 'arg' is one of:\n");
   1.265 +    fprintf(stderr, "	-fps <frames per second>\n");
   1.266 +    fprintf(stderr, "	-format <fmt> (one of the: YV12, IYUV, YUY2, UYVY, YVYU)\n");
   1.267 +    fprintf(stderr, "	-scale <scale factor> (initial scale of the overlay)\n");
   1.268 +    fprintf(stderr, "	-help (shows this help)\n");
   1.269 +    fprintf(stderr, "\n");
   1.270 +    fprintf(stderr, "	Press ESC to exit, or SPACE to freeze the movie while application running.\n");
   1.271 +    fprintf(stderr, "\n");
   1.272 +}
   1.273 +
   1.274 +int main(int argc, char **argv)
   1.275 +{
   1.276 +    Uint8* RawMooseData;
   1.277 +    SDL_RWops* handle;
   1.278 +    SDL_Surface* screen;
   1.279 +    SDL_Surface* MooseFrame[MOOSEFRAMES_COUNT];
   1.280 +    SDL_Overlay* overlay;
   1.281 +    SDL_Rect overlayrect;
   1.282 +    SDL_Event event;
   1.283 +    Uint32 lastftick;
   1.284 +    int paused=0;
   1.285 +    int i;
   1.286 +    int fps=12;
   1.287 +    int fpsdelay;
   1.288 +    int overlay_format=SDL_YUY2_OVERLAY;
   1.289 +    int scale=5;
   1.290 +
   1.291 +    while ( argc > 1 )
   1.292 +    {
   1.293 +        if (strcmp(argv[1], "-fps")== 0)
   1.294 +        {
   1.295 +            if (argv[2])
   1.296 +            {
   1.297 +                fps = atoi(argv[2]);
   1.298 +                if (fps==0)
   1.299 +                {
   1.300 +                    fprintf(stderr, "The -fps option requires an argument [from 1 to 1000], default is 12.\n");
   1.301 +                    return -1;
   1.302 +                }
   1.303 +                if ((fps<0) || (fps>1000))
   1.304 +                {
   1.305 +                    fprintf(stderr, "The -fps option must be in range from 1 to 1000, default is 12.\n");
   1.306 +                    return -1;
   1.307 +                }
   1.308 +                argv += 2;
   1.309 +                argc -= 2;
   1.310 +            }
   1.311 +            else
   1.312 +            {
   1.313 +                fprintf(stderr, "The -fps option requires an argument [from 1 to 1000], default is 12.\n");
   1.314 +                return -1;
   1.315 +            }
   1.316 +        } else
   1.317 +        if (strcmp(argv[1], "-format") == 0)
   1.318 +        {
   1.319 +            if (argv[2])
   1.320 +            {
   1.321 +                if (!strcmp(argv[2],"YV12"))
   1.322 +                    overlay_format = SDL_YV12_OVERLAY;
   1.323 +                else if(!strcmp(argv[2],"IYUV"))
   1.324 +                    overlay_format = SDL_IYUV_OVERLAY;
   1.325 +                else if(!strcmp(argv[2],"YUY2"))
   1.326 +                    overlay_format = SDL_YUY2_OVERLAY;
   1.327 +                else if(!strcmp(argv[2],"UYVY"))
   1.328 +                    overlay_format = SDL_UYVY_OVERLAY;
   1.329 +                else if(!strcmp(argv[2],"YVYU"))
   1.330 +                    overlay_format = SDL_YVYU_OVERLAY;
   1.331 +                else
   1.332 +                {
   1.333 +                    fprintf(stderr, "The -format option %s is not recognized, see help for info.\n", argv[2]);
   1.334 +                    return -1;
   1.335 +                }
   1.336 +                argv += 2;
   1.337 +                argc -= 2;
   1.338 +            }
   1.339 +            else
   1.340 +            {
   1.341 +                fprintf(stderr, "The -format option requires an argument, default is YUY2.\n");
   1.342 +                return -1;
   1.343 +            }
   1.344 +        } else
   1.345 +        if (strcmp(argv[1], "-scale") == 0)
   1.346 +        {
   1.347 +            if (argv[2])
   1.348 +            {
   1.349 +                scale = atoi(argv[2]);
   1.350 +                if (scale==0)
   1.351 +                {
   1.352 +                    fprintf(stderr, "The -scale option requires an argument [from 1 to 50], default is 5.\n");
   1.353 +                    return -1;
   1.354 +                }
   1.355 +                if ((scale<0) || (scale>50))
   1.356 +                {
   1.357 +                    fprintf(stderr, "The -scale option must be in range from 1 to 50, default is 5.\n");
   1.358 +                    return -1;
   1.359 +                }
   1.360 +                argv += 2;
   1.361 +                argc -= 2;
   1.362 +            }
   1.363 +            else
   1.364 +            {
   1.365 +                fprintf(stderr, "The -fps option requires an argument [from 1 to 1000], default is 12.\n");
   1.366 +                return -1;
   1.367 +            }
   1.368 +        } else
   1.369 +        if ((strcmp(argv[1], "-help") == 0 ) || (strcmp(argv[1], "-h") == 0))
   1.370 +        {
   1.371 +            PrintUsage(argv[0]);
   1.372 +            return 0;
   1.373 +        } else
   1.374 +        {
   1.375 +            fprintf(stderr, "Unrecognized option: %s.\n", argv[1]);
   1.376 +            return -1;
   1.377 +        }
   1.378 +        break;
   1.379 +    }
   1.380 +   
   1.381 +    RawMooseData=(Uint8*)malloc(MOOSEFRAME_SIZE * MOOSEFRAMES_COUNT);
   1.382 +    if (RawMooseData==NULL)
   1.383 +    {
   1.384 +        fprintf(stderr, "Can't allocate memory for movie !\n");
   1.385 +        free(RawMooseData);
   1.386 +        return 1;
   1.387 +    }
   1.388 +
   1.389 +    /* load the trojan moose images */
   1.390 +    handle=SDL_RWFromFile("moose.dat", "r");
   1.391 +    if (handle==NULL)
   1.392 +    {
   1.393 +        fprintf(stderr, "Can't find the file moose.dat !\n");
   1.394 +        free(RawMooseData);
   1.395 +        return 2;
   1.396 +    }
   1.397 +   
   1.398 +    SDL_RWread(handle, RawMooseData, MOOSEFRAME_SIZE, MOOSEFRAMES_COUNT);
   1.399 +
   1.400 +    SDL_RWclose(handle);
   1.401 +
   1.402 +    if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) < 0)
   1.403 +    {
   1.404 +        fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
   1.405 +        free(RawMooseData);
   1.406 +        return 3;
   1.407 +    }
   1.408 +    atexit(SDL_Quit);
   1.409 +
   1.410 +    /* Set 640x480 video mode */
   1.411 +    if ( (screen=SDL_SetVideoMode(MOOSEPIC_W*scale, MOOSEPIC_H*scale, 0, SDL_RESIZABLE | SDL_SWSURFACE)) == NULL )
   1.412 +    {
   1.413 +        fprintf(stderr, "Couldn't set video mode: %s\n", 0, SDL_GetError());
   1.414 +        free(RawMooseData);
   1.415 +        return 4;
   1.416 +    }
   1.417 +
   1.418 +    /* Set the window manager title bar */
   1.419 +    SDL_WM_SetCaption("SDL test overlay: running moose", "testoverlay2");
   1.420 +
   1.421 +    for (i=0; i<MOOSEFRAMES_COUNT; i++)
   1.422 +    {
   1.423 +        MooseFrame[i]=SDL_CreateRGBSurfaceFrom(RawMooseData+i*MOOSEFRAME_SIZE, MOOSEPIC_W,
   1.424 +                                               MOOSEPIC_H, 8, MOOSEPIC_W, 0, 0, 0, 0);
   1.425 +        if (MooseFrame[i]==NULL)
   1.426 +        {
   1.427 +            fprintf(stderr, "Couldn't create SDL_Surfaces:%s\n", 0, SDL_GetError());
   1.428 +            free(RawMooseData);
   1.429 +            return 5;
   1.430 +        }
   1.431 +        SDL_SetColors(MooseFrame[i], MooseColors, 0, 84);
   1.432 +
   1.433 +	{
   1.434 +		SDL_Surface *newsurf;
   1.435 +		SDL_PixelFormat format;
   1.436 +
   1.437 +		format.palette=NULL;
   1.438 +		format.BitsPerPixel=32;
   1.439 +		format.BytesPerPixel=4;
   1.440 +#if SDL_BYTEORDER == SDL_LIL_ENDIAN
   1.441 +		format.Rshift=0;
   1.442 +		format.Gshift=8;
   1.443 +		format.Bshift=16;
   1.444 +#else
   1.445 +		format.Rshift=24;
   1.446 +		format.Gshift=16;
   1.447 +		format.Bshift=8;
   1.448 +#endif
   1.449 +		format.Ashift=0;
   1.450 +		format.Rmask=0xff<<format.Rshift;
   1.451 +		format.Gmask=0xff<<format.Gshift;
   1.452 +		format.Bmask=0xff<<format.Bshift;
   1.453 +		format.Amask=0;
   1.454 +		format.Rloss=0;
   1.455 +		format.Gloss=0;
   1.456 +		format.Bloss=0;
   1.457 +		format.Aloss=8;
   1.458 +		format.colorkey=0;
   1.459 +		format.alpha=0;
   1.460 +
   1.461 +		newsurf=SDL_ConvertSurface(MooseFrame[i], &format, SDL_SWSURFACE);
   1.462 +		if(!newsurf)
   1.463 +		{
   1.464 +                    fprintf(stderr, "Couldn't convert picture to 32bits RGB: %s\n", SDL_GetError());
   1.465 +                    return 6;
   1.466 +		}
   1.467 +		SDL_FreeSurface(MooseFrame[i]);
   1.468 +		MooseFrame[i]=newsurf;
   1.469 +	}
   1.470 +    }
   1.471 +
   1.472 +    free(RawMooseData);
   1.473 +
   1.474 +    overlay=SDL_CreateYUVOverlay(MOOSEPIC_W, MOOSEPIC_H, overlay_format, screen);
   1.475 +
   1.476 +    printf("Created %dx%dx%d %s %s overlay\n",overlay->w,overlay->h,overlay->planes,
   1.477 +           overlay->hw_overlay?"hardware":"software",
   1.478 +           overlay->format==SDL_YV12_OVERLAY?"YV12":
   1.479 +           overlay->format==SDL_IYUV_OVERLAY?"IYUV":
   1.480 +           overlay->format==SDL_YUY2_OVERLAY?"YUY2":
   1.481 +           overlay->format==SDL_UYVY_OVERLAY?"UYVY":
   1.482 +           overlay->format==SDL_YVYU_OVERLAY?"YVYU":
   1.483 +           "Unknown");
   1.484 +
   1.485 +    for(i=0; i<overlay->planes; i++)
   1.486 +    {
   1.487 +        printf("  plane %d: pitch=%d\n", i, overlay->pitches[i]);
   1.488 +    }
   1.489 +
   1.490 +    overlayrect.x=0;
   1.491 +    overlayrect.y=0;
   1.492 +    overlayrect.w=MOOSEPIC_W*scale;
   1.493 +    overlayrect.h=MOOSEPIC_H*scale;
   1.494 +
   1.495 +    /* set the start frame */
   1.496 +    i=0;
   1.497 +    fpsdelay=1000/fps;
   1.498 +
   1.499 +    /* Ignore key up events, they don't even get filtered */
   1.500 +    SDL_EventState(SDL_KEYUP, SDL_IGNORE);
   1.501 +
   1.502 +    lastftick=SDL_GetTicks();
   1.503 +
   1.504 +    /* Loop, waiting for QUIT or RESIZE */
   1.505 +    while (1)
   1.506 +    {
   1.507 +        if (SDL_PollEvent(&event))
   1.508 +        {
   1.509 +            switch (event.type)
   1.510 +            {
   1.511 +                case SDL_VIDEORESIZE:
   1.512 +                     screen=SDL_SetVideoMode(event.resize.w, event.resize.h, 0, SDL_RESIZABLE | SDL_SWSURFACE);
   1.513 +                     overlayrect.w=event.resize.w;
   1.514 +                     overlayrect.h=event.resize.h;
   1.515 +                     break;
   1.516 +                case SDL_KEYDOWN:
   1.517 +                     if (event.key.keysym.sym == SDLK_SPACE)
   1.518 +                     {
   1.519 +                         paused=!paused;
   1.520 +                         break;
   1.521 +                     }
   1.522 +                     if (event.key.keysym.sym != SDLK_ESCAPE)
   1.523 +                     {
   1.524 +                         break;
   1.525 +                     }
   1.526 +                case SDL_QUIT:
   1.527 +                     SDL_FreeYUVOverlay(overlay);
   1.528 +                     for (i=0; i<MOOSEFRAMES_COUNT; i++)
   1.529 +                     {
   1.530 +                         SDL_FreeSurface(MooseFrame[i]);
   1.531 +                     }
   1.532 +                     return 0;
   1.533 +            }
   1.534 +        }
   1.535 +
   1.536 +        if (!paused)
   1.537 +        {
   1.538 +            if ((SDL_GetTicks()-lastftick)>fpsdelay)
   1.539 +            {
   1.540 +                lastftick=SDL_GetTicks();
   1.541 +
   1.542 +                switch (overlay_format)
   1.543 +                {
   1.544 +                    case SDL_YUY2_OVERLAY:
   1.545 +                         ConvertRGBtoYUY2(MooseFrame[i], overlay, 0, 100);
   1.546 +                         break;
   1.547 +                    case SDL_YV12_OVERLAY:
   1.548 +                         ConvertRGBtoYV12(MooseFrame[i], overlay, 0, 100);
   1.549 +                         break;
   1.550 +                    case SDL_UYVY_OVERLAY:
   1.551 +                         ConvertRGBtoUYVY(MooseFrame[i], overlay, 0, 100);
   1.552 +                         break;
   1.553 +                    case SDL_YVYU_OVERLAY:
   1.554 +                         ConvertRGBtoYVYU(MooseFrame[i], overlay, 0, 100);
   1.555 +                         break;
   1.556 +                    case SDL_IYUV_OVERLAY:
   1.557 +                         ConvertRGBtoIYUV(MooseFrame[i], overlay, 0, 100);
   1.558 +                         break;
   1.559 +                }
   1.560 +
   1.561 +                SDL_DisplayYUVOverlay(overlay, &overlayrect);
   1.562 +                i++;
   1.563 +                if (i==10)
   1.564 +                {
   1.565 +                    i=0;
   1.566 +                }
   1.567 +            }
   1.568 +        }
   1.569 +        /* kind of timeslice to OS */
   1.570 +        SDL_Delay(1);
   1.571 +    }
   1.572 +
   1.573 +    return 0;
   1.574 +}
   1.575 +