[FFmpeg-cvslog] avfilter/vf_xfade: add corner wipe transforms

Paul B Mahol git at videolan.org
Thu Aug 27 15:46:30 EEST 2020


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Thu Aug 27 13:49:14 2020 +0200| [9ebde67f0b2c00a88527df55c76b86aee4df934e] | committer: Paul B Mahol

avfilter/vf_xfade: add corner wipe transforms

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

 doc/filters.texi       |   4 ++
 libavfilter/vf_xfade.c | 140 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 144 insertions(+)

diff --git a/doc/filters.texi b/doc/filters.texi
index 62852ac8c6..b0cdf92845 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -20521,6 +20521,10 @@ Set one of available transition effects:
 @item vdslice
 @item hblur
 @item fadegrays
+ at item wipetl
+ at item wipetr
+ at item wipebl
+ at item wipebr
 @end table
 Default transition effect is fade.
 
diff --git a/libavfilter/vf_xfade.c b/libavfilter/vf_xfade.c
index 019aa663a7..05fa32a4db 100644
--- a/libavfilter/vf_xfade.c
+++ b/libavfilter/vf_xfade.c
@@ -67,6 +67,10 @@ enum XFadeTransitions {
     VDSLICE,
     HBLUR,
     FADEGRAYS,
+    WIPETL,
+    WIPETR,
+    WIPEBL,
+    WIPEBR,
     NB_TRANSITIONS,
 };
 
