test/testoverlay.c
author Sam Lantinga <slouken@libsdl.org>
Thu, 14 Feb 2002 00:47:46 +0000
changeset 277 255c7ee077cb
child 569 e8063c656626
permissions -rw-r--r--
Added a YUV overlay test program (thanks Jon!)
slouken@277
     1
slouken@277
     2
/* Bring up a window and play with it */
slouken@277
     3
slouken@277
     4
#include <stdlib.h>
slouken@277
     5
#include <stdio.h>
slouken@277
     6
#include <string.h>
slouken@277
     7
slouken@277
     8
#define BENCHMARK_SDL
slouken@277
     9
slouken@277
    10
#define NOTICE(X)	printf("%s", X);
slouken@277
    11
slouken@277
    12
#include "SDL.h"
slouken@277
    13
slouken@277
    14
SDL_Surface *screen, *pic;
slouken@277
    15
SDL_Overlay *overlay;
slouken@277
    16
int scale;
slouken@277
    17
slouken@277
    18
/* NOTE: These RGB conversion functions are not intended for speed,
slouken@277
    19
         only as examples.
slouken@277
    20
*/
slouken@277
    21
slouken@277
    22
void RGBtoYUV(Uint8 *rgb, int *yuv)
slouken@277
    23
{
slouken@277
    24
	int i;
slouken@277
    25
#if 1 /* these are the two formulas that I found on the FourCC site... */
slouken@277
    26
	yuv[0] = 0.299*rgb[0] + 0.587*rgb[1] + 0.114*rgb[2];
slouken@277
    27
	yuv[1] = (rgb[2]-yuv[0])*0.565 + 128;
slouken@277
    28
	yuv[2] = (rgb[0]-yuv[0])*0.713 + 128;
slouken@277
    29
#else
slouken@277
    30
	yuv[0] = (0.257 * rgb[0]) + (0.504 * rgb[1]) + (0.098 * rgb[2]) + 16;
slouken@277
    31
	yuv[1] = 128 - (0.148 * rgb[0]) - (0.291 * rgb[1]) + (0.439 * rgb[2]);
slouken@277
    32
	yuv[2] = 128 + (0.439 * rgb[0]) - (0.368 * rgb[1]) - (0.071 * rgb[2]);
slouken@277
    33
#endif
slouken@277
    34
	/* clamp values...if you need to, we don't seem to have a need */
slouken@277
    35
	/*
slouken@277
    36
	for(i=0;i<3;i++)
slouken@277
    37
	{
slouken@277
    38
		if(yuv[i]<0)
slouken@277
    39
			yuv[i]=0;
slouken@277
    40
		if(yuv[i]>255)
slouken@277
    41
			yuv[i]=255;
slouken@277
    42
	}
slouken@277
    43
	*/
slouken@277
    44
}
slouken@277
    45
slouken@277
    46
ConvertRGBtoYV12(SDL_Surface *s, SDL_Overlay *o)
slouken@277
    47
{
slouken@277
    48
	int x,y;
slouken@277
    49
	int yuv[3];
slouken@277
    50
	Uint8 *p,*op[3];
slouken@277
    51
slouken@277
    52
	SDL_LockSurface(s);
slouken@277
    53
	SDL_LockYUVOverlay(o);
slouken@277
    54
slouken@277
    55
	/* Black initialization */
slouken@277
    56
	/*
slouken@277
    57
	memset(o->pixels[0],0,o->pitches[0]*o->h);
slouken@277
    58
	memset(o->pixels[1],128,o->pitches[1]*((o->h+1)/2));
slouken@277
    59
	memset(o->pixels[2],128,o->pitches[2]*((o->h+1)/2));
slouken@277
    60
	*/
slouken@277
    61
slouken@277
    62
	/* Convert */
slouken@277
    63
	for(y=0; y<s->h && y<o->h; y++)
slouken@277
    64
	{
slouken@277
    65
		p=s->pixels+s->pitch*y;
slouken@277
    66
		op[0]=o->pixels[0]+o->pitches[0]*y;
slouken@277
    67
		op[1]=o->pixels[1]+o->pitches[1]*(y/2);
slouken@277
    68
		op[2]=o->pixels[2]+o->pitches[2]*(y/2);
slouken@277
    69
		for(x=0; x<s->w && x<o->w; x++)
slouken@277
    70
		{
slouken@277
    71
			RGBtoYUV(p,yuv);
slouken@277
    72
			*(op[0]++)=yuv[0];
slouken@277
    73
			if(x%2==0 && y%2==0)
slouken@277
    74
			{
slouken@277
    75
				*(op[1]++)=yuv[2];
slouken@277
    76
				*(op[2]++)=yuv[1];
slouken@277
    77
			}
slouken@277
    78
			p+=s->format->BytesPerPixel;
slouken@277
    79
		}
slouken@277
    80
	}
slouken@277
    81
slouken@277
    82
	SDL_UnlockYUVOverlay(o);
slouken@277
    83
	SDL_UnlockSurface(s);
slouken@277
    84
}
slouken@277
    85
