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

📄 inflate.c

📁 Intel 5.2 版本的zlib 库实现
💻 C
📖 第 1 页 / 共 5 页
字号:
      } /* infhead */ 
      else if(state->headerMode == infflags)
      {
        while(state->headerBits < 16)
        {   
          if(strm->avail_in == 0) 
          {     
            ret = Z_OK;    
            goto inf_leave;
          } /* if */
          (strm->avail_in)--;  
          state->headerBuf += ((*(strm->next_in)) << state->headerBits);
          (strm->next_in)++;              
          state->headerBits += 8;  
        } /* while */ 
        state->headerFlags = state->headerBuf;

        if((state->headerFlags & 0xff) != Z_DEFLATED) 
        {
          ret = Z_DATA_ERROR;
          goto inf_leave;
        } /* if */
        if(state->headerFlags & 0xe000) 
        {
          ret = Z_DATA_ERROR;
          goto inf_leave;
        } /* if */

        state->headerBuf = 0;
        state->headerBits = 0;
        state->headerMode = inftime;
      } /* infflags */
      else if(state->headerMode == inftime)
      {
        while(state->headerBits < 32)
        {   
          if(strm->avail_in == 0) 
          {     
            ret = Z_OK;    
            goto inf_leave;
          } /* if */
          (strm->avail_in)--;  
          state->headerBuf += ((*(strm->next_in)) << state->headerBits);
          (strm->next_in)++;              
          state->headerBits += 8;  
        } /* while */ 
        state->headerBuf = 0;
        state->headerBits = 0;
        state->headerMode = infos;
      } /* inftime */
      else if(state->headerMode == infos)
      {
        while(state->headerBits < 16)
        {   
          if(strm->avail_in == 0) 
          {     
            ret = Z_OK;    
            goto inf_leave;
          } /* if */
          (strm->avail_in)--;  
          state->headerBuf += ((*(strm->next_in)) << state->headerBits);
          (strm->next_in)++;              
          state->headerBits += 8;  
        } /* while */ 
        state->headerBuf = 0;
        state->headerBits = 0;
        state->headerMode = infexlen;
      } /* infos */
      else if(state->headerMode == infexlen) 
      {
        if(state->headerFlags & 0x0400) 
        {
          while(state->headerBits < 16)
          {   
            if(strm->avail_in == 0) 
            {     
              ret = Z_OK;    
              goto inf_leave;
            } /* if */
            (strm->avail_in)--;  
            state->headerBuf += ((*(strm->next_in)) << state->headerBits);
            (strm->next_in)++;              
            state->headerBits += 8;  
          } /* while */ 
          state->headerLength = state->headerBuf;
          state->headerBuf = 0;
          state->headerBits = 0;
        } /* if */
        state->headerMode = infextra;
      } /* infexlen */
      else if(state->headerMode == infextra)
      {
        if(state->headerFlags & 0x0400) 
        {
          copy = state->headerLength;
          if(copy > (int)strm->avail_in) copy = strm->avail_in;
          if(copy) {
            strm->avail_in -= copy;
            strm->next_in += copy;
            state->headerLength -= copy;
          } /* if */
          if(state->headerLength)
          { 
            ret = Z_OK;
            goto inf_leave;
          } /* if */
        }
        state->headerMode = infname;        
      } /* infextra */
      else if(state->headerMode == infname)
      {
        if(state->headerFlags & 0x0800) 
        {
          if(strm->avail_in == 0)
          {
            ret = Z_OK;  
            goto inf_leave;
          } /* if */
          copy = 0;
          do {
            len = (unsigned int)(strm->next_in[copy++]);
          } while (len && copy < strm->avail_in);

          strm->avail_in -= copy;
          strm->next_in += copy;
          if(len) 
          {      
            ret = Z_OK;
            goto inf_leave;
          } /* if */
        } /* if */
        state->headerMode = infcomment;  
      } /* infname */
      else if(state->headerMode == infcomment)
      {
        if(state->headerFlags & 0x1000) 
        {
          if(strm->avail_in == 0)
          {
            ret = Z_OK;
            goto inf_leave;
          } /* if */
          copy = 0;
          do{
            len = (unsigned int)(strm->next_in[copy++]);
          }while(len && copy < strm->avail_in);

          strm->avail_in -= copy;
          strm->next_in += copy;
          if(len)
          {
            ret = Z_OK;
            goto inf_leave;
          } /* if */
        } /* if */
        state->headerMode = infhcrc;
      } /* infcomment */   
      else if(state->headerMode == infhcrc)
      {
        if(state->headerFlags & 0x0200) 
        {
          while(state->headerBits < 16)
          {   
            if(strm->avail_in == 0) 
            {     
              ret = Z_OK;    
              goto inf_leave;
            } /* if */
            (strm->avail_in)--;  
            state->headerBuf += ((*(strm->next_in)) << state->headerBits);
            (strm->next_in)++;              
            state->headerBits += 8;  
          } /* while */ 
          state->headerBuf = 0;
          state->headerBits = 0;
        } /* if */
        state->headerMode = infmain;
      } /* infhcrc */

      if(state->headerMode == infmain)
	  {
        state->headerBits = 0;
        state->headerBuf = 0;  
        break;    
	  } /* if infmain */

	  if(state->headerMode == infdictid)
	  {
	    while(state->headerBits < 32)
        {   
          if(strm->avail_in == 0) 
          {     
            ret = Z_OK;    
            goto inf_leave;
          } /* if */
          (strm->avail_in)--;  
          state->headerBuf += ((*(strm->next_in)) << state->headerBits);
          (strm->next_in)++;              
          state->headerBits += 8;  
        } /* while */ 

        strm->adler = state->check = REVERSE(state->headerBuf);
        state->headerBits = 0;
        state->headerBuf = 0; 
        state->headerMode = infdict;

	  } /* if infdictid */

	  if(state->headerMode == infdict)
	  {
        if(state->havedict == 0) 
		{
		  ret = Z_NEED_DICT;
		  goto inf_leave;
		} /* if */
        strm->adler = state->check = adler32(0, Z_NULL, 0); 
        state->headerMode = infmain;
	  } /* if infdict */

    } /* for */ 

    inflateStatus = IppLZ77InflateStatusHuffProcess; 
    ippsDecodeLZ77SetStatus_8u(inflateStatus, pLZ77State);  
  } /* IppLZ77InflateStatusInit */ 

  if(flush != Z_BLOCK)
  { 
    ippsDecodeLZ77GetStatus_8u(&inflateStatus, pLZ77State); 

	if(inflateStatus == IppLZ77InflateStatusHuffProcess)
    { 
	  for( ; ; ) /* SPOTTY FOR */
      {
        if(state->lastBlockHuff == 0)
        {    
          ippsDecodeLZ77GetPairs_8u(&pPairConst, &pairsInd, &pairsLenConst, pLZ77State); 
          /*  sequential block: */
          pSrc = strm->next_in;
          srcLen = strm->avail_in;
          retStatus = ippsDecodeLZ77GetBlockType_8u(&pSrc, &srcLen, &huffMode, pLZ77State);  
          
          if((retStatus == ippStsSrcSizeLessExpected) && (state->lastBlockLZ77 == 0))
          {
            ret = Z_OK;
            goto inf_leave;
          }
          else if(retStatus < 0)
          {
            ret = Z_DATA_ERROR; 
            goto inf_leave;
          } /* if else */

          strm->avail_in = srcLen;
          strm->next_in = pSrc;
          /* end of sequential block. */
        } /* if state->lastBlockHuff == 0 */
        /* from here to parallel: */
#pragma omp parallel sections
        {
#pragma omp section
          {
            if(state->lastBlockHuff == 0)
            { 
              /* SECTION 1: */
              if(huffMode == IppLZ77UseFixed)
              {
                pPair = pPairConst + pairsInd;
                dstLen = pairsLenConst - pairsInd;
                pSrc = strm->next_in;
                srcLen = strm->avail_in;
                
				retStatus = ippsDecodeLZ77FixedHuff_8u(&pSrc, &srcLen, &pPair, &dstLen, ippflush, pLZ77State);
				if((retStatus == ippStsNoErr) && (state->lastBlockHuff == 1))
                  retStatus = ippStsStreamEnd; 

                state->decodeHuffStatus = retStatus;
                strm->next_in = pSrc;
                strm->avail_in = srcLen;
                pairsInd = pPair - pPairConst;

                if(retStatus == ippStsNoErr)
                {
                  ippsDecodeLZ77SetPairs_8u(pPairConst, pairsInd, pairsLenConst, pLZ77State);
                }
                else if(retStatus == ippStsDstSizeLessExpected || retStatus == ippStsStreamEnd)
                {
                  ippsDecodeLZ77SetPairs_8u(pPairConst, 0, pairsInd, pLZ77State); 
                  if(retStatus == ippStsStreamEnd)
                    state->headerMode = infhead;
                }
                else if(retStatus == ippStsSrcSizeLessExpected)
                {
                  ippsDecodeLZ77SetPairs_8u(pPairConst, pairsInd, pairsLenConst, pLZ77State);
                } /* if else */
              } /* IF FIXED */
              else if(huffMode == IppLZ77UseDynamic)
              {
                pPair = pPairConst + pairsInd;
                dstLen = pairsLenConst - pairsInd;
                pSrc = strm->next_in;
                srcLen = strm->avail_in;

                retStatus = ippsDecodeLZ77DynamicHuff_8u(&pSrc, &srcLen, &pPair, &dstLen, ippflush, pLZ77State);
                if((retStatus == ippStsNoErr) && (state->lastBlockHuff == 1))
                  retStatus = ippStsStreamEnd;

                state->decodeHuffStatus = retStatus;

                strm->next_in = pSrc;
                strm->avail_in = srcLen;
                pairsInd = pPair - pPairConst;

                if(retStatus == ippStsNoErr)
                {
                  ippsDecodeLZ77SetPairs_8u(pPairConst, pairsInd, pairsLenConst, pLZ77State);
                }
                else if(retStatus == ippStsDstSizeLessExpected || retStatus == ippStsStreamEnd)
                {
                  ippsDecodeLZ77SetPairs_8u(pPairConst, 0, pairsInd, pLZ77State); 
                  if(retStatus == ippStsStreamEnd)
                    state->headerMode = infhead;
                }
                else if(retStatus == ippStsSrcSizeLessExpected)
                {
                  ippsDecodeLZ77SetPairs_8u(pPairConst, pairsInd, pairsLenConst, pLZ77State);
                } /* if else */
              } /* IF DYNAMIC */
			  else if(huffMode == IppLZ77UseStored)
			  {
			    /* HERE TO BE IF STORED(omp_version) */
                pPair = pPairConst + pairsInd;
                dstLen = pairsLenConst - pairsInd;
                pSrc = strm->next_in;
                srcLen = strm->avail_in;

                retStatus = ippsDecodeLZ77StoredHuff_8u(&pSrc, &srcLen, &pPair, &dstLen, pLZ77State);
                if((retStatus == ippStsNoErr) && (state->lastBlockHuff == 1))
                  retStatus = ippStsStreamEnd;

                state->decodeHuffStatus = retStatus;

                strm->next_in = pSrc;
                strm->avail_in = srcLen;
                pairsInd = pPair - pPairConst;

                if(retStatus == ippStsNoErr)
                {
                  ippsDecodeLZ77SetPairs_8u(pPairConst, pairsInd, pairsLenConst, pLZ77State);
                }
                else if(retStatus == ippStsDstSizeLessExpected || retStatus == ippStsStreamEnd)
                {
                  ippsDecodeLZ77SetPairs_8u(pPairConst, 0, pairsInd, pLZ77State); 
                  if(retStatus == ippStsStreamEnd)
                    state->headerMode = infhead;
                }
                else if(retStatus == ippStsSrcSizeLessExpected)
                {
                  ippsDecodeLZ77SetPairs_8u(pPairConst, pairsInd, pairsLenConst, pLZ77State);
                } /* if else */
			  } /* IF STORED */
			  
              /* END OF SECTION 1. */
            } /* if state->lastBlockHuff == 0 */
            else
            {
              state->decodeHuffStatus = ippStsStreamEnd;
            } /* if state->lastBlockHuff == 1 */
          } /* pragma omp section */
#pragma omp section
          {
            /* SECTION 2: */
            ippsDecodeLZ77GetPairs_8u(&pPairConstMT, &pairsIndMT, &pairsLenConstMT, pLZ77StateMT); 

            pPairMT = pPairConstMT + pairsIndMT;        
            srcLenMT = pairsLenConstMT - pairsIndMT;
            pDst = strm->next_out;
            dstLenMT = strm->avail_out;

            if(state->firstSwapDone == 0)
            {
              srcLenMT = 0;
            } /* if */

            retStatusMT = ippsDecodeLZ77_8u(&pPairMT, &srcLenMT, &pDst, &dstLenMT, ippflush, pLZ77StateMT);

⌨️ 快捷键说明

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