Remove division from inner loop
Michael Abbott
michael at araneidae.co.uk
Tue Jun 16 14:06:12 CDT 2009
The attached patch converts an inner loop division added by
http://www.winehq.org/pipermail/wine-patches/2009-June/074312.html
into shifts and adds, and slightly clarifies the code as well, I think!
Author: Michael Abbott <michael at araneidae.co.uk>
Date: Tue Jun 16 16:20:05 2009 +0100
Remove division from inner loop
When rescaling D15S1 data to D24 data it isn't necessary to do full
arithmetic, instead bit shifts are sufficient.
diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c
index 6ab0443..f6c0f8c 100644
--- a/dlls/wined3d/surface.c
+++ b/dlls/wined3d/surface.c
@@ -2461,9 +2461,11 @@ static HRESULT d3dfmt_convert_surface(const BYTE
*src, BYTE *dst, UINT pitch, UI
for (x = 0; x < width; ++x)
{
- /* The depth data is normalized, so needs to be
scaled, the stencil data isn't. */
- WORD d15 = source[x] & 0xfffe;
- DWORD d24 = d15 * 0x100 + (d15 * 0xff80 + 0x3fff80) /
0x7fff00;
+ /* The depth data is normalized, so needs to be
scaled,
+ * the stencil data isn't. Scale depth data by
+ * (2^24-1)/(2^15-1) ~~ (2^9 + 2^-6). */
+ WORD d15 = source[x] >> 1;
+ DWORD d24 = (d15 << 9) + (d15 >> 6);
dest[x] = (d24 << 8) | (source[x] & 0x1);
}
}
More information about the wine-patches
mailing list