/*******************************************************************************
* 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 calculating distance between pixels 
// using Intel(R) Integrated Primitives (Intel(R) IPP) function:
//     ippiDistanceTransform_3x3_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 */

int main(void)
{
    IppStatus status = ippStsNoErr;
    Ipp8u pSrc[7 * 7] = {     /* Pointer to source image */
        1, 2, 3, 4, 5, 6, 7,
        1, 0, 3, 4, 5, 6, 7,
        1, 2, 3, 4, 5, 6, 7,
        1, 2, 3, 0, 5, 6, 7,
        1, 2, 3, 4, 5, 6, 7,
        1, 2, 3, 4, 5, 0, 7,
        1, 2, 3, 4, 5, 6, 7
    };
    Ipp8u pDst[7 * 7];             /* Pointer to destination image */
    int srcStep = 7, dstStep = 7;  /* Steps, in bytes, through the source/destination images */
    IppiSize roiSize   = { 7, 7 }; /* Size of source/destination ROI in pixels */
    Ipp32s pMetrics[2] = { 2, 2 }; /* Array that determines metrics used */
    /* For every non-zero pixel in the source image, the functions calculate   */
    /*                     distance between that pixel and nearest zero pixel. */
    check_sts( status = ippiDistanceTransform_3x3_8u_C1R(pSrc, srcStep, pDst, dstStep, roiSize, pMetrics) )

EXIT_MAIN
    printf("Exit status %d (%s)\n", (int)status, ippGetStatusString(status));
    return (int)status;
}