Intel® Integrated Performance Primitives (Intel® IPP) Developer Guide and Reference

ID 790148
Date 3/22/2024
Public
Document Table of Contents

DecodeLZ4

Performs LZ4 decoding.

Syntax

IppStatus ippsDecodeLZ4_8u(const Ipp8u* pSrc, int srcLen, Ipp8u* pDst, int* pDstLen);

IppStatus ippsDecodeLZ4Dict_8u(const Ipp8u* pSrc, int* pSrcLen, Ipp8u* pDst, int dstIdx, int* pDstLen, const Ipp8u* pDict, int dictSize);

Include Files

ippdc.h

Domain Dependencies

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

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

Parameters

pSrc

Pointer to the source data.

srcLen

Length of the source data for decompression.

pSrcLen

Pointer to the length of the source data for decompression.

pDst

Pointer to the compressed data.

pDstLen

Pointer to the length of the uncompressed data.

dstIdx

Index of the starting byte in the destination vector.

pDict

Pointer to the dictionary.

dictSize

Length of the dictionary.

Description

This function performs decoding of the source data pSrc using the LZ4 algorithm. The destination buffer must have sufficient length for the operation. The length of the uncompressed data is set to pDstLen.

Return Values

ippStsNoErr

Indicates no error.

ippStsNullPtrErr

Indicates an error if at lease one of the specified pointers is NULL.

ippStsSizeErr

Indicates an error if the srcLen value is less than, or equal to zero.

ippStsMemAllocErr

Indicates an error if the size of the allocated memory is not sufficient for decompression.

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 functions:
     ippsEncodeLZ4HashTableGetSize_8u
     ippsEncodeLZ4HashTableInit_8u
     ippsEncodeLZ4_8u
     ippsDecodeLZ4_8u
*/

#include <stdio.h>
#include <string.h>

#include <ipp/ippdc.h>
#include <ipp/ipps.h>

/* 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 Performance Primitives (Intel(R) IPP) function returned status different from ippStsNoErr */

#define TEST_SIZE (1024)

int main(void)
{
    Ipp8u       *srcBuf = NULL, *comprBuf = NULL, *decomprBuf = NULL, *hashTable = NULL;
    IppStatus   st = ippStsNoErr;
    int         hashSize = 0, 
                comprLen = TEST_SIZE + TEST_SIZE / 255 + 16,    /* Extra bytes for
                                                                    uncompressible data */
                decomprLen = TEST_SIZE + 33;
    int         i;

    srcBuf      = ippsMalloc_8u(TEST_SIZE);
    decomprBuf  = ippsMalloc_8u(decomprLen);                    /* Spare bytes for "wild"
                                                            (non-safe) decompression */
    comprBuf    = ippsMalloc_8u(comprLen);
    /* Initialize source buffer */
    check_sts(      st = ippsVectorJaehne_8u(srcBuf, TEST_SIZE, IPP_MAX_8U) )
    for(i = 0; i < TEST_SIZE; i++)
        srcBuf[i] >>= 6;                  /* Decrease source data entropy */
    /* Init and allocate hash table */
    check_sts(  st = ippsEncodeLZ4HashTableGetSize_8u(&hashSize)    )
    hashTable   = ippsMalloc_8u(hashSize);
    check_sts(  st = ippsEncodeLZ4HashTableInit_8u(hashTable, TEST_SIZE)    )
    /* Compress source data */
    check_sts(  st = ippsEncodeLZ4_8u((const Ipp8u*)srcBuf, TEST_SIZE, comprBuf,
                                      &comprLen, hashTable) )
    /* Print compression result */
    printf("Compression: %d bytes compressed into %d bytes\n", TEST_SIZE, comprLen);
    /* Decompression */
    decomprLen  = TEST_SIZE + 33;
    check_sts(  st = ippsDecodeLZ4_8u((const Ipp8u*)comprBuf, comprLen, decomprBuf,
                                      &decomprLen)  )
    /* Check */
    if(decomprLen == TEST_SIZE)/* Decompressed size must be equal to source data size */
    {
        if(memcmp(srcBuf, decomprBuf, TEST_SIZE) != 0)
        {
            printf("Wrong decompression!\n");
            st = ippStsErr;
        }
        else
            printf("Decompressed by ippsDecodeLZ4_8u OK\n");
    }
    else
        printf("Invalid decompressed length %d\n", decomprLen);

EXIT_MAIN
    ippsFree(srcBuf);
    ippsFree(comprBuf);
    ippsFree(decomprBuf);
    ippsFree(hashTable);
    return (int)st;
}