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

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

DCTFwd

Applies a forward discrete cosine transform to an image.

Syntax

IppStatus ippiDCTFwd_<mod> (const Ipp32f* pSrc, int srcStep, Ipp32f* pDst, int dstStep, const IppiDCTFwdSpec_32f* pDCTSpec, Ipp8u* pBuffer);

Supported values for mod:

32f_C1R

32f_C3R

32f_C4R

32f_AC4R

Include Files

ippi.h

Domain Dependencies

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

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

Parameters

pSrc

Pointer to the source image ROI.

srcStep

Distance, in bytes, between the starting points of consecutive lines in the source image.

pDst

Pointer to the destination image ROI.

dstStep

Distance, in bytes, between the starting points of consecutive lines in the destination image.

pDCTSpec

Pointer to the previously initialized forward DCT context structure.

pBuffer

Pointer to the external work buffer.

Description

This function operates with ROI (see Regions of Interest in Intel IPP) of the size that is specified by the ippiDFTInit function.

This function performs a forward DCT on each channel of the source image pSrc and writes the result into the corresponding channel of the destination image buffer pDst. Note that the function flavor with AC4 descriptor does not process alpha channel. This function uses the previously initialized pDCTSpec context structure to set the mode of calculations and retrieve support data.

You can use this function with the external work buffer pBuffer to avoid memory allocation within the functions. Once the work buffer is allocated, it can be used for all following calls to the functions computing DCT. As internal allocation of memory is too expensive operation and depends on operating system and/or runtime libraries used - the use of an external buffer improves performance significantly, especially for the small size transforms.

Before using the forward DCT functions, you need to compute the size of the required buffers and the external work buffer using the ippiDCTFwdGetSize function.

Return Values

ippStsNoErr

Indicates no error. Any other value indicates an error or a warning.

ippStsNullPtrErr

Indicates an error condition if pSrc, pDst, orpDCTSpec pointer is NULL.

ippStsStepErr

Indicates an error condition if srcStep or dstStep value is zero or negative.

ippStsContextMatchErr

Indicates an error condition if a pointer to an invalid pDCTSpec structure is passed.

ippStsMemAllocErr

Indicates an error condition if memory allocation fails.

Example

The code example below demonstrates how to use the ippiDCTFwdGetSize, ippiDCTFwdInit, and ippiDCTFwd functions.

void DCT_example( void )
{
    Ipp32f Src[8*8] = {
        0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0,
        0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0,
        0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0,
        0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0,
        0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0,
        0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0,
        0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0,
        0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0
    };
    Ipp32f Dst[8*8];
    IppiSize roiSize = {8, 8};
    int srcStep;
    int dstStep;

    int sizeSpec;
    int sizeInit;
    int sizeBuffer;

    IppiDCTFwdSpec_32f *pMemSpec;
    Ipp8u *pMemInit = 0;
    Ipp8u *pMemBuffer = 0;

    srcStep = dstStep = 8 * sizeof(Ipp32f);

    /// get sizes for required buffers
    ippiDCTFwdGetSize_32f( roiSize, &sizeSpec, &sizeInit, &sizeBuffer );

    /// allocate memory for required buffers
    pMemSpec = (IppiDCTFwdSpec_32f*) ippMalloc ( sizeSpec );

    if ( sizeInit > 0 )
    {
        pMemInit = (Ipp8u*) ippMalloc ( sizeInit );
    }

    if ( sizeBuffer > 0 )
    {
        pMemBuffer = (Ipp8u*) ippMalloc ( sizeBuffer );
    }

    /// initialize DCT specification structure
    ippiDCTFwdInit_32f( pMemSpec, roiSize, pMemInit );

    /// free initialization buffer
    if ( sizeInit > 0 )
    {
        ippFree( pMemInit );
    }

    /// perform forward DCT
    ippiDCTFwd_32f_C1R( Src, srcStep, Dst, dstStep, pMemSpec, pMemBuffer );

    /// ...

    /// free buffers
    if ( sizeBuffer > 0 )
    {
        ippFree( pMemBuffer );
    }

    ippFree( pMemSpec );
}

Result:

Dst ->	28.0 -18.2  0.0 -1.9  0.0 -0.57   0.0 -0.14
 		 0.0   0.0  0.0  0.0  0.0   0.0   0.0   0.0
 	  0.0   0.0  0.0  0.0  0.0   0.0   0.0   0.0
 		 0.0   0.0  0.0  0.0  0.0   0.0   0.0   0.0
 		 0.0   0.0  0.0  0.0  0.0   0.0   0.0   0.0
 		 0.0   0.0  0.0  0.0  0.0   0.0   0.0   0.0
 		 0.0   0.0  0.0  0.0  0.0   0.0   0.0   0.0
 	  0.0   0.0  0.0  0.0  0.0   0.0   0.0   0.0