1207753Smm/////////////////////////////////////////////////////////////////////////////// 2207753Smm// 3207753Smm/// \file lzma_encoder_presets.c 4207753Smm/// \brief Encoder presets 5207753Smm// 6207753Smm// Author: Lasse Collin 7207753Smm// 8207753Smm// This file has been put into the public domain. 9207753Smm// You can do whatever you want with this file. 10207753Smm// 11207753Smm/////////////////////////////////////////////////////////////////////////////// 12207753Smm 13207753Smm#include "common.h" 14207753Smm 15207753Smm 16207753Smmextern LZMA_API(lzma_bool) 17207753Smmlzma_lzma_preset(lzma_options_lzma *options, uint32_t preset) 18207753Smm{ 19207753Smm const uint32_t level = preset & LZMA_PRESET_LEVEL_MASK; 20207753Smm const uint32_t flags = preset & ~LZMA_PRESET_LEVEL_MASK; 21207753Smm const uint32_t supported_flags = LZMA_PRESET_EXTREME; 22207753Smm 23207753Smm if (level > 9 || (flags & ~supported_flags)) 24207753Smm return true; 25207753Smm 26207753Smm options->preset_dict = NULL; 27207753Smm options->preset_dict_size = 0; 28207753Smm 29207753Smm options->lc = LZMA_LC_DEFAULT; 30207753Smm options->lp = LZMA_LP_DEFAULT; 31207753Smm options->pb = LZMA_PB_DEFAULT; 32207753Smm 33213700Smm options->dict_size = UINT32_C(1) << (uint8_t []){ 34213700Smm 18, 20, 21, 22, 22, 23, 23, 24, 25, 26 }[level]; 35207753Smm 36213700Smm if (level <= 3) { 37213700Smm options->mode = LZMA_MODE_FAST; 38213700Smm options->mf = level == 0 ? LZMA_MF_HC3 : LZMA_MF_HC4; 39213700Smm options->nice_len = level <= 1 ? 128 : 273; 40213700Smm options->depth = (uint8_t []){ 4, 8, 24, 48 }[level]; 41213700Smm } else { 42213700Smm options->mode = LZMA_MODE_NORMAL; 43213700Smm options->mf = LZMA_MF_BT4; 44213700Smm options->nice_len = level == 4 ? 16 : level == 5 ? 32 : 64; 45213700Smm options->depth = 0; 46213700Smm } 47207753Smm 48207753Smm if (flags & LZMA_PRESET_EXTREME) { 49207753Smm options->mode = LZMA_MODE_NORMAL; 50207753Smm options->mf = LZMA_MF_BT4; 51213700Smm if (level == 3 || level == 5) { 52213700Smm options->nice_len = 192; 53213700Smm options->depth = 0; 54213700Smm } else { 55213700Smm options->nice_len = 273; 56213700Smm options->depth = 512; 57213700Smm } 58207753Smm } 59207753Smm 60207753Smm return false; 61207753Smm} 62