5 * \author Copyright (C) 1999-2006 Igor Pavlov
6 * \author Copyright (C) 2007 Lasse Collin
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
19 #ifndef LZMA_H_INTERNAL
20 # error Never include this file directly. Use <lzma.h> instead.
27 * Filter ID of the LZMA filter. This is used as lzma_filter.id.
29 #define LZMA_FILTER_LZMA LZMA_VLI_C(0x20)
31 #define LZMA_FILTER_LZMA2 LZMA_VLI_C(0x21)
35 * \brief Match finders
37 * Match finder has major effect on both speed and compression ratio.
38 * Usually hash chains are faster than binary trees.
43 * \brief Hash Chain with 3 bytes hashing
45 * \todo Memory requirements
47 * \note It's possible that this match finder gets
48 * removed in future. The definition will stay
49 * in this header, but liblzma may return
50 * LZMA_OPTIONS_ERROR if it is specified (just
51 * like it would if the match finder had been
52 * disabled at compile time).
57 * \brief Hash Chain with 4 bytes hashing
59 * Memory requirements: 7.5 * dictionary_size + 4 MiB
61 * \note It's possible that this match finder gets
62 * removed in future. The definition will stay
63 * in this header, but liblzma may return
64 * LZMA_OPTIONS_ERROR if it is specified (just
65 * like it would if the match finder had been
66 * disabled at compile time).
71 * \brief Binary Tree with 2 bytes hashing
73 * Memory requirements: 9.5 * dictionary_size + 4 MiB
78 * \brief Binary Tree with 3 bytes hashing
80 * Memory requirements: 11.5 * dictionary_size + 4 MiB
85 * \brief Binary Tree with 4 bytes hashing
87 * Memory requirements: 11.5 * dictionary_size + 4 MiB
93 * \brief Test if given match finder is supported
95 * Returns true if the given match finder is supported by this liblzma build.
96 * Otherwise false is returned. It is safe to call this with a value that
97 * isn't listed in lzma_match_finder enumeration; the return value will be
100 * There is no way to list which match finders are available in this
101 * particular liblzma version and build. It would be useless, because
102 * a new match finder, which the application developer wasn't aware,
103 * could require giving additional options to the encoder that the older
104 * match finders don't need.
106 extern lzma_bool lzma_mf_is_supported(lzma_match_finder match_finder)
111 * \brief LZMA compression modes
113 * This selects the function used to analyze the data produced by the match
119 * \brief Fast compression
121 * Fast mode is usually at its best when combined with
122 * a hash chain match finder.
127 * \brief Normal compression
129 * This is usually notably slower than fast mode. Use this
130 * together with binary tree match finders to expose the
131 * full potential of the LZMA encoder.
137 * \brief Test if given compression mode is supported
139 * Returns true if the given compression mode is supported by this liblzma
140 * build. Otherwise false is returned. It is safe to call this with a value
141 * that isn't listed in lzma_mode enumeration; the return value will be false.
143 * There is no way to list which modes are available in this particular
144 * liblzma version and build. It would be useless, because a new compression
145 * mode, which the application developer wasn't aware, could require giving
146 * additional options to the encoder that the older modes don't need.
148 extern lzma_bool lzma_mode_is_available(lzma_mode mode) lzma_attr_const;
152 * \brief Options specific to the LZMA method handler
155 /**********************************
156 * LZMA encoding/decoding options *
157 **********************************/
159 /* These options are required in encoder and also with raw decoding. */
162 * \brief Dictionary size in bytes
164 * Dictionary size indicates how many bytes of the recently processed
165 * uncompressed data is kept in memory. One method to reduce size of
166 * the uncompressed data is to store distance-length pairs, which
167 * indicate what data to repeat from the dictionary buffer. Thus,
168 * the bigger the dictionary, the better compression ratio usually is.
170 * Raw decoding: Too big dictionary does no other harm than
171 * wasting memory. This value is ignored by lzma_raw_decode_buffer(),
172 * because it uses the target buffer as the dictionary.
174 uint32_t dictionary_size;
175 # define LZMA_DICTIONARY_SIZE_MIN (UINT32_C(1) << 12)
176 # define LZMA_DICTIONARY_SIZE_MAX (UINT32_C(1) << 30)
177 # define LZMA_DICTIONARY_SIZE_DEFAULT (UINT32_C(1) << 23)
180 * \brief Pointer to an initial dictionary
182 * It is possible to initialize the LZ77 history window using
183 * a preset dictionary. Here is a good quote from zlib's
184 * documentation; this applies to LZMA as is:
186 * "The dictionary should consist of strings (byte sequences) that
187 * are likely to be encountered later in the data to be compressed,
188 * with the most commonly used strings preferably put towards the
189 * end of the dictionary. Using a dictionary is most useful when
190 * the data to be compressed is short and can be predicted with
191 * good accuracy; the data can then be compressed better than
192 * with the default empty dictionary."
193 * (From deflateSetDictionary() in zlib.h of zlib version 1.2.3)
195 * This feature should be used only in special situations.
196 * It works correctly only with raw encoding and decoding.
197 * Currently none of the container formats supported by
198 * liblzma allow preset dictionary when decoding, thus if
199 * you create a .lzma file with preset dictionary, it cannot
200 * be decoded with the regular .lzma decoder functions.
202 * \todo This feature is not implemented yet.
204 const uint8_t *preset_dictionary;
207 * \brief Size of the preset dictionary
209 * Specifies the size of the preset dictionary. If the size is
210 * bigger than dictionary_size, only the last dictionary_size
211 * bytes are processed.
213 * This variable is read only when preset_dictionary is not NULL.
215 uint32_t preset_dictionary_size;
218 * \brief Number of literal context bits
220 * How many of the highest bits of the previous uncompressed
221 * eight-bit byte (also known as `literal') are taken into
222 * account when predicting the bits of the next literal.
226 uint32_t literal_context_bits;
227 # define LZMA_LITERAL_CONTEXT_BITS_MIN 0
228 # define LZMA_LITERAL_CONTEXT_BITS_MAX 4
229 # define LZMA_LITERAL_CONTEXT_BITS_DEFAULT 3
232 * \brief Number of literal position bits
234 * How many of the lowest bits of the current position (number
235 * of bytes from the beginning of the uncompressed data) in the
236 * uncompressed data is taken into account when predicting the
237 * bits of the next literal (a single eight-bit byte).
241 uint32_t literal_pos_bits;
242 # define LZMA_LITERAL_POS_BITS_MIN 0
243 # define LZMA_LITERAL_POS_BITS_MAX 4
244 # define LZMA_LITERAL_POS_BITS_DEFAULT 0
247 * \brief Number of position bits
249 * How many of the lowest bits of the current position in the
250 * uncompressed data is taken into account when estimating
251 * probabilities of matches. A match is a sequence of bytes for
252 * which a matching sequence is found from the dictionary and
253 * thus can be stored as distance-length pair.
255 * Example: If most of the matches occur at byte positions
256 * of 8 * n + 3, that is, 3, 11, 19, ... set pos_bits to 3,
260 # define LZMA_POS_BITS_MIN 0
261 # define LZMA_POS_BITS_MAX 4
262 # define LZMA_POS_BITS_DEFAULT 2
264 /******************************************
265 * LZMA options needed only when encoding *
266 ******************************************/
269 * \brief Indicate if the options structure is persistent
271 * If this is true, the application must keep this options structure
272 * available after the LZMA2 encoder has been initialized. With
273 * persistent structure it is possible to change some encoder options
274 * in the middle of the encoding process without resetting the encoder.
276 * This option is used only by LZMA2. LZMA1 ignores this and it is
277 * safeto not initialize this when encoding with LZMA1.
279 lzma_bool persistent;
281 /** LZMA compression mode */
285 * \brief Number of fast bytes
287 * Number of fast bytes determines how many bytes the encoder
288 * compares from the match candidates when looking for the best
289 * match. Bigger fast bytes value usually increase both compression
293 # define LZMA_FAST_BYTES_MIN 5
294 # define LZMA_FAST_BYTES_MAX 273
295 # define LZMA_FAST_BYTES_DEFAULT 128
297 /** Match finder ID */
298 lzma_match_finder match_finder;
301 * \brief Match finder cycles
303 * Higher values give slightly better compression ratio but
304 * decrease speed. Use special value 0 to let liblzma use
305 * match-finder-dependent default value.
307 * \todo Write much better description.
309 uint32_t match_finder_cycles;
312 * \brief Reserved space for possible future extensions
314 * You should not touch these, because the names of these variables
315 * may change. These are and will never be used with the currently
316 * supported options, so it is safe to leave these uninitialized.
318 uint32_t reserved_int1;
319 uint32_t reserved_int2;
320 uint32_t reserved_int3;
321 uint32_t reserved_int4;
329 * \brief Maximum sum of literal_context_bits and literal_pos_bits
331 * literal_context_bits + literal_pos_bits <= LZMA_LITERAL_BITS_MAX
333 #define LZMA_LITERAL_BITS_MAX 4
337 * \brief Table of presets for the LZMA filter
339 * lzma_preset_lzma[0] is the fastest and lzma_preset_lzma[8] is the slowest.
340 * These presets match the switches -1 .. -9 of the lzma command line tool
342 * The preset values are subject to changes between liblzma versions.
344 * This variable is available only if LZMA encoder has been enabled.
346 extern const lzma_options_lzma lzma_preset_lzma[9];