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.

90 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. context->dec_mem_window[bufpos++] = *p++;
  23. }
  24. context->dec_input_curpos = p;
  25. /*
  26. * Make sure the MAX_MATCH bytes starting at window[window_size]
  27. * are always the same as the first MAX_MATCH bytes starting at
  28. * window[0]. This is for our optimisation in decverb.c and
  29. * decalign.c which allows us to not have to & window_mask all the
  30. * time.
  31. */
  32. end_copy_pos = (((MAX_MATCH) < (bufpos_end)) ? (MAX_MATCH) : (bufpos_end));
  33. /*
  34. * Keep copying until we hit MAX_MATCH or the number of bytes
  35. * we decoded
  36. */
  37. while (bufpos_start < end_copy_pos)
  38. {
  39. context->dec_mem_window[bufpos_start + context->dec_window_size] =
  40. context->dec_mem_window[bufpos_start];
  41. bufpos_start++;
  42. }
  43. decode_residue = bufpos - bufpos_end;
  44. bufpos &= context->dec_window_mask;
  45. context->dec_bufpos = bufpos;
  46. return (int) decode_residue;
  47. }
  48. bool handle_beginning_of_uncompressed_block(t_decoder_context *context)
  49. {
  50. int i;
  51. /*
  52. * we want to read the 16 bits already in bitbuf, so backtrack
  53. * the input pointer by 2 bytes.
  54. */
  55. context->dec_input_curpos -= 2;
  56. if (context->dec_input_curpos+4 >= context->dec_end_input_pos)
  57. return false;
  58. /*
  59. * update LRU repeated offset list
  60. */
  61. for (i = 0; i < NUM_REPEATED_OFFSETS; i++)
  62. {
  63. context->dec_last_matchpos_offset[i] =
  64. ((ulong) *( (byte *) context->dec_input_curpos) ) |
  65. ((ulong) *( ((byte *) context->dec_input_curpos) + 1) << 8) |
  66. ((ulong) *( ((byte *) context->dec_input_curpos) + 2) << 16) |
  67. ((ulong) *( ((byte *) context->dec_input_curpos) + 3) << 24);
  68. context->dec_input_curpos += 4; /* increment by 4 bytes */
  69. }
  70. return true;
  71. }