History

avfilter/vsrc_gradients: add spiral type

Paul B Mahol committed 4 years ago

Commit 21ca2211 parent 8e1cedb2 files · +11 −6Browse files

Unified · Split

2 files
  1. doc/filters.texi +1 −1
  2. libavfilter/vsrc_gradients.c +10 −5
doc/filters.texi+1−1
@@ -25874,7 +25874,7 @@ supposed to be generated forever. · 25873 unmodified lines
2587425874 Set speed of gradients rotation.
2587525875
2587625876 @item type, t
25877−Set type of gradients, can be @code{linear} or @code{radial} or @code{circular}.
25877+Set type of gradients, can be @code{linear} or @code{radial} or @code{circular} or @code{spiral}.
2587825878 @end table
2587925879
2588025880
libavfilter/vsrc_gradients.c+10−5
@@ -79,11 +79,12 @@ static const AVOption gradients_options[] = { · 78 unmodified lines
7979 {"duration", "set video duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64=-1}, -1, INT64_MAX, FLAGS },
8080 {"d", "set video duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64=-1}, -1, INT64_MAX, FLAGS },
8181 {"speed", "set gradients rotation speed", OFFSET(speed), AV_OPT_TYPE_FLOAT,{.dbl=0.01}, 0.00001, 1, FLAGS },
82− {"type", "set gradient type", OFFSET(type), AV_OPT_TYPE_INT, {.i64=0}, 0, 2, FLAGS, "type" },
83− {"t", "set gradient type", OFFSET(type), AV_OPT_TYPE_INT, {.i64=0}, 0, 2, FLAGS, "type" },
82+ {"type", "set gradient type", OFFSET(type), AV_OPT_TYPE_INT, {.i64=0}, 0, 3, FLAGS, "type" },
83+ {"t", "set gradient type", OFFSET(type), AV_OPT_TYPE_INT, {.i64=0}, 0, 3, FLAGS, "type" },
8484 {"linear", "set gradient type", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "type" },
8585 {"radial", "set gradient type", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "type" },
8686 {"circular", "set gradient type", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, FLAGS, "type" },
87+ {"spiral", "set gradient type", 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, FLAGS, "type" },
8788 {NULL},
8889 };
8990
@@ -218,6 +219,7 @@ static float project(float origin_x, float origin_y, · 128 unmodified lines
218219 od_s_q = sqrtf(od_x * od_x + od_y * od_y);
219220 break;
220221 case 2:
222+ case 3:
221223 od_s_q = M_PI * 2.f;
222224 break;
223225 }
@@ -232,6 +234,9 @@ static float project(float origin_x, float origin_y, · 8 unmodified lines
232234 case 2:
233235 op_x_od = atan2f(op_x, op_y) + M_PI;
234236 break;
237+ case 3:
238+ op_x_od = fmodf(atan2f(op_x, op_y) + M_PI + point_x / fmaxf(origin_x, dest_x), 2.f * M_PI);
239+ break;
235240 }
236241
237242 // Normalize and clamp range.
@@ -252,7 +257,7 @@ static int draw_gradients_slice(AVFilterContext *ctx, void *arg, int job, int nb · 14 unmodified lines
252257 for (int y = start; y < end; y++) {
253258 for (int x = 0; x < width; x++) {
254259 float factor = project(s->fx0, s->fy0, s->fx1, s->fy1, x, y, s->type);
255− dst[x] = lerp_colors(s->color_rgba, s->nb_colors, s->nb_colors + (s->type == 2), factor);
260+ dst[x] = lerp_colors(s->color_rgba, s->nb_colors, s->nb_colors + (s->type >= 2), factor);
256261 }
257262
258263 dst += linesize;
@@ -275,7 +280,7 @@ static int draw_gradients_slice16(AVFilterContext *ctx, void *arg, int job, int · 16 unmodified lines
275280 for (int y = start; y < end; y++) {
276281 for (int x = 0; x < width; x++) {
277282 float factor = project(s->fx0, s->fy0, s->fx1, s->fy1, x, y, s->type);
278− dst[x] = lerp_colors16(s->color_rgba, s->nb_colors, s->nb_colors + s->type == 2, factor);
283+ dst[x] = lerp_colors16(s->color_rgba, s->nb_colors, s->nb_colors + s->type >= 2, factor);
279284 }
280285
281286 dst += linesize;
@@ -304,7 +309,7 @@ static int draw_gradients_slice32_planar(AVFilterContext *ctx, void *arg, int jo · 22 unmodified lines
304309 for (int y = start; y < end; y++) {
305310 for (int x = 0; x < width; x++) {
306311 float factor = project(s->fx0, s->fy0, s->fx1, s->fy1, x, y, s->type);
307− lerp_colors32(s->color_rgbaf, s->nb_colors, s->nb_colors + s->type == 2 ,factor,
312+ lerp_colors32(s->color_rgbaf, s->nb_colors, s->nb_colors + s->type >= 2 ,factor,
308313 &dst_r[x], &dst_g[x], &dst_b[x], &dst_a[x]);
309314 }
310315

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