2021-11-08 11:04:58 +00:00
|
|
|
int twoToOne(x, y, width, height) {
|
|
|
|
while(x < 0) {
|
|
|
|
x += width;
|
|
|
|
}
|
|
|
|
while(y < 0) {
|
|
|
|
y += height;
|
|
|
|
}
|
|
|
|
x = x % width;
|
|
|
|
y = y % height;
|
|
|
|
return x + y * width;
|
|
|
|
}
|
|
|
|
|
|
|
|
//float gaussian(float x, float y) {
|
|
|
|
// return exp(-(x*x + y*y) / (1.5F * 1.5F * 2.0F));
|
|
|
|
//}
|
|
|
|
|
2021-01-23 07:42:45 +00:00
|
|
|
__kernel void do_filter(
|
2021-11-08 11:04:58 +00:00
|
|
|
__global float *filter_out, __global const float *precomputed,
|
|
|
|
__global const int *pbp, const int width, const int height,
|
|
|
|
const int filter_size) {
|
2021-01-23 07:42:45 +00:00
|
|
|
int i = get_global_id(0);
|
|
|
|
if(i < 0 || i >= width * height) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int x = i % width;
|
|
|
|
int y = i / width;
|
|
|
|
|
|
|
|
float sum = 0.0f;
|
|
|
|
for(int q = 0; q < filter_size; ++q) {
|
2021-11-08 11:04:58 +00:00
|
|
|
int q_prime = height - filter_size / 2 + y + q;
|
2021-01-23 07:42:45 +00:00
|
|
|
for(int p = 0; p < filter_size; ++p) {
|
2021-11-08 11:04:58 +00:00
|
|
|
int p_prime = width - filter_size / 2 + x + p;
|
|
|
|
if(pbp[twoToOne(p_prime, q_prime, width, height)] != 0) {
|
|
|
|
sum += precomputed[twoToOne(p, q, filter_size, filter_size)];
|
|
|
|
//sum += gaussian(p - filter_size / 2.0F + 0.5F, q - filter_size / 2.0F + 0.5F);
|
2021-01-23 07:42:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
filter_out[i] = sum;
|
|
|
|
}
|
|
|
|
|
|
|
|
// vim: syntax=c
|