author | Ryan C. Gordon <icculus@icculus.org> |
Thu, 25 Feb 2016 01:16:42 -0500 | |
changeset 1371 | da48b9ff4c9b |
parent 1212 | e3cd2449fe8e |
child 1373 | 527ef3c6a2d6 |
permissions | -rw-r--r-- |
1207
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1 |
/* tinfl.c v1.11 - public domain inflate with zlib header parsing/adler32 checking (inflate-only subset of miniz.c) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
2 |
See "unlicense" statement at the end of this file. |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
3 |
Rich Geldreich <richgel99@gmail.com>, last updated May 20, 2011 |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
4 |
Implements RFC 1950: http://www.ietf.org/rfc/rfc1950.txt and RFC 1951: http://www.ietf.org/rfc/rfc1951.txt |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
5 |
|
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
6 |
The entire decompressor coroutine is implemented in tinfl_decompress(). The other functions are optional high-level helpers. |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
7 |
*/ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
8 |
#ifndef TINFL_HEADER_INCLUDED |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
9 |
#define TINFL_HEADER_INCLUDED |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
10 |
|
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
11 |
typedef PHYSFS_uint8 mz_uint8; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
12 |
typedef PHYSFS_sint16 mz_int16; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
13 |
typedef PHYSFS_uint16 mz_uint16; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
14 |
typedef PHYSFS_uint32 mz_uint32; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
15 |
typedef unsigned int mz_uint; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
16 |
typedef PHYSFS_uint64 mz_uint64; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
17 |
|
1212
e3cd2449fe8e
Replace C++/C99 single-line comments in miniz with C98 /* comments */ ...
Ryan C. Gordon <icculus@icculus.org>
parents:
1207
diff
changeset
|
18 |
/* For more compatibility with zlib, miniz.c uses unsigned long for some parameters/struct members. */ |
1207
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
19 |
typedef unsigned long mz_ulong; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
20 |
|
1212
e3cd2449fe8e
Replace C++/C99 single-line comments in miniz with C98 /* comments */ ...
Ryan C. Gordon <icculus@icculus.org>
parents:
1207
diff
changeset
|
21 |
/* Heap allocation callbacks. */ |
1207
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
22 |
typedef void *(*mz_alloc_func)(void *opaque, unsigned int items, unsigned int size); |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
23 |
typedef void (*mz_free_func)(void *opaque, void *address); |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
24 |
|
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
25 |
#if defined(_M_IX86) || defined(_M_X64) |
1212
e3cd2449fe8e
Replace C++/C99 single-line comments in miniz with C98 /* comments */ ...
Ryan C. Gordon <icculus@icculus.org>
parents:
1207
diff
changeset
|
26 |
/* Set MINIZ_USE_UNALIGNED_LOADS_AND_STORES to 1 if integer loads and stores to unaligned addresses are acceptable on the target platform (slightly faster). */ |
1207
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
27 |
#define MINIZ_USE_UNALIGNED_LOADS_AND_STORES 1 |
1212
e3cd2449fe8e
Replace C++/C99 single-line comments in miniz with C98 /* comments */ ...
Ryan C. Gordon <icculus@icculus.org>
parents:
1207
diff
changeset
|
28 |
/* Set MINIZ_LITTLE_ENDIAN to 1 if the processor is little endian. */ |
1207
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
29 |
#define MINIZ_LITTLE_ENDIAN 1 |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
30 |
#endif |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
31 |
|
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
32 |
#if defined(_WIN64) || defined(__MINGW64__) || defined(_LP64) || defined(__LP64__) |
1212
e3cd2449fe8e
Replace C++/C99 single-line comments in miniz with C98 /* comments */ ...
Ryan C. Gordon <icculus@icculus.org>
parents:
1207
diff
changeset
|
33 |
/* Set MINIZ_HAS_64BIT_REGISTERS to 1 if the processor has 64-bit general purpose registers (enables 64-bit bitbuffer in inflator) */ |
1207
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
34 |
#define MINIZ_HAS_64BIT_REGISTERS 1 |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
35 |
#endif |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
36 |
|
1212
e3cd2449fe8e
Replace C++/C99 single-line comments in miniz with C98 /* comments */ ...
Ryan C. Gordon <icculus@icculus.org>
parents:
1207
diff
changeset
|
37 |
/* Works around MSVC's spammy "warning C4127: conditional expression is constant" message. */ |
1207
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
38 |
#ifdef _MSC_VER |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
39 |
#define MZ_MACRO_END while (0, 0) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
40 |
#else |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
41 |
#define MZ_MACRO_END while (0) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
42 |
#endif |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
43 |
|
1212
e3cd2449fe8e
Replace C++/C99 single-line comments in miniz with C98 /* comments */ ...
Ryan C. Gordon <icculus@icculus.org>
parents:
1207
diff
changeset
|
44 |
/* Decompression flags. */ |
1207
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
45 |
enum |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
46 |
{ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
47 |
TINFL_FLAG_PARSE_ZLIB_HEADER = 1, |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
48 |
TINFL_FLAG_HAS_MORE_INPUT = 2, |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
49 |
TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF = 4, |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
50 |
TINFL_FLAG_COMPUTE_ADLER32 = 8 |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
51 |
}; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
52 |
|
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
53 |
struct tinfl_decompressor_tag; typedef struct tinfl_decompressor_tag tinfl_decompressor; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
54 |
|
1212
e3cd2449fe8e
Replace C++/C99 single-line comments in miniz with C98 /* comments */ ...
Ryan C. Gordon <icculus@icculus.org>
parents:
1207
diff
changeset
|
55 |
/* Max size of LZ dictionary. */ |
1207
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
56 |
#define TINFL_LZ_DICT_SIZE 32768 |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
57 |
|
1212
e3cd2449fe8e
Replace C++/C99 single-line comments in miniz with C98 /* comments */ ...
Ryan C. Gordon <icculus@icculus.org>
parents:
1207
diff
changeset
|
58 |
/* Return status. */ |
1207
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
59 |
typedef enum |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
60 |
{ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
61 |
TINFL_STATUS_BAD_PARAM = -3, |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
62 |
TINFL_STATUS_ADLER32_MISMATCH = -2, |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
63 |
TINFL_STATUS_FAILED = -1, |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
64 |
TINFL_STATUS_DONE = 0, |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
65 |
TINFL_STATUS_NEEDS_MORE_INPUT = 1, |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
66 |
TINFL_STATUS_HAS_MORE_OUTPUT = 2 |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
67 |
} tinfl_status; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
68 |
|
1212
e3cd2449fe8e
Replace C++/C99 single-line comments in miniz with C98 /* comments */ ...
Ryan C. Gordon <icculus@icculus.org>
parents:
1207
diff
changeset
|
69 |
/* Initializes the decompressor to its initial state. */ |
1207
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
70 |
#define tinfl_init(r) do { (r)->m_state = 0; } MZ_MACRO_END |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
71 |
#define tinfl_get_adler32(r) (r)->m_check_adler32 |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
72 |
|
1212
e3cd2449fe8e
Replace C++/C99 single-line comments in miniz with C98 /* comments */ ...
Ryan C. Gordon <icculus@icculus.org>
parents:
1207
diff
changeset
|
73 |
/* Main low-level decompressor coroutine function. This is the only function actually needed for decompression. All the other functions are just high-level helpers for improved usability. */ |
e3cd2449fe8e
Replace C++/C99 single-line comments in miniz with C98 /* comments */ ...
Ryan C. Gordon <icculus@icculus.org>
parents:
1207
diff
changeset
|
74 |
/* This is a universal API, i.e. it can be used as a building block to build any desired higher level decompression API. In the limit case, it can be called once per every byte input or output. */ |
1207
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
75 |
static tinfl_status tinfl_decompress(tinfl_decompressor *r, const mz_uint8 *pIn_buf_next, size_t *pIn_buf_size, mz_uint8 *pOut_buf_start, mz_uint8 *pOut_buf_next, size_t *pOut_buf_size, const mz_uint32 decomp_flags); |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
76 |
|
1212
e3cd2449fe8e
Replace C++/C99 single-line comments in miniz with C98 /* comments */ ...
Ryan C. Gordon <icculus@icculus.org>
parents:
1207
diff
changeset
|
77 |
/* Internal/private bits follow. */ |
1207
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
78 |
enum |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
79 |
{ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
80 |
TINFL_MAX_HUFF_TABLES = 3, TINFL_MAX_HUFF_SYMBOLS_0 = 288, TINFL_MAX_HUFF_SYMBOLS_1 = 32, TINFL_MAX_HUFF_SYMBOLS_2 = 19, |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
81 |
TINFL_FAST_LOOKUP_BITS = 10, TINFL_FAST_LOOKUP_SIZE = 1 << TINFL_FAST_LOOKUP_BITS |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
82 |
}; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
83 |
|
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
84 |
typedef struct |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
85 |
{ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
86 |
mz_uint8 m_code_size[TINFL_MAX_HUFF_SYMBOLS_0]; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
87 |
mz_int16 m_look_up[TINFL_FAST_LOOKUP_SIZE], m_tree[TINFL_MAX_HUFF_SYMBOLS_0 * 2]; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
88 |
} tinfl_huff_table; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
89 |
|
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
90 |
#if MINIZ_HAS_64BIT_REGISTERS |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
91 |
#define TINFL_USE_64BIT_BITBUF 1 |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
92 |
#endif |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
93 |
|
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
94 |
#if TINFL_USE_64BIT_BITBUF |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
95 |
typedef mz_uint64 tinfl_bit_buf_t; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
96 |
#define TINFL_BITBUF_SIZE (64) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
97 |
#else |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
98 |
typedef mz_uint32 tinfl_bit_buf_t; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
99 |
#define TINFL_BITBUF_SIZE (32) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
100 |
#endif |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
101 |
|
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
102 |
struct tinfl_decompressor_tag |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
103 |
{ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
104 |
mz_uint32 m_state, m_num_bits, m_zhdr0, m_zhdr1, m_z_adler32, m_final, m_type, m_check_adler32, m_dist, m_counter, m_num_extra, m_table_sizes[TINFL_MAX_HUFF_TABLES]; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
105 |
tinfl_bit_buf_t m_bit_buf; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
106 |
size_t m_dist_from_out_buf_start; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
107 |
tinfl_huff_table m_tables[TINFL_MAX_HUFF_TABLES]; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
108 |
mz_uint8 m_raw_header[4], m_len_codes[TINFL_MAX_HUFF_SYMBOLS_0 + TINFL_MAX_HUFF_SYMBOLS_1 + 137]; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
109 |
}; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
110 |
|
1212
e3cd2449fe8e
Replace C++/C99 single-line comments in miniz with C98 /* comments */ ...
Ryan C. Gordon <icculus@icculus.org>
parents:
1207
diff
changeset
|
111 |
#endif /* #ifdef TINFL_HEADER_INCLUDED */ |
1207
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
112 |
|
1212
e3cd2449fe8e
Replace C++/C99 single-line comments in miniz with C98 /* comments */ ...
Ryan C. Gordon <icculus@icculus.org>
parents:
1207
diff
changeset
|
113 |
/* ------------------- End of Header: Implementation follows. (If you only want the header, define MINIZ_HEADER_FILE_ONLY.) */ |
1207
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
114 |
|
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
115 |
#ifndef TINFL_HEADER_FILE_ONLY |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
116 |
|
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
117 |
#define MZ_MAX(a,b) (((a)>(b))?(a):(b)) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
118 |
#define MZ_MIN(a,b) (((a)<(b))?(a):(b)) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
119 |
#define MZ_CLEAR_OBJ(obj) memset(&(obj), 0, sizeof(obj)) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
120 |
|
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
121 |
#if MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
122 |
#define MZ_READ_LE16(p) *((const mz_uint16 *)(p)) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
123 |
#define MZ_READ_LE32(p) *((const mz_uint32 *)(p)) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
124 |
#else |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
125 |
#define MZ_READ_LE16(p) ((mz_uint32)(((const mz_uint8 *)(p))[0]) | ((mz_uint32)(((const mz_uint8 *)(p))[1]) << 8U)) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
126 |
#define MZ_READ_LE32(p) ((mz_uint32)(((const mz_uint8 *)(p))[0]) | ((mz_uint32)(((const mz_uint8 *)(p))[1]) << 8U) | ((mz_uint32)(((const mz_uint8 *)(p))[2]) << 16U) | ((mz_uint32)(((const mz_uint8 *)(p))[3]) << 24U)) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
127 |
#endif |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
128 |
|
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
129 |
#define TINFL_MEMCPY(d, s, l) memcpy(d, s, l) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
130 |
#define TINFL_MEMSET(p, c, l) memset(p, c, l) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
131 |
|
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
132 |
#define TINFL_CR_BEGIN switch(r->m_state) { case 0: |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
133 |
#define TINFL_CR_RETURN(state_index, result) do { status = result; r->m_state = state_index; goto common_exit; case state_index:; } MZ_MACRO_END |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
134 |
#define TINFL_CR_RETURN_FOREVER(state_index, result) do { for ( ; ; ) { TINFL_CR_RETURN(state_index, result); } } MZ_MACRO_END |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
135 |
#define TINFL_CR_FINISH } |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
136 |
|
1212
e3cd2449fe8e
Replace C++/C99 single-line comments in miniz with C98 /* comments */ ...
Ryan C. Gordon <icculus@icculus.org>
parents:
1207
diff
changeset
|
137 |
/* TODO: If the caller has indicated that there's no more input, and we attempt to read beyond the input buf, then something is wrong with the input because the inflator never */ |
e3cd2449fe8e
Replace C++/C99 single-line comments in miniz with C98 /* comments */ ...
Ryan C. Gordon <icculus@icculus.org>
parents:
1207
diff
changeset
|
138 |
/* reads ahead more than it needs to. Currently TINFL_GET_BYTE() pads the end of the stream with 0's in this scenario. */ |
1207
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
139 |
#define TINFL_GET_BYTE(state_index, c) do { \ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
140 |
if (pIn_buf_cur >= pIn_buf_end) { \ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
141 |
for ( ; ; ) { \ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
142 |
if (decomp_flags & TINFL_FLAG_HAS_MORE_INPUT) { \ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
143 |
TINFL_CR_RETURN(state_index, TINFL_STATUS_NEEDS_MORE_INPUT); \ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
144 |
if (pIn_buf_cur < pIn_buf_end) { \ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
145 |
c = *pIn_buf_cur++; \ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
146 |
break; \ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
147 |
} \ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
148 |
} else { \ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
149 |
c = 0; \ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
150 |
break; \ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
151 |
} \ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
152 |
} \ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
153 |
} else c = *pIn_buf_cur++; } MZ_MACRO_END |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
154 |
|
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
155 |
#define TINFL_NEED_BITS(state_index, n) do { mz_uint c; TINFL_GET_BYTE(state_index, c); bit_buf |= (((tinfl_bit_buf_t)c) << num_bits); num_bits += 8; } while (num_bits < (mz_uint)(n)) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
156 |
#define TINFL_SKIP_BITS(state_index, n) do { if (num_bits < (mz_uint)(n)) { TINFL_NEED_BITS(state_index, n); } bit_buf >>= (n); num_bits -= (n); } MZ_MACRO_END |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
157 |
#define TINFL_GET_BITS(state_index, b, n) do { if (num_bits < (mz_uint)(n)) { TINFL_NEED_BITS(state_index, n); } b = bit_buf & ((1 << (n)) - 1); bit_buf >>= (n); num_bits -= (n); } MZ_MACRO_END |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
158 |
|
1212
e3cd2449fe8e
Replace C++/C99 single-line comments in miniz with C98 /* comments */ ...
Ryan C. Gordon <icculus@icculus.org>
parents:
1207
diff
changeset
|
159 |
/* TINFL_HUFF_BITBUF_FILL() is only used rarely, when the number of bytes remaining in the input buffer falls below 2. */ |
e3cd2449fe8e
Replace C++/C99 single-line comments in miniz with C98 /* comments */ ...
Ryan C. Gordon <icculus@icculus.org>
parents:
1207
diff
changeset
|
160 |
/* It reads just enough bytes from the input stream that are needed to decode the next Huffman code (and absolutely no more). It works by trying to fully decode a */ |
e3cd2449fe8e
Replace C++/C99 single-line comments in miniz with C98 /* comments */ ...
Ryan C. Gordon <icculus@icculus.org>
parents:
1207
diff
changeset
|
161 |
/* Huffman code by using whatever bits are currently present in the bit buffer. If this fails, it reads another byte, and tries again until it succeeds or until the */ |
e3cd2449fe8e
Replace C++/C99 single-line comments in miniz with C98 /* comments */ ...
Ryan C. Gordon <icculus@icculus.org>
parents:
1207
diff
changeset
|
162 |
/* bit buffer contains >=15 bits (deflate's max. Huffman code size). */ |
1207
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
163 |
#define TINFL_HUFF_BITBUF_FILL(state_index, pHuff) \ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
164 |
do { \ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
165 |
temp = (pHuff)->m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]; \ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
166 |
if (temp >= 0) { \ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
167 |
code_len = temp >> 9; \ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
168 |
if ((code_len) && (num_bits >= code_len)) \ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
169 |
break; \ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
170 |
} else if (num_bits > TINFL_FAST_LOOKUP_BITS) { \ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
171 |
code_len = TINFL_FAST_LOOKUP_BITS; \ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
172 |
do { \ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
173 |
temp = (pHuff)->m_tree[~temp + ((bit_buf >> code_len++) & 1)]; \ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
174 |
} while ((temp < 0) && (num_bits >= (code_len + 1))); if (temp >= 0) break; \ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
175 |
} TINFL_GET_BYTE(state_index, c); bit_buf |= (((tinfl_bit_buf_t)c) << num_bits); num_bits += 8; \ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
176 |
} while (num_bits < 15); |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
177 |
|
1212
e3cd2449fe8e
Replace C++/C99 single-line comments in miniz with C98 /* comments */ ...
Ryan C. Gordon <icculus@icculus.org>
parents:
1207
diff
changeset
|
178 |
/* TINFL_HUFF_DECODE() decodes the next Huffman coded symbol. It's more complex than you would initially expect because the zlib API expects the decompressor to never read */ |
e3cd2449fe8e
Replace C++/C99 single-line comments in miniz with C98 /* comments */ ...
Ryan C. Gordon <icculus@icculus.org>
parents:
1207
diff
changeset
|
179 |
/* beyond the final byte of the deflate stream. (In other words, when this macro wants to read another byte from the input, it REALLY needs another byte in order to fully */ |
e3cd2449fe8e
Replace C++/C99 single-line comments in miniz with C98 /* comments */ ...
Ryan C. Gordon <icculus@icculus.org>
parents:
1207
diff
changeset
|
180 |
/* decode the next Huffman code.) Handling this properly is particularly important on raw deflate (non-zlib) streams, which aren't followed by a byte aligned adler-32. */ |
e3cd2449fe8e
Replace C++/C99 single-line comments in miniz with C98 /* comments */ ...
Ryan C. Gordon <icculus@icculus.org>
parents:
1207
diff
changeset
|
181 |
/* The slow path is only executed at the very end of the input buffer. */ |
1207
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
182 |
#define TINFL_HUFF_DECODE(state_index, sym, pHuff) do { \ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
183 |
int temp; mz_uint code_len, c; \ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
184 |
if (num_bits < 15) { \ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
185 |
if ((pIn_buf_end - pIn_buf_cur) < 2) { \ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
186 |
TINFL_HUFF_BITBUF_FILL(state_index, pHuff); \ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
187 |
} else { \ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
188 |
bit_buf |= (((tinfl_bit_buf_t)pIn_buf_cur[0]) << num_bits) | (((tinfl_bit_buf_t)pIn_buf_cur[1]) << (num_bits + 8)); pIn_buf_cur += 2; num_bits += 16; \ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
189 |
} \ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
190 |
} \ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
191 |
if ((temp = (pHuff)->m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]) >= 0) \ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
192 |
code_len = temp >> 9, temp &= 511; \ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
193 |
else { \ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
194 |
code_len = TINFL_FAST_LOOKUP_BITS; do { temp = (pHuff)->m_tree[~temp + ((bit_buf >> code_len++) & 1)]; } while (temp < 0); \ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
195 |
} sym = temp; bit_buf >>= code_len; num_bits -= code_len; } MZ_MACRO_END |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
196 |
|
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
197 |
static tinfl_status tinfl_decompress(tinfl_decompressor *r, const mz_uint8 *pIn_buf_next, size_t *pIn_buf_size, mz_uint8 *pOut_buf_start, mz_uint8 *pOut_buf_next, size_t *pOut_buf_size, const mz_uint32 decomp_flags) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
198 |
{ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
199 |
static const int s_length_base[31] = { 3,4,5,6,7,8,9,10,11,13, 15,17,19,23,27,31,35,43,51,59, 67,83,99,115,131,163,195,227,258,0,0 }; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
200 |
static const int s_length_extra[31]= { 0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0 }; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
201 |
static const int s_dist_base[32] = { 1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193, 257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0}; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
202 |
static const int s_dist_extra[32] = { 0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13}; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
203 |
static const mz_uint8 s_length_dezigzag[19] = { 16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15 }; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
204 |
static const int s_min_table_sizes[3] = { 257, 1, 4 }; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
205 |
|
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
206 |
tinfl_status status = TINFL_STATUS_FAILED; mz_uint32 num_bits, dist, counter, num_extra; tinfl_bit_buf_t bit_buf; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
207 |
const mz_uint8 *pIn_buf_cur = pIn_buf_next, *const pIn_buf_end = pIn_buf_next + *pIn_buf_size; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
208 |
mz_uint8 *pOut_buf_cur = pOut_buf_next, *const pOut_buf_end = pOut_buf_next + *pOut_buf_size; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
209 |
size_t out_buf_size_mask = (decomp_flags & TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF) ? (size_t)-1 : ((pOut_buf_next - pOut_buf_start) + *pOut_buf_size) - 1, dist_from_out_buf_start; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
210 |
|
1212
e3cd2449fe8e
Replace C++/C99 single-line comments in miniz with C98 /* comments */ ...
Ryan C. Gordon <icculus@icculus.org>
parents:
1207
diff
changeset
|
211 |
/* Ensure the output buffer's size is a power of 2, unless the output buffer is large enough to hold the entire output file (in which case it doesn't matter). */ |
1207
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
212 |
if (((out_buf_size_mask + 1) & out_buf_size_mask) || (pOut_buf_next < pOut_buf_start)) { *pIn_buf_size = *pOut_buf_size = 0; return TINFL_STATUS_BAD_PARAM; } |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
213 |
|
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
214 |
num_bits = r->m_num_bits; bit_buf = r->m_bit_buf; dist = r->m_dist; counter = r->m_counter; num_extra = r->m_num_extra; dist_from_out_buf_start = r->m_dist_from_out_buf_start; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
215 |
TINFL_CR_BEGIN |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
216 |
|
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
217 |
bit_buf = num_bits = dist = counter = num_extra = r->m_zhdr0 = r->m_zhdr1 = 0; r->m_z_adler32 = r->m_check_adler32 = 1; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
218 |
if (decomp_flags & TINFL_FLAG_PARSE_ZLIB_HEADER) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
219 |
{ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
220 |
TINFL_GET_BYTE(1, r->m_zhdr0); TINFL_GET_BYTE(2, r->m_zhdr1); |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
221 |
counter = (((r->m_zhdr0 * 256 + r->m_zhdr1) % 31 != 0) || (r->m_zhdr1 & 32) || ((r->m_zhdr0 & 15) != 8)); |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
222 |
if (!(decomp_flags & TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF)) counter |= (((1U << (8U + (r->m_zhdr0 >> 4))) > 32768U) || ((out_buf_size_mask + 1) < (size_t)(1U << (8U + (r->m_zhdr0 >> 4))))); |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
223 |
if (counter) { TINFL_CR_RETURN_FOREVER(36, TINFL_STATUS_FAILED); } |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
224 |
} |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
225 |
|
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
226 |
do |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
227 |
{ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
228 |
TINFL_GET_BITS(3, r->m_final, 3); r->m_type = r->m_final >> 1; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
229 |
if (r->m_type == 0) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
230 |
{ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
231 |
TINFL_SKIP_BITS(5, num_bits & 7); |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
232 |
for (counter = 0; counter < 4; ++counter) { if (num_bits) TINFL_GET_BITS(6, r->m_raw_header[counter], 8); else TINFL_GET_BYTE(7, r->m_raw_header[counter]); } |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
233 |
if ((counter = (r->m_raw_header[0] | (r->m_raw_header[1] << 8))) != (mz_uint)(0xFFFF ^ (r->m_raw_header[2] | (r->m_raw_header[3] << 8)))) { TINFL_CR_RETURN_FOREVER(39, TINFL_STATUS_FAILED); } |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
234 |
while ((counter) && (num_bits)) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
235 |
{ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
236 |
TINFL_GET_BITS(51, dist, 8); |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
237 |
while (pOut_buf_cur >= pOut_buf_end) { TINFL_CR_RETURN(52, TINFL_STATUS_HAS_MORE_OUTPUT); } |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
238 |
*pOut_buf_cur++ = (mz_uint8)dist; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
239 |
counter--; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
240 |
} |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
241 |
while (counter) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
242 |
{ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
243 |
size_t n; while (pOut_buf_cur >= pOut_buf_end) { TINFL_CR_RETURN(9, TINFL_STATUS_HAS_MORE_OUTPUT); } |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
244 |
while (pIn_buf_cur >= pIn_buf_end) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
245 |
{ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
246 |
if (decomp_flags & TINFL_FLAG_HAS_MORE_INPUT) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
247 |
{ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
248 |
TINFL_CR_RETURN(38, TINFL_STATUS_NEEDS_MORE_INPUT); |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
249 |
} |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
250 |
else |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
251 |
{ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
252 |
TINFL_CR_RETURN_FOREVER(40, TINFL_STATUS_FAILED); |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
253 |
} |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
254 |
} |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
255 |
n = MZ_MIN(MZ_MIN((size_t)(pOut_buf_end - pOut_buf_cur), (size_t)(pIn_buf_end - pIn_buf_cur)), counter); |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
256 |
TINFL_MEMCPY(pOut_buf_cur, pIn_buf_cur, n); pIn_buf_cur += n; pOut_buf_cur += n; counter -= (mz_uint)n; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
257 |
} |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
258 |
} |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
259 |
else if (r->m_type == 3) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
260 |
{ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
261 |
TINFL_CR_RETURN_FOREVER(10, TINFL_STATUS_FAILED); |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
262 |
} |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
263 |
else |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
264 |
{ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
265 |
if (r->m_type == 1) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
266 |
{ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
267 |
mz_uint8 *p = r->m_tables[0].m_code_size; mz_uint i; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
268 |
r->m_table_sizes[0] = 288; r->m_table_sizes[1] = 32; TINFL_MEMSET(r->m_tables[1].m_code_size, 5, 32); |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
269 |
for ( i = 0; i <= 143; ++i) *p++ = 8; for ( ; i <= 255; ++i) *p++ = 9; for ( ; i <= 279; ++i) *p++ = 7; for ( ; i <= 287; ++i) *p++ = 8; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
270 |
} |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
271 |
else |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
272 |
{ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
273 |
for (counter = 0; counter < 3; counter++) { TINFL_GET_BITS(11, r->m_table_sizes[counter], "\05\05\04"[counter]); r->m_table_sizes[counter] += s_min_table_sizes[counter]; } |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
274 |
MZ_CLEAR_OBJ(r->m_tables[2].m_code_size); for (counter = 0; counter < r->m_table_sizes[2]; counter++) { mz_uint s; TINFL_GET_BITS(14, s, 3); r->m_tables[2].m_code_size[s_length_dezigzag[counter]] = (mz_uint8)s; } |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
275 |
r->m_table_sizes[2] = 19; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
276 |
} |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
277 |
for ( ; (int)r->m_type >= 0; r->m_type--) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
278 |
{ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
279 |
int tree_next, tree_cur; tinfl_huff_table *pTable; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
280 |
mz_uint i, j, used_syms, total, sym_index, next_code[17], total_syms[16]; pTable = &r->m_tables[r->m_type]; MZ_CLEAR_OBJ(total_syms); MZ_CLEAR_OBJ(pTable->m_look_up); MZ_CLEAR_OBJ(pTable->m_tree); |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
281 |
for (i = 0; i < r->m_table_sizes[r->m_type]; ++i) total_syms[pTable->m_code_size[i]]++; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
282 |
used_syms = 0, total = 0; next_code[0] = next_code[1] = 0; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
283 |
for (i = 1; i <= 15; ++i) { used_syms += total_syms[i]; next_code[i + 1] = (total = ((total + total_syms[i]) << 1)); } |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
284 |
if ((65536 != total) && (used_syms > 1)) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
285 |
{ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
286 |
TINFL_CR_RETURN_FOREVER(35, TINFL_STATUS_FAILED); |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
287 |
} |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
288 |
for (tree_next = -1, sym_index = 0; sym_index < r->m_table_sizes[r->m_type]; ++sym_index) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
289 |
{ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
290 |
mz_uint rev_code = 0, l, cur_code, code_size = pTable->m_code_size[sym_index]; if (!code_size) continue; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
291 |
cur_code = next_code[code_size]++; for (l = code_size; l > 0; l--, cur_code >>= 1) rev_code = (rev_code << 1) | (cur_code & 1); |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
292 |
if (code_size <= TINFL_FAST_LOOKUP_BITS) { mz_int16 k = (mz_int16)((code_size << 9) | sym_index); while (rev_code < TINFL_FAST_LOOKUP_SIZE) { pTable->m_look_up[rev_code] = k; rev_code += (1 << code_size); } continue; } |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
293 |
if (0 == (tree_cur = pTable->m_look_up[rev_code & (TINFL_FAST_LOOKUP_SIZE - 1)])) { pTable->m_look_up[rev_code & (TINFL_FAST_LOOKUP_SIZE - 1)] = (mz_int16)tree_next; tree_cur = tree_next; tree_next -= 2; } |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
294 |
rev_code >>= (TINFL_FAST_LOOKUP_BITS - 1); |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
295 |
for (j = code_size; j > (TINFL_FAST_LOOKUP_BITS + 1); j--) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
296 |
{ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
297 |
tree_cur -= ((rev_code >>= 1) & 1); |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
298 |
if (!pTable->m_tree[-tree_cur - 1]) { pTable->m_tree[-tree_cur - 1] = (mz_int16)tree_next; tree_cur = tree_next; tree_next -= 2; } else tree_cur = pTable->m_tree[-tree_cur - 1]; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
299 |
} |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
300 |
tree_cur -= ((rev_code >>= 1) & 1); pTable->m_tree[-tree_cur - 1] = (mz_int16)sym_index; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
301 |
} |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
302 |
if (r->m_type == 2) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
303 |
{ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
304 |
for (counter = 0; counter < (r->m_table_sizes[0] + r->m_table_sizes[1]); ) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
305 |
{ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
306 |
mz_uint s; TINFL_HUFF_DECODE(16, dist, &r->m_tables[2]); if (dist < 16) { r->m_len_codes[counter++] = (mz_uint8)dist; continue; } |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
307 |
if ((dist == 16) && (!counter)) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
308 |
{ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
309 |
TINFL_CR_RETURN_FOREVER(17, TINFL_STATUS_FAILED); |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
310 |
} |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
311 |
num_extra = "\02\03\07"[dist - 16]; TINFL_GET_BITS(18, s, num_extra); s += "\03\03\013"[dist - 16]; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
312 |
TINFL_MEMSET(r->m_len_codes + counter, (dist == 16) ? r->m_len_codes[counter - 1] : 0, s); counter += s; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
313 |
} |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
314 |
if ((r->m_table_sizes[0] + r->m_table_sizes[1]) != counter) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
315 |
{ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
316 |
TINFL_CR_RETURN_FOREVER(21, TINFL_STATUS_FAILED); |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
317 |
} |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
318 |
TINFL_MEMCPY(r->m_tables[0].m_code_size, r->m_len_codes, r->m_table_sizes[0]); TINFL_MEMCPY(r->m_tables[1].m_code_size, r->m_len_codes + r->m_table_sizes[0], r->m_table_sizes[1]); |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
319 |
} |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
320 |
} |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
321 |
for ( ; ; ) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
322 |
{ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
323 |
mz_uint8 *pSrc; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
324 |
for ( ; ; ) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
325 |
{ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
326 |
if (((pIn_buf_end - pIn_buf_cur) < 4) || ((pOut_buf_end - pOut_buf_cur) < 2)) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
327 |
{ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
328 |
TINFL_HUFF_DECODE(23, counter, &r->m_tables[0]); |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
329 |
if (counter >= 256) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
330 |
break; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
331 |
while (pOut_buf_cur >= pOut_buf_end) { TINFL_CR_RETURN(24, TINFL_STATUS_HAS_MORE_OUTPUT); } |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
332 |
*pOut_buf_cur++ = (mz_uint8)counter; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
333 |
} |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
334 |
else |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
335 |
{ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
336 |
int sym2; mz_uint code_len; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
337 |
#if TINFL_USE_64BIT_BITBUF |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
338 |
if (num_bits < 30) { bit_buf |= (((tinfl_bit_buf_t)MZ_READ_LE32(pIn_buf_cur)) << num_bits); pIn_buf_cur += 4; num_bits += 32; } |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
339 |
#else |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
340 |
if (num_bits < 15) { bit_buf |= (((tinfl_bit_buf_t)MZ_READ_LE16(pIn_buf_cur)) << num_bits); pIn_buf_cur += 2; num_bits += 16; } |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
341 |
#endif |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
342 |
if ((sym2 = r->m_tables[0].m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]) >= 0) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
343 |
code_len = sym2 >> 9; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
344 |
else |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
345 |
{ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
346 |
code_len = TINFL_FAST_LOOKUP_BITS; do { sym2 = r->m_tables[0].m_tree[~sym2 + ((bit_buf >> code_len++) & 1)]; } while (sym2 < 0); |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
347 |
} |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
348 |
counter = sym2; bit_buf >>= code_len; num_bits -= code_len; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
349 |
if (counter & 256) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
350 |
break; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
351 |
|
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
352 |
#if !TINFL_USE_64BIT_BITBUF |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
353 |
if (num_bits < 15) { bit_buf |= (((tinfl_bit_buf_t)MZ_READ_LE16(pIn_buf_cur)) << num_bits); pIn_buf_cur += 2; num_bits += 16; } |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
354 |
#endif |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
355 |
if ((sym2 = r->m_tables[0].m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]) >= 0) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
356 |
code_len = sym2 >> 9; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
357 |
else |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
358 |
{ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
359 |
code_len = TINFL_FAST_LOOKUP_BITS; do { sym2 = r->m_tables[0].m_tree[~sym2 + ((bit_buf >> code_len++) & 1)]; } while (sym2 < 0); |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
360 |
} |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
361 |
bit_buf >>= code_len; num_bits -= code_len; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
362 |
|
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
363 |
pOut_buf_cur[0] = (mz_uint8)counter; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
364 |
if (sym2 & 256) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
365 |
{ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
366 |
pOut_buf_cur++; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
367 |
counter = sym2; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
368 |
break; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
369 |
} |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
370 |
pOut_buf_cur[1] = (mz_uint8)sym2; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
371 |
pOut_buf_cur += 2; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
372 |
} |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
373 |
} |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
374 |
if ((counter &= 511) == 256) break; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
375 |
|
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
376 |
num_extra = s_length_extra[counter - 257]; counter = s_length_base[counter - 257]; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
377 |
if (num_extra) { mz_uint extra_bits; TINFL_GET_BITS(25, extra_bits, num_extra); counter += extra_bits; } |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
378 |
|
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
379 |
TINFL_HUFF_DECODE(26, dist, &r->m_tables[1]); |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
380 |
num_extra = s_dist_extra[dist]; dist = s_dist_base[dist]; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
381 |
if (num_extra) { mz_uint extra_bits; TINFL_GET_BITS(27, extra_bits, num_extra); dist += extra_bits; } |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
382 |
|
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
383 |
dist_from_out_buf_start = pOut_buf_cur - pOut_buf_start; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
384 |
if ((dist > dist_from_out_buf_start) && (decomp_flags & TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF)) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
385 |
{ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
386 |
TINFL_CR_RETURN_FOREVER(37, TINFL_STATUS_FAILED); |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
387 |
} |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
388 |
|
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
389 |
pSrc = pOut_buf_start + ((dist_from_out_buf_start - dist) & out_buf_size_mask); |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
390 |
|
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
391 |
if ((MZ_MAX(pOut_buf_cur, pSrc) + counter) > pOut_buf_end) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
392 |
{ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
393 |
while (counter--) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
394 |
{ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
395 |
while (pOut_buf_cur >= pOut_buf_end) { TINFL_CR_RETURN(53, TINFL_STATUS_HAS_MORE_OUTPUT); } |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
396 |
*pOut_buf_cur++ = pOut_buf_start[(dist_from_out_buf_start++ - dist) & out_buf_size_mask]; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
397 |
} |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
398 |
continue; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
399 |
} |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
400 |
#if MINIZ_USE_UNALIGNED_LOADS_AND_STORES |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
401 |
else if ((counter >= 9) && (counter <= dist)) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
402 |
{ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
403 |
const mz_uint8 *pSrc_end = pSrc + (counter & ~7); |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
404 |
do |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
405 |
{ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
406 |
((mz_uint32 *)pOut_buf_cur)[0] = ((const mz_uint32 *)pSrc)[0]; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
407 |
((mz_uint32 *)pOut_buf_cur)[1] = ((const mz_uint32 *)pSrc)[1]; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
408 |
pOut_buf_cur += 8; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
409 |
} while ((pSrc += 8) < pSrc_end); |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
410 |
if ((counter &= 7) < 3) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
411 |
{ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
412 |
if (counter) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
413 |
{ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
414 |
pOut_buf_cur[0] = pSrc[0]; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
415 |
if (counter > 1) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
416 |
pOut_buf_cur[1] = pSrc[1]; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
417 |
pOut_buf_cur += counter; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
418 |
} |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
419 |
continue; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
420 |
} |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
421 |
} |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
422 |
#endif |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
423 |
do |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
424 |
{ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
425 |
pOut_buf_cur[0] = pSrc[0]; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
426 |
pOut_buf_cur[1] = pSrc[1]; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
427 |
pOut_buf_cur[2] = pSrc[2]; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
428 |
pOut_buf_cur += 3; pSrc += 3; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
429 |
} while ((int)(counter -= 3) > 2); |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
430 |
if ((int)counter > 0) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
431 |
{ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
432 |
pOut_buf_cur[0] = pSrc[0]; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
433 |
if ((int)counter > 1) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
434 |
pOut_buf_cur[1] = pSrc[1]; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
435 |
pOut_buf_cur += counter; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
436 |
} |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
437 |
} |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
438 |
} |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
439 |
} while (!(r->m_final & 1)); |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
440 |
if (decomp_flags & TINFL_FLAG_PARSE_ZLIB_HEADER) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
441 |
{ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
442 |
TINFL_SKIP_BITS(32, num_bits & 7); for (counter = 0; counter < 4; ++counter) { mz_uint s; if (num_bits) TINFL_GET_BITS(41, s, 8); else TINFL_GET_BYTE(42, s); r->m_z_adler32 = (r->m_z_adler32 << 8) | s; } |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
443 |
} |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
444 |
TINFL_CR_RETURN_FOREVER(34, TINFL_STATUS_DONE); |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
445 |
TINFL_CR_FINISH |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
446 |
|
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
447 |
common_exit: |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
448 |
r->m_num_bits = num_bits; r->m_bit_buf = bit_buf; r->m_dist = dist; r->m_counter = counter; r->m_num_extra = num_extra; r->m_dist_from_out_buf_start = dist_from_out_buf_start; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
449 |
*pIn_buf_size = pIn_buf_cur - pIn_buf_next; *pOut_buf_size = pOut_buf_cur - pOut_buf_next; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
450 |
if ((decomp_flags & (TINFL_FLAG_PARSE_ZLIB_HEADER | TINFL_FLAG_COMPUTE_ADLER32)) && (status >= 0)) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
451 |
{ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
452 |
const mz_uint8 *ptr = pOut_buf_next; size_t buf_len = *pOut_buf_size; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
453 |
mz_uint32 i, s1 = r->m_check_adler32 & 0xffff, s2 = r->m_check_adler32 >> 16; size_t block_len = buf_len % 5552; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
454 |
while (buf_len) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
455 |
{ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
456 |
for (i = 0; i + 7 < block_len; i += 8, ptr += 8) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
457 |
{ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
458 |
s1 += ptr[0], s2 += s1; s1 += ptr[1], s2 += s1; s1 += ptr[2], s2 += s1; s1 += ptr[3], s2 += s1; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
459 |
s1 += ptr[4], s2 += s1; s1 += ptr[5], s2 += s1; s1 += ptr[6], s2 += s1; s1 += ptr[7], s2 += s1; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
460 |
} |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
461 |
for ( ; i < block_len; ++i) s1 += *ptr++, s2 += s1; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
462 |
s1 %= 65521U, s2 %= 65521U; buf_len -= block_len; block_len = 5552; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
463 |
} |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
464 |
r->m_check_adler32 = (s2 << 16) + s1; if ((status == TINFL_STATUS_DONE) && (decomp_flags & TINFL_FLAG_PARSE_ZLIB_HEADER) && (r->m_check_adler32 != r->m_z_adler32)) status = TINFL_STATUS_ADLER32_MISMATCH; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
465 |
} |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
466 |
return status; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
467 |
} |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
468 |
|
1212
e3cd2449fe8e
Replace C++/C99 single-line comments in miniz with C98 /* comments */ ...
Ryan C. Gordon <icculus@icculus.org>
parents:
1207
diff
changeset
|
469 |
/* Flush values. For typical usage you only need MZ_NO_FLUSH and MZ_FINISH. The other stuff is for advanced use. */ |
1207
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
470 |
enum { MZ_NO_FLUSH = 0, MZ_PARTIAL_FLUSH = 1, MZ_SYNC_FLUSH = 2, MZ_FULL_FLUSH = 3, MZ_FINISH = 4, MZ_BLOCK = 5 }; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
471 |
|
1212
e3cd2449fe8e
Replace C++/C99 single-line comments in miniz with C98 /* comments */ ...
Ryan C. Gordon <icculus@icculus.org>
parents:
1207
diff
changeset
|
472 |
/* Return status codes. MZ_PARAM_ERROR is non-standard. */ |
1207
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
473 |
enum { MZ_OK = 0, MZ_STREAM_END = 1, MZ_NEED_DICT = 2, MZ_ERRNO = -1, MZ_STREAM_ERROR = -2, MZ_DATA_ERROR = -3, MZ_MEM_ERROR = -4, MZ_BUF_ERROR = -5, MZ_VERSION_ERROR = -6, MZ_PARAM_ERROR = -10000 }; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
474 |
|
1212
e3cd2449fe8e
Replace C++/C99 single-line comments in miniz with C98 /* comments */ ...
Ryan C. Gordon <icculus@icculus.org>
parents:
1207
diff
changeset
|
475 |
/* Compression levels. */ |
1207
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
476 |
enum { MZ_NO_COMPRESSION = 0, MZ_BEST_SPEED = 1, MZ_BEST_COMPRESSION = 9, MZ_DEFAULT_COMPRESSION = -1 }; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
477 |
|
1212
e3cd2449fe8e
Replace C++/C99 single-line comments in miniz with C98 /* comments */ ...
Ryan C. Gordon <icculus@icculus.org>
parents:
1207
diff
changeset
|
478 |
/* Window bits */ |
1207
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
479 |
#define MZ_DEFAULT_WINDOW_BITS 15 |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
480 |
|
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
481 |
struct mz_internal_state; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
482 |
|
1212
e3cd2449fe8e
Replace C++/C99 single-line comments in miniz with C98 /* comments */ ...
Ryan C. Gordon <icculus@icculus.org>
parents:
1207
diff
changeset
|
483 |
/* Compression/decompression stream struct. */ |
1207
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
484 |
typedef struct mz_stream_s |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
485 |
{ |
1212
e3cd2449fe8e
Replace C++/C99 single-line comments in miniz with C98 /* comments */ ...
Ryan C. Gordon <icculus@icculus.org>
parents:
1207
diff
changeset
|
486 |
const unsigned char *next_in; /* pointer to next byte to read */ |
e3cd2449fe8e
Replace C++/C99 single-line comments in miniz with C98 /* comments */ ...
Ryan C. Gordon <icculus@icculus.org>
parents:
1207
diff
changeset
|
487 |
unsigned int avail_in; /* number of bytes available at next_in */ |
e3cd2449fe8e
Replace C++/C99 single-line comments in miniz with C98 /* comments */ ...
Ryan C. Gordon <icculus@icculus.org>
parents:
1207
diff
changeset
|
488 |
mz_ulong total_in; /* total number of bytes consumed so far */ |
1207
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
489 |
|
1212
e3cd2449fe8e
Replace C++/C99 single-line comments in miniz with C98 /* comments */ ...
Ryan C. Gordon <icculus@icculus.org>
parents:
1207
diff
changeset
|
490 |
unsigned char *next_out; /* pointer to next byte to write */ |
e3cd2449fe8e
Replace C++/C99 single-line comments in miniz with C98 /* comments */ ...
Ryan C. Gordon <icculus@icculus.org>
parents:
1207
diff
changeset
|
491 |
unsigned int avail_out; /* number of bytes that can be written to next_out */ |
e3cd2449fe8e
Replace C++/C99 single-line comments in miniz with C98 /* comments */ ...
Ryan C. Gordon <icculus@icculus.org>
parents:
1207
diff
changeset
|
492 |
mz_ulong total_out; /* total number of bytes produced so far */ |
1207
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
493 |
|
1212
e3cd2449fe8e
Replace C++/C99 single-line comments in miniz with C98 /* comments */ ...
Ryan C. Gordon <icculus@icculus.org>
parents:
1207
diff
changeset
|
494 |
char *msg; /* error msg (unused) */ |
e3cd2449fe8e
Replace C++/C99 single-line comments in miniz with C98 /* comments */ ...
Ryan C. Gordon <icculus@icculus.org>
parents:
1207
diff
changeset
|
495 |
struct mz_internal_state *state; /* internal state, allocated by zalloc/zfree */ |
1207
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
496 |
|
1212
e3cd2449fe8e
Replace C++/C99 single-line comments in miniz with C98 /* comments */ ...
Ryan C. Gordon <icculus@icculus.org>
parents:
1207
diff
changeset
|
497 |
mz_alloc_func zalloc; /* optional heap allocation function (defaults to malloc) */ |
e3cd2449fe8e
Replace C++/C99 single-line comments in miniz with C98 /* comments */ ...
Ryan C. Gordon <icculus@icculus.org>
parents:
1207
diff
changeset
|
498 |
mz_free_func zfree; /* optional heap free function (defaults to free) */ |
e3cd2449fe8e
Replace C++/C99 single-line comments in miniz with C98 /* comments */ ...
Ryan C. Gordon <icculus@icculus.org>
parents:
1207
diff
changeset
|
499 |
void *opaque; /* heap alloc function user pointer */ |
1207
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
500 |
|
1212
e3cd2449fe8e
Replace C++/C99 single-line comments in miniz with C98 /* comments */ ...
Ryan C. Gordon <icculus@icculus.org>
parents:
1207
diff
changeset
|
501 |
int data_type; /* data_type (unused) */ |
e3cd2449fe8e
Replace C++/C99 single-line comments in miniz with C98 /* comments */ ...
Ryan C. Gordon <icculus@icculus.org>
parents:
1207
diff
changeset
|
502 |
mz_ulong adler; /* adler32 of the source or uncompressed data */ |
e3cd2449fe8e
Replace C++/C99 single-line comments in miniz with C98 /* comments */ ...
Ryan C. Gordon <icculus@icculus.org>
parents:
1207
diff
changeset
|
503 |
mz_ulong reserved; /* not used */ |
1207
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
504 |
} mz_stream; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
505 |
|
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
506 |
typedef mz_stream *mz_streamp; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
507 |
|
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
508 |
|
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
509 |
typedef struct |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
510 |
{ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
511 |
tinfl_decompressor m_decomp; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
512 |
mz_uint m_dict_ofs, m_dict_avail, m_first_call, m_has_flushed; int m_window_bits; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
513 |
mz_uint8 m_dict[TINFL_LZ_DICT_SIZE]; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
514 |
tinfl_status m_last_status; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
515 |
} inflate_state; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
516 |
|
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
517 |
static int mz_inflateInit2(mz_streamp pStream, int window_bits) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
518 |
{ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
519 |
inflate_state *pDecomp; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
520 |
if (!pStream) return MZ_STREAM_ERROR; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
521 |
if ((window_bits != MZ_DEFAULT_WINDOW_BITS) && (-window_bits != MZ_DEFAULT_WINDOW_BITS)) return MZ_PARAM_ERROR; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
522 |
|
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
523 |
pStream->data_type = 0; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
524 |
pStream->adler = 0; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
525 |
pStream->msg = NULL; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
526 |
pStream->total_in = 0; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
527 |
pStream->total_out = 0; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
528 |
pStream->reserved = 0; |
1212
e3cd2449fe8e
Replace C++/C99 single-line comments in miniz with C98 /* comments */ ...
Ryan C. Gordon <icculus@icculus.org>
parents:
1207
diff
changeset
|
529 |
/* if (!pStream->zalloc) pStream->zalloc = def_alloc_func; */ |
e3cd2449fe8e
Replace C++/C99 single-line comments in miniz with C98 /* comments */ ...
Ryan C. Gordon <icculus@icculus.org>
parents:
1207
diff
changeset
|
530 |
/* if (!pStream->zfree) pStream->zfree = def_free_func; */ |
1207
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
531 |
|
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
532 |
pDecomp = (inflate_state*)pStream->zalloc(pStream->opaque, 1, sizeof(inflate_state)); |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
533 |
if (!pDecomp) return MZ_MEM_ERROR; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
534 |
|
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
535 |
pStream->state = (struct mz_internal_state *)pDecomp; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
536 |
|
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
537 |
tinfl_init(&pDecomp->m_decomp); |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
538 |
pDecomp->m_dict_ofs = 0; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
539 |
pDecomp->m_dict_avail = 0; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
540 |
pDecomp->m_last_status = TINFL_STATUS_NEEDS_MORE_INPUT; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
541 |
pDecomp->m_first_call = 1; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
542 |
pDecomp->m_has_flushed = 0; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
543 |
pDecomp->m_window_bits = window_bits; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
544 |
|
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
545 |
return MZ_OK; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
546 |
} |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
547 |
|
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
548 |
static int mz_inflate(mz_streamp pStream, int flush) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
549 |
{ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
550 |
inflate_state* pState; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
551 |
mz_uint n, first_call, decomp_flags = TINFL_FLAG_COMPUTE_ADLER32; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
552 |
size_t in_bytes, out_bytes, orig_avail_in; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
553 |
tinfl_status status; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
554 |
|
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
555 |
if ((!pStream) || (!pStream->state)) return MZ_STREAM_ERROR; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
556 |
if (flush == MZ_PARTIAL_FLUSH) flush = MZ_SYNC_FLUSH; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
557 |
if ((flush) && (flush != MZ_SYNC_FLUSH) && (flush != MZ_FINISH)) return MZ_STREAM_ERROR; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
558 |
|
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
559 |
pState = (inflate_state*)pStream->state; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
560 |
if (pState->m_window_bits > 0) decomp_flags |= TINFL_FLAG_PARSE_ZLIB_HEADER; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
561 |
orig_avail_in = pStream->avail_in; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
562 |
|
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
563 |
first_call = pState->m_first_call; pState->m_first_call = 0; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
564 |
if (pState->m_last_status < 0) return MZ_DATA_ERROR; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
565 |
|
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
566 |
if (pState->m_has_flushed && (flush != MZ_FINISH)) return MZ_STREAM_ERROR; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
567 |
pState->m_has_flushed |= (flush == MZ_FINISH); |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
568 |
|
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
569 |
if ((flush == MZ_FINISH) && (first_call)) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
570 |
{ |
1212
e3cd2449fe8e
Replace C++/C99 single-line comments in miniz with C98 /* comments */ ...
Ryan C. Gordon <icculus@icculus.org>
parents:
1207
diff
changeset
|
571 |
/* MZ_FINISH on the first call implies that the input and output buffers are large enough to hold the entire compressed/decompressed file. */ |
1207
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
572 |
decomp_flags |= TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
573 |
in_bytes = pStream->avail_in; out_bytes = pStream->avail_out; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
574 |
status = tinfl_decompress(&pState->m_decomp, pStream->next_in, &in_bytes, pStream->next_out, pStream->next_out, &out_bytes, decomp_flags); |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
575 |
pState->m_last_status = status; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
576 |
pStream->next_in += (mz_uint)in_bytes; pStream->avail_in -= (mz_uint)in_bytes; pStream->total_in += (mz_uint)in_bytes; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
577 |
pStream->adler = tinfl_get_adler32(&pState->m_decomp); |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
578 |
pStream->next_out += (mz_uint)out_bytes; pStream->avail_out -= (mz_uint)out_bytes; pStream->total_out += (mz_uint)out_bytes; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
579 |
|
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
580 |
if (status < 0) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
581 |
return MZ_DATA_ERROR; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
582 |
else if (status != TINFL_STATUS_DONE) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
583 |
{ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
584 |
pState->m_last_status = TINFL_STATUS_FAILED; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
585 |
return MZ_BUF_ERROR; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
586 |
} |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
587 |
return MZ_STREAM_END; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
588 |
} |
1212
e3cd2449fe8e
Replace C++/C99 single-line comments in miniz with C98 /* comments */ ...
Ryan C. Gordon <icculus@icculus.org>
parents:
1207
diff
changeset
|
589 |
/* flush != MZ_FINISH then we must assume there's more input. */ |
1207
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
590 |
if (flush != MZ_FINISH) decomp_flags |= TINFL_FLAG_HAS_MORE_INPUT; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
591 |
|
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
592 |
if (pState->m_dict_avail) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
593 |
{ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
594 |
n = MZ_MIN(pState->m_dict_avail, pStream->avail_out); |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
595 |
memcpy(pStream->next_out, pState->m_dict + pState->m_dict_ofs, n); |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
596 |
pStream->next_out += n; pStream->avail_out -= n; pStream->total_out += n; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
597 |
pState->m_dict_avail -= n; pState->m_dict_ofs = (pState->m_dict_ofs + n) & (TINFL_LZ_DICT_SIZE - 1); |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
598 |
return ((pState->m_last_status == TINFL_STATUS_DONE) && (!pState->m_dict_avail)) ? MZ_STREAM_END : MZ_OK; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
599 |
} |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
600 |
|
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
601 |
for ( ; ; ) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
602 |
{ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
603 |
in_bytes = pStream->avail_in; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
604 |
out_bytes = TINFL_LZ_DICT_SIZE - pState->m_dict_ofs; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
605 |
|
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
606 |
status = tinfl_decompress(&pState->m_decomp, pStream->next_in, &in_bytes, pState->m_dict, pState->m_dict + pState->m_dict_ofs, &out_bytes, decomp_flags); |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
607 |
pState->m_last_status = status; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
608 |
|
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
609 |
pStream->next_in += (mz_uint)in_bytes; pStream->avail_in -= (mz_uint)in_bytes; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
610 |
pStream->total_in += (mz_uint)in_bytes; pStream->adler = tinfl_get_adler32(&pState->m_decomp); |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
611 |
|
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
612 |
pState->m_dict_avail = (mz_uint)out_bytes; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
613 |
|
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
614 |
n = MZ_MIN(pState->m_dict_avail, pStream->avail_out); |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
615 |
memcpy(pStream->next_out, pState->m_dict + pState->m_dict_ofs, n); |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
616 |
pStream->next_out += n; pStream->avail_out -= n; pStream->total_out += n; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
617 |
pState->m_dict_avail -= n; pState->m_dict_ofs = (pState->m_dict_ofs + n) & (TINFL_LZ_DICT_SIZE - 1); |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
618 |
|
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
619 |
if (status < 0) |
1212
e3cd2449fe8e
Replace C++/C99 single-line comments in miniz with C98 /* comments */ ...
Ryan C. Gordon <icculus@icculus.org>
parents:
1207
diff
changeset
|
620 |
return MZ_DATA_ERROR; /* Stream is corrupted (there could be some uncompressed data left in the output dictionary - oh well). */ |
1207
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
621 |
else if ((status == TINFL_STATUS_NEEDS_MORE_INPUT) && (!orig_avail_in)) |
1212
e3cd2449fe8e
Replace C++/C99 single-line comments in miniz with C98 /* comments */ ...
Ryan C. Gordon <icculus@icculus.org>
parents:
1207
diff
changeset
|
622 |
return MZ_BUF_ERROR; /* Signal caller that we can't make forward progress without supplying more input or by setting flush to MZ_FINISH. */ |
1207
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
623 |
else if (flush == MZ_FINISH) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
624 |
{ |
1212
e3cd2449fe8e
Replace C++/C99 single-line comments in miniz with C98 /* comments */ ...
Ryan C. Gordon <icculus@icculus.org>
parents:
1207
diff
changeset
|
625 |
/* The output buffer MUST be large to hold the remaining uncompressed data when flush==MZ_FINISH. */ |
1207
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
626 |
if (status == TINFL_STATUS_DONE) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
627 |
return pState->m_dict_avail ? MZ_BUF_ERROR : MZ_STREAM_END; |
1212
e3cd2449fe8e
Replace C++/C99 single-line comments in miniz with C98 /* comments */ ...
Ryan C. Gordon <icculus@icculus.org>
parents:
1207
diff
changeset
|
628 |
/* status here must be TINFL_STATUS_HAS_MORE_OUTPUT, which means there's at least 1 more byte on the way. If there's no more room left in the output buffer then something is wrong. */ |
1207
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
629 |
else if (!pStream->avail_out) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
630 |
return MZ_BUF_ERROR; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
631 |
} |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
632 |
else if ((status == TINFL_STATUS_DONE) || (!pStream->avail_in) || (!pStream->avail_out) || (pState->m_dict_avail)) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
633 |
break; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
634 |
} |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
635 |
|
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
636 |
return ((status == TINFL_STATUS_DONE) && (!pState->m_dict_avail)) ? MZ_STREAM_END : MZ_OK; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
637 |
} |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
638 |
|
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
639 |
static int mz_inflateEnd(mz_streamp pStream) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
640 |
{ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
641 |
if (!pStream) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
642 |
return MZ_STREAM_ERROR; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
643 |
if (pStream->state) |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
644 |
{ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
645 |
pStream->zfree(pStream->opaque, pStream->state); |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
646 |
pStream->state = NULL; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
647 |
} |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
648 |
return MZ_OK; |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
649 |
} |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
650 |
|
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
651 |
/* make this a drop-in replacement for zlib... */ |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
652 |
#define voidpf void* |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
653 |
#define uInt unsigned int |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
654 |
#define z_stream mz_stream |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
655 |
#define inflateInit2 mz_inflateInit2 |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
656 |
#define inflate mz_inflate |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
657 |
#define inflateEnd mz_inflateEnd |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
658 |
#define Z_SYNC_FLUSH MZ_SYNC_FLUSH |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
659 |
#define Z_FINISH MZ_FINISH |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
660 |
#define Z_OK MZ_OK |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
661 |
#define Z_STREAM_END MZ_STREAM_END |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
662 |
#define Z_NEED_DICT MZ_NEED_DICT |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
663 |
#define Z_ERRNO MZ_ERRNO |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
664 |
#define Z_STREAM_ERROR MZ_STREAM_ERROR |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
665 |
#define Z_DATA_ERROR MZ_DATA_ERROR |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
666 |
#define Z_MEM_ERROR MZ_MEM_ERROR |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
667 |
#define Z_BUF_ERROR MZ_BUF_ERROR |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
668 |
#define Z_VERSION_ERROR MZ_VERSION_ERROR |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
669 |
#define MAX_WBITS 15 |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
670 |
|
1212
e3cd2449fe8e
Replace C++/C99 single-line comments in miniz with C98 /* comments */ ...
Ryan C. Gordon <icculus@icculus.org>
parents:
1207
diff
changeset
|
671 |
#endif /* #ifndef TINFL_HEADER_FILE_ONLY */ |
1207
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
672 |
|
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
673 |
/* |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
674 |
This is free and unencumbered software released into the public domain. |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
675 |
|
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
676 |
Anyone is free to copy, modify, publish, use, compile, sell, or |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
677 |
distribute this software, either in source code form or as a compiled |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
678 |
binary, for any purpose, commercial or non-commercial, and by any |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
679 |
means. |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
680 |
|
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
681 |
In jurisdictions that recognize copyright laws, the author or authors |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
682 |
of this software dedicate any and all copyright interest in the |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
683 |
software to the public domain. We make this dedication for the benefit |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
684 |
of the public at large and to the detriment of our heirs and |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
685 |
successors. We intend this dedication to be an overt act of |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
686 |
relinquishment in perpetuity of all present and future rights to this |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
687 |
software under copyright law. |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
688 |
|
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
689 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
690 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
691 |
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
692 |
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
693 |
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
694 |
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
695 |
OTHER DEALINGS IN THE SOFTWARE. |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
696 |
|
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
697 |
For more information, please refer to <http://unlicense.org/> |
42e2aad5ab02
Replaced zlib with a hacked up copy of miniz: http://code.google.com/p/miniz/
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
698 |
*/ |