[PATCH] wined3d: Introduce compare_uint().

Chip Davis cdavis at codeweavers.com
Mon Apr 6 17:56:11 CDT 2020


Signed-off-by: Chip Davis <cdavis at codeweavers.com>
---
 dlls/wined3d/utils.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/dlls/wined3d/utils.c b/dlls/wined3d/utils.c
index 7b08851fbf9..284a7fdec92 100644
--- a/dlls/wined3d/utils.c
+++ b/dlls/wined3d/utils.c
@@ -3262,15 +3262,19 @@ static BOOL init_format_texture_info(struct wined3d_adapter *adapter, struct win
     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 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;
+    if (!compare_uint(c1 & 0xff, c2 & 0xff, max_diff)) return FALSE;
+    if (!compare_uint((c1 >> 8) & 0xff, (c2 >> 8) & 0xff, max_diff)) return FALSE;
+    if (!compare_uint((c1 >> 16) & 0xff, (c2 >> 16) & 0xff, max_diff)) return FALSE;
+    if (!compare_uint((c1 >> 24) & 0xff, (c2 >> 24) & 0xff, max_diff)) return FALSE;
     return TRUE;
 }
 
-- 
2.24.0




More information about the wine-devel mailing list