From 2eaf0cf8fd6e7c290497fedb08134a89e7b49b1d Mon Sep 17 00:00:00 2001 From: Konstantin Ritt Date: Thu, 19 Mar 2015 17:34:42 +0400 Subject: Update bundled FreeType to 2.5.5 Removed everything, imported with help of import_from_tarball.sh script, and then added a pre-generated builds/unix/ftconfig.h Task-number: QTBUG-44648 Change-Id: Iea948e41f7761f1580382b3763d04c7a61383382 Reviewed-by: Lars Knoll --- src/3rdparty/freetype/src/raster/ftraster.c | 298 ++++++++++++++++++---------- 1 file changed, 190 insertions(+), 108 deletions(-) (limited to 'src/3rdparty/freetype/src/raster/ftraster.c') diff --git a/src/3rdparty/freetype/src/raster/ftraster.c b/src/3rdparty/freetype/src/raster/ftraster.c index 23ad592653..b06ac333da 100644 --- a/src/3rdparty/freetype/src/raster/ftraster.c +++ b/src/3rdparty/freetype/src/raster/ftraster.c @@ -4,7 +4,7 @@ /* */ /* The FreeType glyph rasterizer (body). */ /* */ -/* Copyright 1996-2001, 2002, 2003, 2005, 2007, 2008, 2009 by */ +/* Copyright 1996-2003, 2005, 2007-2014 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/raster/ftraster.c' (this file) to your current directory */ /* */ - /* - copy `include/freetype/ftimage.h' and `src/raster/ftmisc.h' */ - /* to your current directory */ + /* - copy `include/ftimage.h' and `src/raster/ftmisc.h' to your current */ + /* directory */ /* */ /* - compile `ftraster' with the _STANDALONE_ macro defined, as in */ /* */ @@ -60,7 +60,7 @@ #include #include "ftraster.h" -#include FT_INTERNAL_CALC_H /* for FT_MulDiv only */ +#include FT_INTERNAL_CALC_H /* for FT_MulDiv and FT_MulDiv_No_Round */ #include "rastpic.h" @@ -179,6 +179,9 @@ #ifdef _STANDALONE_ + /* Auxiliary macros for token concatenation. */ +#define FT_ERR_XCAT( x, y ) x ## y +#define FT_ERR_CAT( x, y ) FT_ERR_XCAT( x, y ) /* This macro is used to indicate that a function parameter is unused. */ /* Its purpose is simply to reduce compiler warnings. Note also that */ @@ -187,7 +190,7 @@ #define FT_UNUSED( x ) (x) = (x) /* Disable the tracing mechanism for simplicity -- developers can */ - /* activate it easily by redefining these two macros. */ + /* activate it easily by redefining these macros. */ #ifndef FT_ERROR #define FT_ERROR( x ) do { } while ( 0 ) /* nothing */ #endif @@ -198,6 +201,10 @@ #define FT_TRACE6( x ) do { } while ( 0 ) /* nothing */ #endif +#ifndef FT_THROW +#define FT_THROW( e ) FT_ERR_CAT( Raster_Err_, e ) +#endif + #define Raster_Err_None 0 #define Raster_Err_Not_Ini -1 #define Raster_Err_Overflow -2 @@ -224,11 +231,11 @@ #include FT_INTERNAL_OBJECTS_H -#include FT_INTERNAL_DEBUG_H /* for FT_TRACE() and FT_ERROR() */ +#include FT_INTERNAL_DEBUG_H /* for FT_TRACE, FT_ERROR, and FT_THROW */ #include "rasterrs.h" -#define Raster_Err_None Raster_Err_Ok +#define Raster_Err_None FT_Err_Ok #define Raster_Err_Not_Ini Raster_Err_Raster_Uninitialized #define Raster_Err_Overflow Raster_Err_Raster_Overflow #define Raster_Err_Neg_Height Raster_Err_Raster_Negative_Height @@ -255,7 +262,8 @@ /* On the other hand, SMulDiv means `Slow MulDiv', and is used typically */ /* for clipping computations. It simply uses the FT_MulDiv() function */ /* defined in `ftcalc.h'. */ -#define SMulDiv FT_MulDiv +#define SMulDiv FT_MulDiv +#define SMulDiv_No_Round FT_MulDiv_No_Round /* The rasterizer is a very general purpose component; please leave */ /* the following redefinitions there (you never know your target */ @@ -370,18 +378,23 @@ /* Simple record used to implement a stack of bands, required */ /* by the sub-banding mechanism */ - typedef struct TBand_ + typedef struct black_TBand_ { Short y_min; /* band's minimum */ Short y_max; /* band's maximum */ - } TBand; + } black_TBand; #define AlignProfileSize \ ( ( sizeof ( TProfile ) + sizeof ( Alignment ) - 1 ) / sizeof ( long ) ) +#undef RAS_ARG +#undef RAS_ARGS +#undef RAS_VAR +#undef RAS_VARS + #ifdef FT_STATIC_RASTER @@ -397,8 +410,8 @@ #else /* !FT_STATIC_RASTER */ -#define RAS_ARGS PWorker worker, -#define RAS_ARG PWorker worker +#define RAS_ARGS black_PWorker worker, +#define RAS_ARG black_PWorker worker #define RAS_VARS worker, #define RAS_VAR worker @@ -409,7 +422,7 @@ #endif /* !FT_STATIC_RASTER */ - typedef struct TWorker_ TWorker, *PWorker; + typedef struct black_TWorker_ black_TWorker, *black_PWorker; /* prototypes used for sweep function dispatch */ @@ -429,26 +442,31 @@ /* NOTE: These operations are only valid on 2's complement processors */ +#undef FLOOR +#undef CEILING +#undef TRUNC +#undef SCALED #define FLOOR( x ) ( (x) & -ras.precision ) #define CEILING( x ) ( ( (x) + ras.precision - 1 ) & -ras.precision ) -#define TRUNC( x ) ( (signed long)(x) >> ras.precision_bits ) +#define TRUNC( x ) ( (Long)(x) >> ras.precision_bits ) #define FRAC( x ) ( (x) & ( ras.precision - 1 ) ) -#define SCALED( x ) ( ( (x) << ras.scale_shift ) - ras.precision_half ) +#define SCALED( x ) ( ( (ULong)(x) << ras.scale_shift ) - ras.precision_half ) -#define IS_BOTTOM_OVERSHOOT( x ) ( CEILING( x ) - x >= ras.precision_half ) -#define IS_TOP_OVERSHOOT( x ) ( x - FLOOR( x ) >= ras.precision_half ) +#define IS_BOTTOM_OVERSHOOT( x ) \ + (Bool)( CEILING( x ) - x >= ras.precision_half ) +#define IS_TOP_OVERSHOOT( x ) \ + (Bool)( x - FLOOR( x ) >= ras.precision_half ) /* The most used variables are positioned at the top of the structure. */ /* Thus, their offset can be coded with less opcodes, resulting in a */ /* smaller executable. */ - struct TWorker_ + struct black_TWorker_ { Int precision_bits; /* precision related variables */ Int precision; Int precision_half; - Long precision_mask; Int precision_shift; Int precision_step; Int precision_jitter; @@ -517,8 +535,8 @@ TPoint arcs[3 * MaxBezier + 1]; /* The Bezier stack */ - TBand band_stack[16]; /* band stack used for sub-banding */ - Int band_top; /* band stack top */ + black_TBand band_stack[16]; /* band stack used for sub-banding */ + Int band_top; /* band stack top */ #ifdef FT_RASTER_OPTION_ANTI_ALIASING @@ -542,20 +560,20 @@ }; - typedef struct TRaster_ + typedef struct black_TRaster_ { - char* buffer; - long buffer_size; - void* memory; - PWorker worker; - Byte grays[5]; - Short gray_width; + char* buffer; + long buffer_size; + void* memory; + black_PWorker worker; + Byte grays[5]; + Short gray_width; - } TRaster, *PRaster; + } black_TRaster, *black_PRaster; #ifdef FT_STATIC_RASTER - static TWorker cur_ras; + static black_TWorker cur_ras; #define ras cur_ras #else /* !FT_STATIC_RASTER */ @@ -647,17 +665,39 @@ /* Set precision variables according to param flag. */ /* */ /* */ - /* High :: Set to True for high precision (typically for ppem < 18), */ + /* High :: Set to True for high precision (typically for ppem < 24), */ /* false otherwise. */ /* */ static void Set_High_Precision( RAS_ARGS Int High ) { + /* + * `precision_step' is used in `Bezier_Up' to decide when to split a + * given y-monotonous Bezier arc that crosses a scanline before + * approximating it as a straight segment. The default value of 32 (for + * low accuracy) corresponds to + * + * 32 / 64 == 0.5 pixels , + * + * while for the high accuracy case we have + * + * 256/ (1 << 12) = 0.0625 pixels . + * + * `precision_jitter' is an epsilon threshold used in + * `Vertical_Sweep_Span' to deal with small imperfections in the Bezier + * decomposition (after all, we are working with approximations only); + * it avoids switching on additional pixels which would cause artifacts + * otherwise. + * + * The value of `precision_jitter' has been determined heuristically. + * + */ + if ( High ) { ras.precision_bits = 12; ras.precision_step = 256; - ras.precision_jitter = 50; + ras.precision_jitter = 30; } else { @@ -671,7 +711,6 @@ ras.precision = 1 << ras.precision_bits; ras.precision_half = ras.precision / 2; ras.precision_shift = ras.precision_bits - Pixel_Bits; - ras.precision_mask = -ras.precision; } @@ -706,7 +745,7 @@ if ( ras.top >= ras.maxBuff ) { - ras.error = Raster_Err_Overflow; + ras.error = FT_THROW( Overflow ); return FAILURE; } @@ -725,18 +764,18 @@ if ( overshoot ) ras.cProfile->flags |= Overshoot_Bottom; - FT_TRACE6(( "New ascending profile = %lx\n", (long)ras.cProfile )); + FT_TRACE6(( "New ascending profile = %p\n", ras.cProfile )); break; case Descending_State: if ( overshoot ) ras.cProfile->flags |= Overshoot_Top; - FT_TRACE6(( "New descending profile = %lx\n", (long)ras.cProfile )); + FT_TRACE6(( "New descending profile = %p\n", ras.cProfile )); break; default: FT_ERROR(( "New_Profile: invalid profile direction\n" )); - ras.error = Raster_Err_Invalid; + ras.error = FT_THROW( Invalid ); return FAILURE; } @@ -769,8 +808,7 @@ static Bool End_Profile( RAS_ARGS Bool overshoot ) { - Long h; - PProfile oldProfile; + Long h; h = (Long)( ras.top - ras.cProfile->offset ); @@ -778,14 +816,17 @@ if ( h < 0 ) { FT_ERROR(( "End_Profile: negative height encountered\n" )); - ras.error = Raster_Err_Neg_Height; + ras.error = FT_THROW( Neg_Height ); return FAILURE; } if ( h > 0 ) { - FT_TRACE6(( "Ending profile %lx, start = %ld, height = %ld\n", - (long)ras.cProfile, ras.cProfile->start, h )); + PProfile oldProfile; + + + FT_TRACE6(( "Ending profile %p, start = %ld, height = %ld\n", + ras.cProfile, ras.cProfile->start, h )); ras.cProfile->height = h; if ( overshoot ) @@ -811,7 +852,7 @@ if ( ras.top >= ras.maxBuff ) { FT_TRACE1(( "overflow in End_Profile\n" )); - ras.error = Raster_Err_Overflow; + ras.error = FT_THROW( Overflow ); return FAILURE; } @@ -840,7 +881,7 @@ Insert_Y_Turn( RAS_ARGS Int y ) { PLong y_turns; - Int y2, n; + Int n; n = ras.numTurns - 1; @@ -854,7 +895,9 @@ if ( n >= 0 && y > y_turns[n] ) while ( n >= 0 ) { - y2 = (Int)y_turns[n]; + Int y2 = (Int)y_turns[n]; + + y_turns[n] = y; y = y2; n--; @@ -865,7 +908,7 @@ ras.maxBuff--; if ( ras.maxBuff <= ras.top ) { - ras.error = Raster_Err_Overflow; + ras.error = FT_THROW( Overflow ); return FAILURE; } ras.numTurns++; @@ -890,7 +933,6 @@ static Bool Finalize_Profile_Table( RAS_ARG ) { - Int bottom, top; UShort n; PProfile p; @@ -902,6 +944,9 @@ { while ( n > 0 ) { + Int bottom, top; + + if ( n > 1 ) p->link = (PProfile)( p->offset + p->height ); else @@ -1094,7 +1139,7 @@ return SUCCESS; else { - x1 += FMulDiv( Dx, ras.precision - f1, Dy ); + x1 += SMulDiv( Dx, ras.precision - f1, Dy ); e1 += 1; } } @@ -1116,20 +1161,20 @@ size = e2 - e1 + 1; if ( ras.top + size >= ras.maxBuff ) { - ras.error = Raster_Err_Overflow; + ras.error = FT_THROW( Overflow ); return FAILURE; } if ( Dx > 0 ) { - Ix = ( ras.precision * Dx ) / Dy; + Ix = SMulDiv_No_Round( ras.precision, Dx, Dy ); Rx = ( ras.precision * Dx ) % Dy; Dx = 1; } else { - Ix = -( ( ras.precision * -Dx ) / Dy ); - Rx = ( ras.precision * -Dx ) % Dy; + Ix = -SMulDiv_No_Round( ras.precision, -Dx, Dy ); + Rx = ( ras.precision * -Dx ) % Dy; Dx = -1; } @@ -1291,7 +1336,7 @@ if ( ( top + TRUNC( e2 - e ) + 1 ) >= ras.maxBuff ) { ras.top = top; - ras.error = Raster_Err_Overflow; + ras.error = FT_THROW( Overflow ); return FAILURE; } @@ -1829,7 +1874,7 @@ v_start.x = ( v_start.x + v_last.x ) / 2; v_start.y = ( v_start.y + v_last.y ) / 2; - v_last = v_start; + /* v_last = v_start; */ } point--; tags--; @@ -1931,18 +1976,21 @@ y1 = SCALED( point[-2].y ); x2 = SCALED( point[-1].x ); y2 = SCALED( point[-1].y ); - x3 = SCALED( point[ 0].x ); - y3 = SCALED( point[ 0].y ); if ( flipped ) { SWAP_( x1, y1 ); SWAP_( x2, y2 ); - SWAP_( x3, y3 ); } if ( point <= limit ) { + x3 = SCALED( point[0].x ); + y3 = SCALED( point[0].y ); + + if ( flipped ) + SWAP_( x3, y3 ); + if ( Cubic_To( RAS_VARS x1, y1, x2, y2, x3, y3 ) ) goto Fail; continue; @@ -1963,7 +2011,7 @@ return SUCCESS; Invalid_Outline: - ras.error = Raster_Err_Invalid; + ras.error = FT_THROW( Invalid ); Fail: return FAILURE; @@ -1992,8 +2040,6 @@ int i; unsigned start; - PProfile lastProfile; - ras.fProfile = NULL; ras.joint = FALSE; @@ -2011,7 +2057,8 @@ for ( i = 0; i < ras.outline.n_contours; i++ ) { - Bool o; + PProfile lastProfile; + Bool o; ras.state = Unknown_State; @@ -2235,10 +2282,10 @@ PProfile right ) { Long e1, e2; - int c1, c2; - Byte f1, f2; Byte* target; + Int dropOutControl = left->flags & 7; + FT_UNUSED( y ); FT_UNUSED( left ); FT_UNUSED( right ); @@ -2248,13 +2295,18 @@ e1 = TRUNC( CEILING( x1 ) ); - if ( x2 - x1 - ras.precision <= ras.precision_jitter ) + if ( dropOutControl != 2 && + x2 - x1 - ras.precision <= ras.precision_jitter ) e2 = e1; else e2 = TRUNC( FLOOR( x2 ) ); if ( e2 >= 0 && e1 < ras.bWidth ) { + int c1, c2; + Byte f1, f2; + + if ( e1 < 0 ) e1 = 0; if ( e2 >= ras.bWidth ) @@ -2403,6 +2455,14 @@ return; /* no drop-out control */ } + /* undocumented but confirmed: If the drop-out would result in a */ + /* pixel outside of the bounding box, use the pixel inside of the */ + /* bounding box instead */ + if ( pxl < 0 ) + pxl = e1; + else if ( TRUNC( pxl ) >= ras.bWidth ) + pxl = e2; + /* check that the other pixel isn't set */ e1 = pxl == e1 ? e2 : e1; @@ -2470,32 +2530,35 @@ PProfile left, PProfile right ) { - Long e1, e2; - PByte bits; - Byte f1; - FT_UNUSED( left ); FT_UNUSED( right ); if ( x2 - x1 < ras.precision ) { + Long e1, e2; + + e1 = CEILING( x1 ); e2 = FLOOR ( x2 ); if ( e1 == e2 ) { + Byte f1; + PByte bits; + + bits = ras.bTarget + ( y >> 3 ); f1 = (Byte)( 0x80 >> ( y & 7 ) ); e1 = TRUNC( e1 ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { PByte p; - p = bits - e1*ras.target.pitch; + p = bits - e1 * ras.target.pitch; if ( ras.target.pitch > 0 ) p += ( ras.target.rows - 1 ) * ras.target.pitch; @@ -2579,6 +2642,14 @@ return; /* no drop-out control */ } + /* undocumented but confirmed: If the drop-out would result in a */ + /* pixel outside of the bounding box, use the pixel inside of the */ + /* bounding box instead */ + if ( pxl < 0 ) + pxl = e1; + else if ( (ULong)( TRUNC( pxl ) ) >= ras.target.rows ) + pxl = e2; + /* check that the other pixel isn't set */ e1 = pxl == e1 ? e2 : e1; @@ -2591,9 +2662,9 @@ if ( ras.target.pitch > 0 ) bits += ( ras.target.rows - 1 ) * ras.target.pitch; - if ( e1 >= 0 && - e1 < ras.target.rows && - *bits & f1 ) + if ( e1 >= 0 && + (ULong)e1 < ras.target.rows && + *bits & f1 ) return; } else @@ -2605,7 +2676,7 @@ e1 = TRUNC( pxl ); - if ( e1 >= 0 && e1 < ras.target.rows ) + if ( e1 >= 0 && (ULong)e1 < ras.target.rows ) { bits -= e1 * ras.target.pitch; if ( ras.target.pitch > 0 ) @@ -2673,8 +2744,6 @@ static void Vertical_Gray_Sweep_Step( RAS_ARG ) { - Int c1, c2; - PByte pix, bit, bit2; short* count = (short*)count_table; Byte* grays; @@ -2683,6 +2752,9 @@ if ( ras.traceOfs > ras.gray_width ) { + PByte pix; + + pix = ras.gTarget + ras.traceG + ras.gray_min_x * 4; grays = ras.grays; @@ -2693,6 +2765,9 @@ Int last_bit = last_pixel & 3; Bool over = 0; + Int c1, c2; + PByte bit, bit2; + if ( ras.gray_max_x >= last_cell && last_bit != 3 ) { @@ -2785,7 +2860,6 @@ { Long e1, e2; PByte pixel; - Byte color; /* During the horizontal sweep, we only take care of drop-outs */ @@ -2839,6 +2913,9 @@ if ( e1 >= 0 ) { + Byte color; + + if ( x2 - x1 >= ras.precision_half ) color = ras.grays[2]; else @@ -2916,7 +2993,7 @@ /* check the Y-turns */ if ( ras.numTurns == 0 ) { - ras.error = Raster_Err_Invalid; + ras.error = FT_THROW( Invalid ); return FAILURE; } @@ -3157,7 +3234,7 @@ if ( ras.band_top >= 7 || k < i ) { ras.band_top = 0; - ras.error = Raster_Err_Invalid; + ras.error = FT_THROW( Invalid ); return ras.error; } @@ -3346,14 +3423,14 @@ { FT_UNUSED_RASTER; - return Raster_Err_Unsupported; + return FT_THROW( Unsupported ); } #endif /* !FT_RASTER_OPTION_ANTI_ALIASING */ static void - ft_black_init( PRaster raster ) + ft_black_init( black_PRaster raster ) { #ifdef FT_RASTER_OPTION_ANTI_ALIASING FT_UInt n; @@ -3381,7 +3458,8 @@ ft_black_new( void* memory, FT_Raster *araster ) { - static TRaster the_raster; + static black_TRaster the_raster; + FT_UNUSED( memory ); *araster = (FT_Raster)&the_raster; @@ -3400,15 +3478,15 @@ } -#else /* _STANDALONE_ */ +#else /* !_STANDALONE_ */ static int - ft_black_new( FT_Memory memory, - PRaster *araster ) + ft_black_new( FT_Memory memory, + black_PRaster *araster ) { - FT_Error error; - PRaster raster; + FT_Error error; + black_PRaster raster = NULL; *araster = 0; @@ -3425,31 +3503,33 @@ static void - ft_black_done( PRaster raster ) + ft_black_done( black_PRaster raster ) { FT_Memory memory = (FT_Memory)raster->memory; + + FT_FREE( raster ); } -#endif /* _STANDALONE_ */ +#endif /* !_STANDALONE_ */ static void - ft_black_reset( PRaster raster, - char* pool_base, - long pool_size ) + ft_black_reset( black_PRaster raster, + char* pool_base, + long pool_size ) { if ( raster ) { - if ( pool_base && pool_size >= (long)sizeof(TWorker) + 2048 ) + if ( pool_base && pool_size >= (long)sizeof ( black_TWorker ) + 2048 ) { - PWorker worker = (PWorker)pool_base; + black_PWorker worker = (black_PWorker)pool_base; - raster->buffer = pool_base + ( (sizeof ( *worker ) + 7 ) & ~7 ); - raster->buffer_size = ( ( pool_base + pool_size ) - - (char*)raster->buffer ) / sizeof ( Long ); + raster->buffer = pool_base + ( ( sizeof ( *worker ) + 7 ) & ~7 ); + raster->buffer_size = (long)( pool_base + pool_size - + (char*)raster->buffer ); raster->worker = worker; } else @@ -3462,8 +3542,8 @@ } - static void - ft_black_set_mode( PRaster raster, + static int + ft_black_set_mode( black_PRaster raster, unsigned long mode, const char* palette ) { @@ -3486,50 +3566,52 @@ FT_UNUSED( palette ); #endif + + return 0; } static int - ft_black_render( PRaster raster, + ft_black_render( black_PRaster raster, const FT_Raster_Params* params ) { const FT_Outline* outline = (const FT_Outline*)params->source; const FT_Bitmap* target_map = params->target; - PWorker worker; + black_PWorker worker; if ( !raster || !raster->buffer || !raster->buffer_size ) - return Raster_Err_Not_Ini; + return FT_THROW( Not_Ini ); if ( !outline ) - return Raster_Err_Invalid; + return FT_THROW( Invalid ); /* return immediately if the outline is empty */ if ( outline->n_points == 0 || outline->n_contours <= 0 ) return Raster_Err_None; if ( !outline->contours || !outline->points ) - return Raster_Err_Invalid; + return FT_THROW( Invalid ); if ( outline->n_points != outline->contours[outline->n_contours - 1] + 1 ) - return Raster_Err_Invalid; + return FT_THROW( Invalid ); worker = raster->worker; /* this version of the raster does not support direct rendering, sorry */ if ( params->flags & FT_RASTER_FLAG_DIRECT ) - return Raster_Err_Unsupported; + return FT_THROW( Unsupported ); if ( !target_map ) - return Raster_Err_Invalid; + return FT_THROW( Invalid ); /* nothing to do */ if ( !target_map->width || !target_map->rows ) return Raster_Err_None; if ( !target_map->buffer ) - return Raster_Err_Invalid; + return FT_THROW( Invalid ); ras.outline = *outline; ras.target = *target_map; -- cgit v1.2.3