slouken@277
    86
ConvertRGBtoIYUV(SDL_Surface *s, SDL_Overlay *o)
slouken@277
    87
{
slouken@277
    88
	int x,y;
slouken@277
    89
	int yuv[3];
slouken@277
    90
	Uint8 *p,*op[3];
slouken@277
    91
slouken@277
    92
	SDL_LockSurface(s);
slouken@277
    93
	SDL_LockYUVOverlay(o);
slouken@277
    94
slouken@277
    95
	/* Black initialization */
slouken@277
    96
	/*
slouken@277
    97
	memset(o->pixels[0],0,o->pitches[0]*o->h);
slouken@277
    98
	memset(o->pixels[1],128,o->pitches[1]*((o->h+1)/2));
slouken@277
    99
	memset(o->pixels[2],128,o->pitches[2]*((o->h+1)/2));
slouken@277
   100
	*/
slouken@277
   101
slouken@277
   102
	/* Convert */
slouken@277
   103
	for(y=0; y<s->h && y<o->h; y++)
slouken@277
   104
	{
slouken@277
   105
		p=s->pixels+s->pitch*y;
slouken@277
   106
		op[0]=o->pixels[0]+o->pitches[0]*y;
slouken@277
   107
		op[1]=o->pixels[1]+o->pitches[1]*(y/2);
slouken@277
   108
		op[2]=o->pixels[2]+o->pitches[2]*(y/2);
slouken@277
   109
		for(x=0; x<s->w && x<o->w; x++)
slouken@277
   110
		{
slouken@277
   111
			RGBtoYUV(p,yuv);
slouken@277
   112
			*(op[0]++)=yuv[0];
slouken@277
   113
			if(x%2==0 && y%2==0)
slouken@277
   114
			{
slouken@277
   115
				*(op[1]++)=yuv[1];
slouken@277
   116
				*(op[2]++)=yuv[2];
slouken@277
   117
			}
slouken@277
   118
			p+=s->format->BytesPerPixel;
slouken@277
   119
		}
slouken@277
   120
	}
slouken@277
   121
slouken@277
   122
	SDL_UnlockYUVOverlay(o);
slouken@277
   123
	SDL_UnlockSurface(s);
slouken@277
   124
}
slouken@277
   125
slouken@277
   126
