-
Notifications
You must be signed in to change notification settings - Fork 0
/
simd.c
52 lines (45 loc) · 1.17 KB
/
simd.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <stdlib.h>
#include <math.h>
#include "Simd/SimdLib.h"
#define TRUE 1
#define FALSE 0
int sobelSimdGray8(uint8_t *src, size_t width, size_t height, uint8_t *dst) {
size_t imgSize = width * height ;
size_t srcStride = width ;
size_t dstStride = srcStride * 2 ;
size_t dstSize = imgSize * 2 ;
uint8_t * dstXC = malloc(dstSize) ;
if (NULL == dstXC ) {
return FALSE ;
}
uint8_t *dstX = dstXC ;
uint8_t * dstYC = malloc(dstSize) ;
if (NULL == dstYC ) {
free(dstXC) ;
return FALSE ;
}
uint8_t *dstY = dstYC ;
SimdSobelDxAbs(src, srcStride, width, height, dstX, dstStride) ;
SimdSobelDyAbs(src, srcStride, width, height, dstY, dstStride) ;
uint32_t fX, fY ;
double fS ;
uint8_t pix ;
for (int i = 0; i < imgSize; i++ ) {
fX = (uint32_t)*dstX ;
fY = (uint32_t)*dstY ;
fS = sqrt((double)(fX*fX + fY*fY));
//clipping
if (fS > 255.0) {
pix = 255 ;
} else {
pix = (uint8_t)fS ;
}
*dst = pix ;
dst++ ;
dstX ++ ;
dstY ++ ;
}
free(dstXC) ;
free(dstYC) ;
return TRUE ;
}