avfilter/signalstats: remove pointless sub filter init system

This commit is contained in:
Clément Bœsch 2014-11-16 21:12:52 +01:00 committed by Clément Bœsch
parent b424e67abf
commit c7e8f610f2
1 changed files with 15 additions and 42 deletions

View File

@ -43,7 +43,6 @@ typedef struct {
enum FilterMode outfilter; enum FilterMode outfilter;
int filters; int filters;
AVFrame *frame_prev; AVFrame *frame_prev;
char *vrep_line;
uint8_t rgba_color[4]; uint8_t rgba_color[4];
int yuv_color[3]; int yuv_color[3];
} SignalstatsContext; } SignalstatsContext;
@ -88,7 +87,6 @@ static av_cold void uninit(AVFilterContext *ctx)
{ {
SignalstatsContext *s = ctx->priv; SignalstatsContext *s = ctx->priv;
av_frame_free(&s->frame_prev); av_frame_free(&s->frame_prev);
av_freep(&s->vrep_line);
} }
static int query_formats(AVFilterContext *ctx) static int query_formats(AVFilterContext *ctx)
@ -124,12 +122,6 @@ static int config_props(AVFilterLink *outlink)
s->fs = inlink->w * inlink->h; s->fs = inlink->w * inlink->h;
s->cfs = s->chromaw * s->chromah; s->cfs = s->chromaw * s->chromah;
if (s->filters & 1<<FILTER_VREP) {
s->vrep_line = av_malloc(inlink->h * sizeof(*s->vrep_line));
if (!s->vrep_line)
return AVERROR(ENOMEM);
}
return 0; return 0;
} }
@ -209,49 +201,34 @@ filter_tout_outlier(p[(y-j) * lw + x + i], \
#define VREP_START 4 #define VREP_START 4
static void filter_init_vrep(SignalstatsContext *s, const AVFrame *p, int w, int h)
{
int i, y;
int lw = p->linesize[0];
for (y = VREP_START; y < h; y++) {
int totdiff = 0;
int y2lw = (y - VREP_START) * lw;
int ylw = y * lw;
for (i = 0; i < w; i++)
totdiff += abs(p->data[0][y2lw + i] - p->data[0][ylw + i]);
/* this value should be definable */
s->vrep_line[y] = totdiff < w;
}
}
static int filter_vrep(SignalstatsContext *s, const AVFrame *in, AVFrame *out, int y, int w, int h) static int filter_vrep(SignalstatsContext *s, const AVFrame *in, AVFrame *out, int y, int w, int h)
{ {
int x, score = 0; const uint8_t *p = in->data[0];
const int lw = in->linesize[0];
int x, score, totdiff = 0;
const int y2lw = (y - VREP_START) * lw;
const int ylw = y * lw;
if (y < VREP_START) if (y < VREP_START)
return 0; return 0;
for (x = 0; x < w; x++) { for (x = 0; x < w; x++)
if (s->vrep_line[y]) { totdiff += abs(p[y2lw + x] - p[ylw + x]);
score++;
if (out) score = (totdiff < w) * w;
burn_frame(s, out, x, y); if (score && out)
} for (x = 0; x < w; x++)
} burn_frame(s, out, x, y);
return score; return score;
} }
static const struct { static const struct {
const char *name; const char *name;
void (*init)(SignalstatsContext *s, const AVFrame *p, int w, int h);
int (*process)(SignalstatsContext *s, const AVFrame *in, AVFrame *out, int y, int w, int h); int (*process)(SignalstatsContext *s, const AVFrame *in, AVFrame *out, int y, int w, int h);
} filters_def[] = { } filters_def[] = {
{"TOUT", NULL, filter_tout}, {"TOUT", filter_tout},
{"VREP", filter_init_vrep, filter_vrep}, {"VREP", filter_vrep},
{"BRNG", NULL, filter_brng}, {"BRNG", filter_brng},
{NULL} {NULL}
}; };
@ -299,10 +276,6 @@ static int filter_frame(AVFilterLink *link, AVFrame *in)
av_frame_make_writable(out); av_frame_make_writable(out);
} }
for (fil = 0; fil < FILT_NUMB; fil ++)
if ((s->filters & 1<<fil) && filters_def[fil].init)
filters_def[fil].init(s, in, link->w, link->h);
// Calculate luma histogram and difference with previous frame or field. // Calculate luma histogram and difference with previous frame or field.
for (j = 0; j < link->h; j++) { for (j = 0; j < link->h; j++) {
for (i = 0; i < link->w; i++) { for (i = 0; i < link->w; i++) {