40 uint16_t *frame_prev[3];
44 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);
52 #define LUT_BITS (depth==16 ? 8 : 4)
53 #define LOAD(x) (((depth == 8 ? src[x] : AV_RN16A(src + (x) * 2)) << (16 - depth))\
54 + (((1 << (16 - depth)) - 1) >> 1))
55 #define STORE(x,val) (depth == 8 ? dst[x] = (val) >> (16 - depth) : \
56 AV_WN16A(dst + (x) * 2, (val) >> (16 - depth)))
59 static uint32_t
lowpass(
int prev,
int cur, int16_t *coef,
int depth)
61 int d = (prev - cur) >> (8 -
LUT_BITS);
68 int w,
int h,
int sstride,
int dstride,
69 int16_t *temporal,
int depth)
76 for (y = 0; y < h; y++) {
77 for (x = 0; x < w; x++) {
78 frame_ant[x] = tmp =
lowpass(frame_ant[x],
LOAD(x), temporal, depth);
90 uint16_t *line_ant, uint16_t *frame_ant,
91 int w,
int h,
int sstride,
int dstride,
92 int16_t *spatial, int16_t *temporal,
int depth)
104 for (x = 0; x < w; x++) {
105 line_ant[x] = tmp = pixel_ant =
lowpass(pixel_ant,
LOAD(x), spatial, depth);
106 frame_ant[x] = tmp =
lowpass(frame_ant[x], tmp, temporal, depth);
110 for (y = 1; y < h; y++) {
115 hqdn3d->
denoise_row[depth](src, dst, line_ant, frame_ant, w, spatial, temporal);
119 for (x = 0; x < w-1; x++) {
120 line_ant[x] = tmp =
lowpass(line_ant[x], pixel_ant, spatial, depth);
121 pixel_ant =
lowpass(pixel_ant,
LOAD(x+1), spatial, depth);
122 frame_ant[x] = tmp =
lowpass(frame_ant[x], tmp, temporal, depth);
125 line_ant[x] = tmp =
lowpass(line_ant[x], pixel_ant, spatial, depth);
126 frame_ant[x] = tmp =
lowpass(frame_ant[x], tmp, temporal, depth);
134 uint16_t *line_ant, uint16_t **frame_ant_ptr,
135 int w,
int h,
int sstride,
int dstride,
136 int16_t *spatial, int16_t *temporal,
int depth)
141 uint16_t *frame_ant = *frame_ant_ptr;
144 *frame_ant_ptr = frame_ant =
av_malloc(w*h*
sizeof(uint16_t));
145 for (y = 0; y < h; y++, src += sstride, frame_ant += w)
146 for (x = 0; x < w; x++)
147 frame_ant[x] =
LOAD(x);
149 frame_ant = *frame_ant_ptr;
154 w, h, sstride, dstride, spatial, temporal, depth);
157 w, h, sstride, dstride, temporal, depth);
161 #define denoise(...) \
162 switch (hqdn3d->depth) {\
163 case 8: denoise_depth(__VA_ARGS__, 8); break;\
164 case 9: denoise_depth(__VA_ARGS__, 9); break;\
165 case 10: denoise_depth(__VA_ARGS__, 10); break;\
166 case 16: denoise_depth(__VA_ARGS__, 16); break;\
172 double gamma, simil, C;
177 gamma = log(0.25) / log(1.0 -
FFMIN(dist25,252.0)/255.0 - 0.00001);
181 simil = 1.0 -
FFABS(f) / 255.0;
182 C = pow(simil, gamma) * 256.0 * f;
190 #define PARAM1_DEFAULT 4.0
191 #define PARAM2_DEFAULT 3.0
192 #define PARAM3_DEFAULT 6.0
197 double lum_spac, lum_tmp, chrom_spac, chrom_tmp;
198 double param1, param2, param3, param4;
203 chrom_tmp = lum_tmp * chrom_spac / lum_spac;
206 switch (sscanf(args,
"%lf:%lf:%lf:%lf",
207 ¶m1, ¶m2, ¶m3, ¶m4)) {
212 chrom_tmp = lum_tmp * chrom_spac / lum_spac;
218 chrom_tmp = lum_tmp * chrom_spac / lum_spac;
224 chrom_tmp = lum_tmp * chrom_spac / lum_spac;
241 lum_spac, chrom_spac, lum_tmp, chrom_tmp);
242 if (lum_spac < 0 || chrom_spac < 0 ||
isnan(chrom_tmp)) {
244 "Invalid negative value for luma or chroma spatial strength, "
245 "or resulting value for chroma temporal strength is nan.\n");
310 for (i = 0; i < 4; i++) {
312 if (!hqdn3d->
coefs[i])
349 for (c = 0; c < 3; c++) {
391 .
inputs = avfilter_vf_hqdn3d_inputs,
393 .
outputs = avfilter_vf_hqdn3d_outputs,
planar YUV 4:2:2, 18bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
AVFilterBufferRefVideoProps * video
video buffer specific properties
planar YUV 4:2:0, 15bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
static const AVFilterPad avfilter_vf_hqdn3d_inputs[]
static const AVFilterPad avfilter_vf_hqdn3d_outputs[]
int linesize[8]
number of bytes per line
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
static const AVFilterPad outputs[]
planar YUV 4:4:4, 27bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
int h
agreed upon image height
int ff_filter_frame(AVFilterLink *link, AVFilterBufferRef *frame)
Send a frame of data to the next filter.
planar YUV 4:2:0, 13.5bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
planar YUV 4:2:0, 24bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
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)
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
const char * name
Pad name.
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
static av_always_inline av_const int isnan(float x)
void avfilter_unref_bufferp(AVFilterBufferRef **ref)
Remove a reference to a buffer and set the pointer to NULL.
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 PIX_FMT_YUV440P and setting color_range ...
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV422P and setting color_...
static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *in)
A filter pad used for either input or output.
planar YUV 4:2:0, 13.5bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
void ff_hqdn3d_row_16_x86(uint8_t *src, uint8_t *dst, uint16_t *line_ant, uint16_t *frame_ant, ptrdiff_t w, int16_t *spatial, int16_t *temporal)
A link between two filters.
void ff_hqdn3d_row_9_x86(uint8_t *src, uint8_t *dst, uint16_t *line_ant, uint16_t *frame_ant, ptrdiff_t w, int16_t *spatial, int16_t *temporal)
planar YUV 4:4:4, 30bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
AVFilterBufferRef * ff_get_video_buffer(AVFilterLink *link, int perms, int w, int h)
Request a picture buffer with a specific set of permissions.
uint16_t depth_minus1
number of bits in the component minus 1
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
planar YUV 4:4:4, 48bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
#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
planar YUV 4:2:2, 20bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
void av_log(void *avcl, int level, const char *fmt,...)
planar YUV 4:2:2, 32bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
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
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV420P and setting color_...
static av_always_inline void denoise_spatial(HQDN3DContext *hqdn3d, 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)
static av_always_inline uint32_t lowpass(int prev, int cur, int16_t *coef, int depth)
planar YUV 4:2:0, 15bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
planar YUV 4:2:2, 18bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
void ff_hqdn3d_row_8_x86(uint8_t *src, uint8_t *dst, uint16_t *line_ant, uint16_t *frame_ant, ptrdiff_t w, int16_t *spatial, int16_t *temporal)
int format
agreed upon media format
A reference to an AVFilterBuffer.
planar YUV 4:2:0, 24bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
int perms
permissions, see the AV_PERM_* flags
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
static void(WINAPI *cond_broadcast)(pthread_cond_t *cond)
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
static const AVFilterPad inputs[]
static void uninit(AVFilterContext *ctx)
static av_always_inline av_const long int lrint(double x)
const char * name
filter name
static av_always_inline void denoise_depth(HQDN3DContext *hqdn3d, 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)
AVFilterLink ** outputs
array of pointers to output links
#define AV_PERM_PRESERVE
nobody else can overwrite the buffer
static int init(AVFilterContext *ctx, const char *args)
AVFilter avfilter_vf_hqdn3d
void ff_hqdn3d_row_10_x86(uint8_t *src, uint8_t *dst, uint16_t *line_ant, uint16_t *frame_ant, ptrdiff_t w, int16_t *spatial, int16_t *temporal)
planar YUV 4:4:4, 27bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
planar YUV 4:4:4, 48bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
common internal and external API header
void avfilter_copy_buffer_ref_props(AVFilterBufferRef *dst, AVFilterBufferRef *src)
Copy properties of src to dst, without copying the actual data.
planar YUV 4:2:2, 32bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV444P and setting color_...
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
#define AV_PERM_WRITE
can write to the buffer
AVFilterContext * dst
dest filter
uint8_t * data[8]
picture/audio data for each plane
static int16_t * precalc_coefs(double dist25, int depth)
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
AVPixelFormat
Pixel format.
static int query_formats(AVFilterContext *ctx)
planar YUV 4:4:4, 30bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
planar YUV 4:2:2, 20bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian