]> git.sesse.net Git - ffmpeg/blob - libavfilter/vf_overlay_cuda.cu
avformat/avio: Add Metacube support
[ffmpeg] / libavfilter / vf_overlay_cuda.cu
1 /*
2  * Copyright (c) 2020 Yaroslav Pogrebnyak <yyyaroslav@gmail.com>
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 extern "C" {
22
23 __global__ void Overlay_Cuda(
24     int x_position, int y_position,
25     unsigned char* main, int main_linesize,
26     unsigned char* overlay, int overlay_linesize,
27     int overlay_w, int overlay_h,
28     unsigned char* overlay_alpha, int alpha_linesize,
29     int alpha_adj_x, int alpha_adj_y)
30 {
31     int x = blockIdx.x * blockDim.x + threadIdx.x;
32     int y = blockIdx.y * blockDim.y + threadIdx.y;
33
34     if (x >= overlay_w + x_position ||
35         y >= overlay_h + y_position ||
36         x < x_position ||
37         y < y_position ) {
38
39         return;
40     }
41
42     int overlay_x = x - x_position;
43     int overlay_y = y - y_position;
44
45     float alpha = 1.0;
46     if (alpha_linesize) {
47         alpha = overlay_alpha[alpha_adj_x * overlay_x  + alpha_adj_y * overlay_y * alpha_linesize] / 255.0f;
48     }
49
50     main[x + y*main_linesize] = alpha * overlay[overlay_x + overlay_y * overlay_linesize] + (1.0f - alpha) * main[x + y*main_linesize];
51 }
52
53 }
54