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)))
51 static uint32_t
lowpass(
int prev,
int cur, int16_t *coef,
int depth)
53 int d = (prev - cur) >> (8 -
LUT_BITS);
60 int w,
int h,
int sstride,
int dstride,
61 int16_t *temporal,
int depth)
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);
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)
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);
102 for (y = 1; y <
h; y++) {
107 s->
denoise_row[depth](
src, dst, line_ant, frame_ant,
w, spatial, temporal);
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);
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);
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)
133 uint16_t *frame_ant = *frame_ant_ptr;
139 for (y = 0; y <
h; y++, src += sstride, frame_ant +=
w)
140 for (x = 0; x <
w; x++)
141 frame_ant[x] =
LOAD(x);
143 frame_ant = *frame_ant_ptr;
148 w, h, sstride, dstride, spatial, temporal, depth);
151 w, h, sstride, dstride, temporal, depth);
156 #define denoise(...) \
158 int ret = AVERROR_BUG; \
159 switch (s->depth) { \
160 case 8: ret = denoise_depth(__VA_ARGS__, 8); break; \
161 case 9: ret = denoise_depth(__VA_ARGS__, 9); break; \
162 case 10: ret = denoise_depth(__VA_ARGS__, 10); break; \
163 case 16: ret = denoise_depth(__VA_ARGS__, 16); break; \
166 av_frame_free(&out); \
168 av_frame_free(&in); \
176 double gamma, simil,
C;
181 gamma = log(0.25) / log(1.0 -
FFMIN(dist25,252.0)/255.0 - 0.00001);
185 simil =
FFMAX(0, 1.0 - fabs(f) / 255.0);
186 C = pow(simil, gamma) * 256.0 * f;
194 #define PARAM1_DEFAULT 4.0
195 #define PARAM2_DEFAULT 3.0
196 #define PARAM3_DEFAULT 6.0
278 for (i = 0; i < 4; i++) {
311 for (c = 0; c < 3; c++) {
332 #define OFFSET(x) offsetof(HQDN3DContext, x)
333 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM
367 .priv_class = &hqdn3d_class,
371 .
inputs = avfilter_vf_hqdn3d_inputs,
372 .
outputs = avfilter_vf_hqdn3d_outputs,
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
This structure describes decoded (raw) audio or video data.
static const AVFilterPad avfilter_vf_hqdn3d_inputs[]
static const AVFilterPad avfilter_vf_hqdn3d_outputs[]
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Main libavfilter public API header.
int h
agreed upon image height
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
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)
int is_disabled
the enabled state from the last expression evaluation
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
void ff_hqdn3d_init_x86(HQDN3DContext *hqdn3d)
Macro definitions for various function/variable attributes.
const char * name
Pad name.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
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)
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range...
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
#define AV_LOG_VERBOSE
Detailed information.
#define AV_PIX_FMT_YUV444P16
A filter pad used for either input or output.
A link between two filters.
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)
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void * priv
private data for use by the filter
#define AV_PIX_FMT_YUV444P10
static int config_input(AVFilterLink *inlink)
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
int w
agreed upon image width
#define AV_PIX_FMT_YUV422P9
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
static av_always_inline int 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)
static av_always_inline uint32_t lowpass(int prev, int cur, int16_t *coef, int depth)
static const AVFilterPad inputs[]
#define AV_PIX_FMT_YUV444P9
static const AVFilterPad outputs[]
int format
agreed upon media format
#define AV_PIX_FMT_YUV420P16
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
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_log(ac->avr, AV_LOG_TRACE,"%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 AV_PIX_FMT_YUV420P10
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
const char * name
Filter name.
#define AV_PIX_FMT_YUV420P9
#define AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
Same as AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, except that the filter will have its filter_frame() c...
AVFilterLink ** outputs
array of pointers to output links
static enum AVPixelFormat pix_fmts[]
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
#define AV_PIX_FMT_YUV422P10
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
static const AVOption hqdn3d_options[]
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
common internal and external API header
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
static av_cold int init(AVFilterContext *ctx)
AVFilterContext * dst
dest filter
static av_cold void uninit(AVFilterContext *ctx)
static int16_t * precalc_coefs(double dist25, int depth)
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
#define av_malloc_array(a, b)
int depth
Number of bits in the component.
AVPixelFormat
Pixel format.
static int query_formats(AVFilterContext *ctx)
#define AV_PIX_FMT_YUV422P16
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
AVFILTER_DEFINE_CLASS(hqdn3d)
#define AV_CEIL_RSHIFT(a, b)