1 /*
2 * Copyright (c) 2018 Danil Iashchenko
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include "config_components.h"
22
28
29
35
38
42
44
48
50
52 {
54 const char *kernel_name;
55 cl_int cle;
56 int err;
57
59 if (err < 0)
61
62 ctx->command_queue = clCreateCommandQueue(
ctx->ocf.hwctx->context,
63 ctx->ocf.hwctx->device_id,
64 0, &cle);
66 "command queue %d.\n", cle);
67
68 if (!strcmp(avctx->
filter->
name,
"erosion_opencl")){
69 kernel_name = "erosion_global";
70 }
else if (!strcmp(avctx->
filter->
name,
"dilation_opencl")){
71 kernel_name = "dilation_global";
72 }
73 ctx->kernel = clCreateKernel(
ctx->ocf.program, kernel_name, &cle);
75 "kernel %d.\n", cle);
76
78 return 0;
79
81 if (
ctx->command_queue)
82 clReleaseCommandQueue(
ctx->command_queue);
84 clReleaseKernel(
ctx->kernel);
85 return err;
86 }
87
89 {
93 cl_int cle;
95
97 ctx->threshold[
i] /= 255.0;
98 }
99
101 for (
i = 0;
i < 8;
i++) {
102 if (
ctx->coordinates & (1 <<
i)) {
104 }
105 }
106 buffer = clCreateBuffer(
ctx->ocf.hwctx->context,
107 CL_MEM_READ_ONLY |
108 CL_MEM_COPY_HOST_PTR |
109 CL_MEM_HOST_NO_ACCESS,
110 9 *
sizeof(cl_int),
matrix, &cle);
113 "%d.\n", cle);
115 }
117
118 return 0;
119 }
120
121
123 {
128 cl_int cle;
129 size_t global_work[2];
132 size_t origin[3] = {0, 0, 0};
133 size_t region[3] = {0, 0, 1};
134
138
139 if (!
input->hw_frames_ctx)
141
142 if (!
ctx->initialised) {
144 if (err < 0)
146
148 if (err < 0)
150
151 }
152
157 }
158
162
164 break;
165
166 if (
ctx->threshold[
p] == 0) {
168 if (err < 0)
170
171 cle = clEnqueueCopyImage(
ctx->command_queue,
src,
dst,
172 origin, origin, region, 0,
NULL,
NULL);
175 } else {
180
182 if (err < 0)
184
187 p, global_work[0], global_work[1]);
188
189 cle = clEnqueueNDRangeKernel(
ctx->command_queue,
ctx->kernel, 2,
NULL,
193 "kernel: %d.\n", cle);
194 }
195 }
196
197 cle = clFinish(
ctx->command_queue);
199
201 if (err < 0)
203
205
209
211
213 clFinish(
ctx->command_queue);
216 return err;
217 }
218
220 {
222 cl_int cle;
223
224 clReleaseMemObject(
ctx->coord);
225
227 cle = clReleaseKernel(
ctx->kernel);
228 if (cle != CL_SUCCESS)
230 "kernel: %d.\n", cle);
231 }
232
233 if (
ctx->command_queue) {
234 cle = clReleaseCommandQueue(
ctx->command_queue);
235 if (cle != CL_SUCCESS)
237 "command queue: %d.\n", cle);
238 }
239
241 }
242
244 {
249 },
250 };
251
253 {
257 },
258 };
259
260 #define OFFSET(x) offsetof(NeighborOpenCLContext, x)
261 #define FLAGS (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
262
263 #if CONFIG_EROSION_OPENCL_FILTER
264
265 static const AVOption erosion_opencl_options[] = {
272 };
273
275
277 .
p.
name =
"erosion_opencl",
279 .p.priv_class = &erosion_opencl_class,
287 };
288
289 #endif /* CONFIG_EROSION_OPENCL_FILTER */
290
291 #if CONFIG_DILATION_OPENCL_FILTER
292
293 static const AVOption dilation_opencl_options[] = {
300 };
301
303
305 .
p.
name =
"dilation_opencl",
307 .p.priv_class = &dilation_opencl_class,
316 };
317
318 #endif /* CONFIG_DILATION_OPENCL_FILTER */