forked from minhngoc25a/freetype2
[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.
This commit is contained in:
parent
a62fd640f3
commit
d7a2e99bb0
|
@ -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>
|
2020-08-1 Anuj Verma <anujv@iitbhilai.ac.in>
|
||||||
|
|
||||||
[sdf -> bsdf] Added option to use squared distances.
|
[sdf -> bsdf] Added option to use squared distances.
|
||||||
|
|
|
@ -769,6 +769,7 @@
|
||||||
FT_Int w, r;
|
FT_Int w, r;
|
||||||
FT_Int i, j;
|
FT_Int i, j;
|
||||||
FT_6D10* t_buffer;
|
FT_6D10* t_buffer;
|
||||||
|
FT_16D16 spread;
|
||||||
|
|
||||||
if ( !worker || !target )
|
if ( !worker || !target )
|
||||||
{
|
{
|
||||||
|
@ -787,6 +788,13 @@
|
||||||
goto Exit;
|
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 ( j = 0; j < r; j++ )
|
||||||
{
|
{
|
||||||
for ( i = 0; i < w; i++ )
|
for ( i = 0; i < w; i++ )
|
||||||
|
@ -800,10 +808,10 @@
|
||||||
index = j * w + i;
|
index = j * w + i;
|
||||||
dist = worker->distance_map[index].dist;
|
dist = worker->distance_map[index].dist;
|
||||||
|
|
||||||
|
if ( dist < 0 || dist > spread )
|
||||||
|
dist = spread;
|
||||||
|
|
||||||
#if USE_SQUARED_DISTANCES
|
#if USE_SQUARED_DISTANCES
|
||||||
if ( dist < 0 )
|
|
||||||
dist = FT_INT_16D16( worker->params.spread );
|
|
||||||
else
|
|
||||||
dist = square_root( dist );
|
dist = square_root( dist );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -811,13 +819,14 @@
|
||||||
dist /= 64;
|
dist /= 64;
|
||||||
final_dist = (FT_6D10)(dist & 0x0000FFFF);
|
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 */
|
/* We assume that if the pixel is inside a contour */
|
||||||
/* then it's coverage value must be > 127. */
|
/* then it's coverage value must be > 127. */
|
||||||
sign = worker->distance_map[index].alpha < 127 ? -1 : 1;
|
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;
|
t_buffer[index] = final_dist * sign;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue