55 * All Rights Reserved
66 * http://www.ibsensoftware.com/
77 *
8- * Copyright (c) 2014 by Paul Sokolovsky
8+ * Copyright (c) 2014-2016 by Paul Sokolovsky
99 */
1010
1111#ifndef TINF_H_INCLUDED
2626extern "C" {
2727#endif
2828
29+ /* ok status, more data produced */
2930#define TINF_OK 0
31+ /* end of compressed stream reached */
32+ #define TINF_DONE 1
3033#define TINF_DATA_ERROR (-3)
31- #define TINF_DEST_OVERFLOW (-4)
34+ #define TINF_CHKSUM_ERROR (-4)
35+
36+ /* checksum types */
37+ #define TINF_CHKSUM_NONE 0
38+ #define TINF_CHKSUM_ADLER 1
39+ #define TINF_CHKSUM_CRC 2
3240
3341/* data structures */
3442
@@ -40,6 +48,10 @@ typedef struct {
4048struct TINF_DATA ;
4149typedef struct TINF_DATA {
4250 const unsigned char * source ;
51+ /* If source above is NULL, this function will be used to read
52+ next byte from source stream */
53+ unsigned char (* readSource )(struct TINF_DATA * data );
54+
4355 unsigned int tag ;
4456 unsigned int bitcount ;
4557
@@ -51,49 +63,51 @@ typedef struct TINF_DATA {
5163 unsigned char * dest ;
5264 /* Remaining bytes in buffer */
5365 unsigned int destRemaining ;
54- /* Argument is the allocation size which didn't fit into buffer. Note that
55- exact mimumum size to grow buffer by is lastAlloc - destRemaining. But
56- growing by this exact size is ineficient, as the next allocation will
57- fail again. */
58- int (* destGrow )(struct TINF_DATA * data , unsigned int lastAlloc );
66+
67+ /* Accumulating checksum */
68+ unsigned int checksum ;
69+ char checksum_type ;
70+
71+ int btype ;
72+ int bfinal ;
73+ unsigned int curlen ;
74+ int lzOff ;
75+ unsigned char * dict_ring ;
76+ unsigned int dict_size ;
77+ unsigned int dict_idx ;
5978
6079 TINF_TREE ltree ; /* dynamic length/symbol tree */
6180 TINF_TREE dtree ; /* dynamic distance tree */
6281} TINF_DATA ;
6382
83+ #define TINF_PUT (d , c ) \
84+ { \
85+ *d->dest++ = c; \
86+ if (d->dict_ring) { d->dict_ring[d->dict_idx++] = c; if (d->dict_idx == d->dict_size) d->dict_idx = 0; } \
87+ }
6488
65- /* low-level API */
66-
67- /* Step 1: Allocate TINF_DATA structure */
68- /* Step 2: Set destStart, destSize, and destGrow fields */
69- /* Step 3: Set source field */
70- /* Step 4: Call tinf_uncompress_dyn() */
71- /* Step 5: In response to destGrow callback, update destStart and destSize fields */
72- /* Step 6: When tinf_uncompress_dyn() returns, buf.dest points to a byte past last uncompressed byte */
73-
74- int TINFCC tinf_uncompress_dyn (TINF_DATA * d );
75- int TINFCC tinf_zlib_uncompress_dyn (TINF_DATA * d , unsigned int sourceLen );
76-
77- /* high-level API */
78-
79- void TINFCC tinf_init (void );
89+ unsigned char TINFCC uzlib_get_byte (TINF_DATA * d );
8090
81- int TINFCC tinf_uncompress (void * dest , unsigned int * destLen ,
82- const void * source , unsigned int sourceLen );
91+ /* Decompression API */
8392
84- int TINFCC tinf_gzip_uncompress (void * dest , unsigned int * destLen ,
85- const void * source , unsigned int sourceLen );
93+ void TINFCC uzlib_init (void );
94+ void TINFCC uzlib_uncompress_init (TINF_DATA * d , void * dict , unsigned int dictLen );
95+ int TINFCC uzlib_uncompress (TINF_DATA * d );
96+ int TINFCC uzlib_uncompress_chksum (TINF_DATA * d );
8697
87- int TINFCC tinf_zlib_uncompress ( void * dest , unsigned int * destLen ,
88- const void * source , unsigned int sourceLen );
98+ int TINFCC uzlib_zlib_parse_header ( TINF_DATA * d );
99+ int TINFCC uzlib_gzip_parse_header ( TINF_DATA * d );
89100
90- unsigned int TINFCC tinf_adler32 ( const void * data , unsigned int length );
101+ /* Compression API */
91102
92- unsigned int TINFCC tinf_crc32 ( const void * data , unsigned int length );
103+ void TINFCC uzlib_compress ( void * data , const uint8_t * src , unsigned slen );
93104
94- /* compression API */
105+ /* Checksum API */
95106
96- void TINFCC tinf_compress (void * data , const uint8_t * src , unsigned slen );
107+ /* prev_sum is previous value for incremental computation, 1 initially */
108+ uint32_t TINFCC uzlib_adler32 (const void * data , unsigned int length , uint32_t prev_sum );
109+ /* crc is previous value for incremental computation, 0xffffffff initially */
110+ uint32_t TINFCC uzlib_crc32 (const void * data , unsigned int length , uint32_t crc );
97111
98112#ifdef __cplusplus
99113} /* extern "C" */
0 commit comments