From: Rémi Bernon rbernon@codeweavers.com
--- dlls/evr/tests/evr.c | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-)
diff --git a/dlls/evr/tests/evr.c b/dlls/evr/tests/evr.c index a684540d977..4674221b86d 100644 --- a/dlls/evr/tests/evr.c +++ b/dlls/evr/tests/evr.c @@ -39,34 +39,39 @@ static void load_resource(const WCHAR *filename, const BYTE **data, DWORD *lengt *length = SizeofResource(GetModuleHandleW(NULL), resource); }
-static DWORD compare_rgb32(const BYTE *data, DWORD *length, const RECT *rect, const BYTE *expect) +static DWORD compare_rgb(const BYTE *data, DWORD *length, const SIZE *size, const RECT *rect, const BYTE *expect, UINT bits) { - DWORD x, y, size, diff = 0, width = rect->right, height = rect->bottom; + DWORD x, y, step = bits / 8, data_size, diff = 0, width = size->cx, height = size->cy;
/* skip BMP header from the dump */ - size = *(DWORD *)(expect + 2 + 2 * sizeof(DWORD)); - *length = *length + size; - expect = expect + size; + data_size = *(DWORD *)(expect + 2 + 2 * sizeof(DWORD)); + *length = *length + data_size; + expect = expect + data_size;
- for (y = 0; y < height; y++, data += width * 4, expect += width * 4) + for (y = 0; y < height; y++, data += width * step, expect += width * step) { if (y < rect->top || y >= rect->bottom) continue; for (x = 0; x < width; x++) { if (x < rect->left || x >= rect->right) continue; - diff += abs((int)expect[4 * x + 0] - (int)data[4 * x + 0]); - diff += abs((int)expect[4 * x + 1] - (int)data[4 * x + 1]); - diff += abs((int)expect[4 * x + 2] - (int)data[4 * x + 2]); + diff += abs((int)expect[step * x + 0] - (int)data[step * x + 0]); + diff += abs((int)expect[step * x + 1] - (int)data[step * x + 1]); + if (step >= 3) diff += abs((int)expect[step * x + 2] - (int)data[step * x + 2]); } }
- size = (rect->right - rect->left) * (rect->bottom - rect->top) * 3; - return diff * 100 / 256 / size; + data_size = (rect->right - rect->left) * (rect->bottom - rect->top) * min(step, 3); + return diff * 100 / 256 / data_size; }
-static void dump_rgb32(const BYTE *data, DWORD length, const RECT *rect, HANDLE output) +static DWORD compare_rgb32(const BYTE *data, DWORD *length, const SIZE *size, const RECT *rect, const BYTE *expect) { - DWORD width = rect->right, height = rect->bottom; + return compare_rgb(data, length, size, rect, expect, 32); +} + +static void dump_rgb(const BYTE *data, DWORD length, const SIZE *size, HANDLE output, UINT bits) +{ + DWORD width = size->cx, height = size->cy; static const char magic[2] = "BM"; struct { @@ -80,7 +85,7 @@ static void dump_rgb32(const BYTE *data, DWORD length, const RECT *rect, HANDLE .biHeader = { .biSize = sizeof(BITMAPINFOHEADER), .biWidth = width, .biHeight = height, .biPlanes = 1, - .biBitCount = 32, .biCompression = BI_RGB, .biSizeImage = width * height * 4, + .biBitCount = bits, .biCompression = BI_RGB, .biSizeImage = width * height * (bits / 8), }, }; DWORD written; @@ -97,9 +102,15 @@ static void dump_rgb32(const BYTE *data, DWORD length, const RECT *rect, HANDLE ok(written == length, "written %lu bytes\n", written); }
+static void dump_rgb32(const BYTE *data, DWORD length, const SIZE *size, HANDLE output) +{ + return dump_rgb(data, length, size, output, 32); +} + #define check_rgb32_data(a, b, c, d) check_rgb32_data_(__LINE__, a, b, c, d) static DWORD check_rgb32_data_(int line, const WCHAR *filename, const BYTE *data, DWORD length, const RECT *rect) { + SIZE size = {rect->right, rect->bottom}; WCHAR output_path[MAX_PATH]; const BYTE *expect_data; HRSRC resource; @@ -109,7 +120,7 @@ static DWORD check_rgb32_data_(int line, const WCHAR *filename, const BYTE *data lstrcatW(output_path, filename); output = CreateFileW(output_path, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0); ok(output != INVALID_HANDLE_VALUE, "CreateFileW failed, error %lu\n", GetLastError()); - dump_rgb32(data, length, rect, output); + dump_rgb32(data, length, &size, output); trace("created %s\n", debugstr_w(output_path)); CloseHandle(output);
@@ -117,7 +128,7 @@ static DWORD check_rgb32_data_(int line, const WCHAR *filename, const BYTE *data ok(resource != 0, "FindResourceW failed, error %lu\n", GetLastError()); expect_data = LockResource(LoadResource(GetModuleHandleW(NULL), resource));
- return compare_rgb32(data, &length, rect, expect_data); + return compare_rgb32(data, &length, &size, rect, expect_data); }
static void set_rect(MFVideoNormalizedRect *rect, float left, float top, float right, float bottom)