ConvertRGBtoUYVY(SDL_Surface *s, SDL_Overlay *o)
slouken@277
   127
{
slouken@277
   128
	int x,y;
slouken@277
   129
	int yuv[3];
slouken@277
   130
	Uint8 *p,*op;
slouken@277
   131
slouken@277
   132
	SDL_LockSurface(s);
slouken@277
   133
	SDL_LockYUVOverlay(o);
slouken@277
   134
slouken@277
   135
	for(y=0; y<s->h && y<o->h; y++)
slouken@277
   136
	{
slouken@277
   137
		p=s->pixels+s->pitch*y;
slouken@277
   138
		op=o->pixels[0]+o->pitches[0]*y;
slouken@277
   139
		for(x=0; x<s->w && x<o->w; x++)
slouken@277
   140
		{
slouken@277
   141
			RGBtoYUV(p,yuv);
slouken@277
   142
			if(x%2==0)
slouken@277
   143
			{
slouken@277
   144
				*(op++)=yuv[1];
slouken@277
   145
				*(op++)=yuv[0];
slouken@277
   146
				*(op++)=yuv[2];
slouken@277
   147
			}
slouken@277
   148
			else
slouken@277
   149
				*(op++)=yuv[0];
slouken@277
   150
slouken@277
   151
			p+=s->format->BytesPerPixel;
slouken@277
   152
		}
slouken@277
   153
	}
slouken@277
   154
slouken@277
   155
	SDL_UnlockYUVOverlay(o);
slouken@277
   156
	SDL_UnlockSurface(s);
slouken@277
   157
}
slouken@277
   158
slouken@277
   159
ConvertRGBtoYVYU(SDL_Surface *s, SDL_Overlay *o)
slouken@277
   160
{
slouken@277
   161
	int x,y;
slouken@277
   162
	int yuv[3];
slouken@277
   163
	Uint8 *p,*op;
slouken@277
   164
slouken@277
   165
	SDL_LockSurface(s);
slouken@277
   166
	SDL_LockYUVOverlay(o);
slouken@277
   167
slouken@277
   168
	for(y=0; y<s->h && y<o->h; y++)
slouken@277
   169
	{
slouken@277
   170
		p=s->pixels+s->pitch*y;
slouken@277
   171
		op=o->pixels[0]+o->pitches[0]*y;
slouken@277
   172
		for(x=0; x<s->w && x<o->w; x++)
slouken@277
   173
		{
slouken@277
   174
			RGBtoYUV(p,yuv);
slouken@277
   175
			if(x%2==0)
slouken@277
   176
			{
slouken@277
   177
				*(op++)=yuv[0];
slouken@277
   178
				*(op++)=yuv[2];
slouken@277
   179
				op[1]=yuv[1];
slouken@277
   180
			}
slouken@277
   181
			else
slouken@277
   182
			{
slouken@277
   183
				*op=yuv[0];
slouken@277
   184
				op+=2;
slouken@277
   185
			}
slouken@277
   186
slouken@277
   187
			p+=s->format->BytesPerPixel;
slouken@277
   188
		}
slouken@277
   189
	}
slouken@277
   190
slouken@277
   191
	SDL_UnlockYUVOverlay(o);
slouken@277
   192
	SDL_UnlockSurface(s);
slouken@277
   193
}
slouken@277
   194
slouken@277
   195
ConvertRGBtoYUY2(SDL_Surface *s, SDL_Overlay *o)
slouken@277
   196
{
slouken@277
   197
	int x,y;
slouken@277
   198
	int yuv[3];
slouken@277
   199
	Uint8 *p,*op;
slouken@277
   200
slouken@277
   201
	SDL_LockSurface(s);
slouken@277
   202
	SDL_LockYUVOverlay(o);
slouken@277
   203
slouken@277
   204
	for(y=0; y<s->h && y<o->h; y++)
slouken@277
   205
	{
slouken@277
   206
		p=s->pixels+s->pitch*y;
slouken@277
   207
		op=o->pixels[0]+o->pitches[0]*y;
slouken@277
   208
		for(x=0; x<s->w && x<o->w; x++)
slouken@277
   209
		{
slouken@277
   210
			RGBtoYUV(p,yuv);
slouken@277
   211
			if(x%2==0)
slouken@277
   212
			{
slouken@277
   213
				*(op++)=yuv[0];
slouken@277
   214
				*(op++)=yuv[1];
slouken@277
   215
				op[1]=yuv[2];
slouken@277
   216
			}
slouken@277
   217
			else
slouken@277
   218
			{
slouken@277
   219
				*op=yuv[0];
slouken@277
   220
				op+=2;
slouken@277
   221
			}
slouken@277
   222
slouken@277
   223
			p+=s->format->BytesPerPixel;
slouken@277
   224
		}
slouken@277
   225
	}
slouken@277
   226
slouken@277
   227
	SDL_UnlockYUVOverlay(o);
slouken@277
   228
	SDL_UnlockSurface(s);
slouken@277
   229
}
slouken@277
   230
