From 869fb8c49ddf292d6daf4826172a308973d3e11f Mon Sep 17 00:00:00 2001 From: Alexei Podtelezhnikov Date: Wed, 23 Jan 2013 19:43:28 -0500 Subject: [PATCH] [base] Split out MSB function. * src/base/fttrigon.c (ft_trig_prenorm): Borrow from here. * include/freetype/internal/ftcalc.h (FT_MSB): Declare here. * src/base/ftcalc.c (FT_MSB): Define here. --- ChangeLog | 8 +++++++ include/freetype/internal/ftcalc.h | 8 ++++++- src/base/ftcalc.c | 36 ++++++++++++++++++++++++++++++ src/base/fttrigon.c | 32 ++------------------------ 4 files changed, 53 insertions(+), 31 deletions(-) diff --git a/ChangeLog b/ChangeLog index 114ddfb25..01db3c4b8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2013-01-23 Alexei Podtelezhnikov + + [base] Split out MSB function. + + * src/base/fttrigon.c (ft_trig_prenorm): Borrow from here. + * include/freetype/internal/ftcalc.h (FT_MSB): Declare here. + * src/base/ftcalc.c (FT_MSB): Define here. + 2013-01-22 Werner Lemberg [truetype] Fix font height. diff --git a/include/freetype/internal/ftcalc.h b/include/freetype/internal/ftcalc.h index 56aa07c2d..e4924d05d 100644 --- a/include/freetype/internal/ftcalc.h +++ b/include/freetype/internal/ftcalc.h @@ -125,7 +125,6 @@ FT_BEGIN_HEADER * A variant of FT_Vector_Transform. See comments for * FT_Matrix_Multiply_Scaled. */ - FT_BASE( void ) FT_Vector_Transform_Scaled( FT_Vector* vector, const FT_Matrix* matrix, @@ -156,6 +155,13 @@ FT_BEGIN_HEADER FT_Pos out_y ); + /* + * Return the most significant bit index. + */ + FT_BASE( FT_Int ) + FT_MSB( FT_UInt32 z ); + + #define INT_TO_F26DOT6( x ) ( (FT_Long)(x) << 6 ) #define INT_TO_F2DOT14( x ) ( (FT_Long)(x) << 14 ) #define INT_TO_FIXED( x ) ( (FT_Long)(x) << 16 ) diff --git a/src/base/ftcalc.c b/src/base/ftcalc.c index 2aeea0459..4122fdad6 100644 --- a/src/base/ftcalc.c +++ b/src/base/ftcalc.c @@ -103,6 +103,42 @@ } + FT_BASE_DEF ( FT_Int ) + FT_MSB( FT_UInt32 z ) + { + FT_Int shift = 0; + + /* determine msb bit index in `shift' */ + if ( z >= ( 1L << 16 ) ) + { + z >>= 16; + shift += 16; + } + if ( z >= ( 1L << 8 ) ) + { + z >>= 8; + shift += 8; + } + if ( z >= ( 1L << 4 ) ) + { + z >>= 4; + shift += 4; + } + if ( z >= ( 1L << 2 ) ) + { + z >>= 2; + shift += 2; + } + if ( z >= ( 1L << 1 ) ) + { + z >>= 1; + shift += 1; + } + + return shift; + } + + #ifdef FT_CONFIG_OPTION_OLD_INTERNALS /* documentation is in ftcalc.h */ diff --git a/src/base/fttrigon.c b/src/base/fttrigon.c index 4bd4320c0..e8cc3e3a7 100644 --- a/src/base/fttrigon.c +++ b/src/base/fttrigon.c @@ -118,42 +118,14 @@ static FT_Int ft_trig_prenorm( FT_Vector* vec ) { - FT_Fixed x, y, z; + FT_Fixed x, y; FT_Int shift; x = vec->x; y = vec->y; - z = FT_ABS( x ) | FT_ABS( y ); - shift = 0; - - /* determine msb bit index in `shift' */ - if ( z >= ( 1L << 16 ) ) - { - z >>= 16; - shift += 16; - } - if ( z >= ( 1L << 8 ) ) - { - z >>= 8; - shift += 8; - } - if ( z >= ( 1L << 4 ) ) - { - z >>= 4; - shift += 4; - } - if ( z >= ( 1L << 2 ) ) - { - z >>= 2; - shift += 2; - } - if ( z >= ( 1L << 1 ) ) - { - z >>= 1; - shift += 1; - } + shift = FT_MSB( FT_ABS( x ) | FT_ABS( y ) ); if ( shift <= FT_TRIG_SAFE_MSB ) {