/*******************************************************************************
* Copyright 2015-2018 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.
*******************************************************************************/
// A simple example of performing the rotate operation of image around the center point.
// Nearest neighbot interpolation is used
// implemented with Intel(R) Integrated Primitives (Intel(R) IPP) functions:
// ippiGetRotateTransform
// ippiWarpAffineGetSize
// ippiWarpAffineNearestInit
// ippiWarpGetBufferSize
// ippiWarpAffineNearest_8u_C1R
#include <stdio.h>
#include "ipp.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) 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)
{
IppStatus status = ippStsNoErr;
Ipp8u src[4*4] = {4, 4, 4, 4,
3, 3, 3, 3,
2, 2, 2, 2,
1, 1, 1, 1};
Ipp8u dst[6*6];
IppiSize srcSize = { 4, 4 };
IppiSize dstSize = { 6, 6 };
double angle = -45.0;
double xCenter = 1.0;
double yCenter = 4.0;
IppiWarpSpec* pSpec = 0;
double coeffs[2][3];
int specSize = 0, initSize = 0, bufSize = 0;
Ipp8u* pBuffer = 0;
IppiPoint dstOffset = {0, 0};
check_sts( status = ippiSet_8u_C1R ( 0, dst, 6, dstSize ) )
check_sts( status = ippiGetRotateTransform (angle, 0, 0, coeffs) )
coeffs[0][2] = xCenter - coeffs[0][0] * xCenter - coeffs[0][1] * yCenter;
coeffs[1][2] = yCenter - coeffs[1][0] * xCenter - coeffs[1][1] * yCenter;
/* Spec and init buffer sizes */
check_sts( status = ippiWarpAffineGetSize(srcSize, dstSize, ipp8u, coeffs, ippNearest, ippWarpForward, ippBorderTransp, &specSize, &initSize) )
/* Memory allocation */
pSpec = (IppiWarpSpec*)ippsMalloc_8u(specSize);
/* Filter initialization */
check_sts( status = ippiWarpAffineNearestInit(srcSize, dstSize, ipp8u, coeffs, ippWarpForward, 1, ippBorderTransp, NULL, 0, pSpec) )
/* work buffer size */
check_sts( status = ippiWarpGetBufferSize(pSpec, dstSize, &bufSize) )
pBuffer = ippsMalloc_8u(bufSize);
/* Image rotation processing */
check_sts( status = ippiWarpAffineNearest_8u_C1R(src, 4, dst, 6, dstOffset, dstSize, pSpec, pBuffer) )
/* Result:
* 0 0 0 0 0 0
* 0 0 0 4 0 0
* 0 0 2 3 4 0
* 0 0 1 2 3 0 dst
* 0 0 0 1 0 0
* 0 0 0 0 0 0
*/
EXIT_MAIN
ippsFree(pSpec);
ippsFree(pBuffer);
printf("Exit status %d (%s)\n", (int)status, ippGetStatusString(status));
return (int)status;
}