Libav
vf_hqdn3d.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2003 Daniel Moreno <comac AT comac DOT darktech DOT org>
3  * Copyright (c) 2010 Baptiste Coudurier
4  * Copyright (c) 2012 Loren Merritt
5  *
6  * This file is part of Libav, ported from MPlayer.
7  *
8  * Libav is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * Libav is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with Libav; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22 
29 #include <float.h>
30 
31 #include "config.h"
32 #include "libavutil/attributes.h"
33 #include "libavutil/common.h"
34 #include "libavutil/pixdesc.h"
35 #include "libavutil/intreadwrite.h"
36 #include "libavutil/opt.h"
37 
38 #include "avfilter.h"
39 #include "formats.h"
40 #include "internal.h"
41 #include "video.h"
42 #include "vf_hqdn3d.h"
43 
44 #define LUT_BITS (depth==16 ? 8 : 4)
45 #define LOAD(x) (((depth == 8 ? src[x] : AV_RN16A(src + (x) * 2)) << (16 - depth))\
46  + (((1 << (16 - depth)) - 1) >> 1))
47 #define STORE(x,val) (depth == 8 ? dst[x] = (val) >> (16 - depth) : \
48  AV_WN16A(dst + (x) * 2, (val) >> (16 - depth)))
49 
51 static uint32_t lowpass(int prev, int cur, int16_t *coef, int depth)
52 {
53  int d = (prev - cur) >> (8 - LUT_BITS);
54  return cur + coef[d];
55 }
56 
58 static void denoise_temporal(uint8_t *src, uint8_t *dst,
59  uint16_t *frame_ant,
60  int w, int h, int sstride, int dstride,
61  int16_t *temporal, int depth)
62 {
63  long x, y;
64  uint32_t tmp;
65 
66  temporal += 256 << LUT_BITS;
67 
68  for (y = 0; y < h; y++) {
69  for (x = 0; x < w; x++) {
70  frame_ant[x] = tmp = lowpass(frame_ant[x], LOAD(x), temporal, depth);
71  STORE(x, tmp);
72  }
73  src += sstride;
74  dst += dstride;
75  frame_ant += w;
76  }
77 }
78 
81  uint8_t *src, uint8_t *dst,
82  uint16_t *line_ant, uint16_t *frame_ant,
83  int w, int h, int sstride, int dstride,
84  int16_t *spatial, int16_t *temporal, int depth)
85 {
86  long x, y;
87  uint32_t pixel_ant;
88  uint32_t tmp;
89 
90  spatial += 256 << LUT_BITS;
91  temporal += 256 << LUT_BITS;
92 
93  /* First line has no top neighbor. Only left one for each tmp and
94  * last frame */
95  pixel_ant = LOAD(0);
96  for (x = 0; x < w; x++) {
97  line_ant[x] = tmp = pixel_ant = lowpass(pixel_ant, LOAD(x), spatial, depth);
98  frame_ant[x] = tmp = lowpass(frame_ant[x], tmp, temporal, depth);
99  STORE(x, tmp);
100  }
101 
102  for (y = 1; y < h; y++) {
103  src += sstride;
104  dst += dstride;
105  frame_ant += w;
106  if (s->denoise_row[depth]) {
107  s->denoise_row[depth](src, dst, line_ant, frame_ant, w, spatial, temporal);
108  continue;
109  }
110  pixel_ant = LOAD(0);
111  for (x = 0; x < w-1; x++) {
112  line_ant[x] = tmp = lowpass(line_ant[x], pixel_ant, spatial, depth);
113  pixel_ant = lowpass(pixel_ant, LOAD(x+1), spatial, depth);
114  frame_ant[x] = tmp = lowpass(frame_ant[x], tmp, temporal, depth);
115  STORE(x, tmp);
116  }
117  line_ant[x] = tmp = lowpass(line_ant[x], pixel_ant, spatial, depth);
118  frame_ant[x] = tmp = lowpass(frame_ant[x], tmp, temporal, depth);
119  STORE(x, tmp);
120  }
121 }
122 
125  uint8_t *src, uint8_t *dst,
126  uint16_t *line_ant, uint16_t **frame_ant_ptr,
127  int w, int h, int sstride, int dstride,
128  int16_t *spatial, int16_t *temporal, int depth)
129 {
130  // FIXME: For 16bit depth, frame_ant could be a pointer to the previous
131  // filtered frame rather than a separate buffer.
132  long x, y;
133  uint16_t *frame_ant = *frame_ant_ptr;
134  if (!frame_ant) {
135  uint8_t *frame_src = src;
136  *frame_ant_ptr = frame_ant = av_malloc(w*h*sizeof(uint16_t));
137  for (y = 0; y < h; y++, src += sstride, frame_ant += w)
138  for (x = 0; x < w; x++)
139  frame_ant[x] = LOAD(x);
140  src = frame_src;
141  frame_ant = *frame_ant_ptr;
142  }
143 
144  if (spatial[0])
145  denoise_spatial(s, src, dst, line_ant, frame_ant,
146  w, h, sstride, dstride, spatial, temporal, depth);
147  else
148  denoise_temporal(src, dst, frame_ant,
149  w, h, sstride, dstride, temporal, depth);
150  emms_c();
151 }
152 
153 #define denoise(...) \
154  switch (s->depth) {\
155  case 8: denoise_depth(__VA_ARGS__, 8); break;\
156  case 9: denoise_depth(__VA_ARGS__, 9); break;\
157  case 10: denoise_depth(__VA_ARGS__, 10); break;\
158  case 16: denoise_depth(__VA_ARGS__, 16); break;\
159  }
160 
161 static int16_t *precalc_coefs(double dist25, int depth)
162 {
163  int i;
164  double gamma, simil, C;
165  int16_t *ct = av_malloc((512<<LUT_BITS)*sizeof(int16_t));
166  if (!ct)
167  return NULL;
168 
169  gamma = log(0.25) / log(1.0 - FFMIN(dist25,252.0)/255.0 - 0.00001);
170 
171  for (i = -255<<LUT_BITS; i <= 255<<LUT_BITS; i++) {
172  double f = ((i<<(9-LUT_BITS)) + (1<<(8-LUT_BITS)) - 1) / 512.0; // midpoint of the bin
173  simil = 1.0 - FFABS(f) / 255.0;
174  C = pow(simil, gamma) * 256.0 * f;
175  ct[(256<<LUT_BITS)+i] = lrint(C);
176  }
177 
178  ct[0] = !!dist25;
179  return ct;
180 }
181 
182 #define PARAM1_DEFAULT 4.0
183 #define PARAM2_DEFAULT 3.0
184 #define PARAM3_DEFAULT 6.0
185 
186 static av_cold int init(AVFilterContext *ctx)
187 {
188  HQDN3DContext *s = ctx->priv;
189 
190  if (!s->strength[LUMA_SPATIAL])
192  if (!s->strength[CHROMA_SPATIAL])
194  if (!s->strength[LUMA_TMP])
196  if (!s->strength[CHROMA_TMP])
198 
199  av_log(ctx, AV_LOG_VERBOSE, "ls:%f cs:%f lt:%f ct:%f\n",
202 
203  return 0;
204 }
205 
206 static av_cold void uninit(AVFilterContext *ctx)
207 {
208  HQDN3DContext *s = ctx->priv;
209 
210  av_freep(&s->coefs[0]);
211  av_freep(&s->coefs[1]);
212  av_freep(&s->coefs[2]);
213  av_freep(&s->coefs[3]);
214  av_freep(&s->line);
215  av_freep(&s->frame_prev[0]);
216  av_freep(&s->frame_prev[1]);
217  av_freep(&s->frame_prev[2]);
218 }
219 
221 {
222  static const enum AVPixelFormat pix_fmts[] = {
243  };
244 
246 
247  return 0;
248 }
249 
250 static int config_input(AVFilterLink *inlink)
251 {
252  HQDN3DContext *s = inlink->dst->priv;
253  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
254  int i;
255 
256  uninit(inlink->dst);
257 
258  s->hsub = desc->log2_chroma_w;
259  s->vsub = desc->log2_chroma_h;
260  s->depth = desc->comp[0].depth_minus1+1;
261 
262  s->line = av_malloc(inlink->w * sizeof(*s->line));
263  if (!s->line)
264  return AVERROR(ENOMEM);
265 
266  for (i = 0; i < 4; i++) {
267  s->coefs[i] = precalc_coefs(s->strength[i], s->depth);
268  if (!s->coefs[i])
269  return AVERROR(ENOMEM);
270  }
271 
272  if (ARCH_X86)
274 
275  return 0;
276 }
277 
278 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
279 {
280  HQDN3DContext *s = inlink->dst->priv;
281  AVFilterLink *outlink = inlink->dst->outputs[0];
282  AVFrame *out;
283  int direct, c;
284 
285  if (av_frame_is_writable(in)) {
286  direct = 1;
287  out = in;
288  } else {
289  direct = 0;
290  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
291  if (!out) {
292  av_frame_free(&in);
293  return AVERROR(ENOMEM);
294  }
295 
296  av_frame_copy_props(out, in);
297  out->width = outlink->w;
298  out->height = outlink->h;
299  }
300 
301  for (c = 0; c < 3; c++) {
302  denoise(s, in->data[c], out->data[c],
303  s->line, &s->frame_prev[c],
304  in->width >> (!!c * s->hsub),
305  in->height >> (!!c * s->vsub),
306  in->linesize[c], out->linesize[c],
307  s->coefs[c?2:0], s->coefs[c?3:1]);
308  }
309 
310  if (!direct)
311  av_frame_free(&in);
312 
313  return ff_filter_frame(outlink, out);
314 }
315 
316 #define OFFSET(x) offsetof(HQDN3DContext, x)
317 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM
318 static const AVOption options[] = {
319  { "luma_spatial", "spatial luma strength", OFFSET(strength[LUMA_SPATIAL]), AV_OPT_TYPE_DOUBLE, { .dbl = 0.0 }, 0, DBL_MAX, FLAGS },
320  { "chroma_spatial", "spatial chroma strength", OFFSET(strength[CHROMA_SPATIAL]), AV_OPT_TYPE_DOUBLE, { .dbl = 0.0 }, 0, DBL_MAX, FLAGS },
321  { "luma_tmp", "temporal luma strength", OFFSET(strength[LUMA_TMP]), AV_OPT_TYPE_DOUBLE, { .dbl = 0.0 }, 0, DBL_MAX, FLAGS },
322  { "chroma_tmp", "temporal chroma strength", OFFSET(strength[CHROMA_TMP]), AV_OPT_TYPE_DOUBLE, { .dbl = 0.0 }, 0, DBL_MAX, FLAGS },
323  { NULL },
324 };
325 
326 static const AVClass hqdn3d_class = {
327  .class_name = "hqdn3d",
328  .item_name = av_default_item_name,
329  .option = options,
330  .version = LIBAVUTIL_VERSION_INT,
331 };
332 
334  {
335  .name = "default",
336  .type = AVMEDIA_TYPE_VIDEO,
337  .config_props = config_input,
338  .filter_frame = filter_frame,
339  },
340  { NULL }
341 };
342 
344  {
345  .name = "default",
346  .type = AVMEDIA_TYPE_VIDEO
347  },
348  { NULL }
349 };
350 
352  .name = "hqdn3d",
353  .description = NULL_IF_CONFIG_SMALL("Apply a High Quality 3D Denoiser."),
354 
355  .priv_size = sizeof(HQDN3DContext),
356  .priv_class = &hqdn3d_class,
357  .init = init,
358  .uninit = uninit,
360 
361  .inputs = avfilter_vf_hqdn3d_inputs,
362 
363  .outputs = avfilter_vf_hqdn3d_outputs,
364 };
static const AVOption options[]
Definition: vf_hqdn3d.c:318
planar YUV 4:2:2, 18bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
Definition: pixfmt.h:160
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:62
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:1599
This structure describes decoded (raw) audio or video data.
Definition: frame.h:135
AVOption.
Definition: opt.h:234
planar YUV 4:2:0, 15bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
Definition: pixfmt.h:153
static const AVFilterPad avfilter_vf_hqdn3d_inputs[]
Definition: vf_hqdn3d.c:333
static const AVFilterPad avfilter_vf_hqdn3d_outputs[]
Definition: vf_hqdn3d.c:343
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:70
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:232
Main libavfilter public API header.
#define LUMA_SPATIAL
Definition: vf_hqdn3d.h:38
planar YUV 4:4:4, 27bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
Definition: pixfmt.h:156
#define ARCH_X86
Definition: config.h:33
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;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);returnNULL;}returnac;}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;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->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);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_dlog(ac->avr,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
#define FLAGS
Definition: vf_hqdn3d.c:317
planar YUV 4:2:0, 13.5bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
Definition: pixfmt.h:150
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:104
uint16_t * line
Definition: vf_hqdn3d.h:30
planar YUV 4:2:0, 24bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
Definition: pixfmt.h:129
void(* denoise_row[17])(uint8_t *src, uint8_t *dst, uint16_t *line_ant, uint16_t *frame_ant, ptrdiff_t w, int16_t *spatial, int16_t *temporal)
Definition: vf_hqdn3d.h:35
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:80
void ff_hqdn3d_init_x86(HQDN3DContext *hqdn3d)
Macro definitions for various function/variable attributes.
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:198
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:165
const char * name
Pad name.
Definition: internal.h:42
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:38
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:733
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:97
uint8_t
#define av_cold
Definition: attributes.h:66
uint16_t * frame_prev[3]
Definition: vf_hqdn3d.h:31
AVOptions.
#define AV_NE(be, le)
Definition: common.h:45
#define emms_c()
Definition: internal.h:47
#define PARAM1_DEFAULT
Definition: vf_hqdn3d.c:182
static av_always_inline void denoise_temporal(uint8_t *src, uint8_t *dst, uint16_t *frame_ant, int w, int h, int sstride, int dstride, int16_t *temporal, int depth)
Definition: vf_hqdn3d.c:58
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of PIX_FMT_YUV440P and setting color_range ...
Definition: pixfmt.h:103
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV422P and setting color_...
Definition: pixfmt.h:78
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:139
void 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:379
AVFilter ff_vf_hqdn3d
Definition: vf_hqdn3d.c:351
#define CHROMA_SPATIAL
Definition: vf_hqdn3d.h:40
A filter pad used for either input or output.
Definition: internal.h:36
planar YUV 4:2:0, 13.5bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
Definition: pixfmt.h:151
static av_always_inline void denoise_depth(HQDN3DContext *s, uint8_t *src, uint8_t *dst, uint16_t *line_ant, uint16_t **frame_ant_ptr, int w, int h, int sstride, int dstride, int16_t *spatial, int16_t *temporal, int depth)
Definition: vf_hqdn3d.c:124
planar YUV 4:4:4, 30bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition: pixfmt.h:159
uint16_t depth_minus1
Number of bits in the component minus 1.
Definition: pixdesc.h:57
static av_always_inline void denoise_spatial(HQDN3DContext *s, uint8_t *src, uint8_t *dst, uint16_t *line_ant, uint16_t *frame_ant, int w, int h, int sstride, int dstride, int16_t *spatial, int16_t *temporal, int depth)
Definition: vf_hqdn3d.c:80
int width
width and height of the video frame
Definition: frame.h:174
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:89
#define LOAD(x)
Definition: vf_hqdn3d.c:45
planar YUV 4:4:4, 48bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
Definition: pixfmt.h:134
#define AVERROR(e)
Definition: error.h:43
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:69
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:150
int16_t * coefs[4]
Definition: vf_hqdn3d.h:29
void * priv
private data for use by the filter
Definition: avfilter.h:584
planar YUV 4:2:2, 20bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
Definition: pixfmt.h:155
double strength[4]
Definition: vf_hqdn3d.h:32
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:168
planar YUV 4:2:2, 32bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
Definition: pixfmt.h:132
static int config_input(AVFilterLink *inlink)
Definition: vf_hqdn3d.c:250
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:69
#define FFMIN(a, b)
Definition: common.h:57
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV420P and setting color_...
Definition: pixfmt.h:77
#define FFABS(a)
Definition: common.h:52
static av_always_inline uint32_t lowpass(int prev, int cur, int16_t *coef, int depth)
Definition: vf_hqdn3d.c:51
planar YUV 4:2:0, 15bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
Definition: pixfmt.h:152
planar YUV 4:2:2, 18bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
Definition: pixfmt.h:161
LIBAVUTIL_VERSION_INT
Definition: eval.c:55
#define OFFSET(x)
Definition: vf_hqdn3d.c:316
NULL
Definition: eval.c:55
planar YUV 4:2:0, 24bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
Definition: pixfmt.h:130
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition: frame.c:309
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:153
av_default_item_name
Definition: dnxhdenc.c:52
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
#define LUMA_TMP
Definition: vf_hqdn3d.h:39
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:71
#define LUT_BITS
Definition: vf_hqdn3d.c:44
#define CHROMA_TMP
Definition: vf_hqdn3d.h:41
Describe the class of an AVClass context structure.
Definition: log.h:33
Filter definition.
Definition: avfilter.h:421
static const AVFilterPad inputs[]
Definition: af_ashowinfo.c:221
static av_always_inline av_const long int lrint(double x)
Definition: libm.h:137
const char * name
Filter name.
Definition: avfilter.h:425
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:578
#define PARAM3_DEFAULT
Definition: vf_hqdn3d.c:184
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_hqdn3d.c:278
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:141
planar YUV 4:4:4, 27bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition: pixfmt.h:157
planar YUV 4:4:4, 48bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition: pixfmt.h:133
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;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);returnNULL;}returnac;}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;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->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);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_dlog(ac->avr,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> out
#define PARAM2_DEFAULT
Definition: vf_hqdn3d.c:183
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:65
common internal and external API header
planar YUV 4:2:2, 32bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
Definition: pixfmt.h:131
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV444P and setting color_...
Definition: pixfmt.h:79
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:72
static const AVClass hqdn3d_class
Definition: vf_hqdn3d.c:326
static av_cold int init(AVFilterContext *ctx)
Definition: vf_hqdn3d.c:186
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_hqdn3d.c:206
An instance of a filter.
Definition: avfilter.h:563
#define denoise(...)
Definition: vf_hqdn3d.c:153
int height
Definition: frame.h:174
static int16_t * precalc_coefs(double dist25, int depth)
Definition: vf_hqdn3d.c:161
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:102
#define av_always_inline
Definition: attributes.h:40
internal API functions
AVPixelFormat
Pixel format.
Definition: pixfmt.h:63
static int query_formats(AVFilterContext *ctx)
Definition: vf_hqdn3d.c:220
planar YUV 4:4:4, 30bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
Definition: pixfmt.h:158
#define STORE(x, val)
Definition: vf_hqdn3d.c:47
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:367
planar YUV 4:2:2, 20bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
Definition: pixfmt.h:154