Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/3rdparty/carotene/src/absdiff.cpp
16337 views
1
/*
2
* By downloading, copying, installing or using the software you agree to this license.
3
* If you do not agree to this license, do not download, install,
4
* copy or use the software.
5
*
6
*
7
* License Agreement
8
* For Open Source Computer Vision Library
9
* (3-clause BSD License)
10
*
11
* Copyright (C) 2014-2015, NVIDIA Corporation, all rights reserved.
12
* Third party copyrights are property of their respective owners.
13
*
14
* Redistribution and use in source and binary forms, with or without modification,
15
* are permitted provided that the following conditions are met:
16
*
17
* * Redistributions of source code must retain the above copyright notice,
18
* this list of conditions and the following disclaimer.
19
*
20
* * Redistributions in binary form must reproduce the above copyright notice,
21
* this list of conditions and the following disclaimer in the documentation
22
* and/or other materials provided with the distribution.
23
*
24
* * Neither the names of the copyright holders nor the names of the contributors
25
* may be used to endorse or promote products derived from this software
26
* without specific prior written permission.
27
*
28
* This software is provided by the copyright holders and contributors "as is" and
29
* any express or implied warranties, including, but not limited to, the implied
30
* warranties of merchantability and fitness for a particular purpose are disclaimed.
31
* In no event shall copyright holders or contributors be liable for any direct,
32
* indirect, incidental, special, exemplary, or consequential damages
33
* (including, but not limited to, procurement of substitute goods or services;
34
* loss of use, data, or profits; or business interruption) however caused
35
* and on any theory of liability, whether in contract, strict liability,
36
* or tort (including negligence or otherwise) arising in any way out of
37
* the use of this software, even if advised of the possibility of such damage.
38
*/
39
40
#include <algorithm>
41
42
#include "common.hpp"
43
#include "vtransform.hpp"
44
45
namespace CAROTENE_NS {
46
47
#ifdef CAROTENE_NEON
48
49
namespace {
50
51
template <typename T>
52
struct AbsDiff
53
{
54
typedef T type;
55
56
void operator() (const typename internal::VecTraits<T>::vec128 & v_src0,
57
const typename internal::VecTraits<T>::vec128 & v_src1,
58
typename internal::VecTraits<T>::vec128 & v_dst) const
59
{
60
v_dst = internal::vabdq(v_src0, v_src1);
61
}
62
63
void operator() (const typename internal::VecTraits<T>::vec64 & v_src0,
64
const typename internal::VecTraits<T>::vec64 & v_src1,
65
typename internal::VecTraits<T>::vec64 & v_dst) const
66
{
67
v_dst = internal::vabd(v_src0, v_src1);
68
}
69
70
void operator() (const T * src0, const T * src1, T * dst) const
71
{
72
dst[0] = src0[0] >= src1[0] ? src0[0] - src1[0] : src1[0] - src0[0];
73
}
74
};
75
76
template <typename T>
77
struct AbsDiffSigned
78
{
79
typedef T type;
80
81
void operator() (const typename internal::VecTraits<T>::vec128 & v_src0,
82
const typename internal::VecTraits<T>::vec128 & v_src1,
83
typename internal::VecTraits<T>::vec128 & v_dst) const
84
{
85
typename internal::VecTraits<T>::vec128 v_min = internal::vminq(v_src0, v_src1);
86
typename internal::VecTraits<T>::vec128 v_max = internal::vmaxq(v_src0, v_src1);
87
v_dst = internal::vqsubq(v_max, v_min);
88
}
89
90
void operator() (const typename internal::VecTraits<T>::vec64 & v_src0,
91
const typename internal::VecTraits<T>::vec64 & v_src1,
92
typename internal::VecTraits<T>::vec64 & v_dst) const
93
{
94
typename internal::VecTraits<T>::vec64 v_min = internal::vmin(v_src0, v_src1);
95
typename internal::VecTraits<T>::vec64 v_max = internal::vmax(v_src0, v_src1);
96
v_dst = internal::vqsub(v_max, v_min);
97
}
98
99
void operator() (const T * src0, const T * src1, T * dst) const
100
{
101
dst[0] = internal::saturate_cast<T>(src0[0] >= src1[0] ? (s64)src0[0] - src1[0] : (s64)src1[0] - src0[0]);
102
}
103
};
104
105
} // namespace
106
107
#endif
108
109
void absDiff(const Size2D &size,
110
const u8 *src0Base, ptrdiff_t src0Stride,
111
const u8 *src1Base, ptrdiff_t src1Stride,
112
u8 *dstBase, ptrdiff_t dstStride)
113
{
114
internal::assertSupportedConfiguration();
115
#ifdef CAROTENE_NEON
116
internal::vtransform(size,
117
src0Base, src0Stride,
118
src1Base, src1Stride,
119
dstBase, dstStride, AbsDiff<u8>());
120
#else
121
(void)size;
122
(void)src0Base;
123
(void)src0Stride;
124
(void)src1Base;
125
(void)src1Stride;
126
(void)dstBase;
127
(void)dstStride;
128
#endif
129
}
130
131
void absDiff(const Size2D &size,
132
const u16 *src0Base, ptrdiff_t src0Stride,
133
const u16 *src1Base, ptrdiff_t src1Stride,
134
u16 *dstBase, ptrdiff_t dstStride)
135
{
136
internal::assertSupportedConfiguration();
137
#ifdef CAROTENE_NEON
138
internal::vtransform(size,
139
src0Base, src0Stride,
140
src1Base, src1Stride,
141
dstBase, dstStride, AbsDiff<u16>());
142
#else
143
(void)size;
144
(void)src0Base;
145
(void)src0Stride;
146
(void)src1Base;
147
(void)src1Stride;
148
(void)dstBase;
149
(void)dstStride;
150
#endif
151
}
152
153
void absDiff(const Size2D &size,
154
const s8 *src0Base, ptrdiff_t src0Stride,
155
const s8 *src1Base, ptrdiff_t src1Stride,
156
s8 *dstBase, ptrdiff_t dstStride)
157
{
158
internal::assertSupportedConfiguration();
159
#ifdef CAROTENE_NEON
160
internal::vtransform(size,
161
src0Base, src0Stride,
162
src1Base, src1Stride,
163
dstBase, dstStride, AbsDiffSigned<s8>());
164
#else
165
(void)size;
166
(void)src0Base;
167
(void)src0Stride;
168
(void)src1Base;
169
(void)src1Stride;
170
(void)dstBase;
171
(void)dstStride;
172
#endif
173
}
174
175
void absDiff(const Size2D &size,
176
const s16 *src0Base, ptrdiff_t src0Stride,
177
const s16 *src1Base, ptrdiff_t src1Stride,
178
s16 *dstBase, ptrdiff_t dstStride)
179
{
180
internal::assertSupportedConfiguration();
181
#ifdef CAROTENE_NEON
182
internal::vtransform(size,
183
src0Base, src0Stride,
184
src1Base, src1Stride,
185
dstBase, dstStride, AbsDiffSigned<s16>());
186
#else
187
(void)size;
188
(void)src0Base;
189
(void)src0Stride;
190
(void)src1Base;
191
(void)src1Stride;
192
(void)dstBase;
193
(void)dstStride;
194
#endif
195
}
196
197
void absDiff(const Size2D &size,
198
const s32 *src0Base, ptrdiff_t src0Stride,
199
const s32 *src1Base, ptrdiff_t src1Stride,
200
s32 *dstBase, ptrdiff_t dstStride)
201
{
202
internal::assertSupportedConfiguration();
203
#ifdef CAROTENE_NEON
204
internal::vtransform(size,
205
src0Base, src0Stride,
206
src1Base, src1Stride,
207
dstBase, dstStride, AbsDiffSigned<s32>());
208
#else
209
(void)size;
210
(void)src0Base;
211
(void)src0Stride;
212
(void)src1Base;
213
(void)src1Stride;
214
(void)dstBase;
215
(void)dstStride;
216
#endif
217
}
218
219
void absDiff(const Size2D &size,
220
const f32 * src0Base, ptrdiff_t src0Stride,
221
const f32 * src1Base, ptrdiff_t src1Stride,
222
f32 * dstBase, ptrdiff_t dstStride)
223
{
224
internal::assertSupportedConfiguration();
225
#ifdef CAROTENE_NEON
226
internal::vtransform(size,
227
src0Base, src0Stride,
228
src1Base, src1Stride,
229
dstBase, dstStride, AbsDiff<f32>());
230
#else
231
(void)size;
232
(void)src0Base;
233
(void)src0Stride;
234
(void)src1Base;
235
(void)src1Stride;
236
(void)dstBase;
237
(void)dstStride;
238
#endif
239
}
240
241
} // namespace CAROTENE_NS
242
243