/*
// Copyright 2015 2018 Intel Corporation All Rights Reserved.
//
// The source code, information and material ("Material") contained herein is
// owned by Intel Corporation or its suppliers or licensors, and title
// to such Material remains with Intel Corporation or its suppliers or
// licensors. The Material contains proprietary information of Intel
// or its suppliers and licensors. The Material is protected by worldwide
// copyright laws and treaty provisions. No part of the Material may be used,
// copied, reproduced, modified, published, uploaded, posted, transmitted,
// distributed or disclosed in any way without Intel's prior express written
// permission. No license under any patent, copyright or other intellectual
// property rights in the Material is granted to or conferred upon you,
// either expressly, by implication, inducement, estoppel or otherwise.
// Any license under such intellectual property rights must be express and
// approved by Intel in writing.
//
// Unless otherwise agreed by Intel in writing,
// you may not remove or alter this notice or any other notice embedded in
// Materials by Intel or Intel's suppliers or licensors in any way.
*/
// A simple example of performing full or valid 2-D convolution of two images using a general integer rectangular kernel
// implemented with Intel(R) Integrated Performance Primitives (Intel(R) IPP) functions:
// ippiConvGetBufferSize
// ippiConv_16s_C1R
#include <stdio.h>
#include "ipp.h"
#define WIDTH_DST 128 /* destination image width */
#define HEIGHT_DST 64 /* destination image height */
#define WIDTH_SRC 16 /* source image width */
#define HEIGHT_SRC 16 /* source image height */
/* 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;
Ipp16s* pSrc1 = NULL, *pSrc2 = NULL, *pDst = NULL; /* Pointers to source/destination images */
int srcStep1 = 0, srcStep2 = 0, dstStep = 0; /* Steps, in bytes, through the source/destination images */
IppiSize dstSize = { WIDTH_DST, HEIGHT_DST }; /* Size of destination ROI in pixels */
IppiSize src1Size = { WIDTH_SRC, HEIGHT_SRC }; /* Size of destination ROI in pixels */
IppiSize src2Size = { WIDTH_SRC - 1, HEIGHT_SRC - 1 }; /* Size of destination ROI in pixels */
int divisor = 2; /* The integer value by which the computed result is divided */
Ipp8u *pBuffer = NULL; /* Pointer to the work buffer */
int iTmpBufSize = 0; /* Common work buffer size */
int numChannels = 1;
IppEnum funCfgFull = (IppEnum)(ippAlgAuto | ippiROIFull | ippiNormNone);
pSrc2 = ippiMalloc_16s_C1(src2Size.width, src2Size.height, &srcStep2);
pSrc1 = ippiMalloc_16s_C1(src1Size.width, src1Size.height, &srcStep1);
pDst = ippiMalloc_16s_C1(dstSize.width, dstSize.height, &dstStep);
check_sts( status = ippiConvGetBufferSize(src1Size, src2Size, ipp16s, numChannels, funCfgFull, &iTmpBufSize) )
pBuffer = ippsMalloc_8u(iTmpBufSize);
check_sts( status = ippiConv_16s_C1R(pSrc1, srcStep1, src1Size, pSrc2, srcStep2, src2Size, pDst, dstStep, divisor, funCfgFull, pBuffer) )
EXIT_MAIN
ippsFree(pBuffer);
ippiFree(pSrc1);
ippiFree(pSrc2);
ippiFree(pDst);
printf("Exit status %d (%s)\n", (int)status, ippGetStatusString(status));
return (int)status;
}