21 #ifndef MINIZ_HEADER_INCLUDED
22 #define MINIZ_HEADER_INCLUDED
55 #if defined(__TINYC__) && (defined(__linux) || defined(__linux__))
60 #if !defined(MINIZ_NO_TIME) && !defined(MINIZ_NO_ARCHIVE_APIS)
64 #if defined(_M_IX86) || defined(_M_X64) || defined(__i386__) || defined(__i386) || defined(__i486__) || defined(__i486) || defined(i386) || defined(__ia64__) || defined(__x86_64__)
66 #define MINIZ_X86_OR_X64_CPU 1
69 #if (__BYTE_ORDER__==__ORDER_LITTLE_ENDIAN__) || MINIZ_X86_OR_X64_CPU
71 #define MINIZ_LITTLE_ENDIAN 1
74 #if MINIZ_X86_OR_X64_CPU
76 #define MINIZ_USE_UNALIGNED_LOADS_AND_STORES 1
80 #if defined(__has_feature)
81 #if __has_feature(undefined_behavior_sanitizer)
82 #undef MINIZ_USE_UNALIGNED_LOADS_AND_STORES
83 #define MINIZ_USE_UNALIGNED_LOADS_AND_STORES 0
87 #if defined(_M_X64) || defined(_WIN64) || defined(__MINGW64__) || defined(_LP64) || defined(__LP64__) || defined(__ia64__) || defined(__x86_64__)
89 #define MINIZ_HAS_64BIT_REGISTERS 1
103 #define MZ_ADLER32_INIT (1)
107 #define MZ_CRC32_INIT (0)
115 #define MZ_DEFLATED 8
117 #ifndef MINIZ_NO_ZLIB_APIS
121 typedef void *(*mz_alloc_func)(
void *opaque,
size_t items,
size_t size);
123 typedef void *(*mz_realloc_func)(
void *opaque,
void *address,
size_t items,
size_t size);
125 #define MZ_VERSION "9.1.15"
126 #define MZ_VERNUM 0x91F0
127 #define MZ_VER_MAJOR 9
128 #define MZ_VER_MINOR 1
129 #define MZ_VER_REVISION 15
130 #define MZ_VER_SUBREVISION 0
142 #define MZ_DEFAULT_WINDOW_BITS 15
144 struct mz_internal_state;
262 #ifndef MINIZ_NO_ZLIB_COMPATIBLE_NAMES
275 #define Z_NO_FLUSH MZ_NO_FLUSH
276 #define Z_PARTIAL_FLUSH MZ_PARTIAL_FLUSH
277 #define Z_SYNC_FLUSH MZ_SYNC_FLUSH
278 #define Z_FULL_FLUSH MZ_FULL_FLUSH
279 #define Z_FINISH MZ_FINISH
280 #define Z_BLOCK MZ_BLOCK
282 #define Z_STREAM_END MZ_STREAM_END
283 #define Z_NEED_DICT MZ_NEED_DICT
284 #define Z_ERRNO MZ_ERRNO
285 #define Z_STREAM_ERROR MZ_STREAM_ERROR
286 #define Z_DATA_ERROR MZ_DATA_ERROR
287 #define Z_MEM_ERROR MZ_MEM_ERROR
288 #define Z_BUF_ERROR MZ_BUF_ERROR
289 #define Z_VERSION_ERROR MZ_VERSION_ERROR
290 #define Z_PARAM_ERROR MZ_PARAM_ERROR
291 #define Z_NO_COMPRESSION MZ_NO_COMPRESSION
292 #define Z_BEST_SPEED MZ_BEST_SPEED
293 #define Z_BEST_COMPRESSION MZ_BEST_COMPRESSION
294 #define Z_DEFAULT_COMPRESSION MZ_DEFAULT_COMPRESSION
295 #define Z_DEFAULT_STRATEGY MZ_DEFAULT_STRATEGY
296 #define Z_FILTERED MZ_FILTERED
297 #define Z_HUFFMAN_ONLY MZ_HUFFMAN_ONLY
299 #define Z_FIXED MZ_FIXED
300 #define Z_DEFLATED MZ_DEFLATED
301 #define Z_DEFAULT_WINDOW_BITS MZ_DEFAULT_WINDOW_BITS
302 #define alloc_func mz_alloc_func
303 #define free_func mz_free_func
304 #define internal_state mz_internal_state
305 #define z_stream mz_stream
306 #define deflateInit mz_deflateInit
307 #define deflateInit2 mz_deflateInit2
308 #define deflateReset mz_deflateReset
309 #define deflate mz_deflate
310 #define deflateEnd mz_deflateEnd
311 #define deflateBound mz_deflateBound
312 #define compress mz_compress
313 #define compress2 mz_compress2
314 #define compressBound mz_compressBound
315 #define inflateInit mz_inflateInit
316 #define inflateInit2 mz_inflateInit2
317 #define inflate mz_inflate
318 #define inflateEnd mz_inflateEnd
319 #define uncompress mz_uncompress
320 #define crc32 mz_crc32
321 #define adler32 mz_adler32
323 #define MAX_MEM_LEVEL 9
324 #define zError mz_error
325 #define ZLIB_VERSION MZ_VERSION
326 #define ZLIB_VERNUM MZ_VERNUM
327 #define ZLIB_VER_MAJOR MZ_VER_MAJOR
328 #define ZLIB_VER_MINOR MZ_VER_MINOR
329 #define ZLIB_VER_REVISION MZ_VER_REVISION
330 #define ZLIB_VER_SUBREVISION MZ_VER_SUBREVISION
331 #define zlibVersion mz_version
332 #define zlib_version mz_version()
353 #define MZ_MACRO_END while (0, 0)
355 #define MZ_MACRO_END while (0)
385 #define TINFL_DECOMPRESS_MEM_TO_MEM_FAILED ((size_t)(-1))
396 #define TINFL_LZ_DICT_SIZE 32768
410 #define tinfl_init(r) do { (r)->m_state = 0; } MZ_MACRO_END
411 #define tinfl_get_adler32(r) (r)->m_check_adler32
430 #if MINIZ_HAS_64BIT_REGISTERS
431 #define TINFL_USE_64BIT_BITBUF 1
434 #if TINFL_USE_64BIT_BITBUF
436 #define TINFL_BITBUF_SIZE (64)
439 #define TINFL_BITBUF_SIZE (32)
444 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];
454 #define TDEFL_LESS_MEMORY 0
497 size_t tdefl_compress_mem_to_mem(
void *pOut_buf,
size_t out_buf_len,
const void *pSrc_buf,
size_t src_buf_len,
int flags);
521 #if TDEFL_LESS_MEMORY
555 mz_uint m_saved_match_dist, m_saved_match_len, m_saved_lit, m_output_flush_ofs, m_output_flush_remaining, m_finished,
m_block_index, m_wants_to_finish;
591 #ifndef MINIZ_NO_ZLIB_APIS
605 #ifndef MINIZ_HEADER_FILE_ONLY
617 #define MZ_ASSERT(x) assert(x)
619 #ifdef MINIZ_NO_MALLOC
620 #define MZ_MALLOC(x) NULL
621 #define MZ_FREE(x) (void)x, ((void)0)
622 #define MZ_REALLOC(p, x) NULL
624 #define MZ_MALLOC(x) malloc(x)
625 #define MZ_FREE(x) free(x)
626 #define MZ_REALLOC(p, x) realloc(p, x)
629 #define MZ_MAX(a,b) (((a)>(b))?(a):(b))
630 #define MZ_MIN(a,b) (((a)<(b))?(a):(b))
631 #define MZ_CLEAR_OBJ(obj) memset(&(obj), 0, sizeof(obj))
633 #if MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN
634 #define MZ_READ_LE16(p) *((const mz_uint16 *)(p))
635 #define MZ_READ_LE32(p) *((const mz_uint32 *)(p))
637 #define MZ_READ_LE16(p) ((mz_uint32)(((const mz_uint8 *)(p))[0]) | ((mz_uint32)(((const mz_uint8 *)(p))[1]) << 8U))
638 #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))
642 #define MZ_FORCEINLINE __forceinline
643 #elif defined(__GNUC__)
644 #define MZ_FORCEINLINE inline __attribute__((__always_inline__))
646 #define MZ_FORCEINLINE inline
654 if (!ptr)
return MZ_ADLER32_INIT;
656 for (i = 0; i + 7 < block_len; i += 8, ptr += 8) {
657 s1 += ptr[0], s2 += s1; s1 += ptr[1], s2 += s1; s1 += ptr[2], s2 += s1; s1 += ptr[3], s2 += s1;
658 s1 += ptr[4], s2 += s1; s1 += ptr[5], s2 += s1; s1 += ptr[6], s2 += s1; s1 += ptr[7], s2 += s1;
660 for (; i < block_len; ++i) s1 += *ptr++, s2 += s1;
661 s1 %= 65521U, s2 %= 65521U; buf_len -= block_len; block_len = 5552;
663 return (s2 << 16) + s1;
669 static const mz_uint32 s_crc32[16] = { 0, 0x1db71064, 0x3b6e20c8, 0x26d930ac, 0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c,
670 0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c, 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c };
672 if (!ptr)
return MZ_CRC32_INIT;
673 crcu32 = ~crcu32;
while (buf_len--) {
mz_uint8 b = *ptr++; crcu32 = (crcu32 >> 4) ^ s_crc32[(crcu32 & 0xF) ^ (b & 0xF)]; crcu32 = (crcu32 >> 4) ^ s_crc32[(crcu32 & 0xF) ^ (b >> 4)]; }
682 #ifndef MINIZ_NO_ZLIB_APIS
684 static void *
def_alloc_func(
void *opaque,
size_t items,
size_t size) { (void)opaque, (
void)items, (void)size;
return MZ_MALLOC(items * size); }
685 static void def_free_func(
void *opaque,
void *address) { (void)opaque, (
void)address; MZ_FREE(address); }
704 if ((method != MZ_DEFLATED) || ((mem_level < 1) || (mem_level > 9)) || ((window_bits != MZ_DEFAULT_WINDOW_BITS) && (-window_bits != MZ_DEFAULT_WINDOW_BITS)))
return MZ_PARAM_ERROR;
707 pStream->
adler = MZ_ADLER32_INIT;
719 pStream->
state = (
struct mz_internal_state *)pComp;
739 size_t in_bytes, out_bytes;
740 mz_ulong orig_total_in, orig_total_out;
741 int mz_status =
MZ_OK;
763 if (defl_status < 0) {
774 if ((flush) || (pStream->
total_in != orig_total_in) || (pStream->
total_out != orig_total_out))
785 if (pStream->
state) {
787 pStream->
state = NULL;
796 mz_uint64 a = 128ULL + (source_len * 110ULL) / 100ULL;
797 mz_uint64 b = 128ULL + (
mz_uint64)source_len + ((source_len / (31 * 1024)) + 1ULL) * 5ULL;
810 memset(&stream, 0,
sizeof(stream));
813 if ((source_len | *pDest_len) > 0xFFFFFFFFU)
return MZ_PARAM_ERROR;
821 if (status !=
MZ_OK)
return status;
855 if ((window_bits != MZ_DEFAULT_WINDOW_BITS) && (-window_bits != MZ_DEFAULT_WINDOW_BITS))
return MZ_PARAM_ERROR;
869 pStream->
state = (
struct mz_internal_state *)pDecomp;
891 size_t in_bytes, out_bytes, orig_avail_in;
908 if ((flush ==
MZ_FINISH) && (first_call)) {
939 out_bytes = TINFL_LZ_DICT_SIZE - pState->
m_dict_ofs;
982 if (pStream->
state) {
984 pStream->
state = NULL;
993 memset(&stream, 0,
sizeof(stream));
996 if ((source_len | *pDest_len) > 0xFFFFFFFFU)
return MZ_PARAM_ERROR;
1004 if (status !=
MZ_OK)
1019 static struct {
int m_err;
const char *m_pDesc; } s_error_descs[] =
1021 {
MZ_OK,
"" }, {
MZ_STREAM_END,
"stream end" }, {
MZ_NEED_DICT,
"need dictionary" }, {
MZ_ERRNO,
"file error" }, {
MZ_STREAM_ERROR,
"stream error" },
1024 mz_uint i;
for (i = 0; i <
sizeof(s_error_descs) /
sizeof(s_error_descs[0]); ++i)
if (s_error_descs[i].m_err == err)
return s_error_descs[i].m_pDesc;
1032 #define TINFL_MEMCPY(d, s, l) memcpy(d, s, l)
1033 #define TINFL_MEMSET(p, c, l) memset(p, c, l)
1035 #define TINFL_CR_BEGIN switch(r->m_state) { case 0:
1036 #define TINFL_CR_RETURN(state_index, result) do { status = result; r->m_state = state_index; goto common_exit; case state_index:; } MZ_MACRO_END
1037 #define TINFL_CR_RETURN_FOREVER(state_index, result) do { for ( ; ; ) { TINFL_CR_RETURN(state_index, result); } } MZ_MACRO_END
1038 #define TINFL_CR_FINISH }
1042 #define TINFL_GET_BYTE(state_index, c) do { \
1043 if (pIn_buf_cur >= pIn_buf_end) { \
1045 if (decomp_flags & TINFL_FLAG_HAS_MORE_INPUT) { \
1046 TINFL_CR_RETURN(state_index, TINFL_STATUS_NEEDS_MORE_INPUT); \
1047 if (pIn_buf_cur < pIn_buf_end) { \
1048 c = *pIn_buf_cur++; \
1056 } else c = *pIn_buf_cur++; } MZ_MACRO_END
1058 #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))
1059 #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
1060 #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
1066 #define TINFL_HUFF_BITBUF_FILL(state_index, pHuff) \
1068 temp = (pHuff)->m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]; \
1070 code_len = temp >> 9; \
1071 if ((code_len) && (num_bits >= code_len)) \
1073 } else if (num_bits > TINFL_FAST_LOOKUP_BITS) { \
1074 code_len = TINFL_FAST_LOOKUP_BITS; \
1076 temp = (pHuff)->m_tree[~temp + ((bit_buf >> code_len++) & 1)]; \
1077 } while ((temp < 0) && (num_bits >= (code_len + 1))); if (temp >= 0) break; \
1078 } TINFL_GET_BYTE(state_index, c); bit_buf |= (((tinfl_bit_buf_t)c) << num_bits); num_bits += 8; \
1079 } while (num_bits < 15);
1085 #define TINFL_HUFF_DECODE(state_index, sym, pHuff) do { \
1086 int temp; mz_uint code_len, c; \
1087 if (num_bits < 15) { \
1088 if ((pIn_buf_end - pIn_buf_cur) < 2) { \
1089 TINFL_HUFF_BITBUF_FILL(state_index, pHuff); \
1091 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; \
1094 if ((temp = (pHuff)->m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]) >= 0) \
1095 code_len = temp >> 9, temp &= 511; \
1097 code_len = TINFL_FAST_LOOKUP_BITS; do { temp = (pHuff)->m_tree[~temp + ((bit_buf >> code_len++) & 1)]; } while (temp < 0); \
1098 } sym = temp; bit_buf >>= code_len; num_bits -= code_len; } MZ_MACRO_END
1102 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 };
1103 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 };
1104 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 };
1105 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 };
1106 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 };
1107 static const int s_min_table_sizes[3] = { 257, 1, 4 };
1110 const mz_uint8 *pIn_buf_cur = pIn_buf_next, *
const pIn_buf_end = pIn_buf_next + *pIn_buf_size;
1111 mz_uint8 *pOut_buf_cur = pOut_buf_next, *
const pOut_buf_end = pOut_buf_next + *pOut_buf_size;
1115 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; }
1131 TINFL_SKIP_BITS(5, num_bits & 7);
1132 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]); }
1134 while ((counter) && (num_bits)) {
1135 TINFL_GET_BITS(51, dist, 8);
1142 while (pIn_buf_cur >= pIn_buf_end) {
1150 n = MZ_MIN(MZ_MIN((
size_t)(pOut_buf_end - pOut_buf_cur), (
size_t)(pIn_buf_end - pIn_buf_cur)), counter);
1151 TINFL_MEMCPY(pOut_buf_cur, pIn_buf_cur, n); pIn_buf_cur += n; pOut_buf_cur += n; counter -= (
mz_uint)n;
1154 else if (r->
m_type == 3) {
1161 for (i = 0; i <= 143; ++i) {
1164 for (; i <= 255; ++i) {
1167 for (; i <= 279; ++i) {
1170 for (; i <= 287; ++i) {
1175 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]; }
1181 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);
1183 used_syms = 0, total = 0; next_code[0] = next_code[1] = 0;
1184 for (i = 1; i <= 15; ++i) { used_syms += total_syms[i]; next_code[i + 1] = (total = ((total + total_syms[i]) << 1)); }
1185 if ((65536 != total) && (used_syms > 1)) {
1188 for (tree_next = -1, sym_index = 0; sym_index < r->
m_table_sizes[r->
m_type]; ++sym_index) {
1189 mz_uint rev_code = 0, l, cur_code, code_size = pTable->
m_code_size[sym_index];
if (!code_size)
continue;
1190 cur_code = next_code[code_size]++;
for (l = code_size; l > 0; l--, cur_code >>= 1) rev_code = (rev_code << 1) | (cur_code & 1);
1195 tree_cur -= ((rev_code >>= 1) & 1);
1196 if (!pTable->
m_tree[-tree_cur - 1]) { pTable->
m_tree[-tree_cur - 1] = (
mz_int16)tree_next; tree_cur = tree_next; tree_next -= 2; }
1197 else tree_cur = pTable->
m_tree[-tree_cur - 1];
1199 tree_cur -= ((rev_code >>= 1) & 1); pTable->
m_tree[-tree_cur - 1] = (
mz_int16)sym_index;
1204 if ((dist == 16) && (!counter)) {
1207 num_extra =
"\02\03\07"[dist - 16]; TINFL_GET_BITS(18, s, num_extra); s +=
"\03\03\013"[dist - 16];
1219 if (((pIn_buf_end - pIn_buf_cur) < 4) || ((pOut_buf_end - pOut_buf_cur) < 2)) {
1220 TINFL_HUFF_DECODE(23, counter, &r->
m_tables[0]);
1224 *pOut_buf_cur++ = (
mz_uint8)counter;
1228 #if TINFL_USE_64BIT_BITBUF
1229 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; }
1231 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; }
1234 code_len = sym2 >> 9;
1238 counter = sym2; bit_buf >>= code_len; num_bits -= code_len;
1242 #if !TINFL_USE_64BIT_BITBUF
1243 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; }
1246 code_len = sym2 >> 9;
1250 bit_buf >>= code_len; num_bits -= code_len;
1252 pOut_buf_cur[0] = (
mz_uint8)counter;
1262 if ((counter &= 511) == 256)
break;
1264 num_extra = s_length_extra[counter - 257]; counter = s_length_base[counter - 257];
1265 if (num_extra) {
mz_uint extra_bits; TINFL_GET_BITS(25, extra_bits, num_extra); counter += extra_bits; }
1267 TINFL_HUFF_DECODE(26, dist, &r->
m_tables[1]);
1268 num_extra = s_dist_extra[dist]; dist = s_dist_base[dist];
1269 if (num_extra) {
mz_uint extra_bits; TINFL_GET_BITS(27, extra_bits, num_extra); dist += extra_bits; }
1271 dist_from_out_buf_start = pOut_buf_cur - pOut_buf_start;
1276 pSrc = pOut_buf_start + ((dist_from_out_buf_start - dist) & out_buf_size_mask);
1278 if ((MZ_MAX(pOut_buf_cur, pSrc) + counter) > pOut_buf_end) {
1281 *pOut_buf_cur++ = pOut_buf_start[(dist_from_out_buf_start++ - dist) & out_buf_size_mask];
1285 #if MINIZ_USE_UNALIGNED_LOADS_AND_STORES
1286 else if ((counter >= 9) && (counter <= dist)) {
1287 const mz_uint8 *pSrc_end = pSrc + (counter & ~7);
1292 }
while ((pSrc += 8) < pSrc_end);
1293 if ((counter &= 7) < 3) {
1295 pOut_buf_cur[0] = pSrc[0];
1297 pOut_buf_cur[1] = pSrc[1];
1298 pOut_buf_cur += counter;
1305 pOut_buf_cur[0] = pSrc[0];
1306 pOut_buf_cur[1] = pSrc[1];
1307 pOut_buf_cur[2] = pSrc[2];
1308 pOut_buf_cur += 3; pSrc += 3;
1309 }
while ((
int)(counter -= 3) > 2);
1310 if ((
int)counter > 0) {
1311 pOut_buf_cur[0] = pSrc[0];
1312 if ((
int)counter > 1)
1313 pOut_buf_cur[1] = pSrc[1];
1314 pOut_buf_cur += counter;
1320 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; }
1327 *pIn_buf_size = pIn_buf_cur - pIn_buf_next; *pOut_buf_size = pOut_buf_cur - pOut_buf_next;
1330 const mz_uint8 *ptr = pOut_buf_next;
size_t buf_len = *pOut_buf_size;
1333 for (i = 0; i + 7 < block_len; i += 8, ptr += 8) {
1334 s1 += ptr[0], s2 += s1; s1 += ptr[1], s2 += s1; s1 += ptr[2], s2 += s1; s1 += ptr[3], s2 += s1;
1335 s1 += ptr[4], s2 += s1; s1 += ptr[5], s2 += s1; s1 += ptr[6], s2 += s1; s1 += ptr[7], s2 += s1;
1337 for (; i < block_len; ++i) s1 += *ptr++, s2 += s1;
1338 s1 %= 65521U, s2 %= 65521U; buf_len -= block_len; block_len = 5552;
1350 tinfl_decompressor decomp;
void *pBuf = NULL, *pNew_buf;
size_t src_buf_ofs = 0, out_buf_capacity = 0;
1352 tinfl_init(&decomp);
1354 size_t src_buf_size = src_buf_len - src_buf_ofs, dst_buf_size = out_buf_capacity - *pOut_len, new_out_buf_capacity;
1358 MZ_FREE(pBuf); *pOut_len = 0;
return NULL;
1360 src_buf_ofs += src_buf_size;
1361 *pOut_len += dst_buf_size;
1363 new_out_buf_capacity = out_buf_capacity * 2;
if (new_out_buf_capacity < 128) new_out_buf_capacity = 128;
1364 pNew_buf = MZ_REALLOC(pBuf, new_out_buf_capacity);
1366 MZ_FREE(pBuf); *pOut_len = 0;
return NULL;
1368 pBuf = pNew_buf; out_buf_capacity = new_out_buf_capacity;
1377 return (status !=
TINFL_STATUS_DONE) ? TINFL_DECOMPRESS_MEM_TO_MEM_FAILED : out_buf_len;
1384 mz_uint8 *pDict = (
mz_uint8 *)MZ_MALLOC(TINFL_LZ_DICT_SIZE);
size_t in_buf_ofs = 0, dict_ofs = 0;
1387 tinfl_init(&decomp);
1389 size_t in_buf_size = *pIn_buf_size - in_buf_ofs, dst_buf_size = TINFL_LZ_DICT_SIZE - dict_ofs;
1392 in_buf_ofs += in_buf_size;
1393 if ((dst_buf_size) && (!(*pPut_buf_func)(pDict + dict_ofs, (
int)dst_buf_size, pPut_buf_user)))
1399 dict_ofs = (dict_ofs + dst_buf_size) & (TINFL_LZ_DICT_SIZE - 1);
1402 *pIn_buf_size = in_buf_ofs;
1410 257,258,259,260,261,262,263,264,265,265,266,266,267,267,268,268,269,269,269,269,270,270,270,270,271,271,271,271,272,272,272,272,
1411 273,273,273,273,273,273,273,273,274,274,274,274,274,274,274,274,275,275,275,275,275,275,275,275,276,276,276,276,276,276,276,276,
1412 277,277,277,277,277,277,277,277,277,277,277,277,277,277,277,277,278,278,278,278,278,278,278,278,278,278,278,278,278,278,278,278,
1413 279,279,279,279,279,279,279,279,279,279,279,279,279,279,279,279,280,280,280,280,280,280,280,280,280,280,280,280,280,280,280,280,
1414 281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,
1415 282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,
1416 283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,
1417 284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,285 };
1420 0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
1421 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
1422 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
1423 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,0 };
1426 0,1,2,3,4,4,5,5,6,6,6,6,7,7,7,7,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
1427 11,11,11,11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,13,
1428 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,14,14,14,14,14,14,14,14,14,14,14,14,
1429 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
1430 14,14,14,14,14,14,14,14,14,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
1431 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,16,16,16,16,16,16,16,16,16,16,16,16,16,
1432 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
1433 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
1434 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
1435 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
1436 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
1437 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17 };
1440 0,0,0,0,1,1,1,1,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,
1441 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
1442 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
1443 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
1444 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
1445 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
1446 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
1450 0,0,18,19,20,20,21,21,22,22,22,22,23,23,23,23,24,24,24,24,24,24,24,24,25,25,25,25,25,25,25,25,26,26,26,26,26,26,26,26,26,26,26,26,
1451 26,26,26,26,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,
1452 28,28,28,28,28,28,28,28,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29 };
1455 0,0,8,8,9,9,9,9,10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
1456 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
1457 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13 };
1463 mz_uint32 total_passes = 2, pass_shift, pass, i, hist[256 * 2];
tdefl_sym_freq *pCur_syms = pSyms0, *pNew_syms = pSyms1; MZ_CLEAR_OBJ(hist);
1464 for (i = 0; i < num_syms; i++) {
mz_uint freq = pSyms0[i].
m_key; hist[freq & 0xFF]++; hist[256 + ((freq >> 8) & 0xFF)]++; }
1465 while ((total_passes > 1) && (num_syms == hist[(total_passes - 1) * 256])) total_passes--;
1466 for (pass_shift = 0, pass = 0; pass < total_passes; pass++, pass_shift += 8) {
1467 const mz_uint32 *pHist = &hist[pass << 8];
1468 mz_uint offsets[256], cur_ofs = 0;
1469 for (i = 0; i < 256; i++) { offsets[i] = cur_ofs; cur_ofs += pHist[i]; }
1470 for (i = 0; i < num_syms; i++) pNew_syms[offsets[(pCur_syms[i].m_key >> pass_shift) & 0xFF]++] = pCur_syms[i];
1471 {
tdefl_sym_freq *t = pCur_syms; pCur_syms = pNew_syms; pNew_syms = t; }
1479 int root, leaf, next, avbl, used, dpth;
1480 if (n==0)
return;
else if (n==1) { A[0].
m_key = 1;
return; }
1481 A[0].
m_key += A[1].
m_key; root = 0; leaf = 2;
1482 for (next = 1; next < n-1; next++) {
1485 if (leaf>=n || (root<next && A[root].m_key<A[leaf].m_key)) { A[next].
m_key = (
mz_uint16)(A[next].m_key + A[root].m_key); A[root++].
m_key = (
mz_uint16)next; }
1486 else A[next].
m_key = (
mz_uint16)(A[next].m_key + A[leaf++].m_key);
1488 A[n-2].
m_key = 0;
for (next = n-3; next>=0; next--) A[next].m_key = A[A[next].m_key].m_key+1;
1489 avbl = 1; used = dpth = 0; root = n-2; next = n-1;
1491 while (root>=0 && (
int)A[root].
m_key==dpth) { used++; root--; }
1492 while (avbl>used) { A[next--].
m_key = (
mz_uint16)(dpth); avbl--; }
1493 avbl = 2*used; dpth++; used = 0;
1501 int i;
mz_uint32 total = 0;
if (code_list_len <= 1)
return;
1503 for (i = max_code_size; i > 0; i--) total += (((
mz_uint32)pNum_codes[i]) << (max_code_size - i));
1504 while (total != (1UL << max_code_size)) {
1505 pNum_codes[max_code_size]--;
1506 for (i = max_code_size - 1; i > 0; i--)
if (pNum_codes[i]) { pNum_codes[i]--; pNum_codes[i + 1] += 2;
break; }
1515 for (i = 0; i < table_len; i++) num_codes[d->m_huff_code_sizes[table_num][i]]++;
1519 int num_used_syms = 0;
1520 const mz_uint16 *pSym_count = &d->m_huff_count[table_num][0];
1525 for (i = 0; i < num_used_syms; ++i) num_codes[pSyms[i].m_key]++;
1529 MZ_CLEAR_OBJ(d->m_huff_code_sizes[table_num]); MZ_CLEAR_OBJ(d->m_huff_codes[table_num]);
1530 for (i = 1, j = num_used_syms; i <= code_size_limit; ++i)
1531 for (l = num_codes[i]; l > 0; l--) d->m_huff_code_sizes[table_num][pSyms[--j].
m_sym_index] = (
mz_uint8)(i);
1534 next_code[1] = 0;
for (j = 0, i = 2; i <= code_size_limit; ++i) next_code[i] = j = ((j + num_codes[i - 1]) << 1);
1536 for (i = 0; i < table_len; ++i) {
1537 mz_uint rev_code = 0, code, code_size;
if ((code_size = d->m_huff_code_sizes[table_num][i]) == 0)
continue;
1538 code = next_code[code_size]++;
for (l = code_size; l > 0; l--, code >>= 1) rev_code = (rev_code << 1) | (code & 1);
1539 d->m_huff_codes[table_num][i] = (
mz_uint16)rev_code;
1543 #define TDEFL_PUT_BITS(b, l) do { \
1544 mz_uint bits = b; mz_uint len = l; MZ_ASSERT(bits <= ((1U << len) - 1U)); \
1545 d->m_bit_buffer |= (bits << d->m_bits_in); d->m_bits_in += len; \
1546 while (d->m_bits_in >= 8) { \
1547 if (d->m_pOutput_buf < d->m_pOutput_buf_end) { \
1548 *d->m_pOutput_buf++ = (mz_uint8)(d->m_bit_buffer); \
1549 d->m_bit_buffer >>= 8; \
1550 d->m_bits_in -= 8; \
1555 #define TDEFL_RLE_PREV_CODE_SIZE() { if (rle_repeat_count) { \
1556 if (rle_repeat_count < 3) { \
1557 d->m_huff_count[2][prev_code_size] = (mz_uint16)(d->m_huff_count[2][prev_code_size] + rle_repeat_count); \
1558 while (rle_repeat_count--) packed_code_sizes[num_packed_code_sizes++] = prev_code_size; \
1560 d->m_huff_count[2][16] = (mz_uint16)(d->m_huff_count[2][16] + 1); packed_code_sizes[num_packed_code_sizes++] = 16; packed_code_sizes[num_packed_code_sizes++] = (mz_uint8)(rle_repeat_count - 3); \
1561 } rle_repeat_count = 0; } }
1563 #define TDEFL_RLE_ZERO_CODE_SIZE() { if (rle_z_count) { \
1564 if (rle_z_count < 3) { \
1565 d->m_huff_count[2][0] = (mz_uint16)(d->m_huff_count[2][0] + rle_z_count); while (rle_z_count--) packed_code_sizes[num_packed_code_sizes++] = 0; \
1566 } else if (rle_z_count <= 10) { \
1567 d->m_huff_count[2][17] = (mz_uint16)(d->m_huff_count[2][17] + 1); packed_code_sizes[num_packed_code_sizes++] = 17; packed_code_sizes[num_packed_code_sizes++] = (mz_uint8)(rle_z_count - 3); \
1569 d->m_huff_count[2][18] = (mz_uint16)(d->m_huff_count[2][18] + 1); packed_code_sizes[num_packed_code_sizes++] = 18; packed_code_sizes[num_packed_code_sizes++] = (mz_uint8)(rle_z_count - 11); \
1570 } rle_z_count = 0; } }
1572 static mz_uint8 s_tdefl_packed_code_size_syms_swizzle[] = { 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 };
1576 int num_lit_codes, num_dist_codes, num_bit_lengths;
mz_uint i, total_code_sizes_to_pack, num_packed_code_sizes, rle_z_count, rle_repeat_count, packed_code_sizes_index;
1579 d->m_huff_count[0][256] = 1;
1584 for (num_lit_codes = 286; num_lit_codes > 257; num_lit_codes--)
if (d->m_huff_code_sizes[0][num_lit_codes - 1])
break;
1585 for (num_dist_codes = 30; num_dist_codes > 1; num_dist_codes--)
if (d->m_huff_code_sizes[1][num_dist_codes - 1])
break;
1587 memcpy(code_sizes_to_pack, &d->m_huff_code_sizes[0][0], num_lit_codes);
1588 memcpy(code_sizes_to_pack + num_lit_codes, &d->m_huff_code_sizes[1][0], num_dist_codes);
1589 total_code_sizes_to_pack = num_lit_codes + num_dist_codes; num_packed_code_sizes = 0; rle_z_count = 0; rle_repeat_count = 0;
1592 for (i = 0; i < total_code_sizes_to_pack; ++i) {
1593 mz_uint8 code_size = code_sizes_to_pack[i];
1595 TDEFL_RLE_PREV_CODE_SIZE();
1596 if (++rle_z_count == 138) { TDEFL_RLE_ZERO_CODE_SIZE(); }
1599 TDEFL_RLE_ZERO_CODE_SIZE();
1600 if (code_size != prev_code_size) {
1601 TDEFL_RLE_PREV_CODE_SIZE();
1602 d->m_huff_count[2][code_size] = (
mz_uint16)(d->m_huff_count[2][code_size] + 1); packed_code_sizes[num_packed_code_sizes++] = code_size;
1604 else if (++rle_repeat_count == 6) {
1605 TDEFL_RLE_PREV_CODE_SIZE();
1608 prev_code_size = code_size;
1610 if (rle_repeat_count) { TDEFL_RLE_PREV_CODE_SIZE(); }
1611 else { TDEFL_RLE_ZERO_CODE_SIZE(); }
1615 TDEFL_PUT_BITS(2, 2);
1617 TDEFL_PUT_BITS(num_lit_codes - 257, 5);
1618 TDEFL_PUT_BITS(num_dist_codes - 1, 5);
1621 num_bit_lengths = MZ_MAX(4, (num_bit_lengths + 1)); TDEFL_PUT_BITS(num_bit_lengths - 4, 4);
1624 for (packed_code_sizes_index = 0; packed_code_sizes_index < num_packed_code_sizes; ) {
1626 TDEFL_PUT_BITS(d->m_huff_codes[2][code], d->m_huff_code_sizes[2][code]);
1627 if (code >= 16) TDEFL_PUT_BITS(packed_code_sizes[packed_code_sizes_index++],
"\02\03\07"[code - 16]);
1634 mz_uint8 *p = &d->m_huff_code_sizes[0][0];
1636 for (i = 0; i <= 143; ++i) *p++ = 8;
1637 for (; i <= 255; ++i) *p++ = 9;
1638 for (; i <= 279; ++i) *p++ = 7;
1639 for (; i <= 287; ++i) *p++ = 8;
1641 memset(d->m_huff_code_sizes[1], 5, 32);
1646 TDEFL_PUT_BITS(1, 2);
1649 static const mz_uint mz_bitmasks[17] = { 0x0000, 0x0001, 0x0003, 0x0007, 0x000F, 0x001F, 0x003F, 0x007F, 0x00FF, 0x01FF, 0x03FF, 0x07FF, 0x0FFF, 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF };
1651 #if MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN && MINIZ_HAS_64BIT_REGISTERS
1656 mz_uint8 *pOutput_buf = d->m_pOutput_buf;
1657 mz_uint8 *pLZ_code_buf_end = d->m_pLZ_code_buf;
1659 mz_uint bits_in = d->m_bits_in;
1661 #define TDEFL_PUT_BITS_FAST(b, l) { bit_buffer |= (((mz_uint64)(b)) << bits_in); bits_in += (l); }
1664 for (pLZ_codes = d->m_lz_code_buf; pLZ_codes < pLZ_code_buf_end; flags >>= 1) {
1666 flags = *pLZ_codes++ | 0x100;
1669 mz_uint s0, s1, n0, n1, sym, num_extra_bits;
1670 mz_uint match_len = pLZ_codes[0], match_dist = *(
const mz_uint16 *)(pLZ_codes + 1); pLZ_codes += 3;
1681 sym = (match_dist < 512) ? s0 : s1;
1682 num_extra_bits = (match_dist < 512) ? n0 : n1;
1684 MZ_ASSERT(d->m_huff_code_sizes[1][sym]);
1685 TDEFL_PUT_BITS_FAST(d->m_huff_codes[1][sym], d->m_huff_code_sizes[1][sym]);
1686 TDEFL_PUT_BITS_FAST(match_dist &
mz_bitmasks[num_extra_bits], num_extra_bits);
1690 MZ_ASSERT(d->m_huff_code_sizes[0][lit]);
1691 TDEFL_PUT_BITS_FAST(d->m_huff_codes[0][lit], d->m_huff_code_sizes[0][lit]);
1693 if (((flags & 2) == 0) && (pLZ_codes < pLZ_code_buf_end)) {
1696 MZ_ASSERT(d->m_huff_code_sizes[0][lit]);
1697 TDEFL_PUT_BITS_FAST(d->m_huff_codes[0][lit], d->m_huff_code_sizes[0][lit]);
1699 if (((flags & 2) == 0) && (pLZ_codes < pLZ_code_buf_end)) {
1702 MZ_ASSERT(d->m_huff_code_sizes[0][lit]);
1703 TDEFL_PUT_BITS_FAST(d->m_huff_codes[0][lit], d->m_huff_code_sizes[0][lit]);
1708 if (pOutput_buf >= d->m_pOutput_buf_end)
1712 pOutput_buf += (bits_in >> 3);
1713 bit_buffer >>= (bits_in & ~7);
1717 #undef TDEFL_PUT_BITS_FAST
1719 d->m_pOutput_buf = pOutput_buf;
1721 d->m_bit_buffer = 0;
1730 TDEFL_PUT_BITS(d->m_huff_codes[0][256], d->m_huff_code_sizes[0][256]);
1732 return (d->m_pOutput_buf < d->m_pOutput_buf_end);
1741 for (pLZ_codes = d->m_lz_code_buf; pLZ_codes < d->m_pLZ_code_buf; flags >>= 1) {
1743 flags = *pLZ_codes++ | 0x100;
1746 mz_uint match_len = pLZ_codes[0], match_dist = (pLZ_codes[1] | (pLZ_codes[2] << 8)); pLZ_codes += 3;
1752 if (match_dist < 512) {
1758 MZ_ASSERT(d->m_huff_code_sizes[1][sym]);
1759 TDEFL_PUT_BITS(d->m_huff_codes[1][sym], d->m_huff_code_sizes[1][sym]);
1760 TDEFL_PUT_BITS(match_dist &
mz_bitmasks[num_extra_bits], num_extra_bits);
1764 MZ_ASSERT(d->m_huff_code_sizes[0][lit]);
1765 TDEFL_PUT_BITS(d->m_huff_codes[0][lit], d->m_huff_code_sizes[0][lit]);
1769 TDEFL_PUT_BITS(d->m_huff_codes[0][256], d->m_huff_code_sizes[0][256]);
1771 return (d->m_pOutput_buf < d->m_pOutput_buf_end);
1786 mz_uint saved_bit_buf, saved_bits_in;
1788 mz_bool comp_block_succeeded = MZ_FALSE;
1789 int n, use_raw_block = ((d->m_flags &
TDEFL_FORCE_ALL_RAW_BLOCKS) != 0) && (d->m_lookahead_pos - d->m_lz_code_buf_dict_pos) <= d->m_dict_size;
1790 mz_uint8 *pOutput_buf_start = ((d->m_pPut_buf_func == NULL) && ((*d->m_pOut_buf_size - d->m_out_buf_ofs) >=
TDEFL_OUT_BUF_SIZE)) ? ((
mz_uint8 *)d->m_pOut_buf + d->m_out_buf_ofs) : d->m_output_buf;
1792 d->m_pOutput_buf = pOutput_buf_start;
1795 MZ_ASSERT(!d->m_output_flush_remaining);
1796 d->m_output_flush_ofs = 0;
1797 d->m_output_flush_remaining = 0;
1799 *d->m_pLZ_flags = (
mz_uint8)(*d->m_pLZ_flags >> d->m_num_flags_left);
1800 d->m_pLZ_code_buf -= (d->m_num_flags_left == 8);
1803 TDEFL_PUT_BITS(0x78, 8); TDEFL_PUT_BITS(0x01, 8);
1808 pSaved_output_buf = d->m_pOutput_buf; saved_bit_buf = d->m_bit_buffer; saved_bits_in = d->m_bits_in;
1814 if (((use_raw_block) || ((d->m_total_lz_bytes) && ((d->m_pOutput_buf - pSaved_output_buf + 1U) >= d->m_total_lz_bytes))) &&
1815 ((d->m_lookahead_pos - d->m_lz_code_buf_dict_pos) <= d->m_dict_size)) {
1816 mz_uint i; d->m_pOutput_buf = pSaved_output_buf; d->m_bit_buffer = saved_bit_buf, d->m_bits_in = saved_bits_in;
1817 TDEFL_PUT_BITS(0, 2);
1818 if (d->m_bits_in) { TDEFL_PUT_BITS(0, 8 - d->m_bits_in); }
1819 for (i = 2; i; --i, d->m_total_lz_bytes ^= 0xFFFF) {
1820 TDEFL_PUT_BITS(d->m_total_lz_bytes & 0xFFFF, 16);
1822 for (i = 0; i < d->m_total_lz_bytes; ++i) {
1827 else if (!comp_block_succeeded) {
1828 d->m_pOutput_buf = pSaved_output_buf; d->m_bit_buffer = saved_bit_buf, d->m_bits_in = saved_bits_in;
1834 if (d->m_bits_in) { TDEFL_PUT_BITS(0, 8 - d->m_bits_in); }
1835 if (d->m_flags &
TDEFL_WRITE_ZLIB_HEADER) {
mz_uint i, a = d->m_adler32;
for (i = 0; i < 4; ++i) { TDEFL_PUT_BITS((a >> 24) & 0xFF, 8); a <<= 8; } }
1838 mz_uint i, z = 0; TDEFL_PUT_BITS(0, 3);
if (d->m_bits_in) { TDEFL_PUT_BITS(0, 8 - d->m_bits_in); }
for (i = 2; i; --i, z ^= 0xFFFF) { TDEFL_PUT_BITS(z & 0xFFFF, 16); }
1842 MZ_ASSERT(d->m_pOutput_buf < d->m_pOutput_buf_end);
1847 d->m_pLZ_code_buf = d->m_lz_code_buf + 1; d->m_pLZ_flags = d->m_lz_code_buf; d->m_num_flags_left = 8; d->m_lz_code_buf_dict_pos += d->m_total_lz_bytes; d->m_total_lz_bytes = 0; d->m_block_index++;
1849 if ((n = (
int)(d->m_pOutput_buf - pOutput_buf_start)) != 0) {
1850 if (d->m_pPut_buf_func) {
1851 *d->m_pIn_buf_size = d->m_pSrc - (
const mz_uint8 *)d->m_pIn_buf;
1852 if (!(*d->m_pPut_buf_func)(d->m_output_buf, n, d->m_pPut_buf_user))
1855 else if (pOutput_buf_start == d->m_output_buf) {
1856 int bytes_to_copy = (int)MZ_MIN((
size_t)n, (size_t)(*d->m_pOut_buf_size - d->m_out_buf_ofs));
1857 memcpy((
mz_uint8 *)d->m_pOut_buf + d->m_out_buf_ofs, d->m_output_buf, bytes_to_copy);
1858 d->m_out_buf_ofs += bytes_to_copy;
1859 if ((n -= bytes_to_copy) != 0) {
1860 d->m_output_flush_ofs = bytes_to_copy;
1861 d->m_output_flush_remaining = n;
1865 d->m_out_buf_ofs += n;
1869 return d->m_output_flush_remaining;
1872 #if MINIZ_USE_UNALIGNED_LOADS_AND_STORES
1873 #define TDEFL_READ_UNALIGNED_WORD(p) *(const mz_uint16*)(p)
1877 mz_uint num_probes_left = d->m_max_probes[match_len >= 32];
1879 mz_uint16 c01 = TDEFL_READ_UNALIGNED_WORD(&d->m_dict[pos + match_len - 1]), s01 = TDEFL_READ_UNALIGNED_WORD(s);
1883 if (--num_probes_left == 0)
return;
1884 #define TDEFL_PROBE \
1885 next_probe_pos = d->m_next[probe_pos]; \
1886 if ((!next_probe_pos) || ((dist = (mz_uint16)(lookahead_pos - next_probe_pos)) > max_dist)) return; \
1887 probe_pos = next_probe_pos & TDEFL_LZ_DICT_SIZE_MASK; \
1888 if (TDEFL_READ_UNALIGNED_WORD(&d->m_dict[probe_pos + match_len - 1]) == c01) break;
1889 TDEFL_PROBE; TDEFL_PROBE; TDEFL_PROBE;
1894 q = (
const mz_uint16 *)(d->m_dict + probe_pos);
1895 if (TDEFL_READ_UNALIGNED_WORD(q) != s01) {
1898 p = s; probe_len = 32;
1899 do { }
while ((TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) && (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) &&
1900 (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) && (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) && (--probe_len > 0));
1905 *pMatch_dist = dist;
if ((*pMatch_len = match_len = MZ_MIN(max_match_len, probe_len)) == max_match_len)
break;
1906 c01 = TDEFL_READ_UNALIGNED_WORD(&d->m_dict[pos + match_len - 1]);
1914 mz_uint num_probes_left = d->m_max_probes[match_len >= 32];
1915 const mz_uint8 *s = d->m_dict + pos, *p, *q;
1916 mz_uint8 c0 = d->m_dict[pos + match_len], c1 = d->m_dict[pos + match_len - 1];
1920 if (--num_probes_left == 0)
return;
1921 #define TDEFL_PROBE \
1922 next_probe_pos = d->m_next[probe_pos]; \
1923 if ((!next_probe_pos) || ((dist = (mz_uint16)(lookahead_pos - next_probe_pos)) > max_dist)) return; \
1924 probe_pos = next_probe_pos & TDEFL_LZ_DICT_SIZE_MASK; \
1925 if ((d->m_dict[probe_pos + match_len] == c0) && (d->m_dict[probe_pos + match_len - 1] == c1)) break;
1926 TDEFL_PROBE; TDEFL_PROBE; TDEFL_PROBE;
1928 if (!dist)
break; p = s; q = d->m_dict + probe_pos;
for (probe_len = 0; probe_len < max_match_len; probe_len++)
if (*p++ != *q++)
break;
1929 if (probe_len > match_len) {
1930 *pMatch_dist = dist;
if ((*pMatch_len = match_len = probe_len) == max_match_len)
return;
1931 c0 = d->m_dict[pos + match_len]; c1 = d->m_dict[pos + match_len - 1];
1937 #if MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN
1938 static mz_bool tdefl_compress_fast(tdefl_compressor *d)
1941 mz_uint lookahead_pos = d->m_lookahead_pos, lookahead_size = d->m_lookahead_size, dict_size = d->m_dict_size, total_lz_bytes = d->m_total_lz_bytes, num_flags_left = d->m_num_flags_left;
1942 mz_uint8 *pLZ_code_buf = d->m_pLZ_code_buf, *pLZ_flags = d->m_pLZ_flags;
1945 while ((d->m_src_buf_left) || ((d->m_flush) && (lookahead_size))) {
1946 const mz_uint TDEFL_COMP_FAST_LOOKAHEAD_SIZE = 4096;
1948 mz_uint num_bytes_to_process = (
mz_uint)MZ_MIN(d->m_src_buf_left, TDEFL_COMP_FAST_LOOKAHEAD_SIZE - lookahead_size);
1949 d->m_src_buf_left -= num_bytes_to_process;
1950 lookahead_size += num_bytes_to_process;
1952 while (num_bytes_to_process) {
1954 memcpy(d->m_dict + dst_pos, d->m_pSrc, n);
1959 num_bytes_to_process -= n;
1963 if ((!d->m_flush) && (lookahead_size < TDEFL_COMP_FAST_LOOKAHEAD_SIZE))
break;
1965 while (lookahead_size >= 4) {
1966 mz_uint cur_match_dist, cur_match_len = 1;
1967 mz_uint8 *pCur_dict = d->m_dict + cur_pos;
1970 mz_uint probe_pos = d->m_hash[hash];
1971 d->m_hash[hash] = (
mz_uint16)lookahead_pos;
1977 do { }
while ((TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) && (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) &&
1978 (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) && (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) && (--probe_len > 0));
1985 *pLZ_code_buf++ = (
mz_uint8)first_trigram;
1986 *pLZ_flags = (
mz_uint8)(*pLZ_flags >> 1);
1987 d->m_huff_count[0][(
mz_uint8)first_trigram]++;
1991 cur_match_len = MZ_MIN(cur_match_len, lookahead_size);
2000 *pLZ_flags = (
mz_uint8)((*pLZ_flags >> 1) | 0x80);
2004 d->m_huff_count[1][(cur_match_dist < 512) ? s0 : s1]++;
2010 *pLZ_code_buf++ = (
mz_uint8)first_trigram;
2011 *pLZ_flags = (
mz_uint8)(*pLZ_flags >> 1);
2012 d->m_huff_count[0][(
mz_uint8)first_trigram]++;
2015 if (--num_flags_left == 0) { num_flags_left = 8; pLZ_flags = pLZ_code_buf++; }
2017 total_lz_bytes += cur_match_len;
2018 lookahead_pos += cur_match_len;
2021 MZ_ASSERT(lookahead_size >= cur_match_len);
2022 lookahead_size -= cur_match_len;
2026 d->m_lookahead_pos = lookahead_pos; d->m_lookahead_size = lookahead_size; d->m_dict_size = dict_size;
2027 d->m_total_lz_bytes = total_lz_bytes; d->m_pLZ_code_buf = pLZ_code_buf; d->m_pLZ_flags = pLZ_flags; d->m_num_flags_left = num_flags_left;
2029 return (n < 0) ? MZ_FALSE : MZ_TRUE;
2030 total_lz_bytes = d->m_total_lz_bytes; pLZ_code_buf = d->m_pLZ_code_buf; pLZ_flags = d->m_pLZ_flags; num_flags_left = d->m_num_flags_left;
2034 while (lookahead_size) {
2038 *pLZ_code_buf++ = lit;
2039 *pLZ_flags = (
mz_uint8)(*pLZ_flags >> 1);
2040 if (--num_flags_left == 0) { num_flags_left = 8; pLZ_flags = pLZ_code_buf++; }
2042 d->m_huff_count[0][lit]++;
2051 d->m_lookahead_pos = lookahead_pos; d->m_lookahead_size = lookahead_size; d->m_dict_size = dict_size;
2052 d->m_total_lz_bytes = total_lz_bytes; d->m_pLZ_code_buf = pLZ_code_buf; d->m_pLZ_flags = pLZ_flags; d->m_num_flags_left = num_flags_left;
2054 return (n < 0) ? MZ_FALSE : MZ_TRUE;
2055 total_lz_bytes = d->m_total_lz_bytes; pLZ_code_buf = d->m_pLZ_code_buf; pLZ_flags = d->m_pLZ_flags; num_flags_left = d->m_num_flags_left;
2060 d->m_lookahead_pos = lookahead_pos; d->m_lookahead_size = lookahead_size; d->m_dict_size = dict_size;
2061 d->m_total_lz_bytes = total_lz_bytes; d->m_pLZ_code_buf = pLZ_code_buf; d->m_pLZ_flags = pLZ_flags; d->m_num_flags_left = num_flags_left;
2068 d->m_total_lz_bytes++;
2069 *d->m_pLZ_code_buf++ = lit;
2070 *d->m_pLZ_flags = (
mz_uint8)(*d->m_pLZ_flags >> 1);
if (--d->m_num_flags_left == 0) { d->m_num_flags_left = 8; d->m_pLZ_flags = d->m_pLZ_code_buf++; }
2071 d->m_huff_count[0][lit]++;
2080 d->m_total_lz_bytes += match_len;
2085 d->m_pLZ_code_buf[1] = (
mz_uint8)(match_dist & 0xFF);
2086 d->m_pLZ_code_buf[2] = (
mz_uint8)(match_dist >> 8); d->m_pLZ_code_buf += 3;
2088 *d->m_pLZ_flags = (
mz_uint8)((*d->m_pLZ_flags >> 1) | 0x80);
if (--d->m_num_flags_left == 0) { d->m_num_flags_left = 8; d->m_pLZ_flags = d->m_pLZ_code_buf++; }
2091 d->m_huff_count[1][(match_dist < 512) ? s0 : s1]++;
2098 const mz_uint8 *pSrc = d->m_pSrc;
size_t src_buf_left = d->m_src_buf_left;
2101 while ((src_buf_left) || ((flush) && (d->m_lookahead_size))) {
2102 mz_uint len_to_move, cur_match_dist, cur_match_len, cur_pos;
2108 const mz_uint8 *pSrc_end = pSrc + num_bytes_to_process;
2109 src_buf_left -= num_bytes_to_process;
2110 d->m_lookahead_size += num_bytes_to_process;
2111 while (pSrc != pSrc_end) {
2123 d->m_dict[dst_pos] = c;
2127 mz_uint ins_pos = d->m_lookahead_pos + (d->m_lookahead_size - 1) - 2;
2142 cur_match_len = 0;
while (cur_match_len < d->m_lookahead_size) {
if (d->m_dict[cur_pos + cur_match_len] != c)
break; cur_match_len++; }
2147 tdefl_find_match(d, d->m_lookahead_pos, d->m_dict_size, d->m_lookahead_size, &cur_match_dist, &cur_match_len);
2150 cur_match_dist = cur_match_len = 0;
2152 if (d->m_saved_match_len) {
2153 if (cur_match_len > d->m_saved_match_len) {
2155 if (cur_match_len >= 128) {
2157 d->m_saved_match_len = 0; len_to_move = cur_match_len;
2160 d->m_saved_lit = d->m_dict[cur_pos]; d->m_saved_match_dist = cur_match_dist; d->m_saved_match_len = cur_match_len;
2165 len_to_move = d->m_saved_match_len - 1; d->m_saved_match_len = 0;
2168 else if (!cur_match_dist)
2170 else if ((d->m_greedy_parsing) || (d->m_flags &
TDEFL_RLE_MATCHES) || (cur_match_len >= 128)) {
2172 len_to_move = cur_match_len;
2175 d->m_saved_lit = d->m_dict[MZ_MIN(cur_pos,
sizeof(d->m_dict) - 1)]; d->m_saved_match_dist = cur_match_dist; d->m_saved_match_len = cur_match_len;
2178 d->m_lookahead_pos += len_to_move;
2179 MZ_ASSERT(d->m_lookahead_size >= len_to_move);
2180 d->m_lookahead_size -= len_to_move;
2184 ((d->m_total_lz_bytes > 31*1024) && (((((
mz_uint)(d->m_pLZ_code_buf - d->m_lz_code_buf) * 115) >> 7) >= d->m_total_lz_bytes) || (d->m_flags &
TDEFL_FORCE_ALL_RAW_BLOCKS)))) {
2186 d->m_pSrc = pSrc; d->m_src_buf_left = src_buf_left;
2188 return (n < 0) ? MZ_FALSE : MZ_TRUE;
2192 d->m_pSrc = pSrc; d->m_src_buf_left = src_buf_left;
2198 if (d->m_pIn_buf_size) {
2199 *d->m_pIn_buf_size = d->m_pSrc - (
const mz_uint8 *)d->m_pIn_buf;
2202 if (d->m_pOut_buf_size) {
2203 size_t n = MZ_MIN(*d->m_pOut_buf_size - d->m_out_buf_ofs, d->m_output_flush_remaining);
2204 memcpy((
mz_uint8 *)d->m_pOut_buf + d->m_out_buf_ofs, d->m_output_buf + d->m_output_flush_ofs, n);
2205 d->m_output_flush_ofs += (
mz_uint)n;
2206 d->m_output_flush_remaining -= (
mz_uint)n;
2207 d->m_out_buf_ofs += n;
2209 *d->m_pOut_buf_size = d->m_out_buf_ofs;
2218 if (pIn_buf_size) *pIn_buf_size = 0;
2219 if (pOut_buf_size) *pOut_buf_size = 0;
2223 d->m_pIn_buf = pIn_buf; d->m_pIn_buf_size = pIn_buf_size;
2224 d->m_pOut_buf = pOut_buf; d->m_pOut_buf_size = pOut_buf_size;
2225 d->m_pSrc = (
const mz_uint8 *)(pIn_buf); d->m_src_buf_left = pIn_buf_size ? *pIn_buf_size : 0;
2226 d->m_out_buf_ofs = 0;
2229 if (((d->m_pPut_buf_func != NULL) == ((pOut_buf != NULL) || (pOut_buf_size != NULL))) || (d->m_prev_return_status !=
TDEFL_STATUS_OKAY) ||
2230 (d->m_wants_to_finish && (flush !=
TDEFL_FINISH)) || (pIn_buf_size && *pIn_buf_size && !pIn_buf) || (pOut_buf_size && *pOut_buf_size && !pOut_buf)) {
2231 if (pIn_buf_size) *pIn_buf_size = 0;
2232 if (pOut_buf_size) *pOut_buf_size = 0;
2237 if ((d->m_output_flush_remaining) || (d->m_finished))
2240 #if MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN
2244 if (!tdefl_compress_fast(d))
2245 return d->m_prev_return_status;
2251 return d->m_prev_return_status;
2257 if ((flush) && (!d->m_lookahead_size) && (!d->m_src_buf_left) && (!d->m_output_flush_remaining)) {
2259 return d->m_prev_return_status;
2261 if (flush ==
TDEFL_FULL_FLUSH) { MZ_CLEAR_OBJ(d->m_hash); MZ_CLEAR_OBJ(d->m_next); d->m_dict_size = 0; }
2269 MZ_ASSERT(d->m_pPut_buf_func);
return tdefl_compress(d, pIn_buf, &in_buf_size, NULL, NULL, flush);
2274 d->m_pPut_buf_func = pPut_buf_func; d->m_pPut_buf_user = pPut_buf_user;
2276 d->m_max_probes[1] = 1 + (((flags & 0xFFF) >> 2) + 2) / 3;
2278 d->m_lookahead_pos = d->m_lookahead_size = d->m_dict_size = d->m_total_lz_bytes = d->m_lz_code_buf_dict_pos = d->m_bits_in = 0;
2279 d->m_output_flush_ofs = d->m_output_flush_remaining = d->m_finished = d->m_block_index = d->m_bit_buffer = d->m_wants_to_finish = 0;
2280 d->m_pLZ_code_buf = d->m_lz_code_buf + 1; d->m_pLZ_flags = d->m_lz_code_buf; d->m_num_flags_left = 8;
2281 d->m_pOutput_buf = d->m_output_buf; d->m_pOutput_buf_end = d->m_output_buf; d->m_prev_return_status =
TDEFL_STATUS_OKAY;
2282 d->m_saved_match_dist = d->m_saved_match_len = d->m_saved_lit = 0; d->m_adler32 = 1;
2283 d->m_pIn_buf = NULL; d->m_pOut_buf = NULL;
2284 d->m_pIn_buf_size = NULL; d->m_pOut_buf_size = NULL;
2285 d->m_flush =
TDEFL_NO_FLUSH; d->m_pSrc = NULL; d->m_src_buf_left = 0; d->m_out_buf_ofs = 0;
2293 return d->m_prev_return_status;
2298 return d->m_adler32;
2307 MZ_FREE(pComp);
return succeeded;
2320 size_t new_size = p->
m_size + len;
2323 do { new_capacity = MZ_MAX(128U, new_capacity << 1U); }
while (new_size > new_capacity);
2324 pNew_buf = (
mz_uint8 *)MZ_REALLOC(p->
m_pBuf, new_capacity);
if (!pNew_buf)
return MZ_FALSE;
2334 if (!pOut_len)
return MZ_FALSE;
else *pOut_len = 0;
2343 if (!pOut_buf)
return 0;
2349 #ifndef MINIZ_NO_ZLIB_APIS
2350 static const mz_uint s_tdefl_num_probes[11] = { 0, 1, 6, 32, 16, 32, 128, 256, 512, 768, 1500 };
2369 #pragma warning (push)
2370 #pragma warning (disable:4204)
2379 static const mz_uint s_tdefl_png_num_probes[11] = { 0, 1, 6, 32, 16, 32, 128, 256, 512, 768, 1500 };
2381 if (!pComp)
return NULL;
2390 *pLen_out = out_buf.
m_size-41;
2392 static const mz_uint8 chans[] = { 0x00, 0x00, 0x04, 0x02, 0x06 };
2393 mz_uint8 pnghdr[41] = { 0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52,
2394 0,0,(
mz_uint8)(w>>8),(
mz_uint8)w,0,0,(
mz_uint8)(h>>8),(
mz_uint8)h,8,chans[num_chans],0,0,0,0,0,0,0,
2397 memcpy(out_buf.
m_pBuf, pnghdr, 41);
2400 if (!
tdefl_output_buffer_putter(
"\0\0\0\0\0\0\0\0\x49\x45\x4e\x44\xae\x42\x60\x82", 16, &out_buf)) { *pLen_out = 0; MZ_FREE(pComp); MZ_FREE(out_buf.
m_pBuf);
return NULL; }
2403 *pLen_out += 57; MZ_FREE(pComp);
return out_buf.
m_pBuf;
2412 #pragma warning (pop)
int mz_deflateInit(mz_streamp pStream, int level)
@ TDEFL_DEFAULT_MAX_PROBES
void * tdefl_write_image_to_png_file_in_memory(const void *pImage, int w, int h, int num_chans, size_t *pLen_out)
tdefl_status tdefl_compress(tdefl_compressor *d, const void *pIn_buf, size_t *pIn_buf_size, void *pOut_buf, size_t *pOut_buf_size, tdefl_flush flush)
int mz_deflateEnd(mz_streamp pStream)
unsigned char mz_validate_uint32[sizeof(mz_uint32)==4 ? 1 :-1]
mz_ulong mz_crc32(mz_ulong crc, const unsigned char *ptr, size_t buf_len)
static void tdefl_optimize_huffman_table(tdefl_compressor *d, int table_num, int table_len, int code_size_limit, int static_table)
static int tdefl_flush_block(tdefl_compressor *d, int flush)
int mz_inflateEnd(mz_streamp pStream)
static mz_bool tdefl_compress_block(tdefl_compressor *d, mz_bool static_block)
static const mz_uint8 s_tdefl_small_dist_extra[512]
size_t tdefl_compress_mem_to_mem(void *pOut_buf, size_t out_buf_len, const void *pSrc_buf, size_t src_buf_len, int flags)
mz_uint tdefl_create_comp_flags_from_zip_params(int level, int window_bits, int strategy)
size_t tinfl_decompress_mem_to_mem(void *pOut_buf, size_t out_buf_len, const void *pSrc_buf, size_t src_buf_len, int flags)
void * tdefl_compress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags)
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)
int mz_inflate(mz_streamp pStream, int flush)
const char * mz_version(void)
@ TDEFL_LEVEL1_HASH_SIZE_MASK
@ TDEFL_LZ_DICT_SIZE_MASK
@ TDEFL_MAX_HUFF_SYMBOLS_2
@ TDEFL_MAX_HUFF_SYMBOLS_0
@ TDEFL_MAX_HUFF_SYMBOLS_1
void * tinfl_decompress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags)
static void tdefl_huffman_enforce_max_code_size(int *pNum_codes, int code_list_len, int max_code_size)
static const mz_uint8 s_tdefl_large_dist_extra[128]
int mz_inflateInit2(mz_streamp pStream, int window_bits)
int mz_compress2(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len, int level)
static const mz_uint8 s_tdefl_small_dist_sym[512]
int mz_deflate(mz_streamp pStream, int flush)
static const mz_uint8 s_tdefl_len_extra[256]
static mz_bool tdefl_output_buffer_putter(const void *pBuf, int len, void *pUser)
static tdefl_sym_freq * tdefl_radix_sort_syms(mz_uint num_syms, tdefl_sym_freq *pSyms0, tdefl_sym_freq *pSyms1)
static void tdefl_calculate_minimum_redundancy(tdefl_sym_freq *A, int n)
mz_ulong mz_adler32(mz_ulong adler, const unsigned char *ptr, size_t buf_len)
@ TDEFL_NONDETERMINISTIC_PARSING_FLAG
@ TDEFL_GREEDY_PARSING_FLAG
@ TDEFL_FORCE_ALL_RAW_BLOCKS
@ TDEFL_WRITE_ZLIB_HEADER
@ TDEFL_FORCE_ALL_STATIC_BLOCKS
static void tdefl_start_static_block(tdefl_compressor *d)
@ TDEFL_STATUS_PUT_BUF_FAILED
static const mz_uint s_tdefl_num_probes[11]
const char * mz_error(int err)
static void tdefl_start_dynamic_block(tdefl_compressor *d)
static mz_bool tdefl_compress_lz_codes(tdefl_compressor *d)
tdefl_status tdefl_init(tdefl_compressor *d, tdefl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags)
static mz_bool tdefl_compress_normal(tdefl_compressor *d)
mz_bool(* tdefl_put_buf_func_ptr)(const void *pBuf, int len, void *pUser)
static MZ_FORCEINLINE void tdefl_record_match(tdefl_compressor *d, mz_uint match_len, mz_uint match_dist)
@ TDEFL_MAX_SUPPORTED_HUFF_CODESIZE
int mz_inflateInit(mz_streamp pStream)
static const mz_uint16 s_tdefl_len_sym[256]
mz_ulong mz_compressBound(mz_ulong source_len)
tdefl_status tdefl_get_prev_return_status(tdefl_compressor *d)
static const mz_uint mz_bitmasks[17]
unsigned char mz_validate_uint64[sizeof(mz_uint64)==8 ? 1 :-1]
static tdefl_status tdefl_flush_output_buffer(tdefl_compressor *d)
static const mz_uint8 s_tdefl_large_dist_sym[128]
int tinfl_decompress_mem_to_callback(const void *pIn_buf, size_t *pIn_buf_size, tinfl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags)
static void def_free_func(void *opaque, void *address)
@ TINFL_FLAG_COMPUTE_ADLER32
@ TINFL_FLAG_HAS_MORE_INPUT
@ TINFL_FLAG_PARSE_ZLIB_HEADER
@ TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF
mz_uint32 tinfl_bit_buf_t
unsigned long long mz_uint64
mz_ulong mz_deflateBound(mz_streamp pStream, mz_ulong source_len)
int mz_compress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len)
mz_uint32 tdefl_get_adler32(tdefl_compressor *d)
static MZ_FORCEINLINE void tdefl_find_match(tdefl_compressor *d, mz_uint lookahead_pos, mz_uint max_dist, mz_uint max_match_len, mz_uint *pMatch_dist, mz_uint *pMatch_len)
int mz_deflateInit2(mz_streamp pStream, int level, int method, int window_bits, int mem_level, int strategy)
int(* tinfl_put_buf_func_ptr)(const void *pBuf, int len, void *pUser)
void(* mz_free_func)(void *opaque, void *address)
int mz_uncompress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len)
int mz_inflate2(mz_streamp pStream, int flush, int adler32_checking)
struct buminiz::mz_stream_s mz_stream
tdefl_status tdefl_compress_buffer(tdefl_compressor *d, const void *pIn_buf, size_t in_buf_size, tdefl_flush flush)
void * tdefl_write_image_to_png_file_in_memory_ex(const void *pImage, int w, int h, int num_chans, size_t *pLen_out, mz_uint level, mz_bool flip)
static mz_uint8 s_tdefl_packed_code_size_syms_swizzle[]
unsigned char mz_validate_uint16[sizeof(mz_uint16)==2 ? 1 :-1]
struct tinfl_decompressor_tag tinfl_decompressor
@ TINFL_STATUS_ADLER32_MISMATCH
@ TINFL_STATUS_HAS_MORE_OUTPUT
@ TINFL_STATUS_NEEDS_MORE_INPUT
@ TINFL_MAX_HUFF_SYMBOLS_1
@ TINFL_MAX_HUFF_SYMBOLS_0
@ TINFL_MAX_HUFF_SYMBOLS_2
static MZ_FORCEINLINE void tdefl_record_literal(tdefl_compressor *d, mz_uint8 lit)
static void * def_alloc_func(void *opaque, size_t items, size_t size)
mz_bool tdefl_compress_mem_to_output(const void *pBuf, size_t buf_len, tdefl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags)
int mz_deflateReset(mz_streamp pStream)
void *(* mz_alloc_func)(void *opaque, size_t items, size_t size)
mz_uint8 m_dict[TINFL_LZ_DICT_SIZE]
tinfl_status m_last_status
tinfl_decompressor m_decomp
struct mz_internal_state * state
const unsigned char * next_in
tdefl_status m_prev_return_status
mz_uint8 * m_pLZ_code_buf
tdefl_put_buf_func_ptr m_pPut_buf_func
size_t m_dist_from_out_buf_start
mz_uint8 m_len_codes[TINFL_MAX_HUFF_SYMBOLS_0+TINFL_MAX_HUFF_SYMBOLS_1+137]
mz_uint32 m_check_adler32
tinfl_bit_buf_t m_bit_buf
mz_uint32 m_table_sizes[TINFL_MAX_HUFF_TABLES]
tinfl_huff_table m_tables[TINFL_MAX_HUFF_TABLES]
mz_int16 m_look_up[TINFL_FAST_LOOKUP_SIZE]
mz_int16 m_tree[TINFL_MAX_HUFF_SYMBOLS_0 *2]
mz_uint8 m_code_size[TINFL_MAX_HUFF_SYMBOLS_0]