Tests: Fix memory leaks in test_block_header.
[xz/debian.git] / src / liblzma / lzma / lzma_encoder_presets.c
blob711df0255296c195a02ac2def1912d383c5be07e
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 /// \file lzma_encoder_presets.c
4 /// \brief Encoder presets
5 /// \note xz needs this even when only decoding is enabled.
6 //
7 // Author: Lasse Collin
8 //
9 // This file has been put into the public domain.
10 // You can do whatever you want with this file.
12 ///////////////////////////////////////////////////////////////////////////////
14 #include "common.h"
17 extern LZMA_API(lzma_bool)
18 lzma_lzma_preset(lzma_options_lzma *options, uint32_t preset)
20 const uint32_t level = preset & LZMA_PRESET_LEVEL_MASK;
21 const uint32_t flags = preset & ~LZMA_PRESET_LEVEL_MASK;
22 const uint32_t supported_flags = LZMA_PRESET_EXTREME;
24 if (level > 9 || (flags & ~supported_flags))
25 return true;
27 options->preset_dict = NULL;
28 options->preset_dict_size = 0;
30 options->lc = LZMA_LC_DEFAULT;
31 options->lp = LZMA_LP_DEFAULT;
32 options->pb = LZMA_PB_DEFAULT;
34 static const uint8_t dict_pow2[]
35 = { 18, 20, 21, 22, 22, 23, 23, 24, 25, 26 };
36 options->dict_size = UINT32_C(1) << dict_pow2[level];
38 if (level <= 3) {
39 options->mode = LZMA_MODE_FAST;
40 options->mf = level == 0 ? LZMA_MF_HC3 : LZMA_MF_HC4;
41 options->nice_len = level <= 1 ? 128 : 273;
42 static const uint8_t depths[] = { 4, 8, 24, 48 };
43 options->depth = depths[level];
44 } else {
45 options->mode = LZMA_MODE_NORMAL;
46 options->mf = LZMA_MF_BT4;
47 options->nice_len = level == 4 ? 16 : level == 5 ? 32 : 64;
48 options->depth = 0;
51 if (flags & LZMA_PRESET_EXTREME) {
52 options->mode = LZMA_MODE_NORMAL;
53 options->mf = LZMA_MF_BT4;
54 if (level == 3 || level == 5) {
55 options->nice_len = 192;
56 options->depth = 0;
57 } else {
58 options->nice_len = 273;
59 options->depth = 512;
63 return false;