The BIG graph update
[rrdtool.git] / libraries / freetype-2.0.5 / include / freetype / internal / ftcalc.h
1 /***************************************************************************/
2 /*                                                                         */
3 /*  ftcalc.h                                                               */
4 /*                                                                         */
5 /*    Arithmetic computations (specification).                             */
6 /*                                                                         */
7 /*  Copyright 1996-2001 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
27 FT_BEGIN_HEADER
28
29
30 /* OLD 64-bits internal API */
31
32 #ifdef FT_CONFIG_OPTION_OLD_CALCS
33
34 #ifdef FT_LONG64
35
36   typedef FT_INT64  FT_Int64;
37
38 #define ADD_64( x, y, z )  z = (x) + (y)
39 #define MUL_64( x, y, z )  z = (FT_Int64)(x) * (y)
40 #define DIV_64( x, y )     ( (x) / (y) )
41
42 #define SQRT_64( z )  FT_Sqrt64( z )
43
44
45   /*************************************************************************/
46   /*                                                                       */
47   /* <Function>                                                            */
48   /*    FT_Sqrt64                                                          */
49   /*                                                                       */
50   /* <Description>                                                         */
51   /*    Computes the square root of a 64-bit value.  That sounds stupid,   */
52   /*    but it is needed to obtain maximal accuracy in the TrueType        */
53   /*    bytecode interpreter.                                              */
54   /*                                                                       */
55   /* <Input>                                                               */
56   /*    l :: A 64-bit integer.                                             */
57   /*                                                                       */
58   /* <Return>                                                              */
59   /*    The 32-bit square-root.                                            */
60   /*                                                                       */
61   FT_EXPORT( FT_Int32 )
62   FT_Sqrt64( FT_Int64  l );
63
64
65 #else /* !FT_LONG64 */
66
67
68   typedef struct  FT_Int64_
69   {
70     FT_UInt32  lo;
71     FT_UInt32  hi;
72
73   } FT_Int64;
74
75
76 #define ADD_64( x, y, z )  FT_Add64( &x, &y, &z )
77 #define MUL_64( x, y, z )  FT_MulTo64( x, y, &z )
78 #define DIV_64( x, y )     FT_Div64by32( &x, y )
79
80
81   /*************************************************************************/
82   /*                                                                       */
83   /* <Function>                                                            */
84   /*    FT_Add64                                                           */
85   /*                                                                       */
86   /* <Description>                                                         */
87   /*    Add two Int64 values.                                              */
88   /*                                                                       */
89   /* <Input>                                                               */
90   /*    x :: A pointer to the first value to be added.                     */
91   /*    y :: A pointer to the second value to be added.                    */
92   /*                                                                       */
93   /* <Output>                                                              */
94   /*    z :: A pointer to the result of `x + y'.                           */
95   /*                                                                       */
96   /* <Note>                                                                */
97   /*    Will be wrapped by the ADD_64() macro.                             */
98   /*                                                                       */
99   FT_EXPORT( void )
100   FT_Add64( FT_Int64*  x,
101             FT_Int64*  y,
102             FT_Int64  *z );
103
104
105   /*************************************************************************/
106   /*                                                                       */
107   /* <Function>                                                            */
108   /*    FT_MulTo64                                                         */
109   /*                                                                       */
110   /* <Description>                                                         */
111   /*    Multiplies two Int32 integers.  Returns an Int64 integer.          */
112   /*                                                                       */
113   /* <Input>                                                               */
114   /*    x :: The first multiplier.                                         */
115   /*    y :: The second multiplier.                                        */
116   /*                                                                       */
117   /* <Output>                                                              */
118   /*    z :: A pointer to the result of `x * y'.                           */
119   /*                                                                       */
120   /* <Note>                                                                */
121   /*    Will be wrapped by the MUL_64() macro.                             */
122   /*                                                                       */
123   FT_EXPORT( void )
124   FT_MulTo64( FT_Int32   x,
125               FT_Int32   y,
126               FT_Int64  *z );
127
128
129   /*************************************************************************/
130   /*                                                                       */
131   /* <Function>                                                            */
132   /*    FT_Div64by32                                                       */
133   /*                                                                       */
134   /* <Description>                                                         */
135   /*    Divides an Int64 value by an Int32 value.  Returns an Int32        */
136   /*    integer.                                                           */
137   /*                                                                       */
138   /* <Input>                                                               */
139   /*    x :: A pointer to the dividend.                                    */
140   /*    y :: The divisor.                                                  */
141   /*                                                                       */
142   /* <Return>                                                              */
143   /*    The result of `x / y'.                                             */
144   /*                                                                       */
145   /* <Note>                                                                */
146   /*    Will be wrapped by the DIV_64() macro.                             */
147   /*                                                                       */
148   FT_EXPORT( FT_Int32 )
149   FT_Div64by32( FT_Int64*  x,
150                 FT_Int32   y );
151
152
153 #define SQRT_64( z )  FT_Sqrt64( &z )
154
155
156   /*************************************************************************/
157   /*                                                                       */
158   /* <Function>                                                            */
159   /*    FT_Sqrt64                                                          */
160   /*                                                                       */
161   /* <Description>                                                         */
162   /*    Computes the square root of a 64-bits value.  That sounds stupid,  */
163   /*    but it is needed to obtain maximal accuracy in the TrueType        */
164   /*    bytecode interpreter.                                              */
165   /*                                                                       */
166   /* <Input>                                                               */
167   /*    z :: A pointer to a 64-bit integer.                                */
168   /*                                                                       */
169   /* <Return>                                                              */
170   /*    The 32-bit square-root.                                            */
171   /*                                                                       */
172   FT_EXPORT( FT_Int32 )
173   FT_Sqrt64( FT_Int64*  x );
174
175
176 #endif /* !FT_LONG64 */
177
178 #endif /* FT_CONFIG_OPTION_OLD_CALCS */
179
180
181
182   FT_EXPORT( FT_Int32 )  FT_SqrtFixed( FT_Int32  x );
183
184
185 #ifndef FT_CONFIG_OPTION_OLD_CALCS
186
187 #define SQRT_32( x )  FT_Sqrt32( x )
188
189
190   /*************************************************************************/
191   /*                                                                       */
192   /* <Function>                                                            */
193   /*    FT_Sqrt32                                                          */
194   /*                                                                       */
195   /* <Description>                                                         */
196   /*    Computes the square root of an Int32 integer (which will be        */
197   /*    handled as an unsigned long value).                                */
198   /*                                                                       */
199   /* <Input>                                                               */
200   /*    x :: The value to compute the root for.                            */
201   /*                                                                       */
202   /* <Return>                                                              */
203   /*    The result of `sqrt(x)'.                                           */
204   /*                                                                       */
205   FT_EXPORT( FT_Int32 )
206   FT_Sqrt32( FT_Int32  x );
207
208
209 #endif /* !FT_CONFIG_OPTION_OLD_CALCS */
210
211
212   /*************************************************************************/
213   /*                                                                       */
214   /* FT_MulDiv() and FT_MulFix() are declared in freetype.h.               */
215   /*                                                                       */
216   /*************************************************************************/
217
218
219 #define INT_TO_F26DOT6( x )    ( (FT_Long)(x) << 6  )
220 #define INT_TO_F2DOT14( x )    ( (FT_Long)(x) << 14 )
221 #define INT_TO_FIXED( x )      ( (FT_Long)(x) << 16 )
222 #define F2DOT14_TO_FIXED( x )  ( (FT_Long)(x) << 2  )
223 #define FLOAT_TO_FIXED( x )    ( (FT_Long)( x * 65536.0 ) )
224
225 #define ROUND_F26DOT6( x )     ( x >= 0 ? (    ( (x) + 32 ) & -64 )     \
226                                         : ( -( ( 32 - (x) ) & -64 ) ) )
227
228
229 FT_END_HEADER
230
231 #endif /* __FTCALC_H__ */
232
233
234 /* END */