VXLIB User Guide
VXLIB_thresholdBinary_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_thresholdBinary_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 pThresholdVal,
60  void *restrict pTrueVal,
61  void *restrict pFalseVal)
62 {
63 
64  VXLIB_STATUS status = VXLIB_SUCCESS; // assign status to success by default
65 
66  // typecast handle (void) to struct pointer type associated to kernel
68 
69  // obtain image parameters and overflow policy
70  size_t width = pKerPrivArgs->width;
71  size_t height = pKerPrivArgs->height;
72  size_t strideInElements = pKerPrivArgs->strideInElements;
73  size_t strideOutElements = pKerPrivArgs->strideOutElements;
74 
75 #if VXLIB_DEBUGPRINT
76  printf("Enter VXLIB_thresholdBinary_exec_cn\n");
77 #endif
78 
79  // create local pointers
80  dTypeIn *restrict pInLocal = (dTypeIn *) pIn;
81  dTypeOut *restrict pOutLocal = (dTypeOut *) pOut;
82  // create local pointers
83  dTypeIn *restrict pThresholdLocal = (dTypeIn *) pThresholdVal;
84  dTypeIn *restrict pTrueValLocal = (dTypeIn *) pTrueVal;
85  dTypeIn *restrict pFalseValLocal = (dTypeIn *) pFalseVal;
86 
87 #if VXLIB_DEBUGPRINT
88  printf("In VXLIB_thresholdBinary_exec_cn, width: %d, height: %d\n", width, height);
89 #endif
90 
91  for (uint32_t i = 0; i < height; i++) {
92  for (uint32_t j = 0; j < width; j++) {
93  if (pInLocal[i * strideInElements + j] > *pThresholdLocal) {
94  pOutLocal[i * strideOutElements + j] = *pTrueValLocal;
95  }
96  else {
97  pOutLocal[i * strideOutElements + j] = *pFalseValLocal;
98  }
99  }
100  }
101 #if VXLIB_DEBUGPRINT
102  if (i == 0 && j < 7)
103  printf("row: %d col: %d a %d b %d temp %d \n", i, j, a, b, temp);
104 #endif
105 
106  return (status);
107 }
108 
109 /**********************************************************************************************************************/
110 /* */
111 /* Explicit instantiation for the different data type versions */
112 /* */
113 /**********************************************************************************************************************/
114 
115 template VXLIB_STATUS
117  void *restrict pIn,
118  void *restrict pOut,
119  void *restrict pThresholdVal,
120  void *restrict pTrueVal,
121  void *restrict pFalseVal);
122 
123 template VXLIB_STATUS
125  void *restrict pIn,
126  void *restrict pOut,
127  void *restrict pThresholdVal,
128  void *restrict pTrueVal,
129  void *restrict pFalseVal);
130 
131 template VXLIB_STATUS
133  void *restrict pIn,
134  void *restrict pOut,
135  void *restrict pThresholdVal,
136  void *restrict pTrueVal,
137  void *restrict pFalseVal);
138 
139 template VXLIB_STATUS
141  void *restrict pIn,
142  void *restrict pOut,
143  void *restrict pThresholdVal,
144  void *restrict pTrueVal,
145  void *restrict pFalseVal);
146 
147 /* ======================================================================== */
148 /* End of file: VXLIB_thresholdBinary_cn.cpp */
149 /* ======================================================================== */
template VXLIB_STATUS VXLIB_thresholdBinary_exec_cn< VXLIB_THRESHOLDBINARY_TYPENAME_I8S_O8S >(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut, void *restrict pThresholdVal, void *restrict pTrueVal, void *restrict pFalseVal)
template VXLIB_STATUS VXLIB_thresholdBinary_exec_cn< VXLIB_THRESHOLDBINARY_TYPENAME_I16U_O16U >(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut, void *restrict pThresholdVal, void *restrict pTrueVal, void *restrict pFalseVal)
template VXLIB_STATUS VXLIB_thresholdBinary_exec_cn< VXLIB_THRESHOLDBINARY_TYPENAME_I16S_O16S >(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut, void *restrict pThresholdVal, void *restrict pTrueVal, void *restrict pFalseVal)
VXLIB_STATUS VXLIB_thresholdBinary_exec_cn(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut, void *restrict pThresholdVal, 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_thresholdBinary_exec_cn< VXLIB_THRESHOLDBINARY_TYPENAME_I8U_O8U >(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut, void *restrict pThresholdVal, void *restrict pTrueVal, void *restrict pFalseVal)
Header file for kernel's internal use. For the kernel's interface, please see VXLIB_thresholdBinary.
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.
size_t strideInElements
Stride of input in elements.
size_t strideOutElements
Stride of output in elements.