freetype-commit
[Top][All Lists]
Advanced

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

[freetype2] anuj-distance-field d7a2e99 93/93: [sdf -> bsdf] Fixed a bug


From: Anuj Verma
Subject: [freetype2] anuj-distance-field d7a2e99 93/93: [sdf -> bsdf] Fixed a bug with `finalize_sdf'.
Date: Sun, 2 Aug 2020 07:04:31 -0400 (EDT)

branch: anuj-distance-field
commit d7a2e99bb0a2ff3eaca3ec397ab38f310e7131dc
Author: Anuj Verma <anujv@iitbhilai.ac.in>
Commit: anujverma <anujv@iitbhilai.ac.in>

    [sdf -> bsdf] Fixed a bug with `finalize_sdf'.
    
    * src/sdf/ftbsdf.c (finalize_sdf): First check if the
      value is withing [-spread, spread] and then cast it
      to 6.10 short, otherwise the value can overflow and
      give negative result.
      Also, flip the sign if the property `flip_sign' is
      set to true.
---
 [GSoC]ChangeLog  | 11 +++++++++++
 src/sdf/ftbsdf.c | 21 +++++++++++++++------
 2 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/[GSoC]ChangeLog b/[GSoC]ChangeLog
index 9a1e982..05f202c 100644
--- a/[GSoC]ChangeLog
+++ b/[GSoC]ChangeLog
@@ -1,3 +1,14 @@
+2020-08-2  Anuj Verma  <anujv@iitbhilai.ac.in>
+
+       [sdf -> bsdf] Fixed a bug with `finalize_sdf'.
+
+       * src/sdf/ftbsdf.c (finalize_sdf): First check if the
+         value is withing [-spread, spread] and then cast it
+         to 6.10 short, otherwise the value can overflow and
+         give negative result.
+         Also, flip the sign if the property `flip_sign' is
+         set to true.
+
 2020-08-1  Anuj Verma  <anujv@iitbhilai.ac.in>
 
        [sdf -> bsdf] Added option to use squared distances.
diff --git a/src/sdf/ftbsdf.c b/src/sdf/ftbsdf.c
index 7e4d5e0..d70c9be 100644
--- a/src/sdf/ftbsdf.c
+++ b/src/sdf/ftbsdf.c
@@ -769,6 +769,7 @@
     FT_Int     w, r;
     FT_Int     i, j;
     FT_6D10*   t_buffer;
+    FT_16D16   spread;
 
     if ( !worker || !target )
     {
@@ -787,6 +788,13 @@
       goto Exit;      
     }
 
+  #if USE_SQUARED_DISTANCES
+    spread = FT_INT_16D16( worker->params.spread *
+                           worker->params.spread );
+  #else
+    spread = FT_INT_16D16( worker->params.spread );
+  #endif
+
     for ( j = 0; j < r; j++ )
     {
       for ( i = 0; i < w; i++ )
@@ -800,10 +808,10 @@
         index = j * w + i;
         dist = worker->distance_map[index].dist;
 
+        if ( dist < 0 || dist > spread )
+          dist = spread;
+
   #if USE_SQUARED_DISTANCES
-        if ( dist < 0 )
-          dist = FT_INT_16D16( worker->params.spread );
-        else
           dist = square_root( dist );
   #endif
 
@@ -811,13 +819,14 @@
         dist /= 64;
         final_dist = (FT_6D10)(dist & 0x0000FFFF);
 
-        if ( final_dist > worker->params.spread * 1024 )
-          final_dist = worker->params.spread * 1024;
-
         /* We assume that if the pixel is inside a contour */
         /* then it's coverage value must be > 127.         */
         sign = worker->distance_map[index].alpha < 127 ? -1 : 1;
 
+        /* flip the sign according to the property */
+        if ( worker->params.flip_sign )
+          sign = -sign;
+
         t_buffer[index] = final_dist * sign;
       }
     }



reply via email to

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