X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavfilter%2Fvf_histogram.c;h=0862b2ae2a9d2b2b068c4fc65967a94c86658730;hb=3a3e8c35b63a40c4d59161097dc8652c15d13779;hp=4800c06f26a34caa86d2d9ca3de8ef09d184e199;hpb=2f76476549a01ae2c4ec2a440e4b14c5aba64869;p=ffmpeg diff --git a/libavfilter/vf_histogram.c b/libavfilter/vf_histogram.c index 4800c06f26a..0862b2ae2a9 100644 --- a/libavfilter/vf_histogram.c +++ b/libavfilter/vf_histogram.c @@ -34,6 +34,7 @@ typedef struct HistogramContext { const AVClass *class; ///< AVClass context for log and options purpose int thistogram; int envelope; + int slide; unsigned histogram[256*256]; int histogram_size; int width; @@ -354,8 +355,25 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) max_hval_log = log2(max_hval + 1); if (s->thistogram) { + const int bpp = 1 + (s->histogram_size > 256); int minh = s->histogram_size - 1, maxh = 0; + if (s->slide == 2) { + s->x_pos = out->width - 1; + for (j = 0; j < outlink->h; j++) { + memmove(out->data[p] + j * out->linesize[p] , + out->data[p] + j * out->linesize[p] + bpp, + (outlink->w - 1) * bpp); + } + } else if (s->slide == 3) { + s->x_pos = 0; + for (j = 0; j < outlink->h; j++) { + memmove(out->data[p] + j * out->linesize[p] + bpp, + out->data[p] + j * out->linesize[p], + (outlink->w - 1) * bpp); + } + } + for (int i = 0; i < s->histogram_size; i++) { int idx = s->histogram_size - i - 1; int value = s->start[p]; @@ -443,8 +461,15 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) out->pts = in->pts; av_frame_free(&in); s->x_pos++; - if (s->x_pos >= s->width) + if (s->x_pos >= s->width) { s->x_pos = 0; + if (s->thistogram && (s->slide == 4 || s->slide == 0)) { + s->out = NULL; + goto end; + } + } else if (s->thistogram && s->slide == 4) { + return 0; + } if (s->thistogram) { AVFrame *clone = av_frame_clone(out); @@ -453,6 +478,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) return AVERROR(ENOMEM); return ff_filter_frame(outlink, clone); } +end: return ff_filter_frame(outlink, out); } @@ -477,7 +503,7 @@ static const AVFilterPad outputs[] = { #if CONFIG_HISTOGRAM_FILTER -AVFilter ff_vf_histogram = { +const AVFilter ff_vf_histogram = { .name = "histogram", .description = NULL_IF_CONFIG_SMALL("Compute and draw a histogram."), .priv_size = sizeof(HistogramContext), @@ -491,6 +517,13 @@ AVFilter ff_vf_histogram = { #if CONFIG_THISTOGRAM_FILTER +static av_cold void uninit(AVFilterContext *ctx) +{ + HistogramContext *s = ctx->priv; + + av_frame_free(&s->out); +} + static const AVOption thistogram_options[] = { { "width", "set width", OFFSET(width), AV_OPT_TYPE_INT, {.i64=0}, 0, 8192, FLAGS}, { "w", "set width", OFFSET(width), AV_OPT_TYPE_INT, {.i64=0}, 0, 8192, FLAGS}, @@ -501,18 +534,25 @@ static const AVOption thistogram_options[] = { { "e", "display envelope", OFFSET(envelope), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS }, { "ecolor", "set envelope color", OFFSET(envelope_rgba), AV_OPT_TYPE_COLOR, {.str="gold"}, 0, 0, FLAGS }, { "ec", "set envelope color", OFFSET(envelope_rgba), AV_OPT_TYPE_COLOR, {.str="gold"}, 0, 0, FLAGS }, + { "slide", "set slide mode", OFFSET(slide), AV_OPT_TYPE_INT, {.i64=1}, 0, 4, FLAGS, "slide" }, + {"frame", "draw new frames", OFFSET(slide), AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "slide"}, + {"replace", "replace old columns with new", OFFSET(slide), AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "slide"}, + {"scroll", "scroll from right to left", OFFSET(slide), AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, FLAGS, "slide"}, + {"rscroll", "scroll from left to right", OFFSET(slide), AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, FLAGS, "slide"}, + {"picture", "display graph in single frame", OFFSET(slide), AV_OPT_TYPE_CONST, {.i64=4}, 0, 0, FLAGS, "slide"}, { NULL } }; AVFILTER_DEFINE_CLASS(thistogram); -AVFilter ff_vf_thistogram = { +const AVFilter ff_vf_thistogram = { .name = "thistogram", .description = NULL_IF_CONFIG_SMALL("Compute and draw a temporal histogram."), .priv_size = sizeof(HistogramContext), .query_formats = query_formats, .inputs = inputs, .outputs = outputs, + .uninit = uninit, .priv_class = &thistogram_class, };