Update Portuguese translation
[gegl.git] / opencl / bilateral-filter.cl
blob0205b985576217e707c10473815d4c7736d23923
1 #define POW2(a) ((a) * (a))
2 kernel void bilateral_filter(global float4 *in,
3 global float4 *out,
4 const float radius,
5 const float preserve)
7 int gidx = get_global_id(0);
8 int gidy = get_global_id(1);
9 int n_radius = ceil(radius);
10 int dst_width = get_global_size(0);
11 int src_width = dst_width + n_radius * 2;
13 int u, v, i, j;
14 float4 center_pix =
15 in[(gidy + n_radius) * src_width + gidx + n_radius];
16 float4 accumulated = 0.0f;
17 float4 tempf = 0.0f;
18 float count = 0.0f;
19 float diff_map, gaussian_weight, weight;
21 for (v = -n_radius;v <= n_radius; ++v)
23 for (u = -n_radius;u <= n_radius; ++u)
25 i = gidx + n_radius + u;
26 j = gidy + n_radius + v;
28 int gid1d = i + j * src_width;
29 tempf = in[gid1d];
31 diff_map = exp (
32 - ( POW2(center_pix.x - tempf.x)
33 + POW2(center_pix.y - tempf.y)
34 + POW2(center_pix.z - tempf.z))
35 * preserve);
37 gaussian_weight =
38 exp( - 0.5f * (POW2(u) + POW2(v)) / radius);
40 weight = diff_map * gaussian_weight;
42 accumulated += tempf * weight;
43 count += weight;
46 out[gidx + gidy * dst_width] = accumulated / count;