34 lines
1.3 KiB
C
34 lines
1.3 KiB
C
#ifndef LZW_H_
|
|
#define LZW_H_
|
|
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
|
|
struct lzw_dict_entry {
|
|
uint16_t prefix; /* Code containing the first length-1 bytes in this code */
|
|
uint16_t length; /* Length of this code */
|
|
uint16_t usecount; /* How many codes have this code as a prefix */
|
|
uint16_t lru_prev; /* Previous entry in the lru list */
|
|
uint16_t lru_next; /* Next entry in the lru list */
|
|
uint8_t last; /* Last byte in this code */
|
|
uint8_t first; /* First byte in this code */
|
|
};
|
|
|
|
struct lzw_ctx {
|
|
struct lzw_dict_entry dict[4096]; /* Dictionary entries */
|
|
uint8_t output_buffer[4096]; /* Temporary buffer used to collect the byte string corresponding to a code */
|
|
size_t coffset; /* Position in the compressed stream */
|
|
size_t doffset; /* Position in the decompressed stream */
|
|
size_t codes; /* Number of codes processed so far */
|
|
int input_buffer; /* Temporary buffer used in the extraction of 12bit codes from the compressed stream */
|
|
uint16_t lru_head; /* Index of the first entry in the lru list */
|
|
uint16_t lru_tail; /* Index of the last entry in the lru list */
|
|
uint16_t last_emitted_code; /* Code emitted in the previous round */
|
|
};
|
|
|
|
void lzw_init(struct lzw_ctx* c);
|
|
int lzw_decompress_file(FILE* infp, FILE* outfp);
|
|
|
|
#endif
|