2 * \file lzma/subblock.h
3 * \brief Subblock filter
9 * This file has been put into the public domain.
10 * You can do whatever you want with this file.
12 * See ../lzma.h for information about liblzma as a whole.
15 #ifndef LZMA_H_INTERNAL
16 # error Never include this file directly. Use <lzma.h> instead.
23 * Filter ID of the Subblock filter. This is used as lzma_filter.id.
25 #define LZMA_FILTER_SUBBLOCK LZMA_VLI_C(0x01)
29 * \brief Subfilter mode
31 * See lzma_options_subblock.subfilter_mode for details.
36 * No Subfilter is in use.
41 * New Subfilter has been requested to be initialized.
46 * Subfilter is active.
51 * Subfilter has been requested to be finished.
53 } lzma_subfilter_mode;
57 * \brief Options for the Subblock filter
59 * Specifying options for the Subblock filter is optional: if the pointer
60 * options is NULL, no subfilters are allowed and the default value is used
61 * for subblock_data_size.
64 /* Options for encoder and decoder */
67 * \brief Allowing subfilters
69 * If this true, subfilters are allowed.
71 * In the encoder, if this is set to false, subfilter_mode and
72 * subfilter_options are completely ignored.
74 lzma_bool allow_subfilters;
76 /* Options for encoder only */
81 * The Subblock filter encapsulates the input data into Subblocks.
82 * Each Subblock has a header which takes a few bytes of space.
83 * When the output of the Subblock encoder is fed to another filter
84 * that takes advantage of the alignment of the input data (e.g. LZMA),
85 * the Subblock filter can add padding to keep the actual data parts
86 * in the Subblocks aligned correctly.
88 * The alignment should be a positive integer. Subblock filter will
89 * add enough padding between Subblocks so that this is true for
91 * input_offset % alignment == output_offset % alignment
93 * The Subblock filter assumes that the first output byte will be
94 * written to a position in the output stream that is properly
95 * aligned. This requirement is automatically met when the start
96 * offset of the Stream or Block is correctly told to Block or
100 # define LZMA_SUBBLOCK_ALIGNMENT_MIN 1
101 # define LZMA_SUBBLOCK_ALIGNMENT_MAX 32
102 # define LZMA_SUBBLOCK_ALIGNMENT_DEFAULT 4
105 * \brief Size of the Subblock Data part of each Subblock
107 * This value is re-read every time a new Subblock is started.
110 * - save a few bytes of space;
111 * - increase latency in the encoder (but no effect for decoding);
112 * - decrease memory locality (increased cache pollution) in the
113 * encoder (no effect in decoding).
115 uint32_t subblock_data_size;
116 # define LZMA_SUBBLOCK_DATA_SIZE_MIN 1
117 # define LZMA_SUBBLOCK_DATA_SIZE_MAX (UINT32_C(1) << 28)
118 # define LZMA_SUBBLOCK_DATA_SIZE_DEFAULT 4096
121 * \brief Run-length encoder remote control
123 * The Subblock filter has an internal run-length encoder (RLE). It
124 * can be useful when the data includes byte sequences that repeat
125 * very many times. The RLE can be used also when a Subfilter is
126 * in use; the RLE will be applied to the output of the Subfilter.
128 * Note that in contrast to traditional RLE, this RLE is intended to
129 * be used only when there's a lot of data to be repeated. If the
130 * input data has e.g. 500 bytes of NULs now and then, this RLE
131 * is probably useless, because plain LZMA should provide better
134 * Due to above reasons, it was decided to keep the implementation
135 * of the RLE very simple. When the rle variable is non-zero, it
136 * subblock_data_size must be a multiple of rle. Once the Subblock
137 * encoder has got subblock_data_size bytes of input, it will check
138 * if the whole buffer of the last subblock_data_size can be
139 * represented with repeats of chunks having size of rle bytes.
141 * If there are consecutive identical buffers of subblock_data_size
142 * bytes, they will be encoded using a single repeat entry if
145 * If need arises, more advanced RLE can be implemented later
146 * without breaking API or ABI.
149 # define LZMA_SUBBLOCK_RLE_OFF 0
150 # define LZMA_SUBBLOCK_RLE_MIN 1
151 # define LZMA_SUBBLOCK_RLE_MAX 256
154 * \brief Subfilter remote control
156 * When the Subblock filter is initialized, this variable must be
157 * LZMA_SUBFILTER_NONE or LZMA_SUBFILTER_SET.
159 * When subfilter_mode is LZMA_SUBFILTER_NONE, the application may
160 * put Subfilter options to subfilter_options structure, and then
161 * set subfilter_mode to LZMA_SUBFILTER_SET. No new input data will
162 * be read until the Subfilter has been enabled. Once the Subfilter
163 * has been enabled, liblzma will set subfilter_mode to
164 * LZMA_SUBFILTER_RUN.
166 * When subfilter_mode is LZMA_SUBFILTER_RUN, the application may
167 * set subfilter_mode to LZMA_SUBFILTER_FINISH. All the input
168 * currently available will be encoded before unsetting the
169 * Subfilter. Application must not change the amount of available
170 * input until the Subfilter has finished. Once the Subfilter has
171 * finished, liblzma will set subfilter_mode to LZMA_SUBFILTER_NONE.
173 * If the intent is to have Subfilter enabled to the very end of
174 * the data, it is not needed to separately disable Subfilter with
175 * LZMA_SUBFILTER_FINISH. Using LZMA_FINISH as the second argument
176 * of lzma_code() will make the Subblock encoder to disable the
177 * Subfilter once all the data has been ran through the Subfilter.
179 * After the first call with LZMA_SYNC_FLUSH or LZMA_FINISH, the
180 * application must not change subfilter_mode until LZMA_STREAM_END.
181 * Setting LZMA_SUBFILTER_SET/LZMA_SUBFILTER_FINISH and
182 * LZMA_SYNC_FLUSH/LZMA_FINISH _at the same time_ is fine.
184 * \note This variable is ignored if allow_subfilters is false.
186 lzma_subfilter_mode subfilter_mode;
189 * \brief Subfilter and its options
191 * When no Subfilter is used, the data is copied as is into Subblocks.
192 * Setting a Subfilter allows encoding some parts of the data with
193 * an additional filter. It is possible to many different Subfilters
194 * in the same Block, although only one can be used at once.
196 * \note This variable is ignored if allow_subfilters is false.
198 lzma_filter subfilter_options;
200 } lzma_options_subblock;