Source code of Windows XP (NT5)
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.

84 lines
2.1 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. p = context->dec_input_curpos;
  20. context->dec_bitbuf =
  21. ((ulong) p[2] | (((ulong) p[3]) << 8)) |
  22. ((((ulong) p[0] | (((ulong) p[1]) << 8))) << 16);
  23. context->dec_bitcount = 16;
  24. context->dec_input_curpos += 4;
  25. }
  26. /*
  27. * Initialise input buffer and bitwise i/o
  28. */
  29. void NEAR init_decoder_input(t_decoder_context *context)
  30. {
  31. initialise_decoder_bitbuf(context);
  32. }
  33. void NEAR fillbuf(t_decoder_context *context, int n)
  34. {
  35. context->dec_bitbuf <<= n;
  36. context->dec_bitcount -= (char) n;
  37. if (context->dec_bitcount <= 0)
  38. {
  39. if (context->dec_input_curpos >= context->dec_end_input_pos)
  40. {
  41. context->dec_error_condition = true;
  42. return;
  43. }
  44. context->dec_bitbuf |= ((((ulong) *context->dec_input_curpos | (((ulong) *(context->dec_input_curpos+1)) << 8))) << (-context->dec_bitcount));
  45. context->dec_input_curpos += 2;
  46. context->dec_bitcount += 16;
  47. if (context->dec_bitcount <= 0)
  48. {
  49. if (context->dec_input_curpos >= context->dec_end_input_pos)
  50. {
  51. context->dec_error_condition = true;
  52. return;
  53. }
  54. context->dec_bitbuf |= ((((ulong) *context->dec_input_curpos | (((ulong) *(context->dec_input_curpos+1)) << 8))) << (-context->dec_bitcount));
  55. context->dec_input_curpos += 2;
  56. context->dec_bitcount += 16;
  57. }
  58. }
  59. }
  60. ulong NEAR getbits(t_decoder_context *context, int n)
  61. {
  62. ulong value;
  63. value = context->dec_bitbuf >> (32-(n));
  64. fillbuf(context, n);
  65. return value;
  66. }