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.

193 lines
3.5 KiB

  1. /**************************************************************************\
  2. *
  3. * Copyright (c) 1999 Microsoft Corporation
  4. *
  5. * Module Name:
  6. *
  7. * GDI+ runtime initialization
  8. *
  9. * Abstract:
  10. *
  11. * Initialization and uninitialization functions for the GDI+ run-time.
  12. *
  13. * Revision History:
  14. *
  15. * 09/08/1999 agodfrey
  16. * Created it.
  17. *
  18. \**************************************************************************/
  19. #include "precomp.hpp"
  20. HINSTANCE DllInstance;
  21. /**************************************************************************\
  22. *
  23. * Function Description:
  24. *
  25. * GDI+ run-time initialization function.
  26. *
  27. * Arguments:
  28. *
  29. * NONE
  30. *
  31. * Return Value:
  32. *
  33. * FALSE if failure
  34. *
  35. \**************************************************************************/
  36. BOOL
  37. GpRuntime::Initialize()
  38. {
  39. OSInfo::Initialize();
  40. if (!DllInstance)
  41. DllInstance = GetModuleHandleA(0);
  42. return TRUE;
  43. }
  44. /**************************************************************************\
  45. *
  46. * Function Description:
  47. *
  48. * GDI+ run-time cleanup function.
  49. *
  50. * Arguments:
  51. *
  52. * NONE
  53. *
  54. * Return Value:
  55. *
  56. * NONE
  57. *
  58. \**************************************************************************/
  59. VOID
  60. GpRuntime::Uninitialize()
  61. {
  62. }
  63. /**************************************************************************\
  64. *
  65. * Function Description:
  66. *
  67. * raise to an integer power (up to
  68. *
  69. * Arguments:
  70. *
  71. * exp - an integer exponent
  72. *
  73. * Return Value:
  74. *
  75. * 2^exp. If exp >= 31, then return 2^31.
  76. *
  77. \**************************************************************************/
  78. UINT
  79. GpRuntime::Gppow2 (UINT exp)
  80. {
  81. UINT maxexp = (sizeof(UINT)*8) - 1;
  82. UINT rv = 1;
  83. if (exp >= maxexp)
  84. {
  85. return (rv << maxexp);
  86. }
  87. else
  88. {
  89. while (exp--)
  90. {
  91. rv <<= 1;
  92. }
  93. }
  94. return rv;
  95. }
  96. /**************************************************************************\
  97. *
  98. * Function Description:
  99. *
  100. * raise to an integer power (up to
  101. *
  102. * Arguments:
  103. *
  104. * x - an integer value
  105. *
  106. * Return Value:
  107. *
  108. * floor of log base 2 of x. If x = 0, return 0.
  109. *
  110. \**************************************************************************/
  111. UINT
  112. GpRuntime::Gplog2 (UINT x)
  113. {
  114. UINT rv = 0;
  115. x >>= 1;
  116. while (x)
  117. {
  118. rv++;
  119. x >>= 1;
  120. }
  121. return rv;
  122. }
  123. /**************************************************************************\
  124. *
  125. * Function Description:
  126. *
  127. * Moves a block of memory. Handles overlapping cases.
  128. *
  129. * Arguments:
  130. *
  131. * dest - The destination buffer
  132. * src - The source buffer
  133. * count - The number of bytes to copy
  134. *
  135. * Return Value:
  136. *
  137. * dest
  138. *
  139. * Revision History:
  140. *
  141. * 10/22/1999 AGodfrey
  142. * Wrote it.
  143. *
  144. \******************************************************************************/
  145. void *
  146. GpRuntime::GpMemmove(
  147. void *dest,
  148. const void *src,
  149. size_t count )
  150. {
  151. const BYTE *s = static_cast<const BYTE *>(src);
  152. BYTE *d = static_cast<BYTE *>(dest);
  153. // Test for the overlapping case we care about - dest is within the source
  154. // buffer. The other case is handled by the normal loop.
  155. if ((d > s) && (d < s + count))
  156. {
  157. d += count;
  158. s += count;
  159. while (count)
  160. {
  161. *--d = *--s;
  162. count--;
  163. }
  164. }
  165. else
  166. {
  167. while (count)
  168. {
  169. *d++ = *s++;
  170. count--;
  171. }
  172. }
  173. return dest;
  174. }