117651Speter/* inftrees.h -- header to use inftrees.c
2206924Sdelphij * Copyright (C) 1995-2005, 2010 Mark Adler
3131377Stjr * For conditions of distribution and use, see copyright notice in zlib.h
417651Speter */
517651Speter
617651Speter/* WARNING: this file should *not* be used by applications. It is
717651Speter   part of the implementation of the compression library and is
817651Speter   subject to change. Applications should only use zlib.h.
917651Speter */
1017651Speter
11131377Stjr/* Structure for decoding tables.  Each entry provides either the
12131377Stjr   information needed to do the operation requested by the code that
13131377Stjr   indexed that table entry, or it provides a pointer to another
14131377Stjr   table that indexes more bits of the code.  op indicates whether
15131377Stjr   the entry is a pointer to another table, a literal, a length or
16131377Stjr   distance, an end-of-block, or an invalid code.  For a table
17131377Stjr   pointer, the low four bits of op is the number of index bits of
18131377Stjr   that table.  For a length or distance, the low four bits of op
19131377Stjr   is the number of extra bits to get after the code.  bits is
20131377Stjr   the number of bits in this code or part of the code to drop off
21131377Stjr   of the bit buffer.  val is the actual byte to output in the case
22131377Stjr   of a literal, the base length or distance, or the offset from
23131377Stjr   the current table to the next table.  Each entry is four bytes. */
24131377Stjrtypedef struct {
25131377Stjr    unsigned char op;           /* operation, extra bits, table bits */
26131377Stjr    unsigned char bits;         /* bits in this part of the code */
27131377Stjr    unsigned short val;         /* offset in table or code value */
28131377Stjr} code;
2917651Speter
30131377Stjr/* op values as set by inflate_table():
31131377Stjr    00000000 - literal
32131377Stjr    0000tttt - table link, tttt != 0 is the number of table index bits
33131377Stjr    0001eeee - length or distance, eeee is the number of extra bits
34131377Stjr    01100000 - end of block
35131377Stjr    01000000 - invalid code
36131377Stjr */
3717651Speter
38205471Sdelphij/* Maximum size of the dynamic table.  The maximum number of code structures is
39205471Sdelphij   1444, which is the sum of 852 for literal/length codes and 592 for distance
40205471Sdelphij   codes.  These values were found by exhaustive searches using the program
41205471Sdelphij   examples/enough.c found in the zlib distribtution.  The arguments to that
42205471Sdelphij   program are the number of symbols, the initial root table size, and the
43205471Sdelphij   maximum bit length of a code.  "enough 286 9 15" for literal/length codes
44205471Sdelphij   returns returns 852, and "enough 30 6 15" for distance codes returns 592.
45205471Sdelphij   The initial root table size (9 or 6) is found in the fifth argument of the
46205471Sdelphij   inflate_table() calls in inflate.c and infback.c.  If the root table size is
47205471Sdelphij   changed, then these maximum sizes would be need to be recalculated and
48205471Sdelphij   updated. */
49205471Sdelphij#define ENOUGH_LENS 852
50205471Sdelphij#define ENOUGH_DISTS 592
51205471Sdelphij#define ENOUGH (ENOUGH_LENS+ENOUGH_DISTS)
5217651Speter
53205471Sdelphij/* Type of code to build for inflate_table() */
54131377Stjrtypedef enum {
55131377Stjr    CODES,
56131377Stjr    LENS,
57131377Stjr    DISTS
58131377Stjr} codetype;
5917651Speter
60206924Sdelphijint ZLIB_INTERNAL inflate_table OF((codetype type, unsigned short FAR *lens,
61131377Stjr                             unsigned codes, code FAR * FAR *table,
62131377Stjr                             unsigned FAR *bits, unsigned short FAR *work));
63