shithub: freetype+ttf2subf

Download patch

ref: 869fb8c49ddf292d6daf4826172a308973d3e11f
parent: e0469372be3870a5ad60b2c4586e9c281357bd28
author: Alexei Podtelezhnikov <[email protected]>
date: Wed Jan 23 14:43:28 EST 2013

[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.

git/fs: mount .git/fs: mount/attach disallowed
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2013-01-23  Alexei Podtelezhnikov  <[email protected]>
+
+	[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  <[email protected]>
 
 	[truetype] Fix font height.
--- a/include/freetype/internal/ftcalc.h
+++ b/include/freetype/internal/ftcalc.h
@@ -125,7 +125,6 @@
    *  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,
@@ -154,6 +153,13 @@
                      FT_Pos  in_y,
                      FT_Pos  out_x,
                      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  )
--- 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 */
--- a/src/base/fttrigon.c
+++ b/src/base/fttrigon.c
@@ -118,7 +118,7 @@
   static FT_Int
   ft_trig_prenorm( FT_Vector*  vec )
   {
-    FT_Fixed  x, y, z;
+    FT_Fixed  x, y;
     FT_Int    shift;
 
 
@@ -125,35 +125,7 @@
     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 )
     {