[base] Fix `ft_corner_orientation'.

Remove casting from `FT_Long' to `FT_Int' that might change the sign
of the return value and make it faster too.

* src/base/ftcalc.c (ft_corner_orientation): On 32-bit systems, stay
with 32-bit arithmetic when safe. Use plain math on 64-bit systems.
* src/pshinter/pshalgo.c: Remove old unused code.
This commit is contained in:
Alexei Podtelezhnikov 2015-08-03 23:26:13 -04:00
parent 8dfc760161
commit 7e6c321a58
3 changed files with 35 additions and 136 deletions

View File

@ -1,3 +1,14 @@
2015-08-03 Alexei Podtelezhnikov <apodtele@gmail.com>
[base] Fix `ft_corner_orientation'.
Remove casting from `FT_Long' to `FT_Int' that might change the sign
of the return value and make it faster too.
* src/base/ftcalc.c (ft_corner_orientation): On 32-bit systems, stay
with 32-bit arithmetic when safe. Use plain math on 64-bit systems.
* src/pshinter/pshalgo.c: Remove old unused code.
2015-08-03 Werner Lemberg <wl@gnu.org>
* src/truetype/ttgload.c (load_truetype_glyph)

View File

@ -928,52 +928,34 @@
FT_Pos out_x,
FT_Pos out_y )
{
FT_Long result; /* avoid overflow on 16-bit system */
/* deal with the trivial cases quickly */
if ( in_y == 0 )
{
if ( in_x >= 0 )
result = out_y;
else
result = -out_y;
}
else if ( in_x == 0 )
{
if ( in_y >= 0 )
result = -out_x;
else
result = out_x;
}
else if ( out_y == 0 )
{
if ( out_x >= 0 )
result = in_y;
else
result = -in_y;
}
else if ( out_x == 0 )
{
if ( out_y >= 0 )
result = -in_x;
else
result = in_x;
}
else /* general case */
{
#ifdef FT_LONG64
FT_Int64 delta = (FT_Int64)in_x * out_y - (FT_Int64)in_y * out_x;
FT_Int64 delta = (FT_Int64)in_x * out_y - (FT_Int64)in_y * out_x;
if ( delta == 0 )
result = 0;
else
result = 1 - 2 * ( delta < 0 );
return ( delta > 0 ) - ( delta < 0 );
#else
FT_Int result;
if ( (FT_ULong)FT_ABS( in_x ) + (FT_ULong)FT_ABS( out_y ) <= 131071UL &&
(FT_ULong)FT_ABS( in_y ) + (FT_ULong)FT_ABS( out_x ) <= 131071UL )
{
FT_Long z1 = in_x * out_y;
FT_Long z2 = in_y * out_x;
if ( z1 > z2 )
result = +1;
else if ( z1 < z2 )
result = -1;
else
result = 0;
}
else /* products might overflow 32 bits */
{
FT_Int64 z1, z2;
@ -991,12 +973,12 @@
result = -1;
else
result = 0;
#endif
}
/* XXX: only the sign of return value, +1/0/-1 must be used */
return (FT_Int)result;
return result;
#endif
}

View File

@ -916,103 +916,9 @@
/*************************************************************************/
/*************************************************************************/
#if 1
#define psh_corner_is_flat ft_corner_is_flat
#define psh_corner_orientation ft_corner_orientation
#else
FT_LOCAL_DEF( FT_Int )
psh_corner_is_flat( FT_Pos x_in,
FT_Pos y_in,
FT_Pos x_out,
FT_Pos y_out )
{
FT_Pos ax = x_in;
FT_Pos ay = y_in;
FT_Pos d_in, d_out, d_corner;
if ( ax < 0 )
ax = -ax;
if ( ay < 0 )
ay = -ay;
d_in = ax + ay;
ax = x_out;
if ( ax < 0 )
ax = -ax;
ay = y_out;
if ( ay < 0 )
ay = -ay;
d_out = ax + ay;
ax = x_out + x_in;
if ( ax < 0 )
ax = -ax;
ay = y_out + y_in;
if ( ay < 0 )
ay = -ay;
d_corner = ax + ay;
return ( d_in + d_out - d_corner ) < ( d_corner >> 4 );
}
static FT_Int
psh_corner_orientation( FT_Pos in_x,
FT_Pos in_y,
FT_Pos out_x,
FT_Pos out_y )
{
FT_Int result;
/* deal with the trivial cases quickly */
if ( in_y == 0 )
{
if ( in_x >= 0 )
result = out_y;
else
result = -out_y;
}
else if ( in_x == 0 )
{
if ( in_y >= 0 )
result = -out_x;
else
result = out_x;
}
else if ( out_y == 0 )
{
if ( out_x >= 0 )
result = in_y;
else
result = -in_y;
}
else if ( out_x == 0 )
{
if ( out_y >= 0 )
result = -in_x;
else
result = in_x;
}
else /* general case */
{
long long delta = (long long)in_x * out_y - (long long)in_y * out_x;
if ( delta == 0 )
result = 0;
else
result = 1 - 2 * ( delta < 0 );
}
return result;
}
#endif /* !1 */
#ifdef COMPUTE_INFLEXS