FFmpeg
vf_blend.c
Go to the documentation of this file.
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 "libavutil/imgutils.h"
22 #include "libavutil/intfloat.h"
23 #include "libavutil/eval.h"
24 #include "libavutil/opt.h"
25 #include "libavutil/pixfmt.h"
26 #include "avfilter.h"
27 #include "formats.h"
28 #include "framesync.h"
29 #include "internal.h"
30 #include "video.h"
31 #include "blend.h"
32 
33 #define TOP 0
34 #define BOTTOM 1
35 
36 #define DEPTH 8
37 #include "blend_modes.c"
38 
39 #undef DEPTH
40 #define DEPTH 9
41 #include "blend_modes.c"
42 
43 #undef DEPTH
44 #define DEPTH 10
45 #include "blend_modes.c"
46 
47 #undef DEPTH
48 #define DEPTH 12
49 #include "blend_modes.c"
50 
51 #undef DEPTH
52 #define DEPTH 14
53 #include "blend_modes.c"
54 
55 #undef DEPTH
56 #define DEPTH 16
57 #include "blend_modes.c"
58 
59 #undef DEPTH
60 #define DEPTH 32
61 #include "blend_modes.c"
62 
63 typedef struct BlendContext {
64  const AVClass *class;
66  int hsub, vsub; ///< chroma subsampling values
67  int nb_planes;
68  char *all_expr;
70  double all_opacity;
71 
72  int depth;
74  int tblend;
75  AVFrame *prev_frame; /* only used with tblend */
76 } BlendContext;
77 
78 static const char *const var_names[] = { "X", "Y", "W", "H", "SW", "SH", "T", "N", "A", "B", "TOP", "BOTTOM", NULL };
80 
81 typedef struct ThreadData {
82  const AVFrame *top, *bottom;
85  int plane;
86  int w, h;
88 } ThreadData;
89 
90 #define OFFSET(x) offsetof(BlendContext, x)
91 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
92 
93 static const AVOption blend_options[] = {
94  { "c0_mode", "set component #0 blend mode", OFFSET(params[0].mode), AV_OPT_TYPE_INT, {.i64=0}, 0, BLEND_NB-1, FLAGS, "mode" },
95  { "c1_mode", "set component #1 blend mode", OFFSET(params[1].mode), AV_OPT_TYPE_INT, {.i64=0}, 0, BLEND_NB-1, FLAGS, "mode" },
96  { "c2_mode", "set component #2 blend mode", OFFSET(params[2].mode), AV_OPT_TYPE_INT, {.i64=0}, 0, BLEND_NB-1, FLAGS, "mode" },
97  { "c3_mode", "set component #3 blend mode", OFFSET(params[3].mode), AV_OPT_TYPE_INT, {.i64=0}, 0, BLEND_NB-1, FLAGS, "mode" },
98  { "all_mode", "set blend mode for all components", OFFSET(all_mode), AV_OPT_TYPE_INT, {.i64=-1},-1, BLEND_NB-1, FLAGS, "mode" },
99  { "addition", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_ADDITION}, 0, 0, FLAGS, "mode" },
100  { "addition128","", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_GRAINMERGE}, 0, 0, FLAGS, "mode" },
101  { "grainmerge", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_GRAINMERGE}, 0, 0, FLAGS, "mode" },
102  { "and", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_AND}, 0, 0, FLAGS, "mode" },
103  { "average", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_AVERAGE}, 0, 0, FLAGS, "mode" },
104  { "burn", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_BURN}, 0, 0, FLAGS, "mode" },
105  { "darken", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_DARKEN}, 0, 0, FLAGS, "mode" },
106  { "difference", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_DIFFERENCE}, 0, 0, FLAGS, "mode" },
107  { "difference128", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_GRAINEXTRACT}, 0, 0, FLAGS, "mode" },
108  { "grainextract", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_GRAINEXTRACT}, 0, 0, FLAGS, "mode" },
109  { "divide", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_DIVIDE}, 0, 0, FLAGS, "mode" },
110  { "dodge", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_DODGE}, 0, 0, FLAGS, "mode" },
111  { "exclusion", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_EXCLUSION}, 0, 0, FLAGS, "mode" },
112  { "extremity", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_EXTREMITY}, 0, 0, FLAGS, "mode" },
113  { "freeze", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_FREEZE}, 0, 0, FLAGS, "mode" },
114  { "glow", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_GLOW}, 0, 0, FLAGS, "mode" },
115  { "hardlight", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_HARDLIGHT}, 0, 0, FLAGS, "mode" },
116  { "hardmix", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_HARDMIX}, 0, 0, FLAGS, "mode" },
117  { "heat", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_HEAT}, 0, 0, FLAGS, "mode" },
118  { "lighten", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_LIGHTEN}, 0, 0, FLAGS, "mode" },
119  { "linearlight","", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_LINEARLIGHT},0, 0, FLAGS, "mode" },
120  { "multiply", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_MULTIPLY}, 0, 0, FLAGS, "mode" },
121  { "multiply128","", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_MULTIPLY128},0, 0, FLAGS, "mode" },
122  { "negation", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_NEGATION}, 0, 0, FLAGS, "mode" },
123  { "normal", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_NORMAL}, 0, 0, FLAGS, "mode" },
124  { "or", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_OR}, 0, 0, FLAGS, "mode" },
125  { "overlay", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_OVERLAY}, 0, 0, FLAGS, "mode" },
126  { "phoenix", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_PHOENIX}, 0, 0, FLAGS, "mode" },
127  { "pinlight", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_PINLIGHT}, 0, 0, FLAGS, "mode" },
128  { "reflect", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_REFLECT}, 0, 0, FLAGS, "mode" },
129  { "screen", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_SCREEN}, 0, 0, FLAGS, "mode" },
130  { "softlight", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_SOFTLIGHT}, 0, 0, FLAGS, "mode" },
131  { "subtract", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_SUBTRACT}, 0, 0, FLAGS, "mode" },
132  { "vividlight", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_VIVIDLIGHT}, 0, 0, FLAGS, "mode" },
133  { "xor", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_XOR}, 0, 0, FLAGS, "mode" },
134  { "softdifference","", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_SOFTDIFFERENCE}, 0, 0, FLAGS, "mode" },
135  { "geometric", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_GEOMETRIC}, 0, 0, FLAGS, "mode" },
136  { "harmonic", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_HARMONIC}, 0, 0, FLAGS, "mode" },
137  { "bleach", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_BLEACH}, 0, 0, FLAGS, "mode" },
138  { "stain", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_STAIN}, 0, 0, FLAGS, "mode" },
139  { "interpolate","", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_INTERPOLATE},0, 0, FLAGS, "mode" },
140  { "hardoverlay","", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_HARDOVERLAY},0, 0, FLAGS, "mode" },
141  { "c0_expr", "set color component #0 expression", OFFSET(params[0].expr_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
142  { "c1_expr", "set color component #1 expression", OFFSET(params[1].expr_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
143  { "c2_expr", "set color component #2 expression", OFFSET(params[2].expr_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
144  { "c3_expr", "set color component #3 expression", OFFSET(params[3].expr_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
145  { "all_expr", "set expression for all color components", OFFSET(all_expr), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
146  { "c0_opacity", "set color component #0 opacity", OFFSET(params[0].opacity), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS },
147  { "c1_opacity", "set color component #1 opacity", OFFSET(params[1].opacity), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS },
148  { "c2_opacity", "set color component #2 opacity", OFFSET(params[2].opacity), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS },
149  { "c3_opacity", "set color component #3 opacity", OFFSET(params[3].opacity), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS },
150  { "all_opacity", "set opacity for all color components", OFFSET(all_opacity), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS },
151  { NULL }
152 };
153 
155 
156 #define COPY(src, depth) \
157 static void blend_copy ## src##_##depth(const uint8_t *top, ptrdiff_t top_linesize, \
158  const uint8_t *bottom, ptrdiff_t bottom_linesize,\
159  uint8_t *dst, ptrdiff_t dst_linesize, \
160  ptrdiff_t width, ptrdiff_t height, \
161  FilterParams *param, double *values, int starty) \
162 { \
163  av_image_copy_plane(dst, dst_linesize, src, src ## _linesize, \
164  width * depth / 8, height); \
165 }
166 
167 COPY(top, 8)
168 COPY(bottom, 8)
169 
170 COPY(top, 16)
171 COPY(bottom, 16)
172 
173 COPY(top, 32)
174 COPY(bottom, 32)
175 
176 #undef COPY
177 
178 #define BLEND_NORMAL(name, type) \
179 static void blend_normal_##name(const uint8_t *_top, ptrdiff_t top_linesize, \
180  const uint8_t *_bottom, ptrdiff_t bottom_linesize,\
181  uint8_t *_dst, ptrdiff_t dst_linesize, \
182  ptrdiff_t width, ptrdiff_t height, \
183  FilterParams *param, double *values, int starty) \
184 { \
185  const type *top = (type*)_top; \
186  const type *bottom = (type*)_bottom; \
187  type *dst = (type*)_dst; \
188  const float opacity = param->opacity; \
189  \
190  dst_linesize /= sizeof(type); \
191  top_linesize /= sizeof(type); \
192  bottom_linesize /= sizeof(type); \
193  \
194  for (int i = 0; i < height; i++) { \
195  for (int j = 0; j < width; j++) { \
196  dst[j] = top[j] * opacity + bottom[j] * (1.f - opacity); \
197  } \
198  dst += dst_linesize; \
199  top += top_linesize; \
200  bottom += bottom_linesize; \
201  } \
202 }
203 
204 BLEND_NORMAL(8bit, uint8_t)
205 BLEND_NORMAL(16bit, uint16_t)
206 BLEND_NORMAL(32bit, float)
207 
208 #define DEFINE_BLEND_EXPR(type, name, div) \
209 static void blend_expr_## name(const uint8_t *_top, ptrdiff_t top_linesize, \
210  const uint8_t *_bottom, ptrdiff_t bottom_linesize, \
211  uint8_t *_dst, ptrdiff_t dst_linesize, \
212  ptrdiff_t width, ptrdiff_t height, \
213  FilterParams *param, double *values, int starty) \
214 { \
215  const type *top = (type*)_top; \
216  const type *bottom = (type*)_bottom; \
217  type *dst = (type*)_dst; \
218  AVExpr *e = param->e; \
219  int y, x; \
220  dst_linesize /= div; \
221  top_linesize /= div; \
222  bottom_linesize /= div; \
223  \
224  for (y = 0; y < height; y++) { \
225  values[VAR_Y] = y + starty; \
226  for (x = 0; x < width; x++) { \
227  values[VAR_X] = x; \
228  values[VAR_TOP] = values[VAR_A] = top[x]; \
229  values[VAR_BOTTOM] = values[VAR_B] = bottom[x]; \
230  dst[x] = av_expr_eval(e, values, NULL); \
231  } \
232  dst += dst_linesize; \
233  top += top_linesize; \
234  bottom += bottom_linesize; \
235  } \
236 }
237 
238 DEFINE_BLEND_EXPR(uint8_t, 8bit, 1)
239 DEFINE_BLEND_EXPR(uint16_t, 16bit, 2)
240 DEFINE_BLEND_EXPR(float, 32bit, 4)
241 
242 static int filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
243 {
244  ThreadData *td = arg;
245  int slice_start = (td->h * jobnr ) / nb_jobs;
246  int slice_end = (td->h * (jobnr+1)) / nb_jobs;
247  int height = slice_end - slice_start;
248  const uint8_t *top = td->top->data[td->plane];
249  const uint8_t *bottom = td->bottom->data[td->plane];
250  uint8_t *dst = td->dst->data[td->plane];
251  double values[VAR_VARS_NB];
252 
253  values[VAR_N] = td->inlink->frame_count_out;
254  values[VAR_T] = td->dst->pts == AV_NOPTS_VALUE ? NAN : td->dst->pts * av_q2d(td->inlink->time_base);
255  values[VAR_W] = td->w;
256  values[VAR_H] = td->h;
257  values[VAR_SW] = td->w / (double)td->dst->width;
258  values[VAR_SH] = td->h / (double)td->dst->height;
259 
260  td->param->blend(top + slice_start * td->top->linesize[td->plane],
261  td->top->linesize[td->plane],
262  bottom + slice_start * td->bottom->linesize[td->plane],
263  td->bottom->linesize[td->plane],
264  dst + slice_start * td->dst->linesize[td->plane],
265  td->dst->linesize[td->plane],
266  td->w, height, td->param, &values[0], slice_start);
267  return 0;
268 }
269 
271  const AVFrame *bottom_buf)
272 {
273  BlendContext *s = ctx->priv;
274  AVFilterLink *inlink = ctx->inputs[0];
275  AVFilterLink *outlink = ctx->outputs[0];
276  AVFrame *dst_buf;
277  int plane;
278 
279  dst_buf = ff_get_video_buffer(outlink, outlink->w, outlink->h);
280  if (!dst_buf)
281  return top_buf;
282 
283  if (av_frame_copy_props(dst_buf, top_buf) < 0) {
284  av_frame_free(&dst_buf);
285  return top_buf;
286  }
287 
288  for (plane = 0; plane < s->nb_planes; plane++) {
289  int hsub = plane == 1 || plane == 2 ? s->hsub : 0;
290  int vsub = plane == 1 || plane == 2 ? s->vsub : 0;
291  int outw = AV_CEIL_RSHIFT(dst_buf->width, hsub);
292  int outh = AV_CEIL_RSHIFT(dst_buf->height, vsub);
293  FilterParams *param = &s->params[plane];
294  ThreadData td = { .top = top_buf, .bottom = bottom_buf, .dst = dst_buf,
295  .w = outw, .h = outh, .param = param, .plane = plane,
296  .inlink = inlink };
297 
300  }
301 
302  if (!s->tblend)
303  av_frame_free(&top_buf);
304 
305  return dst_buf;
306 }
307 
309 {
310  AVFilterContext *ctx = fs->parent;
311  AVFrame *top_buf, *bottom_buf, *dst_buf;
312  int ret;
313 
314  ret = ff_framesync_dualinput_get(fs, &top_buf, &bottom_buf);
315  if (ret < 0)
316  return ret;
317  if (!bottom_buf)
318  return ff_filter_frame(ctx->outputs[0], top_buf);
319  dst_buf = blend_frame(ctx, top_buf, bottom_buf);
320  return ff_filter_frame(ctx->outputs[0], dst_buf);
321 }
322 
324 {
325  BlendContext *s = ctx->priv;
326 
327  s->tblend = !strcmp(ctx->filter->name, "tblend");
328 
329  s->fs.on_event = blend_frame_for_dualinput;
330  return 0;
331 }
332 
333 static const enum AVPixelFormat pix_fmts[] = {
352 };
353 
355 {
356  BlendContext *s = ctx->priv;
357  int i;
358 
359  ff_framesync_uninit(&s->fs);
360  av_frame_free(&s->prev_frame);
361 
362  for (i = 0; i < FF_ARRAY_ELEMS(s->params); i++)
363  av_expr_free(s->params[i].e);
364 }
365 
366 #define DEFINE_INIT_BLEND_FUNC(depth, nbits) \
367 static av_cold void init_blend_func_##depth##_##nbits##bit(FilterParams *param) \
368 { \
369  switch (param->mode) { \
370  case BLEND_ADDITION: param->blend = blend_addition_##depth##bit; break; \
371  case BLEND_GRAINMERGE: param->blend = blend_grainmerge_##depth##bit; break; \
372  case BLEND_AND: param->blend = blend_and_##depth##bit; break; \
373  case BLEND_AVERAGE: param->blend = blend_average_##depth##bit; break; \
374  case BLEND_BURN: param->blend = blend_burn_##depth##bit; break; \
375  case BLEND_DARKEN: param->blend = blend_darken_##depth##bit; break; \
376  case BLEND_DIFFERENCE: param->blend = blend_difference_##depth##bit; break; \
377  case BLEND_GRAINEXTRACT: param->blend = blend_grainextract_##depth##bit; break; \
378  case BLEND_DIVIDE: param->blend = blend_divide_##depth##bit; break; \
379  case BLEND_DODGE: param->blend = blend_dodge_##depth##bit; break; \
380  case BLEND_EXCLUSION: param->blend = blend_exclusion_##depth##bit; break; \
381  case BLEND_EXTREMITY: param->blend = blend_extremity_##depth##bit; break; \
382  case BLEND_FREEZE: param->blend = blend_freeze_##depth##bit; break; \
383  case BLEND_GLOW: param->blend = blend_glow_##depth##bit; break; \
384  case BLEND_HARDLIGHT: param->blend = blend_hardlight_##depth##bit; break; \
385  case BLEND_HARDMIX: param->blend = blend_hardmix_##depth##bit; break; \
386  case BLEND_HEAT: param->blend = blend_heat_##depth##bit; break; \
387  case BLEND_LIGHTEN: param->blend = blend_lighten_##depth##bit; break; \
388  case BLEND_LINEARLIGHT: param->blend = blend_linearlight_##depth##bit; break; \
389  case BLEND_MULTIPLY: param->blend = blend_multiply_##depth##bit; break; \
390  case BLEND_MULTIPLY128: param->blend = blend_multiply128_##depth##bit; break; \
391  case BLEND_NEGATION: param->blend = blend_negation_##depth##bit; break; \
392  case BLEND_NORMAL: param->blend = blend_normal_##nbits##bit; break; \
393  case BLEND_OR: param->blend = blend_or_##depth##bit; break; \
394  case BLEND_OVERLAY: param->blend = blend_overlay_##depth##bit; break; \
395  case BLEND_PHOENIX: param->blend = blend_phoenix_##depth##bit; break; \
396  case BLEND_PINLIGHT: param->blend = blend_pinlight_##depth##bit; break; \
397  case BLEND_REFLECT: param->blend = blend_reflect_##depth##bit; break; \
398  case BLEND_SCREEN: param->blend = blend_screen_##depth##bit; break; \
399  case BLEND_SOFTLIGHT: param->blend = blend_softlight_##depth##bit; break; \
400  case BLEND_SUBTRACT: param->blend = blend_subtract_##depth##bit; break; \
401  case BLEND_VIVIDLIGHT: param->blend = blend_vividlight_##depth##bit; break; \
402  case BLEND_XOR: param->blend = blend_xor_##depth##bit; break; \
403  case BLEND_SOFTDIFFERENCE:param->blend=blend_softdifference_##depth##bit;break; \
404  case BLEND_GEOMETRIC: param->blend = blend_geometric_##depth##bit; break; \
405  case BLEND_HARMONIC: param->blend = blend_harmonic_##depth##bit; break; \
406  case BLEND_BLEACH: param->blend = blend_bleach_##depth##bit; break; \
407  case BLEND_STAIN: param->blend = blend_stain_##depth##bit; break; \
408  case BLEND_INTERPOLATE: param->blend = blend_interpolate_##depth##bit; break; \
409  case BLEND_HARDOVERLAY: param->blend = blend_hardoverlay_##depth##bit; break; \
410  } \
411 }
419 
420 void ff_blend_init(FilterParams *param, int depth)
421 {
422  switch (depth) {
423  case 8:
424  init_blend_func_8_8bit(param);
425  break;
426  case 9:
427  init_blend_func_9_16bit(param);
428  break;
429  case 10:
430  init_blend_func_10_16bit(param);
431  break;
432  case 12:
433  init_blend_func_12_16bit(param);
434  break;
435  case 14:
436  init_blend_func_14_16bit(param);
437  break;
438  case 16:
439  init_blend_func_16_16bit(param);
440  break;
441  case 32:
442  init_blend_func_32_32bit(param);
443  break;
444  }
445 
446  if (param->opacity == 0 && param->mode != BLEND_NORMAL) {
447  param->blend = depth > 8 ? depth > 16 ? blend_copytop_32 : blend_copytop_16 : blend_copytop_8;
448  } else if (param->mode == BLEND_NORMAL) {
449  if (param->opacity == 1)
450  param->blend = depth > 8 ? depth > 16 ? blend_copytop_32 : blend_copytop_16 : blend_copytop_8;
451  else if (param->opacity == 0)
452  param->blend = depth > 8 ? depth > 16 ? blend_copybottom_32 : blend_copybottom_16 : blend_copybottom_8;
453  }
454 
455  if (ARCH_X86)
456  ff_blend_init_x86(param, depth);
457 }
458 
460 {
461  BlendContext *s = ctx->priv;
462  int ret;
463 
464  for (int plane = 0; plane < FF_ARRAY_ELEMS(s->params); plane++) {
465  FilterParams *param = &s->params[plane];
466 
467  if (s->all_mode >= 0)
468  param->mode = s->all_mode;
469  if (s->all_opacity < 1)
470  param->opacity = s->all_opacity;
471 
472  ff_blend_init(param, s->depth);
473 
474  if (s->all_expr && !param->expr_str) {
475  param->expr_str = av_strdup(s->all_expr);
476  if (!param->expr_str)
477  return AVERROR(ENOMEM);
478  }
479  if (param->expr_str) {
480  ret = av_expr_parse(&param->e, param->expr_str, var_names,
481  NULL, NULL, NULL, NULL, 0, ctx);
482  if (ret < 0)
483  return ret;
484  param->blend = s->depth > 8 ? s->depth > 16 ? blend_expr_32bit : blend_expr_16bit : blend_expr_8bit;
485  }
486  }
487 
488  return 0;
489 }
490 
491 static int config_output(AVFilterLink *outlink)
492 {
493  AVFilterContext *ctx = outlink->src;
494  AVFilterLink *toplink = ctx->inputs[TOP];
495  BlendContext *s = ctx->priv;
496  const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(toplink->format);
497  int ret;
498 
499  if (!s->tblend) {
500  AVFilterLink *bottomlink = ctx->inputs[BOTTOM];
501 
502  if (toplink->w != bottomlink->w || toplink->h != bottomlink->h) {
503  av_log(ctx, AV_LOG_ERROR, "First input link %s parameters "
504  "(size %dx%d) do not match the corresponding "
505  "second input link %s parameters (size %dx%d)\n",
506  ctx->input_pads[TOP].name, toplink->w, toplink->h,
507  ctx->input_pads[BOTTOM].name, bottomlink->w, bottomlink->h);
508  return AVERROR(EINVAL);
509  }
510  }
511 
512  outlink->w = toplink->w;
513  outlink->h = toplink->h;
514  outlink->time_base = toplink->time_base;
515  outlink->sample_aspect_ratio = toplink->sample_aspect_ratio;
516  outlink->frame_rate = toplink->frame_rate;
517 
518  s->hsub = pix_desc->log2_chroma_w;
519  s->vsub = pix_desc->log2_chroma_h;
520 
521  s->depth = pix_desc->comp[0].depth;
522  s->nb_planes = av_pix_fmt_count_planes(toplink->format);
523 
524  if (!s->tblend)
525  if ((ret = ff_framesync_init_dualinput(&s->fs, ctx)) < 0)
526  return ret;
527 
528  ret = config_params(ctx);
529  if (ret < 0)
530  return ret;
531 
532  if (s->tblend)
533  return 0;
534 
535  ret = ff_framesync_configure(&s->fs);
536  outlink->time_base = s->fs.time_base;
537 
538  return ret;
539 }
540 
541 static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
542  char *res, int res_len, int flags)
543 {
544  int ret;
545 
546  ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags);
547  if (ret < 0)
548  return ret;
549 
550  return config_params(ctx);
551 }
552 
553 #if CONFIG_BLEND_FILTER
554 
555 static int activate(AVFilterContext *ctx)
556 {
557  BlendContext *s = ctx->priv;
558  return ff_framesync_activate(&s->fs);
559 }
560 
561 static const AVFilterPad blend_inputs[] = {
562  {
563  .name = "top",
564  .type = AVMEDIA_TYPE_VIDEO,
565  },{
566  .name = "bottom",
567  .type = AVMEDIA_TYPE_VIDEO,
568  },
569 };
570 
571 static const AVFilterPad blend_outputs[] = {
572  {
573  .name = "default",
574  .type = AVMEDIA_TYPE_VIDEO,
575  .config_props = config_output,
576  },
577 };
578 
579 const AVFilter ff_vf_blend = {
580  .name = "blend",
581  .description = NULL_IF_CONFIG_SMALL("Blend two video frames into each other."),
582  .preinit = blend_framesync_preinit,
583  .init = init,
584  .uninit = uninit,
585  .priv_size = sizeof(BlendContext),
586  .activate = activate,
587  FILTER_INPUTS(blend_inputs),
588  FILTER_OUTPUTS(blend_outputs),
590  .priv_class = &blend_class,
592  .process_command = process_command,
593 };
594 
595 #endif
596 
597 #if CONFIG_TBLEND_FILTER
598 
599 static int tblend_filter_frame(AVFilterLink *inlink, AVFrame *frame)
600 {
601  AVFilterContext *ctx = inlink->dst;
602  BlendContext *s = ctx->priv;
603  AVFilterLink *outlink = ctx->outputs[0];
604 
605  if (s->prev_frame) {
606  AVFrame *out;
607 
608  if (ctx->is_disabled)
610  else
611  out = blend_frame(ctx, frame, s->prev_frame);
612  av_frame_free(&s->prev_frame);
613  s->prev_frame = frame;
614  return ff_filter_frame(outlink, out);
615  }
616  s->prev_frame = frame;
617  return 0;
618 }
619 
620 AVFILTER_DEFINE_CLASS_EXT(tblend, "tblend", blend_options);
621 
622 static const AVFilterPad tblend_inputs[] = {
623  {
624  .name = "default",
625  .type = AVMEDIA_TYPE_VIDEO,
626  .filter_frame = tblend_filter_frame,
627  },
628 };
629 
630 static const AVFilterPad tblend_outputs[] = {
631  {
632  .name = "default",
633  .type = AVMEDIA_TYPE_VIDEO,
634  .config_props = config_output,
635  },
636 };
637 
638 const AVFilter ff_vf_tblend = {
639  .name = "tblend",
640  .description = NULL_IF_CONFIG_SMALL("Blend successive frames."),
641  .priv_size = sizeof(BlendContext),
642  .priv_class = &tblend_class,
643  .init = init,
644  .uninit = uninit,
645  FILTER_INPUTS(tblend_inputs),
646  FILTER_OUTPUTS(tblend_outputs),
649  .process_command = process_command,
650 };
651 
652 #endif
BLEND_GLOW
@ BLEND_GLOW
Definition: blend.h:56
ff_get_video_buffer
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:98
AV_PIX_FMT_YUVA422P16
#define AV_PIX_FMT_YUVA422P16
Definition: pixfmt.h:447
VAR_A
@ VAR_A
Definition: vf_blend.c:79
AV_PIX_FMT_GBRAP16
#define AV_PIX_FMT_GBRAP16
Definition: pixfmt.h:426
BlendContext::vsub
int vsub
chroma subsampling values
Definition: vf_blend.c:66
ff_framesync_configure
int ff_framesync_configure(FFFrameSync *fs)
Configure a frame sync structure.
Definition: framesync.c:119
td
#define td
Definition: regdef.h:70
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
BLEND_EXCLUSION
@ BLEND_EXCLUSION
Definition: blend.h:39
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
ff_framesync_uninit
void ff_framesync_uninit(FFFrameSync *fs)
Free all memory currently allocated.
Definition: framesync.c:285
out
FILE * out
Definition: movenc.c:54
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1018
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2660
FILTER_PIXFMTS_ARRAY
#define FILTER_PIXFMTS_ARRAY(array)
Definition: internal.h:171
blend_modes.c
inlink
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
Definition: filter_design.txt:212
FilterParams::expr_str
char * expr_str
Definition: blend.h:76
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:109
AV_PIX_FMT_YUVA422P9
#define AV_PIX_FMT_YUVA422P9
Definition: pixfmt.h:439
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:317
AVFrame::width
int width
Definition: frame.h:389
AV_PIX_FMT_YUVA420P16
#define AV_PIX_FMT_YUVA420P16
Definition: pixfmt.h:446
AVComponentDescriptor::depth
int depth
Number of bits in the component.
Definition: pixdesc.h:57
AV_PIX_FMT_YUVA420P10
#define AV_PIX_FMT_YUVA420P10
Definition: pixfmt.h:441
AVOption
AVOption.
Definition: opt.h:247
ThreadData::bottom
const AVFrame * bottom
Definition: vf_blend.c:82
OFFSET
#define OFFSET(x)
Definition: vf_blend.c:90
VAR_TOP
@ VAR_TOP
Definition: vf_blend.c:79
AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:404
FilterParams::e
AVExpr * e
Definition: blend.h:75
BLEND_NEGATION
@ BLEND_NEGATION
Definition: blend.h:43
ThreadData::w
int w
Definition: vf_blend.c:86
AV_PIX_FMT_YUV440P
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:99
var_names
static const char *const var_names[]
Definition: vf_blend.c:78
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:169
AVFILTER_DEFINE_CLASS_EXT
#define AVFILTER_DEFINE_CLASS_EXT(name, desc, options)
Definition: internal.h:318
FFFrameSync
Frame sync structure.
Definition: framesync.h:146
BLEND_HARMONIC
@ BLEND_HARMONIC
Definition: blend.h:64
VAR_B
@ VAR_B
Definition: vf_blend.c:79
intfloat.h
video.h
BLEND_ADDITION
@ BLEND_ADDITION
Definition: blend.h:30
AV_PIX_FMT_YUVA422P10
#define AV_PIX_FMT_YUVA422P10
Definition: pixfmt.h:442
VAR_X
@ VAR_X
Definition: vf_blend.c:79
BLEND_MULTIPLY128
@ BLEND_MULTIPLY128
Definition: blend.h:58
AV_PIX_FMT_GRAY9
#define AV_PIX_FMT_GRAY9
Definition: pixfmt.h:384
BLEND_GEOMETRIC
@ BLEND_GEOMETRIC
Definition: blend.h:63
BLEND_BLEACH
@ BLEND_BLEACH
Definition: blend.h:65
hsub
static void hsub(htype *dst, const htype *src, int bins)
Definition: vf_median.c:74
process_command
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
Definition: vf_blend.c:541
BLEND_NB
@ BLEND_NB
Definition: blend.h:69
formats.h
av_expr_parse
int av_expr_parse(AVExpr **expr, const char *s, const char *const *const_names, const char *const *func1_names, double(*const *funcs1)(void *, double), const char *const *func2_names, double(*const *funcs2)(void *, double, double), int log_offset, void *log_ctx)
Parse an expression.
Definition: eval.c:685
bit
#define bit(string, value)
Definition: cbs_mpeg2.c:58
BLEND_DIVIDE
@ BLEND_DIVIDE
Definition: blend.h:37
BLEND_PHOENIX
@ BLEND_PHOENIX
Definition: blend.h:46
av_pix_fmt_count_planes
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2700
AV_PIX_FMT_YUVA420P9
#define AV_PIX_FMT_YUVA420P9
Definition: pixfmt.h:438
AV_PIX_FMT_GBRP14
#define AV_PIX_FMT_GBRP14
Definition: pixfmt.h:422
VAR_N
@ VAR_N
Definition: vf_blend.c:79
AV_PIX_FMT_GBRAP
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:205
AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:420
AV_PIX_FMT_YUVA444P16
#define AV_PIX_FMT_YUVA444P16
Definition: pixfmt.h:448
AV_PIX_FMT_YUV422P9
#define AV_PIX_FMT_YUV422P9
Definition: pixfmt.h:402
config_params
static int config_params(AVFilterContext *ctx)
Definition: vf_blend.c:459
AV_PIX_FMT_GRAY16
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:388
BLEND_AND
@ BLEND_AND
Definition: blend.h:31
BlendContext::params
FilterParams params[4]
Definition: vf_blend.c:73
av_expr_free
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
Definition: eval.c:336
DEFINE_BLEND_EXPR
#define DEFINE_BLEND_EXPR(type, name, div)
Definition: vf_blend.c:208
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: vf_blend.c:333
blend_options
static const AVOption blend_options[]
Definition: vf_blend.c:93
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:50
BLEND_SOFTLIGHT
@ BLEND_SOFTLIGHT
Definition: blend.h:50
AV_PIX_FMT_YUV444P10
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:407
AV_PIX_FMT_YUVJ411P
@ AV_PIX_FMT_YUVJ411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
Definition: pixfmt.h:248
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
av_cold
#define av_cold
Definition: attributes.h:90
AV_PIX_FMT_YUV422P16
#define AV_PIX_FMT_YUV422P16
Definition: pixfmt.h:416
AV_PIX_FMT_YUVJ422P
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
Definition: pixfmt.h:79
AV_PIX_FMT_GBRAP10
#define AV_PIX_FMT_GBRAP10
Definition: pixfmt.h:424
ThreadData::plane
int plane
Definition: vf_blend.c:85
filter_slice
static int filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Definition: vf_blend.c:242
s
#define s(width, name)
Definition: cbs_vp9.c:257
BLEND_OR
@ BLEND_OR
Definition: blend.h:44
AV_PIX_FMT_GBRAP12
#define AV_PIX_FMT_GBRAP12
Definition: pixfmt.h:425
AV_PIX_FMT_YUVA420P
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:101
BLEND_SCREEN
@ BLEND_SCREEN
Definition: blend.h:49
AV_PIX_FMT_YUV444P16
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:417
AV_CEIL_RSHIFT
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:51
VAR_H
@ VAR_H
Definition: vf_blend.c:79
AV_OPT_TYPE_DOUBLE
@ AV_OPT_TYPE_DOUBLE
Definition: opt.h:226
slice_end
static int slice_end(AVCodecContext *avctx, AVFrame *pict)
Handle slice ends.
Definition: mpeg12dec.c:2042
av_q2d
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition: rational.h:104
AV_PIX_FMT_YUVA444P12
#define AV_PIX_FMT_YUVA444P12
Definition: pixfmt.h:445
AV_PIX_FMT_YUV420P9
#define AV_PIX_FMT_YUV420P9
Definition: pixfmt.h:401
AV_PIX_FMT_YUV420P16
#define AV_PIX_FMT_YUV420P16
Definition: pixfmt.h:415
ctx
AVFormatContext * ctx
Definition: movenc.c:48
av_frame_clone
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
Definition: frame.c:422
AVPixFmtDescriptor::log2_chroma_w
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:80
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
AV_PIX_FMT_GRAYF32
#define AV_PIX_FMT_GRAYF32
Definition: pixfmt.h:436
BLEND_EXTREMITY
@ BLEND_EXTREMITY
Definition: blend.h:61
NAN
#define NAN
Definition: mathematics.h:64
FRAMESYNC_DEFINE_CLASS
FRAMESYNC_DEFINE_CLASS(blend, BlendContext, fs)
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: internal.h:191
ThreadData::h
int h
Definition: vf_blend.c:86
AV_PIX_FMT_YUVJ444P
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition: pixfmt.h:80
arg
const char * arg
Definition: jacosubdec.c:67
AV_PIX_FMT_GRAY10
#define AV_PIX_FMT_GRAY10
Definition: pixfmt.h:385
ThreadData::dst
AVFrame * dst
Definition: vf_blend.c:83
BLEND_PINLIGHT
@ BLEND_PINLIGHT
Definition: blend.h:47
FilterParams::mode
enum BlendMode mode
Definition: blend.h:73
AV_PIX_FMT_GBRP16
#define AV_PIX_FMT_GBRP16
Definition: pixfmt.h:423
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
NULL
#define NULL
Definition: coverity.c:32
av_frame_copy_props
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:537
BLEND_MULTIPLY
@ BLEND_MULTIPLY
Definition: blend.h:42
fs
#define fs(width, name, subs,...)
Definition: cbs_vp9.c:259
BlendMode
BlendMode
Definition: blend.h:27
AV_PIX_FMT_YUVJ420P
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition: pixfmt.h:78
BlendContext::depth
int depth
Definition: vf_blend.c:72
activate
filter_frame For filters that do not use the activate() callback
AV_PIX_FMT_YUV440P10
#define AV_PIX_FMT_YUV440P10
Definition: pixfmt.h:406
init
static av_cold int init(AVFilterContext *ctx)
Definition: vf_blend.c:323
ff_blend_init_x86
void ff_blend_init_x86(FilterParams *param, int depth)
Definition: vf_blend_init.c:103
DEFINE_INIT_BLEND_FUNC
#define DEFINE_INIT_BLEND_FUNC(depth, nbits)
Definition: vf_blend.c:366
AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:405
AV_PIX_FMT_GRAY8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:74
AV_PIX_FMT_GBRP9
#define AV_PIX_FMT_GBRP9
Definition: pixfmt.h:419
BLEND_SUBTRACT
@ BLEND_SUBTRACT
Definition: blend.h:51
BLEND_FREEZE
@ BLEND_FREEZE
Definition: blend.h:60
FilterParams
filter data
Definition: mlp.h:75
BLEND_LIGHTEN
@ BLEND_LIGHTEN
Definition: blend.h:41
BLEND_HEAT
@ BLEND_HEAT
Definition: blend.h:59
VAR_SW
@ VAR_SW
Definition: vf_blend.c:79
eval.h
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
ff_framesync_init_dualinput
int ff_framesync_init_dualinput(FFFrameSync *fs, AVFilterContext *parent)
Initialize a frame sync structure for dualinput.
Definition: framesync.c:353
BlendContext::prev_frame
AVFrame * prev_frame
Definition: vf_blend.c:75
COPY
#define COPY(src, depth)
Definition: vf_blend.c:156
AV_PIX_FMT_GBRPF32
#define AV_PIX_FMT_GBRPF32
Definition: pixfmt.h:433
AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:409
BLEND_DODGE
@ BLEND_DODGE
Definition: blend.h:38
VAR_SH
@ VAR_SH
Definition: vf_blend.c:79
BlendContext::all_expr
char * all_expr
Definition: vf_blend.c:68
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
BlendContext::tblend
int tblend
Definition: vf_blend.c:74
BlendContext
Definition: vf_blend.c:63
ff_vf_tblend
const AVFilter ff_vf_tblend
AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:411
BlendContext::hsub
int hsub
Definition: vf_blend.c:66
ff_filter_process_command
int ff_filter_process_command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
Generic processing of user supplied commands that are set in the same way as the filter options.
Definition: avfilter.c:882
height
#define height
AV_PIX_FMT_YUVA444P
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:167
AV_PIX_FMT_YUVA444P10
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:443
ThreadData::param
FilterParams * param
Definition: vf_blend.c:87
BLEND_INTERPOLATE
@ BLEND_INTERPOLATE
Definition: blend.h:67
internal.h
BLEND_HARDLIGHT
@ BLEND_HARDLIGHT
Definition: blend.h:40
BlendContext::all_mode
enum BlendMode all_mode
Definition: vf_blend.c:69
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:271
VAR_BOTTOM
@ VAR_BOTTOM
Definition: vf_blend.c:79
ff_vf_blend
const AVFilter ff_vf_blend
AV_PIX_FMT_GBRP12
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:421
BlendContext::fs
FFFrameSync fs
Definition: vf_blend.c:65
ff_filter_get_nb_threads
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Definition: avfilter.c:803
blend.h
ThreadData
Used for passing data between threads.
Definition: dsddec.c:67
VAR_W
@ VAR_W
Definition: vf_blend.c:79
BLEND_STAIN
@ BLEND_STAIN
Definition: blend.h:66
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
BLEND_SOFTDIFFERENCE
@ BLEND_SOFTDIFFERENCE
Definition: blend.h:62
AV_PIX_FMT_YUVJ440P
@ AV_PIX_FMT_YUVJ440P
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range
Definition: pixfmt.h:100
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:56
BLEND_VIVIDLIGHT
@ BLEND_VIVIDLIGHT
Definition: blend.h:52
TOP
#define TOP
Definition: vf_blend.c:33
BLEND_DIFFERENCE
@ BLEND_DIFFERENCE
Definition: blend.h:35
AV_PIX_FMT_YUV444P9
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:403
BlendContext::nb_planes
int nb_planes
Definition: vf_blend.c:67
ff_blend_init
void ff_blend_init(FilterParams *param, int depth)
Definition: vf_blend.c:420
config_output
static int config_output(AVFilterLink *outlink)
Definition: vf_blend.c:491
AVFilter
Filter definition.
Definition: avfilter.h:165
VAR_VARS_NB
@ VAR_VARS_NB
Definition: vf_blend.c:79
BLEND_HARDMIX
@ BLEND_HARDMIX
Definition: blend.h:54
ret
ret
Definition: filter_design.txt:187
BLEND_GRAINMERGE
@ BLEND_GRAINMERGE
Definition: blend.h:57
pixfmt.h
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
AV_PIX_FMT_YUVA444P9
#define AV_PIX_FMT_YUVA444P9
Definition: pixfmt.h:440
AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:408
ThreadData::inlink
AVFilterLink * inlink
Definition: vf_blend.c:84
AV_PIX_FMT_YUV422P14
#define AV_PIX_FMT_YUV422P14
Definition: pixfmt.h:413
AVFrame::height
int height
Definition: frame.h:389
BLEND_HARDOVERLAY
@ BLEND_HARDOVERLAY
Definition: blend.h:68
framesync.h
blend_frame
static AVFrame * blend_frame(AVFilterContext *ctx, AVFrame *top_buf, const AVFrame *bottom_buf)
Definition: vf_blend.c:270
mode
mode
Definition: ebur128.h:83
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
AV_PIX_FMT_YUVA422P12
#define AV_PIX_FMT_YUVA422P12
Definition: pixfmt.h:444
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:224
avfilter.h
AV_PIX_FMT_GBRAPF32
#define AV_PIX_FMT_GBRAPF32
Definition: pixfmt.h:434
values
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return values
Definition: filter_design.txt:263
AVPixFmtDescriptor::comp
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:105
BLEND_XOR
@ BLEND_XOR
Definition: blend.h:53
BlendContext::all_opacity
double all_opacity
Definition: vf_blend.c:70
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_blend.c:354
AV_PIX_FMT_YUV444P
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:71
AVFilterContext
An instance of a filter.
Definition: avfilter.h:402
AV_PIX_FMT_GBRP
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:158
AVFILTER_FLAG_SLICE_THREADS
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition: avfilter.h:121
av_strdup
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:279
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AV_PIX_FMT_YUV422P
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:70
BLEND_DARKEN
@ BLEND_DARKEN
Definition: blend.h:34
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
blend_frame_for_dualinput
static int blend_frame_for_dualinput(FFFrameSync *fs)
Definition: vf_blend.c:308
BLEND_NORMAL
#define BLEND_NORMAL(name, type)
Definition: vf_blend.c:178
BLEND_AVERAGE
@ BLEND_AVERAGE
Definition: blend.h:32
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:192
FilterParams::opacity
double opacity
Definition: blend.h:74
AV_PIX_FMT_YUV411P
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:73
ThreadData::top
const AVFrame * top
Definition: vf_blend.c:82
FilterParams::blend
void(* blend)(const uint8_t *top, ptrdiff_t top_linesize, const uint8_t *bottom, ptrdiff_t bottom_linesize, uint8_t *dst, ptrdiff_t dst_linesize, ptrdiff_t width, ptrdiff_t height, struct FilterParams *param, double *values, int starty)
Definition: blend.h:77
AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
#define AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
Same as AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, except that the filter will have its filter_frame() c...
Definition: avfilter.h:154
imgutils.h
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561
AV_PIX_FMT_YUV410P
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:72
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
VAR_Y
@ VAR_Y
Definition: vf_blend.c:79
AV_PIX_FMT_YUV440P12
#define AV_PIX_FMT_YUV440P12
Definition: pixfmt.h:410
BLEND_BURN
@ BLEND_BURN
Definition: blend.h:33
AV_PIX_FMT_YUV444P14
#define AV_PIX_FMT_YUV444P14
Definition: pixfmt.h:414
ff_framesync_activate
int ff_framesync_activate(FFFrameSync *fs)
Examine the frames in the filter's input and try to produce output.
Definition: framesync.c:336
ff_framesync_dualinput_get
int ff_framesync_dualinput_get(FFFrameSync *fs, AVFrame **f0, AVFrame **f1)
Definition: framesync.c:371
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Definition: opt.h:228
AV_PIX_FMT_GRAY12
#define AV_PIX_FMT_GRAY12
Definition: pixfmt.h:386
ff_filter_execute
static av_always_inline int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
Definition: internal.h:143
BLEND_REFLECT
@ BLEND_REFLECT
Definition: blend.h:48
BLEND_GRAINEXTRACT
@ BLEND_GRAINEXTRACT
Definition: blend.h:36
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:233
VAR_T
@ VAR_T
Definition: vf_blend.c:79
BOTTOM
#define BOTTOM
Definition: vf_blend.c:34
AVPixFmtDescriptor::log2_chroma_h
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:89
FLAGS
#define FLAGS
Definition: vf_blend.c:91
AV_PIX_FMT_YUVA422P
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition: pixfmt.h:166
BLEND_LINEARLIGHT
@ BLEND_LINEARLIGHT
Definition: blend.h:55
AV_PIX_FMT_YUV420P14
#define AV_PIX_FMT_YUV420P14
Definition: pixfmt.h:412
BLEND_OVERLAY
@ BLEND_OVERLAY
Definition: blend.h:45