Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

334 lines
7.3 KiB

  1. /*++
  2. Copyright (c) 1990-1991 Microsoft Corporation
  3. Module Name:
  4. htmath.h
  5. Abstract:
  6. This module contains the declaration of the halftone math module.
  7. Author:
  8. 28-Mar-1992 Sat 20:57:11 updated -by- Daniel Chou (danielc)
  9. Support FD6 decimal fixed format (upgrade forom UDECI4) for internal
  10. usage.
  11. 16-Jan-1991 Wed 11:01:46 created -by- Daniel Chou (danielc)
  12. [Environment:]
  13. GDI Device Driver - Halftone.
  14. [Notes:]
  15. Revision History:
  16. 10-Oct-1991 Thu 10:00:56 updated -by- Daniel Chou (danielc)
  17. Delete MANTISSASEARCHTABLE structure which repalced with one time
  18. loop up.
  19. --*/
  20. #ifndef _HTMATH_
  21. #define _HTMATH_
  22. #ifdef HTMATH_LIB
  23. #undef HTENTRY
  24. #define HTENTRY FAR
  25. #ifdef ASSERT
  26. #undef ASSERT
  27. #endif
  28. #ifdef ASSERTMSG
  29. #undef ASSERTMSG
  30. #endif
  31. #define ASSERT(exp) assert(exp)
  32. #define ASSERTMSG(msg) assert(msg)
  33. #include <assert.h>
  34. #endif
  35. //
  36. // Define Fix Decimal 6 places type, the FD6 Number is a FIXED 6 decimal point
  37. // number. For example 123456 = 0.123456 -12345678 = -12.345678, because the
  38. // FD6 number using total of 32-bit signed number this leads to maximum FD6
  39. // number = 2147.4836476 and minimum FD6 number is -2147.483648
  40. //
  41. //
  42. typedef long FD6;
  43. typedef FD6 FAR *PFD6;
  44. #define SIZE_FD6 sizeof(FD6)
  45. #define FD6_0 (FD6)0
  46. #define FD6_1 (FD6)1000000
  47. #define FD6_p000001 (FD6)(FD6_1 / 1000000)
  48. #define FD6_p000005 (FD6)(FD6_1 / 200000)
  49. #define FD6_p00001 (FD6)(FD6_1 / 100000)
  50. #define FD6_p00005 (FD6)(FD6_1 / 20000)
  51. #define FD6_p0001 (FD6)(FD6_1 / 10000)
  52. #define FD6_p0005 (FD6)(FD6_1 / 2000)
  53. #define FD6_p001 (FD6)(FD6_1 / 1000)
  54. #define FD6_p005 (FD6)(FD6_1 / 200
  55. #define FD6_p01 (FD6)(FD6_1 / 100)
  56. #define FD6_p05 (FD6)(FD6_1 / 20)
  57. #define FD6_p1 (FD6)(FD6_1 / 10)
  58. #define FD6_p5 (FD6)(FD6_1 / 2)
  59. #define FD6_2 (FD6)(FD6_1 * 2)
  60. #define FD6_3 (FD6)(FD6_1 * 3)
  61. #define FD6_4 (FD6)(FD6_1 * 4)
  62. #define FD6_5 (FD6)(FD6_1 * 5)
  63. #define FD6_6 (FD6)(FD6_1 * 6)
  64. #define FD6_7 (FD6)(FD6_1 * 7)
  65. #define FD6_8 (FD6)(FD6_1 * 8)
  66. #define FD6_9 (FD6)(FD6_1 * 9)
  67. #define FD6_10 (FD6)(FD6_1 * 10)
  68. #define FD6_100 (FD6)(FD6_1 * 100)
  69. #define FD6_1000 (FD6)(FD6_1 * 1000)
  70. #define FD6_MIN (FD6)-2147483648
  71. #define FD6_MAX (FD6)2147483647
  72. #define UDECI4ToFD6(x) (FD6)((FD6)(DWORD)(x) * (FD6)100)
  73. #define DECI4ToFD6(x) (FD6)((FD6)(x) * (FD6)100)
  74. #define INTToFD6(i) (FD6)((LONG)(i) * (LONG)FD6_1)
  75. //
  76. // MATRIX3x3
  77. //
  78. // a 3 x 3 matrix definitions as
  79. //
  80. // | Xr Xg Xb | | Matrix[0][0] Matrix[0][1] Matrix[0][2] |
  81. // | Yr Yg Yb | = | Matrix[1][0] Matrix[1][1] Matrix[1][2] |
  82. // | Zr Zg Zb | | Matrix[2][0] Matrix[2][1] Matrix[2][2] |
  83. //
  84. // Notice each number is a FD6 value.
  85. //
  86. typedef struct _MATRIX3x3 {
  87. FD6 m[3][3];
  88. } MATRIX3x3, FAR *PMATRIX3x3;
  89. //
  90. // This is used for the MulDivFD6Pairs()'s TotalFD6Pairs parameter
  91. //
  92. typedef struct _MULDIVCOUNT {
  93. WORD Size;
  94. WORD Flag;
  95. } MULDIVCOUNT;
  96. typedef struct _MULDIVPAIR {
  97. union {
  98. MULDIVCOUNT Info;
  99. FD6 Mul;
  100. } Pair1;
  101. FD6 Pair2;
  102. } MULDIVPAIR, FAR *PMULDIVPAIR;
  103. #define MULDIV_NO_DIVISOR 0x0000
  104. #define MULDIV_HAS_DIVISOR 0x0001
  105. #define MAKE_MULDIV_SIZE(ap, c) (ap)[0].Pair1.Info.Size=(WORD)(c)
  106. #define MAKE_MULDIV_FLAG(ap, f) (ap)[0].Pair1.Info.Flag=(WORD)(f)
  107. #define MAKE_MULDIV_INFO(ap,c,f) MAKE_MULDIV_SIZE(ap, c); \
  108. MAKE_MULDIV_FLAG(ap, f)
  109. #define MAKE_MULDIV_DVSR(ap,dvsr) (ap)[0].Pair2=(FD6)(dvsr)
  110. #define MAKE_MULDIV_PAIR(ap,i,p1,p2) (ap)[i].Pair1.Mul=(p1); \
  111. (ap)[i].Pair2=(p2)
  112. //
  113. // Following defined is used for the RaisePower()
  114. //
  115. //
  116. #define RPF_RADICAL W_BITPOS(0)
  117. #define RPF_INTEXP W_BITPOS(1)
  118. #define Power(b,i) RaisePower((FD6)(b), (FD6)(i), 0)
  119. #define Radical(b,i) RaisePower((FD6)(b), (FD6)(i), RPF_RADICAL)
  120. #define Square(x) MulFD6((x), (x))
  121. #define SquareRoot(x) RaisePower((FD6)(x), (FD6)2, RPF_RADICAL | RPF_INTEXP)
  122. #define CubeRoot(x) RaisePower((FD6)(x), (FD6)3, RPF_RADICAL | RPF_INTEXP)
  123. //
  124. // Following two marcos make up the Nature Logarithm and Exponential functions
  125. // the nature logarithm has base approximate to 2.718282 (2.718281828)
  126. //
  127. // LogNature(x) = Log10(x) / Log10(2.718281828)
  128. // = Log10(x) / (1.0 / 0.434294482)
  129. // = Log10(x) * 2.302585093
  130. // = Log10(x) * 2.302585 <== FD6 Approximation
  131. //
  132. // x
  133. // Exponential(x) = 2.718281828
  134. // = Power(2.718282, x) <== FD6 Approximation
  135. //
  136. #define NATURE_LOG_BASE (FD6)2718282
  137. #define NATURE_LOG_SCALE (FD6)2302585
  138. #define LogN(x) (FD6)MulFD6(Log((x), NATURE_LOG_SCALE)
  139. #define Exp(x) (FD6)Power(NATURE_LOG_BASE, (x))
  140. //
  141. // These functions are defined as macros for faster excess
  142. //
  143. // Radical is the root function which 'x' is the Radicand, Index is the
  144. // radical index
  145. //
  146. //
  147. // This macro multiply a FD6 number by a LONG integer. The 'Num' is FD6
  148. // Number, and 'l' is a long integer.
  149. //
  150. #define FD6xL(Num, l) (FD6)((LONG)(Num) * (LONG)l)
  151. //
  152. // CIE Y <-> L Conversion
  153. //
  154. #define CIE_L2I(L) (((L) > (FD6)79996) ? \
  155. Cube(DivFD6((L) + (FD6)160000, (FD6)1160000)) : \
  156. DivFD6((L), (FD6)9033000))
  157. #define CIE_y3I2L(Y,y3) (((Y) > (FD6)8856) ? \
  158. MulFD6((y3),(FD6)1160000) - (FD6)160000 : \
  159. MulFD6((Y), (FD6)9033000))
  160. #define CIE_I2L(Y) CIE_y3I2L(Y, CubeRoot(Y))
  161. //
  162. // Function Prototype
  163. //
  164. #ifdef HT_OK_GEN_80x86_CODES
  165. FD6
  166. HTENTRY
  167. Cube(
  168. FD6 Number
  169. );
  170. #else
  171. #define Cube(x) MulFD6((x), Square(x))
  172. #endif
  173. FD6
  174. HTENTRY
  175. Log(
  176. FD6 Number
  177. );
  178. FD6
  179. HTENTRY
  180. AntiLog(
  181. FD6 Number
  182. );
  183. FD6
  184. HTENTRY
  185. RaisePower(
  186. FD6 BaseNumber,
  187. FD6 Exponent,
  188. WORD Flags
  189. );
  190. BOOL
  191. HTENTRY
  192. ComputeInverseMatrix3x3(
  193. PMATRIX3x3 pInMatrix,
  194. PMATRIX3x3 pOutMatrix
  195. );
  196. VOID
  197. HTENTRY
  198. ConcatTwoMatrix3x3(
  199. PMATRIX3x3 pConcat,
  200. PMATRIX3x3 pMatrix,
  201. PMATRIX3x3 pOutMatrix
  202. );
  203. FD6
  204. HTENTRY
  205. MulFD6(
  206. FD6 Multiplicand,
  207. FD6 Multiplier
  208. );
  209. FD6
  210. HTENTRY
  211. DivFD6(
  212. FD6 Dividend,
  213. FD6 Divisor
  214. );
  215. FD6
  216. HTENTRY
  217. FD6DivL(
  218. FD6 Dividend,
  219. LONG Divisor
  220. );
  221. FD6
  222. HTENTRY
  223. MulDivFD6Pairs(
  224. PMULDIVPAIR pMulDivPair
  225. );
  226. FD6
  227. HTENTRY
  228. FractionToMantissa(
  229. FD6 Fraction,
  230. DWORD CorrectData
  231. );
  232. FD6
  233. HTENTRY
  234. MantissaToFraction(
  235. FD6 Mantissa,
  236. DWORD CorrectData
  237. );
  238. DWORD
  239. HTENTRY
  240. ComputeChecksum(
  241. LPBYTE pData,
  242. DWORD InitialChecksum,
  243. DWORD DataSize
  244. );
  245. #endif // _HTMATH_