?? ipp_zlib.c
字號:
} while (--op);
from = out - dist; /* rest from output */
}
}
while (len > 2) {
PUP(out) = PUP(from);
PUP(out) = PUP(from);
PUP(out) = PUP(from);
len -= 3;
}
if (len) {
PUP(out) = PUP(from);
if (len > 1)
PUP(out) = PUP(from);
}
}
else {
from = out - dist; /* copy direct from output */
do { /* minimum length is three */
PUP(out) = PUP(from);
PUP(out) = PUP(from);
PUP(out) = PUP(from);
len -= 3;
} while (len > 2);
if (len) {
PUP(out) = PUP(from);
if (len > 1)
PUP(out) = PUP(from);
}
}
}
else if ((op & 64) == 0) { /* 2nd level distance code */
this = dcode[this.val + (hold & ((1U << op) - 1))];
goto dodist;
}
else {
strm->msg = (char *)"invalid distance code";
state->mode = BAD;
break;
}
}
else if ((op & 64) == 0) { /* 2nd level length code */
this = lcode[this.val + (hold & ((1U << op) - 1))];
goto dolen;
}
else if (op & 32) { /* end-of-block */
state->mode = TYPE;
break;
}
else {
strm->msg = (char *)"invalid literal/length code";
state->mode = BAD;
break;
}
} while (in < last && out < end);
/* return unused bytes (on entry, bits < 8, so in won't go too far back) */
len = bits >> 3;
in -= len;
bits -= len << 3;
hold &= (1U << bits) - 1;
/* update state and return */
strm->next_in = in + OFF;
strm->next_out = out + OFF;
strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last));
strm->avail_out = (unsigned)(out < end ?
257 + (end - out) : 257 - (out - end));
state->hold = hold;
state->bits = bits;
return;
} /* inflate_fast() */
/**********************************************************************************/
/* Macros for inflate() */
/**********************************************************************************/
#ifdef GZIP
# define UPDATE(check, buf, len) \
(state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
#else
# define UPDATE(check, buf, len) adler32(check, buf, len)
#endif
#ifdef GZIP
# define CRC2(check, word) \
do { \
hbuf[0] = (unsigned char)(word); \
hbuf[1] = (unsigned char)((word) >> 8); \
check = crc32(check, hbuf, 2); \
} while (0)
# define CRC4(check, word) \
do { \
hbuf[0] = (unsigned char)(word); \
hbuf[1] = (unsigned char)((word) >> 8); \
hbuf[2] = (unsigned char)((word) >> 16); \
hbuf[3] = (unsigned char)((word) >> 24); \
check = crc32(check, hbuf, 4); \
} while (0)
#endif
#define LOAD() \
do { \
put = strm->next_out; \
left = strm->avail_out; \
next = strm->next_in; \
have = strm->avail_in; \
hold = state->hold; \
bits = state->bits; \
} while (0)
#define RESTORE() \
do { \
strm->next_out = put; \
strm->avail_out = left; \
strm->next_in = next; \
strm->avail_in = have; \
state->hold = hold; \
state->bits = bits; \
} while (0)
#define INITBITS() \
do { \
hold = 0; \
bits = 0; \
} while (0)
#define PULLBYTE() \
do { \
if (have == 0) goto inf_leave; \
have--; \
hold += (unsigned long)(*next++) << bits; \
bits += 8; \
} while (0)
#define NEEDBITS(n) \
do { \
while (bits < (unsigned)(n)) \
PULLBYTE(); \
} while (0)
#define BITS(n) \
((unsigned)hold & ((1U << (n)) - 1))
#define DROPBITS(n) \
do { \
hold >>= (n); \
bits -= (unsigned)(n); \
} while (0)
#define BYTEBITS() \
do { \
hold >>= bits & 7; \
bits -= bits & 7; \
} while (0)
#define REVERSE(q) \
((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
(((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
#endif /* NATIVE_INFLATE */
/**********************************************************************************/
/* Implementation of ZLIB interfaces */
/**********************************************************************************/
int
deflate(z_stream* strm, int flush)
{
IppLZ77State_8u* pLZ77State;
IppLZ77DeflateStatus deflateStatus;
IppLZ77Flush ippflush;
IppLZ77Pair* pPairs;
IppLZ77Pair* cpPairs;
IppStatus status;
int pairsInd;
int pairsLen;
int psrcLen;
int pdstLen;
int srcLen;
Ipp8u* pSrc;
int dstLen;
Ipp8u* pDst;
IppLZ77HuffMode huffMode;
#ifndef GZIP
unsigned int header;
unsigned int level_flags;
#endif
if( flush == Z_NO_FLUSH )
ippflush = IppLZ77NoFlush;
else if( flush == Z_SYNC_FLUSH )
ippflush = IppLZ77SyncFlush;
else if( flush == Z_FULL_FLUSH )
ippflush = IppLZ77FullFlush;
else if( flush == Z_FINISH)
ippflush = IppLZ77FinishFlush;
if(strm == Z_NULL || strm->state == Z_NULL ||
flush > Z_FINISH || flush < 0)
{
return Z_STREAM_ERROR;
}
pLZ77State = strm->state;
if(strm->next_out == Z_NULL || (strm->next_in == Z_NULL && strm->avail_in != 0) )
{
return Z_STREAM_ERROR;
}
for( ; ; )
{
ippsEncodeLZ77GetStatus_8u(&deflateStatus, pLZ77State);
if(deflateStatus == IppLZ77StatusInit)
{
strm->total_out += strm->avail_out;
#ifdef GZIP
put_byte(strm, 31);
put_byte(strm, 139);
put_byte(strm, 8);
put_byte(strm, 0);
put_byte(strm, 0);
put_byte(strm, 0);
put_byte(strm, 0);
put_byte(strm, 0);
put_byte(strm, 4);
put_byte(strm, 255);
deflateStatus = IppLZ77StatusLZ77Process;
ippsEncodeLZ77SetStatus_8u(deflateStatus, pLZ77State);
#endif
#ifndef GZIP
header = (Z_DEFLATED + (7<<4)) << 8;
level_flags = 2;
header |= (level_flags << 6);
header += 31 - (header % 31);
ippsEncodeLZ77SetStatus_8u(IppLZ77StatusLZ77Process, pLZ77State);
putShortMSB(strm, header);
strm->adler = 0;
#endif
strm->total_out -= strm->avail_out;
} /* IppLZ77StatusInit */
ippsEncodeLZ77GetStatus_8u(&deflateStatus, pLZ77State);
if(deflateStatus == IppLZ77StatusLZ77Process)
{
ippsEncodeLZ77GetPairs_8u(&cpPairs, &pairsInd, &pairsLen, pLZ77State);
pPairs = cpPairs + pairsInd;
pdstLen = pairsLen - pairsInd;
pSrc = strm->next_in;
srcLen = strm->avail_in;
strm->total_in += srcLen;
status = ippsEncodeLZ77_8u(&pSrc, &srcLen, &pPairs, &pdstLen, ippflush, pLZ77State);
strm->total_in -= srcLen;
strm->next_in = pSrc;
strm->avail_in = srcLen;
pairsInd = pairsLen - pdstLen;
ippsEncodeLZ77SetPairs_8u(cpPairs, pairsInd, pairsLen, pLZ77State);
if(status < 0 )
return Z_STREAM_ERROR;
else if(status == ippStsNoErr && ippflush == IppLZ77NoFlush)
return Z_OK;
else
{
deflateStatus = IppLZ77StatusHuffProcess;
ippsEncodeLZ77SetStatus_8u(deflateStatus, pLZ77State);
}
} /* IppLZ77StatusLZ77Process */
ippsEncodeLZ77GetStatus_8u(&deflateStatus, pLZ77State);
if(deflateStatus == IppLZ77StatusHuffProcess)
{
ippsEncodeLZ77GetPairs_8u(&cpPairs, &pairsInd, &pairsLen, pLZ77State);
psrcLen = pairsLen - pairsInd;
pPairs = cpPairs + pairsInd;
pDst = strm->next_out;
dstLen = strm->avail_out;
strm->total_out += dstLen;
#ifdef FORCE_FIXED
status = ippsEncodeLZ77FixedHuff_8u(&pPairs, &psrcLen, &pDst, &dstLen, ippflush, pLZ77State);
#endif
#ifndef FORCE_FIXED
#ifdef FORCE_DYNAMIC
status = ippsEncodeLZ77DynamicHuff_8u(&pPairs, &psrcLen, &pDst, &dstLen, ippflush, pLZ77State);
#endif
#ifndef FORCE_DYNAMIC
ippsEncodeLZ77SelectHuffMode_8u(pPairs, psrcLen, &huffMode, pLZ77State);
if(huffMode == IppLZ77UseDynamic)
{
status = ippsEncodeLZ77DynamicHuff_8u(&pPairs, &psrcLen, &pDst, &dstLen, ippflush, pLZ77State);
}
else
{
status = ippsEncodeLZ77FixedHuff_8u(&pPairs, &psrcLen, &pDst, &dstLen, ippflush, pLZ77State);
} /* if else */
#endif
#endif
strm->total_out -= dstLen;
strm->next_out = pDst;
strm->avail_out = dstLen;
pairsInd = pairsLen - psrcLen;
if(status < 0)
return Z_STREAM_ERROR;
if(status == ippStsDstSizeLessExpected)
{
ippsEncodeLZ77SetPairs_8u(cpPairs, pairsInd, pairsLen, pLZ77State);
return Z_OK;
}
else if(status == ippStsNoErr)
{
deflateStatus = IppLZ77StatusLZ77Process;
ippsEncodeLZ77SetStatus_8u(deflateStatus, pLZ77State);
if(ippflush != IppLZ77FinishFlush)
return Z_OK;
}
else if(status == ippStsStreamEnd)
{
deflateStatus = IppLZ77StatusFinal;
ippsEncodeLZ77SetStatus_8u(deflateStatus, pLZ77State);
} /* if else */
} /* IppLZ77StatusHuffProcess */
ippsEncodeLZ77GetStatus_8u(&deflateStatus, pLZ77State);
if(deflateStatus == IppLZ77StatusFinal)
{
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;
return Z_STREAM_END;
} /* IppLZ77StatusFinal */
} /* for */
return Z_STREAM_END;
} /* deflate() */
/**********************************************************************************/
int
deflateInit_(z_stream* strm, int level, const char *version, int stream_size)
{
return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL,
Z_DEFAULT_STRATEGY, version, stream_size);
} /* deflateInit_() */
/**********************************************************************************/
int
deflateInit2_(z_stream* strm, int level, int method,
int windowBits, int memLevel, int strategy,
const char *version, int stream_size)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -