Intel® Integrated Performance Primitives
Deliberate problems developing high-performance vision, signal, security, and storage applications.

Using LZSS Compression Functions

Yolanda_Maxwell
Beginner
712 Views

I'm using the example code from Intel® Integrated Performance Primitives Reference Manual, Volume 1: Signal Processing on LZSS Compression. This document indicates that some of the functions have been Deprecated.  Two of the function used in the example are part of these deprecated function.  The first one is [cpp]IppStatus ippsEncodeLZSSInitAlloc_8u (IppLZSSState_8u** ppLZSSState);[/cpp] and the second one is  [cpp]void ippsLZSSFree_8u (IppLZSSState_8u* pLZSSState);[/cpp]  The warning when I use ippsEncodeLZSSInitAlloc() indicates that I should use the GetSize and Init pair to replace this functionality.  But there is no corresponding functions indicated in place of LZSSFree.  My research indicate the reason for these function being deprecated is that Internal memory allocation will not be supported at some point. This indicates to me that I will need to do the memory allocation, but I don't understand how to do this. The above document indicates that function ippsEncodeLZSSInit_8u(),  initializes the LZSS state structure pLZSSState in the external buffer. But I don't see were or how the external buffer is allocated. But when I call ippsLZSSGetSize() it returns a size indicating that the buffer has been allocated.  If it has been allocated, how do I de-allocate it? Or is that being done automatically?  Is there some way to change the size of this buffer?

0 Kudos
9 Replies
Yolanda_Maxwell
Beginner
712 Views
One more thing, when I try to use [cpp]IppStatus ippsEncodeLZSSInit_8u (IppLZSSState_8u* pLZSSState);[/cpp] using variable [cpp] IppLZSSState_8u *pLZSSState;[/cpp] I get the following error: Run-Time Check Failure #3 - The variable 'pLZSSState' is being used without being initialized. How do I initialize pLZSSState?
0 Kudos
Sergey_K_Intel
Employee
712 Views
Hi Yolanda, Regarding your first topic, you are right, IPP is deprecating internal memory allocation. Internal mallocs are not effective, often contradict with application's usage models and so on. So, you need to allocate and free dynamic memory by yourself. If majority of cases, the usage model is the following: 1) call ippGetSise(&size) function to determine the minimum amount of memory IPP functions will need 2) allocate the requested memory using any of OS functions for dynamic memory (malloc, VirtualAlloc, whatever), assigning the obtained address to ippState pointer 3) use other ipp functions providing the above pointer 4) free dynamic memory using proper OS function (free, VirtualFree and so on). Regarding your second topic, did you assign any obtained dynamic address to pLZSSState variable? Regards, Sergey
0 Kudos
Yolanda_Maxwell
Beginner
712 Views
Hello Sergey, Thank you for your response. Just to clarify, I can use any dynamic memory allocation method (ie new) or does it need to be one specific to Intel? In regards to the second question, no. Thank you for your help. Yolanda
0 Kudos
Yolanda_Maxwell
Beginner
712 Views
Hello again Sergey, Next question, on the buffer. What is the data type? Char or Ipp8u or ?? Do you have any examples using and external buffer? It would really help I had some simple examples that didn't use the deprecated functions. Not just for LZSS Compression, but also for the other methods of data compression supported. Yolanda
0 Kudos
Sergey_K_Intel
Employee
712 Views
Yolanda Maxwell wrote:

I can use any dynamic memory allocation method (ie new) or does it need to be one specific to Intel?

Hi Yolanda, You can use any method. There is no Intel-specific memory allocation procedures, only recommendations to use aligned addresses, which come from Intel architecture specifics. IPP's memory management functions are just wrappers around OS' functions (with 32-byte address alignment for better performance). "new" and "delete" operators are also ok. Regards, Sergey
0 Kudos
Sergey_K_Intel
Employee
712 Views
Yolanda Maxwell wrote:

What is the data type? Char or Ipp8u or ?? Do you have any examples using and external buffer? It would really help I had some simple examples that didn't use the deprecated functions. Not just for LZSS Compression, but also for the other methods of data compression supported.

