extlzham 0.0.1.PROTOTYPE3-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.md +27 -0
- data/README.md +74 -0
- data/Rakefile +152 -0
- data/contrib/lzham/LICENSE +22 -0
- data/contrib/lzham/README.md +209 -0
- data/contrib/lzham/include/lzham.h +781 -0
- data/contrib/lzham/lzhamcomp/lzham_comp.h +38 -0
- data/contrib/lzham/lzhamcomp/lzham_lzbase.cpp +244 -0
- data/contrib/lzham/lzhamcomp/lzham_lzbase.h +45 -0
- data/contrib/lzham/lzhamcomp/lzham_lzcomp.cpp +608 -0
- data/contrib/lzham/lzhamcomp/lzham_lzcomp_internal.cpp +1966 -0
- data/contrib/lzham/lzhamcomp/lzham_lzcomp_internal.h +472 -0
- data/contrib/lzham/lzhamcomp/lzham_lzcomp_state.cpp +1413 -0
- data/contrib/lzham/lzhamcomp/lzham_match_accel.cpp +562 -0
- data/contrib/lzham/lzhamcomp/lzham_match_accel.h +146 -0
- data/contrib/lzham/lzhamcomp/lzham_null_threading.h +97 -0
- data/contrib/lzham/lzhamcomp/lzham_pthreads_threading.cpp +229 -0
- data/contrib/lzham/lzhamcomp/lzham_pthreads_threading.h +520 -0
- data/contrib/lzham/lzhamcomp/lzham_threading.h +12 -0
- data/contrib/lzham/lzhamcomp/lzham_win32_threading.cpp +220 -0
- data/contrib/lzham/lzhamcomp/lzham_win32_threading.h +368 -0
- data/contrib/lzham/lzhamdecomp/lzham_assert.cpp +66 -0
- data/contrib/lzham/lzhamdecomp/lzham_assert.h +40 -0
- data/contrib/lzham/lzhamdecomp/lzham_checksum.cpp +73 -0
- data/contrib/lzham/lzhamdecomp/lzham_checksum.h +13 -0
- data/contrib/lzham/lzhamdecomp/lzham_config.h +23 -0
- data/contrib/lzham/lzhamdecomp/lzham_core.h +264 -0
- data/contrib/lzham/lzhamdecomp/lzham_decomp.h +37 -0
- data/contrib/lzham/lzhamdecomp/lzham_helpers.h +54 -0
- data/contrib/lzham/lzhamdecomp/lzham_huffman_codes.cpp +262 -0
- data/contrib/lzham/lzhamdecomp/lzham_huffman_codes.h +14 -0
- data/contrib/lzham/lzhamdecomp/lzham_lzdecomp.cpp +1527 -0
- data/contrib/lzham/lzhamdecomp/lzham_lzdecompbase.cpp +131 -0
- data/contrib/lzham/lzhamdecomp/lzham_lzdecompbase.h +89 -0
- data/contrib/lzham/lzhamdecomp/lzham_math.h +142 -0
- data/contrib/lzham/lzhamdecomp/lzham_mem.cpp +284 -0
- data/contrib/lzham/lzhamdecomp/lzham_mem.h +112 -0
- data/contrib/lzham/lzhamdecomp/lzham_platform.cpp +157 -0
- data/contrib/lzham/lzhamdecomp/lzham_platform.h +284 -0
- data/contrib/lzham/lzhamdecomp/lzham_prefix_coding.cpp +351 -0
- data/contrib/lzham/lzhamdecomp/lzham_prefix_coding.h +146 -0
- data/contrib/lzham/lzhamdecomp/lzham_symbol_codec.cpp +1484 -0
- data/contrib/lzham/lzhamdecomp/lzham_symbol_codec.h +556 -0
- data/contrib/lzham/lzhamdecomp/lzham_timer.cpp +147 -0
- data/contrib/lzham/lzhamdecomp/lzham_timer.h +99 -0
- data/contrib/lzham/lzhamdecomp/lzham_traits.h +141 -0
- data/contrib/lzham/lzhamdecomp/lzham_types.h +97 -0
- data/contrib/lzham/lzhamdecomp/lzham_utils.h +58 -0
- data/contrib/lzham/lzhamdecomp/lzham_vector.cpp +75 -0
- data/contrib/lzham/lzhamdecomp/lzham_vector.h +588 -0
- data/contrib/lzham/lzhamlib/lzham_lib.cpp +179 -0
- data/examples/basic.rb +48 -0
- data/ext/constants.c +64 -0
- data/ext/decoder.c +313 -0
- data/ext/depend +5 -0
- data/ext/encoder.c +372 -0
- data/ext/error.c +80 -0
- data/ext/extconf.rb +29 -0
- data/ext/extlzham.c +34 -0
- data/ext/extlzham.h +62 -0
- data/gemstub.rb +22 -0
- data/lib/2.0/extlzham.so +0 -0
- data/lib/2.1/extlzham.so +0 -0
- data/lib/2.2/extlzham.so +0 -0
- data/lib/extlzham.rb +158 -0
- data/lib/extlzham/version.rb +5 -0
- data/test/test_extlzham.rb +35 -0
- metadata +156 -0
@@ -0,0 +1,781 @@
|
|
1
|
+
// File: lzham.h - Copyright (c) 2009-2012 Richard Geldreich, Jr. <richgel99@gmail.com>
|
2
|
+
// LZHAM uses the MIT License. See Copyright Notice and license at the end of this file.
|
3
|
+
//
|
4
|
+
// This is the main header file, includable from C or C++ files, which defines all the publically available API's, structs, and types used by the LZHAM codec.
|
5
|
+
//
|
6
|
+
// Notes:
|
7
|
+
//
|
8
|
+
// As of LZHAM alpha8, there are now two sets of API's:
|
9
|
+
// - The first (oldest) API directly exposes all of the codec's functionality. See lzham_compress_init(), lzham_decompress_init(), etc. This API has the lowest overhead
|
10
|
+
// and is the most tested.
|
11
|
+
// - The new API implements the most useful/popular subset of the zlib API, but doesn't expose all of the codec's functionality yet. See the lzham_z* functions.
|
12
|
+
// This functionality is provided because most users of compression libraries are already very familiar with the nuts and bolts of the zlib API.
|
13
|
+
// For the most common zlib usage cases LZHAM is an almost drop-in replacement for zlib. To make switching from zlib even easier, you can define the LZHAM_DEFINE_ZLIB_API macro,
|
14
|
+
// which causes this header to #define most zlib symbols to their LZHAM equivalents.
|
15
|
+
// Note that LZHAM does not actually implement the deflate/inflate algorithm, so it cannot decompress streams created by standard zlib yet (and of course, zlib cannot decompress
|
16
|
+
// streams created by LZHAM). Internally, this API is mostly implemented via the older low-level LZHAM API.
|
17
|
+
|
18
|
+
#ifndef __LZHAM_H__
|
19
|
+
#define __LZHAM_H__
|
20
|
+
|
21
|
+
#ifdef _MSC_VER
|
22
|
+
#pragma once
|
23
|
+
#endif
|
24
|
+
|
25
|
+
#include <stdlib.h>
|
26
|
+
|
27
|
+
// Upper byte = major version
|
28
|
+
// Lower byte = minor version
|
29
|
+
#define LZHAM_DLL_VERSION 0x1010
|
30
|
+
|
31
|
+
#if defined(_WIN64) || defined(__MINGW64__) || defined(_LP64) || defined(__LP64__)
|
32
|
+
#define LZHAM_64BIT 1
|
33
|
+
#endif
|
34
|
+
|
35
|
+
#if defined(_MSC_VER)
|
36
|
+
#define LZHAM_CDECL __cdecl
|
37
|
+
#else
|
38
|
+
#define LZHAM_CDECL
|
39
|
+
#endif
|
40
|
+
|
41
|
+
#ifdef LZHAM_EXPORTS
|
42
|
+
#define LZHAM_DLL_EXPORT __declspec(dllexport)
|
43
|
+
#else
|
44
|
+
#define LZHAM_DLL_EXPORT
|
45
|
+
#endif
|
46
|
+
|
47
|
+
#ifdef __cplusplus
|
48
|
+
extern "C" {
|
49
|
+
#endif
|
50
|
+
|
51
|
+
typedef unsigned char lzham_uint8;
|
52
|
+
typedef signed int lzham_int32;
|
53
|
+
typedef unsigned int lzham_uint32;
|
54
|
+
typedef unsigned int lzham_bool;
|
55
|
+
|
56
|
+
// Returns DLL version (LZHAM_DLL_VERSION).
|
57
|
+
LZHAM_DLL_EXPORT lzham_uint32 LZHAM_CDECL lzham_get_version(void);
|
58
|
+
|
59
|
+
// User provided memory allocation
|
60
|
+
|
61
|
+
// Custom allocation function must return pointers with LZHAM_MIN_ALLOC_ALIGNMENT (or better).
|
62
|
+
#define LZHAM_MIN_ALLOC_ALIGNMENT sizeof(size_t) * 2
|
63
|
+
|
64
|
+
typedef void* (LZHAM_CDECL *lzham_realloc_func)(void* p, size_t size, size_t* pActual_size, lzham_bool movable, void* pUser_data);
|
65
|
+
typedef size_t (LZHAM_CDECL *lzham_msize_func)(void* p, void* pUser_data);
|
66
|
+
|
67
|
+
// Call this function to force LZHAM to use custom memory malloc(), realloc(), free() and msize functions.
|
68
|
+
LZHAM_DLL_EXPORT void LZHAM_CDECL lzham_set_memory_callbacks(lzham_realloc_func pRealloc, lzham_msize_func pMSize, void* pUser_data);
|
69
|
+
|
70
|
+
// lzham_flush_t must map directly to the zlib-style API flush types (LZHAM_Z_NO_FLUSH, etc.)
|
71
|
+
typedef enum
|
72
|
+
{
|
73
|
+
LZHAM_NO_FLUSH = 0,
|
74
|
+
LZHAM_SYNC_FLUSH = 2,
|
75
|
+
LZHAM_FULL_FLUSH = 3,
|
76
|
+
LZHAM_FINISH = 4,
|
77
|
+
LZHAM_TABLE_FLUSH = 10
|
78
|
+
} lzham_flush_t;
|
79
|
+
|
80
|
+
// Compression (keep in sync with g_num_lzx_position_slots[])
|
81
|
+
#define LZHAM_MIN_DICT_SIZE_LOG2 15
|
82
|
+
#define LZHAM_MAX_DICT_SIZE_LOG2_X86 26
|
83
|
+
#define LZHAM_MAX_DICT_SIZE_LOG2_X64 29
|
84
|
+
|
85
|
+
#define LZHAM_MAX_HELPER_THREADS 64
|
86
|
+
|
87
|
+
typedef enum
|
88
|
+
{
|
89
|
+
LZHAM_COMP_STATUS_NOT_FINISHED = 0,
|
90
|
+
LZHAM_COMP_STATUS_NEEDS_MORE_INPUT,
|
91
|
+
LZHAM_COMP_STATUS_HAS_MORE_OUTPUT,
|
92
|
+
|
93
|
+
// All the following enums must indicate failure/success.
|
94
|
+
|
95
|
+
LZHAM_COMP_STATUS_FIRST_SUCCESS_OR_FAILURE_CODE,
|
96
|
+
LZHAM_COMP_STATUS_SUCCESS = LZHAM_COMP_STATUS_FIRST_SUCCESS_OR_FAILURE_CODE,
|
97
|
+
|
98
|
+
LZHAM_COMP_STATUS_FIRST_FAILURE_CODE,
|
99
|
+
LZHAM_COMP_STATUS_FAILED = LZHAM_COMP_STATUS_FIRST_FAILURE_CODE,
|
100
|
+
LZHAM_COMP_STATUS_FAILED_INITIALIZING,
|
101
|
+
LZHAM_COMP_STATUS_INVALID_PARAMETER,
|
102
|
+
LZHAM_COMP_STATUS_OUTPUT_BUF_TOO_SMALL,
|
103
|
+
|
104
|
+
LZHAM_COMP_STATUS_FORCE_DWORD = 0xFFFFFFFF
|
105
|
+
} lzham_compress_status_t;
|
106
|
+
|
107
|
+
typedef enum
|
108
|
+
{
|
109
|
+
LZHAM_COMP_LEVEL_FASTEST = 0,
|
110
|
+
LZHAM_COMP_LEVEL_FASTER,
|
111
|
+
LZHAM_COMP_LEVEL_DEFAULT,
|
112
|
+
LZHAM_COMP_LEVEL_BETTER,
|
113
|
+
LZHAM_COMP_LEVEL_UBER,
|
114
|
+
|
115
|
+
LZHAM_TOTAL_COMP_LEVELS,
|
116
|
+
|
117
|
+
LZHAM_COMP_LEVEL_FORCE_DWORD = 0xFFFFFFFF
|
118
|
+
} lzham_compress_level;
|
119
|
+
|
120
|
+
// Streaming compression
|
121
|
+
typedef void *lzham_compress_state_ptr;
|
122
|
+
|
123
|
+
typedef enum
|
124
|
+
{
|
125
|
+
LZHAM_COMP_FLAG_EXTREME_PARSING = 2, // Improves ratio by allowing the compressor's parse graph to grow "higher" (up to 4 parent nodes per output node), but is much slower.
|
126
|
+
LZHAM_COMP_FLAG_DETERMINISTIC_PARSING = 4, // Guarantees that the compressed output will always be the same given the same input and parameters (no variation between runs due to kernel threading scheduling).
|
127
|
+
|
128
|
+
// If enabled, the compressor is free to use any optimizations which could lower the decompression rate (such
|
129
|
+
// as adaptively resetting the Huffman table update rate to maximum frequency, which is costly for the decompressor).
|
130
|
+
LZHAM_COMP_FLAG_TRADEOFF_DECOMPRESSION_RATE_FOR_COMP_RATIO = 16,
|
131
|
+
|
132
|
+
LZHAM_COMP_FLAG_WRITE_ZLIB_STREAM = 32,
|
133
|
+
} lzham_compress_flags;
|
134
|
+
|
135
|
+
typedef enum
|
136
|
+
{
|
137
|
+
LZHAM_INSANELY_SLOW_TABLE_UPDATE_RATE = 1, // 1=insanely slow decompression, here for reference, use 2!
|
138
|
+
LZHAM_SLOWEST_TABLE_UPDATE_RATE = 2,
|
139
|
+
LZHAM_DEFAULT_TABLE_UPDATE_RATE = 8,
|
140
|
+
LZHAM_FASTEST_TABLE_UPDATE_RATE = 20
|
141
|
+
} lzham_table_update_rate;
|
142
|
+
|
143
|
+
// Compression parameters struct.
|
144
|
+
// IMPORTANT: The values of m_dict_size_log2, m_table_update_rate, m_table_max_update_interval, and m_table_update_interval_slow_rate MUST
|
145
|
+
// match during compression and decompression. The codec does not verify these values for you, if you don't use the same settings during
|
146
|
+
// decompression it will fail (usually with a LZHAM_DECOMP_STATUS_FAILED_BAD_CODE error).
|
147
|
+
// The seed buffer's contents and size must match the seed buffer used during decompression.
|
148
|
+
typedef struct
|
149
|
+
{
|
150
|
+
lzham_uint32 m_struct_size; // set to sizeof(lzham_compress_params)
|
151
|
+
lzham_uint32 m_dict_size_log2; // set to the log2(dictionary_size), must range between [LZHAM_MIN_DICT_SIZE_LOG2, LZHAM_MAX_DICT_SIZE_LOG2_X86] for x86 LZHAM_MAX_DICT_SIZE_LOG2_X64 for x64
|
152
|
+
lzham_compress_level m_level; // set to LZHAM_COMP_LEVEL_FASTEST, etc.
|
153
|
+
lzham_uint32 m_table_update_rate; // Controls tradeoff between ratio and decompression throughput. 0=default, or [1,LZHAM_MAX_TABLE_UPDATE_RATE], higher=faster but lower ratio.
|
154
|
+
lzham_int32 m_max_helper_threads; // max # of additional "helper" threads to create, must range between [-1,LZHAM_MAX_HELPER_THREADS], where -1=max practical
|
155
|
+
lzham_uint32 m_compress_flags; // optional compression flags (see lzham_compress_flags enum)
|
156
|
+
lzham_uint32 m_num_seed_bytes; // for delta compression (optional) - number of seed bytes pointed to by m_pSeed_bytes
|
157
|
+
const void *m_pSeed_bytes; // for delta compression (optional) - pointer to seed bytes buffer, must be at least m_num_seed_bytes long
|
158
|
+
|
159
|
+
// Advanced settings - set to 0 if you don't care.
|
160
|
+
// m_table_max_update_interval/m_table_update_interval_slow_rate override m_table_update_rate and allow finer control over the table update settings.
|
161
|
+
// If either are non-zero they will override whatever m_table_update_rate is set to. Just leave them 0 unless you are specifically customizing them for your data.
|
162
|
+
|
163
|
+
// def=0, typical range 12-128 (LZHAM_DEFAULT_TABLE_UPDATE_RATE=64), controls the max interval between table updates, higher=longer max interval (faster decode/lower ratio). Was 16 in prev. releases.
|
164
|
+
lzham_uint32 m_table_max_update_interval;
|
165
|
+
// def=0, 32 or higher (LZHAM_DEFAULT_TABLE_UPDATE_RATE=64), scaled by 32, controls the slowing of the update update freq, higher=more rapid slowing (faster decode/lower ratio). Was 40 in prev. releases.
|
166
|
+
lzham_uint32 m_table_update_interval_slow_rate;
|
167
|
+
|
168
|
+
} lzham_compress_params;
|
169
|
+
|
170
|
+
// Initializes a compressor. Returns a pointer to the compressor's internal state, or NULL on failure.
|
171
|
+
// pParams cannot be NULL. Be sure to initialize the pParams->m_struct_size member to sizeof(lzham_compress_params) (along with the other members to reasonable values) before calling this function.
|
172
|
+
// TODO: With large dictionaries this function could take a while (due to memory allocation). I need to add a reinit() API for compression (decompression already has one).
|
173
|
+
LZHAM_DLL_EXPORT lzham_compress_state_ptr LZHAM_CDECL lzham_compress_init(const lzham_compress_params *pParams);
|
174
|
+
|
175
|
+
LZHAM_DLL_EXPORT lzham_compress_state_ptr LZHAM_CDECL lzham_compress_reinit(lzham_compress_state_ptr pState);
|
176
|
+
|
177
|
+
// Deinitializes a compressor, releasing all allocated memory.
|
178
|
+
// returns adler32 of source data (valid only on success).
|
179
|
+
LZHAM_DLL_EXPORT lzham_uint32 LZHAM_CDECL lzham_compress_deinit(lzham_compress_state_ptr pState);
|
180
|
+
|
181
|
+
// Compresses an arbitrarily sized block of data, writing as much available compressed data as possible to the output buffer.
|
182
|
+
// This method may be called as many times as needed, but for best perf. try not to call it with tiny buffers.
|
183
|
+
// pState - Pointer to internal compression state, created by lzham_compress_init.
|
184
|
+
// pIn_buf, pIn_buf_size - Pointer to input data buffer, and pointer to a size_t containing the number of bytes available in this buffer.
|
185
|
+
// On return, *pIn_buf_size will be set to the number of bytes read from the buffer.
|
186
|
+
// pOut_buf, pOut_buf_size - Pointer to the output data buffer, and a pointer to a size_t containing the max number of bytes that can be written to this buffer.
|
187
|
+
// On return, *pOut_buf_size will be set to the number of bytes written to this buffer.
|
188
|
+
// no_more_input_bytes_flag - Set to true to indicate that no more input bytes are available to compress (EOF). Once you call this function with this param set to true, it must stay set to true in all future calls.
|
189
|
+
//
|
190
|
+
// Normal return status codes:
|
191
|
+
// LZHAM_COMP_STATUS_NOT_FINISHED - Compression can continue, but the compressor needs more input, or it needs more room in the output buffer.
|
192
|
+
// LZHAM_COMP_STATUS_NEEDS_MORE_INPUT - Compression can contintue, but the compressor has no more output, and has no input but we're not at EOF. Supply more input to continue.
|
193
|
+
// Success/failure return status codes:
|
194
|
+
// LZHAM_COMP_STATUS_SUCCESS - Compression has completed successfully.
|
195
|
+
// LZHAM_COMP_STATUS_FAILED, LZHAM_COMP_STATUS_FAILED_INITIALIZING, LZHAM_COMP_STATUS_INVALID_PARAMETER - Something went wrong.
|
196
|
+
LZHAM_DLL_EXPORT lzham_compress_status_t LZHAM_CDECL lzham_compress(
|
197
|
+
lzham_compress_state_ptr pState,
|
198
|
+
const lzham_uint8 *pIn_buf, size_t *pIn_buf_size,
|
199
|
+
lzham_uint8 *pOut_buf, size_t *pOut_buf_size,
|
200
|
+
lzham_bool no_more_input_bytes_flag);
|
201
|
+
|
202
|
+
LZHAM_DLL_EXPORT lzham_compress_status_t LZHAM_CDECL lzham_compress2(
|
203
|
+
lzham_compress_state_ptr pState,
|
204
|
+
const lzham_uint8 *pIn_buf, size_t *pIn_buf_size,
|
205
|
+
lzham_uint8 *pOut_buf, size_t *pOut_buf_size,
|
206
|
+
lzham_flush_t flush_type);
|
207
|
+
|
208
|
+
// Single function call compression interface.
|
209
|
+
// Same return codes as lzham_compress, except this function can also return LZHAM_COMP_STATUS_OUTPUT_BUF_TOO_SMALL.
|
210
|
+
LZHAM_DLL_EXPORT lzham_compress_status_t LZHAM_CDECL lzham_compress_memory(
|
211
|
+
const lzham_compress_params *pParams,
|
212
|
+
lzham_uint8* pDst_buf,
|
213
|
+
size_t *pDst_len,
|
214
|
+
const lzham_uint8* pSrc_buf,
|
215
|
+
size_t src_len,
|
216
|
+
lzham_uint32 *pAdler32);
|
217
|
+
|
218
|
+
// Decompression
|
219
|
+
typedef enum
|
220
|
+
{
|
221
|
+
// LZHAM_DECOMP_STATUS_NOT_FINISHED indicates that the decompressor is flushing its internal buffer to the caller's output buffer.
|
222
|
+
// There may be more bytes available to decompress on the next call, but there is no guarantee.
|
223
|
+
LZHAM_DECOMP_STATUS_NOT_FINISHED = 0,
|
224
|
+
|
225
|
+
// LZHAM_DECOMP_STATUS_HAS_MORE_OUTPUT indicates that the decompressor is trying to flush its internal buffer to the caller's output buffer,
|
226
|
+
// but the caller hasn't provided any space to copy this data to the caller's output buffer. Call the lzham_decompress() again with a non-empty sized output buffer.
|
227
|
+
LZHAM_DECOMP_STATUS_HAS_MORE_OUTPUT,
|
228
|
+
|
229
|
+
// LZHAM_DECOMP_STATUS_NEEDS_MORE_INPUT indicates that the decompressor has consumed all input bytes, has not encountered an "end of stream" code,
|
230
|
+
// and the caller hasn't set no_more_input_bytes_flag to true, so it's expecting more input to proceed.
|
231
|
+
LZHAM_DECOMP_STATUS_NEEDS_MORE_INPUT,
|
232
|
+
|
233
|
+
// All the following enums always (and MUST) indicate failure/success.
|
234
|
+
LZHAM_DECOMP_STATUS_FIRST_SUCCESS_OR_FAILURE_CODE,
|
235
|
+
|
236
|
+
// LZHAM_DECOMP_STATUS_SUCCESS indicates decompression has successfully completed.
|
237
|
+
LZHAM_DECOMP_STATUS_SUCCESS = LZHAM_DECOMP_STATUS_FIRST_SUCCESS_OR_FAILURE_CODE,
|
238
|
+
|
239
|
+
// The remaining status codes indicate a failure of some sort. Most failures are unrecoverable. TODO: Document which codes are recoverable.
|
240
|
+
LZHAM_DECOMP_STATUS_FIRST_FAILURE_CODE,
|
241
|
+
|
242
|
+
LZHAM_DECOMP_STATUS_FAILED_INITIALIZING = LZHAM_DECOMP_STATUS_FIRST_FAILURE_CODE,
|
243
|
+
LZHAM_DECOMP_STATUS_FAILED_DEST_BUF_TOO_SMALL,
|
244
|
+
LZHAM_DECOMP_STATUS_FAILED_EXPECTED_MORE_RAW_BYTES,
|
245
|
+
LZHAM_DECOMP_STATUS_FAILED_BAD_CODE,
|
246
|
+
LZHAM_DECOMP_STATUS_FAILED_ADLER32,
|
247
|
+
LZHAM_DECOMP_STATUS_FAILED_BAD_RAW_BLOCK,
|
248
|
+
LZHAM_DECOMP_STATUS_FAILED_BAD_COMP_BLOCK_SYNC_CHECK,
|
249
|
+
LZHAM_DECOMP_STATUS_FAILED_BAD_ZLIB_HEADER,
|
250
|
+
LZHAM_DECOMP_STATUS_FAILED_NEED_SEED_BYTES,
|
251
|
+
LZHAM_DECOMP_STATUS_FAILED_BAD_SEED_BYTES,
|
252
|
+
LZHAM_DECOMP_STATUS_FAILED_BAD_SYNC_BLOCK,
|
253
|
+
LZHAM_DECOMP_STATUS_INVALID_PARAMETER,
|
254
|
+
} lzham_decompress_status_t;
|
255
|
+
|
256
|
+
typedef void *lzham_decompress_state_ptr;
|
257
|
+
|
258
|
+
typedef enum
|
259
|
+
{
|
260
|
+
LZHAM_DECOMP_FLAG_OUTPUT_UNBUFFERED = 1,
|
261
|
+
LZHAM_DECOMP_FLAG_COMPUTE_ADLER32 = 2,
|
262
|
+
LZHAM_DECOMP_FLAG_READ_ZLIB_STREAM = 4,
|
263
|
+
} lzham_decompress_flags;
|
264
|
+
|
265
|
+
// Decompression parameters structure.
|
266
|
+
// Notes:
|
267
|
+
// m_dict_size_log2 MUST match the value used during compression!
|
268
|
+
// If m_num_seed_bytes != 0, LZHAM_DECOMP_FLAG_OUTPUT_UNBUFFERED must not be set (i.e. static "seed" dictionaries are not compatible with unbuffered decompression).
|
269
|
+
// The seed buffer's contents and size must match the seed buffer used during compression.
|
270
|
+
// m_table_update_rate (or m_table_max_update_interval/m_table_update_interval_slow_rate) MUST match the values used for compression!
|
271
|
+
typedef struct
|
272
|
+
{
|
273
|
+
lzham_uint32 m_struct_size; // set to sizeof(lzham_decompress_params)
|
274
|
+
lzham_uint32 m_dict_size_log2; // set to the log2(dictionary_size), must range between [LZHAM_MIN_DICT_SIZE_LOG2, LZHAM_MAX_DICT_SIZE_LOG2_X86] for x86 LZHAM_MAX_DICT_SIZE_LOG2_X64 for x64
|
275
|
+
lzham_uint32 m_table_update_rate; // Controls tradeoff between ratio and decompression throughput. 0=default, or [1,LZHAM_MAX_TABLE_UPDATE_RATE], higher=faster but lower ratio.
|
276
|
+
lzham_uint32 m_decompress_flags; // optional decompression flags (see lzham_decompress_flags enum)
|
277
|
+
lzham_uint32 m_num_seed_bytes; // for delta compression (optional) - number of seed bytes pointed to by m_pSeed_bytes
|
278
|
+
const void *m_pSeed_bytes; // for delta compression (optional) - pointer to seed bytes buffer, must be at least m_num_seed_bytes long
|
279
|
+
|
280
|
+
// Advanced settings - set to 0 if you don't care.
|
281
|
+
// m_table_max_update_interval/m_table_update_interval_slow_rate override m_table_update_rate and allow finer control over the table update settings.
|
282
|
+
// If either are non-zero they will override whatever m_table_update_rate is set to. Just leave them 0 unless you are specifically customizing them for your data.
|
283
|
+
|
284
|
+
// def=0, typical range 12-128 (LZHAM_DEFAULT_TABLE_UPDATE_RATE=64), controls the max interval between table updates, higher=longer max interval (faster decode/lower ratio). Was 16 in prev. releases.
|
285
|
+
lzham_uint32 m_table_max_update_interval;
|
286
|
+
// def=0, 32 or higher (LZHAM_DEFAULT_TABLE_UPDATE_RATE=64), scaled by 32, controls the slowing of the update update freq, higher=more rapid slowing (faster decode/lower ratio). Was 40 in prev. releases.
|
287
|
+
lzham_uint32 m_table_update_interval_slow_rate;
|
288
|
+
|
289
|
+
} lzham_decompress_params;
|
290
|
+
|
291
|
+
// Initializes a decompressor.
|
292
|
+
// pParams cannot be NULL. Be sure to initialize the pParams->m_struct_size member to sizeof(lzham_decompress_params) (along with the other members to reasonable values) before calling this function.
|
293
|
+
// Note: With large dictionaries this function could take a while (due to memory allocation). To serially decompress multiple streams, it's faster to init a compressor once and
|
294
|
+
// reuse it using by calling lzham_decompress_reinit().
|
295
|
+
LZHAM_DLL_EXPORT lzham_decompress_state_ptr LZHAM_CDECL lzham_decompress_init(const lzham_decompress_params *pParams);
|
296
|
+
|
297
|
+
// Quickly re-initializes the decompressor to its initial state given an already allocated/initialized state (doesn't do any memory alloc unless necessary).
|
298
|
+
LZHAM_DLL_EXPORT lzham_decompress_state_ptr LZHAM_CDECL lzham_decompress_reinit(lzham_decompress_state_ptr pState, const lzham_decompress_params *pParams);
|
299
|
+
|
300
|
+
// Deinitializes a decompressor.
|
301
|
+
// returns adler32 of decompressed data if compute_adler32 was true, otherwise it returns the adler32 from the compressed stream.
|
302
|
+
LZHAM_DLL_EXPORT lzham_uint32 LZHAM_CDECL lzham_decompress_deinit(lzham_decompress_state_ptr pState);
|
303
|
+
|
304
|
+
// Decompresses an arbitrarily sized block of compressed data, writing as much available decompressed data as possible to the output buffer.
|
305
|
+
// This method is implemented as a coroutine so it may be called as many times as needed. However, for best perf. try not to call it with tiny buffers.
|
306
|
+
// pState - Pointer to internal decompression state, originally created by lzham_decompress_init.
|
307
|
+
// pIn_buf, pIn_buf_size - Pointer to input data buffer, and pointer to a size_t containing the number of bytes available in this buffer.
|
308
|
+
// On return, *pIn_buf_size will be set to the number of bytes read from the buffer.
|
309
|
+
// pOut_buf, pOut_buf_size - Pointer to the output data buffer, and a pointer to a size_t containing the max number of bytes that can be written to this buffer.
|
310
|
+
// On return, *pOut_buf_size will be set to the number of bytes written to this buffer.
|
311
|
+
// no_more_input_bytes_flag - Set to true to indicate that no more input bytes are available to compress (EOF). Once you call this function with this param set to true, it must stay set to true in all future calls.
|
312
|
+
// Notes:
|
313
|
+
// In unbuffered mode, the output buffer MUST be large enough to hold the entire decompressed stream. Otherwise, you'll receive the
|
314
|
+
// LZHAM_DECOMP_STATUS_FAILED_DEST_BUF_TOO_SMALL error (which is currently unrecoverable during unbuffered decompression).
|
315
|
+
// In buffered mode, if the output buffer's size is 0 bytes, the caller is indicating that no more output bytes are expected from the
|
316
|
+
// decompressor. In this case, if the decompressor actually has more bytes you'll receive the LZHAM_DECOMP_STATUS_HAS_MORE_OUTPUT
|
317
|
+
// error (which is recoverable in the buffered case - just call lzham_decompress() again with a non-zero size output buffer).
|
318
|
+
LZHAM_DLL_EXPORT lzham_decompress_status_t LZHAM_CDECL lzham_decompress(
|
319
|
+
lzham_decompress_state_ptr pState,
|
320
|
+
const lzham_uint8 *pIn_buf, size_t *pIn_buf_size,
|
321
|
+
lzham_uint8 *pOut_buf, size_t *pOut_buf_size,
|
322
|
+
lzham_bool no_more_input_bytes_flag);
|
323
|
+
|
324
|
+
// Single function call interface.
|
325
|
+
LZHAM_DLL_EXPORT lzham_decompress_status_t LZHAM_CDECL lzham_decompress_memory(
|
326
|
+
const lzham_decompress_params *pParams,
|
327
|
+
lzham_uint8* pDst_buf,
|
328
|
+
size_t *pDst_len,
|
329
|
+
const lzham_uint8* pSrc_buf,
|
330
|
+
size_t src_len,
|
331
|
+
lzham_uint32 *pAdler32);
|
332
|
+
|
333
|
+
// ------------------- zlib-style API Definitions.
|
334
|
+
|
335
|
+
// Important note: LZHAM doesn't internally support the Deflate algorithm, but for API compatibility the "Deflate" and "Inflate" names are retained here.
|
336
|
+
|
337
|
+
typedef unsigned long lzham_z_ulong;
|
338
|
+
|
339
|
+
// Heap allocation callbacks.
|
340
|
+
// Note that lzham_alloc_func parameter types purposely differ from zlib's: items/size is size_t, not unsigned long.
|
341
|
+
typedef void *(*lzham_z_alloc_func)(void *opaque, size_t items, size_t size);
|
342
|
+
typedef void (*lzham_z_free_func)(void *opaque, void *address);
|
343
|
+
typedef void *(*lzham_z_realloc_func)(void *opaque, void *address, size_t items, size_t size);
|
344
|
+
|
345
|
+
#define LZHAM_Z_ADLER32_INIT (1)
|
346
|
+
// lzham_adler32() returns the initial adler-32 value to use when called with ptr==NULL.
|
347
|
+
LZHAM_DLL_EXPORT lzham_z_ulong lzham_z_adler32(lzham_z_ulong adler, const unsigned char *ptr, size_t buf_len);
|
348
|
+
|
349
|
+
#define LZHAM_Z_CRC32_INIT (0)
|
350
|
+
// lzham_crc32() returns the initial CRC-32 value to use when called with ptr==NULL.
|
351
|
+
LZHAM_DLL_EXPORT lzham_z_ulong lzham_z_crc32(lzham_z_ulong crc, const unsigned char *ptr, size_t buf_len);
|
352
|
+
|
353
|
+
// Compression strategies.
|
354
|
+
enum
|
355
|
+
{
|
356
|
+
LZHAM_Z_DEFAULT_STRATEGY = 0,
|
357
|
+
LZHAM_Z_FILTERED = 1,
|
358
|
+
LZHAM_Z_HUFFMAN_ONLY = 2,
|
359
|
+
LZHAM_Z_RLE = 3,
|
360
|
+
LZHAM_Z_FIXED = 4
|
361
|
+
};
|
362
|
+
|
363
|
+
// Method
|
364
|
+
#define LZHAM_Z_DEFLATED 8
|
365
|
+
#define LZHAM_Z_LZHAM 14
|
366
|
+
|
367
|
+
#define LZHAM_Z_VERSION "10.8.1"
|
368
|
+
#define LZHAM_Z_VERNUM 0xA810
|
369
|
+
#define LZHAM_Z_VER_MAJOR 10
|
370
|
+
#define LZHAM_Z_VER_MINOR 8
|
371
|
+
#define LZHAM_Z_VER_REVISION 1
|
372
|
+
#define LZHAM_Z_VER_SUBREVISION 0
|
373
|
+
|
374
|
+
// Flush values.
|
375
|
+
// For compression, you typically only need to use LZHAM_NO_FLUSH and LZHAM_FINISH.
|
376
|
+
// LZHAM_Z_SYNC_FLUSH and LZHAM_Z_FULL_FLUSH during compression forces compression of all buffered input.
|
377
|
+
//
|
378
|
+
// For decompression, you typically only need to use LZHAM_Z_SYNC_FLUSH or LZHAM_Z_FINISH.
|
379
|
+
// LZHAM_Z_FINISH during decompression guarantees that the output buffer is large enough to hold all remaining data to decompress.
|
380
|
+
// See http://www.bolet.org/~pornin/deflate-flush.html
|
381
|
+
// Must directly map to lzham_flush_t
|
382
|
+
enum
|
383
|
+
{
|
384
|
+
LZHAM_Z_NO_FLUSH = 0, // compression/decompression
|
385
|
+
LZHAM_Z_PARTIAL_FLUSH = 1, // compression/decompression, same as LZHAM_Z_SYNC_FLUSH
|
386
|
+
LZHAM_Z_SYNC_FLUSH = 2, // compression/decompression, when compressing: flush current block (if any), always outputs sync block (aligns output to byte boundary, a 0xFFFF0000 marker will appear in the output stream)
|
387
|
+
LZHAM_Z_FULL_FLUSH = 3, // compression/decompression, when compressing: same as LZHAM_Z_SYNC_FLUSH but also forces a full state flush (LZ dictionary, all symbol statistics)
|
388
|
+
LZHAM_Z_FINISH = 4, // compression/decompression
|
389
|
+
LZHAM_Z_BLOCK = 5, // not supported
|
390
|
+
LZHAM_Z_TABLE_FLUSH = 10 // compression only, resets all symbol table update rates to maximum frequency (LZHAM extension)
|
391
|
+
};
|
392
|
+
|
393
|
+
// Return status codes. LZHAM_Z_PARAM_ERROR is non-standard.
|
394
|
+
enum
|
395
|
+
{
|
396
|
+
LZHAM_Z_OK = 0,
|
397
|
+
LZHAM_Z_STREAM_END = 1,
|
398
|
+
LZHAM_Z_NEED_DICT = 2,
|
399
|
+
LZHAM_Z_ERRNO = -1,
|
400
|
+
LZHAM_Z_STREAM_ERROR = -2,
|
401
|
+
LZHAM_Z_DATA_ERROR = -3,
|
402
|
+
LZHAM_Z_MEM_ERROR = -4,
|
403
|
+
LZHAM_Z_BUF_ERROR = -5,
|
404
|
+
LZHAM_Z_VERSION_ERROR = -6,
|
405
|
+
LZHAM_Z_PARAM_ERROR = -10000
|
406
|
+
};
|
407
|
+
|
408
|
+
// Compression levels.
|
409
|
+
enum
|
410
|
+
{
|
411
|
+
LZHAM_Z_NO_COMPRESSION = 0,
|
412
|
+
LZHAM_Z_BEST_SPEED = 1,
|
413
|
+
LZHAM_Z_BEST_COMPRESSION = 9,
|
414
|
+
LZHAM_Z_UBER_COMPRESSION = 10, // uber = best with extreme parsing (can be very slow)
|
415
|
+
LZHAM_Z_DEFAULT_COMPRESSION = -1
|
416
|
+
};
|
417
|
+
|
418
|
+
// Window bits
|
419
|
+
// Important note: The zlib-style API's default to 32KB dictionary for API compatibility. For improved compression, be sure to call deflateInit2/inflateInit2 and specify larger custom window_bits values!
|
420
|
+
// If changing the calling code isn't practical, unremark LZHAM_Z_API_FORCE_WINDOW_BITS.
|
421
|
+
#define LZHAM_Z_DEFAULT_WINDOW_BITS 15
|
422
|
+
|
423
|
+
// Define LZHAM_Z_API_FORCE_WINDOW_BITS to force the entire library to use a constant value for window_bits (helps with porting) in all zlib API's.
|
424
|
+
// TODO: Might be useful to provide an API to control this at runtime.
|
425
|
+
//#define LZHAM_Z_API_FORCE_WINDOW_BITS 23
|
426
|
+
|
427
|
+
// Data types
|
428
|
+
#define LZHAM_Z_BINARY 0
|
429
|
+
#define LZHAM_Z_TEXT 1
|
430
|
+
#define LZHAM_Z_ASCII 1
|
431
|
+
#define LZHAM_Z_UNKNOWN 2
|
432
|
+
|
433
|
+
struct lzham_z_internal_state;
|
434
|
+
|
435
|
+
// Compression/decompression stream struct.
|
436
|
+
typedef struct
|
437
|
+
{
|
438
|
+
const unsigned char *next_in; // pointer to next byte to read
|
439
|
+
unsigned int avail_in; // number of bytes available at next_in
|
440
|
+
lzham_z_ulong total_in; // total number of bytes consumed so far
|
441
|
+
|
442
|
+
unsigned char *next_out; // pointer to next byte to write
|
443
|
+
unsigned int avail_out; // number of bytes that can be written to next_out
|
444
|
+
lzham_z_ulong total_out; // total number of bytes produced so far
|
445
|
+
|
446
|
+
char *msg; // error msg (unused)
|
447
|
+
struct lzham_z_internal_state *state; // internal state, allocated by zalloc/zfree
|
448
|
+
|
449
|
+
// LZHAM does not support per-stream heap callbacks. Use lzham_set_memory_callbacks() instead.
|
450
|
+
// These members are ignored - they are here for backwards compatibility with zlib.
|
451
|
+
lzham_z_alloc_func zalloc; // optional heap allocation function (defaults to malloc)
|
452
|
+
lzham_z_free_func zfree; // optional heap free function (defaults to free)
|
453
|
+
void *opaque; // heap alloc function user pointer
|
454
|
+
|
455
|
+
int data_type; // data_type (unused)
|
456
|
+
lzham_z_ulong adler; // adler32 of the source or uncompressed data
|
457
|
+
lzham_z_ulong reserved; // not used
|
458
|
+
} lzham_z_stream;
|
459
|
+
|
460
|
+
typedef lzham_z_stream *lzham_z_streamp;
|
461
|
+
|
462
|
+
LZHAM_DLL_EXPORT const char *lzham_z_version(void);
|
463
|
+
|
464
|
+
// lzham_deflateInit() initializes a compressor with default options:
|
465
|
+
// Parameters:
|
466
|
+
// pStream must point to an initialized lzham_stream struct.
|
467
|
+
// level must be between [LZHAM_NO_COMPRESSION, LZHAM_BEST_COMPRESSION].
|
468
|
+
// level 1 enables a specially optimized compression function that's been optimized purely for performance, not ratio.
|
469
|
+
// Return values:
|
470
|
+
// LZHAM_OK on success.
|
471
|
+
// LZHAM_STREAM_ERROR if the stream is bogus.
|
472
|
+
// LZHAM_PARAM_ERROR if the input parameters are bogus.
|
473
|
+
// LZHAM_MEM_ERROR on out of memory.
|
474
|
+
LZHAM_DLL_EXPORT int lzham_z_deflateInit(lzham_z_streamp pStream, int level);
|
475
|
+
|
476
|
+
// lzham_deflateInit2() is like lzham_deflate(), except with more control:
|
477
|
+
// Additional parameters:
|
478
|
+
// method must be LZHAM_Z_DEFLATED or LZHAM_Z_LZHAM (LZHAM_Z_DEFLATED will be internally converted to LZHAM_Z_LZHAM with a windowsize of LZHAM_Z_DEFAULT_WINDOW_BITS)
|
479
|
+
// window_bits must be LZHAM_DEFAULT_WINDOW_BITS (to wrap the deflate stream with zlib header/adler-32 footer) or -LZHAM_Z_DEFAULT_WINDOW_BITS (raw deflate/no header or footer)
|
480
|
+
// mem_level must be between [1, 9] (it's checked but ignored by lzham)
|
481
|
+
LZHAM_DLL_EXPORT int lzham_z_deflateInit2(lzham_z_streamp pStream, int level, int method, int window_bits, int mem_level, int strategy);
|
482
|
+
|
483
|
+
// Quickly resets a compressor without having to reallocate anything. Same as calling lzham_z_deflateEnd() followed by lzham_z_deflateInit()/lzham_z_deflateInit2().
|
484
|
+
LZHAM_DLL_EXPORT int lzham_z_deflateReset(lzham_z_streamp pStream);
|
485
|
+
|
486
|
+
// lzham_deflate() compresses the input to output, consuming as much of the input and producing as much output as possible.
|
487
|
+
// Parameters:
|
488
|
+
// pStream is the stream to read from and write to. You must initialize/update the next_in, avail_in, next_out, and avail_out members.
|
489
|
+
// flush may be LZHAM_Z_NO_FLUSH, LZHAM_Z_PARTIAL_FLUSH/LZHAM_Z_SYNC_FLUSH, LZHAM_Z_FULL_FLUSH, or LZHAM_Z_FINISH.
|
490
|
+
// Return values:
|
491
|
+
// LZHAM_Z_OK on success (when flushing, or if more input is needed but not available, and/or there's more output to be written but the output buffer is full).
|
492
|
+
// LZHAM_Z_STREAM_END if all input has been consumed and all output bytes have been written. Don't call lzham_z_deflate() on the stream anymore.
|
493
|
+
// LZHAM_Z_STREAM_ERROR if the stream is bogus.
|
494
|
+
// LZHAM_Z_PARAM_ERROR if one of the parameters is invalid.
|
495
|
+
// LZHAM_Z_BUF_ERROR if no forward progress is possible because the input and/or output buffers are empty. (Fill up the input buffer or free up some output space and try again.)
|
496
|
+
LZHAM_DLL_EXPORT int lzham_z_deflate(lzham_z_streamp pStream, int flush);
|
497
|
+
|
498
|
+
// lzham_deflateEnd() deinitializes a compressor:
|
499
|
+
// Return values:
|
500
|
+
// LZHAM_Z_OK on success.
|
501
|
+
// LZHAM_Z_STREAM_ERROR if the stream is bogus.
|
502
|
+
LZHAM_DLL_EXPORT int lzham_z_deflateEnd(lzham_z_streamp pStream);
|
503
|
+
|
504
|
+
// lzham_deflateBound() returns a (very) conservative upper bound on the amount of data that could be generated by lzham_z_deflate(), assuming flush is set to only LZHAM_Z_NO_FLUSH or LZHAM_Z_FINISH.
|
505
|
+
LZHAM_DLL_EXPORT lzham_z_ulong lzham_z_deflateBound(lzham_z_streamp pStream, lzham_z_ulong source_len);
|
506
|
+
|
507
|
+
// Single-call compression functions lzham_z_compress() and lzham_z_compress2():
|
508
|
+
// Returns LZHAM_Z_OK on success, or one of the error codes from lzham_z_deflate() on failure.
|
509
|
+
LZHAM_DLL_EXPORT int lzham_z_compress(unsigned char *pDest, lzham_z_ulong *pDest_len, const unsigned char *pSource, lzham_z_ulong source_len);
|
510
|
+
LZHAM_DLL_EXPORT int lzham_z_compress2(unsigned char *pDest, lzham_z_ulong *pDest_len, const unsigned char *pSource, lzham_z_ulong source_len, int level);
|
511
|
+
|
512
|
+
// lzham_z_compressBound() returns a (very) conservative upper bound on the amount of data that could be generated by calling lzham_z_compress().
|
513
|
+
LZHAM_DLL_EXPORT lzham_z_ulong lzham_z_compressBound(lzham_z_ulong source_len);
|
514
|
+
|
515
|
+
// Initializes a decompressor.
|
516
|
+
LZHAM_DLL_EXPORT int lzham_z_inflateInit(lzham_z_streamp pStream);
|
517
|
+
|
518
|
+
// lzham_z_inflateInit2() is like lzham_z_inflateInit() with an additional option that controls the window size and whether or not the stream has been wrapped with a zlib header/footer:
|
519
|
+
// window_bits must be LZHAM_Z_DEFAULT_WINDOW_BITS (to parse zlib header/footer) or -LZHAM_Z_DEFAULT_WINDOW_BITS (raw stream with no zlib header/footer).
|
520
|
+
LZHAM_DLL_EXPORT int lzham_z_inflateInit2(lzham_z_streamp pStream, int window_bits);
|
521
|
+
|
522
|
+
LZHAM_DLL_EXPORT int lzham_z_inflateReset(lzham_z_streamp pStream);
|
523
|
+
|
524
|
+
// Decompresses the input stream to the output, consuming only as much of the input as needed, and writing as much to the output as possible.
|
525
|
+
// Parameters:
|
526
|
+
// pStream is the stream to read from and write to. You must initialize/update the next_in, avail_in, next_out, and avail_out members.
|
527
|
+
// flush may be LZHAM_Z_NO_FLUSH, LZHAM_Z_SYNC_FLUSH, or LZHAM_Z_FINISH.
|
528
|
+
// On the first call, if flush is LZHAM_Z_FINISH it's assumed the input and output buffers are both sized large enough to decompress the entire stream in a single call (this is slightly faster).
|
529
|
+
// LZHAM_Z_FINISH implies that there are no more source bytes available beside what's already in the input buffer, and that the output buffer is large enough to hold the rest of the decompressed data.
|
530
|
+
// Return values:
|
531
|
+
// LZHAM_Z_OK on success. Either more input is needed but not available, and/or there's more output to be written but the output buffer is full.
|
532
|
+
// LZHAM_Z_STREAM_END if all needed input has been consumed and all output bytes have been written. For zlib streams, the adler-32 of the decompressed data has also been verified.
|
533
|
+
// LZHAM_Z_STREAM_ERROR if the stream is bogus.
|
534
|
+
// LZHAM_Z_DATA_ERROR if the deflate stream is invalid.
|
535
|
+
// LZHAM_Z_PARAM_ERROR if one of the parameters is invalid.
|
536
|
+
// LZHAM_Z_BUF_ERROR if no forward progress is possible because the input buffer is empty but the inflater needs more input to continue, or if the output buffer is not large enough. Call lzham_inflate() again
|
537
|
+
// with more input data, or with more room in the output buffer (except when using single call decompression, described above).
|
538
|
+
LZHAM_DLL_EXPORT int lzham_z_inflate(lzham_z_streamp pStream, int flush);
|
539
|
+
|
540
|
+
// Deinitializes a decompressor.
|
541
|
+
LZHAM_DLL_EXPORT int lzham_z_inflateEnd(lzham_z_streamp pStream);
|
542
|
+
|
543
|
+
// Single-call decompression.
|
544
|
+
// Returns LZHAM_OK on success, or one of the error codes from lzham_inflate() on failure.
|
545
|
+
LZHAM_DLL_EXPORT int lzham_z_uncompress(unsigned char *pDest, lzham_z_ulong *pDest_len, const unsigned char *pSource, lzham_z_ulong source_len);
|
546
|
+
|
547
|
+
// Returns a string description of the specified error code, or NULL if the error code is invalid.
|
548
|
+
LZHAM_DLL_EXPORT const char *lzham_z_error(int err);
|
549
|
+
|
550
|
+
// Redefine zlib-compatible names to lzham equivalents, so lzham can be used as a more or less drop-in replacement for the subset of zlib that lzham supports.
|
551
|
+
// Define LZHAM_NO_ZLIB_COMPATIBLE_NAMES to disable zlib-compatibility if you use zlib in the same project.
|
552
|
+
#ifdef LZHAM_DEFINE_ZLIB_API
|
553
|
+
typedef unsigned char Byte;
|
554
|
+
typedef unsigned int uInt;
|
555
|
+
typedef lzham_z_ulong uLong;
|
556
|
+
typedef Byte Bytef;
|
557
|
+
typedef uInt uIntf;
|
558
|
+
typedef char charf;
|
559
|
+
typedef int intf;
|
560
|
+
typedef void *voidpf;
|
561
|
+
typedef uLong uLongf;
|
562
|
+
typedef void *voidp;
|
563
|
+
typedef void *const voidpc;
|
564
|
+
#define Z_NULL 0
|
565
|
+
#define Z_NO_FLUSH LZHAM_Z_NO_FLUSH
|
566
|
+
#define Z_PARTIAL_FLUSH LZHAM_Z_PARTIAL_FLUSH
|
567
|
+
#define Z_SYNC_FLUSH LZHAM_Z_SYNC_FLUSH
|
568
|
+
#define Z_FULL_FLUSH LZHAM_Z_FULL_FLUSH
|
569
|
+
#define Z_FINISH LZHAM_Z_FINISH
|
570
|
+
#define Z_BLOCK LZHAM_Z_BLOCK
|
571
|
+
#define Z_OK LZHAM_Z_OK
|
572
|
+
#define Z_STREAM_END LZHAM_Z_STREAM_END
|
573
|
+
#define Z_NEED_DICT LZHAM_Z_NEED_DICT
|
574
|
+
#define Z_ERRNO LZHAM_Z_ERRNO
|
575
|
+
#define Z_STREAM_ERROR LZHAM_Z_STREAM_ERROR
|
576
|
+
#define Z_DATA_ERROR LZHAM_Z_DATA_ERROR
|
577
|
+
#define Z_MEM_ERROR LZHAM_Z_MEM_ERROR
|
578
|
+
#define Z_BUF_ERROR LZHAM_Z_BUF_ERROR
|
579
|
+
#define Z_VERSION_ERROR LZHAM_Z_VERSION_ERROR
|
580
|
+
#define Z_PARAM_ERROR LZHAM_Z_PARAM_ERROR
|
581
|
+
#define Z_NO_COMPRESSION LZHAM_Z_NO_COMPRESSION
|
582
|
+
#define Z_BEST_SPEED LZHAM_Z_BEST_SPEED
|
583
|
+
#define Z_BEST_COMPRESSION LZHAM_Z_BEST_COMPRESSION
|
584
|
+
#define Z_DEFAULT_COMPRESSION LZHAM_Z_DEFAULT_COMPRESSION
|
585
|
+
#define Z_DEFAULT_STRATEGY LZHAM_Z_DEFAULT_STRATEGY
|
586
|
+
#define Z_FILTERED LZHAM_Z_FILTERED
|
587
|
+
#define Z_HUFFMAN_ONLY LZHAM_Z_HUFFMAN_ONLY
|
588
|
+
#define Z_RLE LZHAM_Z_RLE
|
589
|
+
#define Z_FIXED LZHAM_Z_FIXED
|
590
|
+
#define Z_DEFLATED LZHAM_Z_DEFLATED
|
591
|
+
#define Z_DEFAULT_WINDOW_BITS LZHAM_Z_DEFAULT_WINDOW_BITS
|
592
|
+
#define alloc_func lzham_z_alloc_func
|
593
|
+
#define free_func lzham_z_free_func
|
594
|
+
#define internal_state lzham_z_internal_state
|
595
|
+
#define z_stream lzham_z_stream
|
596
|
+
#define deflateInit lzham_z_deflateInit
|
597
|
+
#define deflateInit2 lzham_z_deflateInit2
|
598
|
+
#define deflateReset lzham_z_deflateReset
|
599
|
+
#define deflate lzham_z_deflate
|
600
|
+
#define deflateEnd lzham_z_deflateEnd
|
601
|
+
#define deflateBound lzham_z_deflateBound
|
602
|
+
#define compress lzham_z_compress
|
603
|
+
#define compress2 lzham_z_compress2
|
604
|
+
#define compressBound lzham_z_compressBound
|
605
|
+
#define inflateInit lzham_z_inflateInit
|
606
|
+
#define inflateInit2 lzham_z_inflateInit2
|
607
|
+
#define inflateReset lzham_z_inflateReset
|
608
|
+
#define inflate lzham_z_inflate
|
609
|
+
#define inflateEnd lzham_z_inflateEnd
|
610
|
+
#define uncompress lzham_z_uncompress
|
611
|
+
#define crc32 lzham_z_crc32
|
612
|
+
#define adler32 lzham_z_adler32
|
613
|
+
#define MAX_WBITS 26
|
614
|
+
#define MAX_MEM_LEVEL 9
|
615
|
+
#define zError lzham_z_error
|
616
|
+
#define ZLIB_VERSION LZHAM_Z_VERSION
|
617
|
+
#define ZLIB_VERNUM LZHAM_Z_VERNUM
|
618
|
+
#define ZLIB_VER_MAJOR LZHAM_Z_VER_MAJOR
|
619
|
+
#define ZLIB_VER_MINOR LZHAM_Z_VER_MINOR
|
620
|
+
#define ZLIB_VER_REVISION LZHAM_Z_VER_REVISION
|
621
|
+
#define ZLIB_VER_SUBREVISION LZHAM_Z_VER_SUBREVISION
|
622
|
+
#define zlibVersion lzham_z_version
|
623
|
+
#define zlib_version lzham_z_version()
|
624
|
+
#define Z_BINARY LZHAM_Z_BINARY
|
625
|
+
#define Z_TEXT LZHAM_Z_TEST
|
626
|
+
#define Z_ASCII LZHAM_Z_ASCII
|
627
|
+
#define Z_UNKNOWN LZHAM_Z_UNKNOWN
|
628
|
+
#endif // #ifdef LZHAM_DEFINE_ZLIB_API
|
629
|
+
|
630
|
+
// Exported function typedefs, to simplify loading the LZHAM DLL dynamically.
|
631
|
+
typedef lzham_uint32 (LZHAM_CDECL *lzham_get_version_func)(void);
|
632
|
+
typedef void (LZHAM_CDECL *lzham_set_memory_callbacks_func)(lzham_realloc_func pRealloc, lzham_msize_func pMSize, void* pUser_data);
|
633
|
+
|
634
|
+
typedef lzham_compress_state_ptr (LZHAM_CDECL *lzham_compress_init_func)(const lzham_compress_params *pParams);
|
635
|
+
typedef lzham_compress_state_ptr (LZHAM_CDECL *lzham_compress_reinit_func)(lzham_compress_state_ptr pState);
|
636
|
+
typedef lzham_uint32 (LZHAM_CDECL *lzham_compress_deinit_func)(lzham_compress_state_ptr pState);
|
637
|
+
typedef lzham_compress_status_t (LZHAM_CDECL *lzham_compress_func)(lzham_compress_state_ptr pState, const lzham_uint8 *pIn_buf, size_t *pIn_buf_size, lzham_uint8 *pOut_buf, size_t *pOut_buf_size, lzham_bool no_more_input_bytes_flag);
|
638
|
+
typedef lzham_compress_status_t (LZHAM_CDECL *lzham_compress2_func)(lzham_compress_state_ptr pState, const lzham_uint8 *pIn_buf, size_t *pIn_buf_size, lzham_uint8 *pOut_buf, size_t *pOut_buf_size, lzham_flush_t flush_type);
|
639
|
+
typedef lzham_compress_status_t (LZHAM_CDECL *lzham_compress_memory_func)(const lzham_compress_params *pParams, lzham_uint8* pDst_buf, size_t *pDst_len, const lzham_uint8* pSrc_buf, size_t src_len, lzham_uint32 *pAdler32);
|
640
|
+
|
641
|
+
typedef lzham_decompress_state_ptr (LZHAM_CDECL *lzham_decompress_init_func)(const lzham_decompress_params *pParams);
|
642
|
+
typedef lzham_decompress_state_ptr (LZHAM_CDECL *lzham_decompress_reinit_func)(lzham_compress_state_ptr pState, const lzham_decompress_params *pParams);
|
643
|
+
typedef lzham_uint32 (LZHAM_CDECL *lzham_decompress_deinit_func)(lzham_decompress_state_ptr pState);
|
644
|
+
typedef lzham_decompress_status_t (LZHAM_CDECL *lzham_decompress_func)(lzham_decompress_state_ptr pState, const lzham_uint8 *pIn_buf, size_t *pIn_buf_size, lzham_uint8 *pOut_buf, size_t *pOut_buf_size, lzham_bool no_more_input_bytes_flag);
|
645
|
+
typedef lzham_decompress_status_t (LZHAM_CDECL *lzham_decompress_memory_func)(const lzham_decompress_params *pParams, lzham_uint8* pDst_buf, size_t *pDst_len, const lzham_uint8* pSrc_buf, size_t src_len, lzham_uint32 *pAdler32);
|
646
|
+
|
647
|
+
typedef const char *(LZHAM_CDECL *lzham_z_version_func)(void);
|
648
|
+
typedef int (LZHAM_CDECL *lzham_z_deflateInit_func)(lzham_z_streamp pStream, int level);
|
649
|
+
typedef int (LZHAM_CDECL *lzham_z_deflateInit2_func)(lzham_z_streamp pStream, int level, int method, int window_bits, int mem_level, int strategy);
|
650
|
+
typedef int (LZHAM_CDECL *lzham_z_deflateReset_func)(lzham_z_streamp pStream);
|
651
|
+
typedef int (LZHAM_CDECL *lzham_z_deflate_func)(lzham_z_streamp pStream, int flush);
|
652
|
+
typedef int (LZHAM_CDECL *lzham_z_deflateEnd_func)(lzham_z_streamp pStream);
|
653
|
+
typedef lzham_z_ulong (LZHAM_CDECL *lzham_z_deflateBound_func)(lzham_z_streamp pStream, lzham_z_ulong source_len);
|
654
|
+
typedef int (LZHAM_CDECL *lzham_z_compress_func)(unsigned char *pDest, lzham_z_ulong *pDest_len, const unsigned char *pSource, lzham_z_ulong source_len);
|
655
|
+
typedef int (LZHAM_CDECL *lzham_z_compress2_func)(unsigned char *pDest, lzham_z_ulong *pDest_len, const unsigned char *pSource, lzham_z_ulong source_len, int level);
|
656
|
+
typedef lzham_z_ulong (LZHAM_CDECL *lzham_z_compressBound_func)(lzham_z_ulong source_len);
|
657
|
+
typedef int (LZHAM_CDECL *lzham_z_inflateInit_func)(lzham_z_streamp pStream);
|
658
|
+
typedef int (LZHAM_CDECL *lzham_z_inflateInit2_func)(lzham_z_streamp pStream, int window_bits);
|
659
|
+
typedef int (LZHAM_CDECL *lzham_z_inflateReset_func)(lzham_z_streamp pStream);
|
660
|
+
typedef int (LZHAM_CDECL *lzham_z_inflate_func)(lzham_z_streamp pStream, int flush);
|
661
|
+
typedef int (LZHAM_CDECL *lzham_z_inflateEnd_func)(lzham_z_streamp pStream);
|
662
|
+
typedef int (LZHAM_CDECL *lzham_z_uncompress_func)(unsigned char *pDest, lzham_z_ulong *pDest_len, const unsigned char *pSource, lzham_z_ulong source_len);
|
663
|
+
typedef const char *(LZHAM_CDECL *lzham_z_error_func)(int err);
|
664
|
+
|
665
|
+
#ifdef __cplusplus
|
666
|
+
}
|
667
|
+
#endif
|
668
|
+
|
669
|
+
#ifdef __cplusplus
|
670
|
+
// This optional interface is used by the dynamic/static link helpers defined in lzham_dynamic_lib.h and lzham_static_lib.h.
|
671
|
+
// It allows code to always call LZHAM the same way, independent of how it was linked into the app (statically or dynamically).
|
672
|
+
class ilzham
|
673
|
+
{
|
674
|
+
ilzham(const ilzham &other);
|
675
|
+
ilzham& operator= (const ilzham &rhs);
|
676
|
+
|
677
|
+
public:
|
678
|
+
ilzham() { clear(); }
|
679
|
+
|
680
|
+
virtual ~ilzham() { }
|
681
|
+
virtual bool load() = 0;
|
682
|
+
virtual void unload() = 0;
|
683
|
+
virtual bool is_loaded() = 0;
|
684
|
+
|
685
|
+
void clear()
|
686
|
+
{
|
687
|
+
this->lzham_get_version = NULL;
|
688
|
+
this->lzham_set_memory_callbacks = NULL;
|
689
|
+
|
690
|
+
this->lzham_compress_init = NULL;
|
691
|
+
this->lzham_compress_reinit = NULL;
|
692
|
+
this->lzham_compress_deinit = NULL;
|
693
|
+
this->lzham_compress = NULL;
|
694
|
+
this->lzham_compress2 = NULL;
|
695
|
+
this->lzham_compress_memory = NULL;
|
696
|
+
|
697
|
+
this->lzham_decompress_init = NULL;
|
698
|
+
this->lzham_decompress_reinit = NULL;
|
699
|
+
this->lzham_decompress_deinit = NULL;
|
700
|
+
this->lzham_decompress = NULL;
|
701
|
+
this->lzham_decompress_memory = NULL;
|
702
|
+
|
703
|
+
this->lzham_z_version = NULL;
|
704
|
+
this->lzham_z_deflateInit = NULL;
|
705
|
+
this->lzham_z_deflateInit2 = NULL;
|
706
|
+
this->lzham_z_deflateReset = NULL;
|
707
|
+
this->lzham_z_deflate = NULL;
|
708
|
+
this->lzham_z_deflateEnd = NULL;
|
709
|
+
this->lzham_z_deflateBound = NULL;
|
710
|
+
this->lzham_z_compress = NULL;
|
711
|
+
this->lzham_z_compress2 = NULL;
|
712
|
+
this->lzham_z_compressBound = NULL;
|
713
|
+
this->lzham_z_inflateInit = NULL;
|
714
|
+
this->lzham_z_inflateInit2 = NULL;
|
715
|
+
this->lzham_z_inflate = NULL;
|
716
|
+
this->lzham_z_inflateEnd = NULL;
|
717
|
+
this->lzham_z_inflateReset = NULL;
|
718
|
+
this->lzham_z_uncompress = NULL;
|
719
|
+
this->lzham_z_error = NULL;
|
720
|
+
}
|
721
|
+
|
722
|
+
lzham_get_version_func lzham_get_version;
|
723
|
+
lzham_set_memory_callbacks_func lzham_set_memory_callbacks;
|
724
|
+
|
725
|
+
lzham_compress_init_func lzham_compress_init;
|
726
|
+
lzham_compress_reinit_func lzham_compress_reinit;
|
727
|
+
lzham_compress_deinit_func lzham_compress_deinit;
|
728
|
+
lzham_compress_func lzham_compress;
|
729
|
+
lzham_compress2_func lzham_compress2;
|
730
|
+
lzham_compress_memory_func lzham_compress_memory;
|
731
|
+
|
732
|
+
lzham_decompress_init_func lzham_decompress_init;
|
733
|
+
lzham_decompress_reinit_func lzham_decompress_reinit;
|
734
|
+
lzham_decompress_deinit_func lzham_decompress_deinit;
|
735
|
+
lzham_decompress_func lzham_decompress;
|
736
|
+
lzham_decompress_memory_func lzham_decompress_memory;
|
737
|
+
|
738
|
+
lzham_z_version_func lzham_z_version;
|
739
|
+
lzham_z_deflateInit_func lzham_z_deflateInit;
|
740
|
+
lzham_z_deflateInit2_func lzham_z_deflateInit2;
|
741
|
+
lzham_z_deflateReset_func lzham_z_deflateReset;
|
742
|
+
lzham_z_deflate_func lzham_z_deflate;
|
743
|
+
lzham_z_deflateEnd_func lzham_z_deflateEnd;
|
744
|
+
lzham_z_deflateBound_func lzham_z_deflateBound;
|
745
|
+
lzham_z_compress_func lzham_z_compress;
|
746
|
+
lzham_z_compress2_func lzham_z_compress2;
|
747
|
+
lzham_z_compressBound_func lzham_z_compressBound;
|
748
|
+
lzham_z_inflateInit_func lzham_z_inflateInit;
|
749
|
+
lzham_z_inflateInit2_func lzham_z_inflateInit2;
|
750
|
+
lzham_z_inflateReset_func lzham_z_inflateReset;
|
751
|
+
lzham_z_inflate_func lzham_z_inflate;
|
752
|
+
lzham_z_inflateEnd_func lzham_z_inflateEnd;
|
753
|
+
lzham_z_uncompress_func lzham_z_uncompress;
|
754
|
+
lzham_z_error_func lzham_z_error;
|
755
|
+
};
|
756
|
+
#endif // #ifdef __cplusplus
|
757
|
+
|
758
|
+
#endif // #ifndef __LZHAM_H__
|
759
|
+
|
760
|
+
// Copyright (c) 2009-2012 Richard Geldreich, Jr. <richgel99@gmail.com>
|
761
|
+
//
|
762
|
+
// LZHAM uses the MIT License:
|
763
|
+
//
|
764
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
765
|
+
// of this software and associated documentation files (the "Software"), to deal
|
766
|
+
// in the Software without restriction, including without limitation the rights
|
767
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
768
|
+
// copies of the Software, and to permit persons to whom the Software is
|
769
|
+
// furnished to do so, subject to the following conditions:
|
770
|
+
//
|
771
|
+
// The above copyright notice and this permission notice shall be included in
|
772
|
+
// all copies or substantial portions of the Software.
|
773
|
+
//
|
774
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
775
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
776
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
777
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
778
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
779
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
780
|
+
// THE SOFTWARE.
|
781
|
+
|