test/testoverlay2.c
changeset 12828 27d544cc7236
parent 12503 806492103856
equal deleted inserted replaced
12827:9600f26ce4be 12828:27d544cc7236
   250         SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
   250         SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
   251         return 3;
   251         return 3;
   252     }
   252     }
   253 
   253 
   254     while (argc > 1) {
   254     while (argc > 1) {
   255         if (strcmp(argv[1], "-fps") == 0) {
   255         if (SDL_strcmp(argv[1], "-fps") == 0) {
   256             if (argv[2]) {
   256             if (argv[2]) {
   257                 fps = SDL_atoi(argv[2]);
   257                 fps = SDL_atoi(argv[2]);
   258                 if (fps == 0) {
   258                 if (fps == 0) {
   259                     SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
   259                     SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
   260                             "The -fps option requires an argument [from 1 to 1000], default is 12.\n");
   260                             "The -fps option requires an argument [from 1 to 1000], default is 12.\n");
   270             } else {
   270             } else {
   271                 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
   271                 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
   272                         "The -fps option requires an argument [from 1 to 1000], default is 12.\n");
   272                         "The -fps option requires an argument [from 1 to 1000], default is 12.\n");
   273                 quit(10);
   273                 quit(10);
   274             }
   274             }
   275         } else if (strcmp(argv[1], "-nodelay") == 0) {
   275         } else if (SDL_strcmp(argv[1], "-nodelay") == 0) {
   276             nodelay = 1;
   276             nodelay = 1;
   277             argv += 1;
   277             argv += 1;
   278             argc -= 1;
   278             argc -= 1;
   279         } else if (strcmp(argv[1], "-scale") == 0) {
   279         } else if (SDL_strcmp(argv[1], "-scale") == 0) {
   280             if (argv[2]) {
   280             if (argv[2]) {
   281                 scale = SDL_atoi(argv[2]);
   281                 scale = SDL_atoi(argv[2]);
   282                 if (scale == 0) {
   282                 if (scale == 0) {
   283                     SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
   283                     SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
   284                             "The -scale option requires an argument [from 1 to 50], default is 5.\n");
   284                             "The -scale option requires an argument [from 1 to 50], default is 5.\n");
   294             } else {
   294             } else {
   295                 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
   295                 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
   296                         "The -fps option requires an argument [from 1 to 1000], default is 12.\n");
   296                         "The -fps option requires an argument [from 1 to 1000], default is 12.\n");
   297                 quit(10);
   297                 quit(10);
   298             }
   298             }
   299         } else if ((strcmp(argv[1], "-help") == 0)
   299         } else if ((SDL_strcmp(argv[1], "-help") == 0)
   300                    || (strcmp(argv[1], "-h") == 0)) {
   300                    || (SDL_strcmp(argv[1], "-h") == 0)) {
   301             PrintUsage(argv[0]);
   301             PrintUsage(argv[0]);
   302             quit(0);
   302             quit(0);
   303         } else {
   303         } else {
   304             SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unrecognized option: %s.\n", argv[1]);
   304             SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unrecognized option: %s.\n", argv[1]);
   305             quit(10);
   305             quit(10);
   306         }
   306         }
   307         break;
   307         break;
   308     }
   308     }
   309 
   309 
   310     RawMooseData = (Uint8 *) malloc(MOOSEFRAME_SIZE * MOOSEFRAMES_COUNT);
   310     RawMooseData = (Uint8 *) SDL_malloc(MOOSEFRAME_SIZE * MOOSEFRAMES_COUNT);
   311     if (RawMooseData == NULL) {
   311     if (RawMooseData == NULL) {
   312         SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Can't allocate memory for movie !\n");
   312         SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Can't allocate memory for movie !\n");
   313         quit(1);
   313         quit(1);
   314     }
   314     }
   315 
   315 
   316     /* load the trojan moose images */
   316     /* load the trojan moose images */
   317     handle = SDL_RWFromFile("moose.dat", "rb");
   317     handle = SDL_RWFromFile("moose.dat", "rb");
   318     if (handle == NULL) {
   318     if (handle == NULL) {
   319         SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Can't find the file moose.dat !\n");
   319         SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Can't find the file moose.dat !\n");
   320         free(RawMooseData);
   320         SDL_free(RawMooseData);
   321         quit(2);
   321         quit(2);
   322     }
   322     }
   323 
   323 
   324     SDL_RWread(handle, RawMooseData, MOOSEFRAME_SIZE, MOOSEFRAMES_COUNT);
   324     SDL_RWread(handle, RawMooseData, MOOSEFRAME_SIZE, MOOSEFRAMES_COUNT);
   325 
   325 
   333                               SDL_WINDOWPOS_UNDEFINED,
   333                               SDL_WINDOWPOS_UNDEFINED,
   334                               window_w, window_h,
   334                               window_w, window_h,
   335                               SDL_WINDOW_RESIZABLE);
   335                               SDL_WINDOW_RESIZABLE);
   336     if (!window) {
   336     if (!window) {
   337         SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create window: %s\n", SDL_GetError());
   337         SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create window: %s\n", SDL_GetError());
   338         free(RawMooseData);
   338         SDL_free(RawMooseData);
   339         quit(4);
   339         quit(4);
   340     }
   340     }
   341 
   341 
   342     renderer = SDL_CreateRenderer(window, -1, 0);
   342     renderer = SDL_CreateRenderer(window, -1, 0);
   343     if (!renderer) {
   343     if (!renderer) {
   344         SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create renderer: %s\n", SDL_GetError());
   344         SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create renderer: %s\n", SDL_GetError());
   345         free(RawMooseData);
   345         SDL_free(RawMooseData);
   346         quit(4);
   346         quit(4);
   347     }
   347     }
   348 
   348 
   349     MooseTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_YV12, SDL_TEXTUREACCESS_STREAMING, MOOSEPIC_W, MOOSEPIC_H);
   349     MooseTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_YV12, SDL_TEXTUREACCESS_STREAMING, MOOSEPIC_W, MOOSEPIC_H);
   350     if (!MooseTexture) {
   350     if (!MooseTexture) {
   351         SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create texture: %s\n", SDL_GetError());
   351         SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create texture: %s\n", SDL_GetError());
   352         free(RawMooseData);
   352         SDL_free(RawMooseData);
   353         quit(5);
   353         quit(5);
   354     }
   354     }
   355     /* Uncomment this to check vertex color with a YUV texture */
   355     /* Uncomment this to check vertex color with a YUV texture */
   356     /* SDL_SetTextureColorMod(MooseTexture, 0xff, 0x80, 0x80); */
   356     /* SDL_SetTextureColorMod(MooseTexture, 0xff, 0x80, 0x80); */
   357 
   357 
   371         ConvertRGBtoYUV(SDL_PIXELFORMAT_YV12, MooseFrameRGB, MOOSEPIC_W*3, MooseFrame[i], MOOSEPIC_W, MOOSEPIC_H,
   371         ConvertRGBtoYUV(SDL_PIXELFORMAT_YV12, MooseFrameRGB, MOOSEPIC_W*3, MooseFrame[i], MOOSEPIC_W, MOOSEPIC_H,
   372             SDL_GetYUVConversionModeForResolution(MOOSEPIC_W, MOOSEPIC_H),
   372             SDL_GetYUVConversionModeForResolution(MOOSEPIC_W, MOOSEPIC_H),
   373             0, 100);
   373             0, 100);
   374     }
   374     }
   375 
   375 
   376     free(RawMooseData);
   376     SDL_free(RawMooseData);
   377 
   377 
   378     /* set the start frame */
   378     /* set the start frame */
   379     i = 0;
   379     i = 0;
   380     if (nodelay) {
   380     if (nodelay) {
   381         fpsdelay = 0;
   381         fpsdelay = 0;