/******************************************************************************* * Copyright 2015-2021 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. // Nearest neighbot interpolation is used // implemented with Intel(R) Integrated Primitives (Intel(R) IPP) functions: // ippiGetRotateShift // ippiGetRotateTransform // ippiWarpAffineGetSize // ippiWarpAffineNearestInit // ippiWarpGetBufferSize // ippiWarpAffineNearest_8u_C1R #include #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 }; IppiWarpSpec* pSpec = 0; double coeffs[2][3]; int specSize = 0, initSize = 0, bufSize = 0; Ipp8u* pBuffer = 0; IppiPoint dstOffset = {0, 0}; double xShift; double yShift; double xShiftTmp; double yShiftTmp; double xCenterSrc = 2.0; double yCenterSrc = 2.0; double xCenterDst = 3.5; double yCenterDst = 2.5; double angle = 35.0; check_sts( status = ippiGetRotateShift ( xCenterSrc, yCenterSrc, angle, &xShift, &yShift ) ) /* xShift = -0.79 , yShift = 1.51 */ check_sts( status = ippiGetRotateShift ( 1.0, 1.0, angle, &xShiftTmp, &yShiftTmp) ) xShift += xShiftTmp; yShift += yShiftTmp; /* xShift = -1.18, yShift = 2.26 */ xShift += xCenterDst - xCenterSrc; yShift += yCenterDst - yCenterSrc; /* xShift = 0.32, yShift = 2.76 */ check_sts( status = ippiSet_8u_C1R ( 0, dst, 6, dstSize ) ) check_sts( status = ippiGetRotateTransform (angle, xShift, yShift, coeffs) ) /* 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 0 0 0 * 0 0 4 3 0 0 * 0 3 3 2 2 0 dst * 0 0 2 1 0 0 * 0 0 1 0 0 0 */ EXIT_MAIN ippsFree(pSpec); ippsFree(pBuffer); printf("Exit status %d (%s)\n", (int)status, ippGetStatusString(status)); return (int)status; }