135534e26Sdownsj /* inftrees.h -- header to use inftrees.c 236f395ceStb * Copyright (C) 1995-2005, 2010 Mark Adler 335534e26Sdownsj * For conditions of distribution and use, see copyright notice in zlib.h 435534e26Sdownsj */ 535534e26Sdownsj 635534e26Sdownsj /* WARNING: this file should *not* be used by applications. It is 735534e26Sdownsj part of the implementation of the compression library and is 835534e26Sdownsj subject to change. Applications should only use zlib.h. 935534e26Sdownsj */ 1035534e26Sdownsj 11a79de952Smillert /* Structure for decoding tables. Each entry provides either the 12a79de952Smillert information needed to do the operation requested by the code that 13a79de952Smillert indexed that table entry, or it provides a pointer to another 14a79de952Smillert table that indexes more bits of the code. op indicates whether 15a79de952Smillert the entry is a pointer to another table, a literal, a length or 16a79de952Smillert distance, an end-of-block, or an invalid code. For a table 17a79de952Smillert pointer, the low four bits of op is the number of index bits of 18a79de952Smillert that table. For a length or distance, the low four bits of op 19a79de952Smillert is the number of extra bits to get after the code. bits is 20a79de952Smillert the number of bits in this code or part of the code to drop off 21a79de952Smillert of the bit buffer. val is the actual byte to output in the case 22a79de952Smillert of a literal, the base length or distance, or the offset from 23a79de952Smillert the current table to the next table. Each entry is four bytes. */ 24a79de952Smillert typedef struct { 25a79de952Smillert unsigned char op; /* operation, extra bits, table bits */ 26a79de952Smillert unsigned char bits; /* bits in this part of the code */ 27a79de952Smillert unsigned short val; /* offset in table or code value */ 28a79de952Smillert } code; 2935534e26Sdownsj 30a79de952Smillert /* op values as set by inflate_table(): 31a79de952Smillert 00000000 - literal 32a79de952Smillert 0000tttt - table link, tttt != 0 is the number of table index bits 33a79de952Smillert 0001eeee - length or distance, eeee is the number of extra bits 34a79de952Smillert 01100000 - end of block 35a79de952Smillert 01000000 - invalid code 36a79de952Smillert */ 3735534e26Sdownsj 3836f395ceStb /* Maximum size of the dynamic table. The maximum number of code structures is 3936f395ceStb 1444, which is the sum of 852 for literal/length codes and 592 for distance 4036f395ceStb codes. These values were found by exhaustive searches using the program 41ddf65acdStb examples/enough.c found in the zlib distribution. The arguments to that 4236f395ceStb program are the number of symbols, the initial root table size, and the 4336f395ceStb maximum bit length of a code. "enough 286 9 15" for literal/length codes 44*85d95931Stb returns 852, and "enough 30 6 15" for distance codes returns 592. The 45*85d95931Stb initial root table size (9 or 6) is found in the fifth argument of the 4636f395ceStb inflate_table() calls in inflate.c and infback.c. If the root table size is 4736f395ceStb changed, then these maximum sizes would be need to be recalculated and 4836f395ceStb updated. */ 4936f395ceStb #define ENOUGH_LENS 852 5036f395ceStb #define ENOUGH_DISTS 592 5136f395ceStb #define ENOUGH (ENOUGH_LENS+ENOUGH_DISTS) 5235534e26Sdownsj 5336f395ceStb /* Type of code to build for inflate_table() */ 54a79de952Smillert typedef enum { 55a79de952Smillert CODES, 56a79de952Smillert LENS, 57a79de952Smillert DISTS 58a79de952Smillert } codetype; 5935534e26Sdownsj 60cfac609cStb int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens, 61a79de952Smillert unsigned codes, code FAR * FAR *table, 62cfac609cStb unsigned FAR *bits, unsigned short FAR *work); 63