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

📄 inftrees.cpp

📁 liu7788414
💻 CPP
📖 第 1 页 / 共 2 页
字号:
        /* allocate new table */
        if (*hn + z > MANY)     /* (note: doesn't matter for fixed) */
          return Z_MEM_ERROR;   /* not enough memory */
        u[h] = q = hp + *hn;
        *hn += z;

        /* connect to last table, if there is one */
        if (h)
        {
          x[h] = i;             /* save pattern for backing up */
          r.bits = (Byte)l;     /* bits to dump before this table */
          r.exop = (Byte)j;     /* bits in this table */
          j = i >> (w - l);
          r.base = (uInt)(q - u[h-1] - j);   /* offset to this table */
          u[h-1][j] = r;        /* connect to last table */
        }
        else
          *t = q;               /* first table is returned result */
      }

      /* set up table entry in r */
      r.bits = (Byte)(k - w);
      if (p >= v + n)
        r.exop = 128 + 64;      /* out of values--invalid code */
      else if (*p < s)
      {
        r.exop = (Byte)(*p < 256 ? 0 : 32 + 64);     /* 256 is end-of-block */
        r.base = *p++;          /* simple code is just the value */
      }
      else
      {
        r.exop = (Byte)(e[*p - s] + 16 + 64);/* non-simple--look up in lists */
        r.base = d[*p++ - s];
      }

      /* fill code-like entries with r */
      f = 1 << (k - w);
      for (j = i >> w; j < z; j += f)
        q[j] = r;

      /* backwards increment the k-bit code i */
      for (j = 1 << (k - 1); i & j; j >>= 1)
        i ^= j;
      i ^= j;

      /* backup over finished tables */
      mask = (1 << w) - 1;      /* needed on HP, cc -O bug */
      while ((i & mask) != x[h])
      {
        h--;                    /* don't need to update q */
        w -= l;
        mask = (1 << w) - 1;
      }
    }
  }


  /* Return Z_BUF_ERROR if we were given an incomplete table */
  return y != 0 && g != 1 ? Z_BUF_ERROR : Z_OK;
}


int inflate_trees_bits(
			uIntf *				c,              /* 19 code lengths */
			uIntf *				bb,             /* bits tree desired/actual depth */
			inflate_huft * FAR *tb,				/* bits tree result */
			inflate_huft *		hp,				/* space for trees */
			z_streamp			z		)       /* for messages */
{
  int r;
  uInt hn = 0;          /* hufts used in space */
  uIntf *v;             /* work area for huft_build */

  if ((v = (uIntf*)ZALLOC(z, 19, sizeof(uInt))) == Z_NULL)
    return Z_MEM_ERROR;
  r = huft_build(c, 19, 19, (uIntf*)Z_NULL, (uIntf*)Z_NULL,
                 tb, bb, hp, &hn, v);
  if (r == Z_DATA_ERROR)
    z->msg = (char*)"oversubscribed dynamic bit lengths tree";
  else if (r == Z_BUF_ERROR || *bb == 0)
  {
    z->msg = (char*)"incomplete dynamic bit lengths tree";
    r = Z_DATA_ERROR;
  }
  ZFREE(z, v);
  return r;
}


