test/testoverlay2.c
author Sam Lantinga <slouken@libsdl.org>
Fri, 08 Aug 2003 21:31:18 +0000
changeset 672 5955fa16d4b8
child 673 63419da96d13
permissions -rw-r--r--
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 :)
slouken@672
     1
/********************************************************************************
slouken@672
     2
 *                                                                              *
slouken@672
     3
 * Test of the overlay used for moved pictures, test more closed to real life.  *
slouken@672
     4
 * Running trojan moose :) Coded by Mike Gorchak.                               *
slouken@672
     5
 *                                                                              *
slouken@672
     6
 ********************************************************************************/
slouken@672
     7
slouken@672
     8
#include "SDL.h"
slouken@672
     9
slouken@672
    10
#define MOOSEPIC_W 64
slouken@672
    11
#define MOOSEPIC_H 88
slouken@672
    12
slouken@672
    13
#define MOOSEFRAME_SIZE (MOOSEPIC_W * MOOSEPIC_H)
slouken@672
    14
#define MOOSEFRAMES_COUNT 10
slouken@672
    15
slouken@672
    16
SDL_Color MooseColors[84]={
slouken@672
    17
    { 49,  49,  49}, { 66,  24,   0}, { 66,  33,   0}, { 66,  66,  66},
slouken@672
    18
    { 66, 115,  49}, { 74,  33,   0}, { 74,  41,  16}, { 82,  33,   8},
slouken@672
    19
    { 82,  41,   8}, { 82,  49,  16}, { 82,  82,  82}, { 90,  41,   8},
slouken@672
    20
    { 90,  41,  16}, { 90,  57,  24}, { 99,  49,  16}, { 99,  66,  24},
slouken@672
    21
    { 99,  66,  33}, { 99,  74,  33}, {107,  57,  24}, {107,  82,  41},
slouken@672
    22
    {115,  57,  33}, {115,  66,  33}, {115,  66,  41}, {115,  74,   0},
slouken@672
    23
    {115,  90,  49}, {115, 115, 115}, {123,  82,   0}, {123,  99,  57},
slouken@672
    24
    {132,  66,  41}, {132,  74,  41}, {132,  90,   8}, {132,  99,  33},
slouken@672
    25
    {132,  99,  66}, {132, 107,  66}, {140,  74,  49}, {140,  99,  16},
slouken@672
    26
    {140, 107,  74}, {140, 115,  74}, {148, 107,  24}, {148, 115,  82},
slouken@672
    27
    {148, 123,  74}, {148, 123,  90}, {156, 115,  33}, {156, 115,  90},
slouken@672
    28
    {156, 123,  82}, {156, 132,  82}, {156, 132,  99}, {156, 156, 156},
slouken@672
    29
    {165, 123,  49}, {165, 123,  90}, {165, 132,  82}, {165, 132,  90},
slouken@672
    30
    {165, 132,  99}, {165, 140,  90}, {173, 132,  57}, {173, 132,  99},
slouken@672
    31
    {173, 140, 107}, {173, 140, 115}, {173, 148,  99}, {173, 173, 173},
slouken@672
    32
    {181, 140,  74}, {181, 148, 115}, {181, 148, 123}, {181, 156, 107},
slouken@672
    33
    {189, 148, 123}, {189, 156,  82}, {189, 156, 123}, {189, 156, 132},
slouken@672
    34
    {189, 189, 189}, {198, 156, 123}, {198, 165, 132}, {206, 165,  99},
slouken@672
    35
    {206, 165, 132}, {206, 173, 140}, {206, 206, 206}, {214, 173, 115},
slouken@672
    36
    {214, 173, 140}, {222, 181, 148}, {222, 189, 132}, {222, 189, 156},
slouken@672
    37
    {222, 222, 222}, {231, 198, 165}, {231, 231, 231}, {239, 206, 173}
slouken@672
    38
};
slouken@672
    39
slouken@672
    40
/* All RGB2YUV conversion code and some other parts of code has been taken from testoverlay.c */
slouken@672
    41
slouken@672
    42
/* NOTE: These RGB conversion functions are not intended for speed,
slouken@672
    43
         only as examples.
slouken@672
    44
*/
slouken@672
    45
