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 #define premultiply_options options
64 AVFILTER_DEFINE_CLASS(premultiply);
65 
67 {
68  PreMultiplyContext *s = ctx->priv;
69 
70  static const enum AVPixelFormat no_alpha_pix_fmts[] = {
79  };
80 
81  static const enum AVPixelFormat alpha_pix_fmts[] = {
87  };
88 
89  return ff_set_common_formats(ctx, ff_make_format_list(s->inplace ? alpha_pix_fmts : no_alpha_pix_fmts));
90 }
91 
92 static void premultiply8(const uint8_t *msrc, const uint8_t *asrc,
93  uint8_t *dst,
94  ptrdiff_t mlinesize, ptrdiff_t alinesize,
95  ptrdiff_t dlinesize,
96  int w, int h,
97  int half, int shift, int offset)
98 {
99  int x, y;
100 
101  for (y = 0; y < h; y++) {
102  for (x = 0; x < w; x++) {
103  dst[x] = ((msrc[x] * (((asrc[x] >> 1) & 1) + asrc[x])) + 128) >> 8;
104  }
105 
106  dst += dlinesize;
107  msrc += mlinesize;
108  asrc += alinesize;
109  }
110 }
111 
112 static void premultiply8yuv(const uint8_t *msrc, const uint8_t *asrc,
113  uint8_t *dst,
114  ptrdiff_t mlinesize, ptrdiff_t alinesize,
115  ptrdiff_t dlinesize,
116  int w, int h,
117  int half, int shift, int offset)
118 {
119  int x, y;
120 
121  for (y = 0; y < h; y++) {
122  for (x = 0; x < w; x++) {
123  dst[x] = ((((msrc[x] - 128) * (((asrc[x] >> 1) & 1) + asrc[x]))) >> 8) + 128;
124  }
125 
126  dst += dlinesize;
127  msrc += mlinesize;
128  asrc += alinesize;
129  }
130 }
131 
132 static void premultiply8offset(const uint8_t *msrc, const uint8_t *asrc,
133  uint8_t *dst,
134  ptrdiff_t mlinesize, ptrdiff_t alinesize,
135  ptrdiff_t dlinesize,
136  int w, int h,
137  int half, int shift, int offset)
138 {
139  int x, y;
140 
141  for (y = 0; y < h; y++) {
142  for (x = 0; x < w; x++) {
143  dst[x] = ((((msrc[x] - offset) * (((asrc[x] >> 1) & 1) + asrc[x])) + 128) >> 8) + offset;
144  }
145 
146  dst += dlinesize;
147  msrc += mlinesize;
148  asrc += alinesize;
149  }
150 }
151 
152 static void premultiply16(const uint8_t *mmsrc, const uint8_t *aasrc,
153  uint8_t *ddst,
154  ptrdiff_t mlinesize, ptrdiff_t alinesize,
155  ptrdiff_t dlinesize,
156  int w, int h,
157  int half, int shift, int offset)
158 {
159  const uint16_t *msrc = (const uint16_t *)mmsrc;
160  const uint16_t *asrc = (const uint16_t *)aasrc;
161  uint16_t *dst = (uint16_t *)ddst;
162  int x, y;
163 
164  for (y = 0; y < h; y++) {
165  for (x = 0; x < w; x++) {
166  dst[x] = ((msrc[x] * (((asrc[x] >> 1) & 1) + asrc[x])) + half) >> shift;
167  }
168 
169  dst += dlinesize / 2;
170  msrc += mlinesize / 2;
171  asrc += alinesize / 2;
172  }
173 }
174 
175 static void premultiply16yuv(const uint8_t *mmsrc, const uint8_t *aasrc,
176  uint8_t *ddst,
177  ptrdiff_t mlinesize, ptrdiff_t alinesize,
178  ptrdiff_t dlinesize,
179  int w, int h,
180  int half, int shift, int offset)
181 {
182  const uint16_t *msrc = (const uint16_t *)mmsrc;
183  const uint16_t *asrc = (const uint16_t *)aasrc;
184  uint16_t *dst = (uint16_t *)ddst;
185  int x, y;
186 
187  for (y = 0; y < h; y++) {
188  for (x = 0; x < w; x++) {
189  dst[x] = ((((msrc[x] - half) * (int64_t)(((asrc[x] >> 1) & 1) + asrc[x]))) >> shift) + half;
190  }
191 
192  dst += dlinesize / 2;
193  msrc += mlinesize / 2;
194  asrc += alinesize / 2;
195  }
196 }
197 
198 static void premultiply16offset(const uint8_t *mmsrc, const uint8_t *aasrc,
199  uint8_t *ddst,
200  ptrdiff_t mlinesize, ptrdiff_t alinesize,
201  ptrdiff_t dlinesize,
202  int w, int h,
203  int half, int shift, int offset)
204 {
205  const uint16_t *msrc = (const uint16_t *)mmsrc;
206  const uint16_t *asrc = (const uint16_t *)aasrc;
207  uint16_t *dst = (uint16_t *)ddst;
208  int x, y;
209 
210  for (y = 0; y < h; y++) {
211  for (x = 0; x < w; x++) {
212  dst[x] = ((((msrc[x] - offset) * (int64_t)(((asrc[x] >> 1) & 1) + asrc[x])) + half) >> shift) + offset;
213  }
214 
215  dst += dlinesize / 2;
216  msrc += mlinesize / 2;
217  asrc += alinesize / 2;
218  }
219 }
220 
221 static void premultiplyf32(const uint8_t *mmsrc, const uint8_t *aasrc,
222  uint8_t *ddst,
223  ptrdiff_t mlinesize, ptrdiff_t alinesize,
224  ptrdiff_t dlinesize,
225  int w, int h,
226  int half, int shift, int offset)
227 {
228  const float *msrc = (const float *)mmsrc;
229  const float *asrc = (const float *)aasrc;
230  float *dst = (float *)ddst;
231  int x, y;
232 
233  for (y = 0; y < h; y++) {
234  for (x = 0; x < w; x++) {
235  dst[x] = msrc[x] * asrc[x];
236  }
237 
238  dst += dlinesize / 4;
239  msrc += mlinesize / 4;
240  asrc += alinesize / 4;
241  }
242 }
243 
244 static void premultiplyf32offset(const uint8_t *mmsrc, const uint8_t *aasrc,
245  uint8_t *ddst,
246  ptrdiff_t mlinesize, ptrdiff_t alinesize,
247  ptrdiff_t dlinesize,
248  int w, int h,
249  int half, int shift, int offset)
250 {
251  const float *msrc = (const float *)mmsrc;
252  const float *asrc = (const float *)aasrc;
253  float *dst = (float *)ddst;
254  int x, y;
255 
256  float offsetf = offset / 65535.0f;
257 
258  for (y = 0; y < h; y++) {
259  for (x = 0; x < w; x++) {
260  dst[x] = ((msrc[x] - offsetf) * asrc[x]) + offsetf;
261  }
262 
263  dst += dlinesize / 4;
264  msrc += mlinesize / 4;
265  asrc += alinesize / 4;
266  }
267 }
268 
269 static void unpremultiply8(const uint8_t *msrc, const uint8_t *asrc,
270  uint8_t *dst,
271  ptrdiff_t mlinesize, ptrdiff_t alinesize,
272  ptrdiff_t dlinesize,
273  int w, int h,
274  int half, int max, int offset)
275 {
276  int x, y;
277 
278  for (y = 0; y < h; y++) {
279  for (x = 0; x < w; x++) {
280  if (asrc[x] > 0 && asrc[x] < 255)
281  dst[x] = FFMIN(msrc[x] * 255 / asrc[x], 255);
282  else
283  dst[x] = msrc[x];
284  }
285 
286  dst += dlinesize;
287  msrc += mlinesize;
288  asrc += alinesize;
289  }
290 }
291 
292 static void unpremultiply8yuv(const uint8_t *msrc, const uint8_t *asrc,
293  uint8_t *dst,
294  ptrdiff_t mlinesize, ptrdiff_t alinesize,
295  ptrdiff_t dlinesize,
296  int w, int h,
297  int half, int max, int offset)
298 {
299  int x, y;
300 
301  for (y = 0; y < h; y++) {
302  for (x = 0; x < w; x++) {
303  if (asrc[x] > 0 && asrc[x] < 255)
304  dst[x] = FFMIN((msrc[x] - 128) * 255 / asrc[x] + 128, 255);
305  else
306  dst[x] = msrc[x];
307  }
308 
309  dst += dlinesize;
310  msrc += mlinesize;
311  asrc += alinesize;
312  }
313 }
314 
315 static void unpremultiply8offset(const uint8_t *msrc, const uint8_t *asrc,
316  uint8_t *dst,
317  ptrdiff_t mlinesize, ptrdiff_t alinesize,
318  ptrdiff_t dlinesize,
319  int w, int h,
320  int half, int max, int offset)
321 {
322  int x, y;
323 
324  for (y = 0; y < h; y++) {
325  for (x = 0; x < w; x++) {
326  if (asrc[x] > 0 && asrc[x] < 255)
327  dst[x] = FFMIN(FFMAX(msrc[x] - offset, 0) * 255 / asrc[x] + offset, 255);
328  else
329  dst[x] = msrc[x];
330  }
331 
332  dst += dlinesize;
333  msrc += mlinesize;
334  asrc += alinesize;
335  }
336 }
337 
338 static void unpremultiply16(const uint8_t *mmsrc, const uint8_t *aasrc,
339  uint8_t *ddst,
340  ptrdiff_t mlinesize, ptrdiff_t alinesize,
341  ptrdiff_t dlinesize,
342  int w, int h,
343  int half, int max, int offset)
344 {
345  const uint16_t *msrc = (const uint16_t *)mmsrc;
346  const uint16_t *asrc = (const uint16_t *)aasrc;
347  uint16_t *dst = (uint16_t *)ddst;
348  int x, y;
349 
350  for (y = 0; y < h; y++) {
351  for (x = 0; x < w; x++) {
352  if (asrc[x] > 0 && asrc[x] < max)
353  dst[x] = FFMIN(msrc[x] * (unsigned)max / asrc[x], max);
354  else
355  dst[x] = msrc[x];
356  }
357 
358  dst += dlinesize / 2;
359  msrc += mlinesize / 2;
360  asrc += alinesize / 2;
361  }
362 }
363 
364 static void unpremultiply16yuv(const uint8_t *mmsrc, const uint8_t *aasrc,
365  uint8_t *ddst,
366  ptrdiff_t mlinesize, ptrdiff_t alinesize,
367  ptrdiff_t dlinesize,
368  int w, int h,
369  int half, int max, int offset)
370 {
371  const uint16_t *msrc = (const uint16_t *)mmsrc;
372  const uint16_t *asrc = (const uint16_t *)aasrc;
373  uint16_t *dst = (uint16_t *)ddst;
374  int x, y;
375 
376  for (y = 0; y < h; y++) {
377  for (x = 0; x < w; x++) {
378  if (asrc[x] > 0 && asrc[x] < max)
379  dst[x] = FFMAX(FFMIN((msrc[x] - half) * max / asrc[x], half - 1), -half) + half;
380  else
381  dst[x] = msrc[x];
382  }
383 
384  dst += dlinesize / 2;
385  msrc += mlinesize / 2;
386  asrc += alinesize / 2;
387  }
388 }
389 
390 static void unpremultiply16offset(const uint8_t *mmsrc, const uint8_t *aasrc,
391  uint8_t *ddst,
392  ptrdiff_t mlinesize, ptrdiff_t alinesize,
393  ptrdiff_t dlinesize,
394  int w, int h,
395  int half, int max, int offset)
396 {
397  const uint16_t *msrc = (const uint16_t *)mmsrc;
398  const uint16_t *asrc = (const uint16_t *)aasrc;
399  uint16_t *dst = (uint16_t *)ddst;
400  int x, y;
401 
402  for (y = 0; y < h; y++) {
403  for (x = 0; x < w; x++) {
404  if (asrc[x] > 0 && asrc[x] < max)
405  dst[x] = FFMAX(FFMIN(FFMAX(msrc[x] - offset, 0) * (unsigned)max / asrc[x] + offset, max), 0);
406  else
407  dst[x] = msrc[x];
408  }
409 
410  dst += dlinesize / 2;
411  msrc += mlinesize / 2;
412  asrc += alinesize / 2;
413  }
414 }
415 
416 static void unpremultiplyf32(const uint8_t *mmsrc, const uint8_t *aasrc,
417  uint8_t *ddst,
418  ptrdiff_t mlinesize, ptrdiff_t alinesize,
419  ptrdiff_t dlinesize,
420  int w, int h,
421  int half, int max, int offset)
422 {
423  const float *msrc = (const float *)mmsrc;
424  const float *asrc = (const float *)aasrc;
425 
426  float *dst = (float *)ddst;
427  int x, y;
428 
429  for (y = 0; y < h; y++) {
430  for (x = 0; x < w; x++) {
431  if (asrc[x] > 0.0f)
432  dst[x] = msrc[x] / asrc[x];
433  else
434  dst[x] = msrc[x];
435  }
436 
437  dst += dlinesize / 4;
438  msrc += mlinesize / 4;
439  asrc += alinesize / 4;
440  }
441 }
442 
443 static void unpremultiplyf32offset(const uint8_t *mmsrc, const uint8_t *aasrc,
444  uint8_t *ddst,
445  ptrdiff_t mlinesize, ptrdiff_t alinesize,
446  ptrdiff_t dlinesize,
447  int w, int h,
448  int half, int max, int offset)
449 {
450  const float *msrc = (const float *)mmsrc;
451  const float *asrc = (const float *)aasrc;
452 
453  float *dst = (float *)ddst;
454  int x, y;
455 
456  float offsetf = offset / 65535.0f;
457 
458  for (y = 0; y < h; y++) {
459  for (x = 0; x < w; x++) {
460  if (asrc[x] > 0.0f)
461  dst[x] = (msrc[x] - offsetf) / asrc[x] + offsetf;
462  else
463  dst[x] = msrc[x];
464  }
465 
466  dst += dlinesize / 4;
467  msrc += mlinesize / 4;
468  asrc += alinesize / 4;
469  }
470 }
471 
472 static int premultiply_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
473 {
474  PreMultiplyContext *s = ctx->priv;
475  ThreadData *td = arg;
476  AVFrame *out = td->d;
477  AVFrame *alpha = td->a;
478  AVFrame *base = td->m;
479  int p;
480 
481  for (p = 0; p < s->nb_planes; p++) {
482  const int slice_start = (s->height[p] * jobnr) / nb_jobs;
483  const int slice_end = (s->height[p] * (jobnr+1)) / nb_jobs;
484 
485  if (!((1 << p) & s->planes) || p == 3) {
486  av_image_copy_plane(out->data[p] + slice_start * out->linesize[p],
487  out->linesize[p],
488  base->data[p] + slice_start * base->linesize[p],
489  base->linesize[p],
490  s->linesize[p], slice_end - slice_start);
491  continue;
492  }
493 
494  s->premultiply[p](base->data[p] + slice_start * base->linesize[p],
495  s->inplace ? alpha->data[3] + slice_start * alpha->linesize[3] :
496  alpha->data[0] + slice_start * alpha->linesize[0],
497  out->data[p] + slice_start * out->linesize[p],
498  base->linesize[p], s->inplace ? alpha->linesize[3] : alpha->linesize[0],
499  out->linesize[p],
500  s->width[p], slice_end - slice_start,
501  s->half, s->inverse ? s->max : s->depth, s->offset);
502  }
503 
504  return 0;
505 }
506 
509 {
510  PreMultiplyContext *s = ctx->priv;
511  AVFilterLink *outlink = ctx->outputs[0];
512 
513  if (ctx->is_disabled) {
514  *out = av_frame_clone(base);
515  if (!*out)
516  return AVERROR(ENOMEM);
517  } else {
518  ThreadData td;
519  int full, limited;
520 
521  *out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
522  if (!*out)
523  return AVERROR(ENOMEM);
525 
526  full = base->color_range == AVCOL_RANGE_JPEG;
527  limited = base->color_range == AVCOL_RANGE_MPEG;
528 
529  if (s->inverse) {
530  switch (outlink->format) {
531  case AV_PIX_FMT_YUV444P:
532  case AV_PIX_FMT_YUVA444P:
533  s->premultiply[0] = full ? unpremultiply8 : unpremultiply8offset;
534  s->premultiply[1] = s->premultiply[2] = unpremultiply8yuv;
535  break;
536  case AV_PIX_FMT_YUVJ444P:
537  s->premultiply[0] = unpremultiply8;
538  s->premultiply[1] = s->premultiply[2] = unpremultiply8yuv;
539  break;
540  case AV_PIX_FMT_GBRP:
541  case AV_PIX_FMT_GBRAP:
542  s->premultiply[0] = s->premultiply[1] = s->premultiply[2] = limited ? unpremultiply8offset : unpremultiply8;
543  break;
544  case AV_PIX_FMT_YUV444P9:
553  s->premultiply[0] = full ? unpremultiply16 : unpremultiply16offset;
554  s->premultiply[1] = s->premultiply[2] = unpremultiply16yuv;
555  break;
556  case AV_PIX_FMT_GBRP9:
557  case AV_PIX_FMT_GBRP10:
558  case AV_PIX_FMT_GBRAP10:
559  case AV_PIX_FMT_GBRP12:
560  case AV_PIX_FMT_GBRAP12:
561  case AV_PIX_FMT_GBRP14:
562  case AV_PIX_FMT_GBRP16:
563  case AV_PIX_FMT_GBRAP16:
564  s->premultiply[0] = s->premultiply[1] = s->premultiply[2] = limited ? unpremultiply16offset : unpremultiply16;
565  break;
566  case AV_PIX_FMT_GBRPF32:
567  case AV_PIX_FMT_GBRAPF32:
568  s->premultiply[0] = s->premultiply[1] = s->premultiply[2] = limited ? unpremultiplyf32offset : unpremultiplyf32;
569  break;
570  case AV_PIX_FMT_GRAY8:
571  s->premultiply[0] = limited ? unpremultiply8offset : unpremultiply8;
572  break;
573  case AV_PIX_FMT_GRAY9:
574  case AV_PIX_FMT_GRAY10:
575  case AV_PIX_FMT_GRAY12:
576  case AV_PIX_FMT_GRAY14:
577  case AV_PIX_FMT_GRAY16:
578  s->premultiply[0] = limited ? unpremultiply16offset : unpremultiply16;
579  break;
580  }
581  } else {
582  switch (outlink->format) {
583  case AV_PIX_FMT_YUV444P:
584  case AV_PIX_FMT_YUVA444P:
585  s->premultiply[0] = full ? premultiply8 : premultiply8offset;
586  s->premultiply[1] = s->premultiply[2] = premultiply8yuv;
587  break;
588  case AV_PIX_FMT_YUVJ444P:
589  s->premultiply[0] = premultiply8;
590  s->premultiply[1] = s->premultiply[2] = premultiply8yuv;
591  break;
592  case AV_PIX_FMT_GBRP:
593  case AV_PIX_FMT_GBRAP:
594  s->premultiply[0] = s->premultiply[1] = s->premultiply[2] = limited ? premultiply8offset : premultiply8;
595  break;
596  case AV_PIX_FMT_YUV444P9:
605  s->premultiply[0] = full ? premultiply16 : premultiply16offset;
606  s->premultiply[1] = s->premultiply[2] = premultiply16yuv;
607  break;
608  case AV_PIX_FMT_GBRP9:
609  case AV_PIX_FMT_GBRP10:
610  case AV_PIX_FMT_GBRAP10:
611  case AV_PIX_FMT_GBRP12:
612  case AV_PIX_FMT_GBRAP12:
613  case AV_PIX_FMT_GBRP14:
614  case AV_PIX_FMT_GBRP16:
615  case AV_PIX_FMT_GBRAP16:
616  s->premultiply[0] = s->premultiply[1] = s->premultiply[2] = limited ? premultiply16offset : premultiply16;
617  break;
618  case AV_PIX_FMT_GBRPF32:
619  case AV_PIX_FMT_GBRAPF32:
620  s->premultiply[0] = s->premultiply[1] = s->premultiply[2] = limited ? premultiplyf32offset: premultiplyf32;
621  break;
622  case AV_PIX_FMT_GRAY8:
623  s->premultiply[0] = limited ? premultiply8offset : premultiply8;
624  break;
625  case AV_PIX_FMT_GRAY9:
626  case AV_PIX_FMT_GRAY10:
627  case AV_PIX_FMT_GRAY12:
628  case AV_PIX_FMT_GRAY14:
629  case AV_PIX_FMT_GRAY16:
630  s->premultiply[0] = limited ? premultiply16offset : premultiply16;
631  break;
632  }
633  }
634 
635  td.d = *out;
636  td.a = alpha;
637  td.m = base;
638  ctx->internal->execute(ctx, premultiply_slice, &td, NULL, FFMIN(s->height[0],
640  }
641 
642  return 0;
643 }
644 
646 {
647  AVFilterContext *ctx = fs->parent;
648  PreMultiplyContext *s = fs->opaque;
649  AVFilterLink *outlink = ctx->outputs[0];
650  AVFrame *out = NULL, *base, *alpha;
651  int ret;
652 
653  if ((ret = ff_framesync_get_frame(&s->fs, 0, &base, 0)) < 0 ||
654  (ret = ff_framesync_get_frame(&s->fs, 1, &alpha, 0)) < 0)
655  return ret;
656 
657  if ((ret = filter_frame(ctx, &out, base, alpha)) < 0)
658  return ret;
659 
660  out->pts = av_rescale_q(base->pts, s->fs.time_base, outlink->time_base);
661 
662  return ff_filter_frame(outlink, out);
663 }
664 
666 {
667  AVFilterContext *ctx = inlink->dst;
668  PreMultiplyContext *s = ctx->priv;
670  int vsub, hsub, ret;
671 
672  s->nb_planes = av_pix_fmt_count_planes(inlink->format);
673 
674  if ((ret = av_image_fill_linesizes(s->linesize, inlink->format, inlink->w)) < 0)
675  return ret;
676 
677  hsub = desc->log2_chroma_w;
678  vsub = desc->log2_chroma_h;
679  s->height[1] = s->height[2] = AV_CEIL_RSHIFT(inlink->h, vsub);
680  s->height[0] = s->height[3] = inlink->h;
681  s->width[1] = s->width[2] = AV_CEIL_RSHIFT(inlink->w, hsub);
682  s->width[0] = s->width[3] = inlink->w;
683 
684  s->depth = desc->flags & AV_PIX_FMT_FLAG_FLOAT ? 16 : desc->comp[0].depth;
685  s->max = (1 << s->depth) - 1;
686  s->half = (1 << s->depth) / 2;
687  s->offset = 16 << (s->depth - 8);
688 
689  return 0;
690 }
691 
692 static int config_output(AVFilterLink *outlink)
693 {
694  AVFilterContext *ctx = outlink->src;
695  PreMultiplyContext *s = ctx->priv;
696  AVFilterLink *base = ctx->inputs[0];
698  FFFrameSyncIn *in;
699  int ret;
700 
701  if (!s->inplace) {
702  alpha = ctx->inputs[1];
703 
704  if (base->format != alpha->format) {
705  av_log(ctx, AV_LOG_ERROR, "inputs must be of same pixel format\n");
706  return AVERROR(EINVAL);
707  }
708  if (base->w != alpha->w ||
709  base->h != alpha->h) {
710  av_log(ctx, AV_LOG_ERROR, "First input link %s parameters "
711  "(size %dx%d) do not match the corresponding "
712  "second input link %s parameters (%dx%d) ",
713  ctx->input_pads[0].name, base->w, base->h,
714  ctx->input_pads[1].name, alpha->w, alpha->h);
715  return AVERROR(EINVAL);
716  }
717  }
718 
719  outlink->w = base->w;
720  outlink->h = base->h;
721  outlink->time_base = base->time_base;
722  outlink->sample_aspect_ratio = base->sample_aspect_ratio;
723  outlink->frame_rate = base->frame_rate;
724 
725  if (s->inplace)
726  return 0;
727 
728  if ((ret = ff_framesync_init(&s->fs, ctx, 2)) < 0)
729  return ret;
730 
731  in = s->fs.in;
732  in[0].time_base = base->time_base;
733  in[1].time_base = alpha->time_base;
734  in[0].sync = 1;
735  in[0].before = EXT_STOP;
736  in[0].after = EXT_INFINITY;
737  in[1].sync = 1;
738  in[1].before = EXT_STOP;
739  in[1].after = EXT_INFINITY;
740  s->fs.opaque = s;
741  s->fs.on_event = process_frame;
742 
743  return ff_framesync_configure(&s->fs);
744 }
745 
747 {
748  PreMultiplyContext *s = ctx->priv;
749 
750  if (s->inplace) {
751  AVFrame *frame = NULL;
752  AVFrame *out = NULL;
753  int ret, status;
754  int64_t pts;
755 
757 
758  if ((ret = ff_inlink_consume_frame(ctx->inputs[0], &frame)) > 0) {
761  if (ret < 0)
762  return ret;
763  ret = ff_filter_frame(ctx->outputs[0], out);
764  }
765  if (ret < 0) {
766  return ret;
767  } else if (ff_inlink_acknowledge_status(ctx->inputs[0], &status, &pts)) {
768  ff_outlink_set_status(ctx->outputs[0], status, pts);
769  return 0;
770  } else {
771  if (ff_outlink_frame_wanted(ctx->outputs[0]))
772  ff_inlink_request_frame(ctx->inputs[0]);
773  return 0;
774  }
775  } else {
776  return ff_framesync_activate(&s->fs);
777  }
778 }
779 
781 {
782  PreMultiplyContext *s = ctx->priv;
783  AVFilterPad pad = { 0 };
784  int ret;
785 
786  if (!strcmp(ctx->filter->name, "unpremultiply"))
787  s->inverse = 1;
788 
789  pad.type = AVMEDIA_TYPE_VIDEO;
790  pad.name = "main";
792 
793  if ((ret = ff_insert_inpad(ctx, 0, &pad)) < 0)
794  return ret;
795 
796  if (!s->inplace) {
797  pad.type = AVMEDIA_TYPE_VIDEO;
798  pad.name = "alpha";
799  pad.config_props = NULL;
800 
801  if ((ret = ff_insert_inpad(ctx, 1, &pad)) < 0)
802  return ret;
803  }
804 
805  return 0;
806 }
807 
809 {
810  PreMultiplyContext *s = ctx->priv;
811 
812  if (!s->inplace)
813  ff_framesync_uninit(&s->fs);
814 }
815 
817  {
818  .name = "default",
819  .type = AVMEDIA_TYPE_VIDEO,
820  .config_props = config_output,
821  },
822  { NULL }
823 };
824 
825 #if CONFIG_PREMULTIPLY_FILTER
826 
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,
834  .activate = activate,
835  .inputs = NULL,
837  .priv_class = &premultiply_class,
841 };
842 
843 #endif /* CONFIG_PREMULTIPLY_FILTER */
844 
845 #if CONFIG_UNPREMULTIPLY_FILTER
846 
847 #define unpremultiply_options options
848 AVFILTER_DEFINE_CLASS(unpremultiply);
849 
851  .name = "unpremultiply",
852  .description = NULL_IF_CONFIG_SMALL("UnPreMultiply first stream with first plane of second stream."),
853  .priv_size = sizeof(PreMultiplyContext),
854  .init = init,
855  .uninit = uninit,
857  .activate = activate,
858  .inputs = NULL,
860  .priv_class = &unpremultiply_class,
864 };
865 
866 #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:99
PreMultiplyContext::offset
int offset
Definition: vf_premultiply.c:43
AV_PIX_FMT_GBRAP16
#define AV_PIX_FMT_GBRAP16
Definition: pixfmt.h:421
ff_framesync_configure
int ff_framesync_configure(FFFrameSync *fs)
Configure a frame sync structure.
Definition: framesync.c:124
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_make_format_list
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:286
ff_framesync_uninit
void ff_framesync_uninit(FFFrameSync *fs)
Free all memory currently allocated.
Definition: framesync.c:290
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:1096
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2573
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:253
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:190
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:364
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:203
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:318
PreMultiplyContext::depth
int depth
Definition: vf_premultiply.c:43
pixdesc.h
w
uint8_t w
Definition: llviddspenc.c:39
AVCOL_RANGE_JPEG
@ AVCOL_RANGE_JPEG
Full range content.
Definition: pixfmt.h:586
AVOption
AVOption.
Definition: opt.h:248
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:315
half
static uint8_t half(int a, int b)
Definition: mobiclip.c:541
PreMultiplyContext
Definition: vf_premultiply.c:35
base
uint8_t base
Definition: vp3data.h:141
max
#define max(a, b)
Definition: cuda_runtime.h:33
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:416
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:149
FFFrameSync
Frame sync structure.
Definition: framesync.h:146
EXT_INFINITY
@ EXT_INFINITY
Extend the frame to infinity.
Definition: framesync.h:75
video.h
AVFormatContext::internal
AVFormatInternal * internal
An opaque field for libavformat internal usage.
Definition: avformat.h:1699
AV_PIX_FMT_GRAY9
#define AV_PIX_FMT_GRAY9
Definition: pixfmt.h:379
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:373
hsub
static void hsub(htype *dst, const htype *src, int bins)
Definition: vf_median.c:75
formats.h
ff_insert_inpad
static int ff_insert_inpad(AVFilterContext *f, unsigned index, AVFilterPad *p)
Insert a new input pad for the filter.
Definition: internal.h:240
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:1494
av_pix_fmt_count_planes
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2613
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:244
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:417
AV_PIX_FMT_GBRAP
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:215
AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:415
AV_PIX_FMT_YUVA444P16
#define AV_PIX_FMT_YUVA444P16
Definition: pixfmt.h:443
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:292
pts
static int64_t pts
Definition: transcode_aac.c:652
AV_PIX_FMT_GRAY16
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:383
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:106
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:54
AV_PIX_FMT_YUV444P10
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:402
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
av_cold
#define av_cold
Definition: attributes.h:90
ff_set_common_formats
int ff_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
A helper for query_formats() which sets all links to the same list of formats.
Definition: formats.c:587
premultiply_slice
static int premultiply_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Definition: vf_premultiply.c:472
ff_vf_unpremultiply
AVFilter ff_vf_unpremultiply
AV_PIX_FMT_GBRAP10
#define AV_PIX_FMT_GBRAP10
Definition: pixfmt.h:419
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:645
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:257
AV_PIX_FMT_GBRAP12
#define AV_PIX_FMT_GBRAP12
Definition: pixfmt.h:420
AV_PIX_FMT_YUV444P16
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:412
AV_CEIL_RSHIFT
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:58
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:2033
outputs
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
filters.h
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: vf_premultiply.c:66
AV_PIX_FMT_YUVA444P12
#define AV_PIX_FMT_YUVA444P12
Definition: pixfmt.h:440
ctx
AVFormatContext * ctx
Definition: movenc.c:48
AV_PIX_FMT_GRAY14
#define AV_PIX_FMT_GRAY14
Definition: pixfmt.h:382
av_frame_clone
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
Definition: frame.c:540
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:269
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:66
AV_PIX_FMT_GRAY10
#define AV_PIX_FMT_GRAY10
Definition: pixfmt.h:380
AV_PIX_FMT_GBRP16
#define AV_PIX_FMT_GBRP16
Definition: pixfmt.h:418
ff_vf_premultiply
AVFilter ff_vf_premultiply
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:67
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:198
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:658
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:132
PreMultiplyContext::linesize
int linesize[4]
Definition: vf_premultiply.c:38
init
static av_cold int init(AVFilterContext *ctx)
Definition: vf_premultiply.c:780
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:414
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:1449
activate
static int activate(AVFilterContext *ctx)
Definition: vf_premultiply.c:746
AVFilterPad::config_props
int(* config_props)(AVFilterLink *link)
Link configuration callback.
Definition: internal.h:118
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:221
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:390
FFMAX
#define FFMAX(a, b)
Definition: common.h:103
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:443
AV_PIX_FMT_GBRPF32
#define AV_PIX_FMT_GBRPF32
Definition: pixfmt.h:428
AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:406
config_output
static int config_output(AVFilterLink *outlink)
Definition: vf_premultiply.c:692
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:112
FFMIN
#define FFMIN(a, b)
Definition: common.h:105
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:177
AV_PIX_FMT_YUVA444P10
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:438
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:92
internal.h
ThreadData::d
void ** d
Definition: af_crystalizer.c:77
in
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method !=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2) { ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc) { av_free(ac);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
Definition: audio_convert.c:326
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_premultiply.c:808
AV_PIX_FMT_GBRP12
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:416
ff_filter_get_nb_threads
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Definition: avfilter.c:802
ThreadData
Used for passing data between threads.
Definition: dsddec.c:67
uint8_t
uint8_t
Definition: audio_convert.c:194
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:338
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:60
AVCOL_RANGE_MPEG
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition: pixfmt.h:569
AV_PIX_FMT_YUV444P9
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:398
AVFilter
Filter definition.
Definition: avfilter.h:145
ret
ret
Definition: filter_design.txt:187
AVFilterPad::type
enum AVMediaType type
AVFilterPad type.
Definition: internal.h:65
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:435
ff_framesync_init
int ff_framesync_init(FFFrameSync *fs, AVFilterContext *parent, unsigned nb_in)
Initialize a frame sync structure.
Definition: framesync.c:84
PreMultiplyContext::inverse
int inverse
Definition: vf_premultiply.c:41
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:175
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
avfilter.h
AV_PIX_FMT_GBRAPF32
#define AV_PIX_FMT_GBRAPF32
Definition: pixfmt.h:429
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:152
ThreadData::a
AVFrame * a
Definition: vf_premultiply.c:32
premultiply_outputs
static const AVFilterPad premultiply_outputs[]
Definition: vf_premultiply.c:816
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:341
shift
static int shift(int a, int b)
Definition: sonic.c:82
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:168
planes
static const struct @322 planes[]
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:117
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:81
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(premultiply)
config_input
static int config_input(AVFilterLink *inlink)
Definition: vf_premultiply.c:665
alpha
static const int16_t alpha[]
Definition: ilbcdata.h:55
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:242
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:134
imgutils.h
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
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:409
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:341
AV_PIX_FMT_GRAY12
#define AV_PIX_FMT_GRAY12
Definition: pixfmt.h:381
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:507
PreMultiplyContext::height
int height[4]
Definition: vf_premultiply.c:37