VXLIB User Guide
VXLIB_tableLookup_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_tableLookup_priv.h"
41 
42 /**********************************************************************************************************************/
43 /* */
44 /* DEFINES */
45 /* */
46 /**********************************************************************************************************************/
47 
48 /**********************************************************************************************************************/
49 /* */
50 /* VXLIB_tableLookup_set_cn */
51 /* */
52 /**********************************************************************************************************************/
53 
54 template <typename dataType> VXLIB_STATUS VXLIB_tableLookup_set_cn(VXLIB_kernelHandle handle, void *restrict pLut)
55 {
56 
57  VXLIB_STATUS status = VXLIB_SUCCESS; // assign status to success by default
58  // typecast handle (void) to struct pointer type associated to kernel
59 
60  return (status);
61 }
62 
65 
68 
69 /**********************************************************************************************************************/
70 /* */
71 /* VXLIB_tableLookup_exec_cn */
72 /* */
73 /**********************************************************************************************************************/
74 template <typename dataType>
76 VXLIB_tableLookup_exec_cn(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut, void *restrict pLut)
77 {
78 
79  VXLIB_STATUS status = VXLIB_SUCCESS; // assign status to success by default
80 
81 #if VXLIB_DEBUGPRINT
82  printf("Enter VXLIB_tableLookup_exec_cn\n");
83 #endif
84 
85  // typecast handle (void) to struct pointer type associated to kernel
86  VXLIB_tableLookup_PrivArgs *pKerPrivArgs = (VXLIB_tableLookup_PrivArgs *) handle;
87 
88  // obtain image parameters
89  size_t width = pKerPrivArgs->width;
90  size_t height = pKerPrivArgs->height;
91  size_t strideInElements = pKerPrivArgs->strideInElements;
92  size_t strideOutElements = pKerPrivArgs->strideOutElements;
93 
94  uint32_t count = pKerPrivArgs->pKerInitArgs.count;
95  uint16_t offset = pKerPrivArgs->pKerInitArgs.offset;
96 
97  // variables to hold temporary values
98  dataType srcIndex;
99  int32_t lutIndex;
100 
101  // create local pointers
102  dataType *restrict pInLocal = (dataType *) pIn;
103  dataType *restrict pOutLocal = (dataType *) pOut;
104  dataType *restrict lutLocal = (dataType *) pLut;
105 
106 #if VXLIB_DEBUGPRINT
107  printf("In VXLIB_tableLookup_exec_cn, width: %d, height: %d\n", width, height);
108 #endif
109 
110  for (uint32_t i = 0; i < height; i++) {
111  for (uint32_t j = 0; j < width; j++) {
112  srcIndex = pInLocal[i * strideInElements + j];
113  lutIndex = (int32_t) offset + (int32_t) srcIndex;
114  if (lutIndex >= 0 && (uint32_t)lutIndex < count) {
115 
116  pOutLocal[i * strideOutElements + j] = lutLocal[lutIndex];
117  }
118  else {
120  }
121  }
122  }
123 
124  return (status);
125 }
126 
128  void *restrict pIn,
129  void *restrict pOut,
130  void *restrict pLut);
132  void *restrict pIn,
133  void *restrict pOut,
134  void *restrict pLut);
136  void *restrict pIn,
137  void *restrict pOut,
138  void *restrict pLut);
140  void *restrict pIn,
141  void *restrict pOut,
142  void *restrict pLut);
143 /* ======================================================================== */
144 /* End of file: VXLIB_tableLookup_cn.cpp */
145 /* ======================================================================== */
template VXLIB_STATUS VXLIB_tableLookup_exec_cn< uint16_t >(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut, void *restrict pLut)
template VXLIB_STATUS VXLIB_tableLookup_set_cn< int8_t >(VXLIB_kernelHandle handle, void *restrict pLut)
VXLIB_STATUS VXLIB_tableLookup_set_cn(VXLIB_kernelHandle handle, void *restrict pLut)
This function set the lookup table in memory for the natural C implementation of the kernel....
template VXLIB_STATUS VXLIB_tableLookup_exec_cn< int16_t >(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut, void *restrict pLut)
template VXLIB_STATUS VXLIB_tableLookup_set_cn< uint16_t >(VXLIB_kernelHandle handle, void *restrict pLut)
template VXLIB_STATUS VXLIB_tableLookup_exec_cn< int8_t >(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut, void *restrict pLut)
template VXLIB_STATUS VXLIB_tableLookup_exec_cn< uint8_t >(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut, void *restrict pLut)
template VXLIB_STATUS VXLIB_tableLookup_set_cn< int16_t >(VXLIB_kernelHandle handle, void *restrict pLut)
VXLIB_STATUS VXLIB_tableLookup_exec_cn(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut, void *restrict pLut)
This function is the main execution function for the natural C implementation of the kernel....
template VXLIB_STATUS VXLIB_tableLookup_set_cn< uint8_t >(VXLIB_kernelHandle handle, void *restrict pLut)
Header file for kernel's internal use. For the kernel's interface, please see VXLIB_tableLookup.
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_DIMENSION
Definition: VXLIB_types.h:225
@ VXLIB_SUCCESS
Definition: VXLIB_types.h:221
uint32_t count
Parameter indicating size of lookup table
uint16_t offset
Parameter indicating index of input value = 0 in the lookup table
Structure that is reserved for internal use by the kernel.
size_t strideOutElements
Stride of output in elements.
VXLIB_tableLookup_InitArgs pKerInitArgs
Initargs of the kernel.
size_t strideInElements
Stride of input in elements.