4" * This file is part of FFmpeg.\n"
6" * FFmpeg is free software; you can redistribute it and/or\n"
7" * modify it under the terms of the GNU Lesser General Public\n"
8" * License as published by the Free Software Foundation; either\n"
9" * version 2.1 of the License, or (at your option) any later version.\n"
11" * FFmpeg is distributed in the hope that it will be useful,\n"
12" * but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
13" * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
14" * Lesser General Public License for more details.\n"
16" * You should have received a copy of the GNU Lesser General Public\n"
17" * License along with FFmpeg; if not, write to the Free Software\n"
18" * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n"
21"const sampler_t sampler = (CLK_NORMALIZED_COORDS_FALSE |\n"
22" CLK_ADDRESS_CLAMP_TO_EDGE |\n"
23" CLK_FILTER_NEAREST);\n"
25"kernel void horiz_sum(__global uint4 *integral_img,\n"
26" __read_only image2d_t src,\n"
33" int y = get_global_id(0);\n"
34" int work_size = get_global_size(0);\n"
36" uint4 sum = (uint4)(0);\n"
38" for (int i = 0; i < width; i++) {\n"
39" float s1 = read_imagef(src, sampler, (int2)(i, y)).x;\n"
40" s2.x = read_imagef(src, sampler, (int2)(i + dx.x, y + dy.x)).x;\n"
41" s2.y = read_imagef(src, sampler, (int2)(i + dx.y, y + dy.y)).x;\n"
42" s2.z = read_imagef(src, sampler, (int2)(i + dx.z, y + dy.z)).x;\n"
43" s2.w = read_imagef(src, sampler, (int2)(i + dx.w, y + dy.w)).x;\n"
44" sum += convert_uint4((s1 - s2) * (s1 - s2) * 255 * 255);\n"
45" integral_img[y * width + i] = sum;\n"
49"kernel void vert_sum(__global uint4 *integral_img,\n"
50" __global int *overflow,\n"
54" int x = get_global_id(0);\n"
56" for (int i = 0; i < height; i++) {\n"
57" if (any((uint4)UINT_MAX - integral_img[i * width + x] < sum))\n"
58" atomic_inc(overflow);\n"
59" integral_img[i * width + x] += sum;\n"
60" sum = integral_img[i * width + x];\n"
64"kernel void weight_accum(global float *sum, global float *weight,\n"
65" global uint4 *integral_img, __read_only image2d_t src,\n"
66" int width, int height, int p, float h,\n"
69" // w(x) = integral_img(x-p, y-p) +\n"
70" // integral_img(x+p, y+p) -\n"
71" // integral_img(x+p, y-p) -\n"
72" // integral_img(x-p, y+p)\n"
73" // total_sum[x] += w(x, y) * src(x + dx, y + dy)\n"
74" // total_weight += w(x, y)\n"
76" int x = get_global_id(0);\n"
77" int y = get_global_id(1);\n"
78" int4 xoff = x + dx;\n"
79" int4 yoff = y + dy;\n"
80" uint4 a = 0, b = 0, c = 0, d = 0;\n"
81" uint4 src_pix = 0;\n"
83" // out-of-bounding-box?\n"
84" int oobb = (x - p) < 0 || (y - p) < 0 || (y + p) >= height || (x + p) >= width;\n"
86" src_pix.x = (int)(255 * read_imagef(src, sampler, (int2)(xoff.x, yoff.x)).x);\n"
87" src_pix.y = (int)(255 * read_imagef(src, sampler, (int2)(xoff.y, yoff.y)).x);\n"
88" src_pix.z = (int)(255 * read_imagef(src, sampler, (int2)(xoff.z, yoff.z)).x);\n"
89" src_pix.w = (int)(255 * read_imagef(src, sampler, (int2)(xoff.w, yoff.w)).x);\n"
91" a = integral_img[(y - p) * width + x - p];\n"
92" b = integral_img[(y + p) * width + x - p];\n"
93" c = integral_img[(y - p) * width + x + p];\n"
94" d = integral_img[(y + p) * width + x + p];\n"
97" float4 patch_diff = convert_float4(d + a - c - b);\n"
98" float4 w = native_exp(-patch_diff / (h * h));\n"
99" float w_sum = w.x + w.y + w.z + w.w;\n"
100" weight[y * width + x] += w_sum;\n"
101" sum[y * width + x] += dot(w, convert_float4(src_pix));\n"
104"kernel void average(__write_only image2d_t dst,\n"
105" __read_only image2d_t src,\n"
106" global float *sum, global float *weight) {\n"
107" int x = get_global_id(0);\n"
108" int y = get_global_id(1);\n"
109" int2 dim = get_image_dim(dst);\n"
111" float w = weight[y * dim.x + x];\n"
112" float s = sum[y * dim.x + x];\n"
113" float src_pix = read_imagef(src, sampler, (int2)(x, y)).x;\n"
114" float r = (s + src_pix * 255) / (1.0f + w) / 255.0f;\n"
115" if (x < dim.x && y < dim.y)\n"
116" write_imagef(dst, (int2)(x, y), (float4)(r, 0.0f, 0.0f, 1.0f));\n"
const char * ff_source_nlmeans_cl