c9431fa1e59a88c2f0abf611f25b97af964449e5ahl/* deflate.h -- internal compression state
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl * Copyright (C) 1995-2004 Jean-loup Gailly
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl * For conditions of distribution and use, see copyright notice in zlib.h
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl/* WARNING: this file should *not* be used by applications. It is
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl part of the implementation of the compression library and is
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl subject to change. Applications should only use zlib.h.
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl#ifndef _DEFLATE_H
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl#define _DEFLATE_H
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl#pragma ident "%Z%%M% %I% %E% SMI"
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl#include "zutil.h"
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl/* define NO_GZIP when compiling if you want to disable gzip header and
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl trailer creation by deflate(). NO_GZIP would be used to avoid linking in
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl the crc code when it is not needed. For shared libraries, gzip encoding
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl should be left enabled. */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl#ifndef NO_GZIP
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl# define GZIP
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl#endif
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl/* ===========================================================================
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl * Internal compression state.
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl#define LENGTH_CODES 29
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl/* number of length codes, not counting the special END_BLOCK code */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl#define LITERALS 256
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl/* number of literal bytes 0..255 */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl#define L_CODES (LITERALS+1+LENGTH_CODES)
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl/* number of Literal or Length codes, including the END_BLOCK code */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl#define D_CODES 30
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl/* number of distance codes */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl#define BL_CODES 19
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl/* number of codes used to transfer the bit lengths */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl#define HEAP_SIZE (2*L_CODES+1)
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl/* maximum heap size */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl#define MAX_BITS 15
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl/* All codes must not exceed MAX_BITS bits */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl#define INIT_STATE 42
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl#define EXTRA_STATE 69
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl#define NAME_STATE 73
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl#define COMMENT_STATE 91
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl#define HCRC_STATE 103
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl#define BUSY_STATE 113
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl#define FINISH_STATE 666
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl/* Stream status */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl/* Data structure describing a single value and its code string. */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahltypedef struct ct_data_s {
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl union {
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl ush freq; /* frequency count */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl ush code; /* bit string */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl } fc;
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl union {
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl ush dad; /* father node in Huffman tree */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl ush len; /* length of bit string */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl } dl;
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl} FAR ct_data;
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl#define Freq fc.freq
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl#define Code fc.code
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl#define Dad dl.dad
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl#define Len dl.len
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahltypedef struct static_tree_desc_s static_tree_desc;
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahltypedef struct tree_desc_s {
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl ct_data *dyn_tree; /* the dynamic tree */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl int max_code; /* largest code with non zero frequency */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl static_tree_desc *stat_desc; /* the corresponding static tree */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl} FAR tree_desc;
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahltypedef ush Pos;
c9431fa1e59a88c2f0abf611f25b97af964449e5ahltypedef Pos FAR Posf;
c9431fa1e59a88c2f0abf611f25b97af964449e5ahltypedef unsigned IPos;
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl/* A Pos is an index in the character window. We use short instead of int to
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl * save space in the various tables. IPos is used only for parameter passing.
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahltypedef struct internal_state {
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl z_streamp strm; /* pointer back to this zlib stream */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl int status; /* as the name implies */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl Bytef *pending_buf; /* output still pending */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl ulg pending_buf_size; /* size of pending_buf */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl Bytef *pending_out; /* next pending byte to output to the stream */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl uInt pending; /* nb of bytes in the pending buffer */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl gz_headerp gzhead; /* gzip header information to write */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl uInt gzindex; /* where in extra, name, or comment */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl Byte method; /* STORED (for zip only) or DEFLATED */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl int last_flush; /* value of flush param for previous deflate call */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl /* used by deflate.c: */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl uInt w_size; /* LZ77 window size (32K by default) */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl uInt w_bits; /* log2(w_size) (8..16) */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl uInt w_mask; /* w_size - 1 */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl Bytef *window;
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl /* Sliding window. Input bytes are read into the second half of the window,
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl * and move to the first half later to keep a dictionary of at least wSize
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl * bytes. With this organization, matches are limited to a distance of
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl * wSize-MAX_MATCH bytes, but this ensures that IO is always
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl * performed with a length multiple of the block size. Also, it limits
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl * the window size to 64K, which is quite useful on MSDOS.
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl * To do: use the user input buffer as sliding window.
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl ulg window_size;
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl /* Actual size of window: 2*wSize, except when the user input buffer
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl * is directly used as sliding window.
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl Posf *prev;
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl /* Link to older string with same hash index. To limit the size of this
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl * array to 64K, this link is maintained only for the last 32K strings.
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl * An index in this array is thus a window index modulo 32K.
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl Posf *head; /* Heads of the hash chains or NIL. */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl uInt ins_h; /* hash index of string to be inserted */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl uInt hash_size; /* number of elements in hash table */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl uInt hash_bits; /* log2(hash_size) */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl uInt hash_mask; /* hash_size-1 */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl uInt hash_shift;
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl /* Number of bits by which ins_h must be shifted at each input
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl * step. It must be such that after MIN_MATCH steps, the oldest
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl * byte no longer takes part in the hash key, that is:
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl * hash_shift * MIN_MATCH >= hash_bits
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl long block_start;
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl /* Window position at the beginning of the current output block. Gets
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl * negative when the window is moved backwards.
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl uInt match_length; /* length of best match */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl IPos prev_match; /* previous match */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl int match_available; /* set if previous match exists */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl uInt strstart; /* start of string to insert */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl uInt match_start; /* start of matching string */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl uInt lookahead; /* number of valid bytes ahead in window */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl uInt prev_length;
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl /* Length of the best match at previous step. Matches not greater than this
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl * are discarded. This is used in the lazy match evaluation.
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl uInt max_chain_length;
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl /* To speed up deflation, hash chains are never searched beyond this
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl * length. A higher limit improves compression ratio but degrades the
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl * speed.
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl uInt max_lazy_match;
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl /* Attempt to find a better match only when the current match is strictly
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl * smaller than this value. This mechanism is used only for compression
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl * levels >= 4.
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl# define max_insert_length max_lazy_match
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl /* Insert new strings in the hash table only if the match length is not
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl * greater than this length. This saves time but degrades compression.
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl * max_insert_length is used only for compression levels <= 3.
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl int level; /* compression level (1..9) */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl int strategy; /* favor or force Huffman coding*/
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl uInt good_match;
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl /* Use a faster search when the previous match is longer than this */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl int nice_match; /* Stop searching when current match exceeds this */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl /* used by trees.c: */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl /* Didn't use ct_data typedef below to supress compiler warning */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl struct tree_desc_s l_desc; /* desc. for literal tree */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl struct tree_desc_s d_desc; /* desc. for distance tree */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl struct tree_desc_s bl_desc; /* desc. for bit length tree */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl ush bl_count[MAX_BITS+1];
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl /* number of codes at each bit length for an optimal tree */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl int heap_len; /* number of elements in the heap */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl int heap_max; /* element of largest frequency */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl /* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used.
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl * The same heap array is used to build all trees.
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl uch depth[2*L_CODES+1];
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl /* Depth of each subtree used as tie breaker for trees of equal frequency
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl uchf *l_buf; /* buffer for literals or lengths */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl uInt lit_bufsize;
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl /* Size of match buffer for literals/lengths. There are 4 reasons for
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl * limiting lit_bufsize to 64K:
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl * - frequencies can be kept in 16 bit counters
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl * - if compression is not successful for the first block, all input
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl * data is still in the window so we can still emit a stored block even
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl * when input comes from standard input. (This can also be done for
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl * all blocks if lit_bufsize is not greater than 32K.)
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl * - if compression is not successful for a file smaller than 64K, we can
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl * even emit a stored file instead of a stored block (saving 5 bytes).
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl * This is applicable only for zip (not gzip or zlib).
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl * - creating new Huffman trees less frequently may not provide fast
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl * adaptation to changes in the input data statistics. (Take for
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl * example a binary file with poorly compressible code followed by
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl * a highly compressible string table.) Smaller buffer sizes give
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl * fast adaptation but have of course the overhead of transmitting
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl * trees more frequently.
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl * - I can't count above 4
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl uInt last_lit; /* running index in l_buf */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl ushf *d_buf;
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl /* Buffer for distances. To simplify the code, d_buf and l_buf have
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl * the same number of elements. To use different lengths, an extra flag
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl * array would be necessary.
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl ulg opt_len; /* bit length of current block with optimal trees */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl ulg static_len; /* bit length of current block with static trees */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl uInt matches; /* number of string matches in current block */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl int last_eob_len; /* bit length of EOB code for last block */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl#ifdef DEBUG
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl ulg compressed_len; /* total bit length of compressed file mod 2^32 */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl ulg bits_sent; /* bit length of compressed data sent mod 2^32 */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl#endif
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl ush bi_buf;
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl /* Output buffer. bits are inserted starting at the bottom (least
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl * significant bits).
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl int bi_valid;
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl /* Number of valid bits in bi_buf. All bits above the last valid bit
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl * are always zero.
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl} FAR deflate_state;
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl/* Output a byte on the stream.
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl * IN assertion: there is enough room in pending_buf.
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl#define put_byte(s, c) {s->pending_buf[s->pending++] = (c);}
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl/* Minimum amount of lookahead, except at the end of the input file.
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl * See deflate.c for comments about the MIN_MATCH+1.
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl#define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD)
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl/* In order to simplify the code, particularly on 16 bit machines, match
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl * distances are limited to MAX_DIST instead of WSIZE.
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl /* in trees.c */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahlvoid _tr_init OF((deflate_state *s));
c9431fa1e59a88c2f0abf611f25b97af964449e5ahlint _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc));
c9431fa1e59a88c2f0abf611f25b97af964449e5ahlvoid _tr_flush_block OF((deflate_state *s, charf *buf, ulg stored_len,
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl int eof));
c9431fa1e59a88c2f0abf611f25b97af964449e5ahlvoid _tr_align OF((deflate_state *s));
c9431fa1e59a88c2f0abf611f25b97af964449e5ahlvoid _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len,
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl int eof));
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl#define d_code(dist) \
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl/* Mapping from a distance to a distance code. dist is the distance - 1 and
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl * must not have side effects. _dist_code[256] and _dist_code[257] are never
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl * used.
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl#ifndef DEBUG
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl/* Inline versions of _tr_tally for speed: */
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl#if defined(GEN_TREES_H) || !defined(STDC)
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl extern uch _length_code[];
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl extern uch _dist_code[];
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl#else
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl extern const uch _length_code[];
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl extern const uch _dist_code[];
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl#endif
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl# define _tr_tally_lit(s, c, flush) \
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl { uch cc = (c); \
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl s->d_buf[s->last_lit] = 0; \
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl s->l_buf[s->last_lit++] = cc; \
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl s->dyn_ltree[cc].Freq++; \
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl flush = (s->last_lit == s->lit_bufsize-1); \
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl }
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl# define _tr_tally_dist(s, distance, length, flush) \
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl { uch len = (length); \
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl ush dist = (distance); \
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl s->d_buf[s->last_lit] = dist; \
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl s->l_buf[s->last_lit++] = len; \
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl dist--; \
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl s->dyn_dtree[d_code(dist)].Freq++; \
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl flush = (s->last_lit == s->lit_bufsize-1); \
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl }
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl#else
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl# define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c)
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl# define _tr_tally_dist(s, distance, length, flush) \
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl flush = _tr_tally(s, distance, length)
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl#endif
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl#endif /* _DEFLATE_H */