int inflate_trees_dynamic(
			uInt				nl,             /* number of literal/length codes */
			uInt				nd,             /* number of distance codes */
			uIntf *				c,				/* that many (total) code lengths */
			uIntf *				bl,				/* literal desired/actual bit depth */
			uIntf *				bd,				/* distance desired/actual bit depth */
			inflate_huft * FAR *tl,				/* literal/length tree result */
			inflate_huft * FAR *td,				/* distance tree result */
			inflate_huft *		hp,				/* space for trees */
			z_streamp			z		)		/* for messages */
{
  int r;
  uInt hn = 0;          /* hufts used in space */
  uIntf *v;             /* work area for huft_build */

  /* allocate work area */
  if ((v = (uIntf*)ZALLOC(z, 288, sizeof(uInt))) == Z_NULL)
    return Z_MEM_ERROR;

  /* build literal/length tree */
  r = huft_build(c, nl, 257, cplens, cplext, tl, bl, hp, &hn, v);
  if (r != Z_OK || *bl == 0)
  {
    if (r == Z_DATA_ERROR)
      z->msg = (char*)"oversubscribed literal/length tree";
    else if (r != Z_MEM_ERROR)
    {
      z->msg = (char*)"incomplete literal/length tree";
      r = Z_DATA_ERROR;
    }
    ZFREE(z, v);
    return r;
  }

  /* build distance tree */
  r = huft_build(c + nl, nd, 0, cpdist, cpdext, td, bd, hp, &hn, v);
  if (r != Z_OK || (*bd == 0 && nl > 257))
  {
    if (r == Z_DATA_ERROR)
      z->msg = (char*)"oversubscribed distance tree";
    else if (r == Z_BUF_ERROR) {
#ifdef PKZIP_BUG_WORKAROUND
      r = Z_OK;
    }
#else
      z->msg = (char*)"incomplete distance tree";
      r = Z_DATA_ERROR;
    }
    else if (r != Z_MEM_ERROR)
    {
      z->msg = (char*)"empty distance tree with lengths";
      r = Z_DATA_ERROR;
    }
    ZFREE(z, v);
    return r;
#endif
  }

  /* done */
  ZFREE(z, v);
  return Z_OK;
}

/*
local int				fixed_built = 0;
#define FIXEDH			544					
local inflate_huft		fixed_mem[FIXEDH];
local uInt				fixed_bl;
local uInt				fixed_bd;
local inflate_huft*		fixed_tl;
local inflate_huft*		fixed_td;
*/

int inflate_trees_fixed(
				uIntf *				bl,				/* literal desired/actual bit depth */
				uIntf *				bd,				/* distance desired/actual bit depth */
				inflate_huft * FAR *tl,				/* literal/length tree result */
				inflate_huft * FAR *td,				/* distance tree result */
				z_streamp			z		)		/* for memory allocation */
{
	int				fixed_built;
	inflate_huft*	fixed_mem;
	uInt			fixed_bl;
	uInt			fixed_bd;
	inflate_huft*	fixed_tl;
	inflate_huft*	fixed_td;

	if ( ( fixed_mem = ( inflate_huft*)ZALLOC( z, 544, sizeof( inflate_huft ) ) ) == Z_NULL )
		return Z_MEM_ERROR;

	//getInflateFixedTree( z->opaque, &fixed_built, (void**)&fixed_mem, &fixed_bl, &fixed_bd,(void**) &fixed_tl, (void**)&fixed_td );	
	/* build fixed tables if not already */
	//if (!fixed_built)
	{
		int k;              /* temporary variable */
		uInt f = 0;         /* number of hufts used in fixed_mem */
		uIntf *c;           /* length list for huft_build */
		uIntf *v;           /* work area for huft_build */

		/* allocate memory */
		if ((c = (uIntf*)ZALLOC(z, 288, sizeof(uInt))) == Z_NULL)
			return Z_MEM_ERROR;

		if ((v = (uIntf*)ZALLOC(z, 288, sizeof(uInt))) == Z_NULL)
		{
			ZFREE(z, c);
			return Z_MEM_ERROR;
		}

		/* literal table */
		for (k = 0; k < 144; k++)
			c[k] = 8;
		for (; k < 256; k++)
			c[k] = 9;
		for (; k < 280; k++)
			c[k] = 7;
		for (; k < 288; k++)
			c[k] = 8;
		fixed_bl = 9;
		huft_build(c, 288, 257, cplens, cplext, &fixed_tl, &fixed_bl, fixed_mem, &f, v);

		/* distance table */
		for (k = 0; k < 30; k++)
			c[k] = 5;
		
		fixed_bd = 5;
		huft_build(c, 30, 0, cpdist, cpdext, &fixed_td, &fixed_bd, fixed_mem, &f, v);

		/* done */
		ZFREE(z, v);
		ZFREE(z, c);
		fixed_built = 1;
		//setInflateFixedTree( z->opaque, fixed_bl, fixed_bd, fixed_tl, fixed_td );
	}

	*bl = fixed_bl;
	*bd = fixed_bd;
	*tl = fixed_tl;
	*td = fixed_td;
	return Z_OK;
}


⌨️ 快捷键说明

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