luajitos

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

deflate_impl.h (1647B)


      1 #ifndef DEFLATE_IMPL_H
      2 #define DEFLATE_IMPL_H
      3 
      4 #include <stdint.h>
      5 
      6 /* Deflate implementation with full Huffman coding */
      7 
      8 /* Huffman tree node */
      9 typedef struct huffman_node {
     10     uint16_t symbol;
     11     uint16_t freq;
     12     struct huffman_node* left;
     13     struct huffman_node* right;
     14 } huffman_node_t;
     15 
     16 /* Huffman code */
     17 typedef struct {
     18     uint16_t code;
     19     uint8_t length;
     20 } huffman_code_t;
     21 
     22 /* Bit buffer for output */
     23 typedef struct {
     24     uint8_t* buffer;
     25     uint32_t buffer_size;
     26     uint32_t byte_pos;
     27     uint32_t bit_pos;
     28     uint32_t max_size;
     29 } bit_buffer_t;
     30 
     31 /* Deflate state */
     32 typedef struct {
     33     const uint8_t* input;
     34     uint32_t input_size;
     35     uint32_t input_pos;
     36 
     37     bit_buffer_t output;
     38 
     39     /* LZ77 state */
     40     uint8_t* window;
     41     uint32_t window_pos;
     42     uint32_t window_size;
     43 
     44     /* Huffman trees */
     45     huffman_code_t literal_codes[286];
     46     huffman_code_t distance_codes[30];
     47 
     48     int level;
     49 } deflate_state_t;
     50 
     51 /* Inflate state */
     52 typedef struct {
     53     const uint8_t* input;
     54     uint32_t input_size;
     55     uint32_t byte_pos;
     56     uint32_t bit_pos;
     57 
     58     uint8_t* output;
     59     uint32_t output_size;
     60     uint32_t output_pos;
     61     uint32_t output_capacity;
     62 
     63     /* Huffman trees for decompression */
     64     uint16_t literal_tree[288 * 2];
     65     uint16_t distance_tree[32 * 2];
     66 } inflate_state_t;
     67 
     68 /* Functions */
     69 int deflate_compress_full(const uint8_t* input, uint32_t input_size,
     70                           uint8_t** output, uint32_t* output_size, int level);
     71 
     72 int deflate_decompress_full(const uint8_t* input, uint32_t input_size,
     73                             uint8_t** output, uint32_t* output_size);
     74 
     75 #endif /* DEFLATE_IMPL_H */