comparison zlib/deflate.h @ 2690:9ef72ee5c0b0

Update vendored zlib to 1.3.1
author Michael Pavone <pavone@retrodev.com>
date Sun, 15 Jun 2025 15:39:33 -0700
parents 00d788dac91a
children
comparison
equal deleted inserted replaced
2689:bd6e33de0972 2690:9ef72ee5c0b0
1 /* deflate.h -- internal compression state 1 /* deflate.h -- internal compression state
2 * Copyright (C) 1995-2016 Jean-loup Gailly 2 * Copyright (C) 1995-2024 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
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. */
22 #ifndef NO_GZIP 22 #ifndef NO_GZIP
23 # define GZIP 23 # define GZIP
24 #endif 24 #endif
25
26 /* define LIT_MEM to slightly increase the speed of deflate (order 1% to 2%) at
27 the cost of a larger memory footprint */
28 /* #define LIT_MEM */
25 29
26 /* =========================================================================== 30 /* ===========================================================================
27 * Internal compression state. 31 * Internal compression state.
28 */ 32 */
29 33
215 219
216 uch depth[2*L_CODES+1]; 220 uch depth[2*L_CODES+1];
217 /* Depth of each subtree used as tie breaker for trees of equal frequency 221 /* Depth of each subtree used as tie breaker for trees of equal frequency
218 */ 222 */
219 223
220 uchf *l_buf; /* buffer for literals or lengths */ 224 #ifdef LIT_MEM
225 # define LIT_BUFS 5
226 ushf *d_buf; /* buffer for distances */
227 uchf *l_buf; /* buffer for literals/lengths */
228 #else
229 # define LIT_BUFS 4
230 uchf *sym_buf; /* buffer for distances and literals/lengths */
231 #endif
221 232
222 uInt lit_bufsize; 233 uInt lit_bufsize;
223 /* Size of match buffer for literals/lengths. There are 4 reasons for 234 /* Size of match buffer for literals/lengths. There are 4 reasons for
224 * limiting lit_bufsize to 64K: 235 * limiting lit_bufsize to 64K:
225 * - frequencies can be kept in 16 bit counters 236 * - frequencies can be kept in 16 bit counters
237 * fast adaptation but have of course the overhead of transmitting 248 * fast adaptation but have of course the overhead of transmitting
238 * trees more frequently. 249 * trees more frequently.
239 * - I can't count above 4 250 * - I can't count above 4
240 */ 251 */
241 252
242 uInt last_lit; /* running index in l_buf */ 253 uInt sym_next; /* running index in symbol buffer */
243 254 uInt sym_end; /* symbol table full when sym_next reaches this */
244 ushf *d_buf;
245 /* Buffer for distances. To simplify the code, d_buf and l_buf have
246 * the same number of elements. To use different lengths, an extra flag
247 * array would be necessary.
248 */
249 255
250 ulg opt_len; /* bit length of current block with optimal trees */ 256 ulg opt_len; /* bit length of current block with optimal trees */
251 ulg static_len; /* bit length of current block with static trees */ 257 ulg static_len; /* bit length of current block with static trees */
252 uInt matches; /* number of string matches in current block */ 258 uInt matches; /* number of string matches in current block */
253 uInt insert; /* bytes at end of window left to insert */ 259 uInt insert; /* bytes at end of window left to insert */
294 #define WIN_INIT MAX_MATCH 300 #define WIN_INIT MAX_MATCH
295 /* Number of bytes after end of data in window to initialize in order to avoid 301 /* Number of bytes after end of data in window to initialize in order to avoid
296 memory checker errors from longest match routines */ 302 memory checker errors from longest match routines */
297 303
298 /* in trees.c */ 304 /* in trees.c */
299 void ZLIB_INTERNAL _tr_init OF((deflate_state *s)); 305 void ZLIB_INTERNAL _tr_init(deflate_state *s);
300 int ZLIB_INTERNAL _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc)); 306 int ZLIB_INTERNAL _tr_tally(deflate_state *s, unsigned dist, unsigned lc);
301 void ZLIB_INTERNAL _tr_flush_block OF((deflate_state *s, charf *buf, 307 void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, charf *buf,
302 ulg stored_len, int last)); 308 ulg stored_len, int last);
303 void ZLIB_INTERNAL _tr_flush_bits OF((deflate_state *s)); 309 void ZLIB_INTERNAL _tr_flush_bits(deflate_state *s);
304 void ZLIB_INTERNAL _tr_align OF((deflate_state *s)); 310 void ZLIB_INTERNAL _tr_align(deflate_state *s);
305 void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf, 311 void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, charf *buf,
306 ulg stored_len, int last)); 312 ulg stored_len, int last);
307 313
308 #define d_code(dist) \ 314 #define d_code(dist) \
309 ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)]) 315 ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
310 /* Mapping from a distance to a distance code. dist is the distance - 1 and 316 /* Mapping from a distance to a distance code. dist is the distance - 1 and
311 * must not have side effects. _dist_code[256] and _dist_code[257] are never 317 * must not have side effects. _dist_code[256] and _dist_code[257] are never
321 #else 327 #else
322 extern const uch ZLIB_INTERNAL _length_code[]; 328 extern const uch ZLIB_INTERNAL _length_code[];
323 extern const uch ZLIB_INTERNAL _dist_code[]; 329 extern const uch ZLIB_INTERNAL _dist_code[];
324 #endif 330 #endif
325 331
332 #ifdef LIT_MEM
326 # define _tr_tally_lit(s, c, flush) \ 333 # define _tr_tally_lit(s, c, flush) \
327 { uch cc = (c); \ 334 { uch cc = (c); \
328 s->d_buf[s->last_lit] = 0; \ 335 s->d_buf[s->sym_next] = 0; \
329 s->l_buf[s->last_lit++] = cc; \ 336 s->l_buf[s->sym_next++] = cc; \
330 s->dyn_ltree[cc].Freq++; \ 337 s->dyn_ltree[cc].Freq++; \
331 flush = (s->last_lit == s->lit_bufsize-1); \ 338 flush = (s->sym_next == s->sym_end); \
332 } 339 }
333 # define _tr_tally_dist(s, distance, length, flush) \ 340 # define _tr_tally_dist(s, distance, length, flush) \
334 { uch len = (uch)(length); \ 341 { uch len = (uch)(length); \
335 ush dist = (ush)(distance); \ 342 ush dist = (ush)(distance); \
336 s->d_buf[s->last_lit] = dist; \ 343 s->d_buf[s->sym_next] = dist; \
337 s->l_buf[s->last_lit++] = len; \ 344 s->l_buf[s->sym_next++] = len; \
338 dist--; \ 345 dist--; \
339 s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \ 346 s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
340 s->dyn_dtree[d_code(dist)].Freq++; \ 347 s->dyn_dtree[d_code(dist)].Freq++; \
341 flush = (s->last_lit == s->lit_bufsize-1); \ 348 flush = (s->sym_next == s->sym_end); \
342 } 349 }
350 #else
351 # define _tr_tally_lit(s, c, flush) \
352 { uch cc = (c); \
353 s->sym_buf[s->sym_next++] = 0; \
354 s->sym_buf[s->sym_next++] = 0; \
355 s->sym_buf[s->sym_next++] = cc; \
356 s->dyn_ltree[cc].Freq++; \
357 flush = (s->sym_next == s->sym_end); \
358 }
359 # define _tr_tally_dist(s, distance, length, flush) \
360 { uch len = (uch)(length); \
361 ush dist = (ush)(distance); \
362 s->sym_buf[s->sym_next++] = (uch)dist; \
363 s->sym_buf[s->sym_next++] = (uch)(dist >> 8); \
364 s->sym_buf[s->sym_next++] = len; \
365 dist--; \
366 s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
367 s->dyn_dtree[d_code(dist)].Freq++; \
368 flush = (s->sym_next == s->sym_end); \
369 }
370 #endif
343 #else 371 #else
344 # define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c) 372 # define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c)
345 # define _tr_tally_dist(s, distance, length, flush) \ 373 # define _tr_tally_dist(s, distance, length, flush) \
346 flush = _tr_tally(s, distance, length) 374 flush = _tr_tally(s, distance, length)
347 #endif 375 #endif