OLD | NEW |
1 /* deflate.h -- internal compression state | 1 /* deflate.h -- internal compression state |
2 * Copyright (C) 1995-2012 Jean-loup Gailly | 2 * Copyright (C) 1995-2016 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$ */ | 11 /* @(#) $Id$ */ |
12 | 12 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 | 44 |
45 #define HEAP_SIZE (2*L_CODES+1) | 45 #define HEAP_SIZE (2*L_CODES+1) |
46 /* maximum heap size */ | 46 /* maximum heap size */ |
47 | 47 |
48 #define MAX_BITS 15 | 48 #define MAX_BITS 15 |
49 /* All codes must not exceed MAX_BITS bits */ | 49 /* All codes must not exceed MAX_BITS bits */ |
50 | 50 |
51 #define Buf_size 16 | 51 #define Buf_size 16 |
52 /* size of bit buffer in bi_buf */ | 52 /* size of bit buffer in bi_buf */ |
53 | 53 |
54 #define INIT_STATE 42 | 54 #define INIT_STATE 42 /* zlib header -> BUSY_STATE */ |
55 #define EXTRA_STATE 69 | 55 #ifdef GZIP |
56 #define NAME_STATE 73 | 56 # define GZIP_STATE 57 /* gzip header -> BUSY_STATE | EXTRA_STATE */ |
57 #define COMMENT_STATE 91 | 57 #endif |
58 #define HCRC_STATE 103 | 58 #define EXTRA_STATE 69 /* gzip extra block -> NAME_STATE */ |
59 #define BUSY_STATE 113 | 59 #define NAME_STATE 73 /* gzip file name -> COMMENT_STATE */ |
60 #define FINISH_STATE 666 | 60 #define COMMENT_STATE 91 /* gzip comment -> HCRC_STATE */ |
| 61 #define HCRC_STATE 103 /* gzip header CRC -> BUSY_STATE */ |
| 62 #define BUSY_STATE 113 /* deflate -> FINISH_STATE */ |
| 63 #define FINISH_STATE 666 /* stream complete */ |
61 /* Stream status */ | 64 /* Stream status */ |
62 | 65 |
63 | 66 |
64 /* Data structure describing a single value and its code string. */ | 67 /* Data structure describing a single value and its code string. */ |
65 typedef struct ct_data_s { | 68 typedef struct ct_data_s { |
66 union { | 69 union { |
67 ush freq; /* frequency count */ | 70 ush freq; /* frequency count */ |
68 ush code; /* bit string */ | 71 ush code; /* bit string */ |
69 } fc; | 72 } fc; |
70 union { | 73 union { |
71 ush dad; /* father node in Huffman tree */ | 74 ush dad; /* father node in Huffman tree */ |
72 ush len; /* length of bit string */ | 75 ush len; /* length of bit string */ |
73 } dl; | 76 } dl; |
74 } FAR ct_data; | 77 } FAR ct_data; |
75 | 78 |
76 #define Freq fc.freq | 79 #define Freq fc.freq |
77 #define Code fc.code | 80 #define Code fc.code |
78 #define Dad dl.dad | 81 #define Dad dl.dad |
79 #define Len dl.len | 82 #define Len dl.len |
80 | 83 |
81 typedef struct static_tree_desc_s static_tree_desc; | 84 typedef struct static_tree_desc_s static_tree_desc; |
82 | 85 |
83 typedef struct tree_desc_s { | 86 typedef struct tree_desc_s { |
84 ct_data *dyn_tree; /* the dynamic tree */ | 87 ct_data *dyn_tree; /* the dynamic tree */ |
85 int max_code; /* largest code with non zero frequency */ | 88 int max_code; /* largest code with non zero frequency */ |
86 static_tree_desc *stat_desc; /* the corresponding static tree */ | 89 const static_tree_desc *stat_desc; /* the corresponding static tree */ |
87 } FAR tree_desc; | 90 } FAR tree_desc; |
88 | 91 |
89 typedef ush Pos; | 92 typedef ush Pos; |
90 typedef Pos FAR Posf; | 93 typedef Pos FAR Posf; |
91 typedef unsigned IPos; | 94 typedef unsigned IPos; |
92 | 95 |
93 /* A Pos is an index in the character window. We use short instead of int to | 96 /* A Pos is an index in the character window. We use short instead of int to |
94 * save space in the various tables. IPos is used only for parameter passing. | 97 * save space in the various tables. IPos is used only for parameter passing. |
95 */ | 98 */ |
96 | 99 |
97 typedef struct internal_state { | 100 typedef struct internal_state { |
98 z_streamp strm; /* pointer back to this zlib stream */ | 101 z_streamp strm; /* pointer back to this zlib stream */ |
99 int status; /* as the name implies */ | 102 int status; /* as the name implies */ |
100 Bytef *pending_buf; /* output still pending */ | 103 Bytef *pending_buf; /* output still pending */ |
101 ulg pending_buf_size; /* size of pending_buf */ | 104 ulg pending_buf_size; /* size of pending_buf */ |
102 Bytef *pending_out; /* next pending byte to output to the stream */ | 105 Bytef *pending_out; /* next pending byte to output to the stream */ |
103 uInt pending; /* nb of bytes in the pending buffer */ | 106 ulg pending; /* nb of bytes in the pending buffer */ |
104 int wrap; /* bit 0 true for zlib, bit 1 true for gzip */ | 107 int wrap; /* bit 0 true for zlib, bit 1 true for gzip */ |
105 gz_headerp gzhead; /* gzip header information to write */ | 108 gz_headerp gzhead; /* gzip header information to write */ |
106 uInt gzindex; /* where in extra, name, or comment */ | 109 ulg gzindex; /* where in extra, name, or comment */ |
107 Byte method; /* can only be DEFLATED */ | 110 Byte method; /* can only be DEFLATED */ |
108 int last_flush; /* value of flush param for previous deflate call */ | 111 int last_flush; /* value of flush param for previous deflate call */ |
109 unsigned zalign(16) crc0[4 * 5]; | 112 unsigned zalign(16) crc0[4 * 5]; |
110 /* used by deflate.c: */ | 113 /* used by deflate.c: */ |
111 | 114 |
112 uInt w_size; /* LZ77 window size (32K by default) */ | 115 uInt w_size; /* LZ77 window size (32K by default) */ |
113 uInt w_bits; /* log2(w_size) (8..16) */ | 116 uInt w_bits; /* log2(w_size) (8..16) */ |
114 uInt w_mask; /* w_size - 1 */ | 117 uInt w_mask; /* w_size - 1 */ |
115 | 118 |
116 Bytef *window; | 119 Bytef *window; |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 /* Buffer for distances. To simplify the code, d_buf and l_buf have | 245 /* Buffer for distances. To simplify the code, d_buf and l_buf have |
243 * the same number of elements. To use different lengths, an extra flag | 246 * the same number of elements. To use different lengths, an extra flag |
244 * array would be necessary. | 247 * array would be necessary. |
245 */ | 248 */ |
246 | 249 |
247 ulg opt_len; /* bit length of current block with optimal trees */ | 250 ulg opt_len; /* bit length of current block with optimal trees */ |
248 ulg static_len; /* bit length of current block with static trees */ | 251 ulg static_len; /* bit length of current block with static trees */ |
249 uInt matches; /* number of string matches in current block */ | 252 uInt matches; /* number of string matches in current block */ |
250 uInt insert; /* bytes at end of window left to insert */ | 253 uInt insert; /* bytes at end of window left to insert */ |
251 | 254 |
252 #ifdef DEBUG | 255 #ifdef ZLIB_DEBUG |
253 ulg compressed_len; /* total bit length of compressed file mod 2^32 */ | 256 ulg compressed_len; /* total bit length of compressed file mod 2^32 */ |
254 ulg bits_sent; /* bit length of compressed data sent mod 2^32 */ | 257 ulg bits_sent; /* bit length of compressed data sent mod 2^32 */ |
255 #endif | 258 #endif |
256 | 259 |
257 ush bi_buf; | 260 ush bi_buf; |
258 /* Output buffer. bits are inserted starting at the bottom (least | 261 /* Output buffer. bits are inserted starting at the bottom (least |
259 * significant bits). | 262 * significant bits). |
260 */ | 263 */ |
261 int bi_valid; | 264 int bi_valid; |
262 /* Number of valid bits in bi_buf. All bits above the last valid bit | 265 /* Number of valid bits in bi_buf. All bits above the last valid bit |
263 * are always zero. | 266 * are always zero. |
264 */ | 267 */ |
265 | 268 |
266 ulg high_water; | 269 ulg high_water; |
267 /* High water mark offset in window for initialized bytes -- bytes above | 270 /* High water mark offset in window for initialized bytes -- bytes above |
268 * this are set to zero in order to avoid memory check warnings when | 271 * this are set to zero in order to avoid memory check warnings when |
269 * longest match routines access bytes past the input. This is then | 272 * longest match routines access bytes past the input. This is then |
270 * updated to the new high water mark. | 273 * updated to the new high water mark. |
271 */ | 274 */ |
272 | 275 |
273 } FAR deflate_state; | 276 } FAR deflate_state; |
274 | 277 |
275 /* Output a byte on the stream. | 278 /* Output a byte on the stream. |
276 * IN assertion: there is enough room in pending_buf. | 279 * IN assertion: there is enough room in pending_buf. |
277 */ | 280 */ |
278 #define put_byte(s, c) {s->pending_buf[s->pending++] = (c);} | 281 #define put_byte(s, c) {s->pending_buf[s->pending++] = (Bytef)(c);} |
279 | 282 |
280 | 283 |
281 #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1) | 284 #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1) |
282 /* Minimum amount of lookahead, except at the end of the input file. | 285 /* Minimum amount of lookahead, except at the end of the input file. |
283 * See deflate.c for comments about the MIN_MATCH+1. | 286 * See deflate.c for comments about the MIN_MATCH+1. |
284 */ | 287 */ |
285 | 288 |
286 #define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD) | 289 #define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD) |
287 /* In order to simplify the code, particularly on 16 bit machines, match | 290 /* In order to simplify the code, particularly on 16 bit machines, match |
288 * distances are limited to MAX_DIST instead of WSIZE. | 291 * distances are limited to MAX_DIST instead of WSIZE. |
(...skipping 13 matching lines...) Expand all Loading... |
302 void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf, | 305 void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf, |
303 ulg stored_len, int last)); | 306 ulg stored_len, int last)); |
304 | 307 |
305 #define d_code(dist) \ | 308 #define d_code(dist) \ |
306 ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)]) | 309 ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)]) |
307 /* Mapping from a distance to a distance code. dist is the distance - 1 and | 310 /* Mapping from a distance to a distance code. dist is the distance - 1 and |
308 * must not have side effects. _dist_code[256] and _dist_code[257] are never | 311 * must not have side effects. _dist_code[256] and _dist_code[257] are never |
309 * used. | 312 * used. |
310 */ | 313 */ |
311 | 314 |
312 #ifndef DEBUG | 315 #ifndef ZLIB_DEBUG |
313 /* Inline versions of _tr_tally for speed: */ | 316 /* Inline versions of _tr_tally for speed: */ |
314 | 317 |
315 #if defined(GEN_TREES_H) || !defined(STDC) | 318 #if defined(GEN_TREES_H) || !defined(STDC) |
316 extern uch ZLIB_INTERNAL _length_code[]; | 319 extern uch ZLIB_INTERNAL _length_code[]; |
317 extern uch ZLIB_INTERNAL _dist_code[]; | 320 extern uch ZLIB_INTERNAL _dist_code[]; |
318 #else | 321 #else |
319 extern const uch ZLIB_INTERNAL _length_code[]; | 322 extern const uch ZLIB_INTERNAL _length_code[]; |
320 extern const uch ZLIB_INTERNAL _dist_code[]; | 323 extern const uch ZLIB_INTERNAL _dist_code[]; |
321 #endif | 324 #endif |
322 | 325 |
323 # define _tr_tally_lit(s, c, flush) \ | 326 # define _tr_tally_lit(s, c, flush) \ |
324 { uch cc = (c); \ | 327 { uch cc = (c); \ |
325 s->d_buf[s->last_lit] = 0; \ | 328 s->d_buf[s->last_lit] = 0; \ |
326 s->l_buf[s->last_lit++] = cc; \ | 329 s->l_buf[s->last_lit++] = cc; \ |
327 s->dyn_ltree[cc].Freq++; \ | 330 s->dyn_ltree[cc].Freq++; \ |
328 flush = (s->last_lit == s->lit_bufsize-1); \ | 331 flush = (s->last_lit == s->lit_bufsize-1); \ |
329 } | 332 } |
330 # define _tr_tally_dist(s, distance, length, flush) \ | 333 # define _tr_tally_dist(s, distance, length, flush) \ |
331 { uch len = (length); \ | 334 { uch len = (uch)(length); \ |
332 ush dist = (distance); \ | 335 ush dist = (ush)(distance); \ |
333 s->d_buf[s->last_lit] = dist; \ | 336 s->d_buf[s->last_lit] = dist; \ |
334 s->l_buf[s->last_lit++] = len; \ | 337 s->l_buf[s->last_lit++] = len; \ |
335 dist--; \ | 338 dist--; \ |
336 s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \ | 339 s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \ |
337 s->dyn_dtree[d_code(dist)].Freq++; \ | 340 s->dyn_dtree[d_code(dist)].Freq++; \ |
338 flush = (s->last_lit == s->lit_bufsize-1); \ | 341 flush = (s->last_lit == s->lit_bufsize-1); \ |
339 } | 342 } |
340 #else | 343 #else |
341 # define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c) | 344 # define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c) |
342 # define _tr_tally_dist(s, distance, length, flush) \ | 345 # define _tr_tally_dist(s, distance, length, flush) \ |
343 flush = _tr_tally(s, distance, length) | 346 flush = _tr_tally(s, distance, length) |
344 #endif | 347 #endif |
345 | 348 |
346 /* Functions that are SIMD optimised on x86 */ | 349 /* Functions that are SIMD optimised on x86 */ |
347 void ZLIB_INTERNAL crc_fold_init(deflate_state* const s); | 350 void ZLIB_INTERNAL crc_fold_init(deflate_state* const s); |
348 void ZLIB_INTERNAL crc_fold_copy(deflate_state* const s, | 351 void ZLIB_INTERNAL crc_fold_copy(deflate_state* const s, |
349 unsigned char* dst, | 352 unsigned char* dst, |
350 const unsigned char* src, | 353 const unsigned char* src, |
351 long len); | 354 long len); |
352 unsigned ZLIB_INTERNAL crc_fold_512to32(deflate_state* const s); | 355 unsigned ZLIB_INTERNAL crc_fold_512to32(deflate_state* const s); |
353 | 356 |
354 void ZLIB_INTERNAL fill_window_sse(deflate_state* s); | 357 void ZLIB_INTERNAL fill_window_sse(deflate_state* s); |
355 | 358 |
356 #endif /* DEFLATE_H */ | 359 #endif /* DEFLATE_H */ |
OLD | NEW |