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

📄 inflate.c

📁 Intel 5.2 版本的zlib 库实现
💻 C
📖 第 1 页 / 共 5 页
字号:
            if((retStatusMT == ippStsNoErr) && (state->lastBlockLZ77 == 1))
              retStatusMT = ippStsStreamEnd;

            state->decodeLZ77Status = retStatusMT; 

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

            if(retStatusMT == ippStsNoErr)
            {
              ippsDecodeLZ77SetPairs_8u(pPairConstMT, 0, pairsLenConstMT, pLZ77StateMT);  
            }
            else if(retStatusMT == ippStsDstSizeLessExpected)
            {
              ippsDecodeLZ77SetPairs_8u(pPairConstMT, pairsIndMT, pairsLenConstMT, pLZ77StateMT);
            }
            else if(retStatusMT == ippStsStreamEnd)
            {
              ippsDecodeLZ77SetPairs_8u(pPairConstMT, 0, pairsIndMT, pLZ77StateMT); 
            } /* if else */

            /* END OF SECTION 2. */
          } /* pragma omp section */
        } /* pragma omp parallel sections */

        /* Sequential block:                                                    */
        /* here must be the check of returned statuses by Huffman and LZ77.     */
        /* after check - take a descision to swap (and call SWAP_PAIRS) or not  */
        /* and, if not, - goto inf_leave. Third variant is ippStsStreamEnd and  */
        /* we must break and set inflateStatus to Final.                        */

        decodeHuffStatus = state->decodeHuffStatus;
        decodeLZ77Status = state->decodeLZ77Status; 

        if(decodeHuffStatus == ippStsStreamEnd)
        {
          state->lastBlockHuff = 1;
          if(decodeLZ77Status == ippStsNoErr)
          {
            SWAP_PAIRS(pPairConstSW, pPairConstSWMT, pairsIndSW, pairsIndSWMT, pairsLenConstSW, pairsLenConstSWMT, state);
            state->lastBlockLZ77 = 1;
          }
          else if(decodeLZ77Status == ippStsDstSizeLessExpected)
          {
            inflateStatus = IppLZ77InflateStatusHuffProcess;
            ippsDecodeLZ77SetStatus_8u(inflateStatus, pLZ77State);
            ret = Z_OK;
            goto inf_leave;
          }
          else if(decodeLZ77Status == ippStsStreamEnd)
          {
            inflateStatus = IppLZ77InflateStatusFinal;
            ippsDecodeLZ77SetStatus_8u(inflateStatus, pLZ77State);
            break;
          }
          else
          {
            ret = Z_DATA_ERROR;
            goto inf_leave;
          } /* if else */              
        } /* if */
        else if(decodeHuffStatus == ippStsDstSizeLessExpected)   
        {
          if(decodeLZ77Status == ippStsNoErr)  /* !!!! we gamble on it !!!! */
          {
            SWAP_PAIRS(pPairConstSW, pPairConstSWMT, pairsIndSW, pairsIndSWMT, pairsLenConstSW, pairsLenConstSWMT, state);
          } 
          else if(decodeLZ77Status == ippStsDstSizeLessExpected)
          {
            ippsDecodeLZ77SetPairs_8u(pPairConst, pairsInd, pairsLenConst, pLZ77State);
            inflateStatus = IppLZ77InflateStatusHuffProcess;
            ippsDecodeLZ77SetStatus_8u(inflateStatus, pLZ77State);
            ret = Z_OK;
            goto inf_leave;
          }
          else
          {
            ret = Z_DATA_ERROR;
            goto inf_leave;
          } /* if else */
        }
        else if(decodeHuffStatus == ippStsNoErr)
        {
          if(decodeLZ77Status == ippStsDstSizeLessExpected)
          {
            inflateStatus = IppLZ77InflateStatusHuffProcess;
            ippsDecodeLZ77SetStatus_8u(inflateStatus, pLZ77State);
            ret = Z_OK;
            goto inf_leave;
          }
          else if(decodeLZ77Status == ippStsStreamEnd || decodeLZ77Status < 0) 
          {
            ret = Z_DATA_ERROR;
            goto inf_leave;         
          } 
          else if(decodeLZ77Status == ippStsNoErr)
          {
            ippsDecodeLZ77SetPairs_8u(pPairConstMT, pairsIndMT, pairsLenConstMT, pLZ77StateMT); 
          } /* if else */
        }
        else if(decodeHuffStatus == ippStsSrcSizeLessExpected)
        {
          if(decodeLZ77Status == ippStsNoErr) 
          {
            ippsDecodeLZ77SetPairs_8u(pPairConstMT, pairsIndMT, pairsLenConstMT, pLZ77StateMT); 
            inflateStatus = IppLZ77InflateStatusHuffProcess;
            ippsDecodeLZ77SetStatus_8u(inflateStatus, pLZ77State);
            ret = Z_OK;
            goto inf_leave;
          }
          else if(decodeLZ77Status == ippStsDstSizeLessExpected)
          {
            inflateStatus = IppLZ77InflateStatusHuffProcess;
            ippsDecodeLZ77SetStatus_8u(inflateStatus, pLZ77State);
            ret = Z_OK;
            goto inf_leave;
          }
          else
          {
            ret = Z_DATA_ERROR;
            goto inf_leave;
          } /* if else */
        }
        else
        {
          ret = Z_DATA_ERROR;
          goto inf_leave;
        } /* if else */ 
      } /* SPOTTY FOR flush != Z_BLOCK */
    } /* IF inflateStatus == IppLZ77InflateStatusHuffProcess */
  } /* if flush != Z_BLOCK: 2-thread paralellized spot */
  else
  {
    for( ; ; ) /* SPOTTY FOR flush == Z_BLOCK */
    {
      ippsDecodeLZ77GetStatus_8u(&inflateStatus, pLZ77State);
      ippsDecodeLZ77GetPairs_8u(&pPairConst, &pairsInd, &pairsLenConst, pLZ77State); 
      if(inflateStatus == IppLZ77InflateStatusHuffProcess)
      {
        pSrc = strm->next_in;
        srcLen = strm->avail_in;
        retStatus = ippsDecodeLZ77GetBlockType_8u(&pSrc, &srcLen, &huffMode, pLZ77State);  
        strm->avail_in = srcLen;
        strm->next_in = pSrc;
        if(retStatus == ippStsNoErr)
        {
          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);
			strm->next_in = pSrc;
            strm->avail_in = srcLen;

            pairsInd = pPair - pPairConst;

            if(retStatus == ippStsNoErr)
            {
              ippsDecodeLZ77SetPairs_8u(pPairConst, pairsInd, pairsLenConst, pLZ77State);
              state->blockEnd = 1;
              inflateStatus = IppLZ77InflateStatusLZ77Process;
              ippsDecodeLZ77SetPairs_8u(pPairConst, 0, pairsInd, pLZ77State);
            }
            else if(retStatus == ippStsDstSizeLessExpected || retStatus == ippStsStreamEnd)
            {
              inflateStatus = IppLZ77InflateStatusLZ77Process;
              ippsDecodeLZ77SetPairs_8u(pPairConst, 0, pairsInd, pLZ77State);
              if(retStatus == ippStsStreamEnd)
                state->headerMode = infhead;
            }
            else if(retStatus == ippStsSrcSizeLessExpected)
            {
              ippsDecodeLZ77SetPairs_8u(pPairConst, pairsInd, pairsLenConst, pLZ77State);
              ret = Z_OK;
              goto inf_leave;
            } /* if else */
            ippsDecodeLZ77SetStatus_8u(inflateStatus, pLZ77State);
          }
          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);
            strm->next_in = pSrc;
            strm->avail_in = srcLen;
            pairsInd = pPair - pPairConst;

            if(retStatus == ippStsNoErr)
            {
              ippsDecodeLZ77SetPairs_8u(pPairConst, pairsInd, pairsLenConst, pLZ77State);
              state->blockEnd = 1;
              inflateStatus = IppLZ77InflateStatusLZ77Process;
              ippsDecodeLZ77SetPairs_8u(pPairConst, 0, pairsInd, pLZ77State);
            }
            else if(retStatus == ippStsDstSizeLessExpected || retStatus == ippStsStreamEnd)
            {
              inflateStatus = IppLZ77InflateStatusLZ77Process;
              ippsDecodeLZ77SetPairs_8u(pPairConst, 0, pairsInd, pLZ77State);
              if(retStatus == ippStsStreamEnd)
                state->headerMode = infhead;
            }
            else if(retStatus == ippStsSrcSizeLessExpected)
            {
              ippsDecodeLZ77SetPairs_8u(pPairConst, pairsInd, pairsLenConst, pLZ77State);
              ret = Z_OK;
              goto inf_leave;
            } /* if else */
            ippsDecodeLZ77SetStatus_8u(inflateStatus, pLZ77State);
          }
          else if(huffMode == IppLZ77UseStored)
          {
            pSrc = strm->next_in;
            srcLen = strm->avail_in;
            pDst = strm->next_out;
            dstLen = strm->avail_out;

            retStatus = ippsDecodeLZ77StoredBlock_8u(&pSrc, &srcLen, &pDst, &dstLen, pLZ77State); 
			
            strm->next_in = pSrc;
            strm->avail_in = srcLen;
            strm->next_out = pDst;
            strm->avail_out = dstLen;

            if(retStatus == ippStsNoErr) 
            {
              inflateStatus = IppLZ77InflateStatusHuffProcess; 
            }
            else if(retStatus == ippStsStreamEnd)
            {
              inflateStatus = IppLZ77InflateStatusFinal; 
              state->headerMode = infhead;
              break;
            }
            else if(retStatus == ippStsDstSizeLessExpected || retStatus == ippStsSrcSizeLessExpected)
            {
              ret = Z_OK;
              goto inf_leave;                  
            } 
            else
            {
              ret = Z_DATA_ERROR;
              goto inf_leave;
            } /* if else */
            ippsDecodeLZ77SetStatus_8u(inflateStatus, pLZ77State); 
          } /* if else */ 
        } 
        else if(retStatus == ippStsSrcSizeLessExpected)
        {
          ret = Z_OK;
          goto inf_leave;
        }
        else
        {
          ret = Z_DATA_ERROR; 
          goto inf_leave;
        } /* if else */
      } /* IppLZ77InflateStatusHuffProcess */

      ippsDecodeLZ77GetStatus_8u(&inflateStatus, pLZ77State);
      ippsDecodeLZ77GetPairs_8u(&pPairConst, &pairsInd, &pairsLenConst, pLZ77State); 
      if(inflateStatus == IppLZ77InflateStatusLZ77Process)
      {
        pPair = pPairConst + pairsInd;        
        srcLen = pairsLenConst - pairsInd;
        pDst = strm->next_out;
        dstLen = strm->avail_out;
        retStatus = ippsDecodeLZ77_8u(&pPair, &srcLen, &pDst, &dstLen, ippflush, pLZ77State);
        strm->next_out = pDst;
        strm->avail_out = dstLen;
        pairsInd = pPair - pPairConst;
        if(retStatus == ippStsNoErr)
        {
          ippsDecodeLZ77SetPairs_8u(pPairConst, 0, pairsInd, pLZ77State);         
          inflateStatus = IppLZ77InflateStatusHuffProcess;
          if((flush == Z_BLOCK) && (state->blockEnd == 1))
          { 
            ippsDecodeLZ77SetStatus_8u(inflateStatus, pLZ77State);  
            ret = Z_OK;
            state->blockEnd = 0;
            goto inf_leave;
          } /* if */
        }
        else if(retStatus == ippStsDstSizeLessExpected)
        {
          ippsDecodeLZ77SetPairs_8u(pPairConst, pairsInd, pairsLenConst, pLZ77State);
          ret = Z_OK;
          goto inf_leave;
        }
        else if(retStatus == ippStsStreamEnd)
        {
          ippsDecodeLZ77SetPairs_8u(pPairConst, 0, pairsInd, pLZ77State); 
          inflateStatus = IppLZ77InflateStatusFinal;
          ippsDecodeLZ77SetStatus_8u(inflateStatus, pLZ77State); 
          break;
        }
        else 
        {
          ret = Z_DATA_ERROR;
          goto inf_leave;
        } /* if else */       
        ippsDecodeLZ77SetStatus_8u(inflateStatus, pLZ77State);  
      } /* IppLZ77InflateStatusLZ77Process */
    } /* SPOTTY FOR flush == Z_BLOCK */   
  } /* if flush == Z_BLOCK: single thread execution without OMP */  

  ippsDecodeLZ77GetStatus_8u(&inflateStatus, pLZ77State);
  ippsDecodeLZ77GetPairs_8u(&pPairConst, &pairsInd, &pairsLenConst, pLZ77State); 
  if(inflateStatus == IppLZ77InflateStatusFinal)
  {
	state->decodeHuffStatus = ippStsNoErr;
    state->decodeLZ77Status = ippStsNoErr;
    state->lastBlockHuff    = 0;
    state->lastBlockLZ77    = 0;
    state->firstSwapDone    = 0;

    ret = Z_STREAM_END;
    goto inf_leave;  
  } /* IppLZ77InflateStatusFinal */

  goto next_iteration;

