avformat/mxfdec: Check edit unit for overflow in mxf_set_current_edit_unit()
[FFMpeg-mirror.git] / libavfilter / opencl / overlay.cl
blob8c783d0edceef849203d63a9dac30846a4e1232a
1 /*
2 * This file is part of FFmpeg.
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.
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.
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
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)
25 const sampler_t sampler = (CLK_NORMALIZED_COORDS_FALSE |
26 CLK_FILTER_NEAREST);
28 int2 overlay_size = get_image_dim(overlay);
29 int2 loc = (int2)(get_global_id(0), get_global_id(1));
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);
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)
50 const sampler_t sampler = (CLK_NORMALIZED_COORDS_FALSE |
51 CLK_FILTER_NEAREST);
53 int2 overlay_size = get_image_dim(overlay);
54 int2 loc = (int2)(get_global_id(0), get_global_id(1));
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);
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)
80 const sampler_t sampler = (CLK_NORMALIZED_COORDS_FALSE |
81 CLK_FILTER_NEAREST);
83 int2 overlay_size = get_image_dim(overlay);
84 int2 loc = (int2)(get_global_id(0), get_global_id(1));
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);
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);
101 float4 val = in_overlay * in_alpha.x + in_main * (1.0f - in_alpha.x);
102 write_imagef(dst, loc, val);