freetype-commit
[Top][All Lists]
Advanced

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

[Git][freetype/freetype][master] [sfnt] Apply variation deltas to `Paint


From: Werner Lemberg (@wl)
Subject: [Git][freetype/freetype][master] [sfnt] Apply variation deltas to `PaintVarSolid`.
Date: Thu, 07 Jul 2022 17:56:03 +0000

Werner Lemberg pushed to branch master at FreeType / FreeType

Commits:

  • 7c151abb
    by Dominik Röttsches at 2022-07-07T19:48:19+02:00
    [sfnt] Apply variation deltas to `PaintVarSolid`.
    
    * src/sfnt/ttcolr.c (FT_PaintFormat_Internal_): New enumeration
    `FT_COLR_PAINTFORMAT_INTERNAL_VAR_SOLID`.
    
    (get_deltas_for_var_index_base) [TT_CONFIG_OPTION_GX_VAR_SUPPORT]: New
    function to retrieve an array of delta values, which will be used for most
    of 'COLR' v1 variation formats (in follow-up commits).
    
    (read_paint): Add `face` parameter; update caller.
    Handle `FT_COLR_PAINTFORMAT_INTERNAL_VAR_SOLID`.
    

1 changed file:

Changes:

  • src/sfnt/ttcolr.c
    ... ... @@ -65,6 +65,7 @@
    65 65
     
    
    66 66
       typedef enum  FT_PaintFormat_Internal_
    
    67 67
       {
    
    68
    +    FT_COLR_PAINTFORMAT_INTERNAL_VAR_SOLID            = 3,
    
    68 69
         FT_COLR_PAINTFORMAT_INTERNAL_SCALE_CENTER         = 18,
    
    69 70
         FT_COLR_PAINTFORMAT_INTERNAL_SCALE_UNIFORM        = 20,
    
    70 71
         FT_COLR_PAINTFORMAT_INTERNAL_SCALE_UNIFORM_CENTER = 22,
    
    ... ... @@ -532,13 +533,80 @@
    532 533
       }
    
    533 534
     
    
    534 535
     
    
    536
    +#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
    
    537
    +
    
    538
    +  static FT_Bool
    
    539
    +  get_deltas_for_var_index_base ( TT_Face           face,
    
    540
    +                                  Colr*             colr,
    
    541
    +                                  FT_ULong          var_index_base,
    
    542
    +                                  FT_UInt           num_deltas,
    
    543
    +                                  FT_ItemVarDelta*  deltas )
    
    544
    +  {
    
    545
    +    FT_Error  error = FT_Err_Ok;
    
    546
    +
    
    547
    +    FT_UInt   outer_index    = 0;
    
    548
    +    FT_UInt   inner_index    = 0;
    
    549
    +    FT_ULong  loop_var_index = var_index_base;
    
    550
    +
    
    551
    +    FT_Service_MultiMasters  mm = (FT_Service_MultiMasters)face->mm;
    
    552
    +
    
    553
    +    FT_UInt  i = 0;
    
    554
    +
    
    555
    +
    
    556
    +    if ( !VARIABLE_COLRV1_ENABLED )
    
    557
    +    {
    
    558
    +      FT_ASSERT( 0 );
    
    559
    +      return 0;
    
    560
    +    }
    
    561
    +
    
    562
    +    if ( var_index_base == 0xFFFFFFFF )
    
    563
    +    {
    
    564
    +      for ( i = 0; i < num_deltas; ++i )
    
    565
    +        deltas[i] = 0;
    
    566
    +      return 1;
    
    567
    +    }
    
    568
    +
    
    569
    +    for ( i = 0; i < num_deltas; ++i )
    
    570
    +    {
    
    571
    +      loop_var_index = var_index_base + i;
    
    572
    +
    
    573
    +      if ( colr->delta_set_idx_map.innerIndex )
    
    574
    +      {
    
    575
    +        if ( loop_var_index >= colr->delta_set_idx_map.mapCount )
    
    576
    +          loop_var_index = colr->delta_set_idx_map.mapCount - 1;
    
    577
    +
    
    578
    +        outer_index = colr->delta_set_idx_map.outerIndex[loop_var_index];
    
    579
    +        inner_index = colr->delta_set_idx_map.innerIndex[loop_var_index];
    
    580
    +      }
    
    581
    +      else
    
    582
    +      {
    
    583
    +        /* TODO: Direct lookup case not implemented or tested yet. */
    
    584
    +        FT_ASSERT( 0 );
    
    585
    +        error = FT_THROW( Unimplemented_Feature );
    
    586
    +        return error;
    
    587
    +      }
    
    588
    +
    
    589
    +      deltas[i] = mm->get_item_delta( FT_FACE( face ), &colr->var_store,
    
    590
    +                                      outer_index, inner_index );
    
    591
    +    }
    
    592
    +
    
    593
    +    return 1;
    
    594
    +  }
    
    595
    +
    
    596
    +#endif /* TT_CONFIG_OPTION_GX_VAR_SUPPORT */
    
    597
    +
    
    598
    +
    
    535 599
       static FT_Bool
    
    536
    -  read_paint( Colr*           colr,
    
    600
    +  read_paint( TT_Face         face,
    
    601
    +              Colr*           colr,
    
    537 602
                   FT_Byte*        p,
    
    538 603
                   FT_COLR_Paint*  apaint )
    
    539 604
       {
    
    540
    -    FT_Byte*  paint_base     = p;
    
    541
    -    FT_Byte*  child_table_p  = NULL;
    
    605
    +    FT_Byte*         paint_base      = p;
    
    606
    +    FT_Byte*         child_table_p   = NULL;
    
    607
    +    FT_ULong         var_index_base  = 0;
    
    608
    +    /* Longest varIndexBase offset is 5 in the spec. */
    
    609
    +    FT_ItemVarDelta  item_deltas[6]  = { 0, 0, 0, 0, 0, 0 };
    
    542 610
     
    
    543 611
     
    
    544 612
         if ( !p || !colr || !colr->table )
    
    ... ... @@ -579,11 +647,30 @@
    579 647
           return 1;
    
    580 648
         }
    
    581 649
     
    
    582
    -    else if ( apaint->format == FT_COLR_PAINTFORMAT_SOLID )
    
    650
    +    else if ( apaint->format == FT_COLR_PAINTFORMAT_SOLID ||
    
    651
    +              (FT_PaintFormat_Internal)apaint->format ==
    
    652
    +                  FT_COLR_PAINTFORMAT_INTERNAL_VAR_SOLID  )
    
    583 653
         {
    
    584 654
           apaint->u.solid.color.palette_index = FT_NEXT_USHORT( p );
    
    585 655
           apaint->u.solid.color.alpha         = FT_NEXT_SHORT( p );
    
    586 656
     
    
    657
    +#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
    
    658
    +      if ( (FT_PaintFormat_Internal)apaint->format ==
    
    659
    +               FT_COLR_PAINTFORMAT_INTERNAL_VAR_SOLID &&
    
    660
    +           VARIABLE_COLRV1_ENABLED                    )
    
    661
    +      {
    
    662
    +        var_index_base = FT_NEXT_ULONG( p );
    
    663
    +
    
    664
    +        if ( !get_deltas_for_var_index_base( face, colr, var_index_base, 1,
    
    665
    +                                             item_deltas ) )
    
    666
    +          return 0;
    
    667
    +
    
    668
    +        apaint->u.solid.color.alpha += item_deltas[0];
    
    669
    +      }
    
    670
    +#endif
    
    671
    +
    
    672
    +      apaint->format = FT_COLR_PAINTFORMAT_SOLID;
    
    673
    +
    
    587 674
           return 1;
    
    588 675
         }
    
    589 676
     
    
    ... ... @@ -1243,7 +1330,7 @@
    1243 1330
           return 1;
    
    1244 1331
         }
    
    1245 1332
     
    
    1246
    -    return read_paint( colr, opaque_paint.p, paint );
    
    1333
    +    return read_paint( face, colr, opaque_paint.p, paint );
    
    1247 1334
       }
    
    1248 1335
     
    
    1249 1336
     
    


  • reply via email to

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