freetype-commit
[Top][All Lists]
Advanced

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

[Git][freetype/freetype-demos][master] 2 commits: * graph/gblender.* (GB


From: Alexei Podtelezhnikov (@apodtele)
Subject: [Git][freetype/freetype-demos][master] 2 commits: * graph/gblender.* (GBlenderRec): Cosmetic changes to cache array.
Date: Tue, 06 Sep 2022 21:34:01 +0000

Alexei Podtelezhnikov pushed to branch master at FreeType / FreeType Demo Programs

Commits:

  • 81bb1415
    by Alexei Podtelezhnikov at 2022-09-06T16:41:10-04:00
    * graph/gblender.* (GBlenderRec): Cosmetic changes to cache array.
    
  • af884e3c
    by Alexei Podtelezhnikov at 2022-09-06T17:23:31-04:00
    [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.
    

2 changed files:

Changes:

  • graph/gblender.c
    ... ... @@ -119,15 +119,14 @@ gblender_set_gamma_table( double gamma_value,
    119 119
     static void
    
    120 120
     gblender_clear( GBlender  blender )
    
    121 121
     {
    
    122
    -  int          nn;
    
    123
    -  GBlenderKey  keys = blender->keys;
    
    122
    +  int  nn;
    
    124 123
     
    
    125 124
       if ( blender->channels )
    
    126 125
       {
    
    127 126
         GBlenderChanKey  chan_keys = (GBlenderChanKey) blender->keys;
    
    128 127
     
    
    129 128
         for ( nn = 0; nn < GBLENDER_KEY_COUNT * 3; nn++ )
    
    130
    -      chan_keys[nn].index = -1;
    
    129
    +      chan_keys[nn].index = 0xFFFF;
    
    131 130
     
    
    132 131
         blender->cache_r_back  = 0;
    
    133 132
         blender->cache_r_fore  = ~0U;
    
    ... ... @@ -143,6 +142,8 @@ gblender_clear( GBlender blender )
    143 142
       }
    
    144 143
       else
    
    145 144
       {
    
    145
    +    GBlenderKey  keys = blender->keys;
    
    146
    +
    
    146 147
         for ( nn = 0; nn < GBLENDER_KEY_COUNT; nn++ )
    
    147 148
           keys[nn].cells = NULL;
    
    148 149
     
    
    ... ... @@ -290,7 +291,7 @@ gblender_lookup( GBlender blender,
    290 291
     NewNode:
    
    291 292
       key->background = background;
    
    292 293
       key->foreground = foreground;
    
    293
    -  key->cells      = blender->cells + idx * GBLENDER_SHADE_COUNT;
    
    294
    +  key->cells      = blender->cells[idx];
    
    294 295
     
    
    295 296
       gblender_reset_key( blender, key );
    
    296 297
     
    
    ... ... @@ -309,7 +310,8 @@ gblender_reset_channel_key( GBlender blender,
    309 310
     {
    
    310 311
       unsigned int    back = key->backfore & 255;
    
    311 312
       unsigned int    fore = (key->backfore >> 8) & 255;
    
    312
    -  unsigned char*  gr   = (unsigned char*)blender->cells + key->index;
    
    313
    +  unsigned char*  gr   = (unsigned char*)blender->cells +
    
    314
    +                                         key->index * GBLENDER_SHADE_COUNT;
    
    313 315
       unsigned int    nn;
    
    314 316
     
    
    315 317
       const unsigned char*   gamma_ramp_inv = blender->gamma_ramp_inv;
    
    ... ... @@ -340,7 +342,7 @@ gblender_lookup_channel( GBlender blender,
    340 342
                              unsigned int  background,
    
    341 343
                              unsigned int  foreground )
    
    342 344
     {
    
    343
    -  unsigned         idx;
    
    345
    +  unsigned short   idx;
    
    344 346
       unsigned short   backfore = (unsigned short)((foreground << 8) | background);
    
    345 347
       GBlenderChanKey  key;
    
    346 348
     
    
    ... ... @@ -353,7 +355,7 @@ gblender_lookup_channel( GBlender blender,
    353 355
     
    
    354 356
       key = (GBlenderChanKey)blender->keys + idx;
    
    355 357
     
    
    356
    -  if ( key->index < 0 )
    
    358
    +  if ( key->index == 0xFFFF )
    
    357 359
         goto NewNode;
    
    358 360
     
    
    359 361
       if ( key->backfore == backfore )
    
    ... ... @@ -365,7 +367,7 @@ gblender_lookup_channel( GBlender blender,
    365 367
     
    
    366 368
     NewNode:
    
    367 369
       key->backfore   = backfore;
    
    368
    -  key->index      = (signed short)( idx * GBLENDER_SHADE_COUNT );
    
    370
    +  key->index      = idx;
    
    369 371
     
    
    370 372
       gblender_reset_channel_key( blender, key );
    
    371 373
     
    
    ... ... @@ -374,7 +376,7 @@ NewNode:
    374 376
     #endif
    
    375 377
     
    
    376 378
     Exit:
    
    377
    -  return  (unsigned char*)blender->cells + key->index;
    
    379
    +  return  (unsigned char*)blender->cells + idx * GBLENDER_SHADE_COUNT;
    
    378 380
     }
    
    379 381
     
    
    380 382
     
    

  • graph/gblender.h
    ... ... @@ -62,8 +62,8 @@
    62 62
     
    
    63 63
       typedef struct
    
    64 64
       {
    
    65
    -    unsigned short  backfore;  /* (fore << 8) | back               */
    
    66
    -    signed short    index;     /* offset in (unsigned char*)cells  */
    
    65
    +    unsigned short  backfore;  /* (fore << 8) | back    */
    
    66
    +    unsigned short  index;     /* offset in cache units */
    
    67 67
     
    
    68 68
       } GBlenderChanKeyRec, *GBlenderChanKey;
    
    69 69
     
    
    ... ... @@ -73,7 +73,7 @@
    73 73
       typedef struct GBlenderRec_
    
    74 74
       {
    
    75 75
         GBlenderKeyRec        keys [ GBLENDER_KEY_COUNT ];
    
    76
    -    GBlenderCell          cells[ GBLENDER_KEY_COUNT*GBLENDER_SHADE_COUNT ];
    
    76
    +    GBlenderCell          cells[ GBLENDER_KEY_COUNT ][ GBLENDER_SHADE_COUNT ];
    
    77 77
     
    
    78 78
        /* a small cache for normal modes
    
    79 79
         */
    


  • reply via email to

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