summaryrefslogtreecommitdiff
path: root/rbutil/rbutilqt/mspack/lzx.h
diff options
context:
space:
mode:
Diffstat (limited to 'rbutil/rbutilqt/mspack/lzx.h')
-rw-r--r--rbutil/rbutilqt/mspack/lzx.h61
1 files changed, 44 insertions, 17 deletions
diff --git a/rbutil/rbutilqt/mspack/lzx.h b/rbutil/rbutilqt/mspack/lzx.h
index fc69928c96..a6152f622b 100644
--- a/rbutil/rbutilqt/mspack/lzx.h
+++ b/rbutil/rbutilqt/mspack/lzx.h
@@ -1,5 +1,5 @@
1/* This file is part of libmspack. 1/* This file is part of libmspack.
2 * (C) 2003-2004 Stuart Caie. 2 * (C) 2003-2013 Stuart Caie.
3 * 3 *
4 * The LZX method was created by Jonathan Forbes and Tomi Poutanen, adapted 4 * The LZX method was created by Jonathan Forbes and Tomi Poutanen, adapted
5 * by Microsoft Corporation. 5 * by Microsoft Corporation.
@@ -35,7 +35,7 @@ extern "C" {
35/* LZX huffman defines: tweak tablebits as desired */ 35/* LZX huffman defines: tweak tablebits as desired */
36#define LZX_PRETREE_MAXSYMBOLS (LZX_PRETREE_NUM_ELEMENTS) 36#define LZX_PRETREE_MAXSYMBOLS (LZX_PRETREE_NUM_ELEMENTS)
37#define LZX_PRETREE_TABLEBITS (6) 37#define LZX_PRETREE_TABLEBITS (6)
38#define LZX_MAINTREE_MAXSYMBOLS (LZX_NUM_CHARS + 50*8) 38#define LZX_MAINTREE_MAXSYMBOLS (LZX_NUM_CHARS + 290*8)
39#define LZX_MAINTREE_TABLEBITS (12) 39#define LZX_MAINTREE_TABLEBITS (12)
40#define LZX_LENGTH_MAXSYMBOLS (LZX_NUM_SECONDARY_LENGTHS+1) 40#define LZX_LENGTH_MAXSYMBOLS (LZX_NUM_SECONDARY_LENGTHS+1)
41#define LZX_LENGTH_TABLEBITS (12) 41#define LZX_LENGTH_TABLEBITS (12)
@@ -55,6 +55,8 @@ struct lzxd_stream {
55 55
56 unsigned char *window; /* decoding window */ 56 unsigned char *window; /* decoding window */
57 unsigned int window_size; /* window size */ 57 unsigned int window_size; /* window size */
58 unsigned int ref_data_size; /* LZX DELTA reference data size */
59 unsigned int num_offsets; /* number of match_offset entries in table */
58 unsigned int window_posn; /* decompression offset within window */ 60 unsigned int window_posn; /* decompression offset within window */
59 unsigned int frame_posn; /* current frame offset within in window */ 61 unsigned int frame_posn; /* current frame offset within in window */
60 unsigned int frame; /* the number of 32kb frames processed */ 62 unsigned int frame; /* the number of 32kb frames processed */
@@ -70,8 +72,8 @@ struct lzxd_stream {
70 unsigned char intel_started; /* has intel E8 decoding started? */ 72 unsigned char intel_started; /* has intel E8 decoding started? */
71 unsigned char block_type; /* type of the current block */ 73 unsigned char block_type; /* type of the current block */
72 unsigned char header_read; /* have we started decoding at all yet? */ 74 unsigned char header_read; /* have we started decoding at all yet? */
73 unsigned char posn_slots; /* how many posn slots in stream? */
74 unsigned char input_end; /* have we reached the end of input? */ 75 unsigned char input_end; /* have we reached the end of input? */
76 unsigned char is_delta; /* does stream follow LZX DELTA spec? */
75 77
76 int error; 78 int error;
77 79
@@ -87,13 +89,13 @@ struct lzxd_stream {
87 89
88 /* huffman decoding tables */ 90 /* huffman decoding tables */
89 unsigned short PRETREE_table [(1 << LZX_PRETREE_TABLEBITS) + 91 unsigned short PRETREE_table [(1 << LZX_PRETREE_TABLEBITS) +
90 (LZX_PRETREE_MAXSYMBOLS * 2)]; 92 (LZX_PRETREE_MAXSYMBOLS * 2)];
91 unsigned short MAINTREE_table[(1 << LZX_MAINTREE_TABLEBITS) + 93 unsigned short MAINTREE_table[(1 << LZX_MAINTREE_TABLEBITS) +
92 (LZX_MAINTREE_MAXSYMBOLS * 2)]; 94 (LZX_MAINTREE_MAXSYMBOLS * 2)];
93 unsigned short LENGTH_table [(1 << LZX_LENGTH_TABLEBITS) + 95 unsigned short LENGTH_table [(1 << LZX_LENGTH_TABLEBITS) +
94 (LZX_LENGTH_MAXSYMBOLS * 2)]; 96 (LZX_LENGTH_MAXSYMBOLS * 2)];
95 unsigned short ALIGNED_table [(1 << LZX_ALIGNED_TABLEBITS) + 97 unsigned short ALIGNED_table [(1 << LZX_ALIGNED_TABLEBITS) +
96 (LZX_ALIGNED_MAXSYMBOLS * 2)]; 98 (LZX_ALIGNED_MAXSYMBOLS * 2)];
97 unsigned char LENGTH_empty; 99 unsigned char LENGTH_empty;
98 100
99 /* this is used purely for doing the intel E8 transform */ 101 /* this is used purely for doing the intel E8 transform */
@@ -114,12 +116,14 @@ struct lzxd_stream {
114 * @param input an input stream with the LZX data. 116 * @param input an input stream with the LZX data.
115 * @param output an output stream to write the decoded data to. 117 * @param output an output stream to write the decoded data to.
116 * @param window_bits the size of the decoding window, which must be 118 * @param window_bits the size of the decoding window, which must be
117 * between 15 and 21 inclusive. 119 * between 15 and 21 inclusive for regular LZX
120 * data, or between 17 and 25 inclusive for
121 * LZX DELTA data.
118 * @param reset_interval the interval at which the LZX bitstream is 122 * @param reset_interval the interval at which the LZX bitstream is
119 * reset, in multiples of LZX frames (32678 123 * reset, in multiples of LZX frames (32678
120 * bytes), e.g. a value of 2 indicates the input 124 * bytes), e.g. a value of 2 indicates the input
121 * stream resets after every 65536 output bytes. 125 * stream resets after every 65536 output bytes.
122 * A value of 0 indicates that the bistream never 126 * A value of 0 indicates that the bitstream never
123 * resets, such as in CAB LZX streams. 127 * resets, such as in CAB LZX streams.
124 * @param input_buffer_size the number of bytes to use as an input 128 * @param input_buffer_size the number of bytes to use as an input
125 * bitstream buffer. 129 * bitstream buffer.
@@ -135,26 +139,49 @@ struct lzxd_stream {
135 * lzxd_set_output_length() once it is 139 * lzxd_set_output_length() once it is
136 * known. If never set, 4 of the final 6 bytes 140 * known. If never set, 4 of the final 6 bytes
137 * of the output stream may be incorrect. 141 * of the output stream may be incorrect.
142 * @param is_delta should be zero for all regular LZX data,
143 * non-zero for LZX DELTA encoded data.
138 * @return a pointer to an initialised lzxd_stream structure, or NULL if 144 * @return a pointer to an initialised lzxd_stream structure, or NULL if
139 * there was not enough memory or parameters to the function were wrong. 145 * there was not enough memory or parameters to the function were wrong.
140 */ 146 */
141extern struct lzxd_stream *lzxd_init(struct mspack_system *system, 147extern struct lzxd_stream *lzxd_init(struct mspack_system *system,
142 struct mspack_file *input, 148 struct mspack_file *input,
143 struct mspack_file *output, 149 struct mspack_file *output,
144 int window_bits, 150 int window_bits,
145 int reset_interval, 151 int reset_interval,
146 int input_buffer_size, 152 int input_buffer_size,
147 off_t output_length); 153 off_t output_length,
154 char is_delta);
148 155
149/* see description of output_length in lzxd_init() */ 156/* see description of output_length in lzxd_init() */
150extern void lzxd_set_output_length(struct lzxd_stream *lzx, 157extern void lzxd_set_output_length(struct lzxd_stream *lzx,
151 off_t output_length); 158 off_t output_length);
159
160/**
161 * Reads LZX DELTA reference data into the window and allows
162 * lzxd_decompress() to reference it.
163 *
164 * Call this before the first call to lzxd_decompress().
165
166 * @param lzx the LZX stream to apply this reference data to
167 * @param system an mspack_system implementation to use with the
168 * input param. Only read() will be called.
169 * @param input an input file handle to read reference data using
170 * system->read().
171 * @param length the length of the reference data. Cannot be longer
172 * than the LZX window size.
173 * @return an error code, or MSPACK_ERR_OK if successful
174 */
175extern int lzxd_set_reference_data(struct lzxd_stream *lzx,
176 struct mspack_system *system,
177 struct mspack_file *input,
178 unsigned int length);
152 179
153/** 180/**
154 * Decompresses entire or partial LZX streams. 181 * Decompresses entire or partial LZX streams.
155 * 182 *
156 * The number of bytes of data that should be decompressed is given as the 183 * The number of bytes of data that should be decompressed is given as the
157 * out_bytes parameter. If more bytes are decoded than are needed, they 184 * out_bytes parameter. If more bytes are decoded than are needed, they
158 * will be kept over for a later invocation. 185 * will be kept over for a later invocation.
159 * 186 *
160 * The output bytes will be passed to the system->write() function given in 187 * The output bytes will be passed to the system->write() function given in