X-Git-Url: https://wimlib.net/git/?a=blobdiff_plain;f=src%2Fxpress-compress.c;h=228ac51e623b166aeeb58d653b746d881c9d6e3c;hb=bc38f3735bf6eaa2b856b1e05710b34bcfbbf787;hp=2637ce93cab8fa3de765b37fa6e0980431764043;hpb=883833a4b3dabec325edf1ca938000f91d587c00;p=wimlib diff --git a/src/xpress-compress.c b/src/xpress-compress.c index 2637ce93..228ac51e 100644 --- a/src/xpress-compress.c +++ b/src/xpress-compress.c @@ -34,13 +34,10 @@ #include "wimlib/compressor_ops.h" #include "wimlib/compress_common.h" #include "wimlib/error.h" +#include "wimlib/lz_hash.h" #include "wimlib/util.h" #include "wimlib/xpress.h" -#ifdef HAVE_ALLOCA_H -# include -#endif -#include #include struct xpress_record_ctx { @@ -53,7 +50,7 @@ struct xpress_compressor { u32 max_window_size; struct xpress_match *matches; input_idx_t *prev_tab; - u16 codewords[XPRESS_NUM_SYMBOLS]; + u32 codewords[XPRESS_NUM_SYMBOLS]; u8 lens[XPRESS_NUM_SYMBOLS]; struct xpress_record_ctx record_ctx; }; @@ -74,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,7 +95,7 @@ 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], + const u32 codewords[restrict], const u8 lens[restrict]) { for (input_idx_t i = 0; i < num_matches; i++) { @@ -313,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,