test/testoverlay2.c
author Sam Lantinga <slouken@libsdl.org>
Thu, 06 May 2004 15:55:06 +0000
changeset 886 05c551e5bc64
parent 753 b14fdadd8311
child 1030 6b8f0543337c
permissions -rw-r--r--
Date: Sat, 24 Apr 2004 15:13:32 +0300
From: "Mike Gorchak"
Subject: SDL updates for the QNX6

1. Updated the README.QNX
2. Updated libtool scripts, which are shipped with SDL for QNX6 support.
3. Added some code to support the new QNX 6.3.0, which is in beta now.
4. Added code to detect the hw features, which driver supports.
5. Added hw alpha blits code.
6. Fixed bug when application switches to fullscreen more the 2 times. (afte\
r that window becames always stay on top).
7. Updated a bit README for the tests.
8. Added information about acceleration show in the testalpha.c test.
9. Added small fixes to the testoverlay2.c test.
10. Added alpha and cc+alpha blits benchmarks to the testvidinfo.c test.
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
static void PrintUsage(char *argv0)
slouken@672
   255
{
slouken@672
   256
    fprintf(stderr, "Usage: %s [arg] [arg] [arg] ...\n", argv0);
slouken@886
   257
    fprintf(stderr, "\n");
slouken@886
   258
    fprintf(stderr, "Where 'arg' is any of the following options:\n");
slouken@886
   259
    fprintf(stderr, "\n");
slouken@672
   260
    fprintf(stderr, "	-fps <frames per second>\n");
slouken@672
   261
    fprintf(stderr, "	-format <fmt> (one of the: YV12, IYUV, YUY2, UYVY, YVYU)\n");
slouken@672
   262
    fprintf(stderr, "	-scale <scale factor> (initial scale of the overlay)\n");
slouken@672
   263
    fprintf(stderr, "	-help (shows this help)\n");
slouken@672
   264
    fprintf(stderr, "\n");
slouken@886
   265
    fprintf(stderr, "Press ESC to exit, or SPACE to freeze the movie while application running.\n");
slouken@672
   266
    fprintf(stderr, "\n");
slouken@672
   267
}
slouken@672
   268
slouken@672
   269
