00001 // $Id: zinflate.h 751 2006-03-31 15:43:49Z alex $ 00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE 00003 ================================XARAHEADERSTART=========================== 00004 00005 Xara LX, a vector drawing and manipulation program. 00006 Copyright (C) 1993-2006 Xara Group Ltd. 00007 Copyright on certain contributions may be held in joint with their 00008 respective authors. See AUTHORS file for details. 00009 00010 LICENSE TO USE AND MODIFY SOFTWARE 00011 ---------------------------------- 00012 00013 This file is part of Xara LX. 00014 00015 Xara LX is free software; you can redistribute it and/or modify it 00016 under the terms of the GNU General Public License version 2 as published 00017 by the Free Software Foundation. 00018 00019 Xara LX and its component source files are distributed in the hope 00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the 00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00022 See the GNU General Public License for more details. 00023 00024 You should have received a copy of the GNU General Public License along 00025 with Xara LX (see the file GPL in the root directory of the 00026 distribution); if not, write to the Free Software Foundation, Inc., 51 00027 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00028 00029 00030 ADDITIONAL RIGHTS 00031 ----------------- 00032 00033 Conditional upon your continuing compliance with the GNU General Public 00034 License described above, Xara Group Ltd grants to you certain additional 00035 rights. 00036 00037 The additional rights are to use, modify, and distribute the software 00038 together with the wxWidgets library, the wxXtra library, and the "CDraw" 00039 library and any other such library that any version of Xara LX relased 00040 by Xara Group Ltd requires in order to compile and execute, including 00041 the static linking of that library to XaraLX. In the case of the 00042 "CDraw" library, you may satisfy obligation under the GNU General Public 00043 License to provide source code by providing a binary copy of the library 00044 concerned and a copy of the license accompanying it. 00045 00046 Nothing in this section restricts any of the rights you have under 00047 the GNU General Public License. 00048 00049 00050 SCOPE OF LICENSE 00051 ---------------- 00052 00053 This license applies to this program (XaraLX) and its constituent source 00054 files only, and does not necessarily apply to other Xara products which may 00055 in part share the same code base, and are subject to their own licensing 00056 terms. 00057 00058 This license does not apply to files in the wxXtra directory, which 00059 are built into a separate library, and are subject to the wxWindows 00060 license contained within that directory in the file "WXXTRA-LICENSE". 00061 00062 This license does not apply to the binary libraries (if any) within 00063 the "libs" directory, which are subject to a separate license contained 00064 within that directory in the file "LIBS-LICENSE". 00065 00066 00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS 00068 ---------------------------------------------- 00069 00070 Subject to the terms of the GNU Public License (see above), you are 00071 free to do whatever you like with your modifications. However, you may 00072 (at your option) wish contribute them to Xara's source tree. You can 00073 find details of how to do this at: 00074 http://www.xaraxtreme.org/developers/ 00075 00076 Prior to contributing your modifications, you will need to complete our 00077 contributor agreement. This can be found at: 00078 http://www.xaraxtreme.org/developers/contribute/ 00079 00080 Please note that Xara will not accept modifications which modify any of 00081 the text between the start and end of this header (marked 00082 XARAHEADERSTART and XARAHEADEREND). 00083 00084 00085 MARKS 00086 ----- 00087 00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara 00089 designs are registered or unregistered trademarks, design-marks, and/or 00090 service marks of Xara Group Ltd. All rights in these marks are reserved. 00091 00092 00093 Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK. 00094 http://www.xara.com/ 00095 00096 =================================XARAHEADEREND============================ 00097 */ 00098 00099 // This class contains all the file deflating code 00100 00101 #ifndef INC_ZIPINFLATE 00102 #define INC_ZIPINFLATE 00103 00104 #include "zutil.h" 00105 00106 class ZStream; 00107 00108 /* Huffman code lookup table entry--this entry is four bytes for machines 00109 that have 16-bit pointers (e.g. PC's in the small or medium model). 00110 Valid extra bits (exop) are 0..13. exop == -64 is EOB (end of block), 00111 exop == 16 means that v is a literal, exop < 0 means that v is a pointer 00112 to the next table, which codes -exop bits, and lastly exop == -128 00113 indicates an unused code. If a code with exop == -128 is looked up, 00114 this implies an error in the data. */ 00115 00116 //#if defined(STDC) || defined(sgi) 00117 //typedef signed char Char; 00118 //#else 00119 typedef char Char; /* just hope that char is signed */ 00120 //#endif 00121 00122 // ------------------------------------------------------------------------------------------ 00123 // From inftrees.h 00124 // ------------------------------------------------------------------------------------------ 00125 00126 /* Huffman code lookup table entry--this entry is four bytes for machines 00127 that have 16-bit pointers (e.g. PC's in the small or medium model). */ 00128 00129 typedef struct inflate_huft_s FAR inflate_huft; 00130 00131 struct inflate_huft_s { 00132 union 00133 { 00134 struct 00135 { 00136 Byte Exop; /* number of extra bits or operation */ 00137 Byte Bits; /* number of bits in this code or subcode */ 00138 } what; 00139 Bytef *pad; /* pad structure to a power of 2 (4 bytes for */ 00140 } word; /* 16-bit, 8 bytes for 32-bit machines) */ 00141 union 00142 { 00143 uInt Base; /* literal, length base, or distance base */ 00144 inflate_huft *Next; /* pointer to next level of table */ 00145 } more; 00146 }; 00147 00148 /******************************************************************************************** 00149 00150 ********************************************************************************************/ 00151 00152 /* And'ing with mask[n] masks the lower n bits */ 00153 extern uInt inflate_mask[]; 00154 00155 // ------------------------------------------------------------------------------------------ 00156 // From inftrees.h 00157 // ------------------------------------------------------------------------------------------ 00158 00159 /******************************************************************************************** 00160 ********************************************************************************************/ 00161 00162 enum InflateCodesMode 00163 { /* waiting for "i:"=input, "o:"=output, "x:"=nothing */ 00164 START, /* x: set up for LEN */ 00165 LEN, /* i: get length/literal/eob next */ 00166 LENEXT, /* i: getting length extra (have base) */ 00167 DIST, /* i: get distance next */ 00168 DISTEXT, /* i: getting distance extra */ 00169 COPY, /* o: copying bytes in window, waiting for space */ 00170 LIT, /* o: got literal, waiting for output space */ 00171 WASH, /* o: got eob, possibly still output waiting */ 00172 END, /* x: got eob and all data flushed */ 00173 BADCODE /* x: got error */ 00174 }; 00175 00176 /******************************************************************************************** 00177 00178 > class inflate_codes_state : public CCObject 00179 00180 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> Humprhys 00181 Created: 23/5/95 00182 Purpose: An inflate codes state object for use by the inflater for the file compressor 00183 and decompressor. 00184 00185 ********************************************************************************************/ 00186 00187 class inflate_codes_state : public CC_CLASS_MEMDUMP 00188 { 00189 // Give my name in memory dumps 00190 // If you need a different sort of decare, replace this one. 00191 // See CCObject in the help file for info about DECLARE types 00192 CC_DECLARE_MEMDUMP(inflate_codes_state); 00193 00194 public: 00195 inflate_codes_state() {}; 00196 ~inflate_codes_state() {}; 00197 00198 public: 00199 /* mode */ 00200 InflateCodesMode mode; /* current inflate_codes mode */ 00201 00202 /* mode dependent information */ 00203 uInt len; 00204 union 00205 { 00206 struct 00207 { 00208 inflate_huft *tree; /* pointer into tree */ 00209 uInt need; /* bits needed */ 00210 } code; /* if LEN or DIST, where in tree */ 00211 00212 uInt lit; /* if LIT, literal */ 00213 00214 struct 00215 { 00216 uInt get; /* bits to get for extra */ 00217 uInt dist; /* distance back to copy from */ 00218 } copy; /* if EXT or COPY, where and how much */ 00219 00220 } sub; /* submode */ 00221 00222 /* mode independent information */ 00223 Byte lbits; /* ltree bits decoded per branch */ 00224 Byte dbits; /* dtree bits decoder per branch */ 00225 inflate_huft *ltree; /* literal/length/eob tree */ 00226 inflate_huft *dtree; /* distance tree */ 00227 00228 }; 00229 00230 // ------------------------------------------------------------------------------------------ 00231 // From infutil.h 00232 // ------------------------------------------------------------------------------------------ 00233 00234 /******************************************************************************************** 00235 ********************************************************************************************/ 00236 00237 enum InflateBlockMode 00238 { 00239 TYPE, /* get type bits (3, including end bit) */ 00240 LENS, /* get lengths for stored */ 00241 STORED, /* processing stored block */ 00242 TABLE, /* get table lengths */ 00243 BTREE, /* get bit lengths tree for a dynamic block */ 00244 DTREE, /* get length, distance trees for a dynamic block */ 00245 CODES, /* processing fixed or dynamic block */ 00246 DRY, /* output remaining window bytes */ 00247 BLOCKDONE,/* finished last block, done */ 00248 BLOCKBAD /* got a data error--stuck here */ 00249 }; 00250 00251 /******************************************************************************************** 00252 00253 > class inflate_blocks_state : public CCObject 00254 00255 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> Humprhys 00256 Created: 23/5/95 00257 Purpose: An inflate blocks state object for use by the inflater for the file compressor 00258 and decompressor. 00259 00260 ********************************************************************************************/ 00261 00262 class inflate_blocks_state : public CC_CLASS_MEMDUMP 00263 { 00264 // Give my name in memory dumps 00265 // If you need a different sort of decare, replace this one. 00266 // See CCObject in the help file for info about DECLARE types 00267 CC_DECLARE_MEMDUMP(inflate_blocks_state); 00268 00269 public: 00270 inflate_blocks_state() {}; 00271 ~inflate_blocks_state() {}; 00272 00273 public: 00274 /* inflate blocks semi-private state */ 00275 InflateBlockMode mode; /* current inflate_block mode */ 00276 00277 /* mode dependent information */ 00278 union { 00279 uInt left; /* if STORED, bytes left to copy */ 00280 struct 00281 { 00282 uInt table; /* table lengths (14 bits) */ 00283 uInt index; /* index into blens (or border) */ 00284 uInt *blens; /* bit lengths of codes */ 00285 uInt bb; /* bit length tree depth */ 00286 inflate_huft *tb; /* bit length decoding tree */ 00287 } trees; /* if DTREE, decoding info for trees */ 00288 struct 00289 { 00290 inflate_huft *tl, *td; /* trees to free */ 00291 inflate_codes_state *codes; 00292 } decode; /* if CODES, current state */ 00293 } sub; /* submode */ 00294 uInt last; /* true if this block is the last block */ 00295 00296 /* mode independent information */ 00297 uInt bitk; /* bits in bit buffer */ 00298 uLong bitb; /* bit buffer */ 00299 Bytef *window; /* sliding window */ 00300 Bytef *end; /* one byte after sliding window */ 00301 Bytef *read; /* window read pointer */ 00302 Bytef *write; /* window write pointer */ 00303 check_func checkfn; /* check function */ 00304 uLong check; /* check on output */ 00305 }; 00306 00307 // ------------------------------------------------------------------------------------------ 00308 // From ?.c 00309 // ------------------------------------------------------------------------------------------ 00310 00311 /******************************************************************************************** 00312 ********************************************************************************************/ 00313 00314 /* current inflate mode */ 00315 00316 enum InflateMode 00317 { 00318 METHOD, /* waiting for method byte */ 00319 FLAG, /* waiting for flag byte */ 00320 DICT4, /* four dictionary check bytes to go */ 00321 DICT3, /* three dictionary check bytes to go */ 00322 DICT2, /* two dictionary check bytes to go */ 00323 DICT1, /* one dictionary check byte to go */ 00324 DICT0, /* waiting for inflateSetDictionary */ 00325 BLOCKS, /* decompressing blocks */ 00326 CHECK4, /* four check bytes to go */ 00327 CHECK3, /* three check bytes to go */ 00328 CHECK2, /* two check bytes to go */ 00329 CHECK1, /* one check byte to go */ 00330 DONE, /* finished check, done */ 00331 BAD /* got an error--stay here */ 00332 }; 00333 00334 /******************************************************************************************** 00335 00336 > class InflateState : public CCObject 00337 00338 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> Humprhys 00339 Created: 23/5/95 00340 Purpose: An inflate state object for use by the inflater for the file compressor 00341 and decompressor. 00342 00343 ********************************************************************************************/ 00344 00345 class InflateState : public CC_CLASS_MEMDUMP 00346 { 00347 // Give my name in memory dumps 00348 // If you need a different sort of decare, replace this one. 00349 // See CCObject in the help file for info about DECLARE types 00350 CC_DECLARE_MEMDUMP(InflateState); 00351 00352 public: 00353 InflateState() {}; 00354 ~InflateState() {}; 00355 00356 public: 00357 InflateMode mode; /* current inflate mode */ 00358 00359 /* mode dependent information */ 00360 union { 00361 uInt method; /* if FLAGS, method byte */ 00362 struct 00363 { 00364 uLong was; /* computed check value */ 00365 uLong need; /* stream check value */ 00366 } check; /* if CHECK, check values to compare */ 00367 uInt marker; /* if BAD, inflateSync's marker bytes count */ 00368 } sub; /* submode */ 00369 00370 /* mode independent information */ 00371 INT32 nowrap; /* flag for no wrapper */ 00372 uInt wbits; /* log2(window size) (8..15, defaults to 15) */ 00373 inflate_blocks_state *blocks; /* current inflate_blocks state */ 00374 00375 protected: 00376 00377 }; 00378 00379 /******************************************************************************************** 00380 00381 > class ZipInflate : public CCObject 00382 00383 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> Humprhys 00384 Created: 23/5/95 00385 Purpose: The inflater for the file compressor and decompressor. 00386 Allows the CCDiskFile to offer compression of files. At present just 00387 used to compress the native file format. 00388 00389 ********************************************************************************************/ 00390 00391 class ZipInflate : public CC_CLASS_MEMDUMP 00392 { 00393 // Give my name in memory dumps 00394 // If you need a different sort of decare, replace this one. 00395 // See CCObject in the help file for info about DECLARE types 00396 CC_DECLARE_MEMDUMP(ZipInflate); 00397 00398 public: 00399 ZipInflate(); 00400 ~ZipInflate(); 00401 00402 public: 00403 INT32 Init(ZStream *strm); 00404 00405 INT32 inflate(ZStream *strm, INT32 flush); 00406 00407 INT32 SetDictionary(ZStream *z, const Bytef *dictionary, uInt dictLength); 00408 00409 INT32 End(ZStream *strm); 00410 00411 INT32 Init(ZStream *strm, INT32 windowBits); 00412 00413 INT32 Sync(ZStream *strm); 00414 00415 INT32 Reset(ZStream *strm); 00416 00417 protected: 00418 // from infutil.h 00419 // copy as much as possible from the sliding window to the output area 00420 INT32 inflate_flush(inflate_blocks_state *, ZStream *, INT32); 00421 00422 // from infblocks.h 00423 inflate_blocks_state *inflate_blocks_new(ZStream *, check_func, uInt); 00424 00425 INT32 inflate_blocks(inflate_blocks_state *, ZStream *, INT32); 00426 00427 void inflate_blocks_reset(inflate_blocks_state *, ZStream *, uLongf *); 00428 00429 INT32 inflate_blocks_free(inflate_blocks_state *, ZStream *, uLongf *); 00430 00431 // New version 0.99 00432 void inflate_set_dictionary( 00433 inflate_blocks_state *s, 00434 const Bytef *d, /* dictionary */ 00435 uInt n); /* dictionary length */ 00436 00437 // from inftrees.h 00438 #ifdef DEBUG 00439 uInt inflate_hufts; 00440 #endif 00441 00442 INT32 inflate_trees_bits( 00443 uIntf *, /* 19 code lengths */ 00444 uIntf *, /* bits tree desired/actual depth */ 00445 inflate_huft * FAR *, /* bits tree result */ 00446 ZStream *); /* for zalloc, zfree functions */ 00447 00448 INT32 inflate_trees_dynamic( 00449 uInt, /* number of literal/length codes */ 00450 uInt, /* number of distance codes */ 00451 uIntf *, /* that many (total) code lengths */ 00452 uIntf *, /* literal desired/actual bit depth */ 00453 uIntf *, /* distance desired/actual bit depth */ 00454 inflate_huft * FAR *, /* literal/length tree result */ 00455 inflate_huft * FAR *, /* distance tree result */ 00456 ZStream *); /* for zalloc, zfree functions */ 00457 00458 INT32 inflate_trees_fixed( 00459 uIntf *, /* literal desired/actual bit depth */ 00460 uIntf *, /* distance desired/actual bit depth */ 00461 inflate_huft * FAR *, /* literal/length tree result */ 00462 inflate_huft * FAR *); /* distance tree result */ 00463 00464 INT32 inflate_trees_free( 00465 inflate_huft *, /* tables to free */ 00466 ZStream *); /* for zfree function */ 00467 00468 // inftrees.c 00469 INT32 huft_build( 00470 uIntf *, /* code lengths in bits */ 00471 uInt, /* number of codes */ 00472 uInt, /* number of "simple" codes */ 00473 uIntf *, /* list of base values for non-simple codes */ 00474 uIntf *, /* list of extra bits for non-simple codes */ 00475 inflate_huft * FAR*,/* result: starting table */ 00476 uIntf *, /* maximum lookup bits (returns actual) */ 00477 ZStream *); /* for zalloc function */ 00478 00479 //voidpf falloc( 00480 // voidpf, /* opaque pointer (not used) */ 00481 // uInt, /* number of items */ 00482 // uInt); /* size of item */ 00483 00484 00485 // from inffast.h 00486 INT32 inflate_fast(uInt, uInt, inflate_huft *, inflate_huft *, 00487 inflate_blocks_state *, ZStream *); 00488 00489 // from infcodes.h 00490 inflate_codes_state *inflate_codes_new( uInt, uInt, 00491 inflate_huft *, inflate_huft *, 00492 ZStream *); 00493 00494 INT32 inflate_codes(inflate_blocks_state *, ZStream *, INT32); 00495 00496 void inflate_codes_free(inflate_codes_state *, ZStream *); 00497 00498 }; 00499 00500 #endif // INC_ZIPINFLATE 00501 00502