]> wimlib.net Git - wimlib/blobdiff - src/xpress-compress.c
Get rid of input_idx_t
[wimlib] / src / xpress-compress.c
index b1638877f212f896e2adbad17034c8627c8af441..e5051044bcfaec2962aa7e754808e8cc9558e1c8 100644 (file)
 #include "wimlib/util.h"
 #include "wimlib/xpress.h"
 
-#ifdef HAVE_ALLOCA_H
-#  include <alloca.h>
-#endif
-#include <stdlib.h>
 #include <string.h>
 
 struct xpress_record_ctx {
-       input_idx_t freqs[XPRESS_NUM_SYMBOLS];
+       u32 freqs[XPRESS_NUM_SYMBOLS];
        struct xpress_match *matches;
 };
 
@@ -53,8 +49,8 @@ struct xpress_compressor {
        u8 *window;
        u32 max_window_size;
        struct xpress_match *matches;
-       input_idx_t *prev_tab;
-       u16 codewords[XPRESS_NUM_SYMBOLS];
+       u32 *prev_tab;
+       u32 codewords[XPRESS_NUM_SYMBOLS];
        u8 lens[XPRESS_NUM_SYMBOLS];
        struct xpress_record_ctx record_ctx;
 };
@@ -75,7 +71,7 @@ struct xpress_match {
 static void
 xpress_write_match(struct xpress_match match,
                   struct output_bitstream *restrict ostream,
-                  const u16 codewords[restrict],
+                  const u32 codewords[restrict],
                   const u8 lens[restrict])
 {
        u8 len_hdr = min(match.adjusted_len, 0xf);
@@ -98,11 +94,11 @@ xpress_write_match(struct xpress_match match,
 static void
 xpress_write_matches_and_literals(struct output_bitstream *ostream,
                                  const struct xpress_match matches[restrict],
-                                 input_idx_t num_matches,
-                                 const u16 codewords[restrict],
+                                 u32 num_matches,
+                                 const u32 codewords[restrict],
                                  const u8 lens[restrict])
 {
-       for (input_idx_t i = 0; i < num_matches; i++) {
+       for (u32 i = 0; i < num_matches; i++) {
                if (matches[i].offset) {
                        /* Real match  */
                        xpress_write_match(matches[i], ostream, codewords, lens);
@@ -163,8 +159,8 @@ xpress_compress(const void *uncompressed_data, size_t uncompressed_size,
        struct xpress_compressor *c = _c;
        u8 *cptr = compressed_data;
        struct output_bitstream ostream;
-       input_idx_t num_matches;
-       input_idx_t i;
+       u32 num_matches;
+       u32 i;
        size_t compressed_size;
 
        /* XPRESS requires 256 bytes of overhead for the Huffman code, so it's
@@ -218,7 +214,7 @@ xpress_compress(const void *uncompressed_data, size_t uncompressed_size,
 
        /* Flush any pending data and get the length of the compressed data.  */
        compressed_size = flush_output_bitstream(&ostream);
-       if (compressed_size == ~(input_idx_t)0)
+       if (compressed_size == (u32)~0UL)
                return 0;
 
        compressed_size += XPRESS_NUM_SYMBOLS / 2;
@@ -314,7 +310,22 @@ oom:
        return WIMLIB_ERR_NOMEM;
 }
 
+static u64
+xpress_get_needed_memory(size_t max_window_size,
+                        const struct wimlib_compressor_params_header *params)
+{
+       u64 size = 0;
+
+       size += sizeof(struct xpress_compressor);
+       size += max_window_size + 8;
+       size += max_window_size * sizeof(((struct xpress_compressor*)0)->matches[0]);
+       size += max_window_size * sizeof(((struct xpress_compressor*)0)->prev_tab[0]);
+
+       return size;
+}
+
 const struct compressor_ops xpress_compressor_ops = {
+       .get_needed_memory  = xpress_get_needed_memory,
        .create_compressor  = xpress_create_compressor,
        .compress           = xpress_compress,
        .free_compressor    = xpress_free_compressor,