FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavfilter/vf_blend.c
Date: 2022-12-09 07:38:14
Exec Total Coverage
Lines: 95 141 67.4%
Functions: 7 15 46.7%
Branches: 30 80 37.5%

Line Branch Exec Source
1 /*
2 * Copyright (c) 2013 Paul B Mahol
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 #include "config_components.h"
22
23 #include "libavutil/eval.h"
24 #include "libavutil/opt.h"
25 #include "libavutil/pixfmt.h"
26 #include "avfilter.h"
27 #include "framesync.h"
28 #include "internal.h"
29 #include "vf_blend_init.h"
30 #include "video.h"
31 #include "blend.h"
32
33 #define TOP 0
34 #define BOTTOM 1
35
36 typedef struct BlendContext {
37 const AVClass *class;
38 FFFrameSync fs;
39 int hsub, vsub; ///< chroma subsampling values
40 int nb_planes;
41 char *all_expr;
42 enum BlendMode all_mode;
43 double all_opacity;
44
45 int depth;
46 FilterParams params[4];
47 int tblend;
48 AVFrame *prev_frame; /* only used with tblend */
49 } BlendContext;
50
51 static const char *const var_names[] = { "X", "Y", "W", "H", "SW", "SH", "T", "N", "A", "B", "TOP", "BOTTOM", NULL };
52 enum { VAR_X, VAR_Y, VAR_W, VAR_H, VAR_SW, VAR_SH, VAR_T, VAR_N, VAR_A, VAR_B, VAR_TOP, VAR_BOTTOM, VAR_VARS_NB };
53
54 typedef struct ThreadData {
55 const AVFrame *top, *bottom;
56 AVFrame *dst;
57 AVFilterLink *inlink;
58 int plane;
59 int w, h;
60 FilterParams *param;
61 } ThreadData;
62
63 #define OFFSET(x) offsetof(BlendContext, x)
64 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
65
66 static const AVOption blend_options[] = {
67 { "c0_mode", "set component #0 blend mode", OFFSET(params[0].mode), AV_OPT_TYPE_INT, {.i64=0}, 0, BLEND_NB-1, FLAGS, "mode" },
68 { "c1_mode", "set component #1 blend mode", OFFSET(params[1].mode), AV_OPT_TYPE_INT, {.i64=0}, 0, BLEND_NB-1, FLAGS, "mode" },
69 { "c2_mode", "set component #2 blend mode", OFFSET(params[2].mode), AV_OPT_TYPE_INT, {.i64=0}, 0, BLEND_NB-1, FLAGS, "mode" },
70 { "c3_mode", "set component #3 blend mode", OFFSET(params[3].mode), AV_OPT_TYPE_INT, {.i64=0}, 0, BLEND_NB-1, FLAGS, "mode" },
71 { "all_mode", "set blend mode for all components", OFFSET(all_mode), AV_OPT_TYPE_INT, {.i64=-1},-1, BLEND_NB-1, FLAGS, "mode" },
72 { "addition", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_ADDITION}, 0, 0, FLAGS, "mode" },
73 { "addition128","", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_GRAINMERGE}, 0, 0, FLAGS, "mode" },
74 { "grainmerge", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_GRAINMERGE}, 0, 0, FLAGS, "mode" },
75 { "and", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_AND}, 0, 0, FLAGS, "mode" },
76 { "average", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_AVERAGE}, 0, 0, FLAGS, "mode" },
77 { "burn", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_BURN}, 0, 0, FLAGS, "mode" },
78 { "darken", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_DARKEN}, 0, 0, FLAGS, "mode" },
79 { "difference", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_DIFFERENCE}, 0, 0, FLAGS, "mode" },
80 { "difference128", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_GRAINEXTRACT}, 0, 0, FLAGS, "mode" },
81 { "grainextract", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_GRAINEXTRACT}, 0, 0, FLAGS, "mode" },
82 { "divide", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_DIVIDE}, 0, 0, FLAGS, "mode" },
83 { "dodge", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_DODGE}, 0, 0, FLAGS, "mode" },
84 { "exclusion", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_EXCLUSION}, 0, 0, FLAGS, "mode" },
85 { "extremity", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_EXTREMITY}, 0, 0, FLAGS, "mode" },
86 { "freeze", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_FREEZE}, 0, 0, FLAGS, "mode" },
87 { "glow", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_GLOW}, 0, 0, FLAGS, "mode" },
88 { "hardlight", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_HARDLIGHT}, 0, 0, FLAGS, "mode" },
89 { "hardmix", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_HARDMIX}, 0, 0, FLAGS, "mode" },
90 { "heat", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_HEAT}, 0, 0, FLAGS, "mode" },
91 { "lighten", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_LIGHTEN}, 0, 0, FLAGS, "mode" },
92 { "linearlight","", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_LINEARLIGHT},0, 0, FLAGS, "mode" },
93 { "multiply", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_MULTIPLY}, 0, 0, FLAGS, "mode" },
94 { "multiply128","", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_MULTIPLY128},0, 0, FLAGS, "mode" },
95 { "negation", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_NEGATION}, 0, 0, FLAGS, "mode" },
96 { "normal", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_NORMAL}, 0, 0, FLAGS, "mode" },
97 { "or", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_OR}, 0, 0, FLAGS, "mode" },
98 { "overlay", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_OVERLAY}, 0, 0, FLAGS, "mode" },
99 { "phoenix", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_PHOENIX}, 0, 0, FLAGS, "mode" },
100 { "pinlight", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_PINLIGHT}, 0, 0, FLAGS, "mode" },
101 { "reflect", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_REFLECT}, 0, 0, FLAGS, "mode" },
102 { "screen", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_SCREEN}, 0, 0, FLAGS, "mode" },
103 { "softlight", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_SOFTLIGHT}, 0, 0, FLAGS, "mode" },
104 { "subtract", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_SUBTRACT}, 0, 0, FLAGS, "mode" },
105 { "vividlight", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_VIVIDLIGHT}, 0, 0, FLAGS, "mode" },
106 { "xor", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_XOR}, 0, 0, FLAGS, "mode" },
107 { "softdifference","", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_SOFTDIFFERENCE}, 0, 0, FLAGS, "mode" },
108 { "geometric", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_GEOMETRIC}, 0, 0, FLAGS, "mode" },
109 { "harmonic", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_HARMONIC}, 0, 0, FLAGS, "mode" },
110 { "bleach", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_BLEACH}, 0, 0, FLAGS, "mode" },
111 { "stain", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_STAIN}, 0, 0, FLAGS, "mode" },
112 { "interpolate","", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_INTERPOLATE},0, 0, FLAGS, "mode" },
113 { "hardoverlay","", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_HARDOVERLAY},0, 0, FLAGS, "mode" },
114 { "c0_expr", "set color component #0 expression", OFFSET(params[0].expr_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
115 { "c1_expr", "set color component #1 expression", OFFSET(params[1].expr_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
116 { "c2_expr", "set color component #2 expression", OFFSET(params[2].expr_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
117 { "c3_expr", "set color component #3 expression", OFFSET(params[3].expr_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
118 { "all_expr", "set expression for all color components", OFFSET(all_expr), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
119 { "c0_opacity", "set color component #0 opacity", OFFSET(params[0].opacity), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS },
120 { "c1_opacity", "set color component #1 opacity", OFFSET(params[1].opacity), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS },
121 { "c2_opacity", "set color component #2 opacity", OFFSET(params[2].opacity), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS },
122 { "c3_opacity", "set color component #3 opacity", OFFSET(params[3].opacity), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS },
123 { "all_opacity", "set opacity for all color components", OFFSET(all_opacity), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS },
124 { NULL }
125 };
126
127 FRAMESYNC_DEFINE_CLASS(blend, BlendContext, fs);
128
129 #define DEFINE_BLEND_EXPR(type, name, div) \
130 static void blend_expr_## name(const uint8_t *_top, ptrdiff_t top_linesize, \
131 const uint8_t *_bottom, ptrdiff_t bottom_linesize, \
132 uint8_t *_dst, ptrdiff_t dst_linesize, \
133 ptrdiff_t width, ptrdiff_t height, \
134 FilterParams *param, double *values, int starty) \
135 { \
136 const type *top = (type*)_top; \
137 const type *bottom = (type*)_bottom; \
138 type *dst = (type*)_dst; \
139 AVExpr *e = param->e; \
140 int y, x; \
141 dst_linesize /= div; \
142 top_linesize /= div; \
143 bottom_linesize /= div; \
144 \
145 for (y = 0; y < height; y++) { \
146 values[VAR_Y] = y + starty; \
147 for (x = 0; x < width; x++) { \
148 values[VAR_X] = x; \
149 values[VAR_TOP] = values[VAR_A] = top[x]; \
150 values[VAR_BOTTOM] = values[VAR_B] = bottom[x]; \
151 dst[x] = av_expr_eval(e, values, NULL); \
152 } \
153 dst += dst_linesize; \
154 top += top_linesize; \
155 bottom += bottom_linesize; \
156 } \
157 }
158
159 DEFINE_BLEND_EXPR(uint8_t, 8bit, 1)
160 DEFINE_BLEND_EXPR(uint16_t, 16bit, 2)
161 DEFINE_BLEND_EXPR(float, 32bit, 4)
162
163 1323 static int filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
164 {
165 1323 ThreadData *td = arg;
166 1323 int slice_start = (td->h * jobnr ) / nb_jobs;
167 1323 int slice_end = (td->h * (jobnr+1)) / nb_jobs;
168 1323 int height = slice_end - slice_start;
169 1323 const uint8_t *top = td->top->data[td->plane];
170 1323 const uint8_t *bottom = td->bottom->data[td->plane];
171 1323 uint8_t *dst = td->dst->data[td->plane];
172 double values[VAR_VARS_NB];
173
174 1323 values[VAR_N] = td->inlink->frame_count_out;
175
1/2
✓ Branch 0 taken 1323 times.
✗ Branch 1 not taken.
1323 values[VAR_T] = td->dst->pts == AV_NOPTS_VALUE ? NAN : td->dst->pts * av_q2d(td->inlink->time_base);
176 1323 values[VAR_W] = td->w;
177 1323 values[VAR_H] = td->h;
178 1323 values[VAR_SW] = td->w / (double)td->dst->width;
179 1323 values[VAR_SH] = td->h / (double)td->dst->height;
180
181 1323 td->param->blend(top + slice_start * td->top->linesize[td->plane],
182 1323 td->top->linesize[td->plane],
183 1323 bottom + slice_start * td->bottom->linesize[td->plane],
184 1323 td->bottom->linesize[td->plane],
185 1323 dst + slice_start * td->dst->linesize[td->plane],
186 1323 td->dst->linesize[td->plane],
187 1323 td->w, height, td->param, &values[0], slice_start);
188 1323 return 0;
189 }
190
191 49 static AVFrame *blend_frame(AVFilterContext *ctx, AVFrame *top_buf,
192 const AVFrame *bottom_buf)
193 {
194 49 BlendContext *s = ctx->priv;
195 49 AVFilterLink *inlink = ctx->inputs[0];
196 49 AVFilterLink *outlink = ctx->outputs[0];
197 AVFrame *dst_buf;
198 int plane;
199
200 49 dst_buf = ff_get_video_buffer(outlink, outlink->w, outlink->h);
201
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 49 times.
49 if (!dst_buf)
202 return top_buf;
203
204
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 49 times.
49 if (av_frame_copy_props(dst_buf, top_buf) < 0) {
205 av_frame_free(&dst_buf);
206 return top_buf;
207 }
208
209
2/2
✓ Branch 0 taken 147 times.
✓ Branch 1 taken 49 times.
196 for (plane = 0; plane < s->nb_planes; plane++) {
210
4/4
✓ Branch 0 taken 98 times.
✓ Branch 1 taken 49 times.
✓ Branch 2 taken 49 times.
✓ Branch 3 taken 49 times.
147 int hsub = plane == 1 || plane == 2 ? s->hsub : 0;
211
4/4
✓ Branch 0 taken 98 times.
✓ Branch 1 taken 49 times.
✓ Branch 2 taken 49 times.
✓ Branch 3 taken 49 times.
147 int vsub = plane == 1 || plane == 2 ? s->vsub : 0;
212 147 int outw = AV_CEIL_RSHIFT(dst_buf->width, hsub);
213 147 int outh = AV_CEIL_RSHIFT(dst_buf->height, vsub);
214 147 FilterParams *param = &s->params[plane];
215 147 ThreadData td = { .top = top_buf, .bottom = bottom_buf, .dst = dst_buf,
216 .w = outw, .h = outh, .param = param, .plane = plane,
217 .inlink = inlink };
218
219 147 ff_filter_execute(ctx, filter_slice, &td, NULL,
220
1/2
✓ Branch 0 taken 147 times.
✗ Branch 1 not taken.
147 FFMIN(outh, ff_filter_get_nb_threads(ctx)));
221 }
222
223
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 49 times.
49 if (!s->tblend)
224 av_frame_free(&top_buf);
225
226 49 return dst_buf;
227 }
228
229 static int blend_frame_for_dualinput(FFFrameSync *fs)
230 {
231 AVFilterContext *ctx = fs->parent;
232 AVFrame *top_buf, *bottom_buf, *dst_buf;
233 int ret;
234
235 ret = ff_framesync_dualinput_get(fs, &top_buf, &bottom_buf);
236 if (ret < 0)
237 return ret;
238 if (!bottom_buf)
239 return ff_filter_frame(ctx->outputs[0], top_buf);
240 dst_buf = blend_frame(ctx, top_buf, bottom_buf);
241 return ff_filter_frame(ctx->outputs[0], dst_buf);
242 }
243
244 1 static av_cold int init(AVFilterContext *ctx)
245 {
246 1 BlendContext *s = ctx->priv;
247
248 1 s->tblend = !strcmp(ctx->filter->name, "tblend");
249
250 1 s->fs.on_event = blend_frame_for_dualinput;
251 1 return 0;
252 }
253
254 static const enum AVPixelFormat pix_fmts[] = {
255 AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUVA420P,
256 AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_YUVJ440P, AV_PIX_FMT_YUVJ422P,AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVJ411P,
257 AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV440P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV411P, AV_PIX_FMT_YUV410P,
258 AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP, AV_PIX_FMT_GRAY8,
259 AV_PIX_FMT_YUV420P9, AV_PIX_FMT_YUV422P9, AV_PIX_FMT_YUV444P9,
260 AV_PIX_FMT_YUVA420P9, AV_PIX_FMT_YUVA422P9, AV_PIX_FMT_YUVA444P9, AV_PIX_FMT_GBRP9, AV_PIX_FMT_GRAY9,
261 AV_PIX_FMT_YUV420P10, AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV444P10, AV_PIX_FMT_YUV440P10,
262 AV_PIX_FMT_YUVA420P10, AV_PIX_FMT_YUVA422P10, AV_PIX_FMT_YUVA444P10,
263 AV_PIX_FMT_GBRP10, AV_PIX_FMT_GBRAP10, AV_PIX_FMT_GRAY10,
264 AV_PIX_FMT_YUV420P12, AV_PIX_FMT_YUV422P12, AV_PIX_FMT_YUV444P12, AV_PIX_FMT_YUV440P12,
265 AV_PIX_FMT_YUVA422P12, AV_PIX_FMT_YUVA444P12,
266 AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRAP12, AV_PIX_FMT_GRAY12,
267 AV_PIX_FMT_YUV420P14, AV_PIX_FMT_YUV422P14, AV_PIX_FMT_YUV444P14, AV_PIX_FMT_GBRP14,
268 AV_PIX_FMT_YUV420P16, AV_PIX_FMT_YUV422P16, AV_PIX_FMT_YUV444P16,
269 AV_PIX_FMT_YUVA420P16, AV_PIX_FMT_YUVA422P16, AV_PIX_FMT_YUVA444P16,
270 AV_PIX_FMT_GBRP16, AV_PIX_FMT_GBRAP16, AV_PIX_FMT_GRAY16,
271 AV_PIX_FMT_GBRPF32, AV_PIX_FMT_GBRAPF32, AV_PIX_FMT_GRAYF32,
272 AV_PIX_FMT_NONE
273 };
274
275 1 static av_cold void uninit(AVFilterContext *ctx)
276 {
277 1 BlendContext *s = ctx->priv;
278 int i;
279
280 1 ff_framesync_uninit(&s->fs);
281 1 av_frame_free(&s->prev_frame);
282
283
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
5 for (i = 0; i < FF_ARRAY_ELEMS(s->params); i++)
284 4 av_expr_free(s->params[i].e);
285 1 }
286
287 1 static int config_params(AVFilterContext *ctx)
288 {
289 1 BlendContext *s = ctx->priv;
290 int ret;
291
292
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
5 for (int plane = 0; plane < FF_ARRAY_ELEMS(s->params); plane++) {
293 4 FilterParams *param = &s->params[plane];
294
295
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (s->all_mode >= 0)
296 4 param->mode = s->all_mode;
297
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (s->all_opacity < 1)
298 param->opacity = s->all_opacity;
299
300 4 ff_blend_init(param, s->depth);
301
302
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
4 if (s->all_expr && !param->expr_str) {
303 param->expr_str = av_strdup(s->all_expr);
304 if (!param->expr_str)
305 return AVERROR(ENOMEM);
306 }
307
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (param->expr_str) {
308 ret = av_expr_parse(&param->e, param->expr_str, var_names,
309 NULL, NULL, NULL, NULL, 0, ctx);
310 if (ret < 0)
311 return ret;
312 param->blend = s->depth > 8 ? s->depth > 16 ? blend_expr_32bit : blend_expr_16bit : blend_expr_8bit;
313 }
314 }
315
316 1 return 0;
317 }
318
319 1 static int config_output(AVFilterLink *outlink)
320 {
321 1 AVFilterContext *ctx = outlink->src;
322 1 AVFilterLink *toplink = ctx->inputs[TOP];
323 1 BlendContext *s = ctx->priv;
324 1 const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(toplink->format);
325 int ret;
326
327
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (!s->tblend) {
328 AVFilterLink *bottomlink = ctx->inputs[BOTTOM];
329
330 if (toplink->w != bottomlink->w || toplink->h != bottomlink->h) {
331 av_log(ctx, AV_LOG_ERROR, "First input link %s parameters "
332 "(size %dx%d) do not match the corresponding "
333 "second input link %s parameters (size %dx%d)\n",
334 ctx->input_pads[TOP].name, toplink->w, toplink->h,
335 ctx->input_pads[BOTTOM].name, bottomlink->w, bottomlink->h);
336 return AVERROR(EINVAL);
337 }
338 }
339
340 1 outlink->w = toplink->w;
341 1 outlink->h = toplink->h;
342 1 outlink->time_base = toplink->time_base;
343 1 outlink->sample_aspect_ratio = toplink->sample_aspect_ratio;
344 1 outlink->frame_rate = toplink->frame_rate;
345
346 1 s->hsub = pix_desc->log2_chroma_w;
347 1 s->vsub = pix_desc->log2_chroma_h;
348
349 1 s->depth = pix_desc->comp[0].depth;
350 1 s->nb_planes = av_pix_fmt_count_planes(toplink->format);
351
352
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (!s->tblend)
353 if ((ret = ff_framesync_init_dualinput(&s->fs, ctx)) < 0)
354 return ret;
355
356 1 ret = config_params(ctx);
357
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (ret < 0)
358 return ret;
359
360
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (s->tblend)
361 1 return 0;
362
363 ret = ff_framesync_configure(&s->fs);
364 outlink->time_base = s->fs.time_base;
365
366 return ret;
367 }
368
369 static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
370 char *res, int res_len, int flags)
371 {
372 int ret;
373
374 ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags);
375 if (ret < 0)
376 return ret;
377
378 return config_params(ctx);
379 }
380
381 #if CONFIG_BLEND_FILTER
382
383 static int activate(AVFilterContext *ctx)
384 {
385 BlendContext *s = ctx->priv;
386 return ff_framesync_activate(&s->fs);
387 }
388
389 static const AVFilterPad blend_inputs[] = {
390 {
391 .name = "top",
392 .type = AVMEDIA_TYPE_VIDEO,
393 },{
394 .name = "bottom",
395 .type = AVMEDIA_TYPE_VIDEO,
396 },
397 };
398
399 static const AVFilterPad blend_outputs[] = {
400 {
401 .name = "default",
402 .type = AVMEDIA_TYPE_VIDEO,
403 .config_props = config_output,
404 },
405 };
406
407 const AVFilter ff_vf_blend = {
408 .name = "blend",
409 .description = NULL_IF_CONFIG_SMALL("Blend two video frames into each other."),
410 .preinit = blend_framesync_preinit,
411 .init = init,
412 .uninit = uninit,
413 .priv_size = sizeof(BlendContext),
414 .activate = activate,
415 FILTER_INPUTS(blend_inputs),
416 FILTER_OUTPUTS(blend_outputs),
417 FILTER_PIXFMTS_ARRAY(pix_fmts),
418 .priv_class = &blend_class,
419 .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL | AVFILTER_FLAG_SLICE_THREADS,
420 .process_command = process_command,
421 };
422
423 #endif
424
425 #if CONFIG_TBLEND_FILTER
426
427 50 static int tblend_filter_frame(AVFilterLink *inlink, AVFrame *frame)
428 {
429 50 AVFilterContext *ctx = inlink->dst;
430 50 BlendContext *s = ctx->priv;
431 50 AVFilterLink *outlink = ctx->outputs[0];
432
433
2/2
✓ Branch 0 taken 49 times.
✓ Branch 1 taken 1 times.
50 if (s->prev_frame) {
434 AVFrame *out;
435
436
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 49 times.
49 if (ctx->is_disabled)
437 out = av_frame_clone(frame);
438 else
439 49 out = blend_frame(ctx, frame, s->prev_frame);
440 49 av_frame_free(&s->prev_frame);
441 49 s->prev_frame = frame;
442 49 return ff_filter_frame(outlink, out);
443 }
444 1 s->prev_frame = frame;
445 1 return 0;
446 }
447
448 AVFILTER_DEFINE_CLASS_EXT(tblend, "tblend", blend_options);
449
450 static const AVFilterPad tblend_inputs[] = {
451 {
452 .name = "default",
453 .type = AVMEDIA_TYPE_VIDEO,
454 .filter_frame = tblend_filter_frame,
455 },
456 };
457
458 static const AVFilterPad tblend_outputs[] = {
459 {
460 .name = "default",
461 .type = AVMEDIA_TYPE_VIDEO,
462 .config_props = config_output,
463 },
464 };
465
466 const AVFilter ff_vf_tblend = {
467 .name = "tblend",
468 .description = NULL_IF_CONFIG_SMALL("Blend successive frames."),
469 .priv_size = sizeof(BlendContext),
470 .priv_class = &tblend_class,
471 .init = init,
472 .uninit = uninit,
473 FILTER_INPUTS(tblend_inputs),
474 FILTER_OUTPUTS(tblend_outputs),
475 FILTER_PIXFMTS_ARRAY(pix_fmts),
476 .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL | AVFILTER_FLAG_SLICE_THREADS,
477 .process_command = process_command,
478 };
479
480 #endif
481