mirror of
https://github.com/love2d/megasource.git
synced 2026-08-17 19:24:09 +02:00
update SDL3 to libsdl-org/SDL@186c6e5
This commit is contained in:
@@ -148,7 +148,7 @@ macro(add_sdl_test_executable TARGET)
|
||||
set_property(TARGET ${TARGET} PROPERTY SDL_NONINTERACTIVE_TIMEOUT "${AST_NONINTERACTIVE_TIMEOUT}")
|
||||
endif()
|
||||
if(AST_NEEDS_RESOURCES)
|
||||
if(PSP OR PS2)
|
||||
if(PSP OR PS2 OR N3DS)
|
||||
add_custom_command(TARGET ${TARGET} POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} ARGS -E make_directory $<TARGET_FILE_DIR:${TARGET}>/sdl-${TARGET}
|
||||
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${RESOURCE_FILES} $<TARGET_FILE_DIR:${TARGET}>/sdl-${TARGET})
|
||||
@@ -528,12 +528,11 @@ if(PSP)
|
||||
endif()
|
||||
|
||||
if(N3DS)
|
||||
set(ROMFS_DIR "${CMAKE_CURRENT_BINARY_DIR}/romfs")
|
||||
file(COPY ${RESOURCE_FILES} DESTINATION "${ROMFS_DIR}")
|
||||
|
||||
foreach(APP ${SDL_TEST_EXECUTABLES})
|
||||
get_target_property(TARGET_BINARY_DIR ${APP} BINARY_DIR)
|
||||
set(ROMFS_DIR "${TARGET_BINARY_DIR}/sdl-${APP}")
|
||||
set(SMDH_FILE "${TARGET_BINARY_DIR}/${APP}.smdh")
|
||||
file(MAKE_DIRECTORY ${ROMFS_DIR})
|
||||
ctr_generate_smdh("${SMDH_FILE}"
|
||||
NAME "SDL-${APP}"
|
||||
DESCRIPTION "SDL3 Test suite"
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
Source code in this directory, unless otherwise noted, falls under the
|
||||
following license, which is different (more permissive) than SDL's usual
|
||||
license.
|
||||
|
||||
/*
|
||||
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
|
||||
This directory contains sample.wav, which is a sample from Will Provost's
|
||||
song, The Living Proof:
|
||||
|
||||
From the album The Living Proof
|
||||
Publisher: 5 Guys Named Will
|
||||
Copyright 1996 Will Provost
|
||||
|
||||
You can get a copy of the full song (and album!) from iTunes...
|
||||
|
||||
https://itunes.apple.com/us/album/the-living-proof/id4153978
|
||||
|
||||
or Amazon...
|
||||
|
||||
http://www.amazon.com/The-Living-Proof-Will-Provost/dp/B00004R8RH
|
||||
|
||||
Thanks to Will for permitting us to distribute this sample with SDL!
|
||||
|
||||
|
||||
|
||||
The .bmp files used by testaudio.c were made by AlDraw:
|
||||
|
||||
https://linktr.ee/AlexDraw
|
||||
|
||||
These bitmaps may be distributed as public domain files!
|
||||
@@ -1,18 +0,0 @@
|
||||
|
||||
This directory contains sample.wav, which is a sample from Will Provost's
|
||||
song, The Living Proof:
|
||||
|
||||
From the album The Living Proof
|
||||
Publisher: 5 Guys Named Will
|
||||
Copyright 1996 Will Provost
|
||||
|
||||
You can get a copy of the full song (and album!) from iTunes...
|
||||
|
||||
https://itunes.apple.com/us/album/the-living-proof/id4153978
|
||||
|
||||
or Amazon...
|
||||
|
||||
http://www.amazon.com/The-Living-Proof-Will-Provost/dp/B00004R8RH
|
||||
|
||||
Thanks to Will for permitting us to distribute this sample with SDL!
|
||||
|
||||
@@ -13,6 +13,7 @@ int main(int argc, char *argv[]) {
|
||||
bool stdin_to_stdout = false;
|
||||
bool read_stdin = false;
|
||||
bool stdin_to_stderr = false;
|
||||
SDL_IOStream *log_stdin = NULL;
|
||||
int exit_code = 0;
|
||||
|
||||
state = SDLTest_CommonCreateState(argv, 0);
|
||||
@@ -45,6 +46,15 @@ int main(int argc, char *argv[]) {
|
||||
fprintf(stderr, "%s", argv[i + 1]);
|
||||
consumed = 2;
|
||||
}
|
||||
} else if (SDL_strcmp(argv[i], "--log-stdin") == 0) {
|
||||
if (i + 1 < argc) {
|
||||
log_stdin = SDL_IOFromFile(argv[i + 1], "w");
|
||||
if (!log_stdin) {
|
||||
fprintf(stderr, "Couldn't open %s\n", argv[i + 1]);
|
||||
return 2;
|
||||
}
|
||||
consumed = 2;
|
||||
}
|
||||
} else if (SDL_strcmp(argv[i], "--exit-code") == 0) {
|
||||
if (i + 1 < argc) {
|
||||
char *endptr = NULL;
|
||||
@@ -75,6 +85,7 @@ int main(int argc, char *argv[]) {
|
||||
"[--print-arguments]",
|
||||
"[--print-environment]",
|
||||
"[--stdin]",
|
||||
"[--log-stdin FILE]",
|
||||
"[--stdin-to-stdout]",
|
||||
"[--stdout TEXT]",
|
||||
"[--stdin-to-stderr]",
|
||||
@@ -135,6 +146,10 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (log_stdin) {
|
||||
SDL_WriteIO(log_stdin, buffer, result);
|
||||
SDL_FlushIO(log_stdin);
|
||||
}
|
||||
if (stdin_to_stdout) {
|
||||
fwrite(buffer, 1, result, stdout);
|
||||
fflush(stdout);
|
||||
@@ -145,6 +160,10 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
}
|
||||
|
||||
if (log_stdin) {
|
||||
SDL_CloseIO(log_stdin);
|
||||
}
|
||||
|
||||
SDLTest_CommonDestroyState(state);
|
||||
|
||||
return exit_code;
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
The .bmp files used by testaudio.c were made by AlDraw:
|
||||
|
||||
https://linktr.ee/AlexDraw
|
||||
|
||||
They may be distributed as public domain files!
|
||||
|
||||
|
||||
|
||||
@@ -512,7 +512,8 @@ static int SDLCALL mouse_getMouseFocus(void *arg)
|
||||
float x, y;
|
||||
SDL_Window *window;
|
||||
SDL_Window *focusWindow;
|
||||
const bool video_driver_is_wayland = !SDL_strcmp(SDL_GetCurrentVideoDriver(), "wayland");
|
||||
const char *xdg_session = SDL_getenv("XDG_SESSION_TYPE");
|
||||
const bool env_is_wayland = !SDL_strcmp(xdg_session ? xdg_session : "", "wayland");
|
||||
|
||||
/* Get focus - focus non-deterministic */
|
||||
focusWindow = SDL_GetMouseFocus();
|
||||
@@ -523,9 +524,12 @@ static int SDLCALL mouse_getMouseFocus(void *arg)
|
||||
if (!window) {
|
||||
return TEST_ABORTED;
|
||||
}
|
||||
|
||||
/* Delay a brief period to allow the window to actually appear on the desktop. */
|
||||
SDL_Delay(100);
|
||||
|
||||
/* Wayland explicitly disallows warping the mouse pointer, so this test must be skipped. */
|
||||
if (!video_driver_is_wayland) {
|
||||
/* Warping the pointer when it is outside the window on a Wayland desktop usually doesn't work, so this test will be skipped. */
|
||||
if (!env_is_wayland) {
|
||||
/* Mouse to random position inside window */
|
||||
x = (float)SDLTest_RandomIntegerInRange(1, w - 1);
|
||||
y = (float)SDLTest_RandomIntegerInRange(1, h - 1);
|
||||
@@ -549,7 +553,7 @@ static int SDLCALL mouse_getMouseFocus(void *arg)
|
||||
SDL_WarpMouseInWindow(window, x, y);
|
||||
SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%.f,%.f)", x, y);
|
||||
} else {
|
||||
SDLTest_Log("Skipping mouse warp focus tests: Wayland does not support warping the mouse pointer");
|
||||
SDLTest_Log("Skipping mouse warp focus tests: warping the mouse pointer when outside the window is unreliable on Wayland/XWayland");
|
||||
}
|
||||
|
||||
/* Clean up test window */
|
||||
|
||||
@@ -93,6 +93,17 @@ static int SDLCALL rect_testIntersectRectAndLineFloat(void *arg)
|
||||
intersected = SDL_GetRectAndLineIntersectionFloat(&rect, &x1, &y1, &x2, &y2);
|
||||
validateIntersectRectAndLineFloatResults(intersected, true, &rect, x1, y1, x2, y2, 2.5f, 6.0f, 2.75f, 6.0f);
|
||||
|
||||
x1 = 456.0f;
|
||||
y1 = 592.0f;
|
||||
x2 = 160.0f;
|
||||
y2 = 670.0f;
|
||||
rect.x = 300.0f;
|
||||
rect.y = 592.0f;
|
||||
rect.w = 64.0f;
|
||||
rect.h = 64.0f;
|
||||
intersected = SDL_GetRectAndLineIntersectionFloat(&rect, &x1, &y1, &x2, &y2);
|
||||
validateIntersectRectAndLineFloatResults(intersected, true, &rect, x1, y1, x2, y2, 364.0f, 616.243225f, 300.0f, 633.108093f);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
|
||||
@@ -358,7 +358,7 @@ static int SDLCALL stdlib_snprintf(void *arg)
|
||||
"Check result value, expected: %d, got: %d", (int)SDL_strlen(expected), result);
|
||||
|
||||
if (sizeof(void *) >= 8) {
|
||||
result = SDL_snprintf(text, sizeof(text), "%p", (void *)0x1ba07bddf60L);
|
||||
result = SDL_snprintf(text, sizeof(text), "%p", (void *)SDL_SINT64_C(0x1ba07bddf60));
|
||||
expected = "0x1ba07bddf60";
|
||||
expected2 = "000001BA07BDDF60";
|
||||
expected3 = "000001ba07bddf60";
|
||||
@@ -913,9 +913,11 @@ static int SDLCALL stdlib_aligned_alloc(void *arg)
|
||||
}
|
||||
SDLTest_AssertCheck(ptr != NULL, "Check output, expected non-NULL, got: %p", ptr);
|
||||
SDLTest_AssertCheck((((size_t)ptr) % alignment) == 0, "Check output, expected aligned pointer, actual offset: %"SIZE_FORMAT, (((size_t)ptr) % alignment));
|
||||
SDLTest_AssertPass("Filling memory to alignment value");
|
||||
SDL_memset(ptr, 0xAA, alignment);
|
||||
SDL_aligned_free(ptr);
|
||||
if (ptr != NULL) {
|
||||
SDLTest_AssertPass("Filling memory to alignment value");
|
||||
SDL_memset(ptr, 0xAA, alignment);
|
||||
SDL_aligned_free(ptr);
|
||||
}
|
||||
}
|
||||
|
||||
return TEST_COMPLETED;
|
||||
|
||||
@@ -12,7 +12,10 @@
|
||||
This file is created by : Nitin Jain (nitin.j4\samsung.com)
|
||||
*/
|
||||
|
||||
/* Sample program: Draw a Chess Board by using SDL_CreateSoftwareRenderer API */
|
||||
/* Sample program: Draw a Chess Board by using the SDL render API */
|
||||
|
||||
/* This allows testing SDL_CreateSoftwareRenderer with the window surface API. Undefine it to use the accelerated renderer instead. */
|
||||
#define USE_SOFTWARE_RENDERER
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
#include <SDL3/SDL_main.h>
|
||||
@@ -24,9 +27,11 @@
|
||||
|
||||
static SDL_Window *window;
|
||||
static SDL_Renderer *renderer;
|
||||
static SDL_Surface *surface;
|
||||
static int done;
|
||||
|
||||
#ifdef USE_SOFTWARE_RENDERER
|
||||
static SDL_Surface *surface;
|
||||
#endif
|
||||
|
||||
static void DrawChessBoard(void)
|
||||
{
|
||||
@@ -57,7 +62,6 @@ static void DrawChessBoard(void)
|
||||
}
|
||||
}
|
||||
}
|
||||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
|
||||
static void loop(void)
|
||||
@@ -65,6 +69,7 @@ static void loop(void)
|
||||
SDL_Event e;
|
||||
while (SDL_PollEvent(&e)) {
|
||||
|
||||
#ifdef USE_SOFTWARE_RENDERER
|
||||
/* Re-create when window surface has been resized */
|
||||
if (e.type == SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED) {
|
||||
|
||||
@@ -76,6 +81,7 @@ static void loop(void)
|
||||
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
|
||||
SDL_RenderClear(renderer);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (e.type == SDL_EVENT_QUIT) {
|
||||
done = 1;
|
||||
@@ -94,11 +100,19 @@ static void loop(void)
|
||||
}
|
||||
}
|
||||
|
||||
/* Clear the rendering surface with the specified color */
|
||||
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
DrawChessBoard();
|
||||
|
||||
SDL_RenderPresent(renderer);
|
||||
|
||||
#ifdef USE_SOFTWARE_RENDERER
|
||||
/* Got everything on rendering surface,
|
||||
now Update the drawing image on window screen */
|
||||
SDL_UpdateWindowSurface(window);
|
||||
#endif
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
@@ -128,17 +142,17 @@ int main(int argc, char *argv[])
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Window creation fail : %s\n", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
#ifdef USE_SOFTWARE_RENDERER
|
||||
surface = SDL_GetWindowSurface(window);
|
||||
renderer = SDL_CreateSoftwareRenderer(surface);
|
||||
#else
|
||||
renderer = SDL_CreateRenderer(window, NULL);
|
||||
#endif
|
||||
if (!renderer) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Render creation for surface fail : %s\n", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Clear the rendering surface with the specified color */
|
||||
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
/* Draw the Image on rendering surface */
|
||||
done = 0;
|
||||
#ifdef SDL_PLATFORM_EMSCRIPTEN
|
||||
|
||||
@@ -667,6 +667,8 @@ static int process_testMultiprocessStdinToStdout(void *arg)
|
||||
const char *process_args[] = {
|
||||
data->childprocess_path,
|
||||
"--stdin-to-stdout",
|
||||
"--log-stdin",
|
||||
NULL,
|
||||
NULL,
|
||||
};
|
||||
SDL_Process *process1 = NULL;
|
||||
@@ -680,6 +682,7 @@ static int process_testMultiprocessStdinToStdout(void *arg)
|
||||
size_t total_read = 0;
|
||||
bool finished;
|
||||
|
||||
process_args[3] = "child1-stdin.txt";
|
||||
process1 = SDL_CreateProcess(process_args, true);
|
||||
SDLTest_AssertCheck(process1 != NULL, "SDL_CreateProcess()");
|
||||
if (!process1) {
|
||||
@@ -692,6 +695,7 @@ static int process_testMultiprocessStdinToStdout(void *arg)
|
||||
SDL_SetPointerProperty(props, SDL_PROP_PROCESS_CREATE_STDIN_POINTER, SDL_GetPointerProperty(SDL_GetProcessProperties(process1), SDL_PROP_PROCESS_STDOUT_POINTER, NULL));
|
||||
SDL_SetNumberProperty(props, SDL_PROP_PROCESS_CREATE_STDOUT_NUMBER, SDL_PROCESS_STDIO_APP);
|
||||
SDLTest_AssertPass("About to call SDL_CreateProcessWithProperties");
|
||||
process_args[3] = "child2-stdin.txt";
|
||||
process2 = SDL_CreateProcessWithProperties(props);
|
||||
SDL_DestroyProperties(props);
|
||||
SDLTest_AssertCheck(process2 != NULL, "SDL_CreateProcess()");
|
||||
|
||||
@@ -60,7 +60,12 @@ int main(int argc, char *argv[])
|
||||
goto quit;
|
||||
}
|
||||
} else {
|
||||
shape = SDL_LoadBMP_IO(SDL_IOFromConstMem(glass_bmp, sizeof(glass_bmp)), true);
|
||||
SDL_IOStream *stream = SDL_IOFromConstMem(glass_bmp, sizeof(glass_bmp));
|
||||
if (!stream) {
|
||||
SDL_Log("Couldn't create iostream for glass.bmp: %s\n", SDL_GetError());
|
||||
goto quit;
|
||||
}
|
||||
shape = SDL_LoadBMP_IO(stream, true);
|
||||
if (!shape) {
|
||||
SDL_Log("Couldn't load glass.bmp: %s\n", SDL_GetError());
|
||||
goto quit;
|
||||
|
||||
@@ -178,7 +178,7 @@ int main(int argc, char *argv[])
|
||||
/* Wait for the results to be seen */
|
||||
SDL_Delay(1 * 1000);
|
||||
|
||||
/* Check accuracy of precise delay */
|
||||
/* Check accuracy of nanosecond delay */
|
||||
{
|
||||
Uint64 desired_delay = SDL_NS_PER_SECOND / 60;
|
||||
Uint64 actual_delay;
|
||||
@@ -188,7 +188,7 @@ int main(int argc, char *argv[])
|
||||
SDL_DelayNS(1);
|
||||
now = SDL_GetTicksNS();
|
||||
actual_delay = (now - start);
|
||||
SDL_Log("Minimum precise delay: %" SDL_PRIu64 " ns\n", actual_delay);
|
||||
SDL_Log("Minimum nanosecond delay: %" SDL_PRIu64 " ns\n", actual_delay);
|
||||
|
||||
SDL_Log("Timing 100 frames at 60 FPS\n");
|
||||
for (i = 0; i < 100; ++i) {
|
||||
@@ -206,6 +206,34 @@ int main(int argc, char *argv[])
|
||||
/* Wait for the results to be seen */
|
||||
SDL_Delay(1 * 1000);
|
||||
|
||||
/* Check accuracy of precise delay */
|
||||
{
|
||||
Uint64 desired_delay = SDL_NS_PER_SECOND / 60;
|
||||
Uint64 actual_delay;
|
||||
Uint64 total_overslept = 0;
|
||||
|
||||
start = SDL_GetTicksNS();
|
||||
SDL_DelayPrecise(1);
|
||||
now = SDL_GetTicksNS();
|
||||
actual_delay = (now - start);
|
||||
SDL_Log("Minimum precise delay: %" SDL_PRIu64 " ns\n", actual_delay);
|
||||
|
||||
SDL_Log("Timing 100 frames at 60 FPS\n");
|
||||
for (i = 0; i < 100; ++i) {
|
||||
start = SDL_GetTicksNS();
|
||||
SDL_DelayPrecise(desired_delay);
|
||||
now = SDL_GetTicksNS();
|
||||
actual_delay = (now - start);
|
||||
if (actual_delay > desired_delay) {
|
||||
total_overslept += (actual_delay - desired_delay);
|
||||
}
|
||||
}
|
||||
SDL_Log("Overslept %.2f ms\n", (double)total_overslept / SDL_NS_PER_MS);
|
||||
}
|
||||
|
||||
/* Wait for the results to be seen */
|
||||
SDL_Delay(1 * 1000);
|
||||
|
||||
/* Test multiple timers */
|
||||
SDL_Log("Testing multiple timers...\n");
|
||||
t1 = SDL_AddTimer(100, callback, (void *)1);
|
||||
|
||||
+139
-5
@@ -104,7 +104,7 @@ static bool verify_yuv_data(Uint32 format, SDL_Colorspace colorspace, const Uint
|
||||
return result;
|
||||
}
|
||||
|
||||
static int run_automated_tests(int pattern_size, int extra_pitch)
|
||||
static bool run_automated_tests(int pattern_size, int extra_pitch)
|
||||
{
|
||||
const Uint32 formats[] = {
|
||||
SDL_PIXELFORMAT_YV12,
|
||||
@@ -125,7 +125,7 @@ static int run_automated_tests(int pattern_size, int extra_pitch)
|
||||
SDL_Colorspace colorspace;
|
||||
const int tight_tolerance = 20;
|
||||
const int loose_tolerance = 333;
|
||||
int result = -1;
|
||||
bool result = false;
|
||||
|
||||
if (!pattern || !yuv1 || !yuv2) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't allocate test surfaces");
|
||||
@@ -230,7 +230,7 @@ static int run_automated_tests(int pattern_size, int extra_pitch)
|
||||
goto done;
|
||||
}
|
||||
|
||||
result = 0;
|
||||
result = true;
|
||||
|
||||
done:
|
||||
SDL_free(yuv1);
|
||||
@@ -239,6 +239,129 @@ done:
|
||||
return result;
|
||||
}
|
||||
|
||||
static bool run_colorspace_test(void)
|
||||
{
|
||||
bool result = false;
|
||||
SDL_Window *window;
|
||||
SDL_Renderer *renderer;
|
||||
struct {
|
||||
const char *name;
|
||||
SDL_Colorspace colorspace;
|
||||
} colorspaces[] = {
|
||||
#define COLORSPACE(X) { #X, X }
|
||||
COLORSPACE(SDL_COLORSPACE_JPEG),
|
||||
#if 0 /* We don't support converting color primaries here */
|
||||
COLORSPACE(SDL_COLORSPACE_BT601_LIMITED),
|
||||
COLORSPACE(SDL_COLORSPACE_BT601_FULL),
|
||||
#endif
|
||||
COLORSPACE(SDL_COLORSPACE_BT709_LIMITED),
|
||||
COLORSPACE(SDL_COLORSPACE_BT709_FULL)
|
||||
#undef COLORSPACE
|
||||
};
|
||||
SDL_Surface *rgb = NULL;
|
||||
SDL_Surface *yuv = NULL;
|
||||
SDL_Texture *texture = NULL;
|
||||
int allowed_error = 2;
|
||||
int i;
|
||||
|
||||
if (!SDL_CreateWindowAndRenderer("testyuv", 320, 240, 0, &window, &renderer)) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create window and renderer: %s\n", SDL_GetError());
|
||||
goto done;
|
||||
}
|
||||
|
||||
rgb = SDL_CreateSurface(32, 32, SDL_PIXELFORMAT_XRGB8888);
|
||||
if (!rgb) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create RGB surface: %s\n", SDL_GetError());
|
||||
goto done;
|
||||
}
|
||||
SDL_FillSurfaceRect(rgb, NULL, SDL_MapSurfaceRGB(rgb, 255, 0, 0));
|
||||
|
||||
for (i = 0; i < SDL_arraysize(colorspaces); ++i) {
|
||||
bool next = false;
|
||||
Uint8 r, g, b, a;
|
||||
|
||||
SDL_Log("Checking colorspace %s\n", colorspaces[i].name);
|
||||
|
||||
yuv = SDL_ConvertSurfaceAndColorspace(rgb, SDL_PIXELFORMAT_NV12, NULL, colorspaces[i].colorspace, 0);
|
||||
if (!yuv) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create YUV surface: %s\n", SDL_GetError());
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (!SDL_ReadSurfacePixel(yuv, 0, 0, &r, &g, &b, &a)) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't read YUV surface: %s\n", SDL_GetError());
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (SDL_abs((int)r - 255) > allowed_error ||
|
||||
SDL_abs((int)g - 0) > allowed_error ||
|
||||
SDL_abs((int)b - 0) > allowed_error) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed color conversion, expected 255,0,0, got %d,%d,%d\n", r, g, b);
|
||||
}
|
||||
|
||||
texture = SDL_CreateTextureFromSurface(renderer, yuv);
|
||||
if (!texture) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create YUV texture: %s\n", SDL_GetError());
|
||||
goto done;
|
||||
}
|
||||
|
||||
SDL_DestroySurface(yuv);
|
||||
yuv = NULL;
|
||||
|
||||
SDL_RenderTexture(renderer, texture, NULL, NULL);
|
||||
yuv = SDL_RenderReadPixels(renderer, NULL);
|
||||
|
||||
if (!SDL_ReadSurfacePixel(yuv, 0, 0, &r, &g, &b, &a)) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't read YUV surface: %s\n", SDL_GetError());
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (SDL_abs((int)r - 255) > allowed_error ||
|
||||
SDL_abs((int)g - 0) > allowed_error ||
|
||||
SDL_abs((int)b - 0) > allowed_error) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed renderer color conversion, expected 255,0,0, got %d,%d,%d\n", r, g, b);
|
||||
}
|
||||
|
||||
while (!next) {
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
switch (event.type) {
|
||||
case SDL_EVENT_KEY_DOWN:
|
||||
if (event.key.key == SDLK_ESCAPE) {
|
||||
result = true;
|
||||
goto done;
|
||||
}
|
||||
if (event.key.key == SDLK_SPACE) {
|
||||
next = true;
|
||||
}
|
||||
break;
|
||||
case SDL_EVENT_QUIT:
|
||||
result = true;
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
SDL_RenderTexture(renderer, texture, NULL, NULL);
|
||||
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
|
||||
SDL_RenderDebugText(renderer, 4, 4, colorspaces[i].name);
|
||||
SDL_RenderPresent(renderer);
|
||||
SDL_Delay(10);
|
||||
}
|
||||
|
||||
SDL_DestroyTexture(texture);
|
||||
texture = NULL;
|
||||
}
|
||||
|
||||
result = true;
|
||||
|
||||
done:
|
||||
SDL_DestroySurface(rgb);
|
||||
SDL_DestroySurface(yuv);
|
||||
SDL_DestroyTexture(texture);
|
||||
SDL_Quit();
|
||||
return result;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
struct
|
||||
@@ -297,6 +420,7 @@ int main(int argc, char **argv)
|
||||
Uint64 then, now;
|
||||
int i, iterations = 100;
|
||||
bool should_run_automated_tests = false;
|
||||
bool should_run_colorspace_test = false;
|
||||
SDLTest_CommonState *state;
|
||||
|
||||
/* Initialize test framework */
|
||||
@@ -377,6 +501,9 @@ int main(int argc, char **argv)
|
||||
} else if (SDL_strcmp(argv[i], "--automated") == 0) {
|
||||
should_run_automated_tests = true;
|
||||
consumed = 1;
|
||||
} else if (SDL_strcmp(argv[i], "--colorspace-test") == 0) {
|
||||
should_run_colorspace_test = true;
|
||||
consumed = 1;
|
||||
} else if (!filename) {
|
||||
filename = argv[i];
|
||||
consumed = 1;
|
||||
@@ -388,7 +515,7 @@ int main(int argc, char **argv)
|
||||
"[--yv12|--iyuv|--yuy2|--uyvy|--yvyu|--nv12|--nv21]",
|
||||
"[--rgb555|--rgb565|--rgb24|--argb|--abgr|--rgba|--bgra]",
|
||||
"[--monochrome] [--luminance N%]",
|
||||
"[--automated]",
|
||||
"[--automated] [--colorspace-test]",
|
||||
"[sample.bmp]",
|
||||
NULL,
|
||||
};
|
||||
@@ -407,13 +534,20 @@ int main(int argc, char **argv)
|
||||
automated_test_params[i].pattern_size,
|
||||
automated_test_params[i].extra_pitch,
|
||||
automated_test_params[i].enable_intrinsics ? "enabled" : "disabled");
|
||||
if (run_automated_tests(automated_test_params[i].pattern_size, automated_test_params[i].extra_pitch) < 0) {
|
||||
if (!run_automated_tests(automated_test_params[i].pattern_size, automated_test_params[i].extra_pitch)) {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (should_run_colorspace_test) {
|
||||
if (!run_colorspace_test()) {
|
||||
return 2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
filename = GetResourceFilename(filename, "testyuv.bmp");
|
||||
bmp = SDL_LoadBMP(filename);
|
||||
original = SDL_ConvertSurface(bmp, SDL_PIXELFORMAT_RGB24);
|
||||
|
||||
Reference in New Issue
Block a user