color_match in dlls/d3d8/tests/visual.c may not do what one would think

Gerald Pfeifer gerald at pfeifer.com
Sun Nov 4 15:56:16 CST 2018


Hi Henri, hi everyone,

earlier this year via

   commit 2f6fbdec8caee311e2fb85b2ddc9fbd8a9afaea5
   Author: H. Verbeet <hverbeet at gmail.com>
   Date:   Sat May 24 10:33:36 2008 +0200

       d3d8: Test our texop implementation.

we go the following function in dlls/d3d8/tests/visual.c:

   static BOOL color_match(D3DCOLOR c1, D3DCOLOR 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;
   }

Intuitively it's clear what this does, however there's a little
challenge: c1 and c2 are unsigned integers (D3DCOLOR being DWORD
being unsigned long), and so are c1 & 0xff and c2 & 0xff.

Substraction of two unsigned integer types is done in unsigned
math, so we may be seeing wrapping, but never a negative number
as a result -- and abs() is a noop.

Gerald



More information about the wine-devel mailing list