]> icculus.org git repositories - icculus/xz.git/blob - src/liblzma/lzma/lzma_encoder_presets.c
Made the preset numbering more logical in liblzma API.
[icculus/xz.git] / src / liblzma / lzma / lzma_encoder_presets.c
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 /// \file       lzma_encoder_presets.c
4 /// \brief      Encoder presets
5 //
6 //  Copyright (C) 2007 Lasse Collin
7 //
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.
12 //
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.
17 //
18 ///////////////////////////////////////////////////////////////////////////////
19
20 #include "common.h"
21
22
23 /*
24 #define pow2(e) (UINT32_C(1) << (e))
25
26
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 },
38 };
39
40
41 extern LZMA_API lzma_bool
42 lzma_lzma_preset(lzma_options_lzma *options, uint32_t level)
43 {
44         if (level >= ARRAY_SIZE(presetes))
45                 return true;
46
47         *options = presets[level];
48         return false;
49 }
50 */
51
52
53 extern LZMA_API lzma_bool
54 lzma_lzma_preset(lzma_options_lzma *options, uint32_t level)
55 {
56         if (level == 0 || level > 9)
57                 return true;
58
59         --level;
60         memzero(options, sizeof(*options));
61
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];
64
65         options->preset_dict = NULL;
66         options->preset_dict_size = 0;
67
68         options->lc = LZMA_LC_DEFAULT;
69         options->lp = LZMA_LP_DEFAULT;
70         options->pb = LZMA_PB_DEFAULT;
71
72         options->persistent = false;
73         options->mode = level <= 2 ? LZMA_MODE_FAST : LZMA_MODE_NORMAL;
74
75         options->nice_len = level <= 5 ? 32 : 64;
76         options->mf = level <= 1 ? LZMA_MF_HC3 : level <= 2 ? LZMA_MF_HC4
77                         : LZMA_MF_BT4;
78         options->depth = 0;
79
80         return false;
81 }