#ifndef LZW_H_ #define LZW_H_ #include #include #include 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 */ int eos; /* Flag indicating that the end of stream code was encountered */ 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 */ uint16_t output_buffer_start; uint16_t output_buffer_used; uint16_t input_code; uint16_t input_code_bits; size_t compressed_bytes_processed; size_t uncompressed_bytes_processed; size_t codes_processed; }; void lzw_init(struct lzw_ctx* c); int lzw_decompress(struct lzw_ctx* c, uint8_t* src, size_t src_count, size_t* src_consumed, uint8_t* dst, size_t dst_count, size_t* dst_consumed); #endif