Fix sdf computation while `USE_SQUARED_DISTANCES`. Function `map_fixed_to_sdf` expects spread to be absolute and not squared. * src/sdf/ftbsdf.c (finalize_sdf): Pass absolute spread while `map_fixed_to_sdf`. * src/sdf/ftsdf.c (sdf_generate_bounding_box): Ditto.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
diff --git a/src/sdf/ftbsdf.c b/src/sdf/ftbsdf.c
index f33330f..1328ac4 100644
--- a/src/sdf/ftbsdf.c
+++ b/src/sdf/ftbsdf.c
@@ -1096,7 +1096,7 @@
FT_Int i, j;
FT_SDFFormat* t_buffer;
- FT_16D16 spread;
+ FT_16D16 sp_sq, spread;
if ( !worker || !target )
@@ -1116,11 +1116,13 @@
goto Exit;
}
+ spread = FT_INT_16D16( worker->params.spread );
+
#if USE_SQUARED_DISTANCES
- spread = FT_INT_16D16( worker->params.spread *
- worker->params.spread );
+ sp_sq = FT_INT_16D16( worker->params.spread *
+ worker->params.spread );
#else
- spread = FT_INT_16D16( worker->params.spread );
+ sp_sq = FT_INT_16D16( worker->params.spread );
#endif
for ( j = 0; j < r; j++ )
@@ -1136,8 +1138,8 @@
index = j * w + i;
dist = worker->distance_map[index].dist;
- if ( dist < 0 || dist > spread )
- dist = spread;
+ if ( dist < 0 || dist > sp_sq )
+ dist = sp_sq;
#if USE_SQUARED_DISTANCES
dist = square_root( dist );
diff --git a/src/sdf/ftsdf.c b/src/sdf/ftsdf.c
index 46ef7b1..f5e5551 100644
--- a/src/sdf/ftsdf.c
+++ b/src/sdf/ftsdf.c
@@ -3242,7 +3242,7 @@
buffer = (FT_SDFFormat*)bitmap->buffer;
if ( USE_SQUARED_DISTANCES )
- sp_sq = fixed_spread * fixed_spread;
+ sp_sq = FT_INT_16D16( spread * spread );
else
sp_sq = fixed_spread;