slouken@277
   231
void Draw()
slouken@277
   232
{
slouken@277
   233
	SDL_Rect rect;
slouken@277
   234
	int i;
slouken@277
   235
slouken@277
   236
	if(!scale)
slouken@277
   237
	{
slouken@277
   238
		rect.w=overlay->w;
slouken@277
   239
		rect.h=overlay->h;
slouken@277
   240
		for(i=0; i<200; i++)
slouken@277
   241
		{
slouken@277
   242
			rect.x=i;
slouken@277
   243
			rect.y=i;
slouken@277
   244
			SDL_DisplayYUVOverlay(overlay,&rect);
slouken@277
   245
		}
slouken@277
   246
	}
slouken@277
   247
	else
slouken@277
   248
	{
slouken@277
   249
		rect.w=screen->w;
slouken@277
   250
		rect.h=screen->h;
slouken@277
   251
		for(i=0; i<200; i++)
slouken@277
   252
		{
slouken@277
   253
			rect.x=i-199;
slouken@277
   254
			rect.y=i-199;
slouken@277
   255
			SDL_DisplayYUVOverlay(overlay,&rect);
slouken@277
   256
		}
slouken@277
   257
	}
slouken@277
   258
	printf("Displayed %d times.\n",i);
slouken@277
   259
}
slouken@277
   260
slouken@277
   261
