2014-10-12 22:09:43 +01:00
|
|
|
/*
|
|
|
|
* uzlib - tiny deflate/inflate library (deflate, gzip, zlib)
|
|
|
|
*
|
|
|
|
* Copyright (c) 2003 by Joergen Ibsen / Jibz
|
|
|
|
* All Rights Reserved
|
|
|
|
* http://www.ibsensoftware.com/
|
|
|
|
*
|
2016-08-17 04:00:28 +01:00
|
|
|
* Copyright (c) 2014-2016 by Paul Sokolovsky
|
2014-10-12 22:09:43 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef TINF_H_INCLUDED
|
|
|
|
#define TINF_H_INCLUDED
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
/* calling convention */
|
|
|
|
#ifndef TINFCC
|
|
|
|
#ifdef __WATCOMC__
|
|
|
|
#define TINFCC __cdecl
|
|
|
|
#else
|
|
|
|
#define TINFCC
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2016-08-17 04:00:28 +01:00
|
|
|
/* ok status, more data produced */
|
2014-10-12 22:09:43 +01:00
|
|
|
#define TINF_OK 0
|
2016-08-17 04:00:28 +01:00
|
|
|
/* end of compressed stream reached */
|
|
|
|
#define TINF_DONE 1
|
2014-10-12 22:09:43 +01:00
|
|
|
#define TINF_DATA_ERROR (-3)
|
2016-08-17 04:00:28 +01:00
|
|
|
#define TINF_CHKSUM_ERROR (-4)
|
2016-10-11 05:10:48 +01:00
|
|
|
#define TINF_DICT_ERROR (-5)
|
2016-08-17 04:00:28 +01:00
|
|
|
|
|
|
|
/* checksum types */
|
|
|
|
#define TINF_CHKSUM_NONE 0
|
|
|
|
#define TINF_CHKSUM_ADLER 1
|
|
|
|
#define TINF_CHKSUM_CRC 2
|
2014-10-12 22:09:43 +01:00
|
|
|
|
|
|
|
/* data structures */
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
unsigned short table[16]; /* table of code length counts */
|
|
|
|
unsigned short trans[288]; /* code -> symbol translation table */
|
|
|
|
} TINF_TREE;
|
|
|
|
|
|
|
|
struct TINF_DATA;
|
|
|
|
typedef struct TINF_DATA {
|
|
|
|
const unsigned char *source;
|
2016-08-17 04:00:28 +01:00
|
|
|
/* If source above is NULL, this function will be used to read
|
|
|
|
next byte from source stream */
|
|
|
|
unsigned char (*readSource)(struct TINF_DATA *data);
|
|
|
|
|
2014-10-12 22:09:43 +01:00
|
|
|
unsigned int tag;
|
|
|
|
unsigned int bitcount;
|
|
|
|
|
|
|
|
/* Buffer start */
|
|
|
|
unsigned char *destStart;
|
|
|
|
/* Buffer total size */
|
|
|
|
unsigned int destSize;
|
|
|
|
/* Current pointer in buffer */
|
|
|
|
unsigned char *dest;
|
|
|
|
/* Remaining bytes in buffer */
|
|
|
|
unsigned int destRemaining;
|
2016-08-17 04:00:28 +01:00
|
|
|
|
|
|
|
/* Accumulating checksum */
|
|
|
|
unsigned int checksum;
|
|
|
|
char checksum_type;
|
|
|
|
|
|
|
|
int btype;
|
|
|
|
int bfinal;
|
|
|
|
unsigned int curlen;
|
|
|
|
int lzOff;
|
|
|
|
unsigned char *dict_ring;
|
|
|
|
unsigned int dict_size;
|
|
|
|
unsigned int dict_idx;
|
2014-10-12 22:09:43 +01:00
|
|
|
|
|
|
|
TINF_TREE ltree; /* dynamic length/symbol tree */
|
|
|
|
TINF_TREE dtree; /* dynamic distance tree */
|
|
|
|
} TINF_DATA;
|
|
|
|
|
2016-08-17 04:00:28 +01:00
|
|
|
#define TINF_PUT(d, c) \
|
|
|
|
{ \
|
|
|
|
*d->dest++ = c; \
|
|
|
|
if (d->dict_ring) { d->dict_ring[d->dict_idx++] = c; if (d->dict_idx == d->dict_size) d->dict_idx = 0; } \
|
|
|
|
}
|
2014-10-12 22:09:43 +01:00
|
|
|
|
2016-08-17 04:00:28 +01:00
|
|
|
unsigned char TINFCC uzlib_get_byte(TINF_DATA *d);
|
2014-10-12 22:09:43 +01:00
|
|
|
|
2016-08-17 04:00:28 +01:00
|
|
|
/* Decompression API */
|
2014-10-12 22:09:43 +01:00
|
|
|
|
2016-08-17 04:00:28 +01:00
|
|
|
void TINFCC uzlib_init(void);
|
|
|
|
void TINFCC uzlib_uncompress_init(TINF_DATA *d, void *dict, unsigned int dictLen);
|
|
|
|
int TINFCC uzlib_uncompress(TINF_DATA *d);
|
|
|
|
int TINFCC uzlib_uncompress_chksum(TINF_DATA *d);
|
2014-10-12 22:09:43 +01:00
|
|
|
|
2016-08-17 04:00:28 +01:00
|
|
|
int TINFCC uzlib_zlib_parse_header(TINF_DATA *d);
|
|
|
|
int TINFCC uzlib_gzip_parse_header(TINF_DATA *d);
|
2014-10-12 22:09:43 +01:00
|
|
|
|
2016-08-17 04:00:28 +01:00
|
|
|
/* Compression API */
|
2014-10-12 22:09:43 +01:00
|
|
|
|
2016-08-17 04:00:28 +01:00
|
|
|
void TINFCC uzlib_compress(void *data, const uint8_t *src, unsigned slen);
|
2014-10-12 22:09:43 +01:00
|
|
|
|
2016-08-17 04:00:28 +01:00
|
|
|
/* Checksum API */
|
2014-10-12 22:09:43 +01:00
|
|
|
|
2016-08-17 04:00:28 +01:00
|
|
|
/* prev_sum is previous value for incremental computation, 1 initially */
|
|
|
|
uint32_t TINFCC uzlib_adler32(const void *data, unsigned int length, uint32_t prev_sum);
|
|
|
|
/* crc is previous value for incremental computation, 0xffffffff initially */
|
|
|
|
uint32_t TINFCC uzlib_crc32(const void *data, unsigned int length, uint32_t crc);
|
2014-10-12 22:09:43 +01:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
} /* extern "C" */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* TINF_H_INCLUDED */
|