2007-12-08 23:42:33 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
/// \file lzma_encoder_presets.c
|
|
|
|
/// \brief Encoder presets
|
|
|
|
//
|
2009-04-13 10:27:40 +02:00
|
|
|
// Author: Lasse Collin
|
2007-12-08 23:42:33 +01:00
|
|
|
//
|
2009-04-13 10:27:40 +02:00
|
|
|
// This file has been put into the public domain.
|
|
|
|
// You can do whatever you want with this file.
|
2007-12-08 23:42:33 +01:00
|
|
|
//
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
|
|
|
|
|
2009-02-02 19:14:03 +01:00
|
|
|
extern LZMA_API(lzma_bool)
|
2008-12-27 18:27:49 +01:00
|
|
|
lzma_lzma_preset(lzma_options_lzma *options, uint32_t preset)
|
2008-08-28 21:53:15 +02:00
|
|
|
{
|
2008-12-27 18:27:49 +01:00
|
|
|
const uint32_t level = preset & LZMA_PRESET_LEVEL_MASK;
|
|
|
|
const uint32_t flags = preset & ~LZMA_PRESET_LEVEL_MASK;
|
|
|
|
const uint32_t supported_flags = LZMA_PRESET_EXTREME;
|
2008-08-28 21:53:15 +02:00
|
|
|
|
2008-12-27 18:27:49 +01:00
|
|
|
if (level > 9 || (flags & ~supported_flags))
|
2008-09-27 18:09:21 +02:00
|
|
|
return true;
|
|
|
|
|
|
|
|
options->preset_dict = NULL;
|
|
|
|
options->preset_dict_size = 0;
|
2008-08-28 21:53:15 +02:00
|
|
|
|
2008-09-27 18:09:21 +02:00
|
|
|
options->lc = LZMA_LC_DEFAULT;
|
|
|
|
options->lp = LZMA_LP_DEFAULT;
|
|
|
|
options->pb = LZMA_PB_DEFAULT;
|
2008-08-28 21:53:15 +02:00
|
|
|
|
2014-01-12 15:44:52 +01:00
|
|
|
static const uint8_t dict_pow2[]
|
|
|
|
= { 18, 20, 21, 22, 22, 23, 23, 24, 25, 26 };
|
|
|
|
options->dict_size = UINT32_C(1) << dict_pow2[level];
|
2008-09-27 18:09:21 +02:00
|
|
|
|
2010-09-03 14:13:12 +02:00
|
|
|
if (level <= 3) {
|
|
|
|
options->mode = LZMA_MODE_FAST;
|
|
|
|
options->mf = level == 0 ? LZMA_MF_HC3 : LZMA_MF_HC4;
|
|
|
|
options->nice_len = level <= 1 ? 128 : 273;
|
2014-01-12 15:44:52 +01:00
|
|
|
static const uint8_t depths[] = { 4, 8, 24, 48 };
|
|
|
|
options->depth = depths[level];
|
2010-09-03 14:13:12 +02:00
|
|
|
} else {
|
|
|
|
options->mode = LZMA_MODE_NORMAL;
|
|
|
|
options->mf = LZMA_MF_BT4;
|
|
|
|
options->nice_len = level == 4 ? 16 : level == 5 ? 32 : 64;
|
|
|
|
options->depth = 0;
|
|
|
|
}
|
2008-09-27 18:09:21 +02:00
|
|
|
|
2008-12-27 18:27:49 +01:00
|
|
|
if (flags & LZMA_PRESET_EXTREME) {
|
|
|
|
options->mode = LZMA_MODE_NORMAL;
|
|
|
|
options->mf = LZMA_MF_BT4;
|
2010-09-03 14:13:12 +02:00
|
|
|
if (level == 3 || level == 5) {
|
|
|
|
options->nice_len = 192;
|
2010-09-26 17:10:31 +02:00
|
|
|
options->depth = 0;
|
2010-09-03 14:13:12 +02:00
|
|
|
} else {
|
|
|
|
options->nice_len = 273;
|
|
|
|
options->depth = 512;
|
|
|
|
}
|
2008-12-27 18:27:49 +01:00
|
|
|
}
|
|
|
|
|
2008-09-27 18:09:21 +02:00
|
|
|
return false;
|
2008-08-28 21:53:15 +02:00
|
|
|
}
|