1 ///////////////////////////////////////////////////////////////////////////////
3 /// \file lzma_encoder_presets.c
4 /// \brief Encoder presets
6 // Copyright (C) 2007 Lasse Collin
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Lesser General Public
10 // License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
18 ///////////////////////////////////////////////////////////////////////////////
23 extern LZMA_API(lzma_bool)
24 lzma_lzma_preset(lzma_options_lzma *options, uint32_t preset)
26 const uint32_t level = preset & LZMA_PRESET_LEVEL_MASK;
27 const uint32_t flags = preset & ~LZMA_PRESET_LEVEL_MASK;
28 const uint32_t supported_flags = LZMA_PRESET_EXTREME;
30 if (level > 9 || (flags & ~supported_flags))
33 const uint32_t dict_shift = level <= 1 ? 16 : level + 17;
34 options->dict_size = UINT32_C(1) << dict_shift;
36 options->preset_dict = NULL;
37 options->preset_dict_size = 0;
39 options->lc = LZMA_LC_DEFAULT;
40 options->lp = LZMA_LP_DEFAULT;
41 options->pb = LZMA_PB_DEFAULT;
43 options->persistent = false;
44 options->mode = level <= 2 ? LZMA_MODE_FAST : LZMA_MODE_NORMAL;
46 options->nice_len = level == 0 ? 8 : level <= 5 ? 32 : 64;
47 options->mf = level <= 1 ? LZMA_MF_HC3 : level <= 2 ? LZMA_MF_HC4
51 if (flags & LZMA_PRESET_EXTREME) {
52 options->lc = 4; // FIXME?
53 options->mode = LZMA_MODE_NORMAL;
54 options->mf = LZMA_MF_BT4;
55 options->nice_len = 273;