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