int main(int argc, char **argv)
slouken@672
   270
{
slouken@672
   271
    Uint8* RawMooseData;
slouken@672
   272
    SDL_RWops* handle;
slouken@672
   273
    SDL_Surface* screen;
slouken@672
   274
    SDL_Surface* MooseFrame[MOOSEFRAMES_COUNT];
slouken@672
   275
    SDL_Overlay* overlay;
slouken@672
   276
    SDL_Rect overlayrect;
slouken@672
   277
    SDL_Event event;
slouken@672
   278
    Uint32 lastftick;
slouken@672
   279
    int paused=0;
slouken@753
   280
    int resized=0;
slouken@672
   281
    int i;
slouken@672
   282
    int fps=12;
slouken@672
   283
    int fpsdelay;
slouken@672
   284
    int overlay_format=SDL_YUY2_OVERLAY;
slouken@672
   285
    int scale=5;
slouken@672
   286
slouken@672
   287
    while ( argc > 1 )
slouken@672
   288
    {
slouken@672
   289
        if (strcmp(argv[1], "-fps")== 0)
slouken@672
   290
        {
slouken@672
   291
            if (argv[2])
slouken@672
   292
            {
slouken@672
   293
                fps = atoi(argv[2]);
slouken@672
   294
                if (fps==0)
slouken@672
   295
                {
slouken@672
   296
                    fprintf(stderr, "The -fps option requires an argument [from 1 to 1000], default is 12.\n");
slouken@672
   297
                    return -1;
slouken@672
   298
                }
slouken@672
   299
                if ((fps<0) || (fps>1000))
slouken@672
   300
                {
slouken@672
   301
                    fprintf(stderr, "The -fps option must be in range from 1 to 1000, default is 12.\n");
slouken@672
   302
                    return -1;
slouken@672
   303
                }
slouken@672
   304
                argv += 2;
slouken@672
   305
                argc -= 2;
slouken@672
   306
            }
slouken@672
   307
            else
slouken@672
   308
            {
slouken@672
   309
                fprintf(stderr, "The -fps option requires an argument [from 1 to 1000], default is 12.\n");
slouken@672
   310
                return -1;
slouken@672
   311
            }
slouken@672
   312
        } else
slouken@672
   313
        if (strcmp(argv[1], "-format") == 0)
slouken@672
   314
        {
slouken@672
   315
            if (argv[2])
slouken@672
   316
            {
slouken@672
   317
                if (!strcmp(argv[2],"YV12"))
slouken@672
   318
                    overlay_format = SDL_YV12_OVERLAY;
slouken@672
   319
                else if(!strcmp(argv[2],"IYUV"))
slouken@672
   320
                    overlay_format = SDL_IYUV_OVERLAY;
slouken@672
   321
                else if(!strcmp(argv[2],"YUY2"))
slouken@672
   322
                    overlay_format = SDL_YUY2_OVERLAY;
slouken@672
   323
                else if(!strcmp(argv[2],"UYVY"))
slouken@672
   324
                    overlay_format = SDL_UYVY_OVERLAY;
slouken@672
   325
                else if(!strcmp(argv[2],"YVYU"))
slouken@672
   326
                    overlay_format = SDL_YVYU_OVERLAY;
slouken@672
   327
                else
slouken@672
   328
                {
slouken@672
   329
                    fprintf(stderr, "The -format option %s is not recognized, see help for info.\n", argv[2]);
slouken@672
   330
                    return -1;
slouken@672
   331
                }
slouken@672
   332
                argv += 2;
slouken@672
   333
                argc -= 2;
slouken@672
   334
            }
slouken@672
   335
            else
slouken@672
   336
            {
slouken@672
   337
                fprintf(stderr, "The -format option requires an argument, default is YUY2.\n");
slouken@672
   338
                return -1;
slouken@672
   339
            }
slouken@672
   340
        } else
slouken@672
   341
        if (strcmp(argv[1], "-scale") == 0)
slouken@672
   342
        {
slouken@672
   343
            if (argv[2])
slouken@672
   344
            {
slouken@672
   345
                scale = atoi(argv[2]);
slouken@672
   346
                if (scale==0)
slouken@672
   347
                {
slouken@672
   348
                    fprintf(stderr, "The -scale option requires an argument [from 1 to 50], default is 5.\n");
slouken@672
   349
                    return -1;
slouken@672
   350
                }
slouken@672
   351
                if ((scale<0) || (scale>50))
slouken@672
   352
                {
slouken@672
   353
                    fprintf(stderr, "The -scale option must be in range from 1 to 50, default is 5.\n");
slouken@672
   354
                    return -1;
slouken@672
   355
                }
slouken@672
   356
                argv += 2;
slouken@672
   357
                argc -= 2;
slouken@672
   358
            }
slouken@672
   359
            else
slouken@672
   360
            {
slouken@672
   361
                fprintf(stderr, "The -fps option requires an argument [from 1 to 1000], default is 12.\n");
slouken@672
   362
                return -1;
slouken@672
   363
            }
slouken@672
   364
        } else
slouken@672
   365
        if ((strcmp(argv[1], "-help") == 0 ) || (strcmp(argv[1], "-h") == 0))
slouken@672
   366
        {
slouken@672
   367
            PrintUsage(argv[0]);
slouken@672
   368
            return 0;
slouken@672
   369
        } else
slouken@672
   370
        {
slouken@672
   371
            fprintf(stderr, "Unrecognized option: %s.\n", argv[1]);
slouken@672
   372
            return -1;
slouken@672
   373
        }
slouken@672
   374
        break;
slouken@672
   375
    }
slouken@672
   376
   
slouken@672
   377
    RawMooseData=(Uint8*)malloc(MOOSEFRAME_SIZE * MOOSEFRAMES_COUNT);
slouken@672
   378
    if (RawMooseData==NULL)
slouken@672
   379
    {
slouken@672
   380
        fprintf(stderr, "Can't allocate memory for movie !\n");
slouken@672
   381
        free(RawMooseData);
slouken@672
   382
        return 1;
slouken@672
   383
    }
slouken@672
   384
slouken@672
   385
    /* load the trojan moose images */
slouken@673
   386
    handle=SDL_RWFromFile("moose.dat", "rb");
slouken@672
   387
    if (handle==NULL)
slouken@672
   388
    {
slouken@672
   389
        fprintf(stderr, "Can't find the file moose.dat !\n");
slouken@672
   390
        free(RawMooseData);
slouken@672
   391
        return 2;
slouken@672
   392
    }
slouken@672
   393
   
slouken@672
   394
    SDL_RWread(handle, RawMooseData, MOOSEFRAME_SIZE, MOOSEFRAMES_COUNT);
slouken@672
   395
slouken@672
   396
    SDL_RWclose(handle);
slouken@672
   397
slouken@672
   398
    if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) < 0)
