2 * Copyright (c) 2018 Danil Iashchenko
4 * This file is part of FFmpeg.
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.
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.
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
22 __kernel void erosion_global(__write_only image2d_t dst,
23 __read_only image2d_t src,
25 __constant int *coord)
27 const sampler_t sampler = (CLK_NORMALIZED_COORDS_FALSE |
28 CLK_ADDRESS_CLAMP_TO_EDGE |
31 int2 loc = (int2)(get_global_id(0), get_global_id(1));
33 float4 px = read_imagef(src, sampler, loc);
34 float limit = px.x - threshold;
39 for (int i = -1; i <= 1; i++) {
40 for (int j = -1; j <= 1; j++) {
41 if (coord[(j + 1) * 3 + (i + 1)] == 1) {
42 float4 cur = read_imagef(src, sampler, loc + (int2)(i, j));
52 write_imagef(dst, loc, px);
56 __kernel void dilation_global(__write_only image2d_t dst,
57 __read_only image2d_t src,
59 __constant int *coord)
61 const sampler_t sampler = (CLK_NORMALIZED_COORDS_FALSE |
62 CLK_ADDRESS_CLAMP_TO_EDGE |
65 int2 loc = (int2)(get_global_id(0), get_global_id(1));
67 float4 px = read_imagef(src, sampler, loc);
68 float limit = px.x + threshold;
73 for (int i = -1; i <= 1; i++) {
74 for (int j = -1; j <= 1; j++) {
75 if (coord[(j + 1) * 3 + (i + 1)] == 1) {
76 float4 cur = read_imagef(src, sampler, loc + (int2)(i, j));
86 write_imagef(dst, loc, px);