R-PAGE
Resistance's Portable-Adventure-Game-Engine
Data Structures | Macros | Typedefs | Enumerations | Functions
tinfl.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

Go to the source code of this file.

Data Structures

struct  tinfl_huff_table
 
struct  tinfl_decompressor_tag
 

Macros

#define TINFL_HEADER_INCLUDED
 
#define MZ_MACRO_END   while (0)
 
#define TINFL_DECOMPRESS_MEM_TO_MEM_FAILED   ((size_t)(-1))
 
#define TINFL_LZ_DICT_SIZE   32768
 
#define tinfl_init(r)   do { (r)->m_state = 0; } MZ_MACRO_END
 
#define tinfl_get_adler32(r)   (r)->m_check_adler32
 
#define TINFL_BITBUF_SIZE   (32)
 
#define MZ_MALLOC(x)   malloc(x)
 
#define MZ_FREE(x)   free(x)
 
#define MZ_REALLOC(p, x)   realloc(p, x)
 
#define MZ_MAX(a, b)   (((a)>(b))?(a):(b))
 
#define MZ_MIN(a, b)   (((a)<(b))?(a):(b))
 
#define MZ_CLEAR_OBJ(obj)   memset(&(obj), 0, sizeof(obj))
 
#define MZ_READ_LE16(p)   ((mz_uint32)(((const mz_uint8 *)(p))[0]) | ((mz_uint32)(((const mz_uint8 *)(p))[1]) << 8U))
 
#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))
 
#define TINFL_MEMCPY(d, s, l)   memcpy(d, s, l)
 
#define TINFL_MEMSET(p, c, l)   memset(p, c, l)
 
#define TINFL_CR_BEGIN   switch(r->m_state) { case 0:
 
#define TINFL_CR_RETURN(state_index, result)   do { status = result; r->m_state = state_index; goto common_exit; case state_index:; } MZ_MACRO_END
 
#define TINFL_CR_RETURN_FOREVER(state_index, result)   do { for ( ; ; ) { TINFL_CR_RETURN(state_index, result); } } MZ_MACRO_END
 
#define TINFL_CR_FINISH   }
 
#define TINFL_GET_BYTE(state_index, c)
 
#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))
 
#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
 
#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
 
#define TINFL_HUFF_BITBUF_FILL(state_index, pHuff)
 
#define TINFL_HUFF_DECODE(state_index, sym, pHuff)
 

Typedefs

typedef unsigned char mz_uint8
 
typedef signed short mz_int16
 
typedef unsigned short mz_uint16
 
typedef unsigned int mz_uint32
 
typedef unsigned int mz_uint
 
typedef unsigned long mz_uint64
 
typedef int(* tinfl_put_buf_func_ptr) (const void *pBuf, int len, void *pUser)
 
typedef struct tinfl_decompressor_tag tinfl_decompressor
 
typedef mz_uint32 tinfl_bit_buf_t
 

Enumerations

enum  { TINFL_FLAG_PARSE_ZLIB_HEADER = 1, TINFL_FLAG_HAS_MORE_INPUT = 2, TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF = 4, TINFL_FLAG_COMPUTE_ADLER32 = 8 }
 
enum  tinfl_status {
  TINFL_STATUS_BAD_PARAM = -3, TINFL_STATUS_ADLER32_MISMATCH = -2, TINFL_STATUS_FAILED = -1, TINFL_STATUS_DONE = 0,
  TINFL_STATUS_NEEDS_MORE_INPUT = 1, TINFL_STATUS_HAS_MORE_OUTPUT = 2
}
 
enum  {
  TINFL_MAX_HUFF_TABLES = 3, TINFL_MAX_HUFF_SYMBOLS_0 = 288, TINFL_MAX_HUFF_SYMBOLS_1 = 32, TINFL_MAX_HUFF_SYMBOLS_2 = 19,
  TINFL_FAST_LOOKUP_BITS = 10, TINFL_FAST_LOOKUP_SIZE = 1 << TINFL_FAST_LOOKUP_BITS
}
 

Functions

void tinflDiag (void)
 
void * tinfl_decompress_mem_to_heap (const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags)
 
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)
 
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)
 
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)
 

Macro Definition Documentation

