freetype-commit
[Top][All Lists]
Advanced

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

[Git][freetype/freetype-demos][master] [ftsdf] Synchronize with the chan


From: Anuj Verma (@anujv)
Subject: [Git][freetype/freetype-demos][master] [ftsdf] Synchronize with the change made in the `sdf` renderer.
Date: Tue, 08 Jun 2021 03:00:43 +0000

Anuj Verma pushed to branch master at FreeType / FreeType Demo Programs

Commits:

2 changed files:

Changes:

  • ChangeLog
    1
    +2021-06-06  Anuj Verma  <anujv@iitbhilai.ac.in>
    
    2
    +
    
    3
    +	[ftsdf] Synchronize with the change made in the `sdf` renderer.
    
    4
    +
    
    5
    +	* src/ftsdf.c (draw): Change logic to utilize 8bit SDF instead of 16.
    
    6
    +
    
    1 7
     2021-06-04  Alexei Podtelezhnikov  <apodtele@gmail.com>
    
    2 8
     
    
    3 9
     	* graph/gblender.c (gblender_dump_stats): Fix the lookup rate.
    

  • src/ftsdf.c
    ... ... @@ -426,6 +426,15 @@
    426 426
       }
    
    427 427
     
    
    428 428
     
    
    429
    +  /* Convert normalized unsigned distance values to signed pixel */
    
    430
    +  /* values, also cast the values to floating point.             */
    
    431
    +  static float
    
    432
    +  map_sdf_to_float( FT_Byte value )
    
    433
    +  {
    
    434
    +    float signed_dist = (float)value - 128.0f;
    
    435
    +    return ( signed_dist / 128.0f ) * (float)status.spread;
    
    436
    +  }
    
    437
    +
    
    429 438
       /* Draw an SDF image to the display. */
    
    430 439
       static FT_Error
    
    431 440
       draw( void )
    
    ... ... @@ -436,7 +445,7 @@
    436 445
         Box  sample_region;
    
    437 446
     
    
    438 447
         Vec2       center;
    
    439
    -    FT_Short*  buffer;
    
    448
    +    FT_Byte*   buffer;
    
    440 449
     
    
    441 450
     
    
    442 451
         if ( !bitmap || !bitmap->buffer )
    
    ... ... @@ -496,7 +505,7 @@
    496 505
           draw_region.xMax    = display->bitmap->width;
    
    497 506
         }
    
    498 507
     
    
    499
    -    buffer = (FT_Short*)bitmap->buffer;
    
    508
    +    buffer = (FT_Byte*)bitmap->buffer;
    
    500 509
     
    
    501 510
         /* Finally loop over all pixels inside the draw region        */
    
    502 511
         /* and copy pixels from the sample region to the draw region. */
    
    ... ... @@ -514,14 +523,14 @@
    514 523
     
    
    515 524
             if ( status.nearest_filtering )
    
    516 525
             {
    
    517
    -          FT_UInt   bitmap_index = ( y / status.scale ) * bitmap->width +
    
    518
    -                                     x / status.scale;
    
    519
    -          FT_Short  pixel_value  = buffer[bitmap_index];
    
    526
    +          FT_UInt  bitmap_index = ( y / status.scale ) * bitmap->width +
    
    527
    +                                    x / status.scale;
    
    528
    +          FT_Byte  pixel_value  = buffer[bitmap_index];
    
    520 529
     
    
    521 530
     
    
    522 531
               /* If nearest filtering then simply take the value of the */
    
    523 532
               /* nearest sampling pixel.                                */
    
    524
    -          min_dist = (float)pixel_value / 1024.0f;
    
    533
    +          min_dist = map_sdf_to_float( pixel_value );
    
    525 534
             }
    
    526 535
             else
    
    527 536
             {
    
    ... ... @@ -560,22 +569,22 @@
    560 569
               indc[2] = (int)bi_y * width + (int)bi_x + 1;
    
    561 570
               indc[3] = ( (int)bi_y + 1 ) * width + (int)bi_x + 1;
    
    562 571
     
    
    563
    -          dist[0] = (float)buffer[indc[0]] / 1024.0f;
    
    572
    +          dist[0] = map_sdf_to_float( buffer[indc[0]] );
    
    564 573
     
    
    565 574
               if ( indc[1] >= width * rows )
    
    566 575
                 dist[1] = -status.spread;
    
    567 576
               else
    
    568
    -            dist[1] = (float)buffer[indc[1]] / 1024.0f;
    
    577
    +            dist[1] = map_sdf_to_float( buffer[indc[1]] );
    
    569 578
     
    
    570 579
               if ( indc[2] >= width * rows )
    
    571 580
                 dist[2] = -status.spread;
    
    572 581
               else
    
    573
    -            dist[2] = (float)buffer[indc[2]] / 1024.0f;
    
    582
    +            dist[2] = map_sdf_to_float( buffer[indc[2]] );
    
    574 583
     
    
    575 584
               if ( indc[3] >= width * rows )
    
    576 585
                 dist[3] = -status.spread;
    
    577 586
               else
    
    578
    -            dist[3] = (float)buffer[indc[3]] / 1024.0f;
    
    587
    +            dist[3] = map_sdf_to_float( buffer[indc[3]] );
    
    579 588
     
    
    580 589
               m1 = dist[0] * ( 1.0f - nbi_y ) + dist[1] * nbi_y;
    
    581 590
               m2 = dist[2] * ( 1.0f - nbi_y ) + dist[3] * nbi_y;
    
    ... ... @@ -613,12 +622,11 @@
    613 622
               /* If not reconstructing then normalize the values between */
    
    614 623
               /* [0, 255] and copy to the display buffer.                */
    
    615 624
     
    
    616
    -          /* normalize using `status.spread` */
    
    625
    +          /* get absolute distance */
    
    617 626
               final_dist  = final_dist < 0 ? -final_dist : final_dist;
    
    618
    -          final_dist /= (float)status.spread;
    
    619 627
     
    
    620 628
               /* invert the values */
    
    621
    -          final_dist  = 1.0f - final_dist;
    
    629
    +          final_dist  = 1.0f - final_dist / status.spread;
    
    622 630
               final_dist *= 255;
    
    623 631
     
    
    624 632
               /* finally copy the target value to the display buffer */
    
    ... ... @@ -664,9 +672,7 @@
    664 672
         FT_Error  err       = FT_Err_Ok;
    
    665 673
         char*     exec_name = NULL;
    
    666 674
     
    
    667
    -#ifdef __linux__
    
    668 675
         int  flip_y = 1;
    
    669
    -#endif
    
    670 676
     
    
    671 677
     
    
    672 678
         exec_name = ft_basename( argv[0] );
    
    ... ... @@ -690,10 +696,8 @@
    690 696
           goto Exit;
    
    691 697
         }
    
    692 698
     
    
    693
    -#ifdef __linux__
    
    694 699
         FT_CALL( FT_Property_Set( handle->library, "sdf", "flip_y", &flip_y ) );
    
    695 700
         FT_CALL( FT_Property_Set( handle->library, "bsdf", "flip_y", &flip_y ) );
    
    696
    -#endif
    
    697 701
     
    
    698 702
         grSetTitle( display->surface, "Signed Distance Field Viewer" );
    
    699 703
         event_color_change();
    


  • reply via email to

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