FFmpeg
Loading...
Searching...
No Matches
convolution.c
Go to the documentation of this file.
1// Generated from libavfilter/opencl/convolution.cl
3"/*\n"
4" * Copyright (c) 2018 Danil Iashchenko\n"
5" *\n"
6" * This file is part of FFmpeg.\n"
7" *\n"
8" * FFmpeg is free software; you can redistribute it and/or\n"
9" * modify it under the terms of the GNU Lesser General Public\n"
10" * License as published by the Free Software Foundation; either\n"
11" * version 2.1 of the License, or (at your option) any later version.\n"
12" *\n"
13" * FFmpeg is distributed in the hope that it will be useful,\n"
14" * but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
15" * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
16" * Lesser General Public License for more details.\n"
17" *\n"
18" * You should have received a copy of the GNU Lesser General Public\n"
19" * License along with FFmpeg; if not, write to the Free Software\n"
20" * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n"
21" */\n"
22"\n"
23"__kernel void convolution_global(__write_only image2d_t dst,\n"
24" __read_only image2d_t src,\n"
25" int coef_matrix_dim,\n"
26" __constant float *coef_matrix,\n"
27" float div,\n"
28" float bias)\n"
29"{\n"
30" const sampler_t sampler = (CLK_NORMALIZED_COORDS_FALSE |\n"
31" CLK_ADDRESS_CLAMP_TO_EDGE |\n"
32" CLK_FILTER_NEAREST);\n"
33"\n"
34" const int half_matrix_dim = (coef_matrix_dim / 2);\n"
35" int2 loc = (int2)(get_global_id(0), get_global_id(1));\n"
36" float4 convPix = (float4)(0.0f, 0.0f, 0.0f, 0.0f);\n"
37"\n"
38" for (int conv_i = -half_matrix_dim; conv_i <= half_matrix_dim; conv_i++) {\n"
39" for (int conv_j = -half_matrix_dim; conv_j <= half_matrix_dim; conv_j++) {\n"
40" float4 px = read_imagef(src, sampler, loc + (int2)(conv_j, conv_i));\n"
41" convPix += px * coef_matrix[(conv_i + half_matrix_dim) * coef_matrix_dim +\n"
42" (conv_j + half_matrix_dim)];\n"
43" }\n"
44" }\n"
45" float4 dstPix = convPix * div + bias;\n"
46" write_imagef(dst, loc, dstPix);\n"
47"}\n"
48"\n"
49"\n"
50"__kernel void sobel_global(__write_only image2d_t dst,\n"
51" __read_only image2d_t src,\n"
52" float div,\n"
53" float bias)\n"
54"{\n"
55" const sampler_t sampler = (CLK_NORMALIZED_COORDS_FALSE |\n"
56" CLK_ADDRESS_CLAMP_TO_EDGE |\n"
57" CLK_FILTER_NEAREST);\n"
58"\n"
59" int2 loc = (int2)(get_global_id(0), get_global_id(1));\n"
60"\n"
61" float4 sum1 = read_imagef(src, sampler, loc + (int2)(-1,-1)) * -1 +\n"
62" read_imagef(src, sampler, loc + (int2)( 0,-1)) * -2 +\n"
63" read_imagef(src, sampler, loc + (int2)( 1,-1)) * -1 +\n"
64" read_imagef(src, sampler, loc + (int2)(-1, 1)) * 1 +\n"
65" read_imagef(src, sampler, loc + (int2)( 0, 1)) * 2 +\n"
66" read_imagef(src, sampler, loc + (int2)( 1, 1)) * 1;\n"
67"\n"
68" float4 sum2 = read_imagef(src, sampler, loc + (int2)(-1,-1)) * -1 +\n"
69" read_imagef(src, sampler, loc + (int2)(-1, 0)) * -2 +\n"
70" read_imagef(src, sampler, loc + (int2)(-1, 1)) * -1 +\n"
71" read_imagef(src, sampler, loc + (int2)( 1,-1)) * 1 +\n"
72" read_imagef(src, sampler, loc + (int2)( 1, 0)) * 2 +\n"
73" read_imagef(src, sampler, loc + (int2)( 1, 1)) * 1;\n"
74"\n"
75" float4 dstPix = hypot(sum1, sum2) * div + bias;\n"
76" write_imagef(dst, loc, dstPix);\n"
77"}\n"
78"\n"
79"__kernel void prewitt_global(__write_only image2d_t dst,\n"
80" __read_only image2d_t src,\n"
81" float div,\n"
82" float bias)\n"
83"{\n"
84" const sampler_t sampler = (CLK_NORMALIZED_COORDS_FALSE |\n"
85" CLK_ADDRESS_CLAMP_TO_EDGE |\n"
86" CLK_FILTER_NEAREST);\n"
87"\n"
88" int2 loc = (int2)(get_global_id(0), get_global_id(1));\n"
89"\n"
90" float4 sum1 = read_imagef(src, sampler, loc + (int2)(-1,-1)) * 1 +\n"
91" read_imagef(src, sampler, loc + (int2)( 0,-1)) * 1 +\n"
92" read_imagef(src, sampler, loc + (int2)( 1,-1)) * 1 +\n"
93" read_imagef(src, sampler, loc + (int2)(-1, 1)) * -1 +\n"
94" read_imagef(src, sampler, loc + (int2)( 0, 1)) * -1 +\n"
95" read_imagef(src, sampler, loc + (int2)( 1, 1)) * -1;\n"
96"\n"
97" float4 sum2 = read_imagef(src, sampler, loc + (int2)(-1,-1)) * 1 +\n"
98" read_imagef(src, sampler, loc + (int2)(-1, 0)) * 1 +\n"
99" read_imagef(src, sampler, loc + (int2)(-1, 1)) * 1 +\n"
100" read_imagef(src, sampler, loc + (int2)( 1,-1)) * -1 +\n"
101" read_imagef(src, sampler, loc + (int2)( 1, 0)) * -1 +\n"
102" read_imagef(src, sampler, loc + (int2)( 1, 1)) * -1;\n"
103"\n"
104" float4 dstPix = hypot(sum1, sum2) * div + bias;\n"
105" write_imagef(dst, loc, dstPix);\n"
106"}\n"
107"\n"
108"__kernel void roberts_global(__write_only image2d_t dst,\n"
109" __read_only image2d_t src,\n"
110" float div,\n"
111" float bias)\n"
112"{\n"
113" const sampler_t sampler = (CLK_NORMALIZED_COORDS_FALSE |\n"
114" CLK_ADDRESS_CLAMP_TO_EDGE |\n"
115" CLK_FILTER_NEAREST);\n"
116"\n"
117" int2 loc = (int2)(get_global_id(0), get_global_id(1));\n"
118"\n"
119" float4 sum1 = read_imagef(src, sampler, loc + (int2)(-1,-1)) * 1 +\n"
120" read_imagef(src, sampler, loc + (int2)( 0,-1)) * -1;\n"
121"\n"
122"\n"
123" float4 sum2 = read_imagef(src, sampler, loc + (int2)(-1, 0)) * -1 +\n"
124" read_imagef(src, sampler, loc + (int2)( 0, 0)) * 1;\n"
125"\n"
126"\n"
127" float4 dstPix = hypot(sum1, sum2) * div + bias;\n"
128" write_imagef(dst, loc, dstPix);\n"
129"}\n"
130;
const char * ff_source_convolution_cl
Definition convolution.c:2