int main(int argc, char **argv)
slouken@277
   262
{
slouken@277
   263
	int flip;
slouken@277
   264
	int w, h;
slouken@277
   265
	int delay;
slouken@277
   266
	int desired_bpp;
slouken@277
   267
	Uint32 video_flags, overlay_format;
slouken@277
   268
	char *bmpfile;
slouken@277
   269
#ifdef BENCHMARK_SDL
slouken@277
   270
	Uint32 then, now;
slouken@277
   271
#endif
slouken@277
   272
	int i;
slouken@277
   273
slouken@277
   274
	/* Set default options and check command-line */
slouken@277
   275
	flip = 0;
slouken@277
   276
	scale=0;
slouken@277
   277
	delay = 1;
slouken@277
   278
	w = 640;
slouken@277
   279
	h = 480;
slouken@277
   280
	desired_bpp = 0;
slouken@277
   281
	video_flags = 0;
slouken@277
   282
	overlay_format = SDL_YV12_OVERLAY;
slouken@277
   283
slouken@277
   284
	while ( argc > 1 ) {
slouken@277
   285
		if ( strcmp(argv[1], "-delay") == 0 ) {
slouken@277
   286
			if ( argv[2] ) {
slouken@277
   287
				delay = atoi(argv[2]);
slouken@277
   288
				argv += 2;
slouken@277
   289
				argc -= 2;
slouken@277
   290
			} else {
slouken@277
   291
				fprintf(stderr,
slouken@277
   292
				"The -delay option requires an argument\n");
slouken@277
   293
				exit(1);
slouken@277
   294
			}
slouken@277
   295
		} else
slouken@277
   296
		if ( strcmp(argv[1], "-width") == 0 ) {
slouken@277
   297
			if ( argv[2] && ((w = atoi(argv[2])) > 0) ) {
slouken@277
   298
				argv += 2;
slouken@277
   299
				argc -= 2;
slouken@277
   300
			} else {
slouken@277
   301
				fprintf(stderr,
slouken@277
   302
				"The -width option requires an argument\n");
slouken@277
   303
				exit(1);
slouken@277
   304
			}
slouken@277
   305
		} else
slouken@277
   306
		if ( strcmp(argv[1], "-height") == 0 ) {
slouken@277
   307
			if ( argv[2] && ((h = atoi(argv[2])) > 0) ) {
slouken@277
   308
				argv += 2;
slouken@277
   309
				argc -= 2;
slouken@277
   310
			} else {
slouken@277
   311
				fprintf(stderr,
slouken@277
   312
				"The -height option requires an argument\n");
slouken@277
   313
				exit(1);
slouken@277
   314
			}
slouken@277
   315
		} else
slouken@277
   316
		if ( strcmp(argv[1], "-bpp") == 0 ) {
slouken@277
   317
			if ( argv[2] ) {
slouken@277
   318
				desired_bpp = atoi(argv[2]);
slouken@277
   319
				argv += 2;
slouken@277
   320
				argc -= 2;
slouken@277
   321
			} else {
slouken@277
   322
				fprintf(stderr,
slouken@277
   323
				"The -bpp option requires an argument\n");
slouken@277
   324
				exit(1);
slouken@277
   325
			}
slouken@277
   326
		} else
slouken@277
   327
		if ( strcmp(argv[1], "-format") == 0 ) {
slouken@277
   328
			if ( argv[2] ) {
slouken@277
   329
				if(!strcmp(argv[2],"YV12"))
slouken@277
   330
					overlay_format = SDL_YV12_OVERLAY;
slouken@277
   331
				else if(!strcmp(argv[2],"IYUV"))
slouken@277
   332
					overlay_format = SDL_IYUV_OVERLAY;
slouken@277
   333
				else if(!strcmp(argv[2],"YUY2"))
slouken@277
   334
					overlay_format = SDL_YUY2_OVERLAY;
slouken@277
   335
				else if(!strcmp(argv[2],"UYVY"))
slouken@277
   336
					overlay_format = SDL_UYVY_OVERLAY;
slouken@277
   337
				else if(!strcmp(argv[2],"YVYU"))
slouken@277
   338
					overlay_format = SDL_YVYU_OVERLAY;
slouken@277
   339
				else
slouken@277
   340
				{
slouken@277
   341
					fprintf(stderr, "The -format option %s is not recognized\n",argv[2]);
slouken@277
   342
					exit(1);
slouken@277
   343
				}
slouken@277
   344
				argv += 2;
slouken@277
   345
				argc -= 2;
slouken@277
   346
			} else {
slouken@277
   347
				fprintf(stderr,
slouken@277
   348
				"The -format option requires an argument\n");
slouken@277
   349
				exit(1);
slouken@277
   350
			}
slouken@277
   351
		} else
slouken@277
   352
		if ( strcmp(argv[1], "-hw") == 0 ) {
slouken@277
   353
			video_flags |= SDL_HWSURFACE;
slouken@277
   354
			argv += 1;
slouken@277
   355
			argc -= 1;
slouken@277
   356
		} else
slouken@277
   357
		if ( strcmp(argv[1], "-flip") == 0 ) {
slouken@277
   358
			video_flags |= SDL_DOUBLEBUF;
slouken@277
   359
			argv += 1;
slouken@277
   360
			argc -= 1;
slouken@277
   361
		} else
slouken@277
   362
		if ( strcmp(argv[1], "-scale") == 0 ) {
slouken@277
   363
			scale = 1;
slouken@277
   364
			argv += 1;
slouken@277
   365
			argc -= 1;
slouken@277
   366
		} else
slouken@277
   367
		if ( strcmp(argv[1], "-fullscreen") == 0 ) {
slouken@277
   368
			video_flags |= SDL_FULLSCREEN;
slouken@277
   369
			argv += 1;
slouken@277
   370
			argc -= 1;
slouken@277
   371
		} else
slouken@277
   372
			break;
slouken@277
   373
	}
slouken@277
   374
	if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
slouken@277
   375
		fprintf(stderr,
slouken@277
   376
			"Couldn't initialize SDL: %s\n", SDL_GetError());
slouken@277
   377
		exit(1);
slouken@277
   378
	}
