Skip to content

Commit

Permalink
avfilter/avf_showcwt: add rotation option
Browse files Browse the repository at this point in the history
  • Loading branch information
richardpl committed Jul 12, 2023
1 parent 422bfdc commit 7430ee2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
7 changes: 7 additions & 0 deletions doc/filters.texi
Original file line number Diff line number Diff line change
Expand Up @@ -30784,6 +30784,13 @@ Direction from up to down.
@item du
Direction from down to up.
@end table

@item bar
Set the ratio of bargraph display to display size. Default is 0.

@item rotation
Set color rotation, must be in [-1.0, 1.0] range.
Default value is @code{0}.
@end table

@section showfreqs
Expand Down
17 changes: 13 additions & 4 deletions libavfilter/avf_showcwt.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ typedef struct ShowCWTContext {
float deviation;
float bar_ratio;
int bar_size;
float rotation;

AVFloatDSPContext *fdsp;
} ShowCWTContext;
Expand Down Expand Up @@ -163,6 +164,7 @@ static const AVOption showcwt_options[] = {
{ "ud", "up to down", 0, AV_OPT_TYPE_CONST,{.i64=DIRECTION_UD}, 0, 0, FLAGS, "direction" },
{ "du", "down to up", 0, AV_OPT_TYPE_CONST,{.i64=DIRECTION_DU}, 0, 0, FLAGS, "direction" },
{ "bar", "set bar ratio", OFFSET(bar_ratio), AV_OPT_TYPE_FLOAT, {.dbl = 0.}, 0, 1, FLAGS },
{ "rotation", "set color rotation", OFFSET(rotation), AV_OPT_TYPE_FLOAT, {.dbl = 0}, -1, 1, FLAGS },
{ NULL }
};

Expand Down Expand Up @@ -407,6 +409,7 @@ static int draw(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
const int end = (count * (jobnr+1)) / nb_jobs;
const int ihop_index = s->ihop_index;
const int ihop_size = s->ihop_size;
const float rotation = s->rotation;
const int direction = s->direction;
uint8_t *dstY, *dstU, *dstV, *dstA;
const int bar_size = s->bar_size;
Expand Down Expand Up @@ -486,8 +489,14 @@ static int draw(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
v = remap_log(v, log_factor);

Y = z;
U = 0.5f + z * sinf((v - u) * M_PI_2);
V = 0.5f + z * sinf((u - v) * M_PI_2);
U = sinf((v - u) * M_PI_2);
V = sinf((u - v) * M_PI_2);

u = U * cosf(rotation * M_PI) - V * sinf(rotation * M_PI);
v = U * sinf(rotation * M_PI) + V * cosf(rotation * M_PI);

U = 0.5f + 0.5f * z * u;
V = 0.5f + 0.5f * z * v;

dstY[0] = av_clip_uint8(lrintf(Y * 255.f));
dstU[0] = av_clip_uint8(lrintf(U * 255.f));
Expand Down Expand Up @@ -515,8 +524,8 @@ static int draw(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
z = remap_log(z, log_factor);

Y += z * yf;
U += z * yf * sinf(2.f * M_PI * ch * yf);
V += z * yf * cosf(2.f * M_PI * ch * yf);
U += z * yf * sinf(2.f * M_PI * (ch * yf + rotation));
V += z * yf * cosf(2.f * M_PI * (ch * yf + rotation));
}

dstY[0] = av_clip_uint8(lrintf(Y * 255.f));
Expand Down

0 comments on commit 7430ee2

Please sign in to comment.