History

avfilter/vf_histogram: add slide modes for thistogram

Paul B Mahol committed 6 years ago

Commit 85195f61 parent a162e782 files · +64 −1Browse files

Unified · Split

2 files
  1. doc/filters.texi +23 −0
  2. libavfilter/vf_histogram.c +41 −1
doc/filters.texi+23−0
@@ -18270,6 +18270,29 @@ Show envelope. Default is disabled. · 18269 unmodified lines
1827018270
1827118271 @item ecolor, ec
1827218272 Set envelope color. Default is @code{gold}.
18273+
18274+@item slide
18275+Set slide mode.
18276+
18277+Available values for slide is:
18278+@table @samp
18279+@item frame
18280+Draw new frame when right border is reached.
18281+
18282+@item replace
18283+Replace old columns with new ones.
18284+
18285+@item scroll
18286+Scroll from right to left.
18287+
18288+@item rscroll
18289+Scroll from left to right.
18290+
18291+@item picture
18292+Draw single picture.
18293+@end table
18294+
18295+Default is @code{replace}.
1827318296 @end table
1827418297
1827518298 @section threshold
libavfilter/vf_histogram.c+41−1
@@ -34,6 +34,7 @@ typedef struct HistogramContext { · 33 unmodified lines
3434 const AVClass *class; ///< AVClass context for log and options purpose
3535 int thistogram;
3636 int envelope;
37+ int slide;
3738 unsigned histogram[256*256];
3839 int histogram_size;
3940 int width;
@@ -354,8 +355,25 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 314 unmodified lines
354355 max_hval_log = log2(max_hval + 1);
355356
356357 if (s->thistogram) {
358+ const int bpp = 1 + (s->histogram_size > 256);
357359 int minh = s->histogram_size - 1, maxh = 0;
358360
361+ if (s->slide == 2) {
362+ s->x_pos = out->width - 1;
363+ for (j = 0; j < outlink->h; j++) {
364+ memmove(out->data[p] + j * out->linesize[p] ,
365+ out->data[p] + j * out->linesize[p] + bpp,
366+ (outlink->w - 1) * bpp);
367+ }
368+ } else if (s->slide == 3) {
369+ s->x_pos = 0;
370+ for (j = 0; j < outlink->h; j++) {
371+ memmove(out->data[p] + j * out->linesize[p] + bpp,
372+ out->data[p] + j * out->linesize[p],
373+ (outlink->w - 1) * bpp);
374+ }
375+ }
376+
359377 for (int i = 0; i < s->histogram_size; i++) {
360378 int idx = s->histogram_size - i - 1;
361379 int value = s->start[p];
@@ -443,8 +461,15 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 81 unmodified lines
443461 out->pts = in->pts;
444462 av_frame_free(&in);
445463 s->x_pos++;
446− if (s->x_pos >= s->width)
464+ if (s->x_pos >= s->width) {
447465 s->x_pos = 0;
466+ if (s->thistogram && (s->slide == 4 || s->slide == 0)) {
467+ s->out = NULL;
468+ goto end;
469+ }
470+ } else if (s->thistogram && s->slide == 4) {
471+ return 0;
472+ }
448473
449474 if (s->thistogram) {
450475 AVFrame *clone = av_frame_clone(out);
@@ -453,6 +478,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 2 unmodified lines
453478 return AVERROR(ENOMEM);
454479 return ff_filter_frame(outlink, clone);
455480 }
481+end:
456482 return ff_filter_frame(outlink, out);
457483 }
458484
@@ -491,6 +517,13 @@ AVFilter ff_vf_histogram = { · 32 unmodified lines
491517
492518 #if CONFIG_THISTOGRAM_FILTER
493519
520+static av_cold void uninit(AVFilterContext *ctx)
521+{
522+ HistogramContext *s = ctx->priv;
523+
524+ av_frame_free(&s->out);
525+}
526+
494527 static const AVOption thistogram_options[] = {
495528 { "width", "set width", OFFSET(width), AV_OPT_TYPE_INT, {.i64=0}, 0, 8192, FLAGS},
496529 { "w", "set width", OFFSET(width), AV_OPT_TYPE_INT, {.i64=0}, 0, 8192, FLAGS},
@@ -501,6 +534,12 @@ static const AVOption thistogram_options[] = { · 4 unmodified lines
501534 { "e", "display envelope", OFFSET(envelope), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS },
502535 { "ecolor", "set envelope color", OFFSET(envelope_rgba), AV_OPT_TYPE_COLOR, {.str="gold"}, 0, 0, FLAGS },
503536 { "ec", "set envelope color", OFFSET(envelope_rgba), AV_OPT_TYPE_COLOR, {.str="gold"}, 0, 0, FLAGS },
537+ { "slide", "set slide mode", OFFSET(slide), AV_OPT_TYPE_INT, {.i64=1}, 0, 4, FLAGS, "slide" },
538+ {"frame", "draw new frames", OFFSET(slide), AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "slide"},
539+ {"replace", "replace old columns with new", OFFSET(slide), AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "slide"},
540+ {"scroll", "scroll from right to left", OFFSET(slide), AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, FLAGS, "slide"},
541+ {"rscroll", "scroll from left to right", OFFSET(slide), AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, FLAGS, "slide"},
542+ {"picture", "display graph in single frame", OFFSET(slide), AV_OPT_TYPE_CONST, {.i64=4}, 0, 0, FLAGS, "slide"},
504543 { NULL }
505544 };
506545
@@ -513,6 +552,7 @@ AVFilter ff_vf_thistogram = { · 6 unmodified lines
513552 .query_formats = query_formats,
514553 .inputs = inputs,
515554 .outputs = outputs,
555+ .uninit = uninit,
516556 .priv_class = &thistogram_class,
517557 };
518558

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t