slouken@277
   379
	atexit(SDL_Quit);			/* Clean up on exit */
slouken@277
   380
slouken@277
   381
	/* Initialize the display */
slouken@277
   382
	screen = SDL_SetVideoMode(w, h, desired_bpp, video_flags);
slouken@277
   383
	if ( screen == NULL ) {
slouken@277
   384
		fprintf(stderr, "Couldn't set %dx%dx%d video mode: %s\n",
slouken@277
   385
					w, h, desired_bpp, SDL_GetError());
slouken@277
   386
		exit(1);
slouken@277
   387
	}
slouken@277
   388
	printf("Set%s %dx%dx%d mode\n",
slouken@277
   389
			screen->flags & SDL_FULLSCREEN ? " fullscreen" : "",
slouken@277
   390
			screen->w, screen->h, screen->format->BitsPerPixel);
slouken@277
   391
	printf("(video surface located in %s memory)\n",
slouken@277
   392
			(screen->flags&SDL_HWSURFACE) ? "video" : "system");
slouken@277
   393
	if ( screen->flags & SDL_DOUBLEBUF ) {
slouken@277
   394
		printf("Double-buffering enabled\n");
slouken@277
   395
		flip = 1;
slouken@277
   396
	}
slouken@277
   397
slouken@277
   398
	/* Set the window manager title bar */
slouken@277
   399
	SDL_WM_SetCaption("SDL test overlay", "testoverlay");
slouken@277
   400
slouken@277
   401
	/* Load picture */
slouken@277
   402
	bmpfile=(argv[1]?argv[1]:"sample.bmp");
slouken@277
   403
	pic = SDL_LoadBMP(bmpfile);
slouken@277
   404
	if ( pic == NULL ) {
slouken@277
   405
		fprintf(stderr, "Couldn't load %s: %s\n", bmpfile,
slouken@277
   406
							SDL_GetError());
slouken@277
   407
		exit(1);
slouken@277
   408
	}
slouken@277
   409
slouken@277
   410
	/* Convert the picture to 32bits, for easy conversion */
slouken@277
   411
	{
slouken@277
   412
		SDL_Surface *newsurf;
slouken@277
   413
		SDL_PixelFormat format;
slouken@277
   414
slouken@277
   415
		format.palette=NULL;
slouken@277
   416
		format.BitsPerPixel=32;
slouken@277
   417
		format.BytesPerPixel=4;
slouken@277
   418
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
slouken@277
   419
		format.Rshift=0;
slouken@277
   420
		format.Gshift=8;
slouken@277
   421
		format.Bshift=16;
slouken@277
   422
#else
slouken@277
   423
		format.Rshift=24;
slouken@277
   424
		format.Gshift=16;
slouken@277
   425
		format.Bshift=8;
slouken@277
   426
#endif
slouken@277
   427
		format.Ashift=0;
slouken@277
   428
		format.Rmask=0xff<<format.Rshift;
slouken@277
   429
		format.Gmask=0xff<<format.Gshift;
slouken@277
   430
		format.Bmask=0xff<<format.Bshift;
slouken@277
   431
		format.Amask=0;
slouken@277
   432
		format.Rloss=0;
slouken@277
   433
		format.Gloss=0;
slouken@277
   434
		format.Bloss=0;
slouken@277
   435
		format.Aloss=8;
slouken@277
   436
		format.colorkey=0;
slouken@277
   437
		format.alpha=0;
slouken@277
   438
slouken@277
   439
		newsurf=SDL_ConvertSurface(pic, &format, SDL_SWSURFACE);
slouken@277
   440
		if(!newsurf)
slouken@277
   441
		{
slouken@277
   442
			fprintf(stderr, "Couldn't convert picture to 32bits RGB: %s\n",
slouken@277
   443
							SDL_GetError());
slouken@277
   444
			exit(1);
slouken@277
   445
		}
slouken@277
   446
		SDL_FreeSurface(pic);
slouken@277
   447
		pic=newsurf;
slouken@277
   448
	}
