FFmpeg
vf_premultiply.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 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/imgutils.h"
24 #include "libavutil/pixdesc.h"
25 #include "libavutil/opt.h"
26 #include "avfilter.h"
27 #include "filters.h"
28 #include "formats.h"
29 #include "framesync.h"
30 #include "video.h"
31 
32 typedef struct ThreadData {
33  AVFrame *m, *a, *d;
34 } ThreadData;
35 
36 typedef struct PreMultiplyContext {
37  const AVClass *class;
40  int nb_planes;
41  int planes;
42  int inverse;
43  int inplace;
44  int half, depth, offset, max;
46 
47  void (*premultiply[AV_VIDEO_MAX_PLANES])(const uint8_t *msrc, const uint8_t *asrc,
48  uint8_t *dst,
49  ptrdiff_t mlinesize, ptrdiff_t alinesize,
50  ptrdiff_t dlinesize,
51  int w, int h,
52  int half, int shift, int offset);
54 
55 #define OFFSET(x) offsetof(PreMultiplyContext, x)
56 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
57 
58 static const AVOption options[] = {
59  { "planes", "set planes", OFFSET(planes), AV_OPT_TYPE_INT, {.i64=0xF}, 0, 0xF, FLAGS },
60  { "inplace","enable inplace mode", OFFSET(inplace), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS },
61  { NULL }
62 };
63 
64 AVFILTER_DEFINE_CLASS_EXT(premultiply, "(un)premultiply", options);
65 
66 static int query_formats(const AVFilterContext *ctx,
67  AVFilterFormatsConfig **cfg_in,
68  AVFilterFormatsConfig **cfg_out)
69 {
70  const PreMultiplyContext *s = ctx->priv;
71 
72  static const enum AVPixelFormat no_alpha_pix_fmts[] = {
81  };
82 
83  static const enum AVPixelFormat alpha_pix_fmts[] = {
89  };
90 
91  return ff_set_common_formats_from_list2(ctx, cfg_in, cfg_out,
92  s->inplace ? alpha_pix_fmts : no_alpha_pix_fmts);
93 }
94 
95 static void premultiply8(const uint8_t *msrc, const uint8_t *asrc,
96  uint8_t *dst,
97  ptrdiff_t mlinesize, ptrdiff_t alinesize,
98  ptrdiff_t dlinesize,
99  int w, int h,
100  int half, int shift, int offset)
101 {
102  int x, y;
103 
104  for (y = 0; y < h; y++) {
105  for (x = 0; x < w; x++) {
106  dst[x] = ((msrc[x] * (((asrc[x] >> 1) & 1) + asrc[x])) + 128) >> 8;
107  }
108 
109  dst += dlinesize;
110  msrc += mlinesize;
111  asrc += alinesize;
112  }
113 }
114 
115 static void premultiply8yuv(const uint8_t *msrc, const uint8_t *asrc,
116  uint8_t *dst,
117  ptrdiff_t mlinesize, ptrdiff_t alinesize,
118  ptrdiff_t dlinesize,
119  int w, int h,
120  int half, int shift, int offset)
121 {
122  int x, y;
123 
124  for (y = 0; y < h; y++) {
125  for (x = 0; x < w; x++) {
126  dst[x] = ((((msrc[x] - 128) * (((asrc[x] >> 1) & 1) + asrc[x]))) >> 8) + 128;
127  }
128 
129  dst += dlinesize;
130  msrc += mlinesize;
131  asrc += alinesize;
132  }
133 }
134 
135 static void premultiply8offset(const uint8_t *msrc, const uint8_t *asrc,
136  uint8_t *dst,
137  ptrdiff_t mlinesize, ptrdiff_t alinesize,
138  ptrdiff_t dlinesize,
139  int w, int h,
140  int half, int shift, int offset)
141 {
142  int x, y;
143 
144  for (y = 0; y < h; y++) {
145  for (x = 0; x < w; x++) {
146  dst[x] = ((((msrc[x] - offset) * (((asrc[x] >> 1) & 1) + asrc[x])) + 128) >> 8) + offset;
147  }
148 
149  dst += dlinesize;
150  msrc += mlinesize;
151  asrc += alinesize;
152  }
153 }
154 
155 static void premultiply16(const uint8_t *mmsrc, const uint8_t *aasrc,
156  uint8_t *ddst,
157  ptrdiff_t mlinesize, ptrdiff_t alinesize,
158  ptrdiff_t dlinesize,
159  int w, int h,
160  int half, int shift, int offset)
161 {
162  const uint16_t *msrc = (const uint16_t *)mmsrc;
163  const uint16_t *asrc = (const uint16_t *)aasrc;
164  uint16_t *dst = (uint16_t *)ddst;
165  int x, y;
166 
167  for (y = 0; y < h; y++) {
168  for (x = 0; x < w; x++) {
169  dst[x] = ((msrc[x] * (((asrc[x] >> 1) & 1) + asrc[x])) + half) >> shift;
170  }
171 
172  dst += dlinesize / 2;
173  msrc += mlinesize / 2;
174  asrc += alinesize / 2;
175  }
176 }
177 
178 static void premultiply16yuv(const uint8_t *mmsrc, const uint8_t *aasrc,
179  uint8_t *ddst,
180  ptrdiff_t mlinesize, ptrdiff_t alinesize,
181  ptrdiff_t dlinesize,
182  int w, int h,
183  int half, int shift, int offset)
184 {
185  const uint16_t *msrc = (const uint16_t *)mmsrc;
186  const uint16_t *asrc = (const uint16_t *)aasrc;
187  uint16_t *dst = (uint16_t *)ddst;
188  int x, y;
189 
190  for (y = 0; y < h; y++) {
191  for (x = 0; x < w; x++) {
192  dst[x] = ((((msrc[x] - half) * (int64_t)(((asrc[x] >> 1) & 1) + asrc[x]))) >> shift) + half;
193  }
194 
195  dst += dlinesize / 2;
196  msrc += mlinesize / 2;
197  asrc += alinesize / 2;
198  }
199 }
200 
201 static void premultiply16offset(const uint8_t *mmsrc, const uint8_t *aasrc,
202  uint8_t *ddst,
203  ptrdiff_t mlinesize, ptrdiff_t alinesize,
204  ptrdiff_t dlinesize,
205  int w, int h,
206  int half, int shift, int offset)
207 {
208  const uint16_t *msrc = (const uint16_t *)mmsrc;
209  const uint16_t *asrc = (const uint16_t *)aasrc;
210  uint16_t *dst = (uint16_t *)ddst;
211  int x, y;
212 
213  for (y = 0; y < h; y++) {
214  for (x = 0; x < w; x++) {
215  dst[x] = ((((msrc[x] - offset) * (int64_t)(((asrc[x] >> 1) & 1) + asrc[x])) + half) >> shift) + offset;
216  }
217 
218  dst += dlinesize / 2;
219  msrc += mlinesize / 2;
220  asrc += alinesize / 2;
221  }
222 }
223 
224 static void premultiplyf32(const uint8_t *mmsrc, const uint8_t *aasrc,
225  uint8_t *ddst,
226  ptrdiff_t mlinesize, ptrdiff_t alinesize,
227  ptrdiff_t dlinesize,
228  int w, int h,
229  int half, int shift, int offset)
230 {
231  const float *msrc = (const float *)mmsrc;
232  const float *asrc = (const float *)aasrc;
233  float *dst = (float *)ddst;
234  int x, y;
235 
236  for (y = 0; y < h; y++) {
237  for (x = 0; x < w; x++) {
238  dst[x] = msrc[x] * asrc[x];
239  }
240 
241  dst += dlinesize / 4;
242  msrc += mlinesize / 4;
243  asrc += alinesize / 4;
244  }
245 }
246 
247 static void premultiplyf32offset(const uint8_t *mmsrc, const uint8_t *aasrc,
248  uint8_t *ddst,
249  ptrdiff_t mlinesize, ptrdiff_t alinesize,
250  ptrdiff_t dlinesize,
251  int w, int h,
252  int half, int shift, int offset)
253 {
254  const float *msrc = (const float *)mmsrc;
255  const float *asrc = (const float *)aasrc;
256  float *dst = (float *)ddst;
257  int x, y;
258 
259  float offsetf = offset / 65535.0f;
260 
261  for (y = 0; y < h; y++) {
262  for (x = 0; x < w; x++) {
263  dst[x] = ((msrc[x] - offsetf) * asrc[x]) + offsetf;
264  }
265 
266  dst += dlinesize / 4;
267  msrc += mlinesize / 4;
268  asrc += alinesize / 4;
269  }
270 }
271 
272 static void unpremultiply8(const uint8_t *msrc, const uint8_t *asrc,
273  uint8_t *dst,
274  ptrdiff_t mlinesize, ptrdiff_t alinesize,
275  ptrdiff_t dlinesize,
276  int w, int h,
277  int half, int max, int offset)
278 {
279  int x, y;
280 
281  for (y = 0; y < h; y++) {
282  for (x = 0; x < w; x++) {
283  if (asrc[x] > 0 && asrc[x] < 255)
284  dst[x] = FFMIN(msrc[x] * 255 / asrc[x], 255);
285  else
286  dst[x] = msrc[x];
287  }
288 
289  dst += dlinesize;
290  msrc += mlinesize;
291  asrc += alinesize;
292  }
293 }
294 
295 static void unpremultiply8yuv(const uint8_t *msrc, const uint8_t *asrc,
296  uint8_t *dst,
297  ptrdiff_t mlinesize, ptrdiff_t alinesize,
298  ptrdiff_t dlinesize,
299  int w, int h,
300  int half, int max, int offset)
301 {
302  int x, y;
303 
304  for (y = 0; y < h; y++) {
305  for (x = 0; x < w; x++) {
306  if (asrc[x] > 0 && asrc[x] < 255)
307  dst[x] = FFMIN((msrc[x] - 128) * 255 / asrc[x] + 128, 255);
308  else
309  dst[x] = msrc[x];
310  }
311 
312  dst += dlinesize;
313  msrc += mlinesize;
314  asrc += alinesize;
315  }
316 }
317 
318 static void unpremultiply8offset(const uint8_t *msrc, const uint8_t *asrc,
319  uint8_t *dst,
320  ptrdiff_t mlinesize, ptrdiff_t alinesize,
321  ptrdiff_t dlinesize,
322  int w, int h,
323  int half, int max, int offset)
324 {
325  int x, y;
326 
327  for (y = 0; y < h; y++) {
328  for (x = 0; x < w; x++) {
329  if (asrc[x] > 0 && asrc[x] < 255)
330  dst[x] = FFMIN(FFMAX(msrc[x] - offset, 0) * 255 / asrc[x] + offset, 255);
331  else
332  dst[x] = msrc[x];
333  }
334 
335  dst += dlinesize;
336  msrc += mlinesize;
337  asrc += alinesize;
338  }
339 }
340 
341 static void unpremultiply16(const uint8_t *mmsrc, const uint8_t *aasrc,
342  uint8_t *ddst,
343  ptrdiff_t mlinesize, ptrdiff_t alinesize,
344  ptrdiff_t dlinesize,
345  int w, int h,
346  int half, int max, int offset)
347 {
348  const uint16_t *msrc = (const uint16_t *)mmsrc;
349  const uint16_t *asrc = (const uint16_t *)aasrc;
350  uint16_t *dst = (uint16_t *)ddst;
351  int x, y;
352 
353  for (y = 0; y < h; y++) {
354  for (x = 0; x < w; x++) {
355  if (asrc[x] > 0 && asrc[x] < max)
356  dst[x] = FFMIN(msrc[x] * (unsigned)max / asrc[x], max);
357  else
358  dst[x] = msrc[x];
359  }
360 
361  dst += dlinesize / 2;
362  msrc += mlinesize / 2;
363  asrc += alinesize / 2;
364  }
365 }
366 
367 static void unpremultiply16yuv(const uint8_t *mmsrc, const uint8_t *aasrc,
368  uint8_t *ddst,
369  ptrdiff_t mlinesize, ptrdiff_t alinesize,
370  ptrdiff_t dlinesize,
371  int w, int h,
372  int half, int max, int offset)
373 {
374  const uint16_t *msrc = (const uint16_t *)mmsrc;
375  const uint16_t *asrc = (const uint16_t *)aasrc;
376  uint16_t *dst = (uint16_t *)ddst;
377  int x, y;
378 
379  for (y = 0; y < h; y++) {
380  for (x = 0; x < w; x++) {
381  if (asrc[x] > 0 && asrc[x] < max)
382  dst[x] = FFMAX(FFMIN((msrc[x] - half) * max / asrc[x], half - 1), -half) + half;
383  else
384  dst[x] = msrc[x];
385  }
386 
387  dst += dlinesize / 2;
388  msrc += mlinesize / 2;
389  asrc += alinesize / 2;
390  }
391 }
392 
393 static void unpremultiply16offset(const uint8_t *mmsrc, const uint8_t *aasrc,
394  uint8_t *ddst,
395  ptrdiff_t mlinesize, ptrdiff_t alinesize,
396  ptrdiff_t dlinesize,
397  int w, int h,
398  int half, int max, int offset)
399 {
400  const uint16_t *msrc = (const uint16_t *)mmsrc;
401  const uint16_t *asrc = (const uint16_t *)aasrc;
402  uint16_t *dst = (uint16_t *)ddst;
403  int x, y;
404 
405  for (y = 0; y < h; y++) {
406  for (x = 0; x < w; x++) {
407  if (asrc[x] > 0 && asrc[x] < max)
408  dst[x] = FFMAX(FFMIN(FFMAX(msrc[x] - offset, 0) * (unsigned)max / asrc[x] + offset, max), 0);
409  else
410  dst[x] = msrc[x];
411  }
412 
413  dst += dlinesize / 2;
414  msrc += mlinesize / 2;
415  asrc += alinesize / 2;
416  }
417 }
418 
419 static void unpremultiplyf32(const uint8_t *mmsrc, const uint8_t *aasrc,
420  uint8_t *ddst,
421  ptrdiff_t mlinesize, ptrdiff_t alinesize,
422  ptrdiff_t dlinesize,
423  int w, int h,
424  int half, int max, int offset)
425 {
426  const float *msrc = (const float *)mmsrc;
427  const float *asrc = (const float *)aasrc;
428 
429  float *dst = (float *)ddst;
430  int x, y;
431 
432  for (y = 0; y < h; y++) {
433  for (x = 0; x < w; x++) {
434  if (asrc[x] > 0.0f)
435  dst[x] = msrc[x] / asrc[x];
436  else
437  dst[x] = msrc[x];
438  }
439 
440  dst += dlinesize / 4;
441  msrc += mlinesize / 4;
442  asrc += alinesize / 4;
443  }
444 }
445 
446 static void unpremultiplyf32offset(const uint8_t *mmsrc, const uint8_t *aasrc,
447  uint8_t *ddst,
448  ptrdiff_t mlinesize, ptrdiff_t alinesize,
449  ptrdiff_t dlinesize,
450  int w, int h,
451  int half, int max, int offset)
452 {
453  const float *msrc = (const float *)mmsrc;
454  const float *asrc = (const float *)aasrc;
455 
456  float *dst = (float *)ddst;
457  int x, y;
458 
459  float offsetf = offset / 65535.0f;
460 
461  for (y = 0; y < h; y++) {
462  for (x = 0; x < w; x++) {
463  if (asrc[x] > 0.0f)
464  dst[x] = (msrc[x] - offsetf) / asrc[x] + offsetf;
465  else
466  dst[x] = msrc[x];
467  }
468 
469  dst += dlinesize / 4;
470  msrc += mlinesize / 4;
471  asrc += alinesize / 4;
472  }
473 }
474 
475 static int premultiply_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
476 {
477  PreMultiplyContext *s = ctx->priv;
478  ThreadData *td = arg;
479  AVFrame *out = td->d;
480  AVFrame *alpha = td->a;
481  AVFrame *base = td->m;
482  int p;
483 
484  for (p = 0; p < s->nb_planes; p++) {
485  const int slice_start = (s->height[p] * jobnr) / nb_jobs;
486  const int slice_end = (s->height[p] * (jobnr+1)) / nb_jobs;
487 
488  if (!((1 << p) & s->planes) || p == 3) {
489  av_image_copy_plane(out->data[p] + slice_start * out->linesize[p],
490  out->linesize[p],
491  base->data[p] + slice_start * base->linesize[p],
492  base->linesize[p],
493  s->linesize[p], slice_end - slice_start);
494  continue;
495  }
496 
497  s->premultiply[p](base->data[p] + slice_start * base->linesize[p],
498  s->inplace ? alpha->data[3] + slice_start * alpha->linesize[3] :
499  alpha->data[0] + slice_start * alpha->linesize[0],
500  out->data[p] + slice_start * out->linesize[p],
501  base->linesize[p], s->inplace ? alpha->linesize[3] : alpha->linesize[0],
502  out->linesize[p],
503  s->width[p], slice_end - slice_start,
504  s->half, s->inverse ? s->max : s->depth, s->offset);
505  }
506 
507  return 0;
508 }
509 
512 {
513  PreMultiplyContext *s = ctx->priv;
514  AVFilterLink *outlink = ctx->outputs[0];
515 
516  if (ctx->is_disabled) {
517  *out = av_frame_clone(base);
518  if (!*out)
519  return AVERROR(ENOMEM);
520  } else {
521  ThreadData td;
522  int full, limited;
523 
524  *out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
525  if (!*out)
526  return AVERROR(ENOMEM);
528 
529  full = base->color_range == AVCOL_RANGE_JPEG;
530  limited = base->color_range == AVCOL_RANGE_MPEG;
531 
532  if (s->inverse) {
533  switch (outlink->format) {
534  case AV_PIX_FMT_YUV444P:
535  case AV_PIX_FMT_YUVA444P:
536  s->premultiply[0] = full ? unpremultiply8 : unpremultiply8offset;
537  s->premultiply[1] = s->premultiply[2] = unpremultiply8yuv;
538  break;
539  case AV_PIX_FMT_YUVJ444P:
540  s->premultiply[0] = unpremultiply8;
541  s->premultiply[1] = s->premultiply[2] = unpremultiply8yuv;
542  break;
543  case AV_PIX_FMT_GBRP:
544  case AV_PIX_FMT_GBRAP:
545  s->premultiply[0] = s->premultiply[1] = s->premultiply[2] = limited ? unpremultiply8offset : unpremultiply8;
546  break;
547  case AV_PIX_FMT_YUV444P9:
556  s->premultiply[0] = full ? unpremultiply16 : unpremultiply16offset;
557  s->premultiply[1] = s->premultiply[2] = unpremultiply16yuv;
558  break;
559  case AV_PIX_FMT_GBRP9:
560  case AV_PIX_FMT_GBRP10:
561  case AV_PIX_FMT_GBRAP10:
562  case AV_PIX_FMT_GBRP12:
563  case AV_PIX_FMT_GBRAP12:
564  case AV_PIX_FMT_GBRP14:
565  case AV_PIX_FMT_GBRP16:
566  case AV_PIX_FMT_GBRAP16:
567  s->premultiply[0] = s->premultiply[1] = s->premultiply[2] = limited ? unpremultiply16offset : unpremultiply16;
568  break;
569  case AV_PIX_FMT_GBRPF32:
570  case AV_PIX_FMT_GBRAPF32:
571  s->premultiply[0] = s->premultiply[1] = s->premultiply[2] = limited ? unpremultiplyf32offset : unpremultiplyf32;
572  break;
573  case AV_PIX_FMT_GRAY8:
574  s->premultiply[0] = limited ? unpremultiply8offset : unpremultiply8;
575  break;
576  case AV_PIX_FMT_GRAY9:
577  case AV_PIX_FMT_GRAY10:
578  case AV_PIX_FMT_GRAY12:
579  case AV_PIX_FMT_GRAY14:
580  case AV_PIX_FMT_GRAY16:
581  s->premultiply[0] = limited ? unpremultiply16offset : unpremultiply16;
582  break;
583  }
584  } else {
585  switch (outlink->format) {
586  case AV_PIX_FMT_YUV444P:
587  case AV_PIX_FMT_YUVA444P:
588  s->premultiply[0] = full ? premultiply8 : premultiply8offset;
589  s->premultiply[1] = s->premultiply[2] = premultiply8yuv;
590  break;
591  case AV_PIX_FMT_YUVJ444P:
592  s->premultiply[0] = premultiply8;
593  s->premultiply[1] = s->premultiply[2] = premultiply8yuv;
594  break;
595  case AV_PIX_FMT_GBRP:
596  case AV_PIX_FMT_GBRAP:
597  s->premultiply[0] = s->premultiply[1] = s->premultiply[2] = limited ? premultiply8offset : premultiply8;
598  break;
599  case AV_PIX_FMT_YUV444P9:
608  s->premultiply[0] = full ? premultiply16 : premultiply16offset;
609  s->premultiply[1] = s->premultiply[2] = premultiply16yuv;
610  break;
611  case AV_PIX_FMT_GBRP9:
612  case AV_PIX_FMT_GBRP10:
613  case AV_PIX_FMT_GBRAP10:
614  case AV_PIX_FMT_GBRP12:
615  case AV_PIX_FMT_GBRAP12:
616  case AV_PIX_FMT_GBRP14:
617  case AV_PIX_FMT_GBRP16:
618  case AV_PIX_FMT_GBRAP16:
619  s->premultiply[0] = s->premultiply[1] = s->premultiply[2] = limited ? premultiply16offset : premultiply16;
620  break;
621  case AV_PIX_FMT_GBRPF32:
622  case AV_PIX_FMT_GBRAPF32:
623  s->premultiply[0] = s->premultiply[1] = s->premultiply[2] = limited ? premultiplyf32offset: premultiplyf32;
624  break;
625  case AV_PIX_FMT_GRAY8:
626  s->premultiply[0] = limited ? premultiply8offset : premultiply8;
627  break;
628  case AV_PIX_FMT_GRAY9:
629  case AV_PIX_FMT_GRAY10:
630  case AV_PIX_FMT_GRAY12:
631  case AV_PIX_FMT_GRAY14:
632  case AV_PIX_FMT_GRAY16:
633  s->premultiply[0] = limited ? premultiply16offset : premultiply16;
634  break;
635  }
636  }
637 
638  td.d = *out;
639  td.a = alpha;
640  td.m = base;
642  FFMIN(s->height[0], ff_filter_get_nb_threads(ctx)));
643  }
644 
645  return 0;
646 }
647 
649 {
650  AVFilterContext *ctx = fs->parent;
651  PreMultiplyContext *s = fs->opaque;
652  AVFilterLink *outlink = ctx->outputs[0];
653  AVFrame *out = NULL, *base, *alpha;
654  int ret;
655 
656  if ((ret = ff_framesync_get_frame(&s->fs, 0, &base, 0)) < 0 ||
657  (ret = ff_framesync_get_frame(&s->fs, 1, &alpha, 0)) < 0)
658  return ret;
659 
660  if ((ret = filter_frame(ctx, &out, base, alpha)) < 0)
661  return ret;
662 
663  out->pts = av_rescale_q(base->pts, s->fs.time_base, outlink->time_base);
664 
665  return ff_filter_frame(outlink, out);
666 }
667 
669 {
670  AVFilterContext *ctx = inlink->dst;
671  PreMultiplyContext *s = ctx->priv;
673  int vsub, hsub, ret;
674 
675  s->nb_planes = av_pix_fmt_count_planes(inlink->format);
676 
677  if ((ret = av_image_fill_linesizes(s->linesize, inlink->format, inlink->w)) < 0)
678  return ret;
679 
680  hsub = desc->log2_chroma_w;
681  vsub = desc->log2_chroma_h;
682  s->height[1] = s->height[2] = AV_CEIL_RSHIFT(inlink->h, vsub);
683  s->height[0] = s->height[3] = inlink->h;
684  s->width[1] = s->width[2] = AV_CEIL_RSHIFT(inlink->w, hsub);
685  s->width[0] = s->width[3] = inlink->w;
686 
687  s->depth = desc->flags & AV_PIX_FMT_FLAG_FLOAT ? 16 : desc->comp[0].depth;
688  s->max = (1 << s->depth) - 1;
689  s->half = (1 << s->depth) / 2;
690  s->offset = 16 << (s->depth - 8);
691 
692  return 0;
693 }
694 
695 static int config_output(AVFilterLink *outlink)
696 {
697  AVFilterContext *ctx = outlink->src;
698  PreMultiplyContext *s = ctx->priv;
699  AVFilterLink *base = ctx->inputs[0];
702  FilterLink *ol = ff_filter_link(outlink);
703  FFFrameSyncIn *in;
704  int ret;
705 
706  if (!s->inplace) {
707  alpha = ctx->inputs[1];
708 
709  if (base->w != alpha->w ||
710  base->h != alpha->h) {
711  av_log(ctx, AV_LOG_ERROR, "First input link %s parameters "
712  "(size %dx%d) do not match the corresponding "
713  "second input link %s parameters (%dx%d) ",
714  ctx->input_pads[0].name, base->w, base->h,
715  ctx->input_pads[1].name, alpha->w, alpha->h);
716  return AVERROR(EINVAL);
717  }
718  }
719 
720  outlink->w = base->w;
721  outlink->h = base->h;
722  outlink->time_base = base->time_base;
723  outlink->sample_aspect_ratio = base->sample_aspect_ratio;
724  ol->frame_rate = il->frame_rate;
725 
726  if (s->inplace)
727  return 0;
728 
729  if ((ret = ff_framesync_init(&s->fs, ctx, 2)) < 0)
730  return ret;
731 
732  in = s->fs.in;
733  in[0].time_base = base->time_base;
734  in[1].time_base = alpha->time_base;
735  in[0].sync = 1;
736  in[0].before = EXT_STOP;
737  in[0].after = EXT_INFINITY;
738  in[1].sync = 1;
739  in[1].before = EXT_STOP;
740  in[1].after = EXT_INFINITY;
741  s->fs.opaque = s;
742  s->fs.on_event = process_frame;
743 
744  return ff_framesync_configure(&s->fs);
745 }
746 
748 {
749  PreMultiplyContext *s = ctx->priv;
750 
751  if (s->inplace) {
752  AVFrame *frame = NULL;
753  AVFrame *out = NULL;
754  int ret, status;
755  int64_t pts;
756 
758 
759  if ((ret = ff_inlink_consume_frame(ctx->inputs[0], &frame)) > 0) {
762  if (ret < 0)
763  return ret;
764  ret = ff_filter_frame(ctx->outputs[0], out);
765  }
766  if (ret < 0) {
767  return ret;
768  } else if (ff_inlink_acknowledge_status(ctx->inputs[0], &status, &pts)) {
769  ff_outlink_set_status(ctx->outputs[0], status, pts);
770  return 0;
771  } else {
772  if (ff_outlink_frame_wanted(ctx->outputs[0]))
773  ff_inlink_request_frame(ctx->inputs[0]);
774  return 0;
775  }
776  } else {
777  return ff_framesync_activate(&s->fs);
778  }
779 }
780 
782 {
783  PreMultiplyContext *s = ctx->priv;
784  AVFilterPad pad = { 0 };
785  int ret;
786 
787  if (!strcmp(ctx->filter->name, "unpremultiply"))
788  s->inverse = 1;
789 
790  pad.type = AVMEDIA_TYPE_VIDEO;
791  pad.name = "main";
793 
794  if ((ret = ff_append_inpad(ctx, &pad)) < 0)
795  return ret;
796 
797  if (!s->inplace) {
798  pad.type = AVMEDIA_TYPE_VIDEO;
799  pad.name = "alpha";
800  pad.config_props = NULL;
801 
802  if ((ret = ff_append_inpad(ctx, &pad)) < 0)
803  return ret;
804  }
805 
806  return 0;
807 }
808 
810 {
811  PreMultiplyContext *s = ctx->priv;
812 
813  if (!s->inplace)
814  ff_framesync_uninit(&s->fs);
815 }
816 
818  {
819  .name = "default",
820  .type = AVMEDIA_TYPE_VIDEO,
821  .config_props = config_output,
822  },
823 };
824 
825 #if CONFIG_PREMULTIPLY_FILTER
826 
827 const AVFilter ff_vf_premultiply = {
828  .name = "premultiply",
829  .description = NULL_IF_CONFIG_SMALL("PreMultiply first stream with first plane of second stream."),
830  .priv_size = sizeof(PreMultiplyContext),
831  .init = init,
832  .uninit = uninit,
833  .activate = activate,
834  .inputs = NULL,
837  .priv_class = &premultiply_class,
841 };
842 
843 #endif /* CONFIG_PREMULTIPLY_FILTER */
844 
845 #if CONFIG_UNPREMULTIPLY_FILTER
846 
848  .name = "unpremultiply",
849  .description = NULL_IF_CONFIG_SMALL("UnPreMultiply first stream with first plane of second stream."),
850  .priv_class = &premultiply_class,
851  .priv_size = sizeof(PreMultiplyContext),
852  .init = init,
853  .uninit = uninit,
854  .activate = activate,
855  .inputs = NULL,
861 };
862 
863 #endif /* CONFIG_UNPREMULTIPLY_FILTER */
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:116
PreMultiplyContext::offset
int offset
Definition: vf_premultiply.c:44
AV_PIX_FMT_GBRAP16
#define AV_PIX_FMT_GBRAP16
Definition: pixfmt.h:525
FFFrameSyncIn::time_base
AVRational time_base
Time base for the incoming frames.
Definition: framesync.h:117
ff_framesync_configure
int ff_framesync_configure(FFFrameSync *fs)
Configure a frame sync structure.
Definition: framesync.c:137
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
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:301
out
FILE * out
Definition: movenc.c:55
PreMultiplyContext::planes
int planes
Definition: vf_premultiply.c:41
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1062
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3170
ff_framesync_get_frame
int ff_framesync_get_frame(FFFrameSync *fs, unsigned in, AVFrame **rframe, unsigned get)
Get the current frame in an input.
Definition: framesync.c:269
int64_t
long long int64_t
Definition: coverity.c:34
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
AV_VIDEO_MAX_PLANES
#define AV_VIDEO_MAX_PLANES
Maximum number of planes in any pixel format.
Definition: pixfmt.h:40
AV_PIX_FMT_FLAG_FLOAT
#define AV_PIX_FMT_FLAG_FLOAT
The pixel format contains IEEE-754 floating point values.
Definition: pixdesc.h:158
unpremultiply16yuv
static void unpremultiply16yuv(const uint8_t *mmsrc, const uint8_t *aasrc, uint8_t *ddst, ptrdiff_t mlinesize, ptrdiff_t alinesize, ptrdiff_t dlinesize, int w, int h, int half, int max, int offset)
Definition: vf_premultiply.c:367
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:162
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:389
PreMultiplyContext::depth
int depth
Definition: vf_premultiply.c:44
pixdesc.h
w
uint8_t w
Definition: llviddspenc.c:38
AVCOL_RANGE_JPEG
@ AVCOL_RANGE_JPEG
Full range content.
Definition: pixfmt.h:717
AVOption
AVOption.
Definition: opt.h:429
unpremultiply8offset
static void unpremultiply8offset(const uint8_t *msrc, const uint8_t *asrc, uint8_t *dst, ptrdiff_t mlinesize, ptrdiff_t alinesize, ptrdiff_t dlinesize, int w, int h, int half, int max, int offset)
Definition: vf_premultiply.c:318
half
static uint8_t half(int a, int b)
Definition: mobiclip.c:539
PreMultiplyContext
Definition: vf_premultiply.c:36
base
uint8_t base
Definition: vp3data.h:128
PreMultiplyContext::linesize
int linesize[AV_VIDEO_MAX_PLANES]
Definition: vf_premultiply.c:39
max
#define max(a, b)
Definition: cuda_runtime.h:33
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
unpremultiplyf32
static void unpremultiplyf32(const uint8_t *mmsrc, const uint8_t *aasrc, uint8_t *ddst, ptrdiff_t mlinesize, ptrdiff_t alinesize, ptrdiff_t dlinesize, int w, int h, int half, int max, int offset)
Definition: vf_premultiply.c:419
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:205
FFFrameSync
Frame sync structure.
Definition: framesync.h:168
EXT_INFINITY
@ EXT_INFINITY
Extend the frame to infinity.
Definition: framesync.h:75
video.h
AV_PIX_FMT_GRAY9
#define AV_PIX_FMT_GRAY9
Definition: pixfmt.h:482
av_image_copy_plane
void av_image_copy_plane(uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize, int bytewidth, int height)
Copy image plane from src to dst.
Definition: imgutils.c:374
hsub
static void hsub(htype *dst, const htype *src, int bins)
Definition: vf_median.c:74
formats.h
planes
static const struct @466 planes[]
ff_inlink_consume_frame
int ff_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe)
Take a frame from the link's FIFO and update the link's stats.
Definition: avfilter.c:1491
av_pix_fmt_count_planes
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3210
premultiplyf32offset
static void premultiplyf32offset(const uint8_t *mmsrc, const uint8_t *aasrc, uint8_t *ddst, ptrdiff_t mlinesize, ptrdiff_t alinesize, ptrdiff_t dlinesize, int w, int h, int half, int shift, int offset)
Definition: vf_premultiply.c:247
options
static const AVOption options[]
Definition: vf_premultiply.c:58
EXT_STOP
@ EXT_STOP
Completely stop all streams with this one.
Definition: framesync.h:65
FF_FILTER_FORWARD_STATUS_BACK_ALL
#define FF_FILTER_FORWARD_STATUS_BACK_ALL(outlink, filter)
Forward the status on an output link to all input links.
Definition: filters.h:447
AV_PIX_FMT_GBRP14
#define AV_PIX_FMT_GBRP14
Definition: pixfmt.h:520
ff_append_inpad
int ff_append_inpad(AVFilterContext *f, AVFilterPad *p)
Append a new input/output pad to the filter's list of such pads.
Definition: avfilter.c:127
ff_vf_unpremultiply
const AVFilter ff_vf_unpremultiply
slice_end
static int slice_end(AVCodecContext *avctx, AVFrame *pict, int *got_output)
Handle slice ends.
Definition: mpeg12dec.c:1719
AV_PIX_FMT_GBRAP
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:212
PreMultiplyContext::height
int height[AV_VIDEO_MAX_PLANES]
Definition: vf_premultiply.c:38
AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:518
AV_PIX_FMT_YUVA444P16
#define AV_PIX_FMT_YUVA444P16
Definition: pixfmt.h:547
FFFrameSyncIn
Input stream structure.
Definition: framesync.h:102
unpremultiply8yuv
static void unpremultiply8yuv(const uint8_t *msrc, const uint8_t *asrc, uint8_t *dst, ptrdiff_t mlinesize, ptrdiff_t alinesize, ptrdiff_t dlinesize, int w, int h, int half, int max, int offset)
Definition: vf_premultiply.c:295
pts
static int64_t pts
Definition: transcode_aac.c:644
AV_PIX_FMT_GRAY16
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:486
FFFrameSyncIn::sync
unsigned sync
Synchronization level: frames on input at the highest sync level will generate output frame events.
Definition: framesync.h:160
AVFILTER_FLAG_DYNAMIC_INPUTS
#define AVFILTER_FLAG_DYNAMIC_INPUTS
The number of the filter inputs is not determined just by AVFilter.inputs.
Definition: avfilter.h:141
AVFilterPad
A filter pad used for either input or output.
Definition: filters.h:38
AV_PIX_FMT_YUV444P10
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:505
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:209
av_cold
#define av_cold
Definition: attributes.h:90
premultiply_slice
static int premultiply_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Definition: vf_premultiply.c:475
AV_PIX_FMT_GBRAP10
#define AV_PIX_FMT_GBRAP10
Definition: pixfmt.h:522
ff_outlink_set_status
static void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the source filter.
Definition: filters.h:424
process_frame
static int process_frame(FFFrameSync *fs)
Definition: vf_premultiply.c:648
ff_inlink_request_frame
void ff_inlink_request_frame(AVFilterLink *link)
Mark that a frame is wanted on the link.
Definition: avfilter.c:1594
av_image_fill_linesizes
int av_image_fill_linesizes(int linesizes[4], enum AVPixelFormat pix_fmt, int width)
Fill plane linesizes for an image with pixel format pix_fmt and width width.
Definition: imgutils.c:89
s
#define s(width, name)
Definition: cbs_vp9.c:198
AV_PIX_FMT_GBRAP12
#define AV_PIX_FMT_GBRAP12
Definition: pixfmt.h:523
AV_PIX_FMT_YUV444P16
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:515
AV_CEIL_RSHIFT
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:60
PreMultiplyContext::half
int half
Definition: vf_premultiply.c:44
PreMultiplyContext::max
int max
Definition: vf_premultiply.c:44
filters.h
AV_PIX_FMT_YUVA444P12
#define AV_PIX_FMT_YUVA444P12
Definition: pixfmt.h:544
ctx
AVFormatContext * ctx
Definition: movenc.c:49
AV_PIX_FMT_GRAY14
#define AV_PIX_FMT_GRAY14
Definition: pixfmt.h:485
av_frame_clone
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
Definition: frame.c:597
av_rescale_q
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:142
unpremultiply8
static void unpremultiply8(const uint8_t *msrc, const uint8_t *asrc, uint8_t *dst, ptrdiff_t mlinesize, ptrdiff_t alinesize, ptrdiff_t dlinesize, int w, int h, int half, int max, int offset)
Definition: vf_premultiply.c:272
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: filters.h:263
FLAGS
#define FLAGS
Definition: vf_premultiply.c:56
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:87
arg
const char * arg
Definition: jacosubdec.c:67
AV_PIX_FMT_GRAY10
#define AV_PIX_FMT_GRAY10
Definition: pixfmt.h:483
AV_PIX_FMT_GBRP16
#define AV_PIX_FMT_GBRP16
Definition: pixfmt.h:521
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:75
premultiply16offset
static void premultiply16offset(const uint8_t *mmsrc, const uint8_t *aasrc, uint8_t *ddst, ptrdiff_t mlinesize, ptrdiff_t alinesize, ptrdiff_t dlinesize, int w, int h, int half, int shift, int offset)
Definition: vf_premultiply.c:201
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:713
fs
#define fs(width, name, subs,...)
Definition: cbs_vp9.c:200
premultiply8offset
static void premultiply8offset(const uint8_t *msrc, const uint8_t *asrc, uint8_t *dst, ptrdiff_t mlinesize, ptrdiff_t alinesize, ptrdiff_t dlinesize, int w, int h, int half, int shift, int offset)
Definition: vf_premultiply.c:135
AVFILTER_DEFINE_CLASS_EXT
AVFILTER_DEFINE_CLASS_EXT(premultiply, "(un)premultiply", options)
init
static av_cold int init(AVFilterContext *ctx)
Definition: vf_premultiply.c:781
OFFSET
#define OFFSET(x)
Definition: vf_premultiply.c:55
inputs
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 inputs
Definition: filter_design.txt:243
AV_PIX_FMT_GRAY8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:81
AV_PIX_FMT_GBRP9
#define AV_PIX_FMT_GBRP9
Definition: pixfmt.h:517
ff_inlink_acknowledge_status
int ff_inlink_acknowledge_status(AVFilterLink *link, int *rstatus, int64_t *rpts)
Test and acknowledge the change of status on the link.
Definition: avfilter.c:1438
ff_vf_premultiply
const AVFilter ff_vf_premultiply
AVFilterFormatsConfig
Lists of formats / etc.
Definition: avfilter.h:111
ff_filter_link
static FilterLink * ff_filter_link(AVFilterLink *link)
Definition: filters.h:197
activate
static int activate(AVFilterContext *ctx)
Definition: vf_premultiply.c:747
AVFilterPad::config_props
int(* config_props)(AVFilterLink *link)
Link configuration callback.
Definition: filters.h:118
f
f
Definition: af_crystalizer.c:122
ThreadData::m
AVFrame * m
Definition: vf_maskedclamp.c:34
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:94
premultiplyf32
static void premultiplyf32(const uint8_t *mmsrc, const uint8_t *aasrc, uint8_t *ddst, ptrdiff_t mlinesize, ptrdiff_t alinesize, ptrdiff_t dlinesize, int w, int h, int half, int shift, int offset)
Definition: vf_premultiply.c:224
shift
static int shift(int a, int b)
Definition: bonk.c:261
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:83
unpremultiply16offset
static void unpremultiply16offset(const uint8_t *mmsrc, const uint8_t *aasrc, uint8_t *ddst, ptrdiff_t mlinesize, ptrdiff_t alinesize, ptrdiff_t dlinesize, int w, int h, int half, int max, int offset)
Definition: vf_premultiply.c:393
unpremultiplyf32offset
static void unpremultiplyf32offset(const uint8_t *mmsrc, const uint8_t *aasrc, uint8_t *ddst, ptrdiff_t mlinesize, ptrdiff_t alinesize, ptrdiff_t dlinesize, int w, int h, int half, int max, int offset)
Definition: vf_premultiply.c:446
AV_PIX_FMT_GBRPF32
#define AV_PIX_FMT_GBRPF32
Definition: pixfmt.h:532
AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:509
config_output
static int config_output(AVFilterLink *outlink)
Definition: vf_premultiply.c:695
premultiply8yuv
static void premultiply8yuv(const uint8_t *msrc, const uint8_t *asrc, uint8_t *dst, ptrdiff_t mlinesize, ptrdiff_t alinesize, ptrdiff_t dlinesize, int w, int h, int half, int shift, int offset)
Definition: vf_premultiply.c:115
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:174
AV_PIX_FMT_YUVA444P10
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:542
offset
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
Definition: writing_filters.txt:86
premultiply8
static void premultiply8(const uint8_t *msrc, const uint8_t *asrc, uint8_t *dst, ptrdiff_t mlinesize, ptrdiff_t alinesize, ptrdiff_t dlinesize, int w, int h, int half, int shift, int offset)
Definition: vf_premultiply.c:95
ThreadData::d
void ** d
Definition: af_crystalizer.c:47
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_premultiply.c:809
PreMultiplyContext::premultiply
void(* premultiply[AV_VIDEO_MAX_PLANES])(const uint8_t *msrc, const uint8_t *asrc, uint8_t *dst, ptrdiff_t mlinesize, ptrdiff_t alinesize, ptrdiff_t dlinesize, int w, int h, int half, int shift, int offset)
Definition: vf_premultiply.c:47
AV_PIX_FMT_GBRP12
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:519
ff_filter_get_nb_threads
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Definition: avfilter.c:841
ThreadData
Used for passing data between threads.
Definition: dsddec.c:71
FILTER_QUERY_FUNC2
#define FILTER_QUERY_FUNC2(func)
Definition: filters.h:239
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
unpremultiply16
static void unpremultiply16(const uint8_t *mmsrc, const uint8_t *aasrc, uint8_t *ddst, ptrdiff_t mlinesize, ptrdiff_t alinesize, ptrdiff_t dlinesize, int w, int h, int half, int max, int offset)
Definition: vf_premultiply.c:341
AVFilterPad::name
const char * name
Pad name.
Definition: filters.h:44
AVCOL_RANGE_MPEG
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition: pixfmt.h:700
AV_PIX_FMT_YUV444P9
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:501
slice_start
static int slice_start(SliceContext *sc, VVCContext *s, VVCFrameContext *fc, const CodedBitstreamUnit *unit, const int is_first_slice)
Definition: dec.c:738
AVFilter
Filter definition.
Definition: avfilter.h:201
ret
ret
Definition: filter_design.txt:187
AVFilterPad::type
enum AVMediaType type
AVFilterPad type.
Definition: filters.h:49
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:539
ff_framesync_init
int ff_framesync_init(FFFrameSync *fs, AVFilterContext *parent, unsigned nb_in)
Initialize a frame sync structure.
Definition: framesync.c:86
PreMultiplyContext::inverse
int inverse
Definition: vf_premultiply.c:42
FFFrameSyncIn::before
enum FFFrameSyncExtMode before
Extrapolation mode for timestamps before the first frame.
Definition: framesync.h:107
PreMultiplyContext::fs
FFFrameSync fs
Definition: vf_premultiply.c:45
status
ov_status_e status
Definition: dnn_backend_openvino.c:100
ff_set_common_formats_from_list2
int ff_set_common_formats_from_list2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, const int *fmts)
Definition: formats.c:1016
framesync.h
ff_filter_execute
int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
Definition: avfilter.c:1667
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
premultiply16yuv
static void premultiply16yuv(const uint8_t *mmsrc, const uint8_t *aasrc, uint8_t *ddst, ptrdiff_t mlinesize, ptrdiff_t alinesize, ptrdiff_t dlinesize, int w, int h, int half, int shift, int offset)
Definition: vf_premultiply.c:178
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
avfilter.h
AV_PIX_FMT_GBRAPF32
#define AV_PIX_FMT_GBRAPF32
Definition: pixfmt.h:533
premultiply16
static void premultiply16(const uint8_t *mmsrc, const uint8_t *aasrc, uint8_t *ddst, ptrdiff_t mlinesize, ptrdiff_t alinesize, ptrdiff_t dlinesize, int w, int h, int half, int shift, int offset)
Definition: vf_premultiply.c:155
ThreadData::a
AVFrame * a
Definition: vf_premultiply.c:33
premultiply_outputs
static const AVFilterPad premultiply_outputs[]
Definition: vf_premultiply.c:817
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:78
AVFilterContext
An instance of a filter.
Definition: avfilter.h:457
PreMultiplyContext::inplace
int inplace
Definition: vf_premultiply.c:43
AV_PIX_FMT_GBRP
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:165
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:152
desc
const char * desc
Definition: libsvtav1.c:79
query_formats
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
Definition: vf_premultiply.c:66
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
config_input
static int config_input(AVFilterLink *inlink)
Definition: vf_premultiply.c:668
alpha
static const int16_t alpha[]
Definition: ilbcdata.h:55
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition: opt.h:327
PreMultiplyContext::nb_planes
int nb_planes
Definition: vf_premultiply.c:40
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:190
imgutils.h
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
FFFrameSyncIn::after
enum FFFrameSyncExtMode after
Extrapolation mode for timestamps after the last frame.
Definition: framesync.h:112
h
h
Definition: vp9dsp_template.c:2070
ff_outlink_frame_wanted
the definition of that something depends on the semantic of the filter The callback must examine the status of the filter s links and proceed accordingly The status of output links is stored in the status_in and status_out fields and tested by the ff_outlink_frame_wanted() function. If this function returns true
AV_PIX_FMT_YUV444P14
#define AV_PIX_FMT_YUV444P14
Definition: pixfmt.h:512
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:352
PreMultiplyContext::width
int width[AV_VIDEO_MAX_PLANES]
Definition: vf_premultiply.c:38
AV_PIX_FMT_GRAY12
#define AV_PIX_FMT_GRAY12
Definition: pixfmt.h:484
alpha_pix_fmts
static enum AVPixelFormat alpha_pix_fmts[]
Definition: vf_overlay.c:157
filter_frame
static int filter_frame(AVFilterContext *ctx, AVFrame **out, AVFrame *base, AVFrame *alpha)
Definition: vf_premultiply.c:510