Commit 206f65b0 authored by Paul B Mahol's avatar Paul B Mahol

avfilter/avf_avectorscope: add line drawing support

Signed-off-by: 's avatarPaul B Mahol <onemda@gmail.com>
parent c13216ac
...@@ -13372,6 +13372,20 @@ Allowed range is @code{[0, 255]}. ...@@ -13372,6 +13372,20 @@ Allowed range is @code{[0, 255]}.
@item zoom @item zoom
Set the zoom factor. Default value is @code{1}. Allowed range is @code{[1, 10]}. Set the zoom factor. Default value is @code{1}. Allowed range is @code{[1, 10]}.
@item draw
Set the vectorscope drawing mode.
Available values are:
@table @samp
@item dot
Draw dot for each sample.
@item line
Draw line between previous and current sample.
@end table
Default value is @samp{dot}.
@end table @end table
@subsection Examples @subsection Examples
......
...@@ -40,15 +40,23 @@ enum VectorScopeMode { ...@@ -40,15 +40,23 @@ enum VectorScopeMode {
MODE_NB, MODE_NB,
}; };
enum VectorScopeDraw {
DOT,
LINE,
DRAW_NB,
};
typedef struct AudioVectorScopeContext { typedef struct AudioVectorScopeContext {
const AVClass *class; const AVClass *class;
AVFrame *outpicref; AVFrame *outpicref;
int w, h; int w, h;
int hw, hh; int hw, hh;
int mode; int mode;
int draw;
int contrast[4]; int contrast[4];
int fade[4]; int fade[4];
double zoom; double zoom;
unsigned prev_x, prev_y;
AVRational frame_rate; AVRational frame_rate;
} AudioVectorScopeContext; } AudioVectorScopeContext;
...@@ -74,6 +82,9 @@ static const AVOption avectorscope_options[] = { ...@@ -74,6 +82,9 @@ static const AVOption avectorscope_options[] = {
{ "bf", "set blue fade", OFFSET(fade[2]), AV_OPT_TYPE_INT, {.i64=5}, 0, 255, FLAGS }, { "bf", "set blue fade", OFFSET(fade[2]), AV_OPT_TYPE_INT, {.i64=5}, 0, 255, FLAGS },
{ "af", "set alpha fade", OFFSET(fade[3]), AV_OPT_TYPE_INT, {.i64=5}, 0, 255, FLAGS }, { "af", "set alpha fade", OFFSET(fade[3]), AV_OPT_TYPE_INT, {.i64=5}, 0, 255, FLAGS },
{ "zoom", "set zoom factor", OFFSET(zoom), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 1, 10, FLAGS }, { "zoom", "set zoom factor", OFFSET(zoom), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 1, 10, FLAGS },
{ "draw", "set draw mode", OFFSET(draw), AV_OPT_TYPE_INT, {.i64=DOT}, 0, DRAW_NB-1, FLAGS, "draw" },
{ "dot", "", 0, AV_OPT_TYPE_CONST, {.i64=DOT} , 0, 0, FLAGS, "draw" },
{ "line", "", 0, AV_OPT_TYPE_CONST, {.i64=LINE}, 0, 0, FLAGS, "draw" },
{ NULL } { NULL }
}; };
...@@ -99,6 +110,32 @@ static void draw_dot(AudioVectorScopeContext *s, unsigned x, unsigned y) ...@@ -99,6 +110,32 @@ static void draw_dot(AudioVectorScopeContext *s, unsigned x, unsigned y)
dst[3] = FFMIN(dst[3] + s->contrast[3], 255); dst[3] = FFMIN(dst[3] + s->contrast[3], 255);
} }
static void draw_line(AudioVectorScopeContext *s, int x0, int y0, int x1, int y1)
{
int dx = FFABS(x1-x0), sx = x0 < x1 ? 1 : -1;
int dy = FFABS(y1-y0), sy = y0 < y1 ? 1 : -1;
int err = (dx>dy ? dx : -dy) / 2, e2;
for (;;) {
draw_dot(s, x0, y0);
if (x0 == x1 && y0 == y1)
break;
e2 = err;
if (e2 >-dx) {
err -= dy;
x0 += sx;
}
if (e2 < dy) {
err += dx;
y0 += sy;
}
}
}
static void fade(AudioVectorScopeContext *s) static void fade(AudioVectorScopeContext *s)
{ {
const int linesize = s->outpicref->linesize[0]; const int linesize = s->outpicref->linesize[0];
...@@ -168,8 +205,8 @@ static int config_output(AVFilterLink *outlink) ...@@ -168,8 +205,8 @@ static int config_output(AVFilterLink *outlink)
outlink->sample_aspect_ratio = (AVRational){1,1}; outlink->sample_aspect_ratio = (AVRational){1,1};
outlink->frame_rate = s->frame_rate; outlink->frame_rate = s->frame_rate;
s->hw = s->w / 2; s->prev_x = s->hw = s->w / 2;
s->hh = s->h / 2; s->prev_y = s->hh = s->h / 2;
return 0; return 0;
} }
...@@ -182,6 +219,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamples) ...@@ -182,6 +219,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamples)
const int hw = s->hw; const int hw = s->hw;
const int hh = s->hh; const int hh = s->hh;
unsigned x, y; unsigned x, y;
unsigned prev_x = s->prev_x, prev_y = s->prev_y;
const double zoom = s->zoom; const double zoom = s->zoom;
int i; int i;
...@@ -223,7 +261,13 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamples) ...@@ -223,7 +261,13 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamples)
y = s->h - s->h * fabsf(cx + cy) * .7; y = s->h - s->h * fabsf(cx + cy) * .7;
} }
draw_dot(s, x, y); if (s->draw == DOT) {
draw_dot(s, x, y);
} else {
draw_line(s, x, y, prev_x, prev_y);
}
prev_x = x;
prev_y = y;
} }
break; break;
case AV_SAMPLE_FMT_FLT: case AV_SAMPLE_FMT_FLT:
...@@ -247,11 +291,18 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamples) ...@@ -247,11 +291,18 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamples)
y = s->h - s->h * fabsf(cx + cy) * .7; y = s->h - s->h * fabsf(cx + cy) * .7;
} }
draw_dot(s, x, y); if (s->draw == DOT) {
draw_dot(s, x, y);
} else {
draw_line(s, x, y, prev_x, prev_y);
}
prev_x = x;
prev_y = y;
} }
break; break;
} }
s->prev_x = x, s->prev_y = y;
av_frame_free(&insamples); av_frame_free(&insamples);
return ff_filter_frame(outlink, av_frame_clone(s->outpicref)); return ff_filter_frame(outlink, av_frame_clone(s->outpicref));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment