]> git.sesse.net Git - ffmpeg/blob - libavfilter/opencl/xfade.cl
avfilter/vf_psnr: remove unnecessary check
[ffmpeg] / libavfilter / opencl / xfade.cl
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18
19 const sampler_t sampler = (CLK_NORMALIZED_COORDS_FALSE |
20                            CLK_FILTER_NEAREST);
21
22 __kernel void fade(__write_only image2d_t dst,
23                    __read_only  image2d_t src1,
24                    __read_only  image2d_t src2,
25                    float progress)
26 {
27     int2  p = (int2)(get_global_id(0), get_global_id(1));
28
29     float4 val1 = read_imagef(src1, sampler, p);
30     float4 val2 = read_imagef(src2, sampler, p);
31
32     write_imagef(dst, p, mix(val2, val1, progress));
33 }
34
35 __kernel void wipeleft(__write_only image2d_t dst,
36                        __read_only  image2d_t src1,
37                        __read_only  image2d_t src2,
38                        float progress)
39 {
40     int   s = (int)(get_image_dim(src1).x * progress);
41     int2  p = (int2)(get_global_id(0), get_global_id(1));
42
43     float4 val1 = read_imagef(src1, sampler, p);
44     float4 val2 = read_imagef(src2, sampler, p);
45
46     write_imagef(dst, p, p.x > s ? val2 : val1);
47 }
48
49 __kernel void wiperight(__write_only image2d_t dst,
50                         __read_only  image2d_t src1,
51                         __read_only  image2d_t src2,
52                         float progress)
53 {
54     int   s = (int)(get_image_dim(src1).x * (1.f - progress));
55     int2  p = (int2)(get_global_id(0), get_global_id(1));
56
57     float4 val1 = read_imagef(src1, sampler, p);
58     float4 val2 = read_imagef(src2, sampler, p);
59
60     write_imagef(dst, p, p.x > s ? val1 : val2);
61 }
62
63 __kernel void wipeup(__write_only image2d_t dst,
64                      __read_only  image2d_t src1,
65                      __read_only  image2d_t src2,
66                      float progress)
67 {
68     int   s = (int)(get_image_dim(src1).y * progress);
69     int2  p = (int2)(get_global_id(0), get_global_id(1));
70
71     float4 val1 = read_imagef(src1, sampler, p);
72     float4 val2 = read_imagef(src2, sampler, p);
73
74     write_imagef(dst, p, p.y > s ? val2 : val1);
75 }
76
77 __kernel void wipedown(__write_only image2d_t dst,
78                        __read_only  image2d_t src1,
79                        __read_only  image2d_t src2,
80                        float progress)
81 {
82     int   s = (int)(get_image_dim(src1).y * (1.f - progress));
83     int2  p = (int2)(get_global_id(0), get_global_id(1));
84
85     float4 val1 = read_imagef(src1, sampler, p);
86     float4 val2 = read_imagef(src2, sampler, p);
87
88     write_imagef(dst, p, p.y > s ? val1 : val2);
89 }
90
91 void slide(__write_only image2d_t dst,
92            __read_only  image2d_t src1,
93            __read_only  image2d_t src2,
94            float progress,
95            int2 direction)
96 {
97     int   w = get_image_dim(src1).x;
98     int   h = get_image_dim(src1).y;
99     int2 wh = (int2)(w, h);
100     int2 uv = (int2)(get_global_id(0), get_global_id(1));
101     int2 pi = (int2)(progress * w, progress * h);
102     int2 p = uv + pi * direction;
103     int2 f = p % wh;
104
105     f = f + (int2)(w, h) * (int2)(f.x < 0, f.y < 0);
106     float4 val1 = read_imagef(src1, sampler, f);
107     float4 val2 = read_imagef(src2, sampler, f);
108     write_imagef(dst, uv, mix(val1, val2, (p.y >= 0) * (h > p.y) * (p.x >= 0) * (w > p.x)));
109 }
110
111 __kernel void slidedown(__write_only image2d_t dst,
112                         __read_only  image2d_t src1,
113                         __read_only  image2d_t src2,
114                         float progress)
115 {
116     int2 direction = (int2)(0, 1);
117     slide(dst, src1, src2, progress, direction);
118 }
119
120 __kernel void slideup(__write_only image2d_t dst,
121                       __read_only  image2d_t src1,
122                       __read_only  image2d_t src2,
123                       float progress)
124 {
125     int2 direction = (int2)(0, -1);
126     slide(dst, src1, src2, progress, direction);
127 }
128
129 __kernel void slideleft(__write_only image2d_t dst,
130                         __read_only  image2d_t src1,
131                         __read_only  image2d_t src2,
132                         float progress)
133 {
134     int2 direction = (int2)(-1, 0);
135     slide(dst, src1, src2, progress, direction);
136 }
137
138 __kernel void slideright(__write_only image2d_t dst,
139                          __read_only  image2d_t src1,
140                          __read_only  image2d_t src2,
141                          float progress)
142 {
143     int2 direction = (int2)(1, 0);
144     slide(dst, src1, src2, progress, direction);
145 }