⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 inflate.h

📁 该代码包为INTEL IXP2400单板的BSP,同时经过修改,可以对MSN和ixf1104做自定义配置
💻 H
字号:
/*****************************************************************************
 * 版权所有 (C)2001-2008, 深圳市中兴通讯股份有限公司。
 * 
 * 文件名称:    
 * 文件标识:    
 * 内容摘要:    
 * 其它说明: 
 * 当前版本:    ZXR10 V2.6
 * 作    者:    刘文龙
 * 完成日期:    2005-10-12 17:04
 * 当前责任人-1:刘文龙
 * 当前责任人-2:
 *
 * 修改记录1:   
 *    修改日期:2005-10-12 17:04
 *    版 本 号:ZXR10 V2.6
 *    修 改 人:刘文龙
 *    修改内容:创建 
 * 修改记录2:
 *****************************************************************************/
#define VXWORKS
/* definitions */
/* Maximum value for windowBits in deflateInit2 and inflateInit */
#define DEF_WBITS       15   /* 32K LZ77 window */
#define PRESET_DICT     0x20 /* preset dictionary flag in zlib header */

/* Return codes for the compression/decompression functions. Negative
 * values are errors, positive values are used for special but normal events.
 */
#define Z_OK            0
#define Z_STREAM_END    1
#define Z_NEED_DICT     2
#define Z_ERRNO        (-1)
#define Z_STREAM_ERROR (-2)
#define Z_DATA_ERROR   (-3)
#define Z_MEM_ERROR    (-4)
#define Z_BUF_ERROR    (-5)
#define Z_DEFLATED      8

#define BASE            65521L /* largest prime smaller than 65536 */
#define NMAX            5552

/* If BMAX needs to be larger than 16, then h and x[] should be ULONG. */
#define BMAX            15         /* maximum bit length of any code */
#define N_MAX           288       /* maximum number of codes in any set */

/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
/* internal data types */
typedef unsigned char   BYTE;  /* 8 bits */
typedef void*           VOIDP;
#ifndef VXWORKS
    typedef unsigned int    UINT;  /* 16 bits or more */
    typedef unsigned long   ULONG; /* 32 bits or more */
    typedef unsigned short  USHORT;
#endif

typedef ULONG (*check_func) (ULONG check, const BYTE *buf, UINT len);

/* Data structure describing a single value and its code string. */
typedef struct ct_data_s {
     union {
          USHORT  freq;       /* frequency count */
          USHORT  code;       /* bit string */
     } fc;
     union {
          USHORT  dad;        /* father node in Huffman tree */
          USHORT  len;        /* length of bit string */
     } dl;
}  ct_data;

/* Huffman code lookup table entry--this entry is four bytes for machines
   that have 16-bit pointers (e.g. PC's in the small or medium model). */

typedef struct inflate_huft_s  inflate_huft;

struct inflate_huft_s {
  union {
    struct {
      BYTE Exop;        /* number of extra bits or operation */
      BYTE Bits;        /* number of bits in this code or subcode */
    } what;
    BYTE *pad;         /* pad structure to a power of 2 (4 bytes for */
  } word;               /*  16-bit, 8 bytes for 32-bit machines) */
  union {
    UINT Base;          /* literal, length base, or distance base */
    inflate_huft *Next; /* pointer to next level of table */
  } more;
};

struct inflate_blocks_state;
typedef struct inflate_blocks_state  inflate_blocks_statef;

struct inflate_codes_state;
typedef struct inflate_codes_state  inflate_codes_statef;

typedef enum {
      TYPE,     /* get type bits (3, including end bit) */
      LENS,     /* get lengths for stored */
      STORED,   /* processing stored block */
      TABLE,    /* get table lengths */
      BTREE,    /* get bit lengths tree for a dynamic block */
      DTREE,    /* get length, distance trees for a dynamic block */
      CODES,    /* processing fixed or dynamic block */
      DRY,      /* output remaining window bytes */
      DONE,     /* finished last block, done */
      BAD}      /* got a data error--stuck here */
inflate_block_mode;

/* inflate blocks semi-private state */
struct inflate_blocks_state {

  /* mode */
  inflate_block_mode  mode;     /* current inflate_block mode */

  /* mode dependent information */
  union {
    UINT left;          /* if STORED, bytes left to copy */
    struct {
      UINT table;               /* table lengths (14 bits) */
      UINT index;               /* index into blens (or border) */
      UINT *blens;             /* bit lengths of codes */
      UINT bb;                  /* bit length tree depth */
      inflate_huft *tb;         /* bit length decoding tree */
    } trees;            /* if DTREE, decoding info for trees */
    struct {
      inflate_huft *tl;
      inflate_huft *td;         /* trees to free */
      inflate_codes_statef
         *codes;
    } decode;           /* if CODES, current state */
  } sub;                /* submode */
  UINT last;            /* true if this block is the last block */

  /* mode independent information */
  UINT bitk;            /* bits in bit buffer */
  ULONG bitb;           /* bit buffer */
  BYTE *window;        /* sliding window */
  BYTE *end;           /* one byte after sliding window */
  BYTE *read;          /* window read pointer */
  BYTE *write;         /* window write pointer */
  check_func checkfn;   /* check function */
  ULONG check;          /* check on output */

};


