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