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.

201 lines
5.7 KiB

  1. /* *************************************************************************
  2. ** INTEL Corporation Proprietary Information
  3. **
  4. ** This listing is supplied under the terms of a license
  5. ** agreement with INTEL Corporation and may not be copied
  6. ** nor disclosed except in accordance with the terms of
  7. ** that agreement.
  8. **
  9. ** Copyright (c) 1995 Intel Corporation.
  10. ** All Rights Reserved.
  11. **
  12. ** *************************************************************************
  13. */
  14. /*****************************************************************************
  15. *
  16. * dxgetbit.h
  17. *
  18. * Description:
  19. * bit reading interface
  20. */
  21. /*
  22. * $Header: S:\h26x\src\dec\dxgetbit.h_v 1.5 27 Dec 1995 14:36:20 RMCKENZX $
  23. * $Log: S:\h26x\src\dec\dxgetbit.h_v $
  24. ;//
  25. ;// Rev 1.5 27 Dec 1995 14:36:20 RMCKENZX
  26. ;// Added copyright notice
  27. */
  28. #ifndef __DXGETBIT_H__
  29. #define __DXGETBIT_H__
  30. /*****************************************************************************
  31. *
  32. * DESCRIPTION:
  33. * The bit reading functions support reading from 1 to 24 bits from a
  34. * stream of bytes. The most significant bit is read first.
  35. *
  36. * VARIABLES:
  37. * U8 FAR * fpu8 - pointer to a stream of bytes
  38. * U32 uWork - working storage
  39. * U32 uBitsReady - the number of bits that have been read into the
  40. * working storage
  41. * U32 uCount - the number of bits
  42. * U32 uResult - the output value
  43. * BITSTREAM_STATE FAR * fpbsState - the bitstream state.
  44. * U32 uCode - the code used to look up the uResult
  45. * U32 uBitCount - number of bits in the code
  46. */
  47. /*****************************************************************************
  48. *
  49. * The GetBitsMask is an array of masks indexed by the number of valid bits
  50. */
  51. extern const U32 GetBitsMask[33];
  52. /*****************************************************************************
  53. *
  54. * The state of a stream can be represented using the following structure.
  55. * This state structure can be passed between functions and used to initialize
  56. * or reinitialize the bitstream.
  57. */
  58. typedef struct {
  59. U8 FAR * fpu8;
  60. U32 uWork;
  61. U32 uBitsReady;
  62. } BITSTREAM_STATE;
  63. /*****************************************************************************
  64. *
  65. * GET_BITS_INIT
  66. *
  67. * Initialize the bit reading functions.
  68. *
  69. * Parameters:
  70. * uBitsReady - OUT parameter
  71. * uWork - OUT parameter
  72. */
  73. #define GET_BITS_INIT(uWork, uBitsReady) { \
  74. uBitsReady = 0; \
  75. uWork = 0; \
  76. }
  77. /*****************************************************************************
  78. *
  79. * GET_BITS_SAVE_STATE
  80. *
  81. * Save the state
  82. *
  83. * Parameters
  84. * fpu8 - IN
  85. * uBitsReady - IN
  86. * uWork - IN
  87. * fpbsState - OUT
  88. */
  89. #define GET_BITS_SAVE_STATE(fp, uW, uBR, fpbs) { \
  90. fpbs->fpu8 = fp; \
  91. fpbs->uBitsReady = uBR; \
  92. fpbs->uWork = uW; \
  93. }
  94. /*****************************************************************************
  95. *
  96. * GET_BITS_RESTORE_STATE
  97. *
  98. * Restore the state
  99. *
  100. * Parameters
  101. */
  102. #define GET_BITS_RESTORE_STATE(fp, uW, uBR, fpbs) { \
  103. fp = fpbs->fpu8; \
  104. uBR = fpbs->uBitsReady; \
  105. uW = fpbs->uWork; \
  106. }
  107. /*****************************************************************************
  108. *
  109. * GET_FIXED_BITS
  110. *
  111. * Read from 1 to 24 bits from the pointer.
  112. *
  113. * Parameters:
  114. * uCount - IN
  115. * fpu8 - IN and OUT
  116. * uWork - IN and OUT
  117. * uBitsReady - IN and OUT
  118. * uResult - OUT
  119. */
  120. #define GET_FIXED_BITS(uCount, fpu8, uWork, uBitsReady, uResult) { \
  121. while (uBitsReady < uCount) { \
  122. uWork <<= 8; \
  123. uBitsReady += 8; \
  124. uWork |= *fpu8++; \
  125. } \
  126. /* setup uBitsReady for next time */ \
  127. uBitsReady = uBitsReady - uCount; \
  128. uResult = (uWork >> uBitsReady); \
  129. uWork &= GetBitsMask[uBitsReady]; \
  130. }
  131. /*****************************************************************************
  132. *
  133. * GET_ONE_BIT
  134. *
  135. * Read 1 bit from the pointer. This is a special case of GET_FIXED_BITS
  136. * provided because of the possible assembly optimization advantages.
  137. *
  138. * Parameters:
  139. * fpu8 - IN and OUT
  140. * uWork - IN and OUT
  141. * uBitsReady - IN and OUT
  142. * uResult - OUT
  143. */
  144. #define GET_ONE_BIT(fpu8, uWork, uBitsReady, uResult) { \
  145. GET_FIXED_BITS(1, fpu8, uWork, uBitsReady, uResult) \
  146. }
  147. /*****************************************************************************
  148. *
  149. * GET_VARIABLE_BITS
  150. *
  151. * Read a variable number of bits using a lookup table.
  152. *
  153. * The input count should be the number of bits used to index the table.
  154. * The output count is the number of bits in that symbol.
  155. *
  156. * The table should be initialized such that all don't care symbols match to
  157. * the same value. Thus if the table is indexed by 6-bits a two bit symbol
  158. * 01XX XX will be used to initialize all entries 0100 00 -> 0111 11. These
  159. * entries will include an 8-bit length in the least significant byte.
  160. *
  161. * uCount - IN
  162. * fpu8 - IN and OUT
  163. * uWork - IN and OUT
  164. * uBitsReady - IN and OUT
  165. * uResult - OUT
  166. * uCode - OUT
  167. * fpTable - IN
  168. */
  169. #define GET_VARIABLE_BITS(uCount, fpu8, uWork, uBitsReady, uResult, uCode, uBitCount, fpTable) { \
  170. while (uBitsReady < uCount) { \
  171. uWork <<= 8; \
  172. uBitsReady += 8; \
  173. uWork |= *fpu8++; \
  174. } \
  175. /* calculate how much to shift off */ \
  176. /* and get the code */ \
  177. uCode = uBitsReady - uCount; \
  178. uCode = (uWork >> uCode); \
  179. /* read the data */ \
  180. uResult = fpTable[uCode]; \
  181. /* count of bits used */ \
  182. uBitCount = uResult & 0xFF; \
  183. /* bits remaining */ \
  184. uBitsReady = uBitsReady - uBitCount; \
  185. uWork &= GetBitsMask[uBitsReady]; \
  186. }
  187. #endif /* __DXGETBIT_H__ */