Module: wine Branch: master Commit: e463fa29ef7729106f02a4d4122a1b2a335df4c6 URL: https://source.winehq.org/git/wine.git/?a=commit;h=e463fa29ef7729106f02a4d41...
Author: Chip Davis cdavis@codeweavers.com Date: Wed Apr 8 19:18:07 2020 +0430
wined3d: Introduce compare_uint().
Signed-off-by: Chip Davis cdavis@codeweavers.com Signed-off-by: Henri Verbeet hverbeet@codeweavers.com Signed-off-by: Alexandre Julliard julliard@winehq.org
---
dlls/wined3d/utils.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-)
diff --git a/dlls/wined3d/utils.c b/dlls/wined3d/utils.c index 7b08851fbf..211160ad4d 100644 --- a/dlls/wined3d/utils.c +++ b/dlls/wined3d/utils.c @@ -3262,16 +3262,19 @@ static BOOL init_format_texture_info(struct wined3d_adapter *adapter, struct win return TRUE; }
-static BOOL color_match(DWORD c1, DWORD c2, BYTE max_diff) -{ - if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE; - c1 >>= 8; c2 >>= 8; - if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE; - c1 >>= 8; c2 >>= 8; - if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE; - c1 >>= 8; c2 >>= 8; - if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE; - return TRUE; +static BOOL compare_uint(unsigned int x, unsigned int y, unsigned int max_diff) +{ + unsigned int diff = x > y ? x - y : y - x; + + return diff <= max_diff; +} + +static BOOL compare_colour(DWORD c1, DWORD c2, BYTE max_diff) +{ + return compare_uint(c1 & 0xff, c2 & 0xff, max_diff) + && compare_uint((c1 >> 8) & 0xff, (c2 >> 8) & 0xff, max_diff) + && compare_uint((c1 >> 16) & 0xff, (c2 >> 16) & 0xff, max_diff) + && compare_uint((c1 >> 24) & 0xff, (c2 >> 24) & 0xff, max_diff); }
/* A context is provided by the caller */ @@ -3345,8 +3348,8 @@ static BOOL check_filter(const struct wined3d_gl_info *gl_info, GLenum internal) gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, buffer); memset(readback, 0x7f, sizeof(readback)); gl_info->gl_ops.gl.p_glGetTexImage(GL_TEXTURE_2D, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, readback); - if (color_match(readback[6], 0xffffffff, 5) || color_match(readback[6], 0x00000000, 5) - || color_match(readback[9], 0xffffffff, 5) || color_match(readback[9], 0x00000000, 5)) + if (compare_colour(readback[6], 0xffffffff, 5) || compare_colour(readback[6], 0x00000000, 5) + || compare_colour(readback[9], 0xffffffff, 5) || compare_colour(readback[9], 0x00000000, 5)) { TRACE("Read back colors 0x%08x and 0x%08x close to unfiltered color, assuming no filtering\n", readback[6], readback[9]);