1 /* Copyright (C) 2003 Aladdin Enterprises. All rights reserved. 2 3 This software is provided AS-IS with no warranty, either express or 4 implied. 5 6 This software is distributed under license and may not be copied, 7 modified or distributed except as expressly authorized under the terms 8 of the license contained in the file LICENSE in this distribution. 9 10 For more information about licensing, please refer to 11 http://www.ghostscript.com/licensing/. For information on 12 commercial licensing, go to http://www.artifex.com/licensing/ or 13 contact Artifex Software, Inc., 101 Lucas Valley Road #110, 14 San Rafael, CA 94903, U.S.A., +1(415)492-9861. 15 */ 16 17 /* $Id: ttcalc.h,v 1.1 2003/10/01 13:44:56 igor Exp $ */ 18 19 /* Changes after FreeType: cut out the TrueType instruction interpreter. */ 20 21 /******************************************************************* 22 * 23 * ttcalc.h 24 * 25 * Arithmetic Computations (specification). 26 * 27 * Copyright 1996-1998 by 28 * David Turner, Robert Wilhelm, and Werner Lemberg. 29 * 30 * This file is part of the FreeType project, and may only be used 31 * modified and distributed under the terms of the FreeType project 32 * license, LICENSE.TXT. By continuing to use, modify, or distribute 33 * this file you indicate that you have read the license and 34 * understand and accept it fully. 35 * 36 ******************************************************************/ 37 38 #ifndef TTCALC_H 39 #define TTCALC_H 40 41 #include "ttcommon.h" 42 #include "tttypes.h" 43 44 /* IntN types: */ 45 /* */ 46 /* Used to guarantee the size of some specific integers. */ 47 /* */ 48 /* Of course, they are equivalent to Short, UShort, Long, etc. */ 49 /* but parts of this unit could be used by different programs. */ 50 /* */ 51 52 typedef signed short Int16; 53 typedef unsigned short Word16; 54 55 #if SIZEOF_INT == 4 56 57 typedef signed int Int32; 58 typedef unsigned int Word32; 59 60 #elif SIZEOF_LONG == 4 61 62 typedef signed long Int32; 63 typedef unsigned long Word32; 64 65 #else 66 #error "no 32bit type found" 67 #endif 68 69 #if SIZEOF_LONG == 8 70 71 /* LONG64 must be defined when a 64-bit type is available */ 72 #define LONG64 73 #define INT64 long 74 75 #else 76 77 /* GCC provides the non-ANSI 'long long' 64-bit type. You can activate */ 78 /* by defining the _GNUC_LONG64_ macro in 'ttconfig.h'. Note that this */ 79 /* will produce many -ansi warnings during library compilation. */ 80 #ifdef _GNUC_LONG64_ 81 82 #define LONG64 83 #define INT64 long long 84 85 #endif /* __GNUC__ */ 86 87 /* Microsoft Visual C++ also supports 64-bit integers */ 88 #ifdef _MSC_VER 89 #if _MSC_VER >= 1100 90 91 #define LONG64 92 #define INT64 __int64 93 94 #endif 95 #endif 96 97 #endif 98 99 100 #ifdef __cplusplus 101 extern "C" { 102 #endif 103 104 #ifdef LONG64 105 106 typedef INT64 Int64; 107 108 /* Fast muldiv */ 109 #define FMulDiv( x, y, z ) ( (Int64)(x) * (y) / (z) ) 110 111 /* Fast muldiv_round */ 112 #define FMulDiv_Round( x, y, z ) ( ( (Int64)(x) * (y) + (z)/2 ) / (z) ) 113 114 #define ADD_64( x, y, z ) ( (z) = (x) + (y) ) 115 #define SUB_64( x, y, z ) ( (z) = (x) - (y) ) 116 #define MUL_64( x, y, z ) ( (z) = (Int64)(x) * (y) ) 117 118 #define DIV_64( x, y ) ( (x) / (y) ) 119 120 #define SQRT_64( x ) Sqrt64( x ) 121 #define SQRT_32( x ) Sqrt32( x ) 122 123 Int32 MulDiv( Int32 a, Int32 b, Int32 c ); 124 Int32 MulDiv_Round( Int32 a, Int32 b, Int32 c ); 125 126 Int32 Sqrt32( Int32 l ); 127 Int32 Sqrt64( Int64 l ); 128 129 #else /* LONG64 */ 130 131 struct _Int64 132 { 133 Word32 lo; 134 Word32 hi; 135 }; 136 137 typedef struct _Int64 Int64; 138 139 #define FMulDiv( x, y, z ) MulDiv( x, y, z ) 140 #define FMulDiv_Round( x, y, z ) MulDiv_Round( x, y, z ) 141 142 #define ADD_64( x, y, z ) Add64( &x, &y, &z ) 143 #define SUB_64( x, y, z ) Sub64( &x, &y, &z ) 144 #define MUL_64( x, y, z ) MulTo64( x, y, &z ) 145 146 #define DIV_64( x, y ) Div64by32( &x, y ) 147 148 #define SQRT_64( x ) Sqrt64( &x ) 149 #define SQRT_32( x ) Sqrt32( x ) 150 151 Int32 MulDiv( Int32 a, Int32 b, Int32 c ); 152 Int32 MulDiv_Round( Int32 a, Int32 b, Int32 c ); 153 154 void Add64( Int64* x, Int64* y, Int64* z ); 155 void Sub64( Int64* x, Int64* y, Int64* z ); 156 157 void MulTo64( Int32 x, Int32 y, Int64* z ); 158 159 Int32 Div64by32( Int64* x, Int32 y ); 160 161 Int Order64( Int64* z ); 162 Int Order32( Int32 z ); 163 164 Int32 Sqrt32( Int32 l ); 165 Int32 Sqrt64( Int64* l ); 166 167 #endif /* LONG64 */ 168 169 170 #define MUL_FIXED( a, b ) MulDiv_Round( (a), (b), 1 << 16 ) 171 #define INT_TO_F26DOT6( x ) ( (Long)(x) << 6 ) 172 #define INT_TO_F2DOT14( x ) ( (Long)(x) << 14 ) 173 #define INT_TO_FIXED( x ) ( (Long)(x) << 16 ) 174 #define F2DOT14_TO_FIXED( x ) ( (Long)(x) << 2 ) 175 #define FLOAT_TO_FIXED( x ) ( (Long)((x) * 65536.0) ) 176 177 #define ROUND_F26DOT6( x ) ( (x) >= 0 ? ( ((x) + 32) & -64) \ 178 : ( -((32 - (x)) & -64) ) ) 179 180 #ifdef __cplusplus 181 } 182 #endif 183 184 #endif /* TTCALC_H */ 185 186 187 /* END */ 188