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 dynamic;
45  int half, depth, offset, max;
47 
48  void (*premultiply[AV_VIDEO_MAX_PLANES])(const uint8_t *msrc, const uint8_t *asrc,
49  uint8_t *dst,
50  ptrdiff_t mlinesize, ptrdiff_t alinesize,
51  ptrdiff_t dlinesize,
52  int w, int h,
53  int half, int shift, int offset);
55 
56 #define OFFSET(x) offsetof(PreMultiplyContext, x)
57 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
58 
59 static const AVOption options[] = {
60  { "planes", "set planes", OFFSET(planes), AV_OPT_TYPE_INT, {.i64=0xF}, 0, 0xF, FLAGS },
61  { "inplace","enable inplace mode", OFFSET(inplace), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS },
62  { NULL }
63 };
64 
65 AVFILTER_DEFINE_CLASS_EXT(premultiply, "(un)premultiply", options);
66 
67 static int query_formats(const AVFilterContext *ctx,
68  AVFilterFormatsConfig **cfg_in,
69  AVFilterFormatsConfig **cfg_out)
70 {
71  const PreMultiplyContext *s = ctx->priv;
73  int ret;
74 
75  static const enum AVPixelFormat no_alpha_pix_fmts[] = {
84  };
85 
86  static const enum AVPixelFormat alpha_pix_fmts[] = {
92  };
93 
94  ret = ff_set_common_formats_from_list2(ctx, cfg_in, cfg_out,
95  s->inplace ? alpha_pix_fmts : no_alpha_pix_fmts);
96  if (ret < 0)
97  return ret;
98 
99  if (s->dynamic) {
100  ret = ff_formats_ref(ff_all_alpha_modes(), &cfg_in[0]->alpha_modes);
101  if (ret < 0)
102  return ret;
103  return ff_formats_ref(ff_all_alpha_modes(), &cfg_out[0]->alpha_modes);
104  } else {
105  /* Configure alpha mode corresponding to the chosen direction */
106  if (s->inplace) {
109  ret = ff_formats_ref(formats, &cfg_in[0]->alpha_modes);
110  if (ret < 0)
111  return ret;
112  }
113 
116  return ff_formats_ref(formats, &cfg_out[0]->alpha_modes);
117  }
118 }
119 
120 static void premultiply8(const uint8_t *msrc, const uint8_t *asrc,
121  uint8_t *dst,
122  ptrdiff_t mlinesize, ptrdiff_t alinesize,
123  ptrdiff_t dlinesize,
124  int w, int h,
125  int half, int shift, int offset)
126 {
127  int x, y;
128 
129  for (y = 0; y < h; y++) {
130  for (x = 0; x < w; x++) {
131  dst[x] = (msrc[x] * asrc[x] + 128) >> 8;
132  }
133 
134  dst += dlinesize;
135  msrc += mlinesize;
136  asrc += alinesize;
137  }
138 }
139 
140 static void premultiply8yuv(const uint8_t *msrc, const uint8_t *asrc,
141  uint8_t *dst,
142  ptrdiff_t mlinesize, ptrdiff_t alinesize,
143  ptrdiff_t dlinesize,
144  int w, int h,
145  int half, int shift, int offset)
146 {
147  int x, y;
148 
149  for (y = 0; y < h; y++) {
150  for (x = 0; x < w; x++) {
151  dst[x] = (((msrc[x] - 128) * asrc[x]) >> 8) + 128;
152  }
153 
154  dst += dlinesize;
155  msrc += mlinesize;
156  asrc += alinesize;
157  }
158 }
159 
160 static void premultiply8offset(const uint8_t *msrc, const uint8_t *asrc,
161  uint8_t *dst,
162  ptrdiff_t mlinesize, ptrdiff_t alinesize,
163  ptrdiff_t dlinesize,
164  int w, int h,
165  int half, int shift, int offset)
166 {
167  int x, y;
168 
169  for (y = 0; y < h; y++) {
170  for (x = 0; x < w; x++) {
171  dst[x] = ((((msrc[x] - offset) * asrc[x]) + 128) >> 8) + offset;
172  }
173 
174  dst += dlinesize;
175  msrc += mlinesize;
176  asrc += alinesize;
177  }
178 }
179 
180 static void premultiply16(const uint8_t *mmsrc, const uint8_t *aasrc,
181  uint8_t *ddst,
182  ptrdiff_t mlinesize, ptrdiff_t alinesize,
183  ptrdiff_t dlinesize,
184  int w, int h,
185  int half, int shift, int offset)
186 {
187  const uint16_t *msrc = (const uint16_t *)mmsrc;
188  const uint16_t *asrc = (const uint16_t *)aasrc;
189  uint16_t *dst = (uint16_t *)ddst;
190  int x, y;
191 
192  for (y = 0; y < h; y++) {
193  for (x = 0; x < w; x++) {
194  dst[x] = (msrc[x] * asrc[x] + half) >> shift;
195  }
196 
197  dst += dlinesize / 2;
198  msrc += mlinesize / 2;
199  asrc += alinesize / 2;
200  }
201 }
202 
203 static void premultiply16yuv(const uint8_t *mmsrc, const uint8_t *aasrc,
204  uint8_t *ddst,
205  ptrdiff_t mlinesize, ptrdiff_t alinesize,
206  ptrdiff_t dlinesize,
207  int w, int h,
208  int half, int shift, int offset)
209 {
210  const uint16_t *msrc = (const uint16_t *)mmsrc;
211  const uint16_t *asrc = (const uint16_t *)aasrc;
212  uint16_t *dst = (uint16_t *)ddst;
213  int x, y;
214 
215  for (y = 0; y < h; y++) {
216  for (x = 0; x < w; x++) {
217  dst[x] = (((msrc[x] - half) * (int64_t)asrc[x]) >> shift) + half;
218  }
219 
220  dst += dlinesize / 2;
221  msrc += mlinesize / 2;
222  asrc += alinesize / 2;
223  }
224 }
225 
226 static void premultiply16offset(const uint8_t *mmsrc, const uint8_t *aasrc,
227  uint8_t *ddst,
228  ptrdiff_t mlinesize, ptrdiff_t alinesize,
229  ptrdiff_t dlinesize,
230  int w, int h,
231  int half, int shift, int offset)
232 {
233  const uint16_t *msrc = (const uint16_t *)mmsrc;
234  const uint16_t *asrc = (const uint16_t *)aasrc;
235  uint16_t *dst = (uint16_t *)ddst;
236  int x, y;
237 
238  for (y = 0; y < h; y++) {
239  for (x = 0; x < w; x++) {
240  dst[x] = ((((msrc[x] - offset) * (int64_t)asrc[x]) + half) >> shift) + offset;
241  }
242 
243  dst += dlinesize / 2;
244  msrc += mlinesize / 2;
245  asrc += alinesize / 2;
246  }
247 }
248 
249 static void premultiplyf32(const uint8_t *mmsrc, const uint8_t *aasrc,
250  uint8_t *ddst,
251  ptrdiff_t mlinesize, ptrdiff_t alinesize,
252  ptrdiff_t dlinesize,
253  int w, int h,
254  int half, int shift, int offset)
255 {
256  const float *msrc = (const float *)mmsrc;
257  const float *asrc = (const float *)aasrc;
258  float *dst = (float *)ddst;
259  int x, y;
260 
261  for (y = 0; y < h; y++) {
262  for (x = 0; x < w; x++) {
263  dst[x] = msrc[x] * asrc[x];
264  }
265 
266  dst += dlinesize / 4;
267  msrc += mlinesize / 4;
268  asrc += alinesize / 4;
269  }
270 }
271 
272 static void premultiplyf32offset(const uint8_t *mmsrc, const uint8_t *aasrc,
273  uint8_t *ddst,
274  ptrdiff_t mlinesize, ptrdiff_t alinesize,
275  ptrdiff_t dlinesize,
276  int w, int h,
277  int half, int shift, int offset)
278 {
279  const float *msrc = (const float *)mmsrc;
280  const float *asrc = (const float *)aasrc;
281  float *dst = (float *)ddst;
282  int x, y;
283 
284  float offsetf = offset / 65535.0f;
285 
286  for (y = 0; y < h; y++) {
287  for (x = 0; x < w; x++) {
288  dst[x] = ((msrc[x] - offsetf) * asrc[x]) + offsetf;
289  }
290 
291  dst += dlinesize / 4;
292  msrc += mlinesize / 4;
293  asrc += alinesize / 4;
294  }
295 }
296 
297 static void unpremultiply8(const uint8_t *msrc, const uint8_t *asrc,
298  uint8_t *dst,
299  ptrdiff_t mlinesize, ptrdiff_t alinesize,
300  ptrdiff_t dlinesize,
301  int w, int h,
302  int half, int max, int offset)
303 {
304  int x, y;
305 
306  for (y = 0; y < h; y++) {
307  for (x = 0; x < w; x++) {
308  if (asrc[x] > 0 && asrc[x] < 255)
309  dst[x] = FFMIN(msrc[x] * 255 / asrc[x], 255);
310  else
311  dst[x] = msrc[x];
312  }
313 
314  dst += dlinesize;
315  msrc += mlinesize;
316  asrc += alinesize;
317  }
318 }
319 
320 static void unpremultiply8yuv(const uint8_t *msrc, const uint8_t *asrc,
321  uint8_t *dst,
322  ptrdiff_t mlinesize, ptrdiff_t alinesize,
323  ptrdiff_t dlinesize,
324  int w, int h,
325  int half, int max, int offset)
326 {
327  int x, y;
328 
329  for (y = 0; y < h; y++) {
330  for (x = 0; x < w; x++) {
331  if (asrc[x] > 0 && asrc[x] < 255)
332  dst[x] = FFMIN((msrc[x] - 128) * 255 / asrc[x] + 128, 255);
333  else
334  dst[x] = msrc[x];
335  }
336 
337  dst += dlinesize;
338  msrc += mlinesize;
339  asrc += alinesize;
340  }
341 }
342 
343 static void unpremultiply8offset(const uint8_t *msrc, const uint8_t *asrc,
344  uint8_t *dst,
345  ptrdiff_t mlinesize, ptrdiff_t alinesize,
346  ptrdiff_t dlinesize,
347  int w, int h,
348  int half, int max, int offset)
349 {
350  int x, y;
351 
352  for (y = 0; y < h; y++) {
353  for (x = 0; x < w; x++) {
354  if (asrc[x] > 0 && asrc[x] < 255)
355  dst[x] = FFMIN(FFMAX(msrc[x] - offset, 0) * 255 / asrc[x] + offset, 255);
356  else
357  dst[x] = msrc[x];
358  }
359 
360  dst += dlinesize;
361  msrc += mlinesize;
362  asrc += alinesize;
363  }
364 }
365 
366 static void unpremultiply16(const uint8_t *mmsrc, const uint8_t *aasrc,
367  uint8_t *ddst,
368  ptrdiff_t mlinesize, ptrdiff_t alinesize,
369  ptrdiff_t dlinesize,
370  int w, int h,
371  int half, int max, int offset)
372 {
373  const uint16_t *msrc = (const uint16_t *)mmsrc;
374  const uint16_t *asrc = (const uint16_t *)aasrc;
375  uint16_t *dst = (uint16_t *)ddst;
376  int x, y;
377 
378  for (y = 0; y < h; y++) {
379  for (x = 0; x < w; x++) {
380  if (asrc[x] > 0 && asrc[x] < max)
381  dst[x] = FFMIN(msrc[x] * (unsigned)max / asrc[x], max);
382  else
383  dst[x] = msrc[x];
384  }
385 
386  dst += dlinesize / 2;
387  msrc += mlinesize / 2;
388  asrc += alinesize / 2;
389  }
390 }
391 
392 static void unpremultiply16yuv(const uint8_t *mmsrc, const uint8_t *aasrc,
393  uint8_t *ddst,
394  ptrdiff_t mlinesize, ptrdiff_t alinesize,
395  ptrdiff_t dlinesize,
396  int w, int h,
397  int half, int max, int offset)
398 {
399  const uint16_t *msrc = (const uint16_t *)mmsrc;
400  const uint16_t *asrc = (const uint16_t *)aasrc;
401  uint16_t *dst = (uint16_t *)ddst;
402  int x, y;
403 
404  for (y = 0; y < h; y++) {
405  for (x = 0; x < w; x++) {
406  if (asrc[x] > 0 && asrc[x] < max)
407  dst[x] = FFMAX(FFMIN((msrc[x] - half) * max / asrc[x], half - 1), -half) + half;
408  else
409  dst[x] = msrc[x];
410  }
411 
412  dst += dlinesize / 2;
413  msrc += mlinesize / 2;
414  asrc += alinesize / 2;
415  }
416 }
417 
418 static void unpremultiply16offset(const uint8_t *mmsrc, const uint8_t *aasrc,
419  uint8_t *ddst,
420  ptrdiff_t mlinesize, ptrdiff_t alinesize,
421  ptrdiff_t dlinesize,
422  int w, int h,
423  int half, int max, int offset)
424 {
425  const uint16_t *msrc = (const uint16_t *)mmsrc;
426  const uint16_t *asrc = (const uint16_t *)aasrc;
427  uint16_t *dst = (uint16_t *)ddst;
428  int x, y;
429 
430  for (y = 0; y < h; y++) {
431  for (x = 0; x < w; x++) {
432  if (asrc[x] > 0 && asrc[x] < max)
433  dst[x] = FFMAX(FFMIN(FFMAX(msrc[x] - offset, 0) * (unsigned)max / asrc[x] + offset, max), 0);
434  else
435  dst[x] = msrc[x];
436  }
437 
438  dst += dlinesize / 2;
439  msrc += mlinesize / 2;
440  asrc += alinesize / 2;
441  }
442 }
443 
444 static void unpremultiplyf32(const uint8_t *mmsrc, const uint8_t *aasrc,
445  uint8_t *ddst,
446  ptrdiff_t mlinesize, ptrdiff_t alinesize,
447  ptrdiff_t dlinesize,
448  int w, int h,
449  int half, int max, int offset)
450 {
451  const float *msrc = (const float *)mmsrc;
452  const float *asrc = (const float *)aasrc;
453 
454  float *dst = (float *)ddst;
455  int x, y;
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] / asrc[x];
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 void unpremultiplyf32offset(const uint8_t *mmsrc, const uint8_t *aasrc,
472  uint8_t *ddst,
473  ptrdiff_t mlinesize, ptrdiff_t alinesize,
474  ptrdiff_t dlinesize,
475  int w, int h,
476  int half, int max, int offset)
477 {
478  const float *msrc = (const float *)mmsrc;
479  const float *asrc = (const float *)aasrc;
480 
481  float *dst = (float *)ddst;
482  int x, y;
483 
484  float offsetf = offset / 65535.0f;
485 
486  for (y = 0; y < h; y++) {
487  for (x = 0; x < w; x++) {
488  if (asrc[x] > 0.0f)
489  dst[x] = (msrc[x] - offsetf) / asrc[x] + offsetf;
490  else
491  dst[x] = msrc[x];
492  }
493 
494  dst += dlinesize / 4;
495  msrc += mlinesize / 4;
496  asrc += alinesize / 4;
497  }
498 }
499 
500 static int premultiply_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
501 {
502  PreMultiplyContext *s = ctx->priv;
503  ThreadData *td = arg;
504  AVFrame *out = td->d;
505  AVFrame *alpha = td->a;
506  AVFrame *base = td->m;
507  int p;
508 
509  for (p = 0; p < s->nb_planes; p++) {
510  const int slice_start = (s->height[p] * jobnr) / nb_jobs;
511  const int slice_end = (s->height[p] * (jobnr+1)) / nb_jobs;
512 
513  if (!((1 << p) & s->planes) || p == 3) {
514  av_image_copy_plane(out->data[p] + slice_start * out->linesize[p],
515  out->linesize[p],
516  base->data[p] + slice_start * base->linesize[p],
517  base->linesize[p],
518  s->linesize[p], slice_end - slice_start);
519  continue;
520  }
521 
522  s->premultiply[p](base->data[p] + slice_start * base->linesize[p],
523  s->inplace ? alpha->data[3] + slice_start * alpha->linesize[3] :
524  alpha->data[0] + slice_start * alpha->linesize[0],
525  out->data[p] + slice_start * out->linesize[p],
526  base->linesize[p], s->inplace ? alpha->linesize[3] : alpha->linesize[0],
527  out->linesize[p],
528  s->width[p], slice_end - slice_start,
529  s->half, s->inverse ? s->max : s->depth, s->offset);
530  }
531 
532  return 0;
533 }
534 
537 {
538  PreMultiplyContext *s = ctx->priv;
539  AVFilterLink *outlink = ctx->outputs[0];
540 
541  if (ctx->is_disabled || outlink->alpha_mode == base->alpha_mode) {
542  *out = av_frame_clone(base);
543  if (!*out)
544  return AVERROR(ENOMEM);
545  } else {
546  ThreadData td;
547  int full, limited;
548 
549  *out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
550  if (!*out)
551  return AVERROR(ENOMEM);
553  (*out)->alpha_mode = outlink->alpha_mode;
554 
555  full = base->color_range == AVCOL_RANGE_JPEG;
556  limited = base->color_range == AVCOL_RANGE_MPEG;
557 
558  if (s->inverse) {
559  switch (outlink->format) {
560  case AV_PIX_FMT_YUV444P:
561  case AV_PIX_FMT_YUVA444P:
562  s->premultiply[0] = full ? unpremultiply8 : unpremultiply8offset;
563  s->premultiply[1] = s->premultiply[2] = unpremultiply8yuv;
564  break;
565  case AV_PIX_FMT_YUVJ444P:
566  s->premultiply[0] = unpremultiply8;
567  s->premultiply[1] = s->premultiply[2] = unpremultiply8yuv;
568  break;
569  case AV_PIX_FMT_GBRP:
570  case AV_PIX_FMT_GBRAP:
571  s->premultiply[0] = s->premultiply[1] = s->premultiply[2] = limited ? unpremultiply8offset : unpremultiply8;
572  break;
573  case AV_PIX_FMT_YUV444P9:
582  s->premultiply[0] = full ? unpremultiply16 : unpremultiply16offset;
583  s->premultiply[1] = s->premultiply[2] = unpremultiply16yuv;
584  break;
585  case AV_PIX_FMT_GBRP9:
586  case AV_PIX_FMT_GBRP10:
587  case AV_PIX_FMT_GBRAP10:
588  case AV_PIX_FMT_GBRP12:
589  case AV_PIX_FMT_GBRAP12:
590  case AV_PIX_FMT_GBRP14:
591  case AV_PIX_FMT_GBRP16:
592  case AV_PIX_FMT_GBRAP16:
593  s->premultiply[0] = s->premultiply[1] = s->premultiply[2] = limited ? unpremultiply16offset : unpremultiply16;
594  break;
595  case AV_PIX_FMT_GBRPF32:
596  case AV_PIX_FMT_GBRAPF32:
597  s->premultiply[0] = s->premultiply[1] = s->premultiply[2] = limited ? unpremultiplyf32offset : unpremultiplyf32;
598  break;
599  case AV_PIX_FMT_GRAY8:
600  s->premultiply[0] = limited ? unpremultiply8offset : unpremultiply8;
601  break;
602  case AV_PIX_FMT_GRAY9:
603  case AV_PIX_FMT_GRAY10:
604  case AV_PIX_FMT_GRAY12:
605  case AV_PIX_FMT_GRAY14:
606  case AV_PIX_FMT_GRAY16:
607  s->premultiply[0] = limited ? unpremultiply16offset : unpremultiply16;
608  break;
609  }
610  } else {
611  switch (outlink->format) {
612  case AV_PIX_FMT_YUV444P:
613  case AV_PIX_FMT_YUVA444P:
614  s->premultiply[0] = full ? premultiply8 : premultiply8offset;
615  s->premultiply[1] = s->premultiply[2] = premultiply8yuv;
616  break;
617  case AV_PIX_FMT_YUVJ444P:
618  s->premultiply[0] = premultiply8;
619  s->premultiply[1] = s->premultiply[2] = premultiply8yuv;
620  break;
621  case AV_PIX_FMT_GBRP:
622  case AV_PIX_FMT_GBRAP:
623  s->premultiply[0] = s->premultiply[1] = s->premultiply[2] = limited ? premultiply8offset : premultiply8;
624  break;
625  case AV_PIX_FMT_YUV444P9:
634  s->premultiply[0] = full ? premultiply16 : premultiply16offset;
635  s->premultiply[1] = s->premultiply[2] = premultiply16yuv;
636  break;
637  case AV_PIX_FMT_GBRP9:
638  case AV_PIX_FMT_GBRP10:
639  case AV_PIX_FMT_GBRAP10:
640  case AV_PIX_FMT_GBRP12:
641  case AV_PIX_FMT_GBRAP12:
642  case AV_PIX_FMT_GBRP14:
643  case AV_PIX_FMT_GBRP16:
644  case AV_PIX_FMT_GBRAP16:
645  s->premultiply[0] = s->premultiply[1] = s->premultiply[2] = limited ? premultiply16offset : premultiply16;
646  break;
647  case AV_PIX_FMT_GBRPF32:
648  case AV_PIX_FMT_GBRAPF32:
649  s->premultiply[0] = s->premultiply[1] = s->premultiply[2] = limited ? premultiplyf32offset: premultiplyf32;
650  break;
651  case AV_PIX_FMT_GRAY8:
652  s->premultiply[0] = limited ? premultiply8offset : premultiply8;
653  break;
654  case AV_PIX_FMT_GRAY9:
655  case AV_PIX_FMT_GRAY10:
656  case AV_PIX_FMT_GRAY12:
657  case AV_PIX_FMT_GRAY14:
658  case AV_PIX_FMT_GRAY16:
659  s->premultiply[0] = limited ? premultiply16offset : premultiply16;
660  break;
661  }
662  }
663 
664  td.d = *out;
665  td.a = alpha;
666  td.m = base;
668  FFMIN(s->height[0], ff_filter_get_nb_threads(ctx)));
669  }
670 
671  return 0;
672 }
673 
675 {
676  AVFilterContext *ctx = fs->parent;
677  PreMultiplyContext *s = fs->opaque;
678  AVFilterLink *outlink = ctx->outputs[0];
679  AVFrame *out = NULL, *base, *alpha;
680  int ret;
681 
682  if ((ret = ff_framesync_get_frame(&s->fs, 0, &base, 0)) < 0 ||
683  (ret = ff_framesync_get_frame(&s->fs, 1, &alpha, 0)) < 0)
684  return ret;
685 
686  if ((ret = filter_frame(ctx, &out, base, alpha)) < 0)
687  return ret;
688 
689  out->pts = av_rescale_q(base->pts, s->fs.time_base, outlink->time_base);
690 
691  return ff_filter_frame(outlink, out);
692 }
693 
695 {
696  AVFilterContext *ctx = inlink->dst;
697  PreMultiplyContext *s = ctx->priv;
699  int vsub, hsub, ret;
700 
701  s->nb_planes = av_pix_fmt_count_planes(inlink->format);
702 
703  if ((ret = av_image_fill_linesizes(s->linesize, inlink->format, inlink->w)) < 0)
704  return ret;
705 
706  hsub = desc->log2_chroma_w;
707  vsub = desc->log2_chroma_h;
708  s->height[1] = s->height[2] = AV_CEIL_RSHIFT(inlink->h, vsub);
709  s->height[0] = s->height[3] = inlink->h;
710  s->width[1] = s->width[2] = AV_CEIL_RSHIFT(inlink->w, hsub);
711  s->width[0] = s->width[3] = inlink->w;
712 
713  s->depth = desc->flags & AV_PIX_FMT_FLAG_FLOAT ? 16 : desc->comp[0].depth;
714  s->max = (1 << s->depth) - 1;
715  s->half = (1 << s->depth) / 2;
716  s->offset = 16 << (s->depth - 8);
717 
718  return 0;
719 }
720 
721 static int config_output(AVFilterLink *outlink)
722 {
723  AVFilterContext *ctx = outlink->src;
724  PreMultiplyContext *s = ctx->priv;
725  AVFilterLink *base = ctx->inputs[0];
728  FilterLink *ol = ff_filter_link(outlink);
729  FFFrameSyncIn *in;
730  int ret;
731 
732  if (!s->inplace) {
733  alpha = ctx->inputs[1];
734 
735  if (base->w != alpha->w ||
736  base->h != alpha->h) {
737  av_log(ctx, AV_LOG_ERROR, "First input link %s parameters "
738  "(size %dx%d) do not match the corresponding "
739  "second input link %s parameters (%dx%d) ",
740  ctx->input_pads[0].name, base->w, base->h,
741  ctx->input_pads[1].name, alpha->w, alpha->h);
742  return AVERROR(EINVAL);
743  }
744  }
745 
746  outlink->w = base->w;
747  outlink->h = base->h;
748  outlink->time_base = base->time_base;
749  outlink->sample_aspect_ratio = base->sample_aspect_ratio;
750  ol->frame_rate = il->frame_rate;
751 
752  if (s->dynamic)
753  s->inverse = base->alpha_mode == AVALPHA_MODE_PREMULTIPLIED;
754 
755  if (s->inplace)
756  return 0;
757 
758  if ((ret = ff_framesync_init(&s->fs, ctx, 2)) < 0)
759  return ret;
760 
761  in = s->fs.in;
762  in[0].time_base = base->time_base;
763  in[1].time_base = alpha->time_base;
764  in[0].sync = 1;
765  in[0].before = EXT_STOP;
766  in[0].after = EXT_INFINITY;
767  in[1].sync = 1;
768  in[1].before = EXT_STOP;
769  in[1].after = EXT_INFINITY;
770  s->fs.opaque = s;
771  s->fs.on_event = process_frame;
772 
773  return ff_framesync_configure(&s->fs);
774 }
775 
777 {
778  PreMultiplyContext *s = ctx->priv;
779 
780  if (s->inplace) {
781  AVFrame *frame = NULL;
782  AVFrame *out = NULL;
783  int ret, status;
784  int64_t pts;
785 
787 
788  if ((ret = ff_inlink_consume_frame(ctx->inputs[0], &frame)) > 0) {
791  if (ret < 0)
792  return ret;
793  ret = ff_filter_frame(ctx->outputs[0], out);
794  }
795  if (ret < 0) {
796  return ret;
797  } else if (ff_inlink_acknowledge_status(ctx->inputs[0], &status, &pts)) {
798  ff_outlink_set_status(ctx->outputs[0], status, pts);
799  return 0;
800  } else {
801  if (ff_outlink_frame_wanted(ctx->outputs[0]))
802  ff_inlink_request_frame(ctx->inputs[0]);
803  return 0;
804  }
805  } else {
806  return ff_framesync_activate(&s->fs);
807  }
808 }
809 
811 {
812  PreMultiplyContext *s = ctx->priv;
813  AVFilterPad pad = { 0 };
814  int ret;
815 
816  if (!strcmp(ctx->filter->name, "premultiply_dynamic")) {
817  s->dynamic = s->inplace = 1;
818  return 0;
819  }
820 
821  if (!strcmp(ctx->filter->name, "unpremultiply"))
822  s->inverse = 1;
823 
824  pad.type = AVMEDIA_TYPE_VIDEO;
825  pad.name = "main";
827 
828  if ((ret = ff_append_inpad(ctx, &pad)) < 0)
829  return ret;
830 
831  if (!s->inplace) {
832  pad.type = AVMEDIA_TYPE_VIDEO;
833  pad.name = "alpha";
834  pad.config_props = NULL;
835 
836  if ((ret = ff_append_inpad(ctx, &pad)) < 0)
837  return ret;
838  }
839 
840  return 0;
841 }
842 
844 {
845  PreMultiplyContext *s = ctx->priv;
846 
847  if (!s->inplace)
848  ff_framesync_uninit(&s->fs);
849 }
850 
852  {
853  .name = "default",
854  .type = AVMEDIA_TYPE_VIDEO,
855  .config_props = config_output,
856  },
857 };
858 
859 #if CONFIG_PREMULTIPLY_FILTER
860 
861 const FFFilter ff_vf_premultiply = {
862  .p.name = "premultiply",
863  .p.description = NULL_IF_CONFIG_SMALL("PreMultiply first stream with first plane of second stream."),
864  .p.priv_class = &premultiply_class,
868  .priv_size = sizeof(PreMultiplyContext),
869  .init = init,
870  .uninit = uninit,
871  .activate = activate,
874 };
875 
876 #endif /* CONFIG_PREMULTIPLY_FILTER */
877 
878 #if CONFIG_UNPREMULTIPLY_FILTER
879 
881  .p.name = "unpremultiply",
882  .p.description = NULL_IF_CONFIG_SMALL("UnPreMultiply first stream with first plane of second stream."),
883  .p.priv_class = &premultiply_class,
887  .priv_size = sizeof(PreMultiplyContext),
888  .init = init,
889  .uninit = uninit,
890  .activate = activate,
893 };
894 
895 #endif /* CONFIG_UNPREMULTIPLY_FILTER */
896 
897 #if CONFIG_PREMULTIPLY_DYNAMIC_FILTER
898 
899 static const AVFilterPad premultiply_input[] = {
900  {
901  .name = "default",
902  .type = AVMEDIA_TYPE_VIDEO,
903  .config_props = config_input,
904  },
905 };
906 
908  .p.name = "premultiply_dynamic",
909  .p.description = NULL_IF_CONFIG_SMALL("Premultiply or unpremultiply an image in-place, as needed."),
910  .p.priv_class = &premultiply_class,
911  .p.flags = AVFILTER_FLAG_SLICE_THREADS,
912  .priv_size = sizeof(PreMultiplyContext),
913  .init = init,
914  .uninit = uninit,
915  .activate = activate,
916  FILTER_INPUTS(premultiply_input),
919 };
920 
921 #endif /* CONFIG_UNPREMULTIPLY_DYNAMIC_FILTER */
formats
formats
Definition: signature.h:47
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:117
PreMultiplyContext::offset
int offset
Definition: vf_premultiply.c:45
AV_PIX_FMT_GBRAP16
#define AV_PIX_FMT_GBRAP16
Definition: pixfmt.h:565
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
AVALPHA_MODE_STRAIGHT
@ AVALPHA_MODE_STRAIGHT
Alpha channel is independent of color values.
Definition: pixfmt.h:803
AVALPHA_MODE_PREMULTIPLIED
@ AVALPHA_MODE_PREMULTIPLIED
Alpha channel is multiplied into color values.
Definition: pixfmt.h:802
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:1067
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3447
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
PreMultiplyContext::dynamic
int dynamic
Definition: vf_premultiply.c:44
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:392
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:64
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: filters.h:263
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:427
PreMultiplyContext::depth
int depth
Definition: vf_premultiply.c:45
pixdesc.h
w
uint8_t w
Definition: llviddspenc.c:38
AVCOL_RANGE_JPEG
@ AVCOL_RANGE_JPEG
Full range content.
Definition: pixfmt.h:767
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:343
half
static uint8_t half(int a, int b)
Definition: mobiclip.c:540
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:444
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:220
FFFrameSync
Frame sync structure.
Definition: framesync.h:168
EXT_INFINITY
@ EXT_INFINITY
Extend the frame to infinity.
Definition: framesync.h:75
video.h
ff_make_formats_list_singleton
AVFilterFormats * ff_make_formats_list_singleton(int fmt)
Equivalent to ff_make_format_list({const int[]}{ fmt, -1 })
Definition: formats.c:545
AV_PIX_FMT_GRAY9
#define AV_PIX_FMT_GRAY9
Definition: pixfmt.h:518
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
AVFilterFormats
A list of supported formats for one end of a filter link.
Definition: formats.h:64
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:1517
av_pix_fmt_count_planes
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3487
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:272
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:651
AV_PIX_FMT_GBRP14
#define AV_PIX_FMT_GBRP14
Definition: pixfmt.h:560
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
slice_end
static int slice_end(AVCodecContext *avctx, AVFrame *pict, int *got_output)
Handle slice ends.
Definition: mpeg12dec.c:1688
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:558
AV_PIX_FMT_YUVA444P16
#define AV_PIX_FMT_YUVA444P16
Definition: pixfmt.h:597
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:320
pts
static int64_t pts
Definition: transcode_aac.c:644
AV_PIX_FMT_GRAY16
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:522
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:156
AVFilterPad
A filter pad used for either input or output.
Definition: filters.h:39
AV_PIX_FMT_YUV444P10
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:542
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:210
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:500
FFFilter
Definition: filters.h:266
AV_PIX_FMT_GBRAP10
#define AV_PIX_FMT_GBRAP10
Definition: pixfmt.h:562
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:628
process_frame
static int process_frame(FFFrameSync *fs)
Definition: vf_premultiply.c:674
ff_inlink_request_frame
void ff_inlink_request_frame(AVFilterLink *link)
Mark that a frame is wanted on the link.
Definition: avfilter.c:1620
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:563
AV_PIX_FMT_YUV444P16
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:552
AV_CEIL_RSHIFT
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:60
PreMultiplyContext::half
int half
Definition: vf_premultiply.c:45
PreMultiplyContext::max
int max
Definition: vf_premultiply.c:45
ff_formats_ref
int ff_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
Add *ref as a new reference to formats.
Definition: formats.c:705
filters.h
AV_PIX_FMT_YUVA444P12
#define AV_PIX_FMT_YUVA444P12
Definition: pixfmt.h:594
ctx
AVFormatContext * ctx
Definition: movenc.c:49
AV_PIX_FMT_GRAY14
#define AV_PIX_FMT_GRAY14
Definition: pixfmt.h:521
av_frame_clone
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
Definition: frame.c:483
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:297
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: filters.h:264
FLAGS
#define FLAGS
Definition: vf_premultiply.c:57
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:519
AV_PIX_FMT_GBRP16
#define AV_PIX_FMT_GBRP16
Definition: pixfmt.h:561
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:76
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:226
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:599
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:160
AVFILTER_DEFINE_CLASS_EXT
AVFILTER_DEFINE_CLASS_EXT(premultiply, "(un)premultiply", options)
options
Definition: swscale.c:43
init
static av_cold int init(AVFilterContext *ctx)
Definition: vf_premultiply.c:810
OFFSET
#define OFFSET(x)
Definition: vf_premultiply.c:56
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:557
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:1464
AVFilterFormatsConfig
Lists of formats / etc.
Definition: avfilter.h:121
ff_filter_link
static FilterLink * ff_filter_link(AVFilterLink *link)
Definition: filters.h:198
activate
static int activate(AVFilterContext *ctx)
Definition: vf_premultiply.c:776
AVFilterPad::config_props
int(* config_props)(AVFilterLink *link)
Link configuration callback.
Definition: filters.h:119
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:249
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:87
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:418
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:471
AV_PIX_FMT_GBRPF32
#define AV_PIX_FMT_GBRPF32
Definition: pixfmt.h:578
AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:546
config_output
static int config_output(AVFilterLink *outlink)
Definition: vf_premultiply.c:721
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:140
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:592
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:120
ThreadData::d
void ** d
Definition: af_crystalizer.c:47
planes
static const struct @527 planes[]
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_premultiply.c:843
ff_vf_unpremultiply
const FFFilter ff_vf_unpremultiply
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:48
AV_PIX_FMT_GBRP12
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:559
ff_filter_get_nb_threads
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Definition: avfilter.c:845
ThreadData
Used for passing data between threads.
Definition: dsddec.c:71
FILTER_QUERY_FUNC2
#define FILTER_QUERY_FUNC2(func)
Definition: filters.h:240
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
ff_vf_premultiply
const FFFilter ff_vf_premultiply
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:366
AVFilterPad::name
const char * name
Pad name.
Definition: filters.h:45
AVCOL_RANGE_MPEG
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition: pixfmt.h:750
AV_PIX_FMT_YUV444P9
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:538
slice_start
static int slice_start(SliceContext *sc, VVCContext *s, VVCFrameContext *fc, const CodedBitstreamUnit *unit, const int is_first_slice)
Definition: dec.c:845
ret
ret
Definition: filter_design.txt:187
AVFilterPad::type
enum AVMediaType type
AVFilterPad type.
Definition: filters.h:50
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:265
AV_PIX_FMT_YUVA444P9
#define AV_PIX_FMT_YUVA444P9
Definition: pixfmt.h:589
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:46
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:1085
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:1693
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:203
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:579
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:180
ThreadData::a
AVFrame * a
Definition: vf_premultiply.c:33
ff_all_alpha_modes
AVFilterFormats * ff_all_alpha_modes(void)
Construct an AVFilterFormats representing all possible alpha modes.
Definition: formats.c:673
Windows::Graphics::DirectX::Direct3D11::p
IDirect3DDxgiInterfaceAccess _COM_Outptr_ void ** p
Definition: vsrc_gfxcapture_winrt.hpp:53
premultiply_outputs
static const AVFilterPad premultiply_outputs[]
Definition: vf_premultiply.c:851
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:274
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:167
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:67
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:200
FFFilter::p
AVFilter p
The public AVFilter.
Definition: filters.h:270
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:694
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:205
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:549
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:520
alpha_pix_fmts
static enum AVPixelFormat alpha_pix_fmts[]
Definition: vf_overlay.c:154
ff_vf_premultiply_dynamic
const FFFilter ff_vf_premultiply_dynamic
filter_frame
static int filter_frame(AVFilterContext *ctx, AVFrame **out, AVFrame *base, AVFrame *alpha)
Definition: vf_premultiply.c:535