From f2f6d45dbd1795ae9f9b8ddf933201deff3d452a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= Date: Thu, 26 Dec 2013 12:08:24 +0100 Subject: [PATCH] avfilter/showwaves: add "cline" mode (centered line) --- doc/filters.texi | 3 +++ libavfilter/avf_showwaves.c | 24 +++++++++++++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/doc/filters.texi b/doc/filters.texi index 0ca1d6fd5b..2d39fca6c7 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -10813,6 +10813,9 @@ Draw a vertical line for each sample. @item p2p Draw a point for each sample and a line between them. + +@item centered_line +Draw a centered vertical line for each sample. @end table Default value is @code{point}. diff --git a/libavfilter/avf_showwaves.c b/libavfilter/avf_showwaves.c index e02566370c..6deb55ed55 100644 --- a/libavfilter/avf_showwaves.c +++ b/libavfilter/avf_showwaves.c @@ -36,6 +36,7 @@ enum ShowWavesMode { MODE_POINT, MODE_LINE, MODE_P2P, + MODE_CENTERED_LINE, MODE_NB, }; @@ -62,6 +63,7 @@ static const AVOption showwaves_options[] = { { "point", "draw a point for each sample", 0, AV_OPT_TYPE_CONST, {.i64=MODE_POINT}, .flags=FLAGS, .unit="mode"}, { "line", "draw a line for each sample", 0, AV_OPT_TYPE_CONST, {.i64=MODE_LINE}, .flags=FLAGS, .unit="mode"}, { "p2p", "draw a line between samples", 0, AV_OPT_TYPE_CONST, {.i64=MODE_P2P}, .flags=FLAGS, .unit="mode"}, + { "cline","draw a centered line for each sample", 0, AV_OPT_TYPE_CONST, {.i64=MODE_CENTERED_LINE}, .flags=FLAGS, .unit="mode"}, { "n", "set how many samples to show in the same point", OFFSET(n), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, FLAGS }, { "rate", "set video rate", OFFSET(rate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, 0, FLAGS }, { "r", "set video rate", OFFSET(rate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, 0, FLAGS }, @@ -206,26 +208,30 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamples) memset(outpicref->data[0] + j * linesize, 0, outlink->w); } for (j = 0; j < nb_channels; j++) { - h = showwaves->h/2 - av_rescale(*p++, showwaves->h/2, MAX_INT16); + int start, end; switch (showwaves->mode) { case MODE_POINT: + h = showwaves->h/2 - av_rescale(*p++, showwaves->h/2, MAX_INT16); if (h >= 0 && h < outlink->h) *(outpicref->data[0] + showwaves->buf_idx + h * linesize) += x; break; case MODE_LINE: - { - int start = showwaves->h/2, end = av_clip(h, 0, outlink->h-1); + h = showwaves->h/2 - av_rescale(*p++, showwaves->h/2, MAX_INT16); + start = showwaves->h/2; + end = av_clip(h, 0, outlink->h-1); if (start > end) FFSWAP(int16_t, start, end); for (k = start; k < end; k++) *(outpicref->data[0] + showwaves->buf_idx + k * linesize) += x; break; - } + case MODE_P2P: + h = showwaves->h/2 - av_rescale(*p++, showwaves->h/2, MAX_INT16); if (h >= 0 && h < outlink->h) { *(outpicref->data[0] + showwaves->buf_idx + h * linesize) += x; if (showwaves->buf_idy[j] && h != showwaves->buf_idy[j]) { - int start = showwaves->buf_idy[j], end = av_clip(h, 0, outlink->h-1); + start = showwaves->buf_idy[j]; + end = av_clip(h, 0, outlink->h-1); if (start > end) FFSWAP(int16_t, start, end); for (k = start + 1; k < end; k++) @@ -233,6 +239,14 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamples) } } break; + + case MODE_CENTERED_LINE: + h = av_rescale(abs(*p++), showwaves->h, UINT16_MAX); + start = (showwaves->h - h) / 2; + end = start + h; + for (k = start; k < end; k++) + *(outpicref->data[0] + showwaves->buf_idx + k * linesize) += x; + break; } /* store current y coordinate for this channel */ showwaves->buf_idy[j] = h;