FFmpeg
vf_sab.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2002 Michael Niedermayer <michaelni@gmx.at>
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (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
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20 
21 /**
22  * @file
23  * Shape Adaptive Blur filter, ported from MPlayer libmpcodecs/vf_sab.c
24  */
25 
26 #include "libavutil/opt.h"
27 #include "libavutil/pixdesc.h"
28 #include "libswscale/swscale.h"
29 
30 #include "avfilter.h"
31 #include "formats.h"
32 #include "internal.h"
33 
34 typedef struct FilterParam {
35  float radius;
37  float strength;
38  float quality;
44  int *dist_coeff;
45 #define COLOR_DIFF_COEFF_SIZE 512
47 } FilterParam;
48 
49 typedef struct SabContext {
50  const AVClass *class;
53  int hsub;
54  int vsub;
55  unsigned int sws_flags;
56 } SabContext;
57 
59 {
60  static const enum AVPixelFormat pix_fmts[] = {
67  };
69  if (!fmts_list)
70  return AVERROR(ENOMEM);
71  return ff_set_common_formats(ctx, fmts_list);
72 }
73 
74 #define RADIUS_MIN 0.1
75 #define RADIUS_MAX 4.0
76 
77 #define PRE_FILTER_RADIUS_MIN 0.1
78 #define PRE_FILTER_RADIUS_MAX 2.0
79 
80 #define STRENGTH_MIN 0.1
81 #define STRENGTH_MAX 100.0
82 
83 #define OFFSET(x) offsetof(SabContext, x)
84 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
85 
86 static const AVOption sab_options[] = {
87  { "luma_radius", "set luma radius", OFFSET(luma.radius), AV_OPT_TYPE_FLOAT, {.dbl=1.0}, RADIUS_MIN, RADIUS_MAX, .flags=FLAGS },
88  { "lr" , "set luma radius", OFFSET(luma.radius), AV_OPT_TYPE_FLOAT, {.dbl=1.0}, RADIUS_MIN, RADIUS_MAX, .flags=FLAGS },
89  { "luma_pre_filter_radius", "set luma pre-filter radius", OFFSET(luma.pre_filter_radius), AV_OPT_TYPE_FLOAT, {.dbl=1.0}, PRE_FILTER_RADIUS_MIN, PRE_FILTER_RADIUS_MAX, .flags=FLAGS },
90  { "lpfr", "set luma pre-filter radius", OFFSET(luma.pre_filter_radius), AV_OPT_TYPE_FLOAT, {.dbl=1.0}, PRE_FILTER_RADIUS_MIN, PRE_FILTER_RADIUS_MAX, .flags=FLAGS },
91  { "luma_strength", "set luma strength", OFFSET(luma.strength), AV_OPT_TYPE_FLOAT, {.dbl=1.0}, STRENGTH_MIN, STRENGTH_MAX, .flags=FLAGS },
92  { "ls", "set luma strength", OFFSET(luma.strength), AV_OPT_TYPE_FLOAT, {.dbl=1.0}, STRENGTH_MIN, STRENGTH_MAX, .flags=FLAGS },
93 
94  { "chroma_radius", "set chroma radius", OFFSET(chroma.radius), AV_OPT_TYPE_FLOAT, {.dbl=RADIUS_MIN-1}, RADIUS_MIN-1, RADIUS_MAX, .flags=FLAGS },
95  { "cr", "set chroma radius", OFFSET(chroma.radius), AV_OPT_TYPE_FLOAT, {.dbl=RADIUS_MIN-1}, RADIUS_MIN-1, RADIUS_MAX, .flags=FLAGS },
96  { "chroma_pre_filter_radius", "set chroma pre-filter radius", OFFSET(chroma.pre_filter_radius), AV_OPT_TYPE_FLOAT, {.dbl=PRE_FILTER_RADIUS_MIN-1},
98  { "cpfr", "set chroma pre-filter radius", OFFSET(chroma.pre_filter_radius), AV_OPT_TYPE_FLOAT, {.dbl=PRE_FILTER_RADIUS_MIN-1},
100  { "chroma_strength", "set chroma strength", OFFSET(chroma.strength), AV_OPT_TYPE_FLOAT, {.dbl=STRENGTH_MIN-1}, STRENGTH_MIN-1, STRENGTH_MAX, .flags=FLAGS },
101  { "cs", "set chroma strength", OFFSET(chroma.strength), AV_OPT_TYPE_FLOAT, {.dbl=STRENGTH_MIN-1}, STRENGTH_MIN-1, STRENGTH_MAX, .flags=FLAGS },
102 
103  { NULL }
104 };
105 
107 
109 {
110  SabContext *s = ctx->priv;
111 
112  /* make chroma default to luma values, if not explicitly set */
113  if (s->chroma.radius < RADIUS_MIN)
114  s->chroma.radius = s->luma.radius;
115  if (s->chroma.pre_filter_radius < PRE_FILTER_RADIUS_MIN)
116  s->chroma.pre_filter_radius = s->luma.pre_filter_radius;
117  if (s->chroma.strength < STRENGTH_MIN)
118  s->chroma.strength = s->luma.strength;
119 
120  s->luma.quality = s->chroma.quality = 3.0;
121  s->sws_flags = SWS_POINT;
122 
124  "luma_radius:%f luma_pre_filter_radius::%f luma_strength:%f "
125  "chroma_radius:%f chroma_pre_filter_radius:%f chroma_strength:%f\n",
126  s->luma .radius, s->luma .pre_filter_radius, s->luma .strength,
127  s->chroma.radius, s->chroma.pre_filter_radius, s->chroma.strength);
128  return 0;
129 }
130 
132 {
133  if (f->pre_filter_context) {
134  sws_freeContext(f->pre_filter_context);
135  f->pre_filter_context = NULL;
136  }
137  av_freep(&f->pre_filter_buf);
138  av_freep(&f->dist_coeff);
139 }
140 
142 {
143  SabContext *s = ctx->priv;
144 
145  close_filter_param(&s->luma);
146  close_filter_param(&s->chroma);
147 }
148 
149 static int open_filter_param(FilterParam *f, int width, int height, unsigned int sws_flags)
150 {
151  SwsVector *vec;
152  SwsFilter sws_f;
153  int i, x, y;
154  int linesize = FFALIGN(width, 8);
155 
156  f->pre_filter_buf = av_malloc(linesize * height);
157  if (!f->pre_filter_buf)
158  return AVERROR(ENOMEM);
159 
160  f->pre_filter_linesize = linesize;
161  vec = sws_getGaussianVec(f->pre_filter_radius, f->quality);
162  sws_f.lumH = sws_f.lumV = vec;
163  sws_f.chrH = sws_f.chrV = NULL;
164  f->pre_filter_context = sws_getContext(width, height, AV_PIX_FMT_GRAY8,
166  sws_flags, &sws_f, NULL, NULL);
167  sws_freeVec(vec);
168 
169  vec = sws_getGaussianVec(f->strength, 5.0);
170  for (i = 0; i < COLOR_DIFF_COEFF_SIZE; i++) {
171  double d;
172  int index = i-COLOR_DIFF_COEFF_SIZE/2 + vec->length/2;
173 
174  if (index < 0 || index >= vec->length) d = 0.0;
175  else d = vec->coeff[index];
176 
177  f->color_diff_coeff[i] = (int)(d/vec->coeff[vec->length/2]*(1<<12) + 0.5);
178  }
179  sws_freeVec(vec);
180 
181  vec = sws_getGaussianVec(f->radius, f->quality);
182  f->dist_width = vec->length;
183  f->dist_linesize = FFALIGN(vec->length, 8);
184  f->dist_coeff = av_malloc_array(f->dist_width, f->dist_linesize * sizeof(*f->dist_coeff));
185  if (!f->dist_coeff) {
186  sws_freeVec(vec);
187  return AVERROR(ENOMEM);
188  }
189 
190  for (y = 0; y < vec->length; y++) {
191  for (x = 0; x < vec->length; x++) {
192  double d = vec->coeff[x] * vec->coeff[y];
193  f->dist_coeff[x + y*f->dist_linesize] = (int)(d*(1<<10) + 0.5);
194  }
195  }
196  sws_freeVec(vec);
197 
198  return 0;
199 }
200 
202 {
203  SabContext *s = inlink->dst->priv;
205  int ret;
206 
207  s->hsub = desc->log2_chroma_w;
208  s->vsub = desc->log2_chroma_h;
209 
210  close_filter_param(&s->luma);
211  ret = open_filter_param(&s->luma, inlink->w, inlink->h, s->sws_flags);
212  if (ret < 0)
213  return ret;
214 
215  close_filter_param(&s->chroma);
216  ret = open_filter_param(&s->chroma,
217  AV_CEIL_RSHIFT(inlink->w, s->hsub),
218  AV_CEIL_RSHIFT(inlink->h, s->vsub), s->sws_flags);
219  return ret;
220 }
221 
222 #define NB_PLANES 4
223 
224 static void blur(uint8_t *dst, const int dst_linesize,
225  const uint8_t *src, const int src_linesize,
226  const int w, const int h, FilterParam *fp)
227 {
228  int x, y;
229  FilterParam f = *fp;
230  const int radius = f.dist_width/2;
231 
232  const uint8_t * const src2[NB_PLANES] = { src };
233  int src2_linesize[NB_PLANES] = { src_linesize };
234  uint8_t *dst2[NB_PLANES] = { f.pre_filter_buf };
235  int dst2_linesize[NB_PLANES] = { f.pre_filter_linesize };
236 
237  sws_scale(f.pre_filter_context, src2, src2_linesize, 0, h, dst2, dst2_linesize);
238 
239 #define UPDATE_FACTOR do { \
240  int factor; \
241  factor = f.color_diff_coeff[COLOR_DIFF_COEFF_SIZE/2 + pre_val - \
242  f.pre_filter_buf[ix + iy*f.pre_filter_linesize]] * f.dist_coeff[dx + dy*f.dist_linesize]; \
243  sum += src[ix + iy*src_linesize] * factor; \
244  div += factor; \
245  } while (0)
246 
247  for (y = 0; y < h; y++) {
248  for (x = 0; x < w; x++) {
249  int sum = 0;
250  int div = 0;
251  int dy;
252  const int pre_val = f.pre_filter_buf[x + y*f.pre_filter_linesize];
253  if (x >= radius && x < w - radius) {
254  for (dy = 0; dy < radius*2 + 1; dy++) {
255  int dx;
256  int iy = y+dy - radius;
257  iy = avpriv_mirror(iy, h-1);
258 
259  for (dx = 0; dx < radius*2 + 1; dx++) {
260  const int ix = x+dx - radius;
262  }
263  }
264  } else {
265  for (dy = 0; dy < radius*2+1; dy++) {
266  int dx;
267  int iy = y+dy - radius;
268  iy = avpriv_mirror(iy, h-1);
269 
270  for (dx = 0; dx < radius*2 + 1; dx++) {
271  int ix = x+dx - radius;
272  ix = avpriv_mirror(ix, w-1);
274  }
275  }
276  }
277  dst[x + y*dst_linesize] = (sum + div/2) / div;
278  }
279  }
280 }
281 
283 {
284  SabContext *s = inlink->dst->priv;
285  AVFilterLink *outlink = inlink->dst->outputs[0];
286  AVFrame *outpic;
287 
288  outpic = ff_get_video_buffer(outlink, outlink->w, outlink->h);
289  if (!outpic) {
291  return AVERROR(ENOMEM);
292  }
293  av_frame_copy_props(outpic, inpic);
294 
295  blur(outpic->data[0], outpic->linesize[0], inpic->data[0], inpic->linesize[0],
296  inlink->w, inlink->h, &s->luma);
297  if (inpic->data[2]) {
298  int cw = AV_CEIL_RSHIFT(inlink->w, s->hsub);
299  int ch = AV_CEIL_RSHIFT(inlink->h, s->vsub);
300  blur(outpic->data[1], outpic->linesize[1], inpic->data[1], inpic->linesize[1], cw, ch, &s->chroma);
301  blur(outpic->data[2], outpic->linesize[2], inpic->data[2], inpic->linesize[2], cw, ch, &s->chroma);
302  }
303 
305  return ff_filter_frame(outlink, outpic);
306 }
307 
308 static const AVFilterPad sab_inputs[] = {
309  {
310  .name = "default",
311  .type = AVMEDIA_TYPE_VIDEO,
312  .filter_frame = filter_frame,
313  .config_props = config_props,
314  },
315  { NULL }
316 };
317 
318 static const AVFilterPad sab_outputs[] = {
319  {
320  .name = "default",
321  .type = AVMEDIA_TYPE_VIDEO,
322  },
323  { NULL }
324 };
325 
327  .name = "sab",
328  .description = NULL_IF_CONFIG_SMALL("Apply shape adaptive blur."),
329  .priv_size = sizeof(SabContext),
330  .init = init,
331  .uninit = uninit,
333  .inputs = sab_inputs,
334  .outputs = sab_outputs,
335  .priv_class = &sab_class,
337 };
PRE_FILTER_RADIUS_MAX
#define PRE_FILTER_RADIUS_MAX
Definition: vf_sab.c:78
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
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
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:283
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1080
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2522
ch
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(const uint8_t *) pi - 0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(const int16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(const int16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(const int32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(const int32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(const int64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64, *(const int64_t *) pi *(1.0f/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64, *(const int64_t *) pi *(1.0/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(const float *) pi *(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(const double *) pi *(INT64_C(1)<< 63))) #define FMT_PAIR_FUNC(out, in) static conv_func_type *const fmt_pair_to_conv_functions[AV_SAMPLE_FMT_NB *AV_SAMPLE_FMT_NB]={ FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S64), };static void cpy1(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, len);} static void cpy2(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 2 *len);} static void cpy4(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 4 *len);} static void cpy8(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 8 *len);} AudioConvert *swri_audio_convert_alloc(enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, const int *ch_map, int flags) { AudioConvert *ctx;conv_func_type *f=fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt)+AV_SAMPLE_FMT_NB *av_get_packed_sample_fmt(in_fmt)];if(!f) return NULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) return NULL;if(channels==1){ in_fmt=av_get_planar_sample_fmt(in_fmt);out_fmt=av_get_planar_sample_fmt(out_fmt);} ctx->channels=channels;ctx->conv_f=f;ctx->ch_map=ch_map;if(in_fmt==AV_SAMPLE_FMT_U8||in_fmt==AV_SAMPLE_FMT_U8P) memset(ctx->silence, 0x80, sizeof(ctx->silence));if(out_fmt==in_fmt &&!ch_map) { switch(av_get_bytes_per_sample(in_fmt)){ case 1:ctx->simd_f=cpy1;break;case 2:ctx->simd_f=cpy2;break;case 4:ctx->simd_f=cpy4;break;case 8:ctx->simd_f=cpy8;break;} } if(HAVE_X86ASM &&1) swri_audio_convert_init_x86(ctx, out_fmt, in_fmt, channels);if(ARCH_ARM) swri_audio_convert_init_arm(ctx, out_fmt, in_fmt, channels);if(ARCH_AARCH64) swri_audio_convert_init_aarch64(ctx, out_fmt, in_fmt, channels);return ctx;} void swri_audio_convert_free(AudioConvert **ctx) { av_freep(ctx);} int swri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, int len) { int ch;int off=0;const int os=(out->planar ? 1 :out->ch_count) *out->bps;unsigned misaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask) { int planes=in->planar ? in->ch_count :1;unsigned m=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) in->ch[ch];misaligned|=m &ctx->in_simd_align_mask;} if(ctx->out_simd_align_mask) { int planes=out->planar ? out->ch_count :1;unsigned m=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) out->ch[ch];misaligned|=m &ctx->out_simd_align_mask;} if(ctx->simd_f &&!ctx->ch_map &&!misaligned){ off=len &~15;av_assert1(off >=0);av_assert1(off<=len);av_assert2(ctx->channels==SWR_CH_MAX||!in->ch[ctx->channels]);if(off >0){ if(out->planar==in->planar){ int planes=out->planar ? out->ch_count :1;for(ch=0;ch< planes;ch++){ ctx->simd_f(out-> ch ch
Definition: audioconvert.c:56
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_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:202
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:295
OFFSET
#define OFFSET(x)
Definition: vf_sab.c:83
pixdesc.h
w
uint8_t w
Definition: llviddspenc.c:38
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(sab)
AVOption
AVOption.
Definition: opt.h:246
chroma
static av_always_inline void chroma(WaveformContext *s, AVFrame *in, AVFrame *out, int component, int intensity, int offset_y, int offset_x, int column, int mirror, int jobnr, int nb_jobs)
Definition: vf_waveform.c:1511
blur
static void blur(uint8_t *dst, const int dst_linesize, const uint8_t *src, const int src_linesize, const int w, const int h, FilterParam *fp)
Definition: vf_sab.c:224
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:192
sab_options
static const AVOption sab_options[]
Definition: vf_sab.c:86
sws_scale
int attribute_align_arg sws_scale(struct SwsContext *c, const uint8_t *const srcSlice[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[])
swscale wrapper, so we don't need to export the SwsContext.
Definition: swscale.c:759
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:148
FilterParam::radius
float radius
Definition: vf_sab.c:35
PRE_FILTER_RADIUS_MIN
#define PRE_FILTER_RADIUS_MIN
Definition: vf_sab.c:77
sws_freeVec
void sws_freeVec(SwsVector *a)
Definition: utils.c:2290
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:309
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:31
AVFilterFormats
A list of supported formats for one end of a filter link.
Definition: formats.h:64
formats.h
sab_outputs
static const AVFilterPad sab_outputs[]
Definition: vf_sab.c:318
SWS_POINT
#define SWS_POINT
Definition: swscale.h:62
src
#define src
Definition: vp8dsp.c:254
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:54
SabContext::hsub
int hsub
Definition: vf_sab.c:53
av_cold
#define av_cold
Definition: attributes.h:84
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:568
COLOR_DIFF_COEFF_SIZE
#define COLOR_DIFF_COEFF_SIZE
Definition: vf_sab.c:45
width
#define width
RADIUS_MIN
#define RADIUS_MIN
Definition: vf_sab.c:74
s
#define s(width, name)
Definition: cbs_vp9.c:257
AV_CEIL_RSHIFT
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:58
SwsVector::length
int length
number of coefficients in the vector
Definition: swscale.h:111
outputs
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:275
ctx
AVFormatContext * ctx
Definition: movenc.c:48
sws_flags
static unsigned sws_flags
Definition: ffplay.c:110
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
sws_getGaussianVec
SwsVector * sws_getGaussianVec(double variance, double quality)
Return a normalized Gaussian curve used to filter stuff quality = 3 is high quality,...
Definition: utils.c:2028
f
#define f(width, name)
Definition: cbs_vp9.c:255
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:67
UPDATE_FACTOR
#define UPDATE_FACTOR
NULL
#define NULL
Definition: coverity.c:32
sab_inputs
static const AVFilterPad sab_inputs[]
Definition: vf_sab.c:308
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:654
inpic
av_frame_free & inpic
Definition: vf_mcdeint.c:278
SabContext::vsub
int vsub
Definition: vf_sab.c:54
SabContext
Definition: vf_sab.c:49
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: vf_sab.c:58
FLAGS
#define FLAGS
Definition: vf_sab.c:84
close_filter_param
static void close_filter_param(FilterParam *f)
Definition: vf_sab.c:131
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
avpriv_mirror
static av_always_inline av_const int avpriv_mirror(int x, int w)
Definition: internal.h:340
SwsVector::coeff
double * coeff
pointer to the list of coefficients
Definition: swscale.h:110
AV_PIX_FMT_GRAY8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:74
fp
#define fp
Definition: regdef.h:44
index
int index
Definition: gxfenc.c:89
SwsFilter::chrV
SwsVector * chrV
Definition: swscale.h:119
desc
const char * desc
Definition: nvenc.c:68
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:188
SwsVector
Definition: swscale.h:109
sws_getContext
struct SwsContext * sws_getContext(int srcW, int srcH, enum AVPixelFormat srcFormat, int dstW, int dstH, enum AVPixelFormat dstFormat, int flags, SwsFilter *srcFilter, SwsFilter *dstFilter, const double *param)
Allocate and return an SwsContext.
Definition: utils.c:1891
FilterParam::color_diff_coeff
int color_diff_coeff[COLOR_DIFF_COEFF_SIZE]
Definition: vf_sab.c:46
config_props
static int config_props(AVFilterLink *inlink)
Definition: vf_sab.c:201
SwsFilter
Definition: swscale.h:115
height
#define height
SwsFilter::lumV
SwsVector * lumV
Definition: swscale.h:117
FilterParam
Definition: boxblur.h:32
internal.h
AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
Definition: avfilter.h:125
AV_OPT_TYPE_FLOAT
@ AV_OPT_TYPE_FLOAT
Definition: opt.h:226
RADIUS_MAX
#define RADIUS_MAX
Definition: vf_sab.c:75
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:259
av_malloc_array
#define av_malloc_array(a, b)
Definition: tableprint_vlc.h:32
STRENGTH_MAX
#define STRENGTH_MAX
Definition: vf_sab.c:81
uint8_t
uint8_t
Definition: audio_convert.c:194
FilterParam::pre_filter_radius
float pre_filter_radius
Definition: vf_sab.c:36
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:60
ff_vf_sab
AVFilter ff_vf_sab
Definition: vf_sab.c:326
SabContext::luma
FilterParam luma
Definition: vf_sab.c:51
AVFilter
Filter definition.
Definition: avfilter.h:144
ret
ret
Definition: filter_design.txt:187
FilterParam::pre_filter_context
struct SwsContext * pre_filter_context
Definition: vf_sab.c:39
open_filter_param
static int open_filter_param(FilterParam *f, int width, int height, unsigned int sws_flags)
Definition: vf_sab.c:149
FilterParam::quality
float quality
Definition: vf_sab.c:38
FilterParam::strength
float strength
Definition: vf_sab.c:37
sws_freeContext
void sws_freeContext(struct SwsContext *swsContext)
Free the swscaler context swsContext.
Definition: utils.c:2311
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
avfilter.h
SabContext::sws_flags
unsigned int sws_flags
Definition: vf_sab.c:55
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:338
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AV_PIX_FMT_YUV422P
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:70
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *inpic)
Definition: vf_sab.c:282
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
STRENGTH_MIN
#define STRENGTH_MIN
Definition: vf_sab.c:80
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:48
SwsFilter::lumH
SwsVector * lumH
Definition: swscale.h:116
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
AV_PIX_FMT_YUV411P
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:73
NB_PLANES
#define NB_PLANES
Definition: vf_sab.c:222
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:565
AVFrame::linesize
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:326
AV_PIX_FMT_YUV410P
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:72
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
FilterParam::dist_coeff
int * dist_coeff
Definition: vf_sab.c:44
h
h
Definition: vp9dsp_template.c:2038
FilterParam::pre_filter_buf
uint8_t * pre_filter_buf
Definition: vf_sab.c:40
init
static av_cold int init(AVFilterContext *ctx)
Definition: vf_sab.c:108
int
int
Definition: ffmpeg_filter.c:191
SwsContext
Definition: swscale_internal.h:280
FilterParam::pre_filter_linesize
int pre_filter_linesize
Definition: vf_sab.c:41
FilterParam::dist_linesize
int dist_linesize
Definition: vf_sab.c:43
SwsFilter::chrH
SwsVector * chrH
Definition: swscale.h:118
SabContext::chroma
FilterParam chroma
Definition: vf_sab.c:52
swscale.h
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_sab.c:141
FilterParam::dist_width
int dist_width
Definition: vf_sab.c:42