• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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__kernel void overlay_no_alpha(__write_only image2d_t dst,
20                               __read_only  image2d_t main,
21                               __read_only  image2d_t overlay,
22                               int x_position,
23                               int y_position)
24{
25    const sampler_t sampler = (CLK_NORMALIZED_COORDS_FALSE |
26                               CLK_FILTER_NEAREST);
27
28    int2 overlay_size = get_image_dim(overlay);
29    int2 loc = (int2)(get_global_id(0), get_global_id(1));
30
31    if (loc.x <  x_position ||
32        loc.y <  y_position ||
33        loc.x >= overlay_size.x + x_position ||
34        loc.y >= overlay_size.y + y_position) {
35        float4 val = read_imagef(main, sampler, loc);
36        write_imagef(dst, loc, val);
37    } else {
38        int2 loc_overlay = (int2)(x_position, y_position);
39        float4 val       = read_imagef(overlay, sampler, loc - loc_overlay);
40        write_imagef(dst, loc, val);
41    }
42}
43
44__kernel void overlay_internal_alpha(__write_only image2d_t dst,
45                                     __read_only  image2d_t main,
46                                     __read_only  image2d_t overlay,
47                                     int x_position,
48                                     int y_position)
49{
50    const sampler_t sampler = (CLK_NORMALIZED_COORDS_FALSE |
51                               CLK_FILTER_NEAREST);
52
53    int2 overlay_size = get_image_dim(overlay);
54    int2 loc = (int2)(get_global_id(0), get_global_id(1));
55
56    if (loc.x <  x_position ||
57        loc.y <  y_position ||
58        loc.x >= overlay_size.x + x_position ||
59        loc.y >= overlay_size.y + y_position) {
60        float4 val = read_imagef(main, sampler, loc);
61        write_imagef(dst, loc, val);
62    } else {
63        int2 loc_overlay  = (int2)(x_position, y_position);
64        float4 in_main    = read_imagef(main,    sampler, loc);
65        float4 in_overlay = read_imagef(overlay, sampler, loc - loc_overlay);
66        float4 val        = in_overlay * in_overlay.w + in_main * (1.0f - in_overlay.w);
67        write_imagef(dst, loc, val);
68    }
69}
70
71__kernel void overlay_external_alpha(__write_only image2d_t dst,
72                                     __read_only  image2d_t main,
73                                     __read_only  image2d_t overlay,
74                                     __read_only  image2d_t alpha,
75                                     int x_position,
76                                     int y_position,
77                                     int alpha_adj_x,
78                                     int alpha_adj_y)
79{
80    const sampler_t sampler = (CLK_NORMALIZED_COORDS_FALSE |
81                               CLK_FILTER_NEAREST);
82
83    int2 overlay_size = get_image_dim(overlay);
84    int2 loc = (int2)(get_global_id(0), get_global_id(1));
85
86    if (loc.x <  x_position ||
87        loc.y <  y_position ||
88        loc.x >= overlay_size.x + x_position ||
89        loc.y >= overlay_size.y + y_position) {
90        float4 val = read_imagef(main, sampler, loc);
91        write_imagef(dst, loc, val);
92    } else {
93        int2 loc_overlay  = (int2)(x_position, y_position);
94        float4 in_main    = read_imagef(main,    sampler, loc);
95        float4 in_overlay = read_imagef(overlay, sampler, loc - loc_overlay);
96
97        int2 loc_alpha    = (int2)(loc.x * alpha_adj_x,
98                                   loc.y * alpha_adj_y) - loc_overlay;
99        float4 in_alpha   = read_imagef(alpha,   sampler, loc_alpha);
100
101        float4 val = in_overlay * in_alpha.x + in_main * (1.0f - in_alpha.x);
102        write_imagef(dst, loc, val);
103    }
104}
105