Ipp8u is typedef for "unsigned char". So, they are interchangeable. Regarding deprecated functions, we are working on cleaning the sample source files from deprecated functions for new release. Below is an example of how to initialize LZSS structure for encoding (decoding is the same) without extra status checking and failure returns for simplicity. I am not sure how it will look in this new forum engine, though )) [cpp] IppLZSSState_8u * pLZSSState = NULL; int iLZSSStateSize; st = ippsLZSSGetSize_8u(&iLZSSStateSize); pLZSSState = (IppLZSSState_8u*)ippsMalloc_8u(iLZSSStateSize); st = ippsEncodeLZSSInit_8u(pLZSSState); /* LZSS Encoding, buffer flushing ... */ ippsFree(pLZSSState); [/cpp] On C++ it will be like [cpp] pLZSSState = (IppLZSSState_8u*) new Ipp8u[iLZSSStateSize]; [/cpp] and [cpp] delete [] (Ipp8u*)pLZSSState; [/cpp] Regards, Sergey
0 Kudos
Yolanda_Maxwell
Beginner
712 Views
Hello again Sergey, Thank you for your example code. I'm having problems with the decompression. [cpp]ippsDecodeLZSS_8u( &pSrc, &srcLen, &pDst, &dstLen, pLZSSState);[/cpp] the dstLen is not returning any value other then zero and the srcLen is a very large negative number. The status value returned it [cpp] ippStsSizeErr[/cpp] My code is as follows: [cpp] FILE *inFile; FILE *outFile; char * pInFileName char * pOutFileName Ipp8u *pSrc = NULL; Ipp8u *pDst = NULL; Ipp8u *startpSrc; Ipp8u *startpDst; Ipp8u *buffer ; int srcLen; int dstLen = 0; int pLZSSSize; IppStatus status; IppLZSSState_8u *pLZSSState; startpSrc = ippsMalloc_8u( OUTBLOCKSIZE * sizeof(Ipp8u) ); startpDst = ippsMalloc_8u( INBLOCKSIZE * sizeof(Ipp8u) ); status = ippsLZSSGetSize_8u(&pLZSSSize); buffer = ippsMalloc_8u(pLZSSSize); pLZSSState = (IppLZSSState_8u*)buffer; status = ippsDecodeLZSSInit_8u(pLZSSState); errno_t junk = fopen_s( &inFile, pInFileName,"rb" ) ; junk = fopen_s( &outFile, pOutFileName,"wb" ) ; srcLen = fread( startpSrc, sizeof(Ipp8u), OUTBLOCKSIZE, inFile ); pSrc = startpSrc; pDst = startpDst; for( ; ; ) { status = ippsDecodeLZSS_8u( &pSrc, &srcLen, &pDst, &dstLen, pLZSSState); if( status == ippStsNoErr ) { fwrite(startpDst, sizeof(Ipp8u), (INBLOCKSIZE - dstLen), outFile); pDst = startpDst; dstLen = INBLOCKSIZE; srcLen = fread( startpSrc, sizeof(Ipp8u), OUTBLOCKSIZE, inFile ); pSrc = startpSrc; if(srcLen == 0) break; } else if( status == ippStsDstSizeLessExpected ) { fwrite(startpDst, sizeof(Ipp8u), (INBLOCKSIZE - dstLen), outFile); pDst = startpDst; dstLen = INBLOCKSIZE; } else if(status == ippStsNullPtrErr) { printf("null pointer\n"); break; } else if( status == ippStsSizeErr) { printf("size error\n"); break; } } /* for */ ippsFree(buffer); ippsFree( startpSrc ); ippsFree( startpDst ); fclose(outFile); fclose(inFile); [/cpp] Thank you for you help. Yolanda
0 Kudos
Sergey_K_Intel
Employee
712 Views
Yolanda, Your code must be ok if between lines 38 and 40 you will set "dstLen=INBLOCKSIZE;". This length variable must be initially set up. Or, set it at line 18: int dstLen = INBLOCKSIZE; Regards, Sergey
0 Kudos
Yolanda_Maxwell
Beginner
712 Views
Thank you Sergey.
0 Kudos
Reply