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.

93 lines
2.3 KiB

  1. /*
  2. * decuncmp.c
  3. *
  4. * Decoding uncompressed blocks
  5. */
  6. #include "decoder.h"
  7. int decode_uncompressed_block(t_decoder_context *context, long bufpos, int amount_to_decode)
  8. {
  9. long bytes_decoded = 0;
  10. long bufpos_end;
  11. long decode_residue;
  12. ulong bufpos_start;
  13. ulong end_copy_pos;
  14. byte * p;
  15. bufpos_start = bufpos;
  16. bufpos_end = bufpos + amount_to_decode;
  17. p = context->dec_input_curpos;
  18. while (bufpos < bufpos_end)
  19. {
  20. if (p >= context->dec_end_input_pos)
  21. return -1; // input overflow
  22. #ifdef TRACING
  23. TracingLiteral(bufpos, *p);
  24. #endif
  25. context->dec_mem_window[bufpos++] = *p++;
  26. }
  27. context->dec_input_curpos = p;
  28. /*
  29. * Make sure the MAX_MATCH bytes starting at window[window_size]
  30. * are always the same as the first MAX_MATCH bytes starting at
  31. * window[0]. This is for our optimisation in decverb.c and
  32. * decalign.c which allows us to not have to & window_mask all the
  33. * time.
  34. */
  35. end_copy_pos = min(MAX_MATCH, bufpos_end);
  36. /*
  37. * Keep copying until we hit MAX_MATCH or the number of bytes
  38. * we decoded
  39. */
  40. while (bufpos_start < end_copy_pos)
  41. {
  42. context->dec_mem_window[bufpos_start + context->dec_window_size] =
  43. context->dec_mem_window[bufpos_start];
  44. bufpos_start++;
  45. }
  46. decode_residue = bufpos - bufpos_end;
  47. bufpos &= context->dec_window_mask;
  48. context->dec_bufpos = bufpos;
  49. return (int) decode_residue;
  50. }
  51. bool handle_beginning_of_uncompressed_block(t_decoder_context *context)
  52. {
  53. int i;
  54. /*
  55. * we want to read the 16 bits already in bitbuf, so backtrack
  56. * the input pointer by 2 bytes.
  57. */
  58. context->dec_input_curpos -= 2;
  59. if (context->dec_input_curpos+4 >= context->dec_end_input_pos)
  60. return false;
  61. /*
  62. * update LRU repeated offset list
  63. */
  64. for (i = 0; i < NUM_REPEATED_OFFSETS; i++)
  65. {
  66. context->dec_last_matchpos_offset[i] =
  67. ((ulong) *( (byte *) context->dec_input_curpos) ) |
  68. ((ulong) *( ((byte *) context->dec_input_curpos) + 1) << 8) |
  69. ((ulong) *( ((byte *) context->dec_input_curpos) + 2) << 16) |
  70. ((ulong) *( ((byte *) context->dec_input_curpos) + 3) << 24);
  71. context->dec_input_curpos += 4; /* increment by 4 bytes */
  72. }
  73. return true;
  74. }