2 * \file lzma/subblock.h
3 * \brief Subblock filter
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 Subblock filter. This is used as lzma_options_filter.id.
29 #define LZMA_FILTER_SUBBLOCK LZMA_VLI_C(0x01)
33 * \brief Subfilter mode
35 * See lzma_options_subblock.subfilter_mode for details.
40 * No Subfilter is in use.
45 * New Subfilter has been requested to be initialized.
50 * Subfilter is active.
55 * Subfilter has been requested to be finished.
57 } lzma_subfilter_mode;
61 * \brief Options for the Subblock filter
63 * Specifying options for the Subblock filter is optional: if the pointer
64 * options is NULL, no subfilters are allowed and the default value is used
65 * for subblock_data_size.
68 /* Options for encoder and decoder */
71 * \brief Allowing subfilters
73 * If this true, subfilters are allowed.
75 * In the encoder, if this is set to false, subfilter_mode and
76 * subfilter_options are completely ignored.
78 lzma_bool allow_subfilters;
80 /* Options for encoder only */
85 * The Subblock filter encapsulates the input data into Subblocks.
86 * Each Subblock has a header which takes a few bytes of space.
87 * When the output of the Subblock encoder is fed to another filter
88 * that takes advantage of the alignment of the input data (e.g. LZMA),
89 * the Subblock filter can add padding to keep the actual data parts
90 * in the Subblocks aligned correctly.
92 * The alignment should be a positive integer. Subblock filter will
93 * add enough padding between Subblocks so that this is true for
95 * input_offset % alignment == output_offset % alignment
97 * The Subblock filter assumes that the first output byte will be
98 * written to a position in the output stream that is properly aligned.
103 # define LZMA_SUBBLOCK_ALIGNMENT_MIN 1
104 # define LZMA_SUBBLOCK_ALIGNMENT_MAX 32
105 # define LZMA_SUBBLOCK_ALIGNMENT_DEFAULT 4
108 * \brief Size of the Subblock Data part of each Subblock
110 * This value is re-read every time a new Subblock is started.
113 * - save a few bytes of space;
114 * - increase latency in the encoder (but no effect for decoding);
115 * - decrease memory locality (increased cache pollution) in the
116 * encoder (no effect in decoding).
118 uint32_t subblock_data_size;
119 # define LZMA_SUBBLOCK_DATA_SIZE_MIN 1
120 # define LZMA_SUBBLOCK_DATA_SIZE_MAX (UINT32_C(1) << 28)
121 # define LZMA_SUBBLOCK_DATA_SIZE_DEFAULT 4096
124 * \brief Run-length encoder remote control
126 * The Subblock filter has an internal run-length encoder (RLE). It
127 * can be useful when the data includes byte sequences that repeat
128 * very many times. The RLE can be used also when a Subfilter is
129 * in use; the RLE will be applied to the output of the Subfilter.
131 * Note that in contrast to traditional RLE, this RLE is intended to
132 * be used only when there's a lot of data to be repeated. If the
133 * input data has e.g. 500 bytes of NULs now and then, this RLE
134 * is probably useless, because plain LZMA should provide better
137 * Due to above reasons, it was decided to keep the implementation
138 * of the RLE very simple. When the rle variable is non-zero, it
139 * subblock_data_size must be a multiple of rle. Once the Subblock
140 * encoder has got subblock_data_size bytes of input, it will check
141 * if the whole buffer of the last subblock_data_size can be
142 * represented with repeats of chunks having size of rle bytes.
144 * If there are consecutive identical buffers of subblock_data_size
145 * bytes, they will be encoded using a single repeat entry if
148 * If need arises, more advanced RLE can be implemented later
149 * without breaking API or ABI.
152 # define LZMA_SUBBLOCK_RLE_OFF 0
153 # define LZMA_SUBBLOCK_RLE_MIN 1
154 # define LZMA_SUBBLOCK_RLE_MAX 256
157 * \brief Subfilter remote control
159 * When the Subblock filter is initialized, this variable must be
160 * LZMA_SUBFILTER_NONE or LZMA_SUBFILTER_SET.
162 * When subfilter_mode is LZMA_SUBFILTER_NONE, the application may
163 * put Subfilter options to subfilter_options structure, and then
164 * set subfilter_mode to LZMA_SUBFILTER_SET. This implies setting
165 * flush to true. No new input data will be read until the Subfilter
166 * has been enabled. Once the Subfilter has been enabled, liblzma
167 * will set subfilter_mode to LZMA_SUBFILTER_RUN.
169 * When subfilter_mode is LZMA_SUBFILTER_RUN, the application may
170 * set subfilter_mode to LZMA_SUBFILTER_FINISH. No new input data
171 * will be read until the Subfilter has been finished. Once the
172 * Subfilter has been finished, liblzma will set subfilter_mode
173 * to LZMA_SUBFILTER_NONE.
175 * If the intent is to have Subfilter enabled to the very end of
176 * the data, it is not needed to separately disable Subfilter with
177 * LZMA_SUBFILTER_FINISH. Using LZMA_FINISH as the second argument
178 * of lzma_code() will make the Subblock encoder to disable the
179 * Subfilter once all the data has been ran through the Subfilter.
181 * \note This variable is ignored if allow_subfilters is false.
183 lzma_subfilter_mode subfilter_mode;
186 * \brief Subfilter and its options
188 * When no Subfilter is used, the data is copied as is into Subblocks.
189 * Setting a Subfilter allows encoding some parts of the data with
190 * an additional filter. It is possible to many different Subfilters
191 * in the same Block, although only one can be used at once.
193 * \note This variable is ignored if allow_subfilters is false.
195 lzma_options_filter subfilter_options;
197 } lzma_options_subblock;