istereo

annotate libs/zlib/inflate.h @ 26:862a3329a8f0

wohooo, added a shitload of code from zlib/libpng/libjpeg. When the good lord was raining shared libraries the iphone held a fucking umbrella...
author John Tsiombikas <nuclear@mutantstargoat.com>
date Thu, 08 Sep 2011 06:28:38 +0300
parents
children
rev   line source
nuclear@26 1 /* inflate.h -- internal inflate state definition
nuclear@26 2 * Copyright (C) 1995-2004 Mark Adler
nuclear@26 3 * For conditions of distribution and use, see copyright notice in zlib.h
nuclear@26 4 */
nuclear@26 5
nuclear@26 6 /* WARNING: this file should *not* be used by applications. It is
nuclear@26 7 part of the implementation of the compression library and is
nuclear@26 8 subject to change. Applications should only use zlib.h.
nuclear@26 9 */
nuclear@26 10
nuclear@26 11 /* define NO_GZIP when compiling if you want to disable gzip header and
nuclear@26 12 trailer decoding by inflate(). NO_GZIP would be used to avoid linking in
nuclear@26 13 the crc code when it is not needed. For shared libraries, gzip decoding
nuclear@26 14 should be left enabled. */
nuclear@26 15 #ifndef NO_GZIP
nuclear@26 16 # define GUNZIP
nuclear@26 17 #endif
nuclear@26 18
nuclear@26 19 /* Possible inflate modes between inflate() calls */
nuclear@26 20 typedef enum {
nuclear@26 21 HEAD, /* i: waiting for magic header */
nuclear@26 22 FLAGS, /* i: waiting for method and flags (gzip) */
nuclear@26 23 TIME, /* i: waiting for modification time (gzip) */
nuclear@26 24 OS, /* i: waiting for extra flags and operating system (gzip) */
nuclear@26 25 EXLEN, /* i: waiting for extra length (gzip) */
nuclear@26 26 EXTRA, /* i: waiting for extra bytes (gzip) */
nuclear@26 27 NAME, /* i: waiting for end of file name (gzip) */
nuclear@26 28 COMMENT, /* i: waiting for end of comment (gzip) */
nuclear@26 29 HCRC, /* i: waiting for header crc (gzip) */
nuclear@26 30 DICTID, /* i: waiting for dictionary check value */
nuclear@26 31 DICT, /* waiting for inflateSetDictionary() call */
nuclear@26 32 TYPE, /* i: waiting for type bits, including last-flag bit */
nuclear@26 33 TYPEDO, /* i: same, but skip check to exit inflate on new block */
nuclear@26 34 STORED, /* i: waiting for stored size (length and complement) */
nuclear@26 35 COPY, /* i/o: waiting for input or output to copy stored block */
nuclear@26 36 TABLE, /* i: waiting for dynamic block table lengths */
nuclear@26 37 LENLENS, /* i: waiting for code length code lengths */
nuclear@26 38 CODELENS, /* i: waiting for length/lit and distance code lengths */
nuclear@26 39 LEN, /* i: waiting for length/lit code */
nuclear@26 40 LENEXT, /* i: waiting for length extra bits */
nuclear@26 41 DIST, /* i: waiting for distance code */
nuclear@26 42 DISTEXT, /* i: waiting for distance extra bits */
nuclear@26 43 MATCH, /* o: waiting for output space to copy string */
nuclear@26 44 LIT, /* o: waiting for output space to write literal */
nuclear@26 45 CHECK, /* i: waiting for 32-bit check value */
nuclear@26 46 LENGTH, /* i: waiting for 32-bit length (gzip) */
nuclear@26 47 DONE, /* finished check, done -- remain here until reset */
nuclear@26 48 BAD, /* got a data error -- remain here until reset */
nuclear@26 49 MEM, /* got an inflate() memory error -- remain here until reset */
nuclear@26 50 SYNC /* looking for synchronization bytes to restart inflate() */
nuclear@26 51 } inflate_mode;
nuclear@26 52
nuclear@26 53 /*
nuclear@26 54 State transitions between above modes -
nuclear@26 55
nuclear@26 56 (most modes can go to the BAD or MEM mode -- not shown for clarity)
nuclear@26 57
nuclear@26 58 Process header:
nuclear@26 59 HEAD -> (gzip) or (zlib)
nuclear@26 60 (gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME
nuclear@26 61 NAME -> COMMENT -> HCRC -> TYPE
nuclear@26 62 (zlib) -> DICTID or TYPE
nuclear@26 63 DICTID -> DICT -> TYPE
nuclear@26 64 Read deflate blocks:
nuclear@26 65 TYPE -> STORED or TABLE or LEN or CHECK
nuclear@26 66 STORED -> COPY -> TYPE
nuclear@26 67 TABLE -> LENLENS -> CODELENS -> LEN
nuclear@26 68 Read deflate codes:
nuclear@26 69 LEN -> LENEXT or LIT or TYPE
nuclear@26 70 LENEXT -> DIST -> DISTEXT -> MATCH -> LEN
nuclear@26 71 LIT -> LEN
nuclear@26 72 Process trailer:
nuclear@26 73 CHECK -> LENGTH -> DONE
nuclear@26 74 */
nuclear@26 75
nuclear@26 76 /* state maintained between inflate() calls. Approximately 7K bytes. */
nuclear@26 77 struct inflate_state {
nuclear@26 78 inflate_mode mode; /* current inflate mode */
nuclear@26 79 int last; /* true if processing last block */
nuclear@26 80 int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
nuclear@26 81 int havedict; /* true if dictionary provided */
nuclear@26 82 int flags; /* gzip header method and flags (0 if zlib) */
nuclear@26 83 unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */
nuclear@26 84 unsigned long check; /* protected copy of check value */
nuclear@26 85 unsigned long total; /* protected copy of output count */
nuclear@26 86 gz_headerp head; /* where to save gzip header information */
nuclear@26 87 /* sliding window */
nuclear@26 88 unsigned wbits; /* log base 2 of requested window size */
nuclear@26 89 unsigned wsize; /* window size or zero if not using window */
nuclear@26 90 unsigned whave; /* valid bytes in the window */
nuclear@26 91 unsigned write; /* window write index */
nuclear@26 92 unsigned char FAR *window; /* allocated sliding window, if needed */
nuclear@26 93 /* bit accumulator */
nuclear@26 94 unsigned long hold; /* input bit accumulator */
nuclear@26 95 unsigned bits; /* number of bits in "in" */
nuclear@26 96 /* for string and stored block copying */
nuclear@26 97 unsigned length; /* literal or length of data to copy */
nuclear@26 98 unsigned offset; /* distance back to copy string from */
nuclear@26 99 /* for table and code decoding */
nuclear@26 100 unsigned extra; /* extra bits needed */
nuclear@26 101 /* fixed and dynamic code tables */
nuclear@26 102 code const FAR *lencode; /* starting table for length/literal codes */
nuclear@26 103 code const FAR *distcode; /* starting table for distance codes */
nuclear@26 104 unsigned lenbits; /* index bits for lencode */
nuclear@26 105 unsigned distbits; /* index bits for distcode */
nuclear@26 106 /* dynamic table building */
nuclear@26 107 unsigned ncode; /* number of code length code lengths */
nuclear@26 108 unsigned nlen; /* number of length code lengths */
nuclear@26 109 unsigned ndist; /* number of distance code lengths */
nuclear@26 110 unsigned have; /* number of code lengths in lens[] */
nuclear@26 111 code FAR *next; /* next available space in codes[] */
nuclear@26 112 unsigned short lens[320]; /* temporary storage for code lengths */
nuclear@26 113 unsigned short work[288]; /* work area for code table building */
nuclear@26 114 code codes[ENOUGH]; /* space for code tables */
nuclear@26 115 };