aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexei Podtelezhnikov <apodtele@gmail.com>2024-05-06 13:39:06 +0000
committerAlexei Podtelezhnikov <apodtele@gmail.com>2024-05-06 13:39:06 +0000
commitd0e3239f32a0fe71c234cf2c1ce7a90cb11b64bb (patch)
tree274d53f07fb628c151d2f3e43e7a318cfbd656c2
parent2edfd7e1687c311e695b1645b0e7f6df6e2b5406 (diff)
downloadfreetype-d0e3239f32a0fe71c234cf2c1ce7a90cb11b64bb.tar.gz
[sdf, bsdf] Use shared FT_SqrtFixed.
FT_SqrtFixed (95b0fe2a6dff) is faster and does not overflow. * src/sdf/ftsdfcommin.h (square_root): Replace with a macro. * src/sdf/ftsdfcommin.c (square_root): Remove function.
-rw-r--r--src/sdf/ftsdfcommon.c43
-rw-r--r--src/sdf/ftsdfcommon.h3
2 files changed, 1 insertions, 45 deletions
diff --git a/src/sdf/ftsdfcommon.c b/src/sdf/ftsdfcommon.c
index 5841ded21..6b2cf7dfe 100644
--- a/src/sdf/ftsdfcommon.c
+++ b/src/sdf/ftsdfcommon.c
@@ -24,49 +24,6 @@
/**************************************************************************
*
- * common functions
- *
- */
-
- /*
- * Original algorithm:
- *
- * https://github.com/chmike/fpsqrt
- *
- * Use this to compute the square root of a 16.16 fixed-point number.
- */
- FT_LOCAL_DEF( FT_16D16 )
- square_root( FT_16D16 val )
- {
- FT_ULong t, q, b, r;
-
-
- r = (FT_ULong)val;
- b = 0x40000000L;
- q = 0;
-
- while ( b > 0x40L )
- {
- t = q + b;
-
- if ( r >= t )
- {
- r -= t;
- q = t + b;
- }
-
- r <<= 1;
- b >>= 1;
- }
-
- q >>= 8;
-
- return (FT_16D16)q;
- }
-
-
- /**************************************************************************
- *
* format and sign manipulating functions
*
*/
diff --git a/src/sdf/ftsdfcommon.h b/src/sdf/ftsdfcommon.h
index 44274e349..d0f623f9f 100644
--- a/src/sdf/ftsdfcommon.h
+++ b/src/sdf/ftsdfcommon.h
@@ -122,8 +122,7 @@ FT_BEGIN_HEADER
typedef FT_BBox FT_CBox; /* control box of a curve */
- FT_LOCAL( FT_16D16 )
- square_root( FT_16D16 val );
+#define square_root( x ) (FT_16D16)FT_SqrtFixed( (FT_UInt32)( x ) )
FT_LOCAL( FT_SDFFormat )
map_fixed_to_sdf( FT_16D16 dist,