inf_leave:

  in -= strm->avail_in;
  out -= strm->avail_out;
  strm->total_in += in;
  strm->total_out += out;
  
  if(out) strm->adler = state->check = UPDATE(state->check, strm->next_out - out, out);
  
  if(ret == Z_STREAM_END && state->wrap)
  {
    while(state->headerBits < 32)
    {   
       if(strm->avail_in == 0) return Z_OK;

       (strm->avail_in)--;  
       state->headerBuf += ((*(strm->next_in)) << state->headerBits);
	   (strm->next_in)++; 
       (strm->total_in)++;
       state->headerBits += 8;  
    } /* while */ 

    if(( 
#ifdef GUNZIP		   
	  state->headerFlags ? state->headerBuf:
#endif		   
	  REVERSE(state->headerBuf)) != (int)(state->check) ) 
	{
	   ret = Z_DATA_ERROR;
	} /* if */
  } /* if */

  return ret;
} /* parallel inflate() */

#else /* else - means if either INFLATE_OMP or _OPENMP undefined: */

int ZEXPORT inflate(strm, flush)
z_streamp strm;
int flush;
{
  struct inflate_state FAR *state;

  int ret;
  unsigned int           in, out;  /* save starting available input and output */
  IppLZ77State_8u*       pLZ77State;
  IppLZ77InflateStatus   inflateStatus;
  IppStatus              retStatus; 
  IppLZ77Flush           ippflush;
  Ipp8u*                 pSrc;             
  int                    srcLen;
  Ipp8u*                 pDst;
  int                    dstLen;
  IppLZ77HuffMode        huffMode;
  unsigned int           copy;
  unsigned int           len;

  in = strm->avail_in;

⌨️ 快捷键说明

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