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.

87 lines
2.2 KiB

  1. /*
  2. * decin.c
  3. *
  4. * Decoder inputting of compressed data
  5. */
  6. #include "decoder.h"
  7. /*
  8. * Initialises the bit buffer state
  9. */
  10. void NEAR initialise_decoder_bitbuf(t_decoder_context *context)
  11. {
  12. byte *p;
  13. /*
  14. * If we're decoding an uncompressed block, don't use the
  15. * bit buffer; we're reading directly out of the input.
  16. */
  17. if (context->dec_block_type == BLOCKTYPE_UNCOMPRESSED)
  18. return;
  19. if ((context->dec_input_curpos + sizeof(ulong)) > context->dec_end_input_pos)
  20. return;
  21. p = context->dec_input_curpos;
  22. context->dec_bitbuf =
  23. ((ulong) p[2] | (((ulong) p[3]) << 8)) |
  24. ((((ulong) p[0] | (((ulong) p[1]) << 8))) << 16);
  25. context->dec_bitcount = 16;
  26. context->dec_input_curpos += 4;
  27. }
  28. /*
  29. * Initialise input buffer and bitwise i/o
  30. */
  31. void NEAR init_decoder_input(t_decoder_context *context)
  32. {
  33. initialise_decoder_bitbuf(context);
  34. }
  35. void NEAR fillbuf(t_decoder_context *context, int n)
  36. {
  37. context->dec_bitbuf <<= n;
  38. context->dec_bitcount -= (char)n;
  39. if (context->dec_bitcount <= 0)
  40. {
  41. if (context->dec_input_curpos >= context->dec_end_input_pos)
  42. {
  43. context->dec_error_condition = true;
  44. return;
  45. }
  46. context->dec_bitbuf |= ((((ulong) *context->dec_input_curpos | (((ulong) *(context->dec_input_curpos+1)) << 8))) << (-context->dec_bitcount));
  47. context->dec_input_curpos += 2;
  48. context->dec_bitcount += 16;
  49. if (context->dec_bitcount <= 0)
  50. {
  51. if (context->dec_input_curpos >= context->dec_end_input_pos)
  52. {
  53. context->dec_error_condition = true;
  54. return;
  55. }
  56. context->dec_bitbuf |= ((((ulong) *context->dec_input_curpos | (((ulong) *(context->dec_input_curpos+1)) << 8))) << (-context->dec_bitcount));
  57. context->dec_input_curpos += 2;
  58. context->dec_bitcount += 16;
  59. }
  60. }
  61. }
  62. ulong NEAR getbits(t_decoder_context *context, int n)
  63. {
  64. ulong value;
  65. value = context->dec_bitbuf >> (32-(n));
  66. fillbuf(context, n);
  67. return value;
  68. }