History

avfilter/vsrc_gradients: add square type

Paul B Mahol committed 2 years ago

Commit f1acb0d1 parent 72390de2 files · +26 −10Browse files

Showing the changes to libavfilter (1 of 2 files). Show all

Unified · Split

libavfilter/vsrc_gradients.c+16−9
@@ -76,12 +76,13 @@ static const AVOption gradients_options[] = { · 75 unmodified lines
76 {"duration", "set video duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64=-1}, -1, INT64_MAX, FLAGS },76 {"duration", "set video duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64=-1}, -1, INT64_MAX, FLAGS },
77 {"d", "set video duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64=-1}, -1, INT64_MAX, FLAGS },77 {"d", "set video duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64=-1}, -1, INT64_MAX, FLAGS },
78 {"speed", "set gradients rotation speed", OFFSET(speed), AV_OPT_TYPE_FLOAT,{.dbl=0.01}, 0.00001, 1, FLAGS },78 {"speed", "set gradients rotation speed", OFFSET(speed), AV_OPT_TYPE_FLOAT,{.dbl=0.01}, 0.00001, 1, FLAGS },
79 {"type", "set gradient type", OFFSET(type), AV_OPT_TYPE_INT, {.i64=0}, 0, 3, FLAGS, "type" },79 {"type", "set gradient type", OFFSET(type), AV_OPT_TYPE_INT, {.i64=0}, 0, 4, FLAGS, "type" },
80 {"t", "set gradient type", OFFSET(type), AV_OPT_TYPE_INT, {.i64=0}, 0, 3, FLAGS, "type" },80 {"t", "set gradient type", OFFSET(type), AV_OPT_TYPE_INT, {.i64=0}, 0, 4, FLAGS, "type" },
81 {"linear", "set gradient type", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "type" },81 { "linear", "set linear gradient", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "type" },
82 {"radial", "set gradient type", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "type" },82 { "radial", "set radial gradient", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "type" },
83 {"circular", "set gradient type", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, FLAGS, "type" },83 { "circular", "set circular gradient", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, FLAGS, "type" },
84 {"spiral", "set gradient type", 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, FLAGS, "type" },84 { "spiral", "set spiral gradient", 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, FLAGS, "type" },
85 { "square", "set square gradient", 0, AV_OPT_TYPE_CONST, {.i64=4}, 0, 0, FLAGS, "type" },
85 {NULL},86 {NULL},
86};87};
87 88
@@ -219,6 +220,9 @@ static float project(float origin_x, float origin_y, · 131 unmodified lines
219 case 3:220 case 3:
220 od_s_q = M_PI * 2.f;221 od_s_q = M_PI * 2.f;
221 break;222 break;
223 case 4:
224 od_s_q = fmaxf(fabsf(od_x), fabsf(od_y));
225 break;
222 }226 }
223 227
224 switch (type) {228 switch (type) {
@@ -234,6 +238,9 @@ static float project(float origin_x, float origin_y, · 9 unmodified lines
234 case 3:238 case 3:
235 op_x_od = fmodf(atan2f(op_x, op_y) + M_PI + point_x / fmaxf(origin_x, dest_x), 2.f * M_PI);239 op_x_od = fmodf(atan2f(op_x, op_y) + M_PI + point_x / fmaxf(origin_x, dest_x), 2.f * M_PI);
236 break;240 break;
241 case 4:
242 op_x_od = fmaxf(fabsf(op_x), fabsf(op_y));
243 break;
237 }244 }
238 245
239 // Normalize and clamp range.246 // Normalize and clamp range.
@@ -255,7 +262,7 @@ static int draw_gradients_slice(AVFilterContext *ctx, void *arg, int job, int nb · 15 unmodified lines
255 for (int y = start; y < end; y++) {262 for (int y = start; y < end; y++) {
256 for (int x = 0; x < width; x++) {263 for (int x = 0; x < width; x++) {
257 float factor = project(s->fx0, s->fy0, s->fx1, s->fy1, x, y, type);264 float factor = project(s->fx0, s->fy0, s->fx1, s->fy1, x, y, type);
258 dst[x] = lerp_colors(s->color_rgba, s->nb_colors, s->nb_colors + (type >= 2), factor);265 dst[x] = lerp_colors(s->color_rgba, s->nb_colors, s->nb_colors + (type >= 2 && type <= 3), factor);
259 }266 }
260 267
261 dst += linesize;268 dst += linesize;
@@ -279,7 +286,7 @@ static int draw_gradients_slice16(AVFilterContext *ctx, void *arg, int job, int · 17 unmodified lines
279 for (int y = start; y < end; y++) {286 for (int y = start; y < end; y++) {
280 for (int x = 0; x < width; x++) {287 for (int x = 0; x < width; x++) {
281 float factor = project(s->fx0, s->fy0, s->fx1, s->fy1, x, y, type);288 float factor = project(s->fx0, s->fy0, s->fx1, s->fy1, x, y, type);
282 dst[x] = lerp_colors16(s->color_rgba, s->nb_colors, s->nb_colors + (type >= 2), factor);289 dst[x] = lerp_colors16(s->color_rgba, s->nb_colors, s->nb_colors + (type >= 2 && type <= 3), factor);
283 }290 }
284 291
285 dst += linesize;292 dst += linesize;
@@ -309,7 +316,7 @@ static int draw_gradients_slice32_planar(AVFilterContext *ctx, void *arg, int jo · 23 unmodified lines
309 for (int y = start; y < end; y++) {316 for (int y = start; y < end; y++) {
310 for (int x = 0; x < width; x++) {317 for (int x = 0; x < width; x++) {
311 float factor = project(s->fx0, s->fy0, s->fx1, s->fy1, x, y, type);318 float factor = project(s->fx0, s->fy0, s->fx1, s->fy1, x, y, type);
312 lerp_colors32(s->color_rgbaf, s->nb_colors, s->nb_colors + (type >= 2), factor,319 lerp_colors32(s->color_rgbaf, s->nb_colors, s->nb_colors + (type >= 2 && type <= 3), factor,
313 &dst_r[x], &dst_g[x], &dst_b[x], &dst_a[x]);320 &dst_r[x], &dst_g[x], &dst_b[x], &dst_a[x]);
314 }321 }
315 322

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