Intel® Integrated Performance Primitives Developer Guide and Reference

ID 790148
Date 11/07/2023
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

EncodeLZSSFlush

Encodes the last few bits in the bitstream and aligns the output data on the byte boundary.

Syntax

IppStatus ippsEncodeLZSSFlush_8u (Ipp8u** ppDst, int* pDstLen, IppLZSSState_8u* pLZSSState);

Include Files

ippdc.h

Domain Dependencies

Headers: ippcore.h, ippvm.h, ipps.h

Libraries: ippcore.lib, ippvm.lib, ipps.lib

Parameters

ppDst

Double pointer to the destination buffer.

pDstLen

Pointer to the length of destination buffer.

pLZSSState

Pointer to the LZSS encoder state structure.

Description

This function encodes the last few bits (remainder) in the bitstream, writes them to ppDst, and aligns the output data on a byte boundary.

Return Values

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.

Example

/*******************************************************************************
* Copyright 2015 Intel Corporation.
*
*
* This software and the related documents are Intel copyrighted materials, and your use of them is governed by
* the express license under which they were provided to you ('License'). Unless the License provides otherwise,
* you may not use, modify, copy, publish, distribute, disclose or transmit this software or the related
* documents without Intel's prior written permission.
* This software and the related documents are provided as is, with no express or implied warranties, other than
* those that are expressly stated in the License.
*******************************************************************************/

// The example below shows how to use the function ippsEncodeLZSS_8u and supporting functions:
//     ippsLZSSGetSize_8u, ippsEncodeLZSSInit_8u
//     ippsEncodeLZSS_8u
//     ippsEncodeLZSSFlush_8u

#include <stdio.h>
#include "ipp.h"

#define INBLOCKSIZE 65536
#define OUTBLOCKSIZE 16384

/* Next two defines are created to simplify code reading and understanding */
#define EXIT_MAIN exitLine:                                  /* Label for Exit */
#define check_sts(st) if((st) != ippStsNoErr) goto exitLine; /* Go to Exit if Intel(R) Integrated Primitives (Intel(R) IPP) function returned status different from ippStsNoErr */

/* Results of ippMalloc() are not validated because Intel(R) IPP functions perform bad arguments check and will return an appropriate status  */


int main(void)
{
   FILE *inFile = NULL, *outFile = NULL;
   Ipp8u *pSrc  = NULL, *pDst    = NULL, *startpSrc = NULL, *startpDst = NULL;
   int srcLen, dstLen = 0;
   int commonDstLen = 0;
   IppLZSSState_8u *pLZSSState = NULL;
   int szState = 0;
   IppStatus status = ippStsNoErr;

   inFile = fopen("EncodeLZSSFlush.c", "rb");
   if ( !inFile )
   {
      printf("\nCan't open input data file ""EncodeLZSSFlush.c"". program terminated.\n");
      goto exitLine;
   }
   outFile = fopen("EncodeLZSSFlush.bin", "wb");
   if ( !outFile ) {
      printf("\nCan't open output data file ""EncodeLZSSFlush.bin"". program terminated.\n");
      goto exitLine;
   }

   /*************************************************************/
   /* 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) );

   check_sts( status = ippsLZSSGetSize_8u( &szState ) )

   pLZSSState = (IppLZSSState_8u*)ippsMalloc_8u( szState );

   check_sts( status = ippsEncodeLZSSInit_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) {
      printf("\nInput data file ""EncodeLZSSFlush.c"" is corrupted. program terminated.\n");
      goto exitLine;
   }
   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 {
          check_sts( status )
      }
   }

   /**************************************************************/
   /*  The call of ippsEncodeLZSSFlush_8u flushes the last few   */
   /*  bits of code to the destination buffer:                   */
   /**************************************************************/
   check_sts( ippsEncodeLZSSFlush_8u(&pDst, &dstLen, pLZSSState) ) 
   fwrite( startpDst, sizeof(Ipp8u), (commonDstLen - dstLen), outFile );
   printf( "\n EncodeLZSSFlush.c successfully encoded to EncodeLZSSFlush.bin \n");

EXIT_MAIN
   ippsFree( pLZSSState );
   ippsFree( startpSrc );
   ippsFree( startpDst );
   if ( inFile ) fclose( inFile );
   if ( outFile ) fclose( outFile );
   printf("Exit status %d (%s)\n", (int)status, ippGetStatusString(status));
   return (int)status;
}