Update THANKS
[xz/debian.git] / src / liblzma / lzma / lzma_encoder_presets.c
blobe53483f99582e5a1d51908c7343c9fd5129d1bce
1 // SPDX-License-Identifier: 0BSD
3 ///////////////////////////////////////////////////////////////////////////////
4 //
5 /// \file lzma_encoder_presets.c
6 /// \brief Encoder presets
7 /// \note xz needs this even when only decoding is enabled.
8 //
9 // Author: Lasse Collin
11 ///////////////////////////////////////////////////////////////////////////////
13 #include "common.h"
16 extern LZMA_API(lzma_bool)
17 lzma_lzma_preset(lzma_options_lzma *options, uint32_t preset)
19 const uint32_t level = preset & LZMA_PRESET_LEVEL_MASK;
20 const uint32_t flags = preset & ~LZMA_PRESET_LEVEL_MASK;
21 const uint32_t supported_flags = LZMA_PRESET_EXTREME;
23 if (level > 9 || (flags & ~supported_flags))
24 return true;
26 options->preset_dict = NULL;
27 options->preset_dict_size = 0;
29 options->lc = LZMA_LC_DEFAULT;
30 options->lp = LZMA_LP_DEFAULT;
31 options->pb = LZMA_PB_DEFAULT;
33 static const uint8_t dict_pow2[]
34 = { 18, 20, 21, 22, 22, 23, 23, 24, 25, 26 };
35 options->dict_size = UINT32_C(1) << dict_pow2[level];
37 if (level <= 3) {
38 options->mode = LZMA_MODE_FAST;
39 options->mf = level == 0 ? LZMA_MF_HC3 : LZMA_MF_HC4;
40 options->nice_len = level <= 1 ? 128 : 273;
41 static const uint8_t depths[] = { 4, 8, 24, 48 };
42 options->depth = depths[level];
43 } else {
44 options->mode = LZMA_MODE_NORMAL;
45 options->mf = LZMA_MF_BT4;
46 options->nice_len = level == 4 ? 16 : level == 5 ? 32 : 64;
47 options->depth = 0;
50 if (flags & LZMA_PRESET_EXTREME) {
51 options->mode = LZMA_MODE_NORMAL;
52 options->mf = LZMA_MF_BT4;
53 if (level == 3 || level == 5) {
54 options->nice_len = 192;
55 options->depth = 0;
56 } else {
57 options->nice_len = 273;
58 options->depth = 512;
62 return false;