slouken@672
    46
void RGBtoYUV(Uint8 *rgb, int *yuv, int monochrome, int luminance)
slouken@672
    47
{
slouken@672
    48
    int i;
slouken@672
    49
slouken@672
    50
    if (monochrome)
slouken@672
    51
    {
slouken@672
    52
#if 1 /* these are the two formulas that I found on the FourCC site... */
slouken@672
    53
        yuv[0] = 0.299*rgb[0] + 0.587*rgb[1] + 0.114*rgb[2];
slouken@672
    54
        yuv[1] = 128;
slouken@672
    55
        yuv[2] = 128;
slouken@672
    56
#else
slouken@672
    57
        yuv[0] = (0.257 * rgb[0]) + (0.504 * rgb[1]) + (0.098 * rgb[2]) + 16;
slouken@672
    58
        yuv[1] = 128;
slouken@672
    59
        yuv[2] = 128;
slouken@672
    60
#endif
slouken@672
    61
    }
slouken@672
    62
    else
slouken@672
    63
    {
slouken@672
    64
#if 1 /* these are the two formulas that I found on the FourCC site... */
slouken@672
    65
        yuv[0] = 0.299*rgb[0] + 0.587*rgb[1] + 0.114*rgb[2];
slouken@672
    66
        yuv[1] = (rgb[2]-yuv[0])*0.565 + 128;
slouken@672
    67
        yuv[2] = (rgb[0]-yuv[0])*0.713 + 128;
slouken@672
    68
#else
slouken@672
    69
        yuv[0] = (0.257 * rgb[0]) + (0.504 * rgb[1]) + (0.098 * rgb[2]) + 16;
slouken@672
    70
        yuv[1] = 128 - (0.148 * rgb[0]) - (0.291 * rgb[1]) + (0.439 * rgb[2]);
slouken@672
    71
        yuv[2] = 128 + (0.439 * rgb[0]) - (0.368 * rgb[1]) - (0.071 * rgb[2]);
slouken@672
    72
#endif
slouken@672
    73
    }
slouken@672
    74
slouken@672
    75
    if (luminance!=100)
slouken@672
    76
    {
slouken@672
    77
        yuv[0]=yuv[0]*luminance/100;
slouken@672
    78
        if (yuv[0]>255)
slouken@672
    79
            yuv[0]=255;
slouken@672
    80
    }
slouken@672
    81
}
slouken@672
    82
slouken@672
    83
ConvertRGBtoYV12(SDL_Surface *s, SDL_Overlay *o, int monochrome, int luminance)
slouken@672
    84
{
slouken@672
    85
	int x,y;
slouken@672
    86
	int yuv[3];
slouken@672
    87
	Uint8 *p,*op[3];
slouken@672
    88
slouken@672
    89
	SDL_LockSurface(s);
slouken@672
    90
	SDL_LockYUVOverlay(o);
slouken@672
    91
slouken@672
    92
	/* Convert */
slouken@672
    93
	for(y=0; y<s->h && y<o->h; y++)
slouken@672
    94
	{
slouken@672
    95
		p=((Uint8 *) s->pixels)+s->pitch*y;
slouken@672
    96
		op[0]=o->pixels[0]+o->pitches[0]*y;
slouken@672
    97
		op[1]=o->pixels[1]+o->pitches[1]*(y/2);
slouken@672
    98
		op[2]=o->pixels[2]+o->pitches[2]*(y/2);
slouken@672
    99
		for(x=0; x<s->w && x<o->w; x++)
slouken@672
   100
		{
slouken@672
   101
			RGBtoYUV(p, yuv, monochrome, luminance);
slouken@672
   102
			*(op[0]++)=yuv[0];
slouken@672
   103
			if(x%2==0 && y%2==0)
slouken@672
   104
			{
slouken@672
   105
				*(op[1]++)=yuv[2];
slouken@672
   106
				*(op[2]++)=yuv[1];
slouken@672
   107
			}
slouken@672
   108
			p+=s->format->BytesPerPixel;
slouken@672
   109
		}
slouken@672
   110
	}
slouken@672
   111
slouken@672
   112
	SDL_UnlockYUVOverlay(o);
slouken@672
   113
	SDL_UnlockSurface(s);
slouken@672
   114
}
slouken@672
   115
