00001
00002
00003
00004
00005 #ifndef DEFLATE_H
00006 #define DEFLATE_H
00007
00008 #include "zutil.h"
00009
00010 #ifndef NO_GZIP
00011 # define GZIP
00012 #endif
00013
00014 #define LENGTH_CODES 29
00015
00016 #define LITERALS 256
00017
00018 #define L_CODES (LITERALS+1+LENGTH_CODES)
00019
00020 #define D_CODES 30
00021
00022 #define BL_CODES 19
00023
00024 #define HEAP_SIZE (2*L_CODES+1)
00025
00026 #define MAX_BITS 15
00027
00028 #define INIT_STATE 42
00029 #define EXTRA_STATE 69
00030 #define NAME_STATE 73
00031 #define COMMENT_STATE 91
00032 #define HCRC_STATE 103
00033 #define BUSY_STATE 113
00034 #define FINISH_STATE 666
00035
00036 typedef struct ct_data_s {
00037 union {
00038 ush freq;
00039 ush code;
00040 } fc;
00041 union {
00042 ush dad;
00043 ush len;
00044 } dl;
00045 } FAR ct_data;
00046
00047 #define Freq fc.freq
00048 #define Code fc.code
00049 #define Dad dl.dad
00050 #define Len dl.len
00051
00052 typedef struct static_tree_desc_s static_tree_desc;
00053
00054 typedef struct tree_desc_s {
00055 ct_data *dyn_tree;
00056 int max_code;
00057 static_tree_desc *stat_desc;
00058 } FAR tree_desc;
00059
00060 typedef ush Pos;
00061 typedef Pos FAR Posf;
00062 typedef unsigned IPos;
00063
00064 typedef struct internal_state {
00065 z_streamp strm;
00066 int status;
00067 Bytef *pending_buf;
00068 ulg pending_buf_size;
00069 Bytef *pending_out;
00070 uInt pending;
00071 int wrap;
00072 gz_headerp gzhead;
00073 uInt gzindex;
00074 Byte method;
00075 int last_flush;
00076
00077
00078
00079 uInt w_size;
00080 uInt w_bits;
00081 uInt w_mask;
00082
00083 Bytef *window;
00084
00085
00086 ulg window_size;
00087
00088
00089 Posf *prev;
00090
00091
00092 Posf *head;
00093
00094 uInt ins_h;
00095 uInt hash_size;
00096 uInt hash_bits;
00097 uInt hash_mask;
00098
00099 uInt hash_shift;
00100
00101
00102 long block_start;
00103
00104
00105 uInt match_length;
00106 IPos prev_match;
00107 int match_available;
00108 uInt strstart;
00109 uInt match_start;
00110 uInt lookahead;
00111
00112 uInt prev_length;
00113
00114
00115 uInt max_chain_length;
00116
00117
00118 uInt max_lazy_match;
00119
00120 # define max_insert_length max_lazy_match
00121
00122
00123 int level;
00124 int strategy;
00125
00126 uInt good_match;
00127
00128
00129 int nice_match;
00130
00131
00132
00133 struct ct_data_s dyn_ltree[HEAP_SIZE];
00134 struct ct_data_s dyn_dtree[2*D_CODES+1];
00135 struct ct_data_s bl_tree[2*BL_CODES+1];
00136
00137 struct tree_desc_s l_desc;
00138 struct tree_desc_s d_desc;
00139 struct tree_desc_s bl_desc;
00140
00141 ush bl_count[MAX_BITS+1];
00142
00143
00144 int heap[2*L_CODES+1];
00145 int heap_len;
00146 int heap_max;
00147
00148
00149 uch depth[2*L_CODES+1];
00150
00151
00152 uchf *l_buf;
00153
00154 uInt lit_bufsize;
00155
00156
00157 uInt last_lit;
00158
00159 ushf *d_buf;
00160
00161
00162 ulg opt_len;
00163 ulg static_len;
00164 uInt matches;
00165 int last_eob_len;
00166
00167 #ifdef DEBUG
00168 ulg compressed_len;
00169 ulg bits_sent;
00170 #endif
00171
00172 ush bi_buf;
00173
00174 int bi_valid;
00175
00176
00177 } FAR deflate_state;
00178
00179 #define put_byte(s, c) {s->pending_buf[s->pending++] = (c);}
00180
00181 #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
00182
00183 #define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD)
00184
00185
00186 void _tr_init OF((deflate_state *s));
00187 int _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc));
00188 void _tr_flush_block OF((deflate_state *s, charf *buf, ulg stored_len,
00189 int eof));
00190 void _tr_align OF((deflate_state *s));
00191 void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len,
00192 int eof));
00193
00194 #define d_code(dist) \
00195 ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
00196
00197 #ifndef DEBUG
00198
00199 #if defined(GEN_TREES_H) || !defined(STDC)
00200 extern uch _length_code[];
00201 extern uch _dist_code[];
00202 #else
00203 extern const uch _length_code[];
00204 extern const uch _dist_code[];
00205 #endif
00206
00207 # define _tr_tally_lit(s, c, flush) \
00208 { uch cc = (c); \
00209 s->d_buf[s->last_lit] = 0; \
00210 s->l_buf[s->last_lit++] = cc; \
00211 s->dyn_ltree[cc].Freq++; \
00212 flush = (s->last_lit == s->lit_bufsize-1); \
00213 }
00214 # define _tr_tally_dist(s, distance, length, flush) \
00215 { uch len = (length); \
00216 ush dist = (distance); \
00217 s->d_buf[s->last_lit] = dist; \
00218 s->l_buf[s->last_lit++] = len; \
00219 dist--; \
00220 s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
00221 s->dyn_dtree[d_code(dist)].Freq++; \
00222 flush = (s->last_lit == s->lit_bufsize-1); \
00223 }
00224 #else
00225 # define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c)
00226 # define _tr_tally_dist(s, distance, length, flush) \
00227 flush = _tr_tally(s, distance, length)
00228 #endif
00229
00230 #endif