Encodes the last few bits in the bitstream and aligns the output data on the byte boundary.
IppStatus ippsEncodeLZSSFlush_8u (Ipp8u** ppDst, int* pDstLen, IppLZSSState_8u* pLZSSState);
ppDst |
Double pointer to the destination buffer. |
pDstLen |
Pointer to the length of destination buffer. |
pLZSSState |
Pointer to the LZSS encoder state structure. |
The function ippsEncodeLZSSFlush is declared in the ippdc.h file. This function encodes the last few bits (remainder) in the bitstream, writes them to ppDst, and aligns the output data on a byte boundary.
Example below shows how to use the function ippsEncodeLZSSFlush_8u and supporting functions.
ippStsNoErr |
Indicates no error. |
ippStsNullPtrErr |
Indicates an error if one of the pointers is NULL. |
ippStsSizeErr |
Indicates an error if pDstLen is less than or equal to 0. |
ippStsDstSizeLessExpected |
Indicates a warning that the size of the destination buffer is insufficient for completing the operation. |
#define INBLOCKSIZE 65536
#define OUTBLOCKSIZE 16384
........................
#include <stdio.h>
#include "ippdc.h"
........................
FILE *inFile, *outFile;
Ipp8u *pSrc = NULL, *pDst = NULL, *startpSrc, *startpDst;
int srcLen, dstLen = 0;
int commonDstLen;
IppLZSSState_8u *pLZSSState;
IppStatus status;
........................
/*************************************************************/
/* Memory allocation for input data and output code buffers, */
/* and for the internal encoding state structure: */
/*************************************************************/
startpSrc = ippsMalloc_8u( (INBLOCKSIZE) * sizeof(char) );
startpDst = ippsMalloc_8u( (OUTBLOCKSIZE) * sizeof(char) );
ippsEncodeLZSSInitAlloc_8u(&pLZSSState);
/*************************************************************/
/* Initializing the arguments, reading srcLen bytes of */
/* input data from input data file to startpSrc: */
/*************************************************************/
commonDstLen = (OUTBLOCKSIZE);
pDst = startpDst;
dstLen = commonDstLen;
srcLen = fread( startpSrc, sizeof(Ipp8u), INBLOCKSIZE, inFile );
if(srcLen <= 0)
return -1;
pSrc = startpSrc;
/*************************************************************/
/* The main loop. In every iteration program calls the */
/* ippsEncodeLZSS_8u. ippsEncodeLZSS_8u changes the values */
/* of pSrc, srcLen, pDst and dstLen. ippsEncodeLZSS_8u */
/* returns ippStsDstSizeLessExpected if there is no */
/* room in the destination buffer pDst to continue encoding. */
/* In this case dstLen == 0. Such case is handled by */
/* flushing the pDst to the output file. If ippsEncodeLZSS_8u */
/* returns ippStsNoErr, then the program flushes the current */
/* pDst of length of (commonDstLen - dstLen) bytes to */
/* the output file and reads next srcLen bytes of input data */
/* to startpSrc. */
/*************************************************************/
for( ; ; )
{
status = ippsEncodeLZSS_8u(&pSrc, &srcLen, &pDst, &dstLen, pLZSSState);
if( status == ippStsDstSizeLessExpected )
{
fwrite( startpDst, sizeof(Ipp8u), (commonDstLen - dstLen), outFile );
dstLen = commonDstLen;
pDst = startpDst;
}
else if( status == ippStsNoErr )
{
fwrite( startpDst, sizeof(Ipp8u), (commonDstLen - dstLen), outFile );
pDst = startpDst;
dstLen = commonDstLen;
srcLen = fread( startpSrc, sizeof(Ipp8u), INBLOCKSIZE, inFile );
if( srcLen <= 0 )
break;
pSrc = startpSrc;
}
else
return (-1);
} /* for */
/**************************************************************/
/* The call of ippsEncodeLZSSFlush_8u flushes the last few */
/* bits of code to the destination buffer: */
/**************************************************************/
if( ippsEncodeLZSSFlush_8u(&pDst, &dstLen, pLZSSState) == ippStsNoErr )
{
fwrite( startpDst, sizeof(Ipp8u), (commonDstLen - dstLen), outFile );
ippsLZSSFree_8u(pLZSSState);
ippsFree( startpSrc );
ippsFree( startpDst );
_fcloseall();
}
else
return (-1);
....................
Copyright © 2000 - 2010, Intel Corporation. All rights reserved.