VisionServer  v2.1.1-1-g21dc5465
FRC vision library
neon.h
Go to the documentation of this file.
1#pragma once
2
3#include <stdint.h>
4
5
6#ifndef ENABLE_WRAPPER_DIM_SAFETY
7#define ENABLE_WRAPPER_DIM_SAFETY true // use CV_Assert for checking correnct mat sizes/channel nums
8#endif
9
10#ifdef __cplusplus
11extern "C" {
12#endif
13
14void memcpy_threshold_asm( // keeps original threshold values
15 uint8_t const *src,
16 uint8_t* dest,
17 int32_t size,
18 uint8_t thresh
19);
20void memcpy_threshold_binary_asm( // thresholds evaulate to all 1's rather than their original value
21 uint8_t const *src,
22 uint8_t* dest,
23 int32_t size,
24 uint8_t thresh
25);
26void memcpy_compare3_add_asm( // threshold a channel based on if it has the highest value of all (3), then add some other amount (WST result)
27 uint8_t const *primary,
28 uint8_t const *cmp1,
29 uint8_t const *cmp2,
30 uint8_t const *add,
31 uint8_t* dest,
32 int32_t size
33);
35 uint8_t const *primary,
36 uint8_t const *ch2,
37 uint8_t const *ch3,
38 uint8_t *dest,
39 int32_t size,
40 uint8_t alpha,
41 uint8_t beta,
42 uint8_t gamma
43);
44void memcpy_deinterlace_wstb_asm( // subtracts weighted channels from primary, adds gamma, and thresholds into binary frame
45 uint8_t const *framebuff_3C,
46 uint8_t *dest,
47 int32_t size,
48 uint8_t offset,
49 uint8_t alpha,
50 uint8_t beta,
51 uint8_t thresh
52);
54 uint8_t const *framebuff_3C,
55 uint8_t *dest,
56 int32_t size
57);
58
60 uint8_t const *a,
61 uint8_t const *b,
62 uint8_t* dest,
63 int32_t size
64);
65void memcpy_bitwise_or_3c_asm( // computes the bitwise or of a binary frame with each channel of a 3-channel frame
66 uint8_t const *a_3C,
67 uint8_t const *b,
68 uint8_t* dest_3C,
69 int32_t size
70);
71void memcpy_add_asm( // totally unnecessary but it wouldn't be 'neon_add' w/o the definite function
72 uint8_t const *a,
73 uint8_t const *b,
74 uint8_t* dest,
75 int32_t size
76);
77void memcpy_add_3c_asm( // for combining a 3-channel image w/ a single channel binary image w/o the need for pre-converting
78 uint8_t const *a_3C,
79 uint8_t const *b,
80 uint8_t* dest_3C,
81 int32_t size
82);
84 uint8_t const *a_3C,
85 uint8_t const *b,
86 uint8_t* dest_3C,
87 int32_t size
88);
89void memcpy_subtract_asm( // don't use this it does not account for underflows (10/29/22)--> maybe fixed now?
90 uint8_t const *base,
91 uint8_t const *sub,
92 uint8_t* dest,
93 int32_t size
94);
95
96#ifdef __cplusplus
97}
98#endif
99
100
101
102
103#include <opencv2/opencv.hpp>
104#include "extensions.h"
105
106inline void neon_threshold(
107 const cv::Mat& src, cv::Mat& dest, uint8_t thresh
108) {
109#if ENABLE_WRAPPER_DIM_SAFETY
110 CV_Assert(src.type() == CV_8UC1);
111 CV_Assert(dest.type() == CV_8UC1);
112 CV_Assert(src.size().area() == dest.size().area());
113#endif
115 src.data,
116 dest.data,
117 src.size().area(),
118 thresh
119 );
120}
122 const cv::Mat& src, cv::Mat& dest, uint8_t thresh
123) {
124#if ENABLE_WRAPPER_DIM_SAFETY
125 CV_Assert(src.type() == CV_8UC1);
126 CV_Assert(dest.type() == CV_8UC1);
127 CV_Assert(src.size().area() == dest.size().area());
128#endif
130 src.data,
131 dest.data,
132 src.size().area(),
133 thresh
134 );
135}
137 const cv::Mat& primary,
138 const cv::Mat& comp1, const cv::Mat& comp2,
139 const cv::Mat& add, cv::Mat& dest
140) {
141#if ENABLE_WRAPPER_DIM_SAFETY
142 CV_Assert(primary.type() == CV_8UC1);
143 CV_Assert(comp1.type() == CV_8UC1);
144 CV_Assert(comp2.type() == CV_8UC1);
145 CV_Assert(add.type() == CV_8UC1);
146 CV_Assert(dest.type() == CV_8UC1);
147 CV_Assert(primary.size().area() == comp1.size().area());
148 CV_Assert(primary.size().area() == comp2.size().area());
149 CV_Assert(primary.size().area() == add.size().area());
150 CV_Assert(primary.size().area() == dest.size().area());
151#endif
153 primary.data,
154 comp1.data,
155 comp2.data,
156 add.data,
157 dest.data,
158 primary.size().area()
159 );
160}
161inline void neon_wst(
162 const cv::Mat& primary,
163 const cv::Mat& ch1, uint8_t alpha,
164 const cv::Mat& ch2, uint8_t beta,
165 cv::Mat& dest, uint8_t gamma = 0
166) {
167#if ENABLE_WRAPPER_DIM_SAFETY
168 CV_Assert(primary.type() == CV_8UC1);
169 CV_Assert(ch1.type() == CV_8UC1);
170 CV_Assert(ch2.type() == CV_8UC1);
171 CV_Assert(dest.type() == CV_8UC1);
172 CV_Assert(primary.size().area() == ch1.size().area());
173 CV_Assert(primary.size().area() == ch2.size().area());
174 CV_Assert(primary.size().area() == dest.size().area());
175#endif
177 primary.data,
178 ch1.data,
179 ch2.data,
180 dest.data,
181 primary.size().area(),
182 alpha, beta, gamma
183 );
184}
186 const cv::Mat& frame_3C, cv::Mat& dest,
187 vs2::BGR primary, uint8_t alpha = 0xFF, uint8_t beta = 0xFF, uint8_t thresh = 0x7F
188) {
189#if ENABLE_WRAPPER_DIM_SAFETY
190 CV_Assert(frame_3C.type() == CV_8UC3);
191 CV_Assert(dest.type() == CV_8UC1);
192 CV_Assert(frame_3C.size().area() == dest.size().area());
193#endif
195 frame_3C.data,
196 dest.data,
197 frame_3C.size().area(),
198 ~primary, alpha, beta, thresh);
199}
201 const cv::Mat& frame_3C, cv::Mat& dest
202) {
203#if ENABLE_WRAPPER_DIM_SAFETY
204 CV_Assert(frame_3C.type() == CV_8UC3);
205 CV_Assert(dest.type() == CV_8UC1);
206 CV_Assert(frame_3C.size().area() == dest.size().area());
207#endif
209 frame_3C.data,
210 dest.data,
211 frame_3C.size().area()
212 );
213}
214
215inline void neon_bitwise_or(
216 const cv::Mat& a, const cv::Mat& b, cv::Mat& dest
217) {
218#if ENABLE_WRAPPER_DIM_SAFETY
219 CV_Assert(a.size().area() == b.size().area());
220 CV_Assert(a.size().area() == dest.size().area());
221#endif
222 if(a.type() == b.type()) {
223#if ENABLE_WRAPPER_DIM_SAFETY
224 CV_Assert(a.type() == dest.type());
225#endif
227 a.data,
228 b.data,
229 dest.data,
230 a.size().area() * a.channels()
231 );
232 } else if(a.type() == CV_8UC3) {
233#if ENABLE_WRAPPER_DIM_SAFETY
234 CV_Assert(b.type() == CV_8UC1);
235 CV_Assert(dest.type() == CV_8UC3);
236#endif
238 a.data,
239 b.data,
240 dest.data,
241 a.size().area()
242 );
243 } else {
244#if ENABLE_WRAPPER_DIM_SAFETY
245 CV_Assert(a.type() == CV_8UC1);
246 CV_Assert(b.type() == CV_8UC3);
247 CV_Assert(dest.type() == CV_8UC3);
248#endif
250 b.data,
251 a.data,
252 dest.data,
253 a.size().area()
254 );
255 }
256}
257inline void neon_add(
258 const cv::Mat& a, const cv::Mat& b, cv::Mat& dest
259) {
260#if ENABLE_WRAPPER_DIM_SAFETY
261 CV_Assert(a.size().area() == b.size().area());
262 CV_Assert(a.size().area() == dest.size().area());
263#endif
264 if(a.type() == CV_8UC3) {
265#if ENABLE_WRAPPER_DIM_SAFETY
266 CV_Assert(dest.type() == CV_8UC3);
267#endif
268 if(b.type() == CV_8UC3) {
270 a.data,
271 b.data,
272 dest.data,
273 a.size().area()
274 );
275 } else {
276#if ENABLE_WRAPPER_DIM_SAFETY
277 CV_Assert(b.type() == CV_8UC1);
278#endif
280 a.data,
281 b.data,
282 dest.data,
283 a.size().area()
284 );
285 }
286 } else if(b.type() == CV_8UC3) {
287#if ENABLE_WRAPPER_DIM_SAFETY
288 CV_Assert(a.type() == CV_8UC1);
289 CV_Assert(dest.type() == CV_8UC3);
290#endif
292 b.data,
293 a.data,
294 dest.data,
295 a.size().area()
296 );
297 } else {
298#if ENABLE_WRAPPER_DIM_SAFETY
299 CV_Assert(a.type() == CV_8UC1);
300 CV_Assert(b.type() == CV_8UC1);
301 CV_Assert(dest.type() == CV_8UC1);
302#endif
304 a.data,
305 b.data,
306 dest.data,
307 a.size().area()
308 );
309 }
310}
311inline void neon_subtract(
312 const cv::Mat& src, const cv::Mat& sub, cv::Mat& dest
313) {
314#if ENABLE_WRAPPER_DIM_SAFETY
315 CV_Assert(src.type() == CV_8UC1);
316 CV_Assert(sub.type() == CV_8UC1);
317 CV_Assert(dest.type() == dest.type());
318 CV_Assert(src.size().area() == sub.size().area());
319 CV_Assert(src.size().area() == dest.size().area());
320#endif
322 src.data,
323 sub.data,
324 dest.data,
325 src.size().area()
326 );
327}
void memcpy_bitwise_or_3c_asm(uint8_t const *a_3C, uint8_t const *b, uint8_t *dest_3C, int32_t size)
void memcpy_bitwise_or_asm(uint8_t const *a, uint8_t const *b, uint8_t *dest, int32_t size)
void neon_wst(const cv::Mat &primary, const cv::Mat &ch1, uint8_t alpha, const cv::Mat &ch2, uint8_t beta, cv::Mat &dest, uint8_t gamma=0)
Definition: neon.h:161
void neon_compare3_add(const cv::Mat &primary, const cv::Mat &comp1, const cv::Mat &comp2, const cv::Mat &add, cv::Mat &dest)
Definition: neon.h:136
void neon_add(const cv::Mat &a, const cv::Mat &b, cv::Mat &dest)
Definition: neon.h:257
void neon_threshold_binary(const cv::Mat &src, cv::Mat &dest, uint8_t thresh)
Definition: neon.h:121
void memcpy_add_asm(uint8_t const *a, uint8_t const *b, uint8_t *dest, int32_t size)
void memcpy_add_3c_asm(uint8_t const *a_3C, uint8_t const *b, uint8_t *dest_3C, int32_t size)
void memcpy_subtract_asm(uint8_t const *base, uint8_t const *sub, uint8_t *dest, int32_t size)
void neon_deinterlace_wstb(const cv::Mat &frame_3C, cv::Mat &dest, vs2::BGR primary, uint8_t alpha=0xFF, uint8_t beta=0xFF, uint8_t thresh=0x7F)
Definition: neon.h:185
void memcpy_deinterlace_wstb_asm(uint8_t const *framebuff_3C, uint8_t *dest, int32_t size, uint8_t offset, uint8_t alpha, uint8_t beta, uint8_t thresh)
void neon_bitwise_or(const cv::Mat &a, const cv::Mat &b, cv::Mat &dest)
Definition: neon.h:215
void memcpy_add_3c2_asm(uint8_t const *a_3C, uint8_t const *b, uint8_t *dest_3C, int32_t size)
void neon_threshold(const cv::Mat &src, cv::Mat &dest, uint8_t thresh)
Definition: neon.h:106
void neon_deinterlace_cvt2gray(const cv::Mat &frame_3C, cv::Mat &dest)
Definition: neon.h:200
void memcpy_threshold_binary_asm(uint8_t const *src, uint8_t *dest, int32_t size, uint8_t thresh)
void neon_subtract(const cv::Mat &src, const cv::Mat &sub, cv::Mat &dest)
Definition: neon.h:311
void memcpy_threshold_asm(uint8_t const *src, uint8_t *dest, int32_t size, uint8_t thresh)
void memcpy_wst_asm(uint8_t const *primary, uint8_t const *ch2, uint8_t const *ch3, uint8_t *dest, int32_t size, uint8_t alpha, uint8_t beta, uint8_t gamma)
void memcpy_deinterlace_togray_asm(uint8_t const *framebuff_3C, uint8_t *dest, int32_t size)
void memcpy_compare3_add_asm(uint8_t const *primary, uint8_t const *cmp1, uint8_t const *cmp2, uint8_t const *add, uint8_t *dest, int32_t size)