diff options
Diffstat (limited to 'src/smooth/ftgrays.c')
-rw-r--r-- | src/smooth/ftgrays.c | 100 |
1 files changed, 51 insertions, 49 deletions
diff --git a/src/smooth/ftgrays.c b/src/smooth/ftgrays.c index e9a3ce7a7..803a19e41 100644 --- a/src/smooth/ftgrays.c +++ b/src/smooth/ftgrays.c @@ -4,7 +4,7 @@ /* */ /* A new `perfect' anti-aliasing renderer (body). */ /* */ -/* Copyright 2000-2017 by */ +/* Copyright 2000-2018 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -141,6 +141,16 @@ #define FT_INT_MAX INT_MAX #define FT_ULONG_MAX ULONG_MAX +#define ADD_LONG( a, b ) \ + (long)( (unsigned long)(a) + (unsigned long)(b) ) +#define SUB_LONG( a, b ) \ + (long)( (unsigned long)(a) - (unsigned long)(b) ) +#define MUL_LONG( a, b ) \ + (long)( (unsigned long)(a) * (unsigned long)(b) ) +#define NEG_LONG( a ) \ + (long)( -(unsigned long)(a) ) + + #define ft_memset memset #define ft_setjmp setjmp @@ -264,6 +274,7 @@ typedef ptrdiff_t FT_PtrDist; #include "ftgrays.h" #include FT_INTERNAL_OBJECTS_H #include FT_INTERNAL_DEBUG_H +#include FT_INTERNAL_CALC_H #include FT_OUTLINE_H #include "ftsmerrs.h" @@ -359,7 +370,7 @@ typedef ptrdiff_t FT_PtrDist; /* optimize a division and modulo operation on the same parameters */ /* into a single call to `__aeabi_idivmod'. See */ /* */ - /* http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43721 */ + /* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43721 */ #undef FT_DIV_MOD #define FT_DIV_MOD( type, dividend, divisor, quotient, remainder ) \ FT_BEGIN_STMNT \ @@ -393,7 +404,7 @@ typedef ptrdiff_t FT_PtrDist; /* need to define them to "float" or "double" when experimenting with */ /* new algorithms */ - typedef long TPos; /* sub-pixel coordinate */ + typedef long TPos; /* subpixel coordinate */ typedef int TCoord; /* integer scanline/pixel coordinate */ typedef int TArea; /* cell areas, coordinate products */ @@ -571,8 +582,8 @@ typedef ptrdiff_t FT_PtrDist; if ( ex < ras.min_ex ) ex = ras.min_ex - 1; - /* record the current one if it is valid */ - if ( !ras.invalid ) + /* record the current one if it is valid and substantial */ + if ( !ras.invalid && ( ras.area || ras.cover ) ) gray_record_cell( RAS_VAR ); ras.area = 0; @@ -1135,7 +1146,7 @@ typedef ptrdiff_t FT_PtrDist; /* s is L * the perpendicular distance from P1 to the line P0-P3. */ dx1 = arc[1].x - arc[0].x; dy1 = arc[1].y - arc[0].y; - s = FT_ABS( dy * dx1 - dx * dy1 ); + s = FT_ABS( SUB_LONG( MUL_LONG( dy, dx1 ), MUL_LONG( dx, dy1 ) ) ); if ( s > s_limit ) goto Split; @@ -1143,7 +1154,7 @@ typedef ptrdiff_t FT_PtrDist; /* s is L * the perpendicular distance from P2 to the line P0-P3. */ dx2 = arc[2].x - arc[0].x; dy2 = arc[2].y - arc[0].y; - s = FT_ABS( dy * dx2 - dx * dy2 ); + s = FT_ABS( SUB_LONG( MUL_LONG( dy, dx2 ), MUL_LONG( dx, dy2 ) ) ); if ( s > s_limit ) goto Split; @@ -1289,8 +1300,6 @@ typedef ptrdiff_t FT_PtrDist; int y; - FT_TRACE7(( "gray_sweep: start\n" )); - for ( y = ras.min_ey; y < ras.max_ey; y++ ) { PCell cell = ras.ycells[y - ras.min_ey]; @@ -1316,8 +1325,6 @@ typedef ptrdiff_t FT_PtrDist; if ( cover != 0 ) gray_hline( RAS_VAR_ x, y, cover, ras.max_ex - x ); } - - FT_TRACE7(( "gray_sweep: end\n" )); } @@ -1711,8 +1718,11 @@ typedef ptrdiff_t FT_PtrDist; if ( !ras.invalid ) gray_record_cell( RAS_VAR ); - FT_TRACE7(( "band [%d..%d]: %d cells\n", - ras.min_ey, ras.max_ey, ras.num_cells )); + FT_TRACE7(( "band [%d..%d]: %d cell%s\n", + ras.min_ey, + ras.max_ey, + ras.num_cells, + ras.num_cells == 1 ? "" : "s" )); } else { @@ -1729,35 +1739,43 @@ typedef ptrdiff_t FT_PtrDist; static int gray_convert_glyph( RAS_ARG ) { + const TCoord yMin = ras.min_ey; + const TCoord yMax = ras.max_ey; + const TCoord xMin = ras.min_ex; + const TCoord xMax = ras.max_ex; + TCell buffer[FT_MAX_GRAY_POOL]; - TCoord band_size = FT_MAX_GRAY_POOL / 8; - TCoord count = ras.max_ey - ras.min_ey; - int num_bands; - TCoord min, max, max_y; + size_t height = (size_t)( yMax - yMin ); + size_t n = FT_MAX_GRAY_POOL / 8; + TCoord y; TCoord bands[32]; /* enough to accommodate bisections */ TCoord* band; /* set up vertical bands */ - if ( count > band_size ) + if ( height > n ) { /* two divisions rounded up */ - num_bands = (int)( ( count + band_size - 1) / band_size ); - band_size = ( count + num_bands - 1 ) / num_bands; + n = ( height + n - 1 ) / n; + height = ( height + n - 1 ) / n; } - min = ras.min_ey; - max_y = ras.max_ey; + /* memory management */ + n = ( height * sizeof ( PCell ) + sizeof ( TCell ) - 1 ) / sizeof ( TCell ); + + ras.cells = buffer + n; + ras.max_cells = (FT_PtrDist)( FT_MAX_GRAY_POOL - n ); + ras.ycells = (PCell*)buffer; - for ( ; min < max_y; min = max ) + for ( y = yMin; y < yMax; ) { - max = min + band_size; - if ( max > max_y ) - max = max_y; + ras.min_ey = y; + y += height; + ras.max_ey = FT_MIN( y, yMax ); band = bands; - band[1] = min; - band[0] = max; + band[1] = xMin; + band[0] = xMax; do { @@ -1765,27 +1783,12 @@ typedef ptrdiff_t FT_PtrDist; int error; - /* memory management */ - { - size_t ycount = (size_t)width; - size_t cell_start; - - - cell_start = ( ycount * sizeof ( PCell ) + sizeof ( TCell ) - 1 ) / - sizeof ( TCell ); - - ras.cells = buffer + cell_start; - ras.max_cells = (FT_PtrDist)( FT_MAX_GRAY_POOL - cell_start ); - ras.num_cells = 0; - - ras.ycells = (PCell*)buffer; - while ( ycount ) - ras.ycells[--ycount] = NULL; - } + FT_MEM_ZERO( ras.ycells, height * sizeof ( PCell ) ); + ras.num_cells = 0; ras.invalid = 1; - ras.min_ey = band[1]; - ras.max_ey = band[0]; + ras.min_ex = band[1]; + ras.max_ex = band[0]; error = gray_convert_glyph_inner( RAS_VAR ); @@ -1801,8 +1804,7 @@ typedef ptrdiff_t FT_PtrDist; /* render pool overflow; we will reduce the render band by half */ width >>= 1; - /* This is too complex for a single scanline; there must */ - /* be some problems. */ + /* this should never happen even with tiny rendering pool */ if ( width == 0 ) { FT_TRACE7(( "gray_convert_glyph: rotten glyph\n" )); |