slouken@672
   399
    {
slouken@672
   400
        fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
slouken@672
   401
        free(RawMooseData);
slouken@672
   402
        return 3;
slouken@672
   403
    }
slouken@672
   404
    atexit(SDL_Quit);
slouken@672
   405
slouken@673
   406
    /* Set video mode */
slouken@672
   407
    if ( (screen=SDL_SetVideoMode(MOOSEPIC_W*scale, MOOSEPIC_H*scale, 0, SDL_RESIZABLE | SDL_SWSURFACE)) == NULL )
slouken@672
   408
    {
slouken@672
   409
        fprintf(stderr, "Couldn't set video mode: %s\n", 0, SDL_GetError());
slouken@672
   410
        free(RawMooseData);
slouken@672
   411
        return 4;
slouken@672
   412
    }
slouken@672
   413
slouken@672
   414
    /* Set the window manager title bar */
slouken@672
   415
    SDL_WM_SetCaption("SDL test overlay: running moose", "testoverlay2");
slouken@672
   416
slouken@672
   417
    for (i=0; i<MOOSEFRAMES_COUNT; i++)
slouken@672
   418
    {
slouken@672
   419
        MooseFrame[i]=SDL_CreateRGBSurfaceFrom(RawMooseData+i*MOOSEFRAME_SIZE, MOOSEPIC_W,
slouken@672
   420
                                               MOOSEPIC_H, 8, MOOSEPIC_W, 0, 0, 0, 0);
slouken@672
   421
        if (MooseFrame[i]==NULL)
slouken@672
   422
        {
slouken@672
   423
            fprintf(stderr, "Couldn't create SDL_Surfaces:%s\n", 0, SDL_GetError());
slouken@672
   424
            free(RawMooseData);
slouken@672
   425
            return 5;
slouken@672
   426
        }
slouken@672
   427
        SDL_SetColors(MooseFrame[i], MooseColors, 0, 84);
slouken@672
   428
slouken@672
   429
	{
slouken@672
   430
		SDL_Surface *newsurf;
slouken@672
   431
		SDL_PixelFormat format;
slouken@672
   432
slouken@672
   433
		format.palette=NULL;
slouken@672
   434
		format.BitsPerPixel=32;
slouken@672
   435
		format.BytesPerPixel=4;
slouken@672
   436
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
slouken@672
   437
		format.Rshift=0;
slouken@672
   438
		format.Gshift=8;
slouken@672
   439
		format.Bshift=16;
slouken@672
   440
#else
slouken@672
   441
		format.Rshift=24;
slouken@672
   442
		format.Gshift=16;
slouken@672
   443
		format.Bshift=8;
slouken@672
   444
#endif
slouken@672
   445
		format.Ashift=0;
slouken@672
   446
		format.Rmask=0xff<<format.Rshift;
slouken@672
   447
		format.Gmask=0xff<<format.Gshift;
slouken@672
   448
		format.Bmask=0xff<<format.Bshift;
slouken@672
   449
		format.Amask=0;
slouken@672
   450
		format.Rloss=0;
slouken@672
   451
		format.Gloss=0;
slouken@672
   452
		format.Bloss=0;
slouken@672
   453
		format.Aloss=8;
slouken@672
   454
		format.colorkey=0;
slouken@672
   455
		format.alpha=0;
slouken@672
   456
slouken@672
   457
		newsurf=SDL_ConvertSurface(MooseFrame[i], &format, SDL_SWSURFACE);
slouken@672
   458
		if(!newsurf)
slouken@672
   459
		{
slouken@672
   460
                    fprintf(stderr, "Couldn't convert picture to 32bits RGB: %s\n", SDL_GetError());
slouken@672
   461
                    return 6;
slouken@672
   462
		}
slouken@672
   463
		SDL_FreeSurface(MooseFrame[i]);
slouken@672
   464
		MooseFrame[i]=newsurf;
slouken@672
   465
	}
slouken@672
   466
    }
