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
18270 18270
18271@item ecolor, ec18271@item ecolor, ec
18272Set envelope color. Default is @code{gold}.18272Set envelope color. Default is @code{gold}.
18273
18274@item slide
18275Set slide mode.
18276
18277Available values for slide is:
18278@table @samp
18279@item frame
18280Draw new frame when right border is reached.
18281
18282@item replace
18283Replace old columns with new ones.
18284
18285@item scroll
18286Scroll from right to left.
18287
18288@item rscroll
18289Scroll from left to right.
18290
18291@item picture
18292Draw single picture.
18293@end table
18294
18295Default is @code{replace}.
18273@end table18296@end table
18274 18297
18275@section threshold18298@section threshold
libavfilter/vf_histogram.c+41−1
@@ -34,6 +34,7 @@ typedef struct HistogramContext { · 33 unmodified lines
34 const AVClass *class; ///< AVClass context for log and options purpose34 const AVClass *class; ///< AVClass context for log and options purpose
35 int thistogram;35 int thistogram;
36 int envelope;36 int envelope;
37 int slide;
37 unsigned histogram[256*256];38 unsigned histogram[256*256];
38 int histogram_size;39 int histogram_size;
39 int width;40 int width;
@@ -354,8 +355,25 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 314 unmodified lines
354 max_hval_log = log2(max_hval + 1);355 max_hval_log = log2(max_hval + 1);
355 356
356 if (s->thistogram) {357 if (s->thistogram) {
358 const int bpp = 1 + (s->histogram_size > 256);
357 int minh = s->histogram_size - 1, maxh = 0;359 int minh = s->histogram_size - 1, maxh = 0;
358 360
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
359 for (int i = 0; i < s->histogram_size; i++) {377 for (int i = 0; i < s->histogram_size; i++) {
360 int idx = s->histogram_size - i - 1;378 int idx = s->histogram_size - i - 1;
361 int value = s->start[p];379 int value = s->start[p];
@@ -443,8 +461,15 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 81 unmodified lines
443 out->pts = in->pts;461 out->pts = in->pts;
444 av_frame_free(&in);462 av_frame_free(&in);
445 s->x_pos++;463 s->x_pos++;
446 if (s->x_pos >= s->width)464 if (s->x_pos >= s->width) {
447 s->x_pos = 0;465 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 }
448 473
449 if (s->thistogram) {474 if (s->thistogram) {
450 AVFrame *clone = av_frame_clone(out);475 AVFrame *clone = av_frame_clone(out);
@@ -453,6 +478,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 2 unmodified lines
453 return AVERROR(ENOMEM);478 return AVERROR(ENOMEM);
454 return ff_filter_frame(outlink, clone);479 return ff_filter_frame(outlink, clone);
455 }480 }
481end:
456 return ff_filter_frame(outlink, out);482 return ff_filter_frame(outlink, out);
457}483}
458 484
@@ -491,6 +517,13 @@ AVFilter ff_vf_histogram = { · 32 unmodified lines
491 517
492#if CONFIG_THISTOGRAM_FILTER518#if CONFIG_THISTOGRAM_FILTER
493 519
520static av_cold void uninit(AVFilterContext *ctx)
521{
522 HistogramContext *s = ctx->priv;
523
524 av_frame_free(&s->out);
525}
526
494static const AVOption thistogram_options[] = {527static const AVOption thistogram_options[] = {
495 { "width", "set width", OFFSET(width), AV_OPT_TYPE_INT, {.i64=0}, 0, 8192, FLAGS},528 { "width", "set width", OFFSET(width), AV_OPT_TYPE_INT, {.i64=0}, 0, 8192, FLAGS},
496 { "w", "set width", OFFSET(width), AV_OPT_TYPE_INT, {.i64=0}, 0, 8192, FLAGS},529 { "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
501 { "e", "display envelope", OFFSET(envelope), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS },534 { "e", "display envelope", OFFSET(envelope), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS },
502 { "ecolor", "set envelope color", OFFSET(envelope_rgba), AV_OPT_TYPE_COLOR, {.str="gold"}, 0, 0, FLAGS },535 { "ecolor", "set envelope color", OFFSET(envelope_rgba), AV_OPT_TYPE_COLOR, {.str="gold"}, 0, 0, FLAGS },
503 { "ec", "set envelope color", OFFSET(envelope_rgba), AV_OPT_TYPE_COLOR, {.str="gold"}, 0, 0, FLAGS },536 { "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"},
504 { NULL }543 { NULL }
505};544};
506 545
@@ -513,6 +552,7 @@ AVFilter ff_vf_thistogram = { · 6 unmodified lines
513 .query_formats = query_formats,552 .query_formats = query_formats,
514 .inputs = inputs,553 .inputs = inputs,
515 .outputs = outputs,554 .outputs = outputs,
555 .uninit = uninit,
516 .priv_class = &thistogram_class,556 .priv_class = &thistogram_class,
517};557};
518 558

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