2 * Copyright (c) 2020 Yaroslav Pogrebnyak <yyyaroslav@gmail.com>
4 * This file is part of FFmpeg.
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.
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.
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
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)
31 int x = blockIdx.x * blockDim.x + threadIdx.x;
32 int y = blockIdx.y * blockDim.y + threadIdx.y;
34 if (x >= overlay_w + x_position ||
35 y >= overlay_h + y_position ||
42 int overlay_x = x - x_position;
43 int overlay_y = y - y_position;
47 alpha = overlay_alpha[alpha_adj_x * overlay_x + alpha_adj_y * overlay_y * alpha_linesize] / 255.0f;
50 main[x + y*main_linesize] = alpha * overlay[overlay_x + overlay_y * overlay_linesize] + (1.0f - alpha) * main[x + y*main_linesize];