/* inflate codes private state */
struct inflate_codes_state {

  /* mode */
  enum {        /* waiting for "i:"=input, "o:"=output, "x:"=nothing */
      START,    /* x: set up for LEN */
      LEN,      /* i: get length/literal/eob next */
      LENEXT,   /* i: getting length extra (have base) */
      DIST,     /* i: get distance next */
      DISTEXT,  /* i: getting distance extra */
      COPY,     /* o: copying bytes in window, waiting for space */
      LIT,      /* o: got literal, waiting for output space */
      WASH,     /* o: got eob, possibly still output waiting */
      END,      /* x: got eob and all data flushed */
      BADCODE}  /* x: got error */
    mode;               /* current inflate_codes mode */

  /* mode dependent information */
  UINT len;
  union {
    struct {
      inflate_huft *tree;       /* pointer into tree */
      UINT need;                /* bits needed */
    } code;             /* if LEN or DIST, where in tree */
    UINT lit;           /* if LIT, literal */
    struct {
      UINT get;                 /* bits to get for extra */
      UINT dist;                /* distance back to copy from */
    } copy;             /* if EXT or COPY, where and how much */
  } sub;                /* submode */

  /* mode independent information */
  BYTE lbits;           /* ltree bits decoded per branch */
  BYTE dbits;           /* dtree bits decoder per branch */
  inflate_huft *ltree;          /* literal/length/eob tree */
  inflate_huft *dtree;          /* distance tree */
};

/* inflate private state */
struct internal_state {

  /* mode */
  enum {
      METHOD,   /* waiting for method byte */
      FLAG,     /* waiting for flag byte */
      DICT4,    /* four dictionary check bytes to go */
      DICT3,    /* three dictionary check bytes to go */
      DICT2,    /* two dictionary check bytes to go */
      DICT1,    /* one dictionary check byte to go */
      DICT0,    /* waiting for inflateSetDictionary */
      BLOCKS,   /* decompressing blocks */
      CHECK4,   /* four check bytes to go */
      CHECK3,   /* three check bytes to go */
      CHECK2,   /* two check bytes to go */
      CHECK1,   /* one check byte to go */
      INF_DONE, /* finished check, done */
      INF_BAD}  /* got an error--stay here */
    mode;               /* current inflate mode */

  /* mode dependent information */
  union {
    UINT method;        /* if FLAGS, method byte */
    struct {
      ULONG was;                /* computed check value */
      ULONG need;               /* stream check value */
    } check;            /* if CHECK, check values to compare */
  } sub;        /* submode */

  /* mode independent information */
  int  nowrap;          /* flag for no wrapper */
  UINT wbits;           /* log2(window size)  (8..15, defaults to 15) */
  inflate_blocks_statef
    *blocks;            /* current inflate_blocks state */

};

struct z_stream_s;
typedef void  (*free_func)  (struct z_stream_s* z,VOIDP opaque, VOIDP address);
typedef VOIDP (*alloc_func) (struct z_stream_s* z,VOIDP opaque, UINT items, UINT size);

struct z_stream_s {
    BYTE    *next_in;      /* next input byte */
    UINT    avail_in;     /* number of bytes available at next_in */
    ULONG   total_in;     /* total nb of input bytes read so far */

    BYTE    *next_out;     /* next output byte should be put there */
    UINT    avail_out;    /* remaining free space at next_out */
    ULONG   total_out;    /* total nb of bytes output so far */

    char    *msg;                 /* last error message, NULL if no error */
    struct internal_state  *state; /* not visible by applications */

    alloc_func  zalloc;     /* used to allocate the internal state */
    free_func   zfree;      /* used to free the internal state */
    VOIDP       opaque;     /* private data object passed to zalloc and zfree */

    ULONG       adler;      /* adler32 value of the uncompressed data */

    /* the following is used to port to multitask system */
    /* build fixed tables only once--keep them here */
    int             z_fixed_built;
    UINT            z_fixed_bl;
    UINT            z_fixed_bd;
    inflate_huft *  z_fixed_tl;
    inflate_huft *  z_fixed_td;

    /* allocate two extra words for prev/next pointers for first block */
    BYTE *   z_mem_pool;
    BYTE *   z_next_block;

    UINT            z_c[BMAX+1];             /* bit length count table */
    inflate_huft    *z_u[BMAX];      /* table stack */
    UINT            z_v[N_MAX];              /* values in order of bit length */
    UINT            z_x[BMAX+1];             /* bit offsets, then code stack */

};

typedef struct z_stream_s ZAR_STREAM;

#define OUTBUF_SIZE 512

int     inflateEnd( ZAR_STREAM* z);
int     inflateInit( ZAR_STREAM* z);
int     zinflate  (   ZAR_STREAM* z, int f );
USHORT  z_cksum(  unsigned short       prevSum,        /* previous total */
                const unsigned char* buf,            /* buffer to checksum */
                unsigned int         len,
                int                  oddflag );            /* size of buffer */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -