[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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
diff --git a/ChangeLog b/ChangeLog
index 114ddfb..01db3c4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2013-01-23 Alexei Podtelezhnikov <apodtele@gmail.com>
+
+ [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 <wl@gnu.org>
[truetype] Fix font height.
diff --git a/include/freetype/internal/ftcalc.h b/include/freetype/internal/ftcalc.h
index 56aa07c..e4924d0 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 2aeea04..4122fda 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 4bd4320..e8cc3e3 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 )
{