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
7676 {"duration", "set video duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64=-1}, -1, INT64_MAX, FLAGS },
7777 {"d", "set video duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64=-1}, -1, INT64_MAX, FLAGS },
7878 {"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" },
80− {"t", "set gradient type", OFFSET(type), AV_OPT_TYPE_INT, {.i64=0}, 0, 3, FLAGS, "type" },
81− {"linear", "set gradient type", 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" },
83− {"circular", "set gradient type", 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" },
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, 4, FLAGS, "type" },
81+ { "linear", "set linear gradient", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "type" },
82+ { "radial", "set radial gradient", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "type" },
83+ { "circular", "set circular gradient", 0, AV_OPT_TYPE_CONST, {.i64=2}, 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" },
8586 {NULL},
8687 };
8788
@@ -219,6 +220,9 @@ static float project(float origin_x, float origin_y, · 131 unmodified lines
219220 case 3:
220221 od_s_q = M_PI * 2.f;
221222 break;
223+ case 4:
224+ od_s_q = fmaxf(fabsf(od_x), fabsf(od_y));
225+ break;
222226 }
223227
224228 switch (type) {
@@ -234,6 +238,9 @@ static float project(float origin_x, float origin_y, · 9 unmodified lines
234238 case 3:
235239 op_x_od = fmodf(atan2f(op_x, op_y) + M_PI + point_x / fmaxf(origin_x, dest_x), 2.f * M_PI);
236240 break;
241+ case 4:
242+ op_x_od = fmaxf(fabsf(op_x), fabsf(op_y));
243+ break;
237244 }
238245
239246 // Normalize and clamp range.
@@ -255,7 +262,7 @@ static int draw_gradients_slice(AVFilterContext *ctx, void *arg, int job, int nb · 15 unmodified lines
255262 for (int y = start; y < end; y++) {
256263 for (int x = 0; x < width; x++) {
257264 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);
259266 }
260267
261268 dst += linesize;
@@ -279,7 +286,7 @@ static int draw_gradients_slice16(AVFilterContext *ctx, void *arg, int job, int · 17 unmodified lines
279286 for (int y = start; y < end; y++) {
280287 for (int x = 0; x < width; x++) {
281288 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);
283290 }
284291
285292 dst += linesize;
@@ -309,7 +316,7 @@ static int draw_gradients_slice32_planar(AVFilterContext *ctx, void *arg, int jo · 23 unmodified lines
309316 for (int y = start; y < end; y++) {
310317 for (int x = 0; x < width; x++) {
311318 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,
313320 &dst_r[x], &dst_g[x], &dst_b[x], &dst_a[x]);
314321 }
315322

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