#define MZ_CLEAR_OBJ (   obj)    memset(&(obj), 0, sizeof(obj))

Definition at line 155 of file tinfl.c.

#define MZ_FREE (   x)    free(x)

Definition at line 149 of file tinfl.c.

#define MZ_MACRO_END   while (0)

Definition at line 37 of file tinfl.c.

#define MZ_MALLOC (   x)    malloc(x)

Definition at line 148 of file tinfl.c.

#define MZ_MAX (   a,
 
)    (((a)>(b))?(a):(b))

Definition at line 153 of file tinfl.c.

#define MZ_MIN (   a,
 
)    (((a)<(b))?(a):(b))

Definition at line 154 of file tinfl.c.

#define MZ_READ_LE16 (   p)    ((mz_uint32)(((const mz_uint8 *)(p))[0]) | ((mz_uint32)(((const mz_uint8 *)(p))[1]) << 8U))

Definition at line 161 of file tinfl.c.

#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))

Definition at line 162 of file tinfl.c.

#define MZ_REALLOC (   p,
 
)    realloc(p, x)

Definition at line 150 of file tinfl.c.

#define TINFL_BITBUF_SIZE   (32)

Definition at line 122 of file tinfl.c.

#define TINFL_CR_BEGIN   switch(r->m_state) { case 0:

Definition at line 168 of file tinfl.c.

#define TINFL_CR_FINISH   }

Definition at line 171 of file tinfl.c.

#define TINFL_CR_RETURN (   state_index,
  result 
)    do { status = result; r->m_state = state_index; goto common_exit; case state_index:; } MZ_MACRO_END

Definition at line 169 of file tinfl.c.

#define TINFL_CR_RETURN_FOREVER (   state_index,
  result 
)    do { for ( ; ; ) { TINFL_CR_RETURN(state_index, result); } } MZ_MACRO_END

Definition at line 170 of file tinfl.c.

#define TINFL_DECOMPRESS_MEM_TO_MEM_FAILED   ((size_t)(-1))

Definition at line 68 of file tinfl.c.

#define tinfl_get_adler32 (   r)    (r)->m_check_adler32

Definition at line 94 of file tinfl.c.

#define TINFL_GET_BITS (   state_index,
  b,
 
)    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

Definition at line 193 of file tinfl.c.

#define TINFL_GET_BYTE (   state_index,
 
)
Value:
do { \
if (pIn_buf_cur >= pIn_buf_end) { \
for ( ; ; ) { \
if (decomp_flags & TINFL_FLAG_HAS_MORE_INPUT) { \
if (pIn_buf_cur < pIn_buf_end) { \
c = *pIn_buf_cur++; \
break; \
} \
} else { \
c = 0; \
break; \
} \
} \
} else c = *pIn_buf_cur++; } MZ_MACRO_END
#define TINFL_CR_RETURN(state_index, result)
Definition: tinfl.c:169
#define MZ_MACRO_END
Definition: tinfl.c:37

Definition at line 175 of file tinfl.c.

#define TINFL_HEADER_INCLUDED

Definition at line 9 of file tinfl.c.

#define TINFL_HUFF_BITBUF_FILL (   state_index,
  pHuff 
)
Value:
do { \
temp = (pHuff)->m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]; \
if (temp >= 0) { \
code_len = temp >> 9; \
if ((code_len) && (num_bits >= code_len)) \
break; \
} else if (num_bits > TINFL_FAST_LOOKUP_BITS) { \
code_len = TINFL_FAST_LOOKUP_BITS; \
do { \
temp = (pHuff)->m_tree[~temp + ((bit_buf >> code_len++) & 1)]; \
} while ((temp < 0) && (num_bits >= (code_len + 1))); if (temp >= 0) break; \
} TINFL_GET_BYTE(state_index, c); bit_buf |= (((tinfl_bit_buf_t)c) << num_bits); num_bits += 8; \
} while (num_bits < 15);
#define TINFL_GET_BYTE(state_index, c)
Definition: tinfl.c:175
mz_uint32 tinfl_bit_buf_t
Definition: tinfl.c:121

Definition at line 199 of file tinfl.c.