slouken@672
   116
ConvertRGBtoIYUV(SDL_Surface *s, SDL_Overlay *o, int monochrome, int luminance)
slouken@672
   117
{
slouken@672
   118
	int x,y;
slouken@672
   119
	int yuv[3];
slouken@672
   120
	Uint8 *p,*op[3];
slouken@672
   121
slouken@672
   122
	SDL_LockSurface(s);
slouken@672
   123
	SDL_LockYUVOverlay(o);
slouken@672
   124
slouken@672
   125
	/* Convert */
slouken@672
   126
	for(y=0; y<s->h && y<o->h; y++)
slouken@672
   127
	{
slouken@672
   128
		p=((Uint8 *) s->pixels)+s->pitch*y;
slouken@672
   129
		op[0]=o->pixels[0]+o->pitches[0]*y;
slouken@672
   130
		op[1]=o->pixels[1]+o->pitches[1]*(y/2);
slouken@672
   131
		op[2]=o->pixels[2]+o->pitches[2]*(y/2);
slouken@672
   132
		for(x=0; x<s->w && x<o->w; x++)
slouken@672
   133
		{
slouken@672
   134
			RGBtoYUV(p,yuv, monochrome, luminance);
slouken@672
   135
			*(op[0]++)=yuv[0];
slouken@672
   136
			if(x%2==0 && y%2==0)
slouken@672
   137
			{
slouken@672
   138
				*(op[1]++)=yuv[1];
slouken@672
   139
				*(op[2]++)=yuv[2];
slouken@672
   140
			}
slouken@672
   141
			p+=s->format->BytesPerPixel;
slouken@672
   142
		}
slouken@672
   143
	}
slouken@672
   144
slouken@672
   145
	SDL_UnlockYUVOverlay(o);
slouken@672
   146
	SDL_UnlockSurface(s);
slouken@672
   147
}
slouken@672
   148
slouken@672
   149
ConvertRGBtoUYVY(SDL_Surface *s, SDL_Overlay *o, int monochrome, int luminance)
slouken@672
   150
{
slouken@672
   151
	int x,y;
slouken@672
   152
	int yuv[3];
slouken@672
   153
	Uint8 *p,*op;
slouken@672
   154
slouken@672
   155
	SDL_LockSurface(s);
slouken@672
   156
	SDL_LockYUVOverlay(o);
slouken@672
   157
slouken@672
   158
	for(y=0; y<s->h && y<o->h; y++)
slouken@672
   159
	{
slouken@672
   160
		p=((Uint8 *) s->pixels)+s->pitch*y;
slouken@672
   161
		op=o->pixels[0]+o->pitches[0]*y;
slouken@672
   162
		for(x=0; x<s->w && x<o->w; x++)
slouken@672
   163
		{
slouken@672
   164
			RGBtoYUV(p, yuv, monochrome, luminance);
slouken@672
   165
			if(x%2==0)
slouken@672
   166
			{
slouken@672
   167
				*(op++)=yuv[1];
slouken@672
   168
				*(op++)=yuv[0];
slouken@672
   169
				*(op++)=yuv[2];
slouken@672
   170
			}
slouken@672
   171
			else
slouken@672
   172
				*(op++)=yuv[0];
slouken@672
   173
slouken@672
   174
			p+=s->format->BytesPerPixel;
slouken@672
   175
		}
slouken@672
   176
	}
slouken@672
   177
slouken@672
   178
	SDL_UnlockYUVOverlay(o);
slouken@672
   179
	SDL_UnlockSurface(s);
slouken@672
   180
}
slouken@672
   181
slouken@672
   182
