diff options
Diffstat (limited to 'rbutil/rbutilqt/mspack/mszip.h')
-rw-r--r-- | rbutil/rbutilqt/mspack/mszip.h | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/rbutil/rbutilqt/mspack/mszip.h b/rbutil/rbutilqt/mspack/mszip.h new file mode 100644 index 0000000000..13c9542ee6 --- /dev/null +++ b/rbutil/rbutilqt/mspack/mszip.h | |||
@@ -0,0 +1,121 @@ | |||
1 | /* This file is part of libmspack. | ||
2 | * (C) 2003-2004 Stuart Caie. | ||
3 | * | ||
4 | * The deflate method was created by Phil Katz. MSZIP is equivalent to the | ||
5 | * deflate method. | ||
6 | * | ||
7 | * libmspack is free software; you can redistribute it and/or modify it under | ||
8 | * the terms of the GNU Lesser General Public License (LGPL) version 2.1 | ||
9 | * | ||
10 | * For further details, see the file COPYING.LIB distributed with libmspack | ||
11 | */ | ||
12 | |||
13 | #ifndef MSPACK_MSZIP_H | ||
14 | #define MSPACK_MSZIP_H 1 | ||
15 | |||
16 | #ifdef __cplusplus | ||
17 | extern "C" { | ||
18 | #endif | ||
19 | |||
20 | /* MSZIP (deflate) compression / (inflate) decompression definitions */ | ||
21 | |||
22 | #define MSZIP_FRAME_SIZE (32768) /* size of LZ history window */ | ||
23 | #define MSZIP_LITERAL_MAXSYMBOLS (288) /* literal/length huffman tree */ | ||
24 | #define MSZIP_LITERAL_TABLEBITS (9) | ||
25 | #define MSZIP_DISTANCE_MAXSYMBOLS (32) /* distance huffman tree */ | ||
26 | #define MSZIP_DISTANCE_TABLEBITS (6) | ||
27 | |||
28 | /* if there are less direct lookup entries than symbols, the longer | ||
29 | * code pointers will be <= maxsymbols. This must not happen, or we | ||
30 | * will decode entries badly */ | ||
31 | #if (1 << MSZIP_LITERAL_TABLEBITS) < (MSZIP_LITERAL_MAXSYMBOLS * 2) | ||
32 | # define MSZIP_LITERAL_TABLESIZE (MSZIP_LITERAL_MAXSYMBOLS * 4) | ||
33 | #else | ||
34 | # define MSZIP_LITERAL_TABLESIZE ((1 << MSZIP_LITERAL_TABLEBITS) + \ | ||
35 | (MSZIP_LITERAL_MAXSYMBOLS * 2)) | ||
36 | #endif | ||
37 | |||
38 | #if (1 << MSZIP_DISTANCE_TABLEBITS) < (MSZIP_DISTANCE_MAXSYMBOLS * 2) | ||
39 | # define MSZIP_DISTANCE_TABLESIZE (MSZIP_DISTANCE_MAXSYMBOLS * 4) | ||
40 | #else | ||
41 | # define MSZIP_DISTANCE_TABLESIZE ((1 << MSZIP_DISTANCE_TABLEBITS) + \ | ||
42 | (MSZIP_DISTANCE_MAXSYMBOLS * 2)) | ||
43 | #endif | ||
44 | |||
45 | struct mszipd_stream { | ||
46 | struct mspack_system *sys; /* I/O routines */ | ||
47 | struct mspack_file *input; /* input file handle */ | ||
48 | struct mspack_file *output; /* output file handle */ | ||
49 | unsigned int window_posn; /* offset within window */ | ||
50 | |||
51 | /* inflate() will call this whenever the window should be emptied. */ | ||
52 | int (*flush_window)(struct mszipd_stream *, unsigned int); | ||
53 | |||
54 | int error, repair_mode, bytes_output; | ||
55 | |||
56 | /* I/O buffering */ | ||
57 | unsigned char *inbuf, *i_ptr, *i_end, *o_ptr, *o_end, input_end; | ||
58 | unsigned int bit_buffer, bits_left, inbuf_size; | ||
59 | |||
60 | |||
61 | /* huffman code lengths */ | ||
62 | unsigned char LITERAL_len[MSZIP_LITERAL_MAXSYMBOLS]; | ||
63 | unsigned char DISTANCE_len[MSZIP_DISTANCE_MAXSYMBOLS]; | ||
64 | |||
65 | /* huffman decoding tables */ | ||
66 | unsigned short LITERAL_table [MSZIP_LITERAL_TABLESIZE]; | ||
67 | unsigned short DISTANCE_table[MSZIP_DISTANCE_TABLESIZE]; | ||
68 | |||
69 | /* 32kb history window */ | ||
70 | unsigned char window[MSZIP_FRAME_SIZE]; | ||
71 | }; | ||
72 | |||
73 | /* allocates MS-ZIP decompression stream for decoding the given stream. | ||
74 | * | ||
75 | * - uses system->alloc() to allocate memory | ||
76 | * | ||
77 | * - returns NULL if not enough memory | ||
78 | * | ||
79 | * - input_buffer_size is how many bytes to use as an input bitstream buffer | ||
80 | * | ||
81 | * - if repair_mode is non-zero, errors in decompression will be skipped | ||
82 | * and 'holes' left will be filled with zero bytes. This allows at least | ||
83 | * a partial recovery of erroneous data. | ||
84 | */ | ||
85 | extern struct mszipd_stream *mszipd_init(struct mspack_system *system, | ||
86 | struct mspack_file *input, | ||
87 | struct mspack_file *output, | ||
88 | int input_buffer_size, | ||
89 | int repair_mode); | ||
90 | |||
91 | /* decompresses, or decompresses more of, an MS-ZIP stream. | ||
92 | * | ||
93 | * - out_bytes of data will be decompressed and the function will return | ||
94 | * with an MSPACK_ERR_OK return code. | ||
95 | * | ||
96 | * - decompressing will stop as soon as out_bytes is reached. if the true | ||
97 | * amount of bytes decoded spills over that amount, they will be kept for | ||
98 | * a later invocation of mszipd_decompress(). | ||
99 | * | ||
100 | * - the output bytes will be passed to the system->write() function given in | ||
101 | * mszipd_init(), using the output file handle given in mszipd_init(). More | ||
102 | * than one call may be made to system->write() | ||
103 | * | ||
104 | * - MS-ZIP will read input bytes as necessary using the system->read() | ||
105 | * function given in mszipd_init(), using the input file handle given in | ||
106 | * mszipd_init(). This will continue until system->read() returns 0 bytes, | ||
107 | * or an error. | ||
108 | */ | ||
109 | extern int mszipd_decompress(struct mszipd_stream *zip, off_t out_bytes); | ||
110 | |||
111 | /* frees all stream associated with an MS-ZIP data stream | ||
112 | * | ||
113 | * - calls system->free() using the system pointer given in mszipd_init() | ||
114 | */ | ||
115 | void mszipd_free(struct mszipd_stream *zip); | ||
116 | |||
117 | #ifdef __cplusplus | ||
118 | } | ||
119 | #endif | ||
120 | |||
121 | #endif | ||