26 #include "libavcodec/avfft.h"
27 #include "libavutil/eval.h"
28 #include "libavutil/opt.h"
33 #define BSIZE (1<<(NBITS))
35 static const char *
const var_names[] = {
"c", NULL };
49 float color_dct[3][3];
59 #define OFFSET(x) offsetof(DCTdnoizContext, x)
60 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
77 for (y = 0; y <
BSIZE; y++) {
80 memcpy(line, src, BSIZE *
sizeof(*line));
85 column[0] = line[0] * (1. / sqrt(BSIZE));
87 for (x = 1; x <
BSIZE; x++) {
88 *column = line[x] * sqrt(2. / BSIZE);
94 for (x = 0; x <
BSIZE; x++) {
96 column[0] *= 1. / sqrt(BSIZE);
97 for (y = 1; y <
BSIZE; y++)
98 column[y] *= sqrt(2. / BSIZE);
102 for (y = 0; y <
BSIZE; y++)
103 for (x = 0; x <
BSIZE; x++)
115 for (y = 0; y <
BSIZE; y++) {
116 block[0] *= sqrt(BSIZE);
117 for (x = 1; x <
BSIZE; x++)
118 block[x] *= 1./sqrt(2. / BSIZE);
124 for (y = 0; y <
BSIZE; y++) {
125 tmp[0] = block[
y] * sqrt(BSIZE);
126 for (x = 1; x <
BSIZE; x++)
127 tmp[x] = block[x*BSIZE + y] * (1./sqrt(2. / BSIZE));
129 for (x = 0; x <
BSIZE; x++)
130 dst[x*dst_linesize + y] += tmp[x];
138 int i, x,
y, bx, by, linesize, *iweights;
139 const float dct_3x3[3][3] = {
140 { 1./sqrt(3), 1./sqrt(3), 1./sqrt(3) },
141 { 1./sqrt(2), 0, -1./sqrt(2) },
142 { 1./sqrt(6), -2./sqrt(6), 1./sqrt(6) },
147 for (y = 0; y < 3; y++)
148 for (x = 0; x < 3; x++)
149 s->
color_dct[y][x] = dct_3x3[rgba_map[y]][rgba_map[x]];
161 for (i = 0; i < 2; i++) {
177 for (by = 0; by <
BSIZE; by++)
178 for (bx = 0; bx <
BSIZE; bx++)
179 iweights[(y + by)*linesize + x + bx]++;
182 s->
weights[y*linesize + x] = 1. / iweights[y*linesize + x];
194 NULL, NULL, NULL, NULL, 0, ctx);
223 const uint8_t *
src,
int src_linesize,
int w,
int h)
226 float *dstp_r = dst[0];
227 float *dstp_g = dst[1];
228 float *dstp_b = dst[2];
230 for (y = 0; y < h; y++) {
233 for (x = 0; x < w; x++) {
234 dstp_r[x] = srcp[0] * dct3ch[0][0] + srcp[1] * dct3ch[0][1] + srcp[2] * dct3ch[0][2];
235 dstp_g[x] = srcp[0] * dct3ch[1][0] + srcp[1] * dct3ch[1][1] + srcp[2] * dct3ch[1][2];
236 dstp_b[x] = srcp[0] * dct3ch[2][0] + srcp[1] * dct3ch[2][1] + srcp[2] * dct3ch[2][2];
240 dstp_r += dst_linesize;
241 dstp_g += dst_linesize;
242 dstp_b += dst_linesize;
247 float **
src,
int src_linesize,
int w,
int h)
250 const float *src_r = src[0];
251 const float *src_g = src[1];
252 const float *src_b = src[2];
254 for (y = 0; y < h; y++) {
257 for (x = 0; x < w; x++) {
258 dstp[0] = av_clip_uint8(src_r[x] * dct3ch[0][0] + src_g[x] * dct3ch[1][0] + src_b[x] * dct3ch[2][0]);
259 dstp[1] = av_clip_uint8(src_r[x] * dct3ch[0][1] + src_g[x] * dct3ch[1][1] + src_b[x] * dct3ch[2][1]);
260 dstp[2] = av_clip_uint8(src_r[x] * dct3ch[0][2] + src_g[x] * dct3ch[1][2] + src_b[x] * dct3ch[2][2]);
264 src_r += src_linesize;
265 src_g += src_linesize;
266 src_b += src_linesize;
271 float *dst,
int dst_linesize,
272 const float *
src,
int src_linesize,
278 const float *weights = s->
weights;
281 memset(dst, 0, h * dst_linesize *
sizeof(*dst));
284 for (y = 0; y < h -
BSIZE + 1; y += s->
step) {
285 for (x = 0; x < w - BSIZE + 1; x += s->
step) {
286 float *ftb =
dct_block(s, src + x, src_linesize);
289 for (by = 0; by <
BSIZE; by++) {
290 for (bx = 0; bx <
BSIZE; bx++) {
296 for (by = 0; by <
BSIZE; by++) {
297 for (bx = 0; bx <
BSIZE; bx++) {
306 src += s->
step * src_linesize;
307 dst += s->
step * dst_linesize;
312 for (y = 0; y < h; y++) {
313 for (x = 0; x < w; x++)
314 dst[x] *= weights[x];
316 weights += dst_linesize;
343 for (plane = 0; plane < 3; plane++)
354 const int dst_linesize = out->
linesize[0];
355 const int src_linesize = in->
linesize[0];
356 const int hpad = (inlink->
w - s->
pr_width) * 3;
364 memcpy(dstp, srcp, hpad);
365 dstp += dst_linesize;
366 srcp += src_linesize;
373 for (y = 0; y < vpad; y++) {
374 memcpy(dstp, srcp, inlink->
w * 3);
375 dstp += dst_linesize;
376 srcp += src_linesize;
396 for (i = 0; i < 2; i++) {
429 .
inputs = dctdnoiz_inputs,
431 .priv_class = &dctdnoiz_class,
static void color_correlation(float dct3ch[3][3], uint8_t *dst, int dst_linesize, float **src, int src_linesize, int w, int h)
void * av_calloc(size_t nmemb, size_t size) av_malloc_attrib
Allocate a block of nmemb * size bytes with alignment suitable for all memory accesses (including vec...
This structure describes decoded (raw) audio or video data.
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
Evaluate a previously parsed expression.
const char * name
Filter name.
void * priv
private data for use by the filter
#define AV_LOG_WARNING
Something somehow does not look correct.
static const AVFilterPad outputs[]
int h
agreed upon image height
packed RGB 8:8:8, 24bpp, RGBRGB...
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
int av_expr_parse(AVExpr **expr, const char *s, const char *const *const_names, const char *const *func1_names, double(*const *funcs1)(void *, double), const char *const *func2_names, double(*const *funcs2)(void *, double, double), int log_offset, void *log_ctx)
Parse an expression.
static void filter_plane(AVFilterContext *ctx, float *dst, int dst_linesize, const float *src, int src_linesize, int w, int h)
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
if((e=av_dict_get(options,"", NULL, AV_DICT_IGNORE_SUFFIX)))
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
BYTE int const BYTE * srcp
static const AVOption dctdnoiz_options[]
packed RGB 8:8:8, 24bpp, BGRBGR...
const char * name
Pad name.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
static const AVFilterPad dctdnoiz_inputs[]
static int query_formats(AVFilterContext *ctx)
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
A filter pad used for either input or output.
A link between two filters.
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
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){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));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=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);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);ff_audio_convert_init_arm(ac);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
static av_cold void uninit(AVFilterContext *ctx)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static void color_decorrelation(float dct3ch[3][3], float **dst, int dst_linesize, const uint8_t *src, int src_linesize, int w, int h)
static void idct_block(DCTdnoizContext *ctx, float *dst, int dst_linesize)
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
AVPixelFormat
Pixel format.
static const char *const var_names[]
int w
agreed upon image width
double var_values[VAR_VARS_NB]
void * av_malloc(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
#define NBITS
A simple, relatively efficient and extremely slow DCT image denoiser.
int format
agreed upon media format
int ff_fill_rgba_map(uint8_t *rgba_map, enum AVPixelFormat pix_fmt)
AVFilterLink ** outputs
array of pointers to output links
DCTContext * av_dct_init(int nbits, enum DCTTransformType type)
Set up DCT.
void av_dct_end(DCTContext *s)
Describe the class of an AVClass context structure.
static const AVFilterPad inputs[]
static float * dct_block(DCTdnoizContext *ctx, const float *src, int src_linesize)
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
AVFilterContext * dst
dest filter
void av_dct_calc(DCTContext *s, FFTSample *data)
static const AVFilterPad dctdnoiz_outputs[]
AVFilter avfilter_vf_dctdnoiz
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){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));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=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);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);ff_audio_convert_init_arm(ac);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 AVFILTER_DEFINE_CLASS(fname)
static int config_input(AVFilterLink *inlink)
static av_cold int init(AVFilterContext *ctx)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.