]> wimlib.net Git - wimlib/blobdiff - src/lzx-compress.c
Remove unneeded parameter from compression functions
[wimlib] / src / lzx-compress.c
index 1bc107ff3f96c80fd544cd5b9873220aaf39b348..c829a4272d5b2011ba619e5dc06f30c6e93908e0 100644 (file)
@@ -91,7 +91,8 @@ struct lzx_freq_tables {
  * numbers in the lzx_position_base array to calculate the slot directly from
  * the formatted offset without actually looking at the array.
  */
-static inline unsigned lzx_get_position_slot(unsigned formatted_offset)
+static inline unsigned
+lzx_get_position_slot(unsigned formatted_offset)
 {
 #if 0
        /*
@@ -120,7 +121,8 @@ static inline unsigned lzx_get_position_slot(unsigned formatted_offset)
        }
 }
 
-static u32 lzx_record_literal(u8 literal, void *__main_freq_tab)
+static u32
+lzx_record_literal(u8 literal, void *__main_freq_tab)
 {
        freq_t *main_freq_tab = __main_freq_tab;
        main_freq_tab[literal]++;
@@ -131,8 +133,9 @@ static u32 lzx_record_literal(u8 literal, void *__main_freq_tab)
  * the frequency of symbols in the main, length, and aligned offset alphabets.
  * The return value is a 32-bit number that provides the match in an
  * intermediate representation documented below. */
-static u32 lzx_record_match(unsigned match_offset, unsigned match_len,
-                           void *__freq_tabs, void *__queue)
+static u32
+lzx_record_match(unsigned match_offset, unsigned match_len,
+                void *__freq_tabs, void *__queue)
 {
        struct lzx_freq_tables *freq_tabs = __freq_tabs;
        struct lru_queue *queue = __queue;
@@ -241,8 +244,9 @@ static u32 lzx_record_match(unsigned match_offset, unsigned match_len,
  * @codes:     Pointer to a structure that contains the codewords for the
  *                     main, length, and aligned offset Huffman codes.
  */
-static int lzx_write_match(struct output_bitstream *out, int block_type,
-                          u32 match, const struct lzx_codes *codes)
+static int
+lzx_write_match(struct output_bitstream *out, int block_type,
+               u32 match, const struct lzx_codes *codes)
 {
        /* low 8 bits are the match length minus 2 */
        unsigned match_len_minus_2 = match & 0xff;
@@ -347,11 +351,12 @@ static int lzx_write_match(struct output_bitstream *out, int block_type,
  * @codes:     Pointer to a structure that contains the codewords for the
  *                     main, length, and aligned offset Huffman codes.
  */
-static int lzx_write_compressed_literals(struct output_bitstream *ostream,
-                                        int block_type,
-                                        const u32 match_tab[],
-                                        unsigned  num_compressed_literals,
-                                        const struct lzx_codes *codes)
+static int
+lzx_write_compressed_literals(struct output_bitstream *ostream,
+                             int block_type,
+                             const u32 match_tab[],
+                             unsigned  num_compressed_literals,
+                             const struct lzx_codes *codes)
 {
        unsigned i;
        u32 match;
@@ -397,8 +402,9 @@ static int lzx_write_compressed_literals(struct output_bitstream *ostream,
  * @lens:      The code lengths for the Huffman tree, indexed by symbol.
  * @num_symbols:       The number of symbols in the code.
  */
-static int lzx_write_compressed_tree(struct output_bitstream *out,
-                                    const u8 lens[], unsigned num_symbols)
+static int
+lzx_write_compressed_tree(struct output_bitstream *out,
+                         const u8 lens[], unsigned num_symbols)
 {
        /* Frequencies of the length symbols, including the RLE symbols (NOT the
         * actual lengths themselves). */
@@ -560,8 +566,9 @@ static int lzx_write_compressed_tree(struct output_bitstream *out,
 
 /* Builds the canonical Huffman code for the main tree, the length tree, and the
  * aligned offset tree. */
-static void lzx_make_huffman_codes(const struct lzx_freq_tables *freq_tabs,
-                               struct lzx_codes *codes)
+static void 
+lzx_make_huffman_codes(const struct lzx_freq_tables *freq_tabs,
+                      struct lzx_codes *codes)
 {
        make_canonical_huffman_code(LZX_MAINTREE_NUM_SYMBOLS,
                                        LZX_MAX_CODEWORD_LEN,
@@ -581,8 +588,9 @@ static void lzx_make_huffman_codes(const struct lzx_freq_tables *freq_tabs,
                                        codes->aligned_codewords);
 }
 
-static void do_call_insn_translation(u32 *call_insn_target, int input_pos,
-                                    int32_t file_size)
+static void
+do_call_insn_translation(u32 *call_insn_target, int input_pos,
+                        int32_t file_size)
 {
        int32_t abs_offset;
        int32_t rel_offset;
@@ -602,8 +610,8 @@ static void do_call_insn_translation(u32 *call_insn_target, int input_pos,
 
 /* This is the reverse of undo_call_insn_preprocessing() in lzx-decompress.c.
  * See the comment above that function for more information. */
-static void do_call_insn_preprocessing(u8 uncompressed_data[],
-                                      int uncompressed_data_len)
+static void
+do_call_insn_preprocessing(u8 uncompressed_data[], int uncompressed_data_len)
 {
        for (int i = 0; i < uncompressed_data_len - 10; i++) {
                if (uncompressed_data[i] == 0xe8) {
@@ -633,22 +641,12 @@ static const struct lz_params lzx_lz_params = {
 /*
  * Performs LZX compression on a block of data.
  *
- * @__uncompressed_data:  Pointer to the data to be compressed.
- * @uncompressed_len:    Length, in bytes, of the data to be compressed.
- * @compressed_data:     Pointer to a location at least (@uncompressed_len - 1)
- *                             bytes long into which the compressed data may be
- *                             written.
- * @compressed_len_ret:          A pointer to an unsigned int into which the length of
- *                             the compressed data may be returned.
- *
- * Returns zero if compression was successfully performed.  In that case
- * @compressed_data and @compressed_len_ret will contain the compressed data and
- * its length.  A return value of nonzero means that compressing the data did
- * not reduce its size, and @compressed_data will not contain the full
- * compressed data.
+ * Please see the documentation for the 'compress_func_t' type in write.c for
+ * the exact behavior of this function and how to call it.
  */
-int lzx_compress(const void *__uncompressed_data, unsigned uncompressed_len,
-                void *compressed_data, unsigned *compressed_len_ret)
+unsigned
+lzx_compress(const void *__uncompressed_data, unsigned uncompressed_len,
+            void *compressed_data)
 {
        struct output_bitstream ostream;
        u8 uncompressed_data[uncompressed_len + 8];
@@ -662,8 +660,10 @@ int lzx_compress(const void *__uncompressed_data, unsigned uncompressed_len,
        int ret;
        int block_type = LZX_BLOCKTYPE_ALIGNED;
 
+       wimlib_assert(uncompressed_len <= 32768);
+
        if (uncompressed_len < 100)
-               return 1;
+               return 0;
 
        memset(&freq_tabs, 0, sizeof(freq_tabs));
        queue.R0 = 1;
@@ -719,37 +719,35 @@ int lzx_compress(const void *__uncompressed_data, unsigned uncompressed_len,
         * main tree. */
        ret = lzx_write_compressed_tree(&ostream, codes.main_lens,
                                        LZX_NUM_CHARS);
-       if (ret != 0)
-               return ret;
+       if (ret)
+               return 0;
 
        /* Write the pre-tree and symbols for the rest of the main tree. */
        ret = lzx_write_compressed_tree(&ostream, codes.main_lens +
                                        LZX_NUM_CHARS,
                                        LZX_MAINTREE_NUM_SYMBOLS -
                                                LZX_NUM_CHARS);
-       if (ret != 0)
-               return ret;
+       if (ret)
+               return 0;
 
        /* Write the pre-tree and symbols for the length tree. */
        ret = lzx_write_compressed_tree(&ostream, codes.len_lens,
                                        LZX_LENTREE_NUM_SYMBOLS);
-       if (ret != 0)
-               return ret;
+       if (ret)
+               return 0;
 
        /* Write the compressed literals. */
        ret = lzx_write_compressed_literals(&ostream, block_type,
                                            match_tab, num_matches, &codes);
-       if (ret != 0)
-               return ret;
+       if (ret)
+               return 0;
 
        ret = flush_output_bitstream(&ostream);
-       if (ret != 0)
-               return ret;
+       if (ret)
+               return 0;
 
        compressed_len = ostream.bit_output - (u8*)compressed_data;
 
-       *compressed_len_ret = compressed_len;
-
 #ifdef ENABLE_VERIFY_COMPRESSION
        /* Verify that we really get the same thing back when decompressing. */
        u8 buf[uncompressed_len];
@@ -769,5 +767,5 @@ int lzx_compress(const void *__uncompressed_data, unsigned uncompressed_len,
                }
        }
 #endif
-       return 0;
+       return compressed_len;
 }