]> icculus.org git repositories - icculus/xz.git/blob - src/liblzma/lzma/lzma_encoder_presets.c
Modify LZMA_API macro so that it works on Windows with
[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 extern LZMA_API(lzma_bool)
24 lzma_lzma_preset(lzma_options_lzma *options, uint32_t preset)
25 {
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;
29
30         if (level > 9 || (flags & ~supported_flags))
31                 return true;
32
33         const uint32_t dict_shift = level <= 1 ? 16 : level + 17;
34         options->dict_size = UINT32_C(1) << dict_shift;
35
36         options->preset_dict = NULL;
37         options->preset_dict_size = 0;
38
39         options->lc = LZMA_LC_DEFAULT;
40         options->lp = LZMA_LP_DEFAULT;
41         options->pb = LZMA_PB_DEFAULT;
42
43         options->persistent = false;
44         options->mode = level <= 2 ? LZMA_MODE_FAST : LZMA_MODE_NORMAL;
45
46         options->nice_len = level == 0 ? 8 : level <= 5 ? 32 : 64;
47         options->mf = level <= 1 ? LZMA_MF_HC3 : level <= 2 ? LZMA_MF_HC4
48                         : LZMA_MF_BT4;
49         options->depth = 0;
50
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;
56                 options->depth = 512;
57         }
58
59         return false;
60 }