35 #define OFFSET(x) offsetof(RemoveGrainContext, x)
36 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
67 #define REMOVE_GRAIN_SORT_AXIS \
68 const int ma1 = FFMAX(a1, a8); \
69 const int mi1 = FFMIN(a1, a8); \
70 const int ma2 = FFMAX(a2, a7); \
71 const int mi2 = FFMIN(a2, a7); \
72 const int ma3 = FFMAX(a3, a6); \
73 const int mi3 = FFMIN(a3, a6); \
74 const int ma4 = FFMAX(a4, a5); \
75 const int mi4 = FFMIN(a4, a5);
85 static int cmp_int(
const void *p1,
const void *p2)
87 int left = *(
const int *)p1;
88 int right = *(
const int *)p2;
133 }
else if (mindiff ==
c2) {
135 }
else if (mindiff == c3) {
146 const int d1 = ma1 - mi1;
147 const int d2 = ma2 - mi2;
148 const int d3 = ma3 - mi3;
149 const int d4 = ma4 - mi4;
151 const int cli1 =
av_clip(
c, mi1, ma1);
152 const int cli2 =
av_clip(
c, mi2, ma2);
153 const int cli3 =
av_clip(
c, mi3, ma3);
154 const int cli4 =
av_clip(
c, mi4, ma4);
165 }
else if (mindiff ==
c2) {
167 }
else if (mindiff == c3) {
178 const int d1 = ma1 - mi1;
179 const int d2 = ma2 - mi2;
180 const int d3 = ma3 - mi3;
181 const int d4 = ma4 - mi4;
183 const int cli1 =
av_clip(
c, mi1, ma1);
184 const int cli2 =
av_clip(
c, mi2, ma2);
185 const int cli3 =
av_clip(
c, mi3, ma3);
186 const int cli4 =
av_clip(
c, mi4, ma4);
188 const int c1 =
FFABS(
c - cli1) + d1;
189 const int c2 =
FFABS(
c - cli2) + d2;
190 const int c3 =
FFABS(
c - cli3) + d3;
191 const int c4 =
FFABS(
c - cli4) + d4;
197 }
else if (mindiff ==
c2) {
199 }
else if (mindiff == c3) {
210 const int d1 = ma1 - mi1;
211 const int d2 = ma2 - mi2;
212 const int d3 = ma3 - mi3;
213 const int d4 = ma4 - mi4;
215 const int cli1 =
av_clip(
c, mi1, ma1);
216 const int cli2 =
av_clip(
c, mi2, ma2);
217 const int cli3 =
av_clip(
c, mi3, ma3);
218 const int cli4 =
av_clip(
c, mi4, ma4);
229 }
else if (mindiff ==
c2) {
231 }
else if (mindiff == c3) {
242 const int d1 = ma1 - mi1;
243 const int d2 = ma2 - mi2;
244 const int d3 = ma3 - mi3;
245 const int d4 = ma4 - mi4;
251 }
else if (mindiff == d2) {
253 }
else if (mindiff == d3) {
267 const int d6 =
FFABS(
c - a6);
268 const int d7 =
FFABS(
c - a7);
269 const int d8 =
FFABS(
c - a8);
274 if (mindiff == d7)
return a7;
275 if (mindiff == d8)
return a8;
276 if (mindiff == d6)
return a6;
277 if (mindiff == d2)
return a2;
278 if (mindiff == d3)
return a3;
279 if (mindiff == d1)
return a1;
280 if (mindiff == d5)
return a5;
287 const int sum = 4 *
c + 2 * (
a2 +
a4 +
a5 + a7) +
a1 +
a3 + a6 + a8;
288 const int val = (sum + 8) >> 4;
302 return (
a2 + a7 + 1) >> 1;
305 return (
a3 + a6 + 1) >> 1;
308 return (
a1 + a8 + 1) >> 1;
318 const int average = (2 * (
a2 + a7) +
a1 +
a3 + a6 + a8 + 4) >> 3;
364 const int sum =
a1 +
a2 +
a3 +
a4 +
a5 + a6 + a7 + a8;
365 const int val = (sum + 4) >> 3;
372 const int sum =
a1 +
a2 +
a3 +
a4 +
c +
a5 + a6 + a7 + a8;
373 const int val = (sum + 4) / 9;
380 const int l1l = (
a1 + a8) >> 1;
381 const int l2l = (
a2 + a7) >> 1;
382 const int l3l = (
a3 + a6) >> 1;
383 const int l4l = (
a4 +
a5) >> 1;
385 const int l1h = (
a1 + a8 + 1) >> 1;
386 const int l2h = (
a2 + a7 + 1) >> 1;
387 const int l3h = (
a3 + a6 + 1) >> 1;
388 const int l4h = (
a4 +
a5 + 1) >> 1;
398 const int l1 = (
a1 + a8 + 1) >> 1;
399 const int l2 = (
a2 + a7 + 1) >> 1;
400 const int l3 = (
a3 + a6 + 1) >> 1;
401 const int l4 = (
a4 +
a5 + 1) >> 1;
413 const int linediff1 = ma1 - mi1;
414 const int linediff2 = ma2 - mi2;
415 const int linediff3 = ma3 - mi3;
416 const int linediff4 = ma4 - mi4;
418 const int u1 =
FFMIN(
c - ma1, linediff1);
419 const int u2 =
FFMIN(
c - ma2, linediff2);
420 const int u3 =
FFMIN(
c - ma3, linediff3);
421 const int u4 =
FFMIN(
c - ma4, linediff4);
424 const int d1 =
FFMIN(mi1 -
c, linediff1);
425 const int d2 =
FFMIN(mi2 -
c, linediff2);
426 const int d3 =
FFMIN(mi3 -
c, linediff3);
427 const int d4 =
FFMIN(mi4 -
c, linediff4);
437 const int linediff1 = ma1 - mi1;
438 const int linediff2 = ma2 - mi2;
439 const int linediff3 = ma3 - mi3;
440 const int linediff4 = ma4 - mi4;
442 const int tu1 =
c - ma1;
443 const int tu2 =
c - ma2;
444 const int tu3 =
c - ma3;
445 const int tu4 =
c - ma4;
447 const int u1 =
FFMIN(tu1, linediff1 - tu1);
448 const int u2 =
FFMIN(tu2, linediff2 - tu2);
449 const int u3 =
FFMIN(tu3, linediff3 - tu3);
450 const int u4 =
FFMIN(tu4, linediff4 - tu4);
453 const int td1 = mi1 -
c;
454 const int td2 = mi2 -
c;
455 const int td3 = mi3 -
c;
456 const int td4 = mi4 -
c;
458 const int d1 =
FFMIN(td1, linediff1 - td1);
459 const int d2 =
FFMIN(td2, linediff2 - td2);
460 const int d3 =
FFMIN(td3, linediff3 - td3);
461 const int d4 =
FFMIN(td4, linediff4 - td4);
476 s->planeheight[0] =
s->planeheight[3] = inlink->
h;
478 s->planewidth[0] =
s->planewidth[3] = inlink->
w;
480 for (
i = 0;
i <
s->nb_planes;
i++) {
481 switch (
s->mode[
i]) {
494 case 13:
s->skip_odd = 1;
496 case 14:
s->skip_even = 1;
498 case 15:
s->skip_odd = 1;
500 case 16:
s->skip_even = 1;
530 const int i =
td->plane;
531 const int height =
s->planeheight[
i];
532 const int om =
in->linesize[
i] - 1;
533 const int o0 =
in->linesize[
i] ;
534 const int op =
in->linesize[
i] + 1;
539 start =
FFMAX(1, start);
541 for (y = start; y < end; y++) {
546 dst =
out->data[
i] + y *
out->linesize[
i];
548 if (
s->skip_even && !(y & 1)) {
549 memcpy(dst,
src,
s->planewidth[
i]);
552 if (
s->skip_odd && y & 1) {
553 memcpy(dst,
src,
s->planewidth[
i]);
560 int w_asm = (
s->planewidth[
i] - 2) & ~15;
562 s->fl[
i](dst,
src,
in->linesize[
i], w_asm);
570 for (; x <
s->planewidth[
i] - 1; x++) {
572 const int a2 =
src[-o0];
573 const int a3 =
src[-om];
574 const int a4 =
src[-1 ];
575 const int c =
src[ 0 ];
576 const int a5 =
src[ 1 ];
577 const int a6 =
src[ om];
578 const int a7 =
src[ o0];
579 const int a8 =
src[
op];
608 for (
i = 0;
i <
s->nb_planes;
i++) {
612 if (
s->mode[
i] == 0) {
615 s->planewidth[
i],
s->planeheight[
i]);
619 memcpy(dst,
src,
s->planewidth[
i]);
625 src =
in->data[
i] + (
s->planeheight[
i] - 1) *
in->linesize[
i];
626 dst =
out->data[
i] + (
s->planeheight[
i] - 1) *
out->linesize[
i];
627 memcpy(dst,
src,
s->planewidth[
i]);
653 .
name =
"removegrain",
659 .priv_class = &removegrain_class,
static double val(void *priv, double ch)
static const AVFilterPad inputs[]
static const AVFilterPad outputs[]
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;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);return NULL;} return ac;} 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;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->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);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Main libavfilter public API header.
#define flags(name, subs,...)
#define u(width, name, range_min, range_max)
#define AV_CEIL_RSHIFT(a, b)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
#define FFDIFFSIGN(x, y)
Comparator.
mode
Use these values in ebur128_init (or'ed).
static int ff_slice_pos(int total, int jobnr, int nb_jobs)
Compute the boundary index for a slice when work of size total is split into nb_jobs slices.
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
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.
static int op(uint8_t **dst, const uint8_t *dst_end, GetByteContext *gb, int pixel, int count, int *x, int width, int linesize)
Perform decode operation.
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static enum AVPixelFormat pix_fmts[]
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
@ AV_PIX_FMT_YUVJ440P
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
@ AV_PIX_FMT_YUVJ411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
#define AV_QSORT(p, num, type, cmp)
Quicksort This sort is fast, and fully inplace but not stable and it is possible to construct input t...
void ff_removegrain_init_x86(RemoveGrainContext *rg)
void * priv
private data for use by the filter
A link between two filters.
int w
agreed upon image width
int h
agreed upon image height
AVFilterContext * dst
dest filter
int format
agreed upon media format
A filter pad used for either input or output.
const char * name
Pad name.
const char * name
Filter name.
AVFormatInternal * internal
An opaque field for libavformat internal usage.
This structure describes decoded (raw) audio or video data.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Used for passing data between threads.
static int mode03(int c, int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8)
static int mode20(int c, int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8)
static int mode22(int c, int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8)
static int mode1314(int c, int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8)
static int filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int mode19(int c, int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8)
static int mode01(int c, int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8)
static int mode08(int c, int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8)
static int mode18(int c, int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8)
static int mode1112(int c, int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8)
static int mode24(int c, int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8)
static const AVFilterPad removegrain_outputs[]
static int mode1516(int c, int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8)
static const AVFilterPad removegrain_inputs[]
static int query_formats(AVFilterContext *ctx)
static int config_input(AVFilterLink *inlink)
static int mode02(int c, int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8)
static int mode10(int c, int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8)
AVFilter ff_vf_removegrain
static int mode09(int c, int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8)
static int mode04(int c, int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8)
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
static int mode05(int c, int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8)
AVFILTER_DEFINE_CLASS(removegrain)
static int mode06(int c, int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8)
#define REMOVE_GRAIN_SORT_AXIS
static int mode23(int c, int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8)
static int mode07(int c, int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8)
static int cmp_int(const void *p1, const void *p2)
static int mode17(int c, int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8)
static const AVOption removegrain_options[]
static int mode21(int c, int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8)
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.