diff options
author | mm <mm@FreeBSD.org> | 2010-05-10 06:59:50 +0000 |
---|---|---|
committer | mm <mm@FreeBSD.org> | 2010-05-10 06:59:50 +0000 |
commit | 5c358d45429b654efa9c8177ecd370a7965ec1a7 (patch) | |
tree | d2d916954c6a66a3168ee356b5f24da01c2017d6 /contrib/xz/src/liblzma/lzma/lzma_encoder_presets.c | |
parent | 3e09decd1986826f54af1a47be97bb87c1220783 (diff) | |
parent | 1008b7c6744a190c5b15aaf8cab1054671e4c7c3 (diff) | |
download | FreeBSD-src-5c358d45429b654efa9c8177ecd370a7965ec1a7.zip FreeBSD-src-5c358d45429b654efa9c8177ecd370a7965ec1a7.tar.gz |
Import of liblzma, xz, xzdec, lzmainfo from vendor branch
Add support for xz and lzma to lesspipe.sh (xzless, lzless)
Bump __FreeBSD_version
Approved by: delphij (mentor)
MFC after: 2 weeks
Diffstat (limited to 'contrib/xz/src/liblzma/lzma/lzma_encoder_presets.c')
-rw-r--r-- | contrib/xz/src/liblzma/lzma/lzma_encoder_presets.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/contrib/xz/src/liblzma/lzma/lzma_encoder_presets.c b/contrib/xz/src/liblzma/lzma/lzma_encoder_presets.c new file mode 100644 index 0000000..c4c9c14 --- /dev/null +++ b/contrib/xz/src/liblzma/lzma/lzma_encoder_presets.c @@ -0,0 +1,52 @@ +/////////////////////////////////////////////////////////////////////////////// +// +/// \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; + + const uint32_t dict_shift = level <= 1 ? 16 : level + 17; + options->dict_size = UINT32_C(1) << dict_shift; + + options->preset_dict = NULL; + options->preset_dict_size = 0; + + options->lc = LZMA_LC_DEFAULT; + options->lp = LZMA_LP_DEFAULT; + options->pb = LZMA_PB_DEFAULT; + + options->mode = level <= 2 ? LZMA_MODE_FAST : LZMA_MODE_NORMAL; + + options->nice_len = level == 0 ? 8 : level <= 5 ? 32 : 64; + options->mf = level <= 1 ? LZMA_MF_HC3 : level <= 2 ? LZMA_MF_HC4 + : LZMA_MF_BT4; + options->depth = 0; + + if (flags & LZMA_PRESET_EXTREME) { + options->lc = 4; // FIXME? + options->mode = LZMA_MODE_NORMAL; + options->mf = LZMA_MF_BT4; + options->nice_len = 273; + options->depth = 512; + } + + return false; +} |