]> icculus.org git repositories - icculus/xz.git/blob - src/liblzma/api/lzma/subblock.h
Imported to git.
[icculus/xz.git] / src / liblzma / api / lzma / subblock.h
1 /**
2  * \file        lzma/subblock.h
3  * \brief       Subblock filter
4  *
5  * \author      Copyright (C) 1999-2006 Igor Pavlov
6  * \author      Copyright (C) 2007 Lasse Collin
7  *
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.
12  *
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.
17  */
18
19 #ifndef LZMA_H_INTERNAL
20 #       error Never include this file directly. Use <lzma.h> instead.
21 #endif
22
23
24 /**
25  * \brief       Filter ID
26  *
27  * Filter ID of the Subblock filter. This is used as lzma_options_filter.id.
28  */
29 #define LZMA_FILTER_SUBBLOCK    LZMA_VLI_C(0x01)
30
31
32 /**
33  * \brief       Subfilter mode
34  *
35  * See lzma_options_subblock.subfilter_mode for details.
36  */
37 typedef enum {
38         LZMA_SUBFILTER_NONE,
39                 /**<
40                  * No Subfilter is in use.
41                  */
42
43         LZMA_SUBFILTER_SET,
44                 /**<
45                  * New Subfilter has been requested to be initialized.
46                  */
47
48         LZMA_SUBFILTER_RUN,
49                 /**<
50                  * Subfilter is active.
51                  */
52
53         LZMA_SUBFILTER_FINISH
54                 /**<
55                  * Subfilter has been requested to be finished.
56                  */
57 } lzma_subfilter_mode;
58
59
60 /**
61  * \brief       Options for the Subblock filter
62  *
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.
66  */
67 typedef struct {
68         /* Options for encoder and decoder */
69
70         /**
71          * \brief       Allowing subfilters
72          *
73          * If this true, subfilters are allowed.
74          *
75          * In the encoder, if this is set to false, subfilter_mode and
76          * subfilter_options are completely ignored.
77          */
78         lzma_bool allow_subfilters;
79
80         /* Options for encoder only */
81
82         /**
83          * \brief       Alignment
84          *
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.
91          *
92          * The alignment should be a positive integer. Subblock filter will
93          * add enough padding between Subblocks so that this is true for
94          * every payload byte:
95          * input_offset % alignment == output_offset % alignment
96          *
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.
99          *
100          * FIXME desc
101          */
102         uint32_t alignment;
103 #       define LZMA_SUBBLOCK_ALIGNMENT_MIN 1
104 #       define LZMA_SUBBLOCK_ALIGNMENT_MAX 32
105 #       define LZMA_SUBBLOCK_ALIGNMENT_DEFAULT 4
106
107         /**
108          * \brief       Size of the Subblock Data part of each Subblock
109          *
110          * This value is re-read every time a new Subblock is started.
111          *
112          * Bigger values
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).
117          */
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
122
123         /**
124          * \brief       Run-length encoder remote control
125          *
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.
130          *
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
135          * results.
136          *
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.
143          *
144          * If there are consecutive identical buffers of subblock_data_size
145          * bytes, they will be encoded using a single repeat entry if
146          * possible.
147          *
148          * If need arises, more advanced RLE can be implemented later
149          * without breaking API or ABI.
150          */
151         uint32_t rle;
152 #       define LZMA_SUBBLOCK_RLE_OFF 0
153 #       define LZMA_SUBBLOCK_RLE_MIN 1
154 #       define LZMA_SUBBLOCK_RLE_MAX 256
155
156         /**
157          * \brief       Subfilter remote control
158          *
159          * When the Subblock filter is initialized, this variable must be
160          * LZMA_SUBFILTER_NONE or LZMA_SUBFILTER_SET.
161          *
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.
168          *
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.
174          *
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.
180          *
181          * \note        This variable is ignored if allow_subfilters is false.
182          */
183         lzma_subfilter_mode subfilter_mode;
184
185         /**
186          * \brief       Subfilter and its options
187          *
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.
192          *
193          * \note        This variable is ignored if allow_subfilters is false.
194          */
195         lzma_options_filter subfilter_options;
196
197 } lzma_options_subblock;