VXLIB User Guide
VXLIB_debugPrintMatrix3D.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright (C) 2015 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_bufParams.h"
41 #include "../VXLIB_types.h"
42 #include "../VXLIB_utility.h"
43 
44 template <typename dataType> void VXLIB_debugPrintMatrix3D_helper(dataType *matrix, const VXLIB_bufParams3D_t *params)
45 {
46  uint32_t x, y, z;
47  dataType *xPtr;
48  dataType *yPtr;
49  dataType *zPtr = matrix;
50 
51  // stride_y is stored in bytes, but easier to use in elements
52  uint32_t stride_y_elements = params->stride_y / VXLIB_sizeof(params->data_type);
53  uint32_t stride_z_elements = params->stride_z / VXLIB_sizeof(params->data_type);
54 
55  for (z = 0; z < params->dim_z; z++) {
56  VXLIB_PRINTF("%s", "\n");
57  yPtr = zPtr;
58  for (y = 0; y < params->dim_y; y++) {
59  xPtr = yPtr;
60  VXLIB_PRINTF("%p |", xPtr);
61  for (x = 0; x < params->dim_x; x++) {
62  VXLIB_PRINTF("%3d ", *(xPtr));
63  xPtr++;
64  }
65  VXLIB_PRINTF("%s", "|\n");
66  yPtr += stride_y_elements;
67  }
68  zPtr += stride_z_elements;
69  }
70 
71  return;
72 }
73 
74 template void VXLIB_debugPrintMatrix3D_helper<int8_t>(int8_t *matrix, const VXLIB_bufParams3D_t *params);
75 template void VXLIB_debugPrintMatrix3D_helper<int16_t>(int16_t *matrix, const VXLIB_bufParams3D_t *params);
76 template void VXLIB_debugPrintMatrix3D_helper<int32_t>(int32_t *matrix, const VXLIB_bufParams3D_t *params);
77 
78 template <typename dataType> void VXLIB_debugPrintMatrix3D_helperU(dataType *matrix, const VXLIB_bufParams3D_t *params)
79 {
80  uint32_t x, y, z;
81  dataType *xPtr;
82  dataType *yPtr;
83  dataType *zPtr = matrix;
84 
85  // stride_y is stored in bytes, but easier to use in elements
86  uint32_t stride_y_elements = params->stride_y / VXLIB_sizeof(params->data_type);
87  uint32_t stride_z_elements = params->stride_z / VXLIB_sizeof(params->data_type);
88 
89  for (z = 0; z < params->dim_z; z++) {
90  VXLIB_PRINTF("%s", "\n");
91  yPtr = zPtr;
92  for (y = 0; y < params->dim_y; y++) {
93  xPtr = yPtr;
94  VXLIB_PRINTF("%p |", xPtr);
95  for (x = 0; x < params->dim_x; x++) {
96  VXLIB_PRINTF("%3u ", *(xPtr));
97  xPtr++;
98  }
99  VXLIB_PRINTF("%s", "|\n");
100  yPtr += stride_y_elements;
101  }
102  zPtr += stride_z_elements;
103  }
104 
105  return;
106 }
107 
108 template void VXLIB_debugPrintMatrix3D_helper<uint8_t>(uint8_t *matrix, const VXLIB_bufParams3D_t *params);
109 template void VXLIB_debugPrintMatrix3D_helper<uint16_t>(uint16_t *matrix, const VXLIB_bufParams3D_t *params);
110 
111 /******************************************************************************/
112 
113 // want this function to have C-linkage in library...
114 #ifdef __cplusplus
115 extern "C" {
116 #endif /* __cplusplus */
117 
118 void VXLIB_debugPrintMatrix3D(void *matrix, const VXLIB_bufParams3D_t *params)
119 {
120  switch (params->data_type) {
121  case VXLIB_INT32:
122  VXLIB_debugPrintMatrix3D_helper<int32_t>((int32_t *) matrix, params);
123  break;
124  case VXLIB_INT16:
125  VXLIB_debugPrintMatrix3D_helper<int16_t>((int16_t *) matrix, params);
126  break;
127  case VXLIB_UINT16:
128  VXLIB_debugPrintMatrix3D_helperU<uint16_t>((uint16_t *) matrix, params);
129  break;
130  case VXLIB_INT8:
131  VXLIB_debugPrintMatrix3D_helper<int8_t>((int8_t *) matrix, params);
132  break;
133  case VXLIB_UINT8:
134  VXLIB_debugPrintMatrix3D_helperU<uint8_t>((uint8_t *) matrix, params);
135  break;
136  default:
137  VXLIB_PRINTF("\nERROR: Unrecognized data type in %s.\n", __FUNCTION__);
138  }
139 
140  return;
141 }
142 #ifdef __cplusplus
143 }
144 #endif /* __cplusplus */
template void VXLIB_debugPrintMatrix3D_helper< int16_t >(int16_t *matrix, const VXLIB_bufParams3D_t *params)
template void VXLIB_debugPrintMatrix3D_helper< int32_t >(int32_t *matrix, const VXLIB_bufParams3D_t *params)
void VXLIB_debugPrintMatrix3D_helper(dataType *matrix, const VXLIB_bufParams3D_t *params)
void VXLIB_debugPrintMatrix3D_helperU(dataType *matrix, const VXLIB_bufParams3D_t *params)
void VXLIB_debugPrintMatrix3D(void *matrix, const VXLIB_bufParams3D_t *params)
template void VXLIB_debugPrintMatrix3D_helper< int8_t >(int8_t *matrix, const VXLIB_bufParams3D_t *params)
template void VXLIB_debugPrintMatrix3D_helper< uint8_t >(uint8_t *matrix, const VXLIB_bufParams3D_t *params)
template void VXLIB_debugPrintMatrix3D_helper< uint16_t >(uint16_t *matrix, const VXLIB_bufParams3D_t *params)
#define VXLIB_PRINTF(fmt,...)
Definition: VXLIB_types.h:95
static int32_t VXLIB_sizeof(uint32_t type)
Inline function returns number of bytes per element given a type of VXLIB_data_type_e.
@ VXLIB_UINT16
@ VXLIB_INT32
@ VXLIB_INT16
@ VXLIB_INT8
@ VXLIB_UINT8
A structure for a 3 dimensional buffer descriptor.
int32_t stride_z
Stride in Z dimension in bytes.
int32_t stride_y
Stride in Y dimension in bytes.
uint32_t dim_z
Depth of patch in Z dimension in elements.
uint32_t dim_y
Height of buffer in Y dimension in elements.
uint32_t dim_x
Width of buffer in X dimension in elements.
uint32_t data_type
Values are of type VXLIB_data_type_e.