[PATCH v2 2/5] win32u: Use pre-calculated decoded_text value.

Byeongsik Jeon bsjeon at hanmail.net
Thu Apr 21 13:49:19 CDT 2022


Signed-off-by: Byeongsik Jeon <bsjeon at hanmail.net>
---
v2: no change.

Because text_pixel does not change, we can use pre-computed
gamma_ramp->decode[text] value.

 dlls/win32u/dibdrv/primitives.c | 53 ++++++++++++++++++++++-----------
 1 file changed, 36 insertions(+), 17 deletions(-)

diff --git a/dlls/win32u/dibdrv/primitives.c b/dlls/win32u/dibdrv/primitives.c
index c9432fca4b8..4687ead5585 100644
--- a/dlls/win32u/dibdrv/primitives.c
+++ b/dlls/win32u/dibdrv/primitives.c
@@ -6339,24 +6339,22 @@ static void draw_glyph_null( const dib_info *dib, const RECT *rect, const dib_in
 {
     return;
 }
-static inline BYTE blend_color_gamma( BYTE dst, BYTE text, BYTE alpha,
+static inline BYTE blend_color_gamma( BYTE dst, BYTE text, BYTE decoded_text, BYTE alpha,
                                       const struct font_gamma_ramp *gamma_ramp )
 {
     if (alpha == 0) return dst;
     if (alpha == 255) return text;
     if (dst == text) return dst;
 
-    return gamma_ramp->encode[ blend_color( gamma_ramp->decode[dst],
-                                            gamma_ramp->decode[text],
-                                            alpha ) ];
+    return gamma_ramp->encode[ blend_color( gamma_ramp->decode[dst], decoded_text, alpha ) ];
 }
 
-static inline DWORD blend_subpixel( BYTE r, BYTE g, BYTE b, DWORD text, DWORD alpha,
+static inline DWORD blend_subpixel( BYTE r, BYTE g, BYTE b, DWORD text, DWORD decoded_text, DWORD alpha,
                                     const struct font_gamma_ramp *gamma_ramp )
 {
-    return blend_color_gamma( r, text >> 16, alpha >> 16, gamma_ramp ) << 16 |
-           blend_color_gamma( g, text >> 8,  alpha >> 8,  gamma_ramp ) << 8  |
-           blend_color_gamma( b, text,       alpha,       gamma_ramp );
+    return blend_color_gamma( r, text >> 16, decoded_text >> 16, alpha >> 16, gamma_ramp ) << 16 |
+           blend_color_gamma( g, text >> 8,  decoded_text >> 8,  alpha >> 8,  gamma_ramp ) << 8  |
+           blend_color_gamma( b, text,       decoded_text,       alpha,       gamma_ramp );
 }
 
 static void draw_subpixel_glyph_8888( const dib_info *dib, const RECT *rect, const dib_info *glyph,
@@ -6366,6 +6364,11 @@ static void draw_subpixel_glyph_8888( const dib_info *dib, const RECT *rect, con
     DWORD *dst_ptr = get_pixel_ptr_32( dib, rect->left, rect->top );
     const DWORD *glyph_ptr = get_pixel_ptr_32( glyph, origin->x, origin->y );
     int x, y;
+    DWORD decoded_text;
+
+    decoded_text = gamma_ramp->decode[ (BYTE)(text_pixel >> 16) ] << 16 |
+                   gamma_ramp->decode[ (BYTE)(text_pixel >> 8 ) ] << 8 |
+                   gamma_ramp->decode[ (BYTE)(text_pixel      ) ];
 
     for (y = rect->top; y < rect->bottom; y++)
     {
@@ -6373,7 +6376,7 @@ static void draw_subpixel_glyph_8888( const dib_info *dib, const RECT *rect, con
         {
             if (glyph_ptr[x] == 0) continue;
             dst_ptr[x] = blend_subpixel( dst_ptr[x] >> 16, dst_ptr[x] >> 8, dst_ptr[x],
-                                         text_pixel, glyph_ptr[x], gamma_ramp );
+                                         text_pixel, decoded_text, glyph_ptr[x], gamma_ramp );
         }
         dst_ptr += dib->stride / 4;
         glyph_ptr += glyph->stride / 4;
@@ -6387,12 +6390,16 @@ static void draw_subpixel_glyph_32( const dib_info *dib, const RECT *rect, const
     DWORD *dst_ptr = get_pixel_ptr_32( dib, rect->left, rect->top );
     const DWORD *glyph_ptr = get_pixel_ptr_32( glyph, origin->x, origin->y );
     int x, y;
-    DWORD text, val;
+    DWORD text, decoded_text, val;
 
     text = get_field( text_pixel, dib->red_shift,   dib->red_len ) << 16 |
            get_field( text_pixel, dib->green_shift, dib->green_len ) << 8 |
            get_field( text_pixel, dib->blue_shift,  dib->blue_len );
 
+    decoded_text = gamma_ramp->decode[ (BYTE)(text >> 16) ] << 16 |
+                   gamma_ramp->decode[ (BYTE)(text >> 8 ) ] << 8 |
+                   gamma_ramp->decode[ (BYTE)(text      ) ];
+
     for (y = rect->top; y < rect->bottom; y++)
     {
         for (x = 0; x < rect->right - rect->left; x++)
@@ -6401,7 +6408,7 @@ static void draw_subpixel_glyph_32( const dib_info *dib, const RECT *rect, const
             val = blend_subpixel( get_field(dst_ptr[x], dib->red_shift,   dib->red_len),
                                   get_field(dst_ptr[x], dib->green_shift, dib->green_len),
                                   get_field(dst_ptr[x], dib->blue_shift,  dib->blue_len),
-                                  text, glyph_ptr[x], gamma_ramp );
+                                  text, decoded_text, glyph_ptr[x], gamma_ramp );
             dst_ptr[x] = rgb_to_pixel_masks( dib, val >> 16, val >> 8, val );
         }
         dst_ptr += dib->stride / 4;
@@ -6416,7 +6423,11 @@ static void draw_subpixel_glyph_24( const dib_info *dib, const RECT *rect, const
     BYTE *dst_ptr = get_pixel_ptr_24( dib, rect->left, rect->top );
     const DWORD *glyph_ptr = get_pixel_ptr_32( glyph, origin->x, origin->y );
     int x, y;
-    DWORD val;
+    DWORD decoded_text, val;
+
+    decoded_text = gamma_ramp->decode[ (BYTE)(text_pixel >> 16) ] << 16 |
+                   gamma_ramp->decode[ (BYTE)(text_pixel >> 8 ) ] << 8 |
+                   gamma_ramp->decode[ (BYTE)(text_pixel      ) ];
 
     for (y = rect->top; y < rect->bottom; y++)
     {
@@ -6424,7 +6435,7 @@ static void draw_subpixel_glyph_24( const dib_info *dib, const RECT *rect, const
         {
             if (glyph_ptr[x] == 0) continue;
             val = blend_subpixel( dst_ptr[x * 3 + 2], dst_ptr[x * 3 + 1], dst_ptr[x * 3],
-                                  text_pixel, glyph_ptr[x], gamma_ramp );
+                                  text_pixel, decoded_text, glyph_ptr[x], gamma_ramp );
             dst_ptr[x * 3]     = val;
             dst_ptr[x * 3 + 1] = val >> 8;
             dst_ptr[x * 3 + 2] = val >> 16;
@@ -6441,12 +6452,16 @@ static void draw_subpixel_glyph_555( const dib_info *dib, const RECT *rect, cons
     WORD *dst_ptr = get_pixel_ptr_16( dib, rect->left, rect->top );
     const DWORD *glyph_ptr = get_pixel_ptr_32( glyph, origin->x, origin->y );
     int x, y;
-    DWORD text, val;
+    DWORD text, decoded_text, val;
 
     text = ((text_pixel << 9) & 0xf80000) | ((text_pixel << 4) & 0x070000) |
            ((text_pixel << 6) & 0x00f800) | ((text_pixel << 1) & 0x000700) |
            ((text_pixel << 3) & 0x0000f8) | ((text_pixel >> 2) & 0x000007);
 
+    decoded_text = gamma_ramp->decode[ (BYTE)(text >> 16) ] << 16 |
+                   gamma_ramp->decode[ (BYTE)(text >> 8 ) ] << 8 |
+                   gamma_ramp->decode[ (BYTE)(text      ) ];
+
     for (y = rect->top; y < rect->bottom; y++)
     {
         for (x = 0; x < rect->right - rect->left; x++)
@@ -6455,7 +6470,7 @@ static void draw_subpixel_glyph_555( const dib_info *dib, const RECT *rect, cons
             val = blend_subpixel( ((dst_ptr[x] >> 7) & 0xf8) | ((dst_ptr[x] >> 12) & 0x07),
                                   ((dst_ptr[x] >> 2) & 0xf8) | ((dst_ptr[x] >>  7) & 0x07),
                                   ((dst_ptr[x] << 3) & 0xf8) | ((dst_ptr[x] >>  2) & 0x07),
-                                  text, glyph_ptr[x], NULL );
+                                  text, decoded_text, glyph_ptr[x], NULL );
             dst_ptr[x] = ((val >> 9) & 0x7c00) | ((val >> 6) & 0x03e0) | ((val >> 3) & 0x001f);
         }
         dst_ptr += dib->stride / 2;
@@ -6470,12 +6485,16 @@ static void draw_subpixel_glyph_16( const dib_info *dib, const RECT *rect, const
     WORD *dst_ptr = get_pixel_ptr_16( dib, rect->left, rect->top );
     const DWORD *glyph_ptr = get_pixel_ptr_32( glyph, origin->x, origin->y );
     int x, y;
-    DWORD text, val;
+    DWORD text, decoded_text, val;
 
     text = get_field( text_pixel, dib->red_shift,   dib->red_len ) << 16 |
            get_field( text_pixel, dib->green_shift, dib->green_len ) << 8 |
            get_field( text_pixel, dib->blue_shift,  dib->blue_len );
 
+    decoded_text = gamma_ramp->decode[ (BYTE)(text >> 16) ] << 16 |
+                   gamma_ramp->decode[ (BYTE)(text >> 8 ) ] << 8 |
+                   gamma_ramp->decode[ (BYTE)(text      ) ];
+
     for (y = rect->top; y < rect->bottom; y++)
     {
         for (x = 0; x < rect->right - rect->left; x++)
@@ -6484,7 +6503,7 @@ static void draw_subpixel_glyph_16( const dib_info *dib, const RECT *rect, const
             val = blend_subpixel( get_field(dst_ptr[x], dib->red_shift,   dib->red_len),
                                   get_field(dst_ptr[x], dib->green_shift, dib->green_len),
                                   get_field(dst_ptr[x], dib->blue_shift,  dib->blue_len),
-                                  text, glyph_ptr[x], NULL );
+                                  text, decoded_text, glyph_ptr[x], NULL );
             dst_ptr[x] = rgb_to_pixel_masks( dib, val >> 16, val >> 8, val );
         }
         dst_ptr += dib->stride / 2;
-- 
2.36.0




More information about the wine-devel mailing list