diff options
Diffstat (limited to 'src/base')
-rw-r--r-- | src/base/basepic.c | 6 | ||||
-rw-r--r-- | src/base/ftbitmap.c | 45 | ||||
-rw-r--r-- | src/base/ftcalc.c | 267 | ||||
-rw-r--r-- | src/base/ftlcdfil.c | 23 | ||||
-rw-r--r-- | src/base/ftobjs.c | 24 | ||||
-rw-r--r-- | src/base/ftoutln.c | 4 | ||||
-rw-r--r-- | src/base/ftrfork.c | 26 | ||||
-rw-r--r-- | src/base/ftutil.c | 22 |
8 files changed, 329 insertions, 88 deletions
diff --git a/src/base/basepic.c b/src/base/basepic.c index 0af770e..aeb6fd5 100644 --- a/src/base/basepic.c +++ b/src/base/basepic.c @@ -4,7 +4,7 @@ /* */ /* The FreeType position independent code services for base. */ /* */ -/* Copyright 2009, 2012 by */ +/* Copyright 2009, 2012, 2013 by */ /* Oran Agra and Mickey Gabel. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -35,7 +35,7 @@ /* forward declaration of PIC init function from ftrfork.c */ /* (not modularized) */ void - FT_Init_Table_raccess_guess_table( ft_raccess_guess_rec* record ); + FT_Init_Table_ft_raccess_guess_table( ft_raccess_guess_rec* record ); #endif /* forward declaration of PIC init functions from ftinit.c */ @@ -92,7 +92,7 @@ FT_Init_Class_ft_bitmap_glyph_class( &container->ft_bitmap_glyph_class ); #ifdef FT_CONFIG_OPTION_MAC_FONTS - FT_Init_Table_raccess_guess_table( + FT_Init_Table_ft_raccess_guess_table( (ft_raccess_guess_rec*)&container->ft_raccess_guess_table ); #endif diff --git a/src/base/ftbitmap.c b/src/base/ftbitmap.c index 182b1cc..6542c79 100644 --- a/src/base/ftbitmap.c +++ b/src/base/ftbitmap.c @@ -4,7 +4,7 @@ /* */ /* FreeType utility functions for bitmaps (body). */ /* */ -/* Copyright 2004-2009, 2011, 2013 by */ +/* Copyright 2004-2009, 2011, 2013, 2014 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -375,14 +375,11 @@ } - FT_Byte + static FT_Byte ft_gray_for_premultiplied_srgb_bgra( const FT_Byte* bgra ) { - FT_Long a = bgra[3]; - FT_Long b = bgra[0]; - FT_Long g = bgra[1]; - FT_Long r = bgra[2]; - FT_Long l; + FT_Byte a = bgra[3]; + FT_ULong l; /* Short-circuit transparent color to avoid div-by-zero. */ @@ -397,38 +394,30 @@ * * http://accessibility.kde.org/hsl-adjusted.php * - * We do the computation with integers only. + * We do the computation with integers only, applying a gamma of 2.0. + * The following will never overflow 32 bits; it is a scaled-up + * luminosity with premultiplication not yet undone. + * */ - /* Undo premultification, get the number in a 16.16 form. */ - b = FT_MulDiv( b, 65536, a ); - g = FT_MulDiv( g, 65536, a ); - r = FT_MulDiv( r, 65536, a ); - a = a * 256; - - /* Apply gamma of 2.0 instead of 2.2. */ - b = FT_MulFix( b, b ); - g = FT_MulFix( g, g ); - r = FT_MulFix( r, r ); - - /* Apply coefficients. */ - b = FT_MulFix( b, 4731 /* 0.0722 * 65536 */ ); - g = FT_MulFix( g, 46871 /* 0.7152 * 65536 */ ); - r = FT_MulFix( r, 13933 /* 0.2126 * 65536 */ ); - - l = r + g + b; + l = 4731UL /* 0.0722 * 65536 */ * bgra[0] * bgra[0] + + 46871UL /* 0.7152 * 65536 */ * bgra[1] * bgra[1] + + 13933UL /* 0.2126 * 65536 */ * bgra[2] * bgra[2]; /* - * Final transparency can be determined this way: + * Final transparency can be determined as follows. * * - If alpha is zero, we want 0. * - If alpha is zero and luminosity is zero, we want 255. * - If alpha is zero and luminosity is one, we want 0. * - * So the formula is a * (1 - l). + * So the formula is a * (1 - l) = a - l * a. + * + * In the actual code, we undo premultiplication and scale down again. + * */ - return (FT_Byte)( FT_MulFix( 65535 - l, a ) >> 8 ); + return a - (FT_Byte)( ( l / a ) >> 16 ); } diff --git a/src/base/ftcalc.c b/src/base/ftcalc.c index b23b4d4..4db43e0 100644 --- a/src/base/ftcalc.c +++ b/src/base/ftcalc.c @@ -4,7 +4,7 @@ /* */ /* Arithmetic computations (body). */ /* */ -/* Copyright 1996-2006, 2008, 2012-2013 by */ +/* Copyright 1996-2006, 2008, 2012-2014 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -39,6 +39,235 @@ #include FT_INTERNAL_DEBUG_H #include FT_INTERNAL_OBJECTS_H + +#ifndef FT_CONFIG_OPTION_NO_ASSEMBLER + /* Provide assembler fragments for performance-critical functions. */ + /* These must be defined `static __inline__' with GCC. */ + +#if defined( __CC_ARM ) || defined( __ARMCC__ ) /* RVCT */ + +#define FT_MULFIX_ASSEMBLER FT_MulFix_arm + + /* documentation is in freetype.h */ + + static __inline FT_Int32 + FT_MulFix_arm( FT_Int32 a, + FT_Int32 b ) + { + register FT_Int32 t, t2; + + + __asm + { + smull t2, t, b, a /* (lo=t2,hi=t) = a*b */ + mov a, t, asr #31 /* a = (hi >> 31) */ + add a, a, #0x8000 /* a += 0x8000 */ + adds t2, t2, a /* t2 += a */ + adc t, t, #0 /* t += carry */ + mov a, t2, lsr #16 /* a = t2 >> 16 */ + orr a, a, t, lsl #16 /* a |= t << 16 */ + } + return a; + } + +#endif /* __CC_ARM || __ARMCC__ */ + + +#ifdef __GNUC__ + +#if defined( __arm__ ) && \ + ( !defined( __thumb__ ) || defined( __thumb2__ ) ) && \ + !( defined( __CC_ARM ) || defined( __ARMCC__ ) ) + +#define FT_MULFIX_ASSEMBLER FT_MulFix_arm + + /* documentation is in freetype.h */ + + static __inline__ FT_Int32 + FT_MulFix_arm( FT_Int32 a, + FT_Int32 b ) + { + register FT_Int32 t, t2; + + + __asm__ __volatile__ ( + "smull %1, %2, %4, %3\n\t" /* (lo=%1,hi=%2) = a*b */ + "mov %0, %2, asr #31\n\t" /* %0 = (hi >> 31) */ +#if defined( __clang__ ) && defined( __thumb2__ ) + "add.w %0, %0, #0x8000\n\t" /* %0 += 0x8000 */ +#else + "add %0, %0, #0x8000\n\t" /* %0 += 0x8000 */ +#endif + "adds %1, %1, %0\n\t" /* %1 += %0 */ + "adc %2, %2, #0\n\t" /* %2 += carry */ + "mov %0, %1, lsr #16\n\t" /* %0 = %1 >> 16 */ + "orr %0, %0, %2, lsl #16\n\t" /* %0 |= %2 << 16 */ + : "=r"(a), "=&r"(t2), "=&r"(t) + : "r"(a), "r"(b) + : "cc" ); + return a; + } + +#endif /* __arm__ && */ + /* ( __thumb2__ || !__thumb__ ) && */ + /* !( __CC_ARM || __ARMCC__ ) */ + + +#if defined( __i386__ ) + +#define FT_MULFIX_ASSEMBLER FT_MulFix_i386 + + /* documentation is in freetype.h */ + + static __inline__ FT_Int32 + FT_MulFix_i386( FT_Int32 a, + FT_Int32 b ) + { + register FT_Int32 result; + + + __asm__ __volatile__ ( + "imul %%edx\n" + "movl %%edx, %%ecx\n" + "sarl $31, %%ecx\n" + "addl $0x8000, %%ecx\n" + "addl %%ecx, %%eax\n" + "adcl $0, %%edx\n" + "shrl $16, %%eax\n" + "shll $16, %%edx\n" + "addl %%edx, %%eax\n" + : "=a"(result), "=d"(b) + : "a"(a), "d"(b) + : "%ecx", "cc" ); + return result; + } + +#endif /* i386 */ + +#endif /* __GNUC__ */ + + +#ifdef _MSC_VER /* Visual C++ */ + +#ifdef _M_IX86 + +#define FT_MULFIX_ASSEMBLER FT_MulFix_i386 + + /* documentation is in freetype.h */ + + static __inline FT_Int32 + FT_MulFix_i386( FT_Int32 a, + FT_Int32 b ) + { + register FT_Int32 result; + + __asm + { + mov eax, a + mov edx, b + imul edx + mov ecx, edx + sar ecx, 31 + add ecx, 8000h + add eax, ecx + adc edx, 0 + shr eax, 16 + shl edx, 16 + add eax, edx + mov result, eax + } + return result; + } + +#endif /* _M_IX86 */ + +#endif /* _MSC_VER */ + + +#if defined( __GNUC__ ) && defined( __x86_64__ ) + +#define FT_MULFIX_ASSEMBLER FT_MulFix_x86_64 + + static __inline__ FT_Int32 + FT_MulFix_x86_64( FT_Int32 a, + FT_Int32 b ) + { + /* Temporarily disable the warning that C90 doesn't support */ + /* `long long'. */ +#if ( __GNUC__ > 4 ) || ( ( __GNUC__ == 4 ) && ( __GNUC_MINOR__ >= 6 ) ) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wlong-long" +#endif + +#if 1 + /* Technically not an assembly fragment, but GCC does a really good */ + /* job at inlining it and generating good machine code for it. */ + long long ret, tmp; + + + ret = (long long)a * b; + tmp = ret >> 63; + ret += 0x8000 + tmp; + + return (FT_Int32)( ret >> 16 ); +#else + + /* For some reason, GCC 4.6 on Ubuntu 12.04 generates invalid machine */ + /* code from the lines below. The main issue is that `wide_a' is not */ + /* properly initialized by sign-extending `a'. Instead, the generated */ + /* machine code assumes that the register that contains `a' on input */ + /* can be used directly as a 64-bit value, which is wrong most of the */ + /* time. */ + long long wide_a = (long long)a; + long long wide_b = (long long)b; + long long result; + + + __asm__ __volatile__ ( + "imul %2, %1\n" + "mov %1, %0\n" + "sar $63, %0\n" + "lea 0x8000(%1, %0), %0\n" + "sar $16, %0\n" + : "=&r"(result), "=&r"(wide_a) + : "r"(wide_b) + : "cc" ); + + return (FT_Int32)result; +#endif + +#if ( __GNUC__ > 4 ) || ( ( __GNUC__ == 4 ) && ( __GNUC_MINOR__ >= 6 ) ) +#pragma GCC diagnostic pop +#endif + } + +#endif /* __GNUC__ && __x86_64__ */ + +#if defined( __GNUC__ ) +#if ( __GNUC__ > 3 ) || ( ( __GNUC__ == 3 ) && ( __GNUC_MINOR__ >= 4 ) ) + +#if FT_SIZEOF_INT == 4 + +#define FT_MSB_BUILTIN( x ) ( 31 - __builtin_clz( x ) ) + +#elif FT_SIZEOF_LONG == 4 + +#define FT_MSB_BUILTIN( x ) ( 31 - __builtin_clzl( x ) ) + +#endif + +#endif +#endif /* __GNUC__ */ + +#endif /* !FT_CONFIG_OPTION_NO_ASSEMBLER */ + + +#ifdef FT_CONFIG_OPTION_INLINE_MULFIX +#ifdef FT_MULFIX_ASSEMBLER +#define FT_MULFIX_INLINED FT_MULFIX_ASSEMBLER +#endif +#endif + #ifdef FT_MULFIX_INLINED #undef FT_MulFix #endif @@ -103,6 +332,12 @@ FT_BASE_DEF ( FT_Int ) FT_MSB( FT_UInt32 z ) { +#ifdef FT_MSB_BUILTIN + + return FT_MSB_BUILTIN( z ); + +#else + FT_Int shift = 0; /* determine msb bit index in `shift' */ @@ -128,11 +363,13 @@ } if ( z >= ( 1L << 1 ) ) { - z >>= 1; + /* z >>= 1; */ shift += 1; } return shift; + +#endif /* FT_MSB_BUILTIN */ } @@ -358,20 +595,26 @@ /* documentation is in freetype.h */ /* The FT_MulDiv function has been optimized thanks to ideas from */ - /* Graham Asher. The trick is to optimize computation when everything */ - /* fits within 32-bits (a rather common case). */ + /* Graham Asher and Alexei Podtelezhnikov. The trick is to optimize */ + /* a rather common case when everything fits within 32-bits. */ + /* */ + /* We compute 'a*b+c/2', then divide it by 'c'. (positive values) */ /* */ - /* we compute 'a*b+c/2', then divide it by 'c'. (positive values) */ + /* The product of two positive numbers never exceeds the square of */ + /* their mean. Therefore, we always avoid the overflow by imposing */ /* */ - /* 46340 is FLOOR(SQRT(2^31-1)). */ + /* ( a + b ) / 2 <= sqrt( X - c/2 ) */ /* */ - /* if ( a <= 46340 && b <= 46340 ) then ( a*b <= 0x7FFEA810 ) */ + /* where X = 2^31 - 1. Now we replace sqrt with a linear function */ + /* that is smaller or equal in the entire range of c from 0 to X; */ + /* it should be equal to sqrt(X) and sqrt(X/2) at the range termini. */ + /* Substituting the linear solution and explicit numbers we get */ /* */ - /* 0x7FFFFFFF - 0x7FFEA810 = 0x157F0 */ + /* a + b <= 92681.9 - c / 79108.95 */ /* */ - /* if ( c < 0x157F0*2 ) then ( a*b+c/2 <= 0x7FFFFFFF ) */ + /* In practice we use a faster and even stronger inequality */ /* */ - /* and 2*0x157F0 = 176096 */ + /* a + b <= 92681 - (c >> 16) */ /* */ FT_EXPORT_DEF( FT_Long ) @@ -390,7 +633,7 @@ s ^= b; b = FT_ABS( b ); s ^= c; c = FT_ABS( c ); - if ( a <= 46340L && b <= 46340L && c <= 176095L && c > 0 ) + if ( (FT_ULong)a + (FT_ULong)b <= 92681UL - ( c >> 16 ) && c > 0 ) a = ( a * b + ( c >> 1 ) ) / c; else if ( (FT_Int32)c > 0 ) @@ -427,7 +670,7 @@ s ^= b; b = FT_ABS( b ); s ^= c; c = FT_ABS( c ); - if ( a <= 46340L && b <= 46340L && c > 0 ) + if ( (FT_ULong)a + (FT_ULong)b <= 92681UL && c > 0 ) a = a * b / c; else if ( (FT_Int32)c > 0 ) diff --git a/src/base/ftlcdfil.c b/src/base/ftlcdfil.c index 852fb32..4aefb68 100644 --- a/src/base/ftlcdfil.c +++ b/src/base/ftlcdfil.c @@ -4,7 +4,7 @@ /* */ /* FreeType API for color filtering of subpixel bitmap glyphs (body). */ /* */ -/* Copyright 2006, 2008-2010, 2013 by */ +/* Copyright 2006, 2008-2010, 2013, 2014 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -46,9 +46,12 @@ FT_Byte* line = bitmap->buffer; + /* `fir' and `pix' must be at least 32 bit wide, since the sum of */ + /* the values in `weights' can exceed 0xFF */ + for ( ; height > 0; height--, line += bitmap->pitch ) { - FT_UInt fir[5]; + FT_UInt fir[4]; /* below, `pix' is used as the 5th element */ FT_UInt val1, xx; @@ -57,7 +60,6 @@ fir[1] = weights[3] * val1; fir[2] = weights[4] * val1; fir[3] = 0; - fir[4] = 0; val1 = line[1]; fir[0] += weights[1] * val1; @@ -78,7 +80,7 @@ fir[3] = weights[4] * val; pix >>= 8; - pix |= -( pix >> 8 ); + pix |= (FT_UInt)-(FT_Int)( pix >> 8 ); line[xx - 2] = (FT_Byte)pix; } @@ -87,11 +89,11 @@ pix = fir[0] >> 8; - pix |= -( pix >> 8 ); + pix |= (FT_UInt)-(FT_Int)( pix >> 8 ); line[xx - 2] = (FT_Byte)pix; pix = fir[1] >> 8; - pix |= -( pix >> 8 ); + pix |= (FT_UInt)-(FT_Int)( pix >> 8 ); line[xx - 1] = (FT_Byte)pix; } } @@ -107,7 +109,7 @@ for ( ; width > 0; width--, column++ ) { FT_Byte* col = column; - FT_UInt fir[5]; + FT_UInt fir[4]; /* below, `pix' is used as the 5th element */ FT_UInt val1, yy; @@ -116,7 +118,6 @@ fir[1] = weights[3] * val1; fir[2] = weights[4] * val1; fir[3] = 0; - fir[4] = 0; col += pitch; val1 = col[0]; @@ -139,7 +140,7 @@ fir[3] = weights[4] * val; pix >>= 8; - pix |= -( pix >> 8 ); + pix |= (FT_UInt)-(FT_Int)( pix >> 8 ); col[-2 * pitch] = (FT_Byte)pix; col += pitch; } @@ -149,11 +150,11 @@ pix = fir[0] >> 8; - pix |= -( pix >> 8 ); + pix |= (FT_UInt)-(FT_Int)( pix >> 8 ); col[-2 * pitch] = (FT_Byte)pix; pix = fir[1] >> 8; - pix |= -( pix >> 8 ); + pix |= (FT_UInt)-(FT_Int)( pix >> 8 ); col[-pitch] = (FT_Byte)pix; } } diff --git a/src/base/ftobjs.c b/src/base/ftobjs.c index bd0c66e..cc56105 100644 --- a/src/base/ftobjs.c +++ b/src/base/ftobjs.c @@ -4,7 +4,7 @@ /* */ /* The FreeType private base classes (body). */ /* */ -/* Copyright 1996-2013 by */ +/* Copyright 1996-2014 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -1801,9 +1801,10 @@ if ( error ) return error; + /* POST resources must be sorted to concatenate properly */ error = FT_Raccess_Get_DataOffsets( library, stream, map_offset, rdara_pos, - TTAG_POST, + TTAG_POST, TRUE, &data_offsets, &count ); if ( !error ) { @@ -1816,9 +1817,11 @@ return error; } + /* sfnt resources should not be sorted to preserve the face order by + QuickDraw API */ error = FT_Raccess_Get_DataOffsets( library, stream, map_offset, rdara_pos, - TTAG_sfnt, + TTAG_sfnt, FALSE, &data_offsets, &count ); if ( !error ) { @@ -3357,6 +3360,7 @@ FT_UInt gindex = 0; + /* only do something if we have a charmap, and we have glyphs at all */ if ( face && face->charmap && face->num_glyphs ) { gindex = FT_Get_Char_Index( face, 0 ); @@ -3943,11 +3947,17 @@ static void ft_remove_renderer( FT_Module module ) { - FT_Library library = module->library; - FT_Memory memory = library->memory; + FT_Library library; + FT_Memory memory; FT_ListNode node; + library = module->library; + if ( !library ) + return; + + memory = library->memory; + node = FT_List_Find( &library->renderers, module ); if ( node ) { @@ -4463,7 +4473,7 @@ } - FT_Error + static FT_Error ft_property_do( FT_Library library, const FT_String* module_name, const FT_String* property_name, @@ -4871,6 +4881,8 @@ *p_arg1 = subg->arg1; *p_arg2 = subg->arg2; *p_transform = subg->transform; + + error = FT_Err_Ok; } return error; diff --git a/src/base/ftoutln.c b/src/base/ftoutln.c index 35df0cd..4a39dcd 100644 --- a/src/base/ftoutln.c +++ b/src/base/ftoutln.c @@ -4,7 +4,7 @@ /* */ /* FreeType outline management (body). */ /* */ -/* Copyright 1996-2008, 2010, 2012-2013 by */ +/* Copyright 1996-2008, 2010, 2012-2014 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -128,7 +128,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--; diff --git a/src/base/ftrfork.c b/src/base/ftrfork.c index 8049117..5352970 100644 --- a/src/base/ftrfork.c +++ b/src/base/ftrfork.c @@ -4,7 +4,7 @@ /* */ /* Embedded resource forks accessor (body). */ /* */ -/* Copyright 2004-2010, 2013 by */ +/* Copyright 2004-2010, 2013, 2014 by */ /* Masatake YAMATO and Redhat K.K. */ /* */ /* FT_Raccess_Get_HeaderInfo() and raccess_guess_darwin_hfsplus() are */ @@ -29,6 +29,7 @@ #include FT_INTERNAL_STREAM_H #include FT_INTERNAL_RFORK_H #include "basepic.h" +#include "ftbase.h" #undef FT_COMPONENT #define FT_COMPONENT trace_raccess @@ -151,6 +152,7 @@ FT_Long map_offset, FT_Long rdata_pos, FT_Long tag, + FT_Bool sort_by_res_id, FT_Long **offsets, FT_Long *count ) { @@ -163,6 +165,7 @@ FT_RFork_Ref *ref = NULL; + FT_TRACE3(( "\n" )); error = FT_Stream_Seek( stream, map_offset ); if ( error ) return error; @@ -183,6 +186,8 @@ (char)( 0xff & ( tag_internal >> 16 ) ), (char)( 0xff & ( tag_internal >> 8 ) ), (char)( 0xff & ( tag_internal >> 0 ) ) )); + FT_TRACE3(( " : subcount=%d, suboffset=0x%04x\n", + subcnt, rpos )); if ( tag_internal == tag ) { @@ -208,11 +213,24 @@ goto Exit; ref[j].offset = temp & 0xFFFFFFL; + FT_TRACE3(( " [%d]:" + " resource_id=0x%04x, offset=0x%08x\n", + j, ref[j].res_id, ref[j].offset )); } - ft_qsort( ref, *count, sizeof ( FT_RFork_Ref ), - ( int(*)(const void*, const void*) ) - ft_raccess_sort_ref_by_id ); + if (sort_by_res_id) + { + ft_qsort( ref, *count, sizeof ( FT_RFork_Ref ), + ( int(*)(const void*, const void*) ) + ft_raccess_sort_ref_by_id ); + + FT_TRACE3(( " -- sort resources by their ids --\n" )); + for ( j = 0; j < *count; ++ j ) { + FT_TRACE3(( " [%d]:" + " resource_id=0x%04x, offset=0x%08x\n", + j, ref[j].res_id, ref[j].offset )); + } + } if ( FT_NEW_ARRAY( offsets_internal, *count ) ) goto Exit; diff --git a/src/base/ftutil.c b/src/base/ftutil.c index 879d027..9f37189 100644 --- a/src/base/ftutil.c +++ b/src/base/ftutil.c @@ -411,26 +411,4 @@ } - FT_BASE_DEF( FT_UInt32 ) - ft_highpow2( FT_UInt32 value ) - { - FT_UInt32 value2; - - - /* - * We simply clear the lowest bit in each iteration. When - * we reach 0, we know that the previous value was our result. - */ - for ( ;; ) - { - value2 = value & (value - 1); /* clear lowest bit */ - if ( value2 == 0 ) - break; - - value = value2; - } - return value; - } - - /* END */ |