From 4cc584985c0b7a13901da1b7a64ef9f7cc36e8ab Mon Sep 17 00:00:00 2001 From: Lasse Collin Date: Tue, 3 Nov 2015 18:06:40 +0200 Subject: Build: Build LZMA1/2 presets also when only decoder is wanted. People shouldn't rely on the presets when decoding raw streams, but xz uses the presets as the starting point for raw decoder options anyway. lzma_encocder_presets.c was renamed to lzma_presets.c to make it clear it's not used solely by the encoder code. --- src/liblzma/lzma/Makefile.inc | 6 +++- src/liblzma/lzma/lzma_encoder_presets.c | 63 -------------------------------- src/liblzma/lzma/lzma_presets.c | 64 +++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 64 deletions(-) delete mode 100644 src/liblzma/lzma/lzma_encoder_presets.c create mode 100644 src/liblzma/lzma/lzma_presets.c (limited to 'src/liblzma') diff --git a/src/liblzma/lzma/Makefile.inc b/src/liblzma/lzma/Makefile.inc index 7fc4d172..0c8cd380 100644 --- a/src/liblzma/lzma/Makefile.inc +++ b/src/liblzma/lzma/Makefile.inc @@ -9,12 +9,16 @@ EXTRA_DIST += lzma/fastpos_tablegen.c liblzma_la_SOURCES += lzma/lzma_common.h +if COND_FILTER_LZMA1 +liblzma_la_SOURCES += \ + lzma/lzma_presets.c +endif + if COND_ENCODER_LZMA1 liblzma_la_SOURCES += \ lzma/fastpos.h \ lzma/lzma_encoder.h \ lzma/lzma_encoder.c \ - lzma/lzma_encoder_presets.c \ lzma/lzma_encoder_private.h \ lzma/lzma_encoder_optimum_fast.c \ lzma/lzma_encoder_optimum_normal.c diff --git a/src/liblzma/lzma/lzma_encoder_presets.c b/src/liblzma/lzma/lzma_encoder_presets.c deleted file mode 100644 index 8484b774..00000000 --- a/src/liblzma/lzma/lzma_encoder_presets.c +++ /dev/null @@ -1,63 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// -/// \file lzma_encoder_presets.c -/// \brief Encoder presets -// -// Author: Lasse Collin -// -// This file has been put into the public domain. -// You can do whatever you want with this file. -// -/////////////////////////////////////////////////////////////////////////////// - -#include "common.h" - - -extern LZMA_API(lzma_bool) -lzma_lzma_preset(lzma_options_lzma *options, uint32_t preset) -{ - const uint32_t level = preset & LZMA_PRESET_LEVEL_MASK; - const uint32_t flags = preset & ~LZMA_PRESET_LEVEL_MASK; - const uint32_t supported_flags = LZMA_PRESET_EXTREME; - - if (level > 9 || (flags & ~supported_flags)) - return true; - - options->preset_dict = NULL; - options->preset_dict_size = 0; - - options->lc = LZMA_LC_DEFAULT; - options->lp = LZMA_LP_DEFAULT; - options->pb = LZMA_PB_DEFAULT; - - static const uint8_t dict_pow2[] - = { 18, 20, 21, 22, 22, 23, 23, 24, 25, 26 }; - options->dict_size = UINT32_C(1) << dict_pow2[level]; - - if (level <= 3) { - options->mode = LZMA_MODE_FAST; - options->mf = level == 0 ? LZMA_MF_HC3 : LZMA_MF_HC4; - options->nice_len = level <= 1 ? 128 : 273; - static const uint8_t depths[] = { 4, 8, 24, 48 }; - options->depth = depths[level]; - } else { - options->mode = LZMA_MODE_NORMAL; - options->mf = LZMA_MF_BT4; - options->nice_len = level == 4 ? 16 : level == 5 ? 32 : 64; - options->depth = 0; - } - - if (flags & LZMA_PRESET_EXTREME) { - options->mode = LZMA_MODE_NORMAL; - options->mf = LZMA_MF_BT4; - if (level == 3 || level == 5) { - options->nice_len = 192; - options->depth = 0; - } else { - options->nice_len = 273; - options->depth = 512; - } - } - - return false; -} diff --git a/src/liblzma/lzma/lzma_presets.c b/src/liblzma/lzma/lzma_presets.c new file mode 100644 index 00000000..d49d2427 --- /dev/null +++ b/src/liblzma/lzma/lzma_presets.c @@ -0,0 +1,64 @@ +/////////////////////////////////////////////////////////////////////////////// +// +/// \file lzma_presets.c +/// \brief Encoder presets +/// \note xz needs this even when only decoding is enabled. +// +// Author: Lasse Collin +// +// This file has been put into the public domain. +// You can do whatever you want with this file. +// +/////////////////////////////////////////////////////////////////////////////// + +#include "common.h" + + +extern LZMA_API(lzma_bool) +lzma_lzma_preset(lzma_options_lzma *options, uint32_t preset) +{ + const uint32_t level = preset & LZMA_PRESET_LEVEL_MASK; + const uint32_t flags = preset & ~LZMA_PRESET_LEVEL_MASK; + const uint32_t supported_flags = LZMA_PRESET_EXTREME; + + if (level > 9 || (flags & ~supported_flags)) + return true; + + options->preset_dict = NULL; + options->preset_dict_size = 0; + + options->lc = LZMA_LC_DEFAULT; + options->lp = LZMA_LP_DEFAULT; + options->pb = LZMA_PB_DEFAULT; + + static const uint8_t dict_pow2[] + = { 18, 20, 21, 22, 22, 23, 23, 24, 25, 26 }; + options->dict_size = UINT32_C(1) << dict_pow2[level]; + + if (level <= 3) { + options->mode = LZMA_MODE_FAST; + options->mf = level == 0 ? LZMA_MF_HC3 : LZMA_MF_HC4; + options->nice_len = level <= 1 ? 128 : 273; + static const uint8_t depths[] = { 4, 8, 24, 48 }; + options->depth = depths[level]; + } else { + options->mode = LZMA_MODE_NORMAL; + options->mf = LZMA_MF_BT4; + options->nice_len = level == 4 ? 16 : level == 5 ? 32 : 64; + options->depth = 0; + } + + if (flags & LZMA_PRESET_EXTREME) { + options->mode = LZMA_MODE_NORMAL; + options->mf = LZMA_MF_BT4; + if (level == 3 || level == 5) { + options->nice_len = 192; + options->depth = 0; + } else { + options->nice_len = 273; + options->depth = 512; + } + } + + return false; +} -- cgit v1.2.3