ConvertRGBtoYVYU(SDL_Surface *s, SDL_Overlay *o, int monochrome, int luminance)
slouken@672
   183
{
slouken@672
   184
	int x,y;
slouken@672
   185
	int yuv[3];
slouken@672
   186
	Uint8 *p,*op;
slouken@672
   187
slouken@672
   188
	SDL_LockSurface(s);
slouken@672
   189
	SDL_LockYUVOverlay(o);
slouken@672
   190
slouken@672
   191
	for(y=0; y<s->h && y<o->h; y++)
slouken@672
   192
	{
slouken@672
   193
		p=((Uint8 *) s->pixels)+s->pitch*y;
slouken@672
   194
		op=o->pixels[0]+o->pitches[0]*y;
slouken@672
   195
		for(x=0; x<s->w && x<o->w; x++)
slouken@672
   196
		{
slouken@672
   197
			RGBtoYUV(p,yuv, monochrome, luminance);
slouken@672
   198
			if(x%2==0)
slouken@672
   199
			{
slouken@672
   200
				*(op++)=yuv[0];
slouken@672
   201
				*(op++)=yuv[2];
slouken@672
   202
				op[1]=yuv[1];
slouken@672
   203
			}
slouken@672
   204
			else
slouken@672
   205
			{
slouken@672
   206
				*op=yuv[0];
slouken@672
   207
				op+=2;
slouken@672
   208
			}
slouken@672
   209
slouken@672
   210
			p+=s->format->BytesPerPixel;
slouken@672
   211
		}
slouken@672
   212
	}
slouken@672
   213
slouken@672
   214
	SDL_UnlockYUVOverlay(o);
slouken@672
   215
	SDL_UnlockSurface(s);
slouken@672
   216
}
slouken@672
   217
slouken@672
   218
ConvertRGBtoYUY2(SDL_Surface *s, SDL_Overlay *o, int monochrome, int luminance)
slouken@672
   219
{
slouken@672
   220
	int x,y;
slouken@672
   221
	int yuv[3];
slouken@672
   222
	Uint8 *p,*op;
slouken@672
   223
slouken@672
   224
	SDL_LockSurface(s);
slouken@672
   225
	SDL_LockYUVOverlay(o);
slouken@672
   226
        
slouken@672
   227
	for(y=0; y<s->h && y<o->h; y++)
slouken@672
   228
	{
slouken@672
   229
		p=((Uint8 *) s->pixels)+s->pitch*y;
slouken@672
   230
		op=o->pixels[0]+o->pitches[0]*y;
slouken@672
   231
		for(x=0; x<s->w && x<o->w; x++)
slouken@672
   232
		{
slouken@672
   233
			RGBtoYUV(p,yuv, monochrome, luminance);
slouken@672
   234
			if(x%2==0)
slouken@672
   235
			{
slouken@672
   236
				*(op++)=yuv[0];
slouken@672
   237
				*(op++)=yuv[1];
slouken@672
   238
				op[1]=yuv[2];
slouken@672
   239
			}
slouken@672
   240
			else
slouken@672
   241
			{
slouken@672
   242
				*op=yuv[0];
slouken@672
   243
				op+=2;
slouken@672
   244
			}
slouken@672
   245
slouken@672
   246
			p+=s->format->BytesPerPixel;
slouken@672
   247
		}
slouken@672
   248
	}
slouken@672
   249
slouken@672
   250
	SDL_UnlockYUVOverlay(o);
slouken@672
   251
	SDL_UnlockSurface(s);
slouken@672
   252
}
slouken@672
   253
slouken@672
   254
void Draw()
slouken@672
   255
{
slouken@672
   256
}
slouken@672
   257
slouken@672
   258
static void PrintUsage(char *argv0)
slouken@672
   259
{
slouken@672
   260
    fprintf(stderr, "Usage: %s [arg] [arg] [arg] ...\n", argv0);
slouken@672
   261
    fprintf(stderr, "Where 'arg' is one of:\n");
slouken@672
   262
    fprintf(stderr, "	-fps <frames per second>\n");
slouken@672
   263
    fprintf(stderr, "	-format <fmt> (one of the: YV12, IYUV, YUY2, UYVY, YVYU)\n");
slouken@672
   264
    fprintf(stderr, "	-scale <scale factor> (initial scale of the overlay)\n");
slouken@672
   265
    fprintf(stderr, "	-help (shows this help)\n");
slouken@672
   266
    fprintf(stderr, "\n");
slouken@672
   267
    fprintf(stderr, "	Press ESC to exit, or SPACE to freeze the movie while application running.\n");
slouken@672
   268
    fprintf(stderr, "\n");
slouken@672
   269
}
slouken@672
   270
