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.

94 lines
2.0 KiB

  1. /*
  2. * decinit.c
  3. *
  4. * Initialisation routines for LZX decoder
  5. */
  6. #include "decoder.h"
  7. /*
  8. * Allocate memory for decompression
  9. */
  10. bool NEAR allocate_decompression_memory(t_decoder_context *context)
  11. {
  12. ulong pos_start;
  13. context->dec_num_position_slots = 4;
  14. pos_start = 4;
  15. while (1)
  16. {
  17. pos_start += 1L << dec_extra_bits[context->dec_num_position_slots];
  18. context->dec_num_position_slots++;
  19. if (pos_start >= context->dec_window_size)
  20. break;
  21. }
  22. #ifdef BIT16
  23. if (DComp_Init(context))
  24. return false;
  25. #else
  26. if (!(context->dec_mem_window = (byte *) context->dec_malloc(context->dec_window_size+(MAX_MATCH+4))))
  27. return false;
  28. #endif
  29. return true;
  30. }
  31. /*
  32. * Free decompression memory
  33. */
  34. void NEAR free_decompression_memory(t_decoder_context *context)
  35. {
  36. #ifdef BIT16
  37. DComp_Close(context);
  38. #else
  39. if (context->dec_mem_window)
  40. {
  41. context->dec_free(context->dec_mem_window);
  42. context->dec_mem_window = NULL;
  43. }
  44. #endif
  45. }
  46. /*
  47. * Set/reset decoder trees to initial state
  48. */
  49. void NEAR reset_decoder_trees(t_decoder_context *context)
  50. {
  51. memset(context->dec_main_tree_len, 0, MAIN_TREE_ELEMENTS);
  52. memset(context->dec_main_tree_prev_len, 0, MAIN_TREE_ELEMENTS);
  53. memset(context->dec_secondary_length_tree_len, 0, NUM_SECONDARY_LENGTHS);
  54. memset(context->dec_secondary_length_tree_prev_len, 0, NUM_SECONDARY_LENGTHS);
  55. }
  56. /*
  57. * Miscellaneous state initialisations
  58. */
  59. void NEAR decoder_misc_init(t_decoder_context *context)
  60. {
  61. context->dec_last_matchpos_offset[0] = 1;
  62. context->dec_last_matchpos_offset[1] = 1;
  63. context->dec_last_matchpos_offset[2] = 1;
  64. context->dec_bufpos = 0;
  65. context->dec_position_at_start = 0;
  66. context->dec_decoder_state = DEC_STATE_START_NEW_BLOCK;
  67. context->dec_block_size = 0;
  68. /* so that initialise_decoder_bitbuf() will succeed */
  69. context->dec_block_type = BLOCKTYPE_INVALID;
  70. context->dec_first_time_this_group = true;
  71. context->dec_current_file_size = 0;
  72. context->dec_error_condition = false;
  73. }