Inflater.h
资源名称:DXGuide.zip [点击查看]
上传用户:wymy58
上传日期:2007-01-07
资源大小:2086k
文件大小:8k
源码类别:
DirextX编程
开发平台:
Visual C++
- // Form zlib 1.1.3, Copyright (C) 1995-1998 Jean-loup Gailly
- // Copyright (C) 1999 DXGuide. All Rights Reserved.
- // File: Inflater.h
- #ifndef _INFLATER__H
- #define _INFLATER__H
- #if _MSC_VER >= 1000
- #pragma once
- #endif // _MSC_VER >= 1000
- //#define PKZIP_BUG_WORKAROUND
- //#define BUILDFIXED
- //#define SLOW
- #include "Zlib113.h"
- #include "Checksum.h"
- // Huffman code lookup table entry
- struct InflateHuft
- {
- BYTE m_byteExop; // number of extra bits or operation
- BYTE m_byteBits; // number of bits in this code or subcode
- UINT m_uBase; // literal, length base, distance base, or table offset
- };
- // simplify the use of the InflateHuft type with some defines
- enum InflateCodesMode
- {
- // waiting for "i:"=input, "o:"=output, "x:"=nothing
- INFLATECODESMODE_START, // x: set up for LEN
- INFLATECODESMODE_LEN, // i: get length/literal/eob next
- INFLATECODESMODE_LENEXT, // i: getting length extra (have base)
- INFLATECODESMODE_DIST, // i: get distance next
- INFLATECODESMODE_DISTEXT, // i: getting distance extra
- INFLATECODESMODE_COPY, // o: copying bytes in window, waiting for space
- INFLATECODESMODE_LIT, // o: got literal, waiting for output space
- INFLATECODESMODE_WASH, // o: got eob, possibly still output waiting
- INFLATECODESMODE_END, // x: got eob and all data flushed
- INFLATECODESMODE_BADCODE // x: got error
- };
- // inflate codes private state
- struct CInflateCodesState
- {
- public:
- InflateCodesMode m_inflateCodesMode; // current inflate_codes mode
- // mode dependent information
- UINT m_uLen;
- union
- {
- struct
- {
- InflateHuft* m_pHufTree; // pointer into tree
- UINT m_uNeedBits; // bits needed
- } code; // if LEN or DIST, where in tree
- UINT m_uLit; // if LIT, literal
- struct
- {
- UINT m_uGet; // bits to get for extra
- UINT m_uDist; // distance back to copy from
- } copy; // if EXT or COPY, where and how much
- }; // submode
- // mode independent information
- BYTE m_LBits; // ltree bits decoded per branch
- BYTE m_dBits; // dtree bits decoder per branch
- InflateHuft* m_pLTree; // literal/length/eob tree
- InflateHuft* m_pDTree; // distance tree
- };
- class CInflater
- {
- protected:
- enum InflateMode
- {
- INFLATEMODE_METHOD, // waiting for method byte
- INFLATEMODE_FLAG, // waiting for flag byte
- INFLATEMODE_DICT4, // four dictionary check bytes to go
- INFLATEMODE_DICT3, // three dictionary check bytes to go
- INFLATEMODE_DICT2, // two dictionary check bytes to go
- INFLATEMODE_DICT1, // one dictionary check byte to go
- INFLATEMODE_DICT0, // waiting for InflateSetDictionary
- INFLATEMODE_BLOCKS, // decompressing blocks
- INFLATEMODE_CHECK4, // four check bytes to go
- INFLATEMODE_CHECK3, // three check bytes to go
- INFLATEMODE_CHECK2, // two check bytes to go
- INFLATEMODE_CHECK1, // one check byte to go
- INFLATEMODE_DONE, // finished check, done
- INFLATEMODE_BAD // got an error--stay here
- };
- public:
- CInflater(void);
- ~CInflater();
- public:
- ZRetVal Inflate(FlushValues flush);
- ZRetVal InflateEnd(void);
- // Advanced functions, The following functions are needed only in some special applications.
- public:
- ZRetVal Init(int nWindowBits = DEF_WBITS);
- ZRetVal InflateSetDictionary(
- const BYTE* pDictionary, UINT uDictLength);
- ZRetVal InflateSync(void);
- ZRetVal InflateReset(void);
- bool InflateSyncPoint(void);
- // infblock
- protected:
- bool inflate_blocks_new(UINT w); // window size
- void inflate_blocks_reset(void); // check value on output
- void inflate_set_dictionary(
- const BYTE* pDictionary, // dictionary
- UINT uDictLength); // dictionary length
- ZRetVal inflate_blocks(ZRetVal r); // initial return code
- ZRetVal inflate_flush(ZRetVal r);
- // inftrees
- protected:
- ZRetVal inflate_trees_bits(
- UINT*, // 19 code lengths
- UINT*, // bits tree desired/actual depth
- InflateHuft**, // bits tree result
- InflateHuft*); // space for trees
- ZRetVal inflate_trees_dynamic(
- UINT, // number of literal/length codes
- UINT, // number of distance codes
- UINT*, // that many (total) code lengths
- UINT*, // literal desired/actual bit depth
- UINT*, // distance desired/actual bit depth
- InflateHuft**, // literal/length tree result
- InflateHuft**, // distance tree result
- InflateHuft*); // space for trees
- ZRetVal inflate_trees_fixed(
- UINT*, // literal desired/actual bit depth
- UINT*, // distance desired/actual bit depth
- InflateHuft**, // literal/length tree result
- InflateHuft**); // distance tree result
- // inflate codes
- protected:
- CInflateCodesState* inflate_codes_new(
- UINT, UINT,
- InflateHuft*, InflateHuft*);
- ZRetVal inflate_codes(ZRetVal);
- protected:
- ZRetVal inflate_fast(UINT, UINT, InflateHuft*,
- InflateHuft*);
- public:
- const BYTE* m_pSourceBuf; // next input byte
- UINT m_uSourceBufLen; // number of bytes available at m_pSourceBuf
- BYTE* m_pDestBuf; // next output byte should be put there
- UINT m_uDestBufLen; // remaining free space at m_pDestBuf
- public:
- DWORD m_dwTotalInputBytes; // total nb of input bytes read so far
- DWORD m_dwTotalOutputBytes; // total nb of bytes output so far
- protected:
- LPCTSTR m_lpszMsg; // last error message, NULL if no error
- CChecksum m_checksum; // adler32 value of the uncompressed data
- public:
- DWORD GetTotalIn(void) const;
- DWORD GetTotalOut(void) const;
- DWORD GetAdler32(void) const;
- void SetInput(const void* pBuf, UINT uLen);
- protected:
- InflateMode m_curInflateMode; // current inflate mode
- // mode dependent information
- union
- {
- UINT m_method; // if INFLATEMODE_METHOD, INFLATEMODE_FLAG, method byte
- struct
- {
- DWORD m_dwWas; // computed check value
- DWORD m_dwNeed; // stream check value
- } check; // if CHECK, check values to compare
- UINT m_marker; // if INFLATEMODE_BAD, InflateSync's marker bytes count
- }; // submode
- // mode independent information
- bool m_bNoWrap; // flag for no wrapper
- UINT m_uWindowBits; // log2(window size) (8..15, defaults to 15)
- // blocks ! - inflate blocks semi-private state
- protected:
- enum InflateBlockMode
- {
- INFLATEBLOCKMODE_TYPE, // get type bits (3, including end bit)
- INFLATEBLOCKMODE_LENS, // get lengths for stored
- INFLATEBLOCKMODE_STORED, // processing stored block
- INFLATEBLOCKMODE_TABLE, // get table lengths
- INFLATEBLOCKMODE_BTREE, // get bit lengths tree for a dynamic block
- INFLATEBLOCKMODE_DTREE, // get length, distance trees for a dynamic block
- INFLATEBLOCKMODE_CODES, // processing fixed or dynamic block
- INFLATEBLOCKMODE_DRY, // output remaining window bytes
- INFLATEBLOCKMODE_DONE, // finished last block, done
- INFLATEBLOCKMODE_BAD // got a data error--stuck here
- };
- protected:
- InflateBlockMode m_blockMode; // current inflate_block mode
- // mode dependent information
- union
- {
- UINT m_uLeftBytes; // if INFLATEBLOCKMODE_LENS & INFLATEBLOCKMODE_STORED(STORED), bytes left to copy
- struct
- {
- UINT m_uTableLen; // table lengths (14 bits)
- UINT m_uIndex; // index into blens (or border)
- UINT* m_puBitLens; // bit lengths of codes
- UINT m_ubb; // bit length tree depth
- InflateHuft* m_ptb; // bit length decoding tree
- } trees; // if DTREE, decoding info for trees
- struct
- {
- CInflateCodesState* m_pInflateCodesState;
- }decode; // if CODES, current state
- }; // sub - submode
- bool m_bLast; // true if this block is the last block
- // mode independent information
- UINT m_uBitK; // bits in bit buffer
- DWORD m_dwBitBuf; // bit buffer
- InflateHuft* m_pHufts; // single malloc for tree space
- BYTE* m_pSlidingWindow; // sliding window
- BYTE* m_pEnd; // one byte after sliding window
- BYTE* m_pRead; // window read pointer
- BYTE* m_pWrite; // window write pointer
- };
- #include "Inflater.inl"
- #endif // _INFLATER__H