slouken@672
   271
int main(int argc, char **argv)
slouken@672
   272
{
slouken@672
   273
    Uint8* RawMooseData;
slouken@672
   274
    SDL_RWops* handle;
slouken@672
   275
    SDL_Surface* screen;
slouken@672
   276
    SDL_Surface* MooseFrame[MOOSEFRAMES_COUNT];
slouken@672
   277
    SDL_Overlay* overlay;
slouken@672
   278
    SDL_Rect overlayrect;
slouken@672
   279
    SDL_Event event;
slouken@672
   280
    Uint32 lastftick;
slouken@672
   281
    int paused=0;
slouken@672
   282
    int i;
slouken@672
   283
    int fps=12;
slouken@672
   284
    int fpsdelay;
slouken@672
   285
    int overlay_format=SDL_YUY2_OVERLAY;
slouken@672
   286
    int scale=5;
slouken@672
   287
slouken@672
   288
    while ( argc > 1 )
slouken@672
   289
    {
slouken@672
   290
        if (strcmp(argv[1], "-fps")== 0)
slouken@672
   291
        {
slouken@672
   292
            if (argv[2])
slouken@672
   293
            {
slouken@672
   294
                fps = atoi(argv[2]);
slouken@672
   295
                if (fps==0)
slouken@672
   296
                {
slouken@672
   297
                    fprintf(stderr, "The -fps option requires an argument [from 1 to 1000], default is 12.\n");
slouken@672
   298
                    return -1;
slouken@672
   299
                }
slouken@672
   300
                if ((fps<0) || (fps>1000))
slouken@672
   301
                {
slouken@672
   302
                    fprintf(stderr, "The -fps option must be in range from 1 to 1000, default is 12.\n");
slouken@672
   303
                    return -1;
slouken@672
   304
                }
slouken@672
   305
                argv += 2;
slouken@672
   306
                argc -= 2;
slouken@672
   307
            }
slouken@672
   308
            else
slouken@672
   309
            {
slouken@672
   310
                fprintf(stderr, "The -fps option requires an argument [from 1 to 1000], default is 12.\n");
slouken@672
   311
                return -1;
slouken@672
   312
            }
slouken@672
   313
        } else
slouken@672
   314
        if (strcmp(argv[1], "-format") == 0)
slouken@672
   315
        {
slouken@672
   316
            if (argv[2])
slouken@672
   317
            {
slouken@672
   318
                if (!strcmp(argv[2],"YV12"))
slouken@672
   319
                    overlay_format = SDL_YV12_OVERLAY;
slouken@672
   320
                else if(!strcmp(argv[2],"IYUV"))
slouken@672
   321
                    overlay_format = SDL_IYUV_OVERLAY;
slouken@672
   322
                else if(!strcmp(argv[2],"YUY2"))
slouken@672
   323
                    overlay_format = SDL_YUY2_OVERLAY;
slouken@672
   324
                else if(!strcmp(argv[2],"UYVY"))
slouken@672
   325
                    overlay_format = SDL_UYVY_OVERLAY;
slouken@672
   326
                else if(!strcmp(argv[2],"YVYU"))
slouken@672
   327
                    overlay_format = SDL_YVYU_OVERLAY;
slouken@672
   328
                else
slouken@672
   329
                {
slouken@672
   330
                    fprintf(stderr, "The -format option %s is not recognized, see help for info.\n", argv[2]);
slouken@672
   331
                    return -1;
slouken@672
   332
                }
slouken@672
   333
                argv += 2;
slouken@672
   334
                argc -= 2;
slouken@672
   335
            }
slouken@672
   336
            else
slouken@672
   337
            {
slouken@672
   338
                fprintf(stderr, "The -format option requires an argument, default is YUY2.\n");
slouken@672
   339
                return -1;
slouken@672
   340
            }
slouken@672
   341
        } else
slouken@672
   342
        if (strcmp(argv[1], "-scale") == 0)
slouken@672
   343
        {
slouken@672
   344
            if (argv[2])
slouken@672
   345
            {
slouken@672
   346
                scale = atoi(argv[2]);
slouken@672
   347
                if (scale==0)
slouken@672
   348
                {
slouken@672
   349
                    fprintf(stderr, "The -scale option requires an argument [from 1 to 50], default is 5.\n");
slouken@672
   350
                    return -1;
slouken@672
   351
                }
slouken@672
   352
                if ((scale<0) || (scale>50))
slouken@672
   353
                {
slouken@672
   354
                    fprintf(stderr, "The -scale option must be in range from 1 to 50, default is 5.\n");
slouken@672
   355
                    return -1;
slouken@672
   356
                }
slouken@672
   357
                argv += 2;
slouken@672
   358
                argc -= 2;
slouken@672
   359
            }
slouken@672
   360
            else
slouken@672
   361
            {
slouken@672
   362
                fprintf(stderr, "The -fps option requires an argument [from 1 to 1000], default is 12.\n");
slouken@672
   363
                return -1;
slouken@672
   364
            }
slouken@672
   365
        } else
slouken@672
   366
        if ((strcmp(argv[1], "-help") == 0 ) || (strcmp(argv[1], "-h") == 0))
slouken@672
   367
        {
slouken@672
   368
            PrintUsage(argv[0]);
slouken@672
   369
            return 0;
slouken@672
   370
        } else
slouken@672
   371
        {
slouken@672
   372
            fprintf(stderr, "Unrecognized option: %s.\n", argv[1]);
slouken@672
   373
            return -1;
slouken@672
   374
        }
slouken@672
   375
        break;
slouken@672
   376
    }
slouken@672
   377
   
slouken@672
   378
    RawMooseData=(Uint8*)malloc(MOOSEFRAME_SIZE * MOOSEFRAMES_COUNT);
slouken@672
   379
    if (RawMooseData==NULL)
slouken@672
   380
    {
slouken@672
   381
        fprintf(stderr, "Can't allocate memory for movie !\n");
slouken@672
   382
        free(RawMooseData);
slouken@672
   383
        return 1;
slouken@672
   384
    }
slouken@672
   385
slouken@672
   386
    /* load the trojan moose images */
slouken@672
   387
    handle=SDL_RWFromFile("moose.dat", "r");
slouken@672
   388
    if (handle==NULL)
slouken@672
   389
    {
slouken@672
   390
        fprintf(stderr, "Can't find the file moose.dat !\n");
slouken@672
   391
        free(RawMooseData);
slouken@672
   392
        return 2;
slouken@672
   393
    }
slouken@672
   394
   
slouken@672
   395
    SDL_RWread(handle, RawMooseData, MOOSEFRAME_SIZE, MOOSEFRAMES_COUNT);
slouken@672
   396
slouken@672
   397
    SDL_RWclose(handle);
slouken@672
   398
slouken@672
   399
    if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) < 0)