slouken@672
   467
slouken@672
   468
    free(RawMooseData);
slouken@672
   469
slouken@672
   470
    overlay=SDL_CreateYUVOverlay(MOOSEPIC_W, MOOSEPIC_H, overlay_format, screen);
slouken@886
   471
    if (!overlay)
slouken@886
   472
    {
slouken@886
   473
        fprintf(stderr, "Couldn't create overlay: %s\n", SDL_GetError());
slouken@886
   474
        return 7;
slouken@886
   475
    }
slouken@672
   476
slouken@672
   477
    printf("Created %dx%dx%d %s %s overlay\n",overlay->w,overlay->h,overlay->planes,
slouken@672
   478
           overlay->hw_overlay?"hardware":"software",
slouken@672
   479
           overlay->format==SDL_YV12_OVERLAY?"YV12":
slouken@672
   480
           overlay->format==SDL_IYUV_OVERLAY?"IYUV":
slouken@672
   481
           overlay->format==SDL_YUY2_OVERLAY?"YUY2":
slouken@672
   482
           overlay->format==SDL_UYVY_OVERLAY?"UYVY":
slouken@672
   483
           overlay->format==SDL_YVYU_OVERLAY?"YVYU":
slouken@672
   484
           "Unknown");
slouken@672
   485
slouken@672
   486
    for(i=0; i<overlay->planes; i++)
slouken@672
   487
    {
slouken@672
   488
        printf("  plane %d: pitch=%d\n", i, overlay->pitches[i]);
slouken@672
   489
    }
slouken@672
   490
slouken@672
   491
    overlayrect.x=0;
slouken@672
   492
    overlayrect.y=0;
slouken@672
   493
    overlayrect.w=MOOSEPIC_W*scale;
slouken@672
   494
    overlayrect.h=MOOSEPIC_H*scale;
slouken@672
   495
slouken@672
   496
    /* set the start frame */
slouken@672
   497
    i=0;
slouken@672
   498
    fpsdelay=1000/fps;
slouken@672
   499
slouken@672
   500
    /* Ignore key up events, they don't even get filtered */
slouken@672
   501
    SDL_EventState(SDL_KEYUP, SDL_IGNORE);
slouken@672
   502
slouken@672
   503
    lastftick=SDL_GetTicks();
slouken@672
   504
slouken@672
   505
    /* Loop, waiting for QUIT or RESIZE */
slouken@672
   506
    while (1)
