jpayne@69
|
1 /* SPDX-License-Identifier: 0BSD */
|
jpayne@69
|
2
|
jpayne@69
|
3 /**
|
jpayne@69
|
4 * \file lzma/lzma12.h
|
jpayne@69
|
5 * \brief LZMA1 and LZMA2 filters
|
jpayne@69
|
6 * \note Never include this file directly. Use <lzma.h> instead.
|
jpayne@69
|
7 */
|
jpayne@69
|
8
|
jpayne@69
|
9 /*
|
jpayne@69
|
10 * Author: Lasse Collin
|
jpayne@69
|
11 */
|
jpayne@69
|
12
|
jpayne@69
|
13 #ifndef LZMA_H_INTERNAL
|
jpayne@69
|
14 # error Never include this file directly. Use <lzma.h> instead.
|
jpayne@69
|
15 #endif
|
jpayne@69
|
16
|
jpayne@69
|
17
|
jpayne@69
|
18 /**
|
jpayne@69
|
19 * \brief LZMA1 Filter ID (for raw encoder/decoder only, not in .xz)
|
jpayne@69
|
20 *
|
jpayne@69
|
21 * LZMA1 is the very same thing as what was called just LZMA in LZMA Utils,
|
jpayne@69
|
22 * 7-Zip, and LZMA SDK. It's called LZMA1 here to prevent developers from
|
jpayne@69
|
23 * accidentally using LZMA when they actually want LZMA2.
|
jpayne@69
|
24 */
|
jpayne@69
|
25 #define LZMA_FILTER_LZMA1 LZMA_VLI_C(0x4000000000000001)
|
jpayne@69
|
26
|
jpayne@69
|
27 /**
|
jpayne@69
|
28 * \brief LZMA1 Filter ID with extended options (for raw encoder/decoder)
|
jpayne@69
|
29 *
|
jpayne@69
|
30 * This is like LZMA_FILTER_LZMA1 but with this ID a few extra options
|
jpayne@69
|
31 * are supported in the lzma_options_lzma structure:
|
jpayne@69
|
32 *
|
jpayne@69
|
33 * - A flag to tell the encoder if the end of payload marker (EOPM) alias
|
jpayne@69
|
34 * end of stream (EOS) marker must be written at the end of the stream.
|
jpayne@69
|
35 * In contrast, LZMA_FILTER_LZMA1 always writes the end marker.
|
jpayne@69
|
36 *
|
jpayne@69
|
37 * - Decoder needs to be told the uncompressed size of the stream
|
jpayne@69
|
38 * or that it is unknown (using the special value UINT64_MAX).
|
jpayne@69
|
39 * If the size is known, a flag can be set to allow the presence of
|
jpayne@69
|
40 * the end marker anyway. In contrast, LZMA_FILTER_LZMA1 always
|
jpayne@69
|
41 * behaves as if the uncompressed size was unknown.
|
jpayne@69
|
42 *
|
jpayne@69
|
43 * This allows handling file formats where LZMA1 streams are used but where
|
jpayne@69
|
44 * the end marker isn't allowed or where it might not (always) be present.
|
jpayne@69
|
45 * This extended LZMA1 functionality is provided as a Filter ID for raw
|
jpayne@69
|
46 * encoder and decoder instead of adding new encoder and decoder initialization
|
jpayne@69
|
47 * functions because this way it is possible to also use extra filters,
|
jpayne@69
|
48 * for example, LZMA_FILTER_X86 in a filter chain with LZMA_FILTER_LZMA1EXT,
|
jpayne@69
|
49 * which might be needed to handle some file formats.
|
jpayne@69
|
50 */
|
jpayne@69
|
51 #define LZMA_FILTER_LZMA1EXT LZMA_VLI_C(0x4000000000000002)
|
jpayne@69
|
52
|
jpayne@69
|
53 /**
|
jpayne@69
|
54 * \brief LZMA2 Filter ID
|
jpayne@69
|
55 *
|
jpayne@69
|
56 * Usually you want this instead of LZMA1. Compared to LZMA1, LZMA2 adds
|
jpayne@69
|
57 * support for LZMA_SYNC_FLUSH, uncompressed chunks (smaller expansion
|
jpayne@69
|
58 * when trying to compress incompressible data), possibility to change
|
jpayne@69
|
59 * lc/lp/pb in the middle of encoding, and some other internal improvements.
|
jpayne@69
|
60 */
|
jpayne@69
|
61 #define LZMA_FILTER_LZMA2 LZMA_VLI_C(0x21)
|
jpayne@69
|
62
|
jpayne@69
|
63
|
jpayne@69
|
64 /**
|
jpayne@69
|
65 * \brief Match finders
|
jpayne@69
|
66 *
|
jpayne@69
|
67 * Match finder has major effect on both speed and compression ratio.
|
jpayne@69
|
68 * Usually hash chains are faster than binary trees.
|
jpayne@69
|
69 *
|
jpayne@69
|
70 * If you will use LZMA_SYNC_FLUSH often, the hash chains may be a better
|
jpayne@69
|
71 * choice, because binary trees get much higher compression ratio penalty
|
jpayne@69
|
72 * with LZMA_SYNC_FLUSH.
|
jpayne@69
|
73 *
|
jpayne@69
|
74 * The memory usage formulas are only rough estimates, which are closest to
|
jpayne@69
|
75 * reality when dict_size is a power of two. The formulas are more complex
|
jpayne@69
|
76 * in reality, and can also change a little between liblzma versions. Use
|
jpayne@69
|
77 * lzma_raw_encoder_memusage() to get more accurate estimate of memory usage.
|
jpayne@69
|
78 */
|
jpayne@69
|
79 typedef enum {
|
jpayne@69
|
80 LZMA_MF_HC3 = 0x03,
|
jpayne@69
|
81 /**<
|
jpayne@69
|
82 * \brief Hash Chain with 2- and 3-byte hashing
|
jpayne@69
|
83 *
|
jpayne@69
|
84 * Minimum nice_len: 3
|
jpayne@69
|
85 *
|
jpayne@69
|
86 * Memory usage:
|
jpayne@69
|
87 * - dict_size <= 16 MiB: dict_size * 7.5
|
jpayne@69
|
88 * - dict_size > 16 MiB: dict_size * 5.5 + 64 MiB
|
jpayne@69
|
89 */
|
jpayne@69
|
90
|
jpayne@69
|
91 LZMA_MF_HC4 = 0x04,
|
jpayne@69
|
92 /**<
|
jpayne@69
|
93 * \brief Hash Chain with 2-, 3-, and 4-byte hashing
|
jpayne@69
|
94 *
|
jpayne@69
|
95 * Minimum nice_len: 4
|
jpayne@69
|
96 *
|
jpayne@69
|
97 * Memory usage:
|
jpayne@69
|
98 * - dict_size <= 32 MiB: dict_size * 7.5
|
jpayne@69
|
99 * - dict_size > 32 MiB: dict_size * 6.5
|
jpayne@69
|
100 */
|
jpayne@69
|
101
|
jpayne@69
|
102 LZMA_MF_BT2 = 0x12,
|
jpayne@69
|
103 /**<
|
jpayne@69
|
104 * \brief Binary Tree with 2-byte hashing
|
jpayne@69
|
105 *
|
jpayne@69
|
106 * Minimum nice_len: 2
|
jpayne@69
|
107 *
|
jpayne@69
|
108 * Memory usage: dict_size * 9.5
|
jpayne@69
|
109 */
|
jpayne@69
|
110
|
jpayne@69
|
111 LZMA_MF_BT3 = 0x13,
|
jpayne@69
|
112 /**<
|
jpayne@69
|
113 * \brief Binary Tree with 2- and 3-byte hashing
|
jpayne@69
|
114 *
|
jpayne@69
|
115 * Minimum nice_len: 3
|
jpayne@69
|
116 *
|
jpayne@69
|
117 * Memory usage:
|
jpayne@69
|
118 * - dict_size <= 16 MiB: dict_size * 11.5
|
jpayne@69
|
119 * - dict_size > 16 MiB: dict_size * 9.5 + 64 MiB
|
jpayne@69
|
120 */
|
jpayne@69
|
121
|
jpayne@69
|
122 LZMA_MF_BT4 = 0x14
|
jpayne@69
|
123 /**<
|
jpayne@69
|
124 * \brief Binary Tree with 2-, 3-, and 4-byte hashing
|
jpayne@69
|
125 *
|
jpayne@69
|
126 * Minimum nice_len: 4
|
jpayne@69
|
127 *
|
jpayne@69
|
128 * Memory usage:
|
jpayne@69
|
129 * - dict_size <= 32 MiB: dict_size * 11.5
|
jpayne@69
|
130 * - dict_size > 32 MiB: dict_size * 10.5
|
jpayne@69
|
131 */
|
jpayne@69
|
132 } lzma_match_finder;
|
jpayne@69
|
133
|
jpayne@69
|
134
|
jpayne@69
|
135 /**
|
jpayne@69
|
136 * \brief Test if given match finder is supported
|
jpayne@69
|
137 *
|
jpayne@69
|
138 * It is safe to call this with a value that isn't listed in
|
jpayne@69
|
139 * lzma_match_finder enumeration; the return value will be false.
|
jpayne@69
|
140 *
|
jpayne@69
|
141 * There is no way to list which match finders are available in this
|
jpayne@69
|
142 * particular liblzma version and build. It would be useless, because
|
jpayne@69
|
143 * a new match finder, which the application developer wasn't aware,
|
jpayne@69
|
144 * could require giving additional options to the encoder that the older
|
jpayne@69
|
145 * match finders don't need.
|
jpayne@69
|
146 *
|
jpayne@69
|
147 * \param match_finder Match finder ID
|
jpayne@69
|
148 *
|
jpayne@69
|
149 * \return lzma_bool:
|
jpayne@69
|
150 * - true if the match finder is supported by this liblzma build.
|
jpayne@69
|
151 * - false otherwise.
|
jpayne@69
|
152 */
|
jpayne@69
|
153 extern LZMA_API(lzma_bool) lzma_mf_is_supported(lzma_match_finder match_finder)
|
jpayne@69
|
154 lzma_nothrow lzma_attr_const;
|
jpayne@69
|
155
|
jpayne@69
|
156
|
jpayne@69
|
157 /**
|
jpayne@69
|
158 * \brief Compression modes
|
jpayne@69
|
159 *
|
jpayne@69
|
160 * This selects the function used to analyze the data produced by the match
|
jpayne@69
|
161 * finder.
|
jpayne@69
|
162 */
|
jpayne@69
|
163 typedef enum {
|
jpayne@69
|
164 LZMA_MODE_FAST = 1,
|
jpayne@69
|
165 /**<
|
jpayne@69
|
166 * \brief Fast compression
|
jpayne@69
|
167 *
|
jpayne@69
|
168 * Fast mode is usually at its best when combined with
|
jpayne@69
|
169 * a hash chain match finder.
|
jpayne@69
|
170 */
|
jpayne@69
|
171
|
jpayne@69
|
172 LZMA_MODE_NORMAL = 2
|
jpayne@69
|
173 /**<
|
jpayne@69
|
174 * \brief Normal compression
|
jpayne@69
|
175 *
|
jpayne@69
|
176 * This is usually notably slower than fast mode. Use this
|
jpayne@69
|
177 * together with binary tree match finders to expose the
|
jpayne@69
|
178 * full potential of the LZMA1 or LZMA2 encoder.
|
jpayne@69
|
179 */
|
jpayne@69
|
180 } lzma_mode;
|
jpayne@69
|
181
|
jpayne@69
|
182
|
jpayne@69
|
183 /**
|
jpayne@69
|
184 * \brief Test if given compression mode is supported
|
jpayne@69
|
185 *
|
jpayne@69
|
186 * It is safe to call this with a value that isn't listed in lzma_mode
|
jpayne@69
|
187 * enumeration; the return value will be false.
|
jpayne@69
|
188 *
|
jpayne@69
|
189 * There is no way to list which modes are available in this particular
|
jpayne@69
|
190 * liblzma version and build. It would be useless, because a new compression
|
jpayne@69
|
191 * mode, which the application developer wasn't aware, could require giving
|
jpayne@69
|
192 * additional options to the encoder that the older modes don't need.
|
jpayne@69
|
193 *
|
jpayne@69
|
194 * \param mode Mode ID.
|
jpayne@69
|
195 *
|
jpayne@69
|
196 * \return lzma_bool:
|
jpayne@69
|
197 * - true if the compression mode is supported by this liblzma
|
jpayne@69
|
198 * build.
|
jpayne@69
|
199 * - false otherwise.
|
jpayne@69
|
200 */
|
jpayne@69
|
201 extern LZMA_API(lzma_bool) lzma_mode_is_supported(lzma_mode mode)
|
jpayne@69
|
202 lzma_nothrow lzma_attr_const;
|
jpayne@69
|
203
|
jpayne@69
|
204
|
jpayne@69
|
205 /**
|
jpayne@69
|
206 * \brief Options specific to the LZMA1 and LZMA2 filters
|
jpayne@69
|
207 *
|
jpayne@69
|
208 * Since LZMA1 and LZMA2 share most of the code, it's simplest to share
|
jpayne@69
|
209 * the options structure too. For encoding, all but the reserved variables
|
jpayne@69
|
210 * need to be initialized unless specifically mentioned otherwise.
|
jpayne@69
|
211 * lzma_lzma_preset() can be used to get a good starting point.
|
jpayne@69
|
212 *
|
jpayne@69
|
213 * For raw decoding, both LZMA1 and LZMA2 need dict_size, preset_dict, and
|
jpayne@69
|
214 * preset_dict_size (if preset_dict != NULL). LZMA1 needs also lc, lp, and pb.
|
jpayne@69
|
215 */
|
jpayne@69
|
216 typedef struct {
|
jpayne@69
|
217 /**
|
jpayne@69
|
218 * \brief Dictionary size in bytes
|
jpayne@69
|
219 *
|
jpayne@69
|
220 * Dictionary size indicates how many bytes of the recently processed
|
jpayne@69
|
221 * uncompressed data is kept in memory. One method to reduce size of
|
jpayne@69
|
222 * the uncompressed data is to store distance-length pairs, which
|
jpayne@69
|
223 * indicate what data to repeat from the dictionary buffer. Thus,
|
jpayne@69
|
224 * the bigger the dictionary, the better the compression ratio
|
jpayne@69
|
225 * usually is.
|
jpayne@69
|
226 *
|
jpayne@69
|
227 * Maximum size of the dictionary depends on multiple things:
|
jpayne@69
|
228 * - Memory usage limit
|
jpayne@69
|
229 * - Available address space (not a problem on 64-bit systems)
|
jpayne@69
|
230 * - Selected match finder (encoder only)
|
jpayne@69
|
231 *
|
jpayne@69
|
232 * Currently the maximum dictionary size for encoding is 1.5 GiB
|
jpayne@69
|
233 * (i.e. (UINT32_C(1) << 30) + (UINT32_C(1) << 29)) even on 64-bit
|
jpayne@69
|
234 * systems for certain match finder implementation reasons. In the
|
jpayne@69
|
235 * future, there may be match finders that support bigger
|
jpayne@69
|
236 * dictionaries.
|
jpayne@69
|
237 *
|
jpayne@69
|
238 * Decoder already supports dictionaries up to 4 GiB - 1 B (i.e.
|
jpayne@69
|
239 * UINT32_MAX), so increasing the maximum dictionary size of the
|
jpayne@69
|
240 * encoder won't cause problems for old decoders.
|
jpayne@69
|
241 *
|
jpayne@69
|
242 * Because extremely small dictionaries sizes would have unneeded
|
jpayne@69
|
243 * overhead in the decoder, the minimum dictionary size is 4096 bytes.
|
jpayne@69
|
244 *
|
jpayne@69
|
245 * \note When decoding, too big dictionary does no other harm
|
jpayne@69
|
246 * than wasting memory.
|
jpayne@69
|
247 */
|
jpayne@69
|
248 uint32_t dict_size;
|
jpayne@69
|
249 # define LZMA_DICT_SIZE_MIN UINT32_C(4096)
|
jpayne@69
|
250 # define LZMA_DICT_SIZE_DEFAULT (UINT32_C(1) << 23)
|
jpayne@69
|
251
|
jpayne@69
|
252 /**
|
jpayne@69
|
253 * \brief Pointer to an initial dictionary
|
jpayne@69
|
254 *
|
jpayne@69
|
255 * It is possible to initialize the LZ77 history window using
|
jpayne@69
|
256 * a preset dictionary. It is useful when compressing many
|
jpayne@69
|
257 * similar, relatively small chunks of data independently from
|
jpayne@69
|
258 * each other. The preset dictionary should contain typical
|
jpayne@69
|
259 * strings that occur in the files being compressed. The most
|
jpayne@69
|
260 * probable strings should be near the end of the preset dictionary.
|
jpayne@69
|
261 *
|
jpayne@69
|
262 * This feature should be used only in special situations. For
|
jpayne@69
|
263 * now, it works correctly only with raw encoding and decoding.
|
jpayne@69
|
264 * Currently none of the container formats supported by
|
jpayne@69
|
265 * liblzma allow preset dictionary when decoding, thus if
|
jpayne@69
|
266 * you create a .xz or .lzma file with preset dictionary, it
|
jpayne@69
|
267 * cannot be decoded with the regular decoder functions. In the
|
jpayne@69
|
268 * future, the .xz format will likely get support for preset
|
jpayne@69
|
269 * dictionary though.
|
jpayne@69
|
270 */
|
jpayne@69
|
271 const uint8_t *preset_dict;
|
jpayne@69
|
272
|
jpayne@69
|
273 /**
|
jpayne@69
|
274 * \brief Size of the preset dictionary
|
jpayne@69
|
275 *
|
jpayne@69
|
276 * Specifies the size of the preset dictionary. If the size is
|
jpayne@69
|
277 * bigger than dict_size, only the last dict_size bytes are
|
jpayne@69
|
278 * processed.
|
jpayne@69
|
279 *
|
jpayne@69
|
280 * This variable is read only when preset_dict is not NULL.
|
jpayne@69
|
281 * If preset_dict is not NULL but preset_dict_size is zero,
|
jpayne@69
|
282 * no preset dictionary is used (identical to only setting
|
jpayne@69
|
283 * preset_dict to NULL).
|
jpayne@69
|
284 */
|
jpayne@69
|
285 uint32_t preset_dict_size;
|
jpayne@69
|
286
|
jpayne@69
|
287 /**
|
jpayne@69
|
288 * \brief Number of literal context bits
|
jpayne@69
|
289 *
|
jpayne@69
|
290 * How many of the highest bits of the previous uncompressed
|
jpayne@69
|
291 * eight-bit byte (also known as 'literal') are taken into
|
jpayne@69
|
292 * account when predicting the bits of the next literal.
|
jpayne@69
|
293 *
|
jpayne@69
|
294 * E.g. in typical English text, an upper-case letter is
|
jpayne@69
|
295 * often followed by a lower-case letter, and a lower-case
|
jpayne@69
|
296 * letter is usually followed by another lower-case letter.
|
jpayne@69
|
297 * In the US-ASCII character set, the highest three bits are 010
|
jpayne@69
|
298 * for upper-case letters and 011 for lower-case letters.
|
jpayne@69
|
299 * When lc is at least 3, the literal coding can take advantage of
|
jpayne@69
|
300 * this property in the uncompressed data.
|
jpayne@69
|
301 *
|
jpayne@69
|
302 * There is a limit that applies to literal context bits and literal
|
jpayne@69
|
303 * position bits together: lc + lp <= 4. Without this limit the
|
jpayne@69
|
304 * decoding could become very slow, which could have security related
|
jpayne@69
|
305 * results in some cases like email servers doing virus scanning.
|
jpayne@69
|
306 * This limit also simplifies the internal implementation in liblzma.
|
jpayne@69
|
307 *
|
jpayne@69
|
308 * There may be LZMA1 streams that have lc + lp > 4 (maximum possible
|
jpayne@69
|
309 * lc would be 8). It is not possible to decode such streams with
|
jpayne@69
|
310 * liblzma.
|
jpayne@69
|
311 */
|
jpayne@69
|
312 uint32_t lc;
|
jpayne@69
|
313 # define LZMA_LCLP_MIN 0
|
jpayne@69
|
314 # define LZMA_LCLP_MAX 4
|
jpayne@69
|
315 # define LZMA_LC_DEFAULT 3
|
jpayne@69
|
316
|
jpayne@69
|
317 /**
|
jpayne@69
|
318 * \brief Number of literal position bits
|
jpayne@69
|
319 *
|
jpayne@69
|
320 * lp affects what kind of alignment in the uncompressed data is
|
jpayne@69
|
321 * assumed when encoding literals. A literal is a single 8-bit byte.
|
jpayne@69
|
322 * See pb below for more information about alignment.
|
jpayne@69
|
323 */
|
jpayne@69
|
324 uint32_t lp;
|
jpayne@69
|
325 # define LZMA_LP_DEFAULT 0
|
jpayne@69
|
326
|
jpayne@69
|
327 /**
|
jpayne@69
|
328 * \brief Number of position bits
|
jpayne@69
|
329 *
|
jpayne@69
|
330 * pb affects what kind of alignment in the uncompressed data is
|
jpayne@69
|
331 * assumed in general. The default means four-byte alignment
|
jpayne@69
|
332 * (2^ pb =2^2=4), which is often a good choice when there's
|
jpayne@69
|
333 * no better guess.
|
jpayne@69
|
334 *
|
jpayne@69
|
335 * When the alignment is known, setting pb accordingly may reduce
|
jpayne@69
|
336 * the file size a little. E.g. with text files having one-byte
|
jpayne@69
|
337 * alignment (US-ASCII, ISO-8859-*, UTF-8), setting pb=0 can
|
jpayne@69
|
338 * improve compression slightly. For UTF-16 text, pb=1 is a good
|
jpayne@69
|
339 * choice. If the alignment is an odd number like 3 bytes, pb=0
|
jpayne@69
|
340 * might be the best choice.
|
jpayne@69
|
341 *
|
jpayne@69
|
342 * Even though the assumed alignment can be adjusted with pb and
|
jpayne@69
|
343 * lp, LZMA1 and LZMA2 still slightly favor 16-byte alignment.
|
jpayne@69
|
344 * It might be worth taking into account when designing file formats
|
jpayne@69
|
345 * that are likely to be often compressed with LZMA1 or LZMA2.
|
jpayne@69
|
346 */
|
jpayne@69
|
347 uint32_t pb;
|
jpayne@69
|
348 # define LZMA_PB_MIN 0
|
jpayne@69
|
349 # define LZMA_PB_MAX 4
|
jpayne@69
|
350 # define LZMA_PB_DEFAULT 2
|
jpayne@69
|
351
|
jpayne@69
|
352 /** Compression mode */
|
jpayne@69
|
353 lzma_mode mode;
|
jpayne@69
|
354
|
jpayne@69
|
355 /**
|
jpayne@69
|
356 * \brief Nice length of a match
|
jpayne@69
|
357 *
|
jpayne@69
|
358 * This determines how many bytes the encoder compares from the match
|
jpayne@69
|
359 * candidates when looking for the best match. Once a match of at
|
jpayne@69
|
360 * least nice_len bytes long is found, the encoder stops looking for
|
jpayne@69
|
361 * better candidates and encodes the match. (Naturally, if the found
|
jpayne@69
|
362 * match is actually longer than nice_len, the actual length is
|
jpayne@69
|
363 * encoded; it's not truncated to nice_len.)
|
jpayne@69
|
364 *
|
jpayne@69
|
365 * Bigger values usually increase the compression ratio and
|
jpayne@69
|
366 * compression time. For most files, 32 to 128 is a good value,
|
jpayne@69
|
367 * which gives very good compression ratio at good speed.
|
jpayne@69
|
368 *
|
jpayne@69
|
369 * The exact minimum value depends on the match finder. The maximum
|
jpayne@69
|
370 * is 273, which is the maximum length of a match that LZMA1 and
|
jpayne@69
|
371 * LZMA2 can encode.
|
jpayne@69
|
372 */
|
jpayne@69
|
373 uint32_t nice_len;
|
jpayne@69
|
374
|
jpayne@69
|
375 /** Match finder ID */
|
jpayne@69
|
376 lzma_match_finder mf;
|
jpayne@69
|
377
|
jpayne@69
|
378 /**
|
jpayne@69
|
379 * \brief Maximum search depth in the match finder
|
jpayne@69
|
380 *
|
jpayne@69
|
381 * For every input byte, match finder searches through the hash chain
|
jpayne@69
|
382 * or binary tree in a loop, each iteration going one step deeper in
|
jpayne@69
|
383 * the chain or tree. The searching stops if
|
jpayne@69
|
384 * - a match of at least nice_len bytes long is found;
|
jpayne@69
|
385 * - all match candidates from the hash chain or binary tree have
|
jpayne@69
|
386 * been checked; or
|
jpayne@69
|
387 * - maximum search depth is reached.
|
jpayne@69
|
388 *
|
jpayne@69
|
389 * Maximum search depth is needed to prevent the match finder from
|
jpayne@69
|
390 * wasting too much time in case there are lots of short match
|
jpayne@69
|
391 * candidates. On the other hand, stopping the search before all
|
jpayne@69
|
392 * candidates have been checked can reduce compression ratio.
|
jpayne@69
|
393 *
|
jpayne@69
|
394 * Setting depth to zero tells liblzma to use an automatic default
|
jpayne@69
|
395 * value, that depends on the selected match finder and nice_len.
|
jpayne@69
|
396 * The default is in the range [4, 200] or so (it may vary between
|
jpayne@69
|
397 * liblzma versions).
|
jpayne@69
|
398 *
|
jpayne@69
|
399 * Using a bigger depth value than the default can increase
|
jpayne@69
|
400 * compression ratio in some cases. There is no strict maximum value,
|
jpayne@69
|
401 * but high values (thousands or millions) should be used with care:
|
jpayne@69
|
402 * the encoder could remain fast enough with typical input, but
|
jpayne@69
|
403 * malicious input could cause the match finder to slow down
|
jpayne@69
|
404 * dramatically, possibly creating a denial of service attack.
|
jpayne@69
|
405 */
|
jpayne@69
|
406 uint32_t depth;
|
jpayne@69
|
407
|
jpayne@69
|
408 /**
|
jpayne@69
|
409 * \brief For LZMA_FILTER_LZMA1EXT: Extended flags
|
jpayne@69
|
410 *
|
jpayne@69
|
411 * This is used only with LZMA_FILTER_LZMA1EXT.
|
jpayne@69
|
412 *
|
jpayne@69
|
413 * Currently only one flag is supported, LZMA_LZMA1EXT_ALLOW_EOPM:
|
jpayne@69
|
414 *
|
jpayne@69
|
415 * - Encoder: If the flag is set, then end marker is written just
|
jpayne@69
|
416 * like it is with LZMA_FILTER_LZMA1. Without this flag the
|
jpayne@69
|
417 * end marker isn't written and the application has to store
|
jpayne@69
|
418 * the uncompressed size somewhere outside the compressed stream.
|
jpayne@69
|
419 * To decompress streams without the end marker, the application
|
jpayne@69
|
420 * has to set the correct uncompressed size in ext_size_low and
|
jpayne@69
|
421 * ext_size_high.
|
jpayne@69
|
422 *
|
jpayne@69
|
423 * - Decoder: If the uncompressed size in ext_size_low and
|
jpayne@69
|
424 * ext_size_high is set to the special value UINT64_MAX
|
jpayne@69
|
425 * (indicating unknown uncompressed size) then this flag is
|
jpayne@69
|
426 * ignored and the end marker must always be present, that is,
|
jpayne@69
|
427 * the behavior is identical to LZMA_FILTER_LZMA1.
|
jpayne@69
|
428 *
|
jpayne@69
|
429 * Otherwise, if this flag isn't set, then the input stream
|
jpayne@69
|
430 * must not have the end marker; if the end marker is detected
|
jpayne@69
|
431 * then it will result in LZMA_DATA_ERROR. This is useful when
|
jpayne@69
|
432 * it is known that the stream must not have the end marker and
|
jpayne@69
|
433 * strict validation is wanted.
|
jpayne@69
|
434 *
|
jpayne@69
|
435 * If this flag is set, then it is autodetected if the end marker
|
jpayne@69
|
436 * is present after the specified number of uncompressed bytes
|
jpayne@69
|
437 * has been decompressed (ext_size_low and ext_size_high). The
|
jpayne@69
|
438 * end marker isn't allowed in any other position. This behavior
|
jpayne@69
|
439 * is useful when uncompressed size is known but the end marker
|
jpayne@69
|
440 * may or may not be present. This is the case, for example,
|
jpayne@69
|
441 * in .7z files (valid .7z files that have the end marker in
|
jpayne@69
|
442 * LZMA1 streams are rare but they do exist).
|
jpayne@69
|
443 */
|
jpayne@69
|
444 uint32_t ext_flags;
|
jpayne@69
|
445 # define LZMA_LZMA1EXT_ALLOW_EOPM UINT32_C(0x01)
|
jpayne@69
|
446
|
jpayne@69
|
447 /**
|
jpayne@69
|
448 * \brief For LZMA_FILTER_LZMA1EXT: Uncompressed size (low bits)
|
jpayne@69
|
449 *
|
jpayne@69
|
450 * The 64-bit uncompressed size is needed for decompression with
|
jpayne@69
|
451 * LZMA_FILTER_LZMA1EXT. The size is ignored by the encoder.
|
jpayne@69
|
452 *
|
jpayne@69
|
453 * The special value UINT64_MAX indicates that the uncompressed size
|
jpayne@69
|
454 * is unknown and that the end of payload marker (also known as
|
jpayne@69
|
455 * end of stream marker) must be present to indicate the end of
|
jpayne@69
|
456 * the LZMA1 stream. Any other value indicates the expected
|
jpayne@69
|
457 * uncompressed size of the LZMA1 stream. (If LZMA1 was used together
|
jpayne@69
|
458 * with filters that change the size of the data then the uncompressed
|
jpayne@69
|
459 * size of the LZMA1 stream could be different than the final
|
jpayne@69
|
460 * uncompressed size of the filtered stream.)
|
jpayne@69
|
461 *
|
jpayne@69
|
462 * ext_size_low holds the least significant 32 bits of the
|
jpayne@69
|
463 * uncompressed size. The most significant 32 bits must be set
|
jpayne@69
|
464 * in ext_size_high. The macro lzma_set_ext_size(opt_lzma, u64size)
|
jpayne@69
|
465 * can be used to set these members.
|
jpayne@69
|
466 *
|
jpayne@69
|
467 * The 64-bit uncompressed size is split into two uint32_t variables
|
jpayne@69
|
468 * because there were no reserved uint64_t members and using the
|
jpayne@69
|
469 * same options structure for LZMA_FILTER_LZMA1, LZMA_FILTER_LZMA1EXT,
|
jpayne@69
|
470 * and LZMA_FILTER_LZMA2 was otherwise more convenient than having
|
jpayne@69
|
471 * a new options structure for LZMA_FILTER_LZMA1EXT. (Replacing two
|
jpayne@69
|
472 * uint32_t members with one uint64_t changes the ABI on some systems
|
jpayne@69
|
473 * as the alignment of this struct can increase from 4 bytes to 8.)
|
jpayne@69
|
474 */
|
jpayne@69
|
475 uint32_t ext_size_low;
|
jpayne@69
|
476
|
jpayne@69
|
477 /**
|
jpayne@69
|
478 * \brief For LZMA_FILTER_LZMA1EXT: Uncompressed size (high bits)
|
jpayne@69
|
479 *
|
jpayne@69
|
480 * This holds the most significant 32 bits of the uncompressed size.
|
jpayne@69
|
481 */
|
jpayne@69
|
482 uint32_t ext_size_high;
|
jpayne@69
|
483
|
jpayne@69
|
484 /*
|
jpayne@69
|
485 * Reserved space to allow possible future extensions without
|
jpayne@69
|
486 * breaking the ABI. You should not touch these, because the names
|
jpayne@69
|
487 * of these variables may change. These are and will never be used
|
jpayne@69
|
488 * with the currently supported options, so it is safe to leave these
|
jpayne@69
|
489 * uninitialized.
|
jpayne@69
|
490 */
|
jpayne@69
|
491
|
jpayne@69
|
492 /** \private Reserved member. */
|
jpayne@69
|
493 uint32_t reserved_int4;
|
jpayne@69
|
494
|
jpayne@69
|
495 /** \private Reserved member. */
|
jpayne@69
|
496 uint32_t reserved_int5;
|
jpayne@69
|
497
|
jpayne@69
|
498 /** \private Reserved member. */
|
jpayne@69
|
499 uint32_t reserved_int6;
|
jpayne@69
|
500
|
jpayne@69
|
501 /** \private Reserved member. */
|
jpayne@69
|
502 uint32_t reserved_int7;
|
jpayne@69
|
503
|
jpayne@69
|
504 /** \private Reserved member. */
|
jpayne@69
|
505 uint32_t reserved_int8;
|
jpayne@69
|
506
|
jpayne@69
|
507 /** \private Reserved member. */
|
jpayne@69
|
508 lzma_reserved_enum reserved_enum1;
|
jpayne@69
|
509
|
jpayne@69
|
510 /** \private Reserved member. */
|
jpayne@69
|
511 lzma_reserved_enum reserved_enum2;
|
jpayne@69
|
512
|
jpayne@69
|
513 /** \private Reserved member. */
|
jpayne@69
|
514 lzma_reserved_enum reserved_enum3;
|
jpayne@69
|
515
|
jpayne@69
|
516 /** \private Reserved member. */
|
jpayne@69
|
517 lzma_reserved_enum reserved_enum4;
|
jpayne@69
|
518
|
jpayne@69
|
519 /** \private Reserved member. */
|
jpayne@69
|
520 void *reserved_ptr1;
|
jpayne@69
|
521
|
jpayne@69
|
522 /** \private Reserved member. */
|
jpayne@69
|
523 void *reserved_ptr2;
|
jpayne@69
|
524
|
jpayne@69
|
525 } lzma_options_lzma;
|
jpayne@69
|
526
|
jpayne@69
|
527
|
jpayne@69
|
528 /**
|
jpayne@69
|
529 * \brief Macro to set the 64-bit uncompressed size in ext_size_*
|
jpayne@69
|
530 *
|
jpayne@69
|
531 * This might be convenient when decoding using LZMA_FILTER_LZMA1EXT.
|
jpayne@69
|
532 * This isn't used with LZMA_FILTER_LZMA1 or LZMA_FILTER_LZMA2.
|
jpayne@69
|
533 */
|
jpayne@69
|
534 #define lzma_set_ext_size(opt_lzma2, u64size) \
|
jpayne@69
|
535 do { \
|
jpayne@69
|
536 (opt_lzma2).ext_size_low = (uint32_t)(u64size); \
|
jpayne@69
|
537 (opt_lzma2).ext_size_high = (uint32_t)((uint64_t)(u64size) >> 32); \
|
jpayne@69
|
538 } while (0)
|
jpayne@69
|
539
|
jpayne@69
|
540
|
jpayne@69
|
541 /**
|
jpayne@69
|
542 * \brief Set a compression preset to lzma_options_lzma structure
|
jpayne@69
|
543 *
|
jpayne@69
|
544 * 0 is the fastest and 9 is the slowest. These match the switches -0 .. -9
|
jpayne@69
|
545 * of the xz command line tool. In addition, it is possible to bitwise-or
|
jpayne@69
|
546 * flags to the preset. Currently only LZMA_PRESET_EXTREME is supported.
|
jpayne@69
|
547 * The flags are defined in container.h, because the flags are used also
|
jpayne@69
|
548 * with lzma_easy_encoder().
|
jpayne@69
|
549 *
|
jpayne@69
|
550 * The preset levels are subject to changes between liblzma versions.
|
jpayne@69
|
551 *
|
jpayne@69
|
552 * This function is available only if LZMA1 or LZMA2 encoder has been enabled
|
jpayne@69
|
553 * when building liblzma.
|
jpayne@69
|
554 *
|
jpayne@69
|
555 * If features (like certain match finders) have been disabled at build time,
|
jpayne@69
|
556 * then the function may return success (false) even though the resulting
|
jpayne@69
|
557 * LZMA1/LZMA2 options may not be usable for encoder initialization
|
jpayne@69
|
558 * (LZMA_OPTIONS_ERROR).
|
jpayne@69
|
559 *
|
jpayne@69
|
560 * \param[out] options Pointer to LZMA1 or LZMA2 options to be filled
|
jpayne@69
|
561 * \param preset Preset level bitwse-ORed with preset flags
|
jpayne@69
|
562 *
|
jpayne@69
|
563 * \return lzma_bool:
|
jpayne@69
|
564 * - true if the preset is not supported (failure).
|
jpayne@69
|
565 * - false otherwise (success).
|
jpayne@69
|
566 */
|
jpayne@69
|
567 extern LZMA_API(lzma_bool) lzma_lzma_preset(
|
jpayne@69
|
568 lzma_options_lzma *options, uint32_t preset) lzma_nothrow;
|