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 ///////////////////////////////////////////////////////////////////////////////
24 #define pow2(e) (UINT32_C(1) << (e))
27 static const lzma_options_lzma presets[9] = {
28 // dict lc lp pb mode fb mf mfc
29 { pow2(16), NULL, 0, 3, 0, 2, false, LZMA_MODE_FAST, 64, LZMA_MF_HC3, 0, 0, 0, 0, 0, NULL, NULL },
30 { pow2(20), NULL, 0, 3, 0, 0, false, LZMA_MODE_FAST, 64, LZMA_MF_HC4, 0, 0, 0, 0, 0, NULL, NULL },
31 { pow2(19), NULL, 0, 3, 0, 0, false, LZMA_MODE_NORMAL, 64, LZMA_MF_BT4, 0, 0, 0, 0, 0, NULL, NULL },
32 { pow2(20), NULL, 0, 3, 0, 0, false, LZMA_MODE_NORMAL, 64, LZMA_MF_BT4, 0, 0, 0, 0, 0, NULL, NULL },
33 { pow2(21), NULL, 0, 3, 0, 0, false, LZMA_MODE_NORMAL, 128, LZMA_MF_BT4, 0, 0, 0, 0, 0, NULL, NULL },
34 { pow2(22), NULL, 0, 3, 0, 0, false, LZMA_MODE_NORMAL, 128, LZMA_MF_BT4, 0, 0, 0, 0, 0, NULL, NULL },
35 { pow2(23), NULL, 0, 3, 0, 0, false, LZMA_MODE_NORMAL, 128, LZMA_MF_BT4, 0, 0, 0, 0, 0, NULL, NULL },
36 { pow2(24), NULL, 0, 3, 0, 0, false, LZMA_MODE_NORMAL, 273, LZMA_MF_BT4, 0, 0, 0, 0, 0, NULL, NULL },
37 { pow2(25), NULL, 0, 3, 0, 0, false, LZMA_MODE_NORMAL, 273, LZMA_MF_BT4, 0, 0, 0, 0, 0, NULL, NULL },
41 extern LZMA_API lzma_bool
42 lzma_lzma_preset(lzma_options_lzma *options, uint32_t level)
44 if (level >= ARRAY_SIZE(presetes))
47 *options = presets[level];
53 extern LZMA_API lzma_bool
54 lzma_lzma_preset(lzma_options_lzma *options, uint32_t level)
56 if (level == 0 || level > 9)
60 memzero(options, sizeof(*options));
62 static const uint8_t shift[9] = { 16, 20, 19, 20, 21, 22, 23, 24, 25 };
63 options->dict_size = UINT32_C(1) << shift[level];
65 options->preset_dict = NULL;
66 options->preset_dict_size = 0;
68 options->lc = LZMA_LC_DEFAULT;
69 options->lp = LZMA_LP_DEFAULT;
70 options->pb = LZMA_PB_DEFAULT;
72 options->persistent = false;
73 options->mode = level <= 2 ? LZMA_MODE_FAST : LZMA_MODE_NORMAL;
75 options->nice_len = level <= 5 ? 32 : 64;
76 options->mf = level <= 1 ? LZMA_MF_HC3 : level <= 2 ? LZMA_MF_HC4