-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathConvOperation.cl
More file actions
25 lines (22 loc) · 853 Bytes
/
ConvOperation.cl
File metadata and controls
25 lines (22 loc) · 853 Bytes
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
int sat(int min, int val, int max) {
return val > min ? (val < max ? val : max) : min;
}
__kernel void Convolution(__global float* inImage,
int kernelWidth,
__global float* kernelData,
__global float* outImage) {
int c = get_global_id(0),
r = get_global_id(1);
int cs = c - kernelWidth / 2,
rs = r - kernelWidth / 2;
int imgWidth = get_global_size(0),
imgHeight = get_global_size(1);
for (int m = 0; m < kernelWidth; m++) {
for (int n = 0; n < kernelWidth; n++) {
for (int ch = 0; ch < 3; ch++) {
outImage[3 * (r*imgWidth + c) + ch] += inImage[3 * (sat(0, rs + m, imgHeight - 1) * imgWidth + sat(0, cs + n, imgWidth)) + ch] *
kernelData[n * kernelWidth + m];
}
}
}
}