slouken@277
   449
	
slouken@277
   450
	/* Create the overlay */
slouken@277
   451
	overlay = SDL_CreateYUVOverlay(pic->w, pic->h, overlay_format, screen);
slouken@277
   452
	if ( overlay == NULL ) {
slouken@277
   453
		fprintf(stderr, "Couldn't create overlay: %s\n", SDL_GetError());
slouken@277
   454
		exit(1);
slouken@277
   455
	}
slouken@277
   456
	printf("Created %dx%dx%d %s %s overlay\n",overlay->w,overlay->h,overlay->planes,
slouken@277
   457
			overlay->hw_overlay?"hardware":"software",
slouken@277
   458
			overlay->format==SDL_YV12_OVERLAY?"YV12":
slouken@277
   459
			overlay->format==SDL_IYUV_OVERLAY?"IYUV":
slouken@277
   460
			overlay->format==SDL_YUY2_OVERLAY?"YUY2":
slouken@277
   461
			overlay->format==SDL_UYVY_OVERLAY?"UYVY":
slouken@277
   462
			overlay->format==SDL_YVYU_OVERLAY?"YVYU":
slouken@277
   463
			"Unknown");
slouken@277
   464
	for(i=0; i<overlay->planes; i++)
slouken@277
   465
	{
slouken@277
   466
		printf("  plane %d: pitch=%d\n", i, overlay->pitches[i]);
slouken@277
   467
	}
slouken@277
   468
	
slouken@277
   469
	/* Convert to YUV, and draw to the overlay */
slouken@277
   470
#ifdef BENCHMARK_SDL
slouken@277
   471
	then = SDL_GetTicks();
slouken@277
   472
#endif
slouken@277
   473
	switch(overlay->format)
slouken@277
   474
	{
slouken@277
   475
		case SDL_YV12_OVERLAY:
slouken@277
   476
			ConvertRGBtoYV12(pic,overlay);
slouken@277
   477
			break;
slouken@277
   478
		case SDL_UYVY_OVERLAY:
slouken@277
   479
			ConvertRGBtoUYVY(pic,overlay);
slouken@277
   480
			break;
slouken@277
   481
		case SDL_YVYU_OVERLAY:
slouken@277
   482
			ConvertRGBtoYVYU(pic,overlay);
slouken@277
   483
			break;
slouken@277
   484
		case SDL_YUY2_OVERLAY:
slouken@277
   485
			ConvertRGBtoYUY2(pic,overlay);
slouken@277
   486
			break;
slouken@277
   487
		case SDL_IYUV_OVERLAY:
slouken@277
   488
			ConvertRGBtoIYUV(pic,overlay);
slouken@277
   489
			break;
slouken@277
   490
		default:
slouken@277
   491
			printf("cannot convert RGB picture to obtained YUV format!\n");
slouken@277
   492
			exit(1);
slouken@277
   493
			break;
slouken@277
   494
	}
slouken@277
   495
#ifdef BENCHMARK_SDL
slouken@277
   496
	now = SDL_GetTicks();
slouken@277
   497
	printf("Conversion Time: %d milliseconds\n", now-then);
slouken@277
   498
#endif
slouken@277
   499
	
slouken@277
   500
	/* Do all the drawing work */
slouken@277
   501
#ifdef BENCHMARK_SDL
slouken@277
   502
	then = SDL_GetTicks();
slouken@277
   503
#endif
slouken@277
   504
	Draw();
slouken@277
   505
#ifdef BENCHMARK_SDL
slouken@277
   506
	now = SDL_GetTicks();
slouken@277
   507
	printf("Time: %d milliseconds\n", now-then);
slouken@277
   508
#endif
slouken@277
   509
	SDL_Delay(delay*1000);
slouken@277
   510
	return(0);
slouken@277
   511
}
slouken@277
   512