freetype-commit
[Top][All Lists]
Advanced

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

[Git][freetype/freetype][master] 2 commits: * src/smooth/ftgrays.c (FT_I


From: Alexei Podtelezhnikov
Subject: [Git][freetype/freetype][master] 2 commits: * src/smooth/ftgrays.c (FT_INTEGRATE): New convenience macro.
Date: Fri, 12 Mar 2021 03:41:32 +0000

Alexei Podtelezhnikov pushed to branch master at FreeType / FreeType

Commits:

2 changed files:

Changes:

  • ChangeLog
    1
    +2021-03-11  Alexei Podtelezhnikov  <apodtele@gmail.com>
    
    2
    +
    
    3
    +	[smooth] Reduce copying during integration phase.
    
    4
    +
    
    5
    +	We now record `cover' and `area' directly into the linked list. This
    
    6
    +	makes rendering faster by 10% or even more at larger sizes.
    
    7
    +
    
    8
    +	* src/smooth/ftgrays.c (FT_INTEGRATE): Write directly.
    
    9
    +	(gray_TWorker): Add direct cell reference and remove unused fields.
    
    10
    +	(gray_set_cell): Consolidate the linked list management and pointers.
    
    11
    +	(gray_convert_glyph, gray_convert_glyph_inner): Updated.
    
    12
    +
    
    13
    +2021-03-10  Alexei Podtelezhnikov  <apodtele@gmail.com>
    
    14
    +
    
    15
    +	* src/smooth/ftgrays.c (FT_INTEGRATE): New convenience macro.
    
    16
    +	(gray_render_line, gray_render_scanline): Use it.
    
    17
    +
    
    1 18
     2021-03-09  Alexei Podtelezhnikov  <apodtele@gmail.com>
    
    2 19
     
    
    3 20
     	* src/smooth/ftgrays.c (gray_render_line): Rearrange conditionals.
    

  • src/smooth/ftgrays.c
    ... ... @@ -447,14 +447,10 @@ typedef ptrdiff_t FT_PtrDist;
    447 447
       {
    
    448 448
         ft_jmp_buf  jump_buffer;
    
    449 449
     
    
    450
    -    TCoord  ex, ey;
    
    451 450
         TCoord  min_ex, max_ex;
    
    452 451
         TCoord  min_ey, max_ey;
    
    453 452
     
    
    454
    -    TArea   area;
    
    455
    -    TCoord  cover;
    
    456
    -    int     invalid;
    
    457
    -
    
    453
    +    PCell       cell;
    
    458 454
         PCell*      ycells;
    
    459 455
         PCell       cells;
    
    460 456
         FT_PtrDist  max_cells;
    
    ... ... @@ -483,6 +479,10 @@ typedef ptrdiff_t FT_PtrDist;
    483 479
       static gray_TWorker  ras;
    
    484 480
     #endif
    
    485 481
     
    
    482
    +#define FT_INTEGRATE( ras, a, b )                                       \
    
    483
    +           if ( ras.cell )                                              \
    
    484
    +             ras.cell->cover += (a), ras.cell->area += (a) * (TArea)(b)
    
    485
    +
    
    486 486
     
    
    487 487
       typedef struct gray_TRaster_
    
    488 488
       {
    
    ... ... @@ -518,50 +518,6 @@ typedef ptrdiff_t FT_PtrDist;
    518 518
     #endif /* FT_DEBUG_LEVEL_TRACE */
    
    519 519
     
    
    520 520
     
    
    521
    -  /**************************************************************************
    
    522
    -   *
    
    523
    -   * Record the current cell in the linked list.
    
    524
    -   */
    
    525
    -  static void
    
    526
    -  gray_record_cell( RAS_ARG )
    
    527
    -  {
    
    528
    -    PCell  *pcell, cell;
    
    529
    -    TCoord  x = ras.ex;
    
    530
    -
    
    531
    -
    
    532
    -    pcell = &ras.ycells[ras.ey - ras.min_ey];
    
    533
    -    while ( ( cell = *pcell ) )
    
    534
    -    {
    
    535
    -      if ( cell->x > x )
    
    536
    -        break;
    
    537
    -
    
    538
    -      if ( cell->x == x )
    
    539
    -        goto Found;
    
    540
    -
    
    541
    -      pcell = &cell->next;
    
    542
    -    }
    
    543
    -
    
    544
    -    if ( ras.num_cells >= ras.max_cells )
    
    545
    -      ft_longjmp( ras.jump_buffer, 1 );
    
    546
    -
    
    547
    -    /* insert new cell */
    
    548
    -    cell        = ras.cells + ras.num_cells++;
    
    549
    -    cell->x     = x;
    
    550
    -    cell->area  = ras.area;
    
    551
    -    cell->cover = ras.cover;
    
    552
    -
    
    553
    -    cell->next  = *pcell;
    
    554
    -    *pcell      = cell;
    
    555
    -
    
    556
    -    return;
    
    557
    -
    
    558
    -  Found:
    
    559
    -    /* update old cell */
    
    560
    -    cell->area  += ras.area;
    
    561
    -    cell->cover += ras.cover;
    
    562
    -  }
    
    563
    -
    
    564
    -
    
    565 521
       /**************************************************************************
    
    566 522
        *
    
    567 523
        * Set the current cell to a new position.
    
    ... ... @@ -570,9 +526,9 @@ typedef ptrdiff_t FT_PtrDist;
    570 526
       gray_set_cell( RAS_ARG_ TCoord  ex,
    
    571 527
                               TCoord  ey )
    
    572 528
       {
    
    573
    -    /* Move the cell pointer to a new position.  We set the `invalid'      */
    
    574
    -    /* flag to indicate that the cell isn't part of those we're interested */
    
    575
    -    /* in during the render phase.  This means that:                       */
    
    529
    +    /* Move the cell pointer to a new position in the linked list. We use  */
    
    530
    +    /* NULL to indicate that the cell is outside of the clipping region    */
    
    531
    +    /* during the render phase.  This means that:                          */
    
    576 532
         /*                                                                     */
    
    577 533
         /* . the new vertical position must be within min_ey..max_ey-1.        */
    
    578 534
         /* . the new horizontal position must be strictly less than max_ex     */
    
    ... ... @@ -580,17 +536,42 @@ typedef ptrdiff_t FT_PtrDist;
    580 536
         /* Note that if a cell is to the left of the clipping region, it is    */
    
    581 537
         /* actually set to the (min_ex-1) horizontal position.                 */
    
    582 538
     
    
    583
    -    /* record the current one if it is valid and substantial */
    
    584
    -    if ( !ras.invalid && ( ras.area || ras.cover ) )
    
    585
    -      gray_record_cell( RAS_VAR );
    
    539
    +    if ( ey >= ras.max_ey || ey < ras.min_ey || ex >= ras.max_ex )
    
    540
    +      ras.cell = NULL;
    
    541
    +    else
    
    542
    +    {
    
    543
    +      PCell  *pcell, cell;
    
    544
    +
    
    545
    +
    
    546
    +      ex = FT_MAX( ex, ras.min_ex - 1 );
    
    547
    +
    
    548
    +      pcell = &ras.ycells[ey - ras.min_ey];
    
    549
    +      while ( ( cell = *pcell ) )
    
    550
    +      {
    
    551
    +        if ( cell->x > ex )
    
    552
    +          break;
    
    553
    +
    
    554
    +        if ( cell->x == ex )
    
    555
    +          goto Found;
    
    586 556
     
    
    587
    -    ras.area  = 0;
    
    588
    -    ras.cover = 0;
    
    589
    -    ras.ex    = FT_MAX( ex, ras.min_ex - 1 );
    
    590
    -    ras.ey    = ey;
    
    557
    +        pcell = &cell->next;
    
    558
    +      }
    
    559
    +
    
    560
    +      if ( ras.num_cells >= ras.max_cells )
    
    561
    +        ft_longjmp( ras.jump_buffer, 1 );
    
    562
    +
    
    563
    +      /* insert new cell */
    
    564
    +      cell        = ras.cells + ras.num_cells++;
    
    565
    +      cell->x     = ex;
    
    566
    +      cell->area  = 0;
    
    567
    +      cell->cover = 0;
    
    591 568
     
    
    592
    -    ras.invalid = ( ey >= ras.max_ey || ey < ras.min_ey ||
    
    593
    -                    ex >= ras.max_ex );
    
    569
    +      cell->next  = *pcell;
    
    570
    +      *pcell      = cell;
    
    571
    +
    
    572
    +    Found:
    
    573
    +      ras.cell = cell;
    
    574
    +    }
    
    594 575
       }
    
    595 576
     
    
    596 577
     
    
    ... ... @@ -655,10 +636,9 @@ typedef ptrdiff_t FT_PtrDist;
    655 636
         /* XXX: y-delta and x-delta below should be related.            */
    
    656 637
         FT_DIV_MOD( TCoord, p, dx, delta, mod );
    
    657 638
     
    
    658
    -    ras.area  += (TArea)( ( fx1 + first ) * delta );
    
    659
    -    ras.cover += delta;
    
    660
    -    y1        += delta;
    
    661
    -    ex1       += incr;
    
    639
    +    FT_INTEGRATE( ras, delta, fx1 + first );
    
    640
    +    y1  += delta;
    
    641
    +    ex1 += incr;
    
    662 642
         gray_set_cell( RAS_VAR_ ex1, ey );
    
    663 643
     
    
    664 644
         if ( ex1 != ex2 )
    
    ... ... @@ -679,10 +659,9 @@ typedef ptrdiff_t FT_PtrDist;
    679 659
               delta++;
    
    680 660
             }
    
    681 661
     
    
    682
    -        ras.area  += (TArea)( ONE_PIXEL * delta );
    
    683
    -        ras.cover += delta;
    
    684
    -        y1        += delta;
    
    685
    -        ex1       += incr;
    
    662
    +        FT_INTEGRATE( ras, delta, ONE_PIXEL );
    
    663
    +        y1  += delta;
    
    664
    +        ex1 += incr;
    
    686 665
             gray_set_cell( RAS_VAR_ ex1, ey );
    
    687 666
           } while ( ex1 != ex2 );
    
    688 667
         }
    
    ... ... @@ -690,10 +669,7 @@ typedef ptrdiff_t FT_PtrDist;
    690 669
         fx1 = ONE_PIXEL - first;
    
    691 670
     
    
    692 671
       End:
    
    693
    -    dy = y2 - y1;
    
    694
    -
    
    695
    -    ras.area  += (TArea)( ( fx1 + fx2 ) * dy );
    
    696
    -    ras.cover += dy;
    
    672
    +    FT_INTEGRATE( ras, y2 - y1, fx1 + fx2 );
    
    697 673
       }
    
    698 674
     
    
    699 675
     
    
    ... ... @@ -736,7 +712,6 @@ typedef ptrdiff_t FT_PtrDist;
    736 712
         {
    
    737 713
           TCoord  ex     = TRUNC( ras.x );
    
    738 714
           TCoord  two_fx = FRACT( ras.x ) << 1;
    
    739
    -      TArea   area;
    
    740 715
     
    
    741 716
     
    
    742 717
           if ( dy > 0)
    
    ... ... @@ -750,27 +725,23 @@ typedef ptrdiff_t FT_PtrDist;
    750 725
             incr  = -1;
    
    751 726
           }
    
    752 727
     
    
    753
    -      delta      = first - fy1;
    
    754
    -      ras.area  += (TArea)two_fx * delta;
    
    755
    -      ras.cover += delta;
    
    756
    -      ey1       += incr;
    
    728
    +      delta = first - fy1;
    
    729
    +      FT_INTEGRATE( ras, delta, two_fx);
    
    730
    +      ey1 += incr;
    
    757 731
     
    
    758 732
           gray_set_cell( RAS_VAR_ ex, ey1 );
    
    759 733
     
    
    760 734
           delta = first + first - ONE_PIXEL;
    
    761
    -      area  = (TArea)two_fx * delta;
    
    762 735
           while ( ey1 != ey2 )
    
    763 736
           {
    
    764
    -        ras.area  += area;
    
    765
    -        ras.cover += delta;
    
    766
    -        ey1       += incr;
    
    737
    +        FT_INTEGRATE( ras, delta, two_fx);
    
    738
    +        ey1 += incr;
    
    767 739
     
    
    768 740
             gray_set_cell( RAS_VAR_ ex, ey1 );
    
    769 741
           }
    
    770 742
     
    
    771
    -      delta      = fy2 - ONE_PIXEL + first;
    
    772
    -      ras.area  += (TArea)two_fx * delta;
    
    773
    -      ras.cover += delta;
    
    743
    +      delta = fy2 - ONE_PIXEL + first;
    
    744
    +      FT_INTEGRATE( ras, delta, two_fx);
    
    774 745
     
    
    775 746
           goto End;
    
    776 747
         }
    
    ... ... @@ -883,8 +854,7 @@ typedef ptrdiff_t FT_PtrDist;
    883 854
             do
    
    884 855
             {
    
    885 856
               fy2 = ONE_PIXEL;
    
    886
    -          ras.cover += ( fy2 - fy1 );
    
    887
    -          ras.area  += ( fy2 - fy1 ) * fx1 * 2;
    
    857
    +          FT_INTEGRATE( ras, fy2 - fy1, fx1 * 2 );
    
    888 858
               fy1 = 0;
    
    889 859
               ey1++;
    
    890 860
               gray_set_cell( RAS_VAR_ ex1, ey1 );
    
    ... ... @@ -893,8 +863,7 @@ typedef ptrdiff_t FT_PtrDist;
    893 863
             do
    
    894 864
             {
    
    895 865
               fy2 = 0;
    
    896
    -          ras.cover += ( fy2 - fy1 );
    
    897
    -          ras.area  += ( fy2 - fy1 ) * fx1 * 2;
    
    866
    +          FT_INTEGRATE( ras, fy2 - fy1, fx1 * 2 );
    
    898 867
               fy1 = ONE_PIXEL;
    
    899 868
               ey1--;
    
    900 869
               gray_set_cell( RAS_VAR_ ex1, ey1 );
    
    ... ... @@ -918,8 +887,7 @@ typedef ptrdiff_t FT_PtrDist;
    918 887
               fx2 = 0;
    
    919 888
               fy2 = FT_UDIV( -prod, -dx );
    
    920 889
               prod -= dy * ONE_PIXEL;
    
    921
    -          ras.cover += ( fy2 - fy1 );
    
    922
    -          ras.area  += ( fy2 - fy1 ) * ( fx1 + fx2 );
    
    890
    +          FT_INTEGRATE( ras, fy2 - fy1, fx1 + fx2 );
    
    923 891
               fx1 = ONE_PIXEL;
    
    924 892
               fy1 = fy2;
    
    925 893
               ex1--;
    
    ... ... @@ -930,8 +898,7 @@ typedef ptrdiff_t FT_PtrDist;
    930 898
               prod -= dx * ONE_PIXEL;
    
    931 899
               fx2 = FT_UDIV( -prod, dy );
    
    932 900
               fy2 = ONE_PIXEL;
    
    933
    -          ras.cover += ( fy2 - fy1 );
    
    934
    -          ras.area  += ( fy2 - fy1 ) * ( fx1 + fx2 );
    
    901
    +          FT_INTEGRATE( ras, fy2 - fy1, fx1 + fx2 );
    
    935 902
               fx1 = fx2;
    
    936 903
               fy1 = 0;
    
    937 904
               ey1++;
    
    ... ... @@ -942,8 +909,7 @@ typedef ptrdiff_t FT_PtrDist;
    942 909
               prod += dy * ONE_PIXEL;
    
    943 910
               fx2 = ONE_PIXEL;
    
    944 911
               fy2 = FT_UDIV( prod, dx );
    
    945
    -          ras.cover += ( fy2 - fy1 );
    
    946
    -          ras.area  += ( fy2 - fy1 ) * ( fx1 + fx2 );
    
    912
    +          FT_INTEGRATE( ras, fy2 - fy1, fx1 + fx2 );
    
    947 913
               fx1 = 0;
    
    948 914
               fy1 = fy2;
    
    949 915
               ex1++;
    
    ... ... @@ -954,8 +920,7 @@ typedef ptrdiff_t FT_PtrDist;
    954 920
               fx2 = FT_UDIV( prod, -dy );
    
    955 921
               fy2 = 0;
    
    956 922
               prod += dx * ONE_PIXEL;
    
    957
    -          ras.cover += ( fy2 - fy1 );
    
    958
    -          ras.area  += ( fy2 - fy1 ) * ( fx1 + fx2 );
    
    923
    +          FT_INTEGRATE( ras, fy2 - fy1, fx1 + fx2 );
    
    959 924
               fx1 = fx2;
    
    960 925
               fy1 = ONE_PIXEL;
    
    961 926
               ey1--;
    
    ... ... @@ -968,8 +933,7 @@ typedef ptrdiff_t FT_PtrDist;
    968 933
         fx2 = FRACT( to_x );
    
    969 934
         fy2 = FRACT( to_y );
    
    970 935
     
    
    971
    -    ras.cover += ( fy2 - fy1 );
    
    972
    -    ras.area  += ( fy2 - fy1 ) * ( fx1 + fx2 );
    
    936
    +    FT_INTEGRATE( ras, fy2 - fy1, fx1 + fx2 );
    
    973 937
     
    
    974 938
       End:
    
    975 939
         ras.x       = to_x;
    
    ... ... @@ -1645,9 +1609,6 @@ typedef ptrdiff_t FT_PtrDist;
    1645 1609
           if ( continued )
    
    1646 1610
             FT_Trace_Enable();
    
    1647 1611
     
    
    1648
    -      if ( !ras.invalid )
    
    1649
    -        gray_record_cell( RAS_VAR );
    
    1650
    -
    
    1651 1612
           FT_TRACE7(( "band [%d..%d]: %ld cell%s\n",
    
    1652 1613
                       ras.min_ey,
    
    1653 1614
                       ras.max_ey,
    
    ... ... @@ -1716,7 +1677,7 @@ typedef ptrdiff_t FT_PtrDist;
    1716 1677
             FT_MEM_ZERO( ras.ycells, height * sizeof ( PCell ) );
    
    1717 1678
     
    
    1718 1679
             ras.num_cells = 0;
    
    1719
    -        ras.invalid   = 1;
    
    1680
    +        ras.cell      = NULL;
    
    1720 1681
             ras.min_ey    = band[1];
    
    1721 1682
             ras.max_ey    = band[0];
    
    1722 1683
     
    


  • reply via email to

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