2015-06-21 09:33:46 -06:00
|
|
|
/*
|
2024-01-01 14:15:26 -07:00
|
|
|
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
|
2015-06-21 09:33:46 -06:00
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied
|
|
|
|
warranty. In no event will the authors be held liable for any damages
|
|
|
|
arising from the use of this software.
|
|
|
|
|
|
|
|
Permission is granted to anyone to use this software for any purpose,
|
|
|
|
including commercial applications, and to alter it and redistribute it
|
|
|
|
freely.
|
|
|
|
*/
|
|
|
|
/********************************************************************************
|
|
|
|
* *
|
|
|
|
* Test of the overlay used for moved pictures, test more closed to real life. *
|
|
|
|
* Running trojan moose :) Coded by Mike Gorchak. *
|
|
|
|
* *
|
|
|
|
********************************************************************************/
|
|
|
|
|
2022-12-02 13:53:48 -07:00
|
|
|
#include <SDL3/SDL_test.h>
|
|
|
|
#include <SDL3/SDL_test_common.h>
|
2022-12-14 21:58:20 -07:00
|
|
|
#include <SDL3/SDL_main.h>
|
2022-04-12 06:07:18 -06:00
|
|
|
#include "testutils.h"
|
2017-11-12 23:51:12 -07:00
|
|
|
|
2024-01-23 18:40:51 -07:00
|
|
|
#ifdef SDL_PLATFORM_EMSCRIPTEN
|
|
|
|
#include <emscripten/emscripten.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2015-06-21 09:33:46 -06:00
|
|
|
#define MOOSEPIC_W 64
|
|
|
|
#define MOOSEPIC_H 88
|
|
|
|
|
2022-11-30 13:51:59 -07:00
|
|
|
#define MOOSEFRAME_SIZE (MOOSEPIC_W * MOOSEPIC_H)
|
2015-06-21 09:33:46 -06:00
|
|
|
#define MOOSEFRAMES_COUNT 10
|
|
|
|
|
2022-11-30 13:51:59 -07:00
|
|
|
/* *INDENT-OFF* */ /* clang-format off */
|
2023-03-08 03:40:07 -07:00
|
|
|
static SDL_Color MooseColors[84] = {
|
2017-01-14 13:34:45 -07:00
|
|
|
{49, 49, 49, SDL_ALPHA_OPAQUE}
|
|
|
|
, {66, 24, 0, SDL_ALPHA_OPAQUE}
|
|
|
|
, {66, 33, 0, SDL_ALPHA_OPAQUE}
|
|
|
|
, {66, 66, 66, SDL_ALPHA_OPAQUE}
|
|
|
|
,
|
|
|
|
{66, 115, 49, SDL_ALPHA_OPAQUE}
|
|
|
|
, {74, 33, 0, SDL_ALPHA_OPAQUE}
|
|
|
|
, {74, 41, 16, SDL_ALPHA_OPAQUE}
|
|
|
|
, {82, 33, 8, SDL_ALPHA_OPAQUE}
|
|
|
|
,
|
|
|
|
{82, 41, 8, SDL_ALPHA_OPAQUE}
|
|
|
|
, {82, 49, 16, SDL_ALPHA_OPAQUE}
|
|
|
|
, {82, 82, 82, SDL_ALPHA_OPAQUE}
|
|
|
|
, {90, 41, 8, SDL_ALPHA_OPAQUE}
|
|
|
|
,
|
|
|
|
{90, 41, 16, SDL_ALPHA_OPAQUE}
|
|
|
|
, {90, 57, 24, SDL_ALPHA_OPAQUE}
|
|
|
|
, {99, 49, 16, SDL_ALPHA_OPAQUE}
|
|
|
|
, {99, 66, 24, SDL_ALPHA_OPAQUE}
|
|
|
|
,
|
|
|
|
{99, 66, 33, SDL_ALPHA_OPAQUE}
|
|
|
|
, {99, 74, 33, SDL_ALPHA_OPAQUE}
|
|
|
|
, {107, 57, 24, SDL_ALPHA_OPAQUE}
|
|
|
|
, {107, 82, 41, SDL_ALPHA_OPAQUE}
|
|
|
|
,
|
|
|
|
{115, 57, 33, SDL_ALPHA_OPAQUE}
|
|
|
|
, {115, 66, 33, SDL_ALPHA_OPAQUE}
|
|
|
|
, {115, 66, 41, SDL_ALPHA_OPAQUE}
|
|
|
|
, {115, 74, 0, SDL_ALPHA_OPAQUE}
|
|
|
|
,
|
|
|
|
{115, 90, 49, SDL_ALPHA_OPAQUE}
|
|
|
|
, {115, 115, 115, SDL_ALPHA_OPAQUE}
|
|
|
|
, {123, 82, 0, SDL_ALPHA_OPAQUE}
|
|
|
|
, {123, 99, 57, SDL_ALPHA_OPAQUE}
|
|
|
|
,
|
|
|
|
{132, 66, 41, SDL_ALPHA_OPAQUE}
|
|
|
|
, {132, 74, 41, SDL_ALPHA_OPAQUE}
|
|
|
|
, {132, 90, 8, SDL_ALPHA_OPAQUE}
|
|
|
|
, {132, 99, 33, SDL_ALPHA_OPAQUE}
|
|
|
|
,
|
|
|
|
{132, 99, 66, SDL_ALPHA_OPAQUE}
|
|
|
|
, {132, 107, 66, SDL_ALPHA_OPAQUE}
|
|
|
|
, {140, 74, 49, SDL_ALPHA_OPAQUE}
|
|
|
|
, {140, 99, 16, SDL_ALPHA_OPAQUE}
|
|
|
|
,
|
|
|
|
{140, 107, 74, SDL_ALPHA_OPAQUE}
|
|
|
|
, {140, 115, 74, SDL_ALPHA_OPAQUE}
|
|
|
|
, {148, 107, 24, SDL_ALPHA_OPAQUE}
|
|
|
|
, {148, 115, 82, SDL_ALPHA_OPAQUE}
|
|
|
|
,
|
|
|
|
{148, 123, 74, SDL_ALPHA_OPAQUE}
|
|
|
|
, {148, 123, 90, SDL_ALPHA_OPAQUE}
|
|
|
|
, {156, 115, 33, SDL_ALPHA_OPAQUE}
|
|
|
|
, {156, 115, 90, SDL_ALPHA_OPAQUE}
|
|
|
|
,
|
|
|
|
{156, 123, 82, SDL_ALPHA_OPAQUE}
|
|
|
|
, {156, 132, 82, SDL_ALPHA_OPAQUE}
|
|
|
|
, {156, 132, 99, SDL_ALPHA_OPAQUE}
|
|
|
|
, {156, 156, 156, SDL_ALPHA_OPAQUE}
|
|
|
|
,
|
|
|
|
{165, 123, 49, SDL_ALPHA_OPAQUE}
|
|
|
|
, {165, 123, 90, SDL_ALPHA_OPAQUE}
|
|
|
|
, {165, 132, 82, SDL_ALPHA_OPAQUE}
|
|
|
|
, {165, 132, 90, SDL_ALPHA_OPAQUE}
|
|
|
|
,
|
|
|
|
{165, 132, 99, SDL_ALPHA_OPAQUE}
|
|
|
|
, {165, 140, 90, SDL_ALPHA_OPAQUE}
|
|
|
|
, {173, 132, 57, SDL_ALPHA_OPAQUE}
|
|
|
|
, {173, 132, 99, SDL_ALPHA_OPAQUE}
|
|
|
|
,
|
|
|
|
{173, 140, 107, SDL_ALPHA_OPAQUE}
|
|
|
|
, {173, 140, 115, SDL_ALPHA_OPAQUE}
|
|
|
|
, {173, 148, 99, SDL_ALPHA_OPAQUE}
|
|
|
|
, {173, 173, 173, SDL_ALPHA_OPAQUE}
|
|
|
|
,
|
|
|
|
{181, 140, 74, SDL_ALPHA_OPAQUE}
|
|
|
|
, {181, 148, 115, SDL_ALPHA_OPAQUE}
|
|
|
|
, {181, 148, 123, SDL_ALPHA_OPAQUE}
|
|
|
|
, {181, 156, 107, SDL_ALPHA_OPAQUE}
|
|
|
|
,
|
|
|
|
{189, 148, 123, SDL_ALPHA_OPAQUE}
|
|
|
|
, {189, 156, 82, SDL_ALPHA_OPAQUE}
|
|
|
|
, {189, 156, 123, SDL_ALPHA_OPAQUE}
|
|
|
|
, {189, 156, 132, SDL_ALPHA_OPAQUE}
|
|
|
|
,
|
|
|
|
{189, 189, 189, SDL_ALPHA_OPAQUE}
|
|
|
|
, {198, 156, 123, SDL_ALPHA_OPAQUE}
|
|
|
|
, {198, 165, 132, SDL_ALPHA_OPAQUE}
|
|
|
|
, {206, 165, 99, SDL_ALPHA_OPAQUE}
|
|
|
|
,
|
|
|
|
{206, 165, 132, SDL_ALPHA_OPAQUE}
|
|
|
|
, {206, 173, 140, SDL_ALPHA_OPAQUE}
|
|
|
|
, {206, 206, 206, SDL_ALPHA_OPAQUE}
|
|
|
|
, {214, 173, 115, SDL_ALPHA_OPAQUE}
|
|
|
|
,
|
|
|
|
{214, 173, 140, SDL_ALPHA_OPAQUE}
|
|
|
|
, {222, 181, 148, SDL_ALPHA_OPAQUE}
|
|
|
|
, {222, 189, 132, SDL_ALPHA_OPAQUE}
|
|
|
|
, {222, 189, 156, SDL_ALPHA_OPAQUE}
|
|
|
|
,
|
|
|
|
{222, 222, 222, SDL_ALPHA_OPAQUE}
|
|
|
|
, {231, 198, 165, SDL_ALPHA_OPAQUE}
|
|
|
|
, {231, 231, 231, SDL_ALPHA_OPAQUE}
|
|
|
|
, {239, 206, 173, SDL_ALPHA_OPAQUE}
|
2015-06-21 09:33:46 -06:00
|
|
|
};
|
2022-11-30 13:51:59 -07:00
|
|
|
/* *INDENT-ON* */ /* clang-format on */
|
2015-06-21 09:33:46 -06:00
|
|
|
|
2022-12-02 13:53:48 -07:00
|
|
|
static SDLTest_CommonState *state;
|
2022-12-02 14:11:04 -07:00
|
|
|
static Uint64 next_fps_check;
|
|
|
|
static Uint32 frames;
|
2022-12-02 13:53:48 -07:00
|
|
|
static const Uint32 fps_check_delay = 5000;
|
|
|
|
|
2023-10-10 01:04:45 -06:00
|
|
|
static Uint32 yuv_format = SDL_PIXELFORMAT_YV12;
|
2023-03-08 03:40:07 -07:00
|
|
|
static SDL_Surface *MooseYUVSurfaces[MOOSEFRAMES_COUNT];
|
|
|
|
static SDL_Texture *MooseTexture = NULL;
|
|
|
|
static SDL_FRect displayrect;
|
|
|
|
static int window_w;
|
|
|
|
static int window_h;
|
|
|
|
static int paused = 0;
|
|
|
|
static int done = 0;
|
2016-12-30 11:57:50 -07:00
|
|
|
static int fpsdelay;
|
2023-03-08 03:40:07 -07:00
|
|
|
static SDL_bool streaming = SDL_TRUE;
|
|
|
|
static Uint8 *RawMooseData = NULL;
|
2015-06-21 09:33:46 -06:00
|
|
|
|
|
|
|
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
|
|
|
|
static void
|
|
|
|
quit(int rc)
|
|
|
|
{
|
2022-12-02 13:53:48 -07:00
|
|
|
int i;
|
|
|
|
|
|
|
|
/* If rc is 0, just let main return normally rather than calling exit.
|
|
|
|
* This allows testing of platforms where SDL_main is required and does meaningful cleanup.
|
|
|
|
*/
|
2023-01-29 20:06:08 -07:00
|
|
|
|
2022-12-02 13:53:48 -07:00
|
|
|
SDL_free(RawMooseData);
|
|
|
|
|
|
|
|
for (i = 0; i < MOOSEFRAMES_COUNT; i++) {
|
2022-12-27 07:36:39 -07:00
|
|
|
SDL_DestroySurface(MooseYUVSurfaces[i]);
|
2022-12-02 13:53:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
SDLTest_CommonQuit(state);
|
|
|
|
|
2023-04-12 03:07:28 -06:00
|
|
|
/* Let 'main()' return normally */
|
2022-12-02 13:53:48 -07:00
|
|
|
if (rc != 0) {
|
2023-04-12 03:07:28 -06:00
|
|
|
exit(rc);
|
2022-12-02 13:53:48 -07:00
|
|
|
}
|
2015-06-21 09:33:46 -06:00
|
|
|
}
|
|
|
|
|
2023-03-08 03:40:07 -07:00
|
|
|
static void MoveSprites(SDL_Renderer *renderer)
|
2015-06-21 09:33:46 -06:00
|
|
|
{
|
2022-12-02 13:53:48 -07:00
|
|
|
static int i = 0;
|
|
|
|
|
|
|
|
if (streaming) {
|
2023-10-10 01:04:45 -06:00
|
|
|
if (!paused) {
|
|
|
|
i = (i + 1) % MOOSEFRAMES_COUNT;
|
|
|
|
/* Test both upload paths for NV12/NV21 formats */
|
|
|
|
if ((yuv_format == SDL_PIXELFORMAT_NV12 || yuv_format == SDL_PIXELFORMAT_NV21) &&
|
|
|
|
(i % 2) == 0) {
|
|
|
|
#ifdef TEST_RECT_UPDATE
|
|
|
|
SDL_Rect rect;
|
|
|
|
|
|
|
|
if (i == 0) {
|
|
|
|
rect.x = 0;
|
|
|
|
rect.y = 0;
|
|
|
|
rect.w = MOOSEPIC_W;
|
|
|
|
rect.h = MOOSEPIC_H;
|
|
|
|
} else {
|
|
|
|
rect.x = MOOSEPIC_W / 4;
|
|
|
|
rect.y = MOOSEPIC_H / 4;
|
|
|
|
rect.w = MOOSEPIC_W / 2;
|
|
|
|
rect.h = MOOSEPIC_H / 2;
|
|
|
|
}
|
|
|
|
SDL_UpdateNVTexture(MooseTexture, &rect,
|
|
|
|
(Uint8 *)MooseYUVSurfaces[i]->pixels + rect.y * MooseYUVSurfaces[i]->pitch + rect.x, MooseYUVSurfaces[i]->pitch,
|
|
|
|
(Uint8 *)MooseYUVSurfaces[i]->pixels + MOOSEFRAME_SIZE + (rect.y + 1) / 2 * MooseYUVSurfaces[i]->pitch + (rect.x + 1) / 2, MooseYUVSurfaces[i]->pitch);
|
|
|
|
#else
|
|
|
|
SDL_UpdateNVTexture(MooseTexture, NULL,
|
|
|
|
MooseYUVSurfaces[i]->pixels, MooseYUVSurfaces[i]->pitch,
|
|
|
|
(Uint8 *)MooseYUVSurfaces[i]->pixels + MOOSEFRAME_SIZE, MooseYUVSurfaces[i]->pitch);
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
SDL_UpdateTexture(MooseTexture, NULL, MooseYUVSurfaces[i]->pixels, MooseYUVSurfaces[i]->pitch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SDL_RenderClear(renderer);
|
|
|
|
SDL_RenderTexture(renderer, MooseTexture, NULL, &displayrect);
|
|
|
|
SDL_RenderPresent(renderer);
|
2022-12-02 13:53:48 -07:00
|
|
|
} else {
|
2023-10-10 01:04:45 -06:00
|
|
|
SDL_Texture *tmp;
|
|
|
|
|
|
|
|
/* Test SDL_CreateTextureFromSurface */
|
|
|
|
if (!paused) {
|
|
|
|
i = (i + 1) % MOOSEFRAMES_COUNT;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp = SDL_CreateTextureFromSurface(renderer, MooseYUVSurfaces[i]);
|
2023-11-09 14:29:15 -07:00
|
|
|
if (!tmp) {
|
2023-10-10 01:04:45 -06:00
|
|
|
SDL_Log("Error %s", SDL_GetError());
|
|
|
|
quit(7);
|
|
|
|
}
|
|
|
|
|
|
|
|
SDL_RenderClear(renderer);
|
|
|
|
SDL_RenderTexture(renderer, tmp, NULL, &displayrect);
|
|
|
|
SDL_RenderPresent(renderer);
|
|
|
|
SDL_DestroyTexture(tmp);
|
2022-12-02 13:53:48 -07:00
|
|
|
}
|
2015-06-21 09:33:46 -06:00
|
|
|
}
|
|
|
|
|
2022-12-02 13:53:48 -07:00
|
|
|
|
2023-03-08 03:40:07 -07:00
|
|
|
static void loop(void)
|
2015-06-21 09:33:46 -06:00
|
|
|
{
|
2022-12-02 14:11:04 -07:00
|
|
|
Uint64 now;
|
2022-12-02 13:53:48 -07:00
|
|
|
int i;
|
2015-06-21 09:33:46 -06:00
|
|
|
SDL_Event event;
|
2023-01-29 20:06:08 -07:00
|
|
|
|
2022-12-02 13:53:48 -07:00
|
|
|
SDL_Renderer *renderer = state->renderers[0]; /* only 1 window */
|
2015-06-21 09:33:46 -06:00
|
|
|
|
2022-12-02 13:53:48 -07:00
|
|
|
/* Check for events */
|
2015-06-21 09:33:46 -06:00
|
|
|
while (SDL_PollEvent(&event)) {
|
2022-12-02 13:53:48 -07:00
|
|
|
SDLTest_CommonEvent(state, &event, &done);
|
|
|
|
|
2015-06-21 09:33:46 -06:00
|
|
|
switch (event.type) {
|
2023-01-23 18:54:09 -07:00
|
|
|
case SDL_EVENT_WINDOW_RESIZED:
|
2022-12-27 07:21:13 -07:00
|
|
|
SDL_SetRenderViewport(renderer, NULL);
|
2022-12-29 20:31:12 -07:00
|
|
|
window_w = event.window.data1;
|
|
|
|
window_h = event.window.data2;
|
|
|
|
displayrect.w = (float)window_w;
|
|
|
|
displayrect.h = (float)window_h;
|
2015-06-21 09:33:46 -06:00
|
|
|
break;
|
2023-01-29 20:06:08 -07:00
|
|
|
case SDL_EVENT_MOUSE_BUTTON_DOWN:
|
2015-06-21 09:33:46 -06:00
|
|
|
displayrect.x = event.button.x - window_w / 2;
|
|
|
|
displayrect.y = event.button.y - window_h / 2;
|
|
|
|
break;
|
2023-01-23 18:54:09 -07:00
|
|
|
case SDL_EVENT_MOUSE_MOTION:
|
2015-06-21 09:33:46 -06:00
|
|
|
if (event.motion.state) {
|
|
|
|
displayrect.x = event.motion.x - window_w / 2;
|
|
|
|
displayrect.y = event.motion.y - window_h / 2;
|
|
|
|
}
|
|
|
|
break;
|
2023-01-23 18:54:09 -07:00
|
|
|
case SDL_EVENT_KEY_DOWN:
|
2015-06-21 09:33:46 -06:00
|
|
|
if (event.key.keysym.sym == SDLK_SPACE) {
|
|
|
|
paused = !paused;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (event.key.keysym.sym != SDLK_ESCAPE) {
|
|
|
|
break;
|
|
|
|
}
|
2024-03-18 10:56:22 -06:00
|
|
|
break;
|
2024-03-06 12:37:39 -07:00
|
|
|
default:
|
|
|
|
break;
|
2015-06-21 09:33:46 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-23 18:40:51 -07:00
|
|
|
#ifndef SDL_PLATFORM_EMSCRIPTEN
|
2015-06-21 09:33:46 -06:00
|
|
|
SDL_Delay(fpsdelay);
|
|
|
|
#endif
|
|
|
|
|
2022-12-02 13:53:48 -07:00
|
|
|
for (i = 0; i < state->num_windows; ++i) {
|
|
|
|
if (state->windows[i] == NULL) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
MoveSprites(state->renderers[i]);
|
2015-06-21 09:33:46 -06:00
|
|
|
}
|
2024-01-23 18:40:51 -07:00
|
|
|
#ifdef SDL_PLATFORM_EMSCRIPTEN
|
2015-06-21 09:33:46 -06:00
|
|
|
if (done) {
|
|
|
|
emscripten_cancel_main_loop();
|
|
|
|
}
|
|
|
|
#endif
|
2022-12-02 13:53:48 -07:00
|
|
|
|
|
|
|
frames++;
|
|
|
|
now = SDL_GetTicks();
|
2022-12-02 14:11:04 -07:00
|
|
|
if (now >= next_fps_check) {
|
2022-12-02 13:53:48 -07:00
|
|
|
/* Print out some timing information */
|
2022-12-02 14:11:04 -07:00
|
|
|
const Uint64 then = next_fps_check - fps_check_delay;
|
2022-12-02 13:53:48 -07:00
|
|
|
const double fps = ((double)frames * 1000) / (now - then);
|
|
|
|
SDL_Log("%2.2f frames per second\n", fps);
|
|
|
|
next_fps_check = now + fps_check_delay;
|
|
|
|
frames = 0;
|
|
|
|
}
|
2015-06-21 09:33:46 -06:00
|
|
|
}
|
|
|
|
|
2022-12-02 13:53:48 -07:00
|
|
|
|
2022-11-30 13:51:59 -07:00
|
|
|
int main(int argc, char **argv)
|
2015-06-21 09:33:46 -06:00
|
|
|
{
|
2024-03-14 17:32:50 -06:00
|
|
|
SDL_IOStream *handle;
|
2022-12-02 13:53:48 -07:00
|
|
|
int i;
|
2015-06-21 09:33:46 -06:00
|
|
|
int j;
|
|
|
|
int fps = 12;
|
|
|
|
int nodelay = 0;
|
|
|
|
int scale = 5;
|
2022-04-12 06:07:18 -06:00
|
|
|
char *filename = NULL;
|
2015-06-21 09:33:46 -06:00
|
|
|
|
2022-12-02 13:53:48 -07:00
|
|
|
/* Initialize test framework */
|
|
|
|
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
|
2023-11-09 14:29:15 -07:00
|
|
|
if (!state) {
|
2022-12-02 13:53:48 -07:00
|
|
|
return 1;
|
2015-06-21 09:33:46 -06:00
|
|
|
}
|
2023-01-29 20:06:08 -07:00
|
|
|
|
2022-12-02 13:53:48 -07:00
|
|
|
SDL_zeroa(MooseYUVSurfaces);
|
|
|
|
|
|
|
|
for (i = 1; i < argc;) {
|
|
|
|
int consumed;
|
2023-01-29 20:06:08 -07:00
|
|
|
|
2022-12-02 13:53:48 -07:00
|
|
|
consumed = SDLTest_CommonArg(state, i);
|
|
|
|
if (consumed == 0) {
|
|
|
|
consumed = -1;
|
|
|
|
if (SDL_strcmp(argv[i], "--fps") == 0) {
|
|
|
|
if (argv[i + 1]) {
|
|
|
|
consumed = 2;
|
|
|
|
fps = SDL_atoi(argv[i + 1]);
|
|
|
|
if (fps == 0) {
|
|
|
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "The --fps option requires an argument [from 1 to 1000], default is 12.\n");
|
|
|
|
quit(10);
|
|
|
|
}
|
|
|
|
if ((fps < 0) || (fps > 1000)) {
|
|
|
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "The --fps option must be in range from 1 to 1000, default is 12.\n");
|
|
|
|
quit(10);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "The --fps option requires an argument [from 1 to 1000], default is 12.\n");
|
2015-06-21 09:33:46 -06:00
|
|
|
quit(10);
|
|
|
|
}
|
2022-12-02 13:53:48 -07:00
|
|
|
} else if (SDL_strcmp(argv[i], "--nodelay") == 0) {
|
|
|
|
consumed = 1;
|
|
|
|
nodelay = 1;
|
|
|
|
} else if (SDL_strcmp(argv[i], "--nostreaming") == 0) {
|
|
|
|
consumed = 1;
|
|
|
|
streaming = SDL_FALSE;
|
|
|
|
} else if (SDL_strcmp(argv[i], "--scale") == 0) {
|
|
|
|
consumed = 2;
|
|
|
|
if (argv[i + 1]) {
|
|
|
|
scale = SDL_atoi(argv[i + 1]);
|
|
|
|
if (scale == 0) {
|
|
|
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "The --scale option requires an argument [from 1 to 50], default is 5.\n");
|
|
|
|
quit(10);
|
|
|
|
}
|
|
|
|
if ((scale < 0) || (scale > 50)) {
|
|
|
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "The --scale option must be in range from 1 to 50, default is 5.\n");
|
|
|
|
quit(10);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "The --fps option requires an argument [from 1 to 1000], default is 12.\n");
|
2015-06-21 09:33:46 -06:00
|
|
|
quit(10);
|
|
|
|
}
|
2022-12-02 13:53:48 -07:00
|
|
|
} else if (SDL_strcmp(argv[i], "--yuvformat") == 0) {
|
|
|
|
consumed = 2;
|
|
|
|
if (argv[i + 1]) {
|
|
|
|
char *fmt = argv[i + 1];
|
|
|
|
|
|
|
|
if (SDL_strcmp(fmt, "YV12") == 0) {
|
|
|
|
yuv_format = SDL_PIXELFORMAT_YV12;
|
|
|
|
} else if (SDL_strcmp(fmt, "IYUV") == 0) {
|
|
|
|
yuv_format = SDL_PIXELFORMAT_IYUV;
|
|
|
|
} else if (SDL_strcmp(fmt, "YUY2") == 0) {
|
|
|
|
yuv_format = SDL_PIXELFORMAT_YUY2;
|
|
|
|
} else if (SDL_strcmp(fmt, "UYVY") == 0) {
|
|
|
|
yuv_format = SDL_PIXELFORMAT_UYVY;
|
|
|
|
} else if (SDL_strcmp(fmt, "YVYU") == 0) {
|
|
|
|
yuv_format = SDL_PIXELFORMAT_YVYU;
|
|
|
|
} else if (SDL_strcmp(fmt, "NV12") == 0) {
|
|
|
|
yuv_format = SDL_PIXELFORMAT_NV12;
|
|
|
|
} else if (SDL_strcmp(fmt, "NV21") == 0) {
|
|
|
|
yuv_format = SDL_PIXELFORMAT_NV21;
|
|
|
|
} else {
|
|
|
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "The --yuvformat option requires one of the: YV12 (default), IYUV, YUY2, UYVY, YVYU, NV12, NV21)\n");
|
|
|
|
quit(10);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "The --yuvformat option requires one of the: YV12 (default), IYUV, YUY2, UYVY, YVYU, NV12, NV21)\n");
|
2015-06-21 09:33:46 -06:00
|
|
|
quit(10);
|
|
|
|
}
|
|
|
|
}
|
2022-12-02 13:53:48 -07:00
|
|
|
|
|
|
|
}
|
|
|
|
if (consumed < 0) {
|
|
|
|
static const char *options[] = {
|
|
|
|
"[--fps <frames per second>]",
|
|
|
|
"[--nodelay]",
|
2023-01-29 20:06:08 -07:00
|
|
|
"[--yuvformat <fmt>] (one of the: YV12 (default), IYUV, YUY2, UYVY, YVYU, NV12, NV21)",
|
2022-12-02 13:53:48 -07:00
|
|
|
"[--scale <scale factor>] (initial scale of the overlay)",
|
|
|
|
"[--nostreaming] path that use SDL_CreateTextureFromSurface() not STREAMING texture",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
SDLTest_CommonLogUsage(state, argv[0], options);
|
|
|
|
quit(1);
|
2015-06-21 09:33:46 -06:00
|
|
|
}
|
2022-12-02 13:53:48 -07:00
|
|
|
i += consumed;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Force window size */
|
|
|
|
state->window_w = MOOSEPIC_W * scale;
|
|
|
|
state->window_h = MOOSEPIC_H * scale;
|
|
|
|
|
|
|
|
if (!SDLTest_CommonInit(state)) {
|
|
|
|
quit(2);
|
2015-06-21 09:33:46 -06:00
|
|
|
}
|
|
|
|
|
2022-11-30 13:51:59 -07:00
|
|
|
RawMooseData = (Uint8 *)SDL_malloc(MOOSEFRAME_SIZE * MOOSEFRAMES_COUNT);
|
2023-11-09 14:29:15 -07:00
|
|
|
if (!RawMooseData) {
|
2015-06-21 09:33:46 -06:00
|
|
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Can't allocate memory for movie !\n");
|
|
|
|
quit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* load the trojan moose images */
|
2022-04-12 06:07:18 -06:00
|
|
|
filename = GetResourceFilename(NULL, "moose.dat");
|
2023-11-09 14:29:15 -07:00
|
|
|
if (!filename) {
|
2022-04-12 06:07:18 -06:00
|
|
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory\n");
|
2022-12-02 13:53:48 -07:00
|
|
|
quit(2);
|
2022-04-12 06:07:18 -06:00
|
|
|
}
|
2024-03-14 17:32:50 -06:00
|
|
|
handle = SDL_IOFromFile(filename, "rb");
|
2022-04-12 06:07:18 -06:00
|
|
|
SDL_free(filename);
|
2023-11-09 14:29:15 -07:00
|
|
|
if (!handle) {
|
2015-06-21 09:33:46 -06:00
|
|
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Can't find the file moose.dat !\n");
|
|
|
|
quit(2);
|
|
|
|
}
|
|
|
|
|
2024-03-14 17:32:50 -06:00
|
|
|
SDL_ReadIO(handle, RawMooseData, MOOSEFRAME_SIZE * MOOSEFRAMES_COUNT);
|
2015-06-21 09:33:46 -06:00
|
|
|
|
2024-03-14 17:32:50 -06:00
|
|
|
SDL_CloseIO(handle);
|
2015-06-21 09:33:46 -06:00
|
|
|
|
|
|
|
/* Create the window and renderer */
|
|
|
|
window_w = MOOSEPIC_W * scale;
|
|
|
|
window_h = MOOSEPIC_H * scale;
|
|
|
|
|
2022-12-02 13:53:48 -07:00
|
|
|
if (state->num_windows != 1) {
|
|
|
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Only one window allowed\n");
|
|
|
|
quit(1);
|
2015-06-21 09:33:46 -06:00
|
|
|
}
|
|
|
|
|
2022-12-02 13:53:48 -07:00
|
|
|
for (i = 0; i < state->num_windows; ++i) {
|
|
|
|
SDL_Renderer *renderer = state->renderers[i];
|
|
|
|
|
|
|
|
if (streaming) {
|
|
|
|
MooseTexture = SDL_CreateTexture(renderer, yuv_format, SDL_TEXTUREACCESS_STREAMING, MOOSEPIC_W, MOOSEPIC_H);
|
2023-11-09 14:29:15 -07:00
|
|
|
if (!MooseTexture) {
|
2022-12-02 13:53:48 -07:00
|
|
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create texture: %s\n", SDL_GetError());
|
|
|
|
quit(5);
|
|
|
|
}
|
|
|
|
}
|
2015-06-21 09:33:46 -06:00
|
|
|
}
|
2022-12-02 13:53:48 -07:00
|
|
|
|
2015-06-21 09:33:46 -06:00
|
|
|
/* Uncomment this to check vertex color with a YUV texture */
|
|
|
|
/* SDL_SetTextureColorMod(MooseTexture, 0xff, 0x80, 0x80); */
|
|
|
|
|
|
|
|
for (i = 0; i < MOOSEFRAMES_COUNT; i++) {
|
2022-12-02 13:53:48 -07:00
|
|
|
/* Create RGB SDL_Surface */
|
|
|
|
SDL_Surface *mooseRGBSurface = SDL_CreateSurface(MOOSEPIC_W, MOOSEPIC_H, SDL_PIXELFORMAT_RGB24);
|
2023-11-09 14:29:15 -07:00
|
|
|
if (!mooseRGBSurface) {
|
2022-12-02 13:53:48 -07:00
|
|
|
quit(6);
|
2015-06-21 09:33:46 -06:00
|
|
|
}
|
2022-12-02 13:53:48 -07:00
|
|
|
|
|
|
|
/* Load Moose into a RGB SDL_Surface */
|
|
|
|
{
|
|
|
|
Uint8 *rgb = mooseRGBSurface->pixels;
|
|
|
|
Uint8 *frame = RawMooseData + i * MOOSEFRAME_SIZE;
|
|
|
|
for (j = 0; j < MOOSEFRAME_SIZE; ++j) {
|
|
|
|
rgb[0] = MooseColors[frame[j]].r;
|
|
|
|
rgb[1] = MooseColors[frame[j]].g;
|
|
|
|
rgb[2] = MooseColors[frame[j]].b;
|
|
|
|
rgb += 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Convert to YUV SDL_Surface */
|
|
|
|
MooseYUVSurfaces[i] = SDL_ConvertSurfaceFormat(mooseRGBSurface, yuv_format);
|
|
|
|
if (MooseYUVSurfaces[i] == NULL) {
|
|
|
|
quit(7);
|
|
|
|
}
|
|
|
|
|
2022-12-27 07:36:39 -07:00
|
|
|
SDL_DestroySurface(mooseRGBSurface);
|
2015-06-21 09:33:46 -06:00
|
|
|
}
|
|
|
|
|
2019-06-11 00:32:43 -06:00
|
|
|
SDL_free(RawMooseData);
|
2022-12-02 13:53:48 -07:00
|
|
|
RawMooseData = NULL;
|
2015-06-21 09:33:46 -06:00
|
|
|
|
|
|
|
/* set the start frame */
|
|
|
|
i = 0;
|
|
|
|
if (nodelay) {
|
|
|
|
fpsdelay = 0;
|
|
|
|
} else {
|
|
|
|
fpsdelay = 1000 / fps;
|
|
|
|
}
|
|
|
|
|
|
|
|
displayrect.x = 0;
|
|
|
|
displayrect.y = 0;
|
2022-12-29 20:31:12 -07:00
|
|
|
displayrect.w = (float)window_w;
|
|
|
|
displayrect.h = (float)window_h;
|
2015-06-21 09:33:46 -06:00
|
|
|
|
|
|
|
/* Ignore key up events, they don't even get filtered */
|
2023-01-23 18:54:09 -07:00
|
|
|
SDL_SetEventEnabled(SDL_EVENT_KEY_UP, SDL_FALSE);
|
2015-06-21 09:33:46 -06:00
|
|
|
|
2022-12-02 13:53:48 -07:00
|
|
|
/* Main render loop */
|
|
|
|
frames = 0;
|
|
|
|
next_fps_check = SDL_GetTicks() + fps_check_delay;
|
|
|
|
done = 0;
|
|
|
|
|
2015-06-21 09:33:46 -06:00
|
|
|
/* Loop, waiting for QUIT or RESIZE */
|
2024-01-23 18:40:51 -07:00
|
|
|
#ifdef SDL_PLATFORM_EMSCRIPTEN
|
2015-06-21 09:33:46 -06:00
|
|
|
emscripten_set_main_loop(loop, nodelay ? 0 : fps, 1);
|
|
|
|
#else
|
|
|
|
while (!done) {
|
|
|
|
loop();
|
2022-11-30 13:51:59 -07:00
|
|
|
}
|
2015-06-21 09:33:46 -06:00
|
|
|
#endif
|
|
|
|
|
|
|
|
quit(0);
|
|
|
|
return 0;
|
|
|
|
}
|