VXLIB User Guide
VXLIB_minMaxLoc_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 
40 #include "VXLIB_minMaxLoc_priv.h"
41 
42 /**********************************************************************************************************************/
43 /* */
44 /* VXLIB_minMaxLoc_exec_cn */
45 /* */
46 /**********************************************************************************************************************/
47 
48 // this method computes add in via natural C code
49 template <typename dType>
51  void *restrict pIn,
52  void *restrict pMinVal,
53  void *restrict pMaxVal,
54  void *restrict pMinCount,
55  void *restrict pMaxCount,
56  void *restrict pMinLocCapacity,
57  void *restrict pMaxLocCapacity,
58  void *restrict pMinLoc,
59  void *restrict pMaxLoc,
60  void *restrict pStartX,
61  void *restrict pStartY)
62 {
63  VXLIB_DEBUGPRINTFN(0, "%s\n", "Entering function");
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
68  VXLIB_minMaxLoc_PrivArgs *pKerPrivArgs = (VXLIB_minMaxLoc_PrivArgs *) handle;
69 
70  // create local pointers
71  dType restrict *pInLocal = (dType *) pIn;
72  dType restrict *pMinValLocal = (dType *) pMinVal;
73  dType restrict *pMaxValLocal = (dType *) pMaxVal;
74  uint32_t restrict *pMinCountLocal = (uint32_t *) pMinCount;
75  uint32_t restrict *pMaxCountLocal = (uint32_t *) pMaxCount;
76  uint32_t restrict *pMinLocLocal = (uint32_t *) pMinLoc;
77  uint32_t restrict *pMaxLocLocal = (uint32_t *) pMaxLoc;
78  uint32_t restrict *pStartXLocal = (uint32_t *) pStartX;
79  uint32_t restrict *pStartYLocal = (uint32_t *) pStartY;
80  uint32_t restrict *minLocCapacity = (uint32_t *) pMinLocCapacity;
81  uint32_t restrict *maxLocCapacity = (uint32_t *) pMaxLocCapacity;
82 
83  // printf("NAT maxLocCapacity: %u\n", *maxLocCapacity);
84 
85  // obtain dimensional parameters
86  uint32_t width = pKerPrivArgs->width;
87  uint32_t height = pKerPrivArgs->height;
88  uint32_t strideInElements = pKerPrivArgs->strideInElements;
89  uint32_t x, y, srcIndex;
90  {
91  dType min = *pMinValLocal;
92  dType max = *pMaxValLocal;
93  uint32_t mincnt = 0;
94  uint32_t maxcnt = 0;
95  if (pMinCountLocal) {
96  mincnt = *pMinCountLocal;
97  }
98  if (pMaxCountLocal) {
99  maxcnt = *pMaxCountLocal;
100  }
101 
102  for (y = 0; y < height; y++) {
103 
104  for (x = 0; x < width; x++) {
105 
106  srcIndex = (y * strideInElements) + x;
107 
108  if (pInLocal[srcIndex] > max) {
109  max = pInLocal[srcIndex];
110  maxcnt = 1;
111  if (pMaxLocLocal) {
112  pMaxLocLocal[0] = x + (*pStartXLocal);
113  pMaxLocLocal[1] = y + (*pStartYLocal);
114  }
115  }
116  else if (pInLocal[srcIndex] == max) {
117  if (pMaxLocLocal && maxcnt < *maxLocCapacity) {
118  pMaxLocLocal[2 * maxcnt] = x + (*pStartXLocal);
119  pMaxLocLocal[(2 * maxcnt) + 1] = y + (*pStartYLocal);
120  }
121  ++maxcnt;
122  }
123  else {
124  /* Do nothing */
125  }
126 
127  if (pInLocal[srcIndex] < min) {
128  min = pInLocal[srcIndex];
129  mincnt = 1;
130  if (pMinLocLocal) {
131  pMinLocLocal[0] = x + (*pStartXLocal);
132  pMinLocLocal[1] = y + (*pStartYLocal);
133  }
134  }
135  else if (pInLocal[srcIndex] == min) {
136  if (pMinLocLocal && mincnt < *minLocCapacity) {
137  pMinLocLocal[2 * mincnt] = x + (*pStartXLocal);
138  pMinLocLocal[2 * mincnt + 1] = y + (*pStartYLocal);
139  }
140  ++mincnt;
141  }
142  else {
143  /* Do nothing */
144  }
145  }
146  }
147 
148  *pMinValLocal = min;
149  *pMaxValLocal = max;
150  if (pMinCountLocal) {
151  *pMinCountLocal = mincnt;
152  }
153  if (pMaxCountLocal) {
154  *pMaxCountLocal = maxcnt;
155  }
156  }
157 
158  return (status);
159 }
160 
161 /**********************************************************************************************************************/
162 /* */
163 /* Explicit instantiation for the different data type versions */
164 /* */
165 /**********************************************************************************************************************/
166 
168  void *restrict pIn,
169  void *restrict pMinVal,
170  void *restrict pMaxVal,
171  void *restrict pMinCount,
172  void *restrict pMaxCount,
173  void *restrict pMinLocCapacity,
174  void *restrict pMaxLocCapacity,
175  void *restrict pMinLoc,
176  void *restrict pMaxLoc,
177  void *restrict pStartX,
178  void *restrict pStartY);
179 
181  void *restrict pIn,
182  void *restrict pMinVal,
183  void *restrict pMaxVal,
184  void *restrict pMinCount,
185  void *restrict pMaxCount,
186  void *restrict pMinLocCapacity,
187  void *restrict pMaxLocCapacity,
188  void *restrict pMinLoc,
189  void *restrict pMaxLoc,
190  void *restrict pStartX,
191  void *restrict pStartY);
192 
194  void *restrict pIn,
195  void *restrict pMinVal,
196  void *restrict pMaxVal,
197  void *restrict pMinCount,
198  void *restrict pMaxCount,
199  void *restrict pMinLocCapacity,
200  void *restrict pMaxLocCapacity,
201  void *restrict pMinLoc,
202  void *restrict pMaxLoc,
203  void *restrict pStartX,
204  void *restrict pStartY);
205 
207  void *restrict pIn,
208  void *restrict pMinVal,
209  void *restrict pMaxVal,
210  void *restrict pMinCount,
211  void *restrict pMaxCount,
212  void *restrict pMinLocCapacity,
213  void *restrict pMaxLocCapacity,
214  void *restrict pMinLoc,
215  void *restrict pMaxLoc,
216  void *restrict pStartX,
217  void *restrict pStartY);
218 /* ======================================================================== */
219 /* End of file: VXLIB_minMaxLoc_cn.cpp */
220 /* ======================================================================== */
VXLIB_STATUS VXLIB_minMaxLoc_exec_cn(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pMinVal, void *restrict pMaxVal, void *restrict pMinCount, void *restrict pMaxCount, void *restrict pMinLocCapacity, void *restrict pMaxLocCapacity, void *restrict pMinLoc, void *restrict pMaxLoc, void *restrict pStartX, void *restrict pStartY)
This function is the main execution function for the natural C implementation of the kernel....
template VXLIB_STATUS VXLIB_minMaxLoc_exec_cn< VXLIB_MINMAXLOC_TYPENAME_8U >(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pMinVal, void *restrict pMaxVal, void *restrict pMinCount, void *restrict pMaxCount, void *restrict pMinLocCapacity, void *restrict pMaxLocCapacity, void *restrict pMinLoc, void *restrict pMaxLoc, void *restrict pStartX, void *restrict pStartY)
template VXLIB_STATUS VXLIB_minMaxLoc_exec_cn< VXLIB_MINMAXLOC_TYPENAME_16U >(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pMinVal, void *restrict pMaxVal, void *restrict pMinCount, void *restrict pMaxCount, void *restrict pMinLocCapacity, void *restrict pMaxLocCapacity, void *restrict pMinLoc, void *restrict pMaxLoc, void *restrict pStartX, void *restrict pStartY)
template VXLIB_STATUS VXLIB_minMaxLoc_exec_cn< VXLIB_MINMAXLOC_TYPENAME_16S >(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pMinVal, void *restrict pMaxVal, void *restrict pMinCount, void *restrict pMaxCount, void *restrict pMinLocCapacity, void *restrict pMaxLocCapacity, void *restrict pMinLoc, void *restrict pMaxLoc, void *restrict pStartX, void *restrict pStartY)
template VXLIB_STATUS VXLIB_minMaxLoc_exec_cn< VXLIB_MINMAXLOC_TYPENAME_8S >(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pMinVal, void *restrict pMaxVal, void *restrict pMinCount, void *restrict pMaxCount, void *restrict pMinLocCapacity, void *restrict pMaxLocCapacity, void *restrict pMinLoc, void *restrict pMaxLoc, void *restrict pStartX, void *restrict pStartY)
Header file for kernel's internal use. For the kernel's interface, please see VXLIB_minMaxLoc.
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
#define VXLIB_DEBUGPRINTFN(N, fmt,...)
Definition: VXLIB_types.h:94
Structure that is reserved for internal use by the kernel.
uint32_t strideInElements
Stride of input0 in elements.
uint32_t height
Height of image
uint32_t width
Width of image