22 #define MAX_YUV_SURFACE_SIZE(W, H, P) (H*4*(W+P+1)/2) 41 const int thickness = 2;
44 for (y = 0; y < pattern->
h; y += thickness) {
45 for (i = 0; i < thickness; ++
i) {
46 p = (
Uint8 *)pattern->
pixels + (y + i) * pattern->
pitch + ((y/thickness) % 3);
47 for (x = 0; x < pattern->
w; ++
x) {
56 for (x = 1*thickness; x < pattern->
w; x += 2*thickness) {
57 for (i = 0; i < thickness; ++
i) {
59 for (y = 0; y < pattern->
h; ++
y) {
76 const int tolerance = 20;
77 const int size = (surface->
h * surface->
pitch);
90 for (y = 0; y < surface->
h; ++
y) {
91 const Uint8 *actual = rgb + y * surface->
pitch;
93 for (x = 0; x < surface->
w; ++
x) {
94 int deltaR = (int)actual[0] - expected[0];
95 int deltaG = (int)actual[1] - expected[1];
96 int deltaB = (int)actual[2] - expected[2];
97 int distance = (deltaR * deltaR + deltaG * deltaG + deltaB * deltaB);
98 if (distance > tolerance) {
99 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);
130 int yuv1_pitch, yuv2_pitch;
133 if (!pattern || !yuv1 || !yuv2) {
173 if (
SDL_ConvertPixels(pattern->
w, pattern->
h, formats[i], yuv1, yuv1_pitch, formats[j], yuv2, yuv2_pitch) < 0) {
198 if (
SDL_ConvertPixels(pattern->
w, pattern->
h, formats[i], yuv1, yuv1_pitch, formats[j], yuv1, yuv2_pitch) < 0) {
226 } automated_test_params[] = {
257 const char *titles[3] = {
"ORIGINAL",
"SOFTWARE",
"HARDWARE" };
259 const char *yuv_name;
260 const char *yuv_mode;
269 while (argv[arg] && *argv[arg] ==
'-') {
272 }
else if (
SDL_strcmp(argv[arg],
"--bt601") == 0) {
274 }
else if (
SDL_strcmp(argv[arg],
"--bt709") == 0) {
276 }
else if (
SDL_strcmp(argv[arg],
"--auto") == 0) {
278 }
else if (
SDL_strcmp(argv[arg],
"--yv12") == 0) {
280 }
else if (
SDL_strcmp(argv[arg],
"--iyuv") == 0) {
282 }
else if (
SDL_strcmp(argv[arg],
"--yuy2") == 0) {
284 }
else if (
SDL_strcmp(argv[arg],
"--uyvy") == 0) {
286 }
else if (
SDL_strcmp(argv[arg],
"--yvyu") == 0) {
288 }
else if (
SDL_strcmp(argv[arg],
"--nv12") == 0) {
290 }
else if (
SDL_strcmp(argv[arg],
"--nv21") == 0) {
292 }
else if (
SDL_strcmp(argv[arg],
"--rgb555") == 0) {
294 }
else if (
SDL_strcmp(argv[arg],
"--rgb565") == 0) {
296 }
else if (
SDL_strcmp(argv[arg],
"--rgb24") == 0) {
298 }
else if (
SDL_strcmp(argv[arg],
"--argb") == 0) {
300 }
else if (
SDL_strcmp(argv[arg],
"--abgr") == 0) {
302 }
else if (
SDL_strcmp(argv[arg],
"--rgba") == 0) {
304 }
else if (
SDL_strcmp(argv[arg],
"--bgra") == 0) {
306 }
else if (
SDL_strcmp(argv[arg],
"--automated") == 0) {
307 should_run_automated_tests =
SDL_TRUE;
309 SDL_LogError(
SDL_LOG_CATEGORY_APPLICATION,
"Usage: %s [--jpeg|--bt601|-bt709|--auto] [--yv12|--iyuv|--yuy2|--uyvy|--yvyu|--nv12|--nv21] [--rgb555|--rgb565|--rgb24|--argb|--abgr|--rgba|--bgra] [image_filename]\n", argv[0]);
316 if (should_run_automated_tests) {
319 automated_test_params[i].pattern_size,
320 automated_test_params[i].extra_pitch,
321 automated_test_params[i].enable_intrinsics ?
"enabled" :
"disabled");
322 if (
run_automated_tests(automated_test_params[i].pattern_size, automated_test_params[i].extra_pitch) < 0) {
330 filename = argv[arg];
332 filename =
"testyuv.bmp";
362 original->
w, original->
h,
378 if (!output[0] || !output[1] || !output[2]) {
385 if (
SDL_strncmp(yuv_name,
"SDL_PIXELFORMAT_", 16) == 0) {
400 yuv_mode =
"UNKNOWN";
422 if (event.
button.
x < (original->
w/2)) {
444 SDL_snprintf(title,
sizeof(title),
"%s %s %s", titles[current], yuv_name, yuv_mode);
#define SDL_CreateTexture
static SDL_bool is_packed_yuv_format(Uint32 format)
#define SDL_ConvertSurfaceFormat
#define SDL_LoadBMP(file)
GLint GLint GLint GLint GLint x
A collection of pixels used in software blitting.
static int run_automated_tests(int pattern_size, int extra_pitch)
#define SDL_WINDOWPOS_UNDEFINED
#define SDL_UpdateTexture
static SDL_bool verify_yuv_data(Uint32 format, const Uint8 *yuv, int yuv_pitch, SDL_Surface *surface)
GLsizei GLsizei GLfloat distance
#define MAX_YUV_SURFACE_SIZE(W, H, P)
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
int main(int argc, char **argv)
#define SDL_CreateTextureFromSurface
Uint32 SDL_GetTicks(void)
Get the number of milliseconds since the SDL library initialization.
#define SDL_SetYUVConversionMode
static SDL_Renderer * renderer
int SDLTest_DrawString(SDL_Renderer *renderer, int x, int y, const char *s)
Draw a string in the currently set font.
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int int in j)
GLint GLint GLint GLint GLint GLint y
int CalculateYUVPitch(Uint32 format, int width)
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
static SDL_Surface * generate_test_pattern(int pattern_size)
EGLSurface EGLNativeWindowType * window
The type used to identify a window.
SDL_MouseButtonEvent button
#define SDL_arraysize(array)
#define SDL_SetRenderDrawColor
#define SDL_ConvertPixels
#define SDL_GetYUVConversionModeForResolution
#define SDL_CreateRGBSurfaceWithFormat
#define SDL_CreateRenderer
#define SDL_RenderPresent
SDL_bool ConvertRGBtoYUV(Uint32 format, Uint8 *src, int pitch, Uint8 *out, int w, int h, SDL_YUV_CONVERSION_MODE mode, int monochrome, int luminance)
#define SDL_GetPixelFormatName