freetype-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[freetype2-demos] master af884e3c 2/2: [graph] Fortify channel cache.


From: Werner Lemberg
Subject: [freetype2-demos] master af884e3c 2/2: [graph] Fortify channel cache.
Date: Tue, 6 Sep 2022 17:34:10 -0400 (EDT)

branch: master
commit af884e3cbf1a5c8e4469be4ef51ae0bf9532b4fd
Author: Alexei Podtelezhnikov <apodtele@gmail.com>
Commit: Alexei Podtelezhnikov <apodtele@gmail.com>

    [graph] Fortify channel cache.
    
    Using signed short offsets in the channel cache will risk to overflow
    if the current cache size is to increase.  Here we switch to unsigned
    index and express it in the cache units.
    
    * graph/gblender.h (GBlenderChanKeyRec): Update `index`.
    * graph/gblender.c (gblender_clear, gblender_lookup_channel,
    gblender_reset_channel_key): Updated accordingly.
---
 graph/gblender.c | 13 +++++++------
 graph/gblender.h |  4 ++--
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/graph/gblender.c b/graph/gblender.c
index e4de0fe9..984d3ecc 100644
--- a/graph/gblender.c
+++ b/graph/gblender.c
@@ -126,7 +126,7 @@ gblender_clear( GBlender  blender )
     GBlenderChanKey  chan_keys = (GBlenderChanKey) blender->keys;
 
     for ( nn = 0; nn < GBLENDER_KEY_COUNT * 3; nn++ )
-      chan_keys[nn].index = -1;
+      chan_keys[nn].index = 0xFFFF;
 
     blender->cache_r_back  = 0;
     blender->cache_r_fore  = ~0U;
@@ -310,7 +310,8 @@ gblender_reset_channel_key( GBlender         blender,
 {
   unsigned int    back = key->backfore & 255;
   unsigned int    fore = (key->backfore >> 8) & 255;
-  unsigned char*  gr   = (unsigned char*)blender->cells + key->index;
+  unsigned char*  gr   = (unsigned char*)blender->cells +
+                                         key->index * GBLENDER_SHADE_COUNT;
   unsigned int    nn;
 
   const unsigned char*   gamma_ramp_inv = blender->gamma_ramp_inv;
@@ -341,7 +342,7 @@ gblender_lookup_channel( GBlender      blender,
                          unsigned int  background,
                          unsigned int  foreground )
 {
-  unsigned         idx;
+  unsigned short   idx;
   unsigned short   backfore = (unsigned short)((foreground << 8) | background);
   GBlenderChanKey  key;
 
@@ -354,7 +355,7 @@ gblender_lookup_channel( GBlender      blender,
 
   key = (GBlenderChanKey)blender->keys + idx;
 
-  if ( key->index < 0 )
+  if ( key->index == 0xFFFF )
     goto NewNode;
 
   if ( key->backfore == backfore )
@@ -366,7 +367,7 @@ gblender_lookup_channel( GBlender      blender,
 
 NewNode:
   key->backfore   = backfore;
-  key->index      = (signed short)( idx * GBLENDER_SHADE_COUNT );
+  key->index      = idx;
 
   gblender_reset_channel_key( blender, key );
 
@@ -375,7 +376,7 @@ NewNode:
 #endif
 
 Exit:
-  return  (unsigned char*)blender->cells + key->index;
+  return  (unsigned char*)blender->cells + idx * GBLENDER_SHADE_COUNT;
 }
 
 
diff --git a/graph/gblender.h b/graph/gblender.h
index 5fed4aa7..b5970202 100644
--- a/graph/gblender.h
+++ b/graph/gblender.h
@@ -62,8 +62,8 @@
 
   typedef struct
   {
-    unsigned short  backfore;  /* (fore << 8) | back               */
-    signed short    index;     /* offset in (unsigned char*)cells  */
+    unsigned short  backfore;  /* (fore << 8) | back    */
+    unsigned short  index;     /* offset in cache units */
 
   } GBlenderChanKeyRec, *GBlenderChanKey;
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]