BitStream.cs 957 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System;
  2. using System.IO;
  3. namespace ByteFX.Data.Common
  4. {
  5. /// <summary>
  6. /// Summary description for BitStream.
  7. /// </summary>
  8. public class BitStream : MemoryStream
  9. {
  10. private byte[] _input;
  11. private int _start;
  12. private int _end;
  13. private int _bitindex;
  14. private uint _bitbuffer;
  15. private int _bits_in_buffer;
  16. public BitStream(byte[] input, int index, int len)
  17. {
  18. _bitindex = 0;
  19. _bitbuffer = 0;
  20. _bits_in_buffer = 0;
  21. _input = input;
  22. _start = index;
  23. _end = _start + len;
  24. }
  25. public int GetBits(int numbits)
  26. {
  27. return 0;
  28. }
  29. public int PeekBits(int numbits)
  30. {
  31. int val=0;
  32. int index=_start;
  33. while (numbits > 0)
  34. {
  35. val = (val << 8) | _input[index++];
  36. numbits -= 8;
  37. }
  38. while (_bits_in_buffer < numbits)
  39. {
  40. if (_start == _end)
  41. throw new Exception("Out of bits");
  42. byte b = _input[_start++];
  43. }
  44. return 0;
  45. }
  46. }
  47. }