]> git.sesse.net Git - ffmpeg/blob - libavfilter/opencl/neighbor.cl
avfilter/vf_psnr: remove unnecessary check
[ffmpeg] / libavfilter / opencl / neighbor.cl
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
22 __kernel void erosion_global(__write_only image2d_t dst,
23                              __read_only  image2d_t src,
24                              float threshold,
25                              __constant int *coord)
26 {
27     const sampler_t sampler = (CLK_NORMALIZED_COORDS_FALSE |
28                                CLK_ADDRESS_CLAMP_TO_EDGE   |
29                                CLK_FILTER_NEAREST);
30
31     int2 loc = (int2)(get_global_id(0), get_global_id(1));
32
33     float4 px = read_imagef(src, sampler, loc);
34     float limit = px.x - threshold;
35     if (limit < 0) {
36         limit = 0;
37     }
38
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));
43                 if (cur.x < px.x) {
44                     px = cur;
45                 }
46             }
47         }
48     }
49     if (limit > px.x) {
50         px = (float4)(limit);
51     }
52     write_imagef(dst, loc, px);
53 }
54
55
56 __kernel void dilation_global(__write_only image2d_t dst,
57                               __read_only  image2d_t src,
58                               float threshold,
59                               __constant int *coord)
60 {
61     const sampler_t sampler = (CLK_NORMALIZED_COORDS_FALSE |
62                                CLK_ADDRESS_CLAMP_TO_EDGE   |
63                                CLK_FILTER_NEAREST);
64
65     int2 loc = (int2)(get_global_id(0), get_global_id(1));
66
67     float4 px = read_imagef(src, sampler, loc);
68     float limit = px.x + threshold;
69     if (limit > 1) {
70         limit = 1;
71     }
72
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));
77                 if (cur.x > px.x) {
78                     px = cur;
79                 }
80             }
81         }
82     }
83     if (limit < px.x) {
84         px = (float4)(limit);
85     }
86     write_imagef(dst, loc, px);
87 }