[PATCH 1/5] wined3d: Properly up-scale WINED3DFMT_R5G5_SNORM_L6_UNORM (v2).

Stefan Dösinger stefan at codeweavers.com
Sat Mar 7 03:03:35 CST 2015


Version 2: Don't use a struct with bitfields, instead stick to masks and
shifts.

Simply left-shifting is not enough in positive ranges. 0xff / 255 !=
0xff00 / 65535.
---
 dlls/wined3d/utils.c | 39 ++++++++++++++++++++-------------------
 1 file changed, 20 insertions(+), 19 deletions(-)

diff --git a/dlls/wined3d/utils.c b/dlls/wined3d/utils.c
index 1ce23ac..5f35ffb 100644
--- a/dlls/wined3d/utils.c
+++ b/dlls/wined3d/utils.c
@@ -322,8 +322,8 @@ static void convert_r5g5_snorm_l6_unorm_nv(const BYTE *src, BYTE *dst, UINT src_
         UINT dst_row_pitch, UINT dst_slice_pitch, UINT width, UINT height, UINT depth)
 {
     unsigned int x, y, z;
-    const WORD *Source;
-    unsigned char *Dest;
+    unsigned char *texel_out, ds_out, dt_out, r_in, g_in, l_in;
+    const unsigned short *texel_in;
 
     /* This makes the gl surface bigger(24 bit instead of 16), but it works with
      * fixed function and shaders without further conversion once the surface is
@@ -333,27 +333,28 @@ static void convert_r5g5_snorm_l6_unorm_nv(const BYTE *src, BYTE *dst, UINT src_
     {
         for (y = 0; y < height; y++)
         {
-            Source = (const WORD *)(src + z * src_slice_pitch + y * src_row_pitch);
-            Dest = dst + z * dst_slice_pitch + y * dst_row_pitch;
+            texel_in = (const unsigned short *)(src + z * src_slice_pitch + y * src_row_pitch);
+            texel_out = dst + z * dst_slice_pitch + y * dst_row_pitch;
             for (x = 0; x < width; x++ )
             {
-                short color = (*Source++);
-                unsigned char l = ((color >> 10) & 0xfc);
-                         char v = ((color >>  5) & 0x3e);
-                         char u = ((color      ) & 0x1f);
+                l_in = (*texel_in & 0xfc00) >> 10;
+                g_in = (*texel_in & 0x03e0) >> 5;
+                r_in = *texel_in & 0x001f;
 
-                /* 8 bits destination, 6 bits source, 8th bit is the sign. gl ignores the sign
-                 * and doubles the positive range. Thus shift left only once, gl does the 2nd
-                 * shift. GL reads a signed value and converts it into an unsigned value.
-                 */
-                /* M */ Dest[2] = l << 1;
+                ds_out = r_in << 3;
+                if (!(r_in & 0x10)) /* r > 0 */
+                    ds_out |= r_in >> 1;
 
-                /* Those are read as signed, but kept signed. Just left-shift 3 times to scale
-                 * from 5 bit values to 8 bit values.
-                 */
-                /* V */ Dest[1] = v << 3;
-                /* U */ Dest[0] = u << 3;
-                Dest += 3;
+                dt_out = g_in << 3;
+                if (!(g_in & 0x10)) /* g > 0 */
+                    dt_out |= g_in >> 1;
+
+                texel_out[0] = ds_out;
+                texel_out[1] = dt_out;
+                texel_out[2] = l_in << 1 | l_in >> 5;
+
+                texel_out += 3;
+                texel_in++;
             }
         }
     }
-- 
2.3.0




More information about the wine-patches mailing list