[FFmpeg-cvslog] avfilter/vsrc_gradients: add square type

Paul B Mahol git at videolan.org
Sun Nov 26 03:00:50 EET 2023


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Sun Nov 26 01:25:03 2023 +0100| [f1acb0d843e4e69f95cca598b69cec96b0451597] | committer: Paul B Mahol

avfilter/vsrc_gradients: add square type

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=f1acb0d843e4e69f95cca598b69cec96b0451597
---

 doc/filters.texi             | 11 ++++++++++-
 libavfilter/vsrc_gradients.c | 25 ++++++++++++++++---------
 2 files changed, 26 insertions(+), 10 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index c3607dd036..5268b2003c 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -28260,9 +28260,18 @@ supposed to be generated forever.
 Set speed of gradients rotation.
 
 @item type, t
-Set type of gradients, can be @code{linear} or @code{radial} or @code{circular} or @code{spiral}.
+Set type of gradients.
+Available values are:
+ at table @samp
+ at item linear
+ at item radial
+ at item circular
+ at item spiral
+ at item square
 @end table
 
+Default type is @var{linear}.
+ at end table
 
 @section mandelbrot
 
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]);
         }
 



More information about the ffmpeg-cvslog mailing list