#define TINFL_HUFF_DECODE (   state_index,
  sym,
  pHuff 
)
Value:
do { \
int temp; mz_uint code_len, c; \
if (num_bits < 15) { \
if ((pIn_buf_end - pIn_buf_cur) < 2) { \
TINFL_HUFF_BITBUF_FILL(state_index, pHuff); \
} else { \
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; \
} \
} \
if ((temp = (pHuff)->m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]) >= 0) \
code_len = temp >> 9, temp &= 511; \
else { \
code_len = TINFL_FAST_LOOKUP_BITS; do { temp = (pHuff)->m_tree[~temp + ((bit_buf >> code_len++) & 1)]; } while (temp < 0); \
} sym = temp; bit_buf >>= code_len; num_bits -= code_len; } MZ_MACRO_END
#define TINFL_HUFF_BITBUF_FILL(state_index, pHuff)
Definition: tinfl.c:199
unsigned int mz_uint
Definition: tinfl.c:18
#define MZ_MACRO_END
Definition: tinfl.c:37
mz_uint32 tinfl_bit_buf_t
Definition: tinfl.c:121

Definition at line 218 of file tinfl.c.

#define tinfl_init (   r)    do { (r)->m_state = 0; } MZ_MACRO_END

Definition at line 93 of file tinfl.c.

#define TINFL_LZ_DICT_SIZE   32768

Definition at line 79 of file tinfl.c.

#define TINFL_MEMCPY (   d,
  s,
 
)    memcpy(d, s, l)

Definition at line 165 of file tinfl.c.

#define TINFL_MEMSET (   p,
  c,
 
)    memset(p, c, l)

Definition at line 166 of file tinfl.c.

#define TINFL_NEED_BITS (   state_index,
 
)    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))

Definition at line 191 of file tinfl.c.

#define TINFL_SKIP_BITS (   state_index,
 
)    do { if (num_bits < (mz_uint)(n)) { TINFL_NEED_BITS(state_index, n); } bit_buf >>= (n); num_bits -= (n); } MZ_MACRO_END

Definition at line 192 of file tinfl.c.

Typedef Documentation

typedef signed short mz_int16

Definition at line 15 of file tinfl.c.

typedef unsigned int mz_uint

Definition at line 18 of file tinfl.c.

typedef unsigned short mz_uint16

Definition at line 16 of file tinfl.c.

typedef unsigned int mz_uint32

Definition at line 17 of file tinfl.c.

typedef unsigned long mz_uint64

Definition at line 19 of file tinfl.c.

typedef unsigned char mz_uint8

Definition at line 14 of file tinfl.c.

Definition at line 121 of file tinfl.c.

Definition at line 76 of file tinfl.c.

typedef int(* tinfl_put_buf_func_ptr) (const void *pBuf, int len, void *pUser)

Definition at line 73 of file tinfl.c.

Enumeration Type Documentation

anonymous enum
Enumerator
TINFL_FLAG_PARSE_ZLIB_HEADER 
TINFL_FLAG_HAS_MORE_INPUT 
TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF 
TINFL_FLAG_COMPUTE_ADLER32 

Definition at line 45 of file tinfl.c.

anonymous enum
Enumerator
TINFL_MAX_HUFF_TABLES 
TINFL_MAX_HUFF_SYMBOLS_0 
TINFL_MAX_HUFF_SYMBOLS_1 
TINFL_MAX_HUFF_SYMBOLS_2 
TINFL_FAST_LOOKUP_BITS 
TINFL_FAST_LOOKUP_SIZE 

Definition at line 101 of file tinfl.c.

Enumerator
TINFL_STATUS_BAD_PARAM 
TINFL_STATUS_ADLER32_MISMATCH 
TINFL_STATUS_FAILED 
TINFL_STATUS_DONE 
TINFL_STATUS_NEEDS_MORE_INPUT 
TINFL_STATUS_HAS_MORE_OUTPUT 

Definition at line 82 of file tinfl.c.

Function Documentation

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 
)

Definition at line 233 of file tinfl.c.

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 
)

Definition at line 551 of file tinfl.c.

void * tinfl_decompress_mem_to_heap ( const void *  pSrc_buf,
size_t  src_buf_len,
size_t *  pOut_len,
int  flags 
)

Definition at line 516 of file tinfl.c.

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 
)

Definition at line 544 of file tinfl.c.

void tinflDiag ( void  )

Definition at line 579 of file tinfl.c.