Date: Mon, 28 Jul 2003 18:30:50 +0300
authorSam Lantinga <slouken@libsdl.org>
Fri, 08 Aug 2003 21:31:18 +0000
changeset 6725955fa16d4b8
parent 671 338a62f9a528
child 673 63419da96d13
Date: Mon, 28 Jul 2003 18:30:50 +0300
From: "Mike Gorchak"
Subject: New test for overlays

While writting QNX Photon Overlay code I've found that the existent overlay test application is not enough, it performs too artificial tests - it always moves/resizes the overlay's viewport, but in the real life that happens very rare. So I decided to write new test (commonly base on testoverlay.c code) and called it testoverlay2 :)

moose.dat - raw 8 bit paletted data of the small movie. (It was a moose.gif, also included in the attachment as reference, but not needed for this test, it is just for information). I cannot find, who created this .gif, so no credits this time :) But over inet I saw this gif zillion times, so I think we do not infringing somebody rights :)
test/Makefile.am
test/moose.dat
test/testoverlay2.c
     1.1 --- a/test/Makefile.am	Fri Aug 08 20:09:15 2003 +0000
     1.2 +++ b/test/Makefile.am	Fri Aug 08 21:31:18 2003 +0000
     1.3 @@ -4,7 +4,7 @@
     1.4  	testver testtypes testhread testlock testerror testsem testtimer \
     1.5  	loopwave testcdrom testkeys testvidinfo checkkeys testwin graywin \
     1.6  	testsprite testbitmap testalpha testgamma testpalette testwm \
     1.7 -	threadwin testoverlay testgl testjoystick
     1.8 +	threadwin testoverlay testoverlay2 testgl testjoystick
     1.9  
    1.10  testalpha_SOURCES = testalpha.c
    1.11  testalpha_LDADD = @MATHLIB@
     2.1 Binary file test/moose.dat has changed
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/testoverlay2.c	Fri Aug 08 21:31:18 2003 +0000
     3.3 @@ -0,0 +1,572 @@
     3.4 +/********************************************************************************
     3.5 + *                                                                              *
     3.6 + * Test of the overlay used for moved pictures, test more closed to real life.  *
     3.7 + * Running trojan moose :) Coded by Mike Gorchak.                               *
     3.8 + *                                                                              *
     3.9 + ********************************************************************************/
    3.10 +
    3.11 +#include "SDL.h"
    3.12 +
    3.13 +#define MOOSEPIC_W 64
    3.14 +#define MOOSEPIC_H 88
    3.15 +
    3.16 +#define MOOSEFRAME_SIZE (MOOSEPIC_W * MOOSEPIC_H)
    3.17 +#define MOOSEFRAMES_COUNT 10
    3.18 +
    3.19 +SDL_Color MooseColors[84]={
    3.20 +    { 49,  49,  49}, { 66,  24,   0}, { 66,  33,   0}, { 66,  66,  66},
    3.21 +    { 66, 115,  49}, { 74,  33,   0}, { 74,  41,  16}, { 82,  33,   8},
    3.22 +    { 82,  41,   8}, { 82,  49,  16}, { 82,  82,  82}, { 90,  41,   8},
    3.23 +    { 90,  41,  16}, { 90,  57,  24}, { 99,  49,  16}, { 99,  66,  24},
    3.24 +    { 99,  66,  33}, { 99,  74,  33}, {107,  57,  24}, {107,  82,  41},
    3.25 +    {115,  57,  33}, {115,  66,  33}, {115,  66,  41}, {115,  74,   0},
    3.26 +    {115,  90,  49}, {115, 115, 115}, {123,  82,   0}, {123,  99,  57},
    3.27 +    {132,  66,  41}, {132,  74,  41}, {132,  90,   8}, {132,  99,  33},
    3.28 +    {132,  99,  66}, {132, 107,  66}, {140,  74,  49}, {140,  99,  16},
    3.29 +    {140, 107,  74}, {140, 115,  74}, {148, 107,  24}, {148, 115,  82},
    3.30 +    {148, 123,  74}, {148, 123,  90}, {156, 115,  33}, {156, 115,  90},
    3.31 +    {156, 123,  82}, {156, 132,  82}, {156, 132,  99}, {156, 156, 156},
    3.32 +    {165, 123,  49}, {165, 123,  90}, {165, 132,  82}, {165, 132,  90},
    3.33 +    {165, 132,  99}, {165, 140,  90}, {173, 132,  57}, {173, 132,  99},
    3.34 +    {173, 140, 107}, {173, 140, 115}, {173, 148,  99}, {173, 173, 173},
    3.35 +    {181, 140,  74}, {181, 148, 115}, {181, 148, 123}, {181, 156, 107},
    3.36 +    {189, 148, 123}, {189, 156,  82}, {189, 156, 123}, {189, 156, 132},
    3.37 +    {189, 189, 189}, {198, 156, 123}, {198, 165, 132}, {206, 165,  99},
    3.38 +    {206, 165, 132}, {206, 173, 140}, {206, 206, 206}, {214, 173, 115},
    3.39 +    {214, 173, 140}, {222, 181, 148}, {222, 189, 132}, {222, 189, 156},
    3.40 +    {222, 222, 222}, {231, 198, 165}, {231, 231, 231}, {239, 206, 173}
    3.41 +};
    3.42 +
    3.43 +/* All RGB2YUV conversion code and some other parts of code has been taken from testoverlay.c */
    3.44 +
    3.45 +/* NOTE: These RGB conversion functions are not intended for speed,
    3.46 +         only as examples.
    3.47 +*/
    3.48 +
    3.49 +void RGBtoYUV(Uint8 *rgb, int *yuv, int monochrome, int luminance)
    3.50 +{
    3.51 +    int i;
    3.52 +
    3.53 +    if (monochrome)
    3.54 +    {
    3.55 +#if 1 /* these are the two formulas that I found on the FourCC site... */
    3.56 +        yuv[0] = 0.299*rgb[0] + 0.587*rgb[1] + 0.114*rgb[2];
    3.57 +        yuv[1] = 128;
    3.58 +        yuv[2] = 128;
    3.59 +#else
    3.60 +        yuv[0] = (0.257 * rgb[0]) + (0.504 * rgb[1]) + (0.098 * rgb[2]) + 16;
    3.61 +        yuv[1] = 128;
    3.62 +        yuv[2] = 128;
    3.63 +#endif
    3.64 +    }
    3.65 +    else
    3.66 +    {
    3.67 +#if 1 /* these are the two formulas that I found on the FourCC site... */
    3.68 +        yuv[0] = 0.299*rgb[0] + 0.587*rgb[1] + 0.114*rgb[2];
    3.69 +        yuv[1] = (rgb[2]-yuv[0])*0.565 + 128;
    3.70 +        yuv[2] = (rgb[0]-yuv[0])*0.713 + 128;
    3.71 +#else
    3.72 +        yuv[0] = (0.257 * rgb[0]) + (0.504 * rgb[1]) + (0.098 * rgb[2]) + 16;
    3.73 +        yuv[1] = 128 - (0.148 * rgb[0]) - (0.291 * rgb[1]) + (0.439 * rgb[2]);
    3.74 +        yuv[2] = 128 + (0.439 * rgb[0]) - (0.368 * rgb[1]) - (0.071 * rgb[2]);
    3.75 +#endif
    3.76 +    }
    3.77 +
    3.78 +    if (luminance!=100)
    3.79 +    {
    3.80 +        yuv[0]=yuv[0]*luminance/100;
    3.81 +        if (yuv[0]>255)
    3.82 +            yuv[0]=255;
    3.83 +    }
    3.84 +}
    3.85 +
    3.86 +ConvertRGBtoYV12(SDL_Surface *s, SDL_Overlay *o, int monochrome, int luminance)
    3.87 +{
    3.88 +	int x,y;
    3.89 +	int yuv[3];
    3.90 +	Uint8 *p,*op[3];
    3.91 +
    3.92 +	SDL_LockSurface(s);
    3.93 +	SDL_LockYUVOverlay(o);
    3.94 +
    3.95 +	/* Convert */
    3.96 +	for(y=0; y<s->h && y<o->h; y++)
    3.97 +	{
    3.98 +		p=((Uint8 *) s->pixels)+s->pitch*y;
    3.99 +		op[0]=o->pixels[0]+o->pitches[0]*y;
   3.100 +		op[1]=o->pixels[1]+o->pitches[1]*(y/2);
   3.101 +		op[2]=o->pixels[2]+o->pitches[2]*(y/2);
   3.102 +		for(x=0; x<s->w && x<o->w; x++)
   3.103 +		{
   3.104 +			RGBtoYUV(p, yuv, monochrome, luminance);
   3.105 +			*(op[0]++)=yuv[0];
   3.106 +			if(x%2==0 && y%2==0)
   3.107 +			{
   3.108 +				*(op[1]++)=yuv[2];
   3.109 +				*(op[2]++)=yuv[1];
   3.110 +			}
   3.111 +			p+=s->format->BytesPerPixel;
   3.112 +		}
   3.113 +	}
   3.114 +
   3.115 +	SDL_UnlockYUVOverlay(o);
   3.116 +	SDL_UnlockSurface(s);
   3.117 +}
   3.118 +
   3.119 +ConvertRGBtoIYUV(SDL_Surface *s, SDL_Overlay *o, int monochrome, int luminance)
   3.120 +{
   3.121 +	int x,y;
   3.122 +	int yuv[3];
   3.123 +	Uint8 *p,*op[3];
   3.124 +
   3.125 +	SDL_LockSurface(s);
   3.126 +	SDL_LockYUVOverlay(o);
   3.127 +
   3.128 +	/* Convert */
   3.129 +	for(y=0; y<s->h && y<o->h; y++)
   3.130 +	{
   3.131 +		p=((Uint8 *) s->pixels)+s->pitch*y;
   3.132 +		op[0]=o->pixels[0]+o->pitches[0]*y;
   3.133 +		op[1]=o->pixels[1]+o->pitches[1]*(y/2);
   3.134 +		op[2]=o->pixels[2]+o->pitches[2]*(y/2);
   3.135 +		for(x=0; x<s->w && x<o->w; x++)
   3.136 +		{
   3.137 +			RGBtoYUV(p,yuv, monochrome, luminance);
   3.138 +			*(op[0]++)=yuv[0];
   3.139 +			if(x%2==0 && y%2==0)
   3.140 +			{
   3.141 +				*(op[1]++)=yuv[1];
   3.142 +				*(op[2]++)=yuv[2];
   3.143 +			}
   3.144 +			p+=s->format->BytesPerPixel;
   3.145 +		}
   3.146 +	}
   3.147 +
   3.148 +	SDL_UnlockYUVOverlay(o);
   3.149 +	SDL_UnlockSurface(s);
   3.150 +}
   3.151 +
   3.152 +ConvertRGBtoUYVY(SDL_Surface *s, SDL_Overlay *o, int monochrome, int luminance)
   3.153 +{
   3.154 +	int x,y;
   3.155 +	int yuv[3];
   3.156 +	Uint8 *p,*op;
   3.157 +
   3.158 +	SDL_LockSurface(s);
   3.159 +	SDL_LockYUVOverlay(o);
   3.160 +
   3.161 +	for(y=0; y<s->h && y<o->h; y++)
   3.162 +	{
   3.163 +		p=((Uint8 *) s->pixels)+s->pitch*y;
   3.164 +		op=o->pixels[0]+o->pitches[0]*y;
   3.165 +		for(x=0; x<s->w && x<o->w; x++)
   3.166 +		{
   3.167 +			RGBtoYUV(p, yuv, monochrome, luminance);
   3.168 +			if(x%2==0)
   3.169 +			{
   3.170 +				*(op++)=yuv[1];
   3.171 +				*(op++)=yuv[0];
   3.172 +				*(op++)=yuv[2];
   3.173 +			}
   3.174 +			else
   3.175 +				*(op++)=yuv[0];
   3.176 +
   3.177 +			p+=s->format->BytesPerPixel;
   3.178 +		}
   3.179 +	}
   3.180 +
   3.181 +	SDL_UnlockYUVOverlay(o);
   3.182 +	SDL_UnlockSurface(s);
   3.183 +}
   3.184 +
   3.185 +ConvertRGBtoYVYU(SDL_Surface *s, SDL_Overlay *o, int monochrome, int luminance)
   3.186 +{
   3.187 +	int x,y;
   3.188 +	int yuv[3];
   3.189 +	Uint8 *p,*op;
   3.190 +
   3.191 +	SDL_LockSurface(s);
   3.192 +	SDL_LockYUVOverlay(o);
   3.193 +
   3.194 +	for(y=0; y<s->h && y<o->h; y++)
   3.195 +	{
   3.196 +		p=((Uint8 *) s->pixels)+s->pitch*y;
   3.197 +		op=o->pixels[0]+o->pitches[0]*y;
   3.198 +		for(x=0; x<s->w && x<o->w; x++)
   3.199 +		{
   3.200 +			RGBtoYUV(p,yuv, monochrome, luminance);
   3.201 +			if(x%2==0)
   3.202 +			{
   3.203 +				*(op++)=yuv[0];
   3.204 +				*(op++)=yuv[2];
   3.205 +				op[1]=yuv[1];
   3.206 +			}
   3.207 +			else
   3.208 +			{
   3.209 +				*op=yuv[0];
   3.210 +				op+=2;
   3.211 +			}
   3.212 +
   3.213 +			p+=s->format->BytesPerPixel;
   3.214 +		}
   3.215 +	}
   3.216 +
   3.217 +	SDL_UnlockYUVOverlay(o);
   3.218 +	SDL_UnlockSurface(s);
   3.219 +}
   3.220 +
   3.221 +ConvertRGBtoYUY2(SDL_Surface *s, SDL_Overlay *o, int monochrome, int luminance)
   3.222 +{
   3.223 +	int x,y;
   3.224 +	int yuv[3];
   3.225 +	Uint8 *p,*op;
   3.226 +
   3.227 +	SDL_LockSurface(s);
   3.228 +	SDL_LockYUVOverlay(o);
   3.229 +        
   3.230 +	for(y=0; y<s->h && y<o->h; y++)
   3.231 +	{
   3.232 +		p=((Uint8 *) s->pixels)+s->pitch*y;
   3.233 +		op=o->pixels[0]+o->pitches[0]*y;
   3.234 +		for(x=0; x<s->w && x<o->w; x++)
   3.235 +		{
   3.236 +			RGBtoYUV(p,yuv, monochrome, luminance);
   3.237 +			if(x%2==0)
   3.238 +			{
   3.239 +				*(op++)=yuv[0];
   3.240 +				*(op++)=yuv[1];
   3.241 +				op[1]=yuv[2];
   3.242 +			}
   3.243 +			else
   3.244 +			{
   3.245 +				*op=yuv[0];
   3.246 +				op+=2;
   3.247 +			}
   3.248 +
   3.249 +			p+=s->format->BytesPerPixel;
   3.250 +		}
   3.251 +	}
   3.252 +
   3.253 +	SDL_UnlockYUVOverlay(o);
   3.254 +	SDL_UnlockSurface(s);
   3.255 +}
   3.256 +
   3.257 +void Draw()
   3.258 +{
   3.259 +}
   3.260 +
   3.261 +static void PrintUsage(char *argv0)
   3.262 +{
   3.263 +    fprintf(stderr, "Usage: %s [arg] [arg] [arg] ...\n", argv0);
   3.264 +    fprintf(stderr, "Where 'arg' is one of:\n");
   3.265 +    fprintf(stderr, "	-fps <frames per second>\n");
   3.266 +    fprintf(stderr, "	-format <fmt> (one of the: YV12, IYUV, YUY2, UYVY, YVYU)\n");
   3.267 +    fprintf(stderr, "	-scale <scale factor> (initial scale of the overlay)\n");
   3.268 +    fprintf(stderr, "	-help (shows this help)\n");
   3.269 +    fprintf(stderr, "\n");
   3.270 +    fprintf(stderr, "	Press ESC to exit, or SPACE to freeze the movie while application running.\n");
   3.271 +    fprintf(stderr, "\n");
   3.272 +}
   3.273 +
   3.274 +int main(int argc, char **argv)
   3.275 +{
   3.276 +    Uint8* RawMooseData;
   3.277 +    SDL_RWops* handle;
   3.278 +    SDL_Surface* screen;
   3.279 +    SDL_Surface* MooseFrame[MOOSEFRAMES_COUNT];
   3.280 +    SDL_Overlay* overlay;
   3.281 +    SDL_Rect overlayrect;
   3.282 +    SDL_Event event;
   3.283 +    Uint32 lastftick;
   3.284 +    int paused=0;
   3.285 +    int i;
   3.286 +    int fps=12;
   3.287 +    int fpsdelay;
   3.288 +    int overlay_format=SDL_YUY2_OVERLAY;
   3.289 +    int scale=5;
   3.290 +
   3.291 +    while ( argc > 1 )
   3.292 +    {
   3.293 +        if (strcmp(argv[1], "-fps")== 0)
   3.294 +        {
   3.295 +            if (argv[2])
   3.296 +            {
   3.297 +                fps = atoi(argv[2]);
   3.298 +                if (fps==0)
   3.299 +                {
   3.300 +                    fprintf(stderr, "The -fps option requires an argument [from 1 to 1000], default is 12.\n");
   3.301 +                    return -1;
   3.302 +                }
   3.303 +                if ((fps<0) || (fps>1000))
   3.304 +                {
   3.305 +                    fprintf(stderr, "The -fps option must be in range from 1 to 1000, default is 12.\n");
   3.306 +                    return -1;
   3.307 +                }
   3.308 +                argv += 2;
   3.309 +                argc -= 2;
   3.310 +            }
   3.311 +            else
   3.312 +            {
   3.313 +                fprintf(stderr, "The -fps option requires an argument [from 1 to 1000], default is 12.\n");
   3.314 +                return -1;
   3.315 +            }
   3.316 +        } else
   3.317 +        if (strcmp(argv[1], "-format") == 0)
   3.318 +        {
   3.319 +            if (argv[2])
   3.320 +            {
   3.321 +                if (!strcmp(argv[2],"YV12"))
   3.322 +                    overlay_format = SDL_YV12_OVERLAY;
   3.323 +                else if(!strcmp(argv[2],"IYUV"))
   3.324 +                    overlay_format = SDL_IYUV_OVERLAY;
   3.325 +                else if(!strcmp(argv[2],"YUY2"))
   3.326 +                    overlay_format = SDL_YUY2_OVERLAY;
   3.327 +                else if(!strcmp(argv[2],"UYVY"))
   3.328 +                    overlay_format = SDL_UYVY_OVERLAY;
   3.329 +                else if(!strcmp(argv[2],"YVYU"))
   3.330 +                    overlay_format = SDL_YVYU_OVERLAY;
   3.331 +                else
   3.332 +                {
   3.333 +                    fprintf(stderr, "The -format option %s is not recognized, see help for info.\n", argv[2]);
   3.334 +                    return -1;
   3.335 +                }
   3.336 +                argv += 2;
   3.337 +                argc -= 2;
   3.338 +            }
   3.339 +            else
   3.340 +            {
   3.341 +                fprintf(stderr, "The -format option requires an argument, default is YUY2.\n");
   3.342 +                return -1;
   3.343 +            }
   3.344 +        } else
   3.345 +        if (strcmp(argv[1], "-scale") == 0)
   3.346 +        {
   3.347 +            if (argv[2])
   3.348 +            {
   3.349 +                scale = atoi(argv[2]);
   3.350 +                if (scale==0)
   3.351 +                {
   3.352 +                    fprintf(stderr, "The -scale option requires an argument [from 1 to 50], default is 5.\n");
   3.353 +                    return -1;
   3.354 +                }
   3.355 +                if ((scale<0) || (scale>50))
   3.356 +                {
   3.357 +                    fprintf(stderr, "The -scale option must be in range from 1 to 50, default is 5.\n");
   3.358 +                    return -1;
   3.359 +                }
   3.360 +                argv += 2;
   3.361 +                argc -= 2;
   3.362 +            }
   3.363 +            else
   3.364 +            {
   3.365 +                fprintf(stderr, "The -fps option requires an argument [from 1 to 1000], default is 12.\n");
   3.366 +                return -1;
   3.367 +            }
   3.368 +        } else
   3.369 +        if ((strcmp(argv[1], "-help") == 0 ) || (strcmp(argv[1], "-h") == 0))
   3.370 +        {
   3.371 +            PrintUsage(argv[0]);
   3.372 +            return 0;
   3.373 +        } else
   3.374 +        {
   3.375 +            fprintf(stderr, "Unrecognized option: %s.\n", argv[1]);
   3.376 +            return -1;
   3.377 +        }
   3.378 +        break;
   3.379 +    }
   3.380 +   
   3.381 +    RawMooseData=(Uint8*)malloc(MOOSEFRAME_SIZE * MOOSEFRAMES_COUNT);
   3.382 +    if (RawMooseData==NULL)
   3.383 +    {
   3.384 +        fprintf(stderr, "Can't allocate memory for movie !\n");
   3.385 +        free(RawMooseData);
   3.386 +        return 1;
   3.387 +    }
   3.388 +
   3.389 +    /* load the trojan moose images */
   3.390 +    handle=SDL_RWFromFile("moose.dat", "r");
   3.391 +    if (handle==NULL)
   3.392 +    {
   3.393 +        fprintf(stderr, "Can't find the file moose.dat !\n");
   3.394 +        free(RawMooseData);
   3.395 +        return 2;
   3.396 +    }
   3.397 +   
   3.398 +    SDL_RWread(handle, RawMooseData, MOOSEFRAME_SIZE, MOOSEFRAMES_COUNT);
   3.399 +
   3.400 +    SDL_RWclose(handle);
   3.401 +
   3.402 +    if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) < 0)
   3.403 +    {
   3.404 +        fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
   3.405 +        free(RawMooseData);
   3.406 +        return 3;
   3.407 +    }
   3.408 +    atexit(SDL_Quit);
   3.409 +
   3.410 +    /* Set 640x480 video mode */
   3.411 +    if ( (screen=SDL_SetVideoMode(MOOSEPIC_W*scale, MOOSEPIC_H*scale, 0, SDL_RESIZABLE | SDL_SWSURFACE)) == NULL )
   3.412 +    {
   3.413 +        fprintf(stderr, "Couldn't set video mode: %s\n", 0, SDL_GetError());
   3.414 +        free(RawMooseData);
   3.415 +        return 4;
   3.416 +    }
   3.417 +
   3.418 +    /* Set the window manager title bar */
   3.419 +    SDL_WM_SetCaption("SDL test overlay: running moose", "testoverlay2");
   3.420 +
   3.421 +    for (i=0; i<MOOSEFRAMES_COUNT; i++)
   3.422 +    {
   3.423 +        MooseFrame[i]=SDL_CreateRGBSurfaceFrom(RawMooseData+i*MOOSEFRAME_SIZE, MOOSEPIC_W,
   3.424 +                                               MOOSEPIC_H, 8, MOOSEPIC_W, 0, 0, 0, 0);
   3.425 +        if (MooseFrame[i]==NULL)
   3.426 +        {
   3.427 +            fprintf(stderr, "Couldn't create SDL_Surfaces:%s\n", 0, SDL_GetError());
   3.428 +            free(RawMooseData);
   3.429 +            return 5;
   3.430 +        }
   3.431 +        SDL_SetColors(MooseFrame[i], MooseColors, 0, 84);
   3.432 +
   3.433 +	{
   3.434 +		SDL_Surface *newsurf;
   3.435 +		SDL_PixelFormat format;
   3.436 +
   3.437 +		format.palette=NULL;
   3.438 +		format.BitsPerPixel=32;
   3.439 +		format.BytesPerPixel=4;
   3.440 +#if SDL_BYTEORDER == SDL_LIL_ENDIAN
   3.441 +		format.Rshift=0;
   3.442 +		format.Gshift=8;
   3.443 +		format.Bshift=16;
   3.444 +#else
   3.445 +		format.Rshift=24;
   3.446 +		format.Gshift=16;
   3.447 +		format.Bshift=8;
   3.448 +#endif
   3.449 +		format.Ashift=0;
   3.450 +		format.Rmask=0xff<<format.Rshift;
   3.451 +		format.Gmask=0xff<<format.Gshift;
   3.452 +		format.Bmask=0xff<<format.Bshift;
   3.453 +		format.Amask=0;
   3.454 +		format.Rloss=0;
   3.455 +		format.Gloss=0;
   3.456 +		format.Bloss=0;
   3.457 +		format.Aloss=8;
   3.458 +		format.colorkey=0;
   3.459 +		format.alpha=0;
   3.460 +
   3.461 +		newsurf=SDL_ConvertSurface(MooseFrame[i], &format, SDL_SWSURFACE);
   3.462 +		if(!newsurf)
   3.463 +		{
   3.464 +                    fprintf(stderr, "Couldn't convert picture to 32bits RGB: %s\n", SDL_GetError());
   3.465 +                    return 6;
   3.466 +		}
   3.467 +		SDL_FreeSurface(MooseFrame[i]);
   3.468 +		MooseFrame[i]=newsurf;
   3.469 +	}
   3.470 +    }
   3.471 +
   3.472 +    free(RawMooseData);
   3.473 +
   3.474 +    overlay=SDL_CreateYUVOverlay(MOOSEPIC_W, MOOSEPIC_H, overlay_format, screen);
   3.475 +
   3.476 +    printf("Created %dx%dx%d %s %s overlay\n",overlay->w,overlay->h,overlay->planes,
   3.477 +           overlay->hw_overlay?"hardware":"software",
   3.478 +           overlay->format==SDL_YV12_OVERLAY?"YV12":
   3.479 +           overlay->format==SDL_IYUV_OVERLAY?"IYUV":
   3.480 +           overlay->format==SDL_YUY2_OVERLAY?"YUY2":
   3.481 +           overlay->format==SDL_UYVY_OVERLAY?"UYVY":
   3.482 +           overlay->format==SDL_YVYU_OVERLAY?"YVYU":
   3.483 +           "Unknown");
   3.484 +
   3.485 +    for(i=0; i<overlay->planes; i++)
   3.486 +    {
   3.487 +        printf("  plane %d: pitch=%d\n", i, overlay->pitches[i]);
   3.488 +    }
   3.489 +
   3.490 +    overlayrect.x=0;
   3.491 +    overlayrect.y=0;
   3.492 +    overlayrect.w=MOOSEPIC_W*scale;
   3.493 +    overlayrect.h=MOOSEPIC_H*scale;
   3.494 +
   3.495 +    /* set the start frame */
   3.496 +    i=0;
   3.497 +    fpsdelay=1000/fps;
   3.498 +
   3.499 +    /* Ignore key up events, they don't even get filtered */
   3.500 +    SDL_EventState(SDL_KEYUP, SDL_IGNORE);
   3.501 +
   3.502 +    lastftick=SDL_GetTicks();
   3.503 +
   3.504 +    /* Loop, waiting for QUIT or RESIZE */
   3.505 +    while (1)
   3.506 +    {
   3.507 +        if (SDL_PollEvent(&event))
   3.508 +        {
   3.509 +            switch (event.type)
   3.510 +            {
   3.511 +                case SDL_VIDEORESIZE:
   3.512 +                     screen=SDL_SetVideoMode(event.resize.w, event.resize.h, 0, SDL_RESIZABLE | SDL_SWSURFACE);
   3.513 +                     overlayrect.w=event.resize.w;
   3.514 +                     overlayrect.h=event.resize.h;
   3.515 +                     break;
   3.516 +                case SDL_KEYDOWN:
   3.517 +                     if (event.key.keysym.sym == SDLK_SPACE)
   3.518 +                     {
   3.519 +                         paused=!paused;
   3.520 +                         break;
   3.521 +                     }
   3.522 +                     if (event.key.keysym.sym != SDLK_ESCAPE)
   3.523 +                     {
   3.524 +                         break;
   3.525 +                     }
   3.526 +                case SDL_QUIT:
   3.527 +                     SDL_FreeYUVOverlay(overlay);
   3.528 +                     for (i=0; i<MOOSEFRAMES_COUNT; i++)
   3.529 +                     {
   3.530 +                         SDL_FreeSurface(MooseFrame[i]);
   3.531 +                     }
   3.532 +                     return 0;
   3.533 +            }
   3.534 +        }
   3.535 +
   3.536 +        if (!paused)
   3.537 +        {
   3.538 +            if ((SDL_GetTicks()-lastftick)>fpsdelay)
   3.539 +            {
   3.540 +                lastftick=SDL_GetTicks();
   3.541 +
   3.542 +                switch (overlay_format)
   3.543 +                {
   3.544 +                    case SDL_YUY2_OVERLAY:
   3.545 +                         ConvertRGBtoYUY2(MooseFrame[i], overlay, 0, 100);
   3.546 +                         break;
   3.547 +                    case SDL_YV12_OVERLAY:
   3.548 +                         ConvertRGBtoYV12(MooseFrame[i], overlay, 0, 100);
   3.549 +                         break;
   3.550 +                    case SDL_UYVY_OVERLAY:
   3.551 +                         ConvertRGBtoUYVY(MooseFrame[i], overlay, 0, 100);
   3.552 +                         break;
   3.553 +                    case SDL_YVYU_OVERLAY:
   3.554 +                         ConvertRGBtoYVYU(MooseFrame[i], overlay, 0, 100);
   3.555 +                         break;
   3.556 +                    case SDL_IYUV_OVERLAY:
   3.557 +                         ConvertRGBtoIYUV(MooseFrame[i], overlay, 0, 100);
   3.558 +                         break;
   3.559 +                }
   3.560 +
   3.561 +                SDL_DisplayYUVOverlay(overlay, &overlayrect);
   3.562 +                i++;
   3.563 +                if (i==10)
   3.564 +                {
   3.565 +                    i=0;
   3.566 +                }
   3.567 +            }
   3.568 +        }
   3.569 +        /* kind of timeslice to OS */
   3.570 +        SDL_Delay(1);
   3.571 +    }
   3.572 +
   3.573 +    return 0;
   3.574 +}
   3.575 +