12940b44dSPeter Avalos ///////////////////////////////////////////////////////////////////////////////
22940b44dSPeter Avalos //
32940b44dSPeter Avalos /// \file lzma_encoder_presets.c
42940b44dSPeter Avalos /// \brief Encoder presets
5*46a2189dSzrj /// \note xz needs this even when only decoding is enabled.
62940b44dSPeter Avalos //
72940b44dSPeter Avalos // Author: Lasse Collin
82940b44dSPeter Avalos //
92940b44dSPeter Avalos // This file has been put into the public domain.
102940b44dSPeter Avalos // You can do whatever you want with this file.
112940b44dSPeter Avalos //
122940b44dSPeter Avalos ///////////////////////////////////////////////////////////////////////////////
132940b44dSPeter Avalos
142940b44dSPeter Avalos #include "common.h"
152940b44dSPeter Avalos
162940b44dSPeter Avalos
172940b44dSPeter Avalos extern LZMA_API(lzma_bool)
lzma_lzma_preset(lzma_options_lzma * options,uint32_t preset)182940b44dSPeter Avalos lzma_lzma_preset(lzma_options_lzma *options, uint32_t preset)
192940b44dSPeter Avalos {
202940b44dSPeter Avalos const uint32_t level = preset & LZMA_PRESET_LEVEL_MASK;
212940b44dSPeter Avalos const uint32_t flags = preset & ~LZMA_PRESET_LEVEL_MASK;
222940b44dSPeter Avalos const uint32_t supported_flags = LZMA_PRESET_EXTREME;
232940b44dSPeter Avalos
242940b44dSPeter Avalos if (level > 9 || (flags & ~supported_flags))
252940b44dSPeter Avalos return true;
262940b44dSPeter Avalos
272940b44dSPeter Avalos options->preset_dict = NULL;
282940b44dSPeter Avalos options->preset_dict_size = 0;
292940b44dSPeter Avalos
302940b44dSPeter Avalos options->lc = LZMA_LC_DEFAULT;
312940b44dSPeter Avalos options->lp = LZMA_LP_DEFAULT;
322940b44dSPeter Avalos options->pb = LZMA_PB_DEFAULT;
332940b44dSPeter Avalos
34a530a267SJohn Marino static const uint8_t dict_pow2[]
35a530a267SJohn Marino = { 18, 20, 21, 22, 22, 23, 23, 24, 25, 26 };
36a530a267SJohn Marino options->dict_size = UINT32_C(1) << dict_pow2[level];
372940b44dSPeter Avalos
382940b44dSPeter Avalos if (level <= 3) {
392940b44dSPeter Avalos options->mode = LZMA_MODE_FAST;
402940b44dSPeter Avalos options->mf = level == 0 ? LZMA_MF_HC3 : LZMA_MF_HC4;
412940b44dSPeter Avalos options->nice_len = level <= 1 ? 128 : 273;
42a530a267SJohn Marino static const uint8_t depths[] = { 4, 8, 24, 48 };
43a530a267SJohn Marino options->depth = depths[level];
442940b44dSPeter Avalos } else {
452940b44dSPeter Avalos options->mode = LZMA_MODE_NORMAL;
462940b44dSPeter Avalos options->mf = LZMA_MF_BT4;
472940b44dSPeter Avalos options->nice_len = level == 4 ? 16 : level == 5 ? 32 : 64;
482940b44dSPeter Avalos options->depth = 0;
492940b44dSPeter Avalos }
502940b44dSPeter Avalos
512940b44dSPeter Avalos if (flags & LZMA_PRESET_EXTREME) {
522940b44dSPeter Avalos options->mode = LZMA_MODE_NORMAL;
532940b44dSPeter Avalos options->mf = LZMA_MF_BT4;
542940b44dSPeter Avalos if (level == 3 || level == 5) {
552940b44dSPeter Avalos options->nice_len = 192;
562940b44dSPeter Avalos options->depth = 0;
572940b44dSPeter Avalos } else {
582940b44dSPeter Avalos options->nice_len = 273;
592940b44dSPeter Avalos options->depth = 512;
602940b44dSPeter Avalos }
612940b44dSPeter Avalos }
622940b44dSPeter Avalos
632940b44dSPeter Avalos return false;
642940b44dSPeter Avalos }
65