Tutorial: Image Blurring and Rotation with Intel® Integrated Performance Primitives

ID 751830
Date 6/30/2025
Public

Rotating an Image Using Intel IPP Warp Functions

Intel® Integrated Performance Primitives (Intel® IPP) enables you to use the ippiWarpAffine<Interpolation> functions to implement rotation of an image using pre-calculated affine coefficients based on rotation parameters (angle, x-, y-shifts ). To obtain affine coefficients for the specified rotation parameters, you can apply the ippiGetRotateTransform function. This function computes the affine coefficients for the transform that rotates an image by the specified angle around (0, 0) and shifts the image by the specified x- and y- shift values.

You can apply the computed bounding box to change the x-, y-shifts of the rotated image to fit the transformed image to the destination Region of Interest (ROI). To compute the bounding box for the affine transform, use the ippiGetAffineBound function.

Before calling the warp affine processing function, you need to:

  • Compute the size of the specification structure for affine warping with the specified interpolation method using the ippiWarpAffineGetSize function
  • Initialize the specification structure using the ippiWarpAffine<Interpolation>Init function
  • Compute the size of the temporary work buffer required for warping using ippiWarpAffineGetSize and pass a pointer to the buffer to the processing function

The following code example demonstrates how to perform image rotation using the Intel IPP affine warping functions:


IppStatus warpAffine(Ipp8u* pSrc, IppiSize srcSize, int srcStep, Ipp8u* pDst, IppiSize dstSize, int dstStep, const double coeffs[2][3])
{
    /* functions status */
    IppStatus status = ippStsNoErr;

    /* number of image channels */
    const Ipp32u numChannels =3;

    /* border value to extend the source image */
    Ipp64f pBorderValue[numChannels];

    /* sizes for WarpAffine data structure, initialization buffer, work buffer */ 
    int specSize = 0, initSize = 0, bufSize = 0; 

    /* pointer to work buffer */ 
    Ipp8u *pBuffer = NULL; 

    /* pointer to WarpAffine data structure */ 
    IppiWarpSpec *pSpec = NULL; 

    /* set offset of the processing destination ROI */ 
    IppiPoint dstOffset = {0, 0}; 

    /* border type for affine transform */ 
    IppiBorderType borderType = ippBorderConst; 

    /* direction of warp affine transform */ 
    IppiWarpDirection direction = ippWarpForward;
 
    /* set border value to extend the source image */ 
    for (int i = 0; i < numChannels; ++i) 
         pBorderValue[i] = 255.0; 

    /* computed buffer sizes for warp affine data structure and initialization buffer */ 
    status = ippiWarpAffineGetSize(srcSize, dstSize, ipp8u, coeffs, ippLinear, direction, borderType, &specSize, &initSize);

    /* allocate memory */
    pSpec = (IppiWarpSpec *)ippsMalloc_8u(specSize);

    /* initialize data for affine transform */ 
    if (status >= ippStsNoErr) 
        status = ippiWarpAffineLinearInit(srcSize, dstSize, ipp8u, coeffs, direction, numChannels, borderType, pBorderValue, 0, pSpec);

    /* get work buffer size */ 
    if (status >= ippStsNoErr)
        status = ippiWarpGetBufferSize(pSpec, dstSize, &bufSize); 

    /* allocate memory for work buffer */ 
    pBuffer = ippsMalloc_8u(bufSize); 

    /* affine transform processing */ 
    if (status >= ippStsNoErr) 
        status = ippiWarpAffineLinear_8u_C3R(pSrc, srcStep, pDst, dstStep, dstOffset, dstSize, pSpec, pBuffer); 

    /* free allocated memory */ 
    ippsFree(pSpec); 
    ippsFree(pBuffer); 

    return status; 
}

For more information on the Intel IPP Warp functions, refer to the Warp Functions with Prior Initialization page of the Intel® Integrated Performance Primitives (Intel® IPP) Developer Guide and Reference.