X-Git-Url: https://wimlib.net/git/?p=wimlib;a=blobdiff_plain;f=src%2Fxpress-compress.c;h=e5051044bcfaec2962aa7e754808e8cc9558e1c8;hp=b1638877f212f896e2adbad17034c8627c8af441;hb=31786dbc470c919893bf4fc5cc91a0f73cbee720;hpb=e940fda88a92ff9e931ec88fb4c0e1ebd6fa2dfb diff --git a/src/xpress-compress.c b/src/xpress-compress.c index b1638877..e5051044 100644 --- a/src/xpress-compress.c +++ b/src/xpress-compress.c @@ -38,14 +38,10 @@ #include "wimlib/util.h" #include "wimlib/xpress.h" -#ifdef HAVE_ALLOCA_H -# include -#endif -#include #include 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,