@@ -187,6 +191,10 @@ static const AVOption xfade_options[] = {
     {   "vdslice",    "vd slice transition",    0, AV_OPT_TYPE_CONST, {.i64=VDSLICE},    0, 0, FLAGS, "transition" },
     {   "hblur",      "hblur transition",       0, AV_OPT_TYPE_CONST, {.i64=HBLUR},      0, 0, FLAGS, "transition" },
     {   "fadegrays",  "fadegrays transition",   0, AV_OPT_TYPE_CONST, {.i64=FADEGRAYS},  0, 0, FLAGS, "transition" },
+    {   "wipetl",     "wipe tl transition",     0, AV_OPT_TYPE_CONST, {.i64=WIPETL},     0, 0, FLAGS, "transition" },
+    {   "wipetr",     "wipe tr transition",     0, AV_OPT_TYPE_CONST, {.i64=WIPETR},     0, 0, FLAGS, "transition" },
+    {   "wipebl",     "wipe bl transition",     0, AV_OPT_TYPE_CONST, {.i64=WIPEBL},     0, 0, FLAGS, "transition" },
+    {   "wipebr",     "wipe br transition",     0, AV_OPT_TYPE_CONST, {.i64=WIPEBR},     0, 0, FLAGS, "transition" },
     { "duration", "set cross fade duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64=1000000}, 0, 60000000, FLAGS },
     { "offset",   "set cross fade start relative to first input stream", OFFSET(offset), AV_OPT_TYPE_DURATION, {.i64=0}, INT64_MIN, INT64_MAX, FLAGS },
     { "expr",   "set expression for custom transition", OFFSET(custom_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
@@ -1416,6 +1424,134 @@ static void fadegrays##name##_transition(AVFilterContext *ctx,
 FADEGRAYS_TRANSITION(8, uint8_t, 1)
 FADEGRAYS_TRANSITION(16, uint16_t, 2)
 
+#define WIPETL_TRANSITION(name, type, div)                                           \
+static void wipetl##name##_transition(AVFilterContext *ctx,                          \
+                                const AVFrame *a, const AVFrame *b, AVFrame *out,    \
+                                float progress,                                      \
+                                int slice_start, int slice_end, int jobnr)           \
+{                                                                                    \
+    XFadeContext *s = ctx->priv;                                                     \
+    const int height = slice_end - slice_start;                                      \
+    const int zw = out->width * progress;                                            \
+    const int zh = out->height * progress;                                           \
+                                                                                     \
+    for (int p = 0; p < s->nb_planes; p++) {                                         \
+        const type *xf0 = (const type *)(a->data[p] + slice_start * a->linesize[p]); \
+        const type *xf1 = (const type *)(b->data[p] + slice_start * b->linesize[p]); \
+        type *dst = (type *)(out->data[p] + slice_start * out->linesize[p]);         \
+                                                                                     \
+        for (int y = 0; y < height; y++) {                                           \
+            for (int x = 0; x < out->width; x++) {                                   \
+                dst[x] = slice_start + y <= zh &&                                    \
+                         x <= zw ? xf0[x] : xf1[x];                                  \
+            }                                                                        \
+                                                                                     \
+            dst += out->linesize[p] / div;                                           \
+            xf0 += a->linesize[p] / div;                                             \
+            xf1 += b->linesize[p] / div;                                             \
+        }                                                                            \
+    }                                                                                \
+}
+
+WIPETL_TRANSITION(8, uint8_t, 1)
+WIPETL_TRANSITION(16, uint16_t, 2)
+
+#define WIPETR_TRANSITION(name, type, div)                                           \
+static void wipetr##name##_transition(AVFilterContext *ctx,                          \
+                                const AVFrame *a, const AVFrame *b, AVFrame *out,    \
+                                float progress,                                      \
+                                int slice_start, int slice_end, int jobnr)           \
+{                                                                                    \
+    XFadeContext *s = ctx->priv;                                                     \
+    const int height = slice_end - slice_start;                                      \
+    const int zw = out->width * (1.f - progress);                                    \
+    const int zh = out->height * progress;                                           \
+                                                                                     \
+    for (int p = 0; p < s->nb_planes; p++) {                                         \
+        const type *xf0 = (const type *)(a->data[p] + slice_start * a->linesize[p]); \
+        const type *xf1 = (const type *)(b->data[p] + slice_start * b->linesize[p]); \
+        type *dst = (type *)(out->data[p] + slice_start * out->linesize[p]);         \
+                                                                                     \
+        for (int y = 0; y < height; y++) {                                           \
+            for (int x = 0; x < out->width; x++) {                                   \
+                dst[x] = slice_start + y <= zh &&                                    \
+                         x > zw ? xf0[x] : xf1[x];                                   \
+            }                                                                        \
+                                                                                     \
+            dst += out->linesize[p] / div;                                           \
+            xf0 += a->linesize[p] / div;                                             \
+            xf1 += b->linesize[p] / div;                                             \
+        }                                                                            \
+    }                                                                                \
+}
+
+WIPETR_TRANSITION(8, uint8_t, 1)
+WIPETR_TRANSITION(16, uint16_t, 2)
+
+#define WIPEBL_TRANSITION(name, type, div)                                           \
+static void wipebl##name##_transition(AVFilterContext *ctx,                          \
+                                const AVFrame *a, const AVFrame *b, AVFrame *out,    \
+                                float progress,                                      \
+                                int slice_start, int slice_end, int jobnr)           \
+{                                                                                    \
+    XFadeContext *s = ctx->priv;                                                     \
+    const int height = slice_end - slice_start;                                      \
+    const int zw = out->width * progress;                                            \
+    const int zh = out->height * (1.f - progress);                                   \
+                                                                                     \
+    for (int p = 0; p < s->nb_planes; p++) {                                         \
+        const type *xf0 = (const type *)(a->data[p] + slice_start * a->linesize[p]); \
+        const type *xf1 = (const type *)(b->data[p] + slice_start * b->linesize[p]); \
+        type *dst = (type *)(out->data[p] + slice_start * out->linesize[p]);         \
+                                                                                     \
+        for (int y = 0; y < height; y++) {                                           \
+            for (int x = 0; x < out->width; x++) {                                   \
+                dst[x] = slice_start + y > zh &&                                     \
+                         x <= zw ? xf0[x] : xf1[x];                                  \
+            }                                                                        \
+                                                                                     \
+            dst += out->linesize[p] / div;                                           \
+            xf0 += a->linesize[p] / div;                                             \
+            xf1 += b->linesize[p] / div;                                             \
+        }                                                                            \
+    }                                                                                \
+}
+
+WIPEBL_TRANSITION(8, uint8_t, 1)
+WIPEBL_TRANSITION(16, uint16_t, 2)
+
+#define WIPEBR_TRANSITION(name, type, div)                                           \
+static void wipebr##name##_transition(AVFilterContext *ctx,                          \
+                                const AVFrame *a, const AVFrame *b, AVFrame *out,    \
+                                float progress,                                      \
+                                int slice_start, int slice_end, int jobnr)           \
+{                                                                                    \
+    XFadeContext *s = ctx->priv;                                                     \
+    const int height = slice_end - slice_start;                                      \
+    const int zh = out->height * (1.f - progress);                                   \
+    const int zw = out->width * (1.f - progress);                                    \
+                                                                                     \
+    for (int p = 0; p < s->nb_planes; p++) {                                         \
+        const type *xf0 = (const type *)(a->data[p] + slice_start * a->linesize[p]); \
+        const type *xf1 = (const type *)(b->data[p] + slice_start * b->linesize[p]); \
+        type *dst = (type *)(out->data[p] + slice_start * out->linesize[p]);         \
+                                                                                     \
+        for (int y = 0; y < height; y++) {                                           \
+            for (int x = 0; x < out->width; x++) {                                   \
+                dst[x] = slice_start + y > zh &&                                     \
+                         x > zw ? xf0[x] : xf1[x];                                   \
+            }                                                                        \
+                                                                                     \
+            dst += out->linesize[p] / div;                                           \
+            xf0 += a->linesize[p] / div;                                             \
+            xf1 += b->linesize[p] / div;                                             \
+        }                                                                            \
+    }                                                                                \
+}
+
+WIPEBR_TRANSITION(8, uint8_t, 1)
+WIPEBR_TRANSITION(16, uint16_t, 2)
+
 static inline double getpix(void *priv, double x, double y, int plane, int nb)
 {
     XFadeContext *s = priv;
@@ -1559,6 +1695,10 @@ static int config_output(AVFilterLink *outlink)
     case VDSLICE:    s->transitionf = s->depth <= 8 ? vdslice8_transition    : vdslice16_transition;    break;
     case HBLUR:      s->transitionf = s->depth <= 8 ? hblur8_transition      : hblur16_transition;      break;
     case FADEGRAYS:  s->transitionf = s->depth <= 8 ? fadegrays8_transition  : fadegrays16_transition;  break;
+    case WIPETL:     s->transitionf = s->depth <= 8 ? wipetl8_transition     : wipetl16_transition;     break;
+    case WIPETR:     s->transitionf = s->depth <= 8 ? wipetr8_transition     : wipetr16_transition;     break;
+    case WIPEBL:     s->transitionf = s->depth <= 8 ? wipebl8_transition     : wipebl16_transition;     break;
+    case WIPEBR:     s->transitionf = s->depth <= 8 ? wipebr8_transition     : wipebr16_transition;     break;
     }
 
     if (s->transition == CUSTOM) {



More information about the ffmpeg-cvslog mailing list