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.

226 lines
5.7 KiB

  1. /*
  2. * encvars.h
  3. *
  4. * Variables for the compressor
  5. */
  6. #ifdef ALLOC_VARS
  7. # undef EXT
  8. # define EXT
  9. #else
  10. # undef EXT
  11. # define EXT extern
  12. #endif
  13. /*
  14. * For the optimal parser
  15. *
  16. * Uses less memory if it's ushort, but then we're forcing the CPU
  17. * to do 16 bit operations.
  18. *
  19. * Change this to ulong if you don't mind a small memory hit.
  20. * Also, if you make LOOK too large, this number may cause the
  21. * cost estimation to overflow; e.g. 10000 uncompressed symbols
  22. * @ 8 bits each > 65535 bits.
  23. */
  24. typedef ulong numbits_t;
  25. /*
  26. * For the optimal parser
  27. */
  28. typedef struct
  29. {
  30. ulong link;
  31. ulong path;
  32. ulong repeated_offset[NUM_REPEATED_OFFSETS];
  33. numbits_t numbits;
  34. } decision_node;
  35. /*
  36. * 8 * max_position_slots(50) = 656
  37. */
  38. #define MAX_MAIN_TREE_ELEMENTS 700
  39. typedef struct
  40. {
  41. /* "fake" window pointer, based on enc_RealMemWindow */
  42. byte *enc_MemWindow;
  43. ulong enc_window_size;
  44. #ifdef MULTIPLE_SEARCH_TREES
  45. /* root node pointers for our search trees */
  46. ulong *enc_tree_root;
  47. #else /* !MULTIPLE_SEARCH_TREES */
  48. ulong enc_single_tree_root;
  49. #endif /* MULTIPLE_SEARCH_TREES */
  50. /* "fake" start of left nodes */
  51. ulong *enc_Left;
  52. /* "fake" start of right nodes */
  53. ulong *enc_Right;
  54. /* bitwise outputting */
  55. ulong enc_bitbuf;
  56. signed char enc_bitcount;
  57. bool enc_output_overflow;
  58. char pad1[2];
  59. /* used to record literals and displacements */
  60. ulong enc_literals; /* current number of literals */
  61. ulong enc_distances; /* current number of displacements */
  62. ulong *enc_DistData; /* match displacement array */
  63. byte *enc_LitData; /* contains a character or a matchlength */
  64. byte *enc_ItemType; /* bitmap for whether it's a character or matchlength */
  65. ulong enc_repeated_offset_at_literal_zero[NUM_REPEATED_OFFSETS];
  66. /*
  67. * the last three match offsets (displacements) encoded, the most recent
  68. * one being enc_last_matchpos_offset[0].
  69. */
  70. ulong enc_last_matchpos_offset[NUM_REPEATED_OFFSETS];
  71. /* used for optimal parsing */
  72. ulong enc_matchpos_table[MAX_MATCH+1];
  73. /* current encoding position in data */
  74. ulong enc_BufPos;
  75. /* lookup table for converting a match position into a slot */
  76. byte enc_slot_table[1024];
  77. /* buffering the output data */
  78. byte *enc_output_buffer_start;
  79. byte *enc_output_buffer_curpos;
  80. byte *enc_output_buffer_end;
  81. ulong enc_input_running_total;
  82. ulong enc_bufpos_last_output_block;
  83. /* number of distinct position slots */
  84. ulong enc_num_position_slots;
  85. /* misc */
  86. ulong enc_file_size_for_translation;
  87. bool enc_allocated_compression_memory;
  88. /* number of block splits for this 32K of uncompressed data */
  89. byte enc_num_block_splits;
  90. /* the number of 1 bits in any given integer */
  91. byte enc_ones[256];
  92. /* compression parameters */
  93. byte enc_first_block;
  94. bool enc_need_to_recalc_stats;
  95. bool enc_first_time_this_group;
  96. ulong enc_encoder_second_partition_size;
  97. ulong enc_earliest_window_data_remaining;
  98. ulong enc_bufpos_at_last_block;
  99. byte *enc_input_ptr;
  100. long enc_input_left;
  101. ulong enc_instr_pos;
  102. /* for tree.c */
  103. ushort *enc_tree_freq;
  104. ushort *enc_tree_sortptr;
  105. byte *enc_len;
  106. short enc_tree_heap[MAX_MAIN_TREE_ELEMENTS + 2];
  107. ushort enc_tree_leftright[2*(2*MAX_MAIN_TREE_ELEMENTS-1)];
  108. ushort enc_tree_len_cnt[17];
  109. int enc_tree_n;
  110. short enc_tree_heapsize;
  111. char enc_depth;
  112. ulong enc_next_tree_create;
  113. ulong enc_last_literals;
  114. ulong enc_last_distances;
  115. decision_node *enc_decision_node;
  116. /* trees */
  117. byte enc_main_tree_len[MAX_MAIN_TREE_ELEMENTS+1];
  118. byte enc_secondary_tree_len[NUM_SECONDARY_LENGTHS+1];
  119. ushort enc_main_tree_freq[MAX_MAIN_TREE_ELEMENTS*2];
  120. ushort enc_main_tree_code[MAX_MAIN_TREE_ELEMENTS];
  121. byte enc_main_tree_prev_len[MAX_MAIN_TREE_ELEMENTS+1];
  122. ushort enc_secondary_tree_freq[NUM_SECONDARY_LENGTHS*2];
  123. ushort enc_secondary_tree_code[NUM_SECONDARY_LENGTHS];
  124. byte enc_secondary_tree_prev_len[NUM_SECONDARY_LENGTHS+1];
  125. ushort enc_aligned_tree_freq[ALIGNED_NUM_ELEMENTS*2];
  126. ushort enc_aligned_tree_code[ALIGNED_NUM_ELEMENTS];
  127. byte enc_aligned_tree_len[ALIGNED_NUM_ELEMENTS];
  128. byte enc_aligned_tree_prev_len[ALIGNED_NUM_ELEMENTS];
  129. /* start of allocated window memory */
  130. byte *enc_RealMemWindow;
  131. /* start of allocated left nodes */
  132. ulong *enc_RealLeft;
  133. /* start of allocated right nodes */
  134. ulong *enc_RealRight;
  135. /* # cfdata frames this folder */
  136. ulong enc_num_cfdata_frames;
  137. /* misc */
  138. void *enc_fci_data;
  139. PFNALLOC enc_malloc;
  140. PFNFREE enc_free;
  141. int FAR (DIAMONDAPI *enc_output_callback_function)(
  142. void * pfol,
  143. unsigned char * compressed_data,
  144. long compressed_size,
  145. long uncompressed_size
  146. );
  147. } t_encoder_context;
  148. /*
  149. * Declare arrays?
  150. */
  151. #ifdef ALLOC_VARS
  152. /*
  153. * (1 << extra_bits[n])-1
  154. */
  155. const ulong enc_slot_mask[] =
  156. {
  157. 0, 0, 0, 0, 1, 1, 3, 3,
  158. 7, 7, 15, 15, 31, 31, 63, 63,
  159. 127, 127, 255, 255, 511, 511, 1023, 1023,
  160. 2047, 2047, 4095, 4095, 8191, 8191, 16383, 16383,
  161. 32767, 32767, 65535, 65535, 131071, 131071, 131071, 131071,
  162. 131071, 131071, 131071, 131071, 131071, 131071, 131071, 131071,
  163. 131071, 131071, 131071
  164. };
  165. const byte enc_extra_bits[] =
  166. {
  167. 0,0,0,0,1,1,2,2,
  168. 3,3,4,4,5,5,6,6,
  169. 7,7,8,8,9,9,10,10,
  170. 11,11,12,12,13,13,14,14,
  171. 15,15,16,16,17,17,17,17,
  172. 17,17,17,17,17,17,17,17,
  173. 17,17,17
  174. };
  175. #else
  176. extern const ulong enc_slot_mask[];
  177. extern const byte enc_extra_bits[];
  178. #endif