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