slouken@672
   507
    {
slouken@672
   508
        if (SDL_PollEvent(&event))
slouken@672
   509
        {
slouken@672
   510
            switch (event.type)
slouken@672
   511
            {
slouken@672
   512
                case SDL_VIDEORESIZE:
slouken@672
   513
                     screen=SDL_SetVideoMode(event.resize.w, event.resize.h, 0, SDL_RESIZABLE | SDL_SWSURFACE);
slouken@672
   514
                     overlayrect.w=event.resize.w;
slouken@672
   515
                     overlayrect.h=event.resize.h;
slouken@753
   516
                     if (paused)
slouken@753
   517
                     {
slouken@753
   518
                         resized=1;
slouken@753
   519
                     }
slouken@672
   520
                     break;
slouken@672
   521
                case SDL_KEYDOWN:
slouken@672
   522
                     if (event.key.keysym.sym == SDLK_SPACE)
slouken@672
   523
                     {
slouken@672
   524
                         paused=!paused;
slouken@672
   525
                         break;
slouken@672
   526
                     }
slouken@672
   527
                     if (event.key.keysym.sym != SDLK_ESCAPE)
slouken@672
   528
                     {
slouken@672
   529
                         break;
slouken@672
   530
                     }
slouken@672
   531
                case SDL_QUIT:
slouken@672
   532
                     SDL_FreeYUVOverlay(overlay);
slouken@672
   533
                     for (i=0; i<MOOSEFRAMES_COUNT; i++)
slouken@672
   534
                     {
slouken@672
   535
                         SDL_FreeSurface(MooseFrame[i]);
slouken@672
   536
                     }
slouken@672
   537
                     return 0;
slouken@672
   538
            }
slouken@672
   539
        }
slouken@672
   540
slouken@753
   541
        if ((!paused)||(resized))
slouken@672
   542
        {
slouken@753
   543
            if (((SDL_GetTicks()-lastftick)>fpsdelay)||(resized))
slouken@672
   544
            {
slouken@672
   545
                lastftick=SDL_GetTicks();
slouken@672
   546
slouken@672
   547
                switch (overlay_format)
slouken@672
   548
                {
slouken@672
   549
                    case SDL_YUY2_OVERLAY:
slouken@672
   550
                         ConvertRGBtoYUY2(MooseFrame[i], overlay, 0, 100);
slouken@672
   551
                         break;
slouken@672
   552
                    case SDL_YV12_OVERLAY:
slouken@672
   553
                         ConvertRGBtoYV12(MooseFrame[i], overlay, 0, 100);
slouken@672
   554
                         break;
slouken@672
   555
                    case SDL_UYVY_OVERLAY:
slouken@672
   556
                         ConvertRGBtoUYVY(MooseFrame[i], overlay, 0, 100);
slouken@672
   557
                         break;
slouken@672
   558
                    case SDL_YVYU_OVERLAY:
slouken@672
   559
                         ConvertRGBtoYVYU(MooseFrame[i], overlay, 0, 100);
slouken@672
   560
                         break;
slouken@672
   561
                    case SDL_IYUV_OVERLAY:
slouken@672
   562
                         ConvertRGBtoIYUV(MooseFrame[i], overlay, 0, 100);
slouken@672
   563
                         break;
slouken@672
   564
                }
slouken@672
   565
slouken@672
   566
                SDL_DisplayYUVOverlay(overlay, &overlayrect);
slouken@753
   567
                if (!resized)
slouken@672
   568
                {
slouken@753
   569
                    i++;
slouken@753
   570
                    if (i==10)
slouken@753
   571
                    {
slouken@753
   572
                        i=0;
slouken@753
   573
                    }
slouken@753
   574
                }
slouken@753
   575
                else
slouken@753
   576
                {
slouken@753
   577
                    resized=0;
slouken@672
   578
                }
slouken@672
   579
            }
slouken@672
   580
        }
slouken@672
   581
        /* kind of timeslice to OS */
slouken@672
   582
        SDL_Delay(1);
slouken@672
   583
    }
slouken@672
   584
slouken@672
   585
    return 0;
slouken@672
   586
}
slouken@672
   587