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 18 19#ifndef __FTCALC_H__ 20#define __FTCALC_H__ 21 22 23#include <ft2build.h> 24#include FT_FREETYPE_H 25 26 27FT_BEGIN_HEADER 28 29 30 /*************************************************************************/ 31 /* */ 32 /* <Function> */ 33 /* FT_FixedSqrt */ 34 /* */ 35 /* <Description> */ 36 /* Computes the square root of a 16.16 fixed-point value. */ 37 /* */ 38 /* <Input> */ 39 /* x :: The value to compute the root for. */ 40 /* */ 41 /* <Return> */ 42 /* The result of `sqrt(x)'. */ 43 /* */ 44 /* <Note> */ 45 /* This function is not very fast. */ 46 /* */ 47 FT_BASE( FT_Int32 ) 48 FT_SqrtFixed( FT_Int32 x ); 49 50 51 /*************************************************************************/ 52 /* */ 53 /* FT_MulDiv() and FT_MulFix() are declared in freetype.h. */ 54 /* */ 55 /*************************************************************************/ 56 57 58 /*************************************************************************/ 59 /* */ 60 /* <Function> */ 61 /* FT_MulDiv_No_Round */ 62 /* */ 63 /* <Description> */ 64 /* A very simple function used to perform the computation `(a*b)/c' */ 65 /* (without rounding) with maximum accuracy (it uses a 64-bit */ 66 /* intermediate integer whenever necessary). */ 67 /* */ 68 /* This function isn't necessarily as fast as some processor specific */ 69 /* operations, but is at least completely portable. */ 70 /* */ 71 /* <Input> */ 72 /* a :: The first multiplier. */ 73 /* b :: The second multiplier. */ 74 /* c :: The divisor. */ 75 /* */ 76 /* <Return> */ 77 /* The result of `(a*b)/c'. This function never traps when trying to */ 78 /* divide by zero; it simply returns `MaxInt' or `MinInt' depending */ 79 /* on the signs of `a' and `b'. */ 80 /* */ 81 FT_BASE( FT_Long ) 82 FT_MulDiv_No_Round( FT_Long a, 83 FT_Long b, 84 FT_Long c ); 85 86 87 /* 88 * A variant of FT_Matrix_Multiply which scales its result afterwards. 89 * The idea is that both `a' and `b' are scaled by factors of 10 so that 90 * the values are as precise as possible to get a correct result during 91 * the 64bit multiplication. Let `sa' and `sb' be the scaling factors of 92 * `a' and `b', respectively, then the scaling factor of the result is 93 * `sa*sb'. 94 */ 95 FT_BASE( void ) 96 FT_Matrix_Multiply_Scaled( const FT_Matrix* a, 97 FT_Matrix *b, 98 FT_Long scaling ); 99 100 101 /* 102 * A variant of FT_Vector_Transform. See comments for 103 * FT_Matrix_Multiply_Scaled. 104 */ 105 FT_BASE( void ) 106 FT_Vector_Transform_Scaled( FT_Vector* vector, 107 const FT_Matrix* matrix, 108 FT_Long scaling ); 109 110 111 /* 112 * Return -1, 0, or +1, depending on the orientation of a given corner. 113 * We use the Cartesian coordinate system, with positive vertical values 114 * going upwards. The function returns +1 if the corner turns to the 115 * left, -1 to the right, and 0 for undecidable cases. 116 */ 117 FT_BASE( FT_Int ) 118 ft_corner_orientation( FT_Pos in_x, 119 FT_Pos in_y, 120 FT_Pos out_x, 121 FT_Pos out_y ); 122 123 /* 124 * Return TRUE if a corner is flat or nearly flat. This is equivalent to 125 * saying that the angle difference between the `in' and `out' vectors is 126 * very small. 127 */ 128 FT_BASE( FT_Int ) 129 ft_corner_is_flat( FT_Pos in_x, 130 FT_Pos in_y, 131 FT_Pos out_x, 132 FT_Pos out_y ); 133 134 135 /* 136 * Return the most significant bit index. 137 */ 138 FT_BASE( FT_Int ) 139 FT_MSB( FT_UInt32 z ); 140 141 142 /* 143 * Return sqrt(x*x+y*y), which is the same as `FT_Vector_Length' but uses 144 * two fixed-point arguments instead. 145 */ 146 FT_BASE( FT_Fixed ) 147 FT_Hypot( FT_Fixed x, 148 FT_Fixed y ); 149 150 151#define INT_TO_F26DOT6( x ) ( (FT_Long)(x) << 6 ) 152#define INT_TO_F2DOT14( x ) ( (FT_Long)(x) << 14 ) 153#define INT_TO_FIXED( x ) ( (FT_Long)(x) << 16 ) 154#define F2DOT14_TO_FIXED( x ) ( (FT_Long)(x) << 2 ) 155#define FLOAT_TO_FIXED( x ) ( (FT_Long)( x * 65536.0 ) ) 156#define FIXED_TO_INT( x ) ( FT_RoundFix( x ) >> 16 ) 157 158#define ROUND_F26DOT6( x ) ( x >= 0 ? ( ( (x) + 32 ) & -64 ) \ 159 : ( -( ( 32 - (x) ) & -64 ) ) ) 160 161 162FT_END_HEADER 163 164#endif /* __FTCALC_H__ */ 165 166 167/* END */ 168