📄 deflate.c
字号:
case IppLZ77StatusInit:
#ifdef GZIP
if( s->wrap == 2 ) {
strm->adler = 0L;
put_byte_ipp(s, 31);
put_byte_ipp(s, 139);
put_byte_ipp(s, 8);
if (s->gzhead == NULL) {
put_byte_ipp(s, 0);
put_byte_ipp(s, 0);
put_byte_ipp(s, 0);
put_byte_ipp(s, 0);
put_byte_ipp(s, 0);
if( s->level < 4 ) { put_byte_ipp(s, 4); }
else if( (s->level >= 4) && (s->level < 8) ) { put_byte_ipp(s, 0); }
else { put_byte_ipp(s, 2); }
put_byte_ipp(s, OS_CODE);
} /* if */
else {
put_byte_ipp(s, (s->gzhead->text ? 1 : 0) +
(s->gzhead->hcrc ? 2 : 0));
put_byte_ipp(s, (Byte)(s->gzhead->time & 0xff));
put_byte_ipp(s, (Byte)((s->gzhead->time >> 8) & 0xff));
put_byte_ipp(s, (Byte)((s->gzhead->time >> 16) & 0xff));
put_byte_ipp(s, (Byte)((s->gzhead->time >> 24) & 0xff));
if( s->level < 4 ) { put_byte_ipp(s, 4); }
else if( (s->level >= 4) && (s->level < 8) ) { put_byte_ipp(s, 0); }
else { put_byte_ipp(s, 2); }
put_byte_ipp(s, s->gzhead->os & 0xff);
if( s->gzhead->hcrc ) {
strm->adler = crc32(strm->adler, s->header_trailer_buff, s->header_trailer_bytes_valid);
put_byte_ipp(s, (Byte)(strm->adler & 0xff));
put_byte_ipp(s, (Byte)((strm->adler >> 8) & 0xff));
strm->adler = 0L;
} /* if */
} /* else */
} /* if */
else
#endif
{ /* block */
header = (Z_DEFLATED + (7 << 4)) << 8;
if( s->level < 4 ) level_flags = 0;
else if( (s->level >= 4) && (s->level < 8) ) level_flags = 1;
else level_flags = 3;
header |= (level_flags << 6);
header += 31 - (header % 31);
putShortMSB_ipp( s, header );
strm->adler = 1L;
} /* block */
deflateStatus = IppLZ77StatusLZ77Process;
ippsEncodeLZ77SetStatus_8u( deflateStatus, pLZ77State );
if( flush_header_trailer(strm) < 0 ) return Z_OK;
case IppLZ77StatusLZ77Process:
#ifdef USE_NC_BLK
if( ((ippflush == IppLZ77NoFlush) || (ippflush == IppLZ77FinishFlush)) && (s->in_tmpbuff_valid) ) {
int minLen = ( strm->avail_in > s->in_tmpbuff_avail ) ?
s->in_tmpbuff_avail : strm->avail_in;
if( minLen ) {
ippsCopy_8u( (const Ipp8u*)strm->next_in, (Ipp8u*)s->in_tmpbuff_next, minLen );
strm->total_in += minLen;
strm->next_in += minLen;
strm->avail_in -= minLen;
s->in_tmpbuff_next += minLen;
s->in_tmpbuff_avail -= minLen;
if( s->in_tmpbuff_avail ) return Z_OK;
} /* if */
ippsEncodeLZ77GetPairs_8u( &cpPairs, &pairsInd, &pairsLen, pLZ77State );
pPairs = cpPairs + pairsInd;
pdstLen = pairsLen - pairsInd;
pSrc = s->in_tmpbuff_ptr;
srcLen = s->in_tmpbuff_size - s->in_tmpbuff_avail;
chslen = srcLen;
status = ippsEncodeLZ77_8u( &pSrc, &srcLen, &pPairs, &pdstLen, ippflush, pLZ77State );
chslen -= srcLen;
if( s->wrap == 1 ) strm->adler = adler32( strm->adler, strm->next_in, chslen );
pairsInd = pairsLen - pdstLen;
ippsEncodeLZ77SetPairs_8u( cpPairs, pairsInd, pairsLen, pLZ77State );
if( status < 0 ) return Z_STREAM_ERROR;
if( status == ippStsNoErr ) {
s->in_tmpbuff_next = s->in_tmpbuff_ptr;
s->in_tmpbuff_rem = 0;
s->in_tmpbuff_avail = s->in_tmpbuff_size;
s->in_tmpbuff_valid = 0;
if( strm->avail_in || (ippflush == IppLZ77FinishFlush) ) break;
return Z_OK;
} /* if */
s->in_tmpbuff_next = s->in_tmpbuff_ptr;
s->in_tmpbuff_rem = s->in_tmpbuff_avail + srcLen;
s->in_tmpbuff_avail = chslen;
deflateStatus = IppLZ77StatusHuffProcess;
ippsEncodeLZ77SetStatus_8u( deflateStatus, pLZ77State );
break;
} /* if */
#endif
ippsEncodeLZ77GetPairs_8u( &cpPairs, &pairsInd, &pairsLen, pLZ77State );
pPairs = cpPairs + pairsInd;
pdstLen = pairsLen - pairsInd;
pSrc = strm->next_in;
srcLen = strm->avail_in;
strm->total_in += srcLen;
chslen = srcLen;
status = ippsEncodeLZ77_8u( &pSrc, &srcLen, &pPairs, &pdstLen, ippflush, pLZ77State );
strm->total_in -= srcLen;
chslen -= srcLen;
if( s->wrap == 1 ) strm->adler = adler32( strm->adler, strm->next_in, chslen );
strm->next_in = pSrc;
strm->avail_in = srcLen;
pairsInd = pairsLen - pdstLen;
ippsEncodeLZ77SetPairs_8u( cpPairs, pairsInd, pairsLen, pLZ77State );
if( status < 0 ) return Z_STREAM_ERROR;
if( (status == ippStsNoErr) && (ippflush == IppLZ77NoFlush) ) return Z_OK;
deflateStatus = IppLZ77StatusHuffProcess;
ippsEncodeLZ77SetStatus_8u( deflateStatus, pLZ77State );
case IppLZ77StatusHuffProcess:
pDst = strm->next_out;
dstLen = strm->avail_out;
strm->total_out += dstLen;
#ifdef USE_NC_BLK
if( s->in_tmpbuff_valid ) {
status = ippsEncodeLZ77StoredBlock_8u( &s->in_tmpbuff_next, &s->in_tmpbuff_avail, &pDst, &dstLen, ippflush, pLZ77State );
} /* if */
else
#endif
{ /* block */
ippsEncodeLZ77GetPairs_8u( &cpPairs, &pairsInd, &pairsLen, pLZ77State );
psrcLen = pairsLen - pairsInd;
pPairs = cpPairs + pairsInd;
#ifdef FORCE_STATIC
status = ippsEncodeLZ77FixedHuff_8u( &pPairs, &psrcLen, &pDst, &dstLen, ippflush, pLZ77State );
#else
status = ippsEncodeLZ77DynamicHuff_8u( &pPairs, &psrcLen, &pDst, &dstLen, ippflush, pLZ77State );
#endif
pairsInd = pairsLen - psrcLen;
ippsEncodeLZ77SetPairs_8u( cpPairs, pairsInd, pairsLen, pLZ77State );
} /* block */
strm->total_out -= dstLen;
strm->next_out = pDst;
strm->avail_out = dstLen;
switch( status ) {
case ippStsDstSizeLessExpected:
return Z_OK;
case ippStsNoErr:
#ifdef USE_NC_BLK
if( s->in_tmpbuff_valid && s->in_tmpbuff_rem ) {
s->in_tmpbuff_avail = s->in_tmpbuff_size - s->in_tmpbuff_rem;
ippsMove_8u( (const Ipp8u*)s->in_tmpbuff_next, (Ipp8u*)s->in_tmpbuff_ptr, s->in_tmpbuff_rem );
s->in_tmpbuff_next = s->in_tmpbuff_ptr + s->in_tmpbuff_rem;
} /* if */
s->in_tmpbuff_valid = 1;
#endif
deflateStatus = IppLZ77StatusLZ77Process;
ippsEncodeLZ77SetStatus_8u( deflateStatus, pLZ77State );
if( ippflush != IppLZ77FinishFlush ) return Z_OK;
break;
case ippStsStreamEnd:
deflateStatus = IppLZ77StatusFinal;
ippsEncodeLZ77SetStatus_8u( deflateStatus, pLZ77State );
break;
default: return Z_STREAM_ERROR;
} /* switch */
break;
case IppLZ77StatusFinal:
if( s->wrap < 0 ) return Z_STREAM_END;
switch( s->wrap ) {
case 1:
if( s->trailer_empty == 1 ) {
putShortMSB_ipp( s, (uInt)(strm->adler >> 16) );
putShortMSB_ipp( s, (uInt)(strm->adler & 0xffff) );
} /* if */
if( flush_header_trailer(strm) < 0 ) {
s->trailer_empty = 0;
return Z_OK;
} /* if */
break;
case 2:
pDst = strm->next_out;
dstLen = strm->avail_out;
strm->total_out += dstLen;
status = ippsEncodeLZ77Flush_8u( &pDst, &dstLen, pLZ77State );
strm->total_out -= dstLen;
strm->next_out = pDst;
strm->avail_out = dstLen;
if( status < 0 ) return Z_STREAM_ERROR;
if( status == ippStsDstSizeLessExpected ) return Z_OK;
break;
} /* switch */
s->wrap = -s->wrap; /* write the trailer only once! */
s->trailer_empty = 1;
return Z_STREAM_END;
default: return Z_STREAM_ERROR;
} /* switch */
} /* for */
return Z_STREAM_END;
} /* deflate() */
/* ========================================================================= */
int ZEXPORT deflateEnd (strm)
z_streamp strm;
{
IppLZ77DeflateStatus deflateStatus;
if (strm == Z_NULL || strm->state == Z_NULL || strm->state->ipp_state == Z_NULL) return Z_STREAM_ERROR;
ippsEncodeLZ77GetStatus_8u(&deflateStatus, strm->state->ipp_state);
if(deflateStatus != IppLZ77StatusInit && deflateStatus != IppLZ77StatusLZ77Process &&
deflateStatus != IppLZ77StatusHuffProcess && deflateStatus != IppLZ77StatusFinal) {
return Z_STREAM_ERROR;
}
TRY_FREE(strm, strm->state->ipp_state);
/* Deallocate in reverse order of allocations: */
TRY_FREE(strm, strm->state->pending_buf);
TRY_FREE(strm, strm->state->head);
TRY_FREE(strm, strm->state->prev);
TRY_FREE(strm, strm->state->window);
ZFREE(strm, strm->state);
strm->state = Z_NULL;
return deflateStatus == IppLZ77StatusLZ77Process ? Z_DATA_ERROR : Z_OK;
}
/* =========================================================================
* Copy the source state to the destination state.
* To simplify the source, this is not supported for 16-bit MSDOS (which
* doesn't have enough memory anyway to duplicate compression states).
*/
int ZEXPORT deflateCopy (dest, source)
z_streamp dest;
z_streamp source;
{
#ifdef MAXSEG_64K
return Z_STREAM_ERROR;
#else
deflate_state *ds;
deflate_state *ss;
ushf *overlay;
if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) {
return Z_STREAM_ERROR;
}
ss = source->state;
zmemcpy(dest, source, sizeof(z_stream));
ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state));
if (ds == Z_NULL) return Z_MEM_ERROR;
dest->state = (struct internal_state FAR *) ds;
zmemcpy(ds, ss, sizeof(deflate_state));
ds->strm = dest;
ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos));
ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos));
overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2);
ds->pending_buf = (uchf *) overlay;
if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL ||
ds->pending_buf == Z_NULL) {
deflateEnd (dest);
return Z_MEM_ERROR;
}
/* following zmemcpy do not work for 16-bit MSDOS */
zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte));
zmemcpy(ds->prev, ss->prev, ds->w_size * sizeof(Pos));
zmemcpy(ds->head, ss->head, ds->hash_size * sizeof(Pos));
zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush);
ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize;
ds->l_desc.dyn_tree = ds->dyn_ltree;
ds->d_desc.dyn_tree = ds->dyn_dtree;
ds->bl_desc.dyn_tree = ds->bl_tree;
return Z_OK;
#endif /* MAXSEG_64K */
}
/* ===========================================================================
* Read a new buffer from the current input stream, update the adler32
* and total number of bytes read. All deflate() input goes through
* this function so some applications may wish to modify it to avoid
* allocating a large strm->next_in buffer and copying from it.
* (See also flush_pending()).
*/
local int read_buf(strm, buf, size)
z_streamp strm;
Bytef *buf;
unsigned size;
{
unsigned len = strm->avail_in;
if (len > size) len = size;
if (len == 0) return 0;
strm->avail_in -= len;
if (strm->state->wrap == 1) {
strm->adler = adler32(strm->adler, strm->next_in, len);
}
#ifdef GZIP
else if (strm->state->wrap == 2) {
strm->adler = crc32(strm->adler, strm->next_in, len);
}
#endif
zmemcpy(buf, strm->next_in, len);
strm->next_in += len;
strm->total_in += len;
return (int)len;
}
/* ===========================================================================
* Initialize the "longest match" routines for a new zlib stream
*/
local void lm_init (s)
deflate_state *s;
{
s->window_size = (ulg)2L*s->w_size;
CLEAR_HASH(s);
/* Set the default configuration parameters:
*/
s->max_lazy_match = configuration_table[s->level].max_lazy;
s->good_match = configuration_table[s->level].good_length;
s->nice_match = configuration_table[s->level].nice_length;
s->max_chain_length = configuration_table[s->level].max_chain;
s->strstart = 0;
s->block_start = 0L;
s->lookahead = 0;
s->match_length = s->prev_length = MIN_MATCH-1;
s->match_available = 0;
s->ins_h = 0;
#ifndef FASTEST
#ifdef ASMV
match_init(); /* initialize the asm code */
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -