5
5
* All Rights Reserved
6
6
* http://www.ibsensoftware.com/
7
7
*
8
- * Copyright (c) 2014 by Paul Sokolovsky
8
+ * Copyright (c) 2014-2016 by Paul Sokolovsky
9
9
*/
10
10
11
11
#ifndef TINF_H_INCLUDED
26
26
extern "C" {
27
27
#endif
28
28
29
+ /* ok status, more data produced */
29
30
#define TINF_OK 0
31
+ /* end of compressed stream reached */
32
+ #define TINF_DONE 1
30
33
#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
32
40
33
41
/* data structures */
34
42
@@ -40,6 +48,10 @@ typedef struct {
40
48
struct TINF_DATA ;
41
49
typedef struct TINF_DATA {
42
50
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
+
43
55
unsigned int tag ;
44
56
unsigned int bitcount ;
45
57
@@ -51,49 +63,51 @@ typedef struct TINF_DATA {
51
63
unsigned char * dest ;
52
64
/* Remaining bytes in buffer */
53
65
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 ;
59
78
60
79
TINF_TREE ltree ; /* dynamic length/symbol tree */
61
80
TINF_TREE dtree ; /* dynamic distance tree */
62
81
} TINF_DATA ;
63
82
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
+ }
64
88
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 );
80
90
81
- int TINFCC tinf_uncompress (void * dest , unsigned int * destLen ,
82
- const void * source , unsigned int sourceLen );
91
+ /* Decompression API */
83
92
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 );
86
97
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 );
89
100
90
- unsigned int TINFCC tinf_adler32 ( const void * data , unsigned int length );
101
+ /* Compression API */
91
102
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 );
93
104
94
- /* compression API */
105
+ /* Checksum API */
95
106
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 );
97
111
98
112
#ifdef __cplusplus
99
113
} /* extern "C" */
0 commit comments