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