Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(405)

Unified Diff: third_party/freetype/src/smooth/ftgrays.c

Issue 1416993005: Merge to XFA: Update bundled freetype to 2.6.1 (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/freetype/src/smooth/ftgrays.h ('k') | third_party/freetype/src/smooth/ftsmerrs.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/freetype/src/smooth/ftgrays.c
diff --git a/third_party/freetype/src/smooth/ftgrays.c b/third_party/freetype/src/smooth/ftgrays.c
index 9d37d64517beb14b4b475a0e5edc0a47563f3c9f..ba2944559c3335bfb05ffd4cdcb2054cd45866c9 100644
--- a/third_party/freetype/src/smooth/ftgrays.c
+++ b/third_party/freetype/src/smooth/ftgrays.c
@@ -4,7 +4,7 @@
/* */
/* A new `perfect' anti-aliasing renderer (body). */
/* */
-/* Copyright 2000-2003, 2005-2014 by */
+/* Copyright 2000-2015 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -24,8 +24,8 @@
/* */
/* - copy `src/smooth/ftgrays.c' (this file) to your current directory */
/* */
- /* - copy `include/ftimage.h' and `src/smooth/ftgrays.h' to the same */
- /* directory */
+ /* - copy `include/freetype/ftimage.h' and `src/smooth/ftgrays.h' to the */
+ /* same directory */
/* */
/* - compile `ftgrays' with the _STANDALONE_ macro defined, as in */
/* */
@@ -94,6 +94,11 @@
#ifdef _STANDALONE_
+ /* The size in bytes of the render pool used by the scan-line converter */
+ /* to do all of its work. */
+#define FT_RENDER_POOL_SIZE 16384L
+
+
/* Auxiliary macros for token concatenation. */
#define FT_ERR_XCAT( x, y ) x ## y
#define FT_ERR_CAT( x, y ) FT_ERR_XCAT( x, y )
@@ -101,6 +106,21 @@
#define FT_BEGIN_STMNT do {
#define FT_END_STMNT } while ( 0 )
+#define FT_MAX( a, b ) ( (a) > (b) ? (a) : (b) )
+#define FT_ABS( a ) ( (a) < 0 ? -(a) : (a) )
+
+
+ /*
+ * Approximate sqrt(x*x+y*y) using the `alpha max plus beta min'
+ * algorithm. We use alpha = 1, beta = 3/8, giving us results with a
+ * largest error less than 7% compared to the exact value.
+ */
+#define FT_HYPOT( x, y ) \
+ ( x = FT_ABS( x ), \
+ y = FT_ABS( y ), \
+ x > y ? x + ( 3 * y >> 3 ) \
+ : y + ( 3 * x >> 3 ) )
+
/* define this to dump debugging information */
/* #define FT_DEBUG_LEVEL_TRACE */
@@ -297,7 +317,6 @@ typedef ptrdiff_t FT_PtrDist;
#undef SCALED
#define ONE_PIXEL ( 1L << PIXEL_BITS )
-#define PIXEL_MASK ( -1L << PIXEL_BITS )
#define TRUNC( x ) ( (TCoord)( (x) >> PIXEL_BITS ) )
#define SUBPIXELS( x ) ( (TPos)(x) << PIXEL_BITS )
#define FLOOR( x ) ( (x) & -ONE_PIXEL )
@@ -405,6 +424,8 @@ typedef ptrdiff_t FT_PtrDist;
typedef struct gray_TWorker_
{
+ ft_jmp_buf jump_buffer;
+
TCoord ex, ey;
TPos min_ex, max_ex;
TPos min_ey, max_ey;
@@ -418,11 +439,8 @@ typedef ptrdiff_t FT_PtrDist;
FT_PtrDist max_cells;
FT_PtrDist num_cells;
- TCoord cx, cy;
TPos x, y;
- TPos last_ey;
-
FT_Vector bez_stack[32 * 3 + 1];
int lev_stack[32];
@@ -440,8 +458,6 @@ typedef ptrdiff_t FT_PtrDist;
int band_size;
int band_shoot;
- ft_jmp_buf jump_buffer;
-
void* buffer;
long buffer_size;
@@ -464,11 +480,7 @@ typedef ptrdiff_t FT_PtrDist;
typedef struct gray_TRaster_
{
- void* buffer;
- long buffer_size;
- int band_size;
void* memory;
- gray_PWorker worker;
} gray_TRaster, *gray_PRaster;
@@ -480,7 +492,7 @@ typedef ptrdiff_t FT_PtrDist;
/* */
static void
gray_init_cells( RAS_ARG_ void* buffer,
- long byte_size )
+ long byte_size )
{
ras.buffer = buffer;
ras.buffer_size = byte_size;
@@ -638,8 +650,8 @@ typedef ptrdiff_t FT_PtrDist;
ras.ey = ey;
}
- ras.invalid = ( (unsigned)ey >= (unsigned)ras.count_ey ||
- ex >= ras.count_ex );
+ ras.invalid = ( (unsigned int)ey >= (unsigned int)ras.count_ey ||
+ ex >= ras.count_ex );
}
@@ -661,7 +673,6 @@ typedef ptrdiff_t FT_PtrDist;
ras.cover = 0;
ras.ex = ex - ras.min_ex;
ras.ey = ey - ras.min_ey;
- ras.last_ey = SUBPIXELS( ey );
ras.invalid = 0;
gray_set_cell( RAS_VAR_ ex, ey );
@@ -742,7 +753,7 @@ typedef ptrdiff_t FT_PtrDist;
mod -= (int)dx;
- while ( ex1 != ex2 )
+ do
{
delta = lift;
mod += rem;
@@ -757,7 +768,7 @@ typedef ptrdiff_t FT_PtrDist;
y1 += delta;
ex1 += incr;
gray_set_cell( RAS_VAR_ ex1, ey );
- }
+ } while ( ex1 != ex2 );
}
delta = y2 - y1;
@@ -780,29 +791,18 @@ typedef ptrdiff_t FT_PtrDist;
int delta, rem, lift, incr;
- ey1 = TRUNC( ras.last_ey );
+ ey1 = TRUNC( ras.y );
ey2 = TRUNC( to_y ); /* if (ey2 >= ras.max_ey) ey2 = ras.max_ey-1; */
- fy1 = (TCoord)( ras.y - ras.last_ey );
+ fy1 = (TCoord)( ras.y - SUBPIXELS( ey1 ) );
fy2 = (TCoord)( to_y - SUBPIXELS( ey2 ) );
dx = to_x - ras.x;
dy = to_y - ras.y;
/* perform vertical clipping */
- {
- TCoord min, max;
-
-
- min = ey1;
- max = ey2;
- if ( ey1 > ey2 )
- {
- min = ey2;
- max = ey1;
- }
- if ( min >= ras.max_ey || max < ras.min_ey )
- goto End;
- }
+ if ( ( ey1 >= ras.max_ey && ey2 >= ras.max_ey ) ||
+ ( ey1 < ras.min_ey && ey2 < ras.min_ey ) )
+ goto End;
/* everything is on a single scanline */
if ( ey1 == ey2 )
@@ -880,7 +880,7 @@ typedef ptrdiff_t FT_PtrDist;
FT_DIV_MOD( int, p, dy, lift, rem );
mod -= (int)dy;
- while ( ey1 != ey2 )
+ do
{
delta = lift;
mod += rem;
@@ -898,7 +898,7 @@ typedef ptrdiff_t FT_PtrDist;
ey1 += incr;
gray_set_cell( RAS_VAR_ TRUNC( x ), ey1 );
- }
+ } while ( ey1 != ey2 );
}
gray_render_scanline( RAS_VAR_ ey1, x,
@@ -908,7 +908,6 @@ typedef ptrdiff_t FT_PtrDist;
End:
ras.x = to_x;
ras.y = to_y;
- ras.last_ey = SUBPIXELS( ey2 );
}
@@ -1212,7 +1211,7 @@ typedef ptrdiff_t FT_PtrDist;
/* first of all, compute the scanline offset */
p = (unsigned char*)map->buffer - y * map->pitch;
if ( map->pitch >= 0 )
- p += (unsigned)( ( map->rows - 1 ) * map->pitch );
+ p += ( map->rows - 1 ) * (unsigned int)map->pitch;
for ( ; count > 0; count--, spans++ )
{
@@ -1744,14 +1743,17 @@ typedef ptrdiff_t FT_PtrDist;
} gray_TBand;
- FT_DEFINE_OUTLINE_FUNCS(func_interface,
- (FT_Outline_MoveTo_Func) gray_move_to,
- (FT_Outline_LineTo_Func) gray_line_to,
- (FT_Outline_ConicTo_Func)gray_conic_to,
- (FT_Outline_CubicTo_Func)gray_cubic_to,
- 0,
- 0
- )
+
+ FT_DEFINE_OUTLINE_FUNCS(
+ func_interface,
+
+ (FT_Outline_MoveTo_Func) gray_move_to,
+ (FT_Outline_LineTo_Func) gray_line_to,
+ (FT_Outline_ConicTo_Func)gray_conic_to,
+ (FT_Outline_CubicTo_Func)gray_cubic_to,
+ 0,
+ 0 )
+
static int
gray_convert_glyph_inner( RAS_ARG )
@@ -1828,7 +1830,7 @@ typedef ptrdiff_t FT_PtrDist;
bands[0].max = max;
band = bands;
- while ( band >= bands )
+ do
{
TPos bottom, top, middle;
int error;
@@ -1842,13 +1844,13 @@ typedef ptrdiff_t FT_PtrDist;
ras.ycells = (PCell*)ras.buffer;
ras.ycount = band->max - band->min;
- cell_start = sizeof ( PCell ) * ras.ycount;
- cell_mod = cell_start % sizeof ( TCell );
+ cell_start = (long)sizeof ( PCell ) * ras.ycount;
+ cell_mod = cell_start % (long)sizeof ( TCell );
if ( cell_mod > 0 )
- cell_start += sizeof ( TCell ) - cell_mod;
+ cell_start += (long)sizeof ( TCell ) - cell_mod;
cell_end = ras.buffer_size;
- cell_end -= cell_end % sizeof ( TCell );
+ cell_end -= cell_end % (long)sizeof ( TCell );
cells_max = (PCell)( (char*)ras.buffer + cell_end );
ras.cells = (PCell)( (char*)ras.buffer + cell_start );
@@ -1904,7 +1906,7 @@ typedef ptrdiff_t FT_PtrDist;
band[0].min = middle;
band[0].max = top;
band++;
- }
+ } while ( band >= bands );
}
if ( ras.band_shoot > 8 && ras.band_size > 16 )
@@ -1918,12 +1920,18 @@ typedef ptrdiff_t FT_PtrDist;
gray_raster_render( gray_PRaster raster,
const FT_Raster_Params* params )
{
- const FT_Outline* outline = (const FT_Outline*)params->source;
- const FT_Bitmap* target_map = params->target;
- gray_PWorker worker;
+ const FT_Outline* outline = (const FT_Outline*)params->source;
+ const FT_Bitmap* target_map = params->target;
+ gray_TWorker worker[1];
- if ( !raster || !raster->buffer || !raster->buffer_size )
+ TCell buffer[FT_MAX( FT_RENDER_POOL_SIZE, 2048 ) / sizeof ( TCell )];
+ long buffer_size = sizeof ( buffer );
+ int band_size = (int)( buffer_size /
+ (long)( sizeof ( TCell ) * 8 ) );
+
+
+ if ( !raster )
return FT_THROW( Invalid_Argument );
if ( !outline )
@@ -1940,8 +1948,6 @@ typedef ptrdiff_t FT_PtrDist;
outline->contours[outline->n_contours - 1] + 1 )
return FT_THROW( Invalid_Outline );
- worker = raster->worker;
-
/* if direct mode is not set, we must have a target bitmap */
if ( !( params->flags & FT_RASTER_FLAG_DIRECT ) )
{
@@ -1966,8 +1972,8 @@ typedef ptrdiff_t FT_PtrDist;
/* compute clip box from target pixmap */
ras.clip_box.xMin = 0;
ras.clip_box.yMin = 0;
- ras.clip_box.xMax = target_map->width;
- ras.clip_box.yMax = target_map->rows;
+ ras.clip_box.xMax = (FT_Pos)target_map->width;
+ ras.clip_box.yMax = (FT_Pos)target_map->rows;
}
else if ( params->flags & FT_RASTER_FLAG_CLIP )
ras.clip_box = params->clip_box;
@@ -1979,13 +1985,14 @@ typedef ptrdiff_t FT_PtrDist;
ras.clip_box.yMax = 32767L;
}
- gray_init_cells( RAS_VAR_ raster->buffer, raster->buffer_size );
+ gray_init_cells( RAS_VAR_ buffer, buffer_size );
ras.outline = *outline;
ras.num_cells = 0;
ras.invalid = 1;
- ras.band_size = raster->band_size;
+ ras.band_size = band_size;
ras.num_gray_spans = 0;
+ ras.span_y = 0;
if ( params->flags & FT_RASTER_FLAG_DIRECT )
{
@@ -2069,34 +2076,9 @@ typedef ptrdiff_t FT_PtrDist;
char* pool_base,
long pool_size )
{
- gray_PRaster rast = (gray_PRaster)raster;
-
-
- if ( raster )
- {
- if ( pool_base && pool_size >= (long)sizeof ( gray_TWorker ) + 2048 )
- {
- gray_PWorker worker = (gray_PWorker)pool_base;
-
-
- rast->worker = worker;
- rast->buffer = pool_base +
- ( ( sizeof ( gray_TWorker ) +
- sizeof ( TCell ) - 1 ) &
- ~( sizeof ( TCell ) - 1 ) );
- rast->buffer_size = (long)( ( pool_base + pool_size ) -
- (char*)rast->buffer ) &
- ~( sizeof ( TCell ) - 1 );
- rast->band_size = (int)( rast->buffer_size /
- ( sizeof ( TCell ) * 8 ) );
- }
- else
- {
- rast->buffer = NULL;
- rast->buffer_size = 0;
- rast->worker = NULL;
- }
- }
+ FT_UNUSED( raster );
+ FT_UNUSED( pool_base );
+ FT_UNUSED( pool_size );
}
@@ -2114,15 +2096,16 @@ typedef ptrdiff_t FT_PtrDist;
}
- FT_DEFINE_RASTER_FUNCS(ft_grays_raster,
+ FT_DEFINE_RASTER_FUNCS(
+ ft_grays_raster,
+
FT_GLYPH_FORMAT_OUTLINE,
(FT_Raster_New_Func) gray_raster_new,
(FT_Raster_Reset_Func) gray_raster_reset,
(FT_Raster_Set_Mode_Func)gray_raster_set_mode,
(FT_Raster_Render_Func) gray_raster_render,
- (FT_Raster_Done_Func) gray_raster_done
- )
+ (FT_Raster_Done_Func) gray_raster_done )
/* END */
« no previous file with comments | « third_party/freetype/src/smooth/ftgrays.h ('k') | third_party/freetype/src/smooth/ftsmerrs.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698