slouken@672
   400
    {
slouken@672
   401
        fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
slouken@672
   402
        free(RawMooseData);
slouken@672
   403
        return 3;
slouken@672
   404
    }
slouken@672
   405
    atexit(SDL_Quit);
slouken@672
   406
slouken@672
   407
    /* Set 640x480 video mode */
slouken@672
   408
    if ( (screen=SDL_SetVideoMode(MOOSEPIC_W*scale, MOOSEPIC_H*scale, 0, SDL_RESIZABLE | SDL_SWSURFACE)) == NULL )
slouken@672
   409
    {
slouken@672
   410
        fprintf(stderr, "Couldn't set video mode: %s\n", 0, SDL_GetError());
slouken@672
   411
        free(RawMooseData);
slouken@672
   412
        return 4;
slouken@672
   413
    }
slouken@672
   414
slouken@672
   415
    /* Set the window manager title bar */
slouken@672
   416
    SDL_WM_SetCaption("SDL test overlay: running moose", "testoverlay2");
slouken@672
   417
slouken@672
   418
    for (i=0; i<MOOSEFRAMES_COUNT; i++)
slouken@672
   419
    {
slouken@672
   420
        MooseFrame[i]=SDL_CreateRGBSurfaceFrom(RawMooseData+i*MOOSEFRAME_SIZE, MOOSEPIC_W,
slouken@672
   421
                                               MOOSEPIC_H, 8, MOOSEPIC_W, 0, 0, 0, 0);
slouken@672
   422
        if (MooseFrame[i]==NULL)
slouken@672
   423
        {
slouken@672
   424
            fprintf(stderr, "Couldn't create SDL_Surfaces:%s\n", 0, SDL_GetError());
slouken@672
   425
            free(RawMooseData);
slouken@672
   426
            return 5;
slouken@672
   427
        }
slouken@672
   428
        SDL_SetColors(MooseFrame[i], MooseColors, 0, 84);
slouken@672
   429
slouken@672
   430
	{
slouken@672
   431
		SDL_Surface *newsurf;
slouken@672
   432
		SDL_PixelFormat format;
slouken@672
   433
slouken@672
   434
		format.palette=NULL;
slouken@672
   435
		format.BitsPerPixel=32;
slouken@672
   436
		format.BytesPerPixel=4;
slouken@672
   437
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
slouken@672
   438
		format.Rshift=0;
slouken@672
   439
		format.Gshift=8;
slouken@672
   440
		format.Bshift=16;
slouken@672
   441
#else
slouken@672
   442
		format.Rshift=24;
slouken@672
   443
		format.Gshift=16;
slouken@672
   444
		format.Bshift=8;
slouken@672
   445
#endif
slouken@672
   446
		format.Ashift=0;
slouken@672
   447
		format.Rmask=0xff<<format.Rshift;
slouken@672
   448
		format.Gmask=0xff<<format.Gshift;
slouken@672
   449
		format.Bmask=0xff<<format.Bshift;
slouken@672
   450
		format.Amask=0;
slouken@672
   451
		format.Rloss=0;
slouken@672
   452
		format.Gloss=0;
slouken@672
   453
		format.Bloss=0;
slouken@672
   454
		format.Aloss=8;
slouken@672
   455
		format.colorkey=0;
slouken@672
   456
		format.alpha=0;
slouken@672
   457
slouken@672
   458
		newsurf=SDL_ConvertSurface(MooseFrame[i], &format, SDL_SWSURFACE);
slouken@672
   459
		if(!newsurf)
slouken@672
   460
		{
slouken@672
   461
                    fprintf(stderr, "Couldn't convert picture to 32bits RGB: %s\n", SDL_GetError());
slouken@672
   462
                    return 6;
slouken@672
   463
		}
slouken@672
   464
		SDL_FreeSurface(MooseFrame[i]);
slouken@672
   465
		MooseFrame[i]=newsurf;
slouken@672
   466
	}
slouken@672
   467
    }
