Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenbzlib_private.h
Go to the documentation of this file.
00001 00002 /*-------------------------------------------------------------*/ 00003 /*--- Private header file for the library. ---*/ 00004 /*--- bzlib_private.h ---*/ 00005 /*-------------------------------------------------------------*/ 00006 00007 /* ------------------------------------------------------------------ 00008 This file is part of bzip2/libbzip2, a program and library for 00009 lossless, block-sorting data compression. 00010 00011 bzip2/libbzip2 version 1.0.6 of 6 September 2010 00012 Copyright (C) 1996-2010 Julian Seward <jseward@bzip.org> 00013 00014 Please read the WARNING, DISCLAIMER and PATENTS sections in the 00015 README file. 00016 00017 This program is released under the terms of the license contained 00018 in the file LICENSE. 00019 ------------------------------------------------------------------ */ 00020 00021 00022 #ifndef _BZLIB_PRIVATE_H 00023 #define _BZLIB_PRIVATE_H 00024 00025 #include <stdlib.h> 00026 00027 #ifndef BZ_NO_STDIO 00028 #include <stdio.h> 00029 #include <ctype.h> 00030 #include <string.h> 00031 #endif 00032 00033 #include "bzlib.h" 00034 00035 00036 00037 /*-- General stuff. --*/ 00038 00039 #define BZ_VERSION "1.0.6, 6-Sept-2010" 00040 00041 typedef char Char; 00042 typedef unsigned char Bool; 00043 typedef unsigned char UChar; 00044 typedef int Int32; 00045 typedef unsigned int UInt32; 00046 typedef short Int16; 00047 typedef unsigned short UInt16; 00048 00049 #define True ((Bool)1) 00050 #define False ((Bool)0) 00051 00052 #ifndef __GNUC__ 00053 #define __inline__ /* */ 00054 #endif 00055 00056 #ifndef BZ_NO_STDIO 00057 00058 extern void BZ2_bz__AssertH__fail ( int errcode ); 00059 #define AssertH(cond,errcode) \ 00060 { if (!(cond)) BZ2_bz__AssertH__fail ( errcode ); } 00061 00062 #if BZ_DEBUG 00063 #define AssertD(cond,msg) \ 00064 { if (!(cond)) { \ 00065 fprintf ( stderr, \ 00066 "\n\nlibbzip2(debug build): internal error\n\t%s\n", msg );\ 00067 exit(1); \ 00068 }} 00069 #else 00070 #define AssertD(cond,msg) /* */ 00071 #endif 00072 00073 #define VPrintf0(zf) \ 00074 fprintf(stderr,zf) 00075 #define VPrintf1(zf,za1) \ 00076 fprintf(stderr,zf,za1) 00077 #define VPrintf2(zf,za1,za2) \ 00078 fprintf(stderr,zf,za1,za2) 00079 #define VPrintf3(zf,za1,za2,za3) \ 00080 fprintf(stderr,zf,za1,za2,za3) 00081 #define VPrintf4(zf,za1,za2,za3,za4) \ 00082 fprintf(stderr,zf,za1,za2,za3,za4) 00083 #define VPrintf5(zf,za1,za2,za3,za4,za5) \ 00084 fprintf(stderr,zf,za1,za2,za3,za4,za5) 00085 00086 #else 00087 00088 extern void bz_internal_error ( int errcode ); 00089 #define AssertH(cond,errcode) \ 00090 { if (!(cond)) bz_internal_error ( errcode ); } 00091 #define AssertD(cond,msg) do { } while (0) 00092 #define VPrintf0(zf) do { } while (0) 00093 #define VPrintf1(zf,za1) do { } while (0) 00094 #define VPrintf2(zf,za1,za2) do { } while (0) 00095 #define VPrintf3(zf,za1,za2,za3) do { } while (0) 00096 #define VPrintf4(zf,za1,za2,za3,za4) do { } while (0) 00097 #define VPrintf5(zf,za1,za2,za3,za4,za5) do { } while (0) 00098 00099 #endif 00100 00101 00102 #define BZALLOC(nnn) (strm->bzalloc)(strm->opaque,(nnn),1) 00103 #define BZFREE(ppp) (strm->bzfree)(strm->opaque,(ppp)) 00104 00105 00106 /*-- Header bytes. --*/ 00107 00108 #define BZ_HDR_B 0x42 /* 'B' */ 00109 #define BZ_HDR_Z 0x5a /* 'Z' */ 00110 #define BZ_HDR_h 0x68 /* 'h' */ 00111 #define BZ_HDR_0 0x30 /* '0' */ 00112 00113 /*-- Constants for the back end. --*/ 00114 00115 #define BZ_MAX_ALPHA_SIZE 258 00116 #define BZ_MAX_CODE_LEN 23 00117 00118 #define BZ_RUNA 0 00119 #define BZ_RUNB 1 00120 00121 #define BZ_N_GROUPS 6 00122 #define BZ_G_SIZE 50 00123 #define BZ_N_ITERS 4 00124 00125 #define BZ_MAX_SELECTORS (2 + (900000 / BZ_G_SIZE)) 00126 00127 00128 00129 /*-- Stuff for randomising repetitive blocks. --*/ 00130 00131 extern Int32 BZ2_rNums[512]; 00132 00133 #define BZ_RAND_DECLS \ 00134 Int32 rNToGo; \ 00135 Int32 rTPos \ 00136 00137 #define BZ_RAND_INIT_MASK \ 00138 s->rNToGo = 0; \ 00139 s->rTPos = 0 \ 00140 00141 #define BZ_RAND_MASK ((s->rNToGo == 1) ? 1 : 0) 00142 00143 #define BZ_RAND_UPD_MASK \ 00144 if (s->rNToGo == 0) { \ 00145 s->rNToGo = BZ2_rNums[s->rTPos]; \ 00146 s->rTPos++; \ 00147 if (s->rTPos == 512) s->rTPos = 0; \ 00148 } \ 00149 s->rNToGo--; 00150 00151 00152 00153 /*-- Stuff for doing CRCs. --*/ 00154 00155 extern UInt32 BZ2_crc32Table[256]; 00156 00157 #define BZ_INITIALISE_CRC(crcVar) \ 00158 { \ 00159 crcVar = 0xffffffffL; \ 00160 } 00161 00162 #define BZ_FINALISE_CRC(crcVar) \ 00163 { \ 00164 crcVar = ~(crcVar); \ 00165 } 00166 00167 #define BZ_UPDATE_CRC(crcVar,cha) \ 00168 { \ 00169 crcVar = (crcVar << 8) ^ \ 00170 BZ2_crc32Table[(crcVar >> 24) ^ \ 00171 ((UChar)cha)]; \ 00172 } 00173 00174 00175 00176 /*-- States and modes for compression. --*/ 00177 00178 #define BZ_M_IDLE 1 00179 #define BZ_M_RUNNING 2 00180 #define BZ_M_FLUSHING 3 00181 #define BZ_M_FINISHING 4 00182 00183 #define BZ_S_OUTPUT 1 00184 #define BZ_S_INPUT 2 00185 00186 #define BZ_N_RADIX 2 00187 #define BZ_N_QSORT 12 00188 #define BZ_N_SHELL 18 00189 #define BZ_N_OVERSHOOT (BZ_N_RADIX + BZ_N_QSORT + BZ_N_SHELL + 2) 00190 00191 00192 00193 00194 /*-- Structure holding all the compression-side stuff. --*/ 00195 00196 typedef 00197 struct { 00198 /* pointer back to the struct bz_stream */ 00199 bz_stream* strm; 00200 00201 /* mode this stream is in, and whether inputting */ 00202 /* or outputting data */ 00203 Int32 mode; 00204 Int32 state; 00205 00206 /* remembers avail_in when flush/finish requested */ 00207 UInt32 avail_in_expect; 00208 00209 /* for doing the block sorting */ 00210 UInt32* arr1; 00211 UInt32* arr2; 00212 UInt32* ftab; 00213 Int32 origPtr; 00214 00215 /* aliases for arr1 and arr2 */ 00216 UInt32* ptr; 00217 UChar* block; 00218 UInt16* mtfv; 00219 UChar* zbits; 00220 00221 /* for deciding when to use the fallback sorting algorithm */ 00222 Int32 workFactor; 00223 00224 /* run-length-encoding of the input */ 00225 UInt32 state_in_ch; 00226 Int32 state_in_len; 00227 BZ_RAND_DECLS; 00228 00229 /* input and output limits and current posns */ 00230 Int32 nblock; 00231 Int32 nblockMAX; 00232 Int32 numZ; 00233 Int32 state_out_pos; 00234 00235 /* map of bytes used in block */ 00236 Int32 nInUse; 00237 Bool inUse[256]; 00238 UChar unseqToSeq[256]; 00239 00240 /* the buffer for bit stream creation */ 00241 UInt32 bsBuff; 00242 Int32 bsLive; 00243 00244 /* block and combined CRCs */ 00245 UInt32 blockCRC; 00246 UInt32 combinedCRC; 00247 00248 /* misc administratium */ 00249 Int32 verbosity; 00250 Int32 blockNo; 00251 Int32 blockSize100k; 00252 00253 /* stuff for coding the MTF values */ 00254 Int32 nMTF; 00255 Int32 mtfFreq [BZ_MAX_ALPHA_SIZE]; 00256 UChar selector [BZ_MAX_SELECTORS]; 00257 UChar selectorMtf[BZ_MAX_SELECTORS]; 00258 00259 UChar len [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE]; 00260 Int32 code [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE]; 00261 Int32 rfreq [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE]; 00262 /* second dimension: only 3 needed; 4 makes index calculations faster */ 00263 UInt32 len_pack[BZ_MAX_ALPHA_SIZE][4]; 00264 00265 } 00266 EState; 00267 00268 00269 00270 /*-- externs for compression. --*/ 00271 00272 extern void 00273 BZ2_blockSort ( EState* ); 00274 00275 extern void 00276 BZ2_compressBlock ( EState*, Bool ); 00277 00278 extern void 00279 BZ2_bsInitWrite ( EState* ); 00280 00281 extern void 00282 BZ2_hbAssignCodes ( Int32*, UChar*, Int32, Int32, Int32 ); 00283 00284 extern void 00285 BZ2_hbMakeCodeLengths ( UChar*, Int32*, Int32, Int32 ); 00286 00287 00288 00289 /*-- states for decompression. --*/ 00290 00291 #define BZ_X_IDLE 1 00292 #define BZ_X_OUTPUT 2 00293 00294 #define BZ_X_MAGIC_1 10 00295 #define BZ_X_MAGIC_2 11 00296 #define BZ_X_MAGIC_3 12 00297 #define BZ_X_MAGIC_4 13 00298 #define BZ_X_BLKHDR_1 14 00299 #define BZ_X_BLKHDR_2 15 00300 #define BZ_X_BLKHDR_3 16 00301 #define BZ_X_BLKHDR_4 17 00302 #define BZ_X_BLKHDR_5 18 00303 #define BZ_X_BLKHDR_6 19 00304 #define BZ_X_BCRC_1 20 00305 #define BZ_X_BCRC_2 21 00306 #define BZ_X_BCRC_3 22 00307 #define BZ_X_BCRC_4 23 00308 #define BZ_X_RANDBIT 24 00309 #define BZ_X_ORIGPTR_1 25 00310 #define BZ_X_ORIGPTR_2 26 00311 #define BZ_X_ORIGPTR_3 27 00312 #define BZ_X_MAPPING_1 28 00313 #define BZ_X_MAPPING_2 29 00314 #define BZ_X_SELECTOR_1 30 00315 #define BZ_X_SELECTOR_2 31 00316 #define BZ_X_SELECTOR_3 32 00317 #define BZ_X_CODING_1 33 00318 #define BZ_X_CODING_2 34 00319 #define BZ_X_CODING_3 35 00320 #define BZ_X_MTF_1 36 00321 #define BZ_X_MTF_2 37 00322 #define BZ_X_MTF_3 38 00323 #define BZ_X_MTF_4 39 00324 #define BZ_X_MTF_5 40 00325 #define BZ_X_MTF_6 41 00326 #define BZ_X_ENDHDR_2 42 00327 #define BZ_X_ENDHDR_3 43 00328 #define BZ_X_ENDHDR_4 44 00329 #define BZ_X_ENDHDR_5 45 00330 #define BZ_X_ENDHDR_6 46 00331 #define BZ_X_CCRC_1 47 00332 #define BZ_X_CCRC_2 48 00333 #define BZ_X_CCRC_3 49 00334 #define BZ_X_CCRC_4 50 00335 00336 00337 00338 /*-- Constants for the fast MTF decoder. --*/ 00339 00340 #define MTFA_SIZE 4096 00341 #define MTFL_SIZE 16 00342 00343 00344 00345 /*-- Structure holding all the decompression-side stuff. --*/ 00346 00347 typedef 00348 struct { 00349 /* pointer back to the struct bz_stream */ 00350 bz_stream* strm; 00351 00352 /* state indicator for this stream */ 00353 Int32 state; 00354 00355 /* for doing the final run-length decoding */ 00356 UChar state_out_ch; 00357 Int32 state_out_len; 00358 Bool blockRandomised; 00359 BZ_RAND_DECLS; 00360 00361 /* the buffer for bit stream reading */ 00362 UInt32 bsBuff; 00363 Int32 bsLive; 00364 00365 /* misc administratium */ 00366 Int32 blockSize100k; 00367 Bool smallDecompress; 00368 Int32 currBlockNo; 00369 Int32 verbosity; 00370 00371 /* for undoing the Burrows-Wheeler transform */ 00372 Int32 origPtr; 00373 UInt32 tPos; 00374 Int32 k0; 00375 Int32 unzftab[256]; 00376 Int32 nblock_used; 00377 Int32 cftab[257]; 00378 Int32 cftabCopy[257]; 00379 00380 /* for undoing the Burrows-Wheeler transform (FAST) */ 00381 UInt32 *tt; 00382 00383 /* for undoing the Burrows-Wheeler transform (SMALL) */ 00384 UInt16 *ll16; 00385 UChar *ll4; 00386 00387 /* stored and calculated CRCs */ 00388 UInt32 storedBlockCRC; 00389 UInt32 storedCombinedCRC; 00390 UInt32 calculatedBlockCRC; 00391 UInt32 calculatedCombinedCRC; 00392 00393 /* map of bytes used in block */ 00394 Int32 nInUse; 00395 Bool inUse[256]; 00396 Bool inUse16[16]; 00397 UChar seqToUnseq[256]; 00398 00399 /* for decoding the MTF values */ 00400 UChar mtfa [MTFA_SIZE]; 00401 Int32 mtfbase[256 / MTFL_SIZE]; 00402 UChar selector [BZ_MAX_SELECTORS]; 00403 UChar selectorMtf[BZ_MAX_SELECTORS]; 00404 UChar len [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE]; 00405 00406 Int32 limit [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE]; 00407 Int32 base [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE]; 00408 Int32 perm [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE]; 00409 Int32 minLens[BZ_N_GROUPS]; 00410 00411 /* save area for scalars in the main decompress code */ 00412 Int32 save_i; 00413 Int32 save_j; 00414 Int32 save_t; 00415 Int32 save_alphaSize; 00416 Int32 save_nGroups; 00417 Int32 save_nSelectors; 00418 Int32 save_EOB; 00419 Int32 save_groupNo; 00420 Int32 save_groupPos; 00421 Int32 save_nextSym; 00422 Int32 save_nblockMAX; 00423 Int32 save_nblock; 00424 Int32 save_es; 00425 Int32 save_N; 00426 Int32 save_curr; 00427 Int32 save_zt; 00428 Int32 save_zn; 00429 Int32 save_zvec; 00430 Int32 save_zj; 00431 Int32 save_gSel; 00432 Int32 save_gMinlen; 00433 Int32* save_gLimit; 00434 Int32* save_gBase; 00435 Int32* save_gPerm; 00436 00437 } 00438 DState; 00439 00440 00441 00442 /*-- Macros for decompression. --*/ 00443 00444 #define BZ_GET_FAST(cccc) \ 00445 /* c_tPos is unsigned, hence test < 0 is pointless. */ \ 00446 if (s->tPos >= (UInt32)100000 * (UInt32)s->blockSize100k) return True; \ 00447 s->tPos = s->tt[s->tPos]; \ 00448 cccc = (UChar)(s->tPos & 0xff); \ 00449 s->tPos >>= 8; 00450 00451 #define BZ_GET_FAST_C(cccc) \ 00452 /* c_tPos is unsigned, hence test < 0 is pointless. */ \ 00453 if (c_tPos >= (UInt32)100000 * (UInt32)ro_blockSize100k) return True; \ 00454 c_tPos = c_tt[c_tPos]; \ 00455 cccc = (UChar)(c_tPos & 0xff); \ 00456 c_tPos >>= 8; 00457 00458 #define SET_LL4(i,n) \ 00459 { if (((i) & 0x1) == 0) \ 00460 s->ll4[(i) >> 1] = (s->ll4[(i) >> 1] & 0xf0) | (n); else \ 00461 s->ll4[(i) >> 1] = (s->ll4[(i) >> 1] & 0x0f) | ((n) << 4); \ 00462 } 00463 00464 #define GET_LL4(i) \ 00465 ((((UInt32)(s->ll4[(i) >> 1])) >> (((i) << 2) & 0x4)) & 0xF) 00466 00467 #define SET_LL(i,n) \ 00468 { s->ll16[i] = (UInt16)(n & 0x0000ffff); \ 00469 SET_LL4(i, n >> 16); \ 00470 } 00471 00472 #define GET_LL(i) \ 00473 (((UInt32)s->ll16[i]) | (GET_LL4(i) << 16)) 00474 00475 #define BZ_GET_SMALL(cccc) \ 00476 /* c_tPos is unsigned, hence test < 0 is pointless. */ \ 00477 if (s->tPos >= (UInt32)100000 * (UInt32)s->blockSize100k) return True; \ 00478 cccc = BZ2_indexIntoF ( s->tPos, s->cftab ); \ 00479 s->tPos = GET_LL(s->tPos); 00480 00481 00482 /*-- externs for decompression. --*/ 00483 00484 extern Int32 00485 BZ2_indexIntoF ( Int32, Int32* ); 00486 00487 extern Int32 00488 BZ2_decompress ( DState* ); 00489 00490 extern void 00491 BZ2_hbCreateDecodeTables ( Int32*, Int32*, Int32*, UChar*, 00492 Int32, Int32, Int32 ); 00493 00494 00495 #endif 00496 00497 00498 /*-- BZ_NO_STDIO seems to make NULL disappear on some platforms. --*/ 00499 00500 #ifdef BZ_NO_STDIO 00501 #ifndef NULL 00502 #define NULL 0 00503 #endif 00504 #endif 00505 00506 00507 /*-------------------------------------------------------------*/ 00508 /*--- end bzlib_private.h ---*/ 00509 /*-------------------------------------------------------------*/ Generated on Thu May 24 2012 04:33:52 for ReactOS by
1.7.6.1
|