VXLIB User Guide
VXLIB_histogram_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_histogram_priv.h"
41 
42 /**********************************************************************************************************************/
43 /* */
44 /* DEFINES */
45 /* */
46 /**********************************************************************************************************************/
47 
48 #define VXLIB_HISTOGRAM_NUMERIC_MIN(x) std::numeric_limits<x>::min()
49 #define VXLIB_HISTOGRAM_NUMERIC_MAX(x) std::numeric_limits<x>::max()
50 
51 /**********************************************************************************************************************/
52 /* */
53 /* VXLIB_histogram_exec_cn */
54 /* */
55 /**********************************************************************************************************************/
56 // this method computes histogram in via natural C code
57 template <typename dTypeIn, typename dTypeOut>
58 VXLIB_STATUS VXLIB_histogram_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  // typecast handle (void) to struct pointer type associated to kernel
64  VXLIB_histogram_PrivArgs *pKerPrivArgs = (VXLIB_histogram_PrivArgs *) handle;
65 
66  // obtain image parameters and overflow policy
67  size_t width = pKerPrivArgs->width;
68  size_t height = pKerPrivArgs->height;
69  size_t strideInElements = pKerPrivArgs->strideInElements;
70  uint8_t offset = pKerPrivArgs->pKerInitArgs.offset;
71  uint16_t range = pKerPrivArgs->pKerInitArgs.range;
72  uint16_t numBins = pKerPrivArgs->pKerInitArgs.numBins;
73 
74 #if VXLIB_DEBUGPRINT
75  printf("Enter VXLIB_histogram_exec_cn\n");
76 #endif
77 
78  // create local pointers
79  dTypeIn *restrict pInLocal = (dTypeIn *) pIn;
80  dTypeOut *restrict pOutLocal = (dTypeOut *) pOut;
81 
82 #if VXLIB_DEBUGPRINT
83  printf("In VXLIB_histogram_exec_cn, width: %d, height: %d\n", width, height);
84 #endif
85  int x, y;
86  for (x = 0; x < numBins; x++) {
87  pOutLocal[x] = 0;
88  }
89 
90  for (y = 0; y < height; y++) {
91 
92  for (x = 0; x < width; x++) {
93 
94  uint8_t pixel = pInLocal[y * strideInElements + x];
95  if ((offset <= (size_t) pixel) && ((size_t) pixel < (offset + range))) {
96  size_t index = (pixel - (uint16_t) offset) * numBins / range;
97  pOutLocal[index]++;
98  }
99  }
100  }
101 
102  return (status);
103 }
104 
105 /**********************************************************************************************************************/
106 /* */
107 /* Explicit instantiation for the different data type versions */
108 /* */
109 /**********************************************************************************************************************/
110 
112  void *restrict pIn,
113  void *restrict pOut);
template VXLIB_STATUS VXLIB_histogram_exec_cn< VXLIB_HISTOGRAM_TYPENAME_I8U_O32U >(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
VXLIB_STATUS VXLIB_histogram_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....
Header file for kernel's internal use. For the kernel's interface, please see VXLIB_histogram.
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
uint16_t numBins
Parameter indicating distribution number of bins (<= 256)
uint8_t offset
Parameter indicating distribution offset.
uint16_t range
Parameter indicating distribution range (<= 256)
Structure that is reserved for internal use by the kernel.
VXLIB_histogram_InitArgs pKerInitArgs
Initargs of the kernel.
size_t height
Height of image
size_t strideInElements
Stride of input0 in elements.
size_t width
Width of image