summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnuj Verma <anujv@iitbhilai.ac.in>2020-08-02 08:22:51 +0530
committeranujverma <anujv@iitbhilai.ac.in>2020-08-02 16:33:22 +0530
commitd7a2e99bb0a2ff3eaca3ec397ab38f310e7131dc (patch)
tree816c1a53c2dceed05bf293a87648ea6ed0fb8b9a
parenta62fd640f351267ca40348de079747371b07ce39 (diff)
downloadfreetype2-d7a2e99bb0a2ff3eaca3ec397ab38f310e7131dc.tar.gz
[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.
-rw-r--r--[GSoC]ChangeLog11
-rw-r--r--src/sdf/ftbsdf.c21
2 files changed, 26 insertions, 6 deletions
diff --git a/[GSoC]ChangeLog b/[GSoC]ChangeLog
index 9a1e98250..05f202c5e 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 7e4d5e01c..d70c9be1d 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;
}
}