update SDL3 to latest commit

This commit is contained in:
Sasha Szpakowski
2024-10-06 20:30:44 -03:00
parent 1b0fdc338b
commit 9e5eb1b018
1426 changed files with 242456 additions and 103496 deletions
+45 -47
View File
@@ -19,7 +19,7 @@
#define MAX_YUV_SURFACE_SIZE(W, H, P) ((H + 1) * ((W + 1) + P) * 4)
/* Return true if the YUV format is packed pixels */
static SDL_bool is_packed_yuv_format(Uint32 format)
static bool is_packed_yuv_format(Uint32 format)
{
return format == SDL_PIXELFORMAT_YUY2 || format == SDL_PIXELFORMAT_UYVY || format == SDL_PIXELFORMAT_YVYU;
}
@@ -65,21 +65,21 @@ static SDL_Surface *generate_test_pattern(int pattern_size)
return pattern;
}
static SDL_bool verify_yuv_data(Uint32 format, SDL_Colorspace colorspace, const Uint8 *yuv, int yuv_pitch, SDL_Surface *surface, int tolerance)
static bool verify_yuv_data(Uint32 format, SDL_Colorspace colorspace, const Uint8 *yuv, int yuv_pitch, SDL_Surface *surface, int tolerance)
{
const int size = (surface->h * surface->pitch);
Uint8 *rgb;
SDL_bool result = SDL_FALSE;
bool result = false;
rgb = (Uint8 *)SDL_malloc(size);
if (!rgb) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory");
return SDL_FALSE;
return false;
}
if (SDL_ConvertPixelsAndColorspace(surface->w, surface->h, format, colorspace, 0, yuv, yuv_pitch, surface->format->format, SDL_COLORSPACE_SRGB, 0, rgb, surface->pitch) == 0) {
if (SDL_ConvertPixelsAndColorspace(surface->w, surface->h, format, colorspace, 0, yuv, yuv_pitch, surface->format, SDL_COLORSPACE_SRGB, 0, rgb, surface->pitch)) {
int x, y;
result = SDL_TRUE;
result = true;
for (y = 0; y < surface->h; ++y) {
const Uint8 *actual = rgb + y * surface->pitch;
const Uint8 *expected = (const Uint8 *)surface->pixels + y * surface->pitch;
@@ -90,14 +90,14 @@ static SDL_bool verify_yuv_data(Uint32 format, SDL_Colorspace colorspace, const
int distance = (deltaR * deltaR + deltaG * deltaG + deltaB * deltaB);
if (distance > tolerance) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Pixel at %d,%d was 0x%.2x,0x%.2x,0x%.2x, expected 0x%.2x,0x%.2x,0x%.2x, distance = %d\n", x, y, actual[0], actual[1], actual[2], expected[0], expected[1], expected[2], distance);
result = SDL_FALSE;
result = false;
}
actual += 3;
expected += 3;
}
}
} else {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't convert %s to %s: %s\n", SDL_GetPixelFormatName(format), SDL_GetPixelFormatName(surface->format->format), SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't convert %s to %s: %s\n", SDL_GetPixelFormatName(format), SDL_GetPixelFormatName(surface->format), SDL_GetError());
}
SDL_free(rgb);
@@ -151,8 +151,8 @@ static int run_automated_tests(int pattern_size, int extra_pitch)
/* Verify conversion to YUV formats */
for (i = 0; i < SDL_arraysize(formats); ++i) {
yuv1_pitch = CalculateYUVPitch(formats[i], pattern->w) + extra_pitch;
if (SDL_ConvertPixelsAndColorspace(pattern->w, pattern->h, pattern->format->format, SDL_COLORSPACE_SRGB, 0, pattern->pixels, pattern->pitch, formats[i], colorspace, 0, yuv1, yuv1_pitch) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't convert %s to %s: %s\n", SDL_GetPixelFormatName(pattern->format->format), SDL_GetPixelFormatName(formats[i]), SDL_GetError());
if (!SDL_ConvertPixelsAndColorspace(pattern->w, pattern->h, pattern->format, SDL_COLORSPACE_SRGB, 0, pattern->pixels, pattern->pitch, formats[i], colorspace, 0, yuv1, yuv1_pitch)) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't convert %s to %s: %s\n", SDL_GetPixelFormatName(pattern->format), SDL_GetPixelFormatName(formats[i]), SDL_GetError());
goto done;
}
if (!verify_yuv_data(formats[i], colorspace, yuv1, yuv1_pitch, pattern, tight_tolerance)) {
@@ -166,11 +166,11 @@ static int run_automated_tests(int pattern_size, int extra_pitch)
for (j = 0; j < SDL_arraysize(formats); ++j) {
yuv1_pitch = CalculateYUVPitch(formats[i], pattern->w) + extra_pitch;
yuv2_pitch = CalculateYUVPitch(formats[j], pattern->w) + extra_pitch;
if (SDL_ConvertPixelsAndColorspace(pattern->w, pattern->h, pattern->format->format, SDL_COLORSPACE_SRGB, 0, pattern->pixels, pattern->pitch, formats[i], colorspace, 0, yuv1, yuv1_pitch) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't convert %s to %s: %s\n", SDL_GetPixelFormatName(pattern->format->format), SDL_GetPixelFormatName(formats[i]), SDL_GetError());
if (!SDL_ConvertPixelsAndColorspace(pattern->w, pattern->h, pattern->format, SDL_COLORSPACE_SRGB, 0, pattern->pixels, pattern->pitch, formats[i], colorspace, 0, yuv1, yuv1_pitch)) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't convert %s to %s: %s\n", SDL_GetPixelFormatName(pattern->format), SDL_GetPixelFormatName(formats[i]), SDL_GetError());
goto done;
}
if (SDL_ConvertPixelsAndColorspace(pattern->w, pattern->h, formats[i], colorspace, 0, yuv1, yuv1_pitch, formats[j], colorspace, 0, yuv2, yuv2_pitch) < 0) {
if (!SDL_ConvertPixelsAndColorspace(pattern->w, pattern->h, formats[i], colorspace, 0, yuv1, yuv1_pitch, formats[j], colorspace, 0, yuv2, yuv2_pitch)) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't convert %s to %s: %s\n", SDL_GetPixelFormatName(formats[i]), SDL_GetPixelFormatName(formats[j]), SDL_GetError());
goto done;
}
@@ -191,11 +191,11 @@ static int run_automated_tests(int pattern_size, int extra_pitch)
yuv1_pitch = CalculateYUVPitch(formats[i], pattern->w) + extra_pitch;
yuv2_pitch = CalculateYUVPitch(formats[j], pattern->w) + extra_pitch;
if (SDL_ConvertPixelsAndColorspace(pattern->w, pattern->h, pattern->format->format, SDL_COLORSPACE_SRGB, 0, pattern->pixels, pattern->pitch, formats[i], colorspace, 0, yuv1, yuv1_pitch) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't convert %s to %s: %s\n", SDL_GetPixelFormatName(pattern->format->format), SDL_GetPixelFormatName(formats[i]), SDL_GetError());
if (!SDL_ConvertPixelsAndColorspace(pattern->w, pattern->h, pattern->format, SDL_COLORSPACE_SRGB, 0, pattern->pixels, pattern->pitch, formats[i], colorspace, 0, yuv1, yuv1_pitch)) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't convert %s to %s: %s\n", SDL_GetPixelFormatName(pattern->format), SDL_GetPixelFormatName(formats[i]), SDL_GetError());
goto done;
}
if (SDL_ConvertPixelsAndColorspace(pattern->w, pattern->h, formats[i], colorspace, 0, yuv1, yuv1_pitch, formats[j], colorspace, 0, yuv1, yuv2_pitch) < 0) {
if (!SDL_ConvertPixelsAndColorspace(pattern->w, pattern->h, formats[i], colorspace, 0, yuv1, yuv1_pitch, formats[j], colorspace, 0, yuv1, yuv2_pitch)) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't convert %s to %s: %s\n", SDL_GetPixelFormatName(formats[i]), SDL_GetPixelFormatName(formats[j]), SDL_GetError());
goto done;
}
@@ -220,8 +220,8 @@ static int run_automated_tests(int pattern_size, int extra_pitch)
/* The pitch needs to be Uint16 aligned for P010 pixels */
yuv1_pitch = CalculateYUVPitch(SDL_PIXELFORMAT_P010, pattern->w) + ((extra_pitch + 1) & ~1);
if (SDL_ConvertPixelsAndColorspace(pattern->w, pattern->h, pattern->format->format, SDL_COLORSPACE_SRGB, 0, pattern->pixels, pattern->pitch, SDL_PIXELFORMAT_P010, colorspace, 0, yuv1, yuv1_pitch) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't convert %s to %s: %s\n", SDL_GetPixelFormatName(pattern->format->format), SDL_GetPixelFormatName(SDL_PIXELFORMAT_P010), SDL_GetError());
if (!SDL_ConvertPixelsAndColorspace(pattern->w, pattern->h, pattern->format, SDL_COLORSPACE_SRGB, 0, pattern->pixels, pattern->pitch, SDL_PIXELFORMAT_P010, colorspace, 0, yuv1, yuv1_pitch)) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't convert %s to %s: %s\n", SDL_GetPixelFormatName(pattern->format), SDL_GetPixelFormatName(SDL_PIXELFORMAT_P010), SDL_GetError());
goto done;
}
/* Going through XRGB2101010 format during P010 conversion is slightly lossy, so use looser tolerance here */
@@ -243,34 +243,34 @@ int main(int argc, char **argv)
{
struct
{
SDL_bool enable_intrinsics;
bool enable_intrinsics;
int pattern_size;
int extra_pitch;
} automated_test_params[] = {
/* Test: single pixel */
{ SDL_FALSE, 1, 0 },
{ false, 1, 0 },
/* Test: even width and height */
{ SDL_FALSE, 2, 0 },
{ SDL_FALSE, 4, 0 },
{ false, 2, 0 },
{ false, 4, 0 },
/* Test: odd width and height */
{ SDL_FALSE, 1, 0 },
{ SDL_FALSE, 3, 0 },
{ false, 1, 0 },
{ false, 3, 0 },
/* Test: even width and height, extra pitch */
{ SDL_FALSE, 2, 3 },
{ SDL_FALSE, 4, 3 },
{ false, 2, 3 },
{ false, 4, 3 },
/* Test: odd width and height, extra pitch */
{ SDL_FALSE, 1, 3 },
{ SDL_FALSE, 3, 3 },
{ false, 1, 3 },
{ false, 3, 3 },
/* Test: even width and height with intrinsics */
{ SDL_TRUE, 32, 0 },
{ true, 32, 0 },
/* Test: odd width and height with intrinsics */
{ SDL_TRUE, 33, 0 },
{ SDL_TRUE, 37, 0 },
{ true, 33, 0 },
{ true, 37, 0 },
/* Test: even width and height with intrinsics, extra pitch */
{ SDL_TRUE, 32, 3 },
{ true, 32, 3 },
/* Test: odd width and height with intrinsics, extra pitch */
{ SDL_TRUE, 33, 3 },
{ SDL_TRUE, 37, 3 },
{ true, 33, 3 },
{ true, 37, 3 },
};
char *filename = NULL;
SDL_Surface *original;
@@ -289,14 +289,14 @@ int main(int argc, char **argv)
Uint32 rgb_format = SDL_PIXELFORMAT_RGBX8888;
SDL_Colorspace rgb_colorspace = SDL_COLORSPACE_SRGB;
SDL_PropertiesID props;
SDL_bool monochrome = SDL_FALSE;
bool monochrome = false;
int luminance = 100;
int current = 0;
int pitch;
Uint8 *raw_yuv;
Uint64 then, now;
int i, iterations = 100;
SDL_bool should_run_automated_tests = SDL_FALSE;
bool should_run_automated_tests = false;
SDLTest_CommonState *state;
/* Initialize test framework */
@@ -305,9 +305,6 @@ int main(int argc, char **argv)
return 1;
}
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Parse commandline */
for (i = 1; i < argc;) {
int consumed;
@@ -351,7 +348,7 @@ int main(int argc, char **argv)
yuv_format = SDL_PIXELFORMAT_NV21;
consumed = 1;
} else if (SDL_strcmp(argv[i], "--rgb555") == 0) {
rgb_format = SDL_PIXELFORMAT_RGB555;
rgb_format = SDL_PIXELFORMAT_XRGB1555;
consumed = 1;
} else if (SDL_strcmp(argv[i], "--rgb565") == 0) {
rgb_format = SDL_PIXELFORMAT_RGB565;
@@ -372,13 +369,13 @@ int main(int argc, char **argv)
rgb_format = SDL_PIXELFORMAT_BGRA8888;
consumed = 1;
} else if (SDL_strcmp(argv[i], "--monochrome") == 0) {
monochrome = SDL_TRUE;
monochrome = true;
consumed = 1;
} else if (SDL_strcmp(argv[i], "--luminance") == 0 && argv[i+1]) {
luminance = SDL_atoi(argv[i+1]);
consumed = 2;
} else if (SDL_strcmp(argv[i], "--automated") == 0) {
should_run_automated_tests = SDL_TRUE;
should_run_automated_tests = true;
consumed = 1;
} else if (!filename) {
filename = argv[i];
@@ -396,6 +393,7 @@ int main(int argc, char **argv)
NULL,
};
SDLTest_CommonLogUsage(state, argv[0], options);
SDL_Quit();
SDLTest_CommonDestroyState(state);
return 1;
}
@@ -418,7 +416,7 @@ int main(int argc, char **argv)
filename = GetResourceFilename(filename, "testyuv.bmp");
bmp = SDL_LoadBMP(filename);
original = SDL_ConvertSurfaceFormat(bmp, SDL_PIXELFORMAT_RGB24);
original = SDL_ConvertSurface(bmp, SDL_PIXELFORMAT_RGB24);
SDL_DestroySurface(bmp);
if (!original) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s\n", filename, SDL_GetError());
@@ -471,7 +469,7 @@ int main(int argc, char **argv)
return 4;
}
renderer = SDL_CreateRenderer(window, NULL, 0);
renderer = SDL_CreateRenderer(window, NULL);
if (!renderer) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create renderer: %s\n", SDL_GetError());
return 4;
@@ -507,11 +505,11 @@ int main(int argc, char **argv)
done = 1;
}
if (event.type == SDL_EVENT_KEY_DOWN) {
if (event.key.keysym.sym == SDLK_ESCAPE) {
if (event.key.key == SDLK_ESCAPE) {
done = 1;
} else if (event.key.keysym.sym == SDLK_LEFT) {
} else if (event.key.key == SDLK_LEFT) {
--current;
} else if (event.key.keysym.sym == SDLK_RIGHT) {
} else if (event.key.key == SDLK_RIGHT) {
++current;
}
}