mirror of
https://git.tukaani.org/xz.git
synced 2024-04-04 12:36:23 +02:00
xz: Fix interaction between preset and custom filter chains.
There was somewhat illogical behavior when --extreme was specified and mixed with custom filter chains. Before this commit, "xz -9 --lzma2 -e" was equivalent to "xz --lzma2". After it is equivalent to "xz -6e" (all earlier preset options get forgotten when a custom filter chain is specified and the default preset is 6 to which -e is applied). I find this less illogical. This also affects the meaning of "xz -9e --lzma2 -7". Earlier it was equivalent to "xz -7e" (the -e specified before a custom filter chain wasn't forgotten). Now it is "xz -7". Note that "xz -7e" still is the same as "xz -e7". Hopefully very few cared about this in the first place, so pretty much no one should even notice this change. Thanks to Conley Moorhous.
This commit is contained in:
parent
97379c5ea7
commit
2fcda89939
1 changed files with 21 additions and 14 deletions
|
@ -43,12 +43,7 @@ static io_buf out_buf;
|
||||||
static uint32_t filters_count = 0;
|
static uint32_t filters_count = 0;
|
||||||
|
|
||||||
/// Number of the preset (0-9)
|
/// Number of the preset (0-9)
|
||||||
static uint32_t preset_number = 6;
|
static uint32_t preset_number = LZMA_PRESET_DEFAULT;
|
||||||
|
|
||||||
/// If a preset is used (no custom filter chain) and preset_extreme is true,
|
|
||||||
/// a significantly slower compression is used to achieve slightly better
|
|
||||||
/// compression ratio.
|
|
||||||
static bool preset_extreme = false;
|
|
||||||
|
|
||||||
/// Integrity check type
|
/// Integrity check type
|
||||||
static lzma_check check;
|
static lzma_check check;
|
||||||
|
@ -74,11 +69,9 @@ coder_set_check(lzma_check new_check)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
extern void
|
static void
|
||||||
coder_set_preset(uint32_t new_preset)
|
forget_filter_chain(void)
|
||||||
{
|
{
|
||||||
preset_number = new_preset;
|
|
||||||
|
|
||||||
// Setting a preset makes us forget a possibly defined custom
|
// Setting a preset makes us forget a possibly defined custom
|
||||||
// filter chain.
|
// filter chain.
|
||||||
while (filters_count > 0) {
|
while (filters_count > 0) {
|
||||||
|
@ -91,10 +84,21 @@ coder_set_preset(uint32_t new_preset)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
extern void
|
||||||
|
coder_set_preset(uint32_t new_preset)
|
||||||
|
{
|
||||||
|
preset_number &= ~LZMA_PRESET_LEVEL_MASK;
|
||||||
|
preset_number |= new_preset;
|
||||||
|
forget_filter_chain();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
extern void
|
extern void
|
||||||
coder_set_extreme(void)
|
coder_set_extreme(void)
|
||||||
{
|
{
|
||||||
preset_extreme = true;
|
preset_number |= LZMA_PRESET_EXTREME;
|
||||||
|
forget_filter_chain();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,6 +113,12 @@ coder_add_filter(lzma_vli id, void *options)
|
||||||
filters[filters_count].options = options;
|
filters[filters_count].options = options;
|
||||||
++filters_count;
|
++filters_count;
|
||||||
|
|
||||||
|
// Setting a custom filter chain makes us forget the preset options.
|
||||||
|
// This makes a difference if one specifies e.g. "xz -9 --lzma2 -e"
|
||||||
|
// where the custom filter chain resets the preset level back to
|
||||||
|
// the default 6, making the example equivalent to "xz -6e".
|
||||||
|
preset_number = LZMA_PRESET_DEFAULT;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,9 +164,6 @@ coder_set_compression_settings(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the preset for LZMA1 or LZMA2.
|
// Get the preset for LZMA1 or LZMA2.
|
||||||
if (preset_extreme)
|
|
||||||
preset_number |= LZMA_PRESET_EXTREME;
|
|
||||||
|
|
||||||
if (lzma_lzma_preset(&opt_lzma, preset_number))
|
if (lzma_lzma_preset(&opt_lzma, preset_number))
|
||||||
message_bug();
|
message_bug();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue