[smooth] Faster fractions.

* src/smooth/ftgrays.c (SUBPIXELS): Replace with...
(FRACT): A fractional coordinate macro to use in...
(gray_render_line, gray_render_scanline): ... here.
This commit is contained in:
Alexei Podtelezhnikov 2019-05-08 22:08:40 -04:00
parent 0c6f61ab12
commit bc3b5281ed
2 changed files with 30 additions and 21 deletions

View File

@ -1,3 +1,11 @@
2019-05-08 Alexei Podtelezhnikov <apodtele@gmail.com>
[smooth] Faster fractions.
* src/smooth/ftgrays.c (SUBPIXELS): Replace with...
(FRACT): A fractional coordinate macro to use in...
(gray_render_line, gray_render_scanline): ... here.
2019-05-07 Alexei Podtelezhnikov <apodtele@gmail.com>
* src/raster/ftraster.c (Draw_Sweep): Unbreak.

View File

@ -328,8 +328,8 @@ typedef ptrdiff_t FT_PtrDist;
#define PIXEL_BITS 8
#define ONE_PIXEL ( 1 << PIXEL_BITS )
#define TRUNC( x ) ( (TCoord)( (x) >> PIXEL_BITS ) )
#define SUBPIXELS( x ) ( (TPos)(x) * ONE_PIXEL )
#define TRUNC( x ) (TCoord)( (x) >> PIXEL_BITS )
#define FRACT( x ) (TCoord)( (x) & ( ONE_PIXEL - 1 ) )
#if PIXEL_BITS >= 6
#define UPSCALE( x ) ( (x) * ( ONE_PIXEL >> 6 ) )
@ -380,9 +380,9 @@ typedef ptrdiff_t FT_PtrDist;
#define FT_UDIVPREP( c, b ) \
long b ## _r = c ? (long)( FT_ULONG_MAX >> PIXEL_BITS ) / ( b ) \
: 0
#define FT_UDIV( a, b ) \
( ( (unsigned long)( a ) * (unsigned long)( b ## _r ) ) >> \
( sizeof( long ) * FT_CHAR_BIT - PIXEL_BITS ) )
#define FT_UDIV( a, b ) \
(TCoord)( ( (unsigned long)( a ) * (unsigned long)( b ## _r ) ) >> \
( sizeof( long ) * FT_CHAR_BIT - PIXEL_BITS ) )
/**************************************************************************
@ -610,8 +610,8 @@ typedef ptrdiff_t FT_PtrDist;
return;
}
fx1 = (TCoord)( x1 - SUBPIXELS( ex1 ) );
fx2 = (TCoord)( x2 - SUBPIXELS( ex2 ) );
fx1 = FRACT( x1 );
fx2 = FRACT( x2 );
/* everything is located in a single cell. That is easy! */
/* */
@ -703,8 +703,8 @@ typedef ptrdiff_t FT_PtrDist;
( ey1 < ras.min_ey && ey2 < ras.min_ey ) )
goto End;
fy1 = (TCoord)( ras.y - SUBPIXELS( ey1 ) );
fy2 = (TCoord)( to_y - SUBPIXELS( ey2 ) );
fy1 = FRACT( ras.y );
fy2 = FRACT( to_y );
/* everything is on a single scanline */
if ( ey1 == ey2 )
@ -720,7 +720,7 @@ typedef ptrdiff_t FT_PtrDist;
if ( dx == 0 )
{
TCoord ex = TRUNC( ras.x );
TCoord two_fx = (TCoord)( ( ras.x - SUBPIXELS( ex ) ) << 1 );
TCoord two_fx = FRACT( ras.x ) << 1;
TArea area;
@ -831,8 +831,9 @@ typedef ptrdiff_t FT_PtrDist;
gray_render_line( RAS_ARG_ TPos to_x,
TPos to_y )
{
TPos dx, dy, fx1, fy1, fx2, fy2;
TCoord ex1, ex2, ey1, ey2;
TPos dx, dy;
TCoord fx1, fy1, fx2, fy2;
TCoord ex1, ey1, ex2, ey2;
ey1 = TRUNC( ras.y );
@ -846,8 +847,8 @@ typedef ptrdiff_t FT_PtrDist;
ex1 = TRUNC( ras.x );
ex2 = TRUNC( to_x );
fx1 = ras.x - SUBPIXELS( ex1 );
fy1 = ras.y - SUBPIXELS( ey1 );
fx1 = FRACT( ras.x );
fy1 = FRACT( ras.y );
dx = to_x - ras.x;
dy = to_y - ras.y;
@ -884,7 +885,7 @@ typedef ptrdiff_t FT_PtrDist;
}
else /* any other line */
{
TPos prod = dx * fy1 - dy * fx1;
TPos prod = dx * (TPos)fy1 - dy * (TPos)fx1;
FT_UDIVPREP( ex1 != ex2, dx );
FT_UDIVPREP( ey1 != ey2, dy );
@ -898,7 +899,7 @@ typedef ptrdiff_t FT_PtrDist;
prod - dx * ONE_PIXEL > 0 ) /* left */
{
fx2 = 0;
fy2 = (TPos)FT_UDIV( -prod, -dx );
fy2 = FT_UDIV( -prod, -dx );
prod -= dy * ONE_PIXEL;
ras.cover += ( fy2 - fy1 );
ras.area += ( fy2 - fy1 ) * ( fx1 + fx2 );
@ -910,7 +911,7 @@ typedef ptrdiff_t FT_PtrDist;
prod - dx * ONE_PIXEL + dy * ONE_PIXEL > 0 ) /* up */
{
prod -= dx * ONE_PIXEL;
fx2 = (TPos)FT_UDIV( -prod, dy );
fx2 = FT_UDIV( -prod, dy );
fy2 = ONE_PIXEL;
ras.cover += ( fy2 - fy1 );
ras.area += ( fy2 - fy1 ) * ( fx1 + fx2 );
@ -923,7 +924,7 @@ typedef ptrdiff_t FT_PtrDist;
{
prod += dy * ONE_PIXEL;
fx2 = ONE_PIXEL;
fy2 = (TPos)FT_UDIV( prod, dx );
fy2 = FT_UDIV( prod, dx );
ras.cover += ( fy2 - fy1 );
ras.area += ( fy2 - fy1 ) * ( fx1 + fx2 );
fx1 = 0;
@ -933,7 +934,7 @@ typedef ptrdiff_t FT_PtrDist;
else /* ( prod + dy * ONE_PIXEL < 0 &&
prod > 0 ) down */
{
fx2 = (TPos)FT_UDIV( prod, -dy );
fx2 = FT_UDIV( prod, -dy );
fy2 = 0;
prod += dx * ONE_PIXEL;
ras.cover += ( fy2 - fy1 );
@ -947,8 +948,8 @@ typedef ptrdiff_t FT_PtrDist;
} while ( ex1 != ex2 || ey1 != ey2 );
}
fx2 = to_x - SUBPIXELS( ex2 );
fy2 = to_y - SUBPIXELS( ey2 );
fx2 = FRACT( to_x );
fy2 = FRACT( to_y );
ras.cover += ( fy2 - fy1 );
ras.area += ( fy2 - fy1 ) * ( fx1 + fx2 );