]> wimlib.net Git - wimlib/blobdiff - src/lzx_common.c
lzx_common: rename to lzx_preprocess/lzx_postprocess
[wimlib] / src / lzx_common.c
index 3cc6981b186926ebef22bd63633153a6eb80a217..0677e0a0d40693a37888c431b521771621ad60e1 100644 (file)
@@ -57,7 +57,7 @@ const u32 lzx_offset_slot_base[LZX_MAX_OFFSET_SLOTS + 1] = {
 
 /* Mapping: offset slot => how many extra bits must be read and added to the
  * corresponding offset slot base to decode the match offset.  */
-const u8 lzx_extra_offset_bits[LZX_MAX_OFFSET_SLOTS + 1] = {
+const u8 lzx_extra_offset_bits[LZX_MAX_OFFSET_SLOTS] = {
        0 , 0 , 0 , 0 , 1 ,
        1 , 2 , 2 , 3 , 3 ,
        4 , 4 , 5 , 5 , 6 ,
@@ -68,7 +68,6 @@ const u8 lzx_extra_offset_bits[LZX_MAX_OFFSET_SLOTS + 1] = {
        16, 17, 17, 17, 17,
        17, 17, 17, 17, 17,
        17, 17, 17, 17, 17,
-       17
 };
 
 /* Round the specified buffer size up to the next valid LZX window size, and
@@ -90,8 +89,10 @@ lzx_get_window_order(size_t max_bufsize)
        return max(order, LZX_MIN_WINDOW_ORDER);
 }
 
+/* Given a valid LZX window order, return the number of symbols that will exist
+ * in the main Huffman code.  */
 unsigned
-lzx_get_num_offset_slots(unsigned window_order)
+lzx_get_num_main_syms(unsigned window_order)
 {
        /* Note: one would expect that the maximum match offset would be
         * 'window_size - LZX_MIN_MATCH_LEN', which would occur if the first two
@@ -99,17 +100,13 @@ lzx_get_num_offset_slots(unsigned window_order)
         * disallows this case.  This reduces the number of needed offset slots
         * by 1.  */
        u32 window_size = (u32)1 << window_order;
-       u32 max_offset = window_size - LZX_MIN_MATCH_LEN - 1;
-       return 1 + lzx_get_offset_slot(max_offset);
-}
+       u32 max_adjusted_offset = (window_size - LZX_MIN_MATCH_LEN - 1) +
+                                 LZX_OFFSET_ADJUSTMENT;
+       unsigned num_offset_slots = 30;
+       while (max_adjusted_offset >= lzx_offset_slot_base[num_offset_slots])
+               num_offset_slots++;
 
-/* Given a valid LZX window order, return the number of symbols that will exist
- * in the main Huffman code.  */
-unsigned
-lzx_get_num_main_syms(unsigned window_order)
-{
-       return LZX_NUM_CHARS + (lzx_get_num_offset_slots(window_order) *
-                               LZX_NUM_LEN_HEADERS);
+       return LZX_NUM_CHARS + (num_offset_slots * LZX_NUM_LEN_HEADERS);
 }
 
 static void
@@ -326,13 +323,13 @@ lzx_e8_filter(u8 *data, u32 size, void (*process_target)(void *, s32))
 }
 
 void
-lzx_do_e8_preprocessing(u8 *data, u32 size)
+lzx_preprocess(u8 *data, u32 size)
 {
        lzx_e8_filter(data, size, do_translate_target);
 }
 
 void
-lzx_undo_e8_preprocessing(u8 *data, u32 size)
+lzx_postprocess(u8 *data, u32 size)
 {
        lzx_e8_filter(data, size, undo_translate_target);
 }