31 #include "libavutil/imgutils.h"
32 #include "libavutil/opt.h"
33 #include "libavutil/pixdesc.h"
42 float *plane[16+1][4];
47 #define OFFSET(x) offsetof(OWDenoiseContext, x)
48 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
61 { 0, 48, 12, 60, 3, 51, 15, 63 },
62 { 32, 16, 44, 28, 35, 19, 47, 31 },
63 { 8, 56, 4, 52, 11, 59, 7, 55 },
64 { 40, 24, 36, 20, 43, 27, 39, 23 },
65 { 2, 50, 14, 62, 1, 49, 13, 61 },
66 { 34, 18, 46, 30, 33, 17, 45, 29 },
67 { 10, 58, 6, 54, 9, 57, 5, 53 },
68 { 42, 26, 38, 22, 41, 25, 37, 21 },
71 static const double coeff[2][5] = {
103 while ((
unsigned)x > (
unsigned)w) {
111 static inline void decompose(
float *dst_l,
float *dst_h,
const float *
src,
115 for (x = 0; x < w; x++) {
116 double sum_l = src[x * linesize] *
coeff[0][0];
117 double sum_h = src[x * linesize] * coeff[1][0];
118 for (i = 1; i <= 4; i++) {
119 const double s = src[
mirror(x - i, w - 1) * linesize]
120 + src[
mirror(x + i, w - 1) * linesize];
122 sum_l += coeff[0][i] *
s;
123 sum_h += coeff[1][i] *
s;
125 dst_l[x * linesize] = sum_l;
126 dst_h[x * linesize] = sum_h;
130 static inline void compose(
float *dst,
const float *src_l,
const float *src_h,
134 for (x = 0; x < w; x++) {
135 double sum_l = src_l[x * linesize] *
icoeff[0][0];
136 double sum_h = src_h[x * linesize] * icoeff[1][0];
137 for (i = 1; i <= 4; i++) {
138 const int x0 =
mirror(x - i, w - 1) * linesize;
139 const int x1 =
mirror(x + i, w - 1) * linesize;
141 sum_l += icoeff[0][i] * (src_l[x0] + src_l[x1]);
142 sum_h += icoeff[1][i] * (src_h[x0] + src_h[x1]);
144 dst[x * linesize] = (sum_l + sum_h) * 0.5;
149 int xlinesize,
int ylinesize,
150 int step,
int w,
int h)
153 for (y = 0; y < h; y++)
154 for (x = 0; x < step; x++)
155 decompose(dst_l + ylinesize*y + xlinesize*x,
156 dst_h + ylinesize*y + xlinesize*x,
157 src + ylinesize*y + xlinesize*x,
158 step * xlinesize, (w - x + step - 1) / step);
161 static inline void compose2D(
float *dst,
const float *src_l,
const float *src_h,
162 int xlinesize,
int ylinesize,
163 int step,
int w,
int h)
166 for (y = 0; y < h; y++)
167 for (x = 0; x < step; x++)
168 compose(dst + ylinesize*y + xlinesize*x,
169 src_l + ylinesize*y + xlinesize*x,
170 src_h + ylinesize*y + xlinesize*x,
171 step * xlinesize, (w - x + step - 1) / step);
175 int linesize,
int step,
int w,
int h)
177 decompose2D(temp[0], temp[1], src, 1, linesize, step, w, h);
178 decompose2D( dst[0], dst[1], temp[0], linesize, 1, step, h, w);
179 decompose2D( dst[2], dst[3], temp[1], linesize, 1, step, h, w);
183 int linesize,
int step,
int w,
int h)
185 compose2D(temp[0], src[0], src[1], linesize, 1, step, h, w);
186 compose2D(temp[1], src[2], src[3], linesize, 1, step, h, w);
187 compose2D(dst, temp[0], temp[1], 1, linesize, step, w, h);
191 uint8_t *dst,
int dst_linesize,
197 while (1<<depth > width || 1<<depth > height)
200 for (y = 0; y <
height; y++)
201 for(x = 0; x <
width; x++)
207 for (i = 0; i <
depth; i++) {
208 for (j = 1; j < 4; j++) {
209 for (y = 0; y <
height; y++) {
210 for (x = 0; x <
width; x++) {
212 if (v > strength) v -= strength;
213 else if (v < -strength) v += strength;
220 for (i = depth-1; i >= 0; i--)
223 for (y = 0; y <
height; y++) {
224 for (x = 0; x <
width; x++) {
226 if ((
unsigned)i > 255
U) i = ~(i >> 31);
227 dst[y*dst_linesize + x] = i;
262 inlink->
w, inlink->
h);
288 const int h =
FFALIGN(inlink->
h, 16);
294 for (j = 0; j < 4; j++) {
295 for (i = 0; i <= s->
depth; i++) {
309 for (j = 0; j < 4; j++)
310 for (i = 0; i <= s->
depth; i++)
338 .
inputs = owdenoise_inputs,
340 .priv_class = &owdenoise_class,
static void compose(float *dst, const float *src_l, const float *src_h, int linesize, int w)
This structure describes decoded (raw) audio or video data.
const char * name
Filter name.
void * priv
private data for use by the filter
static const AVFilterPad outputs[]
static int config_input(AVFilterLink *inlink)
int h
agreed upon image height
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
static void decompose2D2(float *dst[4], float *src, float *temp[2], int linesize, int step, int w, int h)
AVFilter avfilter_vf_owdenoise
#define DECLARE_ALIGNED(n, t, v)
static void filter(OWDenoiseContext *s, uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize, int width, int height, double strength)
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
void av_freep(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
const char * name
Pad name.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
static void decompose(float *dst_l, float *dst_h, const float *src, int linesize, int w)
static const AVOption owdenoise_options[]
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
#define FF_CEIL_RSHIFT(a, b)
static void decompose2D(float *dst_l, float *dst_h, const float *src, int xlinesize, int ylinesize, int step, int w, int h)
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
A filter pad used for either input or output.
A link between two filters.
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
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
AVPixelFormat
Pixel format.
int w
agreed upon image width
static void compose2D2(float *dst, float *src[4], float *temp[2], int linesize, int step, int w, int h)
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 ...
int format
agreed upon media format
static const AVFilterPad owdenoise_outputs[]
Main libavfilter public API header.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
AVFilterLink ** outputs
array of pointers to output links
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
static const uint8_t dither[8][8]
BYTE int const BYTE int int int height
Describe the class of an AVClass context structure.
static const double icoeff[2][5]
static const AVFilterPad inputs[]
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
static int query_formats(AVFilterContext *ctx)
static void compose2D(float *dst, const float *src_l, const float *src_h, int xlinesize, int ylinesize, int step, int w, int h)
AVFilterContext * dst
dest filter
static av_cold void uninit(AVFilterContext *ctx)
static int mirror(int x, int w)
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 const double coeff[2][5]
void av_image_copy_plane(uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize, int bytewidth, int height)
Copy image plane from src to dst.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
static const AVFilterPad owdenoise_inputs[]