diff options
author | Paul B Mahol <onemda@gmail.com> | 2023-11-26 01:25:03 +0100 |
---|---|---|
committer | Paul B Mahol <onemda@gmail.com> | 2023-11-26 02:07:44 +0100 |
commit | f1acb0d843e4e69f95cca598b69cec96b0451597 (patch) | |
tree | 775d714fa9a41b12fbbb377911493ee045b11b2f /libavfilter | |
parent | 72390dea003923a4b162a38cc85fd2220098284b (diff) | |
download | ffmpeg-f1acb0d843e4e69f95cca598b69cec96b0451597.tar.gz |
avfilter/vsrc_gradients: add square type
Diffstat (limited to 'libavfilter')
-rw-r--r-- | libavfilter/vsrc_gradients.c | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/libavfilter/vsrc_gradients.c b/libavfilter/vsrc_gradients.c index 39e2670703..c8fda25b6c 100644 --- a/libavfilter/vsrc_gradients.c +++ b/libavfilter/vsrc_gradients.c @@ -76,12 +76,13 @@ static const AVOption gradients_options[] = { {"duration", "set video duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64=-1}, -1, INT64_MAX, FLAGS }, {"d", "set video duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64=-1}, -1, INT64_MAX, FLAGS }, {"speed", "set gradients rotation speed", OFFSET(speed), AV_OPT_TYPE_FLOAT,{.dbl=0.01}, 0.00001, 1, FLAGS }, - {"type", "set gradient type", OFFSET(type), AV_OPT_TYPE_INT, {.i64=0}, 0, 3, FLAGS, "type" }, - {"t", "set gradient type", OFFSET(type), AV_OPT_TYPE_INT, {.i64=0}, 0, 3, FLAGS, "type" }, - {"linear", "set gradient type", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "type" }, - {"radial", "set gradient type", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "type" }, - {"circular", "set gradient type", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, FLAGS, "type" }, - {"spiral", "set gradient type", 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, FLAGS, "type" }, + {"type", "set gradient type", OFFSET(type), AV_OPT_TYPE_INT, {.i64=0}, 0, 4, FLAGS, "type" }, + {"t", "set gradient type", OFFSET(type), AV_OPT_TYPE_INT, {.i64=0}, 0, 4, FLAGS, "type" }, + { "linear", "set linear gradient", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "type" }, + { "radial", "set radial gradient", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "type" }, + { "circular", "set circular gradient", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, FLAGS, "type" }, + { "spiral", "set spiral gradient", 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, FLAGS, "type" }, + { "square", "set square gradient", 0, AV_OPT_TYPE_CONST, {.i64=4}, 0, 0, FLAGS, "type" }, {NULL}, }; @@ -219,6 +220,9 @@ static float project(float origin_x, float origin_y, case 3: od_s_q = M_PI * 2.f; break; + case 4: + od_s_q = fmaxf(fabsf(od_x), fabsf(od_y)); + break; } switch (type) { @@ -234,6 +238,9 @@ static float project(float origin_x, float origin_y, case 3: op_x_od = fmodf(atan2f(op_x, op_y) + M_PI + point_x / fmaxf(origin_x, dest_x), 2.f * M_PI); break; + case 4: + op_x_od = fmaxf(fabsf(op_x), fabsf(op_y)); + break; } // Normalize and clamp range. @@ -255,7 +262,7 @@ static int draw_gradients_slice(AVFilterContext *ctx, void *arg, int job, int nb for (int y = start; y < end; y++) { for (int x = 0; x < width; x++) { float factor = project(s->fx0, s->fy0, s->fx1, s->fy1, x, y, type); - dst[x] = lerp_colors(s->color_rgba, s->nb_colors, s->nb_colors + (type >= 2), factor); + dst[x] = lerp_colors(s->color_rgba, s->nb_colors, s->nb_colors + (type >= 2 && type <= 3), factor); } dst += linesize; @@ -279,7 +286,7 @@ static int draw_gradients_slice16(AVFilterContext *ctx, void *arg, int job, int for (int y = start; y < end; y++) { for (int x = 0; x < width; x++) { float factor = project(s->fx0, s->fy0, s->fx1, s->fy1, x, y, type); - dst[x] = lerp_colors16(s->color_rgba, s->nb_colors, s->nb_colors + (type >= 2), factor); + dst[x] = lerp_colors16(s->color_rgba, s->nb_colors, s->nb_colors + (type >= 2 && type <= 3), factor); } dst += linesize; @@ -309,7 +316,7 @@ static int draw_gradients_slice32_planar(AVFilterContext *ctx, void *arg, int jo for (int y = start; y < end; y++) { for (int x = 0; x < width; x++) { float factor = project(s->fx0, s->fy0, s->fx1, s->fy1, x, y, type); - lerp_colors32(s->color_rgbaf, s->nb_colors, s->nb_colors + (type >= 2), factor, + lerp_colors32(s->color_rgbaf, s->nb_colors, s->nb_colors + (type >= 2 && type <= 3), factor, &dst_r[x], &dst_g[x], &dst_b[x], &dst_a[x]); } |