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.

152 lines
4.0 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. * exbitsio.cpp
  16. *
  17. * Description:
  18. * Routines to write fields to a bit stream buffer.
  19. *
  20. * Routines: Prototypes in:
  21. * BSWriteField e3enc.h
  22. */
  23. //
  24. // $Author: RMCKENZX $
  25. // $Date: 27 Dec 1995 15:32:50 $
  26. // $Archive: S:\h26x\src\enc\exbitsio.cpv $
  27. // $Header: S:\h26x\src\enc\exbitsio.cpv 1.5 27 Dec 1995 15:32:50 RMCKENZX $
  28. // $Log: S:\h26x\src\enc\exbitsio.cpv $
  29. //
  30. // Rev 1.5 27 Dec 1995 15:32:50 RMCKENZX
  31. // Added copyright notice
  32. //
  33. // Rev 1.4 09 Nov 1995 14:11:22 AGUPTA2
  34. // PB-frame+performance+structure enhancements.
  35. //
  36. // Rev 1.3 11 Sep 1995 11:14:06 DBRUCKS
  37. // add h261 ifdef
  38. //
  39. // Rev 1.2 25 Aug 1995 11:54:06 TRGARDOS
  40. //
  41. // Debugged PutBits routine.
  42. //
  43. // Rev 1.1 14 Aug 1995 11:35:18 TRGARDOS
  44. // y
  45. // Finished writing picture frame header
  46. //
  47. // Rev 1.0 11 Aug 1995 17:28:34 TRGARDOS
  48. // Initial revision.
  49. ;////////////////////////////////////////////////////////////////////////////
  50. #include "precomp.h"
  51. /*************************************************************************
  52. * BSWriteField
  53. *
  54. * Write a field value of a specified size of bits into the
  55. * bitstream at the specified byte and bit offset.
  56. *
  57. * It is assumed that the field value is right justified
  58. * in the parameter fieldval, and field len never exceeds
  59. * 25.
  60. *
  61. * Returns void
  62. */
  63. void PutBits(
  64. unsigned int fieldval,
  65. unsigned int fieldlen,
  66. unsigned char **pbs,
  67. unsigned char *bitoffset
  68. )
  69. {
  70. unsigned int wordval;
  71. // Shift field left so that the field starts at
  72. // the current bit offset in the dword.
  73. fieldval <<= (32 - fieldlen) - *bitoffset;
  74. // Read in next dword starting at current byte position.
  75. wordval = (**pbs << 24) + (*(*pbs+1) << 16) + (*(*pbs+2) << 8) + *(*pbs+3);
  76. // Bitwise or the two dwords.
  77. wordval |= fieldval;
  78. // Write word back into memory, big-endian.
  79. *(*pbs+3) = wordval & 0xff;
  80. wordval >>= 8;
  81. *(*pbs+2) = wordval & 0xff;
  82. wordval >>= 8;
  83. *(*pbs+1) = wordval & 0xff;
  84. wordval >>= 8;
  85. **pbs = wordval & 0xff;
  86. // update byte and bit counters.
  87. *pbs += (*bitoffset + fieldlen) >> 3;
  88. *bitoffset = (*bitoffset + fieldlen) % 8;
  89. } // end of BSWriteField function.
  90. /*************************************************************
  91. * CopyBits
  92. *
  93. ************************************************************/
  94. void CopyBits(
  95. U8 **pDestBS,
  96. U8 *pDestBSOffset,
  97. const U8 *pSrcBS,
  98. const U32 uSrcBitOffset,
  99. const U32 uBits
  100. )
  101. {
  102. U32 bitstocopy, bitsinbyte;
  103. const U8 *sptr;
  104. if (uBits == 0) goto done;
  105. bitstocopy = uBits;
  106. sptr = pSrcBS + (uSrcBitOffset >> 3);
  107. bitsinbyte = 8 - (uSrcBitOffset & 0x7);
  108. if (bitsinbyte <= bitstocopy)
  109. {
  110. PutBits((*sptr) & ((1 << bitsinbyte) - 1),
  111. bitsinbyte, pDestBS, pDestBSOffset);
  112. bitstocopy -= bitsinbyte;
  113. sptr++;
  114. }
  115. else
  116. {
  117. PutBits( (*sptr >> (8 - (uSrcBitOffset & 0x7) - bitstocopy))
  118. & ((1 << bitstocopy) - 1),
  119. bitstocopy, pDestBS, pDestBSOffset);
  120. goto done;
  121. }
  122. while (bitstocopy >= 8)
  123. {
  124. PutBits(*sptr, 8, pDestBS, pDestBSOffset);
  125. bitstocopy -= 8;
  126. sptr++;
  127. }
  128. if (bitstocopy > 0)
  129. {
  130. PutBits((*sptr)>>(8-bitstocopy), bitstocopy, pDestBS, pDestBSOffset);
  131. }
  132. done:
  133. return;
  134. } // CopyBits function