slouken@672
   468
slouken@672
   469
    free(RawMooseData);
slouken@672
   470
slouken@672
   471
    overlay=SDL_CreateYUVOverlay(MOOSEPIC_W, MOOSEPIC_H, overlay_format, screen);
slouken@672
   472
slouken@672
   473
    printf("Created %dx%dx%d %s %s overlay\n",overlay->w,overlay->h,overlay->planes,
slouken@672
   474
           overlay->hw_overlay?"hardware":"software",
slouken@672
   475
           overlay->format==SDL_YV12_OVERLAY?"YV12":
slouken@672
   476
           overlay->format==SDL_IYUV_OVERLAY?"IYUV":
slouken@672
   477
           overlay->format==SDL_YUY2_OVERLAY?"YUY2":
slouken@672
   478
           overlay->format==SDL_UYVY_OVERLAY?"UYVY":
slouken@672
   479
           overlay->format==SDL_YVYU_OVERLAY?"YVYU":
slouken@672
   480
           "Unknown");
slouken@672
   481
slouken@672
   482
    for(i=0; i<overlay->planes; i++)
slouken@672
   483
    {
slouken@672
   484
        printf("  plane %d: pitch=%d\n", i, overlay->pitches[i]);
slouken@672
   485
    }
slouken@672
   486
slouken@672
   487
    overlayrect.x=0;
slouken@672
   488
    overlayrect.y=0;
slouken@672
   489
    overlayrect.w=MOOSEPIC_W*scale;
slouken@672
   490
    overlayrect.h=MOOSEPIC_H*scale;
slouken@672
   491
slouken@672
   492
    /* set the start frame */
slouken@672
   493
    i=0;
