xref: /utopia/UTPA2-700.0.x/modules/gpd/drv/gpd/inflate.h (revision 53ee8cc121a030b8d368113ac3e966b4705770ef)
1 //<MStar Software>
2 //******************************************************************************
3 // MStar Software
4 // Copyright (c) 2010 - 2012 MStar Semiconductor, Inc. All rights reserved.
5 // All software, firmware and related documentation herein ("MStar Software") are
6 // intellectual property of MStar Semiconductor, Inc. ("MStar") and protected by
7 // law, including, but not limited to, copyright law and international treaties.
8 // Any use, modification, reproduction, retransmission, or republication of all
9 // or part of MStar Software is expressly prohibited, unless prior written
10 // permission has been granted by MStar.
11 //
12 // By accessing, browsing and/or using MStar Software, you acknowledge that you
13 // have read, understood, and agree, to be bound by below terms ("Terms") and to
14 // comply with all applicable laws and regulations:
15 //
16 // 1. MStar shall retain any and all right, ownership and interest to MStar
17 //    Software and any modification/derivatives thereof.
18 //    No right, ownership, or interest to MStar Software and any
19 //    modification/derivatives thereof is transferred to you under Terms.
20 //
21 // 2. You understand that MStar Software might include, incorporate or be
22 //    supplied together with third party`s software and the use of MStar
23 //    Software may require additional licenses from third parties.
24 //    Therefore, you hereby agree it is your sole responsibility to separately
25 //    obtain any and all third party right and license necessary for your use of
26 //    such third party`s software.
27 //
28 // 3. MStar Software and any modification/derivatives thereof shall be deemed as
29 //    MStar`s confidential information and you agree to keep MStar`s
30 //    confidential information in strictest confidence and not disclose to any
31 //    third party.
32 //
33 // 4. MStar Software is provided on an "AS IS" basis without warranties of any
34 //    kind. Any warranties are hereby expressly disclaimed by MStar, including
35 //    without limitation, any warranties of merchantability, non-infringement of
36 //    intellectual property rights, fitness for a particular purpose, error free
37 //    and in conformity with any international standard.  You agree to waive any
38 //    claim against MStar for any loss, damage, cost or expense that you may
39 //    incur related to your use of MStar Software.
40 //    In no event shall MStar be liable for any direct, indirect, incidental or
41 //    consequential damages, including without limitation, lost of profit or
42 //    revenues, lost or damage of data, and unauthorized system use.
43 //    You agree that this Section 4 shall still apply without being affected
44 //    even if MStar Software has been modified by MStar in accordance with your
45 //    request or instruction for your use, except otherwise agreed by both
46 //    parties in writing.
47 //
48 // 5. If requested, MStar may from time to time provide technical supports or
49 //    services in relation with MStar Software to you for your use of
50 //    MStar Software in conjunction with your or your customer`s product
51 //    ("Services").
52 //    You understand and agree that, except otherwise agreed by both parties in
53 //    writing, Services are provided on an "AS IS" basis and the warranty
54 //    disclaimer set forth in Section 4 above shall apply.
55 //
56 // 6. Nothing contained herein shall be construed as by implication, estoppels
57 //    or otherwise:
58 //    (a) conferring any license or right to use MStar name, trademark, service
59 //        mark, symbol or any other identification;
60 //    (b) obligating MStar or any of its affiliates to furnish any person,
61 //        including without limitation, you and your customers, any assistance
62 //        of any kind whatsoever, or any information; or
63 //    (c) conferring any license or right under any intellectual property right.
64 //
65 // 7. These terms shall be governed by and construed in accordance with the laws
66 //    of Taiwan, R.O.C., excluding its conflict of law rules.
67 //    Any and all dispute arising out hereof or related hereto shall be finally
68 //    settled by arbitration referred to the Chinese Arbitration Association,
69 //    Taipei in accordance with the ROC Arbitration Law and the Arbitration
70 //    Rules of the Association by three (3) arbitrators appointed in accordance
71 //    with the said Rules.
72 //    The place of arbitration shall be in Taipei, Taiwan and the language shall
73 //    be English.
74 //    The arbitration award shall be final and binding to both parties.
75 //
76 //******************************************************************************
77 //<MStar Software>
78 /* inflate.h -- internal inflate state definition
79  * Copyright (C) 1995-2004 Mark Adler
80  * For conditions of distribution and use, see copyright notice in zlib.h
81  */
82 
83 /* WARNING: this file should *not* be used by applications. It is
84    part of the implementation of the compression library and is
85    subject to change. Applications should only use zlib.h.
86  */
87 
88 /* define NO_GZIP when compiling if you want to disable gzip header and
89    trailer decoding by inflate().  NO_GZIP would be used to avoid linking in
90    the crc code when it is not needed.  For shared libraries, gzip decoding
91    should be left enabled. */
92 #ifndef NO_GZIP
93 #  define GUNZIP
94 #endif
95 
96 /* Possible inflate modes between inflate() calls */
97 typedef enum {
98     HEAD,       /* i: waiting for magic header */
99     FLAGS,      /* i: waiting for method and flags (gzip) */
100     TIME,       /* i: waiting for modification time (gzip) */
101     OS,         /* i: waiting for extra flags and operating system (gzip) */
102     EXLEN,      /* i: waiting for extra length (gzip) */
103     EXTRA,      /* i: waiting for extra bytes (gzip) */
104     NAME,       /* i: waiting for end of file name (gzip) */
105     COMMENT,    /* i: waiting for end of comment (gzip) */
106     HCRC,       /* i: waiting for header crc (gzip) */
107     DICTID,     /* i: waiting for dictionary check value */
108     DICT,       /* waiting for inflateSetDictionary() call */
109         TYPE,       /* i: waiting for type bits, including last-flag bit */
110         TYPEDO,     /* i: same, but skip check to exit inflate on new block */
111         STORED,     /* i: waiting for stored size (length and complement) */
112         COPY,       /* i/o: waiting for input or output to copy stored block */
113         TABLE,      /* i: waiting for dynamic block table lengths */
114         LENLENS,    /* i: waiting for code length code lengths */
115         CODELENS,   /* i: waiting for length/lit and distance code lengths */
116             LEN,        /* i: waiting for length/lit code */
117             LENEXT,     /* i: waiting for length extra bits */
118             DIST,       /* i: waiting for distance code */
119             DISTEXT,    /* i: waiting for distance extra bits */
120             MATCH,      /* o: waiting for output space to copy string */
121             LIT,        /* o: waiting for output space to write literal */
122     CHECK,      /* i: waiting for 32-bit check value */
123     LENGTH,     /* i: waiting for 32-bit length (gzip) */
124     DONE,       /* finished check, done -- remain here until reset */
125     BAD,        /* got a data error -- remain here until reset */
126     MEM,        /* got an inflate() memory error -- remain here until reset */
127     SYNC        /* looking for synchronization bytes to restart inflate() */
128 } inflate_mode;
129 
130 /*
131     State transitions between above modes -
132 
133     (most modes can go to the BAD or MEM mode -- not shown for clarity)
134 
135     Process header:
136         HEAD -> (gzip) or (zlib)
137         (gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME
138         NAME -> COMMENT -> HCRC -> TYPE
139         (zlib) -> DICTID or TYPE
140         DICTID -> DICT -> TYPE
141     Read deflate blocks:
142             TYPE -> STORED or TABLE or LEN or CHECK
143             STORED -> COPY -> TYPE
144             TABLE -> LENLENS -> CODELENS -> LEN
145     Read deflate codes:
146                 LEN -> LENEXT or LIT or TYPE
147                 LENEXT -> DIST -> DISTEXT -> MATCH -> LEN
148                 LIT -> LEN
149     Process trailer:
150         CHECK -> LENGTH -> DONE
151  */
152 
153 /* state maintained between inflate() calls.  Approximately 7K bytes. */
154 struct inflate_state {
155     inflate_mode mode;          /* current inflate mode */
156     MS_U32 last;                   /* true if processing last block */
157     MS_U32 wrap;                   /* bit 0 true for zlib, bit 1 true for gzip */
158     MS_U32 havedict;               /* true if dictionary provided */
159     MS_U32 flags;                  /* gzip header method and flags (0 if zlib) */
160     MS_U32 dmax;              /* zlib header max distance (INFLATE_STRICT) */
161     MS_U32 check;        /* protected copy of check value */
162     MS_U32 total;        /* protected copy of output count */
163     gz_headerp head;            /* where to save gzip header information */
164         /* sliding window */
165     MS_U32 wbits;             /* log base 2 of requested window size */
166     MS_U32 wsize;             /* window size or zero if not using window */
167     MS_U32 whave;             /* valid bytes in the window */
168     MS_U32 write;             /* window write index */
169     MS_U8 FAR *window;  /* allocated sliding window, if needed */
170         /* bit accumulator */
171     MS_U32 hold;         /* input bit accumulator */
172     MS_U32 bits;              /* number of bits in "in" */
173         /* for string and stored block copying */
174     MS_U32 length;            /* literal or length of data to copy */
175     MS_U32 offset;            /* distance back to copy string from */
176         /* for table and code decoding */
177     MS_U32 extra;             /* extra bits needed */
178         /* fixed and dynamic code tables */
179     code const FAR *lencode;    /* starting table for length/literal codes */
180     code const FAR *distcode;   /* starting table for distance codes */
181     MS_U32 lenbits;           /* index bits for lencode */
182     MS_U32 distbits;          /* index bits for distcode */
183         /* dynamic table building */
184     MS_U32 ncode;             /* number of code length code lengths */
185     MS_U32 nlen;              /* number of length code lengths */
186     MS_U32 ndist;             /* number of distance code lengths */
187     MS_U32 have;              /* number of code lengths in lens[] */
188     code FAR *next;             /* next available space in codes[] */
189     MS_U16 lens[320];   /* temporary storage for code lengths */
190     MS_U16 work[288];   /* work area for code table building */
191     code codes[ENOUGH];         /* space for code tables */
192 };
193