VXLIB User Guide
VXLIB_absDiff_cn.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright (C) 2023 Texas Instruments Incorporated - https://www.ti.com/
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the
14  * distribution.
15  *
16  * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  ******************************************************************************/
33 
34 #include "VXLIB_absDiff_priv.h"
35 #include <cstdint>
36 
37 template <typename dataType> inline dataType VXLIB_absDiff_calc_cn(dataType A, dataType B);
38 
39 template <> inline uint8_t VXLIB_absDiff_calc_cn<uint8_t>(uint8_t A, uint8_t B)
40 {
41  int16_t diff = (int16_t) A - (int16_t) B;
42  uint8_t out = (diff < 0) ? -diff : diff;
43  return out;
44 }
45 
46 template <> inline int16_t VXLIB_absDiff_calc_cn<int16_t>(int16_t A, int16_t B)
47 {
48  int32_t diff = A - B;
49 
50  diff = (diff < 0) ? -diff : diff;
51  int16_t out = (diff > INT16_MAX) ? INT16_MAX : diff;
52 
53  return out;
54 }
55 
56 template <typename dataType>
58 VXLIB_absDiff_exec_cn(VXLIB_kernelHandle handle, void *restrict pIn0, void *restrict pIn1, void *restrict pOut)
59 {
60  VXLIB_STATUS status = VXLIB_SUCCESS;
61 
62  VXLIB_absDiff_PrivArgs *pKerPrivArgs = (VXLIB_absDiff_PrivArgs *) handle;
63 
64  int32_t m = 0;
65  int32_t n = 0;
66 
67  int32_t height = pKerPrivArgs->height;
68  int32_t width = pKerPrivArgs->width;
69  int32_t strideIn0 = pKerPrivArgs->strideIn0Elements;
70  int32_t strideIn1 = pKerPrivArgs->strideIn1Elements;
71  int32_t strideOut = pKerPrivArgs->strideOutElements;
72 
73 #if VXLIB_DEBUGPRINT
74  printf("Enter VXLIB_absDiff_exec_cn\n");
75 #endif
76 
77 #if VXLIB_DEBUGPRINT
78  printf("VXLIB_absDiff_exec_cn: height = %d, width = %d\n", height, width);
79 #endif
80 
81  const dataType *restrict A = (const dataType *) pIn0;
82  const dataType *restrict B = (const dataType *) pIn1;
83  dataType *restrict C = (dataType *) pOut;
84 
85  for (m = 0; m < height; m++) {
86  for (n = 0; n < width; n++) {
87  C[n + m * strideOut] = VXLIB_absDiff_calc_cn(A[n + m * strideIn0], B[n + m * strideIn1]);
88  }
89  }
90 
91  return (status);
92 }
93 
95  void *restrict pIn0,
96  void *restrict pIn1,
97  void *restrict pOut);
98 
100  void *restrict pIn0,
101  void *restrict pIn1,
102  void *restrict pOut);
VXLIB_STATUS VXLIB_absDiff_exec_cn(VXLIB_kernelHandle handle, void *restrict pIn0, void *restrict pIn1, void *restrict pOut)
This function is the main execution function for the natural C implementation of the kernel....
dataType VXLIB_absDiff_calc_cn(dataType A, dataType B)
int16_t VXLIB_absDiff_calc_cn< int16_t >(int16_t A, int16_t B)
template VXLIB_STATUS VXLIB_absDiff_exec_cn< int16_t >(VXLIB_kernelHandle handle, void *restrict pIn0, void *restrict pIn1, void *restrict pOut)
uint8_t VXLIB_absDiff_calc_cn< uint8_t >(uint8_t A, uint8_t B)
template VXLIB_STATUS VXLIB_absDiff_exec_cn< uint8_t >(VXLIB_kernelHandle handle, void *restrict pIn0, void *restrict pIn1, void *restrict pOut)
Header file for kernel's internal use. For the kernel's interface, please see VXLIB_absDiff.
void * VXLIB_kernelHandle
Handle type for VXLIB operations.
Definition: VXLIB_types.h:247
VXLIB_STATUS_NAME
The enumeration of all status codes.
Definition: VXLIB_types.h:220
@ VXLIB_SUCCESS
Definition: VXLIB_types.h:221
Structure that is reserved for internal use by the kernel.
uint32_t height
Height of image
uint32_t strideIn1Elements
Stride of input1 in elements.
uint32_t strideIn0Elements
Stride of input0 in elements.
uint32_t width
Width of image
uint32_t strideOutElements
Stride of output in elements.