VXLIB User Guide
VXLIB_halfScaleGaussian_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 #define VXLIB_HALF_SCALE_GAUSSIAN_NUMERIC_MIN(x) std::numeric_limits<x>::min()
49 #define VXLIB_HALF_SCALE_GAUSSIAN_NUMERIC_MAX(x) std::numeric_limits<x>::max()
50 
51 /**********************************************************************************************************************/
52 /* */
53 /* VXLIB_halfScaleGaussian_exec_cn */
54 /* */
55 /**********************************************************************************************************************/
56 // this method computes 5x5 half scale gaussian filter in via natural C code
57 template <typename dTypeIn, typename dTypeOut>
58 VXLIB_STATUS VXLIB_halfScaleGaussian_exec_cn(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
59 {
60 
61  VXLIB_STATUS status = VXLIB_SUCCESS; // assign status to success by default
62 
63 #if VXLIB_DEBUGPRINT
64  printf("Enter VXLIB_halfScaleGaussian_exec_cn\n");
65 #endif
66 
67  // typecast handle (void) to struct pointer type associated to kernel
69 
70  // obtain image parameters
71  size_t widthOut = pKerPrivArgs->widthOut;
72  size_t heightOut = pKerPrivArgs->heightOut;
73  size_t strideInElements = pKerPrivArgs->strideInElements;
74  size_t strideOutElements = pKerPrivArgs->strideOutElements;
75 
76  size_t padLeft = pKerPrivArgs->pKerInitArgs.padLeft;
77  size_t padRight = pKerPrivArgs->pKerInitArgs.padRight;
78  size_t padTop = pKerPrivArgs->pKerInitArgs.padTop;
79  size_t padBottom = pKerPrivArgs->pKerInitArgs.padBottom;
80  bool isNotPadded = (padLeft == 0) && (padRight == 0) && (padTop == 0) && (padBottom == 0);
81 
82  size_t filterDim = pKerPrivArgs->pKerInitArgs.filterSize;
83 
84  // create local pointers
85  dTypeIn *restrict pInLocal = (dTypeIn *) pIn;
86  dTypeOut *restrict pOutLocal = (dTypeOut *) pOut;
87 
88 #if VXLIB_DEBUGPRINT
89  printf("In VXLIB_halfScaleGaussian_exec_cn, width: %d, height: %d\n", width, height);
90 #endif
91 
92  // 5x5 implementation
93  if (filterDim == VXLIB_HALF_SCALE_GAUSSIAN_FILTER_5x5) {
94  // non-padded natc implementation
95  if (isNotPadded) {
96 
97  int32_t x, y, i, j;
98  int32_t sum;
99 
100  int16_t gaussianFilter5x5[5][5] = {
101  {1, 4, 6, 4, 1}, {4, 16, 24, 16, 4}, {6, 24, 36, 24, 6}, {4, 16, 24, 16, 4}, {1, 4, 6, 4, 1}};
102 
103  for (y = 0; y < heightOut; y++) {
104  for (x = 0; x < widthOut; x++) {
105 
106  sum = 0;
107 
108  for (j = 0; j < filterDim; j++) {
109  for (i = 0; i < filterDim; i++) {
110  sum += (pInLocal[((y * 2) + j) * strideInElements + ((x * 2) + i)]) * gaussianFilter5x5[j][i];
111  }
112  }
113  pOutLocal[y * strideOutElements + x] = (dTypeOut)((uint64_t)sum >> 8LLU);
114  }
115  }
116  }
117  // padded natc implementation
118  else {
119  status = VXLIB_ERR_NOT_IMPLEMENTED;
120  }
121  }
122  // other filter dimensions
123  else {
124  status = VXLIB_ERR_NOT_IMPLEMENTED;
125  }
126 
127  return (status);
128 }
129 
130 /**********************************************************************************************************************/
131 /* */
132 /* Explicit instantiation for the different data type versions */
133 /* */
134 /**********************************************************************************************************************/
135 
136 template VXLIB_STATUS
138  void *restrict pIn,
139  void *restrict pOut);
VXLIB_STATUS VXLIB_halfScaleGaussian_exec_cn(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
This function is the main execution function for the natural C implementation of the kernel....
template VXLIB_STATUS VXLIB_halfScaleGaussian_exec_cn< VXLIB_HALF_SCALE_GAUSSIAN_TYPENAME_I8U_O8U >(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
Header file for kernel's internal use. For the kernel's interface, please see VXLIB_halfScaleGaussian...
#define VXLIB_HALF_SCALE_GAUSSIAN_FILTER_5x5
Macros for 5x5 filter dimension.
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_NOT_IMPLEMENTED
Definition: VXLIB_types.h:227
@ VXLIB_SUCCESS
Definition: VXLIB_types.h:221
int8_t filterSize
Width and height of filter
Structure that is reserved for internal use by the kernel.
VXLIB_halfScaleGaussian_InitArgs pKerInitArgs
Initargs of the kernel.
size_t strideInElements
Stride of input in elements.
size_t strideOutElements
Stride of output in elements.