OLD | NEW |
1 /* deflate.h -- internal compression state | 1 /* deflate.h -- internal compression state |
2 * Copyright (C) 1995-2004 Jean-loup Gailly | 2 * Copyright (C) 1995-2010 Jean-loup Gailly |
3 * For conditions of distribution and use, see copyright notice in zlib.h | 3 * For conditions of distribution and use, see copyright notice in zlib.h |
4 */ | 4 */ |
5 | 5 |
6 /* WARNING: this file should *not* be used by applications. It is | 6 /* WARNING: this file should *not* be used by applications. It is |
7 part of the implementation of the compression library and is | 7 part of the implementation of the compression library and is |
8 subject to change. Applications should only use zlib.h. | 8 subject to change. Applications should only use zlib.h. |
9 */ | 9 */ |
10 | 10 |
11 /* @(#) $Id: deflate.h,v 3.6 2005/08/04 19:14:14 tor%cs.brown.edu Exp $ */ | 11 /* @(#) $Id$ */ |
12 | 12 |
13 #ifndef DEFLATE_H | 13 #ifndef DEFLATE_H |
14 #define DEFLATE_H | 14 #define DEFLATE_H |
15 | 15 |
16 #include "zutil.h" | 16 #include "zutil.h" |
17 | 17 |
18 /* define NO_GZIP when compiling if you want to disable gzip header and | 18 /* define NO_GZIP when compiling if you want to disable gzip header and |
19 trailer creation by deflate(). NO_GZIP would be used to avoid linking in | 19 trailer creation by deflate(). NO_GZIP would be used to avoid linking in |
20 the crc code when it is not needed. For shared libraries, gzip encoding | 20 the crc code when it is not needed. For shared libraries, gzip encoding |
21 should be left enabled. */ | 21 should be left enabled. */ |
(...skipping 231 matching lines...) Loading... |
253 | 253 |
254 ush bi_buf; | 254 ush bi_buf; |
255 /* Output buffer. bits are inserted starting at the bottom (least | 255 /* Output buffer. bits are inserted starting at the bottom (least |
256 * significant bits). | 256 * significant bits). |
257 */ | 257 */ |
258 int bi_valid; | 258 int bi_valid; |
259 /* Number of valid bits in bi_buf. All bits above the last valid bit | 259 /* Number of valid bits in bi_buf. All bits above the last valid bit |
260 * are always zero. | 260 * are always zero. |
261 */ | 261 */ |
262 | 262 |
| 263 ulg high_water; |
| 264 /* High water mark offset in window for initialized bytes -- bytes above |
| 265 * this are set to zero in order to avoid memory check warnings when |
| 266 * longest match routines access bytes past the input. This is then |
| 267 * updated to the new high water mark. |
| 268 */ |
| 269 |
263 } FAR deflate_state; | 270 } FAR deflate_state; |
264 | 271 |
265 /* Output a byte on the stream. | 272 /* Output a byte on the stream. |
266 * IN assertion: there is enough room in pending_buf. | 273 * IN assertion: there is enough room in pending_buf. |
267 */ | 274 */ |
268 #define put_byte(s, c) {s->pending_buf[s->pending++] = (c);} | 275 #define put_byte(s, c) {s->pending_buf[s->pending++] = (c);} |
269 | 276 |
270 | 277 |
271 #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1) | 278 #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1) |
272 /* Minimum amount of lookahead, except at the end of the input file. | 279 /* Minimum amount of lookahead, except at the end of the input file. |
273 * See deflate.c for comments about the MIN_MATCH+1. | 280 * See deflate.c for comments about the MIN_MATCH+1. |
274 */ | 281 */ |
275 | 282 |
276 #define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD) | 283 #define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD) |
277 /* In order to simplify the code, particularly on 16 bit machines, match | 284 /* In order to simplify the code, particularly on 16 bit machines, match |
278 * distances are limited to MAX_DIST instead of WSIZE. | 285 * distances are limited to MAX_DIST instead of WSIZE. |
279 */ | 286 */ |
280 | 287 |
| 288 #define WIN_INIT MAX_MATCH |
| 289 /* Number of bytes after end of data in window to initialize in order to avoid |
| 290 memory checker errors from longest match routines */ |
| 291 |
281 /* in trees.c */ | 292 /* in trees.c */ |
282 void _tr_init OF((deflate_state *s)); | 293 void ZLIB_INTERNAL _tr_init OF((deflate_state *s)); |
283 int _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc)); | 294 int ZLIB_INTERNAL _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc)); |
284 void _tr_flush_block OF((deflate_state *s, charf *buf, ulg stored_len, | 295 void ZLIB_INTERNAL _tr_flush_block OF((deflate_state *s, charf *buf, |
285 int eof)); | 296 ulg stored_len, int last)); |
286 void _tr_align OF((deflate_state *s)); | 297 void ZLIB_INTERNAL _tr_align OF((deflate_state *s)); |
287 void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len, | 298 void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf, |
288 int eof)); | 299 ulg stored_len, int last)); |
289 | 300 |
290 #define d_code(dist) \ | 301 #define d_code(dist) \ |
291 ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)]) | 302 ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)]) |
292 /* Mapping from a distance to a distance code. dist is the distance - 1 and | 303 /* Mapping from a distance to a distance code. dist is the distance - 1 and |
293 * must not have side effects. _dist_code[256] and _dist_code[257] are never | 304 * must not have side effects. _dist_code[256] and _dist_code[257] are never |
294 * used. | 305 * used. |
295 */ | 306 */ |
296 | 307 |
297 #ifndef DEBUG | 308 #ifndef DEBUG |
298 /* Inline versions of _tr_tally for speed: */ | 309 /* Inline versions of _tr_tally for speed: */ |
299 | 310 |
300 #if defined(GEN_TREES_H) || !defined(STDC) | 311 #if defined(GEN_TREES_H) || !defined(STDC) |
301 extern uch _length_code[]; | 312 extern uch ZLIB_INTERNAL _length_code[]; |
302 extern uch _dist_code[]; | 313 extern uch ZLIB_INTERNAL _dist_code[]; |
303 #else | 314 #else |
304 extern const uch _length_code[]; | 315 extern const uch ZLIB_INTERNAL _length_code[]; |
305 extern const uch _dist_code[]; | 316 extern const uch ZLIB_INTERNAL _dist_code[]; |
306 #endif | 317 #endif |
307 | 318 |
308 # define _tr_tally_lit(s, c, flush) \ | 319 # define _tr_tally_lit(s, c, flush) \ |
309 { uch cc = (c); \ | 320 { uch cc = (c); \ |
310 s->d_buf[s->last_lit] = 0; \ | 321 s->d_buf[s->last_lit] = 0; \ |
311 s->l_buf[s->last_lit++] = cc; \ | 322 s->l_buf[s->last_lit++] = cc; \ |
312 s->dyn_ltree[cc].Freq++; \ | 323 s->dyn_ltree[cc].Freq++; \ |
313 flush = (s->last_lit == s->lit_bufsize-1); \ | 324 flush = (s->last_lit == s->lit_bufsize-1); \ |
314 } | 325 } |
315 # define _tr_tally_dist(s, distance, length, flush) \ | 326 # define _tr_tally_dist(s, distance, length, flush) \ |
316 { uch len = (length); \ | 327 { uch len = (length); \ |
317 ush dist = (distance); \ | 328 ush dist = (distance); \ |
318 s->d_buf[s->last_lit] = dist; \ | 329 s->d_buf[s->last_lit] = dist; \ |
319 s->l_buf[s->last_lit++] = len; \ | 330 s->l_buf[s->last_lit++] = len; \ |
320 dist--; \ | 331 dist--; \ |
321 s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \ | 332 s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \ |
322 s->dyn_dtree[d_code(dist)].Freq++; \ | 333 s->dyn_dtree[d_code(dist)].Freq++; \ |
323 flush = (s->last_lit == s->lit_bufsize-1); \ | 334 flush = (s->last_lit == s->lit_bufsize-1); \ |
324 } | 335 } |
325 #else | 336 #else |
326 # define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c) | 337 # define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c) |
327 # define _tr_tally_dist(s, distance, length, flush) \ | 338 # define _tr_tally_dist(s, distance, length, flush) \ |
328 flush = _tr_tally(s, distance, length) | 339 flush = _tr_tally(s, distance, length) |
329 #endif | 340 #endif |
330 | 341 |
331 #endif /* DEFLATE_H */ | 342 #endif /* DEFLATE_H */ |
OLD | NEW |