|
| 1 | +/* |
| 2 | + * uzlib - tiny deflate/inflate library (deflate, gzip, zlib) |
| 3 | + * |
| 4 | + * Copyright (c) 2003 by Joergen Ibsen / Jibz |
| 5 | + * All Rights Reserved |
| 6 | + * http://www.ibsensoftware.com/ |
| 7 | + * |
| 8 | + * Copyright (c) 2014 by Paul Sokolovsky |
| 9 | + */ |
| 10 | + |
| 11 | +#ifndef TINF_H_INCLUDED |
| 12 | +#define TINF_H_INCLUDED |
| 13 | + |
| 14 | +#include <stdint.h> |
| 15 | + |
| 16 | +/* calling convention */ |
| 17 | +#ifndef TINFCC |
| 18 | + #ifdef __WATCOMC__ |
| 19 | + #define TINFCC __cdecl |
| 20 | + #else |
| 21 | + #define TINFCC |
| 22 | + #endif |
| 23 | +#endif |
| 24 | + |
| 25 | +#ifdef __cplusplus |
| 26 | +extern "C" { |
| 27 | +#endif |
| 28 | + |
| 29 | +#define TINF_OK 0 |
| 30 | +#define TINF_DATA_ERROR (-3) |
| 31 | +#define TINF_DEST_OVERFLOW (-4) |
| 32 | + |
| 33 | +/* data structures */ |
| 34 | + |
| 35 | +typedef struct { |
| 36 | + unsigned short table[16]; /* table of code length counts */ |
| 37 | + unsigned short trans[288]; /* code -> symbol translation table */ |
| 38 | +} TINF_TREE; |
| 39 | + |
| 40 | +struct TINF_DATA; |
| 41 | +typedef struct TINF_DATA { |
| 42 | + const unsigned char *source; |
| 43 | + unsigned int tag; |
| 44 | + unsigned int bitcount; |
| 45 | + |
| 46 | + /* Buffer start */ |
| 47 | + unsigned char *destStart; |
| 48 | + /* Buffer total size */ |
| 49 | + unsigned int destSize; |
| 50 | + /* Current pointer in buffer */ |
| 51 | + unsigned char *dest; |
| 52 | + /* Remaining bytes in buffer */ |
| 53 | + 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); |
| 59 | + |
| 60 | + TINF_TREE ltree; /* dynamic length/symbol tree */ |
| 61 | + TINF_TREE dtree; /* dynamic distance tree */ |
| 62 | +} TINF_DATA; |
| 63 | + |
| 64 | + |
| 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(); |
| 80 | + |
| 81 | +int TINFCC tinf_uncompress(void *dest, unsigned int *destLen, |
| 82 | + const void *source, unsigned int sourceLen); |
| 83 | + |
| 84 | +int TINFCC tinf_gzip_uncompress(void *dest, unsigned int *destLen, |
| 85 | + const void *source, unsigned int sourceLen); |
| 86 | + |
| 87 | +int TINFCC tinf_zlib_uncompress(void *dest, unsigned int *destLen, |
| 88 | + const void *source, unsigned int sourceLen); |
| 89 | + |
| 90 | +unsigned int TINFCC tinf_adler32(const void *data, unsigned int length); |
| 91 | + |
| 92 | +unsigned int TINFCC tinf_crc32(const void *data, unsigned int length); |
| 93 | + |
| 94 | +/* compression API */ |
| 95 | + |
| 96 | +void TINFCC tinf_compress(void *data, const uint8_t *src, unsigned slen); |
| 97 | + |
| 98 | +#ifdef __cplusplus |
| 99 | +} /* extern "C" */ |
| 100 | +#endif |
| 101 | + |
| 102 | +#endif /* TINF_H_INCLUDED */ |
0 commit comments