Decompresses input data with constantly checking integrity of output.
IppStatus ippsDecodeLZOSafe_8u(Ipp8u* pSrc, Ipp32u srcLen, Ipp8u* pDst, Ipp32u* pDstLen);
pSrc |
Pointer to the source data buffer. |
srcLen |
Number of elements in the source data buffer. |
pDst |
Pointer to the destination data buffer. |
pDstLen |
Pointer to the variable with the number of elements in the destination data buffer. |
The function ippsDecodeLZOSafe is declared in the ippdc.h file.
This function is a version of the function ippsDecodeLZO. It decompresses the source (compressed) data according to the compressed data format. The function can decompress both single-thread and multi-threaded data. The maximum performance can be obtained only in multi-threaded decompression of data compressed in the multi-threaded mode. Additionally this function checks the integrity of the destination data buffer, that is checks the buffer boundary limits. This function works slower, it can be used in doubtful cases when the compressed data integrity is not guaranteed, for example, decoding data received via non-reliable communication lines.
Destination data buffer must have enough free space to hold uncompressed data. Prior to the function call the destination buffer size variable pointed to by pDstLen must be initialized with actual number of free bytes in the destination buffer.
Code example below shows how the Intel IPP functions for the LZO compression can be used.
ippStsNoErr |
Indicates no error. |
ippStsNullPtrErr |
Indicates an error if one of the specified pointers is NULL. |
ippStsLzoBrokenStreamErr |
Indicates an error if compressed data is not valid - not an LZO compressed data. |
ippStsDstSizeLessExpected |
Destination buffer is too small to store decompressed data. |
/* Simple example of file compression using IPP LZO functions */
#include <stdio.h>
#include "ippdc.h"
#include "ipps.h"
#define BUFSIZE 1024
void CompressFile(const char* pInFileName, const char* pOutFileName)
{
FILE *pIn, *pOut;
IppLZOState_8u *pLZOState;
Ipp8u src[BUFSIZE];
/* For uncompressible data the size of output will be bigger */
Ipp8u dst[BUFSIZE + BUFSIZE/10];
Ipp32u srcLen, dstLen, lzoSize;
pIn = fopen(pInFileName, "rb");
pOut = fopen(pOutFileName, "wb");
ippsEncodeLZOGetSize(IppLZO1XST, BUFSIZE, &lzoSize);
pLZOState = (IppLZOState_8u*)ippsMalloc_8u(lzoSize);
ippsEncodeLZOInit_8u(IppLZO1XST, BUFSIZE, pLZOState);
while ((srcLen = (Ipp32u)fread(src, 1, BUFSIZE, pIn)) > 0) {
ippsEncodeLZO_8u(src, srcLen, dst, &dstLen, pLZOState);
fwrite(&srcLen, 1, sizeof(srcLen), pOut);
fwrite(&dstLen, 1, sizeof(dstLen), pOut);
fwrite(dst, 1, dstLen, pOut);
}
fclose(pIn);
fclose(pOut);
}
/* Example of using of DecodeLZO function to decompress the file */
void DecompressFile(const char* pInFileName, const char* pOutFileName)
{
FILE *pIn, *pOut;
size_t allocSizeSrc = 0;
size_t allocSizeDst = 0;
Ipp32u srcLen, dstLen;
Ipp8u *pSrc, *pDst;
pIn = fopen(pInFileName, "rb");
pOut = fopen(pOutFileName, "wb");
while (1) {
if (fread(&dstLen, 1, sizeof(dstLen), pIn) != sizeof(dstLen))
break;
fread(&srcLen, 1, sizeof(srcLen), pIn);
if (srcLen > allocSizeSrc) {
if (allocSizeSrc > 0)
ippsFree(pSrc);
pSrc = ippsMalloc_8u(allocSizeSrc = srcLen);
}
if (dstLen > allocSizeDst) {
if (allocSizeDst > 0)
ippsFree(pDst);
pDst = ippsMalloc_8u(allocSizeDst = dstLen);
}
fread(pSrc, 1, srcLen, pIn);
ippsDecodeLZO_8u(pSrc, srcLen, pDst, &dstLen);
fwrite(pDst, 1, dstLen, pOut);
}
fclose(pIn);
fclose(pOut);
}
Copyright © 2000 - 2010, Intel Corporation. All rights reserved.