xref: /optee_os/core/lib/zlib/inftrees.h (revision b3be2f66b22b7fceaeb67c58f07c18b1b0611191)
1*b3be2f66SJerome Forissier /* inftrees.h -- header to use inftrees.c
2*b3be2f66SJerome Forissier  * Copyright (C) 1995-2005, 2010 Mark Adler
3*b3be2f66SJerome Forissier  * For conditions of distribution and use, see copyright notice in zlib.h
4*b3be2f66SJerome Forissier  */
5*b3be2f66SJerome Forissier 
6*b3be2f66SJerome Forissier /* WARNING: this file should *not* be used by applications. It is
7*b3be2f66SJerome Forissier    part of the implementation of the compression library and is
8*b3be2f66SJerome Forissier    subject to change. Applications should only use zlib.h.
9*b3be2f66SJerome Forissier  */
10*b3be2f66SJerome Forissier 
11*b3be2f66SJerome Forissier /* Structure for decoding tables.  Each entry provides either the
12*b3be2f66SJerome Forissier    information needed to do the operation requested by the code that
13*b3be2f66SJerome Forissier    indexed that table entry, or it provides a pointer to another
14*b3be2f66SJerome Forissier    table that indexes more bits of the code.  op indicates whether
15*b3be2f66SJerome Forissier    the entry is a pointer to another table, a literal, a length or
16*b3be2f66SJerome Forissier    distance, an end-of-block, or an invalid code.  For a table
17*b3be2f66SJerome Forissier    pointer, the low four bits of op is the number of index bits of
18*b3be2f66SJerome Forissier    that table.  For a length or distance, the low four bits of op
19*b3be2f66SJerome Forissier    is the number of extra bits to get after the code.  bits is
20*b3be2f66SJerome Forissier    the number of bits in this code or part of the code to drop off
21*b3be2f66SJerome Forissier    of the bit buffer.  val is the actual byte to output in the case
22*b3be2f66SJerome Forissier    of a literal, the base length or distance, or the offset from
23*b3be2f66SJerome Forissier    the current table to the next table.  Each entry is four bytes. */
24*b3be2f66SJerome Forissier typedef struct {
25*b3be2f66SJerome Forissier     unsigned char op;           /* operation, extra bits, table bits */
26*b3be2f66SJerome Forissier     unsigned char bits;         /* bits in this part of the code */
27*b3be2f66SJerome Forissier     unsigned short val;         /* offset in table or code value */
28*b3be2f66SJerome Forissier } code;
29*b3be2f66SJerome Forissier 
30*b3be2f66SJerome Forissier /* op values as set by inflate_table():
31*b3be2f66SJerome Forissier     00000000 - literal
32*b3be2f66SJerome Forissier     0000tttt - table link, tttt != 0 is the number of table index bits
33*b3be2f66SJerome Forissier     0001eeee - length or distance, eeee is the number of extra bits
34*b3be2f66SJerome Forissier     01100000 - end of block
35*b3be2f66SJerome Forissier     01000000 - invalid code
36*b3be2f66SJerome Forissier  */
37*b3be2f66SJerome Forissier 
38*b3be2f66SJerome Forissier /* Maximum size of the dynamic table.  The maximum number of code structures is
39*b3be2f66SJerome Forissier    1444, which is the sum of 852 for literal/length codes and 592 for distance
40*b3be2f66SJerome Forissier    codes.  These values were found by exhaustive searches using the program
41*b3be2f66SJerome Forissier    examples/enough.c found in the zlib distribtution.  The arguments to that
42*b3be2f66SJerome Forissier    program are the number of symbols, the initial root table size, and the
43*b3be2f66SJerome Forissier    maximum bit length of a code.  "enough 286 9 15" for literal/length codes
44*b3be2f66SJerome Forissier    returns returns 852, and "enough 30 6 15" for distance codes returns 592.
45*b3be2f66SJerome Forissier    The initial root table size (9 or 6) is found in the fifth argument of the
46*b3be2f66SJerome Forissier    inflate_table() calls in inflate.c and infback.c.  If the root table size is
47*b3be2f66SJerome Forissier    changed, then these maximum sizes would be need to be recalculated and
48*b3be2f66SJerome Forissier    updated. */
49*b3be2f66SJerome Forissier #define ENOUGH_LENS 852
50*b3be2f66SJerome Forissier #define ENOUGH_DISTS 592
51*b3be2f66SJerome Forissier #define ENOUGH (ENOUGH_LENS+ENOUGH_DISTS)
52*b3be2f66SJerome Forissier 
53*b3be2f66SJerome Forissier /* Type of code to build for inflate_table() */
54*b3be2f66SJerome Forissier typedef enum {
55*b3be2f66SJerome Forissier     CODES,
56*b3be2f66SJerome Forissier     LENS,
57*b3be2f66SJerome Forissier     DISTS
58*b3be2f66SJerome Forissier } codetype;
59*b3be2f66SJerome Forissier 
60*b3be2f66SJerome Forissier int ZLIB_INTERNAL inflate_table OF((codetype type, unsigned short FAR *lens,
61*b3be2f66SJerome Forissier                              unsigned codes, code FAR * FAR *table,
62*b3be2f66SJerome Forissier                              unsigned FAR *bits, unsigned short FAR *work));
63