|
|
|
@ -41,6 +41,7 @@ |
|
|
|
|
//M*/
|
|
|
|
|
|
|
|
|
|
#include "precomp.hpp" |
|
|
|
|
#include "opencv2/hal/intrin.hpp" |
|
|
|
|
|
|
|
|
|
namespace cv |
|
|
|
|
{ |
|
|
|
@ -96,7 +97,6 @@ void spatialGradient( InputArray _src, OutputArray _dx, OutputArray _dy, int ksi |
|
|
|
|
// No-SSE
|
|
|
|
|
int idx; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
p_dx[0] = 0; // Top-left corner
|
|
|
|
|
p_dy[0] = 0; |
|
|
|
|
p_dx[W-1] = 0; // Top-right corner
|
|
|
|
@ -168,6 +168,100 @@ void spatialGradient( InputArray _src, OutputArray _dx, OutputArray _dy, int ksi |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Do Inner area
|
|
|
|
|
#if CV_SIMD128 |
|
|
|
|
// Characters in variable names have the following meanings:
|
|
|
|
|
// u: unsigned char
|
|
|
|
|
// s: signed int
|
|
|
|
|
//
|
|
|
|
|
// [row][column]
|
|
|
|
|
// m: offset -1
|
|
|
|
|
// n: offset 0
|
|
|
|
|
// p: offset 1
|
|
|
|
|
// Example: umn is offset -1 in row and offset 0 in column
|
|
|
|
|
v_uint8x16 v_umm, v_umn, v_ump, |
|
|
|
|
v_unm, v_unn, v_unp, |
|
|
|
|
v_upm, v_upn, v_upp; |
|
|
|
|
v_uint16x8 v_umm1, v_umm2, v_umn1, v_umn2, v_ump1, v_ump2, |
|
|
|
|
v_unm1, v_unm2, v_unn1, v_unn2, v_unp1, v_unp2, |
|
|
|
|
v_upm1, v_upm2, v_upn1, v_upn2, v_upp1, v_upp2; |
|
|
|
|
v_int16x8 v_smm1, v_smm2, v_smn1, v_smn2, v_smp1, v_smp2, |
|
|
|
|
v_snm1, v_snm2, v_snn1, v_snn2, v_snp1, v_snp2, |
|
|
|
|
v_spm1, v_spm2, v_spn1, v_spn2, v_spp1, v_spp2, |
|
|
|
|
v_two = v_setall_s16(2), |
|
|
|
|
v_sdx1, v_sdx2, v_sdy1, v_sdy2; |
|
|
|
|
for ( i = 1; i < H - 1; i++ ) |
|
|
|
|
for ( j = 1; j < W - 1 - 15; j += 16 ) |
|
|
|
|
{ |
|
|
|
|
// Load
|
|
|
|
|
idx = i*W + j; |
|
|
|
|
v_umm = v_load(&p_src[idx - W - 1]); |
|
|
|
|
v_umn = v_load(&p_src[idx - W]); |
|
|
|
|
v_ump = v_load(&p_src[idx - W + 1]); |
|
|
|
|
v_unm = v_load(&p_src[idx - 1]); |
|
|
|
|
v_unn = v_load(&p_src[idx]); |
|
|
|
|
v_unp = v_load(&p_src[idx + 1]); |
|
|
|
|
v_upm = v_load(&p_src[idx + W - 1]); |
|
|
|
|
v_upn = v_load(&p_src[idx + W]); |
|
|
|
|
v_upp = v_load(&p_src[idx + W + 1]); |
|
|
|
|
|
|
|
|
|
// Expand to uint
|
|
|
|
|
v_expand(v_umm, v_umm1, v_umm2); |
|
|
|
|
v_expand(v_umn, v_umn1, v_umn2); |
|
|
|
|
v_expand(v_ump, v_ump1, v_ump2); |
|
|
|
|
v_expand(v_unm, v_unm1, v_unm2); |
|
|
|
|
v_expand(v_unn, v_unn1, v_unn2); |
|
|
|
|
v_expand(v_unp, v_unp1, v_unp2); |
|
|
|
|
v_expand(v_upm, v_upm1, v_upm2); |
|
|
|
|
v_expand(v_upn, v_upn1, v_upn2); |
|
|
|
|
v_expand(v_upp, v_upp1, v_upp2); |
|
|
|
|
|
|
|
|
|
// Convert to int
|
|
|
|
|
v_smm1 = v_reinterpret_as_s16(v_umm1); |
|
|
|
|
v_smm2 = v_reinterpret_as_s16(v_umm2); |
|
|
|
|
v_smn1 = v_reinterpret_as_s16(v_umn1); |
|
|
|
|
v_smn2 = v_reinterpret_as_s16(v_umn2); |
|
|
|
|
v_smp1 = v_reinterpret_as_s16(v_ump1); |
|
|
|
|
v_smp2 = v_reinterpret_as_s16(v_ump2); |
|
|
|
|
v_snm1 = v_reinterpret_as_s16(v_unm1); |
|
|
|
|
v_snm2 = v_reinterpret_as_s16(v_unm2); |
|
|
|
|
v_snn1 = v_reinterpret_as_s16(v_unn1); |
|
|
|
|
v_snn2 = v_reinterpret_as_s16(v_unn2); |
|
|
|
|
v_snp1 = v_reinterpret_as_s16(v_unp1); |
|
|
|
|
v_snp2 = v_reinterpret_as_s16(v_unp2); |
|
|
|
|
v_spm1 = v_reinterpret_as_s16(v_upm1); |
|
|
|
|
v_spm2 = v_reinterpret_as_s16(v_upm2); |
|
|
|
|
v_spn1 = v_reinterpret_as_s16(v_upn1); |
|
|
|
|
v_spn2 = v_reinterpret_as_s16(v_upn2); |
|
|
|
|
v_spp1 = v_reinterpret_as_s16(v_upp1); |
|
|
|
|
v_spp2 = v_reinterpret_as_s16(v_upp2); |
|
|
|
|
|
|
|
|
|
// dx
|
|
|
|
|
v_sdx1 = (v_smp1 - v_smm1) + v_two*(v_snp1 - v_snm1) + (v_spp1 - v_spm1); |
|
|
|
|
v_sdx2 = (v_smp2 - v_smm2) + v_two*(v_snp2 - v_snm2) + (v_spp2 - v_spm2); |
|
|
|
|
|
|
|
|
|
// dy
|
|
|
|
|
v_sdy1 = (v_spm1 - v_smm1) + v_two*(v_spn1 - v_smn1) + (v_spp1 - v_smp1); |
|
|
|
|
v_sdy2 = (v_spm2 - v_smm2) + v_two*(v_spn2 - v_smn2) + (v_spp2 - v_smp2); |
|
|
|
|
|
|
|
|
|
// Store
|
|
|
|
|
v_store(&p_dx[idx], v_sdx1); |
|
|
|
|
v_store(&p_dx[idx+8], v_sdx2); |
|
|
|
|
v_store(&p_dy[idx], v_sdy1); |
|
|
|
|
v_store(&p_dy[idx+8], v_sdy2); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Cleanup
|
|
|
|
|
int end_j = j; |
|
|
|
|
for ( i = 1; i < H - 1; i++ ) |
|
|
|
|
for ( j = end_j; j < W - 1; j++ ) |
|
|
|
|
{ |
|
|
|
|
idx = i*W + j; |
|
|
|
|
p_dx[idx] = -(p_src[idx-W-1] + 2*p_src[idx-1] + p_src[idx+W-1]) + |
|
|
|
|
(p_src[idx-W+1] + 2*p_src[idx+1] + p_src[idx+W+1]); |
|
|
|
|
p_dy[idx] = -(p_src[idx-W-1] + 2*p_src[idx-W] + p_src[idx-W+1]) + |
|
|
|
|
(p_src[idx+W-1] + 2*p_src[idx+W] + p_src[idx+W+1]); |
|
|
|
|
} |
|
|
|
|
#else |
|
|
|
|
for ( i = 1; i < H - 1; i++ ) |
|
|
|
|
for ( j = 1; j < W - 1; j++ ) |
|
|
|
|
{ |
|
|
|
@ -177,6 +271,7 @@ void spatialGradient( InputArray _src, OutputArray _dx, OutputArray _dy, int ksi |
|
|
|
|
p_dy[idx] = -(p_src[idx-W-1] + 2*p_src[idx-W] + p_src[idx-W+1]) + |
|
|
|
|
(p_src[idx+W-1] + 2*p_src[idx+W] + p_src[idx+W+1]); |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|