VXLIB User Guide
VXLIB_thresholdRange_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 /**********************************************************************************************************************/
35 /* */
36 /* INCLUDES */
37 /* */
38 /**********************************************************************************************************************/
39 
41 
42 /**********************************************************************************************************************/
43 /* */
44 /* DEFINES */
45 /* */
46 /**********************************************************************************************************************/
47 
48 /**********************************************************************************************************************/
49 /* */
50 /* VXLIB_thresholdRange_exec_cn */
51 /* */
52 /**********************************************************************************************************************/
53 
54 // this method computes add in via natural C code
55 template <typename dTypeIn, typename dTypeOut>
57  void *restrict pIn,
58  void *restrict pOut,
59  void *restrict pUpperVal,
60  void *restrict pLowerVal,
61  void *restrict pTrueVal,
62  void *restrict pFalseVal)
63 {
64 
65  VXLIB_STATUS status = VXLIB_SUCCESS; // assign status to success by default
66 
67  // typecast handle (void) to struct pointer type associated to kernel
69 
70  // obtain image parameters and overflow policy
71  size_t width = pKerPrivArgs->width;
72  size_t height = pKerPrivArgs->height;
73  size_t strideInElements = pKerPrivArgs->strideInElements;
74  size_t strideOutElements = pKerPrivArgs->strideOutElements;
75 
76 #if VXLIB_DEBUGPRINT
77  printf("Enter VXLIB_thresholdRange_exec_cn\n");
78 #endif
79 
80  // create local pointers
81  dTypeIn *restrict pInLocal = (dTypeIn *) pIn;
82  dTypeOut *restrict pOutLocal = (dTypeOut *) pOut;
83  // create local pointers
84  dTypeIn *restrict pUpperValLocal = (dTypeIn *) pUpperVal;
85  dTypeIn *restrict pLowerValLocal = (dTypeIn *) pLowerVal;
86  dTypeIn *restrict pTrueValLocal = (dTypeIn *) pTrueVal;
87  dTypeIn *restrict pFalseValLocal = (dTypeIn *) pFalseVal;
88  // variables to hold temporary values
89 
90 #if VXLIB_DEBUGPRINT
91  printf("In VXLIB_thresholdRange_exec_cn, width: %d, height: %d\n", width, height);
92 #endif
93 
94  if (*pLowerValLocal > *pUpperValLocal) {
95  status = VXLIB_ERR_INVALID_VALUE;
96  }
97  else {
98 
99  for (uint32_t i = 0; i < height; i++) {
100  for (uint32_t j = 0; j < width; j++) {
101  if (pInLocal[i * strideInElements + j] > *pUpperValLocal) {
102  pOutLocal[i * strideOutElements + j] = *pFalseValLocal;
103  }
104  else if (pInLocal[i * strideInElements + j] < *pLowerValLocal) {
105  pOutLocal[i * strideOutElements + j] = *pFalseValLocal;
106  }
107  else {
108  pOutLocal[i * strideOutElements + j] = *pTrueValLocal;
109  }
110  }
111  }
112 #if VXLIB_DEBUGPRINT
113  if (i == 0 && j < 7)
114  printf("row: %d col: %d a %d b %d temp %d \n", i, j, a, b, temp);
115 #endif
116  }
117 
118  return (status);
119 }
120 
121 /**********************************************************************************************************************/
122 /* */
123 /* Explicit instantiation for the different data type versions */
124 /* */
125 /**********************************************************************************************************************/
126 
128  void *restrict pIn,
129  void *restrict pOut,
130  void *restrict pUpperVal,
131  void *restrict pLowerVal,
132  void *restrict pTrueVal,
133  void *restrict pFalseVal);
134 
136  void *restrict pIn,
137  void *restrict pOut,
138  void *restrict pUpperVal,
139  void *restrict pLowerVal,
140  void *restrict pTrueVal,
141  void *restrict pFalseVal);
142 
144  void *restrict pIn,
145  void *restrict pOut,
146  void *restrict pUpperVal,
147  void *restrict pLowerVal,
148  void *restrict pTrueVal,
149  void *restrict pFalseVal);
150 
152  void *restrict pIn,
153  void *restrict pOut,
154  void *restrict pUpperVal,
155  void *restrict pLowerVal,
156  void *restrict pTrueVal,
157  void *restrict pFalseVal);
158 /* ======================================================================== */
159 /* End of file: VXLIB_thresholdRange_cn.cpp */
160 /* ======================================================================== */
template VXLIB_STATUS VXLIB_thresholdRange_exec_cn< VXLIB_THRESHOLDRANGE_TYPENAME_I8U_O8U >(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut, void *restrict pUpperVal, void *restrict pLowerVal, void *restrict pTrueVal, void *restrict pFalseVal)
template VXLIB_STATUS VXLIB_thresholdRange_exec_cn< VXLIB_THRESHOLDRANGE_TYPENAME_I16S_O16S >(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut, void *restrict pUpperVal, void *restrict pLowerVal, void *restrict pTrueVal, void *restrict pFalseVal)
template VXLIB_STATUS VXLIB_thresholdRange_exec_cn< VXLIB_THRESHOLDRANGE_TYPENAME_I8S_O8S >(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut, void *restrict pUpperVal, void *restrict pLowerVal, void *restrict pTrueVal, void *restrict pFalseVal)
VXLIB_STATUS VXLIB_thresholdRange_exec_cn(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut, void *restrict pUpperVal, void *restrict pLowerVal, void *restrict pTrueVal, void *restrict pFalseVal)
This function is the main execution function for the natural C implementation of the kernel....
template VXLIB_STATUS VXLIB_thresholdRange_exec_cn< VXLIB_THRESHOLDRANGE_TYPENAME_I16U_O16U >(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut, void *restrict pUpperVal, void *restrict pLowerVal, void *restrict pTrueVal, void *restrict pFalseVal)
Header file for kernel's internal use. For the kernel's interface, please see VXLIB_thresholdRange.
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_ERR_INVALID_VALUE
Definition: VXLIB_types.h:223
@ VXLIB_SUCCESS
Definition: VXLIB_types.h:221
Structure that is reserved for internal use by the kernel.
size_t strideOutElements
Stride of output in elements.
size_t strideInElements
Stride of input in elements.