slouken@672
   494
    fpsdelay=1000/fps;
slouken@672
   495
slouken@672
   496
    /* Ignore key up events, they don't even get filtered */
slouken@672
   497
    SDL_EventState(SDL_KEYUP, SDL_IGNORE);
slouken@672
   498
slouken@672
   499
    lastftick=SDL_GetTicks();
slouken@672
   500
slouken@672
   501
    /* Loop, waiting for QUIT or RESIZE */
slouken@672
   502
    while (1)
slouken@672
   503
    {
slouken@672
   504
        if (SDL_PollEvent(&event))
slouken@672
   505
        {
slouken@672
   506
            switch (event.type)
slouken@672
   507
            {
slouken@672
   508
                case SDL_VIDEORESIZE:
slouken@672
   509
                     screen=SDL_SetVideoMode(event.resize.w, event.resize.h, 0, SDL_RESIZABLE | SDL_SWSURFACE);
slouken@672
   510
                     overlayrect.w=event.resize.w;
slouken@672
   511
                     overlayrect.h=event.resize.h;
slouken@672
   512
                     break;
slouken@672
   513
                case SDL_KEYDOWN:
slouken@672
   514
                     if (event.key.keysym.sym == SDLK_SPACE)
slouken@672
   515
                     {
slouken@672
   516
                         paused=!paused;
slouken@672
   517
                         break;
slouken@672
   518
                     }
slouken@672
   519
                     if (event.key.keysym.sym != SDLK_ESCAPE)
slouken@672
   520
                     {
slouken@672
   521
                         break;
slouken@672
   522
                     }
slouken@672
   523
                case SDL_QUIT:
slouken@672
   524
                     SDL_FreeYUVOverlay(overlay);
slouken@672
   525
                     for (i=0; i<MOOSEFRAMES_COUNT; i++)
slouken@672
   526
                     {
slouken@672
   527
                         SDL_FreeSurface(MooseFrame[i]);
slouken@672
   528
                     }
slouken@672
   529
                     return 0;
slouken@672
   530
            }
slouken@672
   531
        }
slouken@672
   532
slouken@672
   533
        if (!paused)
slouken@672
   534
        {
slouken@672
   535
            if ((SDL_GetTicks()-lastftick)>fpsdelay)
slouken@672
   536
            {
slouken@672
   537
                lastftick=SDL_GetTicks();
slouken@672
   538
slouken@672
   539
                switch (overlay_format)
slouken@672
   540
                {
slouken@672
   541
                    case SDL_YUY2_OVERLAY:
slouken@672
   542
                         ConvertRGBtoYUY2(MooseFrame[i], overlay, 0, 100);
slouken@672
   543
                         break;
slouken@672
   544
                    case SDL_YV12_OVERLAY:
slouken@672
   545
                         ConvertRGBtoYV12(MooseFrame[i], overlay, 0, 100);
slouken@672
   546
                         break;
slouken@672
   547
                    case SDL_UYVY_OVERLAY:
slouken@672
   548
                         ConvertRGBtoUYVY(MooseFrame[i], overlay, 0, 100);
slouken@672
   549
                         break;
slouken@672
   550
                    case SDL_YVYU_OVERLAY:
slouken@672
   551
                         ConvertRGBtoYVYU(MooseFrame[i], overlay, 0, 100);
slouken@672
   552
                         break;
slouken@672
   553
                    case SDL_IYUV_OVERLAY:
slouken@672
   554
                         ConvertRGBtoIYUV(MooseFrame[i], overlay, 0, 100);
slouken@672
   555
                         break;
slouken@672
   556
                }
slouken@672
   557
slouken@672
   558
                SDL_DisplayYUVOverlay(overlay, &overlayrect);
slouken@672
   559
                i++;
slouken@672
   560
                if (i==10)
slouken@672
   561
                {
slouken@672
   562
                    i=0;
slouken@672
   563
                }
slouken@672
   564
            }
slouken@672
   565
        }
slouken@672
   566
        /* kind of timeslice to OS */
slouken@672
   567
        SDL_Delay(1);
slouken@672
   568
    }
slouken@672
   569
slouken@672
   570
    return 0;
slouken@672
   571
}
slouken@672
   572