X-Git-Url: https://wimlib.net/git/?a=blobdiff_plain;f=src%2Flzx-comp.c;h=8267a2eaece40d28187adee2c114a953f2ebe825;hb=ac4e9d3b603a8abcc99965ed99576fd0721f8ccb;hp=601513dd4435a77b948b4ca2cd3391912160edfa;hpb=6f7956a06fcf92a304fae93e393e8eaee34e92d5;p=wimlib diff --git a/src/lzx-comp.c b/src/lzx-comp.c index 601513dd..8267a2ea 100644 --- a/src/lzx-comp.c +++ b/src/lzx-comp.c @@ -14,16 +14,16 @@ * This file is part of wimlib, a library for working with WIM files. * * wimlib is free software; you can redistribute it and/or modify it under the - * terms of the GNU Lesser General Public License as published by the Free - * Software Foundation; either version 2.1 of the License, or (at your option) + * terms of the GNU General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) * any later version. * * wimlib is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * - * You should have received a copy of the GNU Lesser General Public License + * You should have received a copy of the GNU General Public License * along with wimlib; if not, see http://www.gnu.org/licenses/. */ @@ -599,7 +599,11 @@ static void do_call_insn_preprocessing(u8 uncompressed_data[], static const struct lz_params lzx_lz_params = { + + /* LZX_MIN_MATCH == 2, but 2-character matches are rarely useful; the + * minimum match for compression is set to 3 instead. */ .min_match = 3, + .max_match = LZX_MAX_MATCH, .good_match = LZX_MAX_MATCH, .nice_match = LZX_MAX_MATCH, @@ -638,6 +642,7 @@ int lzx_compress(const void *__uncompressed_data, uint uncompressed_len, uint compressed_len; uint i; int ret; + int block_type = LZX_BLOCKTYPE_ALIGNED; LZX_DEBUG("uncompressed_len = %u", uncompressed_len); @@ -676,7 +681,7 @@ int lzx_compress(const void *__uncompressed_data, uint uncompressed_len, /* The first three bits tell us what kind of block it is, and are one * of the LZX_BLOCKTYPE_* values. */ - bitstream_put_bits(&ostream, LZX_BLOCKTYPE_ALIGNED, 3); + bitstream_put_bits(&ostream, block_type, 3); /* The next bit indicates whether the block size is the default (32768), * indicated by a 1 bit, or whether the block size is given by the next @@ -691,9 +696,10 @@ int lzx_compress(const void *__uncompressed_data, uint uncompressed_len, /* Write out the aligned offset tree. Note that M$ lies and says that * the aligned offset tree comes after the length tree, but that is * wrong; it actually is before the main tree. */ - for (i = 0; i < LZX_ALIGNEDTREE_NUM_SYMBOLS; i++) - bitstream_put_bits(&ostream, codes.aligned_lens[i], - LZX_ALIGNEDTREE_ELEMENT_SIZE); + if (block_type == LZX_BLOCKTYPE_ALIGNED) + for (i = 0; i < LZX_ALIGNEDTREE_NUM_SYMBOLS; i++) + bitstream_put_bits(&ostream, codes.aligned_lens[i], + LZX_ALIGNEDTREE_ELEMENT_SIZE); /* Write the pre-tree and lengths for the first LZX_NUM_CHARS symbols in the * main tree. */ @@ -717,7 +723,7 @@ int lzx_compress(const void *__uncompressed_data, uint uncompressed_len, return ret; /* Write the compressed literals. */ - ret = lzx_write_compressed_literals(&ostream, LZX_BLOCKTYPE_ALIGNED, + ret = lzx_write_compressed_literals(&ostream, block_type, match_tab, num_matches, &codes); if (ret != 0) return ret;