Rizin
unix-like reverse engineering framework and cli tools
lzma_encoder_presets.c
Go to the documentation of this file.
1 //
6 //
7 // Author: Lasse Collin
8 //
9 // This file has been put into the public domain.
10 // You can do whatever you want with this file.
11 //
13 
14 #include "common.h"
15 
16 
18 lzma_lzma_preset(lzma_options_lzma *options, uint32_t preset)
19 {
22  const uint32_t supported_flags = LZMA_PRESET_EXTREME;
23 
24  if (level > 9 || (flags & ~supported_flags))
25  return true;
26 
27  options->preset_dict = NULL;
28  options->preset_dict_size = 0;
29 
33 
34  static const uint8_t dict_pow2[]
35  = { 18, 20, 21, 22, 22, 23, 23, 24, 25, 26 };
36  options->dict_size = UINT32_C(1) << dict_pow2[level];
37 
38  if (level <= 3) {
39  options->mode = LZMA_MODE_FAST;
40  options->mf = level == 0 ? LZMA_MF_HC3 : LZMA_MF_HC4;
41  options->nice_len = level <= 1 ? 128 : 273;
42  static const uint8_t depths[] = { 4, 8, 24, 48 };
43  options->depth = depths[level];
44  } else {
45  options->mode = LZMA_MODE_NORMAL;
46  options->mf = LZMA_MF_BT4;
47  options->nice_len = level == 4 ? 16 : level == 5 ? 32 : 64;
48  options->depth = 0;
49  }
50 
51  if (flags & LZMA_PRESET_EXTREME) {
52  options->mode = LZMA_MODE_NORMAL;
53  options->mf = LZMA_MF_BT4;
54  if (level == 3 || level == 5) {
55  options->nice_len = 192;
56  options->depth = 0;
57  } else {
58  options->nice_len = 273;
59  options->depth = 512;
60  }
61  }
62 
63  return false;
64 }
uint32_t preset
Definition: container.h:259
#define LZMA_PRESET_LEVEL_MASK
Mask for preset level.
Definition: container.h:40
#define LZMA_PRESET_EXTREME
Extreme compression preset.
Definition: container.h:60
#define NULL
Definition: cris-opc.c:27
static const char struct stat static buf struct stat static buf static vhangup int options
Definition: sflib.h:145
@ LZMA_MODE_FAST
Fast compression.
Definition: lzma12.h:139
@ LZMA_MODE_NORMAL
Normal compression.
Definition: lzma12.h:147
#define LZMA_PB_DEFAULT
Definition: lzma12.h:319
@ LZMA_MF_HC4
Hash Chain with 2-, 3-, and 4-byte hashing.
Definition: lzma12.h:70
@ LZMA_MF_BT4
Binary Tree with 2-, 3-, and 4-byte hashing.
Definition: lzma12.h:101
@ LZMA_MF_HC3
Hash Chain with 2- and 3-byte hashing.
Definition: lzma12.h:59
#define LZMA_LC_DEFAULT
Definition: lzma12.h:284
#define LZMA_LP_DEFAULT
Definition: lzma12.h:294
LZMA_API(lzma_bool)
static struct sockaddr static addrlen static backlog const void static flags void flags
Definition: sfsocketcall.h:123
unsigned int uint32_t
Definition: sftypes.h:29
unsigned char uint8_t
Definition: sftypes.h:31
#define UINT32_C(val)
Options specific to the LZMA1 and LZMA2 filters.
Definition: lzma12.h:185
static int level
Definition: vmenus.c:2424
unsigned char lzma_bool
Boolean.
Definition: base.h:29