avfilter/avf_avectorscope: add polar mode

This commit is contained in:
Paul B Mahol 2015-08-14 17:24:56 +02:00
parent f3fbe790d9
commit 4b0e112442
2 changed files with 25 additions and 2 deletions

View File

@ -11713,6 +11713,9 @@ Lissajous rotated by 45 degrees.
@item lissajous_xy
Same as above but not rotated.
@item polar
Shape resembling half of circle.
@end table
Default value is @samp{lissajous}.

View File

@ -36,6 +36,7 @@
enum VectorScopeMode {
LISSAJOUS,
LISSAJOUS_XY,
POLAR,
MODE_NB,
};
@ -59,6 +60,7 @@ static const AVOption avectorscope_options[] = {
{ "m", "set mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=LISSAJOUS}, 0, MODE_NB-1, FLAGS, "mode" },
{ "lissajous", "", 0, AV_OPT_TYPE_CONST, {.i64=LISSAJOUS}, 0, 0, FLAGS, "mode" },
{ "lissajous_xy", "", 0, AV_OPT_TYPE_CONST, {.i64=LISSAJOUS_XY}, 0, 0, FLAGS, "mode" },
{ "polar", "", 0, AV_OPT_TYPE_CONST, {.i64=POLAR}, 0, 0, FLAGS, "mode" },
{ "rate", "set video rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str="25"}, 0, 0, FLAGS },
{ "r", "set video rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str="25"}, 0, 0, FLAGS },
{ "size", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str="400x400"}, 0, 0, FLAGS },
@ -210,9 +212,18 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamples)
if (s->mode == LISSAJOUS) {
x = ((src[1] - src[0]) * zoom / (float)(UINT16_MAX) + 1) * hw;
y = (1.0 - (src[0] + src[1]) * zoom / (float)UINT16_MAX) * hh;
} else {
} else if (s->mode == LISSAJOUS_XY) {
x = (src[1] * zoom / (float)INT16_MAX + 1) * hw;
y = (src[0] * zoom / (float)INT16_MAX + 1) * hh;
} else {
float sx, sy, cx, cy;
sx = src[1] * zoom / (float)INT16_MAX;
sy = src[0] * zoom / (float)INT16_MAX;
cx = sx * sqrtf(1 - 0.5*sy*sy);
cy = sy * sqrtf(1 - 0.5*sx*sx);
x = hw + hw * FFSIGN(cx + cy) * (cx - cy) * .7;
y = s->h - s->h * FFABS(cx + cy) * .7;
}
draw_dot(s, x, y);
@ -225,9 +236,18 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamples)
if (s->mode == LISSAJOUS) {
x = ((src[1] - src[0]) * zoom / 2 + 1) * hw;
y = (1.0 - (src[0] + src[1]) * zoom / 2) * hh;
} else {
} else if (s->mode == LISSAJOUS_XY){
x = (src[1] * zoom + 1) * hw;
y = (src[0] * zoom + 1) * hh;
} else {
float sx, sy, cx, cy;
sx = src[1] * zoom;
sy = src[0] * zoom;
cx = sx * sqrtf(1 - 0.5 * sy * sy);
cy = sy * sqrtf(1 - 0.5 * sx * sx);
x = hw + hw * FFSIGN(cx + cy) * (cx - cy) * .7;
y = s->h - s->h * FFABS(cx + cy) * .7;
}
draw_dot(s, x, y);