ftcalc.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /***************************************************************************/
  2. /* */
  3. /* ftcalc.h */
  4. /* */
  5. /* Arithmetic computations (specification). */
  6. /* */
  7. /* Copyright 1996-2006, 2008, 2009, 2012-2013 by */
  8. /* David Turner, Robert Wilhelm, and Werner Lemberg. */
  9. /* */
  10. /* This file is part of the FreeType project, and may only be used, */
  11. /* modified, and distributed under the terms of the FreeType project */
  12. /* license, LICENSE.TXT. By continuing to use, modify, or distribute */
  13. /* this file you indicate that you have read the license and */
  14. /* understand and accept it fully. */
  15. /* */
  16. /***************************************************************************/
  17. #ifndef __FTCALC_H__
  18. #define __FTCALC_H__
  19. #include <ft2build.h>
  20. #include FT_FREETYPE_H
  21. FT_BEGIN_HEADER
  22. #if 0
  23. /*************************************************************************/
  24. /* */
  25. /* <Function> */
  26. /* FT_SqrtFixed */
  27. /* */
  28. /* <Description> */
  29. /* Computes the square root of a 16.16 fixed-point value. */
  30. /* */
  31. /* <Input> */
  32. /* x :: The value to compute the root for. */
  33. /* */
  34. /* <Return> */
  35. /* The result of `sqrt(x)'. */
  36. /* */
  37. /* <Note> */
  38. /* This function is not very fast. */
  39. /* */
  40. FT_BASE( FT_Int32 )
  41. FT_SqrtFixed( FT_Int32 x );
  42. #endif /* 0 */
  43. /*************************************************************************/
  44. /* */
  45. /* FT_MulDiv() and FT_MulFix() are declared in freetype.h. */
  46. /* */
  47. /*************************************************************************/
  48. /*************************************************************************/
  49. /* */
  50. /* <Function> */
  51. /* FT_MulDiv_No_Round */
  52. /* */
  53. /* <Description> */
  54. /* A very simple function used to perform the computation `(a*b)/c' */
  55. /* (without rounding) with maximum accuracy (it uses a 64-bit */
  56. /* intermediate integer whenever necessary). */
  57. /* */
  58. /* This function isn't necessarily as fast as some processor specific */
  59. /* operations, but is at least completely portable. */
  60. /* */
  61. /* <Input> */
  62. /* a :: The first multiplier. */
  63. /* b :: The second multiplier. */
  64. /* c :: The divisor. */
  65. /* */
  66. /* <Return> */
  67. /* The result of `(a*b)/c'. This function never traps when trying to */
  68. /* divide by zero; it simply returns `MaxInt' or `MinInt' depending */
  69. /* on the signs of `a' and `b'. */
  70. /* */
  71. FT_BASE( FT_Long )
  72. FT_MulDiv_No_Round( FT_Long a,
  73. FT_Long b,
  74. FT_Long c );
  75. /*
  76. * A variant of FT_Matrix_Multiply which scales its result afterwards.
  77. * The idea is that both `a' and `b' are scaled by factors of 10 so that
  78. * the values are as precise as possible to get a correct result during
  79. * the 64bit multiplication. Let `sa' and `sb' be the scaling factors of
  80. * `a' and `b', respectively, then the scaling factor of the result is
  81. * `sa*sb'.
  82. */
  83. FT_BASE( void )
  84. FT_Matrix_Multiply_Scaled( const FT_Matrix* a,
  85. FT_Matrix *b,
  86. FT_Long scaling );
  87. /*
  88. * A variant of FT_Vector_Transform. See comments for
  89. * FT_Matrix_Multiply_Scaled.
  90. */
  91. FT_BASE( void )
  92. FT_Vector_Transform_Scaled( FT_Vector* vector,
  93. const FT_Matrix* matrix,
  94. FT_Long scaling );
  95. /*
  96. * Return -1, 0, or +1, depending on the orientation of a given corner.
  97. * We use the Cartesian coordinate system, with positive vertical values
  98. * going upwards. The function returns +1 if the corner turns to the
  99. * left, -1 to the right, and 0 for undecidable cases.
  100. */
  101. FT_BASE( FT_Int )
  102. ft_corner_orientation( FT_Pos in_x,
  103. FT_Pos in_y,
  104. FT_Pos out_x,
  105. FT_Pos out_y );
  106. /*
  107. * Return TRUE if a corner is flat or nearly flat. This is equivalent to
  108. * saying that the angle difference between the `in' and `out' vectors is
  109. * very small.
  110. */
  111. FT_BASE( FT_Int )
  112. ft_corner_is_flat( FT_Pos in_x,
  113. FT_Pos in_y,
  114. FT_Pos out_x,
  115. FT_Pos out_y );
  116. /*
  117. * Return the most significant bit index.
  118. */
  119. FT_BASE( FT_Int )
  120. FT_MSB( FT_UInt32 z );
  121. /*
  122. * Return sqrt(x*x+y*y), which is the same as `FT_Vector_Length' but uses
  123. * two fixed-point arguments instead.
  124. */
  125. FT_BASE( FT_Fixed )
  126. FT_Hypot( FT_Fixed x,
  127. FT_Fixed y );
  128. #define INT_TO_F26DOT6( x ) ( (FT_Long)(x) << 6 )
  129. #define INT_TO_F2DOT14( x ) ( (FT_Long)(x) << 14 )
  130. #define INT_TO_FIXED( x ) ( (FT_Long)(x) << 16 )
  131. #define F2DOT14_TO_FIXED( x ) ( (FT_Long)(x) << 2 )
  132. #define FLOAT_TO_FIXED( x ) ( (FT_Long)( x * 65536.0 ) )
  133. #define FIXED_TO_INT( x ) ( FT_RoundFix( x ) >> 16 )
  134. #define ROUND_F26DOT6( x ) ( x >= 0 ? ( ( (x) + 32 ) & -64 ) \
  135. : ( -( ( 32 - (x) ) & -64 ) ) )
  136. FT_END_HEADER
  137. #endif /* __FTCALC_H__ */
  138. /* END */